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
53c4226f9Spjha  * Common Development and Distribution License (the "License").
63c4226f9Spjha  * 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*e37c6c37Scth  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_LIBDEVINFO_H
277c478bd9Sstevel@tonic-gate #define	_LIBDEVINFO_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
31facf4a8dSllai #ifdef	__cplusplus
32facf4a8dSllai extern "C" {
33facf4a8dSllai #endif
34facf4a8dSllai 
357c478bd9Sstevel@tonic-gate #include <errno.h>
36facf4a8dSllai #include <libnvpair.h>
377c478bd9Sstevel@tonic-gate #include <sys/param.h>
387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
397c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h>
407c478bd9Sstevel@tonic-gate #include <sys/openpromio.h>
417c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
427c478bd9Sstevel@tonic-gate #include <sys/devinfo_impl.h>
437c478bd9Sstevel@tonic-gate #include <limits.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * flags for di_walk_node
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #define	DI_WALK_CLDFIRST	0
497c478bd9Sstevel@tonic-gate #define	DI_WALK_SIBFIRST	1
507c478bd9Sstevel@tonic-gate #define	DI_WALK_LINKGEN		2
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	DI_WALK_MASK		0xf
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * flags for di_walk_link
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	DI_LINK_SRC		1
587c478bd9Sstevel@tonic-gate #define	DI_LINK_TGT		2
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * return code for node_callback
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	DI_WALK_CONTINUE	0
647c478bd9Sstevel@tonic-gate #define	DI_WALK_PRUNESIB	-1
657c478bd9Sstevel@tonic-gate #define	DI_WALK_PRUNECHILD	-2
667c478bd9Sstevel@tonic-gate #define	DI_WALK_TERMINATE	-3
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * flags for di_walk_minor
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate #define	DI_CHECK_ALIAS		0x10
727c478bd9Sstevel@tonic-gate #define	DI_CHECK_INTERNAL_PATH	0x20
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	DI_CHECK_MASK		0xf0
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* nodeid types */
777c478bd9Sstevel@tonic-gate #define	DI_PSEUDO_NODEID	-1
787c478bd9Sstevel@tonic-gate #define	DI_SID_NODEID		-2
797c478bd9Sstevel@tonic-gate #define	DI_PROM_NODEID		-3
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* node & device states */
827c478bd9Sstevel@tonic-gate #define	DI_DRIVER_DETACHED	0x8000
837c478bd9Sstevel@tonic-gate #define	DI_DEVICE_OFFLINE	0x1
847c478bd9Sstevel@tonic-gate #define	DI_DEVICE_DOWN		0x2
857c478bd9Sstevel@tonic-gate #define	DI_BUS_QUIESCED		0x100
867c478bd9Sstevel@tonic-gate #define	DI_BUS_DOWN		0x200
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* property types */
897c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_BOOLEAN	0
907c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_INT	1
917c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_STRING	2
927c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_BYTE	3
937c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_UNKNOWN	4
947c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_UNDEF_IT	5
957c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_INT64	6
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* private macro for checking if a prop type is valid */
987c478bd9Sstevel@tonic-gate #define	DI_PROP_TYPE_VALID(type) \
997c478bd9Sstevel@tonic-gate 	((((type) >= DI_PROP_TYPE_INT) && ((type) <= DI_PROP_TYPE_BYTE)) || \
1007c478bd9Sstevel@tonic-gate 	    ((type) == DI_PROP_TYPE_INT64))
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* opaque handles */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate typedef struct di_node *di_node_t;	/* opaque handle to node */
1057c478bd9Sstevel@tonic-gate typedef struct di_minor *di_minor_t;	/* opaque handle to minor node */
1067c478bd9Sstevel@tonic-gate typedef struct di_prop *di_prop_t;	/* opaque handle to property */
1077c478bd9Sstevel@tonic-gate typedef struct di_prom_prop *di_prom_prop_t;	/* opaque handle to prom prop */
1087c478bd9Sstevel@tonic-gate typedef struct di_prom_handle *di_prom_handle_t;	/* opaque handle */
1097c478bd9Sstevel@tonic-gate typedef struct di_path *di_path_t;	/* opaque handle */
1107c478bd9Sstevel@tonic-gate typedef struct di_path_prop *di_path_prop_t;	/* opaque handle */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate typedef struct di_devlink_handle *di_devlink_handle_t;	/* devlink snapshot */
1137c478bd9Sstevel@tonic-gate typedef struct di_devlink *di_devlink_t;	/* opaque handle to devlink */
1147c478bd9Sstevel@tonic-gate typedef struct di_link *di_link_t;	/* opaque handle to link */
1157c478bd9Sstevel@tonic-gate typedef struct di_lnode *di_lnode_t; /* opaque handle to endpoint */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Null handles to make handles really opaque
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate #define	DI_NODE_NIL	NULL
1217c478bd9Sstevel@tonic-gate #define	DI_LINK_NIL	NULL
1227c478bd9Sstevel@tonic-gate #define	DI_LNODE_NIL	NULL
1237c478bd9Sstevel@tonic-gate #define	DI_MINOR_NIL	NULL
1247c478bd9Sstevel@tonic-gate #define	DI_PROP_NIL	NULL
1257c478bd9Sstevel@tonic-gate #define	DI_PROM_PROP_NIL	NULL
1267c478bd9Sstevel@tonic-gate #define	DI_PROM_HANDLE_NIL	NULL
1277c478bd9Sstevel@tonic-gate #define	DI_PATH_NIL	NULL
1287c478bd9Sstevel@tonic-gate 
1293ebafc43Sjveta /*
1303ebafc43Sjveta  * IEEE 1275 properties and other standardized property names
1313ebafc43Sjveta  */
1323ebafc43Sjveta #define	DI_PROP_FIRST_CHAS	"first-in-chassis"
1333ebafc43Sjveta #define	DI_PROP_SLOT_NAMES	"slot-names"
1343ebafc43Sjveta #define	DI_PROP_PHYS_SLOT	"physical-slot#"
1353ebafc43Sjveta #define	DI_PROP_DEV_TYPE	"device_type"
1363ebafc43Sjveta #define	DI_PROP_BUS_RANGE	"bus-range"
1373ebafc43Sjveta #define	DI_PROP_SERID		"serialid#"
1383ebafc43Sjveta #define	DI_PROP_REG		"reg"
1393ebafc43Sjveta #define	DI_PROP_AP_NAMES	"ap-names"
1403ebafc43Sjveta 
1413ebafc43Sjveta 
1427c478bd9Sstevel@tonic-gate /* Interface Prototypes */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Snapshot initialization and cleanup
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate extern di_node_t di_init(const char *phys_path, uint_t flag);
1487c478bd9Sstevel@tonic-gate extern void di_fini(di_node_t root);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * tree traversal
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate extern di_node_t di_parent_node(di_node_t node);
1547c478bd9Sstevel@tonic-gate extern di_node_t di_sibling_node(di_node_t node);
1557c478bd9Sstevel@tonic-gate extern di_node_t di_child_node(di_node_t node);
1567c478bd9Sstevel@tonic-gate extern di_node_t di_drv_first_node(const char *drv_name, di_node_t root);
1577c478bd9Sstevel@tonic-gate extern di_node_t di_drv_next_node(di_node_t node);
1588c4f8890Srs extern di_node_t di_vhci_first_node(di_node_t root);
1598c4f8890Srs extern di_node_t di_vhci_next_node(di_node_t node);
1608c4f8890Srs extern di_node_t di_phci_first_node(di_node_t vhci_node);
1618c4f8890Srs extern di_node_t di_phci_next_node(di_node_t node);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * tree walking assistants
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate extern int di_walk_node(di_node_t root, uint_t flag, void *arg,
1677c478bd9Sstevel@tonic-gate     int (*node_callback)(di_node_t node, void *arg));
1687c478bd9Sstevel@tonic-gate extern int di_walk_minor(di_node_t root, const char *minortype, uint_t flag,
1697c478bd9Sstevel@tonic-gate     void *arg, int (*minor_callback)(di_node_t node, di_minor_t minor,
1707c478bd9Sstevel@tonic-gate     void *arg));
1717c478bd9Sstevel@tonic-gate extern int di_walk_link(di_node_t root, uint_t flag, uint_t endpoint,
1727c478bd9Sstevel@tonic-gate     void *arg, int (*link_callback)(di_link_t link, void *arg));
1737c478bd9Sstevel@tonic-gate extern int di_walk_lnode(di_node_t root, uint_t flag,
1747c478bd9Sstevel@tonic-gate     void *arg, int (*lnode_callback)(di_lnode_t lnode, void *arg));
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate extern void di_node_private_set(di_node_t node, void *data);
1777c478bd9Sstevel@tonic-gate extern void *di_node_private_get(di_node_t node);
1787c478bd9Sstevel@tonic-gate extern void di_minor_private_set(di_minor_t minor, void *data);
1797c478bd9Sstevel@tonic-gate extern void *di_minor_private_get(di_minor_t minor);
1807c478bd9Sstevel@tonic-gate extern void di_lnode_private_set(di_lnode_t lnode, void *data);
1817c478bd9Sstevel@tonic-gate extern void *di_lnode_private_get(di_lnode_t lnode);
1827c478bd9Sstevel@tonic-gate extern void di_link_private_set(di_link_t link, void *data);
1837c478bd9Sstevel@tonic-gate extern void *di_link_private_get(di_link_t link);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * generic node parameters
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate extern char *di_node_name(di_node_t node);
1897c478bd9Sstevel@tonic-gate extern char *di_bus_addr(di_node_t node);
1907c478bd9Sstevel@tonic-gate extern char *di_binding_name(di_node_t node);
1917c478bd9Sstevel@tonic-gate extern int di_compatible_names(di_node_t, char **names);
1927c478bd9Sstevel@tonic-gate extern int di_instance(di_node_t node);
1937c478bd9Sstevel@tonic-gate extern int di_nodeid(di_node_t node);
1947c478bd9Sstevel@tonic-gate extern int di_driver_major(di_node_t node);
1957c478bd9Sstevel@tonic-gate extern uint_t di_state(di_node_t node);
1967c478bd9Sstevel@tonic-gate extern ddi_node_state_t di_node_state(di_node_t node);
1977c478bd9Sstevel@tonic-gate extern ddi_devid_t di_devid(di_node_t node);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern char *di_driver_name(di_node_t node);
2007c478bd9Sstevel@tonic-gate extern uint_t di_driver_ops(di_node_t node);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate extern char *di_devfs_path(di_node_t node);
2037c478bd9Sstevel@tonic-gate extern char *di_devfs_minor_path(di_minor_t minor);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate extern void di_devfs_path_free(char *path_buf);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * layering data access
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate extern di_link_t	di_link_next_by_node(di_node_t node,
2117c478bd9Sstevel@tonic-gate     di_link_t link, uint_t endpoint);
2127c478bd9Sstevel@tonic-gate extern di_link_t	di_link_next_by_lnode(di_lnode_t lnode,
2137c478bd9Sstevel@tonic-gate     di_link_t link, uint_t endpoint);
2147c478bd9Sstevel@tonic-gate extern di_lnode_t	di_link_to_lnode(di_link_t link, uint_t endpoint);
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate extern di_lnode_t	di_lnode_next(di_node_t node, di_lnode_t lnode);
2177c478bd9Sstevel@tonic-gate extern char		*di_lnode_name(di_lnode_t lnode);
2187c478bd9Sstevel@tonic-gate extern di_node_t	di_lnode_devinfo(di_lnode_t lnode);
2197c478bd9Sstevel@tonic-gate extern int		di_lnode_devt(di_lnode_t lnode, dev_t *devt);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate extern int		di_link_spectype(di_link_t link);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*
2247c478bd9Sstevel@tonic-gate  * minor data access
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate extern di_minor_t	di_minor_next(di_node_t node, di_minor_t minor);
2277c478bd9Sstevel@tonic-gate extern di_node_t	di_minor_devinfo(di_minor_t minor);
2287c478bd9Sstevel@tonic-gate extern ddi_minor_type	di_minor_type(di_minor_t minor);
2297c478bd9Sstevel@tonic-gate extern char		*di_minor_name(di_minor_t minor);
2307c478bd9Sstevel@tonic-gate extern dev_t		di_minor_devt(di_minor_t minor);
2317c478bd9Sstevel@tonic-gate extern int		di_minor_spectype(di_minor_t minor);
2327c478bd9Sstevel@tonic-gate extern char		*di_minor_nodetype(di_minor_t node);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * Software property access
2367c478bd9Sstevel@tonic-gate  */
2377c478bd9Sstevel@tonic-gate extern di_prop_t di_prop_next(di_node_t node, di_prop_t prop);
2387c478bd9Sstevel@tonic-gate extern dev_t di_prop_devt(di_prop_t prop);
2397c478bd9Sstevel@tonic-gate extern char *di_prop_name(di_prop_t prop);
2407c478bd9Sstevel@tonic-gate extern int di_prop_type(di_prop_t prop);
2417c478bd9Sstevel@tonic-gate extern int di_prop_ints(di_prop_t prop, int **prop_data);
2427c478bd9Sstevel@tonic-gate extern int di_prop_int64(di_prop_t prop, int64_t **prop_data);
2437c478bd9Sstevel@tonic-gate extern int di_prop_strings(di_prop_t prop, char **prop_data);
2447c478bd9Sstevel@tonic-gate extern int di_prop_bytes(di_prop_t prop, uchar_t **prop_data);
2457c478bd9Sstevel@tonic-gate extern int di_prop_lookup_ints(dev_t dev, di_node_t node,
2467c478bd9Sstevel@tonic-gate     const char *prop_name, int **prop_data);
2477c478bd9Sstevel@tonic-gate extern int di_prop_lookup_int64(dev_t dev, di_node_t node,
2487c478bd9Sstevel@tonic-gate     const char *prop_name, int64_t **prop_data);
2497c478bd9Sstevel@tonic-gate extern int di_prop_lookup_strings(dev_t dev, di_node_t node,
2507c478bd9Sstevel@tonic-gate     const char *prop_name, char **prop_data);
2517c478bd9Sstevel@tonic-gate extern int di_prop_lookup_bytes(dev_t dev, di_node_t node,
2527c478bd9Sstevel@tonic-gate     const char *prop_name, uchar_t **prop_data);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate  * PROM property access
2567c478bd9Sstevel@tonic-gate  */
2577c478bd9Sstevel@tonic-gate extern di_prom_handle_t di_prom_init(void);
2587c478bd9Sstevel@tonic-gate extern void di_prom_fini(di_prom_handle_t ph);
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate extern di_prom_prop_t di_prom_prop_next(di_prom_handle_t ph, di_node_t node,
2617c478bd9Sstevel@tonic-gate     di_prom_prop_t prom_prop);
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate extern char *di_prom_prop_name(di_prom_prop_t prom_prop);
2647c478bd9Sstevel@tonic-gate extern int di_prom_prop_data(di_prom_prop_t prop, uchar_t **prom_prop_data);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate extern int di_prom_prop_lookup_ints(di_prom_handle_t prom, di_node_t node,
2677c478bd9Sstevel@tonic-gate     const char *prom_prop_name, int **prom_prop_data);
2687c478bd9Sstevel@tonic-gate extern int di_prom_prop_lookup_strings(di_prom_handle_t prom, di_node_t node,
2697c478bd9Sstevel@tonic-gate     const char *prom_prop_name, char **prom_prop_data);
2707c478bd9Sstevel@tonic-gate extern int di_prom_prop_lookup_bytes(di_prom_handle_t prom, di_node_t node,
2717c478bd9Sstevel@tonic-gate     const char *prom_prop_name, uchar_t **prom_prop_data);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Private interfaces
2757c478bd9Sstevel@tonic-gate  *
2767c478bd9Sstevel@tonic-gate  * The interfaces and structures below are private to this implementation
2777c478bd9Sstevel@tonic-gate  * of Solaris and are subject to change at any time without notice.
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  * Applications and drivers using these interfaces will fail
2807c478bd9Sstevel@tonic-gate  * to run on future releases.
2817c478bd9Sstevel@tonic-gate  */
2827c478bd9Sstevel@tonic-gate 
2833ebafc43Sjveta extern di_prop_t di_prop_find(dev_t match_dev, di_node_t node,
2843ebafc43Sjveta     const char *name);
2853ebafc43Sjveta 
2863ebafc43Sjveta /*
2873ebafc43Sjveta  * Interfaces for handling IEEE 1275 and other standardized properties
2883ebafc43Sjveta  */
2893ebafc43Sjveta 
2903ebafc43Sjveta /* structure for a single slot */
2913ebafc43Sjveta typedef struct di_slot_name {
2923ebafc43Sjveta 	int num;	/* corresponding pci device number */
2933ebafc43Sjveta 	char *name;
2943ebafc43Sjveta } di_slot_name_t;
2953ebafc43Sjveta 
2963ebafc43Sjveta extern void di_slot_names_free(int count, di_slot_name_t *slot_names);
2973ebafc43Sjveta extern int di_slot_names_decode(uchar_t *rawdata, int rawlen,
2983ebafc43Sjveta     di_slot_name_t **prop_data);
2993ebafc43Sjveta extern int di_prop_slot_names(di_prop_t prop, di_slot_name_t **prop_data);
3003ebafc43Sjveta extern int di_prom_prop_slot_names(di_prom_prop_t prom_prop,
3013ebafc43Sjveta     di_slot_name_t **prop_data);
3023ebafc43Sjveta extern int di_prop_lookup_slot_names(dev_t dev, di_node_t node,
3033ebafc43Sjveta     di_slot_name_t **prop_data);
3043ebafc43Sjveta extern int di_prom_prop_lookup_slot_names(di_prom_handle_t ph, di_node_t node,
3053ebafc43Sjveta     di_slot_name_t **prop_data);
3063ebafc43Sjveta 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * Interfaces for accessing I/O multipathing data
3097c478bd9Sstevel@tonic-gate  */
3107c478bd9Sstevel@tonic-gate /* XXX remove di_path_next() after updating NWS consolidation */
3117c478bd9Sstevel@tonic-gate extern di_path_t di_path_next(di_node_t node, di_path_t path);
3127c478bd9Sstevel@tonic-gate extern di_path_t di_path_next_phci(di_node_t node, di_path_t path);
3137c478bd9Sstevel@tonic-gate extern di_path_t di_path_next_client(di_node_t node, di_path_t path);
3147c478bd9Sstevel@tonic-gate extern di_path_state_t di_path_state(di_path_t path);
3157c478bd9Sstevel@tonic-gate extern char *di_path_addr(di_path_t path, char *buf);
3167c478bd9Sstevel@tonic-gate extern di_node_t di_path_client_node(di_path_t path);
3177c478bd9Sstevel@tonic-gate extern void di_path_client_path(di_path_t path, char *buf);
3187c478bd9Sstevel@tonic-gate extern di_node_t di_path_phci_node(di_path_t path);
3197c478bd9Sstevel@tonic-gate extern void di_path_phci_path(di_path_t path, char *buf);
3207c478bd9Sstevel@tonic-gate extern di_path_prop_t di_path_prop_next(di_path_t path, di_path_prop_t prop);
3217c478bd9Sstevel@tonic-gate extern char *di_path_prop_name(di_path_prop_t prop);
3227c478bd9Sstevel@tonic-gate extern int di_path_prop_type(di_path_prop_t prop);
3237c478bd9Sstevel@tonic-gate extern int di_path_prop_len(di_path_prop_t prop);
3247c478bd9Sstevel@tonic-gate extern int di_path_prop_bytes(di_path_prop_t prop, uchar_t **prop_data);
3257c478bd9Sstevel@tonic-gate extern int di_path_prop_ints(di_path_prop_t prop, int **prop_data);
3267c478bd9Sstevel@tonic-gate extern int di_path_prop_int64s(di_path_prop_t prop, int64_t **prop_data);
3277c478bd9Sstevel@tonic-gate extern int di_path_prop_strings(di_path_prop_t prop, char **prop_data);
3287c478bd9Sstevel@tonic-gate extern int di_path_prop_lookup_bytes(di_path_t path, const char *prop_name,
3297c478bd9Sstevel@tonic-gate     uchar_t **prop_data);
3307c478bd9Sstevel@tonic-gate extern int di_path_prop_lookup_ints(di_path_t path, const char *prop_name,
3317c478bd9Sstevel@tonic-gate     int **prop_data);
3327c478bd9Sstevel@tonic-gate extern int di_path_prop_lookup_int64s(di_path_t path, const char *prop_name,
3337c478bd9Sstevel@tonic-gate     int64_t **prop_data);
3347c478bd9Sstevel@tonic-gate extern int di_path_prop_lookup_strings(di_path_t path, const char *prop_name,
3357c478bd9Sstevel@tonic-gate     char **prop_data);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate /*
3397c478bd9Sstevel@tonic-gate  * Interfaces for private data
3407c478bd9Sstevel@tonic-gate  */
3417c478bd9Sstevel@tonic-gate extern di_node_t di_init_driver(const char *drv_name, uint_t flag);
3427c478bd9Sstevel@tonic-gate extern di_node_t di_init_impl(const char *phys_path, uint_t flag,
3437c478bd9Sstevel@tonic-gate     struct di_priv_data *priv_data);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * Prtconf needs to know property lists, raw prop_data, and private data
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate extern di_prop_t di_prop_drv_next(di_node_t node, di_prop_t prop);
3497c478bd9Sstevel@tonic-gate extern di_prop_t di_prop_sys_next(di_node_t node, di_prop_t prop);
3507c478bd9Sstevel@tonic-gate extern di_prop_t di_prop_global_next(di_node_t node, di_prop_t prop);
3517c478bd9Sstevel@tonic-gate extern di_prop_t di_prop_hw_next(di_node_t node, di_prop_t prop);
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate extern int di_prop_rawdata(di_prop_t prop, uchar_t **prop_data);
3547c478bd9Sstevel@tonic-gate extern void *di_parent_private_data(di_node_t node);
3557c478bd9Sstevel@tonic-gate extern void *di_driver_private_data(di_node_t node);
3567c478bd9Sstevel@tonic-gate 
35725e8c5aaSvikram /*
35825e8c5aaSvikram  * The value of the dip's devi_flags field
35925e8c5aaSvikram  */
36025e8c5aaSvikram uint_t di_flags(di_node_t node);
36125e8c5aaSvikram 
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate  * Types of links for devlink lookup
3647c478bd9Sstevel@tonic-gate  */
3657c478bd9Sstevel@tonic-gate #define	DI_PRIMARY_LINK		0x01
3667c478bd9Sstevel@tonic-gate #define	DI_SECONDARY_LINK	0x02
3677c478bd9Sstevel@tonic-gate #define	DI_LINK_TYPES		0x03
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * Flag for di_devlink_init()
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate #define	DI_MAKE_LINK	0x01
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * Flag for di_devlink_close()
3767c478bd9Sstevel@tonic-gate  */
3777c478bd9Sstevel@tonic-gate #define	DI_LINK_ERROR	0x01
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate  * For devfsadm synchronous link creation interfaces
3817c478bd9Sstevel@tonic-gate  */
3827c478bd9Sstevel@tonic-gate #define	DEVFSADM_SYNCH_DOOR	".devfsadm_synch_door"
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /*
3857c478bd9Sstevel@tonic-gate  * devlink create argument
3867c478bd9Sstevel@tonic-gate  */
3877c478bd9Sstevel@tonic-gate struct dca_off {
3887c478bd9Sstevel@tonic-gate 	uint32_t	dca_root;
3897c478bd9Sstevel@tonic-gate 	uint32_t	dca_minor;
3907c478bd9Sstevel@tonic-gate 	uint32_t	dca_driver;
3917c478bd9Sstevel@tonic-gate 	int		dca_error;
3927c478bd9Sstevel@tonic-gate 	int		dca_flags;
3937c478bd9Sstevel@tonic-gate 	char		dca_name[PATH_MAX+MAXNAMELEN];
3947c478bd9Sstevel@tonic-gate };
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate extern di_devlink_handle_t di_devlink_init(const char *name, uint_t flags);
3977c478bd9Sstevel@tonic-gate extern int di_devlink_walk(di_devlink_handle_t hdl, const char *re,
3987c478bd9Sstevel@tonic-gate     const char *minor_path, uint_t flags, void *arg,
3997c478bd9Sstevel@tonic-gate     int (*devlink_callback)(di_devlink_t, void *));
4007c478bd9Sstevel@tonic-gate extern const char *di_devlink_path(di_devlink_t devlink);
4017c478bd9Sstevel@tonic-gate extern const char *di_devlink_content(di_devlink_t devlink);
4027c478bd9Sstevel@tonic-gate extern int di_devlink_type(di_devlink_t devlink);
4037c478bd9Sstevel@tonic-gate extern di_devlink_t di_devlink_dup(di_devlink_t devlink);
4047c478bd9Sstevel@tonic-gate extern int di_devlink_free(di_devlink_t devlink);
4057c478bd9Sstevel@tonic-gate extern int di_devlink_fini(di_devlink_handle_t *hdlp);
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate extern di_devlink_handle_t di_devlink_open(const char *root_dir, uint_t flags);
4087c478bd9Sstevel@tonic-gate extern int di_devlink_close(di_devlink_handle_t *pp, int flag);
4097c478bd9Sstevel@tonic-gate extern int di_devlink_rm_link(di_devlink_handle_t hdp, const char *link);
4107c478bd9Sstevel@tonic-gate extern int di_devlink_add_link(di_devlink_handle_t hdp, const char *link,
4117c478bd9Sstevel@tonic-gate     const char *content, int flags);
4127c478bd9Sstevel@tonic-gate extern int di_devlink_update(di_devlink_handle_t hdp);
4137c478bd9Sstevel@tonic-gate extern di_devlink_handle_t di_devlink_init_root(const char *root,
4147c478bd9Sstevel@tonic-gate     const char *name, uint_t flags);
4157c478bd9Sstevel@tonic-gate extern int di_devlink_cache_walk(di_devlink_handle_t hdp, const char *re,
4167c478bd9Sstevel@tonic-gate     const char *path, uint_t flags, void *arg,
4177c478bd9Sstevel@tonic-gate     int (*devlink_callback)(di_devlink_t, void *));
4187c478bd9Sstevel@tonic-gate 
41925e8c5aaSvikram /*
42025e8c5aaSvikram  * Private interfaces for I/O retire
42125e8c5aaSvikram  */
42225e8c5aaSvikram typedef struct di_retire {
42325e8c5aaSvikram 	void	*rt_hdl;
42425e8c5aaSvikram 	void	(*rt_abort)(void *hdl, const char *format, ...);
42525e8c5aaSvikram 	void	(*rt_debug)(void *hdl, const char *format, ...);
42625e8c5aaSvikram } di_retire_t;
42725e8c5aaSvikram 
42825e8c5aaSvikram extern int di_retire_device(char *path, di_retire_t *dp, int flags);
42925e8c5aaSvikram extern int di_unretire_device(char *path, di_retire_t *dp);
43025e8c5aaSvikram extern uint_t di_retired(di_node_t node);
43125e8c5aaSvikram 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Private interfaces for /etc/logindevperm
4347c478bd9Sstevel@tonic-gate  */
4357c478bd9Sstevel@tonic-gate extern int di_devperm_login(const char *, uid_t, gid_t, void (*)(char *));
4367c478bd9Sstevel@tonic-gate extern int di_devperm_logout(const char *);
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * Private interface for looking up a node in a snapshot
4407c478bd9Sstevel@tonic-gate  */
4417c478bd9Sstevel@tonic-gate extern di_node_t di_lookup_node(di_node_t root, char *path);
4427c478bd9Sstevel@tonic-gate 
4433c4226f9Spjha 
4443c4226f9Spjha /*
4453c4226f9Spjha  * Private hotplug interfaces to be used between cfgadm pci plugin and
4463c4226f9Spjha  * devfsadm link generator.
4473c4226f9Spjha  */
4483c4226f9Spjha extern char *di_dli_name(char *);
4493c4226f9Spjha extern int di_dli_openr(char *);
4503c4226f9Spjha extern int di_dli_openw(char *);
4513c4226f9Spjha extern void di_dli_close(int);
4523c4226f9Spjha 
453facf4a8dSllai /*
454facf4a8dSllai  * Private interface for parsing devname binding info
455facf4a8dSllai  */
456facf4a8dSllai extern void di_devname_print_mapinfo(nvlist_t *);
457facf4a8dSllai extern int di_devname_get_mapinfo(char *, nvlist_t **);
458facf4a8dSllai extern int di_devname_get_mapent(char *, char *, nvlist_t **);
459facf4a8dSllai extern int di_devname_action_on_key(nvlist_t *, uint8_t, char *, void *);
460facf4a8dSllai 
4611aef0e11Sjg /*
4621aef0e11Sjg  * Private interface for parsing path_to_inst binding file
4631aef0e11Sjg  */
4641aef0e11Sjg extern int devfs_parse_binding_file(const char *,
4651aef0e11Sjg 	int (*)(void *, const char *, int, const char *), void *);
4661aef0e11Sjg extern int devfs_walk_minor_nodes(const char *,
4671aef0e11Sjg 	int (*)(void *, const char *), void *);
4681aef0e11Sjg 
469facf4a8dSllai /*
470facf4a8dSllai  * finddev - alternate readdir to discover only /dev persisted device names
471facf4a8dSllai  */
472facf4a8dSllai typedef struct __finddevhdl *finddevhdl_t;
473facf4a8dSllai 
474facf4a8dSllai extern int		device_exists(const char *);
475facf4a8dSllai extern int		finddev_readdir(const char *, finddevhdl_t *);
476*e37c6c37Scth extern int		finddev_emptydir(const char *);
477facf4a8dSllai extern void		finddev_close(finddevhdl_t);
478facf4a8dSllai extern const char	*finddev_next(finddevhdl_t);
479facf4a8dSllai 
480facf4a8dSllai 
481facf4a8dSllai /*
482facf4a8dSllai  * Private interfaces for non-global /dev profile
483facf4a8dSllai  */
484facf4a8dSllai typedef struct __di_prof	*di_prof_t;
485facf4a8dSllai 
486facf4a8dSllai extern int	di_prof_init(const char *mountpt, di_prof_t *);
487facf4a8dSllai extern void	di_prof_fini(di_prof_t);
488facf4a8dSllai extern int	di_prof_commit(di_prof_t);
489facf4a8dSllai extern int	di_prof_add_dev(di_prof_t, const char *);
490facf4a8dSllai extern int	di_prof_add_exclude(di_prof_t, const char *);
491facf4a8dSllai extern int	di_prof_add_symlink(di_prof_t, const char *, const char *);
492facf4a8dSllai extern int	di_prof_add_map(di_prof_t, const char *, const char *);
493facf4a8dSllai 
494a08731ecScth /*
495a08731ecScth  * Private interfaces for <driver><instance><minor> to path conversion.
496a08731ecScth  * NOTE: These interfaces do not require or cause attach.  The implementation
497a08731ecScth  * uses the kernel instance-tree (/etc/path_to_inst) and the di_devlinks
498a08731ecScth  * database information.
499a08731ecScth  */
500a08731ecScth typedef struct __di_dim	*di_dim_t;
501a08731ecScth 
502a08731ecScth extern di_dim_t	di_dim_init();
503a08731ecScth extern void	di_dim_fini(di_dim_t);
504a08731ecScth extern char	*di_dim_path_devices(di_dim_t,
505a08731ecScth 		    char *drv_name, int instance, char *minor_name);
506a08731ecScth extern char	*di_dim_path_dev(di_dim_t,
507a08731ecScth 		    char *drv_name, int instance, char *minor_name);
508a08731ecScth 
509a08731ecScth 
5107c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate #endif
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate #endif	/* _LIBDEVINFO_H */
515