bus_if.m revision 49195
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#
2649195Smdodd#	$Id: bus_if.m,v 1.12 1999/07/11 13:42:36 dfr Exp $
2736973Sdfr#
2836973Sdfr
2941017SnsouchINTERFACE bus;
3036973Sdfr
3136973Sdfr#
3246913Sdfr# Default implementations of some methods.
3346913Sdfr#
3446913SdfrCODE {
3546913Sdfr	static struct resource *
3646913Sdfr	null_alloc_resource(device_t dev, device_t child,
3746913Sdfr			    int type, int *rid,
3846913Sdfr			    u_long start, u_long end,
3946913Sdfr			    u_long count, u_int flags)
4046913Sdfr	{
4146913Sdfr	    return 0;
4246913Sdfr	}
4346913Sdfr};
4446913Sdfr
4546913Sdfr#
4636973Sdfr# This is called from system code which prints out a description of a
4736973Sdfr# device.  It should describe the attachment that the child has with
4836973Sdfr# the parent.  For instance the TurboLaser bus prints which node the
4949195Smdodd# device is attached to.  See bus_generic_print_child.9 for more 
5049195Smdodd# information.
5149195Smdodd# This method returns the number of characters output.
5236973Sdfr#
5349195SmdoddMETHOD int print_child {
5436973Sdfr	device_t dev;
5536973Sdfr	device_t child;
5636973Sdfr};
5736973Sdfr
5848754Sdfr# 
5948754Sdfr# Called for each child device that 
6048754Sdfr# did not succeed in probing for a
6148754Sdfr# driver.
6248754Sdfr#    
6348754SdfrMETHOD void probe_nomatch {
6448754Sdfr        device_t dev;
6548754Sdfr        device_t child;
6648754Sdfr};
6748754Sdfr
6836973Sdfr#
6936973Sdfr# These two methods manage a bus specific set of instance variables of
7036973Sdfr# a child device.  The intention is that each different type of bus
7136973Sdfr# defines a set of appropriate instance variables (such as ports and
7236973Sdfr# irqs for ISA bus etc.)
7336973Sdfr#
7436973Sdfr# This information could be given to the child device as a struct but
7536973Sdfr# that makes it hard for a bus to add or remove variables without
7636973Sdfr# forcing an edit and recompile for all drivers which may not be
7736973Sdfr# possible for vendor supplied binary drivers.
7836973Sdfr
7936973Sdfr#
8036973Sdfr# Read an instance variable.  Return 0 on success.
8136973Sdfr#
8236973SdfrMETHOD int read_ivar {
8336973Sdfr	device_t dev;
8436973Sdfr	device_t child;
8536973Sdfr	int index;
8641153Swollman	uintptr_t *result;
8736973Sdfr};
8836973Sdfr
8936973Sdfr#
9036973Sdfr# Write an instance variable.  Return 0 on success.
9136973Sdfr#
9236973SdfrMETHOD int write_ivar {
9336973Sdfr	device_t dev;
9436973Sdfr	device_t child;
9536973Sdfr	int index;
9641153Swollman	uintptr_t value;
9736973Sdfr};
9836973Sdfr
9936973Sdfr#
10045107Sdfr# Called after the child's DEVICE_DETACH method to allow the parent
10145107Sdfr# to reclaim any resources allocated on behalf of the child.
10245107Sdfr#
10345107SdfrMETHOD void child_detached {
10445107Sdfr	device_t dev;
10545107Sdfr	device_t child;
10645107Sdfr};
10745107Sdfr
10845107Sdfr#
10945720Speter# Called when a new driver is added to the devclass which owns this
11045720Speter# bus. The generic implementation of this method attempts to probe and
11145720Speter# attach any un-matched children of the bus.
11245720Speter#
11345720SpeterMETHOD void driver_added {
11445720Speter	device_t dev;
11545720Speter	driver_t *driver;
11645720Speter}
11745720Speter
11845720Speter#
11947178Sdfr# For busses which use use drivers supporting DEVICE_IDENTIFY to
12047178Sdfr# enumerate their devices, these methods are used to create new
12147178Sdfr# device instances. If place is non-NULL, the new device will be
12247578Sdfr# added after the last existing child with the same order.
12347178Sdfr#
12447178SdfrMETHOD device_t add_child {
12547178Sdfr	device_t dev;
12647578Sdfr	int order;
12747178Sdfr	const char *name;
12847178Sdfr	int unit;
12947178Sdfr};
13047178Sdfr
13147178Sdfr#
13241153Swollman# Allocate a system resource attached to `dev' on behalf of `child'.
13341153Swollman# The types are defined in <machine/resource.h>; the meaning of the
13441153Swollman# resource-ID field varies from bus to bus (but *rid == 0 is always
13541153Swollman# valid if the resource type is).  start and end reflect the allowable
13641153Swollman# range, and should be passed as `0UL' and `~0UL', respectively, if
13741153Swollman# the client has no range restriction.  count is the number of consecutive
13841153Swollman# indices in the resource required.  flags is a set of sharing flags
13941153Swollman# as defined in <sys/rman.h>.
14036973Sdfr#
14141153Swollman# Returns a resource or a null pointer on failure.  The caller is
14241153Swollman# responsible for calling rman_activate_resource() when it actually
14341153Swollman# uses the resource.
14441153Swollman#
14541153SwollmanMETHOD struct resource * alloc_resource {
14641153Swollman	device_t	dev;
14741153Swollman	device_t	child;
14841153Swollman	int		type;
14941153Swollman	int	       *rid;
15041153Swollman	u_long		start;
15141153Swollman	u_long		end;
15241153Swollman	u_long		count;
15341153Swollman	u_int		flags;
15446913Sdfr} DEFAULT null_alloc_resource;
15537592Sdfr
15641153SwollmanMETHOD int activate_resource {
15741153Swollman	device_t	dev;
15841153Swollman	device_t	child;
15941153Swollman	int		type;
16041153Swollman	int		rid;
16141153Swollman	struct resource *r;
16241153Swollman};
16341153Swollman
16441153SwollmanMETHOD int deactivate_resource {
16541153Swollman	device_t	dev;
16641153Swollman	device_t	child;
16741153Swollman	int		type;
16841153Swollman	int		rid;
16941153Swollman	struct resource *r;
17041153Swollman};
17141153Swollman
17239344Sdfr#
17341153Swollman# Free a resource allocated by the preceding method.  The `rid' value
17441153Swollman# must be the same as the one returned by BUS_ALLOC_RESOURCE (which
17541153Swollman# is not necessarily the same as the one the client passed).
17639344Sdfr#
17741153SwollmanMETHOD int release_resource {
17841153Swollman	device_t	dev;
17941153Swollman	device_t	child;
18041153Swollman	int		type;
18141153Swollman	int		rid;
18241153Swollman	struct resource *res;
18337592Sdfr};
18441153Swollman
18541153SwollmanMETHOD int setup_intr {
18641153Swollman	device_t	dev;
18741153Swollman	device_t	child;
18841153Swollman	struct resource *irq;
18946743Sdfr	int		flags;
19041153Swollman	driver_intr_t	*intr;
19141153Swollman	void		*arg;
19241153Swollman	void		**cookiep;
19341153Swollman};
19441153Swollman
19541153SwollmanMETHOD int teardown_intr {
19641153Swollman	device_t	dev;
19741153Swollman	device_t	child;
19841153Swollman	struct resource	*irq;
19941153Swollman	void		*cookie;
20041153Swollman};
201