bus_if.m revision 48754
16059Samurai# 26059Samurai# Copyright (c) 1998 Doug Rabson 36059Samurai# All rights reserved. 46059Samurai# 56059Samurai# Redistribution and use in source and binary forms, with or without 66059Samurai# modification, are permitted provided that the following conditions 76059Samurai# are met: 86059Samurai# 1. Redistributions of source code must retain the above copyright 96059Samurai# notice, this list of conditions and the following disclaimer. 106059Samurai# 2. Redistributions in binary form must reproduce the above copyright 116059Samurai# notice, this list of conditions and the following disclaimer in the 126059Samurai# documentation and/or other materials provided with the distribution. 136059Samurai# 146059Samurai# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 156059Samurai# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 166059Samurai# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 176059Samurai# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 186059Samurai# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 196059Samurai# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2037007Sbrian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218857Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 226059Samurai# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 236059Samurai# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2436285Sbrian# SUCH DAMAGE. 2536452Sbrian# 2630715Sbrian# $Id: bus_if.m,v 1.11 1999/05/28 09:25:08 dfr Exp $ 2730715Sbrian# 2830715Sbrian 2930715SbrianINTERFACE bus; 3036285Sbrian 3136285Sbrian# 3230715Sbrian# Default implementations of some methods. 3330715Sbrian# 346059SamuraiCODE { 3511336Samurai static struct resource * 3630715Sbrian null_alloc_resource(device_t dev, device_t child, 3730715Sbrian int type, int *rid, 3830715Sbrian u_long start, u_long end, 396059Samurai u_long count, u_int flags) 406059Samurai { 4118786Sjkh return 0; 4230715Sbrian } 4330715Sbrian}; 4430715Sbrian 4530715Sbrian# 4631061Sbrian# This is called from system code which prints out a description of a 4730715Sbrian# device. It should describe the attachment that the child has with 4830715Sbrian# the parent. For instance the TurboLaser bus prints which node the 4936285Sbrian# device is attached to. 506059Samurai# 5131514SbrianMETHOD void print_child { 5213389Sphk device_t dev; 5336285Sbrian device_t child; 5436285Sbrian}; 5536285Sbrian 566059Samurai# 5736285Sbrian# Called for each child device that 5836285Sbrian# did not succeed in probing for a 5936285Sbrian# driver. 6036285Sbrian# 6136285SbrianMETHOD void probe_nomatch { 6226142Sbrian device_t dev; 636735Samurai device_t child; 6413389Sphk}; 6513389Sphk 6623840Sbrian# 6730715Sbrian# These two methods manage a bus specific set of instance variables of 6831195Sbrian# a child device. The intention is that each different type of bus 6936285Sbrian# defines a set of appropriate instance variables (such as ports and 7036285Sbrian# irqs for ISA bus etc.) 7136285Sbrian# 7236285Sbrian# This information could be given to the child device as a struct but 7336285Sbrian# that makes it hard for a bus to add or remove variables without 746059Samurai# forcing an edit and recompile for all drivers which may not be 756735Samurai# possible for vendor supplied binary drivers. 766735Samurai 776735Samurai# 786735Samurai# Read an instance variable. Return 0 on success. 796735Samurai# 806735SamuraiMETHOD int read_ivar { 8136431Sbrian device_t dev; 8230715Sbrian device_t child; 8331343Sbrian int index; 8430715Sbrian uintptr_t *result; 8536285Sbrian}; 8636285Sbrian 876059Samurai# 8810528Samurai# Write an instance variable. Return 0 on success. 8936285Sbrian# 906059SamuraiMETHOD int write_ivar { 9136285Sbrian device_t dev; 9236285Sbrian device_t child; 9337007Sbrian int index; 946059Samurai uintptr_t value; 956059Samurai}; 966059Samurai 9736285Sbrian# 986059Samurai# Called after the child's DEVICE_DETACH method to allow the parent 9936285Sbrian# to reclaim any resources allocated on behalf of the child. 10036285Sbrian# 10137007SbrianMETHOD void child_detached { 10236285Sbrian device_t dev; 10336285Sbrian device_t child; 1046059Samurai}; 1056059Samurai 1066059Samurai# 1076059Samurai# Called when a new driver is added to the devclass which owns this 10828679Sbrian# bus. The generic implementation of this method attempts to probe and 1096059Samurai# attach any un-matched children of the bus. 11026858Sbrian# 11136285SbrianMETHOD void driver_added { 11236285Sbrian device_t dev; 11336285Sbrian driver_t *driver; 11436285Sbrian} 1156059Samurai 1166059Samurai# 1176059Samurai# For busses which use use drivers supporting DEVICE_IDENTIFY to 11828679Sbrian# enumerate their devices, these methods are used to create new 1196059Samurai# device instances. If place is non-NULL, the new device will be 12036285Sbrian# added after the last existing child with the same order. 12128679Sbrian# 1226059SamuraiMETHOD device_t add_child { 1236059Samurai device_t dev; 12436285Sbrian int order; 12536285Sbrian const char *name; 12610528Samurai int unit; 12736285Sbrian}; 12810528Samurai 12936285Sbrian# 13036285Sbrian# Allocate a system resource attached to `dev' on behalf of `child'. 13110528Samurai# The types are defined in <machine/resource.h>; the meaning of the 13210528Samurai# resource-ID field varies from bus to bus (but *rid == 0 is always 13310528Samurai# valid if the resource type is). start and end reflect the allowable 13436285Sbrian# range, and should be passed as `0UL' and `~0UL', respectively, if 13510528Samurai# the client has no range restriction. count is the number of consecutive 13636285Sbrian# indices in the resource required. flags is a set of sharing flags 13736285Sbrian# as defined in <sys/rman.h>. 13810528Samurai# 13910528Samurai# Returns a resource or a null pointer on failure. The caller is 14026940Sbrian# responsible for calling rman_activate_resource() when it actually 14136285Sbrian# uses the resource. 14226940Sbrian# 14336285SbrianMETHOD struct resource * alloc_resource { 14436285Sbrian device_t dev; 14536285Sbrian device_t child; 14626940Sbrian int type; 14726940Sbrian int *rid; 14831081Sbrian u_long start; 14931081Sbrian u_long end; 15031081Sbrian u_long count; 15136285Sbrian u_int flags; 15236285Sbrian} DEFAULT null_alloc_resource; 15331081Sbrian 15431081SbrianMETHOD int activate_resource { 15531343Sbrian device_t dev; 15625908Sbrian device_t child; 15725908Sbrian int type; 15825908Sbrian int rid; 15931343Sbrian struct resource *r; 16031343Sbrian}; 16131343Sbrian 16231343SbrianMETHOD int deactivate_resource { 16310528Samurai device_t dev; 16431962Sbrian device_t child; 16525908Sbrian int type; 16625908Sbrian int rid; 16725908Sbrian struct resource *r; 16825908Sbrian}; 16925908Sbrian 17030715Sbrian# 17131343Sbrian# Free a resource allocated by the preceding method. The `rid' value 1726059Samurai# must be the same as the one returned by BUS_ALLOC_RESOURCE (which 17320120Snate# is not necessarily the same as the one the client passed). 17431343Sbrian# 17531343SbrianMETHOD int release_resource { 17631343Sbrian device_t dev; 17731343Sbrian device_t child; 17831343Sbrian int type; 1796059Samurai int rid; 1806059Samurai struct resource *res; 1816059Samurai}; 18231197Sbrian 18336285SbrianMETHOD int setup_intr { 1846059Samurai device_t dev; 18536465Sbrian device_t child; 1866059Samurai struct resource *irq; 1876059Samurai int flags; 18836285Sbrian driver_intr_t *intr; 18936465Sbrian void *arg; 1906059Samurai void **cookiep; 1916059Samurai}; 19236465Sbrian 19336465SbrianMETHOD int teardown_intr { 19436465Sbrian device_t dev; 19536465Sbrian device_t child; 19631343Sbrian struct resource *irq; 19736465Sbrian void *cookie; 19836285Sbrian}; 19936465Sbrian