xref: /titanic_50/usr/src/uts/common/sys/instance.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_INSTANCE_H
28 #define	_SYS_INSTANCE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Instance number assignment data structures
34  */
35 
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/dditypes.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #define	INSTANCE_FILE	"/etc/path_to_inst"
45 #define	INSTANCE_FILE_SUFFIX	".old"
46 
47 #if	defined(_KERNEL) || defined(_KMEMUSER)
48 
49 /*
50  * The form of a node;  These form a tree that is parallel to the
51  * dev_info tree, but always fully populated.  The tree is rooted in
52  * the in_softstate struct (e_ddi_inst_state.ins_root).
53  *
54  * Each node has one or more in_drv entries hanging from it.
55  * (It will have more than one if it has been driven by more than one driver
56  * over its lifetime.  This can happen due to a generic name
57  * or to a "compatible" name giving a more specific driver).
58  */
59 
60 typedef struct in_node {
61 	char		*in_node_name;	/* devi_node_name of this node	*/
62 	char		*in_unit_addr;	/* address part of name		*/
63 	struct in_node	*in_child;	/* children of this node	*/
64 	struct in_node	*in_sibling;	/* "peers" of this node	*/
65 	struct in_drv	*in_drivers;	/* drivers bound to this node	*/
66 	struct in_node	*in_parent;	/* parent of this node		*/
67 } in_node_t;
68 
69 typedef struct in_drv {
70 	char		*ind_driver_name; /* canonical name of driver	*/
71 	int		ind_instance;	  /* current instance number	*/
72 	int		ind_state;	  /* see below			*/
73 	/*
74 	 * The following field is used to link instance numbers for the
75 	 * same driver off of devnamesp or in_no_major or in_no_instance
76 	 */
77 	struct in_drv	*ind_next;	  /* next for this driver	*/
78 	struct in_drv	*ind_next_drv;	  /* next driver this node	*/
79 	struct in_node	*ind_node;	  /* node that these hang on	*/
80 } in_drv_t;
81 
82 /*
83  * Values for in_state
84  */
85 #define	IN_PROVISIONAL	0x1	/* provisional instance number assigned */
86 #define	IN_PERMANENT	0x2	/* instance number has been confirmed */
87 #define	IN_UNKNOWN	0x3	/* instance number not yet assigned */
88 
89 /*
90  * special value for dn_instance
91  */
92 #define	IN_SEARCHME (-1)
93 
94 #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
95 
96 #ifdef	_KERNEL
97 void e_ddi_instance_init(void);
98 uint_t e_ddi_assign_instance(dev_info_t *dip);
99 void e_ddi_keep_instance(dev_info_t *dip);
100 void e_ddi_free_instance(dev_info_t *dip, char *addr);
101 int e_ddi_instance_majorinstance_to_path(major_t major,
102 	uint_t instance, char *path);
103 void e_ddi_unorphan_instance_nos(void);
104 void e_ddi_enter_instance(void);
105 void e_ddi_exit_instance(void);
106 in_node_t *e_ddi_instance_root(void);
107 int e_ddi_instance_is_clean(void);
108 void e_ddi_instance_set_clean(void);
109 
110 /* Platform instance override functions */
111 uint_t impl_assign_instance(dev_info_t *dip);
112 int impl_keep_instance(dev_info_t *dip);
113 int impl_free_instance(dev_info_t *dip);
114 
115 /* walk the instance tree */
116 int e_ddi_walk_instances(int (*)(const char *,
117 	in_node_t *, in_drv_t *, void *), void *);
118 
119 /* return values from e_ddi_walk_instances callback */
120 #define	INST_WALK_CONTINUE	0
121 #define	INST_WALK_TERMINATE	1
122 
123 
124 #else	/* _KERNEL */
125 #ifdef __STDC__
126 extern int inst_sync(char *pathname, int flags);
127 #else
128 extern int inst_sync();
129 #endif	/* __STDC__ */
130 #endif	/* _KERNEL */
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif	/* _SYS_INSTANCE_H */
137