xref: /freebsd/sys/kern/device_if.m (revision 6c2e3dde8cb3d10e7825d5e2a4ff46d0ab2ba221)
1b1bf6610SDoug Rabson#
2b1bf6610SDoug Rabson# Copyright (c) 1998 Doug Rabson
3b1bf6610SDoug Rabson# All rights reserved.
4b1bf6610SDoug Rabson#
5b1bf6610SDoug Rabson# Redistribution and use in source and binary forms, with or without
6b1bf6610SDoug Rabson# modification, are permitted provided that the following conditions
7b1bf6610SDoug Rabson# are met:
8b1bf6610SDoug Rabson# 1. Redistributions of source code must retain the above copyright
9b1bf6610SDoug Rabson#    notice, this list of conditions and the following disclaimer.
10b1bf6610SDoug Rabson# 2. Redistributions in binary form must reproduce the above copyright
11b1bf6610SDoug Rabson#    notice, this list of conditions and the following disclaimer in the
12b1bf6610SDoug Rabson#    documentation and/or other materials provided with the distribution.
13b1bf6610SDoug Rabson#
14b1bf6610SDoug Rabson# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15b1bf6610SDoug Rabson# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16b1bf6610SDoug Rabson# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17b1bf6610SDoug Rabson# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18b1bf6610SDoug Rabson# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19b1bf6610SDoug Rabson# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20b1bf6610SDoug Rabson# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21b1bf6610SDoug Rabson# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22b1bf6610SDoug Rabson# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23b1bf6610SDoug Rabson# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24b1bf6610SDoug Rabson# SUCH DAMAGE.
25b1bf6610SDoug Rabson#
266c2e3ddeSDoug Rabson#	$Id: device_if.m,v 1.4 1999/05/10 17:06:13 dfr Exp $
27b1bf6610SDoug Rabson#
28b1bf6610SDoug Rabson
297a8ecb9eSNicolas SouchuINTERFACE device;
30b1bf6610SDoug Rabson
31b1bf6610SDoug Rabson#
328b2970bbSDoug Rabson# Default implementations of some methods.
338b2970bbSDoug Rabson#
348b2970bbSDoug RabsonCODE {
358b2970bbSDoug Rabson	static int null_shutdown(device_t dev)
368b2970bbSDoug Rabson	{
378b2970bbSDoug Rabson	    return 0;
388b2970bbSDoug Rabson	}
398b2970bbSDoug Rabson
408b2970bbSDoug Rabson	static int null_suspend(device_t dev)
418b2970bbSDoug Rabson	{
428b2970bbSDoug Rabson	    return 0;
438b2970bbSDoug Rabson	}
448b2970bbSDoug Rabson
458b2970bbSDoug Rabson	static int null_resume(device_t dev)
468b2970bbSDoug Rabson	{
478b2970bbSDoug Rabson	    return 0;
488b2970bbSDoug Rabson	}
498b2970bbSDoug Rabson};
508b2970bbSDoug Rabson
518b2970bbSDoug Rabson#
52b1bf6610SDoug Rabson# Probe to see if the device is present.  Return 0 if the device exists,
538b2970bbSDoug Rabson# ENXIO if it cannot be found.  For cases where more than one driver
548b2970bbSDoug Rabson# matches a device, a priority value can be returned.  In this case,
558b2970bbSDoug Rabson# success codes are values less than or equal to zero with the highest
568b2970bbSDoug Rabson# value representing the best match.  Failure codes are represented by
578b2970bbSDoug Rabson# positive values and the regular unix error codes should be used for
588b2970bbSDoug Rabson# the purpose.
598b2970bbSDoug Rabson#
608b2970bbSDoug Rabson# If a driver returns a success code which is less than zero, it must
618b2970bbSDoug Rabson# not assume that it will be the same driver which is attached to the
628b2970bbSDoug Rabson# device. In particular, it must not assume that any values stored in
638b2970bbSDoug Rabson# the softc structure will be available for its attach method and any
648b2970bbSDoug Rabson# resources allocated during probe must be released and re-allocated
658b2970bbSDoug Rabson# if the attach method is called.  If a success code of zero is
668b2970bbSDoug Rabson# returned, the driver can assume that it will be the one attached.
67b1bf6610SDoug Rabson#
68b1bf6610SDoug Rabson# Devices which implement busses should use this method to probe for
69b1bf6610SDoug Rabson# the existence of devices attached to the bus and add them as
70b1bf6610SDoug Rabson# children.  If this is combined with the use of bus_generic_attach,
71b1bf6610SDoug Rabson# the child devices will be automatically probed and attached.
72b1bf6610SDoug Rabson#
73b1bf6610SDoug RabsonMETHOD int probe {
74b1bf6610SDoug Rabson	device_t dev;
75b1bf6610SDoug Rabson};
76b1bf6610SDoug Rabson
77b1bf6610SDoug Rabson#
786c2e3ddeSDoug Rabson# Called by a parent bus to add new devices to the bus.
796c2e3ddeSDoug Rabson#
806c2e3ddeSDoug RabsonSTATICMETHOD void identify {
816c2e3ddeSDoug Rabson	driver_t *driver;
826c2e3ddeSDoug Rabson	device_t parent;
836c2e3ddeSDoug Rabson};
846c2e3ddeSDoug Rabson
856c2e3ddeSDoug Rabson#
86b1bf6610SDoug Rabson# Attach a device to the system.  The probe method will have been
87b1bf6610SDoug Rabson# called and will have indicated that the device exists.  This routine
88b1bf6610SDoug Rabson# should initialise the hardware and allocate other system resources
89b1bf6610SDoug Rabson# (such as devfs entries).  Returns 0 on success.
90b1bf6610SDoug Rabson#
91b1bf6610SDoug RabsonMETHOD int attach {
92b1bf6610SDoug Rabson	device_t dev;
93b1bf6610SDoug Rabson};
94b1bf6610SDoug Rabson
95b1bf6610SDoug Rabson#
96b1bf6610SDoug Rabson# Detach a device.  This can be called if the user is replacing the
97b1bf6610SDoug Rabson# driver software or if a device is about to be physically removed
98b1bf6610SDoug Rabson# from the system (e.g. for pccard devices).  Returns 0 on success.
99b1bf6610SDoug Rabson#
100b1bf6610SDoug RabsonMETHOD int detach {
101b1bf6610SDoug Rabson	device_t dev;
102b1bf6610SDoug Rabson};
103b1bf6610SDoug Rabson
104b1bf6610SDoug Rabson#
105b1bf6610SDoug Rabson# This is called during system shutdown to allow the driver to put the
106b1bf6610SDoug Rabson# hardware into a consistent state for rebooting the computer.
107b1bf6610SDoug Rabson#
108b1bf6610SDoug RabsonMETHOD int shutdown {
109b1bf6610SDoug Rabson	device_t dev;
1108b2970bbSDoug Rabson} DEFAULT null_shutdown;
11114177d72SGarrett Wollman
11214177d72SGarrett Wollman#
11314177d72SGarrett Wollman# This is called by the power-management subsystem when a suspend has been
11414177d72SGarrett Wollman# requested by the user or by some automatic mechanism.  This gives
11514177d72SGarrett Wollman# drivers a chance to veto the suspend or save their configuration before
11614177d72SGarrett Wollman# power is removed.
11714177d72SGarrett Wollman#
11814177d72SGarrett WollmanMETHOD int suspend {
11914177d72SGarrett Wollman	device_t dev;
1208b2970bbSDoug Rabson} DEFAULT null_suspend;
12114177d72SGarrett Wollman
12214177d72SGarrett WollmanMETHOD int resume {
12314177d72SGarrett Wollman	device_t dev;
1248b2970bbSDoug Rabson} DEFAULT null_resume;
125