10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57009Scth * Common Development and Distribution License (the "License"). 67009Scth * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 227009Scth * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_DDIPROPDEFS_H 270Sstevel@tonic-gate #define _SYS_DDIPROPDEFS_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * ddiprops.h: All definitions related to DDI properties. 350Sstevel@tonic-gate * Structure definitions are private to the DDI 360Sstevel@tonic-gate * implementation. See also, ddipropfuncs.h 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * ddi_prop_op_t: Enum for prop_op functions 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate 430Sstevel@tonic-gate typedef enum { 440Sstevel@tonic-gate PROP_LEN = 0, /* Get prop len only */ 450Sstevel@tonic-gate PROP_LEN_AND_VAL_BUF, /* Get len+val into callers buffer */ 460Sstevel@tonic-gate PROP_LEN_AND_VAL_ALLOC, /* Get len+val into alloc-ed buffer */ 470Sstevel@tonic-gate PROP_EXISTS /* Does the property exist? */ 480Sstevel@tonic-gate } ddi_prop_op_t; 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * ddi_prop_t: The basic item used to store software defined propeties. 520Sstevel@tonic-gate * Note that properties are always stored by reference. 530Sstevel@tonic-gate */ 540Sstevel@tonic-gate 550Sstevel@tonic-gate typedef struct ddi_prop { 560Sstevel@tonic-gate struct ddi_prop *prop_next; 570Sstevel@tonic-gate dev_t prop_dev; /* specific match/wildcard */ 580Sstevel@tonic-gate char *prop_name; /* Property name */ 590Sstevel@tonic-gate int prop_flags; /* See flags below */ 600Sstevel@tonic-gate int prop_len; /* Prop length (0 == Bool. prop) */ 610Sstevel@tonic-gate caddr_t prop_val; /* ptr to property value */ 620Sstevel@tonic-gate } ddi_prop_t; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * A referenced property list, used for sharing properties among 660Sstevel@tonic-gate * multiple driver instances 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate typedef struct ddi_prop_list { 690Sstevel@tonic-gate ddi_prop_t *prop_list; 700Sstevel@tonic-gate int prop_ref; 710Sstevel@tonic-gate } ddi_prop_list_t; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Handle passed around to encode/decode a property value. 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate typedef struct ddi_prop_handle { 770Sstevel@tonic-gate void *ph_data; /* Encoded data */ 780Sstevel@tonic-gate void *ph_cur_pos; /* encode/decode position */ 790Sstevel@tonic-gate void *ph_save_pos; /* Save/restore position */ 800Sstevel@tonic-gate uint_t ph_size; /* Size of encoded data */ 810Sstevel@tonic-gate uint_t ph_flags; /* See below */ 820Sstevel@tonic-gate struct prop_handle_ops *ph_ops; /* Encode/decode routines */ 830Sstevel@tonic-gate } prop_handle_t; 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Property handle encode/decode ops 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate typedef struct prop_handle_ops { 890Sstevel@tonic-gate int (*op_prop_int)(prop_handle_t *ph, uint_t cmd, int *data); 900Sstevel@tonic-gate int (*op_prop_str)(prop_handle_t *ph, uint_t cmd, char *data); 910Sstevel@tonic-gate int (*op_prop_bytes)(prop_handle_t *ph, uint_t cmd, 920Sstevel@tonic-gate uchar_t *data, uint_t size); 930Sstevel@tonic-gate int (*op_prop_int64)(prop_handle_t *ph, uint_t cmd, int64_t *data); 940Sstevel@tonic-gate } prop_handle_ops_t; 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Data passed back to driver. The driver gets a pointer to driver_data. 980Sstevel@tonic-gate * When we get it back we do negative indexing to find the size and free 990Sstevel@tonic-gate * routine to call 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate struct prop_driver_data { 1020Sstevel@tonic-gate size_t pdd_size; 1030Sstevel@tonic-gate void (*pdd_prop_free)(struct prop_driver_data *); 1040Sstevel@tonic-gate }; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * Macros to call the integer/string/byte OBP 1275 operators 1090Sstevel@tonic-gate */ 1100Sstevel@tonic-gate #define DDI_PROP_INT(ph, cmd, data) \ 1110Sstevel@tonic-gate (*(ph)->ph_ops->op_prop_int)((ph), (cmd), (data)) 1120Sstevel@tonic-gate #define DDI_PROP_STR(ph, cmd, data) \ 1130Sstevel@tonic-gate (*(ph)->ph_ops->op_prop_str)((ph), (cmd), (data)) 1140Sstevel@tonic-gate #define DDI_PROP_BYTES(ph, cmd, data, size) \ 1150Sstevel@tonic-gate (*(ph)->ph_ops->op_prop_bytes)((ph), (cmd), (data), (size)) 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * Macro to call the 64 bit integer operator 1190Sstevel@tonic-gate */ 1200Sstevel@tonic-gate #define DDI_PROP_INT64(ph, cmd, data) \ 1210Sstevel@tonic-gate (*(ph)->ph_ops->op_prop_int64)((ph), (cmd), (data)) 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * Property handle commands 1250Sstevel@tonic-gate */ 1260Sstevel@tonic-gate typedef enum { 1270Sstevel@tonic-gate DDI_PROP_CMD_GET_ESIZE, /* Get encoded size of data */ 1280Sstevel@tonic-gate DDI_PROP_CMD_GET_DSIZE, /* Get decoded size of data */ 1290Sstevel@tonic-gate DDI_PROP_CMD_DECODE, /* Decode the current data */ 1300Sstevel@tonic-gate DDI_PROP_CMD_ENCODE, /* Encode the current data */ 1310Sstevel@tonic-gate DDI_PROP_CMD_SKIP /* Skip the current data */ 1320Sstevel@tonic-gate } ddi_prop_cmd_t; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* 1350Sstevel@tonic-gate * Return values from property handle encode/decode ops 1360Sstevel@tonic-gate * Positive numbers are used to return the encoded or 1370Sstevel@tonic-gate * decode size of the object, so an ok return must be positive, 1380Sstevel@tonic-gate * and all error returns negative. 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate typedef enum { 1410Sstevel@tonic-gate DDI_PROP_RESULT_ERROR = -2, /* error in encoding/decoding data */ 1420Sstevel@tonic-gate DDI_PROP_RESULT_EOF, /* end of data reached */ 1430Sstevel@tonic-gate DDI_PROP_RESULT_OK /* if >= to DDI_PROP_RESULT_OK, */ 1440Sstevel@tonic-gate /* operation was successful */ 1450Sstevel@tonic-gate } ddi_prop_result_t; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1275 property cell */ 1480Sstevel@tonic-gate typedef uint32_t prop_1275_cell_t; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* Length of a 1275 property cell */ 1510Sstevel@tonic-gate #define PROP_1275_CELL_SIZE sizeof (prop_1275_cell_t) 1520Sstevel@tonic-gate #define CELLS_1275_TO_BYTES(n) ((n) * PROP_1275_CELL_SIZE) 1530Sstevel@tonic-gate #define BYTES_TO_1275_CELLS(n) ((n) / PROP_1275_CELL_SIZE) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * Property handle flags 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate #define PH_FROM_PROM 0x01 /* Property came from the prom */ 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * Return values from property functions: 1620Sstevel@tonic-gate */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define DDI_PROP_SUCCESS 0 1650Sstevel@tonic-gate #define DDI_PROP_NOT_FOUND 1 /* Prop not defined */ 1660Sstevel@tonic-gate #define DDI_PROP_UNDEFINED 2 /* Overriden to undefine a prop */ 1670Sstevel@tonic-gate #define DDI_PROP_NO_MEMORY 3 /* Unable to allocate/no sleep */ 1680Sstevel@tonic-gate #define DDI_PROP_INVAL_ARG 4 /* Invalid calling argument */ 1690Sstevel@tonic-gate #define DDI_PROP_BUF_TOO_SMALL 5 /* Callers buf too small */ 1700Sstevel@tonic-gate #define DDI_PROP_CANNOT_DECODE 6 /* Could not decode prop */ 1710Sstevel@tonic-gate #define DDI_PROP_CANNOT_ENCODE 7 /* Could not encode prop */ 1720Sstevel@tonic-gate #define DDI_PROP_END_OF_DATA 8 /* Prop found in an encoded format */ 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate /* 1750Sstevel@tonic-gate * used internally in the framework only 1760Sstevel@tonic-gate */ 1770Sstevel@tonic-gate #define DDI_PROP_FOUND_1275 255 /* Prop found in OPB 1275 format */ 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Size of a 1275 int in bytes 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate #define PROP_1275_INT_SIZE 4 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate /* 1850Sstevel@tonic-gate * Property flags: 1860Sstevel@tonic-gate */ 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #define DDI_PROP_DONTPASS 0x0001 /* Don't pass request to parent */ 1890Sstevel@tonic-gate #define DDI_PROP_CANSLEEP 0x0002 /* Memory allocation may sleep */ 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * Used internally by the DDI property rountines and masked in DDI(9F) 1930Sstevel@tonic-gate * interfaces... 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate #define DDI_PROP_SYSTEM_DEF 0x0004 /* System defined property */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * Used in framework only, to inhibit certain pre-defined s/w property 2000Sstevel@tonic-gate * names from coming from the prom. 2010Sstevel@tonic-gate */ 2020Sstevel@tonic-gate #define DDI_PROP_NOTPROM 0x0008 /* Don't look at prom properties */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Used interally by the DDI property routines to implement the old 2060Sstevel@tonic-gate * depricated functions with the new functions 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate #define DDI_PROP_DONTSLEEP 0x0010 /* Memory allocation may not sleep */ 2090Sstevel@tonic-gate #define DDI_PROP_STACK_CREATE 0x0020 /* Do a LIFO stack of properties */ 2100Sstevel@tonic-gate #define DDI_PROP_UNDEF_IT 0x0040 /* Undefine a property */ 2110Sstevel@tonic-gate #define DDI_PROP_HW_DEF 0x0080 /* Hardware defined property */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Type of data property contains 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate #define DDI_PROP_TYPE_INT 0x0100 2170Sstevel@tonic-gate #define DDI_PROP_TYPE_STRING 0x0200 2180Sstevel@tonic-gate #define DDI_PROP_TYPE_BYTE 0x0400 2190Sstevel@tonic-gate #define DDI_PROP_TYPE_COMPOSITE 0x0800 2200Sstevel@tonic-gate #define DDI_PROP_TYPE_INT64 0x1000 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate #define DDI_PROP_TYPE_ANY (DDI_PROP_TYPE_INT | \ 2230Sstevel@tonic-gate DDI_PROP_TYPE_STRING | \ 2240Sstevel@tonic-gate DDI_PROP_TYPE_BYTE | \ 2250Sstevel@tonic-gate DDI_PROP_TYPE_COMPOSITE) 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #define DDI_PROP_TYPE_MASK (DDI_PROP_TYPE_INT | \ 2280Sstevel@tonic-gate DDI_PROP_TYPE_STRING | \ 2290Sstevel@tonic-gate DDI_PROP_TYPE_BYTE | \ 2300Sstevel@tonic-gate DDI_PROP_TYPE_COMPOSITE | \ 2310Sstevel@tonic-gate DDI_PROP_TYPE_INT64) 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * This flag indicates that the LDI lookup routine 2350Sstevel@tonic-gate * should match the request regardless of the actual 2360Sstevel@tonic-gate * dev_t with which the property was created. In other 2370Sstevel@tonic-gate * words, any dev_t value found on the property list 2380Sstevel@tonic-gate * is an acceptable part of the match criteria. 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate #define LDI_DEV_T_ANY 0x2000 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* 2430Sstevel@tonic-gate * Private flag that should ONLY be used by the LDI Framework 2440Sstevel@tonic-gate * to indicate a property search of an unbound dlpi2 dip. 2450Sstevel@tonic-gate * The LDI property lookup interfaces will set this flag if 2460Sstevel@tonic-gate * it is determined that the dip representing a dlpi-style2 2470Sstevel@tonic-gate * driver is currently unbound (dip == NULL) at the time of 2480Sstevel@tonic-gate * the property lookup request. 2490Sstevel@tonic-gate */ 2500Sstevel@tonic-gate #define DDI_UNBND_DLPI2 0x4000 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate /* 2530Sstevel@tonic-gate * Private flag that indicates that a typed interface that predates typed 2540Sstevel@tonic-gate * properties is being used - the framework should set additional typed flags 2550Sstevel@tonic-gate * (DDI_PROP_TYPE_INT64) when expanding search to DDI_PROP_TYPE_ANY. 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate #define DDI_PROP_CONSUMER_TYPED 0x8000 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* 2600Sstevel@tonic-gate * Private flag that indicates that the ldi is doing a driver prop_op 2610Sstevel@tonic-gate * call to check for driver dynamic properties. This request should 2620Sstevel@tonic-gate * not be passed onto the common property lookup framework since all 2630Sstevel@tonic-gate * the ldi property interface are typed and driver prop_op lookups are 2640Sstevel@tonic-gate * not. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate #define DDI_PROP_DYNAMIC 0x10000 2670Sstevel@tonic-gate 268*8371SVikram.Hegde@Sun.COM /* 269*8371SVikram.Hegde@Sun.COM * Private flag used to lookup global properties specified in rootnex.conf file 270*8371SVikram.Hegde@Sun.COM */ 271*8371SVikram.Hegde@Sun.COM #define DDI_PROP_ROOTNEX_GLOBAL 0x20000 272*8371SVikram.Hegde@Sun.COM 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate /* 2750Sstevel@tonic-gate * DDI_DEV_T_NONE: When creating, property is not associated with 2760Sstevel@tonic-gate * particular dev_t. 2770Sstevel@tonic-gate * DDI_DEV_T_ANY: Wildcard dev_t when searching properties. 2787009Scth */ 2797009Scth #define DDI_DEV_T_NONE ((dev_t)-1) 2807009Scth #define DDI_DEV_T_ANY ((dev_t)-2) 2817009Scth /* 2820Sstevel@tonic-gate * DDI_MAJOR_T_UNKNOWN Used when a driver does not know its dev_t during 2830Sstevel@tonic-gate * a property create. 2847009Scth * DDI_MAJOR_T_NONE Used when a driver does not have a major number. 2850Sstevel@tonic-gate */ 2860Sstevel@tonic-gate #define DDI_MAJOR_T_UNKNOWN ((major_t)0) 2877009Scth #define DDI_MAJOR_T_NONE ((major_t)-1) 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate /* 2900Sstevel@tonic-gate * Some DDI property names... 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * One of the following boolean properties shall be defined in the 2950Sstevel@tonic-gate * root node, and defines the addressing mode understood by the root 2960Sstevel@tonic-gate * node of the implementation.... 2970Sstevel@tonic-gate */ 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate #define DDI_RELATIVE_ADDRESSING "relative-addressing" 3000Sstevel@tonic-gate #define DDI_GENERIC_ADDRESSING "generic-addressing" 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * Common property encoded data search routine. Returns the encoded data 3040Sstevel@tonic-gate * in valuep. Match is done on dip, dev, data type (in flags), and name. 3050Sstevel@tonic-gate */ 3060Sstevel@tonic-gate int ddi_prop_search_common(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 3070Sstevel@tonic-gate uint_t flags, char *name, void *valuep, uint_t *lengthp); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate /* 3110Sstevel@tonic-gate * Property debugging support in kernel... 3120Sstevel@tonic-gate */ 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate /* 3150Sstevel@tonic-gate * Property debugging support... Be careful about enabling this when 3160Sstevel@tonic-gate * you are tipping in to the console. Undefine PROP_DEBUG to remove 3170Sstevel@tonic-gate * all support from the code. (c.f. autoconf.c and zs_common.c) 3180Sstevel@tonic-gate * 3190Sstevel@tonic-gate * It does no good to enable this if the rest of the kernel was built with 3200Sstevel@tonic-gate * this disabled (specifically, the core kernel module.) 3210Sstevel@tonic-gate * 3220Sstevel@tonic-gate * #define DDI_PROP_DEBUG 1 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate #ifdef DDI_PROP_DEBUG 3260Sstevel@tonic-gate #define ddi_prop_printf if (ddi_prop_debug_flag != 0) printf 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* 3290Sstevel@tonic-gate * Returns prev value of debugging flag, non-zero enables debug printf's 3300Sstevel@tonic-gate */ 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate int ddi_prop_debug(int enable); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate #endif /* DDI_PROP_DEBUG */ 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate #ifdef __cplusplus 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate #endif 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate #endif /* _SYS_DDIPROPDEFS_H */ 341