xref: /freebsd/sys/kern/bus_if.m (revision b7d28b2e0b39e28d5f7f35c66be2ab81de3cc75c)
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
29*b7d28b2eSAndriy Gapon#include <sys/types.h>
30*b7d28b2eSAndriy 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	}
61*b7d28b2eSAndriy Gapon
62*b7d28b2eSAndriy Gapon	static device_t
63*b7d28b2eSAndriy Gapon	null_add_child(device_t bus, int order, const char *name,
64*b7d28b2eSAndriy Gapon	    int unit)
65*b7d28b2eSAndriy Gapon	{
66*b7d28b2eSAndriy Gapon
67*b7d28b2eSAndriy Gapon		panic("bus_add_child is not implemented");
68*b7d28b2eSAndriy 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/**
1634c4392e7SDoug Rabson * @brief Notify a bus that a child was detached
1644c4392e7SDoug Rabson *
1654c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent
1664c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child.
1674c4392e7SDoug Rabson *
1684c4392e7SDoug Rabson * @param _dev		the device whose child changed state
1694c4392e7SDoug Rabson * @param _child	the child device which changed state
1704c4392e7SDoug Rabson */
1716350e58aSDoug RabsonMETHOD void child_detached {
172bd418641SMark Murray	device_t _dev;
173bd418641SMark Murray	device_t _child;
1746350e58aSDoug Rabson};
1756350e58aSDoug Rabson
1764c4392e7SDoug Rabson/**
1774c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added
1784c4392e7SDoug Rabson *
1794c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this
1804c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and
1814c4392e7SDoug Rabson * attach any un-matched children of the bus.
1824c4392e7SDoug Rabson *
1834c4392e7SDoug Rabson * @param _dev		the device whose devclass had a new driver
1844c4392e7SDoug Rabson *			added to it
1854c4392e7SDoug Rabson * @param _driver	the new driver which was added
1864c4392e7SDoug Rabson */
1876182fdbdSPeter WemmMETHOD void driver_added {
188bd418641SMark Murray	device_t _dev;
189bd418641SMark Murray	driver_t *_driver;
1906d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added;
1916182fdbdSPeter Wemm
1924c4392e7SDoug Rabson/**
1934c4392e7SDoug Rabson * @brief Create a new child device
1944c4392e7SDoug Rabson *
1954c4392e7SDoug Rabson * For busses which use use drivers supporting DEVICE_IDENTIFY() to
1964c4392e7SDoug Rabson * enumerate their devices, this method is used to create new
1974c4392e7SDoug Rabson * device instances. The new device will be added after the last
1984c4392e7SDoug Rabson * existing child with the same order.
1994c4392e7SDoug Rabson *
2004c4392e7SDoug Rabson * @param _dev		the bus device which will be the parent of the
2014c4392e7SDoug Rabson *			new child device
2024c4392e7SDoug Rabson * @param _order	a value which is used to partially sort the
2034c4392e7SDoug Rabson *			children of @p _dev - devices created using
2044c4392e7SDoug Rabson *			lower values of @p _order appear first in @p
2054c4392e7SDoug Rabson *			_dev's list of children
2064c4392e7SDoug Rabson * @param _name		devclass name for new device or @c NULL if not
2074c4392e7SDoug Rabson *			specified
2084c4392e7SDoug Rabson * @param _unit		unit number for new device or @c -1 if not
2094c4392e7SDoug Rabson *			specified
2104c4392e7SDoug Rabson */
2116c2e3ddeSDoug RabsonMETHOD device_t add_child {
212bd418641SMark Murray	device_t _dev;
2133d844eddSAndriy Gapon	u_int _order;
214bd418641SMark Murray	const char *_name;
215bd418641SMark Murray	int _unit;
216*b7d28b2eSAndriy Gapon} DEFAULT null_add_child;
2176c2e3ddeSDoug Rabson
2184c4392e7SDoug Rabson/**
2194c4392e7SDoug Rabson * @brief Allocate a system resource
2204c4392e7SDoug Rabson *
2214c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources.
2224c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the
2234c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always
2244c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the
2254c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be
2264c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling
2274c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
2284c4392e7SDoug Rabson *
2294c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2304c4392e7SDoug Rabson * @param _child	the device which is requesting an allocation
2314c4392e7SDoug Rabson * @param _type		the type of resource to allocate
2324c4392e7SDoug Rabson * @param _rid		a pointer to the resource identifier
2334c4392e7SDoug Rabson * @param _start	hint at the start of the resource range - pass
2344c4392e7SDoug Rabson *			@c 0UL for any start address
2354c4392e7SDoug Rabson * @param _end		hint at the end of the resource range - pass
2364c4392e7SDoug Rabson *			@c ~0UL for any end address
2374c4392e7SDoug Rabson * @param _count	hint at the size of range required - pass @c 1
2384c4392e7SDoug Rabson *			for any size
2394c4392e7SDoug Rabson * @param _flags	any extra flags to control the resource
2404c4392e7SDoug Rabson *			allocation - see @c RF_XXX flags in
2414c4392e7SDoug Rabson *			<sys/rman.h> for details
2424c4392e7SDoug Rabson *
2434c4392e7SDoug Rabson * @returns		the resource which was allocated or @c NULL if no
2444c4392e7SDoug Rabson *			resource could be allocated
2454c4392e7SDoug Rabson */
24614177d72SGarrett WollmanMETHOD struct resource * alloc_resource {
247bd418641SMark Murray	device_t	_dev;
248bd418641SMark Murray	device_t	_child;
249bd418641SMark Murray	int		_type;
250bd418641SMark Murray	int	       *_rid;
251bd418641SMark Murray	u_long		_start;
252bd418641SMark Murray	u_long		_end;
253bd418641SMark Murray	u_long		_count;
254bd418641SMark Murray	u_int		_flags;
2558b2970bbSDoug Rabson} DEFAULT null_alloc_resource;
25614177d72SGarrett Wollman
2574c4392e7SDoug Rabson/**
2584c4392e7SDoug Rabson * @brief Activate a resource
2594c4392e7SDoug Rabson *
2604c4392e7SDoug Rabson * Activate a resource previously allocated with
2614c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance map a memory region
2624c4392e7SDoug Rabson * into the kernel's virtual address space.
2634c4392e7SDoug Rabson *
2644c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2654c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2664c4392e7SDoug Rabson * @param _type		the type of resource
2674c4392e7SDoug Rabson * @param _rid		the resource identifier
2684c4392e7SDoug Rabson * @param _r		the resource to activate
2694c4392e7SDoug Rabson */
27014177d72SGarrett WollmanMETHOD int activate_resource {
271bd418641SMark Murray	device_t	_dev;
272bd418641SMark Murray	device_t	_child;
273bd418641SMark Murray	int		_type;
274bd418641SMark Murray	int		_rid;
275bd418641SMark Murray	struct resource *_r;
27614177d72SGarrett Wollman};
27714177d72SGarrett Wollman
2784c4392e7SDoug Rabson/**
2794c4392e7SDoug Rabson * @brief Deactivate a resource
2804c4392e7SDoug Rabson *
2814c4392e7SDoug Rabson * Deactivate a resource previously allocated with
2824c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region
2834c4392e7SDoug Rabson * from the kernel's virtual address space.
2844c4392e7SDoug Rabson *
2854c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2864c4392e7SDoug Rabson * @param _child	the device which allocated the resource
2874c4392e7SDoug Rabson * @param _type		the type of resource
2884c4392e7SDoug Rabson * @param _rid		the resource identifier
2894c4392e7SDoug Rabson * @param _r		the resource to deactivate
2904c4392e7SDoug Rabson */
29114177d72SGarrett WollmanMETHOD int deactivate_resource {
292bd418641SMark Murray	device_t	_dev;
293bd418641SMark Murray	device_t	_child;
294bd418641SMark Murray	int		_type;
295bd418641SMark Murray	int		_rid;
296bd418641SMark Murray	struct resource *_r;
297b1bf6610SDoug Rabson};
29845c95fa1SDoug Rabson
2994c4392e7SDoug Rabson/**
3004c4392e7SDoug Rabson * @brief Release a resource
3014c4392e7SDoug Rabson *
3024c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
3034c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
3044c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed).
3054c4392e7SDoug Rabson *
3064c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3074c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3084c4392e7SDoug Rabson * @param _type		the type of resource
3094c4392e7SDoug Rabson * @param _rid		the resource identifier
3104c4392e7SDoug Rabson * @param _r		the resource to release
3114c4392e7SDoug Rabson */
31214177d72SGarrett WollmanMETHOD int release_resource {
313bd418641SMark Murray	device_t	_dev;
314bd418641SMark Murray	device_t	_child;
315bd418641SMark Murray	int		_type;
316bd418641SMark Murray	int		_rid;
317bd418641SMark Murray	struct resource *_res;
31814177d72SGarrett Wollman};
31914177d72SGarrett Wollman
3204c4392e7SDoug Rabson/**
3214c4392e7SDoug Rabson * @brief Install an interrupt handler
3224c4392e7SDoug Rabson *
3234c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with
3244c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr
3254c4392e7SDoug Rabson * will be called with the value of @p _arg as its single
3264c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the
3274c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a
3284c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR().
3294c4392e7SDoug Rabson *
3304c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3314c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3324c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
3334c4392e7SDoug Rabson * @param _flags	a set of bits from enum intr_type specifying
3344c4392e7SDoug Rabson *			the class of interrupt
3354c4392e7SDoug Rabson * @param _intr		the function to call when the interrupt
3364c4392e7SDoug Rabson *			triggers
3374c4392e7SDoug Rabson * @param _arg		a value to use as the single argument in calls
3384c4392e7SDoug Rabson *			to @p _intr
3394c4392e7SDoug Rabson * @param _cookiep	a pointer to a location to recieve a cookie
3404c4392e7SDoug Rabson *			value that may be used to remove the interrupt
3414c4392e7SDoug Rabson *			handler
3424c4392e7SDoug Rabson */
34314177d72SGarrett WollmanMETHOD int setup_intr {
344bd418641SMark Murray	device_t	_dev;
345bd418641SMark Murray	device_t	_child;
346bd418641SMark Murray	struct resource *_irq;
347bd418641SMark Murray	int		_flags;
348ef544f63SPaolo Pisati	driver_filter_t	*_filter;
349bd418641SMark Murray	driver_intr_t	*_intr;
350bd418641SMark Murray	void		*_arg;
351bd418641SMark Murray	void		**_cookiep;
35214177d72SGarrett Wollman};
35314177d72SGarrett Wollman
3544c4392e7SDoug Rabson/**
3554c4392e7SDoug Rabson * @brief Uninstall an interrupt handler
3564c4392e7SDoug Rabson *
3574c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function
3584c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value
3594c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR().
3604c4392e7SDoug Rabson *
3614c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3624c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3634c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
3644c4392e7SDoug Rabson * @param _cookie	the cookie value returned when the interrupt
3654c4392e7SDoug Rabson *			was originally registered
3664c4392e7SDoug Rabson */
36714177d72SGarrett WollmanMETHOD int teardown_intr {
368bd418641SMark Murray	device_t	_dev;
369bd418641SMark Murray	device_t	_child;
370bd418641SMark Murray	struct resource	*_irq;
371bd418641SMark Murray	void		*_cookie;
37245c95fa1SDoug Rabson};
37325afb89bSDoug Rabson
3744c4392e7SDoug Rabson/**
3754c4392e7SDoug Rabson * @brief Define a resource which can be allocated with
3764c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE().
3774c4392e7SDoug Rabson *
3784c4392e7SDoug Rabson * This method is used by some busses (typically ISA) to allow a
3794c4392e7SDoug Rabson * driver to describe a resource range that it would like to
3804c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined
3814c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its
3824c4392e7SDoug Rabson * range.
3834c4392e7SDoug Rabson *
3844c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3854c4392e7SDoug Rabson * @param _child	the device which owns the resource
3864c4392e7SDoug Rabson * @param _type		the type of resource
3874c4392e7SDoug Rabson * @param _rid		the resource identifier
3884c4392e7SDoug Rabson * @param _start	the start of the resource range
3894c4392e7SDoug Rabson * @param _count	the size of the resource range
3904c4392e7SDoug Rabson */
39125afb89bSDoug RabsonMETHOD int set_resource {
392bd418641SMark Murray	device_t	_dev;
393bd418641SMark Murray	device_t	_child;
394bd418641SMark Murray	int		_type;
395bd418641SMark Murray	int		_rid;
396bd418641SMark Murray	u_long		_start;
397bd418641SMark Murray	u_long		_count;
39825afb89bSDoug Rabson};
39925afb89bSDoug Rabson
4004c4392e7SDoug Rabson/**
4014c4392e7SDoug Rabson * @brief Describe a resource
4024c4392e7SDoug Rabson *
4034c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given
4044c4392e7SDoug Rabson * resource without actually allocating it.
4054c4392e7SDoug Rabson *
4064c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4074c4392e7SDoug Rabson * @param _child	the device which owns the resource
4084c4392e7SDoug Rabson * @param _type		the type of resource
4094c4392e7SDoug Rabson * @param _rid		the resource identifier
4104c4392e7SDoug Rabson * @param _start	the address of a location to recieve the start
4114c4392e7SDoug Rabson *			index of the resource range
4124c4392e7SDoug Rabson * @param _count	the address of a location to recieve the size
4134c4392e7SDoug Rabson *			of the resource range
4144c4392e7SDoug Rabson */
41525afb89bSDoug RabsonMETHOD int get_resource {
416bd418641SMark Murray	device_t	_dev;
417bd418641SMark Murray	device_t	_child;
418bd418641SMark Murray	int		_type;
419bd418641SMark Murray	int		_rid;
420bd418641SMark Murray	u_long		*_startp;
421bd418641SMark Murray	u_long		*_countp;
42225afb89bSDoug Rabson};
42325afb89bSDoug Rabson
4244c4392e7SDoug Rabson/**
4254c4392e7SDoug Rabson * @brief Delete a resource.
4264c4392e7SDoug Rabson *
4274c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with
4284c4392e7SDoug Rabson * BUS_SET_RESOURCE()).
4294c4392e7SDoug Rabson *
4304c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4314c4392e7SDoug Rabson * @param _child	the device which owns the resource
4324c4392e7SDoug Rabson * @param _type		the type of resource
4334c4392e7SDoug Rabson * @param _rid		the resource identifier
4344c4392e7SDoug Rabson */
43525afb89bSDoug RabsonMETHOD void delete_resource {
436bd418641SMark Murray	device_t	_dev;
437bd418641SMark Murray	device_t	_child;
438bd418641SMark Murray	int		_type;
439bd418641SMark Murray	int		_rid;
44025afb89bSDoug Rabson};
4410cb53e24SMatthew N. Dodd
4424c4392e7SDoug Rabson/**
4434c4392e7SDoug Rabson * @brief Return a struct resource_list.
4444c4392e7SDoug Rabson *
4454c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
4464c4392e7SDoug Rabson * implement their resource handling. It should return the resource
4474c4392e7SDoug Rabson * list of the given child device.
4484c4392e7SDoug Rabson *
4494c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4504c4392e7SDoug Rabson * @param _child	the device which owns the resource list
4514c4392e7SDoug Rabson */
45246aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list {
453bd418641SMark Murray	device_t	_dev;
454bd418641SMark Murray	device_t	_child;
4550cb53e24SMatthew N. Dodd} DEFAULT bus_generic_get_resource_list;
4565878eb3fSWarner Losh
4574c4392e7SDoug Rabson/**
4584c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the
4594c4392e7SDoug Rabson * system?
4604c4392e7SDoug Rabson *
4619f7f340aSWarner Losh * This method should return 0 if the device is not present.  It
4629f7f340aSWarner Losh * should return -1 if it is present.  Any errors in determining
4639f7f340aSWarner Losh * should be returned as a normal errno value.  Client drivers are to
4649f7f340aSWarner Losh * assume that the device is present, even if there is an error
4659f7f340aSWarner Losh * determining if it is there.  Busses are to try to avoid returning
4669f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to
4679f7f340aSWarner Losh * implement this method.
4684c4392e7SDoug Rabson *
4694c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4704c4392e7SDoug Rabson * @param _child	the device which is being examined
4714c4392e7SDoug Rabson */
4725878eb3fSWarner LoshMETHOD int child_present {
4735878eb3fSWarner Losh	device_t	_dev;
4745878eb3fSWarner Losh	device_t	_child;
4755878eb3fSWarner Losh} DEFAULT bus_generic_child_present;
4763d9841b4SWarner Losh
4774c4392e7SDoug Rabson/**
4784c4392e7SDoug Rabson * @brief Returns the pnp info 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 pnp
4864c4392e7SDoug Rabson *			string
4874c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
4884c4392e7SDoug Rabson */
4893d9841b4SWarner LoshMETHOD int child_pnpinfo_str {
4903d9841b4SWarner Losh	device_t	_dev;
4913d9841b4SWarner Losh	device_t	_child;
4923d9841b4SWarner Losh	char		*_buf;
4933d9841b4SWarner Losh	size_t		_buflen;
4943d9841b4SWarner Losh};
4953d9841b4SWarner Losh
4964c4392e7SDoug Rabson/**
4974c4392e7SDoug Rabson * @brief Returns the location for this device.
4984c4392e7SDoug Rabson *
4994c4392e7SDoug Rabson * Return it as a string.  If the string is insufficient for the
5004c4392e7SDoug Rabson * storage, then return EOVERFLOW.
5014c4392e7SDoug Rabson *
5024c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5034c4392e7SDoug Rabson * @param _child	the device which is being examined
5044c4392e7SDoug Rabson * @param _buf		the address of a buffer to receive the location
5054c4392e7SDoug Rabson *			string
5064c4392e7SDoug Rabson * @param _buflen	the size of the buffer pointed to by @p _buf
5074c4392e7SDoug Rabson */
5083d9841b4SWarner LoshMETHOD int child_location_str {
5093d9841b4SWarner Losh	device_t	_dev;
5103d9841b4SWarner Losh	device_t	_child;
5113d9841b4SWarner Losh	char		*_buf;
5123d9841b4SWarner Losh	size_t		_buflen;
5133d9841b4SWarner Losh};
514da13b8f9SMarcel Moolenaar
5154c4392e7SDoug Rabson/**
516dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific
517dcc81068SJohn Baldwin * CPU.
518dcc81068SJohn Baldwin *
519dcc81068SJohn Baldwin * @param _dev		the parent device of @p _child
520dcc81068SJohn Baldwin * @param _child	the device which allocated the resource
521dcc81068SJohn Baldwin * @param _irq		the resource representing the interrupt
522dcc81068SJohn Baldwin * @param _cpu		the CPU to bind the interrupt to
523dcc81068SJohn Baldwin */
524dcc81068SJohn BaldwinMETHOD int bind_intr {
525dcc81068SJohn Baldwin	device_t	_dev;
526dcc81068SJohn Baldwin	device_t	_child;
527dcc81068SJohn Baldwin	struct resource *_irq;
528dcc81068SJohn Baldwin	int		_cpu;
529dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr;
530dcc81068SJohn Baldwin
531dcc81068SJohn Baldwin/**
5324c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity
5334c4392e7SDoug Rabson * of the specified interrupt.
5344c4392e7SDoug Rabson *
5354c4392e7SDoug Rabson * @param _dev		the bus device
5364c4392e7SDoug Rabson * @param _irq		the interrupt number to modify
5374c4392e7SDoug Rabson * @param _trig		the trigger mode required
5384c4392e7SDoug Rabson * @param _pol		the interrupt polarity required
5394c4392e7SDoug Rabson */
540da13b8f9SMarcel MoolenaarMETHOD int config_intr {
541da13b8f9SMarcel Moolenaar	device_t	_dev;
542da13b8f9SMarcel Moolenaar	int		_irq;
543da13b8f9SMarcel Moolenaar	enum intr_trigger _trig;
544da13b8f9SMarcel Moolenaar	enum intr_polarity _pol;
545da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr;
546db2bc1bbSWarner Losh
547db2bc1bbSWarner Losh/**
54837b8ef16SJohn Baldwin * @brief Allow drivers to associate a description with an active
54937b8ef16SJohn Baldwin * interrupt handler.
55037b8ef16SJohn Baldwin *
55137b8ef16SJohn Baldwin * @param _dev		the parent device of @p _child
55237b8ef16SJohn Baldwin * @param _child	the device which allocated the resource
55337b8ef16SJohn Baldwin * @param _irq		the resource representing the interrupt
55437b8ef16SJohn Baldwin * @param _cookie	the cookie value returned when the interrupt
55537b8ef16SJohn Baldwin *			was originally registered
55637b8ef16SJohn Baldwin * @param _descr	the description to associate with the interrupt
55737b8ef16SJohn Baldwin */
55837b8ef16SJohn BaldwinMETHOD int describe_intr {
55937b8ef16SJohn Baldwin	device_t	_dev;
56037b8ef16SJohn Baldwin	device_t	_child;
56137b8ef16SJohn Baldwin	struct resource *_irq;
56237b8ef16SJohn Baldwin	void		*_cookie;
56337b8ef16SJohn Baldwin	const char	*_descr;
56437b8ef16SJohn Baldwin} DEFAULT bus_generic_describe_intr;
56537b8ef16SJohn Baldwin
56637b8ef16SJohn Baldwin/**
567db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism
568db2bc1bbSWarner Losh * believes it has discovered.
569db2bc1bbSWarner Losh *
570db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order
571db2bc1bbSWarner Losh * and discovering other things about the child.  The bus driver is
572db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc.  It is all up
573db2bc1bbSWarner Losh * to the bus driver to interpret.
574db2bc1bbSWarner Losh *
575db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for
576db2bc1bbSWarner Losh * hinted devices to be enumerated.
577db2bc1bbSWarner Losh *
578db2bc1bbSWarner Losh * @param _dev		the bus device
579db2bc1bbSWarner Losh * @param _dname	the name of the device w/o unit numbers
580db2bc1bbSWarner Losh * @param _dunit	the unit number of the device
581db2bc1bbSWarner Losh */
582db2bc1bbSWarner LoshMETHOD void hinted_child {
583db2bc1bbSWarner Losh	device_t	_dev;
584db2bc1bbSWarner Losh	const char	*_dname;
585db2bc1bbSWarner Losh	int		_dunit;
586db2bc1bbSWarner Losh};
587378f231eSJohn-Mark Gurney
588378f231eSJohn-Mark Gurney/**
589378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
590378f231eSJohn-Mark Gurney *
591378f231eSJohn-Mark Gurney * @param _dev		the parent device of @p _child
592378f231eSJohn-Mark Gurney * @param _child	the device to which the tag will belong
593378f231eSJohn-Mark Gurney */
594378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag {
595378f231eSJohn-Mark Gurney	device_t	_dev;
596378f231eSJohn-Mark Gurney	device_t	_child;
597378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag;
5980d484d24SJohn Baldwin
5990d484d24SJohn Baldwin/**
6000d484d24SJohn Baldwin * @brief Allow the bus to determine the unit number of a device.
6010d484d24SJohn Baldwin *
6020d484d24SJohn Baldwin * @param _dev		the parent device of @p _child
6030d484d24SJohn Baldwin * @param _child	the device whose unit is to be wired
6040d484d24SJohn Baldwin * @param _name		the name of the device's new devclass
6050d484d24SJohn Baldwin * @param _unitp	a pointer to the device's new unit value
6060d484d24SJohn Baldwin */
6070d484d24SJohn BaldwinMETHOD void hint_device_unit {
6080d484d24SJohn Baldwin	device_t	_dev;
6090d484d24SJohn Baldwin	device_t	_child;
6100d484d24SJohn Baldwin	const char	*_name;
6110d484d24SJohn Baldwin	int		*_unitp;
6120d484d24SJohn Baldwin};
6130d484d24SJohn Baldwin
6144ef60d26SJohn Baldwin/**
6154ef60d26SJohn Baldwin * @brief Notify a bus that the bus pass level has been changed
6164ef60d26SJohn Baldwin *
6174ef60d26SJohn Baldwin * @param _dev		the bus device
6184ef60d26SJohn Baldwin */
6194ef60d26SJohn BaldwinMETHOD void new_pass {
6204ef60d26SJohn Baldwin	device_t	_dev;
6214ef60d26SJohn Baldwin} DEFAULT bus_generic_new_pass;
62293fc07b4SAlexander Motin
62393fc07b4SAlexander Motin/**
62493fc07b4SAlexander Motin * @brief Notify a bus that specified child's IRQ should be remapped.
62593fc07b4SAlexander Motin *
62693fc07b4SAlexander Motin * @param _dev		the bus device
62793fc07b4SAlexander Motin * @param _child	the child device
62893fc07b4SAlexander Motin * @param _irq		the irq number
62993fc07b4SAlexander Motin */
63093fc07b4SAlexander MotinMETHOD int remap_intr {
63193fc07b4SAlexander Motin	device_t	_dev;
63293fc07b4SAlexander Motin	device_t	_child;
63393fc07b4SAlexander Motin	u_int		_irq;
63493fc07b4SAlexander Motin} DEFAULT null_remap_intr;
635