bus_if.m revision 47178
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# $Id: bus_if.m,v 1.9 1999/05/10 17:06:12 dfr Exp $ 27# 28 29INTERFACE bus; 30 31# 32# Default implementations of some methods. 33# 34CODE { 35 static struct resource * 36 null_alloc_resource(device_t dev, device_t child, 37 int type, int *rid, 38 u_long start, u_long end, 39 u_long count, u_int flags) 40 { 41 return 0; 42 } 43}; 44 45# 46# This is called from system code which prints out a description of a 47# device. It should describe the attachment that the child has with 48# the parent. For instance the TurboLaser bus prints which node the 49# device is attached to. 50# 51METHOD void print_child { 52 device_t dev; 53 device_t child; 54}; 55 56# 57# These two methods manage a bus specific set of instance variables of 58# a child device. The intention is that each different type of bus 59# defines a set of appropriate instance variables (such as ports and 60# irqs for ISA bus etc.) 61# 62# This information could be given to the child device as a struct but 63# that makes it hard for a bus to add or remove variables without 64# forcing an edit and recompile for all drivers which may not be 65# possible for vendor supplied binary drivers. 66 67# 68# Read an instance variable. Return 0 on success. 69# 70METHOD int read_ivar { 71 device_t dev; 72 device_t child; 73 int index; 74 uintptr_t *result; 75}; 76 77# 78# Write an instance variable. Return 0 on success. 79# 80METHOD int write_ivar { 81 device_t dev; 82 device_t child; 83 int index; 84 uintptr_t value; 85}; 86 87# 88# Called after the child's DEVICE_DETACH method to allow the parent 89# to reclaim any resources allocated on behalf of the child. 90# 91METHOD void child_detached { 92 device_t dev; 93 device_t child; 94}; 95 96# 97# Called when a new driver is added to the devclass which owns this 98# bus. The generic implementation of this method attempts to probe and 99# attach any un-matched children of the bus. 100# 101METHOD void driver_added { 102 device_t dev; 103 driver_t *driver; 104} 105 106# 107# For busses which use use drivers supporting DEVICE_IDENTIFY to 108# enumerate their devices, these methods are used to create new 109# device instances. If place is non-NULL, the new device will be 110# added after place in the list of devices. 111# 112METHOD device_t add_child { 113 device_t dev; 114 device_t place; 115 const char *name; 116 int unit; 117}; 118 119# 120# Allocate a system resource attached to `dev' on behalf of `child'. 121# The types are defined in <machine/resource.h>; the meaning of the 122# resource-ID field varies from bus to bus (but *rid == 0 is always 123# valid if the resource type is). start and end reflect the allowable 124# range, and should be passed as `0UL' and `~0UL', respectively, if 125# the client has no range restriction. count is the number of consecutive 126# indices in the resource required. flags is a set of sharing flags 127# as defined in <sys/rman.h>. 128# 129# Returns a resource or a null pointer on failure. The caller is 130# responsible for calling rman_activate_resource() when it actually 131# uses the resource. 132# 133METHOD struct resource * alloc_resource { 134 device_t dev; 135 device_t child; 136 int type; 137 int *rid; 138 u_long start; 139 u_long end; 140 u_long count; 141 u_int flags; 142} DEFAULT null_alloc_resource; 143 144METHOD int activate_resource { 145 device_t dev; 146 device_t child; 147 int type; 148 int rid; 149 struct resource *r; 150}; 151 152METHOD int deactivate_resource { 153 device_t dev; 154 device_t child; 155 int type; 156 int rid; 157 struct resource *r; 158}; 159 160# 161# Free a resource allocated by the preceding method. The `rid' value 162# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 163# is not necessarily the same as the one the client passed). 164# 165METHOD int release_resource { 166 device_t dev; 167 device_t child; 168 int type; 169 int rid; 170 struct resource *res; 171}; 172 173METHOD int setup_intr { 174 device_t dev; 175 device_t child; 176 struct resource *irq; 177 int flags; 178 driver_intr_t *intr; 179 void *arg; 180 void **cookiep; 181}; 182 183METHOD int teardown_intr { 184 device_t dev; 185 device_t child; 186 struct resource *irq; 187 void *cookie; 188}; 189