1139804Simp#- 2133588Simp# Copyright (c) 1998-2004 Doug Rabson 336973Sdfr# All rights reserved. 436973Sdfr# 536973Sdfr# Redistribution and use in source and binary forms, with or without 636973Sdfr# modification, are permitted provided that the following conditions 736973Sdfr# are met: 836973Sdfr# 1. Redistributions of source code must retain the above copyright 936973Sdfr# notice, this list of conditions and the following disclaimer. 1036973Sdfr# 2. Redistributions in binary form must reproduce the above copyright 1136973Sdfr# notice, this list of conditions and the following disclaimer in the 1236973Sdfr# documentation and/or other materials provided with the distribution. 1336973Sdfr# 1436973Sdfr# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1536973Sdfr# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1636973Sdfr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1736973Sdfr# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1836973Sdfr# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1936973Sdfr# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2036973Sdfr# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2136973Sdfr# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2236973Sdfr# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2336973Sdfr# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2436973Sdfr# SUCH DAMAGE. 2536973Sdfr# 2650477Speter# $FreeBSD: stable/11/sys/kern/bus_if.m 346381 2019-04-19 12:57:37Z kib $ 2736973Sdfr# 2836973Sdfr 29212544Savg#include <sys/types.h> 30212544Savg#include <sys/systm.h> 3159093Sdfr#include <sys/bus.h> 3259093Sdfr 33132354Sdfr/** 34132354Sdfr * @defgroup BUS bus - KObj methods for drivers of devices with children 35132354Sdfr * @brief A set of methods required device drivers that support 36132354Sdfr * child devices. 37132354Sdfr * @{ 38132354Sdfr */ 3941017SnsouchINTERFACE bus; 4036973Sdfr 4136973Sdfr# 4246913Sdfr# Default implementations of some methods. 4346913Sdfr# 4446913SdfrCODE { 4546913Sdfr static struct resource * 4646913Sdfr null_alloc_resource(device_t dev, device_t child, 47294883Sjhibbits int type, int *rid, rman_res_t start, rman_res_t end, 48294883Sjhibbits rman_res_t count, u_int flags) 4946913Sdfr { 50100421Simp return (0); 5146913Sdfr } 52209154Smav 53209154Smav static int 54209154Smav null_remap_intr(device_t bus, device_t dev, u_int irq) 55209154Smav { 56209154Smav 57209154Smav if (dev != NULL) 58209154Smav return (BUS_REMAP_INTR(dev, NULL, irq)); 59209154Smav return (ENXIO); 60209154Smav } 61212544Savg 62212544Savg static device_t 63212544Savg null_add_child(device_t bus, int order, const char *name, 64212544Savg int unit) 65212544Savg { 66212544Savg 67212544Savg panic("bus_add_child is not implemented"); 68212544Savg } 69346381Skib 70346381Skib static int null_reset_post(device_t bus, device_t dev) 71346381Skib { 72346381Skib return (0); 73346381Skib } 74346381Skib 75346381Skib static int null_reset_prepare(device_t bus, device_t dev) 76346381Skib { 77346381Skib return (0); 78346381Skib } 7946913Sdfr}; 8046913Sdfr 81132354Sdfr/** 82132354Sdfr * @brief Print a description of a child device 83132354Sdfr * 84132354Sdfr * This is called from system code which prints out a description of a 85132354Sdfr * device. It should describe the attachment that the child has with 86132354Sdfr * the parent. For instance the TurboLaser bus prints which node the 87132354Sdfr * device is attached to. See bus_generic_print_child() for more 88132354Sdfr * information. 89132354Sdfr * 90132354Sdfr * @param _dev the device whose child is being printed 91132354Sdfr * @param _child the child device to describe 92132354Sdfr * 93132354Sdfr * @returns the number of characters output. 94132354Sdfr */ 9549195SmdoddMETHOD int print_child { 96132354Sdfr device_t _dev; 97132354Sdfr device_t _child; 98112588Smdodd} DEFAULT bus_generic_print_child; 9936973Sdfr 100132354Sdfr/** 101132354Sdfr * @brief Print a notification about an unprobed child device. 102132354Sdfr * 103132354Sdfr * Called for each child device that did not succeed in probing for a 104132354Sdfr * driver. 105132354Sdfr * 106132354Sdfr * @param _dev the device whose child was being probed 107132354Sdfr * @param _child the child device which failed to probe 108132354Sdfr */ 10948754SdfrMETHOD void probe_nomatch { 110132354Sdfr device_t _dev; 111132354Sdfr device_t _child; 11248754Sdfr}; 11348754Sdfr 114132354Sdfr/** 115132354Sdfr * @brief Read the value of a bus-specific attribute of a device 116132354Sdfr * 117132354Sdfr * This method, along with BUS_WRITE_IVAR() manages a bus-specific set 118132354Sdfr * of instance variables of a child device. The intention is that 119132354Sdfr * each different type of bus defines a set of appropriate instance 120132354Sdfr * variables (such as ports and irqs for ISA bus etc.) 121132354Sdfr * 122132354Sdfr * This information could be given to the child device as a struct but 123132354Sdfr * that makes it hard for a bus to add or remove variables without 124132354Sdfr * forcing an edit and recompile for all drivers which may not be 125132354Sdfr * possible for vendor supplied binary drivers. 126132354Sdfr * 127132354Sdfr * This method copies the value of an instance variable to the 128132354Sdfr * location specified by @p *_result. 129132354Sdfr * 130132354Sdfr * @param _dev the device whose child was being examined 131132354Sdfr * @param _child the child device whose instance variable is 132132354Sdfr * being read 133132354Sdfr * @param _index the instance variable to read 134298819Spfg * @param _result a location to receive the instance variable 135132354Sdfr * value 136132354Sdfr * 137132354Sdfr * @retval 0 success 138132354Sdfr * @retval ENOENT no such instance variable is supported by @p 139132354Sdfr * _dev 140132354Sdfr */ 14136973SdfrMETHOD int read_ivar { 14295201Smarkm device_t _dev; 14395201Smarkm device_t _child; 144132354Sdfr int _index; 14595201Smarkm uintptr_t *_result; 14636973Sdfr}; 14736973Sdfr 148132354Sdfr/** 149132354Sdfr * @brief Write the value of a bus-specific attribute of a device 150132354Sdfr * 151132354Sdfr * This method sets the value of an instance variable to @p _value. 152132354Sdfr * 153132354Sdfr * @param _dev the device whose child was being updated 154132354Sdfr * @param _child the child device whose instance variable is 155132354Sdfr * being written 156132354Sdfr * @param _index the instance variable to write 157132354Sdfr * @param _value the value to write to that instance variable 158132354Sdfr * 159132354Sdfr * @retval 0 success 160132354Sdfr * @retval ENOENT no such instance variable is supported by @p 161132354Sdfr * _dev 162132354Sdfr * @retval EINVAL the instance variable was recognised but 163132354Sdfr * contains a read-only value 164132354Sdfr */ 16536973SdfrMETHOD int write_ivar { 16695201Smarkm device_t _dev; 16795201Smarkm device_t _child; 16895201Smarkm int _indx; 16995201Smarkm uintptr_t _value; 17036973Sdfr}; 17136973Sdfr 172132354Sdfr/** 173239512Sjhb * @brief Notify a bus that a child was deleted 174239512Sjhb * 175239512Sjhb * Called at the beginning of device_delete_child() to allow the parent 176239512Sjhb * to teardown any bus-specific state for the child. 177239512Sjhb * 178239512Sjhb * @param _dev the device whose child is being deleted 179239512Sjhb * @param _child the child device which is being deleted 180239512Sjhb */ 181239512SjhbMETHOD void child_deleted { 182239512Sjhb device_t _dev; 183239512Sjhb device_t _child; 184239512Sjhb}; 185239512Sjhb 186239512Sjhb/** 187132354Sdfr * @brief Notify a bus that a child was detached 188132354Sdfr * 189132354Sdfr * Called after the child's DEVICE_DETACH() method to allow the parent 190132354Sdfr * to reclaim any resources allocated on behalf of the child. 191132354Sdfr * 192132354Sdfr * @param _dev the device whose child changed state 193132354Sdfr * @param _child the child device which changed state 194132354Sdfr */ 19545107SdfrMETHOD void child_detached { 19695201Smarkm device_t _dev; 19795201Smarkm device_t _child; 19845107Sdfr}; 19945107Sdfr 200132354Sdfr/** 201132354Sdfr * @brief Notify a bus that a new driver was added 202132354Sdfr * 203132354Sdfr * Called when a new driver is added to the devclass which owns this 204132354Sdfr * bus. The generic implementation of this method attempts to probe and 205132354Sdfr * attach any un-matched children of the bus. 206132354Sdfr * 207132354Sdfr * @param _dev the device whose devclass had a new driver 208132354Sdfr * added to it 209132354Sdfr * @param _driver the new driver which was added 210132354Sdfr */ 21145720SpeterMETHOD void driver_added { 21295201Smarkm device_t _dev; 21395201Smarkm driver_t *_driver; 21452045Simp} DEFAULT bus_generic_driver_added; 21545720Speter 216132354Sdfr/** 217132354Sdfr * @brief Create a new child device 218132354Sdfr * 219132354Sdfr * For busses which use use drivers supporting DEVICE_IDENTIFY() to 220132354Sdfr * enumerate their devices, this method is used to create new 221132354Sdfr * device instances. The new device will be added after the last 222290117Simp * existing child with the same order. Implementations of bus_add_child 223290117Simp * call device_add_child_ordered to add the child and often add 224290117Simp * a suitable ivar to the device specific to that bus. 225132354Sdfr * 226132354Sdfr * @param _dev the bus device which will be the parent of the 227132354Sdfr * new child device 228132354Sdfr * @param _order a value which is used to partially sort the 229132354Sdfr * children of @p _dev - devices created using 230132354Sdfr * lower values of @p _order appear first in @p 231132354Sdfr * _dev's list of children 232132354Sdfr * @param _name devclass name for new device or @c NULL if not 233132354Sdfr * specified 234132354Sdfr * @param _unit unit number for new device or @c -1 if not 235132354Sdfr * specified 236132354Sdfr */ 23747178SdfrMETHOD device_t add_child { 23895201Smarkm device_t _dev; 239212413Savg u_int _order; 24095201Smarkm const char *_name; 24195201Smarkm int _unit; 242212544Savg} DEFAULT null_add_child; 24347178Sdfr 244132354Sdfr/** 245298707Sjhb * @brief Rescan the bus 246298707Sjhb * 247298707Sjhb * This method is called by a parent bridge or devctl to trigger a bus 248298707Sjhb * rescan. The rescan should delete devices no longer present and 249298707Sjhb * enumerate devices that have newly arrived. 250298707Sjhb * 251298707Sjhb * @param _dev the bus device 252298707Sjhb */ 253298707SjhbMETHOD int rescan { 254298707Sjhb device_t _dev; 255298707Sjhb} 256298707Sjhb 257298707Sjhb/** 258132354Sdfr * @brief Allocate a system resource 259132354Sdfr * 260132354Sdfr * This method is called by child devices of a bus to allocate resources. 261132354Sdfr * The types are defined in <machine/resource.h>; the meaning of the 262132354Sdfr * resource-ID field varies from bus to bus (but @p *rid == 0 is always 263132354Sdfr * valid if the resource type is). If a resource was allocated and the 264132354Sdfr * caller did not use the RF_ACTIVE to specify that it should be 265132354Sdfr * activated immediately, the caller is responsible for calling 266132354Sdfr * BUS_ACTIVATE_RESOURCE() when it actually uses the resource. 267132354Sdfr * 268132354Sdfr * @param _dev the parent device of @p _child 269132354Sdfr * @param _child the device which is requesting an allocation 270132354Sdfr * @param _type the type of resource to allocate 271132354Sdfr * @param _rid a pointer to the resource identifier 272132354Sdfr * @param _start hint at the start of the resource range - pass 273296336Sjhibbits * @c 0 for any start address 274132354Sdfr * @param _end hint at the end of the resource range - pass 275296336Sjhibbits * @c ~0 for any end address 276132354Sdfr * @param _count hint at the size of range required - pass @c 1 277132354Sdfr * for any size 278132354Sdfr * @param _flags any extra flags to control the resource 279132354Sdfr * allocation - see @c RF_XXX flags in 280132354Sdfr * <sys/rman.h> for details 281132354Sdfr * 282132354Sdfr * @returns the resource which was allocated or @c NULL if no 283132354Sdfr * resource could be allocated 284132354Sdfr */ 28541153SwollmanMETHOD struct resource * alloc_resource { 28695201Smarkm device_t _dev; 28795201Smarkm device_t _child; 28895201Smarkm int _type; 28995201Smarkm int *_rid; 290294883Sjhibbits rman_res_t _start; 291294883Sjhibbits rman_res_t _end; 292294883Sjhibbits rman_res_t _count; 29395201Smarkm u_int _flags; 29446913Sdfr} DEFAULT null_alloc_resource; 29537592Sdfr 296132354Sdfr/** 297132354Sdfr * @brief Activate a resource 298132354Sdfr * 299132354Sdfr * Activate a resource previously allocated with 300300317Sjhb * BUS_ALLOC_RESOURCE(). This may enable decoding of this resource in a 301300317Sjhb * device for instance. It will also establish a mapping for the resource 302300317Sjhb * unless RF_UNMAPPED was set when allocating the resource. 303132354Sdfr * 304132354Sdfr * @param _dev the parent device of @p _child 305132354Sdfr * @param _child the device which allocated the resource 306132354Sdfr * @param _type the type of resource 307132354Sdfr * @param _rid the resource identifier 308132354Sdfr * @param _r the resource to activate 309132354Sdfr */ 31041153SwollmanMETHOD int activate_resource { 31195201Smarkm device_t _dev; 31295201Smarkm device_t _child; 31395201Smarkm int _type; 31495201Smarkm int _rid; 31595201Smarkm struct resource *_r; 31641153Swollman}; 31741153Swollman 318300317Sjhb 319132354Sdfr/** 320300317Sjhb * @brief Map a resource 321300317Sjhb * 322300317Sjhb * Allocate a mapping for a range of an active resource. The mapping 323300317Sjhb * is described by a struct resource_map object. This may for instance 324300317Sjhb * map a memory region into the kernel's virtual address space. 325300317Sjhb * 326300317Sjhb * @param _dev the parent device of @p _child 327300317Sjhb * @param _child the device which allocated the resource 328300317Sjhb * @param _type the type of resource 329300317Sjhb * @param _r the resource to map 330300317Sjhb * @param _args optional attributes of the mapping 331300317Sjhb * @param _map the mapping 332300317Sjhb */ 333300317SjhbMETHOD int map_resource { 334300317Sjhb device_t _dev; 335300317Sjhb device_t _child; 336300317Sjhb int _type; 337300317Sjhb struct resource *_r; 338300317Sjhb struct resource_map_request *_args; 339300317Sjhb struct resource_map *_map; 340300317Sjhb} DEFAULT bus_generic_map_resource; 341300317Sjhb 342300317Sjhb 343300317Sjhb/** 344300317Sjhb * @brief Unmap a resource 345300317Sjhb * 346300317Sjhb * Release a mapping previously allocated with 347300317Sjhb * BUS_MAP_RESOURCE(). This may for instance unmap a memory region 348300317Sjhb * from the kernel's virtual address space. 349300317Sjhb * 350300317Sjhb * @param _dev the parent device of @p _child 351300317Sjhb * @param _child the device which allocated the resource 352300317Sjhb * @param _type the type of resource 353300317Sjhb * @param _r the resource 354300317Sjhb * @param _map the mapping to release 355300317Sjhb */ 356300317SjhbMETHOD int unmap_resource { 357300317Sjhb device_t _dev; 358300317Sjhb device_t _child; 359300317Sjhb int _type; 360300317Sjhb struct resource *_r; 361300317Sjhb struct resource_map *_map; 362300317Sjhb} DEFAULT bus_generic_unmap_resource; 363300317Sjhb 364300317Sjhb 365300317Sjhb/** 366132354Sdfr * @brief Deactivate a resource 367132354Sdfr * 368132354Sdfr * Deactivate a resource previously allocated with 369300317Sjhb * BUS_ALLOC_RESOURCE(). 370132354Sdfr * 371132354Sdfr * @param _dev the parent device of @p _child 372132354Sdfr * @param _child the device which allocated the resource 373132354Sdfr * @param _type the type of resource 374132354Sdfr * @param _rid the resource identifier 375132354Sdfr * @param _r the resource to deactivate 376132354Sdfr */ 37741153SwollmanMETHOD int deactivate_resource { 37895201Smarkm device_t _dev; 37995201Smarkm device_t _child; 38095201Smarkm int _type; 38195201Smarkm int _rid; 38295201Smarkm struct resource *_r; 38341153Swollman}; 38441153Swollman 385132354Sdfr/** 386221231Sjhb * @brief Adjust a resource 387221231Sjhb * 388221231Sjhb * Adjust the start and/or end of a resource allocated by 389221231Sjhb * BUS_ALLOC_RESOURCE. At least part of the new address range must overlap 390221231Sjhb * with the existing address range. If the successful, the resource's range 391221231Sjhb * will be adjusted to [start, end] on return. 392221231Sjhb * 393221231Sjhb * @param _dev the parent device of @p _child 394221231Sjhb * @param _child the device which allocated the resource 395221231Sjhb * @param _type the type of resource 396221231Sjhb * @param _res the resource to adjust 397221231Sjhb * @param _start the new starting address of the resource range 398221231Sjhb * @param _end the new ending address of the resource range 399221231Sjhb */ 400221231SjhbMETHOD int adjust_resource { 401221231Sjhb device_t _dev; 402221231Sjhb device_t _child; 403221231Sjhb int _type; 404221231Sjhb struct resource *_res; 405294883Sjhibbits rman_res_t _start; 406294883Sjhibbits rman_res_t _end; 407221231Sjhb}; 408221231Sjhb 409221231Sjhb/** 410132354Sdfr * @brief Release a resource 411132354Sdfr * 412132354Sdfr * Free a resource allocated by the BUS_ALLOC_RESOURCE. The @p _rid 413132354Sdfr * value must be the same as the one returned by BUS_ALLOC_RESOURCE() 414132354Sdfr * (which is not necessarily the same as the one the client passed). 415132354Sdfr * 416132354Sdfr * @param _dev the parent device of @p _child 417132354Sdfr * @param _child the device which allocated the resource 418132354Sdfr * @param _type the type of resource 419132354Sdfr * @param _rid the resource identifier 420132354Sdfr * @param _r the resource to release 421132354Sdfr */ 42241153SwollmanMETHOD int release_resource { 42395201Smarkm device_t _dev; 42495201Smarkm device_t _child; 42595201Smarkm int _type; 42695201Smarkm int _rid; 42795201Smarkm struct resource *_res; 42837592Sdfr}; 42941153Swollman 430132354Sdfr/** 431132354Sdfr * @brief Install an interrupt handler 432132354Sdfr * 433132354Sdfr * This method is used to associate an interrupt handler function with 434132354Sdfr * an irq resource. When the interrupt triggers, the function @p _intr 435132354Sdfr * will be called with the value of @p _arg as its single 436132354Sdfr * argument. The value returned in @p *_cookiep is used to cancel the 437132354Sdfr * interrupt handler - the caller should save this value to use in a 438132354Sdfr * future call to BUS_TEARDOWN_INTR(). 439132354Sdfr * 440132354Sdfr * @param _dev the parent device of @p _child 441132354Sdfr * @param _child the device which allocated the resource 442132354Sdfr * @param _irq the resource representing the interrupt 443132354Sdfr * @param _flags a set of bits from enum intr_type specifying 444132354Sdfr * the class of interrupt 445132354Sdfr * @param _intr the function to call when the interrupt 446132354Sdfr * triggers 447132354Sdfr * @param _arg a value to use as the single argument in calls 448132354Sdfr * to @p _intr 449298819Spfg * @param _cookiep a pointer to a location to receive a cookie 450132354Sdfr * value that may be used to remove the interrupt 451132354Sdfr * handler 452132354Sdfr */ 45341153SwollmanMETHOD int setup_intr { 45495201Smarkm device_t _dev; 45595201Smarkm device_t _child; 45695201Smarkm struct resource *_irq; 45795201Smarkm int _flags; 458166901Spiso driver_filter_t *_filter; 45995201Smarkm driver_intr_t *_intr; 46095201Smarkm void *_arg; 46195201Smarkm void **_cookiep; 46241153Swollman}; 46341153Swollman 464132354Sdfr/** 465132354Sdfr * @brief Uninstall an interrupt handler 466132354Sdfr * 467132354Sdfr * This method is used to disassociate an interrupt handler function 468132354Sdfr * with an irq resource. The value of @p _cookie must be the value 469132354Sdfr * returned from a previous call to BUS_SETUP_INTR(). 470132354Sdfr * 471132354Sdfr * @param _dev the parent device of @p _child 472132354Sdfr * @param _child the device which allocated the resource 473132354Sdfr * @param _irq the resource representing the interrupt 474132354Sdfr * @param _cookie the cookie value returned when the interrupt 475132354Sdfr * was originally registered 476132354Sdfr */ 47741153SwollmanMETHOD int teardown_intr { 47895201Smarkm device_t _dev; 47995201Smarkm device_t _child; 48095201Smarkm struct resource *_irq; 48195201Smarkm void *_cookie; 48241153Swollman}; 48352174Sdfr 484132354Sdfr/** 485132354Sdfr * @brief Define a resource which can be allocated with 486132354Sdfr * BUS_ALLOC_RESOURCE(). 487132354Sdfr * 488132354Sdfr * This method is used by some busses (typically ISA) to allow a 489132354Sdfr * driver to describe a resource range that it would like to 490132354Sdfr * allocate. The resource defined by @p _type and @p _rid is defined 491132354Sdfr * to start at @p _start and to include @p _count indices in its 492132354Sdfr * range. 493132354Sdfr * 494132354Sdfr * @param _dev the parent device of @p _child 495132354Sdfr * @param _child the device which owns the resource 496132354Sdfr * @param _type the type of resource 497132354Sdfr * @param _rid the resource identifier 498132354Sdfr * @param _start the start of the resource range 499132354Sdfr * @param _count the size of the resource range 500132354Sdfr */ 50152174SdfrMETHOD int set_resource { 50295201Smarkm device_t _dev; 50395201Smarkm device_t _child; 50495201Smarkm int _type; 50595201Smarkm int _rid; 506294883Sjhibbits rman_res_t _start; 507294883Sjhibbits rman_res_t _count; 50852174Sdfr}; 50952174Sdfr 510132354Sdfr/** 511132354Sdfr * @brief Describe a resource 512132354Sdfr * 513132354Sdfr * This method allows a driver to examine the range used for a given 514132354Sdfr * resource without actually allocating it. 515132354Sdfr * 516132354Sdfr * @param _dev the parent device of @p _child 517132354Sdfr * @param _child the device which owns the resource 518132354Sdfr * @param _type the type of resource 519132354Sdfr * @param _rid the resource identifier 520298819Spfg * @param _start the address of a location to receive the start 521132354Sdfr * index of the resource range 522298819Spfg * @param _count the address of a location to receive the size 523132354Sdfr * of the resource range 524132354Sdfr */ 52552174SdfrMETHOD int get_resource { 52695201Smarkm device_t _dev; 52795201Smarkm device_t _child; 52895201Smarkm int _type; 52995201Smarkm int _rid; 530294883Sjhibbits rman_res_t *_startp; 531294883Sjhibbits rman_res_t *_countp; 53252174Sdfr}; 53352174Sdfr 534132354Sdfr/** 535132354Sdfr * @brief Delete a resource. 536132354Sdfr * 537132354Sdfr * Use this to delete a resource (possibly one previously added with 538132354Sdfr * BUS_SET_RESOURCE()). 539132354Sdfr * 540132354Sdfr * @param _dev the parent device of @p _child 541132354Sdfr * @param _child the device which owns the resource 542132354Sdfr * @param _type the type of resource 543132354Sdfr * @param _rid the resource identifier 544132354Sdfr */ 54552174SdfrMETHOD void delete_resource { 54695201Smarkm device_t _dev; 54795201Smarkm device_t _child; 54895201Smarkm int _type; 54995201Smarkm int _rid; 55052174Sdfr}; 55167278Smdodd 552132354Sdfr/** 553132354Sdfr * @brief Return a struct resource_list. 554132354Sdfr * 555132354Sdfr * Used by drivers which use bus_generic_rl_alloc_resource() etc. to 556132354Sdfr * implement their resource handling. It should return the resource 557132354Sdfr * list of the given child device. 558132354Sdfr * 559132354Sdfr * @param _dev the parent device of @p _child 560132354Sdfr * @param _child the device which owns the resource list 561132354Sdfr */ 56269294SmdoddMETHOD struct resource_list * get_resource_list { 56395201Smarkm device_t _dev; 56495201Smarkm device_t _child; 56567278Smdodd} DEFAULT bus_generic_get_resource_list; 566100421Simp 567132354Sdfr/** 568132354Sdfr * @brief Is the hardware described by @p _child still attached to the 569132354Sdfr * system? 570132354Sdfr * 571133588Simp * This method should return 0 if the device is not present. It 572133588Simp * should return -1 if it is present. Any errors in determining 573133588Simp * should be returned as a normal errno value. Client drivers are to 574133588Simp * assume that the device is present, even if there is an error 575133588Simp * determining if it is there. Busses are to try to avoid returning 576133588Simp * errors, but newcard will return an error if the device fails to 577133588Simp * implement this method. 578132354Sdfr * 579132354Sdfr * @param _dev the parent device of @p _child 580132354Sdfr * @param _child the device which is being examined 581132354Sdfr */ 582100421SimpMETHOD int child_present { 583100421Simp device_t _dev; 584100421Simp device_t _child; 585100421Simp} DEFAULT bus_generic_child_present; 586104597Simp 587132354Sdfr/** 588132354Sdfr * @brief Returns the pnp info for this device. 589132354Sdfr * 590300158Srpokala * Return it as a string. If the storage is insufficient for the 591300158Srpokala * string, then return EOVERFLOW. 592300073Sjhb * 593300073Sjhb * The string must be formatted as a space-separated list of 594300073Sjhb * name=value pairs. Names may only contain alphanumeric characters, 595300073Sjhb * underscores ('_') and hyphens ('-'). Values can contain any 596300073Sjhb * non-whitespace characters. Values containing whitespace can be 597300073Sjhb * quoted with double quotes ('"'). Double quotes and backslashes in 598300073Sjhb * quoted values can be escaped with backslashes ('\'). 599132354Sdfr * 600132354Sdfr * @param _dev the parent device of @p _child 601132354Sdfr * @param _child the device which is being examined 602132354Sdfr * @param _buf the address of a buffer to receive the pnp 603132354Sdfr * string 604132354Sdfr * @param _buflen the size of the buffer pointed to by @p _buf 605132354Sdfr */ 606104597SimpMETHOD int child_pnpinfo_str { 607104597Simp device_t _dev; 608104597Simp device_t _child; 609104597Simp char *_buf; 610104597Simp size_t _buflen; 611104597Simp}; 612104597Simp 613132354Sdfr/** 614132354Sdfr * @brief Returns the location for this device. 615132354Sdfr * 616300158Srpokala * Return it as a string. If the storage is insufficient for the 617300158Srpokala * string, then return EOVERFLOW. 618300073Sjhb * 619300073Sjhb * The string must be formatted as a space-separated list of 620300073Sjhb * name=value pairs. Names may only contain alphanumeric characters, 621300073Sjhb * underscores ('_') and hyphens ('-'). Values can contain any 622300073Sjhb * non-whitespace characters. Values containing whitespace can be 623300073Sjhb * quoted with double quotes ('"'). Double quotes and backslashes in 624300073Sjhb * quoted values can be escaped with backslashes ('\'). 625300073Sjhb * 626132354Sdfr * @param _dev the parent device of @p _child 627132354Sdfr * @param _child the device which is being examined 628132354Sdfr * @param _buf the address of a buffer to receive the location 629132354Sdfr * string 630132354Sdfr * @param _buflen the size of the buffer pointed to by @p _buf 631132354Sdfr */ 632104597SimpMETHOD int child_location_str { 633104597Simp device_t _dev; 634104597Simp device_t _child; 635104597Simp char *_buf; 636104597Simp size_t _buflen; 637104597Simp}; 638119967Smarcel 639132354Sdfr/** 640177467Sjhb * @brief Allow drivers to request that an interrupt be bound to a specific 641177467Sjhb * CPU. 642177467Sjhb * 643177467Sjhb * @param _dev the parent device of @p _child 644177467Sjhb * @param _child the device which allocated the resource 645177467Sjhb * @param _irq the resource representing the interrupt 646177467Sjhb * @param _cpu the CPU to bind the interrupt to 647177467Sjhb */ 648177467SjhbMETHOD int bind_intr { 649177467Sjhb device_t _dev; 650177467Sjhb device_t _child; 651177467Sjhb struct resource *_irq; 652177467Sjhb int _cpu; 653177467Sjhb} DEFAULT bus_generic_bind_intr; 654177467Sjhb 655177467Sjhb/** 656132354Sdfr * @brief Allow (bus) drivers to specify the trigger mode and polarity 657132354Sdfr * of the specified interrupt. 658132354Sdfr * 659132354Sdfr * @param _dev the bus device 660132354Sdfr * @param _irq the interrupt number to modify 661132354Sdfr * @param _trig the trigger mode required 662132354Sdfr * @param _pol the interrupt polarity required 663132354Sdfr */ 664119967SmarcelMETHOD int config_intr { 665119967Smarcel device_t _dev; 666119967Smarcel int _irq; 667119967Smarcel enum intr_trigger _trig; 668119967Smarcel enum intr_polarity _pol; 669119967Smarcel} DEFAULT bus_generic_config_intr; 670160186Simp 671160186Simp/** 672198134Sjhb * @brief Allow drivers to associate a description with an active 673198134Sjhb * interrupt handler. 674198134Sjhb * 675198134Sjhb * @param _dev the parent device of @p _child 676198134Sjhb * @param _child the device which allocated the resource 677198134Sjhb * @param _irq the resource representing the interrupt 678198134Sjhb * @param _cookie the cookie value returned when the interrupt 679198134Sjhb * was originally registered 680198134Sjhb * @param _descr the description to associate with the interrupt 681198134Sjhb */ 682198134SjhbMETHOD int describe_intr { 683198134Sjhb device_t _dev; 684198134Sjhb device_t _child; 685198134Sjhb struct resource *_irq; 686198134Sjhb void *_cookie; 687198134Sjhb const char *_descr; 688198134Sjhb} DEFAULT bus_generic_describe_intr; 689198134Sjhb 690198134Sjhb/** 691160186Simp * @brief Notify a (bus) driver about a child that the hints mechanism 692160186Simp * believes it has discovered. 693160186Simp * 694160186Simp * The bus is responsible for then adding the child in the right order 695160186Simp * and discovering other things about the child. The bus driver is 696160186Simp * free to ignore this hint, to do special things, etc. It is all up 697160186Simp * to the bus driver to interpret. 698160186Simp * 699160186Simp * This method is only called in response to the parent bus asking for 700160186Simp * hinted devices to be enumerated. 701160186Simp * 702160186Simp * @param _dev the bus device 703160186Simp * @param _dname the name of the device w/o unit numbers 704160186Simp * @param _dunit the unit number of the device 705160186Simp */ 706160186SimpMETHOD void hinted_child { 707160186Simp device_t _dev; 708185059Sjhb const char *_dname; 709160186Simp int _dunit; 710160186Simp}; 711161928Sjmg 712161928Sjmg/** 713161928Sjmg * @brief Returns bus_dma_tag_t for use w/ devices on the bus. 714161928Sjmg * 715161928Sjmg * @param _dev the parent device of @p _child 716161928Sjmg * @param _child the device to which the tag will belong 717161928Sjmg */ 718161928SjmgMETHOD bus_dma_tag_t get_dma_tag { 719161928Sjmg device_t _dev; 720161928Sjmg device_t _child; 721161928Sjmg} DEFAULT bus_generic_get_dma_tag; 722185059Sjhb 723185059Sjhb/** 724295755Szbb * @brief Returns bus_space_tag_t for use w/ devices on the bus. 725295755Szbb * 726295755Szbb * @param _dev the parent device of @p _child 727295755Szbb * @param _child the device to which the tag will belong 728295755Szbb */ 729295755SzbbMETHOD bus_space_tag_t get_bus_tag { 730295755Szbb device_t _dev; 731295755Szbb device_t _child; 732295755Szbb} DEFAULT bus_generic_get_bus_tag; 733295755Szbb 734295755Szbb/** 735185059Sjhb * @brief Allow the bus to determine the unit number of a device. 736185059Sjhb * 737185059Sjhb * @param _dev the parent device of @p _child 738185059Sjhb * @param _child the device whose unit is to be wired 739185059Sjhb * @param _name the name of the device's new devclass 740185059Sjhb * @param _unitp a pointer to the device's new unit value 741185059Sjhb */ 742185059SjhbMETHOD void hint_device_unit { 743185059Sjhb device_t _dev; 744185059Sjhb device_t _child; 745185059Sjhb const char *_name; 746185059Sjhb int *_unitp; 747185059Sjhb}; 748185059Sjhb 749193833Sjhb/** 750193833Sjhb * @brief Notify a bus that the bus pass level has been changed 751193833Sjhb * 752193833Sjhb * @param _dev the bus device 753193833Sjhb */ 754193833SjhbMETHOD void new_pass { 755193833Sjhb device_t _dev; 756193833Sjhb} DEFAULT bus_generic_new_pass; 757209154Smav 758209154Smav/** 759209154Smav * @brief Notify a bus that specified child's IRQ should be remapped. 760209154Smav * 761209154Smav * @param _dev the bus device 762209154Smav * @param _child the child device 763209154Smav * @param _irq the irq number 764209154Smav */ 765209154SmavMETHOD int remap_intr { 766209154Smav device_t _dev; 767209154Smav device_t _child; 768209154Smav u_int _irq; 769209154Smav} DEFAULT null_remap_intr; 770272013Sjhibbits 771272013Sjhibbits/** 772272013Sjhibbits * @brief Suspend a given child 773272013Sjhibbits * 774272013Sjhibbits * @param _dev the parent device of @p _child 775272013Sjhibbits * @param _child the device to suspend 776272013Sjhibbits */ 777272013SjhibbitsMETHOD int suspend_child { 778272013Sjhibbits device_t _dev; 779272013Sjhibbits device_t _child; 780272013Sjhibbits} DEFAULT bus_generic_suspend_child; 781272013Sjhibbits 782272013Sjhibbits/** 783272013Sjhibbits * @brief Resume a given child 784272013Sjhibbits * 785272013Sjhibbits * @param _dev the parent device of @p _child 786272013Sjhibbits * @param _child the device to resume 787272013Sjhibbits */ 788272013SjhibbitsMETHOD int resume_child { 789272013Sjhibbits device_t _dev; 790272013Sjhibbits device_t _child; 791272013Sjhibbits} DEFAULT bus_generic_resume_child; 792272799Sadrian 793272799Sadrian/** 794272799Sadrian * @brief Get the VM domain handle for the given bus and child. 795272799Sadrian * 796272799Sadrian * @param _dev the bus device 797272799Sadrian * @param _child the child device 798272799Sadrian * @param _domain a pointer to the bus's domain handle identifier 799272799Sadrian */ 800272799SadrianMETHOD int get_domain { 801272799Sadrian device_t _dev; 802272799Sadrian device_t _child; 803272799Sadrian int *_domain; 804272799Sadrian} DEFAULT bus_generic_get_domain; 805299286Sjhb 806299286Sjhb/** 807299286Sjhb * @brief Request a set of CPUs 808299286Sjhb * 809299286Sjhb * @param _dev the bus device 810299286Sjhb * @param _child the child device 811299286Sjhb * @param _op type of CPUs to request 812299286Sjhb * @param _setsize the size of the set passed in _cpuset 813299286Sjhb * @param _cpuset a pointer to a cpuset to receive the requested 814299286Sjhb * set of CPUs 815299286Sjhb */ 816299286SjhbMETHOD int get_cpus { 817299286Sjhb device_t _dev; 818299286Sjhb device_t _child; 819299286Sjhb enum cpu_sets _op; 820299286Sjhb size_t _setsize; 821299286Sjhb cpuset_t *_cpuset; 822299286Sjhb} DEFAULT bus_generic_get_cpus; 823346381Skib 824346381Skib/** 825346381Skib * @brief Prepares the given child of the bus for reset 826346381Skib * 827346381Skib * Typically bus detaches or suspends children' drivers, and then 828346381Skib * calls this method to save bus-specific information, for instance, 829346381Skib * PCI config space, which is damaged by reset. 830346381Skib * 831346381Skib * The bus_helper_reset_prepare() helper is provided to ease 832346381Skib * implementing bus reset methods. 833346381Skib * 834346381Skib * @param _dev the bus device 835346381Skib * @param _child the child device 836346381Skib */ 837346381SkibMETHOD int reset_prepare { 838346381Skib device_t _dev; 839346381Skib device_t _child; 840346381Skib} DEFAULT null_reset_prepare; 841346381Skib 842346381Skib/** 843346381Skib * @brief Restores the child operations after the reset 844346381Skib * 845346381Skib * The bus_helper_reset_post() helper is provided to ease 846346381Skib * implementing bus reset methods. 847346381Skib * 848346381Skib * @param _dev the bus device 849346381Skib * @param _child the child device 850346381Skib */ 851346381SkibMETHOD int reset_post { 852346381Skib device_t _dev; 853346381Skib device_t _child; 854346381Skib} DEFAULT null_reset_post; 855346381Skib 856346381Skib/** 857346381Skib * @brief Performs reset of the child 858346381Skib * 859346381Skib * @param _dev the bus device 860346381Skib * @param _child the child device 861346381Skib * @param _flags DEVF_RESET_ flags 862346381Skib */ 863346381SkibMETHOD int reset_child { 864346381Skib device_t _dev; 865346381Skib device_t _child; 866346381Skib int _flags; 867346381Skib}; 868