xref: /freebsd/sys/kern/bus_if.m (revision dcc8106854ab911281cbeb98d0bff04f50e7531c)
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	}
508b2970bbSDoug Rabson};
518b2970bbSDoug Rabson
524c4392e7SDoug Rabson/**
534c4392e7SDoug Rabson * @brief Print a description of a child device
544c4392e7SDoug Rabson *
554c4392e7SDoug Rabson * This is called from system code which prints out a description of a
564c4392e7SDoug Rabson * device. It should describe the attachment that the child has with
574c4392e7SDoug Rabson * the parent. For instance the TurboLaser bus prints which node the
584c4392e7SDoug Rabson * device is attached to. See bus_generic_print_child() for more
594c4392e7SDoug Rabson * information.
604c4392e7SDoug Rabson *
614c4392e7SDoug Rabson * @param _dev		the device whose child is being printed
624c4392e7SDoug Rabson * @param _child	the child device to describe
634c4392e7SDoug Rabson *
644c4392e7SDoug Rabson * @returns		the number of characters output.
654c4392e7SDoug Rabson */
6615317dd8SMatthew N. DoddMETHOD int print_child {
674c4392e7SDoug Rabson	device_t _dev;
684c4392e7SDoug Rabson	device_t _child;
69c8440669SMatthew N. Dodd} DEFAULT bus_generic_print_child;
70b1bf6610SDoug Rabson
714c4392e7SDoug Rabson/**
724c4392e7SDoug Rabson * @brief Print a notification about an unprobed child device.
734c4392e7SDoug Rabson *
744c4392e7SDoug Rabson * Called for each child device that did not succeed in probing for a
754c4392e7SDoug Rabson * driver.
764c4392e7SDoug Rabson *
774c4392e7SDoug Rabson * @param _dev		the device whose child was being probed
784c4392e7SDoug Rabson * @param _child	the child device which failed to probe
794c4392e7SDoug Rabson */
80ca7036d8SDoug RabsonMETHOD void probe_nomatch {
814c4392e7SDoug Rabson        device_t _dev;
824c4392e7SDoug Rabson        device_t _child;
83ca7036d8SDoug Rabson};
84ca7036d8SDoug Rabson
854c4392e7SDoug Rabson/**
864c4392e7SDoug Rabson * @brief Read the value of a bus-specific attribute of a device
874c4392e7SDoug Rabson *
884c4392e7SDoug Rabson * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
894c4392e7SDoug Rabson * of instance variables of a child device.  The intention is that
904c4392e7SDoug Rabson * each different type of bus defines a set of appropriate instance
914c4392e7SDoug Rabson * variables (such as ports and irqs for ISA bus etc.)
924c4392e7SDoug Rabson *
934c4392e7SDoug Rabson * This information could be given to the child device as a struct but
944c4392e7SDoug Rabson * that makes it hard for a bus to add or remove variables without
954c4392e7SDoug Rabson * forcing an edit and recompile for all drivers which may not be
964c4392e7SDoug Rabson * possible for vendor supplied binary drivers.
974c4392e7SDoug Rabson *
984c4392e7SDoug Rabson * This method copies the value of an instance variable to the
994c4392e7SDoug Rabson * location specified by @p *_result.
1004c4392e7SDoug Rabson *
1014c4392e7SDoug Rabson * @param _dev		the device whose child was being examined
1024c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1034c4392e7SDoug Rabson *			being read
1044c4392e7SDoug Rabson * @param _index	the instance variable to read
1054c4392e7SDoug Rabson * @param _result	a loction to recieve the instance variable
1064c4392e7SDoug Rabson *			value
1074c4392e7SDoug Rabson *
1084c4392e7SDoug Rabson * @retval 0		success
1094c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1104c4392e7SDoug Rabson *			_dev
1114c4392e7SDoug Rabson */
112b1bf6610SDoug RabsonMETHOD int read_ivar {
113bd418641SMark Murray	device_t _dev;
114bd418641SMark Murray	device_t _child;
1154c4392e7SDoug Rabson	int _index;
116bd418641SMark Murray	uintptr_t *_result;
117b1bf6610SDoug Rabson};
118b1bf6610SDoug Rabson
1194c4392e7SDoug Rabson/**
1204c4392e7SDoug Rabson * @brief Write the value of a bus-specific attribute of a device
1214c4392e7SDoug Rabson *
1224c4392e7SDoug Rabson * This method sets the value of an instance variable to @p _value.
1234c4392e7SDoug Rabson *
1244c4392e7SDoug Rabson * @param _dev		the device whose child was being updated
1254c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1264c4392e7SDoug Rabson *			being written
1274c4392e7SDoug Rabson * @param _index	the instance variable to write
1284c4392e7SDoug Rabson * @param _value	the value to write to that instance variable
1294c4392e7SDoug Rabson *
1304c4392e7SDoug Rabson * @retval 0		success
1314c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1324c4392e7SDoug Rabson *			_dev
1334c4392e7SDoug Rabson * @retval EINVAL	the instance variable was recognised but
1344c4392e7SDoug Rabson *			contains a read-only value
1354c4392e7SDoug Rabson */
136b1bf6610SDoug RabsonMETHOD int write_ivar {
137bd418641SMark Murray	device_t _dev;
138bd418641SMark Murray	device_t _child;
139bd418641SMark Murray	int _indx;
140bd418641SMark Murray	uintptr_t _value;
141b1bf6610SDoug Rabson};
142b1bf6610SDoug Rabson
1434c4392e7SDoug Rabson/**
1444c4392e7SDoug Rabson * @brief Notify a bus that a child was detached
1454c4392e7SDoug Rabson *
1464c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent
1474c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child.
1484c4392e7SDoug Rabson *
1494c4392e7SDoug Rabson * @param _dev		the device whose child changed state
1504c4392e7SDoug Rabson * @param _child	the child device which changed state
1514c4392e7SDoug Rabson */
1526350e58aSDoug RabsonMETHOD void child_detached {
153bd418641SMark Murray	device_t _dev;
154bd418641SMark Murray	device_t _child;
1556350e58aSDoug Rabson};
1566350e58aSDoug Rabson
1574c4392e7SDoug Rabson/**
1584c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added
1594c4392e7SDoug Rabson *
1604c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this
1614c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and
1624c4392e7SDoug Rabson * attach any un-matched children of the bus.
1634c4392e7SDoug Rabson *
1644c4392e7SDoug Rabson * @param _dev		the device whose devclass had a new driver
1654c4392e7SDoug Rabson *			added to it
1664c4392e7SDoug Rabson * @param _driver	the new driver which was added
1674c4392e7SDoug Rabson */
1686182fdbdSPeter WemmMETHOD void driver_added {
169bd418641SMark Murray	device_t _dev;
170bd418641SMark Murray	driver_t *_driver;
1716d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added;
1726182fdbdSPeter Wemm
1734c4392e7SDoug Rabson/**
1744c4392e7SDoug Rabson * @brief Create a new child device
1754c4392e7SDoug Rabson *
1764c4392e7SDoug Rabson * For busses which use use drivers supporting DEVICE_IDENTIFY() to
1774c4392e7SDoug Rabson * enumerate their devices, this method is used to create new
1784c4392e7SDoug Rabson * device instances. The new device will be added after the last
1794c4392e7SDoug Rabson * existing child with the same order.
1804c4392e7SDoug Rabson *
1814c4392e7SDoug Rabson * @param _dev		the bus device which will be the parent of the
1824c4392e7SDoug Rabson *			new child device
1834c4392e7SDoug Rabson * @param _order	a value which is used to partially sort the
1844c4392e7SDoug Rabson *			children of @p _dev - devices created using
1854c4392e7SDoug Rabson *			lower values of @p _order appear first in @p
1864c4392e7SDoug Rabson *			_dev's list of children
1874c4392e7SDoug Rabson * @param _name		devclass name for new device or @c NULL if not
1884c4392e7SDoug Rabson *			specified
1894c4392e7SDoug Rabson * @param _unit		unit number for new device or @c -1 if not
1904c4392e7SDoug Rabson *			specified
1914c4392e7SDoug Rabson */
1926c2e3ddeSDoug RabsonMETHOD device_t add_child {
193bd418641SMark Murray	device_t _dev;
194bd418641SMark Murray	int _order;
195bd418641SMark Murray	const char *_name;
196bd418641SMark Murray	int _unit;
1973bb00f61SJohn Baldwin};
1986c2e3ddeSDoug Rabson
1994c4392e7SDoug Rabson/**
2004c4392e7SDoug Rabson * @brief Allocate a system resource
2014c4392e7SDoug Rabson *
2024c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources.
2034c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the
2044c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always
2054c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the
2064c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be
2074c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling
2084c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
2094c4392e7SDoug Rabson *
2104c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2114c4392e7SDoug Rabson * @param _child	the device which is requesting an allocation
2124c4392e7SDoug Rabson * @param _type		the type of resource to allocate
2134c4392e7SDoug Rabson * @param _rid		a pointer to the resource identifier
2144c4392e7SDoug Rabson * @param _start	hint at the start of the resource range - pass
2154c4392e7SDoug Rabson *			@c 0UL for any start address
2164c4392e7SDoug Rabson * @param _end		hint at the end of the resource range - pass
2174c4392e7SDoug Rabson *			@c ~0UL for any end address
2184c4392e7SDoug Rabson * @param _count	hint at the size of range required - pass @c 1
2194c4392e7SDoug Rabson *			for any size
2204c4392e7SDoug Rabson * @param _flags	any extra flags to control the resource
2214c4392e7SDoug Rabson *			allocation - see @c RF_XXX flags in
2224c4392e7SDoug Rabson *			<sys/rman.h> for details
2234c4392e7SDoug Rabson *
2244c4392e7SDoug Rabson * @returns		the resource which was allocated or @c NULL if no
2254c4392e7SDoug Rabson *			resource could be allocated
2264c4392e7SDoug Rabson */
22714177d72SGarrett WollmanMETHOD struct resource * alloc_resource {
228bd418641SMark Murray	device_t	_dev;
229bd418641SMark Murray	device_t	_child;
230bd418641SMark Murray	int		_type;
231bd418641SMark Murray	int	       *_rid;
232bd418641SMark Murray	u_long		_start;
233bd418641SMark Murray	u_long		_end;
234bd418641SMark Murray	u_long		_count;
235bd418641SMark Murray	u_int		_flags;
2368b2970bbSDoug Rabson} DEFAULT null_alloc_resource;
23714177d72SGarrett Wollman
2384c4392e7SDoug Rabson/**
2394c4392e7SDoug Rabson * @brief Activate a resource
2404c4392e7SDoug Rabson *
2414c4392e7SDoug Rabson * Activate a resource previously allocated with
2424c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance map a memory region
2434c4392e7SDoug Rabson * into the kernel's virtual address space.
2444c4392e7SDoug Rabson *
2454c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2464c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2474c4392e7SDoug Rabson * @param _type		the type of resource
2484c4392e7SDoug Rabson * @param _rid		the resource identifier
2494c4392e7SDoug Rabson * @param _r		the resource to activate
2504c4392e7SDoug Rabson */
25114177d72SGarrett WollmanMETHOD int activate_resource {
252bd418641SMark Murray	device_t	_dev;
253bd418641SMark Murray	device_t	_child;
254bd418641SMark Murray	int		_type;
255bd418641SMark Murray	int		_rid;
256bd418641SMark Murray	struct resource *_r;
25714177d72SGarrett Wollman};
25814177d72SGarrett Wollman
2594c4392e7SDoug Rabson/**
2604c4392e7SDoug Rabson * @brief Deactivate a resource
2614c4392e7SDoug Rabson *
2624c4392e7SDoug Rabson * Deactivate a resource previously allocated with
2634c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region
2644c4392e7SDoug Rabson * from the kernel's virtual address space.
2654c4392e7SDoug Rabson *
2664c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2674c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2684c4392e7SDoug Rabson * @param _type		the type of resource
2694c4392e7SDoug Rabson * @param _rid		the resource identifier
2704c4392e7SDoug Rabson * @param _r		the resource to deactivate
2714c4392e7SDoug Rabson */
27214177d72SGarrett WollmanMETHOD int deactivate_resource {
273bd418641SMark Murray	device_t	_dev;
274bd418641SMark Murray	device_t	_child;
275bd418641SMark Murray	int		_type;
276bd418641SMark Murray	int		_rid;
277bd418641SMark Murray	struct resource *_r;
278b1bf6610SDoug Rabson};
27945c95fa1SDoug Rabson
2804c4392e7SDoug Rabson/**
2814c4392e7SDoug Rabson * @brief Release a resource
2824c4392e7SDoug Rabson *
2834c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
2844c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
2854c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed).
2864c4392e7SDoug Rabson *
2874c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2884c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2894c4392e7SDoug Rabson * @param _type		the type of resource
2904c4392e7SDoug Rabson * @param _rid		the resource identifier
2914c4392e7SDoug Rabson * @param _r		the resource to release
2924c4392e7SDoug Rabson */
29314177d72SGarrett WollmanMETHOD int release_resource {
294bd418641SMark Murray	device_t	_dev;
295bd418641SMark Murray	device_t	_child;
296bd418641SMark Murray	int		_type;
297bd418641SMark Murray	int		_rid;
298bd418641SMark Murray	struct resource *_res;
29914177d72SGarrett Wollman};
30014177d72SGarrett Wollman
3014c4392e7SDoug Rabson/**
3024c4392e7SDoug Rabson * @brief Install an interrupt handler
3034c4392e7SDoug Rabson *
3044c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with
3054c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr
3064c4392e7SDoug Rabson * will be called with the value of @p _arg as its single
3074c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the
3084c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a
3094c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR().
3104c4392e7SDoug Rabson *
3114c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3124c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3134c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
3144c4392e7SDoug Rabson * @param _flags	a set of bits from enum intr_type specifying
3154c4392e7SDoug Rabson *			the class of interrupt
3164c4392e7SDoug Rabson * @param _intr		the function to call when the interrupt
3174c4392e7SDoug Rabson *			triggers
3184c4392e7SDoug Rabson * @param _arg		a value to use as the single argument in calls
3194c4392e7SDoug Rabson *			to @p _intr
3204c4392e7SDoug Rabson * @param _cookiep	a pointer to a location to recieve a cookie
3214c4392e7SDoug Rabson *			value that may be used to remove the interrupt
3224c4392e7SDoug Rabson *			handler
3234c4392e7SDoug Rabson */
32414177d72SGarrett WollmanMETHOD int setup_intr {
325bd418641SMark Murray	device_t	_dev;
326bd418641SMark Murray	device_t	_child;
327bd418641SMark Murray	struct resource *_irq;
328bd418641SMark Murray	int		_flags;
329ef544f63SPaolo Pisati	driver_filter_t	*_filter;
330bd418641SMark Murray	driver_intr_t	*_intr;
331bd418641SMark Murray	void		*_arg;
332bd418641SMark Murray	void		**_cookiep;
33314177d72SGarrett Wollman};
33414177d72SGarrett Wollman
3354c4392e7SDoug Rabson/**
3364c4392e7SDoug Rabson * @brief Uninstall an interrupt handler
3374c4392e7SDoug Rabson *
3384c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function
3394c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value
3404c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR().
3414c4392e7SDoug Rabson *
3424c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3434c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3444c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
3454c4392e7SDoug Rabson * @param _cookie	the cookie value returned when the interrupt
3464c4392e7SDoug Rabson *			was originally registered
3474c4392e7SDoug Rabson */
34814177d72SGarrett WollmanMETHOD int teardown_intr {
349bd418641SMark Murray	device_t	_dev;
350bd418641SMark Murray	device_t	_child;
351bd418641SMark Murray	struct resource	*_irq;
352bd418641SMark Murray	void		*_cookie;
35345c95fa1SDoug Rabson};
35425afb89bSDoug Rabson
3554c4392e7SDoug Rabson/**
3564c4392e7SDoug Rabson * @brief Define a resource which can be allocated with
3574c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE().
3584c4392e7SDoug Rabson *
3594c4392e7SDoug Rabson * This method is used by some busses (typically ISA) to allow a
3604c4392e7SDoug Rabson * driver to describe a resource range that it would like to
3614c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined
3624c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its
3634c4392e7SDoug Rabson * range.
3644c4392e7SDoug Rabson *
3654c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3664c4392e7SDoug Rabson * @param _child	the device which owns the resource
3674c4392e7SDoug Rabson * @param _type		the type of resource
3684c4392e7SDoug Rabson * @param _rid		the resource identifier
3694c4392e7SDoug Rabson * @param _start	the start of the resource range
3704c4392e7SDoug Rabson * @param _count	the size of the resource range
3714c4392e7SDoug Rabson */
37225afb89bSDoug RabsonMETHOD int set_resource {
373bd418641SMark Murray	device_t	_dev;
374bd418641SMark Murray	device_t	_child;
375bd418641SMark Murray	int		_type;
376bd418641SMark Murray	int		_rid;
377bd418641SMark Murray	u_long		_start;
378bd418641SMark Murray	u_long		_count;
37925afb89bSDoug Rabson};
38025afb89bSDoug Rabson
3814c4392e7SDoug Rabson/**
3824c4392e7SDoug Rabson * @brief Describe a resource
3834c4392e7SDoug Rabson *
3844c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given
3854c4392e7SDoug Rabson * resource without actually allocating it.
3864c4392e7SDoug Rabson *
3874c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3884c4392e7SDoug Rabson * @param _child	the device which owns the resource
3894c4392e7SDoug Rabson * @param _type		the type of resource
3904c4392e7SDoug Rabson * @param _rid		the resource identifier
3914c4392e7SDoug Rabson * @param _start	the address of a location to recieve the start
3924c4392e7SDoug Rabson *			index of the resource range
3934c4392e7SDoug Rabson * @param _count	the address of a location to recieve the size
3944c4392e7SDoug Rabson *			of the resource range
3954c4392e7SDoug Rabson */
39625afb89bSDoug RabsonMETHOD int get_resource {
397bd418641SMark Murray	device_t	_dev;
398bd418641SMark Murray	device_t	_child;
399bd418641SMark Murray	int		_type;
400bd418641SMark Murray	int		_rid;
401bd418641SMark Murray	u_long		*_startp;
402bd418641SMark Murray	u_long		*_countp;
40325afb89bSDoug Rabson};
40425afb89bSDoug Rabson
4054c4392e7SDoug Rabson/**
4064c4392e7SDoug Rabson * @brief Delete a resource.
4074c4392e7SDoug Rabson *
4084c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with
4094c4392e7SDoug Rabson * BUS_SET_RESOURCE()).
4104c4392e7SDoug Rabson *
4114c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4124c4392e7SDoug Rabson * @param _child	the device which owns the resource
4134c4392e7SDoug Rabson * @param _type		the type of resource
4144c4392e7SDoug Rabson * @param _rid		the resource identifier
4154c4392e7SDoug Rabson */
41625afb89bSDoug RabsonMETHOD void delete_resource {
417bd418641SMark Murray	device_t	_dev;
418bd418641SMark Murray	device_t	_child;
419bd418641SMark Murray	int		_type;
420bd418641SMark Murray	int		_rid;
42125afb89bSDoug Rabson};
4220cb53e24SMatthew N. Dodd
4234c4392e7SDoug Rabson/**
4244c4392e7SDoug Rabson * @brief Return a struct resource_list.
4254c4392e7SDoug Rabson *
4264c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
4274c4392e7SDoug Rabson * implement their resource handling. It should return the resource
4284c4392e7SDoug Rabson * list of the given child device.
4294c4392e7SDoug Rabson *
4304c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4314c4392e7SDoug Rabson * @param _child	the device which owns the resource list
4324c4392e7SDoug Rabson */
43346aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list {
434bd418641SMark Murray	device_t	_dev;
435bd418641SMark Murray	device_t	_child;
4360cb53e24SMatthew N. Dodd} DEFAULT bus_generic_get_resource_list;
4375878eb3fSWarner Losh
4384c4392e7SDoug Rabson/**
4394c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the
4404c4392e7SDoug Rabson * system?
4414c4392e7SDoug Rabson *
4429f7f340aSWarner Losh * This method should return 0 if the device is not present.  It
4439f7f340aSWarner Losh * should return -1 if it is present.  Any errors in determining
4449f7f340aSWarner Losh * should be returned as a normal errno value.  Client drivers are to
4459f7f340aSWarner Losh * assume that the device is present, even if there is an error
4469f7f340aSWarner Losh * determining if it is there.  Busses are to try to avoid returning
4479f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to
4489f7f340aSWarner Losh * implement this method.
4494c4392e7SDoug Rabson *
4504c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4514c4392e7SDoug Rabson * @param _child	the device which is being examined
4524c4392e7SDoug Rabson */
4535878eb3fSWarner LoshMETHOD int child_present {
4545878eb3fSWarner Losh	device_t	_dev;
4555878eb3fSWarner Losh	device_t	_child;
4565878eb3fSWarner Losh} DEFAULT bus_generic_child_present;
4573d9841b4SWarner Losh
4584c4392e7SDoug Rabson/**
4594c4392e7SDoug Rabson * @brief Returns the pnp info for this device.
4604c4392e7SDoug Rabson *
4614c4392e7SDoug Rabson * Return it as a string.  If the string is insufficient for the
4624c4392e7SDoug Rabson * storage, then return EOVERFLOW.
4634c4392e7SDoug Rabson *
4644c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4654c4392e7SDoug Rabson * @param _child	the device which is being examined
4664c4392e7SDoug Rabson * @param _buf		the address of a buffer to receive the pnp
4674c4392e7SDoug Rabson *			string
4684c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
4694c4392e7SDoug Rabson */
4703d9841b4SWarner LoshMETHOD int child_pnpinfo_str {
4713d9841b4SWarner Losh	device_t	_dev;
4723d9841b4SWarner Losh	device_t	_child;
4733d9841b4SWarner Losh	char		*_buf;
4743d9841b4SWarner Losh	size_t		_buflen;
4753d9841b4SWarner Losh};
4763d9841b4SWarner Losh
4774c4392e7SDoug Rabson/**
4784c4392e7SDoug Rabson * @brief Returns the location for this device.
4794c4392e7SDoug Rabson *
4804c4392e7SDoug Rabson * Return it as a string.  If the string is insufficient for the
4814c4392e7SDoug Rabson * storage, then return EOVERFLOW.
4824c4392e7SDoug Rabson *
4834c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4844c4392e7SDoug Rabson * @param _child	the device which is being examined
4854c4392e7SDoug Rabson * @param _buf		the address of a buffer to receive the location
4864c4392e7SDoug Rabson *			string
4874c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
4884c4392e7SDoug Rabson */
4893d9841b4SWarner LoshMETHOD int child_location_str {
4903d9841b4SWarner Losh	device_t	_dev;
4913d9841b4SWarner Losh	device_t	_child;
4923d9841b4SWarner Losh	char		*_buf;
4933d9841b4SWarner Losh	size_t		_buflen;
4943d9841b4SWarner Losh};
495da13b8f9SMarcel Moolenaar
4964c4392e7SDoug Rabson/**
497dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific
498dcc81068SJohn Baldwin * CPU.
499dcc81068SJohn Baldwin *
500dcc81068SJohn Baldwin * @param _dev		the parent device of @p _child
501dcc81068SJohn Baldwin * @param _child	the device which allocated the resource
502dcc81068SJohn Baldwin * @param _irq		the resource representing the interrupt
503dcc81068SJohn Baldwin * @param _cpu		the CPU to bind the interrupt to
504dcc81068SJohn Baldwin */
505dcc81068SJohn BaldwinMETHOD int bind_intr {
506dcc81068SJohn Baldwin	device_t	_dev;
507dcc81068SJohn Baldwin	device_t	_child;
508dcc81068SJohn Baldwin	struct resource *_irq;
509dcc81068SJohn Baldwin	int		_cpu;
510dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr;
511dcc81068SJohn Baldwin
512dcc81068SJohn Baldwin
513dcc81068SJohn Baldwin/**
5144c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity
5154c4392e7SDoug Rabson * of the specified interrupt.
5164c4392e7SDoug Rabson *
5174c4392e7SDoug Rabson * @param _dev		the bus device
5184c4392e7SDoug Rabson * @param _irq		the interrupt number to modify
5194c4392e7SDoug Rabson * @param _trig		the trigger mode required
5204c4392e7SDoug Rabson * @param _pol		the interrupt polarity required
5214c4392e7SDoug Rabson */
522da13b8f9SMarcel MoolenaarMETHOD int config_intr {
523da13b8f9SMarcel Moolenaar	device_t	_dev;
524da13b8f9SMarcel Moolenaar	int		_irq;
525da13b8f9SMarcel Moolenaar	enum intr_trigger _trig;
526da13b8f9SMarcel Moolenaar	enum intr_polarity _pol;
527da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr;
528db2bc1bbSWarner Losh
529db2bc1bbSWarner Losh/**
530db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism
531db2bc1bbSWarner Losh * believes it has discovered.
532db2bc1bbSWarner Losh *
533db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order
534db2bc1bbSWarner Losh * and discovering other things about the child.  The bus driver is
535db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc.  It is all up
536db2bc1bbSWarner Losh * to the bus driver to interpret.
537db2bc1bbSWarner Losh *
538db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for
539db2bc1bbSWarner Losh * hinted devices to be enumerated.
540db2bc1bbSWarner Losh *
541db2bc1bbSWarner Losh * @param _dev		the bus device
542db2bc1bbSWarner Losh * @param _dname	the name of the device w/o unit numbers
543db2bc1bbSWarner Losh * @param _dunit	the unit number of the device
544db2bc1bbSWarner Losh */
545db2bc1bbSWarner LoshMETHOD void hinted_child {
546db2bc1bbSWarner Losh	device_t	_dev;
547db2bc1bbSWarner Losh	const char *	_dname;
548db2bc1bbSWarner Losh	int		_dunit;
549db2bc1bbSWarner Losh};
550378f231eSJohn-Mark Gurney
551378f231eSJohn-Mark Gurney/**
552378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
553378f231eSJohn-Mark Gurney *
554378f231eSJohn-Mark Gurney * @param _dev		the parent device of @p _child
555378f231eSJohn-Mark Gurney * @param _child	the device to which the tag will belong
556378f231eSJohn-Mark Gurney */
557378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag {
558378f231eSJohn-Mark Gurney	device_t	_dev;
559378f231eSJohn-Mark Gurney	device_t	_child;
560378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag;
561