1# 2# Copyright (c) 1998 Doug Rabson 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24# SUCH DAMAGE. 25# 26# $FreeBSD$ 27# 28 29#include <sys/bus.h> 30 31INTERFACE bus; 32 33# 34# Default implementations of some methods. 35# 36CODE { 37 static struct resource * 38 null_alloc_resource(device_t dev, device_t child, 39 int type, int *rid, 40 u_long start, u_long end, 41 u_long count, u_int flags) 42 { 43 return 0; 44 } 45}; 46 47# 48# This is called from system code which prints out a description of a 49# device. It should describe the attachment that the child has with 50# the parent. For instance the TurboLaser bus prints which node the 51# device is attached to. See bus_generic_print_child.9 for more 52# information. 53# This method returns the number of characters output. 54# 55METHOD int print_child { 56 device_t dev; 57 device_t child; 58}; 59 60# 61# Called for each child device that 62# did not succeed in probing for a 63# driver. 64# 65METHOD void probe_nomatch { 66 device_t dev; 67 device_t child; 68}; 69 70# 71# These two methods manage a bus specific set of instance variables of 72# a child device. The intention is that each different type of bus 73# defines a set of appropriate instance variables (such as ports and 74# irqs for ISA bus etc.) 75# 76# This information could be given to the child device as a struct but 77# that makes it hard for a bus to add or remove variables without 78# forcing an edit and recompile for all drivers which may not be 79# possible for vendor supplied binary drivers. 80 81# 82# Read an instance variable. Return 0 on success. 83# 84METHOD int read_ivar { 85 device_t dev; 86 device_t child; 87 int index; 88 uintptr_t *result; 89}; 90 91# 92# Write an instance variable. Return 0 on success. 93# 94METHOD int write_ivar { 95 device_t dev; 96 device_t child; 97 int index; 98 uintptr_t value; 99}; 100 101# 102# Called after the child's DEVICE_DETACH method to allow the parent 103# to reclaim any resources allocated on behalf of the child. 104# 105METHOD void child_detached { 106 device_t dev; 107 device_t child; 108}; 109 110# 111# Called when a new driver is added to the devclass which owns this 112# bus. The generic implementation of this method attempts to probe and 113# attach any un-matched children of the bus. 114# 115METHOD void driver_added { 116 device_t dev; 117 driver_t *driver; 118} DEFAULT bus_generic_driver_added; 119 120# 121# For busses which use use drivers supporting DEVICE_IDENTIFY to 122# enumerate their devices, these methods are used to create new 123# device instances. If place is non-NULL, the new device will be 124# added after the last existing child with the same order. 125# 126METHOD device_t add_child { 127 device_t dev; 128 int order; 129 const char *name; 130 int unit; 131}; 132 133# 134# Allocate a system resource attached to `dev' on behalf of `child'. 135# The types are defined in <machine/resource.h>; the meaning of the 136# resource-ID field varies from bus to bus (but *rid == 0 is always 137# valid if the resource type is). start and end reflect the allowable 138# range, and should be passed as `0UL' and `~0UL', respectively, if 139# the client has no range restriction. count is the number of consecutive 140# indices in the resource required. flags is a set of sharing flags 141# as defined in <sys/rman.h>. 142# 143# Returns a resource or a null pointer on failure. The caller is 144# responsible for calling rman_activate_resource() when it actually 145# uses the resource. 146# 147METHOD struct resource * alloc_resource { 148 device_t dev; 149 device_t child; 150 int type; 151 int *rid; 152 u_long start; 153 u_long end; 154 u_long count; 155 u_int flags; 156} DEFAULT null_alloc_resource; 157 158METHOD int activate_resource { 159 device_t dev; 160 device_t child; 161 int type; 162 int rid; 163 struct resource *r; 164}; 165 166METHOD int deactivate_resource { 167 device_t dev; 168 device_t child; 169 int type; 170 int rid; 171 struct resource *r; 172}; 173 174# 175# Free a resource allocated by the preceding method. The `rid' value 176# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 177# is not necessarily the same as the one the client passed). 178# 179METHOD int release_resource { 180 device_t dev; 181 device_t child; 182 int type; 183 int rid; 184 struct resource *res; 185}; 186 187METHOD int setup_intr { 188 device_t dev; 189 device_t child; 190 struct resource *irq; 191 int flags; 192 driver_intr_t *intr; 193 void *arg; 194 void **cookiep; 195}; 196 197METHOD int teardown_intr { 198 device_t dev; 199 device_t child; 200 struct resource *irq; 201 void *cookie; 202}; 203 204# 205# Set the range used for a particular resource. Return EINVAL if 206# the type or rid are out of range. 207# 208METHOD int set_resource { 209 device_t dev; 210 device_t child; 211 int type; 212 int rid; 213 u_long start; 214 u_long count; 215}; 216 217# 218# Get the range for a resource. Return ENOENT if the type or rid are 219# out of range or have not been set. 220# 221METHOD int get_resource { 222 device_t dev; 223 device_t child; 224 int type; 225 int rid; 226 u_long *startp; 227 u_long *countp; 228}; 229 230# 231# Delete a resource. 232# 233METHOD void delete_resource { 234 device_t dev; 235 device_t child; 236 int type; 237 int rid; 238}; 239 240# 241# Return a struct resource_list. 242# 243METHOD struct resource_list * get_resource_list { 244 device_t dev; 245 device_t child; 246} DEFAULT bus_generic_get_resource_list; 247