xref: /freebsd/sys/kern/bus_if.m (revision a1c1634858a87a05feee6711d1ba063c3b7d14da)
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
29b7d28b2eSAndriy Gapon#include <sys/types.h>
30b7d28b2eSAndriy Gapon#include <sys/systm.h>
31f7b77691SDoug Rabson#include <sys/bus.h>
32f7b77691SDoug Rabson
334c4392e7SDoug Rabson/**
344c4392e7SDoug Rabson * @defgroup BUS bus - KObj methods for drivers of devices with children
354c4392e7SDoug Rabson * @brief A set of methods required device drivers that support
364c4392e7SDoug Rabson * child devices.
374c4392e7SDoug Rabson * @{
384c4392e7SDoug Rabson */
3931a7daaeSNicolas SouchuINTERFACE bus;
40b1bf6610SDoug Rabson
41b1bf6610SDoug Rabson#
428b2970bbSDoug Rabson# Default implementations of some methods.
438b2970bbSDoug Rabson#
448b2970bbSDoug RabsonCODE {
458b2970bbSDoug Rabson	static struct resource *
468b2970bbSDoug Rabson	null_alloc_resource(device_t dev, device_t child,
475878eb3fSWarner Losh	    int type, int *rid, u_long start, u_long end,
488b2970bbSDoug Rabson	    u_long count, u_int flags)
498b2970bbSDoug Rabson	{
505878eb3fSWarner Losh	    return (0);
518b2970bbSDoug Rabson	}
5293fc07b4SAlexander Motin
5393fc07b4SAlexander Motin	static int
5493fc07b4SAlexander Motin	null_remap_intr(device_t bus, device_t dev, u_int irq)
5593fc07b4SAlexander Motin	{
5693fc07b4SAlexander Motin
5793fc07b4SAlexander Motin		if (dev != NULL)
5893fc07b4SAlexander Motin			return (BUS_REMAP_INTR(dev, NULL, irq));
5993fc07b4SAlexander Motin		return (ENXIO);
6093fc07b4SAlexander Motin	}
61b7d28b2eSAndriy Gapon
62b7d28b2eSAndriy Gapon	static device_t
63b7d28b2eSAndriy Gapon	null_add_child(device_t bus, int order, const char *name,
64b7d28b2eSAndriy Gapon	    int unit)
65b7d28b2eSAndriy Gapon	{
66b7d28b2eSAndriy Gapon
67b7d28b2eSAndriy Gapon		panic("bus_add_child is not implemented");
68b7d28b2eSAndriy Gapon	}
698b2970bbSDoug Rabson};
708b2970bbSDoug Rabson
714c4392e7SDoug Rabson/**
724c4392e7SDoug Rabson * @brief Print a description of a child device
734c4392e7SDoug Rabson *
744c4392e7SDoug Rabson * This is called from system code which prints out a description of a
754c4392e7SDoug Rabson * device. It should describe the attachment that the child has with
764c4392e7SDoug Rabson * the parent. For instance the TurboLaser bus prints which node the
774c4392e7SDoug Rabson * device is attached to. See bus_generic_print_child() for more
784c4392e7SDoug Rabson * information.
794c4392e7SDoug Rabson *
804c4392e7SDoug Rabson * @param _dev		the device whose child is being printed
814c4392e7SDoug Rabson * @param _child	the child device to describe
824c4392e7SDoug Rabson *
834c4392e7SDoug Rabson * @returns		the number of characters output.
844c4392e7SDoug Rabson */
8515317dd8SMatthew N. DoddMETHOD int print_child {
864c4392e7SDoug Rabson	device_t _dev;
874c4392e7SDoug Rabson	device_t _child;
88c8440669SMatthew N. Dodd} DEFAULT bus_generic_print_child;
89b1bf6610SDoug Rabson
904c4392e7SDoug Rabson/**
914c4392e7SDoug Rabson * @brief Print a notification about an unprobed child device.
924c4392e7SDoug Rabson *
934c4392e7SDoug Rabson * Called for each child device that did not succeed in probing for a
944c4392e7SDoug Rabson * driver.
954c4392e7SDoug Rabson *
964c4392e7SDoug Rabson * @param _dev		the device whose child was being probed
974c4392e7SDoug Rabson * @param _child	the child device which failed to probe
984c4392e7SDoug Rabson */
99ca7036d8SDoug RabsonMETHOD void probe_nomatch {
1004c4392e7SDoug Rabson        device_t _dev;
1014c4392e7SDoug Rabson        device_t _child;
102ca7036d8SDoug Rabson};
103ca7036d8SDoug Rabson
1044c4392e7SDoug Rabson/**
1054c4392e7SDoug Rabson * @brief Read the value of a bus-specific attribute of a device
1064c4392e7SDoug Rabson *
1074c4392e7SDoug Rabson * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
1084c4392e7SDoug Rabson * of instance variables of a child device.  The intention is that
1094c4392e7SDoug Rabson * each different type of bus defines a set of appropriate instance
1104c4392e7SDoug Rabson * variables (such as ports and irqs for ISA bus etc.)
1114c4392e7SDoug Rabson *
1124c4392e7SDoug Rabson * This information could be given to the child device as a struct but
1134c4392e7SDoug Rabson * that makes it hard for a bus to add or remove variables without
1144c4392e7SDoug Rabson * forcing an edit and recompile for all drivers which may not be
1154c4392e7SDoug Rabson * possible for vendor supplied binary drivers.
1164c4392e7SDoug Rabson *
1174c4392e7SDoug Rabson * This method copies the value of an instance variable to the
1184c4392e7SDoug Rabson * location specified by @p *_result.
1194c4392e7SDoug Rabson *
1204c4392e7SDoug Rabson * @param _dev		the device whose child was being examined
1214c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1224c4392e7SDoug Rabson *			being read
1234c4392e7SDoug Rabson * @param _index	the instance variable to read
1244c4392e7SDoug Rabson * @param _result	a loction to recieve the instance variable
1254c4392e7SDoug Rabson *			value
1264c4392e7SDoug Rabson *
1274c4392e7SDoug Rabson * @retval 0		success
1284c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1294c4392e7SDoug Rabson *			_dev
1304c4392e7SDoug Rabson */
131b1bf6610SDoug RabsonMETHOD int read_ivar {
132bd418641SMark Murray	device_t _dev;
133bd418641SMark Murray	device_t _child;
1344c4392e7SDoug Rabson	int _index;
135bd418641SMark Murray	uintptr_t *_result;
136b1bf6610SDoug Rabson};
137b1bf6610SDoug Rabson
1384c4392e7SDoug Rabson/**
1394c4392e7SDoug Rabson * @brief Write the value of a bus-specific attribute of a device
1404c4392e7SDoug Rabson *
1414c4392e7SDoug Rabson * This method sets the value of an instance variable to @p _value.
1424c4392e7SDoug Rabson *
1434c4392e7SDoug Rabson * @param _dev		the device whose child was being updated
1444c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1454c4392e7SDoug Rabson *			being written
1464c4392e7SDoug Rabson * @param _index	the instance variable to write
1474c4392e7SDoug Rabson * @param _value	the value to write to that instance variable
1484c4392e7SDoug Rabson *
1494c4392e7SDoug Rabson * @retval 0		success
1504c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1514c4392e7SDoug Rabson *			_dev
1524c4392e7SDoug Rabson * @retval EINVAL	the instance variable was recognised but
1534c4392e7SDoug Rabson *			contains a read-only value
1544c4392e7SDoug Rabson */
155b1bf6610SDoug RabsonMETHOD int write_ivar {
156bd418641SMark Murray	device_t _dev;
157bd418641SMark Murray	device_t _child;
158bd418641SMark Murray	int _indx;
159bd418641SMark Murray	uintptr_t _value;
160b1bf6610SDoug Rabson};
161b1bf6610SDoug Rabson
1624c4392e7SDoug Rabson/**
1636f7d0018SJohn Baldwin * @brief Notify a bus that a child was deleted
1646f7d0018SJohn Baldwin *
1656f7d0018SJohn Baldwin * Called at the beginning of device_delete_child() to allow the parent
1666f7d0018SJohn Baldwin * to teardown any bus-specific state for the child.
1676f7d0018SJohn Baldwin *
1686f7d0018SJohn Baldwin * @param _dev		the device whose child is being deleted
1696f7d0018SJohn Baldwin * @param _child	the child device which is being deleted
1706f7d0018SJohn Baldwin */
1716f7d0018SJohn BaldwinMETHOD void child_deleted {
1726f7d0018SJohn Baldwin	device_t _dev;
1736f7d0018SJohn Baldwin	device_t _child;
1746f7d0018SJohn Baldwin};
1756f7d0018SJohn Baldwin
1766f7d0018SJohn Baldwin/**
1774c4392e7SDoug Rabson * @brief Notify a bus that a child was detached
1784c4392e7SDoug Rabson *
1794c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent
1804c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child.
1814c4392e7SDoug Rabson *
1824c4392e7SDoug Rabson * @param _dev		the device whose child changed state
1834c4392e7SDoug Rabson * @param _child	the child device which changed state
1844c4392e7SDoug Rabson */
1856350e58aSDoug RabsonMETHOD void child_detached {
186bd418641SMark Murray	device_t _dev;
187bd418641SMark Murray	device_t _child;
1886350e58aSDoug Rabson};
1896350e58aSDoug Rabson
1904c4392e7SDoug Rabson/**
1914c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added
1924c4392e7SDoug Rabson *
1934c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this
1944c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and
1954c4392e7SDoug Rabson * attach any un-matched children of the bus.
1964c4392e7SDoug Rabson *
1974c4392e7SDoug Rabson * @param _dev		the device whose devclass had a new driver
1984c4392e7SDoug Rabson *			added to it
1994c4392e7SDoug Rabson * @param _driver	the new driver which was added
2004c4392e7SDoug Rabson */
2016182fdbdSPeter WemmMETHOD void driver_added {
202bd418641SMark Murray	device_t _dev;
203bd418641SMark Murray	driver_t *_driver;
2046d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added;
2056182fdbdSPeter Wemm
2064c4392e7SDoug Rabson/**
2074c4392e7SDoug Rabson * @brief Create a new child device
2084c4392e7SDoug Rabson *
2094c4392e7SDoug Rabson * For busses which use use drivers supporting DEVICE_IDENTIFY() to
2104c4392e7SDoug Rabson * enumerate their devices, this method is used to create new
2114c4392e7SDoug Rabson * device instances. The new device will be added after the last
2124c4392e7SDoug Rabson * existing child with the same order.
2134c4392e7SDoug Rabson *
2144c4392e7SDoug Rabson * @param _dev		the bus device which will be the parent of the
2154c4392e7SDoug Rabson *			new child device
2164c4392e7SDoug Rabson * @param _order	a value which is used to partially sort the
2174c4392e7SDoug Rabson *			children of @p _dev - devices created using
2184c4392e7SDoug Rabson *			lower values of @p _order appear first in @p
2194c4392e7SDoug Rabson *			_dev's list of children
2204c4392e7SDoug Rabson * @param _name		devclass name for new device or @c NULL if not
2214c4392e7SDoug Rabson *			specified
2224c4392e7SDoug Rabson * @param _unit		unit number for new device or @c -1 if not
2234c4392e7SDoug Rabson *			specified
2244c4392e7SDoug Rabson */
2256c2e3ddeSDoug RabsonMETHOD device_t add_child {
226bd418641SMark Murray	device_t _dev;
2273d844eddSAndriy Gapon	u_int _order;
228bd418641SMark Murray	const char *_name;
229bd418641SMark Murray	int _unit;
230b7d28b2eSAndriy Gapon} DEFAULT null_add_child;
2316c2e3ddeSDoug Rabson
2324c4392e7SDoug Rabson/**
2334c4392e7SDoug Rabson * @brief Allocate a system resource
2344c4392e7SDoug Rabson *
2354c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources.
2364c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the
2374c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always
2384c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the
2394c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be
2404c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling
2414c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
2424c4392e7SDoug Rabson *
2434c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2444c4392e7SDoug Rabson * @param _child	the device which is requesting an allocation
2454c4392e7SDoug Rabson * @param _type		the type of resource to allocate
2464c4392e7SDoug Rabson * @param _rid		a pointer to the resource identifier
2474c4392e7SDoug Rabson * @param _start	hint at the start of the resource range - pass
2484c4392e7SDoug Rabson *			@c 0UL for any start address
2494c4392e7SDoug Rabson * @param _end		hint at the end of the resource range - pass
2504c4392e7SDoug Rabson *			@c ~0UL for any end address
2514c4392e7SDoug Rabson * @param _count	hint at the size of range required - pass @c 1
2524c4392e7SDoug Rabson *			for any size
2534c4392e7SDoug Rabson * @param _flags	any extra flags to control the resource
2544c4392e7SDoug Rabson *			allocation - see @c RF_XXX flags in
2554c4392e7SDoug Rabson *			<sys/rman.h> for details
2564c4392e7SDoug Rabson *
2574c4392e7SDoug Rabson * @returns		the resource which was allocated or @c NULL if no
2584c4392e7SDoug Rabson *			resource could be allocated
2594c4392e7SDoug Rabson */
26014177d72SGarrett WollmanMETHOD struct resource * alloc_resource {
261bd418641SMark Murray	device_t	_dev;
262bd418641SMark Murray	device_t	_child;
263bd418641SMark Murray	int		_type;
264bd418641SMark Murray	int	       *_rid;
265bd418641SMark Murray	u_long		_start;
266bd418641SMark Murray	u_long		_end;
267bd418641SMark Murray	u_long		_count;
268bd418641SMark Murray	u_int		_flags;
2698b2970bbSDoug Rabson} DEFAULT null_alloc_resource;
27014177d72SGarrett Wollman
2714c4392e7SDoug Rabson/**
2724c4392e7SDoug Rabson * @brief Activate a resource
2734c4392e7SDoug Rabson *
2744c4392e7SDoug Rabson * Activate a resource previously allocated with
2754c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance map a memory region
2764c4392e7SDoug Rabson * into the kernel's virtual address space.
2774c4392e7SDoug Rabson *
2784c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2794c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2804c4392e7SDoug Rabson * @param _type		the type of resource
2814c4392e7SDoug Rabson * @param _rid		the resource identifier
2824c4392e7SDoug Rabson * @param _r		the resource to activate
2834c4392e7SDoug Rabson */
28414177d72SGarrett WollmanMETHOD int activate_resource {
285bd418641SMark Murray	device_t	_dev;
286bd418641SMark Murray	device_t	_child;
287bd418641SMark Murray	int		_type;
288bd418641SMark Murray	int		_rid;
289bd418641SMark Murray	struct resource *_r;
29014177d72SGarrett Wollman};
29114177d72SGarrett Wollman
2924c4392e7SDoug Rabson/**
2934c4392e7SDoug Rabson * @brief Deactivate a resource
2944c4392e7SDoug Rabson *
2954c4392e7SDoug Rabson * Deactivate a resource previously allocated with
2964c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region
2974c4392e7SDoug Rabson * from the kernel's virtual address space.
2984c4392e7SDoug Rabson *
2994c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3004c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3014c4392e7SDoug Rabson * @param _type		the type of resource
3024c4392e7SDoug Rabson * @param _rid		the resource identifier
3034c4392e7SDoug Rabson * @param _r		the resource to deactivate
3044c4392e7SDoug Rabson */
30514177d72SGarrett WollmanMETHOD int deactivate_resource {
306bd418641SMark Murray	device_t	_dev;
307bd418641SMark Murray	device_t	_child;
308bd418641SMark Murray	int		_type;
309bd418641SMark Murray	int		_rid;
310bd418641SMark Murray	struct resource *_r;
311b1bf6610SDoug Rabson};
31245c95fa1SDoug Rabson
3134c4392e7SDoug Rabson/**
31485ee63c9SJohn Baldwin * @brief Adjust a resource
31585ee63c9SJohn Baldwin *
31685ee63c9SJohn Baldwin * Adjust the start and/or end of a resource allocated by
31785ee63c9SJohn Baldwin * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
31885ee63c9SJohn Baldwin * with the existing address range.  If the successful, the resource's range
31985ee63c9SJohn Baldwin * will be adjusted to [start, end] on return.
32085ee63c9SJohn Baldwin *
32185ee63c9SJohn Baldwin * @param _dev		the parent device of @p _child
32285ee63c9SJohn Baldwin * @param _child	the device which allocated the resource
32385ee63c9SJohn Baldwin * @param _type		the type of resource
32485ee63c9SJohn Baldwin * @param _res		the resource to adjust
32585ee63c9SJohn Baldwin * @param _start	the new starting address of the resource range
32685ee63c9SJohn Baldwin * @param _end		the new ending address of the resource range
32785ee63c9SJohn Baldwin */
32885ee63c9SJohn BaldwinMETHOD int adjust_resource {
32985ee63c9SJohn Baldwin	device_t	_dev;
33085ee63c9SJohn Baldwin	device_t	_child;
33185ee63c9SJohn Baldwin	int		_type;
33285ee63c9SJohn Baldwin	struct resource *_res;
33385ee63c9SJohn Baldwin	u_long		_start;
33485ee63c9SJohn Baldwin	u_long		_end;
33585ee63c9SJohn Baldwin};
33685ee63c9SJohn Baldwin
33785ee63c9SJohn Baldwin/**
3384c4392e7SDoug Rabson * @brief Release a resource
3394c4392e7SDoug Rabson *
3404c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
3414c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
3424c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed).
3434c4392e7SDoug Rabson *
3444c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3454c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3464c4392e7SDoug Rabson * @param _type		the type of resource
3474c4392e7SDoug Rabson * @param _rid		the resource identifier
3484c4392e7SDoug Rabson * @param _r		the resource to release
3494c4392e7SDoug Rabson */
35014177d72SGarrett WollmanMETHOD int release_resource {
351bd418641SMark Murray	device_t	_dev;
352bd418641SMark Murray	device_t	_child;
353bd418641SMark Murray	int		_type;
354bd418641SMark Murray	int		_rid;
355bd418641SMark Murray	struct resource *_res;
35614177d72SGarrett Wollman};
35714177d72SGarrett Wollman
3584c4392e7SDoug Rabson/**
3594c4392e7SDoug Rabson * @brief Install an interrupt handler
3604c4392e7SDoug Rabson *
3614c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with
3624c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr
3634c4392e7SDoug Rabson * will be called with the value of @p _arg as its single
3644c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the
3654c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a
3664c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR().
3674c4392e7SDoug Rabson *
3684c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3694c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3704c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
3714c4392e7SDoug Rabson * @param _flags	a set of bits from enum intr_type specifying
3724c4392e7SDoug Rabson *			the class of interrupt
3734c4392e7SDoug Rabson * @param _intr		the function to call when the interrupt
3744c4392e7SDoug Rabson *			triggers
3754c4392e7SDoug Rabson * @param _arg		a value to use as the single argument in calls
3764c4392e7SDoug Rabson *			to @p _intr
3774c4392e7SDoug Rabson * @param _cookiep	a pointer to a location to recieve a cookie
3784c4392e7SDoug Rabson *			value that may be used to remove the interrupt
3794c4392e7SDoug Rabson *			handler
3804c4392e7SDoug Rabson */
38114177d72SGarrett WollmanMETHOD int setup_intr {
382bd418641SMark Murray	device_t	_dev;
383bd418641SMark Murray	device_t	_child;
384bd418641SMark Murray	struct resource *_irq;
385bd418641SMark Murray	int		_flags;
386ef544f63SPaolo Pisati	driver_filter_t	*_filter;
387bd418641SMark Murray	driver_intr_t	*_intr;
388bd418641SMark Murray	void		*_arg;
389bd418641SMark Murray	void		**_cookiep;
39014177d72SGarrett Wollman};
39114177d72SGarrett Wollman
3924c4392e7SDoug Rabson/**
3934c4392e7SDoug Rabson * @brief Uninstall an interrupt handler
3944c4392e7SDoug Rabson *
3954c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function
3964c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value
3974c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR().
3984c4392e7SDoug Rabson *
3994c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4004c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4014c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
4024c4392e7SDoug Rabson * @param _cookie	the cookie value returned when the interrupt
4034c4392e7SDoug Rabson *			was originally registered
4044c4392e7SDoug Rabson */
40514177d72SGarrett WollmanMETHOD int teardown_intr {
406bd418641SMark Murray	device_t	_dev;
407bd418641SMark Murray	device_t	_child;
408bd418641SMark Murray	struct resource	*_irq;
409bd418641SMark Murray	void		*_cookie;
41045c95fa1SDoug Rabson};
41125afb89bSDoug Rabson
4124c4392e7SDoug Rabson/**
4134c4392e7SDoug Rabson * @brief Define a resource which can be allocated with
4144c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE().
4154c4392e7SDoug Rabson *
4164c4392e7SDoug Rabson * This method is used by some busses (typically ISA) to allow a
4174c4392e7SDoug Rabson * driver to describe a resource range that it would like to
4184c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined
4194c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its
4204c4392e7SDoug Rabson * range.
4214c4392e7SDoug Rabson *
4224c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4234c4392e7SDoug Rabson * @param _child	the device which owns the resource
4244c4392e7SDoug Rabson * @param _type		the type of resource
4254c4392e7SDoug Rabson * @param _rid		the resource identifier
4264c4392e7SDoug Rabson * @param _start	the start of the resource range
4274c4392e7SDoug Rabson * @param _count	the size of the resource range
4284c4392e7SDoug Rabson */
42925afb89bSDoug RabsonMETHOD int set_resource {
430bd418641SMark Murray	device_t	_dev;
431bd418641SMark Murray	device_t	_child;
432bd418641SMark Murray	int		_type;
433bd418641SMark Murray	int		_rid;
434bd418641SMark Murray	u_long		_start;
435bd418641SMark Murray	u_long		_count;
43625afb89bSDoug Rabson};
43725afb89bSDoug Rabson
4384c4392e7SDoug Rabson/**
4394c4392e7SDoug Rabson * @brief Describe a resource
4404c4392e7SDoug Rabson *
4414c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given
4424c4392e7SDoug Rabson * resource without actually allocating it.
4434c4392e7SDoug Rabson *
4444c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4454c4392e7SDoug Rabson * @param _child	the device which owns the resource
4464c4392e7SDoug Rabson * @param _type		the type of resource
4474c4392e7SDoug Rabson * @param _rid		the resource identifier
4484c4392e7SDoug Rabson * @param _start	the address of a location to recieve the start
4494c4392e7SDoug Rabson *			index of the resource range
4504c4392e7SDoug Rabson * @param _count	the address of a location to recieve the size
4514c4392e7SDoug Rabson *			of the resource range
4524c4392e7SDoug Rabson */
45325afb89bSDoug RabsonMETHOD int get_resource {
454bd418641SMark Murray	device_t	_dev;
455bd418641SMark Murray	device_t	_child;
456bd418641SMark Murray	int		_type;
457bd418641SMark Murray	int		_rid;
458bd418641SMark Murray	u_long		*_startp;
459bd418641SMark Murray	u_long		*_countp;
46025afb89bSDoug Rabson};
46125afb89bSDoug Rabson
4624c4392e7SDoug Rabson/**
4634c4392e7SDoug Rabson * @brief Delete a resource.
4644c4392e7SDoug Rabson *
4654c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with
4664c4392e7SDoug Rabson * BUS_SET_RESOURCE()).
4674c4392e7SDoug Rabson *
4684c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4694c4392e7SDoug Rabson * @param _child	the device which owns the resource
4704c4392e7SDoug Rabson * @param _type		the type of resource
4714c4392e7SDoug Rabson * @param _rid		the resource identifier
4724c4392e7SDoug Rabson */
47325afb89bSDoug RabsonMETHOD void delete_resource {
474bd418641SMark Murray	device_t	_dev;
475bd418641SMark Murray	device_t	_child;
476bd418641SMark Murray	int		_type;
477bd418641SMark Murray	int		_rid;
47825afb89bSDoug Rabson};
4790cb53e24SMatthew N. Dodd
4804c4392e7SDoug Rabson/**
4814c4392e7SDoug Rabson * @brief Return a struct resource_list.
4824c4392e7SDoug Rabson *
4834c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
4844c4392e7SDoug Rabson * implement their resource handling. It should return the resource
4854c4392e7SDoug Rabson * list of the given child device.
4864c4392e7SDoug Rabson *
4874c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4884c4392e7SDoug Rabson * @param _child	the device which owns the resource list
4894c4392e7SDoug Rabson */
49046aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list {
491bd418641SMark Murray	device_t	_dev;
492bd418641SMark Murray	device_t	_child;
4930cb53e24SMatthew N. Dodd} DEFAULT bus_generic_get_resource_list;
4945878eb3fSWarner Losh
4954c4392e7SDoug Rabson/**
4964c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the
4974c4392e7SDoug Rabson * system?
4984c4392e7SDoug Rabson *
4999f7f340aSWarner Losh * This method should return 0 if the device is not present.  It
5009f7f340aSWarner Losh * should return -1 if it is present.  Any errors in determining
5019f7f340aSWarner Losh * should be returned as a normal errno value.  Client drivers are to
5029f7f340aSWarner Losh * assume that the device is present, even if there is an error
5039f7f340aSWarner Losh * determining if it is there.  Busses are to try to avoid returning
5049f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to
5059f7f340aSWarner Losh * implement this method.
5064c4392e7SDoug Rabson *
5074c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5084c4392e7SDoug Rabson * @param _child	the device which is being examined
5094c4392e7SDoug Rabson */
5105878eb3fSWarner LoshMETHOD int child_present {
5115878eb3fSWarner Losh	device_t	_dev;
5125878eb3fSWarner Losh	device_t	_child;
5135878eb3fSWarner Losh} DEFAULT bus_generic_child_present;
5143d9841b4SWarner Losh
5154c4392e7SDoug Rabson/**
5164c4392e7SDoug Rabson * @brief Returns the pnp info for this device.
5174c4392e7SDoug Rabson *
5184c4392e7SDoug Rabson * Return it as a string.  If the string is insufficient for the
5194c4392e7SDoug Rabson * storage, then return EOVERFLOW.
5204c4392e7SDoug Rabson *
5214c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5224c4392e7SDoug Rabson * @param _child	the device which is being examined
5234c4392e7SDoug Rabson * @param _buf		the address of a buffer to receive the pnp
5244c4392e7SDoug Rabson *			string
5254c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
5264c4392e7SDoug Rabson */
5273d9841b4SWarner LoshMETHOD int child_pnpinfo_str {
5283d9841b4SWarner Losh	device_t	_dev;
5293d9841b4SWarner Losh	device_t	_child;
5303d9841b4SWarner Losh	char		*_buf;
5313d9841b4SWarner Losh	size_t		_buflen;
5323d9841b4SWarner Losh};
5333d9841b4SWarner Losh
5344c4392e7SDoug Rabson/**
5354c4392e7SDoug Rabson * @brief Returns the location for this device.
5364c4392e7SDoug Rabson *
5374c4392e7SDoug Rabson * Return it as a string.  If the string is insufficient for the
5384c4392e7SDoug Rabson * storage, then return EOVERFLOW.
5394c4392e7SDoug Rabson *
5404c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5414c4392e7SDoug Rabson * @param _child	the device which is being examined
5424c4392e7SDoug Rabson * @param _buf		the address of a buffer to receive the location
5434c4392e7SDoug Rabson *			string
5444c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
5454c4392e7SDoug Rabson */
5463d9841b4SWarner LoshMETHOD int child_location_str {
5473d9841b4SWarner Losh	device_t	_dev;
5483d9841b4SWarner Losh	device_t	_child;
5493d9841b4SWarner Losh	char		*_buf;
5503d9841b4SWarner Losh	size_t		_buflen;
5513d9841b4SWarner Losh};
552da13b8f9SMarcel Moolenaar
5534c4392e7SDoug Rabson/**
554dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific
555dcc81068SJohn Baldwin * CPU.
556dcc81068SJohn Baldwin *
557dcc81068SJohn Baldwin * @param _dev		the parent device of @p _child
558dcc81068SJohn Baldwin * @param _child	the device which allocated the resource
559dcc81068SJohn Baldwin * @param _irq		the resource representing the interrupt
560dcc81068SJohn Baldwin * @param _cpu		the CPU to bind the interrupt to
561dcc81068SJohn Baldwin */
562dcc81068SJohn BaldwinMETHOD int bind_intr {
563dcc81068SJohn Baldwin	device_t	_dev;
564dcc81068SJohn Baldwin	device_t	_child;
565dcc81068SJohn Baldwin	struct resource *_irq;
566dcc81068SJohn Baldwin	int		_cpu;
567dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr;
568dcc81068SJohn Baldwin
569dcc81068SJohn Baldwin/**
5704c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity
5714c4392e7SDoug Rabson * of the specified interrupt.
5724c4392e7SDoug Rabson *
5734c4392e7SDoug Rabson * @param _dev		the bus device
5744c4392e7SDoug Rabson * @param _irq		the interrupt number to modify
5754c4392e7SDoug Rabson * @param _trig		the trigger mode required
5764c4392e7SDoug Rabson * @param _pol		the interrupt polarity required
5774c4392e7SDoug Rabson */
578da13b8f9SMarcel MoolenaarMETHOD int config_intr {
579da13b8f9SMarcel Moolenaar	device_t	_dev;
580da13b8f9SMarcel Moolenaar	int		_irq;
581da13b8f9SMarcel Moolenaar	enum intr_trigger _trig;
582da13b8f9SMarcel Moolenaar	enum intr_polarity _pol;
583da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr;
584db2bc1bbSWarner Losh
585db2bc1bbSWarner Losh/**
58637b8ef16SJohn Baldwin * @brief Allow drivers to associate a description with an active
58737b8ef16SJohn Baldwin * interrupt handler.
58837b8ef16SJohn Baldwin *
58937b8ef16SJohn Baldwin * @param _dev		the parent device of @p _child
59037b8ef16SJohn Baldwin * @param _child	the device which allocated the resource
59137b8ef16SJohn Baldwin * @param _irq		the resource representing the interrupt
59237b8ef16SJohn Baldwin * @param _cookie	the cookie value returned when the interrupt
59337b8ef16SJohn Baldwin *			was originally registered
59437b8ef16SJohn Baldwin * @param _descr	the description to associate with the interrupt
59537b8ef16SJohn Baldwin */
59637b8ef16SJohn BaldwinMETHOD int describe_intr {
59737b8ef16SJohn Baldwin	device_t	_dev;
59837b8ef16SJohn Baldwin	device_t	_child;
59937b8ef16SJohn Baldwin	struct resource *_irq;
60037b8ef16SJohn Baldwin	void		*_cookie;
60137b8ef16SJohn Baldwin	const char	*_descr;
60237b8ef16SJohn Baldwin} DEFAULT bus_generic_describe_intr;
60337b8ef16SJohn Baldwin
60437b8ef16SJohn Baldwin/**
605db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism
606db2bc1bbSWarner Losh * believes it has discovered.
607db2bc1bbSWarner Losh *
608db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order
609db2bc1bbSWarner Losh * and discovering other things about the child.  The bus driver is
610db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc.  It is all up
611db2bc1bbSWarner Losh * to the bus driver to interpret.
612db2bc1bbSWarner Losh *
613db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for
614db2bc1bbSWarner Losh * hinted devices to be enumerated.
615db2bc1bbSWarner Losh *
616db2bc1bbSWarner Losh * @param _dev		the bus device
617db2bc1bbSWarner Losh * @param _dname	the name of the device w/o unit numbers
618db2bc1bbSWarner Losh * @param _dunit	the unit number of the device
619db2bc1bbSWarner Losh */
620db2bc1bbSWarner LoshMETHOD void hinted_child {
621db2bc1bbSWarner Losh	device_t	_dev;
622db2bc1bbSWarner Losh	const char	*_dname;
623db2bc1bbSWarner Losh	int		_dunit;
624db2bc1bbSWarner Losh};
625378f231eSJohn-Mark Gurney
626378f231eSJohn-Mark Gurney/**
627378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
628378f231eSJohn-Mark Gurney *
629378f231eSJohn-Mark Gurney * @param _dev		the parent device of @p _child
630378f231eSJohn-Mark Gurney * @param _child	the device to which the tag will belong
631378f231eSJohn-Mark Gurney */
632378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag {
633378f231eSJohn-Mark Gurney	device_t	_dev;
634378f231eSJohn-Mark Gurney	device_t	_child;
635378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag;
6360d484d24SJohn Baldwin
6370d484d24SJohn Baldwin/**
6380d484d24SJohn Baldwin * @brief Allow the bus to determine the unit number of a device.
6390d484d24SJohn Baldwin *
6400d484d24SJohn Baldwin * @param _dev		the parent device of @p _child
6410d484d24SJohn Baldwin * @param _child	the device whose unit is to be wired
6420d484d24SJohn Baldwin * @param _name		the name of the device's new devclass
6430d484d24SJohn Baldwin * @param _unitp	a pointer to the device's new unit value
6440d484d24SJohn Baldwin */
6450d484d24SJohn BaldwinMETHOD void hint_device_unit {
6460d484d24SJohn Baldwin	device_t	_dev;
6470d484d24SJohn Baldwin	device_t	_child;
6480d484d24SJohn Baldwin	const char	*_name;
6490d484d24SJohn Baldwin	int		*_unitp;
6500d484d24SJohn Baldwin};
6510d484d24SJohn Baldwin
6524ef60d26SJohn Baldwin/**
6534ef60d26SJohn Baldwin * @brief Notify a bus that the bus pass level has been changed
6544ef60d26SJohn Baldwin *
6554ef60d26SJohn Baldwin * @param _dev		the bus device
6564ef60d26SJohn Baldwin */
6574ef60d26SJohn BaldwinMETHOD void new_pass {
6584ef60d26SJohn Baldwin	device_t	_dev;
6594ef60d26SJohn Baldwin} DEFAULT bus_generic_new_pass;
66093fc07b4SAlexander Motin
66193fc07b4SAlexander Motin/**
66293fc07b4SAlexander Motin * @brief Notify a bus that specified child's IRQ should be remapped.
66393fc07b4SAlexander Motin *
66493fc07b4SAlexander Motin * @param _dev		the bus device
66593fc07b4SAlexander Motin * @param _child	the child device
66693fc07b4SAlexander Motin * @param _irq		the irq number
66793fc07b4SAlexander Motin */
66893fc07b4SAlexander MotinMETHOD int remap_intr {
66993fc07b4SAlexander Motin	device_t	_dev;
67093fc07b4SAlexander Motin	device_t	_child;
67193fc07b4SAlexander Motin	u_int		_irq;
67293fc07b4SAlexander Motin} DEFAULT null_remap_intr;
673*a1c16348SJustin Hibbits
674*a1c16348SJustin Hibbits/**
675*a1c16348SJustin Hibbits * @brief Suspend a given child
676*a1c16348SJustin Hibbits *
677*a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
678*a1c16348SJustin Hibbits * @param _child	the device to suspend
679*a1c16348SJustin Hibbits */
680*a1c16348SJustin HibbitsMETHOD int suspend_child {
681*a1c16348SJustin Hibbits	device_t	_dev;
682*a1c16348SJustin Hibbits	device_t	_child;
683*a1c16348SJustin Hibbits} DEFAULT bus_generic_suspend_child;
684*a1c16348SJustin Hibbits
685*a1c16348SJustin Hibbits/**
686*a1c16348SJustin Hibbits * @brief Resume a given child
687*a1c16348SJustin Hibbits *
688*a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
689*a1c16348SJustin Hibbits * @param _child	the device to resume
690*a1c16348SJustin Hibbits */
691*a1c16348SJustin HibbitsMETHOD int resume_child {
692*a1c16348SJustin Hibbits	device_t	_dev;
693*a1c16348SJustin Hibbits	device_t	_child;
694*a1c16348SJustin Hibbits} DEFAULT bus_generic_resume_child;
695