Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / ddi_dev_is_needed.9f
blob00c7f844755a0ef05ca0c4947853ab9068bdd994
1 '\" te
2 .\"  Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH DDI_DEV_IS_NEEDED 9F "Dec 7, 2003"
7 .SH NAME
8 ddi_dev_is_needed \- inform the system that a device's component is required
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/ddi.h>
13 #include <sys/sunddi.h>
17 \fBint\fR \fBddi_dev_is_needed\fR(\fBdev_info_t *\fR\fIdip\fR, \fBint\fR \fIcomponent\fR, \fBint\fR \fIlevel\fR);
18 .fi
20 .SH INTERFACE LEVEL
21 .sp
22 .LP
23 Solaris DDI specific (Solaris DDI)
24 .SH PARAMETERS
25 .sp
26 .ne 2
27 .na
28 \fB\fIdip\fR\fR
29 .ad
30 .RS 13n
31 Pointer to the device's \fBdev_info\fR structure.
32 .RE
34 .sp
35 .ne 2
36 .na
37 \fB\fIcomponent\fR\fR
38 .ad
39 .RS 13n
40 Component of the driver which is needed.
41 .RE
43 .sp
44 .ne 2
45 .na
46 \fB\fIlevel\fR\fR
47 .ad
48 .RS 13n
49 Power level at which the component is needed.
50 .RE
52 .SH DESCRIPTION
53 .sp
54 .LP
55 The \fBddi_dev_is_needed()\fR function is obsolete and will be removed in a
56 future release. It is recommended that device drivers use
57 \fBpm_raise_power\fR(9F) and \fBpm_lower_power\fR(9F).
58 .sp
59 .LP
60 The \fBddi_dev_is_needed()\fR function informs the system that a device
61 component is needed at the specified power level. The \fIlevel\fR argument must
62 be non-zero.
63 .sp
64 .LP
65 This function sets a \fIcomponent\fR to the required level and sets all devices
66 which depend on this to their normal power levels.
67 .sp
68 .LP
69 The state of the device should be examined before each physical access. The
70 \fBddi_dev_is_needed()\fR function should be called to set a \fIcomponent\fR to
71 the required power level if the operation to be performed requires the
72 component to be at a power level other than its current level.
73 .sp
74 .LP
75 The \fBddi_dev_is_needed()\fR function might cause re-entry of the driver.
76 Deadlock may result if driver locks are held across the call to
77 \fBddi_dev_is_needed()\fR.
78 .SH RETURN VALUES
79 .sp
80 .LP
81 The \fBddi_dev_is_needed()\fR function returns:
82 .sp
83 .ne 2
84 .na
85 \fB\fBDDI_SUCCESS\fR\fR
86 .ad
87 .RS 15n
88 Power successfully set to the requested level.
89 .RE
91 .sp
92 .ne 2
93 .na
94 \fB\fBDDI_FAILURE\fR\fR
95 .ad
96 .RS 15n
97 An error occurred.
98 .RE
100 .SH EXAMPLES
102 \fBExample 1 \fRdisk driver code
105 A hypothetical disk driver might include this code:
108 .in +2
110      static int
111 xxdisk_spun_down(struct xxstate *xsp)
113                 return (xsp->power_level[DISK_COMPONENT] < POWER_SPUN_UP);
115 static int
116 xxdisk_strategy(struct buf *bp)
119 \&.\|.\|.
121         mutex_enter(&xxstate_lock);
122         /*
123         * Since we have to drop the mutex, we have to do this in a loop
124         * in case we get preempted and the device gets taken away from
125         * us again
126         */
127         while (device_spun_down(sp)) {
128                 mutex_exit(&xxstate_lock);
129                 if (ddi_dev_is_needed(xsp->mydip,
130                         XXDISK_COMPONENT, XXPOWER_SPUN_UP) != DDI_SUCCESS) {
131                                 bioerror(bp,EIO);
132                                 biodone(bp);
133                 return (0);
134         }
135                 mutex_enter(&xxstate_lock);
136         }
137         xsp->device_busy++;
138         mutex_exit(&xxstate_lock);
140 \&.\|.\|.
144 .in -2
146 .SH CONTEXT
149 This function can be called from user or kernel context.
150 .SH ATTRIBUTES
153 See \fBattributes\fR(5) for descriptions of the following attributes:
158 box;
159 c | c
160 l | l .
161 ATTRIBUTE TYPE  ATTRIBUTE VALUE
163 Interface Stability     Obsolete
166 .SH SEE ALSO
169 \fBpm\fR(7D), \fBpm-components\fR(9P), \fBattach\fR(9E), \fBdetach\fR(9E),
170 \fBpower\fR(9E), \fBpm_busy_component\fR(9F), \fBpm_idle_component\fR(9F)
173 \fIWriting Device Drivers\fR