'\" 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 "7 Dec 2003" "SunOS 5.11" "Driver Entry Points" .SH NAME detach \- detach or suspend a device .SH SYNOPSIS .LP .nf #include #include \fBint prefix\fR \fBdetach\fR(\fBdev_info_t\fR \fIdip\fR, \fBddi_detach_cmd_t\fR \fIcmd\fR); .fi .SH INTERFACE LEVEL .sp .LP Solaris DDI specific (Solaris DDI) .SH PARAMETERS .sp .ne 2 .mk .na \fB\fIdip\fR\fR .ad .RS 7n .rt A pointer to the device's \fBdev_info\fR structure. .RE .sp .ne 2 .mk .na \fB\fIcmd\fR\fR .ad .RS 7n .rt 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 .sp .LP The \fBdetach()\fR function complements the \fBattach\fR(9E) routine. .SS "DDI_DETACH" .sp .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" .sp .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 .sp .ne 2 .mk .na \fB\fBDDI_SUCCESS\fR\fR .ad .RS 15n .rt 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 .mk .na \fB\fBDDI_FAILURE\fR\fR .ad .RS 15n .rt The operation failed or the request was not understood. The associated state is unchanged. .RE .SH CONTEXT .sp .LP This function is called from user context only. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted .TE .SH SEE ALSO .sp .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