10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1961Scth * Common Development and Distribution License (the "License"). 6*1961Scth * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1961Scth * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_SUNNDI_H 270Sstevel@tonic-gate #define _SYS_SUNNDI_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* 320Sstevel@tonic-gate * Sun Specific NDI definitions 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/esunddi.h> 370Sstevel@tonic-gate #include <sys/sunddi.h> 380Sstevel@tonic-gate #include <sys/obpdefs.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate #ifdef _KERNEL 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define NDI_SUCCESS DDI_SUCCESS /* successful return */ 470Sstevel@tonic-gate #define NDI_FAILURE DDI_FAILURE /* unsuccessful return */ 480Sstevel@tonic-gate #define NDI_NOMEM -2 /* failed to allocate resources */ 490Sstevel@tonic-gate #define NDI_BADHANDLE -3 /* bad handle passed to in function */ 500Sstevel@tonic-gate #define NDI_FAULT -4 /* fault during copyin/copyout */ 510Sstevel@tonic-gate #define NDI_BUSY -5 /* device busy - could not offline */ 520Sstevel@tonic-gate #define NDI_UNBOUND -6 /* device not bound to a driver */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Property functions: See also, ddipropdefs.h. 560Sstevel@tonic-gate * In general, the underlying driver MUST be held 570Sstevel@tonic-gate * to call it's property functions. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * Used to create boolean properties 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate int 640Sstevel@tonic-gate ndi_prop_create_boolean(dev_t match_dev, dev_info_t *dip, char *name); 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * Used to create, modify, and lookup integer properties 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate int 700Sstevel@tonic-gate ndi_prop_update_int(dev_t match_dev, dev_info_t *dip, char *name, int data); 710Sstevel@tonic-gate 720Sstevel@tonic-gate int 730Sstevel@tonic-gate ndi_prop_update_int_array(dev_t match_dev, dev_info_t *dip, char *name, 740Sstevel@tonic-gate int *data, uint_t nelements); 750Sstevel@tonic-gate 760Sstevel@tonic-gate int 770Sstevel@tonic-gate ndi_prop_update_int64(dev_t match_dev, dev_info_t *dip, char *name, 780Sstevel@tonic-gate int64_t data); 790Sstevel@tonic-gate 800Sstevel@tonic-gate int 810Sstevel@tonic-gate ndi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip, char *name, 820Sstevel@tonic-gate int64_t *data, uint_t nelements); 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Used to create, modify, and lookup string properties 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate int 880Sstevel@tonic-gate ndi_prop_update_string(dev_t match_dev, dev_info_t *dip, char *name, 890Sstevel@tonic-gate char *data); 900Sstevel@tonic-gate 910Sstevel@tonic-gate int 920Sstevel@tonic-gate ndi_prop_update_string_array(dev_t match_dev, dev_info_t *dip, 930Sstevel@tonic-gate char *name, char **data, uint_t nelements); 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Used to create, modify, and lookup byte properties 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate int 990Sstevel@tonic-gate ndi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip, 1000Sstevel@tonic-gate char *name, uchar_t *data, uint_t nelements); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Used to remove properties 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate int 1060Sstevel@tonic-gate ndi_prop_remove(dev_t dev, dev_info_t *dip, char *name); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate void 1090Sstevel@tonic-gate ndi_prop_remove_all(dev_info_t *dip); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Nexus Driver Functions 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate /* 1150Sstevel@tonic-gate * Allocate and initialize a new dev_info structure. 1160Sstevel@tonic-gate * This routine will often be called at interrupt time by a nexus in 1170Sstevel@tonic-gate * response to a hotplug event, therefore memory allocations are 1180Sstevel@tonic-gate * not allowed to sleep. 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate int 121789Sahrens ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid, 1220Sstevel@tonic-gate dev_info_t **ret_dip); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate void 125789Sahrens ndi_devi_alloc_sleep(dev_info_t *parent, char *node_name, pnode_t nodeid, 1260Sstevel@tonic-gate dev_info_t **ret_dip); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Remove an initialized (but not yet attached) dev_info 1300Sstevel@tonic-gate * node from it's parent. 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate int 1330Sstevel@tonic-gate ndi_devi_free(dev_info_t *dip); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* devinfo locking: use DEVI_BUSY_OWNED in ASSERTs to verify */ 1360Sstevel@tonic-gate void ndi_devi_enter(dev_info_t *dip, int *circ); 1370Sstevel@tonic-gate void ndi_devi_exit(dev_info_t *dip, int circ); 1380Sstevel@tonic-gate int ndi_devi_tryenter(dev_info_t *dip, int *circ); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* devinfo ref counting */ 1410Sstevel@tonic-gate void ndi_hold_devi(dev_info_t *dip); 1420Sstevel@tonic-gate void ndi_rele_devi(dev_info_t *dip); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* driver ref counting */ 1450Sstevel@tonic-gate struct dev_ops *ndi_hold_driver(dev_info_t *dip); 1460Sstevel@tonic-gate void ndi_rele_driver(dev_info_t *dip); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* 1490Sstevel@tonic-gate * Change the node name 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate int 1520Sstevel@tonic-gate ndi_devi_set_nodename(dev_info_t *dip, char *name, int flags); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * Place the devinfo in the DS_BOUND state, 1560Sstevel@tonic-gate * binding a driver to the device 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * Flags: 1590Sstevel@tonic-gate * all flags are ignored. 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate int 1620Sstevel@tonic-gate ndi_devi_bind_driver(dev_info_t *dip, uint_t flags); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * Asynchronous version of ndi_devi_bind_driver, callable from 1660Sstevel@tonic-gate * interrupt context. The dip must be a persistent node. 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate int 1690Sstevel@tonic-gate ndi_devi_bind_driver_async(dev_info_t *dip, uint_t flags); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Return devctl state of the child addressed by "name@addr". 1730Sstevel@tonic-gate * For use by a driver's DEVCTL_DEVICE_GETSTATE handler. 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate int 1760Sstevel@tonic-gate ndi_devctl_device_getstate(dev_info_t *parent, struct devctl_iocdata *dcp, 1770Sstevel@tonic-gate uint_t *state); 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Transition the child addressed by "name@addr" to the online state. 1810Sstevel@tonic-gate * For use by a driver's DEVCTL_DEVICE_ONLINE handler. 1820Sstevel@tonic-gate */ 1830Sstevel@tonic-gate int 1840Sstevel@tonic-gate ndi_devctl_device_online(dev_info_t *dip, struct devctl_iocdata *dcp, 1850Sstevel@tonic-gate uint_t flags); 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * Transition the child addressed by "name@addr" to the offline state. 1890Sstevel@tonic-gate * For use by a driver's DEVCTL_DEVICE_OFFLINE handler. 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate int 1920Sstevel@tonic-gate ndi_devctl_device_offline(dev_info_t *dip, struct devctl_iocdata *dcp, 1930Sstevel@tonic-gate uint_t flags); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* 1960Sstevel@tonic-gate * Remove the child addressed by name@addr. 1970Sstevel@tonic-gate * For use by a driver's DEVCTL_DEVICE_REMOVE handler. 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate int 2000Sstevel@tonic-gate ndi_devctl_device_remove(dev_info_t *dip, struct devctl_iocdata *dcp, 2010Sstevel@tonic-gate uint_t flags); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * Bus get state 2050Sstevel@tonic-gate * For use by a driver's DEVCTL_BUS_GETSTATE handler. 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate int 2080Sstevel@tonic-gate ndi_devctl_bus_getstate(dev_info_t *dip, struct devctl_iocdata *dcp, 2090Sstevel@tonic-gate uint_t *state); 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2120Sstevel@tonic-gate * Place the devinfo in the ONLINE state 2130Sstevel@tonic-gate */ 2140Sstevel@tonic-gate int 2150Sstevel@tonic-gate ndi_devi_online(dev_info_t *dip, uint_t flags); 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * Generic devctl ioctl handler 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate int 2210Sstevel@tonic-gate ndi_devctl_ioctl(dev_info_t *dip, int cmd, intptr_t arg, int mode, 2220Sstevel@tonic-gate uint_t flags); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate /* 2250Sstevel@tonic-gate * Asynchronous version of ndi_devi_online, callable from interrupt 2260Sstevel@tonic-gate * context. The dip must be a persistent node. 2270Sstevel@tonic-gate */ 2280Sstevel@tonic-gate int 2290Sstevel@tonic-gate ndi_devi_online_async(dev_info_t *dip, uint_t flags); 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /* 2330Sstevel@tonic-gate * Configure children of a nexus node. 2340Sstevel@tonic-gate * 2350Sstevel@tonic-gate * Flags: 2360Sstevel@tonic-gate * NDI_ONLINE_ATTACH - Attach driver to devinfo node when placing 2370Sstevel@tonic-gate * the device Online. 2380Sstevel@tonic-gate * NDI_CONFIG - Recursively configure children if child is nexus node 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate int 2410Sstevel@tonic-gate ndi_devi_config(dev_info_t *dip, int flags); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate int 2440Sstevel@tonic-gate ndi_devi_config_driver(dev_info_t *dip, int flags, major_t major); 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate int 2470Sstevel@tonic-gate ndi_devi_config_one(dev_info_t *dip, char *devnm, dev_info_t **dipp, int flags); 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * Unconfigure children of a nexus node. 2510Sstevel@tonic-gate * 2520Sstevel@tonic-gate * Flags: 2530Sstevel@tonic-gate * NDI_DEVI_REMOVE - Remove child devinfo nodes 2540Sstevel@tonic-gate * 2550Sstevel@tonic-gate * NDI_UNCONFIG - Put child devinfo nodes to uninitialized state, 2560Sstevel@tonic-gate * release resources held by child nodes. 2570Sstevel@tonic-gate */ 2580Sstevel@tonic-gate int 2590Sstevel@tonic-gate ndi_devi_unconfig(dev_info_t *dip, int flags); 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate int 2620Sstevel@tonic-gate e_ddi_devi_unconfig(dev_info_t *dip, dev_info_t **dipp, int flags); 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate int 2650Sstevel@tonic-gate ndi_devi_unconfig_one(dev_info_t *dip, char *devnm, dev_info_t **dipp, 2660Sstevel@tonic-gate int flags); 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate int 2690Sstevel@tonic-gate ndi_devi_unconfig_driver(dev_info_t *dip, int flags, major_t major); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Take a device node "Offline". 2730Sstevel@tonic-gate * 2740Sstevel@tonic-gate * Offline means to detach the device instance from the bound 2750Sstevel@tonic-gate * driver and setting the devinfo state to prevent deferred attach 2760Sstevel@tonic-gate * from re-attaching the device instance. 2770Sstevel@tonic-gate * 2780Sstevel@tonic-gate * Flags: 2790Sstevel@tonic-gate * NDI_DEVI_REMOVE - Remove the node from the devinfo tree after 2800Sstevel@tonic-gate * first taking it Offline. 2810Sstevel@tonic-gate */ 2820Sstevel@tonic-gate 283*1961Scth #define NDI_DEVI_REMOVE 0x00000001 /* remove after unconfig */ 284*1961Scth #define NDI_ONLINE_ATTACH 0x00000002 /* online/attach after config */ 285*1961Scth #define NDI_MDI_FALLBACK 0x00000004 /* Leadville to fallback to phci */ 286*1961Scth #define NDI_CONFIG 0x00000008 /* recursively config descendants */ 287*1961Scth #define NDI_UNCONFIG 0x00000010 /* unconfig to uninitialized state */ 288*1961Scth #define NDI_DEVI_BIND 0x00000020 /* transition to DS_BOUND state */ 289*1961Scth #define NDI_DEVI_PERSIST 0x00000040 /* do not config offlined nodes */ 290*1961Scth #define NDI_PROMNAME 0x00000080 /* name comes from prom */ 291*1961Scth #define NDI_DEVFS_CLEAN 0x00001000 /* clean dv_nodes only, no detach */ 292*1961Scth #define NDI_AUTODETACH 0x00002000 /* moduninstall daemon */ 293*1961Scth #define NDI_NO_EVENT 0x00004000 /* don't devfs add/remove events */ 294*1961Scth #define NDI_DEVI_DEBUG 0x00008000 /* turn on observability */ 295*1961Scth #define NDI_CONFIG_REPROBE 0x00010000 /* force reprobe (deferred attach) */ 296*1961Scth #define NDI_DEVI_ONLINE 0x00020000 /* force offlined device to online */ 297*1961Scth #define NDI_DEVI_OFFLINE 0x00040000 /* set detached device to offline */ 298*1961Scth #define NDI_POST_EVENT 0x00080000 /* Post NDI events before remove */ 299*1961Scth #define NDI_BRANCH_EVENT_OP 0x01000000 /* branch op needs branch event */ 300*1961Scth #define NDI_NO_EVENT_STATE_CHNG 0x02000000 /* don't change the event state */ 301*1961Scth #define NDI_DRV_CONF_REPROBE 0x04000000 /* reprobe conf-enum'd nodes only */ 302*1961Scth #define NDI_DETACH_DRIVER 0x08000000 /* performing driver_detach */ 303*1961Scth #define NDI_MTC_OFF 0x10000000 /* disable multi-threading */ 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate /* ndi interface flag values */ 3060Sstevel@tonic-gate #define NDI_SLEEP 0x000000 3070Sstevel@tonic-gate #define NDI_NOSLEEP 0x100000 3080Sstevel@tonic-gate #define NDI_EVENT_NOPASS 0x200000 /* do not pass event req up the tree */ 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate int 3110Sstevel@tonic-gate ndi_devi_offline(dev_info_t *dip, uint_t flags); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * Find the child dev_info node of parent nexus 'p' whose name 3150Sstevel@tonic-gate * matches "cname"@"caddr". Use ndi_devi_findchild() instead. 3160Sstevel@tonic-gate */ 3170Sstevel@tonic-gate dev_info_t * 3180Sstevel@tonic-gate ndi_devi_find(dev_info_t *p, char *cname, char *caddr); 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * Find the child dev_info node of parent nexus 'p' whose name 3220Sstevel@tonic-gate * matches device name "name"@"addr". 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate dev_info_t * 3250Sstevel@tonic-gate ndi_devi_findchild(dev_info_t *p, char *devname); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* 3280Sstevel@tonic-gate * generate debug msg via NDI_DEVI_DEBUG flag 3290Sstevel@tonic-gate */ 3300Sstevel@tonic-gate #define NDI_DEBUG(flags, args) \ 3310Sstevel@tonic-gate if (flags & NDI_DEVI_DEBUG) cmn_err args 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate /* 3340Sstevel@tonic-gate * Copy in the devctl IOCTL data structure and the strings referenced 3350Sstevel@tonic-gate * by the structure. 3360Sstevel@tonic-gate * 3370Sstevel@tonic-gate * Convenience functions for use by nexus drivers as part of the 3380Sstevel@tonic-gate * implementation of devctl IOCTL handling. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate int 3410Sstevel@tonic-gate ndi_dc_allochdl(void *iocarg, struct devctl_iocdata **rdcp); 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate void 3440Sstevel@tonic-gate ndi_dc_freehdl(struct devctl_iocdata *dcp); 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate char * 3470Sstevel@tonic-gate ndi_dc_getpath(struct devctl_iocdata *dcp); 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate char * 3500Sstevel@tonic-gate ndi_dc_getname(struct devctl_iocdata *dcp); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate char * 3530Sstevel@tonic-gate ndi_dc_getaddr(struct devctl_iocdata *dcp); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate nvlist_t * 3560Sstevel@tonic-gate ndi_dc_get_ap_data(struct devctl_iocdata *dcp); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate char * 3590Sstevel@tonic-gate ndi_dc_getminorname(struct devctl_iocdata *dcp); 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate int 3620Sstevel@tonic-gate ndi_dc_return_dev_state(dev_info_t *dip, struct devctl_iocdata *dcp); 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate int 3650Sstevel@tonic-gate ndi_dc_return_ap_state(devctl_ap_state_t *ap, struct devctl_iocdata *dcp); 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate int 3680Sstevel@tonic-gate ndi_dc_return_bus_state(dev_info_t *dip, struct devctl_iocdata *dcp); 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate int 3710Sstevel@tonic-gate ndi_dc_devi_create(struct devctl_iocdata *dcp, dev_info_t *pdip, int flags, 3720Sstevel@tonic-gate dev_info_t **rdip); 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate int 3750Sstevel@tonic-gate ndi_get_bus_state(dev_info_t *dip, uint_t *rstate); 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate int 3780Sstevel@tonic-gate ndi_set_bus_state(dev_info_t *dip, uint_t state); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /* 3810Sstevel@tonic-gate * Post an event notification up the device tree hierarchy to the 3820Sstevel@tonic-gate * parent nexus, until claimed by a bus nexus driver or the top 3830Sstevel@tonic-gate * of the dev_info tree is reached. 3840Sstevel@tonic-gate */ 3850Sstevel@tonic-gate int 3860Sstevel@tonic-gate ndi_post_event(dev_info_t *dip, dev_info_t *rdip, ddi_eventcookie_t eventhdl, 3870Sstevel@tonic-gate void *impl_data); 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* 3900Sstevel@tonic-gate * Called by the NDI Event Framework to deliver a registration request to the 3910Sstevel@tonic-gate * appropriate bus nexus driver. 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate int 3940Sstevel@tonic-gate ndi_busop_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 3950Sstevel@tonic-gate ddi_eventcookie_t eventhdl, void (*callback)(), void *arg, 3960Sstevel@tonic-gate ddi_callback_id_t *cb_id); 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /* 3990Sstevel@tonic-gate * Called by the NDI Event Framework to deliver an unregister request to the 4000Sstevel@tonic-gate * appropriate bus nexus driver. 4010Sstevel@tonic-gate */ 4020Sstevel@tonic-gate int 4030Sstevel@tonic-gate ndi_busop_remove_eventcall(dev_info_t *ddip, ddi_callback_id_t id); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate /* 4060Sstevel@tonic-gate * Called by the NDI Event Framework and/or a bus nexus driver's 4070Sstevel@tonic-gate * implementation of the (*bus_get_eventcookie)() interface up the device tree 4080Sstevel@tonic-gate * hierarchy, until claimed by a bus nexus driver or the top of the dev_info 4090Sstevel@tonic-gate * tree is reached. The NDI Event Framework will skip nexus drivers which are 4100Sstevel@tonic-gate * not configured to handle NDI events. 4110Sstevel@tonic-gate */ 4120Sstevel@tonic-gate int 4130Sstevel@tonic-gate ndi_busop_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, char *name, 4140Sstevel@tonic-gate ddi_eventcookie_t *event_cookiep); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /* 4170Sstevel@tonic-gate * ndi event callback support routines: 4180Sstevel@tonic-gate * 4190Sstevel@tonic-gate * these functions require an opaque ndi event handle 4200Sstevel@tonic-gate */ 4210Sstevel@tonic-gate typedef struct ndi_event_hdl *ndi_event_hdl_t; 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* 4240Sstevel@tonic-gate * structure for maintaining each registered callback 4250Sstevel@tonic-gate */ 4260Sstevel@tonic-gate typedef struct ndi_event_callbacks { 4270Sstevel@tonic-gate struct ndi_event_callbacks *ndi_evtcb_next; 4280Sstevel@tonic-gate struct ndi_event_callbacks *ndi_evtcb_prev; 4290Sstevel@tonic-gate dev_info_t *ndi_evtcb_dip; 4300Sstevel@tonic-gate char *devname; /* name of device defining this callback */ 4310Sstevel@tonic-gate void (*ndi_evtcb_callback)(); 4320Sstevel@tonic-gate void *ndi_evtcb_arg; 4330Sstevel@tonic-gate ddi_eventcookie_t ndi_evtcb_cookie; 4340Sstevel@tonic-gate } ndi_event_callbacks_t; 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* 4370Sstevel@tonic-gate * a nexus driver defines events that it can support using the 4380Sstevel@tonic-gate * following structure 4390Sstevel@tonic-gate */ 4400Sstevel@tonic-gate typedef struct ndi_event_definition { 4410Sstevel@tonic-gate int ndi_event_tag; 4420Sstevel@tonic-gate char *ndi_event_name; 4430Sstevel@tonic-gate ddi_plevel_t ndi_event_plevel; 4440Sstevel@tonic-gate uint_t ndi_event_attributes; 4450Sstevel@tonic-gate } ndi_event_definition_t; 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate typedef struct ndi_event_cookie { 4480Sstevel@tonic-gate ndi_event_definition_t *definition; /* Event Description */ 4490Sstevel@tonic-gate dev_info_t *ddip; /* Devi defining this event */ 4500Sstevel@tonic-gate ndi_event_callbacks_t *callback_list; /* Cb's reg'd to w/ this evt */ 4510Sstevel@tonic-gate struct ndi_event_cookie *next_cookie; /* Next cookie def'd in hdl */ 4520Sstevel@tonic-gate } ndi_event_cookie_t; 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate #define NDI_EVENT(cookie) ((struct ndi_event_cookie *)(void *)(cookie)) 4560Sstevel@tonic-gate #define NDI_EVENT_NAME(cookie) (NDI_EVENT(cookie)->definition->ndi_event_name) 4570Sstevel@tonic-gate #define NDI_EVENT_TAG(cookie) (NDI_EVENT(cookie)->definition->ndi_event_tag) 4580Sstevel@tonic-gate #define NDI_EVENT_ATTRIBUTES(cookie) \ 4590Sstevel@tonic-gate (NDI_EVENT(cookie)->definition->ndi_event_attributes) 4600Sstevel@tonic-gate #define NDI_EVENT_PLEVEL(cookie) \ 4610Sstevel@tonic-gate (NDI_EVENT(cookie)->definition->ndi_event_plevel) 4620Sstevel@tonic-gate #define NDI_EVENT_DDIP(cookie) (NDI_EVENT(cookie)->ddip) 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* ndi_event_attributes */ 4650Sstevel@tonic-gate #define NDI_EVENT_POST_TO_ALL 0x0 /* broadcast: post to all handlers */ 4660Sstevel@tonic-gate #define NDI_EVENT_POST_TO_TGT 0x1 /* call only specific child's hdlr */ 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate typedef struct ndi_event_set { 4690Sstevel@tonic-gate ushort_t ndi_events_version; 4700Sstevel@tonic-gate ushort_t ndi_n_events; 4710Sstevel@tonic-gate ndi_event_definition_t *ndi_event_defs; 4720Sstevel@tonic-gate } ndi_event_set_t; 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate #define NDI_EVENTS_REV0 0 4760Sstevel@tonic-gate #define NDI_EVENTS_REV1 1 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * allocate an ndi event handle 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate int 4820Sstevel@tonic-gate ndi_event_alloc_hdl(dev_info_t *dip, ddi_iblock_cookie_t cookie, 4830Sstevel@tonic-gate ndi_event_hdl_t *ndi_event_hdl, uint_t flag); 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate /* 4860Sstevel@tonic-gate * free the ndi event handle 4870Sstevel@tonic-gate */ 4880Sstevel@tonic-gate int 4890Sstevel@tonic-gate ndi_event_free_hdl(ndi_event_hdl_t handle); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate /* 4920Sstevel@tonic-gate * bind or unbind a set of events to/from the event handle 4930Sstevel@tonic-gate */ 4940Sstevel@tonic-gate int 4950Sstevel@tonic-gate ndi_event_bind_set(ndi_event_hdl_t handle, 4960Sstevel@tonic-gate ndi_event_set_t *ndi_event_set, 4970Sstevel@tonic-gate uint_t flag); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate int 5000Sstevel@tonic-gate ndi_event_unbind_set(ndi_event_hdl_t handle, 5010Sstevel@tonic-gate ndi_event_set_t *ndi_event_set, 5020Sstevel@tonic-gate uint_t flag); 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* 5050Sstevel@tonic-gate * get an event cookie 5060Sstevel@tonic-gate */ 5070Sstevel@tonic-gate int 5080Sstevel@tonic-gate ndi_event_retrieve_cookie(ndi_event_hdl_t handle, 5090Sstevel@tonic-gate dev_info_t *child_dip, 5100Sstevel@tonic-gate char *eventname, 5110Sstevel@tonic-gate ddi_eventcookie_t *cookiep, 5120Sstevel@tonic-gate uint_t flag); 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * add an event callback info to the ndi event handle 5160Sstevel@tonic-gate */ 5170Sstevel@tonic-gate int 5180Sstevel@tonic-gate ndi_event_add_callback(ndi_event_hdl_t handle, 5190Sstevel@tonic-gate dev_info_t *child_dip, 5200Sstevel@tonic-gate ddi_eventcookie_t cookie, 5210Sstevel@tonic-gate void (*event_callback) 5220Sstevel@tonic-gate (dev_info_t *, 5230Sstevel@tonic-gate ddi_eventcookie_t, 5240Sstevel@tonic-gate void *arg, 5250Sstevel@tonic-gate void *impldata), 5260Sstevel@tonic-gate void *arg, 5270Sstevel@tonic-gate uint_t flag, 5280Sstevel@tonic-gate ddi_callback_id_t *cb_id); 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate /* 5310Sstevel@tonic-gate * remove an event callback registration from the ndi event handle 5320Sstevel@tonic-gate */ 5330Sstevel@tonic-gate int 5340Sstevel@tonic-gate ndi_event_remove_callback(ndi_event_hdl_t handle, ddi_callback_id_t id); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate /* 5370Sstevel@tonic-gate * perform callbacks for a specified cookie 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate int 5400Sstevel@tonic-gate ndi_event_run_callbacks(ndi_event_hdl_t handle, dev_info_t *child_dip, 5410Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata); 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * do callback for just one child_dip, regardless of attributes 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate int ndi_event_do_callback(ndi_event_hdl_t handle, dev_info_t *child_dip, 5470Sstevel@tonic-gate ddi_eventcookie_t cookie, void *bus_impldata); 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate /* 5500Sstevel@tonic-gate * ndi_event_tag_to_cookie: utility function to find an event cookie 5510Sstevel@tonic-gate * given an event tag 5520Sstevel@tonic-gate */ 5530Sstevel@tonic-gate ddi_eventcookie_t 5540Sstevel@tonic-gate ndi_event_tag_to_cookie(ndi_event_hdl_t handle, int event_tag); 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate /* 5570Sstevel@tonic-gate * ndi_event_cookie_to_tag: utility function to find an event tag 5580Sstevel@tonic-gate * given an event_cookie 5590Sstevel@tonic-gate */ 5600Sstevel@tonic-gate int 5610Sstevel@tonic-gate ndi_event_cookie_to_tag(ndi_event_hdl_t handle, 5620Sstevel@tonic-gate ddi_eventcookie_t cookie); 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * ndi_event_cookie_to_name: utility function to find an event 5660Sstevel@tonic-gate * name given an event_cookie 5670Sstevel@tonic-gate */ 5680Sstevel@tonic-gate char * 5690Sstevel@tonic-gate ndi_event_cookie_to_name(ndi_event_hdl_t handle, 5700Sstevel@tonic-gate ddi_eventcookie_t cookie); 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate /* 5730Sstevel@tonic-gate * ndi_event_tag_to_name: utility function to find an event 5740Sstevel@tonic-gate * name given an event_tag 5750Sstevel@tonic-gate */ 5760Sstevel@tonic-gate char * 5770Sstevel@tonic-gate ndi_event_tag_to_name(ndi_event_hdl_t handle, int event_tag); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate dev_info_t * 5800Sstevel@tonic-gate ndi_devi_config_vhci(char *, int); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate #ifdef DEBUG 5830Sstevel@tonic-gate /* 5840Sstevel@tonic-gate * ndi_event_dump_hdl: debug functionality used to display event handle 5850Sstevel@tonic-gate */ 5860Sstevel@tonic-gate void 5870Sstevel@tonic-gate ndi_event_dump_hdl(struct ndi_event_hdl *hdl, char *location); 5880Sstevel@tonic-gate #endif 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate /* 5910Sstevel@tonic-gate * Default busop bus_config helper functions 5920Sstevel@tonic-gate */ 5930Sstevel@tonic-gate int 5940Sstevel@tonic-gate ndi_busop_bus_config(dev_info_t *pdip, uint_t flags, ddi_bus_config_op_t op, 5950Sstevel@tonic-gate void *arg, dev_info_t **child, clock_t reset_delay); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate int 5980Sstevel@tonic-gate ndi_busop_bus_unconfig(dev_info_t *dip, uint_t flags, ddi_bus_config_op_t op, 5990Sstevel@tonic-gate void *arg); 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate /* 6030Sstevel@tonic-gate * Bus Resource allocation structures and function prototypes exported 6040Sstevel@tonic-gate * by busra module 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate /* structure for specifying a request */ 6080Sstevel@tonic-gate typedef struct ndi_ra_request { 6090Sstevel@tonic-gate uint_t ra_flags; /* General flags */ 6100Sstevel@tonic-gate /* see bit definitions below */ 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate uint64_t ra_len; /* Requested allocation length */ 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate uint64_t ra_addr; /* Specific base address requested */ 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate uint64_t ra_boundbase; /* Base address of the area for */ 6170Sstevel@tonic-gate /* the allocated resource to be */ 6180Sstevel@tonic-gate /* restricted to */ 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate uint64_t ra_boundlen; /* Length of the area, starting */ 6210Sstevel@tonic-gate /* from ra_boundbase, for the */ 6220Sstevel@tonic-gate /* allocated resource to be */ 6230Sstevel@tonic-gate /* restricted to. */ 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate uint64_t ra_align_mask; /* Alignment mask used for */ 6260Sstevel@tonic-gate /* allocated base address */ 6270Sstevel@tonic-gate } ndi_ra_request_t; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate /* ra_flags bit definitions */ 6310Sstevel@tonic-gate #define NDI_RA_ALIGN_SIZE 0x0001 /* Set the alignment of the */ 6320Sstevel@tonic-gate /* allocated resource address */ 6330Sstevel@tonic-gate /* according to the ra_len */ 6340Sstevel@tonic-gate /* value (alignment mask will */ 6350Sstevel@tonic-gate /* be (ra_len - 1)). Value of */ 6360Sstevel@tonic-gate /* ra_len has to be power of 2. */ 6370Sstevel@tonic-gate /* If this flag is set, value of */ 6380Sstevel@tonic-gate /* ra_align_mask will be ignored. */ 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate #define NDI_RA_ALLOC_BOUNDED 0x0002 /* Indicates that the resource */ 6420Sstevel@tonic-gate /* should be restricted to the */ 6430Sstevel@tonic-gate /* area specified by ra_boundbase */ 6440Sstevel@tonic-gate /* and ra_boundlen */ 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate #define NDI_RA_ALLOC_SPECIFIED 0x0004 /* Indicates that a specific */ 6470Sstevel@tonic-gate /* address (ra_addr value) is */ 6480Sstevel@tonic-gate /* requested. */ 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate #define NDI_RA_ALLOC_PARTIAL_OK 0x0008 /* Indicates if requested size */ 6510Sstevel@tonic-gate /* (ra_len) chunk is not available */ 6520Sstevel@tonic-gate /* then allocate as big chunk as */ 6530Sstevel@tonic-gate /* possible which is less than or */ 6540Sstevel@tonic-gate /* equal to ra_len size. */ 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate /* return values specific to bus resource allocator */ 6580Sstevel@tonic-gate #define NDI_RA_PARTIAL_REQ -7 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate /* Predefined types for generic type of resources */ 6640Sstevel@tonic-gate #define NDI_RA_TYPE_MEM "memory" 6650Sstevel@tonic-gate #define NDI_RA_TYPE_IO "io" 6660Sstevel@tonic-gate #define NDI_RA_TYPE_PCI_BUSNUM "pci_bus_number" 6670Sstevel@tonic-gate #define NDI_RA_TYPE_PCI_PREFETCH_MEM "pci_prefetchable_memory" 6680Sstevel@tonic-gate #define NDI_RA_TYPE_INTR "interrupt" 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate /* flag bit definition */ 6730Sstevel@tonic-gate #define NDI_RA_PASS 0x0001 /* pass request up the dev tree */ 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate /* 6770Sstevel@tonic-gate * Prototype definitions for functions exported 6780Sstevel@tonic-gate */ 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate int 6810Sstevel@tonic-gate ndi_ra_map_setup(dev_info_t *dip, char *type); 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate int 6840Sstevel@tonic-gate ndi_ra_map_destroy(dev_info_t *dip, char *type); 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate int 6870Sstevel@tonic-gate ndi_ra_alloc(dev_info_t *dip, ndi_ra_request_t *req, uint64_t *basep, 6880Sstevel@tonic-gate uint64_t *lenp, char *type, uint_t flag); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate int 6910Sstevel@tonic-gate ndi_ra_free(dev_info_t *dip, uint64_t base, uint64_t len, char *type, 6920Sstevel@tonic-gate uint_t flag); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate /* 6960Sstevel@tonic-gate * ndi_dev_is_prom_node: Return non-zero if the node is a prom node 6970Sstevel@tonic-gate */ 6980Sstevel@tonic-gate int ndi_dev_is_prom_node(dev_info_t *); 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate /* 7010Sstevel@tonic-gate * ndi_dev_is_pseudo_node: Return non-zero if the node is a pseudo node. 7020Sstevel@tonic-gate * NB: all non-prom nodes are pseudo nodes. 7030Sstevel@tonic-gate * c.f. ndi_dev_is_persistent_node 7040Sstevel@tonic-gate */ 7050Sstevel@tonic-gate int ndi_dev_is_pseudo_node(dev_info_t *); 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate /* 7080Sstevel@tonic-gate * ndi_dev_is_persistent_node: Return non-zero if the node has the 7090Sstevel@tonic-gate * property of persistence. 7100Sstevel@tonic-gate */ 7110Sstevel@tonic-gate int ndi_dev_is_persistent_node(dev_info_t *); 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate /* 7140Sstevel@tonic-gate * Event posted when a fault is reported 7150Sstevel@tonic-gate */ 7160Sstevel@tonic-gate #define DDI_DEVI_FAULT_EVENT "DDI:DEVI_FAULT" 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate struct ddi_fault_event_data { 7190Sstevel@tonic-gate dev_info_t *f_dip; 7200Sstevel@tonic-gate ddi_fault_impact_t f_impact; 7210Sstevel@tonic-gate ddi_fault_location_t f_location; 7220Sstevel@tonic-gate const char *f_message; 7230Sstevel@tonic-gate ddi_devstate_t f_oldstate; 7240Sstevel@tonic-gate }; 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate /* 7270Sstevel@tonic-gate * Access handle/DMA handle fault flag setting/clearing functions for nexi 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate void ndi_set_acc_fault(ddi_acc_handle_t ah); 7300Sstevel@tonic-gate void ndi_clr_acc_fault(ddi_acc_handle_t ah); 7310Sstevel@tonic-gate void ndi_set_dma_fault(ddi_dma_handle_t dh); 7320Sstevel@tonic-gate void ndi_clr_dma_fault(ddi_dma_handle_t dh); 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate /* Driver.conf property merging */ 7350Sstevel@tonic-gate int ndi_merge_node(dev_info_t *, int (*)(dev_info_t *, char *, int)); 7360Sstevel@tonic-gate void ndi_merge_wildcard_node(dev_info_t *); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate #endif /* _KERNEL */ 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate #ifdef __cplusplus 7410Sstevel@tonic-gate } 7420Sstevel@tonic-gate #endif 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate #endif /* _SYS_SUNNDI_H */ 745