19454b2d8SWarner Losh#- 29f7f340aSWarner Losh# Copyright (c) 1998-2004 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 314c4392e7SDoug Rabson/** 324c4392e7SDoug Rabson * @defgroup BUS bus - KObj methods for drivers of devices with children 334c4392e7SDoug Rabson * @brief A set of methods required device drivers that support 344c4392e7SDoug Rabson * child devices. 354c4392e7SDoug Rabson * @{ 364c4392e7SDoug Rabson */ 3731a7daaeSNicolas SouchuINTERFACE bus; 38b1bf6610SDoug Rabson 39b1bf6610SDoug Rabson# 408b2970bbSDoug Rabson# Default implementations of some methods. 418b2970bbSDoug Rabson# 428b2970bbSDoug RabsonCODE { 438b2970bbSDoug Rabson static struct resource * 448b2970bbSDoug Rabson null_alloc_resource(device_t dev, device_t child, 455878eb3fSWarner Losh int type, int *rid, u_long start, u_long end, 468b2970bbSDoug Rabson u_long count, u_int flags) 478b2970bbSDoug Rabson { 485878eb3fSWarner Losh return (0); 498b2970bbSDoug Rabson } 5093fc07b4SAlexander Motin 5193fc07b4SAlexander Motin static int 5293fc07b4SAlexander Motin null_remap_intr(device_t bus, device_t dev, u_int irq) 5393fc07b4SAlexander Motin { 5493fc07b4SAlexander Motin 5593fc07b4SAlexander Motin if (dev != NULL) 5693fc07b4SAlexander Motin return (BUS_REMAP_INTR(dev, NULL, irq)); 5793fc07b4SAlexander Motin return (ENXIO); 5893fc07b4SAlexander Motin } 598b2970bbSDoug Rabson}; 608b2970bbSDoug Rabson 614c4392e7SDoug Rabson/** 624c4392e7SDoug Rabson * @brief Print a description of a child device 634c4392e7SDoug Rabson * 644c4392e7SDoug Rabson * This is called from system code which prints out a description of a 654c4392e7SDoug Rabson * device. It should describe the attachment that the child has with 664c4392e7SDoug Rabson * the parent. For instance the TurboLaser bus prints which node the 674c4392e7SDoug Rabson * device is attached to. See bus_generic_print_child() for more 684c4392e7SDoug Rabson * information. 694c4392e7SDoug Rabson * 704c4392e7SDoug Rabson * @param _dev the device whose child is being printed 714c4392e7SDoug Rabson * @param _child the child device to describe 724c4392e7SDoug Rabson * 734c4392e7SDoug Rabson * @returns the number of characters output. 744c4392e7SDoug Rabson */ 7515317dd8SMatthew N. DoddMETHOD int print_child { 764c4392e7SDoug Rabson device_t _dev; 774c4392e7SDoug Rabson device_t _child; 78c8440669SMatthew N. Dodd} DEFAULT bus_generic_print_child; 79b1bf6610SDoug Rabson 804c4392e7SDoug Rabson/** 814c4392e7SDoug Rabson * @brief Print a notification about an unprobed child device. 824c4392e7SDoug Rabson * 834c4392e7SDoug Rabson * Called for each child device that did not succeed in probing for a 844c4392e7SDoug Rabson * driver. 854c4392e7SDoug Rabson * 864c4392e7SDoug Rabson * @param _dev the device whose child was being probed 874c4392e7SDoug Rabson * @param _child the child device which failed to probe 884c4392e7SDoug Rabson */ 89ca7036d8SDoug RabsonMETHOD void probe_nomatch { 904c4392e7SDoug Rabson device_t _dev; 914c4392e7SDoug Rabson device_t _child; 92ca7036d8SDoug Rabson}; 93ca7036d8SDoug Rabson 944c4392e7SDoug Rabson/** 954c4392e7SDoug Rabson * @brief Read the value of a bus-specific attribute of a device 964c4392e7SDoug Rabson * 974c4392e7SDoug Rabson * This method, along with BUS_WRITE_IVAR() manages a bus-specific set 984c4392e7SDoug Rabson * of instance variables of a child device. The intention is that 994c4392e7SDoug Rabson * each different type of bus defines a set of appropriate instance 1004c4392e7SDoug Rabson * variables (such as ports and irqs for ISA bus etc.) 1014c4392e7SDoug Rabson * 1024c4392e7SDoug Rabson * This information could be given to the child device as a struct but 1034c4392e7SDoug Rabson * that makes it hard for a bus to add or remove variables without 1044c4392e7SDoug Rabson * forcing an edit and recompile for all drivers which may not be 1054c4392e7SDoug Rabson * possible for vendor supplied binary drivers. 1064c4392e7SDoug Rabson * 1074c4392e7SDoug Rabson * This method copies the value of an instance variable to the 1084c4392e7SDoug Rabson * location specified by @p *_result. 1094c4392e7SDoug Rabson * 1104c4392e7SDoug Rabson * @param _dev the device whose child was being examined 1114c4392e7SDoug Rabson * @param _child the child device whose instance variable is 1124c4392e7SDoug Rabson * being read 1134c4392e7SDoug Rabson * @param _index the instance variable to read 1144c4392e7SDoug Rabson * @param _result a loction to recieve the instance variable 1154c4392e7SDoug Rabson * value 1164c4392e7SDoug Rabson * 1174c4392e7SDoug Rabson * @retval 0 success 1184c4392e7SDoug Rabson * @retval ENOENT no such instance variable is supported by @p 1194c4392e7SDoug Rabson * _dev 1204c4392e7SDoug Rabson */ 121b1bf6610SDoug RabsonMETHOD int read_ivar { 122bd418641SMark Murray device_t _dev; 123bd418641SMark Murray device_t _child; 1244c4392e7SDoug Rabson int _index; 125bd418641SMark Murray uintptr_t *_result; 126b1bf6610SDoug Rabson}; 127b1bf6610SDoug Rabson 1284c4392e7SDoug Rabson/** 1294c4392e7SDoug Rabson * @brief Write the value of a bus-specific attribute of a device 1304c4392e7SDoug Rabson * 1314c4392e7SDoug Rabson * This method sets the value of an instance variable to @p _value. 1324c4392e7SDoug Rabson * 1334c4392e7SDoug Rabson * @param _dev the device whose child was being updated 1344c4392e7SDoug Rabson * @param _child the child device whose instance variable is 1354c4392e7SDoug Rabson * being written 1364c4392e7SDoug Rabson * @param _index the instance variable to write 1374c4392e7SDoug Rabson * @param _value the value to write to that instance variable 1384c4392e7SDoug Rabson * 1394c4392e7SDoug Rabson * @retval 0 success 1404c4392e7SDoug Rabson * @retval ENOENT no such instance variable is supported by @p 1414c4392e7SDoug Rabson * _dev 1424c4392e7SDoug Rabson * @retval EINVAL the instance variable was recognised but 1434c4392e7SDoug Rabson * contains a read-only value 1444c4392e7SDoug Rabson */ 145b1bf6610SDoug RabsonMETHOD int write_ivar { 146bd418641SMark Murray device_t _dev; 147bd418641SMark Murray device_t _child; 148bd418641SMark Murray int _indx; 149bd418641SMark Murray uintptr_t _value; 150b1bf6610SDoug Rabson}; 151b1bf6610SDoug Rabson 1524c4392e7SDoug Rabson/** 1534c4392e7SDoug Rabson * @brief Notify a bus that a child was detached 1544c4392e7SDoug Rabson * 1554c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent 1564c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child. 1574c4392e7SDoug Rabson * 1584c4392e7SDoug Rabson * @param _dev the device whose child changed state 1594c4392e7SDoug Rabson * @param _child the child device which changed state 1604c4392e7SDoug Rabson */ 1616350e58aSDoug RabsonMETHOD void child_detached { 162bd418641SMark Murray device_t _dev; 163bd418641SMark Murray device_t _child; 1646350e58aSDoug Rabson}; 1656350e58aSDoug Rabson 1664c4392e7SDoug Rabson/** 1674c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added 1684c4392e7SDoug Rabson * 1694c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this 1704c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and 1714c4392e7SDoug Rabson * attach any un-matched children of the bus. 1724c4392e7SDoug Rabson * 1734c4392e7SDoug Rabson * @param _dev the device whose devclass had a new driver 1744c4392e7SDoug Rabson * added to it 1754c4392e7SDoug Rabson * @param _driver the new driver which was added 1764c4392e7SDoug Rabson */ 1776182fdbdSPeter WemmMETHOD void driver_added { 178bd418641SMark Murray device_t _dev; 179bd418641SMark Murray driver_t *_driver; 1806d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added; 1816182fdbdSPeter Wemm 1824c4392e7SDoug Rabson/** 1834c4392e7SDoug Rabson * @brief Create a new child device 1844c4392e7SDoug Rabson * 1854c4392e7SDoug Rabson * For busses which use use drivers supporting DEVICE_IDENTIFY() to 1864c4392e7SDoug Rabson * enumerate their devices, this method is used to create new 1874c4392e7SDoug Rabson * device instances. The new device will be added after the last 1884c4392e7SDoug Rabson * existing child with the same order. 1894c4392e7SDoug Rabson * 1904c4392e7SDoug Rabson * @param _dev the bus device which will be the parent of the 1914c4392e7SDoug Rabson * new child device 1924c4392e7SDoug Rabson * @param _order a value which is used to partially sort the 1934c4392e7SDoug Rabson * children of @p _dev - devices created using 1944c4392e7SDoug Rabson * lower values of @p _order appear first in @p 1954c4392e7SDoug Rabson * _dev's list of children 1964c4392e7SDoug Rabson * @param _name devclass name for new device or @c NULL if not 1974c4392e7SDoug Rabson * specified 1984c4392e7SDoug Rabson * @param _unit unit number for new device or @c -1 if not 1994c4392e7SDoug Rabson * specified 2004c4392e7SDoug Rabson */ 2016c2e3ddeSDoug RabsonMETHOD device_t add_child { 202bd418641SMark Murray device_t _dev; 203*3d844eddSAndriy Gapon u_int _order; 204bd418641SMark Murray const char *_name; 205bd418641SMark Murray int _unit; 2063bb00f61SJohn Baldwin}; 2076c2e3ddeSDoug Rabson 2084c4392e7SDoug Rabson/** 2094c4392e7SDoug Rabson * @brief Allocate a system resource 2104c4392e7SDoug Rabson * 2114c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources. 2124c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the 2134c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always 2144c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the 2154c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be 2164c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling 2174c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource. 2184c4392e7SDoug Rabson * 2194c4392e7SDoug Rabson * @param _dev the parent device of @p _child 2204c4392e7SDoug Rabson * @param _child the device which is requesting an allocation 2214c4392e7SDoug Rabson * @param _type the type of resource to allocate 2224c4392e7SDoug Rabson * @param _rid a pointer to the resource identifier 2234c4392e7SDoug Rabson * @param _start hint at the start of the resource range - pass 2244c4392e7SDoug Rabson * @c 0UL for any start address 2254c4392e7SDoug Rabson * @param _end hint at the end of the resource range - pass 2264c4392e7SDoug Rabson * @c ~0UL for any end address 2274c4392e7SDoug Rabson * @param _count hint at the size of range required - pass @c 1 2284c4392e7SDoug Rabson * for any size 2294c4392e7SDoug Rabson * @param _flags any extra flags to control the resource 2304c4392e7SDoug Rabson * allocation - see @c RF_XXX flags in 2314c4392e7SDoug Rabson * <sys/rman.h> for details 2324c4392e7SDoug Rabson * 2334c4392e7SDoug Rabson * @returns the resource which was allocated or @c NULL if no 2344c4392e7SDoug Rabson * resource could be allocated 2354c4392e7SDoug Rabson */ 23614177d72SGarrett WollmanMETHOD struct resource * alloc_resource { 237bd418641SMark Murray device_t _dev; 238bd418641SMark Murray device_t _child; 239bd418641SMark Murray int _type; 240bd418641SMark Murray int *_rid; 241bd418641SMark Murray u_long _start; 242bd418641SMark Murray u_long _end; 243bd418641SMark Murray u_long _count; 244bd418641SMark Murray u_int _flags; 2458b2970bbSDoug Rabson} DEFAULT null_alloc_resource; 24614177d72SGarrett Wollman 2474c4392e7SDoug Rabson/** 2484c4392e7SDoug Rabson * @brief Activate a resource 2494c4392e7SDoug Rabson * 2504c4392e7SDoug Rabson * Activate a resource previously allocated with 2514c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance map a memory region 2524c4392e7SDoug Rabson * into the kernel's virtual address space. 2534c4392e7SDoug Rabson * 2544c4392e7SDoug Rabson * @param _dev the parent device of @p _child 2554c4392e7SDoug Rabson * @param _child the device which allocated the resource 2564c4392e7SDoug Rabson * @param _type the type of resource 2574c4392e7SDoug Rabson * @param _rid the resource identifier 2584c4392e7SDoug Rabson * @param _r the resource to activate 2594c4392e7SDoug Rabson */ 26014177d72SGarrett WollmanMETHOD int activate_resource { 261bd418641SMark Murray device_t _dev; 262bd418641SMark Murray device_t _child; 263bd418641SMark Murray int _type; 264bd418641SMark Murray int _rid; 265bd418641SMark Murray struct resource *_r; 26614177d72SGarrett Wollman}; 26714177d72SGarrett Wollman 2684c4392e7SDoug Rabson/** 2694c4392e7SDoug Rabson * @brief Deactivate a resource 2704c4392e7SDoug Rabson * 2714c4392e7SDoug Rabson * Deactivate a resource previously allocated with 2724c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region 2734c4392e7SDoug Rabson * from the kernel's virtual address space. 2744c4392e7SDoug Rabson * 2754c4392e7SDoug Rabson * @param _dev the parent device of @p _child 2764c4392e7SDoug Rabson * @param _child the device which allocated the resource 2774c4392e7SDoug Rabson * @param _type the type of resource 2784c4392e7SDoug Rabson * @param _rid the resource identifier 2794c4392e7SDoug Rabson * @param _r the resource to deactivate 2804c4392e7SDoug Rabson */ 28114177d72SGarrett WollmanMETHOD int deactivate_resource { 282bd418641SMark Murray device_t _dev; 283bd418641SMark Murray device_t _child; 284bd418641SMark Murray int _type; 285bd418641SMark Murray int _rid; 286bd418641SMark Murray struct resource *_r; 287b1bf6610SDoug Rabson}; 28845c95fa1SDoug Rabson 2894c4392e7SDoug Rabson/** 2904c4392e7SDoug Rabson * @brief Release a resource 2914c4392e7SDoug Rabson * 2924c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE. The @p _rid 2934c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE() 2944c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed). 2954c4392e7SDoug Rabson * 2964c4392e7SDoug Rabson * @param _dev the parent device of @p _child 2974c4392e7SDoug Rabson * @param _child the device which allocated the resource 2984c4392e7SDoug Rabson * @param _type the type of resource 2994c4392e7SDoug Rabson * @param _rid the resource identifier 3004c4392e7SDoug Rabson * @param _r the resource to release 3014c4392e7SDoug Rabson */ 30214177d72SGarrett WollmanMETHOD int release_resource { 303bd418641SMark Murray device_t _dev; 304bd418641SMark Murray device_t _child; 305bd418641SMark Murray int _type; 306bd418641SMark Murray int _rid; 307bd418641SMark Murray struct resource *_res; 30814177d72SGarrett Wollman}; 30914177d72SGarrett Wollman 3104c4392e7SDoug Rabson/** 3114c4392e7SDoug Rabson * @brief Install an interrupt handler 3124c4392e7SDoug Rabson * 3134c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with 3144c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr 3154c4392e7SDoug Rabson * will be called with the value of @p _arg as its single 3164c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the 3174c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a 3184c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR(). 3194c4392e7SDoug Rabson * 3204c4392e7SDoug Rabson * @param _dev the parent device of @p _child 3214c4392e7SDoug Rabson * @param _child the device which allocated the resource 3224c4392e7SDoug Rabson * @param _irq the resource representing the interrupt 3234c4392e7SDoug Rabson * @param _flags a set of bits from enum intr_type specifying 3244c4392e7SDoug Rabson * the class of interrupt 3254c4392e7SDoug Rabson * @param _intr the function to call when the interrupt 3264c4392e7SDoug Rabson * triggers 3274c4392e7SDoug Rabson * @param _arg a value to use as the single argument in calls 3284c4392e7SDoug Rabson * to @p _intr 3294c4392e7SDoug Rabson * @param _cookiep a pointer to a location to recieve a cookie 3304c4392e7SDoug Rabson * value that may be used to remove the interrupt 3314c4392e7SDoug Rabson * handler 3324c4392e7SDoug Rabson */ 33314177d72SGarrett WollmanMETHOD int setup_intr { 334bd418641SMark Murray device_t _dev; 335bd418641SMark Murray device_t _child; 336bd418641SMark Murray struct resource *_irq; 337bd418641SMark Murray int _flags; 338ef544f63SPaolo Pisati driver_filter_t *_filter; 339bd418641SMark Murray driver_intr_t *_intr; 340bd418641SMark Murray void *_arg; 341bd418641SMark Murray void **_cookiep; 34214177d72SGarrett Wollman}; 34314177d72SGarrett Wollman 3444c4392e7SDoug Rabson/** 3454c4392e7SDoug Rabson * @brief Uninstall an interrupt handler 3464c4392e7SDoug Rabson * 3474c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function 3484c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value 3494c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR(). 3504c4392e7SDoug Rabson * 3514c4392e7SDoug Rabson * @param _dev the parent device of @p _child 3524c4392e7SDoug Rabson * @param _child the device which allocated the resource 3534c4392e7SDoug Rabson * @param _irq the resource representing the interrupt 3544c4392e7SDoug Rabson * @param _cookie the cookie value returned when the interrupt 3554c4392e7SDoug Rabson * was originally registered 3564c4392e7SDoug Rabson */ 35714177d72SGarrett WollmanMETHOD int teardown_intr { 358bd418641SMark Murray device_t _dev; 359bd418641SMark Murray device_t _child; 360bd418641SMark Murray struct resource *_irq; 361bd418641SMark Murray void *_cookie; 36245c95fa1SDoug Rabson}; 36325afb89bSDoug Rabson 3644c4392e7SDoug Rabson/** 3654c4392e7SDoug Rabson * @brief Define a resource which can be allocated with 3664c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). 3674c4392e7SDoug Rabson * 3684c4392e7SDoug Rabson * This method is used by some busses (typically ISA) to allow a 3694c4392e7SDoug Rabson * driver to describe a resource range that it would like to 3704c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined 3714c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its 3724c4392e7SDoug Rabson * range. 3734c4392e7SDoug Rabson * 3744c4392e7SDoug Rabson * @param _dev the parent device of @p _child 3754c4392e7SDoug Rabson * @param _child the device which owns the resource 3764c4392e7SDoug Rabson * @param _type the type of resource 3774c4392e7SDoug Rabson * @param _rid the resource identifier 3784c4392e7SDoug Rabson * @param _start the start of the resource range 3794c4392e7SDoug Rabson * @param _count the size of the resource range 3804c4392e7SDoug Rabson */ 38125afb89bSDoug RabsonMETHOD int set_resource { 382bd418641SMark Murray device_t _dev; 383bd418641SMark Murray device_t _child; 384bd418641SMark Murray int _type; 385bd418641SMark Murray int _rid; 386bd418641SMark Murray u_long _start; 387bd418641SMark Murray u_long _count; 38825afb89bSDoug Rabson}; 38925afb89bSDoug Rabson 3904c4392e7SDoug Rabson/** 3914c4392e7SDoug Rabson * @brief Describe a resource 3924c4392e7SDoug Rabson * 3934c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given 3944c4392e7SDoug Rabson * resource without actually allocating it. 3954c4392e7SDoug Rabson * 3964c4392e7SDoug Rabson * @param _dev the parent device of @p _child 3974c4392e7SDoug Rabson * @param _child the device which owns the resource 3984c4392e7SDoug Rabson * @param _type the type of resource 3994c4392e7SDoug Rabson * @param _rid the resource identifier 4004c4392e7SDoug Rabson * @param _start the address of a location to recieve the start 4014c4392e7SDoug Rabson * index of the resource range 4024c4392e7SDoug Rabson * @param _count the address of a location to recieve the size 4034c4392e7SDoug Rabson * of the resource range 4044c4392e7SDoug Rabson */ 40525afb89bSDoug RabsonMETHOD int get_resource { 406bd418641SMark Murray device_t _dev; 407bd418641SMark Murray device_t _child; 408bd418641SMark Murray int _type; 409bd418641SMark Murray int _rid; 410bd418641SMark Murray u_long *_startp; 411bd418641SMark Murray u_long *_countp; 41225afb89bSDoug Rabson}; 41325afb89bSDoug Rabson 4144c4392e7SDoug Rabson/** 4154c4392e7SDoug Rabson * @brief Delete a resource. 4164c4392e7SDoug Rabson * 4174c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with 4184c4392e7SDoug Rabson * BUS_SET_RESOURCE()). 4194c4392e7SDoug Rabson * 4204c4392e7SDoug Rabson * @param _dev the parent device of @p _child 4214c4392e7SDoug Rabson * @param _child the device which owns the resource 4224c4392e7SDoug Rabson * @param _type the type of resource 4234c4392e7SDoug Rabson * @param _rid the resource identifier 4244c4392e7SDoug Rabson */ 42525afb89bSDoug RabsonMETHOD void delete_resource { 426bd418641SMark Murray device_t _dev; 427bd418641SMark Murray device_t _child; 428bd418641SMark Murray int _type; 429bd418641SMark Murray int _rid; 43025afb89bSDoug Rabson}; 4310cb53e24SMatthew N. Dodd 4324c4392e7SDoug Rabson/** 4334c4392e7SDoug Rabson * @brief Return a struct resource_list. 4344c4392e7SDoug Rabson * 4354c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to 4364c4392e7SDoug Rabson * implement their resource handling. It should return the resource 4374c4392e7SDoug Rabson * list of the given child device. 4384c4392e7SDoug Rabson * 4394c4392e7SDoug Rabson * @param _dev the parent device of @p _child 4404c4392e7SDoug Rabson * @param _child the device which owns the resource list 4414c4392e7SDoug Rabson */ 44246aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list { 443bd418641SMark Murray device_t _dev; 444bd418641SMark Murray device_t _child; 4450cb53e24SMatthew N. Dodd} DEFAULT bus_generic_get_resource_list; 4465878eb3fSWarner Losh 4474c4392e7SDoug Rabson/** 4484c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the 4494c4392e7SDoug Rabson * system? 4504c4392e7SDoug Rabson * 4519f7f340aSWarner Losh * This method should return 0 if the device is not present. It 4529f7f340aSWarner Losh * should return -1 if it is present. Any errors in determining 4539f7f340aSWarner Losh * should be returned as a normal errno value. Client drivers are to 4549f7f340aSWarner Losh * assume that the device is present, even if there is an error 4559f7f340aSWarner Losh * determining if it is there. Busses are to try to avoid returning 4569f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to 4579f7f340aSWarner Losh * implement this method. 4584c4392e7SDoug Rabson * 4594c4392e7SDoug Rabson * @param _dev the parent device of @p _child 4604c4392e7SDoug Rabson * @param _child the device which is being examined 4614c4392e7SDoug Rabson */ 4625878eb3fSWarner LoshMETHOD int child_present { 4635878eb3fSWarner Losh device_t _dev; 4645878eb3fSWarner Losh device_t _child; 4655878eb3fSWarner Losh} DEFAULT bus_generic_child_present; 4663d9841b4SWarner Losh 4674c4392e7SDoug Rabson/** 4684c4392e7SDoug Rabson * @brief Returns the pnp info for this device. 4694c4392e7SDoug Rabson * 4704c4392e7SDoug Rabson * Return it as a string. If the string is insufficient for the 4714c4392e7SDoug Rabson * storage, then return EOVERFLOW. 4724c4392e7SDoug Rabson * 4734c4392e7SDoug Rabson * @param _dev the parent device of @p _child 4744c4392e7SDoug Rabson * @param _child the device which is being examined 4754c4392e7SDoug Rabson * @param _buf the address of a buffer to receive the pnp 4764c4392e7SDoug Rabson * string 4774c4392e7SDoug Rabson * @param _buflen the size of the buffer pointed to by @p _buf 4784c4392e7SDoug Rabson */ 4793d9841b4SWarner LoshMETHOD int child_pnpinfo_str { 4803d9841b4SWarner Losh device_t _dev; 4813d9841b4SWarner Losh device_t _child; 4823d9841b4SWarner Losh char *_buf; 4833d9841b4SWarner Losh size_t _buflen; 4843d9841b4SWarner Losh}; 4853d9841b4SWarner Losh 4864c4392e7SDoug Rabson/** 4874c4392e7SDoug Rabson * @brief Returns the location for this device. 4884c4392e7SDoug Rabson * 4894c4392e7SDoug Rabson * Return it as a string. If the string is insufficient for the 4904c4392e7SDoug Rabson * storage, then return EOVERFLOW. 4914c4392e7SDoug Rabson * 4924c4392e7SDoug Rabson * @param _dev the parent device of @p _child 4934c4392e7SDoug Rabson * @param _child the device which is being examined 4944c4392e7SDoug Rabson * @param _buf the address of a buffer to receive the location 4954c4392e7SDoug Rabson * string 4964c4392e7SDoug Rabson * @param _buflen the size of the buffer pointed to by @p _buf 4974c4392e7SDoug Rabson */ 4983d9841b4SWarner LoshMETHOD int child_location_str { 4993d9841b4SWarner Losh device_t _dev; 5003d9841b4SWarner Losh device_t _child; 5013d9841b4SWarner Losh char *_buf; 5023d9841b4SWarner Losh size_t _buflen; 5033d9841b4SWarner Losh}; 504da13b8f9SMarcel Moolenaar 5054c4392e7SDoug Rabson/** 506dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific 507dcc81068SJohn Baldwin * CPU. 508dcc81068SJohn Baldwin * 509dcc81068SJohn Baldwin * @param _dev the parent device of @p _child 510dcc81068SJohn Baldwin * @param _child the device which allocated the resource 511dcc81068SJohn Baldwin * @param _irq the resource representing the interrupt 512dcc81068SJohn Baldwin * @param _cpu the CPU to bind the interrupt to 513dcc81068SJohn Baldwin */ 514dcc81068SJohn BaldwinMETHOD int bind_intr { 515dcc81068SJohn Baldwin device_t _dev; 516dcc81068SJohn Baldwin device_t _child; 517dcc81068SJohn Baldwin struct resource *_irq; 518dcc81068SJohn Baldwin int _cpu; 519dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr; 520dcc81068SJohn Baldwin 521dcc81068SJohn Baldwin/** 5224c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity 5234c4392e7SDoug Rabson * of the specified interrupt. 5244c4392e7SDoug Rabson * 5254c4392e7SDoug Rabson * @param _dev the bus device 5264c4392e7SDoug Rabson * @param _irq the interrupt number to modify 5274c4392e7SDoug Rabson * @param _trig the trigger mode required 5284c4392e7SDoug Rabson * @param _pol the interrupt polarity required 5294c4392e7SDoug Rabson */ 530da13b8f9SMarcel MoolenaarMETHOD int config_intr { 531da13b8f9SMarcel Moolenaar device_t _dev; 532da13b8f9SMarcel Moolenaar int _irq; 533da13b8f9SMarcel Moolenaar enum intr_trigger _trig; 534da13b8f9SMarcel Moolenaar enum intr_polarity _pol; 535da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr; 536db2bc1bbSWarner Losh 537db2bc1bbSWarner Losh/** 53837b8ef16SJohn Baldwin * @brief Allow drivers to associate a description with an active 53937b8ef16SJohn Baldwin * interrupt handler. 54037b8ef16SJohn Baldwin * 54137b8ef16SJohn Baldwin * @param _dev the parent device of @p _child 54237b8ef16SJohn Baldwin * @param _child the device which allocated the resource 54337b8ef16SJohn Baldwin * @param _irq the resource representing the interrupt 54437b8ef16SJohn Baldwin * @param _cookie the cookie value returned when the interrupt 54537b8ef16SJohn Baldwin * was originally registered 54637b8ef16SJohn Baldwin * @param _descr the description to associate with the interrupt 54737b8ef16SJohn Baldwin */ 54837b8ef16SJohn BaldwinMETHOD int describe_intr { 54937b8ef16SJohn Baldwin device_t _dev; 55037b8ef16SJohn Baldwin device_t _child; 55137b8ef16SJohn Baldwin struct resource *_irq; 55237b8ef16SJohn Baldwin void *_cookie; 55337b8ef16SJohn Baldwin const char *_descr; 55437b8ef16SJohn Baldwin} DEFAULT bus_generic_describe_intr; 55537b8ef16SJohn Baldwin 55637b8ef16SJohn Baldwin/** 557db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism 558db2bc1bbSWarner Losh * believes it has discovered. 559db2bc1bbSWarner Losh * 560db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order 561db2bc1bbSWarner Losh * and discovering other things about the child. The bus driver is 562db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc. It is all up 563db2bc1bbSWarner Losh * to the bus driver to interpret. 564db2bc1bbSWarner Losh * 565db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for 566db2bc1bbSWarner Losh * hinted devices to be enumerated. 567db2bc1bbSWarner Losh * 568db2bc1bbSWarner Losh * @param _dev the bus device 569db2bc1bbSWarner Losh * @param _dname the name of the device w/o unit numbers 570db2bc1bbSWarner Losh * @param _dunit the unit number of the device 571db2bc1bbSWarner Losh */ 572db2bc1bbSWarner LoshMETHOD void hinted_child { 573db2bc1bbSWarner Losh device_t _dev; 574db2bc1bbSWarner Losh const char *_dname; 575db2bc1bbSWarner Losh int _dunit; 576db2bc1bbSWarner Losh}; 577378f231eSJohn-Mark Gurney 578378f231eSJohn-Mark Gurney/** 579378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus. 580378f231eSJohn-Mark Gurney * 581378f231eSJohn-Mark Gurney * @param _dev the parent device of @p _child 582378f231eSJohn-Mark Gurney * @param _child the device to which the tag will belong 583378f231eSJohn-Mark Gurney */ 584378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag { 585378f231eSJohn-Mark Gurney device_t _dev; 586378f231eSJohn-Mark Gurney device_t _child; 587378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag; 5880d484d24SJohn Baldwin 5890d484d24SJohn Baldwin/** 5900d484d24SJohn Baldwin * @brief Allow the bus to determine the unit number of a device. 5910d484d24SJohn Baldwin * 5920d484d24SJohn Baldwin * @param _dev the parent device of @p _child 5930d484d24SJohn Baldwin * @param _child the device whose unit is to be wired 5940d484d24SJohn Baldwin * @param _name the name of the device's new devclass 5950d484d24SJohn Baldwin * @param _unitp a pointer to the device's new unit value 5960d484d24SJohn Baldwin */ 5970d484d24SJohn BaldwinMETHOD void hint_device_unit { 5980d484d24SJohn Baldwin device_t _dev; 5990d484d24SJohn Baldwin device_t _child; 6000d484d24SJohn Baldwin const char *_name; 6010d484d24SJohn Baldwin int *_unitp; 6020d484d24SJohn Baldwin}; 6030d484d24SJohn Baldwin 6044ef60d26SJohn Baldwin/** 6054ef60d26SJohn Baldwin * @brief Notify a bus that the bus pass level has been changed 6064ef60d26SJohn Baldwin * 6074ef60d26SJohn Baldwin * @param _dev the bus device 6084ef60d26SJohn Baldwin */ 6094ef60d26SJohn BaldwinMETHOD void new_pass { 6104ef60d26SJohn Baldwin device_t _dev; 6114ef60d26SJohn Baldwin} DEFAULT bus_generic_new_pass; 61293fc07b4SAlexander Motin 61393fc07b4SAlexander Motin/** 61493fc07b4SAlexander Motin * @brief Notify a bus that specified child's IRQ should be remapped. 61593fc07b4SAlexander Motin * 61693fc07b4SAlexander Motin * @param _dev the bus device 61793fc07b4SAlexander Motin * @param _child the child device 61893fc07b4SAlexander Motin * @param _irq the irq number 61993fc07b4SAlexander Motin */ 62093fc07b4SAlexander MotinMETHOD int remap_intr { 62193fc07b4SAlexander Motin device_t _dev; 62293fc07b4SAlexander Motin device_t _child; 62393fc07b4SAlexander Motin u_int _irq; 62493fc07b4SAlexander Motin} DEFAULT null_remap_intr; 625