bus_if.m revision 95201
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 95201 2002-04-21 11:16:10Z markm $ 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 { 8595201Smarkm device_t _dev; 8695201Smarkm device_t _child; 8795201Smarkm int _indx; 8895201Smarkm uintptr_t *_result; 8936973Sdfr}; 9036973Sdfr 9136973Sdfr# 9236973Sdfr# Write an instance variable. Return 0 on success. 9336973Sdfr# 9436973SdfrMETHOD int write_ivar { 9595201Smarkm device_t _dev; 9695201Smarkm device_t _child; 9795201Smarkm int _indx; 9895201Smarkm 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 { 10695201Smarkm device_t _dev; 10795201Smarkm 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 { 11695201Smarkm device_t _dev; 11795201Smarkm 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 { 12795201Smarkm device_t _dev; 12895201Smarkm int _order; 12995201Smarkm const char *_name; 13095201Smarkm 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 { 14895201Smarkm device_t _dev; 14995201Smarkm device_t _child; 15095201Smarkm int _type; 15195201Smarkm int *_rid; 15295201Smarkm u_long _start; 15395201Smarkm u_long _end; 15495201Smarkm u_long _count; 15595201Smarkm u_int _flags; 15646913Sdfr} DEFAULT null_alloc_resource; 15737592Sdfr 15841153SwollmanMETHOD int activate_resource { 15995201Smarkm device_t _dev; 16095201Smarkm device_t _child; 16195201Smarkm int _type; 16295201Smarkm int _rid; 16395201Smarkm struct resource *_r; 16441153Swollman}; 16541153Swollman 16641153SwollmanMETHOD int deactivate_resource { 16795201Smarkm device_t _dev; 16895201Smarkm device_t _child; 16995201Smarkm int _type; 17095201Smarkm int _rid; 17195201Smarkm 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 { 18095201Smarkm device_t _dev; 18195201Smarkm device_t _child; 18295201Smarkm int _type; 18395201Smarkm int _rid; 18495201Smarkm struct resource *_res; 18537592Sdfr}; 18641153Swollman 18741153SwollmanMETHOD int setup_intr { 18895201Smarkm device_t _dev; 18995201Smarkm device_t _child; 19095201Smarkm struct resource *_irq; 19195201Smarkm int _flags; 19295201Smarkm driver_intr_t *_intr; 19395201Smarkm void *_arg; 19495201Smarkm void **_cookiep; 19541153Swollman}; 19641153Swollman 19741153SwollmanMETHOD int teardown_intr { 19895201Smarkm device_t _dev; 19995201Smarkm device_t _child; 20095201Smarkm struct resource *_irq; 20195201Smarkm 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 { 20995201Smarkm device_t _dev; 21095201Smarkm device_t _child; 21195201Smarkm int _type; 21295201Smarkm int _rid; 21395201Smarkm u_long _start; 21495201Smarkm 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 { 22295201Smarkm device_t _dev; 22395201Smarkm device_t _child; 22495201Smarkm int _type; 22595201Smarkm int _rid; 22695201Smarkm u_long *_startp; 22795201Smarkm u_long *_countp; 22852174Sdfr}; 22952174Sdfr 23052174Sdfr# 23152174Sdfr# Delete a resource. 23252174Sdfr# 23352174SdfrMETHOD void delete_resource { 23495201Smarkm device_t _dev; 23595201Smarkm device_t _child; 23695201Smarkm int _type; 23795201Smarkm int _rid; 23852174Sdfr}; 23967278Smdodd 24067278Smdodd# 24167278Smdodd# Return a struct resource_list. 24267278Smdodd# 24369294SmdoddMETHOD struct resource_list * get_resource_list { 24495201Smarkm device_t _dev; 24595201Smarkm device_t _child; 24667278Smdodd} DEFAULT bus_generic_get_resource_list; 247