xref: /titanic_44/usr/src/lib/libdevinfo/device_info.h (revision 60972f37b111e11c7b4abcfc08e54c7839fe5e63)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * WARNING:
28  * The interfaces defined in this header file are for Sun private use only.
29  * The contents of this file are subject to change without notice in
30  * future releases.
31  */
32 
33 #ifndef	_DEVICE_INFO_H
34 #define	_DEVICE_INFO_H
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /* error return values */
43 #define	DEVFS_ERR	-1	/* operation not successful */
44 #define	DEVFS_INVAL	-2	/* invalid argument */
45 #define	DEVFS_NOMEM	-3	/* out of memory */
46 #define	DEVFS_PERM	-4 	/* permission denied - not root */
47 #define	DEVFS_NOTSUP	-5	/* operation not supported */
48 #define	DEVFS_LIMIT	-6	/* exceeded maximum size of property value */
49 #define	DEVFS_NOTFOUND	-7	/* request not found */
50 
51 /*
52  * for devfs_set_boot_dev()
53  * default behavior is to translate the input logical device name
54  * to most compact prom name(i.e. a prom alias, if one exists)
55  * as possible.  And to prepend the new entry to the existing
56  * list.
57  */
58 
59 /* perform no translation on the input device path */
60 #define	BOOTDEV_LITERAL		0x1
61 /* convert the input device path only a prom device path; not an alias */
62 #define	BOOTDEV_PROMDEV		0x2
63 /* overwrite the existing entry in boot-device - default is to prepend */
64 #define	BOOTDEV_OVERWRITE	0x4
65 
66 /*
67  * for devfs_get_prom_names()
68  * returns a list of prom names for a given logical device name.
69  * the list is sorted first in order of exact aliases, inexact alias
70  * matches (where an option override was needed), and finally the
71  * equivalent prom device path.  Each sublist is sorted in collating
72  * order.
73  */
74 #define	BOOTDEV_NO_PROM_PATH		0x1
75 #define	BOOTDEV_NO_INEXACT_ALIAS	0x2
76 #define	BOOTDEV_NO_EXACT_ALIAS		0x4
77 
78 /* for devfs_get_boot_dev() */
79 struct boot_dev {
80 	char *bootdev_element;	/* an entry from the boot-device variable */
81 	char **bootdev_trans;	/* 0 or more logical dev translations */
82 };
83 
84 /* for devfs_get_all_prom_names() */
85 struct devfs_prom_path {
86 	char *obp_path;
87 	char **alias_list;
88 	struct devfs_prom_path *next;
89 };
90 
91 /* prototypes */
92 
93 /* return the driver for a given device path */
94 extern int devfs_path_to_drv(char *devfs_path, char *drv_buf);
95 
96 /* convert a logical or physical device name to the equivalent prom path */
97 extern int devfs_dev_to_prom_name(char *, char *);
98 
99 /* return the driver name after resolving any aliases */
100 extern char *devfs_resolve_aliases(char *drv);
101 
102 /* set the boot-device configuration variable */
103 extern int devfs_bootdev_set_list(const char *, const uint_t);
104 
105 /* is the boot-device variable modifiable on this platform? */
106 extern int devfs_bootdev_modifiable(void);
107 
108 /*
109  * retrieve the boot-device config variable and corresponding logical
110  * device names
111  */
112 extern int devfs_bootdev_get_list(const char *, struct boot_dev ***);
113 /*
114  * free a list of bootdev structs
115  */
116 extern void devfs_bootdev_free_list(struct boot_dev **);
117 /*
118  * given a logical device name, return a list of equivalent
119  * prom names (aliases and device paths)
120  */
121 extern int devfs_get_prom_names(const char *, uint_t, char ***);
122 /*
123  * like devfs_get_prom_names(), but deals with 1 to many mappings
124  * introduced by mpxio devices
125  */
126 extern int devfs_get_all_prom_names(const char *, uint_t,
127     struct devfs_prom_path **);
128 /*
129  * free a list of devfs_prom_path structures
130  */
131 extern void devfs_free_all_prom_names(struct devfs_prom_path *);
132 
133 /*
134  * map a device name from install OS environment to target OS environment or
135  * vice-versa.
136  */
137 extern int devfs_target2install(const char *, const char *, char *, size_t);
138 extern int devfs_install2target(const char *, const char *, char *, size_t);
139 
140 /*
141  * Minor perm parsing library support for devfsadm, add_drv etc.
142  */
143 #define	MINOR_PERM_FILE		"/etc/minor_perm"
144 #define	MAX_MINOR_PERM_LINE	256
145 #define	DEFAULT_DEV_USER	"root"
146 #define	DEFAULT_DEV_GROUP	"sys"
147 
148 /*
149  * Possible errors the callers of devfs_read_minor_perm() need
150  * to be prepared to deal with via callback.
151  */
152 typedef enum {
153 	MP_FOPEN_ERR,
154 	MP_FCLOSE_ERR,
155 	MP_IGNORING_LINE_ERR,
156 	MP_ALLOC_ERR,
157 	MP_NVLIST_ERR,
158 	MP_CANT_FIND_USER_ERR,
159 	MP_CANT_FIND_GROUP_ERR
160 } minorperm_err_t;
161 
162 
163 /*
164  * Create/free mperm list of minor perm entries
165  */
166 extern struct mperm *devfs_read_minor_perm(void (*)(minorperm_err_t, int));
167 extern void devfs_free_minor_perm(struct mperm *);
168 
169 /*
170  * Load all minor perm entries, and add/remove minor perm entry
171  */
172 extern int devfs_load_minor_perm(struct mperm *,
173 	void (*)(minorperm_err_t, int));
174 extern int devfs_add_minor_perm(char *, void (*)(minorperm_err_t, int));
175 extern int devfs_rm_minor_perm(char *, void (*)(minorperm_err_t, int));
176 
177 /* devfsadm dca_flags values: some are used by libdevinfo devlink_create() */
178 #define	DCA_CREATE_LINK		0x000000001
179 #define	DCA_FREE_LIST		0x000000002
180 #define	DCA_LOAD_DRV		0x000000004
181 #define	DCA_CHECK_TYPE		0x000000010
182 #define	DCA_NOTIFY_RCM		0x000000020
183 #define	DCA_FLUSH_PATHINST	0x000000040
184 #define	DCA_HOT_PLUG		0x000000080
185 #define	DCA_DEVLINK_SYNC	0x000000100
186 #define	DCA_DEVLINK_CACHE	0x000000200
187 
188 #ifdef	__cplusplus
189 }
190 #endif
191 
192 #endif	/* _DEVICE_INFO_H */
193