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