bus_if.m revision 59093
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# 2650477Speter# $FreeBSD: head/sys/kern/bus_if.m 59093 2000-04-08 14:17:18Z dfr $ 2736973Sdfr# 2836973Sdfr 2959093Sdfr#include <sys/bus.h> 3059093Sdfr 3141017SnsouchINTERFACE bus; 3236973Sdfr 3336973Sdfr# 3446913Sdfr# Default implementations of some methods. 3546913Sdfr# 3646913SdfrCODE { 3746913Sdfr static struct resource * 3846913Sdfr null_alloc_resource(device_t dev, device_t child, 3946913Sdfr int type, int *rid, 4046913Sdfr u_long start, u_long end, 4146913Sdfr u_long count, u_int flags) 4246913Sdfr { 4346913Sdfr return 0; 4446913Sdfr } 4546913Sdfr}; 4646913Sdfr 4746913Sdfr# 4836973Sdfr# This is called from system code which prints out a description of a 4936973Sdfr# device. It should describe the attachment that the child has with 5036973Sdfr# the parent. For instance the TurboLaser bus prints which node the 5149195Smdodd# device is attached to. See bus_generic_print_child.9 for more 5249195Smdodd# information. 5349195Smdodd# This method returns the number of characters output. 5436973Sdfr# 5549195SmdoddMETHOD int print_child { 5636973Sdfr device_t dev; 5736973Sdfr device_t child; 5836973Sdfr}; 5936973Sdfr 6048754Sdfr# 6148754Sdfr# Called for each child device that 6248754Sdfr# did not succeed in probing for a 6348754Sdfr# driver. 6448754Sdfr# 6548754SdfrMETHOD void probe_nomatch { 6648754Sdfr device_t dev; 6748754Sdfr device_t child; 6848754Sdfr}; 6948754Sdfr 7036973Sdfr# 7136973Sdfr# These two methods manage a bus specific set of instance variables of 7236973Sdfr# a child device. The intention is that each different type of bus 7336973Sdfr# defines a set of appropriate instance variables (such as ports and 7436973Sdfr# irqs for ISA bus etc.) 7536973Sdfr# 7636973Sdfr# This information could be given to the child device as a struct but 7736973Sdfr# that makes it hard for a bus to add or remove variables without 7836973Sdfr# forcing an edit and recompile for all drivers which may not be 7936973Sdfr# possible for vendor supplied binary drivers. 8036973Sdfr 8136973Sdfr# 8236973Sdfr# Read an instance variable. Return 0 on success. 8336973Sdfr# 8436973SdfrMETHOD int read_ivar { 8536973Sdfr device_t dev; 8636973Sdfr device_t child; 8736973Sdfr int index; 8841153Swollman uintptr_t *result; 8936973Sdfr}; 9036973Sdfr 9136973Sdfr# 9236973Sdfr# Write an instance variable. Return 0 on success. 9336973Sdfr# 9436973SdfrMETHOD int write_ivar { 9536973Sdfr device_t dev; 9636973Sdfr device_t child; 9736973Sdfr int index; 9841153Swollman uintptr_t value; 9936973Sdfr}; 10036973Sdfr 10136973Sdfr# 10245107Sdfr# Called after the child's DEVICE_DETACH method to allow the parent 10345107Sdfr# to reclaim any resources allocated on behalf of the child. 10445107Sdfr# 10545107SdfrMETHOD void child_detached { 10645107Sdfr device_t dev; 10745107Sdfr device_t child; 10845107Sdfr}; 10945107Sdfr 11045107Sdfr# 11145720Speter# Called when a new driver is added to the devclass which owns this 11245720Speter# bus. The generic implementation of this method attempts to probe and 11345720Speter# attach any un-matched children of the bus. 11445720Speter# 11545720SpeterMETHOD void driver_added { 11645720Speter device_t dev; 11745720Speter driver_t *driver; 11852045Simp} DEFAULT bus_generic_driver_added; 11945720Speter 12045720Speter# 12147178Sdfr# For busses which use use drivers supporting DEVICE_IDENTIFY to 12247178Sdfr# enumerate their devices, these methods are used to create new 12347178Sdfr# device instances. If place is non-NULL, the new device will be 12447578Sdfr# added after the last existing child with the same order. 12547178Sdfr# 12647178SdfrMETHOD device_t add_child { 12747178Sdfr device_t dev; 12847578Sdfr int order; 12947178Sdfr const char *name; 13047178Sdfr int unit; 13147178Sdfr}; 13247178Sdfr 13347178Sdfr# 13441153Swollman# Allocate a system resource attached to `dev' on behalf of `child'. 13541153Swollman# The types are defined in <machine/resource.h>; the meaning of the 13641153Swollman# resource-ID field varies from bus to bus (but *rid == 0 is always 13741153Swollman# valid if the resource type is). start and end reflect the allowable 13841153Swollman# range, and should be passed as `0UL' and `~0UL', respectively, if 13941153Swollman# the client has no range restriction. count is the number of consecutive 14041153Swollman# indices in the resource required. flags is a set of sharing flags 14141153Swollman# as defined in <sys/rman.h>. 14236973Sdfr# 14341153Swollman# Returns a resource or a null pointer on failure. The caller is 14441153Swollman# responsible for calling rman_activate_resource() when it actually 14541153Swollman# uses the resource. 14641153Swollman# 14741153SwollmanMETHOD struct resource * alloc_resource { 14841153Swollman device_t dev; 14941153Swollman device_t child; 15041153Swollman int type; 15141153Swollman int *rid; 15241153Swollman u_long start; 15341153Swollman u_long end; 15441153Swollman u_long count; 15541153Swollman u_int flags; 15646913Sdfr} DEFAULT null_alloc_resource; 15737592Sdfr 15841153SwollmanMETHOD int activate_resource { 15941153Swollman device_t dev; 16041153Swollman device_t child; 16141153Swollman int type; 16241153Swollman int rid; 16341153Swollman struct resource *r; 16441153Swollman}; 16541153Swollman 16641153SwollmanMETHOD int deactivate_resource { 16741153Swollman device_t dev; 16841153Swollman device_t child; 16941153Swollman int type; 17041153Swollman int rid; 17141153Swollman struct resource *r; 17241153Swollman}; 17341153Swollman 17439344Sdfr# 17541153Swollman# Free a resource allocated by the preceding method. The `rid' value 17641153Swollman# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 17741153Swollman# is not necessarily the same as the one the client passed). 17839344Sdfr# 17941153SwollmanMETHOD int release_resource { 18041153Swollman device_t dev; 18141153Swollman device_t child; 18241153Swollman int type; 18341153Swollman int rid; 18441153Swollman struct resource *res; 18537592Sdfr}; 18641153Swollman 18741153SwollmanMETHOD int setup_intr { 18841153Swollman device_t dev; 18941153Swollman device_t child; 19041153Swollman struct resource *irq; 19146743Sdfr int flags; 19241153Swollman driver_intr_t *intr; 19341153Swollman void *arg; 19441153Swollman void **cookiep; 19541153Swollman}; 19641153Swollman 19741153SwollmanMETHOD int teardown_intr { 19841153Swollman device_t dev; 19941153Swollman device_t child; 20041153Swollman struct resource *irq; 20141153Swollman void *cookie; 20241153Swollman}; 20352174Sdfr 20452174Sdfr# 20552174Sdfr# Set the range used for a particular resource. Return EINVAL if 20652174Sdfr# the type or rid are out of range. 20752174Sdfr# 20852174SdfrMETHOD int set_resource { 20952174Sdfr device_t dev; 21052174Sdfr device_t child; 21152174Sdfr int type; 21252174Sdfr int rid; 21352174Sdfr u_long start; 21452174Sdfr u_long count; 21552174Sdfr}; 21652174Sdfr 21752174Sdfr# 21852174Sdfr# Get the range for a resource. Return ENOENT if the type or rid are 21952174Sdfr# out of range or have not been set. 22052174Sdfr# 22152174SdfrMETHOD int get_resource { 22252174Sdfr device_t dev; 22352174Sdfr device_t child; 22452174Sdfr int type; 22552174Sdfr int rid; 22652174Sdfr u_long *startp; 22752174Sdfr u_long *countp; 22852174Sdfr}; 22952174Sdfr 23052174Sdfr# 23152174Sdfr# Delete a resource. 23252174Sdfr# 23352174SdfrMETHOD void delete_resource { 23452174Sdfr device_t dev; 23552174Sdfr device_t child; 23652174Sdfr int type; 23752174Sdfr int rid; 23852174Sdfr}; 239