diff options
| author | Richard Lowe <richlowe@richlowe.net> | 2012-03-02 19:01:23 -0500 |
|---|---|---|
| committer | Richard Lowe <richlowe@richlowe.net> | 2012-03-02 19:01:23 -0500 |
| commit | 15e1afcd5e908ae29b1e6018838638befdc225a2 (patch) | |
| tree | 3bbbffe597d2f2e0d037ef18cbaaf932447e1377 /usr/src/uts | |
| parent | 88b44bf4e73233af70877930178dbff7f1c2992b (diff) | |
| download | illumos-gate-15e1afcd5e908ae29b1e6018838638befdc225a2.tar.gz | |
backout 998: breaks common closed drivers
Diffstat (limited to 'usr/src/uts')
56 files changed, 2080 insertions, 302 deletions
diff --git a/usr/src/uts/common/io/1394/nx1394.c b/usr/src/uts/common/io/1394/nx1394.c index 216b70a319..cc710b8417 100644 --- a/usr/src/uts/common/io/1394/nx1394.c +++ b/usr/src/uts/common/io/1394/nx1394.c @@ -23,9 +23,8 @@ * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* * nx1394.c @@ -73,7 +72,7 @@ struct bus_ops nx1394_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ i_ddi_map_fault, /* XXXX bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ nx1394_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, @@ -392,7 +391,7 @@ nx1394_add_eventcall(dev_info_t *dip, dev_info_t *rdip, #if defined(DEBUG) event_name = ndi_event_cookie_to_name(hal->hal_ndi_event_hdl, cookie); if (event_name == NULL) - event_name = ""; + event_name = ""; #endif TNF_PROBE_4_DEBUG(nx1394_add_eventcall_exit, S1394_TNF_SL_NEXUS_STACK, "", tnf_opaque, parent_dip, (void *)dip, tnf_opaque, requestor_dip, @@ -431,7 +430,7 @@ nx1394_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) #if defined(DEBUG) event_name = ndi_event_cookie_to_name(hal->hal_ndi_event_hdl, cookie); if (event_name == NULL) - event_name = ""; + event_name = ""; TNF_PROBE_4_DEBUG(nx1394_remove_eventcall_exit, S1394_TNF_SL_NEXUS_STACK, "", tnf_opaque, parent_dip, (void *)dip, diff --git a/usr/src/uts/common/io/blkdev/blkdev.c b/usr/src/uts/common/io/blkdev/blkdev.c index 7b722f126c..f7d6cff7a1 100644 --- a/usr/src/uts/common/io/blkdev/blkdev.c +++ b/usr/src/uts/common/io/blkdev/blkdev.c @@ -20,8 +20,10 @@ */ /* * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + */ + +/* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #include <sys/types.h> @@ -1678,7 +1680,7 @@ bd_mod_init(struct dev_ops *devops) NULL, /* bus_add_intrspec (OBSOLETE) */ NULL, /* bus_remove_intrspec (OBSOLETE) */ i_ddi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map (OBSOLETE) */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/common/io/bofi.c b/usr/src/uts/common/io/bofi.c index 6554d29f76..80b69bd07b 100644 --- a/usr/src/uts/common/io/bofi.c +++ b/usr/src/uts/common/io/bofi.c @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> @@ -164,6 +161,8 @@ static int bofi_errdef_check_w(struct bofi_errstate *, struct acc_log_elem **); static int bofi_map(dev_info_t *, dev_info_t *, ddi_map_req_t *, off_t, off_t, caddr_t *); +static int bofi_dma_map(dev_info_t *, dev_info_t *, + struct ddi_dma_req *, ddi_dma_handle_t *); static int bofi_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, int (*)(caddr_t), caddr_t, ddi_dma_handle_t *); @@ -210,7 +209,7 @@ static struct bus_ops bofi_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + bofi_dma_map, bofi_dma_allochdl, bofi_dma_freehdl, bofi_dma_bindhdl, @@ -3335,6 +3334,174 @@ xbcopy(void *from, void *to, u_longlong_t len) /* + * our ddi_dma_map routine + */ +static int +bofi_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep) +{ + struct bofi_shadow *hp, *xhp; + int maxrnumber = 0; + int retval = DDI_DMA_NORESOURCES; + auto struct ddi_dma_req dmareq; + int sleep; + struct bofi_shadow *dhashp; + struct bofi_shadow *hhashp; + ddi_dma_impl_t *mp; + unsigned long pagemask = ddi_ptob(rdip, 1) - 1; + + /* + * if driver_list is set, only intercept those drivers + */ + if (handlep == NULL || !driver_under_test(rdip)) + return (save_bus_ops.bus_dma_map(dip, rdip, dmareqp, handlep)); + + sleep = (dmareqp->dmar_fp == DDI_DMA_SLEEP) ? KM_SLEEP : KM_NOSLEEP; + /* + * allocate shadow handle structure and fill it in + */ + hp = kmem_zalloc(sizeof (struct bofi_shadow), sleep); + if (hp == NULL) + goto error; + (void) strncpy(hp->name, ddi_get_name(rdip), NAMESIZE); + hp->instance = ddi_get_instance(rdip); + hp->dip = rdip; + hp->flags = dmareqp->dmar_flags; + if (dmareqp->dmar_object.dmao_type == DMA_OTYP_PAGES) { + hp->map_flags = B_PAGEIO; + hp->map_pp = dmareqp->dmar_object.dmao_obj.pp_obj.pp_pp; + } else if (dmareqp->dmar_object.dmao_obj.virt_obj.v_priv != NULL) { + hp->map_flags = B_SHADOW; + hp->map_pplist = dmareqp->dmar_object.dmao_obj.virt_obj.v_priv; + } else { + hp->map_flags = 0; + } + hp->link = NULL; + hp->type = BOFI_DMA_HDL; + /* + * get a kernel virtual mapping + */ + hp->addr = ddi_dmareq_mapin(dmareqp, &hp->mapaddr, &hp->len); + if (hp->addr == NULL) + goto error; + if (bofi_sync_check) { + /* + * Take a copy and pass pointers to this up to nexus instead. + * Data will be copied from the original on explicit + * and implicit ddi_dma_sync() + * + * - maintain page alignment because some devices assume it. + */ + hp->origaddr = hp->addr; + hp->allocaddr = ddi_umem_alloc( + ((uintptr_t)hp->addr & pagemask) + hp->len, sleep, + &hp->umem_cookie); + if (hp->allocaddr == NULL) + goto error; + hp->addr = hp->allocaddr + ((uintptr_t)hp->addr & pagemask); + if (dmareqp->dmar_flags & DDI_DMA_WRITE) + xbcopy(hp->origaddr, hp->addr, hp->len); + dmareq = *dmareqp; + dmareq.dmar_object.dmao_size = hp->len; + dmareq.dmar_object.dmao_type = DMA_OTYP_VADDR; + dmareq.dmar_object.dmao_obj.virt_obj.v_as = &kas; + dmareq.dmar_object.dmao_obj.virt_obj.v_addr = hp->addr; + dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL; + dmareqp = &dmareq; + } + /* + * call nexus to do the real work + */ + retval = save_bus_ops.bus_dma_map(dip, rdip, dmareqp, handlep); + if (retval != DDI_SUCCESS) + goto error2; + /* + * now set dma_handle to point to real handle + */ + hp->hdl.dma_handle = *handlep; + /* + * unset DMP_NOSYNC + */ + mp = (ddi_dma_impl_t *)*handlep; + mp->dmai_rflags &= ~DMP_NOSYNC; + mp->dmai_fault_check = bofi_check_dma_hdl; + /* + * bind and unbind are cached in devinfo - must overwrite them + * - note that our bind and unbind are quite happy dealing with + * any handles for this devinfo that were previously allocated + */ + if (save_bus_ops.bus_dma_bindhdl == DEVI(rdip)->devi_bus_dma_bindfunc) + DEVI(rdip)->devi_bus_dma_bindfunc = bofi_dma_bindhdl; + if (save_bus_ops.bus_dma_unbindhdl == + DEVI(rdip)->devi_bus_dma_unbindfunc) + DEVI(rdip)->devi_bus_dma_unbindfunc = bofi_dma_unbindhdl; + mutex_enter(&bofi_low_mutex); + mutex_enter(&bofi_mutex); + /* + * get an "rnumber" for this handle - really just seeking to + * get a unique number - generally only care for early allocated + * handles - so we get as far as INT_MAX, just stay there + */ + dhashp = HDL_DHASH(hp->dip); + for (xhp = dhashp->dnext; xhp != dhashp; xhp = xhp->dnext) + if (ddi_name_to_major(xhp->name) == + ddi_name_to_major(hp->name) && + xhp->instance == hp->instance && + xhp->type == BOFI_DMA_HDL) + if (xhp->rnumber >= maxrnumber) { + if (xhp->rnumber == INT_MAX) + maxrnumber = INT_MAX; + else + maxrnumber = xhp->rnumber + 1; + } + hp->rnumber = maxrnumber; + /* + * add to dhash, hhash and inuse lists + */ + hp->next = shadow_list.next; + shadow_list.next->prev = hp; + hp->prev = &shadow_list; + shadow_list.next = hp; + hhashp = HDL_HHASH(*handlep); + hp->hnext = hhashp->hnext; + hhashp->hnext->hprev = hp; + hp->hprev = hhashp; + hhashp->hnext = hp; + dhashp = HDL_DHASH(hp->dip); + hp->dnext = dhashp->dnext; + dhashp->dnext->dprev = hp; + hp->dprev = dhashp; + dhashp->dnext = hp; + /* + * chain on any pre-existing errdefs that apply to this + * acc_handle and corrupt if required (as there is an implicit + * ddi_dma_sync() in this call) + */ + chain_on_errdefs(hp); + mutex_exit(&bofi_mutex); + mutex_exit(&bofi_low_mutex); + return (retval); +error: + if (dmareqp->dmar_fp != DDI_DMA_DONTWAIT) { + /* + * what to do here? Wait a bit and try again + */ + (void) timeout((void (*)())dmareqp->dmar_fp, + dmareqp->dmar_arg, 10); + } +error2: + if (hp) { + ddi_dmareq_mapout(hp->mapaddr, hp->len, hp->map_flags, + hp->map_pp, hp->map_pplist); + if (bofi_sync_check && hp->allocaddr) + ddi_umem_free(hp->umem_cookie); + kmem_free(hp, sizeof (struct bofi_shadow)); + } + return (retval); +} + + +/* * our ddi_dma_allochdl routine */ static int @@ -3836,11 +4003,14 @@ bofi_dma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags) { + struct bofi_link *lp, *next_lp; + struct bofi_errent *ep; struct bofi_shadow *hp; struct bofi_shadow *hhashp; int retval; int i; struct bofi_shadow *dummyhp; + ddi_dma_impl_t *mp; /* * get nexus to do real work @@ -3919,6 +4089,58 @@ bofi_dma_ctl(dev_info_t *dip, dev_info_t *rdip, sizeof (struct bofi_shadow *)); kmem_free(dummyhp, sizeof (struct bofi_shadow)); return (retval); + case DDI_DMA_FREE: + /* + * ddi_dma_free case - remove from dhash, hhash and inuse lists + */ + hp->hnext->hprev = hp->hprev; + hp->hprev->hnext = hp->hnext; + hp->dnext->dprev = hp->dprev; + hp->dprev->dnext = hp->dnext; + hp->next->prev = hp->prev; + hp->prev->next = hp->next; + /* + * free any errdef link structures tagged on to this + * shadow handle + */ + for (lp = hp->link; lp != NULL; ) { + next_lp = lp->link; + /* + * there is an implicit sync_for_cpu on free - + * may need to corrupt + */ + ep = lp->errentp; + if ((ep->errdef.access_type & BOFI_DMA_R) && + (hp->flags & DDI_DMA_READ) && + (ep->state & BOFI_DEV_ACTIVE)) { + do_dma_corrupt(hp, ep, DDI_DMA_SYNC_FORCPU, + 0, hp->len); + } + lp->link = bofi_link_freelist; + bofi_link_freelist = lp; + lp = next_lp; + } + hp->link = NULL; + mutex_exit(&bofi_mutex); + mutex_exit(&bofi_low_mutex); + + if (bofi_sync_check && (hp->flags & DDI_DMA_READ)) + if (hp->allocaddr) + xbcopy(hp->addr, hp->origaddr, hp->len); + ddi_dmareq_mapout(hp->mapaddr, hp->len, hp->map_flags, + hp->map_pp, hp->map_pplist); + if (bofi_sync_check && hp->allocaddr) + ddi_umem_free(hp->umem_cookie); + kmem_free(hp, sizeof (struct bofi_shadow)); + return (retval); + case DDI_DMA_MOVWIN: + mp = (ddi_dma_impl_t *)handle; + mp->dmai_rflags &= ~DMP_NOSYNC; + break; + case DDI_DMA_NEXTWIN: + mp = (ddi_dma_impl_t *)handle; + mp->dmai_rflags &= ~DMP_NOSYNC; + break; default: break; } diff --git a/usr/src/uts/common/io/fcoe/fcoe.c b/usr/src/uts/common/io/fcoe/fcoe.c index f2550c3008..5c58dfb01c 100644 --- a/usr/src/uts/common/io/fcoe/fcoe.c +++ b/usr/src/uts/common/io/fcoe/fcoe.c @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * The following notice accompanied the original version of this file: @@ -159,7 +156,7 @@ static struct bus_ops fcoe_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ i_ddi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/common/io/fdc.c b/usr/src/uts/common/io/fdc.c index fdfc73a4fa..444b6b46e5 100644 --- a/usr/src/uts/common/io/fdc.c +++ b/usr/src/uts/common/io/fdc.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* @@ -217,7 +214,7 @@ struct bus_ops fdc_bus_ops = { 0, /* int (*bus_add_intrspec)(); */ 0, /* void (*bus_remove_intrspec)(); */ i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/fibre-channel/impl/fctl.c b/usr/src/uts/common/io/fibre-channel/impl/fctl.c index 634de6c6dd..747df29d08 100644 --- a/usr/src/uts/common/io/fibre-channel/impl/fctl.c +++ b/usr/src/uts/common/io/fibre-channel/impl/fctl.c @@ -21,11 +21,7 @@ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. - */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ -/* + * * Fibre channel Transport Library (fctl) * * Function naming conventions: @@ -176,7 +172,7 @@ static struct bus_ops fctl_fca_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ i_ddi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/common/io/pci-ide/pci-ide.c b/usr/src/uts/common/io/pci-ide/pci-ide.c index 7afa702ca4..c885fed6a0 100644 --- a/usr/src/uts/common/io/pci-ide/pci-ide.c +++ b/usr/src/uts/common/io/pci-ide/pci-ide.c @@ -21,9 +21,7 @@ /* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ + /* * PCI-IDE bus nexus driver @@ -131,7 +129,7 @@ struct bus_ops pciide_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/pciex/pcieb.c b/usr/src/uts/common/io/pciex/pcieb.c index e01f132156..0aba544755 100644 --- a/usr/src/uts/common/io/pciex/pcieb.c +++ b/usr/src/uts/common/io/pciex/pcieb.c @@ -21,9 +21,6 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * Common x86 and SPARC PCI-E to PCI bus bridge nexus driver @@ -99,7 +96,7 @@ static struct bus_ops pcieb_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, pcieb_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/pshot.c b/usr/src/uts/common/io/pshot.c index bc5c328d6b..a1d69ea9ae 100644 --- a/usr/src/uts/common/io/pshot.c +++ b/usr/src/uts/common/io/pshot.c @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * pseudo bus nexus driver @@ -308,7 +305,7 @@ static struct bus_ops pshot_bus_ops = { NULL, /* bus_add_interspec */ NULL, /* bus_remove_interspec */ i_ddi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/common/io/scsi/impl/scsi_hba.c b/usr/src/uts/common/io/scsi/impl/scsi_hba.c index 252bd5316e..6d9c00840f 100644 --- a/usr/src/uts/common/io/scsi/impl/scsi_hba.c +++ b/usr/src/uts/common/io/scsi/impl/scsi_hba.c @@ -21,7 +21,6 @@ /* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #include <sys/note.h> @@ -294,7 +293,7 @@ static struct bus_ops scsi_hba_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ scsi_hba_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/common/io/usb/hwa/hwahc/hwahc.c b/usr/src/uts/common/io/usb/hwa/hwahc/hwahc.c index 9ca1fa0f54..beba53c65f 100644 --- a/usr/src/uts/common/io/usb/hwa/hwahc/hwahc.c +++ b/usr/src/uts/common/io/usb/hwa/hwahc/hwahc.c @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * The Data Transfer Interface driver for Host Wire Adapter device @@ -255,7 +252,7 @@ static struct bus_ops hwahc_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ NULL, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/usb/usb_ia/usb_ia.c b/usr/src/uts/common/io/usb/usb_ia/usb_ia.c index 243b995ed7..579aae37a7 100644 --- a/usr/src/uts/common/io/usb/usb_ia/usb_ia.c +++ b/usr/src/uts/common/io/usb/usb_ia/usb_ia.c @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* @@ -133,7 +130,7 @@ static struct bus_ops usb_ia_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ NULL, /* XXXX bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/usb/usb_mid/usb_mid.c b/usr/src/uts/common/io/usb/usb_mid/usb_mid.c index faacf41a79..7c6b507b72 100644 --- a/usr/src/uts/common/io/usb/usb_mid/usb_mid.c +++ b/usr/src/uts/common/io/usb/usb_mid/usb_mid.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* @@ -145,7 +142,7 @@ static struct bus_ops usb_mid_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ NULL, /* XXXX bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/usb/usba/hubdi.c b/usr/src/uts/common/io/usb/usba/hubdi.c index de454de41c..23ab998f0e 100644 --- a/usr/src/uts/common/io/usb/usba/hubdi.c +++ b/usr/src/uts/common/io/usb/usba/hubdi.c @@ -20,7 +20,6 @@ */ /* * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* @@ -113,7 +112,7 @@ struct bus_ops usba_hubdi_busops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ usba_hubdi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/common/io/warlock/ddi_dki_comm.inc b/usr/src/uts/common/io/warlock/ddi_dki_comm.inc index 75e51bdbbb..4667eddcb0 100644 --- a/usr/src/uts/common/io/warlock/ddi_dki_comm.inc +++ b/usr/src/uts/common/io/warlock/ddi_dki_comm.inc @@ -23,9 +23,7 @@ * All rights reserved. Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ +#pragma ident "%Z%%M% %I% %E% SMI" /* * ddi_dki_comm.inc - Part of a pseudo-kernel to use when analyzing drivers @@ -190,6 +188,22 @@ ddi_dma_setup( } int +ddi_dma_pp_setup( + dev_info_t *a, + struct page *b, + off_t c, + uint_t d, + uint_t e, + int (*fp)(), + caddr_t f, + ddi_dma_lim_t *g, + ddi_dma_handle_t *h) +{ + struct bus_ops *ops; + (*ops->bus_dma_map)(0, 0, 0, 0); +} + +int ddi_dma_mctl(dev_info_t *a, dev_info_t *b, ddi_dma_handle_t c, enum ddi_dma_ctlops d, off_t *e, size_t *f, caddr_t *g, uint_t h) @@ -220,6 +234,35 @@ ddi_dma_coff(ddi_dma_handle_t h, ddi_dma_cookie_t *c, off_t *o) } int +ddi_dma_movwin(ddi_dma_handle_t h, off_t *o, size_t *l, ddi_dma_cookie_t *c) +{ + struct bus_ops *ops; + (*ops->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0); +} + +int +ddi_dma_curwin(ddi_dma_handle_t h, off_t *o, size_t *l) +{ + struct bus_ops *ops; + (*ops->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0); +} + +int +ddi_dma_nextwin(register ddi_dma_handle_t h, ddi_dma_win_t win, + ddi_dma_win_t *nwin) +{ + struct bus_ops *ops; + (*ops->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0); +} + +int +ddi_dma_nextseg(ddi_dma_win_t win, ddi_dma_seg_t seg, ddi_dma_seg_t *nseg) +{ + struct bus_ops *ops; + (*ops->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0); +} + +int ddi_dma_get_error(ddi_dma_handle_t h, uint_t len, caddr_t errblk) { struct bus_ops *ops; diff --git a/usr/src/uts/common/os/devcfg.c b/usr/src/uts/common/os/devcfg.c index d11c6fb7b7..b2f6db6cdd 100644 --- a/usr/src/uts/common/os/devcfg.c +++ b/usr/src/uts/common/os/devcfg.c @@ -20,8 +20,9 @@ */ /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + */ +/* * Copyright 2012 Nexenta Systems, Inc. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #include <sys/note.h> @@ -3184,6 +3185,7 @@ ddi_optimize_dtree(dev_info_t *devi) * Set the unoptimized values */ DEVI(devi)->devi_bus_map_fault = pdevi; + DEVI(devi)->devi_bus_dma_map = pdevi; DEVI(devi)->devi_bus_dma_allochdl = pdevi; DEVI(devi)->devi_bus_dma_freehdl = pdevi; DEVI(devi)->devi_bus_dma_bindhdl = pdevi; @@ -3210,6 +3212,11 @@ ddi_optimize_dtree(dev_info_t *devi) "bus_map_fault"); } + if (ddi_dma_map == b->bus_dma_map) { + DEVI(devi)->devi_bus_dma_map = pdevi->devi_bus_dma_map; + debug_dtree(devi, DEVI(devi)->devi_bus_dma_map, "bus_dma_map"); + } + if (ddi_dma_allochdl == b->bus_dma_allochdl) { DEVI(devi)->devi_bus_dma_allochdl = pdevi->devi_bus_dma_allochdl; diff --git a/usr/src/uts/common/os/sunddi.c b/usr/src/uts/common/os/sunddi.c index 8daea07d18..ee3fa51b95 100644 --- a/usr/src/uts/common/os/sunddi.c +++ b/usr/src/uts/common/os/sunddi.c @@ -21,7 +21,6 @@ /* * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #include <sys/note.h> @@ -737,6 +736,145 @@ static ddi_dma_lim_t standard_limits = { #endif +int +ddi_dma_setup(dev_info_t *dip, struct ddi_dma_req *dmareqp, + ddi_dma_handle_t *handlep) +{ + int (*funcp)() = ddi_dma_map; + struct bus_ops *bop; +#if defined(__sparc) + auto ddi_dma_lim_t dma_lim; + + if (dmareqp->dmar_limits == (ddi_dma_lim_t *)0) { + dma_lim = standard_limits; + } else { + dma_lim = *dmareqp->dmar_limits; + } + dmareqp->dmar_limits = &dma_lim; +#endif +#if defined(__x86) + if (dmareqp->dmar_limits == (ddi_dma_lim_t *)0) + return (DDI_FAILURE); +#endif + + /* + * Handle the case that the requester is both a leaf + * and a nexus driver simultaneously by calling the + * requester's bus_dma_map function directly instead + * of ddi_dma_map. + */ + bop = DEVI(dip)->devi_ops->devo_bus_ops; + if (bop && bop->bus_dma_map) + funcp = bop->bus_dma_map; + return ((*funcp)(dip, dip, dmareqp, handlep)); +} + +int +ddi_dma_addr_setup(dev_info_t *dip, struct as *as, caddr_t addr, size_t len, + uint_t flags, int (*waitfp)(), caddr_t arg, + ddi_dma_lim_t *limits, ddi_dma_handle_t *handlep) +{ + int (*funcp)() = ddi_dma_map; + ddi_dma_lim_t dma_lim; + struct ddi_dma_req dmareq; + struct bus_ops *bop; + + if (len == 0) { + return (DDI_DMA_NOMAPPING); + } + if (limits == (ddi_dma_lim_t *)0) { + dma_lim = standard_limits; + } else { + dma_lim = *limits; + } + dmareq.dmar_limits = &dma_lim; + dmareq.dmar_flags = flags; + dmareq.dmar_fp = waitfp; + dmareq.dmar_arg = arg; + dmareq.dmar_object.dmao_size = len; + dmareq.dmar_object.dmao_type = DMA_OTYP_VADDR; + dmareq.dmar_object.dmao_obj.virt_obj.v_as = as; + dmareq.dmar_object.dmao_obj.virt_obj.v_addr = addr; + dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL; + + /* + * Handle the case that the requester is both a leaf + * and a nexus driver simultaneously by calling the + * requester's bus_dma_map function directly instead + * of ddi_dma_map. + */ + bop = DEVI(dip)->devi_ops->devo_bus_ops; + if (bop && bop->bus_dma_map) + funcp = bop->bus_dma_map; + + return ((*funcp)(dip, dip, &dmareq, handlep)); +} + +int +ddi_dma_buf_setup(dev_info_t *dip, struct buf *bp, uint_t flags, + int (*waitfp)(), caddr_t arg, ddi_dma_lim_t *limits, + ddi_dma_handle_t *handlep) +{ + int (*funcp)() = ddi_dma_map; + ddi_dma_lim_t dma_lim; + struct ddi_dma_req dmareq; + struct bus_ops *bop; + + if (limits == (ddi_dma_lim_t *)0) { + dma_lim = standard_limits; + } else { + dma_lim = *limits; + } + dmareq.dmar_limits = &dma_lim; + dmareq.dmar_flags = flags; + dmareq.dmar_fp = waitfp; + dmareq.dmar_arg = arg; + dmareq.dmar_object.dmao_size = (uint_t)bp->b_bcount; + + if (bp->b_flags & B_PAGEIO) { + dmareq.dmar_object.dmao_type = DMA_OTYP_PAGES; + dmareq.dmar_object.dmao_obj.pp_obj.pp_pp = bp->b_pages; + dmareq.dmar_object.dmao_obj.pp_obj.pp_offset = + (uint_t)(((uintptr_t)bp->b_un.b_addr) & MMU_PAGEOFFSET); + } else { + dmareq.dmar_object.dmao_type = DMA_OTYP_BUFVADDR; + dmareq.dmar_object.dmao_obj.virt_obj.v_addr = bp->b_un.b_addr; + if (bp->b_flags & B_SHADOW) { + dmareq.dmar_object.dmao_obj.virt_obj.v_priv = + bp->b_shadow; + } else { + dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL; + } + + /* + * If the buffer has no proc pointer, or the proc + * struct has the kernel address space, or the buffer has + * been marked B_REMAPPED (meaning that it is now + * mapped into the kernel's address space), then + * the address space is kas (kernel address space). + */ + if ((bp->b_proc == NULL) || (bp->b_proc->p_as == &kas) || + (bp->b_flags & B_REMAPPED)) { + dmareq.dmar_object.dmao_obj.virt_obj.v_as = 0; + } else { + dmareq.dmar_object.dmao_obj.virt_obj.v_as = + bp->b_proc->p_as; + } + } + + /* + * Handle the case that the requester is both a leaf + * and a nexus driver simultaneously by calling the + * requester's bus_dma_map function directly instead + * of ddi_dma_map. + */ + bop = DEVI(dip)->devi_ops->devo_bus_ops; + if (bop && bop->bus_dma_map) + funcp = bop->bus_dma_map; + + return ((*funcp)(dip, dip, &dmareq, handlep)); +} + #if !defined(__sparc) /* * Request bus_dma_ctl parent to fiddle with a dma request. @@ -770,18 +908,79 @@ ddi_dma_mctl(dev_info_t *dip, dev_info_t *rdip, #define HD ((ddi_dma_impl_t *)h)->dmai_rdip +int +ddi_dma_kvaddrp(ddi_dma_handle_t h, off_t off, size_t len, caddr_t *kp) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_KVADDR, &off, &len, kp, 0)); +} + +int +ddi_dma_htoc(ddi_dma_handle_t h, off_t o, ddi_dma_cookie_t *c) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_HTOC, &o, 0, (caddr_t *)c, 0)); +} + +int +ddi_dma_coff(ddi_dma_handle_t h, ddi_dma_cookie_t *c, off_t *o) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_COFF, + (off_t *)c, 0, (caddr_t *)o, 0)); +} + +int +ddi_dma_movwin(ddi_dma_handle_t h, off_t *o, size_t *l, ddi_dma_cookie_t *c) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_MOVWIN, o, + l, (caddr_t *)c, 0)); +} + +int +ddi_dma_curwin(ddi_dma_handle_t h, off_t *o, size_t *l) +{ + if ((((ddi_dma_impl_t *)h)->dmai_rflags & DDI_DMA_PARTIAL) == 0) + return (DDI_FAILURE); + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_REPWIN, o, l, 0, 0)); +} + +int +ddi_dma_nextwin(ddi_dma_handle_t h, ddi_dma_win_t win, + ddi_dma_win_t *nwin) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_NEXTWIN, (off_t *)&win, 0, + (caddr_t *)nwin, 0)); +} + +int +ddi_dma_nextseg(ddi_dma_win_t win, ddi_dma_seg_t seg, ddi_dma_seg_t *nseg) +{ + ddi_dma_handle_t h = (ddi_dma_handle_t)win; + + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_NEXTSEG, (off_t *)&win, + (size_t *)&seg, (caddr_t *)nseg, 0)); +} + +#if (defined(__i386) && !defined(__amd64)) || defined(__sparc) /* - * This routine is left in place to satisfy link dependencies - * for any 3rd party nexus drivers that rely on it. It is never - * called, though. + * This routine is Obsolete and should be removed from ALL architectures + * in a future release of Solaris. + * + * It is deliberately NOT ported to amd64; please fix the code that + * depends on this routine to use ddi_dma_nextcookie(9F). + * + * NOTE: even though we fixed the pointer through a 32-bit param issue (the fix + * is a side effect to some other cleanup), we're still not going to support + * this interface on x64. */ -/*ARGSUSED*/ int -ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, - struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep) +ddi_dma_segtocookie(ddi_dma_seg_t seg, off_t *o, off_t *l, + ddi_dma_cookie_t *cookiep) { - return (DDI_FAILURE); + ddi_dma_handle_t h = (ddi_dma_handle_t)seg; + + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_SEGTOC, o, (size_t *)l, + (caddr_t *)cookiep, 0)); } +#endif /* (__i386 && !__amd64) || __sparc */ #if !defined(__sparc) @@ -791,6 +990,20 @@ ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, */ int +ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep) +{ + int (*funcp)(dev_info_t *, dev_info_t *, struct ddi_dma_req *, + ddi_dma_handle_t *); + + if (dip != ddi_root_node()) + dip = (dev_info_t *)DEVI(dip)->devi_bus_dma_map; + + funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_map; + return ((*funcp)(dip, rdip, dmareqp, handlep)); +} + +int ddi_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) { @@ -916,9 +1129,66 @@ ddi_dma_unbind_handle(ddi_dma_handle_t h) #endif /* !__sparc */ +int +ddi_dma_free(ddi_dma_handle_t h) +{ + return (ddi_dma_mctl(HD, HD, h, DDI_DMA_FREE, 0, 0, 0, 0)); +} + +int +ddi_iopb_alloc(dev_info_t *dip, ddi_dma_lim_t *limp, uint_t len, caddr_t *iopbp) +{ + ddi_dma_lim_t defalt; + size_t size = len; + + if (!limp) { + defalt = standard_limits; + limp = &defalt; + } + return (i_ddi_mem_alloc_lim(dip, limp, size, 0, 0, 0, + iopbp, NULL, NULL)); +} + +void +ddi_iopb_free(caddr_t iopb) +{ + i_ddi_mem_free(iopb, NULL); +} + +int +ddi_mem_alloc(dev_info_t *dip, ddi_dma_lim_t *limits, uint_t length, + uint_t flags, caddr_t *kaddrp, uint_t *real_length) +{ + ddi_dma_lim_t defalt; + size_t size = length; + + if (!limits) { + defalt = standard_limits; + limits = &defalt; + } + return (i_ddi_mem_alloc_lim(dip, limits, size, flags & 0x1, + 1, 0, kaddrp, real_length, NULL)); +} + +void +ddi_mem_free(caddr_t kaddr) +{ + i_ddi_mem_free(kaddr, NULL); +} + /* - * DMA burst sizes, and transfer minimums + * DMA attributes, alignment, burst sizes, and transfer minimums */ +int +ddi_dma_get_attr(ddi_dma_handle_t handle, ddi_dma_attr_t *attrp) +{ + ddi_dma_impl_t *dimp = (ddi_dma_impl_t *)handle; + + if (attrp == NULL) + return (DDI_FAILURE); + *attrp = dimp->dmai_attr; + return (DDI_SUCCESS); +} int ddi_dma_burstsizes(ddi_dma_handle_t handle) @@ -932,6 +1202,26 @@ ddi_dma_burstsizes(ddi_dma_handle_t handle) } int +ddi_dma_devalign(ddi_dma_handle_t handle, uint_t *alignment, uint_t *mineffect) +{ + ddi_dma_impl_t *dimp = (ddi_dma_impl_t *)handle; + + if (!dimp || !alignment || !mineffect) + return (DDI_FAILURE); + if (!(dimp->dmai_rflags & DDI_DMA_SBUS_64BIT)) { + *alignment = 1 << ddi_ffs(dimp->dmai_burstsizes); + } else { + if (dimp->dmai_burstsizes & 0xff0000) { + *alignment = 1 << ddi_ffs(dimp->dmai_burstsizes >> 16); + } else { + *alignment = 1 << ddi_ffs(dimp->dmai_burstsizes); + } + } + *mineffect = dimp->dmai_minxfer; + return (DDI_SUCCESS); +} + +int ddi_iomin(dev_info_t *a, int i, int stream) { int r; diff --git a/usr/src/uts/common/sys/ddi_impldefs.h b/usr/src/uts/common/sys/ddi_impldefs.h index 3380c6b314..0699d1cbce 100644 --- a/usr/src/uts/common/sys/ddi_impldefs.h +++ b/usr/src/uts/common/sys/ddi_impldefs.h @@ -20,7 +20,6 @@ */ /* * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #ifndef _SYS_DDI_IMPLDEFS_H @@ -161,6 +160,7 @@ struct dev_info { /* logical parents for busop primitives */ struct dev_info *devi_bus_map_fault; /* bus_map_fault parent */ + struct dev_info *devi_bus_dma_map; /* bus_dma_map parent */ struct dev_info *devi_bus_dma_allochdl; /* bus_dma_newhdl parent */ struct dev_info *devi_bus_dma_freehdl; /* bus_dma_freehdl parent */ struct dev_info *devi_bus_dma_bindhdl; /* bus_dma_bindhdl parent */ diff --git a/usr/src/uts/common/sys/ddi_implfuncs.h b/usr/src/uts/common/sys/ddi_implfuncs.h index 23413cffef..d095aff6f8 100644 --- a/usr/src/uts/common/sys/ddi_implfuncs.h +++ b/usr/src/uts/common/sys/ddi_implfuncs.h @@ -23,9 +23,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #ifndef _SYS_DDI_IMPLFUNCS_H #define _SYS_DDI_IMPLFUNCS_H @@ -77,6 +74,12 @@ i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attributes, ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, size_t *real_length, ddi_acc_hdl_t *handlep); +int +i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, + size_t length, int cansleep, int streaming, + ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, + uint_t *real_length, ddi_acc_hdl_t *handlep); + void i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap); diff --git a/usr/src/uts/common/sys/ddi_obsolete.h b/usr/src/uts/common/sys/ddi_obsolete.h index 7123b47af2..f93d89fb7e 100644 --- a/usr/src/uts/common/sys/ddi_obsolete.h +++ b/usr/src/uts/common/sys/ddi_obsolete.h @@ -2,9 +2,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #ifndef _SYS_DDI_OBSOLETE_H #define _SYS_DDI_OBSOLETE_H @@ -36,9 +33,38 @@ int ddi_iomin(dev_info_t *dip, int initial, int streaming); extern long strtol(const char *, char **, int); extern unsigned long strtoul(const char *, char **, int); -/* we'd really like to remove this; unbundled nexus drivers might have it */ -int ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, - struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep); +int ddi_dma_setup(dev_info_t *dip, struct ddi_dma_req *dmareqp, + ddi_dma_handle_t *handlep); +int ddi_dma_addr_setup(dev_info_t *dip, struct as *as, caddr_t addr, size_t len, + uint_t flags, int (*waitfp)(), caddr_t arg, ddi_dma_lim_t *limits, + ddi_dma_handle_t *handlep); +int ddi_dma_buf_setup(dev_info_t *dip, struct buf *bp, uint_t flags, + int (*waitfp)(), caddr_t arg, ddi_dma_lim_t *limits, + ddi_dma_handle_t *handlep); +int ddi_dma_kvaddrp(ddi_dma_handle_t, off_t, size_t, caddr_t *); +int ddi_dma_htoc(ddi_dma_handle_t handle, off_t off, ddi_dma_cookie_t *cookiep); +int ddi_dma_coff(ddi_dma_handle_t handle, ddi_dma_cookie_t *cookiep, + off_t *offp); +int ddi_dma_curwin(ddi_dma_handle_t handle, off_t *offp, size_t *lenp); +int ddi_dma_nextwin(ddi_dma_handle_t, ddi_dma_win_t, ddi_dma_win_t *); +int ddi_dma_nextseg(ddi_dma_win_t, ddi_dma_seg_t, ddi_dma_seg_t *); +int ddi_dma_segtocookie(ddi_dma_seg_t, off_t *, off_t *, ddi_dma_cookie_t *); +int ddi_dma_free(ddi_dma_handle_t handle); +int ddi_iopb_alloc(dev_info_t *dip, ddi_dma_lim_t *limits, uint_t length, + caddr_t *iopbp); +void ddi_iopb_free(caddr_t iopb); +int ddi_mem_alloc(dev_info_t *dip, ddi_dma_lim_t *limits, uint_t length, + uint_t flags, caddr_t *kaddrp, uint_t *real_length); +void ddi_mem_free(caddr_t kaddr); +int ddi_dma_get_attr(ddi_dma_handle_t handle, ddi_dma_attr_t *attrp); +int ddi_dma_devalign(ddi_dma_handle_t handle, uint_t *alignment, + uint_t *mineffect); +void ddi_dmalim_merge(ddi_dma_lim_t *limit, ddi_dma_lim_t *modifier); + +#if defined(__sparc) +int ddi_dma_movwin(ddi_dma_handle_t, off_t *offp, size_t *lenp, + ddi_dma_cookie_t *); +#endif uint8_t ddi_mem_get8(ddi_acc_handle_t handle, uint8_t *host_addr); uint16_t ddi_mem_get16(ddi_acc_handle_t handle, uint16_t *host_addr); diff --git a/usr/src/uts/common/sys/ddidmareq.h b/usr/src/uts/common/sys/ddidmareq.h index e7b2b5f30f..aac53a6555 100644 --- a/usr/src/uts/common/sys/ddidmareq.h +++ b/usr/src/uts/common/sys/ddidmareq.h @@ -21,9 +21,6 @@ /* * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #ifndef _SYS_DDIDMAREQ_H #define _SYS_DDIDMAREQ_H @@ -715,21 +712,21 @@ typedef struct ddi_dma_req { */ enum ddi_dma_ctlops { - DDI_DMA_FREE, /* obsolete - do not use */ - DDI_DMA_SYNC, /* obsolete - do not use */ - DDI_DMA_HTOC, /* obsolete - do not use */ - DDI_DMA_KVADDR, /* obsolete - do not use */ - DDI_DMA_MOVWIN, /* obsolete - do not use */ - DDI_DMA_REPWIN, /* obsolete - do not use */ - DDI_DMA_GETERR, /* obsolete - do not use */ - DDI_DMA_COFF, /* obsolete - do not use */ - DDI_DMA_NEXTWIN, /* obsolete - do not use */ - DDI_DMA_NEXTSEG, /* obsolete - do not use */ - DDI_DMA_SEGTOC, /* obsolete - do not use */ + DDI_DMA_FREE, /* free reference to object */ + DDI_DMA_SYNC, /* synchronize cache references */ + DDI_DMA_HTOC, /* return DMA cookie for handle */ + DDI_DMA_KVADDR, /* return kernel virtual address */ + DDI_DMA_MOVWIN, /* change mapped DMA window on object */ + DDI_DMA_REPWIN, /* report current window on DMA object */ + DDI_DMA_GETERR, /* report any post-transfer DMA errors */ + DDI_DMA_COFF, /* convert a DMA cookie to an offset */ + DDI_DMA_NEXTWIN, /* get next window within object */ + DDI_DMA_NEXTSEG, /* get next segment within window */ + DDI_DMA_SEGTOC, /* return segment DMA cookie */ DDI_DMA_RESERVE, /* reserve some DVMA range */ DDI_DMA_RELEASE, /* free preallocated DVMA range */ - DDI_DMA_RESETH, /* obsolete - do not use */ - DDI_DMA_CKSYNC, /* obsolete - do not use */ + DDI_DMA_RESETH, /* reset next cookie ptr in handle */ + DDI_DMA_CKSYNC, /* sync intermediate buffer to cookies */ DDI_DMA_IOPB_ALLOC, /* get contiguous DMA-able memory */ DDI_DMA_IOPB_FREE, /* return contiguous DMA-able memory */ DDI_DMA_SMEM_ALLOC, /* get contiguous DMA-able memory */ diff --git a/usr/src/uts/common/sys/devops.h b/usr/src/uts/common/sys/devops.h index 9e2bf1f7cc..6efcdcc257 100644 --- a/usr/src/uts/common/sys/devops.h +++ b/usr/src/uts/common/sys/devops.h @@ -22,9 +22,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #ifndef _SYS_DEVOPS_H #define _SYS_DEVOPS_H @@ -77,12 +74,10 @@ extern "C" { * c XXwrite DDI/DKI * c XXioctl DDI/DKI * c XXdevmap DDI(Sun) - * c XXmmap DKI(Obsolete) + * c XXmmap DKI * c XXsegmap DKI * c XXchpoll DDI/DKI * c XXprop_op DDI(Sun) - * c XXaread DDI(Sun) - * c XXawrite DDI(Sun) */ struct cb_ops { @@ -134,33 +129,14 @@ struct cb_ops { * they will be called from outside the ddi. * * bus_map - Map/unmap/control IU -> device mappings. - * bus_get_intrspec - obsolete, not called - * bus_add_intrspec - obsolete, not called - * bus_remove_intrspec - obsolete, not called + * bus_get_intrspec - get interrupt specification by number + * bus_add_intrspec - add interrupt specification, return cookie + * bus_remove_intrspec - remove interrupt specification * bus_map_fault - bus fault handler - * bus_dma_map - obsolete, not called - * bus_dma_allochdl - allocate a DMA handle - * bus_dma_freehdl - free a DMA handle - * bus_dma_bindhdl - bind a DMA handle to physical mapping - * bus_dma_unbindhdl - unbind a DMA handle to physical mapping - * bus_dma_flush - flush DMA caches - * bus_dma_win - access DMA windows - * bus_dma_ctl - control dma mapping (legacy use only) + * bus_dma_map - setup dma mapping + * bus_dma_mapctl - control (and free) dma mapping * bus_ctl - generic control operations - * bus_prop_op - request for property - * bus_get_eventcookie - get an event cookie - * bus_add_eventcall - event call management - * bus_remove_eventcall - event call management - * bus_post_event - post an event - * bus_config - child node configuration - * bus_unconfig - child node unconfiguration - * bus_fm_init - FMA support - * bus_fm_fini - FMA support - * bus_fm_access_enter - FMA support - * bus_fm_access_exit - FMA support - * bus_power - power management - * bus_intr_op - control interrupt mappings - * bus_hp_op - hotplug support + * bus_prop_op _ request for property */ #define BUSO_REV_3 3 diff --git a/usr/src/uts/common/sys/dma_engine.h b/usr/src/uts/common/sys/dma_engine.h index 80f75ec8ef..7e3e492e8e 100644 --- a/usr/src/uts/common/sys/dma_engine.h +++ b/usr/src/uts/common/sys/dma_engine.h @@ -19,11 +19,6 @@ * * CDDL HEADER END */ - -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ - /* * Copyright 1998 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -39,6 +34,8 @@ #ifndef _SYS_DMAENGINE_H #define _SYS_DMAENGINE_H +#pragma ident "%Z%%M% %I% %E% SMI" + #include <sys/types.h> #include <sys/dditypes.h> @@ -235,8 +232,9 @@ int ddi_dmae_1stparty(dev_info_t *dip, int chnl); * ddi_dmae_prog() can have dmaereqp set to NULL if only the address and * count have to be updated. * - * cookiep - pointer to a ddi_dma_cookie object which contains address, - * count and intermediate memory mapping information. + * cookiep - pointer to a ddi_dma_cookie object obtained from + * ddi_dma_segtocookie(), which contains address, count and intermediate + * memory mapping information. */ int ddi_dmae_prog(dev_info_t *dip, struct ddi_dmae_req *dmaereqp, diff --git a/usr/src/uts/common/sys/sunddi.h b/usr/src/uts/common/sys/sunddi.h index 1eaf3a4feb..26cafb882f 100644 --- a/usr/src/uts/common/sys/sunddi.h +++ b/usr/src/uts/common/sys/sunddi.h @@ -21,7 +21,6 @@ /* * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #ifndef _SYS_SUNDDI_H @@ -1736,6 +1735,10 @@ ddi_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t o, void *a, void *v); */ int +ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep); + +int ddi_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep); diff --git a/usr/src/uts/common/xen/io/xpvd.c b/usr/src/uts/common/xen/io/xpvd.c index 7c655becbf..b122e03fc1 100644 --- a/usr/src/uts/common/xen/io/xpvd.c +++ b/usr/src/uts/common/xen/io/xpvd.c @@ -23,9 +23,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * Host to hypervisor virtual devices nexus driver @@ -126,7 +123,7 @@ struct bus_ops xpvd_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/i86pc/io/acpi/acpinex/acpinex_drv.c b/usr/src/uts/i86pc/io/acpi/acpinex/acpinex_drv.c index 7cf06ba394..35fb4b6af5 100644 --- a/usr/src/uts/i86pc/io/acpi/acpinex/acpinex_drv.c +++ b/usr/src/uts/i86pc/io/acpi/acpinex/acpinex_drv.c @@ -28,9 +28,6 @@ * All rights reserved. */ /* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ -/* * This module implements a nexus driver for the ACPI virtual bus. * It does not handle any of the DDI functions passed up to it by the child * drivers, but instead allows them to bubble up to the root node. @@ -90,7 +87,7 @@ static struct bus_ops acpinex_bus_ops = { NULL, /* bus_add_intrspec */ NULL, /* bus_remove_intrspec */ i_ddi_map_fault, /* bus_map_fault */ - NULL, /* bus_dma_map */ + ddi_dma_map, /* bus_dma_map */ ddi_dma_allochdl, /* bus_dma_allochdl */ ddi_dma_freehdl, /* bus_dma_freehdl */ ddi_dma_bindhdl, /* bus_dma_bindhdl */ diff --git a/usr/src/uts/i86pc/io/amd_iommu/amd_iommu_impl.c b/usr/src/uts/i86pc/io/amd_iommu/amd_iommu_impl.c index b5ab7d9cf6..59c004458b 100644 --- a/usr/src/uts/i86pc/io/amd_iommu/amd_iommu_impl.c +++ b/usr/src/uts/i86pc/io/amd_iommu/amd_iommu_impl.c @@ -21,7 +21,6 @@ /* * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #include <sys/sunddi.h> @@ -64,6 +63,13 @@ static int amd_iommu_mapobject(iommulib_handle_t handle, dev_info_t *dip, struct ddi_dma_req *dmareq, ddi_dma_obj_t *dmao); static int amd_iommu_unmapobject(iommulib_handle_t handle, dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, ddi_dma_obj_t *dmao); +static int amd_iommu_map(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, struct ddi_dma_req *dmareq, + ddi_dma_handle_t *dma_handle); +static int amd_iommu_mctl(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, ddi_dma_handle_t dma_handle, + enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, + caddr_t *objpp, uint_t cache_flags); static int unmap_current_window(amd_iommu_t *iommu, dev_info_t *rdip, ddi_dma_cookie_t *cookie_array, uint_t ccount, int ncookies, int locked); @@ -106,6 +112,8 @@ struct iommulib_ops amd_iommulib_ops = { amd_iommu_win, amd_iommu_mapobject, amd_iommu_unmapobject, + amd_iommu_map, + amd_iommu_mctl }; static kmutex_t amd_iommu_pgtable_lock; @@ -1888,6 +1896,30 @@ out: return (error); } +/* Obsoleted DMA routines */ + +/*ARGSUSED*/ +static int +amd_iommu_map(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, struct ddi_dma_req *dmareq, + ddi_dma_handle_t *dma_handle) +{ + ASSERT(0); + return (iommulib_iommu_dma_map(dip, rdip, dmareq, dma_handle)); +} + +/*ARGSUSED*/ +static int +amd_iommu_mctl(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, ddi_dma_handle_t dma_handle, + enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, + caddr_t *objpp, uint_t cache_flags) +{ + ASSERT(0); + return (iommulib_iommu_dma_mctl(dip, rdip, dma_handle, + request, offp, lenp, objpp, cache_flags)); +} + /*ARGSUSED*/ static int amd_iommu_mapobject(iommulib_handle_t handle, dev_info_t *dip, diff --git a/usr/src/uts/i86pc/io/immu_dvma.c b/usr/src/uts/i86pc/io/immu_dvma.c index efc30c3d64..4dfa9c05b4 100644 --- a/usr/src/uts/i86pc/io/immu_dvma.c +++ b/usr/src/uts/i86pc/io/immu_dvma.c @@ -26,9 +26,6 @@ * Copyright (c) 2009, Intel Corporation. * All rights reserved. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * DVMA code @@ -108,6 +105,13 @@ static int immu_mapobject(iommulib_handle_t handle, dev_info_t *dip, struct ddi_dma_req *dmareq, ddi_dma_obj_t *dmao); static int immu_unmapobject(iommulib_handle_t handle, dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, ddi_dma_obj_t *dmao); +static int immu_map(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, struct ddi_dma_req *dmareq, + ddi_dma_handle_t *dma_handle); +static int immu_mctl(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, ddi_dma_handle_t dma_handle, + enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, + caddr_t *objpp, uint_t cachefl); /* static Globals */ @@ -150,6 +154,8 @@ struct iommulib_ops immulib_ops = { immu_win, immu_mapobject, immu_unmapobject, + immu_map, + immu_mctl }; /* @@ -3177,3 +3183,24 @@ immu_unmapobject(iommulib_handle_t handle, dev_info_t *dip, return (DDI_SUCCESS); return (immu_unmap_dvmaseg(rdip, dmao)); } + +/*ARGSUSED*/ +static int +immu_map(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, struct ddi_dma_req *dmareq, + ddi_dma_handle_t *dma_handle) +{ + ASSERT(0); + return (DDI_FAILURE); +} + +/*ARGSUSED*/ +static int +immu_mctl(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, ddi_dma_handle_t dma_handle, + enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, + caddr_t *objpp, uint_t cachefl) +{ + ASSERT(0); + return (DDI_FAILURE); +} diff --git a/usr/src/uts/i86pc/io/isa.c b/usr/src/uts/i86pc/io/isa.c index b94cc6fbb4..d2bb59ca99 100644 --- a/usr/src/uts/i86pc/io/isa.c +++ b/usr/src/uts/i86pc/io/isa.c @@ -20,7 +20,6 @@ */ /* * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* @@ -169,7 +168,7 @@ struct bus_ops isa_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, isa_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/i86pc/io/pci/pci.c b/usr/src/uts/i86pc/io/pci/pci.c index b67b466cd1..d3e4148b40 100644 --- a/usr/src/uts/i86pc/io/pci/pci.c +++ b/usr/src/uts/i86pc/io/pci/pci.c @@ -22,9 +22,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * Host to PCI local bus driver @@ -66,7 +63,7 @@ struct bus_ops pci_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/i86pc/io/pciex/npe.c b/usr/src/uts/i86pc/io/pciex/npe.c index a0728cb7e2..0342d7caf2 100644 --- a/usr/src/uts/i86pc/io/pciex/npe.c +++ b/usr/src/uts/i86pc/io/pciex/npe.c @@ -25,10 +25,6 @@ */ /* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ - -/* * Host to PCI-Express local bus driver */ @@ -91,7 +87,7 @@ struct bus_ops npe_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/i86pc/io/rootnex.c b/usr/src/uts/i86pc/io/rootnex.c index 10b7fcb84b..ab2ffb503e 100644 --- a/usr/src/uts/i86pc/io/rootnex.c +++ b/usr/src/uts/i86pc/io/rootnex.c @@ -24,7 +24,6 @@ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2011 Bayard G. Bell. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* @@ -195,6 +194,8 @@ static int rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, static int rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip, struct hat *hat, struct seg *seg, caddr_t addr, struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock); +static int rootnex_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep); static int rootnex_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep); @@ -265,7 +266,7 @@ static struct bus_ops rootnex_bus_ops = { NULL, NULL, rootnex_map_fault, - 0, + rootnex_dma_map, rootnex_dma_allochdl, rootnex_dma_freehdl, rootnex_dma_bindhdl, @@ -337,6 +338,8 @@ static iommulib_nexops_t iommulib_nexops = { rootnex_coredma_get_sleep_flags, rootnex_coredma_sync, rootnex_coredma_win, + rootnex_dma_map, + rootnex_dma_mctl, rootnex_coredma_hdl_setprivate, rootnex_coredma_hdl_getprivate }; @@ -5000,9 +5003,91 @@ rootnex_coredma_hdl_getprivate(dev_info_t *dip, dev_info_t *rdip, */ /* + * rootnex_dma_map() + * called from ddi_dma_setup() + * NO IOMMU in 32 bit mode. The below routines doesn't work in 64 bit mode. + */ +/* ARGSUSED */ +static int +rootnex_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep) +{ +#if defined(__amd64) + /* + * this interface is not supported in 64-bit x86 kernel. See comment in + * rootnex_dma_mctl() + */ + return (DDI_DMA_NORESOURCES); + +#else /* 32-bit x86 kernel */ + ddi_dma_handle_t *lhandlep; + ddi_dma_handle_t lhandle; + ddi_dma_cookie_t cookie; + ddi_dma_attr_t dma_attr; + ddi_dma_lim_t *dma_lim; + uint_t ccnt; + int e; + + + /* + * if the driver is just testing to see if it's possible to do the bind, + * we'll use local state. Otherwise, use the handle pointer passed in. + */ + if (handlep == NULL) { + lhandlep = &lhandle; + } else { + lhandlep = handlep; + } + + /* convert the limit structure to a dma_attr one */ + dma_lim = dmareq->dmar_limits; + dma_attr.dma_attr_version = DMA_ATTR_V0; + dma_attr.dma_attr_addr_lo = dma_lim->dlim_addr_lo; + dma_attr.dma_attr_addr_hi = dma_lim->dlim_addr_hi; + dma_attr.dma_attr_minxfer = dma_lim->dlim_minxfer; + dma_attr.dma_attr_seg = dma_lim->dlim_adreg_max; + dma_attr.dma_attr_count_max = dma_lim->dlim_ctreg_max; + dma_attr.dma_attr_granular = dma_lim->dlim_granular; + dma_attr.dma_attr_sgllen = dma_lim->dlim_sgllen; + dma_attr.dma_attr_maxxfer = dma_lim->dlim_reqsize; + dma_attr.dma_attr_burstsizes = dma_lim->dlim_burstsizes; + dma_attr.dma_attr_align = MMU_PAGESIZE; + dma_attr.dma_attr_flags = 0; + + e = rootnex_dma_allochdl(dip, rdip, &dma_attr, dmareq->dmar_fp, + dmareq->dmar_arg, lhandlep); + if (e != DDI_SUCCESS) { + return (e); + } + + e = rootnex_dma_bindhdl(dip, rdip, *lhandlep, dmareq, &cookie, &ccnt); + if ((e != DDI_DMA_MAPPED) && (e != DDI_DMA_PARTIAL_MAP)) { + (void) rootnex_dma_freehdl(dip, rdip, *lhandlep); + return (e); + } + + /* + * if the driver is just testing to see if it's possible to do the bind, + * free up the local state and return the result. + */ + if (handlep == NULL) { + (void) rootnex_dma_unbindhdl(dip, rdip, *lhandlep); + (void) rootnex_dma_freehdl(dip, rdip, *lhandlep); + if (e == DDI_DMA_MAPPED) { + return (DDI_DMA_MAPOK); + } else { + return (DDI_DMA_NOMAPPING); + } + } + + return (e); +#endif /* defined(__amd64) */ +} + +/* * rootnex_dma_mctl() * - * We don't support this legacy interface any more on x86. + * No IOMMU in 32 bit mode. The below routine doesn't work in 64 bit mode. */ /* ARGSUSED */ static int @@ -5010,11 +5095,185 @@ rootnex_dma_mctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, caddr_t *objpp, uint_t cache_flags) { +#if defined(__amd64) + /* + * DDI_DMA_SMEM_ALLOC & DDI_DMA_IOPB_ALLOC we're changed to have a + * common implementation in genunix, so they no longer have x86 + * specific functionality which called into dma_ctl. + * + * The rest of the obsoleted interfaces were never supported in the + * 64-bit x86 kernel. For s10, the obsoleted DDI_DMA_SEGTOC interface + * was not ported to the x86 64-bit kernel do to serious x86 rootnex + * implementation issues. + * + * If you can't use DDI_DMA_SEGTOC; DDI_DMA_NEXTSEG, DDI_DMA_FREE, and + * DDI_DMA_NEXTWIN are useless since you can get to the cookie, so we + * reflect that now too... + * + * Even though we fixed the pointer problem in DDI_DMA_SEGTOC, we are + * not going to put this functionality into the 64-bit x86 kernel now. + * It wasn't ported to the 64-bit kernel for s10, no reason to change + * that in a future release. + */ + return (DDI_FAILURE); + +#else /* 32-bit x86 kernel */ + ddi_dma_cookie_t lcookie; + ddi_dma_cookie_t *cookie; + rootnex_window_t *window; + ddi_dma_impl_t *hp; + rootnex_dma_t *dma; + uint_t nwin; + uint_t ccnt; + size_t len; + off_t off; + int e; + + /* - * The only thing dma_mctl is usef for anymore is legacy SPARC - * dvma and sbus-specific routines. + * DDI_DMA_SEGTOC, DDI_DMA_NEXTSEG, and DDI_DMA_NEXTWIN are a little + * hacky since were optimizing for the current interfaces and so we can + * cleanup the mess in genunix. Hopefully we will remove the this + * obsoleted routines someday soon. */ + + switch (request) { + + case DDI_DMA_SEGTOC: /* ddi_dma_segtocookie() */ + hp = (ddi_dma_impl_t *)handle; + cookie = (ddi_dma_cookie_t *)objpp; + + /* + * convert segment to cookie. We don't distinguish between the + * two :-) + */ + *cookie = *hp->dmai_cookie; + *lenp = cookie->dmac_size; + *offp = cookie->dmac_type & ~ROOTNEX_USES_COPYBUF; + return (DDI_SUCCESS); + + case DDI_DMA_NEXTSEG: /* ddi_dma_nextseg() */ + hp = (ddi_dma_impl_t *)handle; + dma = (rootnex_dma_t *)hp->dmai_private; + + if ((*lenp != NULL) && ((uintptr_t)*lenp != (uintptr_t)hp)) { + return (DDI_DMA_STALE); + } + + /* handle the case where we don't have any windows */ + if (dma->dp_window == NULL) { + /* + * if seg == NULL, and we don't have any windows, + * return the first cookie in the sgl. + */ + if (*lenp == NULL) { + dma->dp_current_cookie = 0; + hp->dmai_cookie = dma->dp_cookies; + *objpp = (caddr_t)handle; + return (DDI_SUCCESS); + + /* if we have more cookies, go to the next cookie */ + } else { + if ((dma->dp_current_cookie + 1) >= + dma->dp_sglinfo.si_sgl_size) { + return (DDI_DMA_DONE); + } + dma->dp_current_cookie++; + hp->dmai_cookie++; + return (DDI_SUCCESS); + } + } + + /* We have one or more windows */ + window = &dma->dp_window[dma->dp_current_win]; + + /* + * if seg == NULL, return the first cookie in the current + * window + */ + if (*lenp == NULL) { + dma->dp_current_cookie = 0; + hp->dmai_cookie = window->wd_first_cookie; + + /* + * go to the next cookie in the window then see if we done with + * this window. + */ + } else { + if ((dma->dp_current_cookie + 1) >= + window->wd_cookie_cnt) { + return (DDI_DMA_DONE); + } + dma->dp_current_cookie++; + hp->dmai_cookie++; + } + *objpp = (caddr_t)handle; + return (DDI_SUCCESS); + + case DDI_DMA_NEXTWIN: /* ddi_dma_nextwin() */ + hp = (ddi_dma_impl_t *)handle; + dma = (rootnex_dma_t *)hp->dmai_private; + + if ((*offp != NULL) && ((uintptr_t)*offp != (uintptr_t)hp)) { + return (DDI_DMA_STALE); + } + + /* if win == NULL, return the first window in the bind */ + if (*offp == NULL) { + nwin = 0; + + /* + * else, go to the next window then see if we're done with all + * the windows. + */ + } else { + nwin = dma->dp_current_win + 1; + if (nwin >= hp->dmai_nwin) { + return (DDI_DMA_DONE); + } + } + + /* switch to the next window */ + e = rootnex_dma_win(dip, rdip, handle, nwin, &off, &len, + &lcookie, &ccnt); + ASSERT(e == DDI_SUCCESS); + if (e != DDI_SUCCESS) { + return (DDI_DMA_STALE); + } + + /* reset the cookie back to the first cookie in the window */ + if (dma->dp_window != NULL) { + window = &dma->dp_window[dma->dp_current_win]; + hp->dmai_cookie = window->wd_first_cookie; + } else { + hp->dmai_cookie = dma->dp_cookies; + } + + *objpp = (caddr_t)handle; + return (DDI_SUCCESS); + + case DDI_DMA_FREE: /* ddi_dma_free() */ + (void) rootnex_dma_unbindhdl(dip, rdip, handle); + (void) rootnex_dma_freehdl(dip, rdip, handle); + if (rootnex_state->r_dvma_call_list_id) { + ddi_run_callback(&rootnex_state->r_dvma_call_list_id); + } + return (DDI_SUCCESS); + + case DDI_DMA_IOPB_ALLOC: /* get contiguous DMA-able memory */ + case DDI_DMA_SMEM_ALLOC: /* get contiguous DMA-able memory */ + /* should never get here, handled in genunix */ + ASSERT(0); + return (DDI_FAILURE); + + case DDI_DMA_KVADDR: + case DDI_DMA_GETERR: + case DDI_DMA_COFF: + return (DDI_FAILURE); + } + return (DDI_FAILURE); +#endif /* defined(__amd64) */ } /* diff --git a/usr/src/uts/i86pc/ml/offsets.in b/usr/src/uts/i86pc/ml/offsets.in index d867ade973..20e0c972d4 100644 --- a/usr/src/uts/i86pc/ml/offsets.in +++ b/usr/src/uts/i86pc/ml/offsets.in @@ -1,6 +1,5 @@ \ \ Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. -\ Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. \ \ CDDL HEADER START \ @@ -242,6 +241,7 @@ ddi_dma_impl dev_info devi_ops DEVI_DEV_OPS devi_bus_ctl + devi_bus_dma_map devi_bus_dma_ctl devi_bus_dma_allochdl devi_bus_dma_freehdl diff --git a/usr/src/uts/i86pc/os/ddi_impl.c b/usr/src/uts/i86pc/os/ddi_impl.c index 60347c6168..a1ae318703 100644 --- a/usr/src/uts/i86pc/os/ddi_impl.c +++ b/usr/src/uts/i86pc/os/ddi_impl.c @@ -21,7 +21,6 @@ /* * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* @@ -1713,6 +1712,50 @@ i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, return (DDI_SUCCESS); } +/* + * covert old DMA limits structure to DMA attribute structure + * and continue + */ +int +i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, + size_t length, int cansleep, int streaming, + ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, + uint_t *real_length, ddi_acc_hdl_t *ap) +{ + ddi_dma_attr_t dma_attr, *attrp; + size_t rlen; + int ret; + + if (limits == NULL) { + return (DDI_FAILURE); + } + + /* + * set up DMA attribute structure to pass to i_ddi_mem_alloc() + */ + attrp = &dma_attr; + attrp->dma_attr_version = DMA_ATTR_V0; + attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; + attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; + attrp->dma_attr_count_max = (uint64_t)limits->dlim_ctreg_max; + attrp->dma_attr_align = 1; + attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; + attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; + attrp->dma_attr_maxxfer = (uint64_t)limits->dlim_reqsize; + attrp->dma_attr_seg = (uint64_t)limits->dlim_adreg_max; + attrp->dma_attr_sgllen = limits->dlim_sgllen; + attrp->dma_attr_granular = (uint32_t)limits->dlim_granular; + attrp->dma_attr_flags = 0; + + ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, + accattrp, kaddrp, &rlen, ap); + if (ret == DDI_SUCCESS) { + if (real_length) + *real_length = (uint_t)rlen; + } + return (ret); +} + /* ARGSUSED */ void i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap) diff --git a/usr/src/uts/intel/io/iommulib.c b/usr/src/uts/intel/io/iommulib.c index f3a78bded9..8f36f92894 100644 --- a/usr/src/uts/intel/io/iommulib.c +++ b/usr/src/uts/intel/io/iommulib.c @@ -20,7 +20,6 @@ */ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #pragma ident "@(#)iommulib.c 1.6 08/09/07 SMI" @@ -246,6 +245,21 @@ iommulib_nexus_register(dev_info_t *dip, iommulib_nexops_t *nexops, return (DDI_FAILURE); } + /* Check for legacy ops */ + if (nexops->nops_dma_map == NULL) { + cmn_err(CE_WARN, "%s: %s%d: NULL legacy nops_dma_map op. " + "Failing registration for ops vector: %p", f, + driver, instance, (void *)nexops); + return (DDI_FAILURE); + } + + if (nexops->nops_dma_mctl == NULL) { + cmn_err(CE_WARN, "%s: %s%d: NULL legacy nops_dma_mctl op. " + "Failing registration for ops vector: %p", f, + driver, instance, (void *)nexops); + return (DDI_FAILURE); + } + nexp = kmem_zalloc(sizeof (iommulib_nex_t), KM_SLEEP); mutex_enter(&iommulib_lock); @@ -436,6 +450,21 @@ iommulib_iommu_register(dev_info_t *dip, iommulib_ops_t *ops, return (DDI_FAILURE); } + /* Check for legacy ops */ + if (ops->ilops_dma_map == NULL) { + cmn_err(CE_WARN, "%s: %s%d: NULL legacy dma_map op. " + "Failing registration for ops vector: %p", f, + driver, instance, (void *)ops); + return (DDI_FAILURE); + } + + if (ops->ilops_dma_mctl == NULL) { + cmn_err(CE_WARN, "%s: %s%d: NULL legacy dma_mctl op. " + "Failing registration for ops vector: %p", f, + driver, instance, (void *)ops); + return (DDI_FAILURE); + } + unitp = kmem_zalloc(sizeof (iommulib_unit_t), KM_SLEEP); mutex_enter(&iommulib_lock); if (iommulib_fini == 1) { @@ -728,6 +757,37 @@ iommulib_nexdma_win(dev_info_t *dip, dev_info_t *rdip, win, offp, lenp, cookiep, ccountp)); } +/* Obsolete DMA routines */ + +int +iommulib_nexdma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *dma_handle) +{ + iommulib_handle_t handle = DEVI(rdip)->devi_iommulib_handle; + iommulib_unit_t *unitp = handle; + + ASSERT(unitp); + + /* No need to grab lock - the handle is reference counted */ + return (unitp->ilu_ops->ilops_dma_map(handle, dip, rdip, dmareq, + dma_handle)); +} + +int +iommulib_nexdma_mctl(dev_info_t *dip, dev_info_t *rdip, + ddi_dma_handle_t dma_handle, enum ddi_dma_ctlops request, + off_t *offp, size_t *lenp, caddr_t *objpp, uint_t cache_flags) +{ + iommulib_handle_t handle = DEVI(rdip)->devi_iommulib_handle; + iommulib_unit_t *unitp = (iommulib_unit_t *)handle; + + ASSERT(unitp); + + /* No need to grab lock - the handle is reference counted */ + return (unitp->ilu_ops->ilops_dma_mctl(handle, dip, rdip, dma_handle, + request, offp, lenp, objpp, cache_flags)); +} + int iommulib_nexdma_mapobject(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, struct ddi_dma_req *dmareq, @@ -868,6 +928,28 @@ iommulib_iommu_dma_win(dev_info_t *dip, dev_info_t *rdip, } int +iommulib_iommu_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep) +{ + iommulib_nexops_t *nexops; + + nexops = &DEVI(dip)->devi_iommulib_nex_handle->nex_ops; + return (nexops->nops_dma_map(dip, rdip, dmareq, handlep)); +} + +int +iommulib_iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip, + ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, + size_t *lenp, caddr_t *objpp, uint_t cache_flags) +{ + iommulib_nexops_t *nexops; + + nexops = &DEVI(dip)->devi_iommulib_nex_handle->nex_ops; + return (nexops->nops_dma_mctl(dip, rdip, handle, request, offp, lenp, + objpp, cache_flags)); +} + +int iommulib_iommu_dmahdl_setprivate(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, void *priv) { diff --git a/usr/src/uts/intel/io/pci/pci_pci.c b/usr/src/uts/intel/io/pci/pci_pci.c index 9f0ed4d67f..a0ade1d026 100644 --- a/usr/src/uts/intel/io/pci/pci_pci.c +++ b/usr/src/uts/intel/io/pci/pci_pci.c @@ -22,9 +22,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * PCI to PCI bus bridge nexus driver @@ -96,7 +93,7 @@ struct bus_ops ppb_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/intel/sys/iommulib.h b/usr/src/uts/intel/sys/iommulib.h index 7fb525edec..aa456ac8bb 100644 --- a/usr/src/uts/intel/sys/iommulib.h +++ b/usr/src/uts/intel/sys/iommulib.h @@ -20,12 +20,13 @@ */ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ #ifndef _SYS_IOMMULIB_H #define _SYS_IOMMULIB_H +#pragma ident "@(#)iommulib.h 1.3 08/08/31 SMI" + #ifdef __cplusplus extern "C" { #endif @@ -44,11 +45,10 @@ typedef enum { typedef enum { IOMMU_OPS_VERSION_INVALID = 0, IOMMU_OPS_VERSION_1 = 1, - IOMMU_OPS_VERSION_2 = 2, - IOMMU_OPS_VERSION_3 = 3 + IOMMU_OPS_VERSION_2 = 2 } iommulib_opsversion_t; -#define IOMMU_OPS_VERSION IOMMU_OPS_VERSION_3 +#define IOMMU_OPS_VERSION IOMMU_OPS_VERSION_2 typedef struct iommulib_ops { iommulib_opsversion_t ilops_vers; @@ -90,6 +90,17 @@ typedef struct iommulib_ops { dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, ddi_dma_obj_t *dmao); + /* Obsolete DMA routines */ + + int (*ilops_dma_map)(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, struct ddi_dma_req *dmareq, + ddi_dma_handle_t *dma_handle); + + int (*ilops_dma_mctl)(iommulib_handle_t handle, dev_info_t *dip, + dev_info_t *rdip, ddi_dma_handle_t dma_handle, + enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, + caddr_t *objpp, uint_t cache_flags); + } iommulib_ops_t; /* @@ -119,11 +130,10 @@ typedef struct iommulib_ops { typedef enum { IOMMU_NEXOPS_VERSION_INVALID = 0, IOMMU_NEXOPS_VERSION_1 = 1, - IOMMU_NEXOPS_VERSION_2 = 2, - IOMMU_NEXOPS_VERSION_3 = 3 + IOMMU_NEXOPS_VERSION_2 = 2 } iommulib_nexops_version_t; -#define IOMMU_NEXOPS_VERSION IOMMU_NEXOPS_VERSION_3 +#define IOMMU_NEXOPS_VERSION IOMMU_NEXOPS_VERSION_2 typedef struct iommulib_nexops { iommulib_nexops_version_t nops_vers; @@ -164,6 +174,13 @@ typedef struct iommulib_nexops { ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); + int (*nops_dma_map)(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep); + + int (*nops_dma_mctl)(dev_info_t *dip, dev_info_t *rdip, + ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, + size_t *lenp, caddr_t *objpp, uint_t cache_flags); + int (*nops_dmahdl_setprivate)(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, void *priv); @@ -238,6 +255,13 @@ int iommulib_nexdma_win(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, uint_t win, off_t *offp, size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); +int iommulib_nexdma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *dma_handle); + +int iommulib_nexdma_mctl(dev_info_t *dip, dev_info_t *rdip, + ddi_dma_handle_t dma_handle, enum ddi_dma_ctlops request, + off_t *offp, size_t *lenp, caddr_t *objpp, uint_t cache_flags); + int iommulib_nexdma_mapobject(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle, struct ddi_dma_req *dmareq, ddi_dma_obj_t *dmao); @@ -298,6 +322,13 @@ int iommulib_iommu_dma_win(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); +int iommulib_iommu_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep); + +int iommulib_iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip, + ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, + size_t *lenp, caddr_t *objpp, uint_t cache_flags); + int iommulib_iommu_dmahdl_setprivate(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, void *priv); diff --git a/usr/src/uts/sparc/ml/sparc_ddi.s b/usr/src/uts/sparc/ml/sparc_ddi.s index 7497459b4a..a14d1fa2a0 100644 --- a/usr/src/uts/sparc/ml/sparc_ddi.s +++ b/usr/src/uts/sparc/ml/sparc_ddi.s @@ -23,9 +23,8 @@ * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* * Assembler routines to make some DDI routines go faster. @@ -168,6 +167,30 @@ ddi_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t op, void *a, void *v) /* ARGSUSED */ int +ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep) +{ + return (DDI_SUCCESS); +} + +#else /* lint */ + + ENTRY(ddi_dma_map) + ldn [%o0 + DEVI_BUS_DMA_MAP], %o0 + ! dip = (dev_info_t *)DEVI(dip)->devi_bus_dma_map; + ldn [%o0 + DEVI_DEV_OPS], %g1 ! dip->dev_ops + ldn [%g1 + DEVI_BUS_OPS], %g1 ! dip->dev_ops->devo_bus_ops + ldn [%g1 + OPS_MAP], %g1 ! dip->dev_ops->devo_bus_ops->bus_dma_map + jmpl %g1, %g0 ! bop off to new routine + nop ! as if we had never been here + SET_SIZE(ddi_dma_map) + +#endif /* lint */ + +#if defined(lint) + +/* ARGSUSED */ +int ddi_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) { diff --git a/usr/src/uts/sun/io/socal.c b/usr/src/uts/sun/io/socal.c index 084c59f0d5..6064218c37 100644 --- a/usr/src/uts/sun/io/socal.c +++ b/usr/src/uts/sun/io/socal.c @@ -23,9 +23,7 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ + /* * socal - Serial Optical Channel Arbitrated Loop host adapter driver. @@ -310,7 +308,7 @@ static struct bus_ops socal_bus_ops = { 0, /* int (*bus_add_intrspec)(); */ 0, /* void (*bus_remove_intrspec)(); */ i_ddi_map_fault, /* int (*bus_map_fault)() */ - 0, /* int (*bus_dma_map)() */ + ddi_dma_map, /* int (*bus_dma_map)() */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4/io/ebus.c b/usr/src/uts/sun4/io/ebus.c index 19001588d5..d8d15f484b 100644 --- a/usr/src/uts/sun4/io/ebus.c +++ b/usr/src/uts/sun4/io/ebus.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> @@ -129,7 +126,7 @@ static struct bus_ops ebus_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4/io/px/px_dma.c b/usr/src/uts/sun4/io/px/px_dma.c index 148699c267..aa06547597 100644 --- a/usr/src/uts/sun4/io/px/px_dma.c +++ b/usr/src/uts/sun4/io/px/px_dma.c @@ -22,9 +22,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * PCI Express nexus DVMA and DMA core routines: @@ -897,6 +894,107 @@ px_dvma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_impl_t *mp, uint_t cache_flags) { switch (cmd) { + case DDI_DMA_SYNC: + return (px_lib_dma_sync(dip, rdip, (ddi_dma_handle_t)mp, + *offp, *lenp, cache_flags)); + + case DDI_DMA_HTOC: { + int ret; + off_t wo_off, off = *offp; /* wo_off: wnd's obj offset */ + uint_t win_size = mp->dmai_winsize; + ddi_dma_cookie_t *cp = (ddi_dma_cookie_t *)objp; + + if (off >= mp->dmai_object.dmao_size) { + cmn_err(CE_WARN, "%s%d invalid dma_htoc offset %lx", + NAMEINST(mp->dmai_rdip), off); + return (DDI_FAILURE); + } + off += mp->dmai_roffset; + ret = px_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + off / win_size, &wo_off, NULL, cp, NULL); /* lenp == NULL */ + if (ret) + return (ret); + DBG(DBG_DMA_CTL, dip, "HTOC:cookie=%x+%lx off=%lx,%lx\n", + cp->dmac_address, cp->dmac_size, off, *offp); + + /* adjust cookie addr/len if we are not on window boundary */ + ASSERT((off % win_size) == (off - + (PX_DMA_CURWIN(mp) ? mp->dmai_roffset : 0) - wo_off)); + off = PX_DMA_CURWIN(mp) ? off % win_size : *offp; + ASSERT(cp->dmac_size > off); + cp->dmac_laddress += off; + cp->dmac_size -= off; + DBG(DBG_DMA_CTL, dip, "HTOC:mp=%p cookie=%x+%lx off=%lx,%lx\n", + mp, cp->dmac_address, cp->dmac_size, off, wo_off); + } + return (DDI_SUCCESS); + + case DDI_DMA_REPWIN: + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_MOVWIN: { + off_t off = *offp; + if (off >= mp->dmai_object.dmao_size) + return (DDI_FAILURE); + off += mp->dmai_roffset; + return (px_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + off / mp->dmai_winsize, offp, lenp, + (ddi_dma_cookie_t *)objp, NULL)); + } + + case DDI_DMA_NEXTWIN: { + px_window_t win = PX_DMA_CURWIN(mp); + if (offp) { + if (*(px_window_t *)offp != win) { + /* window not active */ + *(px_window_t *)objp = win; /* return cur win */ + return (DDI_DMA_STALE); + } + win++; + } else /* map win 0 */ + win = 0; + if (win >= mp->dmai_nwin) { + *(px_window_t *)objp = win - 1; + return (DDI_DMA_DONE); + } + if (px_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + win, 0, 0, 0, 0)) { + *(px_window_t *)objp = win - 1; + return (DDI_FAILURE); + } + *(px_window_t *)objp = win; + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTSEG: + if (*(px_window_t *)offp != PX_DMA_CURWIN(mp)) + return (DDI_DMA_STALE); + if (lenp) /* only 1 seg allowed */ + return (DDI_DMA_DONE); + + /* return mp as seg 0 */ + *(ddi_dma_seg_t *)objp = (ddi_dma_seg_t)mp; + return (DDI_SUCCESS); + + case DDI_DMA_SEGTOC: + MAKE_DMA_COOKIE((ddi_dma_cookie_t *)objp, mp->dmai_mapping, + mp->dmai_size); + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_COFF: { + ddi_dma_cookie_t *cp = (ddi_dma_cookie_t *)offp; + if (cp->dmac_address < mp->dmai_mapping || + (cp->dmac_address + cp->dmac_size) > + (mp->dmai_mapping + mp->dmai_size)) + return (DDI_FAILURE); + *objp = (caddr_t)(cp->dmac_address - mp->dmai_mapping + + mp->dmai_offset); + } + return (DDI_SUCCESS); default: DBG(DBG_DMA_CTL, dip, "unknown command (%x): rdip=%s%d\n", cmd, ddi_driver_name(rdip), ddi_get_instance(rdip)); @@ -1245,6 +1343,153 @@ px_dma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_impl_t *mp, uint_t cache_flags) { switch (cmd) { + case DDI_DMA_SYNC: + return (DDI_SUCCESS); + + case DDI_DMA_HTOC: { + off_t off = *offp; + ddi_dma_cookie_t *loop_cp, *cp; + px_dma_win_t *win_p = mp->dmai_winlst; + + if (off >= mp->dmai_object.dmao_size) + return (DDI_FAILURE); + + /* locate window */ + while (win_p->win_offset + win_p->win_size <= off) + win_p = win_p->win_next; + + loop_cp = cp = (ddi_dma_cookie_t *)(win_p + 1); + mp->dmai_offset = win_p->win_offset; + mp->dmai_size = win_p->win_size; + mp->dmai_mapping = cp->dmac_laddress; /* cookie0 start addr */ + + /* adjust cookie addr/len if we are not on cookie boundary */ + off -= win_p->win_offset; /* offset within window */ + for (; off >= loop_cp->dmac_size; loop_cp++) + off -= loop_cp->dmac_size; /* offset within cookie */ + + mp->dmai_cookie = loop_cp + 1; + win_p->win_curseg = loop_cp - cp; + cp = (ddi_dma_cookie_t *)objp; + MAKE_DMA_COOKIE(cp, loop_cp->dmac_laddress + off, + loop_cp->dmac_size - off); + + DBG(DBG_DMA_CTL, dip, + "HTOC: cookie - dmac_laddress=%p dmac_size=%x\n", + cp->dmac_laddress, cp->dmac_size); + } + return (DDI_SUCCESS); + + case DDI_DMA_REPWIN: + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_MOVWIN: { + off_t off = *offp; + ddi_dma_cookie_t *cp; + px_dma_win_t *win_p = mp->dmai_winlst; + + if (off >= mp->dmai_object.dmao_size) + return (DDI_FAILURE); + + /* locate window */ + while (win_p->win_offset + win_p->win_size <= off) + win_p = win_p->win_next; + + cp = (ddi_dma_cookie_t *)(win_p + 1); + mp->dmai_offset = win_p->win_offset; + mp->dmai_size = win_p->win_size; + mp->dmai_mapping = cp->dmac_laddress; /* cookie0 star addr */ + mp->dmai_cookie = cp + 1; + win_p->win_curseg = 0; + + *(ddi_dma_cookie_t *)objp = *cp; + *offp = win_p->win_offset; + *lenp = win_p->win_size; + DBG(DBG_DMA_CTL, dip, + "HTOC: cookie - dmac_laddress=%p dmac_size=%x\n", + cp->dmac_laddress, cp->dmac_size); + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTWIN: { + px_dma_win_t *win_p = *(px_dma_win_t **)offp; + px_dma_win_t **nw_pp = (px_dma_win_t **)objp; + ddi_dma_cookie_t *cp; + if (!win_p) { + *nw_pp = mp->dmai_winlst; + return (DDI_SUCCESS); + } + + if (win_p->win_offset != mp->dmai_offset) + return (DDI_DMA_STALE); + if (!win_p->win_next) + return (DDI_DMA_DONE); + win_p = win_p->win_next; + cp = (ddi_dma_cookie_t *)(win_p + 1); + mp->dmai_offset = win_p->win_offset; + mp->dmai_size = win_p->win_size; + mp->dmai_mapping = cp->dmac_laddress; /* cookie0 star addr */ + mp->dmai_cookie = cp + 1; + win_p->win_curseg = 0; + *nw_pp = win_p; + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTSEG: { + px_dma_win_t *w_p = *(px_dma_win_t **)offp; + if (w_p->win_offset != mp->dmai_offset) + return (DDI_DMA_STALE); + if (w_p->win_curseg + 1 >= w_p->win_ncookies) + return (DDI_DMA_DONE); + w_p->win_curseg++; + } + *(ddi_dma_seg_t *)objp = (ddi_dma_seg_t)mp; + return (DDI_SUCCESS); + + case DDI_DMA_SEGTOC: { + px_dma_win_t *win_p = mp->dmai_winlst; + off_t off = mp->dmai_offset; + ddi_dma_cookie_t *cp; + int i; + + /* locate active window */ + for (; win_p->win_offset != off; win_p = win_p->win_next) + ; + cp = (ddi_dma_cookie_t *)(win_p + 1); + for (i = 0; i < win_p->win_curseg; i++, cp++) + off += cp->dmac_size; + *offp = off; + *lenp = cp->dmac_size; + *(ddi_dma_cookie_t *)objp = *cp; /* copy cookie */ + } + return (DDI_SUCCESS); + + case DDI_DMA_COFF: { + px_dma_win_t *win_p; + ddi_dma_cookie_t *cp; + uint64_t addr, key = ((ddi_dma_cookie_t *)offp)->dmac_laddress; + size_t win_off; + + for (win_p = mp->dmai_winlst; win_p; win_p = win_p->win_next) { + int i; + win_off = 0; + cp = (ddi_dma_cookie_t *)(win_p + 1); + for (i = 0; i < win_p->win_ncookies; i++, cp++) { + size_t sz = cp->dmac_size; + + addr = cp->dmac_laddress; + if ((addr <= key) && (addr + sz >= key)) + goto found; + win_off += sz; + } + } + return (DDI_FAILURE); +found: + *objp = (caddr_t)(win_p->win_offset + win_off + (key - addr)); + return (DDI_SUCCESS); + } default: DBG(DBG_DMA_CTL, dip, "unknown command (%x): rdip=%s%d\n", cmd, ddi_driver_name(rdip), ddi_get_instance(rdip)); diff --git a/usr/src/uts/sun4/io/px/px_mmu.c b/usr/src/uts/sun4/io/px/px_mmu.c index 967edf917c..0c68271053 100644 --- a/usr/src/uts/sun4/io/px/px_mmu.c +++ b/usr/src/uts/sun4/io/px/px_mmu.c @@ -20,7 +20,6 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* @@ -258,7 +257,7 @@ px_mmu_unmap_pages(px_mmu_t *mmu_p, ddi_dma_impl_t *mp, px_dvma_addr_t dvma_pg, /* * px_mmu_map_window - map a dvma window into the mmu - * used by: px_dma_win() + * used by: px_dma_win(), px_dma_ctlops() - DDI_DMA_MOVWIN, DDI_DMA_NEXTWIN * return value: none */ /*ARGSUSED*/ diff --git a/usr/src/uts/sun4/ml/offsets.in b/usr/src/uts/sun4/ml/offsets.in index 4f6d19ba01..377cfbd319 100644 --- a/usr/src/uts/sun4/ml/offsets.in +++ b/usr/src/uts/sun4/ml/offsets.in @@ -1,6 +1,5 @@ \ offsets.in: input file to produce assym.h using the stabs program \ Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. -\ Copyright 2012 Garrett D'Amore <garett@damore.org>. All rights reserved. \ \ CDDL HEADER START \ @@ -467,6 +466,7 @@ syncq SQ_SIZE sq_exitwait bus_ops BUS_OPS_SIZE + bus_dma_map OPS_MAP bus_dma_allochdl OPS_ALLOCHDL bus_dma_freehdl OPS_FREEHDL bus_dma_bindhdl OPS_BINDHDL @@ -489,6 +489,7 @@ dev_info DEVI_SIZE devi_bus_dma_flush devi_bus_dma_unbindfunc devi_bus_ctl + devi_bus_dma_map devi_bus_dma_ctl kstat_io diff --git a/usr/src/uts/sun4/os/ddi_impl.c b/usr/src/uts/sun4/os/ddi_impl.c index 6769c48b9d..f3efc433c5 100644 --- a/usr/src/uts/sun4/os/ddi_impl.c +++ b/usr/src/uts/sun4/os/ddi_impl.c @@ -23,9 +23,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * sun4 specific DDI implementation @@ -1212,6 +1209,44 @@ i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, } } +/* + * covert old DMA limits structure to DMA attribute structure + * and continue + */ +int +i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, + size_t length, int cansleep, int streaming, + ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, + uint_t *real_length, ddi_acc_hdl_t *ap) +{ + ddi_dma_attr_t dma_attr, *attrp; + size_t rlen; + int ret; + + ASSERT(limits); + attrp = &dma_attr; + attrp->dma_attr_version = DMA_ATTR_V0; + attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; + attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; + attrp->dma_attr_count_max = (uint64_t)-1; + attrp->dma_attr_align = 1; + attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; + attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; + attrp->dma_attr_maxxfer = (uint64_t)-1; + attrp->dma_attr_seg = (uint64_t)limits->dlim_cntr_max; + attrp->dma_attr_sgllen = 1; + attrp->dma_attr_granular = 1; + attrp->dma_attr_flags = 0; + + ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, + accattrp, kaddrp, &rlen, ap); + if (ret == DDI_SUCCESS) { + if (real_length) + *real_length = (uint_t)rlen; + } + return (ret); +} + /* ARGSUSED */ void i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap) diff --git a/usr/src/uts/sun4u/io/iommu.c b/usr/src/uts/sun4u/io/iommu.c index 75937f0b0f..66d7a46dc2 100644 --- a/usr/src/uts/sun4u/io/iommu.c +++ b/usr/src/uts/sun4u/io/iommu.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> #include <sys/param.h> @@ -62,7 +59,12 @@ #define IOMMU_DMAMCTL_SYNC_DEBUG 0x8 #define IOMMU_DMAMCTL_HTOC_DEBUG 0x10 #define IOMMU_DMAMCTL_KVADDR_DEBUG 0x20 +#define IOMMU_DMAMCTL_NEXTWIN_DEBUG 0x40 +#define IOMMU_DMAMCTL_NEXTSEG_DEBUG 0x80 +#define IOMMU_DMAMCTL_MOVWIN_DEBUG 0x100 +#define IOMMU_DMAMCTL_REPWIN_DEBUG 0x200 #define IOMMU_DMAMCTL_GETERR_DEBUG 0x400 +#define IOMMU_DMAMCTL_COFF_DEBUG 0x800 #define IOMMU_DMAMCTL_DMA_FREE_DEBUG 0x1000 #define IOMMU_REGISTERS_DEBUG 0x2000 #define IOMMU_DMA_SETUP_DEBUG 0x4000 @@ -1302,6 +1304,85 @@ iommu_map_window(ddi_dma_impl_t *mp, off_t newoff, size_t winsize) } +int +iommu_dma_map(dev_info_t *dip, dev_info_t *rdip, + struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep) +{ + ddi_dma_lim_t *dma_lim = dmareq->dmar_limits; + ddi_dma_impl_t *mp; + ddi_dma_attr_t *dma_attr; + struct dma_impl_priv *mppriv; + ioaddr_t addrlow, addrhigh; + ioaddr_t segalign; + int rval; + struct sbus_soft_state *softsp = + (struct sbus_soft_state *)ddi_get_soft_state(sbusp, + ddi_get_instance(dip)); + + addrlow = dma_lim->dlim_addr_lo; + addrhigh = dma_lim->dlim_addr_hi; + if ((addrhigh <= addrlow) || + (addrhigh < (ioaddr_t)softsp->iommu_dvma_base)) { + return (DDI_DMA_NOMAPPING); + } + + /* + * Setup DMA burstsizes and min-xfer counts. + */ + (void) iommu_dma_lim_setup(dip, rdip, softsp, &dma_lim->dlim_burstsizes, + (uint_t)dma_lim->dlim_burstsizes, &dma_lim->dlim_minxfer, + dmareq->dmar_flags); + + if (dma_lim->dlim_burstsizes == 0) + return (DDI_DMA_NOMAPPING); + /* + * If not an advisory call, get a DMA handle + */ + if (!handlep) { + return (DDI_DMA_MAPOK); + } + + mppriv = kmem_zalloc(sizeof (*mppriv), + (dmareq->dmar_fp == DDI_DMA_SLEEP) ? KM_SLEEP : KM_NOSLEEP); + if (mppriv == NULL) { + if (dmareq->dmar_fp != DDI_DMA_DONTWAIT) { + ddi_set_callback(dmareq->dmar_fp, + dmareq->dmar_arg, &softsp->dvma_call_list_id); + } + return (DDI_DMA_NORESOURCES); + } + mp = (ddi_dma_impl_t *)mppriv; + mp->dmai_rdip = rdip; + mp->dmai_rflags = dmareq->dmar_flags & DMP_DDIFLAGS; + mp->dmai_minxfer = dma_lim->dlim_minxfer; + mp->dmai_burstsizes = dma_lim->dlim_burstsizes; + mp->dmai_offset = 0; + mp->dmai_ndvmapages = 0; + mp->dmai_minfo = 0; + mp->dmai_inuse = 0; + segalign = dma_lim->dlim_cntr_max; + /* See if the DMA engine has any limit restrictions. */ + if (segalign == UINT32_MAX && addrhigh == UINT32_MAX && + addrlow == 0) { + mp->dmai_rflags |= DMP_NOLIMIT; + } + mppriv->softsp = softsp; + mppriv->phys_sync_flag = va_to_pa((caddr_t)&mppriv->sync_flag); + dma_attr = &mp->dmai_attr; + dma_attr->dma_attr_align = 1; + dma_attr->dma_attr_addr_lo = addrlow; + dma_attr->dma_attr_addr_hi = addrhigh; + dma_attr->dma_attr_seg = segalign; + dma_attr->dma_attr_burstsizes = dma_lim->dlim_burstsizes; + rval = iommu_dma_bindhdl(dip, rdip, (ddi_dma_handle_t)mp, + dmareq, NULL, NULL); + if (rval && (rval != DDI_DMA_PARTIAL_MAP)) { + kmem_free(mppriv, sizeof (*mppriv)); + } else { + *handlep = (ddi_dma_handle_t)mp; + } + return (rval); +} /*ARGSUSED*/ int @@ -1309,11 +1390,57 @@ iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, caddr_t *objp, uint_t cache_flags) { + ioaddr_t addr; + uint_t offset; pgcnt_t npages; + size_t size; + ddi_dma_cookie_t *cp; ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; DPRINTF(IOMMU_DMAMCTL_DEBUG, ("dma_mctl: handle %p ", (void *)mp)); switch (request) { + case DDI_DMA_FREE: + { + struct dma_impl_priv *mppriv = (struct dma_impl_priv *)mp; + struct sbus_soft_state *softsp = mppriv->softsp; + ASSERT(softsp != NULL); + + /* + * 'Free' the dma mappings. + */ + addr = (ioaddr_t)(mp->dmai_mapping & ~IOMMU_PAGEOFFSET); + npages = mp->dmai_ndvmapages; + size = iommu_ptob(npages); + + DPRINTF(IOMMU_DMAMCTL_DMA_FREE_DEBUG, ("iommu_dma_mctl dmafree:" + "freeing vaddr %x for %x pages.\n", addr, + mp->dmai_ndvmapages)); + /* sync the entire object */ + if (!(mp->dmai_rflags & DDI_DMA_CONSISTENT)) { + /* flush stream write buffers */ + sync_stream_buf(softsp, addr, npages, + (int *)&mppriv->sync_flag, mppriv->phys_sync_flag); + } + +#if defined(DEBUG) && defined(IO_MEMDEBUG) + iommu_remove_mappings(mp); +#endif /* DEBUG && IO_MEMDEBUG */ + + ASSERT(npages > (uint_t)0); + if (mp->dmai_rflags & DMP_NOLIMIT) + vmem_free(softsp->dvma_arena, + (void *)(uintptr_t)addr, size); + else + vmem_xfree(softsp->dvma_arena, + (void *)(uintptr_t)addr, size); + + kmem_free(mppriv, sizeof (*mppriv)); + + if (softsp->dvma_call_list_id != 0) + ddi_run_callback(&softsp->dvma_call_list_id); + + break; + } case DDI_DMA_SET_SBUS64: { @@ -1324,6 +1451,203 @@ iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip, DDI_DMA_SBUS_64BIT)); } + case DDI_DMA_HTOC: + DPRINTF(IOMMU_DMAMCTL_HTOC_DEBUG, ("htoc off %lx mapping %lx " + "size %x\n", *offp, mp->dmai_mapping, + mp->dmai_size)); + + if ((uint_t)(*offp) >= mp->dmai_size) + return (DDI_FAILURE); + + cp = (ddi_dma_cookie_t *)objp; + cp->dmac_notused = 0; + cp->dmac_address = (mp->dmai_mapping + (uint_t)(*offp)); + cp->dmac_size = + mp->dmai_mapping + mp->dmai_size - cp->dmac_address; + cp->dmac_type = 0; + + break; + + case DDI_DMA_KVADDR: + /* + * If a physical address mapping has percolated this high, + * that is an error (maybe?). + */ + if (mp->dmai_rflags & DMP_PHYSADDR) { + DPRINTF(IOMMU_DMAMCTL_KVADDR_DEBUG, ("kvaddr of phys " + "mapping\n")); + return (DDI_FAILURE); + } + + return (DDI_FAILURE); + + case DDI_DMA_NEXTWIN: + { + ddi_dma_win_t *owin, *nwin; + uint_t winsize, newoff; + int rval; + + DPRINTF(IOMMU_DMAMCTL_NEXTWIN_DEBUG, ("nextwin\n")); + + mp = (ddi_dma_impl_t *)handle; + owin = (ddi_dma_win_t *)offp; + nwin = (ddi_dma_win_t *)objp; + if (mp->dmai_rflags & DDI_DMA_PARTIAL) { + if (*owin == NULL) { + DPRINTF(IOMMU_DMAMCTL_NEXTWIN_DEBUG, + ("nextwin: win == NULL\n")); + mp->dmai_offset = 0; + *nwin = (ddi_dma_win_t)mp; + return (DDI_SUCCESS); + } + + offset = (uint_t)(mp->dmai_mapping & IOMMU_PAGEOFFSET); + winsize = iommu_ptob(mp->dmai_ndvmapages - + iommu_btopr(offset)); + + newoff = (uint_t)(mp->dmai_offset + winsize); + if (newoff > mp->dmai_object.dmao_size - + mp->dmai_minxfer) + return (DDI_DMA_DONE); + + if ((rval = iommu_map_window(mp, newoff, winsize)) + != DDI_SUCCESS) + return (rval); + } else { + DPRINTF(IOMMU_DMAMCTL_NEXTWIN_DEBUG, ("nextwin: no " + "partial mapping\n")); + if (*owin != NULL) + return (DDI_DMA_DONE); + mp->dmai_offset = 0; + *nwin = (ddi_dma_win_t)mp; + } + break; + } + + case DDI_DMA_NEXTSEG: + { + ddi_dma_seg_t *oseg, *nseg; + + DPRINTF(IOMMU_DMAMCTL_NEXTSEG_DEBUG, ("nextseg:\n")); + + oseg = (ddi_dma_seg_t *)lenp; + if (*oseg != NULL) + return (DDI_DMA_DONE); + nseg = (ddi_dma_seg_t *)objp; + *nseg = *((ddi_dma_seg_t *)offp); + break; + } + + case DDI_DMA_SEGTOC: + { + ddi_dma_seg_impl_t *seg; + + seg = (ddi_dma_seg_impl_t *)handle; + cp = (ddi_dma_cookie_t *)objp; + cp->dmac_notused = 0; + cp->dmac_address = (ioaddr_t)seg->dmai_mapping; + cp->dmac_size = *lenp = seg->dmai_size; + cp->dmac_type = 0; + *offp = seg->dmai_offset; + break; + } + + case DDI_DMA_MOVWIN: + { + uint_t winsize; + uint_t newoff; + int rval; + + offset = (uint_t)(mp->dmai_mapping & IOMMU_PAGEOFFSET); + winsize = iommu_ptob(mp->dmai_ndvmapages - iommu_btopr(offset)); + + DPRINTF(IOMMU_DMAMCTL_MOVWIN_DEBUG, ("movwin off %lx len %lx " + "winsize %x\n", *offp, *lenp, winsize)); + + if ((mp->dmai_rflags & DDI_DMA_PARTIAL) == 0) + return (DDI_FAILURE); + + if (*lenp != (uint_t)-1 && *lenp != winsize) { + DPRINTF(IOMMU_DMAMCTL_MOVWIN_DEBUG, ("bad length\n")); + return (DDI_FAILURE); + } + newoff = (uint_t)*offp; + if (newoff & (winsize - 1)) { + DPRINTF(IOMMU_DMAMCTL_MOVWIN_DEBUG, ("bad off\n")); + return (DDI_FAILURE); + } + + if (newoff == mp->dmai_offset) { + /* + * Nothing to do... + */ + break; + } + + /* + * Check out new address... + */ + if (newoff > mp->dmai_object.dmao_size - mp->dmai_minxfer) { + DPRINTF(IOMMU_DMAMCTL_MOVWIN_DEBUG, ("newoff out of " + "range\n")); + return (DDI_FAILURE); + } + + rval = iommu_map_window(mp, newoff, winsize); + if (rval != DDI_SUCCESS) + return (rval); + + if ((cp = (ddi_dma_cookie_t *)objp) != 0) { + cp->dmac_notused = 0; + cp->dmac_address = (ioaddr_t)mp->dmai_mapping; + cp->dmac_size = mp->dmai_size; + cp->dmac_type = 0; + } + *offp = (off_t)newoff; + *lenp = (uint_t)winsize; + break; + } + + case DDI_DMA_REPWIN: + if ((mp->dmai_rflags & DDI_DMA_PARTIAL) == 0) { + DPRINTF(IOMMU_DMAMCTL_REPWIN_DEBUG, ("repwin fail\n")); + return (DDI_FAILURE); + } + + *offp = (off_t)mp->dmai_offset; + + addr = mp->dmai_ndvmapages - + iommu_btopr(mp->dmai_mapping & IOMMU_PAGEOFFSET); + + *lenp = (uint_t)iommu_ptob(addr); + + DPRINTF(IOMMU_DMAMCTL_REPWIN_DEBUG, ("repwin off %lx len %x\n", + mp->dmai_offset, mp->dmai_size)); + + break; + + case DDI_DMA_GETERR: + DPRINTF(IOMMU_DMAMCTL_GETERR_DEBUG, + ("iommu_dma_mctl: geterr\n")); + + break; + + case DDI_DMA_COFF: + cp = (ddi_dma_cookie_t *)offp; + addr = cp->dmac_address; + + if (addr < mp->dmai_mapping || + addr >= mp->dmai_mapping + mp->dmai_size) + return (DDI_FAILURE); + + *objp = (caddr_t)(addr - mp->dmai_mapping); + + DPRINTF(IOMMU_DMAMCTL_COFF_DEBUG, ("coff off %lx mapping %lx " + "size %x\n", (ulong_t)*objp, mp->dmai_mapping, + mp->dmai_size)); + + break; + case DDI_DMA_RESERVE: { struct ddi_dma_req *dmareq = (struct ddi_dma_req *)offp; diff --git a/usr/src/uts/sun4u/io/isadma.c b/usr/src/uts/sun4u/io/isadma.c index 610391baa1..2372b3b11b 100644 --- a/usr/src/uts/sun4u/io/isadma.c +++ b/usr/src/uts/sun4u/io/isadma.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/conf.h> @@ -93,7 +90,7 @@ static struct bus_ops isadma_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/io/pci/db21554.c b/usr/src/uts/sun4u/io/pci/db21554.c index f51ad8c0e6..5a08ae7b5d 100644 --- a/usr/src/uts/sun4u/io/pci/db21554.c +++ b/usr/src/uts/sun4u/io/pci/db21554.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* @@ -280,7 +277,7 @@ struct bus_ops db_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/io/pci/pci_dma.c b/usr/src/uts/sun4u/io/pci/pci_dma.c index 9814a69e68..5a614bf28d 100644 --- a/usr/src/uts/sun4u/io/pci/pci_dma.c +++ b/usr/src/uts/sun4u/io/pci/pci_dma.c @@ -22,9 +22,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * PCI nexus DVMA and DMA core routines: @@ -1113,6 +1110,106 @@ pci_dvma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_impl_t *mp, uint_t cache_flags) { switch (cmd) { + case DDI_DMA_SYNC: + return (pci_dma_sync(dip, rdip, (ddi_dma_handle_t)mp, + *offp, *lenp, cache_flags)); + + case DDI_DMA_HTOC: { + int ret; + off_t wo_off, off = *offp; /* wo_off: wnd's obj offset */ + uint_t win_size = mp->dmai_winsize; + ddi_dma_cookie_t *cp = (ddi_dma_cookie_t *)objp; + + if (off >= mp->dmai_object.dmao_size) { + cmn_err(CE_WARN, "%s%d invalid dma_htoc offset %lx", + NAMEINST(mp->dmai_rdip), off); + return (DDI_FAILURE); + } + off += mp->dmai_roffset; + ret = pci_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + off / win_size, &wo_off, NULL, cp, NULL); /* lenp == NULL */ + if (ret) + return (ret); + DEBUG4(DBG_DMA_CTL, dip, "HTOC:cookie=%x+%lx off=%lx,%lx\n", + cp->dmac_address, cp->dmac_size, off, *offp); + + /* adjust cookie addr/len if we are not on window boundary */ + ASSERT((off % win_size) == (off - + (PCI_DMA_CURWIN(mp) ? mp->dmai_roffset : 0) - wo_off)); + off = PCI_DMA_CURWIN(mp) ? off % win_size : *offp; + ASSERT(cp->dmac_size > off); + cp->dmac_laddress += off; + cp->dmac_size -= off; + DEBUG5(DBG_DMA_CTL, dip, + "HTOC:mp=%p cookie=%x+%lx off=%lx,%lx\n", + mp, cp->dmac_address, cp->dmac_size, off, wo_off); + } + return (DDI_SUCCESS); + + case DDI_DMA_REPWIN: + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_MOVWIN: { + off_t off = *offp; + if (off >= mp->dmai_object.dmao_size) + return (DDI_FAILURE); + off += mp->dmai_roffset; + return (pci_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + off / mp->dmai_winsize, offp, lenp, + (ddi_dma_cookie_t *)objp, NULL)); + } + + case DDI_DMA_NEXTWIN: { + window_t win = PCI_DMA_CURWIN(mp); + if (offp) { + if (*(window_t *)offp != win) { /* window not active */ + *(window_t *)objp = win; /* return cur win */ + return (DDI_DMA_STALE); + } + win++; + } else /* map win 0 */ + win = 0; + if (win >= mp->dmai_nwin) { + *(window_t *)objp = win - 1; + return (DDI_DMA_DONE); + } + if (pci_dma_win(dip, rdip, (ddi_dma_handle_t)mp, + win, 0, 0, 0, 0)) { + *(window_t *)objp = win - 1; + return (DDI_FAILURE); + } + *(window_t *)objp = win; + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTSEG: + if (*(window_t *)offp != PCI_DMA_CURWIN(mp)) + return (DDI_DMA_STALE); + if (lenp) /* only 1 seg allowed */ + return (DDI_DMA_DONE); + /* return mp as seg 0 */ + *(ddi_dma_seg_t *)objp = (ddi_dma_seg_t)mp; + return (DDI_SUCCESS); + + case DDI_DMA_SEGTOC: + MAKE_DMA_COOKIE((ddi_dma_cookie_t *)objp, mp->dmai_mapping, + mp->dmai_size); + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_COFF: { + ddi_dma_cookie_t *cp = (ddi_dma_cookie_t *)offp; + if (cp->dmac_address < mp->dmai_mapping || + (cp->dmac_address + cp->dmac_size) > + (mp->dmai_mapping + mp->dmai_size)) + return (DDI_FAILURE); + *objp = (caddr_t)(cp->dmac_address - mp->dmai_mapping + + mp->dmai_offset); + } + return (DDI_SUCCESS); case DDI_DMA_REMAP: if (pci_dvma_remap_enabled) @@ -1427,6 +1524,8 @@ pci_dma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_impl_t *mp, uint_t cache_flags) { switch (cmd) { + case DDI_DMA_SYNC: /* XXX */ + return (DDI_SUCCESS); case DDI_DMA_HTOC: { off_t off = *offp; @@ -1462,6 +1561,92 @@ pci_dma_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_impl_t *mp, } return (DDI_SUCCESS); + case DDI_DMA_REPWIN: + *offp = mp->dmai_offset; + *lenp = mp->dmai_size; + return (DDI_SUCCESS); + + case DDI_DMA_MOVWIN: { + off_t off = *offp; + ddi_dma_cookie_t *cp; + pci_dma_win_t *win_p = mp->dmai_winlst; + + if (off >= mp->dmai_object.dmao_size) + return (DDI_FAILURE); + + /* locate window */ + while (win_p->win_offset + win_p->win_size <= off) + win_p = win_p->win_next; + + cp = (ddi_dma_cookie_t *)(win_p + 1); + mp->dmai_offset = win_p->win_offset; + mp->dmai_size = win_p->win_size; + mp->dmai_mapping = cp->dmac_laddress; /* cookie0 star addr */ + mp->dmai_cookie = cp + 1; + win_p->win_curseg = 0; + + *(ddi_dma_cookie_t *)objp = *cp; + *offp = win_p->win_offset; + *lenp = win_p->win_size; + DEBUG2(DBG_DMA_CTL, dip, + "HTOC: cookie - dmac_laddress=%p dmac_size=%x\n", + cp->dmac_laddress, cp->dmac_size); + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTWIN: { + pci_dma_win_t *win_p = *(pci_dma_win_t **)offp; + pci_dma_win_t **nw_pp = (pci_dma_win_t **)objp; + ddi_dma_cookie_t *cp; + if (!win_p) { + *nw_pp = mp->dmai_winlst; + return (DDI_SUCCESS); + } + + if (win_p->win_offset != mp->dmai_offset) + return (DDI_DMA_STALE); + if (!win_p->win_next) + return (DDI_DMA_DONE); + win_p = win_p->win_next; + cp = (ddi_dma_cookie_t *)(win_p + 1); + mp->dmai_offset = win_p->win_offset; + mp->dmai_size = win_p->win_size; + mp->dmai_mapping = cp->dmac_laddress; /* cookie0 star addr */ + mp->dmai_cookie = cp + 1; + win_p->win_curseg = 0; + *nw_pp = win_p; + } + return (DDI_SUCCESS); + + case DDI_DMA_NEXTSEG: { + pci_dma_win_t *w_p = *(pci_dma_win_t **)offp; + if (w_p->win_offset != mp->dmai_offset) + return (DDI_DMA_STALE); + if (w_p->win_curseg + 1 >= w_p->win_ncookies) + return (DDI_DMA_DONE); + w_p->win_curseg++; + } + *(ddi_dma_seg_t *)objp = (ddi_dma_seg_t)mp; + return (DDI_SUCCESS); + + case DDI_DMA_SEGTOC: { + pci_dma_win_t *win_p = mp->dmai_winlst; + off_t off = mp->dmai_offset; + ddi_dma_cookie_t *cp; + int i; + + /* locate active window */ + for (; win_p->win_offset != off; win_p = win_p->win_next) + ; + cp = (ddi_dma_cookie_t *)(win_p + 1); + for (i = 0; i < win_p->win_curseg; i++, cp++) + off += cp->dmac_size; + *offp = off; + *lenp = cp->dmac_size; + *(ddi_dma_cookie_t *)objp = *cp; /* copy cookie */ + } + return (DDI_SUCCESS); + case DDI_DMA_COFF: { pci_dma_win_t *win_p; ddi_dma_cookie_t *cp; diff --git a/usr/src/uts/sun4u/io/pci/pci_iommu.c b/usr/src/uts/sun4u/io/pci/pci_iommu.c index cc225aa0dc..0ae6e22e96 100644 --- a/usr/src/uts/sun4u/io/pci/pci_iommu.c +++ b/usr/src/uts/sun4u/io/pci/pci_iommu.c @@ -22,9 +22,8 @@ * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* * PCI iommu initialization and configuration @@ -79,26 +78,26 @@ iommu_create(pci_t *pci_p) * Determine the virtual address of iommu registers. */ iommu_p->iommu_ctrl_reg = - (uint64_t *)(a + COMMON_IOMMU_CTRL_REG_OFFSET); + (uint64_t *)(a + COMMON_IOMMU_CTRL_REG_OFFSET); iommu_p->iommu_tsb_base_addr_reg = - (uint64_t *)(a + COMMON_IOMMU_TSB_BASE_ADDR_REG_OFFSET); + (uint64_t *)(a + COMMON_IOMMU_TSB_BASE_ADDR_REG_OFFSET); iommu_p->iommu_flush_page_reg = - (uint64_t *)(a + COMMON_IOMMU_FLUSH_PAGE_REG_OFFSET); + (uint64_t *)(a + COMMON_IOMMU_FLUSH_PAGE_REG_OFFSET); /* * Configure the rest of the iommu parameters according to: * tsb_size and dvma_end */ iommu_p->iommu_tsb_vaddr = /* retrieve TSB VA reserved by system */ - iommu_tsb_cookie_to_va(pci_p->pci_tsb_cookie); + iommu_tsb_cookie_to_va(pci_p->pci_tsb_cookie); iommu_p->iommu_tsb_entries = tsb_entries = - IOMMU_TSBSIZE_TO_TSBENTRIES(iommu_p->iommu_tsb_size); + IOMMU_TSBSIZE_TO_TSBENTRIES(iommu_p->iommu_tsb_size); iommu_p->iommu_tsb_paddr = va_to_pa((caddr_t)iommu_p->iommu_tsb_vaddr); iommu_p->iommu_dvma_cache_locks = - kmem_zalloc(pci_dvma_page_cache_entries, KM_SLEEP); + kmem_zalloc(pci_dvma_page_cache_entries, KM_SLEEP); iommu_p->iommu_dvma_base = iommu_p->iommu_dvma_end + 1 - - (tsb_entries * IOMMU_PAGE_SIZE); + - (tsb_entries * IOMMU_PAGE_SIZE); iommu_p->dvma_base_pg = IOMMU_BTOP(iommu_p->iommu_dvma_base); iommu_p->iommu_dvma_reserve = tsb_entries >> 1; iommu_p->dvma_end_pg = IOMMU_BTOP(iommu_p->iommu_dvma_end); @@ -111,29 +110,29 @@ iommu_create(pci_t *pci_p) */ pci_dvma_range.dvma_base = (uint32_t)iommu_p->iommu_dvma_base; pci_dvma_range.dvma_len = (uint32_t) - iommu_p->iommu_dvma_end - iommu_p->iommu_dvma_base + 1; + iommu_p->iommu_dvma_end - iommu_p->iommu_dvma_base + 1; (void) ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, - "virtual-dma", (caddr_t)&pci_dvma_range, - sizeof (pci_dvma_range)); + "virtual-dma", (caddr_t)&pci_dvma_range, + sizeof (pci_dvma_range)); DEBUG2(DBG_ATTACH, dip, "iommu_create: ctrl=%p, tsb=%p\n", - iommu_p->iommu_ctrl_reg, iommu_p->iommu_tsb_base_addr_reg); + iommu_p->iommu_ctrl_reg, iommu_p->iommu_tsb_base_addr_reg); DEBUG2(DBG_ATTACH, dip, "iommu_create: page_flush=%p, ctx_flush=%p\n", - iommu_p->iommu_flush_page_reg, iommu_p->iommu_flush_ctx_reg); + iommu_p->iommu_flush_page_reg, iommu_p->iommu_flush_ctx_reg); DEBUG2(DBG_ATTACH, dip, "iommu_create: tsb vaddr=%p tsb_paddr=%p\n", - iommu_p->iommu_tsb_vaddr, iommu_p->iommu_tsb_paddr); + iommu_p->iommu_tsb_vaddr, iommu_p->iommu_tsb_paddr); DEBUG1(DBG_ATTACH, dip, "iommu_create: allocated size=%x\n", - iommu_tsb_cookie_to_size(pci_p->pci_tsb_cookie)); + iommu_tsb_cookie_to_size(pci_p->pci_tsb_cookie)); DEBUG2(DBG_ATTACH, dip, "iommu_create: fast tsb tte addr: %x + %x\n", - iommu_p->iommu_tsb_vaddr, - pci_dvma_page_cache_entries * pci_dvma_page_cache_clustsz); + iommu_p->iommu_tsb_vaddr, + pci_dvma_page_cache_entries * pci_dvma_page_cache_clustsz); DEBUG3(DBG_ATTACH, dip, - "iommu_create: tsb size=%x, tsb entries=%x, dvma base=%x\n", - iommu_p->iommu_tsb_size, iommu_p->iommu_tsb_entries, - iommu_p->iommu_dvma_base); + "iommu_create: tsb size=%x, tsb entries=%x, dvma base=%x\n", + iommu_p->iommu_tsb_size, iommu_p->iommu_tsb_entries, + iommu_p->iommu_dvma_base); DEBUG2(DBG_ATTACH, dip, - "iommu_create: dvma_cache_locks=%x cache_entries=%x\n", - iommu_p->iommu_dvma_cache_locks, pci_dvma_page_cache_entries); + "iommu_create: dvma_cache_locks=%x cache_entries=%x\n", + iommu_p->iommu_dvma_cache_locks, pci_dvma_page_cache_entries); /* * zero out the area to be used for iommu tsb @@ -145,16 +144,16 @@ iommu_create(pci_t *pci_p) * Reserve 'size' bytes of low dvma space for fast track cache. */ (void) snprintf(map_name, sizeof (map_name), "%s%d_dvma", - ddi_driver_name(dip), ddi_get_instance(dip)); + ddi_driver_name(dip), ddi_get_instance(dip)); cache_size = IOMMU_PTOB(pci_dvma_page_cache_entries * - pci_dvma_page_cache_clustsz); + pci_dvma_page_cache_clustsz); iommu_p->iommu_dvma_fast_end = iommu_p->iommu_dvma_base + - cache_size - 1; + cache_size - 1; iommu_p->iommu_dvma_map = vmem_create(map_name, - (void *)(iommu_p->iommu_dvma_fast_end + 1), - IOMMU_PTOB(tsb_entries) - cache_size, IOMMU_PAGE_SIZE, - NULL, NULL, NULL, IOMMU_PAGE_SIZE, VM_SLEEP); + (void *)(iommu_p->iommu_dvma_fast_end + 1), + IOMMU_PTOB(tsb_entries) - cache_size, IOMMU_PAGE_SIZE, + NULL, NULL, NULL, IOMMU_PAGE_SIZE, VM_SLEEP); mutex_init(&iommu_p->dvma_debug_lock, NULL, MUTEX_DRIVER, NULL); @@ -230,13 +229,14 @@ iommu_configure(iommu_t *iommu_p) dev_info_t *dip = iommu_p->iommu_pci_p->pci_dip; dev_info_t *cdip = NULL; volatile uint64_t ctl_val = (uint64_t) - ((iommu_p->iommu_tsb_size << COMMON_IOMMU_CTRL_TSB_SZ_SHIFT) | - (0 /* 8k page */ << COMMON_IOMMU_CTRL_TBW_SZ_SHIFT) | - COMMON_IOMMU_CTRL_ENABLE | COMMON_IOMMU_CTRL_DIAG_ENABLE | - (pci_lock_tlb ? COMMON_IOMMU_CTRL_LCK_ENABLE : 0)); + ((iommu_p->iommu_tsb_size << COMMON_IOMMU_CTRL_TSB_SZ_SHIFT) | + (0 /* 8k page */ << COMMON_IOMMU_CTRL_TBW_SZ_SHIFT) | + COMMON_IOMMU_CTRL_ENABLE | + COMMON_IOMMU_CTRL_DIAG_ENABLE | + (pci_lock_tlb ? COMMON_IOMMU_CTRL_LCK_ENABLE : 0)); DEBUG2(DBG_ATTACH, dip, "iommu_configure: iommu_ctl=%08x.%08x\n", - HI32(ctl_val), LO32(ctl_val)); + HI32(ctl_val), LO32(ctl_val)); if (!pci_preserve_iommu_tsb || !(*iommu_p->iommu_tsb_base_addr_reg)) { *iommu_p->iommu_ctrl_reg = COMMON_IOMMU_CTRL_DIAG_ENABLE; iommu_tlb_flushall(iommu_p); @@ -247,7 +247,7 @@ iommu_configure(iommu_t *iommu_p) uint32_t *reg_p; int reg_len; if (ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, - "reg", (caddr_t)®_p, ®_len) != DDI_PROP_SUCCESS) + "reg", (caddr_t)®_p, ®_len) != DDI_PROP_SUCCESS) continue; cfgpa += (*reg_p) & (PCI_CONF_ADDR_MASK ^ PCI_REG_REG_M); kmem_free(reg_p, reg_len); @@ -274,45 +274,45 @@ iommu_map_pages(iommu_t *iommu_p, ddi_dma_impl_t *mp, ASSERT(pfn_last <= mp->dmai_ndvmapages); DEBUG5(DBG_MAP_WIN, dip, - "iommu_map_pages:%x+%x=%x npages=0x%x pfn_index=0x%x\n", - (uint_t)iommu_p->dvma_base_pg, (uint_t)pg_index, dvma_pg, - (uint_t)npages, (uint_t)pfn_index); + "iommu_map_pages:%x+%x=%x npages=0x%x pfn_index=0x%x\n", + (uint_t)iommu_p->dvma_base_pg, (uint_t)pg_index, dvma_pg, + (uint_t)npages, (uint_t)pfn_index); for (i = pfn_index; i < pfn_last; i++, pg_index++, tte_addr++) { iopfn_t pfn = PCI_GET_MP_PFN(mp, i); volatile uint64_t cur_tte = IOMMU_PTOB(pfn) | tte; DEBUG3(DBG_MAP_WIN, dip, "iommu_map_pages: mp=%p pg[%x]=%x\n", - mp, i, (uint_t)pfn); + mp, i, (uint_t)pfn); DEBUG3(DBG_MAP_WIN, dip, - "iommu_map_pages: pg_index=%x tte=%08x.%08x\n", - pg_index, HI32(cur_tte), LO32(cur_tte)); + "iommu_map_pages: pg_index=%x tte=%08x.%08x\n", + pg_index, HI32(cur_tte), LO32(cur_tte)); ASSERT(TTE_IS_INVALID(*tte_addr)); *tte_addr = cur_tte; #ifdef DEBUG if (pfn == 0 && pci_warn_pp0) cmn_err(CE_WARN, "%s%d <%p> doing DMA to pp0\n", - ddi_driver_name(mp->dmai_rdip), - ddi_get_instance(mp->dmai_rdip), mp); + ddi_driver_name(mp->dmai_rdip), + ddi_get_instance(mp->dmai_rdip), mp); #endif } ASSERT(tte_addr == iommu_p->iommu_tsb_vaddr + pg_index); #ifdef DEBUG if (HAS_REDZONE(mp)) { DEBUG1(DBG_MAP_WIN, dip, "iommu_map_pages: redzone pg=%x\n", - pg_index); + pg_index); ASSERT(TTE_IS_INVALID(iommu_p->iommu_tsb_vaddr[pg_index])); } #endif if (DVMA_DBG_ON(iommu_p)) pci_dvma_alloc_debug(iommu_p, (char *)mp->dmai_mapping, - mp->dmai_size, mp); + mp->dmai_size, mp); } /* * iommu_map_window - map a dvma window into the iommu * - * used by: pci_dma_win(), pci_dma_ctlops() - DDI_DMA_MOVWIN + * used by: pci_dma_win(), pci_dma_ctlops() - DDI_DMA_MOVWIN, DDI_DMA_NEXTWIN * * return value: none */ @@ -404,7 +404,7 @@ iommu_unmap_window(iommu_t *iommu_p, ddi_dma_impl_t *mp) if (DVMA_DBG_ON(iommu_p)) pci_dvma_free_debug(iommu_p, (char *)mp->dmai_mapping, - mp->dmai_size, mp); + mp->dmai_size, mp); } int @@ -465,11 +465,11 @@ iommu_tlb_flushall(iommu_t *iommu_p) { int i; uint64_t base = (uint64_t)(iommu_p->iommu_ctrl_reg) - - COMMON_IOMMU_CTRL_REG_OFFSET; + COMMON_IOMMU_CTRL_REG_OFFSET; volatile uint64_t *tlb_tag = (volatile uint64_t *) - (base + COMMON_IOMMU_TLB_TAG_DIAG_ACC_OFFSET); + (base + COMMON_IOMMU_TLB_TAG_DIAG_ACC_OFFSET); volatile uint64_t *tlb_data = (volatile uint64_t *) - (base + COMMON_IOMMU_TLB_DATA_DIAG_ACC_OFFSET); + (base + COMMON_IOMMU_TLB_DATA_DIAG_ACC_OFFSET); for (i = 0; i < IOMMU_TLB_ENTRIES; i++) tlb_tag[i] = tlb_data[i] = 0ull; } @@ -486,32 +486,32 @@ iommu_preserve_tsb(iommu_t *iommu_p) uint64_t *base_tte_addr; DEBUG3(DBG_ATTACH, dip, - "iommu_tsb_base_addr_reg=0x%08x (0x%08x.0x%08x)\n", - iommu_p->iommu_tsb_base_addr_reg, - (uint32_t)(*iommu_p->iommu_tsb_base_addr_reg >> 32), - (uint32_t)(*iommu_p->iommu_tsb_base_addr_reg & 0xffffffff)); + "iommu_tsb_base_addr_reg=0x%08x (0x%08x.0x%08x)\n", + iommu_p->iommu_tsb_base_addr_reg, + (uint32_t)(*iommu_p->iommu_tsb_base_addr_reg >> 32), + (uint32_t)(*iommu_p->iommu_tsb_base_addr_reg & 0xffffffff)); obp_tsb_size = IOMMU_CTL_TO_TSBSIZE(ctl); obp_tsb_entries = IOMMU_TSBSIZE_TO_TSBENTRIES(obp_tsb_size); base_pg_index = iommu_p->dvma_end_pg - obp_tsb_entries + 1; base_tte_addr = iommu_p->iommu_tsb_vaddr + - (iommu_p->iommu_tsb_entries - obp_tsb_entries); + (iommu_p->iommu_tsb_entries - obp_tsb_entries); /* * old darwin prom does not set tsb size correctly, bail out. */ if ((obp_tsb_size == IOMMU_DARWIN_BOGUS_TSBSIZE) && - (CHIP_TYPE(iommu_p->iommu_pci_p) == PCI_CHIP_SABRE)) - return; + (CHIP_TYPE(iommu_p->iommu_pci_p) == PCI_CHIP_SABRE)) + return; DEBUG3(DBG_ATTACH, dip, "iommu_preserve_tsb: kernel info\n" - "iommu_tsb_vaddr=%08x copy to base_tte_addr=%08x " - "base_pg_index=%x\n", iommu_p->iommu_tsb_vaddr, - base_tte_addr, base_pg_index); + "iommu_tsb_vaddr=%08x copy to base_tte_addr=%08x " + "base_pg_index=%x\n", iommu_p->iommu_tsb_vaddr, + base_tte_addr, base_pg_index); DEBUG3(DBG_ATTACH | DBG_CONT, dip, "iommu_preserve_tsb: obp info " - "obp_tsb_entries=0x%x obp_tsb_pa=%08x.%08x\n", obp_tsb_entries, - (uint32_t)(obp_tsb_pa >> 32), (uint32_t)obp_tsb_pa); + "obp_tsb_entries=0x%x obp_tsb_pa=%08x.%08x\n", obp_tsb_entries, + (uint32_t)(obp_tsb_pa >> 32), (uint32_t)obp_tsb_pa); for (i = 0; i < obp_tsb_entries; i++) { uint64_t tte = lddphys(obp_tsb_pa + i * 8); @@ -524,8 +524,8 @@ iommu_preserve_tsb(iommu_t *iommu_p) base_tte_addr[i] = tte; DEBUG3(DBG_ATTACH | DBG_CONT, dip, - "\npreserve_tsb: (%x)=%08x.%08x\n", base_tte_addr + i, - (uint_t)(tte >> 32), (uint_t)(tte & 0xffffffff)); + "\npreserve_tsb: (%x)=%08x.%08x\n", base_tte_addr + i, + (uint_t)(tte >> 32), (uint_t)(tte & 0xffffffff)); /* * permanantly reserve this page from dvma address space @@ -534,7 +534,7 @@ iommu_preserve_tsb(iommu_t *iommu_p) va = (caddr_t)(IOMMU_PTOB(base_pg_index + i)); (void) vmem_xalloc(iommu_p->iommu_dvma_map, IOMMU_PAGE_SIZE, - IOMMU_PAGE_SIZE, 0, 0, va, va + IOMMU_PAGE_SIZE, - VM_NOSLEEP | VM_BESTFIT | VM_PANIC); + IOMMU_PAGE_SIZE, 0, 0, va, va + IOMMU_PAGE_SIZE, + VM_NOSLEEP | VM_BESTFIT | VM_PANIC); } } diff --git a/usr/src/uts/sun4u/io/pci/pci_pci.c b/usr/src/uts/sun4u/io/pci/pci_pci.c index 0196c3d2b4..8ec953f18b 100644 --- a/usr/src/uts/sun4u/io/pci/pci_pci.c +++ b/usr/src/uts/sun4u/io/pci/pci_pci.c @@ -22,9 +22,6 @@ * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* * Sun4u PCI to PCI bus bridge nexus driver @@ -111,7 +108,7 @@ struct bus_ops ppb_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/io/pci/simba.c b/usr/src/uts/sun4u/io/pci/simba.c index fbce93e6a6..480117ce24 100644 --- a/usr/src/uts/sun4u/io/pci/simba.c +++ b/usr/src/uts/sun4u/io/pci/simba.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ /* @@ -126,7 +123,7 @@ struct bus_ops simba_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/io/pmubus.c b/usr/src/uts/sun4u/io/pmubus.c index 66a969c698..502ace5b73 100644 --- a/usr/src/uts/sun4u/io/pmubus.c +++ b/usr/src/uts/sun4u/io/pmubus.c @@ -22,9 +22,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> @@ -98,7 +95,7 @@ static struct bus_ops pmubus_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/io/sysiosbus.c b/usr/src/uts/sun4u/io/sysiosbus.c index 71ec224b19..fbfde87d14 100644 --- a/usr/src/uts/sun4u/io/sysiosbus.c +++ b/usr/src/uts/sun4u/io/sysiosbus.c @@ -23,9 +23,6 @@ * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> #include <sys/conf.h> @@ -311,7 +308,7 @@ static struct bus_ops sbus_bus_ops = { 0, 0, i_ddi_map_fault, - 0, + iommu_dma_map, iommu_dma_allochdl, iommu_dma_freehdl, iommu_dma_bindhdl, diff --git a/usr/src/uts/sun4u/montecarlo/io/acebus.c b/usr/src/uts/sun4u/montecarlo/io/acebus.c index f1c92ea5b2..5c7ffcf8ba 100644 --- a/usr/src/uts/sun4u/montecarlo/io/acebus.c +++ b/usr/src/uts/sun4u/montecarlo/io/acebus.c @@ -23,9 +23,6 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> @@ -102,7 +99,7 @@ static struct bus_ops acebus_bus_ops = { NULL, NULL, i_ddi_map_fault, - NULL, + ddi_dma_map, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/serengeti/io/ssm.c b/usr/src/uts/sun4u/serengeti/io/ssm.c index ccd68ed9b5..4aba952a86 100644 --- a/usr/src/uts/sun4u/serengeti/io/ssm.c +++ b/usr/src/uts/sun4u/serengeti/io/ssm.c @@ -23,9 +23,6 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #include <sys/types.h> #include <sys/conf.h> #include <sys/ddi.h> @@ -164,7 +161,7 @@ static struct bus_ops ssm_bus_ops = { 0, /* add_intrspec */ 0, /* remove_intrspec */ i_ddi_map_fault, /* map_fault */ - 0, /* dma_map */ + ddi_dma_map, /* dma_map */ ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, diff --git a/usr/src/uts/sun4u/sys/iommu.h b/usr/src/uts/sun4u/sys/iommu.h index f2731f4699..947427280d 100644 --- a/usr/src/uts/sun4u/sys/iommu.h +++ b/usr/src/uts/sun4u/sys/iommu.h @@ -23,13 +23,12 @@ * Copyright (c) 1991-2000 by Sun Microsystems, Inc. * All rights reserved. */ -/* - * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. - */ #ifndef _SYS_IOMMU_H #define _SYS_IOMMU_H +#pragma ident "%Z%%M% %I% %E% SMI" + #if defined(_KERNEL) && !defined(_ASM) #include <sys/sunddi.h> #include <sys/sysiosbus.h> @@ -132,6 +131,8 @@ extern int iommu_init(struct sbus_soft_state *, caddr_t); extern int iommu_resume_init(struct sbus_soft_state *); extern int iommu_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops, off_t *, size_t *, caddr_t *, uint_t); +extern int iommu_dma_map(dev_info_t *, dev_info_t *, struct ddi_dma_req *, + ddi_dma_handle_t *); extern int iommu_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *); extern int iommu_dma_freehdl(dev_info_t *, dev_info_t *, ddi_dma_handle_t); |
