xref: /freebsd/sys/kern/bus_if.m (revision 7979205e0553ed23b61faa473d9dd866872cb710)
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
667030980bSBjoern A. Zeeb		panic("%s: bus_add_child is not implemented, name '%s', "
677030980bSBjoern 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	}
87*7979205eSJohn Baldwin
88*7979205eSJohn Baldwin	static struct resource_list *
89*7979205eSJohn Baldwin	null_get_resource_list(device_t bus, device_t dev)
90*7979205eSJohn Baldwin	{
91*7979205eSJohn Baldwin		return (NULL);
92*7979205eSJohn Baldwin	}
938b2970bbSDoug Rabson};
948b2970bbSDoug Rabson
954c4392e7SDoug Rabson/**
964c4392e7SDoug Rabson * @brief Print a description of a child device
974c4392e7SDoug Rabson *
984c4392e7SDoug Rabson * This is called from system code which prints out a description of a
994c4392e7SDoug Rabson * device. It should describe the attachment that the child has with
1004c4392e7SDoug Rabson * the parent. For instance the TurboLaser bus prints which node the
1014c4392e7SDoug Rabson * device is attached to. See bus_generic_print_child() for more
1024c4392e7SDoug Rabson * information.
1034c4392e7SDoug Rabson *
1044c4392e7SDoug Rabson * @param _dev		the device whose child is being printed
1054c4392e7SDoug Rabson * @param _child	the child device to describe
1064c4392e7SDoug Rabson *
1074c4392e7SDoug Rabson * @returns		the number of characters output.
1084c4392e7SDoug Rabson */
10915317dd8SMatthew N. DoddMETHOD int print_child {
1104c4392e7SDoug Rabson	device_t _dev;
1114c4392e7SDoug Rabson	device_t _child;
112c8440669SMatthew N. Dodd} DEFAULT bus_generic_print_child;
113b1bf6610SDoug Rabson
1144c4392e7SDoug Rabson/**
1154c4392e7SDoug Rabson * @brief Print a notification about an unprobed child device.
1164c4392e7SDoug Rabson *
1174c4392e7SDoug Rabson * Called for each child device that did not succeed in probing for a
1184c4392e7SDoug Rabson * driver.
1194c4392e7SDoug Rabson *
1204c4392e7SDoug Rabson * @param _dev		the device whose child was being probed
1214c4392e7SDoug Rabson * @param _child	the child device which failed to probe
1224c4392e7SDoug Rabson */
123ca7036d8SDoug RabsonMETHOD void probe_nomatch {
1244c4392e7SDoug Rabson        device_t _dev;
1254c4392e7SDoug Rabson        device_t _child;
126ca7036d8SDoug Rabson};
127ca7036d8SDoug Rabson
1284c4392e7SDoug Rabson/**
1294c4392e7SDoug Rabson * @brief Read the value of a bus-specific attribute of a device
1304c4392e7SDoug Rabson *
1314c4392e7SDoug Rabson * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
1324c4392e7SDoug Rabson * of instance variables of a child device.  The intention is that
1334c4392e7SDoug Rabson * each different type of bus defines a set of appropriate instance
1344c4392e7SDoug Rabson * variables (such as ports and irqs for ISA bus etc.)
1354c4392e7SDoug Rabson *
1364c4392e7SDoug Rabson * This information could be given to the child device as a struct but
1374c4392e7SDoug Rabson * that makes it hard for a bus to add or remove variables without
1384c4392e7SDoug Rabson * forcing an edit and recompile for all drivers which may not be
1394c4392e7SDoug Rabson * possible for vendor supplied binary drivers.
1404c4392e7SDoug Rabson *
1414c4392e7SDoug Rabson * This method copies the value of an instance variable to the
1424c4392e7SDoug Rabson * location specified by @p *_result.
1434c4392e7SDoug Rabson *
1444c4392e7SDoug Rabson * @param _dev		the device whose child was being examined
1454c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1464c4392e7SDoug Rabson *			being read
1474c4392e7SDoug Rabson * @param _index	the instance variable to read
148e3043798SPedro F. Giffuni * @param _result	a location to receive the instance variable
1494c4392e7SDoug Rabson *			value
1504c4392e7SDoug Rabson *
1514c4392e7SDoug Rabson * @retval 0		success
1524c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1534c4392e7SDoug Rabson *			_dev
1544c4392e7SDoug Rabson */
155b1bf6610SDoug RabsonMETHOD int read_ivar {
156bd418641SMark Murray	device_t _dev;
157bd418641SMark Murray	device_t _child;
1584c4392e7SDoug Rabson	int _index;
159bd418641SMark Murray	uintptr_t *_result;
160b1bf6610SDoug Rabson};
161b1bf6610SDoug Rabson
1624c4392e7SDoug Rabson/**
1634c4392e7SDoug Rabson * @brief Write the value of a bus-specific attribute of a device
1644c4392e7SDoug Rabson *
1654c4392e7SDoug Rabson * This method sets the value of an instance variable to @p _value.
1664c4392e7SDoug Rabson *
1674c4392e7SDoug Rabson * @param _dev		the device whose child was being updated
1684c4392e7SDoug Rabson * @param _child	the child device whose instance variable is
1694c4392e7SDoug Rabson *			being written
1704c4392e7SDoug Rabson * @param _index	the instance variable to write
1714c4392e7SDoug Rabson * @param _value	the value to write to that instance variable
1724c4392e7SDoug Rabson *
1734c4392e7SDoug Rabson * @retval 0		success
1744c4392e7SDoug Rabson * @retval ENOENT	no such instance variable is supported by @p
1754c4392e7SDoug Rabson *			_dev
1764c4392e7SDoug Rabson * @retval EINVAL	the instance variable was recognised but
1774c4392e7SDoug Rabson *			contains a read-only value
1784c4392e7SDoug Rabson */
179b1bf6610SDoug RabsonMETHOD int write_ivar {
180bd418641SMark Murray	device_t _dev;
181bd418641SMark Murray	device_t _child;
182bd418641SMark Murray	int _indx;
183bd418641SMark Murray	uintptr_t _value;
184b1bf6610SDoug Rabson};
185b1bf6610SDoug Rabson
1864c4392e7SDoug Rabson/**
1876f7d0018SJohn Baldwin * @brief Notify a bus that a child was deleted
1886f7d0018SJohn Baldwin *
1896f7d0018SJohn Baldwin * Called at the beginning of device_delete_child() to allow the parent
1906f7d0018SJohn Baldwin * to teardown any bus-specific state for the child.
1916f7d0018SJohn Baldwin *
1926f7d0018SJohn Baldwin * @param _dev		the device whose child is being deleted
1936f7d0018SJohn Baldwin * @param _child	the child device which is being deleted
1946f7d0018SJohn Baldwin */
1956f7d0018SJohn BaldwinMETHOD void child_deleted {
1966f7d0018SJohn Baldwin	device_t _dev;
1976f7d0018SJohn Baldwin	device_t _child;
1986f7d0018SJohn Baldwin};
1996f7d0018SJohn Baldwin
2006f7d0018SJohn Baldwin/**
2014c4392e7SDoug Rabson * @brief Notify a bus that a child was detached
2024c4392e7SDoug Rabson *
2034c4392e7SDoug Rabson * Called after the child's DEVICE_DETACH() method to allow the parent
2044c4392e7SDoug Rabson * to reclaim any resources allocated on behalf of the child.
2054c4392e7SDoug Rabson *
2064c4392e7SDoug Rabson * @param _dev		the device whose child changed state
2074c4392e7SDoug Rabson * @param _child	the child device which changed state
2084c4392e7SDoug Rabson */
2096350e58aSDoug RabsonMETHOD void child_detached {
210bd418641SMark Murray	device_t _dev;
211bd418641SMark Murray	device_t _child;
2126350e58aSDoug Rabson};
2136350e58aSDoug Rabson
2144c4392e7SDoug Rabson/**
2154c4392e7SDoug Rabson * @brief Notify a bus that a new driver was added
2164c4392e7SDoug Rabson *
2174c4392e7SDoug Rabson * Called when a new driver is added to the devclass which owns this
2184c4392e7SDoug Rabson * bus. The generic implementation of this method attempts to probe and
2194c4392e7SDoug Rabson * attach any un-matched children of the bus.
2204c4392e7SDoug Rabson *
2214c4392e7SDoug Rabson * @param _dev		the device whose devclass had a new driver
2224c4392e7SDoug Rabson *			added to it
2234c4392e7SDoug Rabson * @param _driver	the new driver which was added
2244c4392e7SDoug Rabson */
2256182fdbdSPeter WemmMETHOD void driver_added {
226bd418641SMark Murray	device_t _dev;
227bd418641SMark Murray	driver_t *_driver;
2286d4d0ac9SWarner Losh} DEFAULT bus_generic_driver_added;
2296182fdbdSPeter Wemm
2304c4392e7SDoug Rabson/**
2314c4392e7SDoug Rabson * @brief Create a new child device
2324c4392e7SDoug Rabson *
233db4fcadfSConrad Meyer * For buses which use use drivers supporting DEVICE_IDENTIFY() to
2344c4392e7SDoug Rabson * enumerate their devices, this method is used to create new
2354c4392e7SDoug Rabson * device instances. The new device will be added after the last
23683a283cfSWarner Losh * existing child with the same order. Implementations of bus_add_child
23783a283cfSWarner Losh * call device_add_child_ordered to add the child and often add
23883a283cfSWarner Losh * a suitable ivar to the device specific to that bus.
2394c4392e7SDoug Rabson *
2404c4392e7SDoug Rabson * @param _dev		the bus device which will be the parent of the
2414c4392e7SDoug Rabson *			new child device
2424c4392e7SDoug Rabson * @param _order	a value which is used to partially sort the
2434c4392e7SDoug Rabson *			children of @p _dev - devices created using
2444c4392e7SDoug Rabson *			lower values of @p _order appear first in @p
2454c4392e7SDoug Rabson *			_dev's list of children
2464c4392e7SDoug Rabson * @param _name		devclass name for new device or @c NULL if not
2474c4392e7SDoug Rabson *			specified
2484c4392e7SDoug Rabson * @param _unit		unit number for new device or @c -1 if not
2494c4392e7SDoug Rabson *			specified
2504c4392e7SDoug Rabson */
2516c2e3ddeSDoug RabsonMETHOD device_t add_child {
252bd418641SMark Murray	device_t _dev;
2533d844eddSAndriy Gapon	u_int _order;
254bd418641SMark Murray	const char *_name;
255bd418641SMark Murray	int _unit;
256b7d28b2eSAndriy Gapon} DEFAULT null_add_child;
2576c2e3ddeSDoug Rabson
2584c4392e7SDoug Rabson/**
259a907c691SJohn Baldwin * @brief Rescan the bus
260a907c691SJohn Baldwin *
261a907c691SJohn Baldwin * This method is called by a parent bridge or devctl to trigger a bus
262a907c691SJohn Baldwin * rescan.  The rescan should delete devices no longer present and
263a907c691SJohn Baldwin * enumerate devices that have newly arrived.
264a907c691SJohn Baldwin *
265a907c691SJohn Baldwin * @param _dev		the bus device
266a907c691SJohn Baldwin */
267a907c691SJohn BaldwinMETHOD int rescan {
268a907c691SJohn Baldwin	device_t _dev;
26929afffb9SMitchell Horne} DEFAULT bus_null_rescan;
270a907c691SJohn Baldwin
271a907c691SJohn Baldwin/**
2724c4392e7SDoug Rabson * @brief Allocate a system resource
2734c4392e7SDoug Rabson *
2744c4392e7SDoug Rabson * This method is called by child devices of a bus to allocate resources.
2754c4392e7SDoug Rabson * The types are defined in <machine/resource.h>; the meaning of the
2764c4392e7SDoug Rabson * resource-ID field varies from bus to bus (but @p *rid == 0 is always
2774c4392e7SDoug Rabson * valid if the resource type is). If a resource was allocated and the
2784c4392e7SDoug Rabson * caller did not use the RF_ACTIVE to specify that it should be
2794c4392e7SDoug Rabson * activated immediately, the caller is responsible for calling
2804c4392e7SDoug Rabson * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
2814c4392e7SDoug Rabson *
2824c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
2834c4392e7SDoug Rabson * @param _child	the device which is requesting an allocation
2844c4392e7SDoug Rabson * @param _type		the type of resource to allocate
2854c4392e7SDoug Rabson * @param _rid		a pointer to the resource identifier
2864c4392e7SDoug Rabson * @param _start	hint at the start of the resource range - pass
287534ccd7bSJustin Hibbits *			@c 0 for any start address
2884c4392e7SDoug Rabson * @param _end		hint at the end of the resource range - pass
289534ccd7bSJustin Hibbits *			@c ~0 for any end address
2904c4392e7SDoug Rabson * @param _count	hint at the size of range required - pass @c 1
2914c4392e7SDoug Rabson *			for any size
2924c4392e7SDoug Rabson * @param _flags	any extra flags to control the resource
2934c4392e7SDoug Rabson *			allocation - see @c RF_XXX flags in
2944c4392e7SDoug Rabson *			<sys/rman.h> for details
2954c4392e7SDoug Rabson *
2964c4392e7SDoug Rabson * @returns		the resource which was allocated or @c NULL if no
2974c4392e7SDoug Rabson *			resource could be allocated
2984c4392e7SDoug Rabson */
29914177d72SGarrett WollmanMETHOD struct resource * alloc_resource {
300bd418641SMark Murray	device_t	_dev;
301bd418641SMark Murray	device_t	_child;
302bd418641SMark Murray	int		_type;
303bd418641SMark Murray	int	       *_rid;
3042dd1bdf1SJustin Hibbits	rman_res_t	_start;
3052dd1bdf1SJustin Hibbits	rman_res_t	_end;
3062dd1bdf1SJustin Hibbits	rman_res_t	_count;
307bd418641SMark Murray	u_int		_flags;
3088b2970bbSDoug Rabson} DEFAULT null_alloc_resource;
30914177d72SGarrett Wollman
3104c4392e7SDoug Rabson/**
3114c4392e7SDoug Rabson * @brief Activate a resource
3124c4392e7SDoug Rabson *
3134c4392e7SDoug Rabson * Activate a resource previously allocated with
314cc981af2SJohn Baldwin * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
315cc981af2SJohn Baldwin * device for instance.  It will also establish a mapping for the resource
316cc981af2SJohn Baldwin * unless RF_UNMAPPED was set when allocating the resource.
3174c4392e7SDoug Rabson *
3184c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3194c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3204c4392e7SDoug Rabson * @param _r		the resource to activate
3214c4392e7SDoug Rabson */
32214177d72SGarrett WollmanMETHOD int activate_resource {
323bd418641SMark Murray	device_t	_dev;
324bd418641SMark Murray	device_t	_child;
325bd418641SMark Murray	struct resource *_r;
32614177d72SGarrett Wollman};
32714177d72SGarrett Wollman
328cc981af2SJohn Baldwin
329cc981af2SJohn Baldwin/**
330cc981af2SJohn Baldwin * @brief Map a resource
331cc981af2SJohn Baldwin *
332cc981af2SJohn Baldwin * Allocate a mapping for a range of an active resource.  The mapping
333cc981af2SJohn Baldwin * is described by a struct resource_map object.  This may for instance
334cc981af2SJohn Baldwin * map a memory region into the kernel's virtual address space.
335cc981af2SJohn Baldwin *
336cc981af2SJohn Baldwin * @param _dev		the parent device of @p _child
337cc981af2SJohn Baldwin * @param _child	the device which allocated the resource
338cc981af2SJohn Baldwin * @param _r		the resource to map
339cc981af2SJohn Baldwin * @param _args		optional attributes of the mapping
340cc981af2SJohn Baldwin * @param _map		the mapping
341cc981af2SJohn Baldwin */
342cc981af2SJohn BaldwinMETHOD int map_resource {
343cc981af2SJohn Baldwin	device_t	_dev;
344cc981af2SJohn Baldwin	device_t	_child;
345cc981af2SJohn Baldwin	struct resource *_r;
346cc981af2SJohn Baldwin	struct resource_map_request *_args;
347cc981af2SJohn Baldwin	struct resource_map *_map;
348cc981af2SJohn Baldwin} DEFAULT bus_generic_map_resource;
349cc981af2SJohn Baldwin
350cc981af2SJohn Baldwin
351cc981af2SJohn Baldwin/**
352cc981af2SJohn Baldwin * @brief Unmap a resource
353cc981af2SJohn Baldwin *
354cc981af2SJohn Baldwin * Release a mapping previously allocated with
355cc981af2SJohn Baldwin * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
356cc981af2SJohn Baldwin * from the kernel's virtual address space.
357cc981af2SJohn Baldwin *
358cc981af2SJohn Baldwin * @param _dev		the parent device of @p _child
359cc981af2SJohn Baldwin * @param _child	the device which allocated the resource
360cc981af2SJohn Baldwin * @param _r		the resource
361cc981af2SJohn Baldwin * @param _map		the mapping to release
362cc981af2SJohn Baldwin */
363cc981af2SJohn BaldwinMETHOD int unmap_resource {
364cc981af2SJohn Baldwin	device_t	_dev;
365cc981af2SJohn Baldwin	device_t	_child;
366cc981af2SJohn Baldwin	struct resource *_r;
367cc981af2SJohn Baldwin	struct resource_map *_map;
368cc981af2SJohn Baldwin} DEFAULT bus_generic_unmap_resource;
369cc981af2SJohn Baldwin
370cc981af2SJohn Baldwin
3714c4392e7SDoug Rabson/**
3724c4392e7SDoug Rabson * @brief Deactivate a resource
3734c4392e7SDoug Rabson *
3744c4392e7SDoug Rabson * Deactivate a resource previously allocated with
375cc981af2SJohn Baldwin * BUS_ALLOC_RESOURCE().
3764c4392e7SDoug Rabson *
3774c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
3784c4392e7SDoug Rabson * @param _child	the device which allocated the resource
3794c4392e7SDoug Rabson * @param _r		the resource to deactivate
3804c4392e7SDoug Rabson */
38114177d72SGarrett WollmanMETHOD int deactivate_resource {
382bd418641SMark Murray	device_t	_dev;
383bd418641SMark Murray	device_t	_child;
384bd418641SMark Murray	struct resource *_r;
385b1bf6610SDoug Rabson};
38645c95fa1SDoug Rabson
3874c4392e7SDoug Rabson/**
38885ee63c9SJohn Baldwin * @brief Adjust a resource
38985ee63c9SJohn Baldwin *
39085ee63c9SJohn Baldwin * Adjust the start and/or end of a resource allocated by
39185ee63c9SJohn Baldwin * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
39285ee63c9SJohn Baldwin * with the existing address range.  If the successful, the resource's range
39385ee63c9SJohn Baldwin * will be adjusted to [start, end] on return.
39485ee63c9SJohn Baldwin *
39585ee63c9SJohn Baldwin * @param _dev		the parent device of @p _child
39685ee63c9SJohn Baldwin * @param _child	the device which allocated the resource
39785ee63c9SJohn Baldwin * @param _res		the resource to adjust
39885ee63c9SJohn Baldwin * @param _start	the new starting address of the resource range
39985ee63c9SJohn Baldwin * @param _end		the new ending address of the resource range
40085ee63c9SJohn Baldwin */
40185ee63c9SJohn BaldwinMETHOD int adjust_resource {
40285ee63c9SJohn Baldwin	device_t	_dev;
40385ee63c9SJohn Baldwin	device_t	_child;
40485ee63c9SJohn Baldwin	struct resource *_res;
4052dd1bdf1SJustin Hibbits	rman_res_t	_start;
4062dd1bdf1SJustin Hibbits	rman_res_t	_end;
40785ee63c9SJohn Baldwin};
40885ee63c9SJohn Baldwin
409937a05baSJustin Hibbits/**
410937a05baSJustin Hibbits * @brief translate a resource value
411937a05baSJustin Hibbits *
4121fb99e97SMark Johnston * Give a bus driver the opportunity to translate resource ranges.  If
4131fb99e97SMark Johnston * successful, the host's view of the resource starting at @p _start is
4141fb99e97SMark Johnston * returned in @p _newstart, otherwise an error is returned.
415937a05baSJustin Hibbits *
416937a05baSJustin Hibbits * @param _dev		the device associated with the resource
417937a05baSJustin Hibbits * @param _type		the type of resource
418937a05baSJustin Hibbits * @param _start	the starting address of the resource range
419937a05baSJustin Hibbits * @param _newstart	the new starting address of the resource range
420937a05baSJustin Hibbits */
421937a05baSJustin HibbitsMETHOD int translate_resource {
422937a05baSJustin Hibbits	device_t	_dev;
423937a05baSJustin Hibbits	int		_type;
424937a05baSJustin Hibbits	rman_res_t	_start;
425937a05baSJustin Hibbits	rman_res_t	*_newstart;
4261fb99e97SMark Johnston} DEFAULT bus_generic_translate_resource;
427937a05baSJustin Hibbits
42885ee63c9SJohn Baldwin/**
4294c4392e7SDoug Rabson * @brief Release a resource
4304c4392e7SDoug Rabson *
4314c4392e7SDoug Rabson * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
4324c4392e7SDoug Rabson * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
4334c4392e7SDoug Rabson * (which is not necessarily the same as the one the client passed).
4344c4392e7SDoug Rabson *
4354c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4364c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4374c4392e7SDoug Rabson * @param _r		the resource to release
4384c4392e7SDoug Rabson */
43914177d72SGarrett WollmanMETHOD int release_resource {
440bd418641SMark Murray	device_t	_dev;
441bd418641SMark Murray	device_t	_child;
442bd418641SMark Murray	struct resource *_res;
44314177d72SGarrett Wollman};
44414177d72SGarrett Wollman
4454c4392e7SDoug Rabson/**
4464c4392e7SDoug Rabson * @brief Install an interrupt handler
4474c4392e7SDoug Rabson *
4484c4392e7SDoug Rabson * This method is used to associate an interrupt handler function with
4494c4392e7SDoug Rabson * an irq resource. When the interrupt triggers, the function @p _intr
4504c4392e7SDoug Rabson * will be called with the value of @p _arg as its single
4514c4392e7SDoug Rabson * argument. The value returned in @p *_cookiep is used to cancel the
4524c4392e7SDoug Rabson * interrupt handler - the caller should save this value to use in a
4534c4392e7SDoug Rabson * future call to BUS_TEARDOWN_INTR().
4544c4392e7SDoug Rabson *
4554c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4564c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4574c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
4584c4392e7SDoug Rabson * @param _flags	a set of bits from enum intr_type specifying
4594c4392e7SDoug Rabson *			the class of interrupt
4604c4392e7SDoug Rabson * @param _intr		the function to call when the interrupt
4614c4392e7SDoug Rabson *			triggers
4624c4392e7SDoug Rabson * @param _arg		a value to use as the single argument in calls
4634c4392e7SDoug Rabson *			to @p _intr
464e3043798SPedro F. Giffuni * @param _cookiep	a pointer to a location to receive a cookie
4654c4392e7SDoug Rabson *			value that may be used to remove the interrupt
4664c4392e7SDoug Rabson *			handler
4674c4392e7SDoug Rabson */
46814177d72SGarrett WollmanMETHOD int setup_intr {
469bd418641SMark Murray	device_t	_dev;
470bd418641SMark Murray	device_t	_child;
471bd418641SMark Murray	struct resource *_irq;
472bd418641SMark Murray	int		_flags;
473ef544f63SPaolo Pisati	driver_filter_t	*_filter;
474bd418641SMark Murray	driver_intr_t	*_intr;
475bd418641SMark Murray	void		*_arg;
476bd418641SMark Murray	void		**_cookiep;
47714177d72SGarrett Wollman};
47814177d72SGarrett Wollman
4794c4392e7SDoug Rabson/**
4804c4392e7SDoug Rabson * @brief Uninstall an interrupt handler
4814c4392e7SDoug Rabson *
4824c4392e7SDoug Rabson * This method is used to disassociate an interrupt handler function
4834c4392e7SDoug Rabson * with an irq resource. The value of @p _cookie must be the value
4844c4392e7SDoug Rabson * returned from a previous call to BUS_SETUP_INTR().
4854c4392e7SDoug Rabson *
4864c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
4874c4392e7SDoug Rabson * @param _child	the device which allocated the resource
4884c4392e7SDoug Rabson * @param _irq		the resource representing the interrupt
4894c4392e7SDoug Rabson * @param _cookie	the cookie value returned when the interrupt
4904c4392e7SDoug Rabson *			was originally registered
4914c4392e7SDoug Rabson */
49214177d72SGarrett WollmanMETHOD int teardown_intr {
493bd418641SMark Murray	device_t	_dev;
494bd418641SMark Murray	device_t	_child;
495bd418641SMark Murray	struct resource	*_irq;
496bd418641SMark Murray	void		*_cookie;
49745c95fa1SDoug Rabson};
49825afb89bSDoug Rabson
4994c4392e7SDoug Rabson/**
50082a5a275SAndriy Gapon * @brief Suspend an interrupt handler
50182a5a275SAndriy Gapon *
50282a5a275SAndriy Gapon * This method is used to mark a handler as suspended in the case
50382a5a275SAndriy Gapon * that the associated device is powered down and cannot be a source
50482a5a275SAndriy Gapon * for the, typically shared, interrupt.
50582a5a275SAndriy Gapon * The value of @p _irq must be the interrupt resource passed
50682a5a275SAndriy Gapon * to a previous call to BUS_SETUP_INTR().
50782a5a275SAndriy Gapon *
50882a5a275SAndriy Gapon * @param _dev		the parent device of @p _child
50982a5a275SAndriy Gapon * @param _child	the device which allocated the resource
51082a5a275SAndriy Gapon * @param _irq		the resource representing the interrupt
51182a5a275SAndriy Gapon */
51282a5a275SAndriy GaponMETHOD int suspend_intr {
51382a5a275SAndriy Gapon	device_t	_dev;
51482a5a275SAndriy Gapon	device_t	_child;
51582a5a275SAndriy Gapon	struct resource *_irq;
51682a5a275SAndriy Gapon} DEFAULT bus_generic_suspend_intr;
51782a5a275SAndriy Gapon
51882a5a275SAndriy Gapon/**
51982a5a275SAndriy Gapon * @brief Resume an interrupt handler
52082a5a275SAndriy Gapon *
52182a5a275SAndriy Gapon * This method is used to clear suspended state of a handler when
52282a5a275SAndriy Gapon * the associated device is powered up and can be an interrupt source
52382a5a275SAndriy Gapon * again.
52482a5a275SAndriy Gapon * The value of @p _irq must be the interrupt resource passed
52582a5a275SAndriy Gapon * to a previous call to BUS_SETUP_INTR().
52682a5a275SAndriy Gapon *
52782a5a275SAndriy Gapon * @param _dev		the parent device of @p _child
52882a5a275SAndriy Gapon * @param _child	the device which allocated the resource
52982a5a275SAndriy Gapon * @param _irq		the resource representing the interrupt
53082a5a275SAndriy Gapon */
53182a5a275SAndriy GaponMETHOD int resume_intr {
53282a5a275SAndriy Gapon	device_t	_dev;
53382a5a275SAndriy Gapon	device_t	_child;
53482a5a275SAndriy Gapon	struct resource *_irq;
53582a5a275SAndriy Gapon} DEFAULT bus_generic_resume_intr;
53682a5a275SAndriy Gapon
53782a5a275SAndriy Gapon/**
5384c4392e7SDoug Rabson * @brief Define a resource which can be allocated with
5394c4392e7SDoug Rabson * BUS_ALLOC_RESOURCE().
5404c4392e7SDoug Rabson *
541db4fcadfSConrad Meyer * This method is used by some buses (typically ISA) to allow a
5424c4392e7SDoug Rabson * driver to describe a resource range that it would like to
5434c4392e7SDoug Rabson * allocate. The resource defined by @p _type and @p _rid is defined
5444c4392e7SDoug Rabson * to start at @p _start and to include @p _count indices in its
5454c4392e7SDoug Rabson * range.
5464c4392e7SDoug Rabson *
5474c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5484c4392e7SDoug Rabson * @param _child	the device which owns the resource
5494c4392e7SDoug Rabson * @param _type		the type of resource
5504c4392e7SDoug Rabson * @param _rid		the resource identifier
5514c4392e7SDoug Rabson * @param _start	the start of the resource range
5524c4392e7SDoug Rabson * @param _count	the size of the resource range
5534c4392e7SDoug Rabson */
55425afb89bSDoug RabsonMETHOD int set_resource {
555bd418641SMark Murray	device_t	_dev;
556bd418641SMark Murray	device_t	_child;
557bd418641SMark Murray	int		_type;
558bd418641SMark Murray	int		_rid;
5592dd1bdf1SJustin Hibbits	rman_res_t	_start;
5602dd1bdf1SJustin Hibbits	rman_res_t	_count;
56125afb89bSDoug Rabson};
56225afb89bSDoug Rabson
5634c4392e7SDoug Rabson/**
5644c4392e7SDoug Rabson * @brief Describe a resource
5654c4392e7SDoug Rabson *
5664c4392e7SDoug Rabson * This method allows a driver to examine the range used for a given
5674c4392e7SDoug Rabson * resource without actually allocating it.
5684c4392e7SDoug Rabson *
5694c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5704c4392e7SDoug Rabson * @param _child	the device which owns the resource
5714c4392e7SDoug Rabson * @param _type		the type of resource
5724c4392e7SDoug Rabson * @param _rid		the resource identifier
573e3043798SPedro F. Giffuni * @param _start	the address of a location to receive the start
5744c4392e7SDoug Rabson *			index of the resource range
575e3043798SPedro F. Giffuni * @param _count	the address of a location to receive the size
5764c4392e7SDoug Rabson *			of the resource range
5774c4392e7SDoug Rabson */
57825afb89bSDoug RabsonMETHOD int get_resource {
579bd418641SMark Murray	device_t	_dev;
580bd418641SMark Murray	device_t	_child;
581bd418641SMark Murray	int		_type;
582bd418641SMark Murray	int		_rid;
5832dd1bdf1SJustin Hibbits	rman_res_t	*_startp;
5842dd1bdf1SJustin Hibbits	rman_res_t	*_countp;
58525afb89bSDoug Rabson};
58625afb89bSDoug Rabson
5874c4392e7SDoug Rabson/**
5884c4392e7SDoug Rabson * @brief Delete a resource.
5894c4392e7SDoug Rabson *
5904c4392e7SDoug Rabson * Use this to delete a resource (possibly one previously added with
5914c4392e7SDoug Rabson * BUS_SET_RESOURCE()).
5924c4392e7SDoug Rabson *
5934c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
5944c4392e7SDoug Rabson * @param _child	the device which owns the resource
5954c4392e7SDoug Rabson * @param _type		the type of resource
5964c4392e7SDoug Rabson * @param _rid		the resource identifier
5974c4392e7SDoug Rabson */
59825afb89bSDoug RabsonMETHOD void delete_resource {
599bd418641SMark Murray	device_t	_dev;
600bd418641SMark Murray	device_t	_child;
601bd418641SMark Murray	int		_type;
602bd418641SMark Murray	int		_rid;
60325afb89bSDoug Rabson};
6040cb53e24SMatthew N. Dodd
6054c4392e7SDoug Rabson/**
6064c4392e7SDoug Rabson * @brief Return a struct resource_list.
6074c4392e7SDoug Rabson *
6084c4392e7SDoug Rabson * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
6094c4392e7SDoug Rabson * implement their resource handling. It should return the resource
6104c4392e7SDoug Rabson * list of the given child device.
6114c4392e7SDoug Rabson *
6124c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6134c4392e7SDoug Rabson * @param _child	the device which owns the resource list
6144c4392e7SDoug Rabson */
61546aa504eSMatthew N. DoddMETHOD struct resource_list * get_resource_list {
616bd418641SMark Murray	device_t	_dev;
617bd418641SMark Murray	device_t	_child;
618*7979205eSJohn Baldwin} DEFAULT null_get_resource_list;
6195878eb3fSWarner Losh
6204c4392e7SDoug Rabson/**
621751615c5SJohn Baldwin * @brief Return a struct rman.
622751615c5SJohn Baldwin *
623751615c5SJohn Baldwin * Used by drivers which use bus_generic_rman_alloc_resource() etc. to
624751615c5SJohn Baldwin * implement their resource handling. It should return the resource
625751615c5SJohn Baldwin * manager used for the given resource type.
626751615c5SJohn Baldwin *
627751615c5SJohn Baldwin * @param _dev		the bus device
628751615c5SJohn Baldwin * @param _type		the resource type
629751615c5SJohn Baldwin * @param _flags	resource flags (@c RF_XXX flags in
630751615c5SJohn Baldwin *			<sys/rman.h>)
631751615c5SJohn Baldwin */
632751615c5SJohn BaldwinMETHOD struct rman * get_rman {
633751615c5SJohn Baldwin	device_t	_dev;
634751615c5SJohn Baldwin	int		_type;
635751615c5SJohn Baldwin	u_int		_flags;
636751615c5SJohn Baldwin} DEFAULT null_get_rman;
637751615c5SJohn Baldwin
638751615c5SJohn Baldwin/**
6394c4392e7SDoug Rabson * @brief Is the hardware described by @p _child still attached to the
6404c4392e7SDoug Rabson * system?
6414c4392e7SDoug Rabson *
6429f7f340aSWarner Losh * This method should return 0 if the device is not present.  It
6439f7f340aSWarner Losh * should return -1 if it is present.  Any errors in determining
6449f7f340aSWarner Losh * should be returned as a normal errno value.  Client drivers are to
6459f7f340aSWarner Losh * assume that the device is present, even if there is an error
646db4fcadfSConrad Meyer * determining if it is there.  Buses are to try to avoid returning
6479f7f340aSWarner Losh * errors, but newcard will return an error if the device fails to
6489f7f340aSWarner Losh * implement this method.
6494c4392e7SDoug Rabson *
6504c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6514c4392e7SDoug Rabson * @param _child	the device which is being examined
6524c4392e7SDoug Rabson */
6535878eb3fSWarner LoshMETHOD int child_present {
6545878eb3fSWarner Losh	device_t	_dev;
6555878eb3fSWarner Losh	device_t	_child;
6565878eb3fSWarner Losh} DEFAULT bus_generic_child_present;
6573d9841b4SWarner Losh
6584c4392e7SDoug Rabson/**
6594c4392e7SDoug Rabson * @brief Returns the pnp info for this device.
6604c4392e7SDoug Rabson *
661ddfc9c4cSWarner Losh * Return it as a string, appended to @p _sb
6624c4392e7SDoug Rabson *
663ed7ed7f0SJohn Baldwin * The string must be formatted as a space-separated list of
664ed7ed7f0SJohn Baldwin * name=value pairs.  Names may only contain alphanumeric characters,
665ed7ed7f0SJohn Baldwin * underscores ('_') and hyphens ('-').  Values can contain any
666ed7ed7f0SJohn Baldwin * non-whitespace characters.  Values containing whitespace can be
667ed7ed7f0SJohn Baldwin * quoted with double quotes ('"').  Double quotes and backslashes in
668ed7ed7f0SJohn Baldwin * quoted values can be escaped with backslashes ('\').
669ed7ed7f0SJohn Baldwin *
6704c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6714c4392e7SDoug Rabson * @param _child	the device which is being examined
672ddfc9c4cSWarner Losh * @param _sb		sbuf for results string
6734c4392e7SDoug Rabson */
674ddfc9c4cSWarner LoshMETHOD int child_pnpinfo {
6753d9841b4SWarner Losh	device_t	_dev;
6763d9841b4SWarner Losh	device_t	_child;
677ddfc9c4cSWarner Losh	struct sbuf	*_sb;
678ddfc9c4cSWarner Losh} DEFAULT bus_generic_child_pnpinfo;
6793d9841b4SWarner Losh
6804c4392e7SDoug Rabson/**
6814c4392e7SDoug Rabson * @brief Returns the location for this device.
6824c4392e7SDoug Rabson *
683ddfc9c4cSWarner Losh * Return it as a string, appended to @p _sb
6844c4392e7SDoug Rabson *
685ed7ed7f0SJohn Baldwin * The string must be formatted as a space-separated list of
686ed7ed7f0SJohn Baldwin * name=value pairs.  Names may only contain alphanumeric characters,
687ed7ed7f0SJohn Baldwin * underscores ('_') and hyphens ('-').  Values can contain any
688ed7ed7f0SJohn Baldwin * non-whitespace characters.  Values containing whitespace can be
689ed7ed7f0SJohn Baldwin * quoted with double quotes ('"').  Double quotes and backslashes in
690ed7ed7f0SJohn Baldwin * quoted values can be escaped with backslashes ('\').
691ed7ed7f0SJohn Baldwin *
6924c4392e7SDoug Rabson * @param _dev		the parent device of @p _child
6934c4392e7SDoug Rabson * @param _child	the device which is being examined
694ddfc9c4cSWarner Losh * @param _sb		sbuf for results string
6954c4392e7SDoug Rabson */
696ddfc9c4cSWarner LoshMETHOD int child_location {
6973d9841b4SWarner Losh	device_t	_dev;
6983d9841b4SWarner Losh	device_t	_child;
699ddfc9c4cSWarner Losh	struct sbuf	*_sb;
700ddfc9c4cSWarner Losh} DEFAULT bus_generic_child_location;
701da13b8f9SMarcel Moolenaar
7024c4392e7SDoug Rabson/**
703dcc81068SJohn Baldwin * @brief Allow drivers to request that an interrupt be bound to a specific
704dcc81068SJohn Baldwin * CPU.
705dcc81068SJohn Baldwin *
706dcc81068SJohn Baldwin * @param _dev		the parent device of @p _child
707dcc81068SJohn Baldwin * @param _child	the device which allocated the resource
708dcc81068SJohn Baldwin * @param _irq		the resource representing the interrupt
709dcc81068SJohn Baldwin * @param _cpu		the CPU to bind the interrupt to
710dcc81068SJohn Baldwin */
711dcc81068SJohn BaldwinMETHOD int bind_intr {
712dcc81068SJohn Baldwin	device_t	_dev;
713dcc81068SJohn Baldwin	device_t	_child;
714dcc81068SJohn Baldwin	struct resource *_irq;
715dcc81068SJohn Baldwin	int		_cpu;
716dcc81068SJohn Baldwin} DEFAULT bus_generic_bind_intr;
717dcc81068SJohn Baldwin
718dcc81068SJohn Baldwin/**
7194c4392e7SDoug Rabson * @brief Allow (bus) drivers to specify the trigger mode and polarity
7204c4392e7SDoug Rabson * of the specified interrupt.
7214c4392e7SDoug Rabson *
7224c4392e7SDoug Rabson * @param _dev		the bus device
7234c4392e7SDoug Rabson * @param _irq		the interrupt number to modify
7244c4392e7SDoug Rabson * @param _trig		the trigger mode required
7254c4392e7SDoug Rabson * @param _pol		the interrupt polarity required
7264c4392e7SDoug Rabson */
727da13b8f9SMarcel MoolenaarMETHOD int config_intr {
728da13b8f9SMarcel Moolenaar	device_t	_dev;
729da13b8f9SMarcel Moolenaar	int		_irq;
730da13b8f9SMarcel Moolenaar	enum intr_trigger _trig;
731da13b8f9SMarcel Moolenaar	enum intr_polarity _pol;
732da13b8f9SMarcel Moolenaar} DEFAULT bus_generic_config_intr;
733db2bc1bbSWarner Losh
734db2bc1bbSWarner Losh/**
73537b8ef16SJohn Baldwin * @brief Allow drivers to associate a description with an active
73637b8ef16SJohn Baldwin * interrupt handler.
73737b8ef16SJohn Baldwin *
73837b8ef16SJohn Baldwin * @param _dev		the parent device of @p _child
73937b8ef16SJohn Baldwin * @param _child	the device which allocated the resource
74037b8ef16SJohn Baldwin * @param _irq		the resource representing the interrupt
74137b8ef16SJohn Baldwin * @param _cookie	the cookie value returned when the interrupt
74237b8ef16SJohn Baldwin *			was originally registered
74337b8ef16SJohn Baldwin * @param _descr	the description to associate with the interrupt
74437b8ef16SJohn Baldwin */
74537b8ef16SJohn BaldwinMETHOD int describe_intr {
74637b8ef16SJohn Baldwin	device_t	_dev;
74737b8ef16SJohn Baldwin	device_t	_child;
74837b8ef16SJohn Baldwin	struct resource *_irq;
74937b8ef16SJohn Baldwin	void		*_cookie;
75037b8ef16SJohn Baldwin	const char	*_descr;
75137b8ef16SJohn Baldwin} DEFAULT bus_generic_describe_intr;
75237b8ef16SJohn Baldwin
75337b8ef16SJohn Baldwin/**
754db2bc1bbSWarner Losh * @brief Notify a (bus) driver about a child that the hints mechanism
755db2bc1bbSWarner Losh * believes it has discovered.
756db2bc1bbSWarner Losh *
757db2bc1bbSWarner Losh * The bus is responsible for then adding the child in the right order
758db2bc1bbSWarner Losh * and discovering other things about the child.  The bus driver is
759db2bc1bbSWarner Losh * free to ignore this hint, to do special things, etc.  It is all up
760db2bc1bbSWarner Losh * to the bus driver to interpret.
761db2bc1bbSWarner Losh *
762db2bc1bbSWarner Losh * This method is only called in response to the parent bus asking for
763db2bc1bbSWarner Losh * hinted devices to be enumerated.
764db2bc1bbSWarner Losh *
765db2bc1bbSWarner Losh * @param _dev		the bus device
766db2bc1bbSWarner Losh * @param _dname	the name of the device w/o unit numbers
767db2bc1bbSWarner Losh * @param _dunit	the unit number of the device
768db2bc1bbSWarner Losh */
769db2bc1bbSWarner LoshMETHOD void hinted_child {
770db2bc1bbSWarner Losh	device_t	_dev;
771db2bc1bbSWarner Losh	const char	*_dname;
772db2bc1bbSWarner Losh	int		_dunit;
773db2bc1bbSWarner Losh};
774378f231eSJohn-Mark Gurney
775378f231eSJohn-Mark Gurney/**
776378f231eSJohn-Mark Gurney * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
777378f231eSJohn-Mark Gurney *
778378f231eSJohn-Mark Gurney * @param _dev		the parent device of @p _child
779378f231eSJohn-Mark Gurney * @param _child	the device to which the tag will belong
780378f231eSJohn-Mark Gurney */
781378f231eSJohn-Mark GurneyMETHOD bus_dma_tag_t get_dma_tag {
782378f231eSJohn-Mark Gurney	device_t	_dev;
783378f231eSJohn-Mark Gurney	device_t	_child;
784378f231eSJohn-Mark Gurney} DEFAULT bus_generic_get_dma_tag;
7850d484d24SJohn Baldwin
7860d484d24SJohn Baldwin/**
787b998c965SZbigniew Bodek * @brief Returns bus_space_tag_t for use w/ devices on the bus.
788b998c965SZbigniew Bodek *
789b998c965SZbigniew Bodek * @param _dev		the parent device of @p _child
790b998c965SZbigniew Bodek * @param _child	the device to which the tag will belong
791b998c965SZbigniew Bodek */
792b998c965SZbigniew BodekMETHOD bus_space_tag_t get_bus_tag {
793b998c965SZbigniew Bodek	device_t	_dev;
794b998c965SZbigniew Bodek	device_t	_child;
795b998c965SZbigniew Bodek} DEFAULT bus_generic_get_bus_tag;
796b998c965SZbigniew Bodek
797b998c965SZbigniew Bodek/**
7980d484d24SJohn Baldwin * @brief Allow the bus to determine the unit number of a device.
7990d484d24SJohn Baldwin *
8000d484d24SJohn Baldwin * @param _dev		the parent device of @p _child
8010d484d24SJohn Baldwin * @param _child	the device whose unit is to be wired
8020d484d24SJohn Baldwin * @param _name		the name of the device's new devclass
8030d484d24SJohn Baldwin * @param _unitp	a pointer to the device's new unit value
8040d484d24SJohn Baldwin */
8050d484d24SJohn BaldwinMETHOD void hint_device_unit {
8060d484d24SJohn Baldwin	device_t	_dev;
8070d484d24SJohn Baldwin	device_t	_child;
8080d484d24SJohn Baldwin	const char	*_name;
8090d484d24SJohn Baldwin	int		*_unitp;
8100d484d24SJohn Baldwin};
8110d484d24SJohn Baldwin
8124ef60d26SJohn Baldwin/**
8134ef60d26SJohn Baldwin * @brief Notify a bus that the bus pass level has been changed
8144ef60d26SJohn Baldwin *
8154ef60d26SJohn Baldwin * @param _dev		the bus device
8164ef60d26SJohn Baldwin */
8174ef60d26SJohn BaldwinMETHOD void new_pass {
8184ef60d26SJohn Baldwin	device_t	_dev;
8194ef60d26SJohn Baldwin} DEFAULT bus_generic_new_pass;
82093fc07b4SAlexander Motin
82193fc07b4SAlexander Motin/**
82293fc07b4SAlexander Motin * @brief Notify a bus that specified child's IRQ should be remapped.
82393fc07b4SAlexander Motin *
82493fc07b4SAlexander Motin * @param _dev		the bus device
82593fc07b4SAlexander Motin * @param _child	the child device
82693fc07b4SAlexander Motin * @param _irq		the irq number
82793fc07b4SAlexander Motin */
82893fc07b4SAlexander MotinMETHOD int remap_intr {
82993fc07b4SAlexander Motin	device_t	_dev;
83093fc07b4SAlexander Motin	device_t	_child;
83193fc07b4SAlexander Motin	u_int		_irq;
83293fc07b4SAlexander Motin} DEFAULT null_remap_intr;
833a1c16348SJustin Hibbits
834a1c16348SJustin Hibbits/**
835a1c16348SJustin Hibbits * @brief Suspend a given child
836a1c16348SJustin Hibbits *
837a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
838a1c16348SJustin Hibbits * @param _child	the device to suspend
839a1c16348SJustin Hibbits */
840a1c16348SJustin HibbitsMETHOD int suspend_child {
841a1c16348SJustin Hibbits	device_t	_dev;
842a1c16348SJustin Hibbits	device_t	_child;
843a1c16348SJustin Hibbits} DEFAULT bus_generic_suspend_child;
844a1c16348SJustin Hibbits
845a1c16348SJustin Hibbits/**
846a1c16348SJustin Hibbits * @brief Resume a given child
847a1c16348SJustin Hibbits *
848a1c16348SJustin Hibbits * @param _dev		the parent device of @p _child
849a1c16348SJustin Hibbits * @param _child	the device to resume
850a1c16348SJustin Hibbits */
851a1c16348SJustin HibbitsMETHOD int resume_child {
852a1c16348SJustin Hibbits	device_t	_dev;
853a1c16348SJustin Hibbits	device_t	_child;
854a1c16348SJustin Hibbits} DEFAULT bus_generic_resume_child;
855ffcf962dSAdrian Chadd
856ffcf962dSAdrian Chadd/**
857ffcf962dSAdrian Chadd * @brief Get the VM domain handle for the given bus and child.
858ffcf962dSAdrian Chadd *
859ffcf962dSAdrian Chadd * @param _dev		the bus device
860ffcf962dSAdrian Chadd * @param _child	the child device
861ffcf962dSAdrian Chadd * @param _domain	a pointer to the bus's domain handle identifier
862ffcf962dSAdrian Chadd */
863ffcf962dSAdrian ChaddMETHOD int get_domain {
864ffcf962dSAdrian Chadd	device_t	_dev;
865ffcf962dSAdrian Chadd	device_t	_child;
866ffcf962dSAdrian Chadd	int		*_domain;
867ffcf962dSAdrian Chadd} DEFAULT bus_generic_get_domain;
8688d791e5aSJohn Baldwin
8698d791e5aSJohn Baldwin/**
8708d791e5aSJohn Baldwin * @brief Request a set of CPUs
8718d791e5aSJohn Baldwin *
8728d791e5aSJohn Baldwin * @param _dev		the bus device
8738d791e5aSJohn Baldwin * @param _child	the child device
8748d791e5aSJohn Baldwin * @param _op		type of CPUs to request
8758d791e5aSJohn Baldwin * @param _setsize	the size of the set passed in _cpuset
8768d791e5aSJohn Baldwin * @param _cpuset	a pointer to a cpuset to receive the requested
8778d791e5aSJohn Baldwin *			set of CPUs
8788d791e5aSJohn Baldwin */
8798d791e5aSJohn BaldwinMETHOD int get_cpus {
8808d791e5aSJohn Baldwin	device_t	_dev;
8818d791e5aSJohn Baldwin	device_t	_child;
8828d791e5aSJohn Baldwin	enum cpu_sets	_op;
8838d791e5aSJohn Baldwin	size_t		_setsize;
884e2e050c8SConrad Meyer	struct _cpuset	*_cpuset;
8858d791e5aSJohn Baldwin} DEFAULT bus_generic_get_cpus;
886c53df6daSKonstantin Belousov
887c53df6daSKonstantin Belousov/**
888c53df6daSKonstantin Belousov * @brief Prepares the given child of the bus for reset
889c53df6daSKonstantin Belousov *
890c53df6daSKonstantin Belousov * Typically bus detaches or suspends children' drivers, and then
891c53df6daSKonstantin Belousov * calls this method to save bus-specific information, for instance,
892c53df6daSKonstantin Belousov * PCI config space, which is damaged by reset.
893c53df6daSKonstantin Belousov *
894c53df6daSKonstantin Belousov * The bus_helper_reset_prepare() helper is provided to ease
895c53df6daSKonstantin Belousov * implementing bus reset methods.
896c53df6daSKonstantin Belousov *
897c53df6daSKonstantin Belousov * @param _dev		the bus device
898c53df6daSKonstantin Belousov * @param _child	the child device
899c53df6daSKonstantin Belousov */
900c53df6daSKonstantin BelousovMETHOD int reset_prepare {
901c53df6daSKonstantin Belousov	device_t _dev;
902c53df6daSKonstantin Belousov	device_t _child;
903c53df6daSKonstantin Belousov} DEFAULT null_reset_prepare;
904c53df6daSKonstantin Belousov
905c53df6daSKonstantin Belousov/**
906c53df6daSKonstantin Belousov * @brief Restores the child operations after the reset
907c53df6daSKonstantin Belousov *
908c53df6daSKonstantin Belousov * The bus_helper_reset_post() helper is provided to ease
909c53df6daSKonstantin Belousov * implementing bus reset methods.
910c53df6daSKonstantin Belousov *
911c53df6daSKonstantin Belousov * @param _dev		the bus device
912c53df6daSKonstantin Belousov * @param _child	the child device
913c53df6daSKonstantin Belousov */
914c53df6daSKonstantin BelousovMETHOD int reset_post {
915c53df6daSKonstantin Belousov	device_t _dev;
916c53df6daSKonstantin Belousov	device_t _child;
917c53df6daSKonstantin Belousov} DEFAULT null_reset_post;
918c53df6daSKonstantin Belousov
919c53df6daSKonstantin Belousov/**
920c53df6daSKonstantin Belousov * @brief Performs reset of the child
921c53df6daSKonstantin Belousov *
922c53df6daSKonstantin Belousov * @param _dev		the bus device
923c53df6daSKonstantin Belousov * @param _child	the child device
924c53df6daSKonstantin Belousov * @param _flags	DEVF_RESET_ flags
925c53df6daSKonstantin Belousov */
926c53df6daSKonstantin BelousovMETHOD int reset_child {
927c53df6daSKonstantin Belousov	device_t _dev;
928c53df6daSKonstantin Belousov	device_t _child;
929c53df6daSKonstantin Belousov	int _flags;
930c53df6daSKonstantin Belousov};
9313f9a00e3SBartlomiej Grzesik
9323f9a00e3SBartlomiej Grzesik/**
9333f9a00e3SBartlomiej Grzesik * @brief Gets child's specific property
9343f9a00e3SBartlomiej Grzesik *
9353f9a00e3SBartlomiej Grzesik * The bus_get_property can be used to access device
9363f9a00e3SBartlomiej Grzesik * specific properties stored on the bus. If _propvalue
9373f9a00e3SBartlomiej Grzesik * is NULL or _size is 0, then method only returns size
9383f9a00e3SBartlomiej Grzesik * of the property.
9393f9a00e3SBartlomiej Grzesik *
9403f9a00e3SBartlomiej Grzesik * @param _dev			the bus device
9413f9a00e3SBartlomiej Grzesik * @param _child		the child device
9423f9a00e3SBartlomiej Grzesik * @param _propname		property name
9433f9a00e3SBartlomiej Grzesik * @param _propvalue	property value destination
9443f9a00e3SBartlomiej Grzesik * @param _size			property value size
9453f9a00e3SBartlomiej Grzesik *
9463f9a00e3SBartlomiej Grzesik * @returns size of property if successful otherwise -1
9473f9a00e3SBartlomiej Grzesik */
9483f9a00e3SBartlomiej GrzesikMETHOD ssize_t get_property {
9493f9a00e3SBartlomiej Grzesik	device_t _dev;
9503f9a00e3SBartlomiej Grzesik	device_t _child;
9513f9a00e3SBartlomiej Grzesik	const char *_propname;
9523f9a00e3SBartlomiej Grzesik	void *_propvalue;
9533f9a00e3SBartlomiej Grzesik	size_t _size;
954b344de4dSKornel Duleba	device_property_type_t type;
955206dc82bSKornel Duleba} DEFAULT bus_generic_get_property;
956e19db707SWarner Losh
957e19db707SWarner Losh/**
958e19db707SWarner Losh * @brief Gets a child's full path to the device
959e19db707SWarner Losh *
960e19db707SWarner Losh * The get_device_path method retrieves a device's
961e19db707SWarner Losh * full path to the device using one of several
962e19db707SWarner Losh * locators present in the system.
963e19db707SWarner Losh *
964e19db707SWarner Losh * @param _bus			the bus device
965e19db707SWarner Losh * @param _child		the child device
966e19db707SWarner Losh * @param _locator		locator name
967e19db707SWarner Losh * @param _sb			buffer loaction string
968e19db707SWarner Losh */
969e19db707SWarner LoshMETHOD int get_device_path {
970e19db707SWarner Losh	device_t _bus;
971e19db707SWarner Losh	device_t _child;
972e19db707SWarner Losh	const char *_locator;
973e19db707SWarner Losh	struct sbuf *_sb;
974e19db707SWarner Losh} DEFAULT bus_generic_get_device_path;
975