1b1bf6610SDoug Rabson# 2b1bf6610SDoug Rabson# Copyright (c) 1998 Doug Rabson 3b1bf6610SDoug Rabson# All rights reserved. 4b1bf6610SDoug Rabson# 5b1bf6610SDoug Rabson# Redistribution and use in source and binary forms, with or without 6b1bf6610SDoug Rabson# modification, are permitted provided that the following conditions 7b1bf6610SDoug Rabson# are met: 8b1bf6610SDoug Rabson# 1. Redistributions of source code must retain the above copyright 9b1bf6610SDoug Rabson# notice, this list of conditions and the following disclaimer. 10b1bf6610SDoug Rabson# 2. Redistributions in binary form must reproduce the above copyright 11b1bf6610SDoug Rabson# notice, this list of conditions and the following disclaimer in the 12b1bf6610SDoug Rabson# documentation and/or other materials provided with the distribution. 13b1bf6610SDoug Rabson# 14b1bf6610SDoug Rabson# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15b1bf6610SDoug Rabson# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16b1bf6610SDoug Rabson# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17b1bf6610SDoug Rabson# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18b1bf6610SDoug Rabson# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19b1bf6610SDoug Rabson# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20b1bf6610SDoug Rabson# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21b1bf6610SDoug Rabson# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22b1bf6610SDoug Rabson# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23b1bf6610SDoug Rabson# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24b1bf6610SDoug Rabson# SUCH DAMAGE. 25b1bf6610SDoug Rabson# 26c3aac50fSPeter Wemm# $FreeBSD$ 27b1bf6610SDoug Rabson# 28b1bf6610SDoug Rabson 29f7b77691SDoug Rabson#include <sys/bus.h> 30f7b77691SDoug Rabson 3131a7daaeSNicolas SouchuINTERFACE bus; 32b1bf6610SDoug Rabson 33b1bf6610SDoug Rabson# 348b2970bbSDoug Rabson# Default implementations of some methods. 358b2970bbSDoug Rabson# 368b2970bbSDoug RabsonCODE { 378b2970bbSDoug Rabson static struct resource * 388b2970bbSDoug Rabson null_alloc_resource(device_t dev, device_t child, 398b2970bbSDoug Rabson int type, int *rid, 408b2970bbSDoug Rabson u_long start, u_long end, 418b2970bbSDoug Rabson u_long count, u_int flags) 428b2970bbSDoug Rabson { 438b2970bbSDoug Rabson return 0; 448b2970bbSDoug Rabson } 458b2970bbSDoug Rabson}; 468b2970bbSDoug Rabson 478b2970bbSDoug Rabson# 48b1bf6610SDoug Rabson# This is called from system code which prints out a description of a 49b1bf6610SDoug Rabson# device. It should describe the attachment that the child has with 50b1bf6610SDoug Rabson# the parent. For instance the TurboLaser bus prints which node the 5115317dd8SMatthew N. Dodd# device is attached to. See bus_generic_print_child.9 for more 5215317dd8SMatthew N. Dodd# information. 5315317dd8SMatthew N. Dodd# This method returns the number of characters output. 54b1bf6610SDoug Rabson# 5515317dd8SMatthew N. DoddMETHOD int print_child { 56b1bf6610SDoug Rabson device_t dev; 57b1bf6610SDoug Rabson device_t child; 58b1bf6610SDoug Rabson}; 59b1bf6610SDoug Rabson 60b1bf6610SDoug Rabson# 61ca7036d8SDoug Rabson# Called for each child device that 62ca7036d8SDoug Rabson# did not succeed in probing for a 63ca7036d8SDoug Rabson# driver. 64ca7036d8SDoug Rabson# 65ca7036d8SDoug RabsonMETHOD void probe_nomatch { 66ca7036d8SDoug Rabson device_t dev; 67ca7036d8SDoug Rabson device_t child; 68ca7036d8SDoug Rabson}; 69ca7036d8SDoug Rabson 70ca7036d8SDoug Rabson# 71b1bf6610SDoug Rabson# These two methods manage a bus specific set of instance variables of 72b1bf6610SDoug Rabson# a child device. The intention is that each different type of bus 73b1bf6610SDoug Rabson# defines a set of appropriate instance variables (such as ports and 74b1bf6610SDoug Rabson# irqs for ISA bus etc.) 75b1bf6610SDoug Rabson# 76b1bf6610SDoug Rabson# This information could be given to the child device as a struct but 77b1bf6610SDoug Rabson# that makes it hard for a bus to add or remove variables without 78b1bf6610SDoug Rabson# forcing an edit and recompile for all drivers which may not be 79b1bf6610SDoug Rabson# possible for vendor supplied binary drivers. 80b1bf6610SDoug Rabson 81b1bf6610SDoug Rabson# 82b1bf6610SDoug Rabson# Read an instance variable. Return 0 on success. 83b1bf6610SDoug Rabson# 84b1bf6610SDoug RabsonMETHOD int read_ivar { 85b1bf6610SDoug Rabson device_t dev; 86b1bf6610SDoug Rabson device_t child; 87b1bf6610SDoug Rabson int index; 8814177d72SGarrett Wollman uintptr_t *result; 89b1bf6610SDoug Rabson}; 90b1bf6610SDoug Rabson 91b1bf6610SDoug Rabson# 92b1bf6610SDoug Rabson# Write an instance variable. Return 0 on success. 93b1bf6610SDoug Rabson# 94b1bf6610SDoug RabsonMETHOD int write_ivar { 95b1bf6610SDoug Rabson device_t dev; 96b1bf6610SDoug Rabson device_t child; 97b1bf6610SDoug Rabson int index; 9814177d72SGarrett Wollman uintptr_t value; 99b1bf6610SDoug Rabson}; 100b1bf6610SDoug Rabson 101b1bf6610SDoug Rabson# 1026350e58aSDoug Rabson# Called after the child's DEVICE_DETACH method to allow the parent 1036350e58aSDoug Rabson# to reclaim any resources allocated on behalf of the child. 1046350e58aSDoug Rabson# 1056350e58aSDoug RabsonMETHOD void child_detached { 1066350e58aSDoug Rabson device_t dev; 1076350e58aSDoug Rabson device_t child; 1086350e58aSDoug Rabson}; 1096350e58aSDoug Rabson 1106350e58aSDoug Rabson# 1116182fdbdSPeter Wemm# Called when a new driver is added to the devclass which owns this 1126182fdbdSPeter Wemm# bus. The generic implementation of this method attempts to probe and 1136182fdbdSPeter Wemm# attach any un-matched children of the bus. 1146182fdbdSPeter Wemm# 1156182fdbdSPeter WemmMETHOD void driver_added { 1166182fdbdSPeter Wemm device_t dev; 1176182fdbdSPeter Wemm driver_t *driver; 1186d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added; 1196182fdbdSPeter Wemm 1206182fdbdSPeter Wemm# 1216c2e3ddeSDoug Rabson# For busses which use use drivers supporting DEVICE_IDENTIFY to 1226c2e3ddeSDoug Rabson# enumerate their devices, these methods are used to create new 1236c2e3ddeSDoug Rabson# device instances. If place is non-NULL, the new device will be 124bea6af4dSDoug Rabson# added after the last existing child with the same order. 1256c2e3ddeSDoug Rabson# 1266c2e3ddeSDoug RabsonMETHOD device_t add_child { 1276c2e3ddeSDoug Rabson device_t dev; 128bea6af4dSDoug Rabson int order; 1296c2e3ddeSDoug Rabson const char *name; 1306c2e3ddeSDoug Rabson int unit; 1316c2e3ddeSDoug Rabson}; 1326c2e3ddeSDoug Rabson 1336c2e3ddeSDoug Rabson# 13414177d72SGarrett Wollman# Allocate a system resource attached to `dev' on behalf of `child'. 13514177d72SGarrett Wollman# The types are defined in <machine/resource.h>; the meaning of the 13614177d72SGarrett Wollman# resource-ID field varies from bus to bus (but *rid == 0 is always 13714177d72SGarrett Wollman# valid if the resource type is). start and end reflect the allowable 13814177d72SGarrett Wollman# range, and should be passed as `0UL' and `~0UL', respectively, if 13914177d72SGarrett Wollman# the client has no range restriction. count is the number of consecutive 14014177d72SGarrett Wollman# indices in the resource required. flags is a set of sharing flags 14114177d72SGarrett Wollman# as defined in <sys/rman.h>. 142b1bf6610SDoug Rabson# 14314177d72SGarrett Wollman# Returns a resource or a null pointer on failure. The caller is 14414177d72SGarrett Wollman# responsible for calling rman_activate_resource() when it actually 14514177d72SGarrett Wollman# uses the resource. 14614177d72SGarrett Wollman# 14714177d72SGarrett WollmanMETHOD struct resource * alloc_resource { 148b1bf6610SDoug Rabson device_t dev; 149b1bf6610SDoug Rabson device_t child; 15014177d72SGarrett Wollman int type; 15114177d72SGarrett Wollman int *rid; 15214177d72SGarrett Wollman u_long start; 15314177d72SGarrett Wollman u_long end; 15414177d72SGarrett Wollman u_long count; 15514177d72SGarrett Wollman u_int flags; 1568b2970bbSDoug Rabson} DEFAULT null_alloc_resource; 15714177d72SGarrett Wollman 15814177d72SGarrett WollmanMETHOD int activate_resource { 15914177d72SGarrett Wollman device_t dev; 16014177d72SGarrett Wollman device_t child; 16114177d72SGarrett Wollman int type; 16214177d72SGarrett Wollman int rid; 16314177d72SGarrett Wollman struct resource *r; 16414177d72SGarrett Wollman}; 16514177d72SGarrett Wollman 16614177d72SGarrett WollmanMETHOD int deactivate_resource { 16714177d72SGarrett Wollman device_t dev; 16814177d72SGarrett Wollman device_t child; 16914177d72SGarrett Wollman int type; 17014177d72SGarrett Wollman int rid; 17114177d72SGarrett Wollman struct resource *r; 172b1bf6610SDoug Rabson}; 17345c95fa1SDoug Rabson 1746e4fb915SDoug Rabson# 17514177d72SGarrett Wollman# Free a resource allocated by the preceding method. The `rid' value 17614177d72SGarrett Wollman# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 17714177d72SGarrett Wollman# is not necessarily the same as the one the client passed). 1786e4fb915SDoug Rabson# 17914177d72SGarrett WollmanMETHOD int release_resource { 18045c95fa1SDoug Rabson device_t dev; 18114177d72SGarrett Wollman device_t child; 18214177d72SGarrett Wollman int type; 18314177d72SGarrett Wollman int rid; 18414177d72SGarrett Wollman struct resource *res; 18514177d72SGarrett Wollman}; 18614177d72SGarrett Wollman 18714177d72SGarrett WollmanMETHOD int setup_intr { 18814177d72SGarrett Wollman device_t dev; 18914177d72SGarrett Wollman device_t child; 19014177d72SGarrett Wollman struct resource *irq; 191566643e3SDoug Rabson int flags; 19214177d72SGarrett Wollman driver_intr_t *intr; 19314177d72SGarrett Wollman void *arg; 19414177d72SGarrett Wollman void **cookiep; 19514177d72SGarrett Wollman}; 19614177d72SGarrett Wollman 19714177d72SGarrett WollmanMETHOD int teardown_intr { 19814177d72SGarrett Wollman device_t dev; 19914177d72SGarrett Wollman device_t child; 20014177d72SGarrett Wollman struct resource *irq; 20114177d72SGarrett Wollman void *cookie; 20245c95fa1SDoug Rabson}; 20325afb89bSDoug Rabson 20425afb89bSDoug Rabson# 20525afb89bSDoug Rabson# Set the range used for a particular resource. Return EINVAL if 20625afb89bSDoug Rabson# the type or rid are out of range. 20725afb89bSDoug Rabson# 20825afb89bSDoug RabsonMETHOD int set_resource { 20925afb89bSDoug Rabson device_t dev; 21025afb89bSDoug Rabson device_t child; 21125afb89bSDoug Rabson int type; 21225afb89bSDoug Rabson int rid; 21325afb89bSDoug Rabson u_long start; 21425afb89bSDoug Rabson u_long count; 21525afb89bSDoug Rabson}; 21625afb89bSDoug Rabson 21725afb89bSDoug Rabson# 21825afb89bSDoug Rabson# Get the range for a resource. Return ENOENT if the type or rid are 21925afb89bSDoug Rabson# out of range or have not been set. 22025afb89bSDoug Rabson# 22125afb89bSDoug RabsonMETHOD int get_resource { 22225afb89bSDoug Rabson device_t dev; 22325afb89bSDoug Rabson device_t child; 22425afb89bSDoug Rabson int type; 22525afb89bSDoug Rabson int rid; 22625afb89bSDoug Rabson u_long *startp; 22725afb89bSDoug Rabson u_long *countp; 22825afb89bSDoug Rabson}; 22925afb89bSDoug Rabson 23025afb89bSDoug Rabson# 23125afb89bSDoug Rabson# Delete a resource. 23225afb89bSDoug Rabson# 23325afb89bSDoug RabsonMETHOD void delete_resource { 23425afb89bSDoug Rabson device_t dev; 23525afb89bSDoug Rabson device_t child; 23625afb89bSDoug Rabson int type; 23725afb89bSDoug Rabson int rid; 23825afb89bSDoug Rabson}; 239