xref: /illumos-gate/usr/src/uts/common/sys/ddipropdefs.h (revision 24b9abbad58fdd63dad716fd35a99a7944c4e3eb)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DDIPROPDEFS_H
27 #define	_SYS_DDIPROPDEFS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 */
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * ddiprops.h:	All definitions related to DDI properties.
37  *		Structure definitions are private to the DDI
38  *		implementation.  See also, ddipropfuncs.h
39  */
40 
41 /*
42  * ddi_prop_op_t:	Enum for prop_op functions
43  */
44 
45 typedef enum {
46 	PROP_LEN = 0,		/* Get prop len only */
47 	PROP_LEN_AND_VAL_BUF,	/* Get len+val into callers buffer */
48 	PROP_LEN_AND_VAL_ALLOC,	/* Get len+val into alloc-ed buffer */
49 	PROP_EXISTS		/* Does the property exist? */
50 } ddi_prop_op_t;
51 
52 /*
53  * ddi_prop_t:	The basic item used to store software defined propeties.
54  *		Note that properties are always stored by reference.
55  */
56 
57 typedef struct ddi_prop {
58 	struct ddi_prop	*prop_next;
59 	dev_t		prop_dev;	/* specific match/wildcard */
60 	char		*prop_name;	/* Property name */
61 	int		prop_flags;	/* See flags below */
62 	int		prop_len;	/* Prop length (0 == Bool. prop) */
63 	caddr_t		prop_val;	/* ptr to property value */
64 } ddi_prop_t;
65 
66 /*
67  * A referenced property list, used for sharing properties among
68  * multiple driver instances
69  */
70 typedef struct ddi_prop_list {
71 	ddi_prop_t	*prop_list;
72 	int		prop_ref;
73 } ddi_prop_list_t;
74 
75 /*
76  * Handle passed around to encode/decode a property value.
77  */
78 typedef struct ddi_prop_handle {
79 	void			*ph_data;	/* Encoded data */
80 	void			*ph_cur_pos;	/* encode/decode position */
81 	void			*ph_save_pos;	/* Save/restore position */
82 	uint_t			ph_size;	/* Size of encoded data */
83 	uint_t			ph_flags;	/* See below */
84 	struct prop_handle_ops	*ph_ops;	/* Encode/decode routines */
85 } prop_handle_t;
86 
87 /*
88  * Property handle encode/decode ops
89  */
90 typedef struct prop_handle_ops {
91 	int (*op_prop_int)(prop_handle_t *ph, uint_t cmd, int *data);
92 	int (*op_prop_str)(prop_handle_t *ph, uint_t cmd, char *data);
93 	int (*op_prop_bytes)(prop_handle_t *ph, uint_t cmd,
94 				uchar_t *data, uint_t size);
95 	int (*op_prop_int64)(prop_handle_t *ph, uint_t cmd, int64_t *data);
96 } prop_handle_ops_t;
97 
98 /*
99  * Data passed back to driver.  The driver gets a pointer to driver_data.
100  * When we get it back we do negative indexing to find the size and free
101  * routine to call
102  */
103 struct prop_driver_data {
104 	size_t	pdd_size;
105 	void	(*pdd_prop_free)(struct prop_driver_data *);
106 };
107 
108 
109 /*
110  * Macros to call the integer/string/byte OBP 1275 operators
111  */
112 #define	DDI_PROP_INT(ph, cmd, data)		\
113 		(*(ph)->ph_ops->op_prop_int)((ph), (cmd), (data))
114 #define	DDI_PROP_STR(ph, cmd, data)		\
115 		(*(ph)->ph_ops->op_prop_str)((ph), (cmd), (data))
116 #define	DDI_PROP_BYTES(ph, cmd, data, size)	\
117 		(*(ph)->ph_ops->op_prop_bytes)((ph), (cmd), (data), (size))
118 
119 /*
120  * Macro to call the 64 bit integer operator
121  */
122 #define	DDI_PROP_INT64(ph, cmd, data)		\
123 		(*(ph)->ph_ops->op_prop_int64)((ph), (cmd), (data))
124 
125 /*
126  * Property handle commands
127  */
128 typedef enum {
129 	DDI_PROP_CMD_GET_ESIZE,		/* Get encoded size of data  */
130 	DDI_PROP_CMD_GET_DSIZE,		/* Get decoded size of data */
131 	DDI_PROP_CMD_DECODE,		/* Decode the current data */
132 	DDI_PROP_CMD_ENCODE,		/* Encode the current data */
133 	DDI_PROP_CMD_SKIP		/* Skip the current data */
134 } ddi_prop_cmd_t;
135 
136 /*
137  * Return values from property handle encode/decode ops
138  * Positive numbers are used to return the encoded or
139  * decode size of the object, so an ok return must be positive,
140  * and all error returns negative.
141  */
142 typedef enum {
143 	DDI_PROP_RESULT_ERROR = -2,	/* error in encoding/decoding data */
144 	DDI_PROP_RESULT_EOF,		/* end of data reached */
145 	DDI_PROP_RESULT_OK		/* if >= to DDI_PROP_RESULT_OK, */
146 					/* operation was successful */
147 } ddi_prop_result_t;
148 
149 /* 1275 property cell */
150 typedef uint32_t prop_1275_cell_t;
151 
152 /* Length of a 1275 property cell */
153 #define	PROP_1275_CELL_SIZE	sizeof (prop_1275_cell_t)
154 #define	CELLS_1275_TO_BYTES(n)	((n) * PROP_1275_CELL_SIZE)
155 #define	BYTES_TO_1275_CELLS(n)	((n) / PROP_1275_CELL_SIZE)
156 
157 /*
158  * Property handle flags
159  */
160 #define	PH_FROM_PROM	0x01	/* Property came from the prom */
161 
162 /*
163  * Return values from property functions:
164  */
165 
166 #define	DDI_PROP_SUCCESS	0
167 #define	DDI_PROP_NOT_FOUND	1	/* Prop not defined */
168 #define	DDI_PROP_UNDEFINED	2	/* Overriden to undefine a prop */
169 #define	DDI_PROP_NO_MEMORY	3	/* Unable to allocate/no sleep */
170 #define	DDI_PROP_INVAL_ARG	4	/* Invalid calling argument */
171 #define	DDI_PROP_BUF_TOO_SMALL	5	/* Callers buf too small */
172 #define	DDI_PROP_CANNOT_DECODE	6	/* Could not decode prop */
173 #define	DDI_PROP_CANNOT_ENCODE	7	/* Could not encode prop */
174 #define	DDI_PROP_END_OF_DATA	8	/* Prop found in an encoded format */
175 
176 /*
177  * used internally in the framework only
178  */
179 #define	DDI_PROP_FOUND_1275	255	/* Prop found in OPB 1275 format */
180 
181 /*
182  * Size of a 1275 int in bytes
183  */
184 #define	PROP_1275_INT_SIZE	4
185 
186 /*
187  * Property flags:
188  */
189 
190 #define	DDI_PROP_DONTPASS	0x0001	/* Don't pass request to parent */
191 #define	DDI_PROP_CANSLEEP	0x0002	/* Memory allocation may sleep */
192 
193 /*
194  * Used internally by the DDI property rountines and masked in DDI(9F)
195  * interfaces...
196  */
197 
198 #define	DDI_PROP_SYSTEM_DEF	0x0004	/* System defined property */
199 
200 /*
201  * Used in framework only, to inhibit certain pre-defined s/w property
202  * names from coming from the prom.
203  */
204 #define	DDI_PROP_NOTPROM	0x0008	/* Don't look at prom properties */
205 
206 /*
207  * Used interally by the DDI property routines to implement the old
208  * depricated functions with the new functions
209  */
210 #define	DDI_PROP_DONTSLEEP	0x0010	/* Memory allocation may not sleep */
211 #define	DDI_PROP_STACK_CREATE	0x0020	/* Do a LIFO stack of properties */
212 #define	DDI_PROP_UNDEF_IT	0x0040	/* Undefine a property */
213 #define	DDI_PROP_HW_DEF		0x0080	/* Hardware defined property */
214 
215 /*
216  * Type of data property contains
217  */
218 #define	DDI_PROP_TYPE_INT		0x0100
219 #define	DDI_PROP_TYPE_STRING		0x0200
220 #define	DDI_PROP_TYPE_BYTE		0x0400
221 #define	DDI_PROP_TYPE_COMPOSITE		0x0800
222 #define	DDI_PROP_TYPE_INT64		0x1000
223 
224 #define	DDI_PROP_TYPE_ANY		(DDI_PROP_TYPE_INT	|	\
225 					DDI_PROP_TYPE_STRING	|	\
226 					DDI_PROP_TYPE_BYTE	|	\
227 					DDI_PROP_TYPE_COMPOSITE)
228 
229 #define	DDI_PROP_TYPE_MASK		(DDI_PROP_TYPE_INT	|	\
230 					DDI_PROP_TYPE_STRING	|	\
231 					DDI_PROP_TYPE_BYTE	|	\
232 					DDI_PROP_TYPE_COMPOSITE	|	\
233 					DDI_PROP_TYPE_INT64)
234 
235 /*
236  * This flag indicates that the LDI lookup routine
237  * should match the request regardless of the actual
238  * dev_t with which the property was created.  In other
239  * words, any dev_t value found on the property list
240  * is an acceptable part of the match criteria.
241  */
242 #define	LDI_DEV_T_ANY		0x2000
243 
244 /*
245  * Private flag that should ONLY be used by the LDI Framework
246  * to indicate a property search of an unbound dlpi2 dip.
247  * The LDI property lookup interfaces will set this flag if
248  * it is determined that the dip representing a dlpi-style2
249  * driver is currently unbound (dip == NULL) at the time of
250  * the property lookup request.
251  */
252 #define	DDI_UNBND_DLPI2		0x4000
253 
254 /*
255  * Private flag that indicates that a typed interface that predates typed
256  * properties is being used - the framework should set additional typed flags
257  * (DDI_PROP_TYPE_INT64) when expanding search to DDI_PROP_TYPE_ANY.
258  */
259 #define	DDI_PROP_CONSUMER_TYPED	0x8000
260 
261 /*
262  * Private flag that indicates that the ldi is doing a driver prop_op
263  * call to check for driver dynamic properties.  This request should
264  * not be passed onto the common property lookup framework since all
265  * the ldi property interface are typed and driver prop_op lookups are
266  * not.
267  */
268 #define	DDI_PROP_DYNAMIC	0x10000
269 
270 
271 /*
272  * DDI_DEV_T_NONE:	When creating, property is not associated with
273  *			particular dev_t.
274  * DDI_DEV_T_ANY:	Wildcard dev_t when searching properties.
275  */
276 #define	DDI_DEV_T_NONE		((dev_t)-1)
277 #define	DDI_DEV_T_ANY		((dev_t)-2)
278 /*
279  * DDI_MAJOR_T_UNKNOWN	Used when a driver does not know its dev_t during
280  *			a property create.
281  * DDI_MAJOR_T_NONE	Used when a driver does not have a major number.
282  */
283 #define	DDI_MAJOR_T_UNKNOWN	((major_t)0)
284 #define	DDI_MAJOR_T_NONE	((major_t)-1)
285 
286 /*
287  * Some DDI property names...
288  */
289 
290 /*
291  * One of the following boolean properties shall be defined in the
292  * root node, and defines the addressing mode understood by the root
293  * node of the implementation....
294  */
295 
296 #define	DDI_RELATIVE_ADDRESSING		"relative-addressing"
297 #define	DDI_GENERIC_ADDRESSING		"generic-addressing"
298 
299 /*
300  * Common property encoded data search routine.  Returns the encoded data
301  * in valuep.  Match is done on dip, dev, data type (in flags), and name.
302  */
303 int ddi_prop_search_common(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
304     uint_t flags, char *name, void *valuep, uint_t *lengthp);
305 
306 
307 /*
308  * Property debugging support in kernel...
309  */
310 
311 /*
312  * Property debugging support...  Be careful about enabling this when
313  * you are tipping in to the console.  Undefine PROP_DEBUG to remove
314  * all support from the code. (c.f. autoconf.c and zs_common.c)
315  *
316  * It does no good to enable this if the rest of the kernel was built with
317  * this disabled (specifically, the core kernel module.)
318  *
319  * #define	DDI_PROP_DEBUG	1
320  */
321 
322 #ifdef	DDI_PROP_DEBUG
323 #define	ddi_prop_printf	if (ddi_prop_debug_flag != 0) printf
324 
325 /*
326  * Returns prev value of debugging flag, non-zero enables debug printf's
327  */
328 
329 int ddi_prop_debug(int enable);
330 
331 #endif	/* DDI_PROP_DEBUG */
332 
333 #ifdef	__cplusplus
334 }
335 #endif
336 
337 #endif /* _SYS_DDIPROPDEFS_H */
338