xref: /freebsd/sys/kern/bus_if.m (revision 7030980bc9aa62aaf25ffab44e24af854c57a9b1)
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#
26b1bf6610SDoug Rabson#
27b1bf6610SDoug Rabson
28b7d28b2eSAndriy Gapon#include <sys/types.h>
29b7d28b2eSAndriy Gapon#include <sys/systm.h>
30f7b77691SDoug Rabson#include <sys/bus.h>
31f7b77691SDoug Rabson
324c4392e7SDoug Rabson/**
334c4392e7SDoug Rabson * @defgroup BUS bus - KObj methods for drivers of devices with children
344c4392e7SDoug Rabson * @brief A set of methods required device drivers that support
354c4392e7SDoug Rabson * child devices.
364c4392e7SDoug Rabson * @{
374c4392e7SDoug Rabson */
3831a7daaeSNicolas SouchuINTERFACE bus;
39b1bf6610SDoug Rabson
40b1bf6610SDoug Rabson#
418b2970bbSDoug Rabson# Default implementations of some methods.
428b2970bbSDoug Rabson#
438b2970bbSDoug RabsonCODE {
448b2970bbSDoug Rabson	static struct resource *
458b2970bbSDoug Rabson	null_alloc_resource(device_t dev, device_t child,
462dd1bdf1SJustin Hibbits	    int type, int *rid, rman_res_t start, rman_res_t end,
472dd1bdf1SJustin Hibbits	    rman_res_t count, u_int flags)
488b2970bbSDoug Rabson	{
495878eb3fSWarner Losh	    return (0);
508b2970bbSDoug Rabson	}
5193fc07b4SAlexander Motin
5293fc07b4SAlexander Motin	static int
5393fc07b4SAlexander Motin	null_remap_intr(device_t bus, device_t dev, u_int irq)
5493fc07b4SAlexander Motin	{
5593fc07b4SAlexander Motin
5693fc07b4SAlexander Motin		if (dev != NULL)
5793fc07b4SAlexander Motin			return (BUS_REMAP_INTR(dev, NULL, irq));
5893fc07b4SAlexander Motin		return (ENXIO);
5993fc07b4SAlexander Motin	}
60b7d28b2eSAndriy Gapon
61b7d28b2eSAndriy Gapon	static device_t
62b7d28b2eSAndriy Gapon	null_add_child(device_t bus, int order, const char *name,
63b7d28b2eSAndriy Gapon	    int unit)
64b7d28b2eSAndriy Gapon	{
65b7d28b2eSAndriy Gapon
66*7030980bSBjoern A. Zeeb		panic("%s: bus_add_child is not implemented, name '%s', "
67*7030980bSBjoern A. Zeeb		    "unit %d", device_get_nameunit(bus), name, unit);
68b7d28b2eSAndriy Gapon	}
69c53df6daSKonstantin Belousov
7036a8572eSMitchell Horne	static int
7136a8572eSMitchell Horne	null_reset_post(device_t bus, device_t dev)
72c53df6daSKonstantin Belousov	{
73c53df6daSKonstantin Belousov		return (0);
74c53df6daSKonstantin Belousov	}
75c53df6daSKonstantin Belousov
7636a8572eSMitchell Horne	static int
7736a8572eSMitchell Horne	null_reset_prepare(device_t bus, device_t dev)
78c53df6daSKonstantin Belousov	{
79c53df6daSKonstantin Belousov		return (0);
80c53df6daSKonstantin Belousov	}
81751615c5SJohn Baldwin
82751615c5SJohn Baldwin	static struct rman *
83751615c5SJohn Baldwin	null_get_rman(device_t bus, int type, u_int flags)
84751615c5SJohn Baldwin	{
85751615c5SJohn Baldwin		return (NULL);
86751615c5SJohn Baldwin	}
878b2970bbSDoug Rabson};
888b2970bbSDoug Rabson
894c4392e7SDoug Rabson/**
904c4392e7SDoug Rabson * @brief Print a description of a child device
914c4392e7SDoug Rabson *
924c4392e7SDoug Rabson * This is called from system code which prints out a description of a
934c4392e7SDoug Rabson * device. It should describe the attachment that the child has with
944c4392e7SDoug Rabson * the parent. For instance the TurboLaser bus prints which node the
954c4392e7SDoug Rabson * device is attached to. See bus_generic_print_child() for more
964c4392e7SDoug Rabson * information.
974c4392e7SDoug Rabson *
984c4392e7SDoug Rabson * @param _dev		the device whose child is being printed
994c4392e7SDoug Rabson * @param _child	the child device to describe
1004c4392e7SDoug Rabson *
1014c4392e7SDoug Rabson * @returns		the number of characters output.
1024c4392e7SDoug Rabson */
10315317dd8SMatthew N. DoddMETHOD int print_child {
1044c4392e7SDoug Rabson	device_t _dev;
1054c4392e7SDoug Rabson	device_t _child;
106c8440669SMatthew N. Dodd} DEFAULT bus_generic_print_child;
107b1bf6610SDoug Rabson
1084c4392e7SDoug Rabson/**
1094c4392e7SDoug Rabson * @brief Print a notification about an unprobed child device.
1104c4392e7SDoug Rabson *
1114c4392e7SDoug Rabson * Called for each child device that did not succeed in probing for a
1124c4392e7SDoug Rabson * driver.
1134c4392e7SDoug Rabson *
1144c4392e7SDoug Rabson * @param _dev		the device whose child was being probed
1154c4392e7SDoug Rabson * @param _child	the child device which failed to probe
1164c4392e7SDoug Rabson */
117ca7036d8SDoug RabsonMETHOD void probe_nomatch {
1184c4392e7SDoug Rabson        device_t _dev;
1194c4392e7SDoug Rabson        device_t _child;
120ca7036d8SDoug Rabson};
121ca7036d8SDoug Rabson
1224c4392e7SDoug Rabson/**
1234c4392e7SDoug Rabson * @brief Read the value of a bus-specific attribute of a device
1244c4392e7SDoug Rabson *
1254c4392e7SDoug Rabson * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
1264c4392e7SDoug Rabson * of instance variables of a child device.  The intention is that
1274c4392e7SDoug Rabson * each different type of bus defines a set of appropriate instance
1284c4392e7SDoug Rabson * variables (such as ports and irqs for ISA bus etc.)
1294c4392e7SDoug Rabson *
1304c4392e7SDoug Rabson * This information could be given to the child device as a struct but
1314c4392e7SDoug Rabson * that makes it hard for a bus to add or remove variables without
1324c4392e7SDoug Rabson * forcing an edit and recompile for all drivers which may not be
1334c4392e7SDoug Rabson * possible for vendor supplied binary drivers.
1344c4392e7SDoug Rabson *
1354c4392e7SDoug Rabson * This method copies the value of an instance variable to the
1364c4392e7SDoug Rabson * location specified by @p *_result.
1374c4392e7SDoug Rabson *
1384c4392e7SDoug Rabson * @param _dev		the device whose child was being examined
1394c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1404c4392e7SDoug Rabson *			being read
1414c4392e7SDoug Rabson * @param _index	the instance variable to read
142e3043798SPedro F. Giffuni * @param _result	a location to receive the instance variable
1434c4392e7SDoug Rabson *			value
1444c4392e7SDoug Rabson *
1454c4392e7SDoug Rabson * @retval 0		success
1464c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1474c4392e7SDoug Rabson *			_dev
1484c4392e7SDoug Rabson */
149b1bf6610SDoug RabsonMETHOD int read_ivar {
150bd418641SMark Murray	device_t _dev;
151bd418641SMark Murray	device_t _child;
1524c4392e7SDoug Rabson	int _index;
153bd418641SMark Murray	uintptr_t *_result;
154b1bf6610SDoug Rabson};
155b1bf6610SDoug Rabson
1564c4392e7SDoug Rabson/**
1574c4392e7SDoug Rabson * @brief Write the value of a bus-specific attribute of a device
1584c4392e7SDoug Rabson *
1594c4392e7SDoug Rabson * This method sets the value of an instance variable to @p _value.
1604c4392e7SDoug Rabson *
1614c4392e7SDoug Rabson * @param _dev		the device whose child was being updated
1624c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1634c4392e7SDoug Rabson *			being written
1644c4392e7SDoug Rabson * @param _index	the instance variable to write
1654c4392e7SDoug Rabson * @param _value	the value to write to that instance variable
1664c4392e7SDoug Rabson *
1674c4392e7SDoug Rabson * @retval 0		success
1684c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1694c4392e7SDoug Rabson *			_dev
1704c4392e7SDoug Rabson * @retval EINVAL	the instance variable was recognised but
1714c4392e7SDoug Rabson *			contains a read-only value
1724c4392e7SDoug Rabson */
173b1bf6610SDoug RabsonMETHOD int write_ivar {
174bd418641SMark Murray	device_t _dev;
175bd418641SMark Murray	device_t _child;
176bd418641SMark Murray	int _indx;
177bd418641SMark Murray	uintptr_t _value;
178b1bf6610SDoug Rabson};
179b1bf6610SDoug Rabson
1804c4392e7SDoug Rabson/**
1816f7d0018SJohn Baldwin * @brief Notify a bus that a child was deleted
1826f7d0018SJohn Baldwin *
1836f7d0018SJohn Baldwin * Called at the beginning of device_delete_child() to allow the parent
1846f7d0018SJohn Baldwin * to teardown any bus-specific state for the child.
1856f7d0018SJohn Baldwin *
1866f7d0018SJohn Baldwin * @param _dev		the device whose child is being deleted
1876f7d0018SJohn Baldwin * @param _child	the child device which is being deleted
1886f7d0018SJohn Baldwin */
1896f7d0018SJohn BaldwinMETHOD void child_deleted {
1906f7d0018SJohn Baldwin	device_t _dev;
1916f7d0018SJohn Baldwin	device_t _child;
1926f7d0018SJohn Baldwin};
1936f7d0018SJohn Baldwin
1946f7d0018SJohn Baldwin/**
1954c4392e7SDoug Rabson * @brief Notify a bus that a child was detached
1964c4392e7SDoug Rabson *
1974c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent
1984c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child.
1994c4392e7SDoug Rabson *
2004c4392e7SDoug Rabson * @param _dev		the device whose child changed state
2014c4392e7SDoug Rabson * @param _child	the child device which changed state
2024c4392e7SDoug Rabson */
2036350e58aSDoug RabsonMETHOD void child_detached {
204bd418641SMark Murray	device_t _dev;
205bd418641SMark Murray	device_t _child;
2066350e58aSDoug Rabson};
2076350e58aSDoug Rabson
2084c4392e7SDoug Rabson/**
2094c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added
2104c4392e7SDoug Rabson *
2114c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this
2124c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and
2134c4392e7SDoug Rabson * attach any un-matched children of the bus.
2144c4392e7SDoug Rabson *
2154c4392e7SDoug Rabson * @param _dev		the device whose devclass had a new driver
2164c4392e7SDoug Rabson *			added to it
2174c4392e7SDoug Rabson * @param _driver	the new driver which was added
2184c4392e7SDoug Rabson */
2196182fdbdSPeter WemmMETHOD void driver_added {
220bd418641SMark Murray	device_t _dev;
221bd418641SMark Murray	driver_t *_driver;
2226d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added;
2236182fdbdSPeter Wemm
2244c4392e7SDoug Rabson/**
2254c4392e7SDoug Rabson * @brief Create a new child device
2264c4392e7SDoug Rabson *
227db4fcadfSConrad Meyer * For buses which use use drivers supporting DEVICE_IDENTIFY() to
2284c4392e7SDoug Rabson * enumerate their devices, this method is used to create new
2294c4392e7SDoug Rabson * device instances. The new device will be added after the last
23083a283cfSWarner Losh * existing child with the same order. Implementations of bus_add_child
23183a283cfSWarner Losh * call device_add_child_ordered to add the child and often add
23283a283cfSWarner Losh * a suitable ivar to the device specific to that bus.
2334c4392e7SDoug Rabson *
2344c4392e7SDoug Rabson * @param _dev		the bus device which will be the parent of the
2354c4392e7SDoug Rabson *			new child device
2364c4392e7SDoug Rabson * @param _order	a value which is used to partially sort the
2374c4392e7SDoug Rabson *			children of @p _dev - devices created using
2384c4392e7SDoug Rabson *			lower values of @p _order appear first in @p
2394c4392e7SDoug Rabson *			_dev's list of children
2404c4392e7SDoug Rabson * @param _name		devclass name for new device or @c NULL if not
2414c4392e7SDoug Rabson *			specified
2424c4392e7SDoug Rabson * @param _unit		unit number for new device or @c -1 if not
2434c4392e7SDoug Rabson *			specified
2444c4392e7SDoug Rabson */
2456c2e3ddeSDoug RabsonMETHOD device_t add_child {
246bd418641SMark Murray	device_t _dev;
2473d844eddSAndriy Gapon	u_int _order;
248bd418641SMark Murray	const char *_name;
249bd418641SMark Murray	int _unit;
250b7d28b2eSAndriy Gapon} DEFAULT null_add_child;
2516c2e3ddeSDoug Rabson
2524c4392e7SDoug Rabson/**
253a907c691SJohn Baldwin * @brief Rescan the bus
254a907c691SJohn Baldwin *
255a907c691SJohn Baldwin * This method is called by a parent bridge or devctl to trigger a bus
256a907c691SJohn Baldwin * rescan.  The rescan should delete devices no longer present and
257a907c691SJohn Baldwin * enumerate devices that have newly arrived.
258a907c691SJohn Baldwin *
259a907c691SJohn Baldwin * @param _dev		the bus device
260a907c691SJohn Baldwin */
261a907c691SJohn BaldwinMETHOD int rescan {
262a907c691SJohn Baldwin	device_t _dev;
26329afffb9SMitchell Horne} DEFAULT bus_null_rescan;
264a907c691SJohn Baldwin
265a907c691SJohn Baldwin/**
2664c4392e7SDoug Rabson * @brief Allocate a system resource
2674c4392e7SDoug Rabson *
2684c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources.
2694c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the
2704c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always
2714c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the
2724c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be
2734c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling
2744c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
2754c4392e7SDoug Rabson *
2764c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2774c4392e7SDoug Rabson * @param _child	the device which is requesting an allocation
2784c4392e7SDoug Rabson * @param _type		the type of resource to allocate
2794c4392e7SDoug Rabson * @param _rid		a pointer to the resource identifier
2804c4392e7SDoug Rabson * @param _start	hint at the start of the resource range - pass
281534ccd7bSJustin Hibbits *			@c 0 for any start address
2824c4392e7SDoug Rabson * @param _end		hint at the end of the resource range - pass
283534ccd7bSJustin Hibbits *			@c ~0 for any end address
2844c4392e7SDoug Rabson * @param _count	hint at the size of range required - pass @c 1
2854c4392e7SDoug Rabson *			for any size
2864c4392e7SDoug Rabson * @param _flags	any extra flags to control the resource
2874c4392e7SDoug Rabson *			allocation - see @c RF_XXX flags in
2884c4392e7SDoug Rabson *			<sys/rman.h> for details
2894c4392e7SDoug Rabson *
2904c4392e7SDoug Rabson * @returns		the resource which was allocated or @c NULL if no
2914c4392e7SDoug Rabson *			resource could be allocated
2924c4392e7SDoug Rabson */
29314177d72SGarrett WollmanMETHOD struct resource * alloc_resource {
294bd418641SMark Murray	device_t	_dev;
295bd418641SMark Murray	device_t	_child;
296bd418641SMark Murray	int		_type;
297bd418641SMark Murray	int	       *_rid;
2982dd1bdf1SJustin Hibbits	rman_res_t	_start;
2992dd1bdf1SJustin Hibbits	rman_res_t	_end;
3002dd1bdf1SJustin Hibbits	rman_res_t	_count;
301bd418641SMark Murray	u_int		_flags;
3028b2970bbSDoug Rabson} DEFAULT null_alloc_resource;
30314177d72SGarrett Wollman
3044c4392e7SDoug Rabson/**
3054c4392e7SDoug Rabson * @brief Activate a resource
3064c4392e7SDoug Rabson *
3074c4392e7SDoug Rabson * Activate a resource previously allocated with
308cc981af2SJohn Baldwin * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
309cc981af2SJohn Baldwin * device for instance.  It will also establish a mapping for the resource
310cc981af2SJohn Baldwin * unless RF_UNMAPPED was set when allocating the resource.
3114c4392e7SDoug Rabson *
3124c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3134c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3144c4392e7SDoug Rabson * @param _r		the resource to activate
3154c4392e7SDoug Rabson */
31614177d72SGarrett WollmanMETHOD int activate_resource {
317bd418641SMark Murray	device_t	_dev;
318bd418641SMark Murray	device_t	_child;
319bd418641SMark Murray	struct resource *_r;
32014177d72SGarrett Wollman};
32114177d72SGarrett Wollman
322cc981af2SJohn Baldwin
323cc981af2SJohn Baldwin/**
324cc981af2SJohn Baldwin * @brief Map a resource
325cc981af2SJohn Baldwin *
326cc981af2SJohn Baldwin * Allocate a mapping for a range of an active resource.  The mapping
327cc981af2SJohn Baldwin * is described by a struct resource_map object.  This may for instance
328cc981af2SJohn Baldwin * map a memory region into the kernel's virtual address space.
329cc981af2SJohn Baldwin *
330cc981af2SJohn Baldwin * @param _dev		the parent device of @p _child
331cc981af2SJohn Baldwin * @param _child	the device which allocated the resource
332cc981af2SJohn Baldwin * @param _r		the resource to map
333cc981af2SJohn Baldwin * @param _args		optional attributes of the mapping
334cc981af2SJohn Baldwin * @param _map		the mapping
335cc981af2SJohn Baldwin */
336cc981af2SJohn BaldwinMETHOD int map_resource {
337cc981af2SJohn Baldwin	device_t	_dev;
338cc981af2SJohn Baldwin	device_t	_child;
339cc981af2SJohn Baldwin	struct resource *_r;
340cc981af2SJohn Baldwin	struct resource_map_request *_args;
341cc981af2SJohn Baldwin	struct resource_map *_map;
342cc981af2SJohn Baldwin} DEFAULT bus_generic_map_resource;
343cc981af2SJohn Baldwin
344cc981af2SJohn Baldwin
345cc981af2SJohn Baldwin/**
346cc981af2SJohn Baldwin * @brief Unmap a resource
347cc981af2SJohn Baldwin *
348cc981af2SJohn Baldwin * Release a mapping previously allocated with
349cc981af2SJohn Baldwin * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
350cc981af2SJohn Baldwin * from the kernel's virtual address space.
351cc981af2SJohn Baldwin *
352cc981af2SJohn Baldwin * @param _dev		the parent device of @p _child
353cc981af2SJohn Baldwin * @param _child	the device which allocated the resource
354cc981af2SJohn Baldwin * @param _r		the resource
355cc981af2SJohn Baldwin * @param _map		the mapping to release
356cc981af2SJohn Baldwin */
357cc981af2SJohn BaldwinMETHOD int unmap_resource {
358cc981af2SJohn Baldwin	device_t	_dev;
359cc981af2SJohn Baldwin	device_t	_child;
360cc981af2SJohn Baldwin	struct resource *_r;
361cc981af2SJohn Baldwin	struct resource_map *_map;
362cc981af2SJohn Baldwin} DEFAULT bus_generic_unmap_resource;
363cc981af2SJohn Baldwin
364cc981af2SJohn Baldwin
3654c4392e7SDoug Rabson/**
3664c4392e7SDoug Rabson * @brief Deactivate a resource
3674c4392e7SDoug Rabson *
3684c4392e7SDoug Rabson * Deactivate a resource previously allocated with
369cc981af2SJohn Baldwin * BUS_ALLOC_RESOURCE().
3704c4392e7SDoug Rabson *
3714c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3724c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3734c4392e7SDoug Rabson * @param _r		the resource to deactivate
3744c4392e7SDoug Rabson */
37514177d72SGarrett WollmanMETHOD int deactivate_resource {
376bd418641SMark Murray	device_t	_dev;
377bd418641SMark Murray	device_t	_child;
378bd418641SMark Murray	struct resource *_r;
379b1bf6610SDoug Rabson};
38045c95fa1SDoug Rabson
3814c4392e7SDoug Rabson/**
38285ee63c9SJohn Baldwin * @brief Adjust a resource
38385ee63c9SJohn Baldwin *
38485ee63c9SJohn Baldwin * Adjust the start and/or end of a resource allocated by
38585ee63c9SJohn Baldwin * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
38685ee63c9SJohn Baldwin * with the existing address range.  If the successful, the resource's range
38785ee63c9SJohn Baldwin * will be adjusted to [start, end] on return.
38885ee63c9SJohn Baldwin *
38985ee63c9SJohn Baldwin * @param _dev		the parent device of @p _child
39085ee63c9SJohn Baldwin * @param _child	the device which allocated the resource
39185ee63c9SJohn Baldwin * @param _res		the resource to adjust
39285ee63c9SJohn Baldwin * @param _start	the new starting address of the resource range
39385ee63c9SJohn Baldwin * @param _end		the new ending address of the resource range
39485ee63c9SJohn Baldwin */
39585ee63c9SJohn BaldwinMETHOD int adjust_resource {
39685ee63c9SJohn Baldwin	device_t	_dev;
39785ee63c9SJohn Baldwin	device_t	_child;
39885ee63c9SJohn Baldwin	struct resource *_res;
3992dd1bdf1SJustin Hibbits	rman_res_t	_start;
4002dd1bdf1SJustin Hibbits	rman_res_t	_end;
40185ee63c9SJohn Baldwin};
40285ee63c9SJohn Baldwin
403937a05baSJustin Hibbits/**
404937a05baSJustin Hibbits * @brief translate a resource value
405937a05baSJustin Hibbits *
4061fb99e97SMark Johnston * Give a bus driver the opportunity to translate resource ranges.  If
4071fb99e97SMark Johnston * successful, the host's view of the resource starting at @p _start is
4081fb99e97SMark Johnston * returned in @p _newstart, otherwise an error is returned.
409937a05baSJustin Hibbits *
410937a05baSJustin Hibbits * @param _dev		the device associated with the resource
411937a05baSJustin Hibbits * @param _type		the type of resource
412937a05baSJustin Hibbits * @param _start	the starting address of the resource range
413937a05baSJustin Hibbits * @param _newstart	the new starting address of the resource range
414937a05baSJustin Hibbits */
415937a05baSJustin HibbitsMETHOD int translate_resource {
416937a05baSJustin Hibbits	device_t	_dev;
417937a05baSJustin Hibbits	int		_type;
418937a05baSJustin Hibbits	rman_res_t	_start;
419937a05baSJustin Hibbits	rman_res_t	*_newstart;
4201fb99e97SMark Johnston} DEFAULT bus_generic_translate_resource;
421937a05baSJustin Hibbits
42285ee63c9SJohn Baldwin/**
4234c4392e7SDoug Rabson * @brief Release a resource
4244c4392e7SDoug Rabson *
4254c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
4264c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
4274c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed).
4284c4392e7SDoug Rabson *
4294c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4304c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4314c4392e7SDoug Rabson * @param _r		the resource to release
4324c4392e7SDoug Rabson */
43314177d72SGarrett WollmanMETHOD int release_resource {
434bd418641SMark Murray	device_t	_dev;
435bd418641SMark Murray	device_t	_child;
436bd418641SMark Murray	struct resource *_res;
43714177d72SGarrett Wollman};
43814177d72SGarrett Wollman
4394c4392e7SDoug Rabson/**
4404c4392e7SDoug Rabson * @brief Install an interrupt handler
4414c4392e7SDoug Rabson *
4424c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with
4434c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr
4444c4392e7SDoug Rabson * will be called with the value of @p _arg as its single
4454c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the
4464c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a
4474c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR().
4484c4392e7SDoug Rabson *
4494c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4504c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4514c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
4524c4392e7SDoug Rabson * @param _flags	a set of bits from enum intr_type specifying
4534c4392e7SDoug Rabson *			the class of interrupt
4544c4392e7SDoug Rabson * @param _intr		the function to call when the interrupt
4554c4392e7SDoug Rabson *			triggers
4564c4392e7SDoug Rabson * @param _arg		a value to use as the single argument in calls
4574c4392e7SDoug Rabson *			to @p _intr
458e3043798SPedro F. Giffuni * @param _cookiep	a pointer to a location to receive a cookie
4594c4392e7SDoug Rabson *			value that may be used to remove the interrupt
4604c4392e7SDoug Rabson *			handler
4614c4392e7SDoug Rabson */
46214177d72SGarrett WollmanMETHOD int setup_intr {
463bd418641SMark Murray	device_t	_dev;
464bd418641SMark Murray	device_t	_child;
465bd418641SMark Murray	struct resource *_irq;
466bd418641SMark Murray	int		_flags;
467ef544f63SPaolo Pisati	driver_filter_t	*_filter;
468bd418641SMark Murray	driver_intr_t	*_intr;
469bd418641SMark Murray	void		*_arg;
470bd418641SMark Murray	void		**_cookiep;
47114177d72SGarrett Wollman};
47214177d72SGarrett Wollman
4734c4392e7SDoug Rabson/**
4744c4392e7SDoug Rabson * @brief Uninstall an interrupt handler
4754c4392e7SDoug Rabson *
4764c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function
4774c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value
4784c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR().
4794c4392e7SDoug Rabson *
4804c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4814c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4824c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
4834c4392e7SDoug Rabson * @param _cookie	the cookie value returned when the interrupt
4844c4392e7SDoug Rabson *			was originally registered
4854c4392e7SDoug Rabson */
48614177d72SGarrett WollmanMETHOD int teardown_intr {
487bd418641SMark Murray	device_t	_dev;
488bd418641SMark Murray	device_t	_child;
489bd418641SMark Murray	struct resource	*_irq;
490bd418641SMark Murray	void		*_cookie;
49145c95fa1SDoug Rabson};
49225afb89bSDoug Rabson
4934c4392e7SDoug Rabson/**
49482a5a275SAndriy Gapon * @brief Suspend an interrupt handler
49582a5a275SAndriy Gapon *
49682a5a275SAndriy Gapon * This method is used to mark a handler as suspended in the case
49782a5a275SAndriy Gapon * that the associated device is powered down and cannot be a source
49882a5a275SAndriy Gapon * for the, typically shared, interrupt.
49982a5a275SAndriy Gapon * The value of @p _irq must be the interrupt resource passed
50082a5a275SAndriy Gapon * to a previous call to BUS_SETUP_INTR().
50182a5a275SAndriy Gapon *
50282a5a275SAndriy Gapon * @param _dev		the parent device of @p _child
50382a5a275SAndriy Gapon * @param _child	the device which allocated the resource
50482a5a275SAndriy Gapon * @param _irq		the resource representing the interrupt
50582a5a275SAndriy Gapon */
50682a5a275SAndriy GaponMETHOD int suspend_intr {
50782a5a275SAndriy Gapon	device_t	_dev;
50882a5a275SAndriy Gapon	device_t	_child;
50982a5a275SAndriy Gapon	struct resource *_irq;
51082a5a275SAndriy Gapon} DEFAULT bus_generic_suspend_intr;
51182a5a275SAndriy Gapon
51282a5a275SAndriy Gapon/**
51382a5a275SAndriy Gapon * @brief Resume an interrupt handler
51482a5a275SAndriy Gapon *
51582a5a275SAndriy Gapon * This method is used to clear suspended state of a handler when
51682a5a275SAndriy Gapon * the associated device is powered up and can be an interrupt source
51782a5a275SAndriy Gapon * again.
51882a5a275SAndriy Gapon * The value of @p _irq must be the interrupt resource passed
51982a5a275SAndriy Gapon * to a previous call to BUS_SETUP_INTR().
52082a5a275SAndriy Gapon *
52182a5a275SAndriy Gapon * @param _dev		the parent device of @p _child
52282a5a275SAndriy Gapon * @param _child	the device which allocated the resource
52382a5a275SAndriy Gapon * @param _irq		the resource representing the interrupt
52482a5a275SAndriy Gapon */
52582a5a275SAndriy GaponMETHOD int resume_intr {
52682a5a275SAndriy Gapon	device_t	_dev;
52782a5a275SAndriy Gapon	device_t	_child;
52882a5a275SAndriy Gapon	struct resource *_irq;
52982a5a275SAndriy Gapon} DEFAULT bus_generic_resume_intr;
53082a5a275SAndriy Gapon
53182a5a275SAndriy Gapon/**
5324c4392e7SDoug Rabson * @brief Define a resource which can be allocated with
5334c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE().
5344c4392e7SDoug Rabson *
535db4fcadfSConrad Meyer * This method is used by some buses (typically ISA) to allow a
5364c4392e7SDoug Rabson * driver to describe a resource range that it would like to
5374c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined
5384c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its
5394c4392e7SDoug Rabson * range.
5404c4392e7SDoug Rabson *
5414c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5424c4392e7SDoug Rabson * @param _child	the device which owns the resource
5434c4392e7SDoug Rabson * @param _type		the type of resource
5444c4392e7SDoug Rabson * @param _rid		the resource identifier
5454c4392e7SDoug Rabson * @param _start	the start of the resource range
5464c4392e7SDoug Rabson * @param _count	the size of the resource range
5474c4392e7SDoug Rabson */
54825afb89bSDoug RabsonMETHOD int set_resource {
549bd418641SMark Murray	device_t	_dev;
550bd418641SMark Murray	device_t	_child;
551bd418641SMark Murray	int		_type;
552bd418641SMark Murray	int		_rid;
5532dd1bdf1SJustin Hibbits	rman_res_t	_start;
5542dd1bdf1SJustin Hibbits	rman_res_t	_count;
55525afb89bSDoug Rabson};
55625afb89bSDoug Rabson
5574c4392e7SDoug Rabson/**
5584c4392e7SDoug Rabson * @brief Describe a resource
5594c4392e7SDoug Rabson *
5604c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given
5614c4392e7SDoug Rabson * resource without actually allocating it.
5624c4392e7SDoug Rabson *
5634c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5644c4392e7SDoug Rabson * @param _child	the device which owns the resource
5654c4392e7SDoug Rabson * @param _type		the type of resource
5664c4392e7SDoug Rabson * @param _rid		the resource identifier
567e3043798SPedro F. Giffuni * @param _start	the address of a location to receive the start
5684c4392e7SDoug Rabson *			index of the resource range
569e3043798SPedro F. Giffuni * @param _count	the address of a location to receive the size
5704c4392e7SDoug Rabson *			of the resource range
5714c4392e7SDoug Rabson */
57225afb89bSDoug RabsonMETHOD int get_resource {
573bd418641SMark Murray	device_t	_dev;
574bd418641SMark Murray	device_t	_child;
575bd418641SMark Murray	int		_type;
576bd418641SMark Murray	int		_rid;
5772dd1bdf1SJustin Hibbits	rman_res_t	*_startp;
5782dd1bdf1SJustin Hibbits	rman_res_t	*_countp;
57925afb89bSDoug Rabson};
58025afb89bSDoug Rabson
5814c4392e7SDoug Rabson/**
5824c4392e7SDoug Rabson * @brief Delete a resource.
5834c4392e7SDoug Rabson *
5844c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with
5854c4392e7SDoug Rabson * BUS_SET_RESOURCE()).
5864c4392e7SDoug Rabson *
5874c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5884c4392e7SDoug Rabson * @param _child	the device which owns the resource
5894c4392e7SDoug Rabson * @param _type		the type of resource
5904c4392e7SDoug Rabson * @param _rid		the resource identifier
5914c4392e7SDoug Rabson */
59225afb89bSDoug RabsonMETHOD void delete_resource {
593bd418641SMark Murray	device_t	_dev;
594bd418641SMark Murray	device_t	_child;
595bd418641SMark Murray	int		_type;
596bd418641SMark Murray	int		_rid;
59725afb89bSDoug Rabson};
5980cb53e24SMatthew N. Dodd
5994c4392e7SDoug Rabson/**
6004c4392e7SDoug Rabson * @brief Return a struct resource_list.
6014c4392e7SDoug Rabson *
6024c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
6034c4392e7SDoug Rabson * implement their resource handling. It should return the resource
6044c4392e7SDoug Rabson * list of the given child device.
6054c4392e7SDoug Rabson *
6064c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6074c4392e7SDoug Rabson * @param _child	the device which owns the resource list
6084c4392e7SDoug Rabson */
60946aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list {
610bd418641SMark Murray	device_t	_dev;
611bd418641SMark Murray	device_t	_child;
6120cb53e24SMatthew N. Dodd} DEFAULT bus_generic_get_resource_list;
6135878eb3fSWarner Losh
6144c4392e7SDoug Rabson/**
615751615c5SJohn Baldwin * @brief Return a struct rman.
616751615c5SJohn Baldwin *
617751615c5SJohn Baldwin * Used by drivers which use bus_generic_rman_alloc_resource() etc. to
618751615c5SJohn Baldwin * implement their resource handling. It should return the resource
619751615c5SJohn Baldwin * manager used for the given resource type.
620751615c5SJohn Baldwin *
621751615c5SJohn Baldwin * @param _dev		the bus device
622751615c5SJohn Baldwin * @param _type		the resource type
623751615c5SJohn Baldwin * @param _flags	resource flags (@c RF_XXX flags in
624751615c5SJohn Baldwin *			<sys/rman.h>)
625751615c5SJohn Baldwin */
626751615c5SJohn BaldwinMETHOD struct rman * get_rman {
627751615c5SJohn Baldwin	device_t	_dev;
628751615c5SJohn Baldwin	int		_type;
629751615c5SJohn Baldwin	u_int		_flags;
630751615c5SJohn Baldwin} DEFAULT null_get_rman;
631751615c5SJohn Baldwin
632751615c5SJohn Baldwin/**
6334c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the
6344c4392e7SDoug Rabson * system?
6354c4392e7SDoug Rabson *
6369f7f340aSWarner Losh * This method should return 0 if the device is not present.  It
6379f7f340aSWarner Losh * should return -1 if it is present.  Any errors in determining
6389f7f340aSWarner Losh * should be returned as a normal errno value.  Client drivers are to
6399f7f340aSWarner Losh * assume that the device is present, even if there is an error
640db4fcadfSConrad Meyer * determining if it is there.  Buses are to try to avoid returning
6419f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to
6429f7f340aSWarner Losh * implement this method.
6434c4392e7SDoug Rabson *
6444c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6454c4392e7SDoug Rabson * @param _child	the device which is being examined
6464c4392e7SDoug Rabson */
6475878eb3fSWarner LoshMETHOD int child_present {
6485878eb3fSWarner Losh	device_t	_dev;
6495878eb3fSWarner Losh	device_t	_child;
6505878eb3fSWarner Losh} DEFAULT bus_generic_child_present;
6513d9841b4SWarner Losh
6524c4392e7SDoug Rabson/**
6534c4392e7SDoug Rabson * @brief Returns the pnp info for this device.
6544c4392e7SDoug Rabson *
655ddfc9c4cSWarner Losh * Return it as a string, appended to @p _sb
6564c4392e7SDoug Rabson *
657ed7ed7f0SJohn Baldwin * The string must be formatted as a space-separated list of
658ed7ed7f0SJohn Baldwin * name=value pairs.  Names may only contain alphanumeric characters,
659ed7ed7f0SJohn Baldwin * underscores ('_') and hyphens ('-').  Values can contain any
660ed7ed7f0SJohn Baldwin * non-whitespace characters.  Values containing whitespace can be
661ed7ed7f0SJohn Baldwin * quoted with double quotes ('"').  Double quotes and backslashes in
662ed7ed7f0SJohn Baldwin * quoted values can be escaped with backslashes ('\').
663ed7ed7f0SJohn Baldwin *
6644c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6654c4392e7SDoug Rabson * @param _child	the device which is being examined
666ddfc9c4cSWarner Losh * @param _sb		sbuf for results string
6674c4392e7SDoug Rabson */
668ddfc9c4cSWarner LoshMETHOD int child_pnpinfo {
6693d9841b4SWarner Losh	device_t	_dev;
6703d9841b4SWarner Losh	device_t	_child;
671ddfc9c4cSWarner Losh	struct sbuf	*_sb;
672ddfc9c4cSWarner Losh} DEFAULT bus_generic_child_pnpinfo;
6733d9841b4SWarner Losh
6744c4392e7SDoug Rabson/**
6754c4392e7SDoug Rabson * @brief Returns the location for this device.
6764c4392e7SDoug Rabson *
677ddfc9c4cSWarner Losh * Return it as a string, appended to @p _sb
6784c4392e7SDoug Rabson *
679ed7ed7f0SJohn Baldwin * The string must be formatted as a space-separated list of
680ed7ed7f0SJohn Baldwin * name=value pairs.  Names may only contain alphanumeric characters,
681ed7ed7f0SJohn Baldwin * underscores ('_') and hyphens ('-').  Values can contain any
682ed7ed7f0SJohn Baldwin * non-whitespace characters.  Values containing whitespace can be
683ed7ed7f0SJohn Baldwin * quoted with double quotes ('"').  Double quotes and backslashes in
684ed7ed7f0SJohn Baldwin * quoted values can be escaped with backslashes ('\').
685ed7ed7f0SJohn Baldwin *
6864c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6874c4392e7SDoug Rabson * @param _child	the device which is being examined
688ddfc9c4cSWarner Losh * @param _sb		sbuf for results string
6894c4392e7SDoug Rabson */
690ddfc9c4cSWarner LoshMETHOD int child_location {
6913d9841b4SWarner Losh	device_t	_dev;
6923d9841b4SWarner Losh	device_t	_child;
693ddfc9c4cSWarner Losh	struct sbuf	*_sb;
694ddfc9c4cSWarner Losh} DEFAULT bus_generic_child_location;
695da13b8f9SMarcel Moolenaar
6964c4392e7SDoug Rabson/**
697dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific
698dcc81068SJohn Baldwin * CPU.
699dcc81068SJohn Baldwin *
700dcc81068SJohn Baldwin * @param _dev		the parent device of @p _child
701dcc81068SJohn Baldwin * @param _child	the device which allocated the resource
702dcc81068SJohn Baldwin * @param _irq		the resource representing the interrupt
703dcc81068SJohn Baldwin * @param _cpu		the CPU to bind the interrupt to
704dcc81068SJohn Baldwin */
705dcc81068SJohn BaldwinMETHOD int bind_intr {
706dcc81068SJohn Baldwin	device_t	_dev;
707dcc81068SJohn Baldwin	device_t	_child;
708dcc81068SJohn Baldwin	struct resource *_irq;
709dcc81068SJohn Baldwin	int		_cpu;
710dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr;
711dcc81068SJohn Baldwin
712dcc81068SJohn Baldwin/**
7134c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity
7144c4392e7SDoug Rabson * of the specified interrupt.
7154c4392e7SDoug Rabson *
7164c4392e7SDoug Rabson * @param _dev		the bus device
7174c4392e7SDoug Rabson * @param _irq		the interrupt number to modify
7184c4392e7SDoug Rabson * @param _trig		the trigger mode required
7194c4392e7SDoug Rabson * @param _pol		the interrupt polarity required
7204c4392e7SDoug Rabson */
721da13b8f9SMarcel MoolenaarMETHOD int config_intr {
722da13b8f9SMarcel Moolenaar	device_t	_dev;
723da13b8f9SMarcel Moolenaar	int		_irq;
724da13b8f9SMarcel Moolenaar	enum intr_trigger _trig;
725da13b8f9SMarcel Moolenaar	enum intr_polarity _pol;
726da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr;
727db2bc1bbSWarner Losh
728db2bc1bbSWarner Losh/**
72937b8ef16SJohn Baldwin * @brief Allow drivers to associate a description with an active
73037b8ef16SJohn Baldwin * interrupt handler.
73137b8ef16SJohn Baldwin *
73237b8ef16SJohn Baldwin * @param _dev		the parent device of @p _child
73337b8ef16SJohn Baldwin * @param _child	the device which allocated the resource
73437b8ef16SJohn Baldwin * @param _irq		the resource representing the interrupt
73537b8ef16SJohn Baldwin * @param _cookie	the cookie value returned when the interrupt
73637b8ef16SJohn Baldwin *			was originally registered
73737b8ef16SJohn Baldwin * @param _descr	the description to associate with the interrupt
73837b8ef16SJohn Baldwin */
73937b8ef16SJohn BaldwinMETHOD int describe_intr {
74037b8ef16SJohn Baldwin	device_t	_dev;
74137b8ef16SJohn Baldwin	device_t	_child;
74237b8ef16SJohn Baldwin	struct resource *_irq;
74337b8ef16SJohn Baldwin	void		*_cookie;
74437b8ef16SJohn Baldwin	const char	*_descr;
74537b8ef16SJohn Baldwin} DEFAULT bus_generic_describe_intr;
74637b8ef16SJohn Baldwin
74737b8ef16SJohn Baldwin/**
748db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism
749db2bc1bbSWarner Losh * believes it has discovered.
750db2bc1bbSWarner Losh *
751db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order
752db2bc1bbSWarner Losh * and discovering other things about the child.  The bus driver is
753db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc.  It is all up
754db2bc1bbSWarner Losh * to the bus driver to interpret.
755db2bc1bbSWarner Losh *
756db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for
757db2bc1bbSWarner Losh * hinted devices to be enumerated.
758db2bc1bbSWarner Losh *
759db2bc1bbSWarner Losh * @param _dev		the bus device
760db2bc1bbSWarner Losh * @param _dname	the name of the device w/o unit numbers
761db2bc1bbSWarner Losh * @param _dunit	the unit number of the device
762db2bc1bbSWarner Losh */
763db2bc1bbSWarner LoshMETHOD void hinted_child {
764db2bc1bbSWarner Losh	device_t	_dev;
765db2bc1bbSWarner Losh	const char	*_dname;
766db2bc1bbSWarner Losh	int		_dunit;
767db2bc1bbSWarner Losh};
768378f231eSJohn-Mark Gurney
769378f231eSJohn-Mark Gurney/**
770378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
771378f231eSJohn-Mark Gurney *
772378f231eSJohn-Mark Gurney * @param _dev		the parent device of @p _child
773378f231eSJohn-Mark Gurney * @param _child	the device to which the tag will belong
774378f231eSJohn-Mark Gurney */
775378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag {
776378f231eSJohn-Mark Gurney	device_t	_dev;
777378f231eSJohn-Mark Gurney	device_t	_child;
778378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag;
7790d484d24SJohn Baldwin
7800d484d24SJohn Baldwin/**
781b998c965SZbigniew Bodek * @brief Returns bus_space_tag_t for use w/ devices on the bus.
782b998c965SZbigniew Bodek *
783b998c965SZbigniew Bodek * @param _dev		the parent device of @p _child
784b998c965SZbigniew Bodek * @param _child	the device to which the tag will belong
785b998c965SZbigniew Bodek */
786b998c965SZbigniew BodekMETHOD bus_space_tag_t get_bus_tag {
787b998c965SZbigniew Bodek	device_t	_dev;
788b998c965SZbigniew Bodek	device_t	_child;
789b998c965SZbigniew Bodek} DEFAULT bus_generic_get_bus_tag;
790b998c965SZbigniew Bodek
791b998c965SZbigniew Bodek/**
7920d484d24SJohn Baldwin * @brief Allow the bus to determine the unit number of a device.
7930d484d24SJohn Baldwin *
7940d484d24SJohn Baldwin * @param _dev		the parent device of @p _child
7950d484d24SJohn Baldwin * @param _child	the device whose unit is to be wired
7960d484d24SJohn Baldwin * @param _name		the name of the device's new devclass
7970d484d24SJohn Baldwin * @param _unitp	a pointer to the device's new unit value
7980d484d24SJohn Baldwin */
7990d484d24SJohn BaldwinMETHOD void hint_device_unit {
8000d484d24SJohn Baldwin	device_t	_dev;
8010d484d24SJohn Baldwin	device_t	_child;
8020d484d24SJohn Baldwin	const char	*_name;
8030d484d24SJohn Baldwin	int		*_unitp;
8040d484d24SJohn Baldwin};
8050d484d24SJohn Baldwin
8064ef60d26SJohn Baldwin/**
8074ef60d26SJohn Baldwin * @brief Notify a bus that the bus pass level has been changed
8084ef60d26SJohn Baldwin *
8094ef60d26SJohn Baldwin * @param _dev		the bus device
8104ef60d26SJohn Baldwin */
8114ef60d26SJohn BaldwinMETHOD void new_pass {
8124ef60d26SJohn Baldwin	device_t	_dev;
8134ef60d26SJohn Baldwin} DEFAULT bus_generic_new_pass;
81493fc07b4SAlexander Motin
81593fc07b4SAlexander Motin/**
81693fc07b4SAlexander Motin * @brief Notify a bus that specified child's IRQ should be remapped.
81793fc07b4SAlexander Motin *
81893fc07b4SAlexander Motin * @param _dev		the bus device
81993fc07b4SAlexander Motin * @param _child	the child device
82093fc07b4SAlexander Motin * @param _irq		the irq number
82193fc07b4SAlexander Motin */
82293fc07b4SAlexander MotinMETHOD int remap_intr {
82393fc07b4SAlexander Motin	device_t	_dev;
82493fc07b4SAlexander Motin	device_t	_child;
82593fc07b4SAlexander Motin	u_int		_irq;
82693fc07b4SAlexander Motin} DEFAULT null_remap_intr;
827a1c16348SJustin Hibbits
828a1c16348SJustin Hibbits/**
829a1c16348SJustin Hibbits * @brief Suspend a given child
830a1c16348SJustin Hibbits *
831a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
832a1c16348SJustin Hibbits * @param _child	the device to suspend
833a1c16348SJustin Hibbits */
834a1c16348SJustin HibbitsMETHOD int suspend_child {
835a1c16348SJustin Hibbits	device_t	_dev;
836a1c16348SJustin Hibbits	device_t	_child;
837a1c16348SJustin Hibbits} DEFAULT bus_generic_suspend_child;
838a1c16348SJustin Hibbits
839a1c16348SJustin Hibbits/**
840a1c16348SJustin Hibbits * @brief Resume a given child
841a1c16348SJustin Hibbits *
842a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
843a1c16348SJustin Hibbits * @param _child	the device to resume
844a1c16348SJustin Hibbits */
845a1c16348SJustin HibbitsMETHOD int resume_child {
846a1c16348SJustin Hibbits	device_t	_dev;
847a1c16348SJustin Hibbits	device_t	_child;
848a1c16348SJustin Hibbits} DEFAULT bus_generic_resume_child;
849ffcf962dSAdrian Chadd
850ffcf962dSAdrian Chadd/**
851ffcf962dSAdrian Chadd * @brief Get the VM domain handle for the given bus and child.
852ffcf962dSAdrian Chadd *
853ffcf962dSAdrian Chadd * @param _dev		the bus device
854ffcf962dSAdrian Chadd * @param _child	the child device
855ffcf962dSAdrian Chadd * @param _domain	a pointer to the bus's domain handle identifier
856ffcf962dSAdrian Chadd */
857ffcf962dSAdrian ChaddMETHOD int get_domain {
858ffcf962dSAdrian Chadd	device_t	_dev;
859ffcf962dSAdrian Chadd	device_t	_child;
860ffcf962dSAdrian Chadd	int		*_domain;
861ffcf962dSAdrian Chadd} DEFAULT bus_generic_get_domain;
8628d791e5aSJohn Baldwin
8638d791e5aSJohn Baldwin/**
8648d791e5aSJohn Baldwin * @brief Request a set of CPUs
8658d791e5aSJohn Baldwin *
8668d791e5aSJohn Baldwin * @param _dev		the bus device
8678d791e5aSJohn Baldwin * @param _child	the child device
8688d791e5aSJohn Baldwin * @param _op		type of CPUs to request
8698d791e5aSJohn Baldwin * @param _setsize	the size of the set passed in _cpuset
8708d791e5aSJohn Baldwin * @param _cpuset	a pointer to a cpuset to receive the requested
8718d791e5aSJohn Baldwin *			set of CPUs
8728d791e5aSJohn Baldwin */
8738d791e5aSJohn BaldwinMETHOD int get_cpus {
8748d791e5aSJohn Baldwin	device_t	_dev;
8758d791e5aSJohn Baldwin	device_t	_child;
8768d791e5aSJohn Baldwin	enum cpu_sets	_op;
8778d791e5aSJohn Baldwin	size_t		_setsize;
878e2e050c8SConrad Meyer	struct _cpuset	*_cpuset;
8798d791e5aSJohn Baldwin} DEFAULT bus_generic_get_cpus;
880c53df6daSKonstantin Belousov
881c53df6daSKonstantin Belousov/**
882c53df6daSKonstantin Belousov * @brief Prepares the given child of the bus for reset
883c53df6daSKonstantin Belousov *
884c53df6daSKonstantin Belousov * Typically bus detaches or suspends children' drivers, and then
885c53df6daSKonstantin Belousov * calls this method to save bus-specific information, for instance,
886c53df6daSKonstantin Belousov * PCI config space, which is damaged by reset.
887c53df6daSKonstantin Belousov *
888c53df6daSKonstantin Belousov * The bus_helper_reset_prepare() helper is provided to ease
889c53df6daSKonstantin Belousov * implementing bus reset methods.
890c53df6daSKonstantin Belousov *
891c53df6daSKonstantin Belousov * @param _dev		the bus device
892c53df6daSKonstantin Belousov * @param _child	the child device
893c53df6daSKonstantin Belousov */
894c53df6daSKonstantin BelousovMETHOD int reset_prepare {
895c53df6daSKonstantin Belousov	device_t _dev;
896c53df6daSKonstantin Belousov	device_t _child;
897c53df6daSKonstantin Belousov} DEFAULT null_reset_prepare;
898c53df6daSKonstantin Belousov
899c53df6daSKonstantin Belousov/**
900c53df6daSKonstantin Belousov * @brief Restores the child operations after the reset
901c53df6daSKonstantin Belousov *
902c53df6daSKonstantin Belousov * The bus_helper_reset_post() helper is provided to ease
903c53df6daSKonstantin Belousov * implementing bus reset methods.
904c53df6daSKonstantin Belousov *
905c53df6daSKonstantin Belousov * @param _dev		the bus device
906c53df6daSKonstantin Belousov * @param _child	the child device
907c53df6daSKonstantin Belousov */
908c53df6daSKonstantin BelousovMETHOD int reset_post {
909c53df6daSKonstantin Belousov	device_t _dev;
910c53df6daSKonstantin Belousov	device_t _child;
911c53df6daSKonstantin Belousov} DEFAULT null_reset_post;
912c53df6daSKonstantin Belousov
913c53df6daSKonstantin Belousov/**
914c53df6daSKonstantin Belousov * @brief Performs reset of the child
915c53df6daSKonstantin Belousov *
916c53df6daSKonstantin Belousov * @param _dev		the bus device
917c53df6daSKonstantin Belousov * @param _child	the child device
918c53df6daSKonstantin Belousov * @param _flags	DEVF_RESET_ flags
919c53df6daSKonstantin Belousov */
920c53df6daSKonstantin BelousovMETHOD int reset_child {
921c53df6daSKonstantin Belousov	device_t _dev;
922c53df6daSKonstantin Belousov	device_t _child;
923c53df6daSKonstantin Belousov	int _flags;
924c53df6daSKonstantin Belousov};
9253f9a00e3SBartlomiej Grzesik
9263f9a00e3SBartlomiej Grzesik/**
9273f9a00e3SBartlomiej Grzesik * @brief Gets child's specific property
9283f9a00e3SBartlomiej Grzesik *
9293f9a00e3SBartlomiej Grzesik * The bus_get_property can be used to access device
9303f9a00e3SBartlomiej Grzesik * specific properties stored on the bus. If _propvalue
9313f9a00e3SBartlomiej Grzesik * is NULL or _size is 0, then method only returns size
9323f9a00e3SBartlomiej Grzesik * of the property.
9333f9a00e3SBartlomiej Grzesik *
9343f9a00e3SBartlomiej Grzesik * @param _dev			the bus device
9353f9a00e3SBartlomiej Grzesik * @param _child		the child device
9363f9a00e3SBartlomiej Grzesik * @param _propname		property name
9373f9a00e3SBartlomiej Grzesik * @param _propvalue	property value destination
9383f9a00e3SBartlomiej Grzesik * @param _size			property value size
9393f9a00e3SBartlomiej Grzesik *
9403f9a00e3SBartlomiej Grzesik * @returns size of property if successful otherwise -1
9413f9a00e3SBartlomiej Grzesik */
9423f9a00e3SBartlomiej GrzesikMETHOD ssize_t get_property {
9433f9a00e3SBartlomiej Grzesik	device_t _dev;
9443f9a00e3SBartlomiej Grzesik	device_t _child;
9453f9a00e3SBartlomiej Grzesik	const char *_propname;
9463f9a00e3SBartlomiej Grzesik	void *_propvalue;
9473f9a00e3SBartlomiej Grzesik	size_t _size;
948b344de4dSKornel Duleba	device_property_type_t type;
949206dc82bSKornel Duleba} DEFAULT bus_generic_get_property;
950e19db707SWarner Losh
951e19db707SWarner Losh/**
952e19db707SWarner Losh * @brief Gets a child's full path to the device
953e19db707SWarner Losh *
954e19db707SWarner Losh * The get_device_path method retrieves a device's
955e19db707SWarner Losh * full path to the device using one of several
956e19db707SWarner Losh * locators present in the system.
957e19db707SWarner Losh *
958e19db707SWarner Losh * @param _bus			the bus device
959e19db707SWarner Losh * @param _child		the child device
960e19db707SWarner Losh * @param _locator		locator name
961e19db707SWarner Losh * @param _sb			buffer loaction string
962e19db707SWarner Losh */
963e19db707SWarner LoshMETHOD int get_device_path {
964e19db707SWarner Losh	device_t _bus;
965e19db707SWarner Losh	device_t _child;
966e19db707SWarner Losh	const char *_locator;
967e19db707SWarner Losh	struct sbuf *_sb;
968e19db707SWarner Losh} DEFAULT bus_generic_get_device_path;
969