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 DETACH 9E "Dec 7, 2003"
   7 .SH NAME
   8 detach \- detach or suspend a device
   9 .SH SYNOPSIS
  10 .LP
  11 .nf
  12 #include <sys/ddi.h>
  13 #include <sys/sunddi.h>
  14 
  15 
  16 
  17 \fBint prefix\fR \fBdetach\fR(\fBdev_info_t *\fR \fIdip\fR, \fBddi_detach_cmd_t\fR \fIcmd\fR);
  18 .fi
  19 
  20 .SH INTERFACE LEVEL
  21 .LP
  22 Solaris DDI specific (Solaris DDI)
  23 .SH PARAMETERS
  24 .ne 2
  25 .na
  26 \fB\fIdip\fR\fR
  27 .ad
  28 .RS 7n
  29 A pointer to the device's \fBdev_info\fR structure.
  30 .RE
  31 
  32 .sp
  33 .ne 2
  34 .na
  35 \fB\fIcmd\fR\fR
  36 .ad
  37 .RS 7n
  38 Type of detach; the driver should return \fBDDI_FAILURE\fR if any value other
  39 than \fBDDI_DETACH\fR or \fBDDI_SUSPEND\fR is passed to it.
  40 .RE
  41 
  42 .SH DESCRIPTION
  43 .LP
  44 The \fBdetach()\fR function complements the \fBattach\fR(9E) routine.
  45 .SS "DDI_DETACH"
  46 .LP
  47 If \fIcmd\fR is set to \fBDDI_DETACH\fR, \fBdetach()\fR is used to remove the
  48 state associated with a given instance of a device node prior to the removal of
  49 that instance from the system.
  50 .sp
  51 .LP
  52 The \fBdetach()\fR function will be called once for each instance of the device
  53 for which there has been a successful \fBattach()\fR, once there are no longer
  54 any opens on the device. An attached instance of a driver can be successfully
  55 detached only once. The \fBdetach()\fR function should clean up any per
  56 instance data initialized in \fBattach\fR(9E) and call \fBkmem_free\fR(9F) to
  57 free any heap allocations. For information on how to unregister interrupt
  58 handlers, see \fBddi_add_intr\fR(9F). This should also include putting the
  59 underlying device into a quiescent state so that it will not generate
  60 interrupts.
  61 .sp
  62 .LP
  63 Drivers that set up \fBtimeout\fR(9F) routines should ensure that they are
  64 cancelled before returning \fBDDI_SUCCESS\fR from \fBdetach()\fR.
  65 .sp
  66 .LP
  67 If \fBdetach()\fR determines a particular instance of the device cannot be
  68 removed when requested because of some exceptional condition, \fBdetach()\fR
  69 must return \fBDDI_FAILURE\fR, which prevents the particular device instance
  70 from being detached. This also prevents the driver from being unloaded. A
  71 driver instance failing the detach must ensure that no per instance data or
  72 state is modified or freed that would compromise the system or subsequent
  73 driver operation.
  74 .sp
  75 .LP
  76 The system guarantees that the function will only be called for a particular
  77 \fBdev_info\fR node after (and not concurrently with) a successful
  78 \fBattach\fR(9E) of that device. The system also guarantees that \fBdetach()\fR
  79 will only be called when there are no outstanding \fBopen\fR(9E) calls on the
  80 device.
  81 .SS "DDI_SUSPEND"
  82 .LP
  83 The \fBDDI_SUSPEND\fR \fIcmd\fR is issued when the entire system is being
  84 suspended and power removed from it or when the system must be made quiescent.
  85 It will be issued only to devices which have a \fBreg\fR property or which
  86 export a \fBpm-hardware-state\fR property with the value needs-suspend-resume.
  87 .sp
  88 .LP
  89 If \fIcmd\fR is set to \fBDDI_SUSPEND\fR, \fBdetach()\fR is used to suspend all
  90 activity of a device before power is (possibly) removed from the device. The
  91 steps associated with suspension must include putting the underlying device
  92 into a quiescent state so that it will not generate interrupts or modify or
  93 access memory. Once quiescence has been obtained, \fBdetach()\fR can be called
  94 with outstanding \fBopen\fR(9E) requests. It must save the hardware state of
  95 the device to memory and block incoming or existing requests until
  96 \fBattach()\fR is called with \fBDDI_RESUME\fR.
  97 .sp
  98 .LP
  99 If the device is used to store file systems, then after \fBDDI_SUSPEND\fR is
 100 issued, the device should still honor \fBdump\fR(9E) requests as this entry
 101 point may be used by suspend-resume operation (see \fBcpr\fR(7)) to save state
 102 file. It must do this, however, without disturbing the saved hardware state of
 103 the device.
 104 .sp
 105 .LP
 106 If the device driver uses automatic device Power Management interfaces (driver
 107 exports \fBpm-components\fR(9P) property), it might need to call
 108 \fBpm_raise_power\fR(9F) if the current power level is lower than required to
 109 complete the \fBdump\fR(9E) request.
 110 .sp
 111 .LP
 112 Before returning successfully from a call to \fBdetach()\fR with a command of
 113 \fBDDI_SUSPEND\fR, the driver must cancel any outstanding timeouts and make any
 114 driver threads quiescent.
 115 .sp
 116 .LP
 117 If \fBDDI_FAILURE\fR is returned for the \fBDDI_SUSPEND\fR \fIcmd\fR, either
 118 the operation to suspend the system or to make it quiescent will be aborted.
 119 .SH RETURN VALUES
 120 .ne 2
 121 .na
 122 \fB\fBDDI_SUCCESS\fR\fR
 123 .ad
 124 .RS 15n
 125 For \fBDDI_DETACH\fR, the state associated with the given device was
 126 successfully removed. For \fBDDI_SUSPEND\fR, the driver was successfully
 127 suspended.
 128 .RE
 129 
 130 .sp
 131 .ne 2
 132 .na
 133 \fB\fBDDI_FAILURE\fR\fR
 134 .ad
 135 .RS 15n
 136 The operation failed or the request was not understood. The associated state is
 137 unchanged.
 138 .RE
 139 
 140 .SH CONTEXT
 141 .LP
 142 This function is called from user context only.
 143 .SH ATTRIBUTES
 144 .LP
 145 See \fBattributes\fR(5) for descriptions of the following attributes:
 146 .sp
 147 
 148 .sp
 149 .TS
 150 box;
 151 c | c
 152 l | l .
 153 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 154 _
 155 Interface Stability     Committed
 156 .TE
 157 
 158 .SH SEE ALSO
 159 .LP
 160 \fBcpr\fR(7), \fBpm\fR(7D), \fBpm\fR(9P), \fBpm-components\fR(9P),
 161 \fBattach\fR(9E), \fBdump\fR(9E), \fBopen\fR(9E), \fBpower\fR(9E),
 162 \fBddi_add_intr\fR(9F), \fBddi_dev_is_needed\fR(9F), \fBddi_map_regs\fR(9F),
 163 \fBkmem_free\fR(9F), \fBpm_raise_power\fR(9F), \fBtimeout\fR(9F)
 164 .sp
 165 .LP
 166 \fIWriting Device Drivers\fR