bus_if.m revision 46913
122514Sdarrenr# 253024Sguido# Copyright (c) 1998 Doug Rabson 322514Sdarrenr# All rights reserved. 480490Sdarrenr# 522514Sdarrenr# Redistribution and use in source and binary forms, with or without 622514Sdarrenr# modification, are permitted provided that the following conditions 722514Sdarrenr# are met: 822514Sdarrenr# 1. Redistributions of source code must retain the above copyright 922514Sdarrenr# notice, this list of conditions and the following disclaimer. 1022514Sdarrenr# 2. Redistributions in binary form must reproduce the above copyright 1122514Sdarrenr# notice, this list of conditions and the following disclaimer in the 1222514Sdarrenr# documentation and/or other materials provided with the distribution. 1353024Sguido# 1453024Sguido# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1531183Speter# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1622514Sdarrenr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1753024Sguido# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1853024Sguido# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1953024Sguido# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2053024Sguido# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2153024Sguido# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2253024Sguido# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2353024Sguido# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2453024Sguido# SUCH DAMAGE. 2522514Sdarrenr# 2622514Sdarrenr# $Id: bus_if.m,v 1.8 1999/05/08 21:59:34 dfr Exp $ 2722514Sdarrenr# 2822514Sdarrenr 2931183SpeterINTERFACE bus; 3031183Speter 3131183Speter# 3231183Speter# Default implementations of some methods. 3331183Speter# 3431183SpeterCODE { 3526119Sdarrenr static struct resource * 3626119Sdarrenr null_alloc_resource(device_t dev, device_t child, 3726119Sdarrenr int type, int *rid, 3822514Sdarrenr u_long start, u_long end, 3922514Sdarrenr u_long count, u_int flags) 4022514Sdarrenr { 4122514Sdarrenr return 0; 4222514Sdarrenr } 4322514Sdarrenr}; 4431183Speter 4531183Speter# 4631183Speter# This is called from system code which prints out a description of a 4722514Sdarrenr# device. It should describe the attachment that the child has with 4822514Sdarrenr# the parent. For instance the TurboLaser bus prints which node the 4922514Sdarrenr# device is attached to. 5022514Sdarrenr# 5131183SpeterMETHOD void print_child { 5231183Speter device_t dev; 5331183Speter device_t child; 5431183Speter}; 5531183Speter 5631183Speter# 5731183Speter# These two methods manage a bus specific set of instance variables of 5831183Speter# a child device. The intention is that each different type of bus 5931183Speter# defines a set of appropriate instance variables (such as ports and 6022514Sdarrenr# irqs for ISA bus etc.) 6122514Sdarrenr# 6222514Sdarrenr# This information could be given to the child device as a struct but 6322514Sdarrenr# that makes it hard for a bus to add or remove variables without 6422514Sdarrenr# forcing an edit and recompile for all drivers which may not be 6522514Sdarrenr# possible for vendor supplied binary drivers. 6631183Speter 6731183Speter# 6831183Speter# Read an instance variable. Return 0 on success. 6931183Speter# 7031183SpeterMETHOD int read_ivar { 7131183Speter device_t dev; 7231183Speter device_t child; 7331183Speter int index; 7431183Speter uintptr_t *result; 7524583Sdarrenr}; 7622514Sdarrenr 7784843Sbde# 7880490Sdarrenr# Write an instance variable. Return 0 on success. 7980490Sdarrenr# 8084843SbdeMETHOD int write_ivar { 8180490Sdarrenr device_t dev; 8284843Sbde device_t child; 8324583Sdarrenr int index; 8484843Sbde uintptr_t value; 8580490Sdarrenr}; 8684843Sbde 8722514Sdarrenr# 8822514Sdarrenr# Called after the child's DEVICE_DETACH method to allow the parent 8922514Sdarrenr# to reclaim any resources allocated on behalf of the child. 9022514Sdarrenr# 9122514SdarrenrMETHOD void child_detached { 9222514Sdarrenr device_t dev; 9322514Sdarrenr device_t child; 9422514Sdarrenr}; 9522514Sdarrenr 9622514Sdarrenr# 9722514Sdarrenr# Called when a new driver is added to the devclass which owns this 9822514Sdarrenr# bus. The generic implementation of this method attempts to probe and 9922514Sdarrenr# attach any un-matched children of the bus. 10031183Speter# 10122514SdarrenrMETHOD void driver_added { 10222514Sdarrenr device_t dev; 10322514Sdarrenr driver_t *driver; 10422514Sdarrenr} 10522514Sdarrenr 10622514Sdarrenr# 10722514Sdarrenr# Allocate a system resource attached to `dev' on behalf of `child'. 10822514Sdarrenr# The types are defined in <machine/resource.h>; the meaning of the 10922514Sdarrenr# resource-ID field varies from bus to bus (but *rid == 0 is always 11037074Speter# valid if the resource type is). start and end reflect the allowable 11137074Speter# range, and should be passed as `0UL' and `~0UL', respectively, if 11222514Sdarrenr# the client has no range restriction. count is the number of consecutive 11337074Speter# indices in the resource required. flags is a set of sharing flags 11437074Speter# as defined in <sys/rman.h>. 11522514Sdarrenr# 11622514Sdarrenr# Returns a resource or a null pointer on failure. The caller is 11722514Sdarrenr# responsible for calling rman_activate_resource() when it actually 11822514Sdarrenr# uses the resource. 11922514Sdarrenr# 12022514SdarrenrMETHOD struct resource * alloc_resource { 12122514Sdarrenr device_t dev; 12222514Sdarrenr device_t child; 12322514Sdarrenr int type; 12437074Speter int *rid; 12522514Sdarrenr u_long start; 12622514Sdarrenr u_long end; 12722514Sdarrenr u_long count; 12822514Sdarrenr u_int flags; 12922514Sdarrenr} DEFAULT null_alloc_resource; 13022514Sdarrenr 13122514SdarrenrMETHOD int activate_resource { 13222514Sdarrenr device_t dev; 13322514Sdarrenr device_t child; 13422514Sdarrenr int type; 13522514Sdarrenr int rid; 13622514Sdarrenr struct resource *r; 13722514Sdarrenr}; 13822514Sdarrenr 13922514SdarrenrMETHOD int deactivate_resource { 14037074Speter device_t dev; 14122514Sdarrenr device_t child; 14222514Sdarrenr int type; 14322514Sdarrenr int rid; 14422514Sdarrenr struct resource *r; 14522514Sdarrenr}; 14622514Sdarrenr 14722514Sdarrenr# 14822514Sdarrenr# Free a resource allocated by the preceding method. The `rid' value 14922514Sdarrenr# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 15022514Sdarrenr# is not necessarily the same as the one the client passed). 15122514Sdarrenr# 15222514SdarrenrMETHOD int release_resource { 15322514Sdarrenr device_t dev; 15422514Sdarrenr device_t child; 15522514Sdarrenr int type; 15622514Sdarrenr int rid; 15722514Sdarrenr struct resource *res; 15822514Sdarrenr}; 15922514Sdarrenr 16022514SdarrenrMETHOD int setup_intr { 16122514Sdarrenr device_t dev; 16222514Sdarrenr device_t child; 16322514Sdarrenr struct resource *irq; 16422514Sdarrenr int flags; 16522514Sdarrenr driver_intr_t *intr; 16622514Sdarrenr void *arg; 16722514Sdarrenr void **cookiep; 16822514Sdarrenr}; 16922514Sdarrenr 17022514SdarrenrMETHOD int teardown_intr { 17122514Sdarrenr device_t dev; 17222514Sdarrenr device_t child; 17322514Sdarrenr struct resource *irq; 17422514Sdarrenr void *cookie; 17522514Sdarrenr}; 17622514Sdarrenr