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