device_if.m revision 47178
136973Sdfr#
236973Sdfr# Copyright (c) 1998 Doug Rabson
336973Sdfr# All rights reserved.
436973Sdfr#
536973Sdfr# Redistribution and use in source and binary forms, with or without
636973Sdfr# modification, are permitted provided that the following conditions
736973Sdfr# are met:
836973Sdfr# 1. Redistributions of source code must retain the above copyright
936973Sdfr#    notice, this list of conditions and the following disclaimer.
1036973Sdfr# 2. Redistributions in binary form must reproduce the above copyright
1136973Sdfr#    notice, this list of conditions and the following disclaimer in the
1236973Sdfr#    documentation and/or other materials provided with the distribution.
1336973Sdfr#
1436973Sdfr# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536973Sdfr# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636973Sdfr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736973Sdfr# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836973Sdfr# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936973Sdfr# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036973Sdfr# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136973Sdfr# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236973Sdfr# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336973Sdfr# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436973Sdfr# SUCH DAMAGE.
2536973Sdfr#
2647178Sdfr#	$Id: device_if.m,v 1.4 1999/05/10 17:06:13 dfr Exp $
2736973Sdfr#
2836973Sdfr
2941012SnsouchINTERFACE device;
3036973Sdfr
3136973Sdfr#
3246913Sdfr# Default implementations of some methods.
3346913Sdfr#
3446913SdfrCODE {
3546913Sdfr	static int null_shutdown(device_t dev)
3646913Sdfr	{
3746913Sdfr	    return 0;
3846913Sdfr	}
3946913Sdfr
4046913Sdfr	static int null_suspend(device_t dev)
4146913Sdfr	{
4246913Sdfr	    return 0;
4346913Sdfr	}
4446913Sdfr
4546913Sdfr	static int null_resume(device_t dev)
4646913Sdfr	{
4746913Sdfr	    return 0;
4846913Sdfr	}
4946913Sdfr};
5046913Sdfr
5146913Sdfr#
5236973Sdfr# Probe to see if the device is present.  Return 0 if the device exists,
5346913Sdfr# ENXIO if it cannot be found.  For cases where more than one driver
5446913Sdfr# matches a device, a priority value can be returned.  In this case,
5546913Sdfr# success codes are values less than or equal to zero with the highest 
5646913Sdfr# value representing the best match.  Failure codes are represented by
5746913Sdfr# positive values and the regular unix error codes should be used for
5846913Sdfr# the purpose.
5946913Sdfr#
6046913Sdfr# If a driver returns a success code which is less than zero, it must
6146913Sdfr# not assume that it will be the same driver which is attached to the
6246913Sdfr# device. In particular, it must not assume that any values stored in
6346913Sdfr# the softc structure will be available for its attach method and any
6446913Sdfr# resources allocated during probe must be released and re-allocated
6546913Sdfr# if the attach method is called.  If a success code of zero is
6646913Sdfr# returned, the driver can assume that it will be the one attached.
6736973Sdfr# 
6836973Sdfr# Devices which implement busses should use this method to probe for
6936973Sdfr# the existence of devices attached to the bus and add them as
7036973Sdfr# children.  If this is combined with the use of bus_generic_attach,
7136973Sdfr# the child devices will be automatically probed and attached.
7236973Sdfr#
7336973SdfrMETHOD int probe {
7436973Sdfr	device_t dev;
7536973Sdfr};
7636973Sdfr
7736973Sdfr#
7847178Sdfr# Called by a parent bus to add new devices to the bus.
7947178Sdfr#
8047178SdfrSTATICMETHOD void identify {
8147178Sdfr	driver_t *driver;
8247178Sdfr	device_t parent;
8347178Sdfr};
8447178Sdfr
8547178Sdfr#
8636973Sdfr# Attach a device to the system.  The probe method will have been
8736973Sdfr# called and will have indicated that the device exists.  This routine
8836973Sdfr# should initialise the hardware and allocate other system resources
8936973Sdfr# (such as devfs entries).  Returns 0 on success.
9036973Sdfr#
9136973SdfrMETHOD int attach {
9236973Sdfr	device_t dev;
9336973Sdfr};
9436973Sdfr
9536973Sdfr#
9636973Sdfr# Detach a device.  This can be called if the user is replacing the
9736973Sdfr# driver software or if a device is about to be physically removed
9836973Sdfr# from the system (e.g. for pccard devices).  Returns 0 on success.
9936973Sdfr#
10036973SdfrMETHOD int detach {
10136973Sdfr	device_t dev;
10236973Sdfr};
10336973Sdfr
10436973Sdfr#
10536973Sdfr# This is called during system shutdown to allow the driver to put the 
10636973Sdfr# hardware into a consistent state for rebooting the computer.
10736973Sdfr#
10836973SdfrMETHOD int shutdown {
10936973Sdfr	device_t dev;
11046913Sdfr} DEFAULT null_shutdown;
11141153Swollman
11241153Swollman#
11341153Swollman# This is called by the power-management subsystem when a suspend has been
11441153Swollman# requested by the user or by some automatic mechanism.  This gives
11541153Swollman# drivers a chance to veto the suspend or save their configuration before
11641153Swollman# power is removed.
11741153Swollman#
11841153SwollmanMETHOD int suspend {
11941153Swollman	device_t dev;
12046913Sdfr} DEFAULT null_suspend;
12141153Swollman
12241153SwollmanMETHOD int resume {
12341153Swollman	device_t dev;
12446913Sdfr} DEFAULT null_resume;
125