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