#include <sys/sysmacros.h>
#include <sys/conf.h>
#include <sys/autoconf.h>
#include <sys/sysmacros.h>
#include <sys/debug.h>
#include <sys/psw.h>
#include <sys/ddidmareq.h>
#include <sys/promif.h>
#include <sys/devops.h>
#include <sys/kmem.h>
#include <sys/cmn_err.h>
#include <vm/seg.h>
#include <vm/seg_kmem.h>
#include <vm/seg_dev.h>
#include <sys/vmem.h>
#include <sys/mman.h>
#include <vm/hat.h>
#include <vm/as.h>
#include <vm/page.h>
#include <sys/avintr.h>
#include <sys/errno.h>
#include <sys/modctl.h>
#include <sys/ddi_impldefs.h>
#include <sys/sunddi.h>
#include <sys/sunndi.h>
#include <sys/mach_intr.h>
#include <sys/psm.h>
#include <sys/ontrap.h>
#include <sys/atomic.h>
#include <sys/sdt.h>
#include <sys/rootnex.h>
#include <vm/hat_i86.h>
#include <sys/ddifm.h>
#include <sys/ddi_isa.h>
#include <sys/apic.h>
#ifdef __xpv
#include <sys/bootinfo.h>
#include <sys/hypervisor.h>
#include <sys/bootconf.h>
#include <vm/kboot_mmu.h>
#endif
#if !defined(__xpv)
#include <sys/immu.h>
#endif
#ifdef DEBUG
int rootnex_alloc_check_parms = 1;
int rootnex_bind_check_inuse = 1;
int rootnex_unbind_verify_buffer = 0;
int rootnex_sync_check_parms = 1;
#else
int rootnex_alloc_check_parms = 0;
int rootnex_bind_check_inuse = 0;
int rootnex_unbind_verify_buffer = 0;
int rootnex_sync_check_parms = 0;
#endif
boolean_t rootnex_dmar_not_setup;
int rootnex_fm_ma_ta_panic_flag = 0;
int rootnex_bind_fail = 1;
int rootnex_bind_warn = 1;
uint8_t *rootnex_warn_list;
#define ROOTNEX_BIND_WARNING (0x1 << 0)
int rootnex_sync_ignore_params = 0;
int rootnex_prealloc_cookies = 65;
int rootnex_prealloc_windows = 4;
int rootnex_prealloc_copybuf = 2;
static rootnex_state_t *rootnex_state;
#ifdef DEBUG
static uint64_t *rootnex_cnt;
#endif
static rootnex_intprop_t rootnex_intprp[] = {
{ "PAGESIZE", PAGESIZE },
{ "MMU_PAGESIZE", MMU_PAGESIZE },
{ "MMU_PAGEOFFSET", MMU_PAGEOFFSET },
{ DDI_RELATIVE_ADDRESSING, 1 },
};
#define NROOT_INTPROPS (sizeof (rootnex_intprp) / sizeof (rootnex_intprop_t))
#ifdef __xpv
typedef maddr_t rootnex_addr_t;
#define ROOTNEX_PADDR_TO_RBASE(pa) \
(DOMAIN_IS_INITDOMAIN(xen_info) ? pa_to_ma(pa) : (pa))
#else
typedef paddr_t rootnex_addr_t;
#define ROOTNEX_PADDR_TO_RBASE(pa) (pa)
#endif
static struct cb_ops rootnex_cb_ops = {
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nodev,
nochpoll,
ddi_prop_op,
NULL,
D_NEW | D_MP | D_HOTPLUG,
CB_REV,
nodev,
nodev
};
static int rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
off_t offset, off_t len, caddr_t *vaddrp);
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_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);
static int rootnex_dma_freehdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle);
static int rootnex_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
ddi_dma_cookie_t *cookiep, uint_t *ccountp);
static int rootnex_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle);
static int rootnex_dma_sync(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags);
static int rootnex_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);
static int 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 *objp, uint_t cache_flags);
static int rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip,
ddi_ctl_enum_t ctlop, void *arg, void *result);
static int rootnex_fm_init(dev_info_t *dip, dev_info_t *tdip, int tcap,
ddi_iblock_cookie_t *ibc);
static int rootnex_intr_ops(dev_info_t *pdip, dev_info_t *rdip,
ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result);
static int rootnex_alloc_intr_fixed(dev_info_t *, ddi_intr_handle_impl_t *,
void *);
static int rootnex_free_intr_fixed(dev_info_t *, ddi_intr_handle_impl_t *);
static int rootnex_coredma_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);
static int rootnex_coredma_freehdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle);
static int rootnex_coredma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
ddi_dma_cookie_t *cookiep, uint_t *ccountp);
static int rootnex_coredma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle);
#if !defined(__xpv)
static void rootnex_coredma_reset_cookies(dev_info_t *dip,
ddi_dma_handle_t handle);
static int rootnex_coredma_get_cookies(dev_info_t *dip, ddi_dma_handle_t handle,
ddi_dma_cookie_t **cookiepp, uint_t *ccountp);
static int rootnex_coredma_set_cookies(dev_info_t *dip, ddi_dma_handle_t handle,
ddi_dma_cookie_t *cookiep, uint_t ccount);
static int rootnex_coredma_clear_cookies(dev_info_t *dip,
ddi_dma_handle_t handle);
static int rootnex_coredma_get_sleep_flags(ddi_dma_handle_t handle);
#endif
static int rootnex_coredma_sync(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags);
static int rootnex_coredma_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);
#if !defined(__xpv)
static int rootnex_coredma_hdl_setprivate(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, void *v);
static void *rootnex_coredma_hdl_getprivate(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle);
#endif
static struct bus_ops rootnex_bus_ops = {
BUSO_REV,
rootnex_map,
NULL,
NULL,
NULL,
rootnex_map_fault,
0,
rootnex_dma_allochdl,
rootnex_dma_freehdl,
rootnex_dma_bindhdl,
rootnex_dma_unbindhdl,
rootnex_dma_sync,
rootnex_dma_win,
rootnex_dma_mctl,
rootnex_ctlops,
ddi_bus_prop_op,
i_ddi_rootnex_get_eventcookie,
i_ddi_rootnex_add_eventcall,
i_ddi_rootnex_remove_eventcall,
i_ddi_rootnex_post_event,
0,
0,
0,
rootnex_fm_init,
NULL,
NULL,
NULL,
NULL,
rootnex_intr_ops
};
static int rootnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
static int rootnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
static int rootnex_quiesce(dev_info_t *dip);
static struct dev_ops rootnex_ops = {
DEVO_REV,
0,
ddi_no_info,
nulldev,
nulldev,
rootnex_attach,
rootnex_detach,
nulldev,
&rootnex_cb_ops,
&rootnex_bus_ops,
NULL,
rootnex_quiesce,
};
static struct modldrv rootnex_modldrv = {
&mod_driverops,
"i86pc root nexus",
&rootnex_ops
};
static struct modlinkage rootnex_modlinkage = {
MODREV_1,
(void *)&rootnex_modldrv,
NULL
};
#if !defined(__xpv)
static iommulib_nexops_t iommulib_nexops = {
IOMMU_NEXOPS_VERSION,
"Rootnex IOMMU ops Vers 1.1",
NULL,
rootnex_coredma_allochdl,
rootnex_coredma_freehdl,
rootnex_coredma_bindhdl,
rootnex_coredma_unbindhdl,
rootnex_coredma_reset_cookies,
rootnex_coredma_get_cookies,
rootnex_coredma_set_cookies,
rootnex_coredma_clear_cookies,
rootnex_coredma_get_sleep_flags,
rootnex_coredma_sync,
rootnex_coredma_win,
rootnex_coredma_hdl_setprivate,
rootnex_coredma_hdl_getprivate
};
#endif
extern struct seg_ops segdev_ops;
extern int ignore_hardware_nodes;
#ifdef DDI_MAP_DEBUG
extern int ddi_map_debug_flag;
#define ddi_map_debug if (ddi_map_debug_flag) prom_printf
#endif
extern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *,
psm_intr_op_t, int *);
extern int impl_ddi_sunbus_initchild(dev_info_t *dip);
extern void impl_ddi_sunbus_removechild(dev_info_t *dip);
extern void *device_arena_alloc(size_t size, int vm_flag);
extern void device_arena_free(void * vaddr, size_t size);
static int rootnex_dma_init();
static void rootnex_add_props(dev_info_t *);
static int rootnex_ctl_reportdev(dev_info_t *dip);
static struct intrspec *rootnex_get_ispec(dev_info_t *rdip, int inum);
static int rootnex_map_regspec(ddi_map_req_t *mp, caddr_t *vaddrp);
static int rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp);
static int rootnex_map_handle(ddi_map_req_t *mp);
static void rootnex_clean_dmahdl(ddi_dma_impl_t *hp);
static int rootnex_valid_alloc_parms(ddi_dma_attr_t *attr, uint_t maxsegsize);
static void rootnex_get_sgl(ddi_dma_obj_t *dmar_object, ddi_dma_cookie_t *sgl,
rootnex_sglinfo_t *sglinfo);
static void rootnex_dvma_get_sgl(ddi_dma_obj_t *dmar_object,
ddi_dma_cookie_t *sgl, rootnex_sglinfo_t *sglinfo);
static int rootnex_bind_slowpath(ddi_dma_impl_t *hp, struct ddi_dma_req *dmareq,
rootnex_dma_t *dma, ddi_dma_attr_t *attr, ddi_dma_obj_t *dmao, int kmflag);
static int rootnex_setup_copybuf(ddi_dma_impl_t *hp, struct ddi_dma_req *dmareq,
rootnex_dma_t *dma, ddi_dma_attr_t *attr);
static void rootnex_teardown_copybuf(rootnex_dma_t *dma);
static int rootnex_setup_windows(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
ddi_dma_attr_t *attr, ddi_dma_obj_t *dmao, int kmflag);
static void rootnex_teardown_windows(rootnex_dma_t *dma);
static void rootnex_init_win(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
rootnex_window_t *window, ddi_dma_cookie_t *cookie, off_t cur_offset);
static void rootnex_setup_cookie(ddi_dma_obj_t *dmar_object,
rootnex_dma_t *dma, ddi_dma_cookie_t *cookie, off_t cur_offset,
size_t *copybuf_used, page_t **cur_pp);
static int rootnex_sgllen_window_boundary(ddi_dma_impl_t *hp,
rootnex_dma_t *dma, rootnex_window_t **windowp, ddi_dma_cookie_t *cookie,
ddi_dma_attr_t *attr, off_t cur_offset);
static int rootnex_copybuf_window_boundary(ddi_dma_impl_t *hp,
rootnex_dma_t *dma, rootnex_window_t **windowp,
ddi_dma_cookie_t *cookie, off_t cur_offset, size_t *copybuf_used);
static int rootnex_maxxfer_window_boundary(ddi_dma_impl_t *hp,
rootnex_dma_t *dma, rootnex_window_t **windowp, ddi_dma_cookie_t *cookie);
static int rootnex_valid_sync_parms(ddi_dma_impl_t *hp, rootnex_window_t *win,
off_t offset, size_t size, uint_t cache_flags);
static int rootnex_verify_buffer(rootnex_dma_t *dma);
static int rootnex_dma_check(dev_info_t *dip, const void *handle,
const void *comp_addr, const void *not_used);
static boolean_t rootnex_need_bounce_seg(ddi_dma_obj_t *dmar_object,
rootnex_sglinfo_t *sglinfo);
static struct as *rootnex_get_as(ddi_dma_obj_t *dmar_object);
int
_init(void)
{
rootnex_state = NULL;
return (mod_install(&rootnex_modlinkage));
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&rootnex_modlinkage, modinfop));
}
int
_fini(void)
{
return (EBUSY);
}
static int
rootnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
int fmcap;
int e;
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
#if !defined(__xpv)
return (immu_unquiesce());
#else
return (DDI_SUCCESS);
#endif
default:
return (DDI_FAILURE);
}
ASSERT(rootnex_state == NULL);
rootnex_state = kmem_zalloc(sizeof (rootnex_state_t), KM_SLEEP);
rootnex_state->r_dip = dip;
rootnex_state->r_err_ibc = (ddi_iblock_cookie_t)ipltospl(15);
rootnex_state->r_reserved_msg_printed = B_FALSE;
#ifdef DEBUG
rootnex_cnt = &rootnex_state->r_counters[0];
#endif
ddi_system_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
fmcap = ddi_system_fmcap;
ddi_fm_init(dip, &fmcap, &rootnex_state->r_err_ibc);
e = rootnex_dma_init();
if (e != DDI_SUCCESS) {
kmem_free(rootnex_state, sizeof (rootnex_state_t));
return (DDI_FAILURE);
}
rootnex_add_props(dip);
cmn_err(CE_CONT, "?root nexus = %s\n", ddi_get_name(dip));
i_ddi_rootnex_init_events(dip);
#if !defined(__xpv)
e = iommulib_nexus_register(dip, &iommulib_nexops,
&rootnex_state->r_iommulib_handle);
ASSERT(e == DDI_SUCCESS);
#endif
return (DDI_SUCCESS);
}
static int
rootnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
switch (cmd) {
case DDI_SUSPEND:
#if !defined(__xpv)
return (immu_quiesce());
#else
return (DDI_SUCCESS);
#endif
default:
return (DDI_FAILURE);
}
}
static int
rootnex_dma_init()
{
size_t bufsize;
rootnex_state->r_prealloc_cookies = rootnex_prealloc_cookies;
rootnex_state->r_prealloc_size =
(rootnex_state->r_prealloc_cookies * sizeof (ddi_dma_cookie_t)) +
(rootnex_prealloc_windows * sizeof (rootnex_window_t)) +
(rootnex_prealloc_copybuf * sizeof (rootnex_pgmap_t));
bufsize = sizeof (ddi_dma_impl_t) + sizeof (rootnex_dma_t) +
rootnex_state->r_prealloc_size + 0x10;
rootnex_state->r_dmahdl_cache = kmem_cache_create("rootnex_dmahdl",
bufsize, 64, NULL, NULL, NULL, NULL, NULL, 0);
if (rootnex_state->r_dmahdl_cache == NULL) {
return (DDI_FAILURE);
}
rootnex_warn_list = kmem_zalloc(devcnt * sizeof (*rootnex_warn_list),
KM_SLEEP);
return (DDI_SUCCESS);
}
static void
rootnex_add_props(dev_info_t *dip)
{
rootnex_intprop_t *rpp;
int i;
rpp = rootnex_intprp;
for (i = 0; i < NROOT_INTPROPS; i++) {
(void) e_ddi_prop_update_int(DDI_DEV_T_NONE, dip,
rpp[i].prop_name, rpp[i].prop_value);
}
}
static int
rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop,
void *arg, void *result)
{
int n, *ptr;
struct ddi_parent_private_data *pdp;
switch (ctlop) {
case DDI_CTLOPS_DMAPMAPC:
return (DDI_DMA_PARTIAL);
case DDI_CTLOPS_BTOP:
*(ulong_t *)result = btop(*(ulong_t *)arg);
return (DDI_SUCCESS);
case DDI_CTLOPS_PTOB:
*(ulong_t *)result = ptob(*(ulong_t *)arg);
return (DDI_SUCCESS);
case DDI_CTLOPS_BTOPR:
*(ulong_t *)result = btopr(*(ulong_t *)arg);
return (DDI_SUCCESS);
case DDI_CTLOPS_INITCHILD:
return (impl_ddi_sunbus_initchild(arg));
case DDI_CTLOPS_UNINITCHILD:
impl_ddi_sunbus_removechild(arg);
return (DDI_SUCCESS);
case DDI_CTLOPS_REPORTDEV:
return (rootnex_ctl_reportdev(rdip));
case DDI_CTLOPS_IOMIN:
return (DDI_SUCCESS);
case DDI_CTLOPS_REGSIZE:
case DDI_CTLOPS_NREGS:
break;
case DDI_CTLOPS_SIDDEV:
if (ndi_dev_is_prom_node(rdip))
return (DDI_SUCCESS);
if (ndi_dev_is_persistent_node(rdip))
return (DDI_SUCCESS);
return (DDI_FAILURE);
case DDI_CTLOPS_POWER:
return ((*pm_platform_power)((power_req_t *)arg));
case DDI_CTLOPS_RESERVED0:
case DDI_CTLOPS_RESERVED1:
case DDI_CTLOPS_RESERVED2:
case DDI_CTLOPS_RESERVED3:
case DDI_CTLOPS_RESERVED4:
case DDI_CTLOPS_RESERVED5:
if (!rootnex_state->r_reserved_msg_printed) {
rootnex_state->r_reserved_msg_printed = B_TRUE;
cmn_err(CE_WARN, "Failing ddi_ctlops call(s) for "
"1 or more reserved/obsolete operations.");
}
return (DDI_FAILURE);
default:
return (DDI_FAILURE);
}
if ((pdp = ddi_get_parent_data(rdip)) == NULL)
return (DDI_FAILURE);
if (ctlop == DDI_CTLOPS_NREGS) {
ptr = (int *)result;
*ptr = pdp->par_nreg;
} else {
off_t *size = (off_t *)result;
ptr = (int *)arg;
n = *ptr;
if (n >= pdp->par_nreg) {
return (DDI_FAILURE);
}
*size = (off_t)pdp->par_reg[n].regspec_size;
}
return (DDI_SUCCESS);
}
static int
rootnex_ctl_reportdev(dev_info_t *dev)
{
int i, n, len, f_len = 0;
char *buf;
buf = kmem_alloc(REPORTDEV_BUFSIZE, KM_SLEEP);
f_len += snprintf(buf, REPORTDEV_BUFSIZE,
"%s%d at root", ddi_driver_name(dev), ddi_get_instance(dev));
len = strlen(buf);
for (i = 0; i < sparc_pd_getnreg(dev); i++) {
struct regspec *rp = sparc_pd_getreg(dev, i);
if (i == 0)
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
": ");
else
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
" and ");
len = strlen(buf);
switch (rp->regspec_bustype) {
case BTEISA:
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
"%s 0x%x", DEVI_EISA_NEXNAME, rp->regspec_addr);
break;
case BTISA:
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
"%s 0x%x", DEVI_ISA_NEXNAME, rp->regspec_addr);
break;
default:
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
"space %x offset %x",
rp->regspec_bustype, rp->regspec_addr);
break;
}
len = strlen(buf);
}
for (i = 0, n = sparc_pd_getnintr(dev); i < n; i++) {
int pri;
if (i != 0) {
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
",");
len = strlen(buf);
}
pri = INT_IPL(sparc_pd_getintr(dev, i)->intrspec_pri);
f_len += snprintf(buf + len, REPORTDEV_BUFSIZE - len,
" sparc ipl %d", pri);
len = strlen(buf);
}
#ifdef DEBUG
if (f_len + 1 >= REPORTDEV_BUFSIZE) {
cmn_err(CE_NOTE, "next message is truncated: "
"printed length 1024, real length %d", f_len);
}
#endif
cmn_err(CE_CONT, "?%s\n", buf);
kmem_free(buf, REPORTDEV_BUFSIZE);
return (DDI_SUCCESS);
}
static int
rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, off_t offset,
off_t len, caddr_t *vaddrp)
{
struct regspec *orp = NULL;
struct regspec64 rp = { 0 };
ddi_map_req_t mr = *mp;
mp = &mr;
switch (mp->map_op) {
case DDI_MO_MAP_LOCKED:
case DDI_MO_UNMAP:
case DDI_MO_MAP_HANDLE:
break;
default:
#ifdef DDI_MAP_DEBUG
cmn_err(CE_WARN, "rootnex_map: unimplemented map op %d.",
mp->map_op);
#endif
return (DDI_ME_UNIMPLEMENTED);
}
if (mp->map_flags & DDI_MF_USER_MAPPING) {
#ifdef DDI_MAP_DEBUG
cmn_err(CE_WARN, "rootnex_map: unimplemented map type: user.");
#endif
return (DDI_ME_UNIMPLEMENTED);
}
if (mp->map_type == DDI_MT_RNUMBER) {
int rnumber = mp->map_obj.rnumber;
#ifdef DDI_MAP_DEBUG
static char *out_of_range =
"rootnex_map: Out of range rnumber <%d>, device <%s>";
#endif
orp = i_ddi_rnumber_to_regspec(rdip, rnumber);
if (orp == NULL) {
#ifdef DDI_MAP_DEBUG
cmn_err(CE_WARN, out_of_range, rnumber,
ddi_get_name(rdip));
#endif
return (DDI_ME_RNUMBER_RANGE);
}
} else if (!(mp->map_flags & DDI_MF_EXT_REGSPEC)) {
orp = mp->map_obj.rp;
}
if (orp != NULL) {
rp.regspec_bustype = orp->regspec_bustype;
rp.regspec_addr = orp->regspec_addr;
rp.regspec_size = orp->regspec_size;
} else {
struct regspec64 *rp64;
rp64 = (struct regspec64 *)mp->map_obj.rp;
rp = *rp64;
}
mp->map_type = DDI_MT_REGSPEC;
mp->map_flags |= DDI_MF_EXT_REGSPEC;
mp->map_obj.rp = (struct regspec *)&rp;
#ifdef DDI_MAP_DEBUG
cmn_err(CE_CONT, "rootnex: <%s,%s> <0x%x, 0x%x, 0x%d> offset %d len %d "
"handle 0x%x\n", ddi_get_name(dip), ddi_get_name(rdip),
rp.regspec_bustype, rp.regspec_addr, rp.regspec_size, offset,
len, mp->map_handlep);
#endif
if (rp.regspec_bustype > 1 && rp.regspec_addr != 0) {
cmn_err(CE_WARN, "<%s,%s> invalid register spec"
" <0x%" PRIx64 ", 0x%" PRIx64 ", 0x%" PRIx64 ">",
ddi_get_name(dip), ddi_get_name(rdip), rp.regspec_bustype,
rp.regspec_addr, rp.regspec_size);
return (DDI_ME_INVAL);
}
if (rp.regspec_bustype > 1 && rp.regspec_addr == 0) {
rp.regspec_bustype += offset;
} else {
rp.regspec_addr += offset;
}
if (len != 0)
rp.regspec_size = len;
#ifdef DDI_MAP_DEBUG
cmn_err(CE_CONT, " <%s,%s> <0x%" PRIx64 ", 0x%" PRIx64
", 0x%" PRId64 "> offset %d len %d handle 0x%x\n",
ddi_get_name(dip), ddi_get_name(rdip), rp.regspec_bustype,
rp.regspec_addr, rp.regspec_size, offset, len, mp->map_handlep);
#endif
ASSERT0(sparc_pd_getnrng(dip));
switch (mp->map_op) {
case DDI_MO_MAP_LOCKED:
return (rootnex_map_regspec(mp, vaddrp));
case DDI_MO_UNMAP:
return (rootnex_unmap_regspec(mp, vaddrp));
case DDI_MO_MAP_HANDLE:
return (rootnex_map_handle(mp));
default:
return (DDI_ME_UNIMPLEMENTED);
}
}
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)
{
#ifdef DDI_MAP_DEBUG
ddi_map_debug("rootnex_map_fault: address <%x> pfn <%x>", addr, pfn);
ddi_map_debug(" Seg <%s>\n",
seg->s_ops == &segdev_ops ? "segdev" :
seg == &kvseg ? "segkmem" : "NONE!");
#endif
if (seg->s_ops == &segdev_ops) {
struct segdev_data *sdp = (struct segdev_data *)seg->s_data;
if (hat == NULL) {
ASSERT(AS_READ_HELD(seg->s_as));
hat = seg->s_as->a_hat;
cmn_err(CE_NOTE, "rootnex_map_fault: nil hat");
}
hat_devload(hat, addr, MMU_PAGESIZE, pfn, prot | sdp->hat_attr,
(lock ? HAT_LOAD_LOCK : HAT_LOAD));
} else if (seg == &kvseg && dp == NULL) {
hat_devload(kas.a_hat, addr, MMU_PAGESIZE, pfn, prot,
HAT_LOAD_LOCK);
} else
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
static int
rootnex_map_regspec(ddi_map_req_t *mp, caddr_t *vaddrp)
{
rootnex_addr_t rbase;
void *cvaddr;
uint64_t npages, pgoffset;
struct regspec64 *rp;
ddi_acc_hdl_t *hp;
ddi_acc_impl_t *ap;
uint_t hat_acc_flags;
paddr_t pbase;
ASSERT(mp->map_flags & DDI_MF_EXT_REGSPEC);
rp = (struct regspec64 *)mp->map_obj.rp;
hp = mp->map_handlep;
#ifdef DDI_MAP_DEBUG
ddi_map_debug(
"rootnex_map_regspec: <0x%x 0x%x 0x%x> handle 0x%x\n",
rp->regspec_bustype, rp->regspec_addr,
rp->regspec_size, mp->map_handlep);
#endif
if (rp->regspec_bustype > 1 && rp->regspec_addr != 0) {
cmn_err(CE_WARN, "rootnex: invalid register spec"
" <0x%" PRIx64 ", 0x%" PRIx64", 0x%" PRIx64">",
rp->regspec_bustype, rp->regspec_addr, rp->regspec_size);
return (DDI_FAILURE);
}
if (rp->regspec_bustype != 0) {
if (hp == NULL) {
return (DDI_FAILURE);
}
ap = (ddi_acc_impl_t *)hp->ah_platform_private;
ap->ahi_acc_attr |= DDI_ACCATTR_IO_SPACE;
impl_acc_hdl_init(hp);
if (mp->map_flags & DDI_MF_DEVICE_MAPPING) {
#ifdef DDI_MAP_DEBUG
ddi_map_debug("rootnex_map_regspec: mmap() "
"to I/O space is not supported.\n");
#endif
return (DDI_ME_INVAL);
} else {
*vaddrp =
(rp->regspec_bustype > 1 && rp->regspec_addr == 0) ?
((caddr_t)(uintptr_t)rp->regspec_bustype) :
((caddr_t)(uintptr_t)rp->regspec_addr);
#ifdef __xpv
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
hp->ah_pfn = xen_assign_pfn(
mmu_btop((ulong_t)rp->regspec_addr &
MMU_PAGEMASK));
} else {
hp->ah_pfn = mmu_btop(
(ulong_t)rp->regspec_addr & MMU_PAGEMASK);
}
#else
hp->ah_pfn = mmu_btop((ulong_t)rp->regspec_addr &
MMU_PAGEMASK);
#endif
hp->ah_pnum = mmu_btopr(rp->regspec_size +
(ulong_t)rp->regspec_addr & MMU_PAGEOFFSET);
}
#ifdef DDI_MAP_DEBUG
ddi_map_debug(
"rootnex_map_regspec: \"Mapping\" %d bytes I/O space at 0x%x\n",
rp->regspec_size, *vaddrp);
#endif
return (DDI_SUCCESS);
}
if (hp != NULL) {
switch (hp->ah_acc.devacc_attr_dataorder) {
case DDI_STRICTORDER_ACC:
hat_acc_flags = HAT_STRICTORDER;
break;
case DDI_UNORDERED_OK_ACC:
hat_acc_flags = HAT_UNORDERED_OK;
break;
case DDI_MERGING_OK_ACC:
hat_acc_flags = HAT_MERGING_OK;
break;
case DDI_LOADCACHING_OK_ACC:
hat_acc_flags = HAT_LOADCACHING_OK;
break;
case DDI_STORECACHING_OK_ACC:
hat_acc_flags = HAT_STORECACHING_OK;
break;
default:
return (DDI_ME_INVAL);
}
ap = (ddi_acc_impl_t *)hp->ah_platform_private;
ap->ahi_acc_attr |= DDI_ACCATTR_CPU_VADDR;
impl_acc_hdl_init(hp);
hp->ah_hat_flags = hat_acc_flags;
} else {
hat_acc_flags = HAT_STRICTORDER;
}
rbase = (rootnex_addr_t)(rp->regspec_addr & MMU_PAGEMASK);
#ifdef __xpv
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
pbase = pfn_to_pa(xen_assign_pfn(mmu_btop(rbase)));
} else {
pbase = rbase;
}
#else
pbase = rbase;
#endif
pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET;
if (rp->regspec_size == 0) {
#ifdef DDI_MAP_DEBUG
ddi_map_debug("rootnex_map_regspec: zero regspec_size\n");
#endif
return (DDI_ME_INVAL);
}
if (mp->map_flags & DDI_MF_DEVICE_MAPPING) {
*vaddrp = (caddr_t)((uintptr_t)mmu_btop(pbase));
} else {
npages = mmu_btopr(rp->regspec_size + pgoffset);
#ifdef DDI_MAP_DEBUG
ddi_map_debug("rootnex_map_regspec: Mapping %d pages "
"physical %llx", npages, pbase);
#endif
cvaddr = device_arena_alloc(ptob(npages), VM_NOSLEEP);
if (cvaddr == NULL)
return (DDI_ME_NORESOURCES);
hat_devload(kas.a_hat, cvaddr, mmu_ptob(npages),
mmu_btop(pbase), mp->map_prot | hat_acc_flags,
HAT_LOAD_LOCK);
*vaddrp = (caddr_t)cvaddr + pgoffset;
hp = mp->map_handlep;
if (hp) {
hp->ah_pfn = mmu_btop(pbase);
hp->ah_pnum = npages;
}
}
#ifdef DDI_MAP_DEBUG
ddi_map_debug("at virtual 0x%x\n", *vaddrp);
#endif
return (DDI_SUCCESS);
}
static int
rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp)
{
caddr_t addr = (caddr_t)*vaddrp;
uint64_t npages, pgoffset;
struct regspec64 *rp;
if (mp->map_flags & DDI_MF_DEVICE_MAPPING)
return (0);
ASSERT(mp->map_flags & DDI_MF_EXT_REGSPEC);
rp = (struct regspec64 *)mp->map_obj.rp;
if (rp->regspec_size == 0) {
#ifdef DDI_MAP_DEBUG
ddi_map_debug("rootnex_unmap_regspec: zero regspec_size\n");
#endif
return (DDI_ME_INVAL);
}
if (rp->regspec_bustype != 0) {
return (DDI_SUCCESS);
}
pgoffset = (uintptr_t)addr & MMU_PAGEOFFSET;
npages = mmu_btopr(rp->regspec_size + pgoffset);
hat_unload(kas.a_hat, addr - pgoffset, ptob(npages), HAT_UNLOAD_UNLOCK);
device_arena_free(addr - pgoffset, ptob(npages));
*vaddrp = NULL;
return (DDI_SUCCESS);
}
static int
rootnex_map_handle(ddi_map_req_t *mp)
{
rootnex_addr_t rbase;
ddi_acc_hdl_t *hp;
uint64_t pgoffset;
struct regspec64 *rp;
paddr_t pbase;
rp = (struct regspec64 *)mp->map_obj.rp;
#ifdef DDI_MAP_DEBUG
ddi_map_debug(
"rootnex_map_handle: <0x%x 0x%x 0x%x> handle 0x%x\n",
rp->regspec_bustype, rp->regspec_addr,
rp->regspec_size, mp->map_handlep);
#endif
if (rp->regspec_bustype != 0) {
return (DDI_FAILURE);
}
hp = mp->map_handlep;
switch (hp->ah_acc.devacc_attr_endian_flags) {
case DDI_NEVERSWAP_ACC:
hp->ah_hat_flags = HAT_NEVERSWAP | HAT_STRICTORDER;
break;
case DDI_STRUCTURE_LE_ACC:
hp->ah_hat_flags = HAT_STRUCTURE_LE;
break;
case DDI_STRUCTURE_BE_ACC:
return (DDI_FAILURE);
default:
return (DDI_REGS_ACC_CONFLICT);
}
switch (hp->ah_acc.devacc_attr_dataorder) {
case DDI_STRICTORDER_ACC:
break;
case DDI_UNORDERED_OK_ACC:
hp->ah_hat_flags |= HAT_UNORDERED_OK;
break;
case DDI_MERGING_OK_ACC:
hp->ah_hat_flags |= HAT_MERGING_OK;
break;
case DDI_LOADCACHING_OK_ACC:
hp->ah_hat_flags |= HAT_LOADCACHING_OK;
break;
case DDI_STORECACHING_OK_ACC:
hp->ah_hat_flags |= HAT_STORECACHING_OK;
break;
default:
return (DDI_FAILURE);
}
rbase = (rootnex_addr_t)rp->regspec_addr &
(~(rootnex_addr_t)MMU_PAGEOFFSET);
pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET;
if (rp->regspec_size == 0)
return (DDI_ME_INVAL);
#ifdef __xpv
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
pbase = pfn_to_pa(xen_assign_pfn(mmu_btop(rbase))) |
(rbase & MMU_PAGEOFFSET);
} else {
pbase = rbase;
}
#else
pbase = rbase;
#endif
hp->ah_pfn = mmu_btop(pbase);
hp->ah_pnum = mmu_btopr(rp->regspec_size + pgoffset);
return (DDI_SUCCESS);
}
static int
rootnex_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
ddi_intr_handle_impl_t *hdlp, void *result)
{
struct intrspec *ispec;
DDI_INTR_NEXDBG((CE_CONT,
"rootnex_intr_ops: pdip = %p, rdip = %p, intr_op = %x, hdlp = %p\n",
(void *)pdip, (void *)rdip, intr_op, (void *)hdlp));
switch (intr_op) {
case DDI_INTROP_GETCAP:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_CAP, result)) {
*(int *)result = 0;
return (DDI_FAILURE);
}
break;
case DDI_INTROP_SETCAP:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_CAP, result))
return (DDI_FAILURE);
break;
case DDI_INTROP_ALLOC:
ASSERT(hdlp->ih_type == DDI_INTR_TYPE_FIXED);
return (rootnex_alloc_intr_fixed(rdip, hdlp, result));
case DDI_INTROP_FREE:
ASSERT(hdlp->ih_type == DDI_INTR_TYPE_FIXED);
return (rootnex_free_intr_fixed(rdip, hdlp));
case DDI_INTROP_GETPRI:
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
*(int *)result = ispec->intrspec_pri;
break;
case DDI_INTROP_SETPRI:
if (*(int *)result > LOCK_LEVEL)
return (DDI_FAILURE);
if ((psm_intr_ops == NULL) ||
((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL))
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_PRI, result) ==
PSM_FAILURE)
return (DDI_FAILURE);
ispec->intrspec_pri = *(int *)result;
break;
case DDI_INTROP_ADDISR:
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
ispec->intrspec_func = hdlp->ih_cb_func;
break;
case DDI_INTROP_REMISR:
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
ispec->intrspec_func = (uint_t (*)()) 0;
break;
case DDI_INTROP_ENABLE:
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR,
(int *)&hdlp->ih_vector) == PSM_FAILURE)
return (DDI_FAILURE);
if (!add_avintr((void *)hdlp, ispec->intrspec_pri,
hdlp->ih_cb_func, DEVI(rdip)->devi_name, hdlp->ih_vector,
hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, NULL, rdip))
return (DDI_FAILURE);
break;
case DDI_INTROP_DISABLE:
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
(void) (*psm_intr_ops)(rdip, hdlp,
PSM_INTR_OP_XLATE_VECTOR, (int *)&hdlp->ih_vector);
rem_avintr((void *)hdlp, ispec->intrspec_pri,
hdlp->ih_cb_func, hdlp->ih_vector);
break;
case DDI_INTROP_SETMASK:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_MASK, NULL))
return (DDI_FAILURE);
break;
case DDI_INTROP_CLRMASK:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_CLEAR_MASK, NULL))
return (DDI_FAILURE);
break;
case DDI_INTROP_GETPENDING:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_PENDING,
result)) {
*(int *)result = 0;
return (DDI_FAILURE);
}
break;
case DDI_INTROP_NAVAIL:
case DDI_INTROP_NINTRS:
*(int *)result = i_ddi_get_intx_nintrs(rdip);
if (*(int *)result == 0) {
if (strcmp(ddi_get_name(rdip), "pcic") == 0)
*(int *)result = 1;
else
return (DDI_FAILURE);
}
break;
case DDI_INTROP_SUPPORTED_TYPES:
*(int *)result = DDI_INTR_TYPE_FIXED;
break;
default:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static struct intrspec *
rootnex_get_ispec(dev_info_t *rdip, int inum)
{
struct ddi_parent_private_data *pdp = ddi_get_parent_data(rdip);
if (!pdp->par_intr && strcmp(ddi_get_name(rdip), "pcic") == 0) {
pdp->par_nintr = 1;
pdp->par_intr = kmem_zalloc(sizeof (struct intrspec) *
pdp->par_nintr, KM_SLEEP);
}
if (inum >= pdp->par_nintr)
return (NULL);
return ((struct intrspec *)&pdp->par_intr[inum]);
}
static int
rootnex_alloc_intr_fixed(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp,
void *result)
{
struct intrspec *ispec;
ddi_intr_handle_impl_t info_hdl;
int ret;
int free_phdl = 0;
apic_get_type_t type_info;
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
bzero(&info_hdl, sizeof (ddi_intr_handle_impl_t));
info_hdl.ih_private = &type_info;
if ((*psm_intr_ops)(NULL, &info_hdl, PSM_INTR_OP_APIC_TYPE, NULL) ==
PSM_SUCCESS && strcmp(type_info.avgi_type, APIC_APIX_NAME) == 0) {
if (hdlp->ih_private == NULL) {
free_phdl = 1;
i_ddi_alloc_intr_phdl(hdlp);
}
((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
ret = (*psm_intr_ops)(rdip, hdlp,
PSM_INTR_OP_ALLOC_VECTORS, result);
if (free_phdl) {
free_phdl = 0;
i_ddi_free_intr_phdl(hdlp);
hdlp->ih_private = NULL;
}
} else {
hdlp->ih_pri = ispec->intrspec_pri;
*(int *)result = hdlp->ih_scratch1;
ret = DDI_SUCCESS;
}
return (ret);
}
static int
rootnex_free_intr_fixed(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
{
struct intrspec *ispec;
struct ddi_parent_private_data *pdp;
ddi_intr_handle_impl_t info_hdl;
int ret;
apic_get_type_t type_info;
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
bzero(&info_hdl, sizeof (ddi_intr_handle_impl_t));
info_hdl.ih_private = &type_info;
if ((*psm_intr_ops)(NULL, &info_hdl, PSM_INTR_OP_APIC_TYPE, NULL) ==
PSM_SUCCESS && strcmp(type_info.avgi_type, APIC_APIX_NAME) == 0) {
if ((ispec = rootnex_get_ispec(rdip, hdlp->ih_inum)) == NULL)
return (DDI_FAILURE);
((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec;
ret = (*psm_intr_ops)(rdip, hdlp,
PSM_INTR_OP_FREE_VECTORS, NULL);
} else {
ret = DDI_SUCCESS;
}
pdp = ddi_get_parent_data(rdip);
if (pdp->par_intr && strcmp(ddi_get_name(rdip), "pcic") == 0) {
kmem_free(pdp->par_intr, sizeof (struct intrspec) *
pdp->par_nintr);
pdp->par_intr = NULL;
pdp->par_nintr = 0;
}
return (ret);
}
static int
rootnex_coredma_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)
{
uint64_t maxsegmentsize_ll;
uint_t maxsegmentsize;
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
uint64_t count_max;
uint64_t seg;
int kmflag;
int e;
if (waitfp == DDI_DMA_SLEEP) {
kmflag = KM_SLEEP;
} else {
kmflag = KM_NOSLEEP;
}
hp = kmem_cache_alloc(rootnex_state->r_dmahdl_cache, kmflag);
if (hp == NULL)
return (DDI_DMA_NORESOURCES);
hp->dmai_private = (void *)(((uintptr_t)hp +
(uintptr_t)sizeof (ddi_dma_impl_t) + 0x7) & ~0x7);
dma = (rootnex_dma_t *)hp->dmai_private;
dma->dp_prealloc_buffer = (uchar_t *)(((uintptr_t)dma +
sizeof (rootnex_dma_t) + 0x7) & ~0x7);
rootnex_clean_dmahdl(hp);
hp->dmai_error.err_fep = NULL;
hp->dmai_error.err_cf = NULL;
dma->dp_dip = rdip;
dma->dp_sglinfo.si_flags = attr->dma_attr_flags;
dma->dp_sglinfo.si_min_addr = attr->dma_attr_addr_lo;
if (IOMMU_USED(rdip) &&
(attr->dma_attr_flags & _DDI_DMA_BOUNCE_ON_SEG)) {
dma->dp_sglinfo.si_max_addr = attr->dma_attr_seg;
dma->dp_sglinfo.si_flags &= ~_DDI_DMA_BOUNCE_ON_SEG;
} else
dma->dp_sglinfo.si_max_addr = attr->dma_attr_addr_hi;
hp->dmai_minxfer = attr->dma_attr_minxfer;
hp->dmai_burstsizes = attr->dma_attr_burstsizes;
hp->dmai_rdip = rdip;
hp->dmai_attr = *attr;
if (attr->dma_attr_seg >= dma->dp_sglinfo.si_max_addr)
dma->dp_sglinfo.si_cancross = B_FALSE;
else
dma->dp_sglinfo.si_cancross = B_TRUE;
mutex_init(&dma->dp_mutex, NULL, MUTEX_DRIVER, NULL);
seg = attr->dma_attr_seg + 1;
if (seg < attr->dma_attr_seg) {
seg = attr->dma_attr_seg;
}
count_max = attr->dma_attr_count_max + 1;
if (count_max < attr->dma_attr_count_max) {
count_max = attr->dma_attr_count_max;
}
if (!ISP2(attr->dma_attr_granular)) {
dma->dp_granularity_power_2 = B_FALSE;
} else {
dma->dp_granularity_power_2 = B_TRUE;
}
if (attr->dma_attr_granular > 1) {
if (dma->dp_granularity_power_2) {
dma->dp_maxxfer = attr->dma_attr_maxxfer -
(attr->dma_attr_maxxfer &
(attr->dma_attr_granular - 1));
} else {
dma->dp_maxxfer = attr->dma_attr_maxxfer -
(attr->dma_attr_maxxfer % attr->dma_attr_granular);
}
} else {
dma->dp_maxxfer = attr->dma_attr_maxxfer;
}
maxsegmentsize_ll = MIN(seg, dma->dp_maxxfer);
maxsegmentsize_ll = MIN(maxsegmentsize_ll, count_max);
if (maxsegmentsize_ll == 0 || (maxsegmentsize_ll > 0xFFFFFFFF)) {
maxsegmentsize = 0xFFFFFFFF;
} else {
maxsegmentsize = maxsegmentsize_ll;
}
dma->dp_sglinfo.si_max_cookie_size = maxsegmentsize;
dma->dp_sglinfo.si_segmask = attr->dma_attr_seg;
if (rootnex_alloc_check_parms) {
e = rootnex_valid_alloc_parms(attr, maxsegmentsize);
if (e != DDI_SUCCESS) {
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_ALLOC_FAIL]);
(void) rootnex_dma_freehdl(dip, rdip,
(ddi_dma_handle_t)hp);
return (e);
}
}
*handlep = (ddi_dma_handle_t)hp;
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_ACTIVE_HDLS]);
ROOTNEX_DPROBE1(rootnex__alloc__handle, uint64_t,
rootnex_cnt[ROOTNEX_CNT_ACTIVE_HDLS]);
return (DDI_SUCCESS);
}
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)
{
int retval = DDI_SUCCESS;
#if !defined(__xpv)
if (IOMMU_UNITIALIZED(rdip)) {
retval = iommulib_nex_open(dip, rdip);
if (retval != DDI_SUCCESS && retval != DDI_ENOTSUP)
return (retval);
}
if (IOMMU_UNUSED(rdip)) {
retval = rootnex_coredma_allochdl(dip, rdip, attr, waitfp, arg,
handlep);
} else {
retval = iommulib_nexdma_allochdl(dip, rdip, attr,
waitfp, arg, handlep);
}
#else
retval = rootnex_coredma_allochdl(dip, rdip, attr, waitfp, arg,
handlep);
#endif
switch (retval) {
case DDI_DMA_NORESOURCES:
if (waitfp != DDI_DMA_DONTWAIT) {
ddi_set_callback(waitfp, arg,
&rootnex_state->r_dvma_call_list_id);
}
break;
case DDI_SUCCESS:
ndi_fmc_insert(rdip, DMA_HANDLE, *handlep, NULL);
break;
default:
break;
}
return (retval);
}
static int
rootnex_coredma_freehdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
ASSERT(!dma->dp_inuse);
mutex_destroy(&dma->dp_mutex);
kmem_cache_free(rootnex_state->r_dmahdl_cache, hp);
ROOTNEX_DPROF_DEC(&rootnex_cnt[ROOTNEX_CNT_ACTIVE_HDLS]);
ROOTNEX_DPROBE1(rootnex__free__handle, uint64_t,
rootnex_cnt[ROOTNEX_CNT_ACTIVE_HDLS]);
return (DDI_SUCCESS);
}
static int
rootnex_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
{
int ret;
ndi_fmc_remove(rdip, DMA_HANDLE, handle);
#if !defined(__xpv)
if (IOMMU_USED(rdip))
ret = iommulib_nexdma_freehdl(dip, rdip, handle);
else
#endif
ret = rootnex_coredma_freehdl(dip, rdip, handle);
if (rootnex_state->r_dvma_call_list_id)
ddi_run_callback(&rootnex_state->r_dvma_call_list_id);
return (ret);
}
static int
rootnex_coredma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
ddi_dma_cookie_t *cookiep, uint_t *ccountp)
{
rootnex_sglinfo_t *sinfo;
ddi_dma_obj_t *dmao;
#if !defined(__xpv)
struct dvmaseg *dvs;
ddi_dma_cookie_t *cookie;
#endif
ddi_dma_attr_t *attr;
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
int kmflag;
int e;
uint_t ncookies;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
dmao = &dma->dp_dma;
sinfo = &dma->dp_sglinfo;
attr = &hp->dmai_attr;
if (dmareq->dmar_fp == DDI_DMA_SLEEP) {
dma->dp_sleep_flags = kmflag = KM_SLEEP;
} else {
dma->dp_sleep_flags = kmflag = KM_NOSLEEP;
}
hp->dmai_rflags = dmareq->dmar_flags & DMP_DDIFLAGS;
if (rootnex_bind_check_inuse) {
e = mutex_tryenter(&dma->dp_mutex);
if (e == 0) {
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_BIND_FAIL]);
return (DDI_DMA_INUSE);
}
if (dma->dp_inuse) {
mutex_exit(&dma->dp_mutex);
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_BIND_FAIL]);
return (DDI_DMA_INUSE);
}
dma->dp_inuse = B_TRUE;
mutex_exit(&dma->dp_mutex);
}
dma->dp_dma = dmareq->dmar_object;
#if !defined(__xpv)
if (IOMMU_USED(rdip)) {
dmao = &dma->dp_dvma;
e = iommulib_nexdma_mapobject(dip, rdip, handle, dmareq, dmao);
switch (e) {
case DDI_SUCCESS:
if (sinfo->si_cancross ||
dmao->dmao_obj.dvma_obj.dv_nseg != 1 ||
dmao->dmao_size > sinfo->si_max_cookie_size) {
dma->dp_dvma_used = B_TRUE;
break;
}
sinfo->si_sgl_size = 1;
hp->dmai_rflags |= DMP_NOSYNC;
dma->dp_dvma_used = B_TRUE;
dma->dp_need_to_free_cookie = B_FALSE;
dvs = &dmao->dmao_obj.dvma_obj.dv_seg[0];
cookie = hp->dmai_cookie = dma->dp_cookies =
(ddi_dma_cookie_t *)dma->dp_prealloc_buffer;
cookie->dmac_laddress = dvs->dvs_start +
dmao->dmao_obj.dvma_obj.dv_off;
cookie->dmac_size = dvs->dvs_len;
cookie->dmac_type = 0;
ROOTNEX_DPROBE1(rootnex__bind__dvmafast, dev_info_t *,
rdip);
goto fast;
case DDI_ENOTSUP:
break;
default:
rootnex_clean_dmahdl(hp);
return (e);
}
}
#endif
sinfo->si_max_pages = mmu_btopr(dma->dp_dma.dmao_size) + 1;
if (dma->dp_dvma_used) {
ncookies = (dma->dp_dma.dmao_size / sinfo->si_max_cookie_size)
+ 1;
if (sinfo->si_cancross)
ncookies +=
(dma->dp_dma.dmao_size / attr->dma_attr_seg) + 1;
ncookies += (dmao->dmao_obj.dvma_obj.dv_nseg - 1);
sinfo->si_max_pages = MIN(sinfo->si_max_pages, ncookies);
}
if (sinfo->si_max_pages <= rootnex_state->r_prealloc_cookies) {
dma->dp_cookies = (ddi_dma_cookie_t *)dma->dp_prealloc_buffer;
dma->dp_need_to_free_cookie = B_FALSE;
ROOTNEX_DPROBE2(rootnex__bind__prealloc, dev_info_t *, rdip,
uint_t, sinfo->si_max_pages);
} else {
dma->dp_cookie_size = sinfo->si_max_pages *
sizeof (ddi_dma_cookie_t);
dma->dp_cookies = kmem_alloc(dma->dp_cookie_size, kmflag);
if (dma->dp_cookies == NULL) {
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_BIND_FAIL]);
rootnex_clean_dmahdl(hp);
return (DDI_DMA_NORESOURCES);
}
dma->dp_need_to_free_cookie = B_TRUE;
ROOTNEX_DPROBE2(rootnex__bind__alloc, dev_info_t *, rdip,
uint_t, sinfo->si_max_pages);
}
hp->dmai_cookie = dma->dp_cookies;
if (dma->dp_dvma_used)
rootnex_dvma_get_sgl(dmao, dma->dp_cookies, &dma->dp_sglinfo);
else
rootnex_get_sgl(dmao, dma->dp_cookies, &dma->dp_sglinfo);
ASSERT(sinfo->si_sgl_size <= sinfo->si_max_pages);
if (sinfo->si_copybuf_req == 0) {
hp->dmai_rflags |= DMP_NOSYNC;
}
if ((sinfo->si_copybuf_req == 0) &&
(sinfo->si_sgl_size <= (unsigned)attr->dma_attr_sgllen) &&
(dmao->dmao_size <= dma->dp_maxxfer)) {
#if !defined(__xpv)
fast:
#endif
if (attr->dma_attr_flags & DDI_DMA_FLAGERR)
hp->dmai_error.err_cf = rootnex_dma_check;
*cookiep = dma->dp_cookies[0];
*ccountp = sinfo->si_sgl_size;
hp->dmai_cookie++;
hp->dmai_rflags &= ~DDI_DMA_PARTIAL;
hp->dmai_ncookies = *ccountp;
hp->dmai_curcookie = 1;
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS]);
ROOTNEX_DPROBE4(rootnex__bind__fast, dev_info_t *, rdip,
uint64_t, rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS],
uint_t, dmao->dmao_size, uint_t, *ccountp);
return (DDI_DMA_MAPPED);
}
#if !defined(__xpv)
if (dma->dp_dvma_used) {
(void) iommulib_nexdma_unmapobject(dip, rdip, handle,
&dma->dp_dvma);
e = DDI_DMA_NOMAPPING;
} else {
#endif
e = rootnex_bind_slowpath(hp, dmareq, dma, attr, &dma->dp_dma,
kmflag);
#if !defined(__xpv)
}
#endif
if ((e != DDI_DMA_MAPPED) && (e != DDI_DMA_PARTIAL_MAP)) {
if (dma->dp_need_to_free_cookie) {
kmem_free(dma->dp_cookies, dma->dp_cookie_size);
}
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_BIND_FAIL]);
rootnex_clean_dmahdl(hp);
return (e);
}
if (attr->dma_attr_flags & DDI_DMA_FLAGERR)
hp->dmai_error.err_cf = rootnex_dma_check;
if ((dma->dp_window[dma->dp_current_win].wd_dosync) &&
(hp->dmai_rflags & DDI_DMA_WRITE)) {
(void) rootnex_coredma_sync(dip, rdip, handle, 0, 0,
DDI_DMA_SYNC_FORDEV);
}
if (e == DDI_DMA_MAPPED) {
hp->dmai_rflags &= ~DDI_DMA_PARTIAL;
*ccountp = sinfo->si_sgl_size;
hp->dmai_nwin = 1;
} else {
hp->dmai_rflags |= DDI_DMA_PARTIAL;
*ccountp = dma->dp_window[dma->dp_current_win].wd_cookie_cnt;
ASSERT(hp->dmai_nwin <= dma->dp_max_win);
}
*cookiep = dma->dp_cookies[0];
hp->dmai_cookie++;
hp->dmai_ncookies = *ccountp;
hp->dmai_curcookie = 1;
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS]);
ROOTNEX_DPROBE4(rootnex__bind__slow, dev_info_t *, rdip, uint64_t,
rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS], uint_t,
dmao->dmao_size, uint_t, *ccountp);
return (e);
}
static int
rootnex_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
ddi_dma_cookie_t *cookiep, uint_t *ccountp)
{
int ret;
#if !defined(__xpv)
if (IOMMU_USED(rdip))
ret = iommulib_nexdma_bindhdl(dip, rdip, handle, dmareq,
cookiep, ccountp);
else
#endif
ret = rootnex_coredma_bindhdl(dip, rdip, handle, dmareq,
cookiep, ccountp);
if (ret == DDI_DMA_NORESOURCES && dmareq->dmar_fp != DDI_DMA_DONTWAIT) {
ddi_set_callback(dmareq->dmar_fp, dmareq->dmar_arg,
&rootnex_state->r_dvma_call_list_id);
}
return (ret);
}
static int
rootnex_coredma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
int e;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
if (rootnex_unbind_verify_buffer) {
e = rootnex_verify_buffer(dma);
if (e != DDI_SUCCESS) {
ASSERT(0);
return (DDI_FAILURE);
}
}
if (dma->dp_window && dma->dp_window[dma->dp_current_win].wd_dosync &&
(hp->dmai_rflags & DDI_DMA_READ)) {
(void) rootnex_coredma_sync(dip, rdip, handle, 0, 0,
DDI_DMA_SYNC_FORCPU);
}
rootnex_teardown_copybuf(dma);
rootnex_teardown_windows(dma);
#if !defined(__xpv)
if (IOMMU_USED(rdip) && dma->dp_dvma_used)
(void) iommulib_nexdma_unmapobject(dip, rdip, handle,
&dma->dp_dvma);
#endif
if (dma->dp_need_to_free_cookie) {
kmem_free(dma->dp_cookies, dma->dp_cookie_size);
}
rootnex_clean_dmahdl(hp);
hp->dmai_error.err_cf = NULL;
ROOTNEX_DPROF_DEC(&rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS]);
ROOTNEX_DPROBE1(rootnex__unbind, uint64_t,
rootnex_cnt[ROOTNEX_CNT_ACTIVE_BINDS]);
return (DDI_SUCCESS);
}
static int
rootnex_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle)
{
int ret;
#if !defined(__xpv)
if (IOMMU_USED(rdip))
ret = iommulib_nexdma_unbindhdl(dip, rdip, handle);
else
#endif
ret = rootnex_coredma_unbindhdl(dip, rdip, handle);
if (rootnex_state->r_dvma_call_list_id)
ddi_run_callback(&rootnex_state->r_dvma_call_list_id);
return (ret);
}
#if !defined(__xpv)
static int
rootnex_coredma_get_sleep_flags(ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)handle;
rootnex_dma_t *dma = (rootnex_dma_t *)hp->dmai_private;
if (dma->dp_sleep_flags != KM_SLEEP &&
dma->dp_sleep_flags != KM_NOSLEEP)
cmn_err(CE_PANIC, "kmem sleep flags not set in DMA handle");
return (dma->dp_sleep_flags);
}
static void
rootnex_coredma_reset_cookies(dev_info_t *dip, ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)handle;
rootnex_dma_t *dma = (rootnex_dma_t *)hp->dmai_private;
rootnex_window_t *window;
if (dma->dp_window) {
window = &dma->dp_window[dma->dp_current_win];
hp->dmai_cookie = window->wd_first_cookie;
} else {
hp->dmai_cookie = dma->dp_cookies;
}
hp->dmai_cookie++;
hp->dmai_curcookie = 1;
}
static int
rootnex_coredma_get_cookies(dev_info_t *dip, ddi_dma_handle_t handle,
ddi_dma_cookie_t **cookiepp, uint_t *ccountp)
{
int i;
int km_flags;
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)handle;
rootnex_dma_t *dma = (rootnex_dma_t *)hp->dmai_private;
rootnex_window_t *window;
ddi_dma_cookie_t *cp;
ddi_dma_cookie_t *cookie;
ASSERT(*cookiepp == NULL);
ASSERT(*ccountp == 0);
if (dma->dp_window) {
window = &dma->dp_window[dma->dp_current_win];
cp = window->wd_first_cookie;
*ccountp = window->wd_cookie_cnt;
} else {
cp = dma->dp_cookies;
*ccountp = dma->dp_sglinfo.si_sgl_size;
}
km_flags = rootnex_coredma_get_sleep_flags(handle);
cookie = kmem_zalloc(sizeof (ddi_dma_cookie_t) * (*ccountp), km_flags);
if (cookie == NULL) {
return (DDI_DMA_NORESOURCES);
}
for (i = 0; i < *ccountp; i++) {
cookie[i].dmac_notused = cp[i].dmac_notused;
cookie[i].dmac_type = cp[i].dmac_type;
cookie[i].dmac_address = cp[i].dmac_address;
cookie[i].dmac_size = cp[i].dmac_size;
}
*cookiepp = cookie;
return (DDI_SUCCESS);
}
static int
rootnex_coredma_set_cookies(dev_info_t *dip, ddi_dma_handle_t handle,
ddi_dma_cookie_t *cookiep, uint_t ccount)
{
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)handle;
rootnex_dma_t *dma = (rootnex_dma_t *)hp->dmai_private;
rootnex_window_t *window;
ddi_dma_cookie_t *cur_cookiep;
ASSERT(cookiep);
ASSERT(ccount != 0);
ASSERT(dma->dp_need_to_switch_cookies == B_FALSE);
if (dma->dp_window) {
window = &dma->dp_window[dma->dp_current_win];
dma->dp_saved_cookies = window->wd_first_cookie;
window->wd_first_cookie = cookiep;
ASSERT(ccount == window->wd_cookie_cnt);
cur_cookiep = (hp->dmai_cookie - dma->dp_saved_cookies)
+ window->wd_first_cookie;
} else {
dma->dp_saved_cookies = dma->dp_cookies;
dma->dp_cookies = cookiep;
ASSERT(ccount == dma->dp_sglinfo.si_sgl_size);
cur_cookiep = (hp->dmai_cookie - dma->dp_saved_cookies)
+ dma->dp_cookies;
}
dma->dp_need_to_switch_cookies = B_TRUE;
hp->dmai_cookie = cur_cookiep;
return (DDI_SUCCESS);
}
static int
rootnex_coredma_clear_cookies(dev_info_t *dip, ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)handle;
rootnex_dma_t *dma = (rootnex_dma_t *)hp->dmai_private;
rootnex_window_t *window;
ddi_dma_cookie_t *cur_cookiep;
ddi_dma_cookie_t *cookie_array;
uint_t ccount;
if (dma->dp_need_to_switch_cookies == B_FALSE)
return (DDI_SUCCESS);
ASSERT(dma->dp_saved_cookies);
if (dma->dp_window) {
window = &dma->dp_window[dma->dp_current_win];
cookie_array = window->wd_first_cookie;
window->wd_first_cookie = dma->dp_saved_cookies;
dma->dp_saved_cookies = NULL;
ccount = window->wd_cookie_cnt;
cur_cookiep = (hp->dmai_cookie - cookie_array)
+ window->wd_first_cookie;
} else {
cookie_array = dma->dp_cookies;
dma->dp_cookies = dma->dp_saved_cookies;
dma->dp_saved_cookies = NULL;
ccount = dma->dp_sglinfo.si_sgl_size;
cur_cookiep = (hp->dmai_cookie - cookie_array)
+ dma->dp_cookies;
}
kmem_free(cookie_array, sizeof (ddi_dma_cookie_t) * ccount);
hp->dmai_cookie = cur_cookiep;
dma->dp_need_to_switch_cookies = B_FALSE;
return (DDI_SUCCESS);
}
#endif
static struct as *
rootnex_get_as(ddi_dma_obj_t *dmao)
{
struct as *asp;
switch (dmao->dmao_type) {
case DMA_OTYP_VADDR:
case DMA_OTYP_BUFVADDR:
asp = dmao->dmao_obj.virt_obj.v_as;
if (asp == NULL)
asp = &kas;
break;
default:
asp = NULL;
break;
}
return (asp);
}
static int
rootnex_verify_buffer(rootnex_dma_t *dma)
{
page_t **pplist;
caddr_t vaddr;
uint_t pcnt;
uint_t poff;
page_t *pp;
char b;
int i;
if (dma->dp_dma.dmao_type == DMA_OTYP_PAGES) {
poff = dma->dp_dma.dmao_obj.pp_obj.pp_offset & MMU_PAGEOFFSET;
} else {
vaddr = dma->dp_dma.dmao_obj.virt_obj.v_addr;
poff = (uintptr_t)vaddr & MMU_PAGEOFFSET;
}
pcnt = mmu_btopr(dma->dp_dma.dmao_size + poff);
switch (dma->dp_dma.dmao_type) {
case DMA_OTYP_PAGES:
pp = dma->dp_dma.dmao_obj.pp_obj.pp_pp;
for (i = 0; i < pcnt; i++) {
if (PP_ISFREE(pp) || !PAGE_LOCKED(pp)) {
return (DDI_FAILURE);
}
pp = pp->p_next;
}
break;
case DMA_OTYP_VADDR:
case DMA_OTYP_BUFVADDR:
pplist = dma->dp_dma.dmao_obj.virt_obj.v_priv;
if (pplist) {
for (i = 0; i < pcnt; i++) {
if (PP_ISFREE(pplist[i])) {
return (DDI_FAILURE);
}
}
} else {
if (rootnex_get_as(&dma->dp_dma) == &kas) {
for (i = 0; i < pcnt; i++) {
if (ddi_peek8(NULL, vaddr, &b) ==
DDI_FAILURE)
return (DDI_FAILURE);
vaddr += MMU_PAGESIZE;
}
}
}
break;
default:
cmn_err(CE_PANIC, "rootnex_verify_buffer: bad DMA object");
break;
}
return (DDI_SUCCESS);
}
static void
rootnex_clean_dmahdl(ddi_dma_impl_t *hp)
{
rootnex_dma_t *dma;
dma = (rootnex_dma_t *)hp->dmai_private;
hp->dmai_nwin = 0;
dma->dp_current_cookie = 0;
dma->dp_copybuf_size = 0;
dma->dp_window = NULL;
dma->dp_cbaddr = NULL;
dma->dp_inuse = B_FALSE;
dma->dp_dvma_used = B_FALSE;
dma->dp_need_to_free_cookie = B_FALSE;
dma->dp_need_to_switch_cookies = B_FALSE;
dma->dp_saved_cookies = NULL;
dma->dp_sleep_flags = KM_PANIC;
dma->dp_need_to_free_window = B_FALSE;
dma->dp_partial_required = B_FALSE;
dma->dp_trim_required = B_FALSE;
dma->dp_sglinfo.si_copybuf_req = 0;
hp->dmai_fault = 0;
hp->dmai_fault_check = NULL;
hp->dmai_fault_notify = NULL;
hp->dmai_error.err_ena = 0;
hp->dmai_error.err_status = DDI_FM_OK;
hp->dmai_error.err_expected = DDI_FM_ERR_UNEXPECTED;
hp->dmai_error.err_ontrap = NULL;
hp->dmai_ncookies = 0;
hp->dmai_curcookie = 0;
}
static int
rootnex_valid_alloc_parms(ddi_dma_attr_t *attr, uint_t maxsegmentsize)
{
if ((attr->dma_attr_seg < MMU_PAGEOFFSET) ||
(attr->dma_attr_count_max < MMU_PAGEOFFSET) ||
(attr->dma_attr_granular > MMU_PAGESIZE) ||
(attr->dma_attr_maxxfer < MMU_PAGESIZE)) {
return (DDI_DMA_BADATTR);
}
if (attr->dma_attr_addr_hi <= attr->dma_attr_addr_lo) {
return (DDI_DMA_BADATTR);
}
if ((attr->dma_attr_seg & MMU_PAGEOFFSET) != MMU_PAGEOFFSET ||
MMU_PAGESIZE & (attr->dma_attr_granular - 1) ||
attr->dma_attr_sgllen == 0) {
return (DDI_DMA_BADATTR);
}
if (maxsegmentsize < MMU_PAGESIZE) {
return (DDI_DMA_BADATTR);
}
if ((attr->dma_attr_flags & _DDI_DMA_BOUNCE_ON_SEG) &&
(attr->dma_attr_seg > attr->dma_attr_addr_hi)) {
return (DDI_DMA_BADATTR);
}
return (DDI_SUCCESS);
}
static boolean_t
rootnex_need_bounce_seg(ddi_dma_obj_t *dmar_object, rootnex_sglinfo_t *sglinfo)
{
ddi_dma_atyp_t buftype;
rootnex_addr_t raddr;
boolean_t lower_addr;
boolean_t upper_addr;
uint64_t offset;
page_t **pplist;
uint64_t paddr;
uint32_t psize;
uint32_t size;
caddr_t vaddr;
uint_t pcnt;
page_t *pp;
pp = NULL;
pplist = dmar_object->dmao_obj.virt_obj.v_priv;
vaddr = dmar_object->dmao_obj.virt_obj.v_addr;
buftype = dmar_object->dmao_type;
size = dmar_object->dmao_size;
lower_addr = B_FALSE;
upper_addr = B_FALSE;
pcnt = 0;
if (buftype == DMA_OTYP_PAGES) {
pp = dmar_object->dmao_obj.pp_obj.pp_pp;
offset = dmar_object->dmao_obj.pp_obj.pp_offset &
MMU_PAGEOFFSET;
paddr = pfn_to_pa(pp->p_pagenum) + offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
pp = pp->p_next;
sglinfo->si_asp = NULL;
} else if (pplist != NULL) {
offset = (uintptr_t)vaddr & MMU_PAGEOFFSET;
sglinfo->si_asp = dmar_object->dmao_obj.virt_obj.v_as;
if (sglinfo->si_asp == NULL) {
sglinfo->si_asp = &kas;
}
paddr = pfn_to_pa(pplist[pcnt]->p_pagenum);
paddr += offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
pcnt++;
} else {
offset = (uintptr_t)vaddr & MMU_PAGEOFFSET;
sglinfo->si_asp = dmar_object->dmao_obj.virt_obj.v_as;
if (sglinfo->si_asp == NULL) {
sglinfo->si_asp = &kas;
}
paddr = pfn_to_pa(hat_getpfnum(sglinfo->si_asp->a_hat, vaddr));
paddr += offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
vaddr += psize;
}
raddr = ROOTNEX_PADDR_TO_RBASE(paddr);
if ((raddr + psize) > sglinfo->si_segmask) {
upper_addr = B_TRUE;
} else {
lower_addr = B_TRUE;
}
size -= psize;
while (size > 0) {
psize = MIN(size, MMU_PAGESIZE);
if (buftype == DMA_OTYP_PAGES) {
ASSERT(!PP_ISFREE(pp) && PAGE_LOCKED(pp));
paddr = pfn_to_pa(pp->p_pagenum);
pp = pp->p_next;
} else if (pplist != NULL) {
ASSERT(!PP_ISFREE(pplist[pcnt]));
paddr = pfn_to_pa(pplist[pcnt]->p_pagenum);
pcnt++;
} else {
paddr = pfn_to_pa(hat_getpfnum(sglinfo->si_asp->a_hat,
vaddr));
vaddr += psize;
}
raddr = ROOTNEX_PADDR_TO_RBASE(paddr);
if ((raddr + psize) > sglinfo->si_segmask) {
upper_addr = B_TRUE;
} else {
lower_addr = B_TRUE;
}
if ((lower_addr && upper_addr) ||
(raddr == (sglinfo->si_segmask + 1))) {
return (B_TRUE);
}
size -= psize;
}
return (B_FALSE);
}
static void
rootnex_get_sgl(ddi_dma_obj_t *dmar_object, ddi_dma_cookie_t *sgl,
rootnex_sglinfo_t *sglinfo)
{
ddi_dma_atyp_t buftype;
rootnex_addr_t raddr;
uint64_t last_page;
uint64_t offset;
uint64_t addrhi;
uint64_t addrlo;
uint64_t maxseg;
page_t **pplist;
uint64_t paddr;
uint32_t psize;
uint32_t size;
caddr_t vaddr;
uint_t pcnt;
page_t *pp;
uint_t cnt;
pp = NULL;
pplist = dmar_object->dmao_obj.virt_obj.v_priv;
vaddr = dmar_object->dmao_obj.virt_obj.v_addr;
maxseg = sglinfo->si_max_cookie_size;
buftype = dmar_object->dmao_type;
addrhi = sglinfo->si_max_addr;
addrlo = sglinfo->si_min_addr;
size = dmar_object->dmao_size;
pcnt = 0;
cnt = 0;
sglinfo->si_bounce_on_seg = B_FALSE;
if (sglinfo->si_flags & _DDI_DMA_BOUNCE_ON_SEG) {
sglinfo->si_bounce_on_seg = rootnex_need_bounce_seg(
dmar_object, sglinfo);
}
if (buftype == DMA_OTYP_PAGES) {
pp = dmar_object->dmao_obj.pp_obj.pp_pp;
ASSERT(!PP_ISFREE(pp) && PAGE_LOCKED(pp));
offset = dmar_object->dmao_obj.pp_obj.pp_offset &
MMU_PAGEOFFSET;
paddr = pfn_to_pa(pp->p_pagenum) + offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
pp = pp->p_next;
sglinfo->si_asp = NULL;
} else if (pplist != NULL) {
ASSERT((buftype == DMA_OTYP_VADDR) ||
(buftype == DMA_OTYP_BUFVADDR));
offset = (uintptr_t)vaddr & MMU_PAGEOFFSET;
sglinfo->si_asp = dmar_object->dmao_obj.virt_obj.v_as;
if (sglinfo->si_asp == NULL) {
sglinfo->si_asp = &kas;
}
ASSERT(!PP_ISFREE(pplist[pcnt]));
paddr = pfn_to_pa(pplist[pcnt]->p_pagenum);
paddr += offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
pcnt++;
} else {
ASSERT((buftype == DMA_OTYP_VADDR) ||
(buftype == DMA_OTYP_BUFVADDR));
offset = (uintptr_t)vaddr & MMU_PAGEOFFSET;
sglinfo->si_asp = dmar_object->dmao_obj.virt_obj.v_as;
if (sglinfo->si_asp == NULL) {
sglinfo->si_asp = &kas;
}
paddr = pfn_to_pa(hat_getpfnum(sglinfo->si_asp->a_hat, vaddr));
paddr += offset;
psize = MIN(size, (MMU_PAGESIZE - offset));
vaddr += psize;
}
raddr = ROOTNEX_PADDR_TO_RBASE(paddr);
sgl[cnt].dmac_laddress = raddr;
sgl[cnt].dmac_size = psize;
sgl[cnt].dmac_type = 0;
sglinfo->si_buf_offset = offset;
if (((sglinfo->si_bounce_on_seg) &&
((raddr + psize) > sglinfo->si_segmask)) ||
((raddr < addrlo) || ((raddr + psize) > addrhi))) {
sglinfo->si_copybuf_req += MMU_PAGESIZE;
sgl[cnt].dmac_type = ROOTNEX_USES_COPYBUF;
if ((cnt + 1) < sglinfo->si_max_pages) {
cnt++;
sgl[cnt].dmac_laddress = 0;
sgl[cnt].dmac_size = 0;
sgl[cnt].dmac_type = 0;
}
}
last_page = raddr & MMU_PAGEMASK;
size -= psize;
while (size > 0) {
psize = MIN(size, MMU_PAGESIZE);
if (buftype == DMA_OTYP_PAGES) {
ASSERT(!PP_ISFREE(pp) && PAGE_LOCKED(pp));
paddr = pfn_to_pa(pp->p_pagenum);
pp = pp->p_next;
} else if (pplist != NULL) {
ASSERT(!PP_ISFREE(pplist[pcnt]));
paddr = pfn_to_pa(pplist[pcnt]->p_pagenum);
pcnt++;
} else {
paddr = pfn_to_pa(hat_getpfnum(sglinfo->si_asp->a_hat,
vaddr));
vaddr += psize;
}
raddr = ROOTNEX_PADDR_TO_RBASE(paddr);
if (((sglinfo->si_bounce_on_seg) &&
((raddr + psize) > sglinfo->si_segmask)) ||
((raddr < addrlo) || ((raddr + psize) > addrhi))) {
sglinfo->si_copybuf_req += MMU_PAGESIZE;
if (sgl[cnt].dmac_size != 0) {
cnt++;
}
sgl[cnt].dmac_laddress = raddr;
sgl[cnt].dmac_size = psize;
sgl[cnt].dmac_type = ROOTNEX_USES_COPYBUF;
if ((cnt + 1) < sglinfo->si_max_pages) {
cnt++;
sgl[cnt].dmac_laddress = 0;
sgl[cnt].dmac_size = 0;
sgl[cnt].dmac_type = 0;
}
} else if (((last_page + MMU_PAGESIZE) != raddr) ||
!(raddr & sglinfo->si_segmask) ||
((sgl[cnt].dmac_size + psize) > maxseg) ||
(sgl[cnt].dmac_size == 0)) {
if (sgl[cnt].dmac_size != 0) {
cnt++;
}
sgl[cnt].dmac_laddress = raddr;
sgl[cnt].dmac_size = psize;
sgl[cnt].dmac_type = 0;
} else {
sgl[cnt].dmac_size += psize;
if ((sgl[cnt].dmac_size == maxseg) &&
((cnt + 1) < sglinfo->si_max_pages)) {
cnt++;
sgl[cnt].dmac_laddress = 0;
sgl[cnt].dmac_size = 0;
sgl[cnt].dmac_type = 0;
}
}
last_page = raddr;
size -= psize;
}
if (sgl[cnt].dmac_size == 0) {
ASSERT(cnt < sglinfo->si_max_pages);
sglinfo->si_sgl_size = cnt;
} else {
sglinfo->si_sgl_size = cnt + 1;
}
}
static void
rootnex_dvma_get_sgl(ddi_dma_obj_t *dmar_object, ddi_dma_cookie_t *sgl,
rootnex_sglinfo_t *sglinfo)
{
uint64_t offset;
uint64_t maxseg;
uint64_t dvaddr;
struct dvmaseg *dvs;
uint64_t paddr;
uint32_t psize, ssize;
uint32_t size;
uint_t cnt;
int physcontig;
ASSERT(dmar_object->dmao_type == DMA_OTYP_DVADDR);
maxseg = sglinfo->si_max_cookie_size;
size = dmar_object->dmao_size;
cnt = 0;
sglinfo->si_bounce_on_seg = B_FALSE;
dvs = dmar_object->dmao_obj.dvma_obj.dv_seg;
offset = dmar_object->dmao_obj.dvma_obj.dv_off;
ssize = dvs->dvs_len;
paddr = dvs->dvs_start;
paddr += offset;
psize = MIN(ssize, (maxseg - offset));
dvaddr = paddr + psize;
ssize -= psize;
sgl[cnt].dmac_laddress = paddr;
sgl[cnt].dmac_size = psize;
sgl[cnt].dmac_type = 0;
size -= psize;
while (size > 0) {
if (ssize == 0) {
dvs++;
ssize = dvs->dvs_len;
dvaddr = dvs->dvs_start;
physcontig = 0;
} else
physcontig = 1;
paddr = dvaddr;
psize = MIN(ssize, maxseg);
dvaddr += psize;
ssize -= psize;
if (!physcontig || !(paddr & sglinfo->si_segmask) ||
((sgl[cnt].dmac_size + psize) > maxseg) ||
(sgl[cnt].dmac_size == 0)) {
if (sgl[cnt].dmac_size != 0) {
cnt++;
}
sgl[cnt].dmac_laddress = paddr;
sgl[cnt].dmac_size = psize;
sgl[cnt].dmac_type = 0;
} else {
sgl[cnt].dmac_size += psize;
if ((sgl[cnt].dmac_size == maxseg) &&
((cnt + 1) < sglinfo->si_max_pages)) {
cnt++;
sgl[cnt].dmac_laddress = 0;
sgl[cnt].dmac_size = 0;
sgl[cnt].dmac_type = 0;
}
}
size -= psize;
}
if (sgl[cnt].dmac_size == 0) {
sglinfo->si_sgl_size = cnt;
} else {
sglinfo->si_sgl_size = cnt + 1;
}
}
static int
rootnex_bind_slowpath(ddi_dma_impl_t *hp, struct ddi_dma_req *dmareq,
rootnex_dma_t *dma, ddi_dma_attr_t *attr, ddi_dma_obj_t *dmao, int kmflag)
{
rootnex_sglinfo_t *sinfo;
rootnex_window_t *window;
ddi_dma_cookie_t *cookie;
size_t copybuf_used;
size_t dmac_size;
boolean_t partial;
off_t cur_offset;
page_t *cur_pp;
major_t mnum;
int e;
int i;
sinfo = &dma->dp_sglinfo;
copybuf_used = 0;
partial = B_FALSE;
if (sinfo->si_copybuf_req != 0) {
e = rootnex_setup_copybuf(hp, dmareq, dma, attr);
if (e != DDI_SUCCESS) {
return (e);
}
} else {
dma->dp_copybuf_size = 0;
}
if ((dma->dp_copybuf_size < sinfo->si_copybuf_req) ||
(dmao->dmao_size > dma->dp_maxxfer) ||
((unsigned)attr->dma_attr_sgllen < sinfo->si_sgl_size)) {
dma->dp_partial_required = B_TRUE;
if (attr->dma_attr_granular != 1) {
dma->dp_trim_required = B_TRUE;
}
} else {
dma->dp_partial_required = B_FALSE;
dma->dp_trim_required = B_FALSE;
}
if (dma->dp_partial_required &&
!(dmareq->dmar_flags & DDI_DMA_PARTIAL)) {
mnum = ddi_driver_major(dma->dp_dip);
if ((rootnex_bind_warn) &&
((rootnex_warn_list[mnum] & ROOTNEX_BIND_WARNING) == 0)) {
rootnex_warn_list[mnum] |= ROOTNEX_BIND_WARNING;
cmn_err(CE_WARN, "!%s: coding error detected, the "
"driver is using ddi_dma_attr(9S) incorrectly. "
"There is a small risk of data corruption in "
"particular with large I/Os. The driver should be "
"replaced with a corrected version for proper "
"system operation. To disable this warning, add "
"'set rootnex:rootnex_bind_warn=0' to "
"/etc/system(5).", ddi_driver_name(dma->dp_dip));
}
return (DDI_DMA_TOOBIG);
}
e = rootnex_setup_windows(hp, dma, attr, dmao, kmflag);
if (e != DDI_SUCCESS) {
rootnex_teardown_copybuf(dma);
return (e);
}
window = &dma->dp_window[0];
cookie = &dma->dp_cookies[0];
cur_offset = 0;
rootnex_init_win(hp, dma, window, cookie, cur_offset);
if (dmao->dmao_type == DMA_OTYP_PAGES) {
cur_pp = dmareq->dmar_object.dmao_obj.pp_obj.pp_pp;
}
for (i = 0; i < sinfo->si_sgl_size; i++) {
if (dma->dp_copybuf_size > 0) {
rootnex_setup_cookie(dmao, dma, cookie,
cur_offset, ©buf_used, &cur_pp);
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
window->wd_dosync = B_TRUE;
}
}
dmac_size = cookie->dmac_size;
if (dma->dp_copybuf_size &&
(copybuf_used > dma->dp_copybuf_size)) {
partial = B_TRUE;
e = rootnex_copybuf_window_boundary(hp, dma, &window,
cookie, cur_offset, ©buf_used);
if (e != DDI_SUCCESS) {
rootnex_teardown_copybuf(dma);
rootnex_teardown_windows(dma);
return (e);
}
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
window->wd_dosync = B_TRUE;
}
ROOTNEX_DPROBE1(rootnex__copybuf__window, dev_info_t *,
dma->dp_dip);
} else if (window->wd_cookie_cnt >=
(unsigned)attr->dma_attr_sgllen) {
partial = B_TRUE;
ASSERT(window->wd_cookie_cnt == attr->dma_attr_sgllen);
e = rootnex_sgllen_window_boundary(hp, dma, &window,
cookie, attr, cur_offset);
if (e != DDI_SUCCESS) {
rootnex_teardown_copybuf(dma);
rootnex_teardown_windows(dma);
return (e);
}
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
window->wd_dosync = B_TRUE;
}
ROOTNEX_DPROBE1(rootnex__sgllen__window, dev_info_t *,
dma->dp_dip);
} else if ((window->wd_size + dmac_size) >
dma->dp_maxxfer) {
partial = B_TRUE;
e = rootnex_maxxfer_window_boundary(hp, dma, &window,
cookie);
if (e != DDI_SUCCESS) {
rootnex_teardown_copybuf(dma);
rootnex_teardown_windows(dma);
return (e);
}
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
window->wd_dosync = B_TRUE;
}
ROOTNEX_DPROBE1(rootnex__maxxfer__window, dev_info_t *,
dma->dp_dip);
} else {
window->wd_cookie_cnt++;
window->wd_size += dmac_size;
}
ASSERT(dmac_size <= dmao->dmao_size);
ASSERT(cookie->dmac_size <= dmac_size);
cur_offset += dmac_size;
cookie++;
}
if (window->wd_size == 0) {
hp->dmai_nwin--;
window--;
}
ASSERT(window->wd_trim.tr_trim_last == B_FALSE);
if (!partial) {
return (DDI_DMA_MAPPED);
}
ASSERT(dma->dp_partial_required);
return (DDI_DMA_PARTIAL_MAP);
}
static int
rootnex_setup_copybuf(ddi_dma_impl_t *hp, struct ddi_dma_req *dmareq,
rootnex_dma_t *dma, ddi_dma_attr_t *attr)
{
rootnex_sglinfo_t *sinfo;
ddi_dma_attr_t lattr;
size_t max_copybuf;
int cansleep;
int e;
ASSERT(!dma->dp_dvma_used);
sinfo = &dma->dp_sglinfo;
max_copybuf = i_ddi_copybuf_size() & MMU_PAGEMASK;
hp->dmai_rflags &= ~DMP_NOSYNC;
dma->dp_copybuf_size = MIN(sinfo->si_copybuf_req, max_copybuf);
ASSERT((dma->dp_copybuf_size & MMU_PAGEOFFSET) == 0);
if (dmareq->dmar_fp == DDI_DMA_SLEEP) {
cansleep = 1;
} else {
cansleep = 0;
}
lattr = *attr;
lattr.dma_attr_align = MMU_PAGESIZE;
lattr.dma_attr_sgllen = -1;
if (sinfo->si_bounce_on_seg) {
lattr.dma_attr_addr_hi = lattr.dma_attr_seg;
}
e = i_ddi_mem_alloc(dma->dp_dip, &lattr, dma->dp_copybuf_size, cansleep,
0, NULL, &dma->dp_cbaddr, &dma->dp_cbsize, NULL);
if (e != DDI_SUCCESS) {
return (DDI_DMA_NORESOURCES);
}
ROOTNEX_DPROBE2(rootnex__alloc__copybuf, dev_info_t *, dma->dp_dip,
size_t, dma->dp_copybuf_size);
return (DDI_SUCCESS);
}
static int
rootnex_setup_windows(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
ddi_dma_attr_t *attr, ddi_dma_obj_t *dmao, int kmflag)
{
rootnex_window_t *windowp;
rootnex_sglinfo_t *sinfo;
size_t copy_state_size;
size_t win_state_size;
size_t state_available;
size_t space_needed;
uint_t copybuf_win;
uint_t maxxfer_win;
size_t space_used;
uint_t sglwin;
sinfo = &dma->dp_sglinfo;
dma->dp_current_win = 0;
hp->dmai_nwin = 0;
if (!dma->dp_partial_required) {
dma->dp_max_win = 1;
} else {
if (sinfo->si_copybuf_req > dma->dp_copybuf_size) {
ASSERT(dma->dp_copybuf_size > 0);
copybuf_win = (sinfo->si_copybuf_req /
dma->dp_copybuf_size) + 1 + 2;
} else {
copybuf_win = 0;
}
if ((unsigned)attr->dma_attr_sgllen < sinfo->si_sgl_size) {
sglwin = (sinfo->si_sgl_size /
(attr->dma_attr_sgllen - 1)) + 1;
} else {
sglwin = 0;
}
if (dmao->dmao_size > dma->dp_maxxfer) {
maxxfer_win = (dmao->dmao_size /
dma->dp_maxxfer) + 1 + 2;
} else {
maxxfer_win = 0;
}
dma->dp_max_win = copybuf_win + sglwin + maxxfer_win;
ASSERT(dma->dp_max_win > 0);
}
win_state_size = dma->dp_max_win * sizeof (rootnex_window_t);
space_used = (uintptr_t)(sinfo->si_sgl_size *
sizeof (ddi_dma_cookie_t));
if (dma->dp_need_to_free_cookie) {
ASSERT(space_used <= dma->dp_cookie_size);
if ((dma->dp_cookie_size - space_used) <=
rootnex_state->r_prealloc_size) {
state_available = rootnex_state->r_prealloc_size;
windowp = (rootnex_window_t *)dma->dp_prealloc_buffer;
} else {
state_available = dma->dp_cookie_size - space_used;
windowp = (rootnex_window_t *)
&dma->dp_cookies[sinfo->si_sgl_size];
}
} else {
ASSERT(space_used <= rootnex_state->r_prealloc_size);
state_available = rootnex_state->r_prealloc_size - space_used;
windowp = (rootnex_window_t *)
&dma->dp_cookies[sinfo->si_sgl_size];
}
if (dma->dp_copybuf_size > 0) {
copy_state_size = sinfo->si_max_pages *
sizeof (rootnex_pgmap_t);
} else {
copy_state_size = 0;
}
space_needed = win_state_size + copy_state_size + 0x8;
if (state_available >= space_needed) {
dma->dp_window = windowp;
dma->dp_need_to_free_window = B_FALSE;
} else {
dma->dp_window = kmem_alloc(space_needed, kmflag);
if (dma->dp_window == NULL) {
return (DDI_DMA_NORESOURCES);
}
dma->dp_need_to_free_window = B_TRUE;
dma->dp_window_size = space_needed;
ROOTNEX_DPROBE2(rootnex__bind__sp__alloc, dev_info_t *,
dma->dp_dip, size_t, space_needed);
}
if (dma->dp_copybuf_size > 0) {
dma->dp_pgmap = (rootnex_pgmap_t *)(((uintptr_t)
&dma->dp_window[dma->dp_max_win] + 0x7) & ~0x7);
} else {
dma->dp_pgmap = NULL;
}
return (DDI_SUCCESS);
}
static void
rootnex_teardown_copybuf(rootnex_dma_t *dma)
{
if (dma->dp_cbaddr != NULL) {
i_ddi_mem_free(dma->dp_cbaddr, NULL);
}
}
static void
rootnex_teardown_windows(rootnex_dma_t *dma)
{
if (dma->dp_need_to_free_window) {
kmem_free(dma->dp_window, dma->dp_window_size);
}
}
static void
rootnex_init_win(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
rootnex_window_t *window, ddi_dma_cookie_t *cookie, off_t cur_offset)
{
hp->dmai_nwin++;
window->wd_dosync = B_FALSE;
window->wd_offset = cur_offset;
window->wd_size = 0;
window->wd_first_cookie = cookie;
window->wd_cookie_cnt = 0;
window->wd_trim.tr_trim_first = B_FALSE;
window->wd_trim.tr_trim_last = B_FALSE;
window->wd_trim.tr_first_copybuf_win = B_FALSE;
window->wd_trim.tr_last_copybuf_win = B_FALSE;
}
static void
rootnex_setup_cookie(ddi_dma_obj_t *dmar_object, rootnex_dma_t *dma,
ddi_dma_cookie_t *cookie, off_t cur_offset, size_t *copybuf_used,
page_t **cur_pp)
{
boolean_t copybuf_sz_power_2;
rootnex_sglinfo_t *sinfo;
paddr_t paddr;
uint_t pidx;
uint_t pcnt;
off_t poff;
pfn_t pfn;
ASSERT(dmar_object->dmao_type != DMA_OTYP_DVADDR);
sinfo = &dma->dp_sglinfo;
pidx = (sinfo->si_buf_offset + cur_offset) >> MMU_PAGESHIFT;
ASSERT(pidx < sinfo->si_max_pages);
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
poff = cookie->dmac_laddress & MMU_PAGEOFFSET;
pfn = mfn_to_pfn(cookie->dmac_laddress >> MMU_PAGESHIFT);
if (!ISP2(dma->dp_copybuf_size)) {
copybuf_sz_power_2 = B_FALSE;
} else {
copybuf_sz_power_2 = B_TRUE;
}
dma->dp_pgmap[pidx].pm_uses_copybuf = B_TRUE;
if ((*copybuf_used + MMU_PAGESIZE) <= dma->dp_copybuf_size) {
dma->dp_pgmap[pidx].pm_cbaddr = dma->dp_cbaddr +
*copybuf_used;
} else {
if (copybuf_sz_power_2) {
dma->dp_pgmap[pidx].pm_cbaddr = (caddr_t)(
(uintptr_t)dma->dp_cbaddr +
(*copybuf_used &
(dma->dp_copybuf_size - 1)));
} else {
dma->dp_pgmap[pidx].pm_cbaddr = (caddr_t)(
(uintptr_t)dma->dp_cbaddr +
(*copybuf_used % dma->dp_copybuf_size));
}
}
paddr = pfn_to_pa(hat_getpfnum(kas.a_hat,
dma->dp_pgmap[pidx].pm_cbaddr)) + poff;
cookie->dmac_laddress = ROOTNEX_PADDR_TO_RBASE(paddr);
if ((dmar_object->dmao_type != DMA_OTYP_PAGES) &&
(sinfo->si_asp == &kas)) {
dma->dp_pgmap[pidx].pm_kaddr = (caddr_t)(((uintptr_t)
dmar_object->dmao_obj.virt_obj.v_addr + cur_offset)
& MMU_PAGEMASK);
} else {
dma->dp_pgmap[pidx].pm_kaddr = hat_kpm_pfn2va(pfn);
if (dmar_object->dmao_type == DMA_OTYP_PAGES) {
*cur_pp = (*cur_pp)->p_next;
}
}
*copybuf_used += MMU_PAGESIZE;
} else {
poff = (sinfo->si_buf_offset + cur_offset) & MMU_PAGEOFFSET;
pcnt = mmu_btopr(cookie->dmac_size + poff);
while (pcnt > 0) {
dma->dp_pgmap[pidx].pm_uses_copybuf = B_FALSE;
if (dmar_object->dmao_type == DMA_OTYP_PAGES) {
*cur_pp = (*cur_pp)->p_next;
}
pidx++;
pcnt--;
}
}
}
static int
rootnex_sgllen_window_boundary(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
rootnex_window_t **windowp, ddi_dma_cookie_t *cookie, ddi_dma_attr_t *attr,
off_t cur_offset)
{
off_t new_offset;
size_t trim_sz;
off_t coffset;
if (!dma->dp_trim_required) {
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, cur_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size = cookie->dmac_size;
return (DDI_SUCCESS);
}
ASSERT(attr->dma_attr_granular != 0);
if (dma->dp_granularity_power_2) {
trim_sz = (*windowp)->wd_size & (attr->dma_attr_granular - 1);
} else {
trim_sz = (*windowp)->wd_size % attr->dma_attr_granular;
}
if (trim_sz == 0) {
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, cur_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size = cookie->dmac_size;
return (DDI_SUCCESS);
}
if (attr->dma_attr_sgllen == 1) {
return (DDI_DMA_NOMAPPING);
}
cookie--;
(*windowp)->wd_trim.tr_trim_last = B_TRUE;
(*windowp)->wd_trim.tr_last_cookie = cookie;
(*windowp)->wd_trim.tr_last_paddr = cookie->dmac_laddress;
ASSERT(cookie->dmac_size > trim_sz);
(*windowp)->wd_trim.tr_last_size = cookie->dmac_size - trim_sz;
(*windowp)->wd_size -= trim_sz;
coffset = cookie->dmac_size - trim_sz;
new_offset = (*windowp)->wd_offset + (*windowp)->wd_size;
cookie->dmac_size = (*windowp)->wd_trim.tr_last_size;
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, new_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_trim.tr_trim_first = B_TRUE;
(*windowp)->wd_trim.tr_first_paddr = cookie->dmac_laddress + coffset;
(*windowp)->wd_trim.tr_first_size = trim_sz;
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
(*windowp)->wd_dosync = B_TRUE;
}
cookie++;
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size = trim_sz + cookie->dmac_size;
if ((*windowp)->wd_size > dma->dp_maxxfer) {
trim_sz = (*windowp)->wd_size - dma->dp_maxxfer;
(*windowp)->wd_trim.tr_trim_last = B_TRUE;
(*windowp)->wd_trim.tr_last_cookie = cookie;
(*windowp)->wd_trim.tr_last_paddr = cookie->dmac_laddress;
(*windowp)->wd_trim.tr_last_size = cookie->dmac_size - trim_sz;
(*windowp)->wd_size -= trim_sz;
ASSERT((*windowp)->wd_size == dma->dp_maxxfer);
coffset = cookie->dmac_size - trim_sz;
new_offset = (*windowp)->wd_offset + (*windowp)->wd_size;
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, new_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_trim.tr_trim_first = B_TRUE;
(*windowp)->wd_trim.tr_first_paddr = cookie->dmac_laddress +
coffset;
(*windowp)->wd_trim.tr_first_size = trim_sz;
}
return (DDI_SUCCESS);
}
static int
rootnex_copybuf_window_boundary(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
rootnex_window_t **windowp, ddi_dma_cookie_t *cookie, off_t cur_offset,
size_t *copybuf_used)
{
rootnex_sglinfo_t *sinfo;
off_t new_offset;
size_t trim_sz;
paddr_t paddr;
off_t coffset;
uint_t pidx;
off_t poff;
pidx = 0;
sinfo = &dma->dp_sglinfo;
ASSERT(cookie->dmac_size <= MMU_PAGESIZE);
*copybuf_used = 0;
if (!dma->dp_trim_required) {
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, cur_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size += cookie->dmac_size;
*copybuf_used += MMU_PAGESIZE;
return (DDI_SUCCESS);
}
if (dma->dp_granularity_power_2) {
trim_sz = (*windowp)->wd_size &
(hp->dmai_attr.dma_attr_granular - 1);
} else {
trim_sz = (*windowp)->wd_size % hp->dmai_attr.dma_attr_granular;
}
if (trim_sz == 0) {
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, cur_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size += cookie->dmac_size;
*copybuf_used += MMU_PAGESIZE;
return (DDI_SUCCESS);
}
if (hp->dmai_attr.dma_attr_sgllen == 1) {
return (DDI_DMA_NOMAPPING);
}
cookie--;
(*windowp)->wd_trim.tr_trim_last = B_TRUE;
(*windowp)->wd_trim.tr_last_cookie = cookie;
(*windowp)->wd_trim.tr_last_paddr = cookie->dmac_laddress;
ASSERT(cookie->dmac_size > trim_sz);
(*windowp)->wd_trim.tr_last_size = cookie->dmac_size - trim_sz;
(*windowp)->wd_size -= trim_sz;
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
pidx = (sinfo->si_buf_offset + (*windowp)->wd_offset +
(*windowp)->wd_size) >> MMU_PAGESHIFT;
(*windowp)->wd_trim.tr_last_copybuf_win = B_TRUE;
(*windowp)->wd_trim.tr_last_pidx = pidx;
(*windowp)->wd_trim.tr_last_cbaddr =
dma->dp_pgmap[pidx].pm_cbaddr;
}
coffset = cookie->dmac_size - trim_sz;
new_offset = (*windowp)->wd_offset + (*windowp)->wd_size;
cookie->dmac_size = (*windowp)->wd_trim.tr_last_size;
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, new_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_trim.tr_trim_first = B_TRUE;
(*windowp)->wd_trim.tr_first_paddr = cookie->dmac_laddress + coffset;
(*windowp)->wd_trim.tr_first_size = trim_sz;
if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
(*windowp)->wd_dosync = B_TRUE;
(*windowp)->wd_trim.tr_first_copybuf_win = B_TRUE;
(*windowp)->wd_trim.tr_first_pidx = pidx;
(*windowp)->wd_trim.tr_first_cbaddr = dma->dp_cbaddr;
poff = (*windowp)->wd_trim.tr_first_paddr & MMU_PAGEOFFSET;
paddr = pfn_to_pa(hat_getpfnum(kas.a_hat, dma->dp_cbaddr)) +
poff;
(*windowp)->wd_trim.tr_first_paddr =
ROOTNEX_PADDR_TO_RBASE(paddr);
*copybuf_used += MMU_PAGESIZE;
cookie++;
dma->dp_pgmap[pidx + 1].pm_cbaddr += MMU_PAGESIZE;
poff = cookie->dmac_laddress & MMU_PAGEOFFSET;
paddr = pfn_to_pa(hat_getpfnum(kas.a_hat,
dma->dp_pgmap[pidx + 1].pm_cbaddr)) + poff;
cookie->dmac_laddress = ROOTNEX_PADDR_TO_RBASE(paddr);
} else {
cookie++;
}
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size = trim_sz + cookie->dmac_size;
ASSERT((*windowp)->wd_size < dma->dp_maxxfer);
*copybuf_used += MMU_PAGESIZE;
return (DDI_SUCCESS);
}
static int
rootnex_maxxfer_window_boundary(ddi_dma_impl_t *hp, rootnex_dma_t *dma,
rootnex_window_t **windowp, ddi_dma_cookie_t *cookie)
{
size_t dmac_size;
off_t new_offset;
size_t trim_sz;
off_t coffset;
trim_sz = ((*windowp)->wd_size + cookie->dmac_size) - dma->dp_maxxfer;
ASSERT(trim_sz <= cookie->dmac_size);
ASSERT(trim_sz <= dma->dp_maxxfer);
dmac_size = cookie->dmac_size;
if (trim_sz < cookie->dmac_size) {
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_trim.tr_trim_last = B_TRUE;
(*windowp)->wd_trim.tr_last_cookie = cookie;
(*windowp)->wd_trim.tr_last_paddr = cookie->dmac_laddress;
(*windowp)->wd_trim.tr_last_size = cookie->dmac_size - trim_sz;
(*windowp)->wd_size = dma->dp_maxxfer;
cookie->dmac_size = (*windowp)->wd_trim.tr_last_size;
}
coffset = dmac_size - trim_sz;
new_offset = (*windowp)->wd_offset + (*windowp)->wd_size;
(*windowp)++;
rootnex_init_win(hp, dma, *windowp, cookie, new_offset);
(*windowp)->wd_cookie_cnt++;
(*windowp)->wd_size = trim_sz;
if (trim_sz < dmac_size) {
(*windowp)->wd_trim.tr_trim_first = B_TRUE;
(*windowp)->wd_trim.tr_first_paddr = cookie->dmac_laddress +
coffset;
(*windowp)->wd_trim.tr_first_size = trim_sz;
}
return (DDI_SUCCESS);
}
static int
rootnex_coredma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
off_t off, size_t len, uint_t cache_flags)
{
rootnex_sglinfo_t *sinfo;
rootnex_pgmap_t *cbpage;
rootnex_window_t *win;
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
caddr_t fromaddr;
caddr_t toaddr;
uint_t psize;
off_t offset;
uint_t pidx;
size_t size;
off_t poff;
int e;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
sinfo = &dma->dp_sglinfo;
if (dma->dp_window == NULL) {
return (DDI_SUCCESS);
}
win = &dma->dp_window[dma->dp_current_win];
if (!win->wd_dosync) {
return (DDI_SUCCESS);
}
if ((off == 0) || (rootnex_sync_ignore_params)) {
offset = win->wd_offset;
} else {
offset = off;
}
if ((len == 0) || (rootnex_sync_ignore_params)) {
size = win->wd_size;
} else {
size = len;
}
if (rootnex_sync_check_parms) {
e = rootnex_valid_sync_parms(hp, win, offset, size,
cache_flags);
if (e != DDI_SUCCESS) {
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_SYNC_FAIL]);
return (DDI_FAILURE);
}
}
poff = (sinfo->si_buf_offset + offset) & MMU_PAGEOFFSET;
psize = MIN((MMU_PAGESIZE - poff), size);
while (size > 0) {
pidx = (sinfo->si_buf_offset + offset) >> MMU_PAGESHIFT;
ASSERT(pidx < sinfo->si_max_pages);
cbpage = &dma->dp_pgmap[pidx];
ASSERT((cbpage->pm_uses_copybuf == B_TRUE) ||
(cbpage->pm_uses_copybuf == B_FALSE));
if (cbpage->pm_uses_copybuf) {
ASSERT(((uintptr_t)cbpage->pm_cbaddr &
MMU_PAGEOFFSET) == 0);
ASSERT(((uintptr_t)cbpage->pm_kaddr &
MMU_PAGEOFFSET) == 0);
if (cache_flags == DDI_DMA_SYNC_FORDEV) {
fromaddr = cbpage->pm_kaddr + poff;
toaddr = cbpage->pm_cbaddr + poff;
ROOTNEX_DPROBE2(rootnex__sync__dev,
dev_info_t *, dma->dp_dip, size_t, psize);
} else {
fromaddr = cbpage->pm_cbaddr + poff;
toaddr = cbpage->pm_kaddr + poff;
ROOTNEX_DPROBE2(rootnex__sync__cpu,
dev_info_t *, dma->dp_dip, size_t, psize);
}
bcopy(fromaddr, toaddr, psize);
}
size -= psize;
offset += psize;
psize = MIN(MMU_PAGESIZE, size);
poff = 0;
}
return (DDI_SUCCESS);
}
static int
rootnex_dma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
off_t off, size_t len, uint_t cache_flags)
{
#if !defined(__xpv)
if (IOMMU_USED(rdip)) {
return (iommulib_nexdma_sync(dip, rdip, handle, off, len,
cache_flags));
}
#endif
return (rootnex_coredma_sync(dip, rdip, handle, off, len,
cache_flags));
}
static int
rootnex_valid_sync_parms(ddi_dma_impl_t *hp, rootnex_window_t *win,
off_t offset, size_t size, uint_t cache_flags)
{
off_t woffset;
if (offset < win->wd_offset) {
return (DDI_FAILURE);
}
woffset = offset - win->wd_offset;
if ((woffset + size) > win->wd_size) {
return (DDI_FAILURE);
}
if ((cache_flags == DDI_DMA_SYNC_FORDEV) &&
(hp->dmai_rflags & DDI_DMA_WRITE)) {
return (DDI_SUCCESS);
}
if (((cache_flags == DDI_DMA_SYNC_FORCPU) ||
(cache_flags == DDI_DMA_SYNC_FORKERNEL)) &&
(hp->dmai_rflags & DDI_DMA_READ)) {
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
static int
rootnex_coredma_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)
{
rootnex_window_t *window;
rootnex_trim_t *trim;
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
ddi_dma_obj_t *dmao;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
if (win >= hp->dmai_nwin) {
ROOTNEX_DPROF_INC(&rootnex_cnt[ROOTNEX_CNT_GETWIN_FAIL]);
return (DDI_FAILURE);
}
dmao = dma->dp_dvma_used ? &dma->dp_dvma : &dma->dp_dma;
if (dma->dp_window == NULL) {
if (win != 0) {
ROOTNEX_DPROF_INC(
&rootnex_cnt[ROOTNEX_CNT_GETWIN_FAIL]);
return (DDI_FAILURE);
}
hp->dmai_cookie = dma->dp_cookies;
*offp = 0;
*lenp = dmao->dmao_size;
*ccountp = dma->dp_sglinfo.si_sgl_size;
*cookiep = hp->dmai_cookie[0];
hp->dmai_cookie++;
hp->dmai_ncookies = *ccountp;
hp->dmai_curcookie = 1;
return (DDI_SUCCESS);
}
window = &dma->dp_window[dma->dp_current_win];
if ((window->wd_dosync) && (hp->dmai_rflags & DDI_DMA_READ)) {
(void) rootnex_coredma_sync(dip, rdip, handle, 0, 0,
DDI_DMA_SYNC_FORCPU);
}
dma->dp_current_win = win;
window = &dma->dp_window[win];
trim = &window->wd_trim;
if (trim->tr_trim_first) {
window->wd_first_cookie->dmac_laddress = trim->tr_first_paddr;
window->wd_first_cookie->dmac_size = trim->tr_first_size;
if (trim->tr_first_copybuf_win) {
dma->dp_pgmap[trim->tr_first_pidx].pm_cbaddr =
trim->tr_first_cbaddr;
}
}
if (trim->tr_trim_last) {
trim->tr_last_cookie->dmac_laddress = trim->tr_last_paddr;
trim->tr_last_cookie->dmac_size = trim->tr_last_size;
if (trim->tr_last_copybuf_win) {
dma->dp_pgmap[trim->tr_last_pidx].pm_cbaddr =
trim->tr_last_cbaddr;
}
}
hp->dmai_cookie = window->wd_first_cookie;
*offp = window->wd_offset;
*lenp = window->wd_size;
*ccountp = window->wd_cookie_cnt;
*cookiep = hp->dmai_cookie[0];
hp->dmai_ncookies = *ccountp;
hp->dmai_curcookie = 1;
hp->dmai_cookie++;
if ((window->wd_dosync) && (hp->dmai_rflags & DDI_DMA_WRITE)) {
(void) rootnex_coredma_sync(dip, rdip, handle, 0, 0,
DDI_DMA_SYNC_FORDEV);
}
return (DDI_SUCCESS);
}
static int
rootnex_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)
{
#if !defined(__xpv)
if (IOMMU_USED(rdip)) {
return (iommulib_nexdma_win(dip, rdip, handle, win, offp, lenp,
cookiep, ccountp));
}
#endif
return (rootnex_coredma_win(dip, rdip, handle, win, offp, lenp,
cookiep, ccountp));
}
#if !defined(__xpv)
static int
rootnex_coredma_hdl_setprivate(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle, void *v)
{
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
dma->dp_iommu_private = v;
return (DDI_SUCCESS);
}
static void *
rootnex_coredma_hdl_getprivate(dev_info_t *dip, dev_info_t *rdip,
ddi_dma_handle_t handle)
{
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
hp = (ddi_dma_impl_t *)handle;
dma = (rootnex_dma_t *)hp->dmai_private;
return (dma->dp_iommu_private);
}
#endif
static int
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)
{
return (DDI_FAILURE);
}
static int
rootnex_fm_init(dev_info_t *dip, dev_info_t *tdip, int tcap,
ddi_iblock_cookie_t *ibc)
{
*ibc = rootnex_state->r_err_ibc;
return (ddi_system_fmcap);
}
static int
rootnex_dma_check(dev_info_t *dip, const void *handle, const void *addr,
const void *not_used)
{
rootnex_window_t *window;
uint64_t start_addr;
uint64_t fault_addr;
ddi_dma_impl_t *hp;
rootnex_dma_t *dma;
uint64_t end_addr;
size_t csize;
int i;
int j;
hp = (ddi_dma_impl_t *)handle;
ASSERT(hp);
dma = (rootnex_dma_t *)hp->dmai_private;
fault_addr = *(uint64_t *)addr;
if (dma->dp_window == NULL) {
for (i = 0; i < dma->dp_sglinfo.si_sgl_size; i++) {
if ((fault_addr >= dma->dp_cookies[i].dmac_laddress) &&
(fault_addr <= (dma->dp_cookies[i].dmac_laddress +
dma->dp_cookies[i].dmac_size))) {
return (DDI_FM_NONFATAL);
}
}
return (DDI_FM_UNKNOWN);
}
for (i = 0; i < hp->dmai_nwin; i++) {
window = &dma->dp_window[i];
for (j = 0; j < window->wd_cookie_cnt; j++) {
start_addr = window->wd_first_cookie[j].dmac_laddress;
csize = window->wd_first_cookie[j].dmac_size;
if (window->wd_trim.tr_trim_first && (j == 0)) {
start_addr = window->wd_trim.tr_first_paddr;
csize = window->wd_trim.tr_first_size;
}
if (window->wd_trim.tr_trim_last &&
(j == (window->wd_cookie_cnt - 1))) {
start_addr = window->wd_trim.tr_last_paddr;
csize = window->wd_trim.tr_last_size;
}
end_addr = start_addr + csize;
if ((fault_addr >= start_addr) &&
(fault_addr <= end_addr)) {
return (DDI_FM_NONFATAL);
}
}
}
return (DDI_FM_UNKNOWN);
}
static int
rootnex_quiesce(dev_info_t *dip)
{
#if !defined(__xpv)
return (immu_quiesce());
#else
return (DDI_SUCCESS);
#endif
}
#if defined(__xpv)
void
immu_init(void)
{
;
}
void
immu_startup(void)
{
;
}
void
immu_physmem_update(uint64_t addr, uint64_t size)
{
;
}
#endif