Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
#include <sys/types.h> #include <sys/ddi.h> #include <sys/sunddi.h> int prefixprop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int flags, char *name, caddr_t valuep, int *lengthp);
Device number associated with this device.
A pointer to the device information structure for this device.
Property operator. Valid operators are: PROP_LEN
Get property length only. (valuep unaffected).
Get length and value into caller's buffer. (valuep used as input).
Get length and value into allocated buffer. (valuep returned as pointer to pointer to allocated buffer).
The only possible flag value is: DDI_PROP_DONTPASS
Do not pass request to parent if property not found.
Pointer to name of property to be interrogated.
If prop_op is PROP_LEN_AND_VAL_BUF, this should be a pointer to the user's buffer. If prop_op is PROP_LEN_AND_VAL_ALLOC, this should be the address of a pointer.
On exit, *lengthp will contain the property length. If prop_op is PROP_LEN_AND_VAL_BUF then lengthp should point to an int that contains the length of caller's buffer, before calling prop_op().
Property found and returned.
Property not found.
Prop explicitly undefined.
Property found, but unable to allocate memory. lengthp has the correct property length.
Property found, but the supplied buffer is too small. lengthp has the correct property length.
In the following example, prop_op() intercepts requests for the temperature property. The driver tracks changes to temperature using a variable in the state structure in order to avoid frequent calls to ddi_prop_update(9F). The temperature property is only updated when a request is made for this property. It then uses the system routine ddi_prop_op(9F) to process the property request. If the property request is not specific to a device, the driver does not intercept the request. This is indicated when the value of the dev parameter is equal to DDI_DEV_T_ANY.
int temperature; /* current device temperature */ . . . static int xxprop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int flags, char *name, caddr_t valuep, int *lengthp) { int instance; struct xxstate *xsp; if (dev == DDI_DEV_T_ANY) goto skip; instance = getminor(dev); xsp = ddi_get_soft_state(statep, instance); if (xsp == NULL) return (DDI_PROP_NOT_FOUND); if (strcmp(name, "temperature") == 0) { ddi_prop_update_int(dev, dip,\e "temperature", temperature); } /* other cases... */ skip: return (ddi_prop_op(dev, dip, prop_op, flags,\e name, valuep, lengthp)); }
Writing Device Drivers