summaryrefslogtreecommitdiff
path: root/usr/src/man/man9e/detach.9e
blob: 544cb7536e3657fa316628a69afa244613e3d1d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
'\" te
.\"  Copyright (c) 2003, 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]
.TH DETACH 9E "Jul 25, 2015"
.SH NAME
detach \- detach or suspend a device
.SH SYNOPSIS
.LP
.nf
#include <sys/ddi.h>
#include <sys/sunddi.h>



\fBint prefix\fR\fBdetach\fR(\fBdev_info_t *\fR \fIdip\fR, \fBddi_detach_cmd_t\fR \fIcmd\fR);
.fi

.SH INTERFACE LEVEL
.LP
Solaris DDI specific (Solaris DDI)
.SH PARAMETERS
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 7n
A pointer to the device's \fBdev_info\fR structure.
.RE

.sp
.ne 2
.na
\fB\fIcmd\fR\fR
.ad
.RS 7n
Type of detach; the driver should return \fBDDI_FAILURE\fR if any value other
than \fBDDI_DETACH\fR or \fBDDI_SUSPEND\fR is passed to it.
.RE

.SH DESCRIPTION
.LP
The \fBdetach()\fR function complements the \fBattach\fR(9E) routine.
.SS "DDI_DETACH"
.LP
If \fIcmd\fR is set to \fBDDI_DETACH\fR, \fBdetach()\fR is used to remove the
state associated with a given instance of a device node prior to the removal of
that instance from the system.
.sp
.LP
The \fBdetach()\fR function will be called once for each instance of the device
for which there has been a successful \fBattach()\fR, once there are no longer
any opens on the device. An attached instance of a driver can be successfully
detached only once. The \fBdetach()\fR function should clean up any per
instance data initialized in \fBattach\fR(9E) and call \fBkmem_free\fR(9F) to
free any heap allocations. For information on how to unregister interrupt
handlers, see \fBddi_add_intr\fR(9F). This should also include putting the
underlying device into a quiescent state so that it will not generate
interrupts.
.sp
.LP
Drivers that set up \fBtimeout\fR(9F) routines should ensure that they are
cancelled before returning \fBDDI_SUCCESS\fR from \fBdetach()\fR.
.sp
.LP
If \fBdetach()\fR determines a particular instance of the device cannot be
removed when requested because of some exceptional condition, \fBdetach()\fR
must return \fBDDI_FAILURE\fR, which prevents the particular device instance
from being detached. This also prevents the driver from being unloaded. A
driver instance failing the detach must ensure that no per instance data or
state is modified or freed that would compromise the system or subsequent
driver operation.
.sp
.LP
The system guarantees that the function will only be called for a particular
\fBdev_info\fR node after (and not concurrently with) a successful
\fBattach\fR(9E) of that device. The system also guarantees that \fBdetach()\fR
will only be called when there are no outstanding \fBopen\fR(9E) calls on the
device.
.SS "DDI_SUSPEND"
.LP
The \fBDDI_SUSPEND\fR \fIcmd\fR is issued when the entire system is being
suspended and power removed from it or when the system must be made quiescent.
It will be issued only to devices which have a \fBreg\fR property or which
export a \fBpm-hardware-state\fR property with the value needs-suspend-resume.
.sp
.LP
If \fIcmd\fR is set to \fBDDI_SUSPEND\fR, \fBdetach()\fR is used to suspend all
activity of a device before power is (possibly) removed from the device. The
steps associated with suspension must include putting the underlying device
into a quiescent state so that it will not generate interrupts or modify or
access memory. Once quiescence has been obtained, \fBdetach()\fR can be called
with outstanding \fBopen\fR(9E) requests. It must save the hardware state of
the device to memory and block incoming or existing requests until
\fBattach()\fR is called with \fBDDI_RESUME\fR.
.sp
.LP
If the device is used to store file systems, then after \fBDDI_SUSPEND\fR is
issued, the device should still honor \fBdump\fR(9E) requests as this entry
point may be used by suspend-resume operation (see \fBcpr\fR(7)) to save state
file. It must do this, however, without disturbing the saved hardware state of
the device.
.sp
.LP
If the device driver uses automatic device Power Management interfaces (driver
exports \fBpm-components\fR(9P) property), it might need to call
\fBpm_raise_power\fR(9F) if the current power level is lower than required to
complete the \fBdump\fR(9E) request.
.sp
.LP
Before returning successfully from a call to \fBdetach()\fR with a command of
\fBDDI_SUSPEND\fR, the driver must cancel any outstanding timeouts and make any
driver threads quiescent.
.sp
.LP
If \fBDDI_FAILURE\fR is returned for the \fBDDI_SUSPEND\fR \fIcmd\fR, either
the operation to suspend the system or to make it quiescent will be aborted.
.SH RETURN VALUES
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
For \fBDDI_DETACH\fR, the state associated with the given device was
successfully removed. For \fBDDI_SUSPEND\fR, the driver was successfully
suspended.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
The operation failed or the request was not understood. The associated state is
unchanged.
.RE

.SH CONTEXT
.LP
This function is called from user context only.
.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
.TE

.SH SEE ALSO
.LP
\fBcpr\fR(7), \fBpm\fR(7D), \fBpm\fR(9P), \fBpm-components\fR(9P),
\fBattach\fR(9E), \fBdump\fR(9E), \fBopen\fR(9E), \fBpower\fR(9E),
\fBddi_add_intr\fR(9F), \fBddi_dev_is_needed\fR(9F), \fBddi_map_regs\fR(9F),
\fBkmem_free\fR(9F), \fBpm_raise_power\fR(9F), \fBtimeout\fR(9F)
.sp
.LP
\fIWriting Device Drivers\fR