xref: /titanic_52/usr/src/uts/common/sys/sunndi.h (revision 5cd376e8b7030707d78315f63adb4bb2b4d9963e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5144dfaa9Scth  * Common Development and Distribution License (the "License").
6144dfaa9Scth  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*5cd376e8SJimmy Vetayases  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_SYS_SUNNDI_H
267c478bd9Sstevel@tonic-gate #define	_SYS_SUNNDI_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Sun Specific NDI definitions
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/esunddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef _KERNEL
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	NDI_SUCCESS	DDI_SUCCESS	/* successful return */
437c478bd9Sstevel@tonic-gate #define	NDI_FAILURE	DDI_FAILURE	/* unsuccessful return */
447c478bd9Sstevel@tonic-gate #define	NDI_NOMEM	-2		/* failed to allocate resources */
457c478bd9Sstevel@tonic-gate #define	NDI_BADHANDLE	-3		/* bad handle passed to in function */
467c478bd9Sstevel@tonic-gate #define	NDI_FAULT	-4		/* fault during copyin/copyout */
477c478bd9Sstevel@tonic-gate #define	NDI_BUSY	-5		/* device busy - could not offline */
487c478bd9Sstevel@tonic-gate #define	NDI_UNBOUND	-6		/* device not bound to a driver */
4926947304SEvan Yan #define	NDI_EINVAL	-7		/* invalid request or arguments */
5026947304SEvan Yan #define	NDI_ENOTSUP	-8		/* operation or event not supported */
5126947304SEvan Yan #define	NDI_CLAIMED	NDI_SUCCESS	/* event is claimed */
5226947304SEvan Yan #define	NDI_UNCLAIMED	-9		/* event is not claimed */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Property functions:   See also, ddipropdefs.h.
567c478bd9Sstevel@tonic-gate  *			In general, the underlying driver MUST be held
577c478bd9Sstevel@tonic-gate  *			to call it's property functions.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Used to create boolean properties
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate int
647c478bd9Sstevel@tonic-gate ndi_prop_create_boolean(dev_t match_dev, dev_info_t *dip, char *name);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Used to create, modify, and lookup integer properties
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate int
707c478bd9Sstevel@tonic-gate ndi_prop_update_int(dev_t match_dev, dev_info_t *dip, char *name, int data);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate int
737c478bd9Sstevel@tonic-gate ndi_prop_update_int_array(dev_t match_dev, dev_info_t *dip, char *name,
747c478bd9Sstevel@tonic-gate     int *data, uint_t nelements);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate int
777c478bd9Sstevel@tonic-gate ndi_prop_update_int64(dev_t match_dev, dev_info_t *dip, char *name,
787c478bd9Sstevel@tonic-gate     int64_t data);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate int
817c478bd9Sstevel@tonic-gate ndi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip, char *name,
827c478bd9Sstevel@tonic-gate     int64_t *data, uint_t nelements);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * Used to create, modify, and lookup string properties
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate int
887c478bd9Sstevel@tonic-gate ndi_prop_update_string(dev_t match_dev, dev_info_t *dip, char *name,
897c478bd9Sstevel@tonic-gate     char *data);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate int
927c478bd9Sstevel@tonic-gate ndi_prop_update_string_array(dev_t match_dev, dev_info_t *dip,
937c478bd9Sstevel@tonic-gate     char *name, char **data, uint_t nelements);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * Used to create, modify, and lookup byte properties
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate int
997c478bd9Sstevel@tonic-gate ndi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip,
1007c478bd9Sstevel@tonic-gate     char *name, uchar_t *data, uint_t nelements);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Used to remove properties
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate int
1067c478bd9Sstevel@tonic-gate ndi_prop_remove(dev_t dev, dev_info_t *dip, char *name);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate void
1097c478bd9Sstevel@tonic-gate ndi_prop_remove_all(dev_info_t *dip);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Nexus Driver Functions
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Allocate and initialize a new dev_info structure.
1167c478bd9Sstevel@tonic-gate  * This routine will often be called at interrupt time by a nexus in
1177c478bd9Sstevel@tonic-gate  * response to a hotplug event, therefore memory allocations are
1187c478bd9Sstevel@tonic-gate  * not allowed to sleep.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate int
121fa9e4066Sahrens ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid,
1227c478bd9Sstevel@tonic-gate     dev_info_t **ret_dip);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate void
125fa9e4066Sahrens ndi_devi_alloc_sleep(dev_info_t *parent, char *node_name, pnode_t nodeid,
1267c478bd9Sstevel@tonic-gate     dev_info_t **ret_dip);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Remove an initialized (but not yet attached) dev_info
1307c478bd9Sstevel@tonic-gate  * node from it's parent.
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate int
1337c478bd9Sstevel@tonic-gate ndi_devi_free(dev_info_t *dip);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /* devinfo locking: use DEVI_BUSY_OWNED in ASSERTs to verify */
1367c478bd9Sstevel@tonic-gate void ndi_devi_enter(dev_info_t *dip, int *circ);
1377c478bd9Sstevel@tonic-gate void ndi_devi_exit(dev_info_t *dip, int circ);
1387c478bd9Sstevel@tonic-gate int ndi_devi_tryenter(dev_info_t *dip, int *circ);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /* devinfo ref counting */
1417c478bd9Sstevel@tonic-gate void ndi_hold_devi(dev_info_t *dip);
1427c478bd9Sstevel@tonic-gate void ndi_rele_devi(dev_info_t *dip);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /* driver ref counting */
1457c478bd9Sstevel@tonic-gate struct dev_ops *ndi_hold_driver(dev_info_t *dip);
1467c478bd9Sstevel@tonic-gate void ndi_rele_driver(dev_info_t *dip);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Change the node name
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate int
1527c478bd9Sstevel@tonic-gate ndi_devi_set_nodename(dev_info_t *dip, char *name, int flags);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Place the devinfo in the DS_BOUND state,
1567c478bd9Sstevel@tonic-gate  * binding a driver to the device
1577c478bd9Sstevel@tonic-gate  *
1587c478bd9Sstevel@tonic-gate  * Flags:
1597c478bd9Sstevel@tonic-gate  *	all flags are ignored.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate int
1627c478bd9Sstevel@tonic-gate ndi_devi_bind_driver(dev_info_t *dip, uint_t flags);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * Asynchronous version of ndi_devi_bind_driver, callable from
1667c478bd9Sstevel@tonic-gate  * interrupt context. The dip must be a persistent node.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate int
1697c478bd9Sstevel@tonic-gate ndi_devi_bind_driver_async(dev_info_t *dip, uint_t flags);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * Return devctl state of the child addressed by "name@addr".
1737c478bd9Sstevel@tonic-gate  * For use by a driver's DEVCTL_DEVICE_GETSTATE handler.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate int
1767c478bd9Sstevel@tonic-gate ndi_devctl_device_getstate(dev_info_t *parent, struct devctl_iocdata *dcp,
1777c478bd9Sstevel@tonic-gate 	uint_t *state);
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Transition the child addressed by "name@addr" to the online state.
1817c478bd9Sstevel@tonic-gate  * For use by a driver's DEVCTL_DEVICE_ONLINE handler.
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate int
1847c478bd9Sstevel@tonic-gate ndi_devctl_device_online(dev_info_t *dip, struct devctl_iocdata *dcp,
1857c478bd9Sstevel@tonic-gate 	uint_t flags);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Transition the child addressed by "name@addr" to the offline state.
1897c478bd9Sstevel@tonic-gate  * For use by a driver's DEVCTL_DEVICE_OFFLINE handler.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate int
1927c478bd9Sstevel@tonic-gate ndi_devctl_device_offline(dev_info_t *dip, struct devctl_iocdata *dcp,
1937c478bd9Sstevel@tonic-gate 	uint_t flags);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Remove the child addressed by name@addr.
1977c478bd9Sstevel@tonic-gate  * For use by a driver's DEVCTL_DEVICE_REMOVE handler.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate int
2007c478bd9Sstevel@tonic-gate ndi_devctl_device_remove(dev_info_t *dip, struct devctl_iocdata *dcp,
2017c478bd9Sstevel@tonic-gate 	uint_t flags);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * Bus get state
2057c478bd9Sstevel@tonic-gate  * For use by a driver's DEVCTL_BUS_GETSTATE handler.
2067c478bd9Sstevel@tonic-gate  */
2077c478bd9Sstevel@tonic-gate int
2087c478bd9Sstevel@tonic-gate ndi_devctl_bus_getstate(dev_info_t *dip, struct devctl_iocdata *dcp,
2097c478bd9Sstevel@tonic-gate 	uint_t *state);
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * Place the devinfo in the ONLINE state
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate int
2157c478bd9Sstevel@tonic-gate ndi_devi_online(dev_info_t *dip, uint_t flags);
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * Generic devctl ioctl handler
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate int
2217c478bd9Sstevel@tonic-gate ndi_devctl_ioctl(dev_info_t *dip, int cmd, intptr_t arg, int mode,
2227c478bd9Sstevel@tonic-gate 	uint_t flags);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Asynchronous version of ndi_devi_online, callable from interrupt
2267c478bd9Sstevel@tonic-gate  * context. The dip must be a persistent node.
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate int
2297c478bd9Sstevel@tonic-gate ndi_devi_online_async(dev_info_t *dip, uint_t flags);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * Configure children of a nexus node.
2347c478bd9Sstevel@tonic-gate  *
2357c478bd9Sstevel@tonic-gate  * Flags:
2367c478bd9Sstevel@tonic-gate  *	NDI_ONLINE_ATTACH - Attach driver to devinfo node when placing
2377c478bd9Sstevel@tonic-gate  *			    the device Online.
2387c478bd9Sstevel@tonic-gate  *	NDI_CONFIG - Recursively configure children if child is nexus node
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate int
2417c478bd9Sstevel@tonic-gate ndi_devi_config(dev_info_t *dip, int flags);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate int
2447c478bd9Sstevel@tonic-gate ndi_devi_config_driver(dev_info_t *dip, int flags, major_t major);
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate int
2477c478bd9Sstevel@tonic-gate ndi_devi_config_one(dev_info_t *dip, char *devnm, dev_info_t **dipp, int flags);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * Unconfigure children of a nexus node.
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  * Flags:
2537c478bd9Sstevel@tonic-gate  *	NDI_DEVI_REMOVE - Remove child devinfo nodes
2547c478bd9Sstevel@tonic-gate  *
2557c478bd9Sstevel@tonic-gate  *	NDI_UNCONFIG - Put child devinfo nodes to uninitialized state,
2567c478bd9Sstevel@tonic-gate  *			release resources held by child nodes.
2577c478bd9Sstevel@tonic-gate  */
2587c478bd9Sstevel@tonic-gate int
2597c478bd9Sstevel@tonic-gate ndi_devi_unconfig(dev_info_t *dip, int flags);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate int
2627c478bd9Sstevel@tonic-gate e_ddi_devi_unconfig(dev_info_t *dip, dev_info_t **dipp, int flags);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate int
2657c478bd9Sstevel@tonic-gate ndi_devi_unconfig_one(dev_info_t *dip, char *devnm, dev_info_t **dipp,
2667c478bd9Sstevel@tonic-gate     int flags);
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate int
2697c478bd9Sstevel@tonic-gate ndi_devi_unconfig_driver(dev_info_t *dip, int flags, major_t major);
2707c478bd9Sstevel@tonic-gate 
271eae2e508Skrishnae void
272eae2e508Skrishnae ndi_set_bus_private(dev_info_t *dip, boolean_t up, uint32_t port_type,
273eae2e508Skrishnae     void *data);
274eae2e508Skrishnae 
275eae2e508Skrishnae void *
276eae2e508Skrishnae ndi_get_bus_private(dev_info_t *dip, boolean_t up);
277eae2e508Skrishnae 
278eae2e508Skrishnae boolean_t
279eae2e508Skrishnae ndi_port_type(dev_info_t *dip, boolean_t up, uint32_t port_type);
280eae2e508Skrishnae 
2817c478bd9Sstevel@tonic-gate /*
2827ff178cdSJimmy Vetayases  * Interrupt Resource Management (IRM) Pools.
2835febcb4aSScott Carter, SD IOSW  */
2845febcb4aSScott Carter, SD IOSW int
2855febcb4aSScott Carter, SD IOSW ndi_irm_create(dev_info_t *dip, ddi_irm_params_t *paramsp,
2865febcb4aSScott Carter, SD IOSW     ddi_irm_pool_t **pool_retp);
2875febcb4aSScott Carter, SD IOSW 
2885febcb4aSScott Carter, SD IOSW int
2895febcb4aSScott Carter, SD IOSW ndi_irm_destroy(ddi_irm_pool_t *poolp);
2905febcb4aSScott Carter, SD IOSW 
2917ff178cdSJimmy Vetayases int
2927ff178cdSJimmy Vetayases ndi_irm_resize_pool(ddi_irm_pool_t *poolp, uint_t newsize);
2937ff178cdSJimmy Vetayases 
2945febcb4aSScott Carter, SD IOSW /*
2957c478bd9Sstevel@tonic-gate  * Take a device node "Offline".
2967c478bd9Sstevel@tonic-gate  *
2977c478bd9Sstevel@tonic-gate  * Offline means to detach the device instance from the bound
2987c478bd9Sstevel@tonic-gate  * driver and setting the devinfo state to prevent deferred attach
2997c478bd9Sstevel@tonic-gate  * from re-attaching the device instance.
3007c478bd9Sstevel@tonic-gate  *
3017c478bd9Sstevel@tonic-gate  * Flags:
3027c478bd9Sstevel@tonic-gate  *	NDI_DEVI_REMOVE	- Remove the node from the devinfo tree after
3037c478bd9Sstevel@tonic-gate  *			  first taking it Offline.
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate 
3065e3986cbScth #define	NDI_DEVI_REMOVE		0x00000001 /* remove after unconfig */
3075e3986cbScth #define	NDI_ONLINE_ATTACH	0x00000002 /* online/attach after config */
3085e3986cbScth #define	NDI_MDI_FALLBACK	0x00000004 /* Leadville to fallback to phci */
3095e3986cbScth #define	NDI_CONFIG		0x00000008 /* recursively config descendants */
3105e3986cbScth #define	NDI_UNCONFIG		0x00000010 /* unconfig to uninitialized state */
3115e3986cbScth #define	NDI_DEVI_BIND		0x00000020 /* transition to DS_BOUND state */
3125e3986cbScth #define	NDI_DEVI_PERSIST	0x00000040 /* do not config offlined nodes */
3135e3986cbScth #define	NDI_PROMNAME		0x00000080 /* name comes from prom */
3145e3986cbScth #define	NDI_DEVFS_CLEAN		0x00001000 /* clean dv_nodes only, no detach */
3155e3986cbScth #define	NDI_AUTODETACH		0x00002000 /* moduninstall daemon */
3165e3986cbScth #define	NDI_NO_EVENT		0x00004000 /* don't devfs add/remove events */
3175e3986cbScth #define	NDI_DEVI_DEBUG		0x00008000 /* turn on observability */
3185e3986cbScth #define	NDI_CONFIG_REPROBE	0x00010000 /* force reprobe (deferred attach) */
3195e3986cbScth #define	NDI_DEVI_ONLINE		0x00020000 /* force offlined device to online */
3205e3986cbScth #define	NDI_DEVI_OFFLINE	0x00040000 /* set detached device to offline */
3215e3986cbScth #define	NDI_POST_EVENT		0x00080000 /* Post NDI events before remove */
3225e3986cbScth #define	NDI_BRANCH_EVENT_OP	0x01000000 /* branch op needs branch event */
3235e3986cbScth #define	NDI_NO_EVENT_STATE_CHNG	0x02000000 /* don't change the event state */
3245e3986cbScth #define	NDI_DRV_CONF_REPROBE	0x04000000 /* reprobe conf-enum'd nodes only */
3255e3986cbScth #define	NDI_DETACH_DRIVER	0x08000000 /* performing driver_detach */
3265e3986cbScth #define	NDI_MTC_OFF		0x10000000 /* disable multi-threading */
3274c06356bSdh142964 #define	NDI_USER_REQ		0x20000000 /* user requested operation */
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate /* ndi interface flag values */
3307c478bd9Sstevel@tonic-gate #define	NDI_SLEEP		0x000000
3317c478bd9Sstevel@tonic-gate #define	NDI_NOSLEEP		0x100000
3327c478bd9Sstevel@tonic-gate #define	NDI_EVENT_NOPASS	0x200000 /* do not pass event req up the tree */
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate int
3357c478bd9Sstevel@tonic-gate ndi_devi_offline(dev_info_t *dip, uint_t flags);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * Find the child dev_info node of parent nexus 'p' whose name
3397c478bd9Sstevel@tonic-gate  * matches "cname"@"caddr".  Use ndi_devi_findchild() instead.
3407c478bd9Sstevel@tonic-gate  */
3417c478bd9Sstevel@tonic-gate dev_info_t *
3427c478bd9Sstevel@tonic-gate ndi_devi_find(dev_info_t *p, char *cname, char *caddr);
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  * Find the child dev_info node of parent nexus 'p' whose name
3467c478bd9Sstevel@tonic-gate  * matches device name "name"@"addr".
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate dev_info_t *
3497c478bd9Sstevel@tonic-gate ndi_devi_findchild(dev_info_t *p, char *devname);
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate /*
3524c06356bSdh142964  * Find the child dev_info node of parent nexus 'p' whose name
3534c06356bSdh142964  * matches "dname"@"ua". If a child doesn't have a "ua"
3544c06356bSdh142964  * value, it calls the function "make_ua" to create it.
3554c06356bSdh142964  */
3564c06356bSdh142964 dev_info_t *
3574c06356bSdh142964 ndi_devi_findchild_by_callback(dev_info_t *p, char *dname, char *ua,
3584c06356bSdh142964     int (*make_ua)(dev_info_t *, char *, int));
3594c06356bSdh142964 
3604c06356bSdh142964 /*
3614c06356bSdh142964  * Maintain DEVI_DEVICE_REMOVED hotplug devi_state for remove/reinsert hotplug
3624c06356bSdh142964  * of open devices.
3634c06356bSdh142964  */
3644c06356bSdh142964 int
3654c06356bSdh142964 ndi_devi_device_isremoved(dev_info_t *dip);
3664c06356bSdh142964 int
3674c06356bSdh142964 ndi_devi_device_remove(dev_info_t *dip);
3684c06356bSdh142964 int
3694c06356bSdh142964 ndi_devi_device_insert(dev_info_t *dip);
3704c06356bSdh142964 
3714c06356bSdh142964 /*
3727c478bd9Sstevel@tonic-gate  * generate debug msg via NDI_DEVI_DEBUG flag
3737c478bd9Sstevel@tonic-gate  */
3747c478bd9Sstevel@tonic-gate #define	NDI_DEBUG(flags, args)	\
3757c478bd9Sstevel@tonic-gate 	if (flags & NDI_DEVI_DEBUG) cmn_err args
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate  * Copy in the devctl IOCTL data structure and the strings referenced
3797c478bd9Sstevel@tonic-gate  * by the structure.
3807c478bd9Sstevel@tonic-gate  *
3817c478bd9Sstevel@tonic-gate  * Convenience functions for use by nexus drivers as part of the
3827c478bd9Sstevel@tonic-gate  * implementation of devctl IOCTL handling.
3837c478bd9Sstevel@tonic-gate  */
3847c478bd9Sstevel@tonic-gate int
3857c478bd9Sstevel@tonic-gate ndi_dc_allochdl(void *iocarg, struct devctl_iocdata **rdcp);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate void
3887c478bd9Sstevel@tonic-gate ndi_dc_freehdl(struct devctl_iocdata *dcp);
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate char *
3917c478bd9Sstevel@tonic-gate ndi_dc_getpath(struct devctl_iocdata *dcp);
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate char *
3947c478bd9Sstevel@tonic-gate ndi_dc_getname(struct devctl_iocdata *dcp);
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate char *
3977c478bd9Sstevel@tonic-gate ndi_dc_getaddr(struct devctl_iocdata *dcp);
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate nvlist_t *
4007c478bd9Sstevel@tonic-gate ndi_dc_get_ap_data(struct devctl_iocdata *dcp);
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate char *
4037c478bd9Sstevel@tonic-gate ndi_dc_getminorname(struct devctl_iocdata *dcp);
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate int
4067c478bd9Sstevel@tonic-gate ndi_dc_return_dev_state(dev_info_t *dip, struct devctl_iocdata *dcp);
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate int
4097c478bd9Sstevel@tonic-gate ndi_dc_return_ap_state(devctl_ap_state_t *ap, struct devctl_iocdata *dcp);
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate int
4127c478bd9Sstevel@tonic-gate ndi_dc_return_bus_state(dev_info_t *dip, struct devctl_iocdata *dcp);
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate int
4157c478bd9Sstevel@tonic-gate ndi_dc_devi_create(struct devctl_iocdata *dcp, dev_info_t *pdip, int flags,
4167c478bd9Sstevel@tonic-gate     dev_info_t **rdip);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate int
4197c478bd9Sstevel@tonic-gate ndi_get_bus_state(dev_info_t *dip, uint_t *rstate);
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate int
4227c478bd9Sstevel@tonic-gate ndi_set_bus_state(dev_info_t *dip, uint_t state);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate  * Post an event notification up the device tree hierarchy to the
4267c478bd9Sstevel@tonic-gate  * parent nexus, until claimed by a bus nexus driver or the top
4277c478bd9Sstevel@tonic-gate  * of the dev_info tree is reached.
4287c478bd9Sstevel@tonic-gate  */
4297c478bd9Sstevel@tonic-gate int
4307c478bd9Sstevel@tonic-gate ndi_post_event(dev_info_t *dip, dev_info_t *rdip, ddi_eventcookie_t eventhdl,
4317c478bd9Sstevel@tonic-gate     void *impl_data);
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate /*
4347c478bd9Sstevel@tonic-gate  * Called by the NDI Event Framework to deliver a registration request to the
4357c478bd9Sstevel@tonic-gate  * appropriate bus nexus driver.
4367c478bd9Sstevel@tonic-gate  */
4377c478bd9Sstevel@tonic-gate int
4387c478bd9Sstevel@tonic-gate ndi_busop_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
4397c478bd9Sstevel@tonic-gate     ddi_eventcookie_t eventhdl, void (*callback)(), void *arg,
4407c478bd9Sstevel@tonic-gate     ddi_callback_id_t *cb_id);
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate /*
4437c478bd9Sstevel@tonic-gate  * Called by the NDI Event Framework to deliver an unregister request to the
4447c478bd9Sstevel@tonic-gate  * appropriate bus nexus driver.
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate int
4477c478bd9Sstevel@tonic-gate ndi_busop_remove_eventcall(dev_info_t *ddip, ddi_callback_id_t id);
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * Called by the NDI Event Framework and/or a bus nexus driver's
4517c478bd9Sstevel@tonic-gate  * implementation of the (*bus_get_eventcookie)() interface up the device tree
4527c478bd9Sstevel@tonic-gate  * hierarchy, until claimed by a bus nexus driver or the top of the dev_info
4537c478bd9Sstevel@tonic-gate  * tree is reached.  The NDI Event Framework will skip nexus drivers which are
4547c478bd9Sstevel@tonic-gate  * not configured to handle NDI events.
4557c478bd9Sstevel@tonic-gate  */
4567c478bd9Sstevel@tonic-gate int
4577c478bd9Sstevel@tonic-gate ndi_busop_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, char *name,
4587c478bd9Sstevel@tonic-gate     ddi_eventcookie_t *event_cookiep);
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate /*
4617c478bd9Sstevel@tonic-gate  * ndi event callback support routines:
4627c478bd9Sstevel@tonic-gate  *
4637c478bd9Sstevel@tonic-gate  * these functions require an opaque ndi event handle
4647c478bd9Sstevel@tonic-gate  */
4657c478bd9Sstevel@tonic-gate typedef struct ndi_event_hdl *ndi_event_hdl_t;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate  * structure for maintaining each registered callback
4697c478bd9Sstevel@tonic-gate  */
4707c478bd9Sstevel@tonic-gate typedef struct ndi_event_callbacks {
4717c478bd9Sstevel@tonic-gate 	struct ndi_event_callbacks *ndi_evtcb_next;
4727c478bd9Sstevel@tonic-gate 	struct ndi_event_callbacks *ndi_evtcb_prev;
4737c478bd9Sstevel@tonic-gate 	dev_info_t	*ndi_evtcb_dip;
4747c478bd9Sstevel@tonic-gate 	char		*devname; /* name of device defining this callback */
4757c478bd9Sstevel@tonic-gate 	void		(*ndi_evtcb_callback)();
4767c478bd9Sstevel@tonic-gate 	void		*ndi_evtcb_arg;
4777c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t	ndi_evtcb_cookie;
4787c478bd9Sstevel@tonic-gate } ndi_event_callbacks_t;
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate /*
4817c478bd9Sstevel@tonic-gate  * a nexus driver defines events that it can support using the
4827c478bd9Sstevel@tonic-gate  * following structure
4837c478bd9Sstevel@tonic-gate  */
4847c478bd9Sstevel@tonic-gate typedef struct ndi_event_definition {
4857c478bd9Sstevel@tonic-gate 	int			ndi_event_tag;
4867c478bd9Sstevel@tonic-gate 	char			*ndi_event_name;
4877c478bd9Sstevel@tonic-gate 	ddi_plevel_t		ndi_event_plevel;
4887c478bd9Sstevel@tonic-gate 	uint_t			ndi_event_attributes;
4897c478bd9Sstevel@tonic-gate } ndi_event_definition_t;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate typedef struct ndi_event_cookie {
4927c478bd9Sstevel@tonic-gate 	ndi_event_definition_t	*definition;	/* Event Description */
4937c478bd9Sstevel@tonic-gate 	dev_info_t		*ddip;		/* Devi defining this event */
4947c478bd9Sstevel@tonic-gate 	ndi_event_callbacks_t	*callback_list; /* Cb's reg'd to w/ this evt */
4957c478bd9Sstevel@tonic-gate 	struct ndi_event_cookie *next_cookie;	/* Next cookie def'd in hdl */
4967c478bd9Sstevel@tonic-gate } ndi_event_cookie_t;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate #define	NDI_EVENT(cookie) ((struct ndi_event_cookie *)(void *)(cookie))
5007c478bd9Sstevel@tonic-gate #define	NDI_EVENT_NAME(cookie) (NDI_EVENT(cookie)->definition->ndi_event_name)
5017c478bd9Sstevel@tonic-gate #define	NDI_EVENT_TAG(cookie) (NDI_EVENT(cookie)->definition->ndi_event_tag)
5027c478bd9Sstevel@tonic-gate #define	NDI_EVENT_ATTRIBUTES(cookie) \
5037c478bd9Sstevel@tonic-gate 	(NDI_EVENT(cookie)->definition->ndi_event_attributes)
5047c478bd9Sstevel@tonic-gate #define	NDI_EVENT_PLEVEL(cookie) \
5057c478bd9Sstevel@tonic-gate 	(NDI_EVENT(cookie)->definition->ndi_event_plevel)
5067c478bd9Sstevel@tonic-gate #define	NDI_EVENT_DDIP(cookie) (NDI_EVENT(cookie)->ddip)
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate /* ndi_event_attributes */
5097c478bd9Sstevel@tonic-gate #define	NDI_EVENT_POST_TO_ALL	0x0 /* broadcast: post to all handlers */
5107c478bd9Sstevel@tonic-gate #define	NDI_EVENT_POST_TO_TGT	0x1 /* call only specific child's hdlr */
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate typedef struct ndi_event_set {
5137c478bd9Sstevel@tonic-gate 	ushort_t		ndi_events_version;
5147c478bd9Sstevel@tonic-gate 	ushort_t		ndi_n_events;
5157c478bd9Sstevel@tonic-gate 	ndi_event_definition_t	*ndi_event_defs;
5167c478bd9Sstevel@tonic-gate } ndi_event_set_t;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate #define	NDI_EVENTS_REV0			0
5207c478bd9Sstevel@tonic-gate #define	NDI_EVENTS_REV1			1
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate /*
5237c478bd9Sstevel@tonic-gate  * allocate an ndi event handle
5247c478bd9Sstevel@tonic-gate  */
5257c478bd9Sstevel@tonic-gate int
5267c478bd9Sstevel@tonic-gate ndi_event_alloc_hdl(dev_info_t *dip, ddi_iblock_cookie_t cookie,
5277c478bd9Sstevel@tonic-gate 	ndi_event_hdl_t *ndi_event_hdl, uint_t flag);
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate /*
5307c478bd9Sstevel@tonic-gate  * free the ndi event handle
5317c478bd9Sstevel@tonic-gate  */
5327c478bd9Sstevel@tonic-gate int
5337c478bd9Sstevel@tonic-gate ndi_event_free_hdl(ndi_event_hdl_t handle);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate /*
5367c478bd9Sstevel@tonic-gate  * bind or unbind a set of events to/from the event handle
5377c478bd9Sstevel@tonic-gate  */
5387c478bd9Sstevel@tonic-gate int
5397c478bd9Sstevel@tonic-gate ndi_event_bind_set(ndi_event_hdl_t	handle,
5407c478bd9Sstevel@tonic-gate 	ndi_event_set_t		*ndi_event_set,
5417c478bd9Sstevel@tonic-gate 	uint_t			flag);
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate int
5447c478bd9Sstevel@tonic-gate ndi_event_unbind_set(ndi_event_hdl_t	handle,
5457c478bd9Sstevel@tonic-gate 	ndi_event_set_t		*ndi_event_set,
5467c478bd9Sstevel@tonic-gate 	uint_t			flag);
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate /*
5497c478bd9Sstevel@tonic-gate  * get an event cookie
5507c478bd9Sstevel@tonic-gate  */
5517c478bd9Sstevel@tonic-gate int
5527c478bd9Sstevel@tonic-gate ndi_event_retrieve_cookie(ndi_event_hdl_t	handle,
5537c478bd9Sstevel@tonic-gate 	dev_info_t		*child_dip,
5547c478bd9Sstevel@tonic-gate 	char			*eventname,
5557c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t	*cookiep,
5567c478bd9Sstevel@tonic-gate 	uint_t			flag);
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate /*
5597c478bd9Sstevel@tonic-gate  * add an event callback info to the ndi event handle
5607c478bd9Sstevel@tonic-gate  */
5617c478bd9Sstevel@tonic-gate int
5627c478bd9Sstevel@tonic-gate ndi_event_add_callback(ndi_event_hdl_t	handle,
5637c478bd9Sstevel@tonic-gate 	dev_info_t		*child_dip,
5647c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t	cookie,
5657c478bd9Sstevel@tonic-gate 	void			(*event_callback)
5667c478bd9Sstevel@tonic-gate 					(dev_info_t *,
5677c478bd9Sstevel@tonic-gate 					ddi_eventcookie_t,
5687c478bd9Sstevel@tonic-gate 					void *arg,
5697c478bd9Sstevel@tonic-gate 					void *impldata),
5707c478bd9Sstevel@tonic-gate 	void			*arg,
5717c478bd9Sstevel@tonic-gate 	uint_t			flag,
5727c478bd9Sstevel@tonic-gate 	ddi_callback_id_t *cb_id);
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate  * remove an event callback registration from the ndi event handle
5767c478bd9Sstevel@tonic-gate  */
5777c478bd9Sstevel@tonic-gate int
5787c478bd9Sstevel@tonic-gate ndi_event_remove_callback(ndi_event_hdl_t handle, ddi_callback_id_t id);
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate /*
5817c478bd9Sstevel@tonic-gate  * perform callbacks for a specified cookie
5827c478bd9Sstevel@tonic-gate  */
5837c478bd9Sstevel@tonic-gate int
5847c478bd9Sstevel@tonic-gate ndi_event_run_callbacks(ndi_event_hdl_t	handle, dev_info_t *child_dip,
5857c478bd9Sstevel@tonic-gate     ddi_eventcookie_t cookie, void *bus_impldata);
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate /*
5887c478bd9Sstevel@tonic-gate  * do callback for just one child_dip, regardless of attributes
5897c478bd9Sstevel@tonic-gate  */
5907c478bd9Sstevel@tonic-gate int ndi_event_do_callback(ndi_event_hdl_t handle, dev_info_t *child_dip,
5917c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t cookie, void *bus_impldata);
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate /*
5947c478bd9Sstevel@tonic-gate  * ndi_event_tag_to_cookie: utility function to find an event cookie
5957c478bd9Sstevel@tonic-gate  * given an event tag
5967c478bd9Sstevel@tonic-gate  */
5977c478bd9Sstevel@tonic-gate ddi_eventcookie_t
5987c478bd9Sstevel@tonic-gate ndi_event_tag_to_cookie(ndi_event_hdl_t handle, int event_tag);
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * ndi_event_cookie_to_tag: utility function to find an event tag
6027c478bd9Sstevel@tonic-gate  * given an event_cookie
6037c478bd9Sstevel@tonic-gate  */
6047c478bd9Sstevel@tonic-gate int
6057c478bd9Sstevel@tonic-gate ndi_event_cookie_to_tag(ndi_event_hdl_t handle,
6067c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t cookie);
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate  * ndi_event_cookie_to_name: utility function to find an event
6107c478bd9Sstevel@tonic-gate  * name given an event_cookie
6117c478bd9Sstevel@tonic-gate  */
6127c478bd9Sstevel@tonic-gate char *
6137c478bd9Sstevel@tonic-gate ndi_event_cookie_to_name(ndi_event_hdl_t handle,
6147c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t cookie);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate /*
6177c478bd9Sstevel@tonic-gate  * ndi_event_tag_to_name: utility function to find an event
6187c478bd9Sstevel@tonic-gate  * name given an event_tag
6197c478bd9Sstevel@tonic-gate  */
6207c478bd9Sstevel@tonic-gate char *
6217c478bd9Sstevel@tonic-gate ndi_event_tag_to_name(ndi_event_hdl_t	handle, int event_tag);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate dev_info_t *
6247c478bd9Sstevel@tonic-gate ndi_devi_config_vhci(char *, int);
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate #ifdef DEBUG
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate  * ndi_event_dump_hdl: debug functionality used to display event handle
6297c478bd9Sstevel@tonic-gate  */
6307c478bd9Sstevel@tonic-gate void
6317c478bd9Sstevel@tonic-gate ndi_event_dump_hdl(struct ndi_event_hdl *hdl, char *location);
6327c478bd9Sstevel@tonic-gate #endif
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate /*
6357c478bd9Sstevel@tonic-gate  * Default busop bus_config helper functions
6367c478bd9Sstevel@tonic-gate  */
6377c478bd9Sstevel@tonic-gate int
6387c478bd9Sstevel@tonic-gate ndi_busop_bus_config(dev_info_t *pdip, uint_t flags, ddi_bus_config_op_t op,
6397c478bd9Sstevel@tonic-gate     void *arg, dev_info_t **child, clock_t reset_delay);
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate int
6427c478bd9Sstevel@tonic-gate ndi_busop_bus_unconfig(dev_info_t *dip, uint_t flags, ddi_bus_config_op_t op,
6437c478bd9Sstevel@tonic-gate     void *arg);
6447c478bd9Sstevel@tonic-gate 
64526947304SEvan Yan /*
64626947304SEvan Yan  * Called by the Nexus/HPC drivers to register, unregister and interact
64726947304SEvan Yan  * with the hotplug framework for the specified hotplug connection.
64826947304SEvan Yan  */
64926947304SEvan Yan int
65026947304SEvan Yan ndi_hp_register(dev_info_t *dip, ddi_hp_cn_info_t *info_p);
65126947304SEvan Yan 
65226947304SEvan Yan int
65326947304SEvan Yan ndi_hp_unregister(dev_info_t *dip, char *cn_name);
65426947304SEvan Yan 
65526947304SEvan Yan int
65626947304SEvan Yan ndi_hp_state_change_req(dev_info_t *dip, char *cn_name,
65726947304SEvan Yan     ddi_hp_cn_state_t state, uint_t flag);
65826947304SEvan Yan 
65926947304SEvan Yan void
66026947304SEvan Yan ndi_hp_walk_cn(dev_info_t *dip, int (*f)(ddi_hp_cn_info_t *, void *),
66126947304SEvan Yan     void *arg);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate /*
6647c478bd9Sstevel@tonic-gate  * Bus Resource allocation structures and function prototypes exported
6657c478bd9Sstevel@tonic-gate  * by busra module
6667c478bd9Sstevel@tonic-gate  */
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate /* structure for specifying a request */
6697c478bd9Sstevel@tonic-gate typedef struct ndi_ra_request {
6707c478bd9Sstevel@tonic-gate 	uint_t		ra_flags;	/* General flags		*/
6717c478bd9Sstevel@tonic-gate 					/* see bit definitions below	*/
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	uint64_t	ra_len;		/* Requested allocation length	*/
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 	uint64_t	ra_addr;	/* Specific base address requested */
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	uint64_t	ra_boundbase;	/* Base address of the area for	*/
6787c478bd9Sstevel@tonic-gate 					/* the allocated resource to be	*/
6797c478bd9Sstevel@tonic-gate 					/* restricted to		*/
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	uint64_t	ra_boundlen;	/* Length of the area, starting	*/
6827c478bd9Sstevel@tonic-gate 					/* from ra_boundbase, for the	*/
6837c478bd9Sstevel@tonic-gate 					/* allocated resource to be	*/
6847c478bd9Sstevel@tonic-gate 					/* restricted to.   		*/
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 	uint64_t	ra_align_mask;	/* Alignment mask used for	*/
6877c478bd9Sstevel@tonic-gate 					/* allocated base address	*/
6887c478bd9Sstevel@tonic-gate } ndi_ra_request_t;
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate /* ra_flags bit definitions */
6927c478bd9Sstevel@tonic-gate #define	NDI_RA_ALIGN_SIZE	0x0001	/* Set the alignment of the	*/
6937c478bd9Sstevel@tonic-gate 					/* allocated resource address	*/
6947c478bd9Sstevel@tonic-gate 					/* according to the ra_len	*/
6957c478bd9Sstevel@tonic-gate 					/* value (alignment mask will	*/
6967c478bd9Sstevel@tonic-gate 					/* be (ra_len - 1)). Value of	*/
6977c478bd9Sstevel@tonic-gate 					/* ra_len has to be power of 2.	*/
6987c478bd9Sstevel@tonic-gate 					/* If this flag is set, value of */
6997c478bd9Sstevel@tonic-gate 					/* ra_align_mask will be ignored. */
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate #define	NDI_RA_ALLOC_BOUNDED	0x0002	/* Indicates that the resource	*/
7037c478bd9Sstevel@tonic-gate 					/* should be restricted to the	*/
7047c478bd9Sstevel@tonic-gate 					/* area specified by ra_boundbase */
7057c478bd9Sstevel@tonic-gate 					/* and ra_boundlen */
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate #define	NDI_RA_ALLOC_SPECIFIED	0x0004	/* Indicates that a specific	*/
7087c478bd9Sstevel@tonic-gate 					/* address (ra_addr value) is	*/
7097c478bd9Sstevel@tonic-gate 					/* requested.			*/
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate #define	NDI_RA_ALLOC_PARTIAL_OK	0x0008  /* Indicates if requested size	*/
7127c478bd9Sstevel@tonic-gate 					/* (ra_len) chunk is not available */
7137c478bd9Sstevel@tonic-gate 					/* then allocate as big chunk as */
7147c478bd9Sstevel@tonic-gate 					/* possible which is less than or */
7157c478bd9Sstevel@tonic-gate 					/* equal to ra_len size. */
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate /* return values specific to bus resource allocator */
7197c478bd9Sstevel@tonic-gate #define	NDI_RA_PARTIAL_REQ		-7
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate /* Predefined types for generic type of resources */
7257c478bd9Sstevel@tonic-gate #define	NDI_RA_TYPE_MEM			"memory"
7267c478bd9Sstevel@tonic-gate #define	NDI_RA_TYPE_IO			"io"
7277c478bd9Sstevel@tonic-gate #define	NDI_RA_TYPE_PCI_BUSNUM		"pci_bus_number"
7287c478bd9Sstevel@tonic-gate #define	NDI_RA_TYPE_PCI_PREFETCH_MEM	"pci_prefetchable_memory"
7297c478bd9Sstevel@tonic-gate #define	NDI_RA_TYPE_INTR		"interrupt"
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate /* flag bit definition */
7327c478bd9Sstevel@tonic-gate #define	NDI_RA_PASS	0x0001		/* pass request up the dev tree */
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate /*
7357c478bd9Sstevel@tonic-gate  * Prototype definitions for functions exported
7367c478bd9Sstevel@tonic-gate  */
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate int
7397c478bd9Sstevel@tonic-gate ndi_ra_map_setup(dev_info_t *dip, char *type);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate int
7427c478bd9Sstevel@tonic-gate ndi_ra_map_destroy(dev_info_t *dip, char *type);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate int
7457c478bd9Sstevel@tonic-gate ndi_ra_alloc(dev_info_t *dip, ndi_ra_request_t *req, uint64_t *basep,
7467c478bd9Sstevel@tonic-gate 	uint64_t *lenp, char *type, uint_t flag);
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate int
7497c478bd9Sstevel@tonic-gate ndi_ra_free(dev_info_t *dip, uint64_t base, uint64_t len, char *type,
7507c478bd9Sstevel@tonic-gate 	uint_t flag);
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate  * ndi_dev_is_prom_node: Return non-zero if the node is a prom node
7547c478bd9Sstevel@tonic-gate  */
7557c478bd9Sstevel@tonic-gate int ndi_dev_is_prom_node(dev_info_t *);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate /*
7587c478bd9Sstevel@tonic-gate  * ndi_dev_is_pseudo_node: Return non-zero if the node is a pseudo node.
7597c478bd9Sstevel@tonic-gate  * NB: all non-prom nodes are pseudo nodes.
7607c478bd9Sstevel@tonic-gate  * c.f. ndi_dev_is_persistent_node
7617c478bd9Sstevel@tonic-gate  */
7627c478bd9Sstevel@tonic-gate int ndi_dev_is_pseudo_node(dev_info_t *);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate /*
7657c478bd9Sstevel@tonic-gate  * ndi_dev_is_persistent_node: Return non-zero if the node has the
7667c478bd9Sstevel@tonic-gate  * property of persistence.
7677c478bd9Sstevel@tonic-gate  */
7687c478bd9Sstevel@tonic-gate int ndi_dev_is_persistent_node(dev_info_t *);
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate /*
7714c06356bSdh142964  * ndi_dev_is_hotplug_node: Return non-zero if the node was created by hotplug.
7724c06356bSdh142964  */
7734c06356bSdh142964 int ndi_dev_is_hotplug_node(dev_info_t *);
7744c06356bSdh142964 
7754c06356bSdh142964 /*
776027021c7SChris Horne  * ndi_dev_is_hidden_node: Return non-zero if the node is hidden.
777027021c7SChris Horne  */
778027021c7SChris Horne int ndi_dev_is_hidden_node(dev_info_t *);
779027021c7SChris Horne 
780027021c7SChris Horne /*
781027021c7SChris Horne  * ndi_devi_set_hidden: mark a node as hidden
782027021c7SChris Horne  * ndi_devi_clr_hidden: mark a node as visible
783027021c7SChris Horne  */
784027021c7SChris Horne void ndi_devi_set_hidden(dev_info_t *);
785027021c7SChris Horne void ndi_devi_clr_hidden(dev_info_t *);
786027021c7SChris Horne 
787027021c7SChris Horne /*
7887c478bd9Sstevel@tonic-gate  * Event posted when a fault is reported
7897c478bd9Sstevel@tonic-gate  */
7907c478bd9Sstevel@tonic-gate #define	DDI_DEVI_FAULT_EVENT	"DDI:DEVI_FAULT"
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate struct ddi_fault_event_data {
7937c478bd9Sstevel@tonic-gate 	dev_info_t		*f_dip;
7947c478bd9Sstevel@tonic-gate 	ddi_fault_impact_t	f_impact;
7957c478bd9Sstevel@tonic-gate 	ddi_fault_location_t	f_location;
7967c478bd9Sstevel@tonic-gate 	const char		*f_message;
7977c478bd9Sstevel@tonic-gate 	ddi_devstate_t		f_oldstate;
7987c478bd9Sstevel@tonic-gate };
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate /*
8017c478bd9Sstevel@tonic-gate  * Access handle/DMA handle fault flag setting/clearing functions for nexi
8027c478bd9Sstevel@tonic-gate  */
8037c478bd9Sstevel@tonic-gate void ndi_set_acc_fault(ddi_acc_handle_t ah);
8047c478bd9Sstevel@tonic-gate void ndi_clr_acc_fault(ddi_acc_handle_t ah);
8057c478bd9Sstevel@tonic-gate void ndi_set_dma_fault(ddi_dma_handle_t dh);
8067c478bd9Sstevel@tonic-gate void ndi_clr_dma_fault(ddi_dma_handle_t dh);
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate /* Driver.conf property merging */
8097c478bd9Sstevel@tonic-gate int	ndi_merge_node(dev_info_t *, int (*)(dev_info_t *, char *, int));
8107c478bd9Sstevel@tonic-gate void	ndi_merge_wildcard_node(dev_info_t *);
8117c478bd9Sstevel@tonic-gate 
812255a2d50SMatthew Jacob /*
813255a2d50SMatthew Jacob  * Ndi 'flavor' support: These interfaces are to support a nexus driver
814255a2d50SMatthew Jacob  * with multiple 'flavors' of children (devi_flavor of child), coupled
815255a2d50SMatthew Jacob  * with a child flavor-specifc private data mechanism (via devi_flavor_v
816255a2d50SMatthew Jacob  * of parent). This is provided as an extension to ddi_[sg]et_driver_private,
817255a2d50SMatthew Jacob  * where the vanilla 'flavor' is what is stored or retrieved via
818255a2d50SMatthew Jacob  * ddi_[sg]et_driver_private.
819255a2d50SMatthew Jacob  *
820255a2d50SMatthew Jacob  * Flavors are indexed with a small integer. The first flavor, flavor
821255a2d50SMatthew Jacob  * zero, is always present and reserved as the 'vanilla' flavor.
822255a2d50SMatthew Jacob  * Space for extra flavors can be allocated and private pointers
823255a2d50SMatthew Jacob  * with respect to each flavor set and retrieved.
824255a2d50SMatthew Jacob  *
825255a2d50SMatthew Jacob  * NOTE:For a nexus driver, if the need to support multiple flavors of
826255a2d50SMatthew Jacob  *	children is understood from the begining, then a private 'flavor'
827255a2d50SMatthew Jacob  *	mechanism can be implemented via ddi_[sg]et_driver_private.
828255a2d50SMatthew Jacob  *
829255a2d50SMatthew Jacob  *	With SCSA, the need to support multiple flavors of children was not
830255a2d50SMatthew Jacob  *	anticipated, and ddi_get_driver_private(9F) of an initiator port
831255a2d50SMatthew Jacob  *	devinfo node was publicly defined in the DDI to return a
832255a2d50SMatthew Jacob  *	scsi_device(9S) child-flavor specific value: a pointer to
833255a2d50SMatthew Jacob  *	scsi_hba_tran(9S).  Over the years, each time the need to support
834255a2d50SMatthew Jacob  *	a new flavor of child has occurred, a new form of overload/kludge
835255a2d50SMatthew Jacob  *	has been devised. The ndi 'flavors' interfaces provide a simple way
836255a2d50SMatthew Jacob  *	to address this issue that can be used by both SCSA nexus support,
837255a2d50SMatthew Jacob  *	and by other nexus drivers.
838255a2d50SMatthew Jacob  */
839255a2d50SMatthew Jacob 
840255a2d50SMatthew Jacob /*
841255a2d50SMatthew Jacob  * Interfaces to maintain flavor-specific private data for children of self
842255a2d50SMatthew Jacob  */
843255a2d50SMatthew Jacob #define	NDI_FLAVOR_VANILLA	0
844255a2d50SMatthew Jacob 
845255a2d50SMatthew Jacob void	ndi_flavorv_alloc(dev_info_t *self, int nflavors);
846255a2d50SMatthew Jacob void	ndi_flavorv_set(dev_info_t *self, ndi_flavor_t child_flavor, void *);
847255a2d50SMatthew Jacob void	*ndi_flavorv_get(dev_info_t *self, ndi_flavor_t child_flavor);
848255a2d50SMatthew Jacob 
849255a2d50SMatthew Jacob /* Interfaces for 'self' nexus driver to get/set flavor of child */
850255a2d50SMatthew Jacob void		ndi_flavor_set(dev_info_t *child, ndi_flavor_t child_flavor);
851255a2d50SMatthew Jacob ndi_flavor_t	ndi_flavor_get(dev_info_t *child);
852255a2d50SMatthew Jacob 
8537c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8567c478bd9Sstevel@tonic-gate }
8577c478bd9Sstevel@tonic-gate #endif
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate #endif	/* _SYS_SUNNDI_H */
860