bus_if.m revision 46743
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#
2646743Sdfr#	$Id: bus_if.m,v 1.7 1999/04/16 21:22:37 peter Exp $
2736973Sdfr#
2836973Sdfr
2941017SnsouchINTERFACE bus;
3036973Sdfr
3136973Sdfr#
3236973Sdfr# This is called from system code which prints out a description of a
3336973Sdfr# device.  It should describe the attachment that the child has with
3436973Sdfr# the parent.  For instance the TurboLaser bus prints which node the
3536973Sdfr# device is attached to.
3636973Sdfr#
3736973SdfrMETHOD void print_child {
3836973Sdfr	device_t dev;
3936973Sdfr	device_t child;
4036973Sdfr};
4136973Sdfr
4236973Sdfr#
4336973Sdfr# These two methods manage a bus specific set of instance variables of
4436973Sdfr# a child device.  The intention is that each different type of bus
4536973Sdfr# defines a set of appropriate instance variables (such as ports and
4636973Sdfr# irqs for ISA bus etc.)
4736973Sdfr#
4836973Sdfr# This information could be given to the child device as a struct but
4936973Sdfr# that makes it hard for a bus to add or remove variables without
5036973Sdfr# forcing an edit and recompile for all drivers which may not be
5136973Sdfr# possible for vendor supplied binary drivers.
5236973Sdfr
5336973Sdfr#
5436973Sdfr# Read an instance variable.  Return 0 on success.
5536973Sdfr#
5636973SdfrMETHOD int read_ivar {
5736973Sdfr	device_t dev;
5836973Sdfr	device_t child;
5936973Sdfr	int index;
6041153Swollman	uintptr_t *result;
6136973Sdfr};
6236973Sdfr
6336973Sdfr#
6436973Sdfr# Write an instance variable.  Return 0 on success.
6536973Sdfr#
6636973SdfrMETHOD int write_ivar {
6736973Sdfr	device_t dev;
6836973Sdfr	device_t child;
6936973Sdfr	int index;
7041153Swollman	uintptr_t value;
7136973Sdfr};
7236973Sdfr
7336973Sdfr#
7445107Sdfr# Called after the child's DEVICE_DETACH method to allow the parent
7545107Sdfr# to reclaim any resources allocated on behalf of the child.
7645107Sdfr#
7745107SdfrMETHOD void child_detached {
7845107Sdfr	device_t dev;
7945107Sdfr	device_t child;
8045107Sdfr};
8145107Sdfr
8245107Sdfr#
8345720Speter# Called when a new driver is added to the devclass which owns this
8445720Speter# bus. The generic implementation of this method attempts to probe and
8545720Speter# attach any un-matched children of the bus.
8645720Speter#
8745720SpeterMETHOD void driver_added {
8845720Speter	device_t dev;
8945720Speter	driver_t *driver;
9045720Speter}
9145720Speter
9245720Speter#
9341153Swollman# Allocate a system resource attached to `dev' on behalf of `child'.
9441153Swollman# The types are defined in <machine/resource.h>; the meaning of the
9541153Swollman# resource-ID field varies from bus to bus (but *rid == 0 is always
9641153Swollman# valid if the resource type is).  start and end reflect the allowable
9741153Swollman# range, and should be passed as `0UL' and `~0UL', respectively, if
9841153Swollman# the client has no range restriction.  count is the number of consecutive
9941153Swollman# indices in the resource required.  flags is a set of sharing flags
10041153Swollman# as defined in <sys/rman.h>.
10136973Sdfr#
10241153Swollman# Returns a resource or a null pointer on failure.  The caller is
10341153Swollman# responsible for calling rman_activate_resource() when it actually
10441153Swollman# uses the resource.
10541153Swollman#
10641153SwollmanMETHOD struct resource * alloc_resource {
10741153Swollman	device_t	dev;
10841153Swollman	device_t	child;
10941153Swollman	int		type;
11041153Swollman	int	       *rid;
11141153Swollman	u_long		start;
11241153Swollman	u_long		end;
11341153Swollman	u_long		count;
11441153Swollman	u_int		flags;
11536973Sdfr};
11637592Sdfr
11741153SwollmanMETHOD int activate_resource {
11841153Swollman	device_t	dev;
11941153Swollman	device_t	child;
12041153Swollman	int		type;
12141153Swollman	int		rid;
12241153Swollman	struct resource *r;
12341153Swollman};
12441153Swollman
12541153SwollmanMETHOD int deactivate_resource {
12641153Swollman	device_t	dev;
12741153Swollman	device_t	child;
12841153Swollman	int		type;
12941153Swollman	int		rid;
13041153Swollman	struct resource *r;
13141153Swollman};
13241153Swollman
13339344Sdfr#
13441153Swollman# Free a resource allocated by the preceding method.  The `rid' value
13541153Swollman# must be the same as the one returned by BUS_ALLOC_RESOURCE (which
13641153Swollman# is not necessarily the same as the one the client passed).
13739344Sdfr#
13841153SwollmanMETHOD int release_resource {
13941153Swollman	device_t	dev;
14041153Swollman	device_t	child;
14141153Swollman	int		type;
14241153Swollman	int		rid;
14341153Swollman	struct resource *res;
14437592Sdfr};
14541153Swollman
14641153SwollmanMETHOD int setup_intr {
14741153Swollman	device_t	dev;
14841153Swollman	device_t	child;
14941153Swollman	struct resource *irq;
15046743Sdfr	int		flags;
15141153Swollman	driver_intr_t	*intr;
15241153Swollman	void		*arg;
15341153Swollman	void		**cookiep;
15441153Swollman};
15541153Swollman
15641153SwollmanMETHOD int teardown_intr {
15741153Swollman	device_t	dev;
15841153Swollman	device_t	child;
15941153Swollman	struct resource	*irq;
16041153Swollman	void		*cookie;
16141153Swollman};
162