1139804Simp#-
2133588Simp# Copyright (c) 1998-2004 Doug Rabson
336973Sdfr# All rights reserved.
436973Sdfr#
536973Sdfr# Redistribution and use in source and binary forms, with or without
636973Sdfr# modification, are permitted provided that the following conditions
736973Sdfr# are met:
836973Sdfr# 1. Redistributions of source code must retain the above copyright
936973Sdfr#    notice, this list of conditions and the following disclaimer.
1036973Sdfr# 2. Redistributions in binary form must reproduce the above copyright
1136973Sdfr#    notice, this list of conditions and the following disclaimer in the
1236973Sdfr#    documentation and/or other materials provided with the distribution.
1336973Sdfr#
1436973Sdfr# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536973Sdfr# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636973Sdfr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736973Sdfr# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836973Sdfr# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936973Sdfr# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036973Sdfr# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136973Sdfr# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236973Sdfr# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336973Sdfr# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436973Sdfr# SUCH DAMAGE.
2536973Sdfr#
2650477Speter# $FreeBSD: releng/11.0/sys/kern/bus_if.m 301451 2016-06-05 16:07:57Z skra $
2736973Sdfr#
2836973Sdfr
29212544Savg#include <sys/types.h>
30212544Savg#include <sys/systm.h>
3159093Sdfr#include <sys/bus.h>
3259093Sdfr
33132354Sdfr/**
34132354Sdfr * @defgroup BUS bus - KObj methods for drivers of devices with children
35132354Sdfr * @brief A set of methods required device drivers that support
36132354Sdfr * child devices.
37132354Sdfr * @{
38132354Sdfr */
3941017SnsouchINTERFACE bus;
4036973Sdfr
4136973Sdfr#
4246913Sdfr# Default implementations of some methods.
4346913Sdfr#
4446913SdfrCODE {
4546913Sdfr	static struct resource *
4646913Sdfr	null_alloc_resource(device_t dev, device_t child,
47294883Sjhibbits	    int type, int *rid, rman_res_t start, rman_res_t end,
48294883Sjhibbits	    rman_res_t count, u_int flags)
4946913Sdfr	{
50100421Simp	    return (0);
5146913Sdfr	}
52209154Smav
53209154Smav	static int
54209154Smav	null_remap_intr(device_t bus, device_t dev, u_int irq)
55209154Smav	{
56209154Smav
57209154Smav		if (dev != NULL)
58209154Smav			return (BUS_REMAP_INTR(dev, NULL, irq));
59209154Smav		return (ENXIO);
60209154Smav	}
61212544Savg
62212544Savg	static device_t
63212544Savg	null_add_child(device_t bus, int order, const char *name,
64212544Savg	    int unit)
65212544Savg	{
66212544Savg
67212544Savg		panic("bus_add_child is not implemented");
68212544Savg	}
6946913Sdfr};
7046913Sdfr
71132354Sdfr/**
72132354Sdfr * @brief Print a description of a child device
73132354Sdfr *
74132354Sdfr * This is called from system code which prints out a description of a
75132354Sdfr * device. It should describe the attachment that the child has with
76132354Sdfr * the parent. For instance the TurboLaser bus prints which node the
77132354Sdfr * device is attached to. See bus_generic_print_child() for more 
78132354Sdfr * information.
79132354Sdfr *
80132354Sdfr * @param _dev		the device whose child is being printed
81132354Sdfr * @param _child	the child device to describe
82132354Sdfr *
83132354Sdfr * @returns		the number of characters output.
84132354Sdfr */
8549195SmdoddMETHOD int print_child {
86132354Sdfr	device_t _dev;
87132354Sdfr	device_t _child;
88112588Smdodd} DEFAULT bus_generic_print_child;
8936973Sdfr
90132354Sdfr/**
91132354Sdfr * @brief Print a notification about an unprobed child device.
92132354Sdfr *
93132354Sdfr * Called for each child device that did not succeed in probing for a
94132354Sdfr * driver.
95132354Sdfr *
96132354Sdfr * @param _dev		the device whose child was being probed
97132354Sdfr * @param _child	the child device which failed to probe
98132354Sdfr */   
9948754SdfrMETHOD void probe_nomatch {
100132354Sdfr        device_t _dev;
101132354Sdfr        device_t _child;
10248754Sdfr};
10348754Sdfr
104132354Sdfr/**
105132354Sdfr * @brief Read the value of a bus-specific attribute of a device
106132354Sdfr *
107132354Sdfr * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
108132354Sdfr * of instance variables of a child device.  The intention is that
109132354Sdfr * each different type of bus defines a set of appropriate instance
110132354Sdfr * variables (such as ports and irqs for ISA bus etc.)
111132354Sdfr *
112132354Sdfr * This information could be given to the child device as a struct but
113132354Sdfr * that makes it hard for a bus to add or remove variables without
114132354Sdfr * forcing an edit and recompile for all drivers which may not be
115132354Sdfr * possible for vendor supplied binary drivers.
116132354Sdfr *
117132354Sdfr * This method copies the value of an instance variable to the
118132354Sdfr * location specified by @p *_result.
119132354Sdfr * 
120132354Sdfr * @param _dev		the device whose child was being examined
121132354Sdfr * @param _child	the child device whose instance variable is
122132354Sdfr *			being read
123132354Sdfr * @param _index	the instance variable to read
124298819Spfg * @param _result	a location to receive the instance variable
125132354Sdfr *			value
126132354Sdfr * 
127132354Sdfr * @retval 0		success
128132354Sdfr * @retval ENOENT	no such instance variable is supported by @p
129132354Sdfr *			_dev 
130132354Sdfr */
13136973SdfrMETHOD int read_ivar {
13295201Smarkm	device_t _dev;
13395201Smarkm	device_t _child;
134132354Sdfr	int _index;
13595201Smarkm	uintptr_t *_result;
13636973Sdfr};
13736973Sdfr
138132354Sdfr/**
139132354Sdfr * @brief Write the value of a bus-specific attribute of a device
140132354Sdfr * 
141132354Sdfr * This method sets the value of an instance variable to @p _value.
142132354Sdfr * 
143132354Sdfr * @param _dev		the device whose child was being updated
144132354Sdfr * @param _child	the child device whose instance variable is
145132354Sdfr *			being written
146132354Sdfr * @param _index	the instance variable to write
147132354Sdfr * @param _value	the value to write to that instance variable
148132354Sdfr * 
149132354Sdfr * @retval 0		success
150132354Sdfr * @retval ENOENT	no such instance variable is supported by @p
151132354Sdfr *			_dev 
152132354Sdfr * @retval EINVAL	the instance variable was recognised but
153132354Sdfr *			contains a read-only value
154132354Sdfr */
15536973SdfrMETHOD int write_ivar {
15695201Smarkm	device_t _dev;
15795201Smarkm	device_t _child;
15895201Smarkm	int _indx;
15995201Smarkm	uintptr_t _value;
16036973Sdfr};
16136973Sdfr
162132354Sdfr/**
163239512Sjhb * @brief Notify a bus that a child was deleted
164239512Sjhb *
165239512Sjhb * Called at the beginning of device_delete_child() to allow the parent
166239512Sjhb * to teardown any bus-specific state for the child.
167239512Sjhb * 
168239512Sjhb * @param _dev		the device whose child is being deleted
169239512Sjhb * @param _child	the child device which is being deleted
170239512Sjhb */
171239512SjhbMETHOD void child_deleted {
172239512Sjhb	device_t _dev;
173239512Sjhb	device_t _child;
174239512Sjhb};
175239512Sjhb
176239512Sjhb/**
177132354Sdfr * @brief Notify a bus that a child was detached
178132354Sdfr *
179132354Sdfr * Called after the child's DEVICE_DETACH() method to allow the parent
180132354Sdfr * to reclaim any resources allocated on behalf of the child.
181132354Sdfr * 
182132354Sdfr * @param _dev		the device whose child changed state
183132354Sdfr * @param _child	the child device which changed state
184132354Sdfr */
18545107SdfrMETHOD void child_detached {
18695201Smarkm	device_t _dev;
18795201Smarkm	device_t _child;
18845107Sdfr};
18945107Sdfr
190132354Sdfr/**
191132354Sdfr * @brief Notify a bus that a new driver was added
192132354Sdfr * 
193132354Sdfr * Called when a new driver is added to the devclass which owns this
194132354Sdfr * bus. The generic implementation of this method attempts to probe and
195132354Sdfr * attach any un-matched children of the bus.
196132354Sdfr * 
197132354Sdfr * @param _dev		the device whose devclass had a new driver
198132354Sdfr *			added to it
199132354Sdfr * @param _driver	the new driver which was added
200132354Sdfr */
20145720SpeterMETHOD void driver_added {
20295201Smarkm	device_t _dev;
20395201Smarkm	driver_t *_driver;
20452045Simp} DEFAULT bus_generic_driver_added;
20545720Speter
206132354Sdfr/**
207132354Sdfr * @brief Create a new child device
208132354Sdfr *
209132354Sdfr * For busses which use use drivers supporting DEVICE_IDENTIFY() to
210132354Sdfr * enumerate their devices, this method is used to create new
211132354Sdfr * device instances. The new device will be added after the last
212290117Simp * existing child with the same order. Implementations of bus_add_child
213290117Simp * call device_add_child_ordered to add the child and often add
214290117Simp * a suitable ivar to the device specific to that bus.
215132354Sdfr * 
216132354Sdfr * @param _dev		the bus device which will be the parent of the
217132354Sdfr *			new child device
218132354Sdfr * @param _order	a value which is used to partially sort the
219132354Sdfr *			children of @p _dev - devices created using
220132354Sdfr *			lower values of @p _order appear first in @p
221132354Sdfr *			_dev's list of children
222132354Sdfr * @param _name		devclass name for new device or @c NULL if not
223132354Sdfr *			specified
224132354Sdfr * @param _unit		unit number for new device or @c -1 if not
225132354Sdfr *			specified
226132354Sdfr */
22747178SdfrMETHOD device_t add_child {
22895201Smarkm	device_t _dev;
229212413Savg	u_int _order;
23095201Smarkm	const char *_name;
23195201Smarkm	int _unit;
232212544Savg} DEFAULT null_add_child;
23347178Sdfr
234132354Sdfr/**
235298707Sjhb * @brief Rescan the bus
236298707Sjhb *
237298707Sjhb * This method is called by a parent bridge or devctl to trigger a bus
238298707Sjhb * rescan.  The rescan should delete devices no longer present and
239298707Sjhb * enumerate devices that have newly arrived.
240298707Sjhb *
241298707Sjhb * @param _dev		the bus device
242298707Sjhb */
243298707SjhbMETHOD int rescan {
244298707Sjhb	device_t _dev;
245298707Sjhb}
246298707Sjhb
247298707Sjhb/**
248132354Sdfr * @brief Allocate a system resource
249132354Sdfr *
250132354Sdfr * This method is called by child devices of a bus to allocate resources.
251132354Sdfr * The types are defined in <machine/resource.h>; the meaning of the
252132354Sdfr * resource-ID field varies from bus to bus (but @p *rid == 0 is always
253132354Sdfr * valid if the resource type is). If a resource was allocated and the
254132354Sdfr * caller did not use the RF_ACTIVE to specify that it should be
255132354Sdfr * activated immediately, the caller is responsible for calling
256132354Sdfr * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
257132354Sdfr *
258132354Sdfr * @param _dev		the parent device of @p _child
259132354Sdfr * @param _child	the device which is requesting an allocation
260132354Sdfr * @param _type		the type of resource to allocate
261132354Sdfr * @param _rid		a pointer to the resource identifier
262132354Sdfr * @param _start	hint at the start of the resource range - pass
263296336Sjhibbits *			@c 0 for any start address
264132354Sdfr * @param _end		hint at the end of the resource range - pass
265296336Sjhibbits *			@c ~0 for any end address
266132354Sdfr * @param _count	hint at the size of range required - pass @c 1
267132354Sdfr *			for any size
268132354Sdfr * @param _flags	any extra flags to control the resource
269132354Sdfr *			allocation - see @c RF_XXX flags in
270132354Sdfr *			<sys/rman.h> for details
271132354Sdfr * 
272132354Sdfr * @returns		the resource which was allocated or @c NULL if no
273132354Sdfr *			resource could be allocated
274132354Sdfr */
27541153SwollmanMETHOD struct resource * alloc_resource {
27695201Smarkm	device_t	_dev;
27795201Smarkm	device_t	_child;
27895201Smarkm	int		_type;
27995201Smarkm	int	       *_rid;
280294883Sjhibbits	rman_res_t	_start;
281294883Sjhibbits	rman_res_t	_end;
282294883Sjhibbits	rman_res_t	_count;
28395201Smarkm	u_int		_flags;
28446913Sdfr} DEFAULT null_alloc_resource;
28537592Sdfr
286132354Sdfr/**
287132354Sdfr * @brief Activate a resource
288132354Sdfr *
289132354Sdfr * Activate a resource previously allocated with
290300317Sjhb * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
291300317Sjhb * device for instance.  It will also establish a mapping for the resource
292300317Sjhb * unless RF_UNMAPPED was set when allocating the resource.
293132354Sdfr *
294132354Sdfr * @param _dev		the parent device of @p _child
295132354Sdfr * @param _child	the device which allocated the resource
296132354Sdfr * @param _type		the type of resource
297132354Sdfr * @param _rid		the resource identifier
298132354Sdfr * @param _r		the resource to activate
299132354Sdfr */
30041153SwollmanMETHOD int activate_resource {
30195201Smarkm	device_t	_dev;
30295201Smarkm	device_t	_child;
30395201Smarkm	int		_type;
30495201Smarkm	int		_rid;
30595201Smarkm	struct resource *_r;
30641153Swollman};
30741153Swollman
308300317Sjhb
309132354Sdfr/**
310300317Sjhb * @brief Map a resource
311300317Sjhb *
312300317Sjhb * Allocate a mapping for a range of an active resource.  The mapping
313300317Sjhb * is described by a struct resource_map object.  This may for instance
314300317Sjhb * map a memory region into the kernel's virtual address space.
315300317Sjhb *
316300317Sjhb * @param _dev		the parent device of @p _child
317300317Sjhb * @param _child	the device which allocated the resource
318300317Sjhb * @param _type		the type of resource
319300317Sjhb * @param _r		the resource to map
320300317Sjhb * @param _args		optional attributes of the mapping
321300317Sjhb * @param _map		the mapping
322300317Sjhb */
323300317SjhbMETHOD int map_resource {
324300317Sjhb	device_t	_dev;
325300317Sjhb	device_t	_child;
326300317Sjhb	int		_type;
327300317Sjhb	struct resource *_r;
328300317Sjhb	struct resource_map_request *_args;
329300317Sjhb	struct resource_map *_map;
330300317Sjhb} DEFAULT bus_generic_map_resource;
331300317Sjhb
332300317Sjhb
333300317Sjhb/**
334300317Sjhb * @brief Unmap a resource
335300317Sjhb *
336300317Sjhb * Release a mapping previously allocated with
337300317Sjhb * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
338300317Sjhb * from the kernel's virtual address space.
339300317Sjhb *
340300317Sjhb * @param _dev		the parent device of @p _child
341300317Sjhb * @param _child	the device which allocated the resource
342300317Sjhb * @param _type		the type of resource
343300317Sjhb * @param _r		the resource
344300317Sjhb * @param _map		the mapping to release
345300317Sjhb */
346300317SjhbMETHOD int unmap_resource {
347300317Sjhb	device_t	_dev;
348300317Sjhb	device_t	_child;
349300317Sjhb	int		_type;
350300317Sjhb	struct resource *_r;
351300317Sjhb	struct resource_map *_map;
352300317Sjhb} DEFAULT bus_generic_unmap_resource;
353300317Sjhb
354300317Sjhb
355300317Sjhb/**
356132354Sdfr * @brief Deactivate a resource
357132354Sdfr *
358132354Sdfr * Deactivate a resource previously allocated with
359300317Sjhb * BUS_ALLOC_RESOURCE(). 
360132354Sdfr *
361132354Sdfr * @param _dev		the parent device of @p _child
362132354Sdfr * @param _child	the device which allocated the resource
363132354Sdfr * @param _type		the type of resource
364132354Sdfr * @param _rid		the resource identifier
365132354Sdfr * @param _r		the resource to deactivate
366132354Sdfr */
36741153SwollmanMETHOD int deactivate_resource {
36895201Smarkm	device_t	_dev;
36995201Smarkm	device_t	_child;
37095201Smarkm	int		_type;
37195201Smarkm	int		_rid;
37295201Smarkm	struct resource *_r;
37341153Swollman};
37441153Swollman
375132354Sdfr/**
376221231Sjhb * @brief Adjust a resource
377221231Sjhb *
378221231Sjhb * Adjust the start and/or end of a resource allocated by
379221231Sjhb * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
380221231Sjhb * with the existing address range.  If the successful, the resource's range
381221231Sjhb * will be adjusted to [start, end] on return.
382221231Sjhb *
383221231Sjhb * @param _dev		the parent device of @p _child
384221231Sjhb * @param _child	the device which allocated the resource
385221231Sjhb * @param _type		the type of resource
386221231Sjhb * @param _res		the resource to adjust
387221231Sjhb * @param _start	the new starting address of the resource range
388221231Sjhb * @param _end		the new ending address of the resource range
389221231Sjhb */
390221231SjhbMETHOD int adjust_resource {
391221231Sjhb	device_t	_dev;
392221231Sjhb	device_t	_child;
393221231Sjhb	int		_type;
394221231Sjhb	struct resource *_res;
395294883Sjhibbits	rman_res_t	_start;
396294883Sjhibbits	rman_res_t	_end;
397221231Sjhb};
398221231Sjhb
399221231Sjhb/**
400132354Sdfr * @brief Release a resource
401132354Sdfr *
402132354Sdfr * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
403132354Sdfr * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
404132354Sdfr * (which is not necessarily the same as the one the client passed).
405132354Sdfr *
406132354Sdfr * @param _dev		the parent device of @p _child
407132354Sdfr * @param _child	the device which allocated the resource
408132354Sdfr * @param _type		the type of resource
409132354Sdfr * @param _rid		the resource identifier
410132354Sdfr * @param _r		the resource to release
411132354Sdfr */
41241153SwollmanMETHOD int release_resource {
41395201Smarkm	device_t	_dev;
41495201Smarkm	device_t	_child;
41595201Smarkm	int		_type;
41695201Smarkm	int		_rid;
41795201Smarkm	struct resource *_res;
41837592Sdfr};
41941153Swollman
420132354Sdfr/**
421301451Sskra * @brief Map an interrupt
422301451Sskra *
423301451Sskra * This method is used to get an interrupt mapping data according to provided
424301451Sskra * hints. The hints could be modified afterwards, but only if mapping data was
425301451Sskra * allocated. This method is intended to be called before BUS_ALLOC_RESOURCE().
426301451Sskra *
427301451Sskra * @param _dev		the parent device of @p _child
428301451Sskra * @param _child	the device which is requesting an allocation
429301451Sskra * @param _rid		a pointer to the resource identifier
430301451Sskra * @param _start	a pointer to the hint at the start of the resource
431301451Sskra *			range - pass @c 0 for any start address
432301451Sskra * @param _end		a pointer to the hint at the end of the resource
433301451Sskra *			range - pass @c ~0 for any end address
434301451Sskra * @param _count	a pointer to the hint at the size of resource
435301451Sskra *			range required - pass @c 1 for any size
436301451Sskra * @param _imd		a pointer to the interrupt mapping data which was
437301451Sskra *			allocated
438301451Sskra */
439301451SskraMETHOD int map_intr {
440301451Sskra	device_t	_dev;
441301451Sskra	device_t	_child;
442301451Sskra	int		*_rid;
443301451Sskra	rman_res_t	*_start;
444301451Sskra	rman_res_t	*_end;
445301451Sskra	rman_res_t	*_count;
446301451Sskra	struct intr_map_data **_imd;
447301451Sskra} DEFAULT bus_generic_map_intr;
448301451Sskra
449301451Sskra/**
450132354Sdfr * @brief Install an interrupt handler
451132354Sdfr *
452132354Sdfr * This method is used to associate an interrupt handler function with
453132354Sdfr * an irq resource. When the interrupt triggers, the function @p _intr
454132354Sdfr * will be called with the value of @p _arg as its single
455132354Sdfr * argument. The value returned in @p *_cookiep is used to cancel the
456132354Sdfr * interrupt handler - the caller should save this value to use in a
457132354Sdfr * future call to BUS_TEARDOWN_INTR().
458132354Sdfr * 
459132354Sdfr * @param _dev		the parent device of @p _child
460132354Sdfr * @param _child	the device which allocated the resource
461132354Sdfr * @param _irq		the resource representing the interrupt
462132354Sdfr * @param _flags	a set of bits from enum intr_type specifying
463132354Sdfr *			the class of interrupt
464132354Sdfr * @param _intr		the function to call when the interrupt
465132354Sdfr *			triggers
466132354Sdfr * @param _arg		a value to use as the single argument in calls
467132354Sdfr *			to @p _intr
468298819Spfg * @param _cookiep	a pointer to a location to receive a cookie
469132354Sdfr *			value that may be used to remove the interrupt
470132354Sdfr *			handler
471132354Sdfr */
47241153SwollmanMETHOD int setup_intr {
47395201Smarkm	device_t	_dev;
47495201Smarkm	device_t	_child;
47595201Smarkm	struct resource *_irq;
47695201Smarkm	int		_flags;
477166901Spiso	driver_filter_t	*_filter;
47895201Smarkm	driver_intr_t	*_intr;
47995201Smarkm	void		*_arg;
48095201Smarkm	void		**_cookiep;
48141153Swollman};
48241153Swollman
483132354Sdfr/**
484132354Sdfr * @brief Uninstall an interrupt handler
485132354Sdfr *
486132354Sdfr * This method is used to disassociate an interrupt handler function
487132354Sdfr * with an irq resource. The value of @p _cookie must be the value
488132354Sdfr * returned from a previous call to BUS_SETUP_INTR().
489132354Sdfr * 
490132354Sdfr * @param _dev		the parent device of @p _child
491132354Sdfr * @param _child	the device which allocated the resource
492132354Sdfr * @param _irq		the resource representing the interrupt
493132354Sdfr * @param _cookie	the cookie value returned when the interrupt
494132354Sdfr *			was originally registered
495132354Sdfr */
49641153SwollmanMETHOD int teardown_intr {
49795201Smarkm	device_t	_dev;
49895201Smarkm	device_t	_child;
49995201Smarkm	struct resource	*_irq;
50095201Smarkm	void		*_cookie;
50141153Swollman};
50252174Sdfr
503132354Sdfr/**
504132354Sdfr * @brief Define a resource which can be allocated with
505132354Sdfr * BUS_ALLOC_RESOURCE().
506132354Sdfr *
507132354Sdfr * This method is used by some busses (typically ISA) to allow a
508132354Sdfr * driver to describe a resource range that it would like to
509132354Sdfr * allocate. The resource defined by @p _type and @p _rid is defined
510132354Sdfr * to start at @p _start and to include @p _count indices in its
511132354Sdfr * range.
512132354Sdfr * 
513132354Sdfr * @param _dev		the parent device of @p _child
514132354Sdfr * @param _child	the device which owns the resource
515132354Sdfr * @param _type		the type of resource
516132354Sdfr * @param _rid		the resource identifier
517132354Sdfr * @param _start	the start of the resource range
518132354Sdfr * @param _count	the size of the resource range
519132354Sdfr */
52052174SdfrMETHOD int set_resource {
52195201Smarkm	device_t	_dev;
52295201Smarkm	device_t	_child;
52395201Smarkm	int		_type;
52495201Smarkm	int		_rid;
525294883Sjhibbits	rman_res_t	_start;
526294883Sjhibbits	rman_res_t	_count;
52752174Sdfr};
52852174Sdfr
529132354Sdfr/**
530132354Sdfr * @brief Describe a resource
531132354Sdfr *
532132354Sdfr * This method allows a driver to examine the range used for a given
533132354Sdfr * resource without actually allocating it.
534132354Sdfr * 
535132354Sdfr * @param _dev		the parent device of @p _child
536132354Sdfr * @param _child	the device which owns the resource
537132354Sdfr * @param _type		the type of resource
538132354Sdfr * @param _rid		the resource identifier
539298819Spfg * @param _start	the address of a location to receive the start
540132354Sdfr *			index of the resource range
541298819Spfg * @param _count	the address of a location to receive the size
542132354Sdfr *			of the resource range
543132354Sdfr */
54452174SdfrMETHOD int get_resource {
54595201Smarkm	device_t	_dev;
54695201Smarkm	device_t	_child;
54795201Smarkm	int		_type;
54895201Smarkm	int		_rid;
549294883Sjhibbits	rman_res_t	*_startp;
550294883Sjhibbits	rman_res_t	*_countp;
55152174Sdfr};
55252174Sdfr
553132354Sdfr/**
554132354Sdfr * @brief Delete a resource.
555132354Sdfr * 
556132354Sdfr * Use this to delete a resource (possibly one previously added with
557132354Sdfr * BUS_SET_RESOURCE()).
558132354Sdfr * 
559132354Sdfr * @param _dev		the parent device of @p _child
560132354Sdfr * @param _child	the device which owns the resource
561132354Sdfr * @param _type		the type of resource
562132354Sdfr * @param _rid		the resource identifier
563132354Sdfr */
56452174SdfrMETHOD void delete_resource {
56595201Smarkm	device_t	_dev;
56695201Smarkm	device_t	_child;
56795201Smarkm	int		_type;
56895201Smarkm	int		_rid;
56952174Sdfr};
57067278Smdodd
571132354Sdfr/**
572132354Sdfr * @brief Return a struct resource_list.
573132354Sdfr *
574132354Sdfr * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
575132354Sdfr * implement their resource handling. It should return the resource
576132354Sdfr * list of the given child device.
577132354Sdfr * 
578132354Sdfr * @param _dev		the parent device of @p _child
579132354Sdfr * @param _child	the device which owns the resource list
580132354Sdfr */
58169294SmdoddMETHOD struct resource_list * get_resource_list {
58295201Smarkm	device_t	_dev;
58395201Smarkm	device_t	_child;
58467278Smdodd} DEFAULT bus_generic_get_resource_list;
585100421Simp
586132354Sdfr/**
587132354Sdfr * @brief Is the hardware described by @p _child still attached to the
588132354Sdfr * system?
589132354Sdfr *
590133588Simp * This method should return 0 if the device is not present.  It
591133588Simp * should return -1 if it is present.  Any errors in determining
592133588Simp * should be returned as a normal errno value.  Client drivers are to
593133588Simp * assume that the device is present, even if there is an error
594133588Simp * determining if it is there.  Busses are to try to avoid returning
595133588Simp * errors, but newcard will return an error if the device fails to
596133588Simp * implement this method.
597132354Sdfr * 
598132354Sdfr * @param _dev		the parent device of @p _child
599132354Sdfr * @param _child	the device which is being examined
600132354Sdfr */
601100421SimpMETHOD int child_present {
602100421Simp	device_t	_dev;
603100421Simp	device_t	_child;
604100421Simp} DEFAULT bus_generic_child_present;
605104597Simp
606132354Sdfr/**
607132354Sdfr * @brief Returns the pnp info for this device.
608132354Sdfr *
609300158Srpokala * Return it as a string.  If the storage is insufficient for the
610300158Srpokala * string, then return EOVERFLOW.
611300073Sjhb *
612300073Sjhb * The string must be formatted as a space-separated list of
613300073Sjhb * name=value pairs.  Names may only contain alphanumeric characters,
614300073Sjhb * underscores ('_') and hyphens ('-').  Values can contain any
615300073Sjhb * non-whitespace characters.  Values containing whitespace can be
616300073Sjhb * quoted with double quotes ('"').  Double quotes and backslashes in
617300073Sjhb * quoted values can be escaped with backslashes ('\').
618132354Sdfr * 
619132354Sdfr * @param _dev		the parent device of @p _child
620132354Sdfr * @param _child	the device which is being examined
621132354Sdfr * @param _buf		the address of a buffer to receive the pnp
622132354Sdfr *			string
623132354Sdfr * @param _buflen	the size of the buffer pointed to by @p _buf
624132354Sdfr */
625104597SimpMETHOD int child_pnpinfo_str {
626104597Simp	device_t	_dev;
627104597Simp	device_t	_child;
628104597Simp	char		*_buf;
629104597Simp	size_t		_buflen;
630104597Simp};
631104597Simp
632132354Sdfr/**
633132354Sdfr * @brief Returns the location for this device.
634132354Sdfr *
635300158Srpokala * Return it as a string.  If the storage is insufficient for the
636300158Srpokala * string, then return EOVERFLOW.
637300073Sjhb *
638300073Sjhb * The string must be formatted as a space-separated list of
639300073Sjhb * name=value pairs.  Names may only contain alphanumeric characters,
640300073Sjhb * underscores ('_') and hyphens ('-').  Values can contain any
641300073Sjhb * non-whitespace characters.  Values containing whitespace can be
642300073Sjhb * quoted with double quotes ('"').  Double quotes and backslashes in
643300073Sjhb * quoted values can be escaped with backslashes ('\').
644300073Sjhb *
645132354Sdfr * @param _dev		the parent device of @p _child
646132354Sdfr * @param _child	the device which is being examined
647132354Sdfr * @param _buf		the address of a buffer to receive the location
648132354Sdfr *			string
649132354Sdfr * @param _buflen	the size of the buffer pointed to by @p _buf
650132354Sdfr */
651104597SimpMETHOD int child_location_str {
652104597Simp	device_t	_dev;
653104597Simp	device_t	_child;
654104597Simp	char		*_buf;
655104597Simp	size_t		_buflen;
656104597Simp};
657119967Smarcel
658132354Sdfr/**
659177467Sjhb * @brief Allow drivers to request that an interrupt be bound to a specific
660177467Sjhb * CPU.
661177467Sjhb * 
662177467Sjhb * @param _dev		the parent device of @p _child
663177467Sjhb * @param _child	the device which allocated the resource
664177467Sjhb * @param _irq		the resource representing the interrupt
665177467Sjhb * @param _cpu		the CPU to bind the interrupt to
666177467Sjhb */
667177467SjhbMETHOD int bind_intr {
668177467Sjhb	device_t	_dev;
669177467Sjhb	device_t	_child;
670177467Sjhb	struct resource *_irq;
671177467Sjhb	int		_cpu;
672177467Sjhb} DEFAULT bus_generic_bind_intr;
673177467Sjhb
674177467Sjhb/**
675132354Sdfr * @brief Allow (bus) drivers to specify the trigger mode and polarity
676132354Sdfr * of the specified interrupt.
677132354Sdfr * 
678132354Sdfr * @param _dev		the bus device
679132354Sdfr * @param _irq		the interrupt number to modify
680132354Sdfr * @param _trig		the trigger mode required
681132354Sdfr * @param _pol		the interrupt polarity required
682132354Sdfr */
683119967SmarcelMETHOD int config_intr {
684119967Smarcel	device_t	_dev;
685119967Smarcel	int		_irq;
686119967Smarcel	enum intr_trigger _trig;
687119967Smarcel	enum intr_polarity _pol;
688119967Smarcel} DEFAULT bus_generic_config_intr;
689160186Simp
690160186Simp/**
691198134Sjhb * @brief Allow drivers to associate a description with an active
692198134Sjhb * interrupt handler.
693198134Sjhb *
694198134Sjhb * @param _dev		the parent device of @p _child
695198134Sjhb * @param _child	the device which allocated the resource
696198134Sjhb * @param _irq		the resource representing the interrupt
697198134Sjhb * @param _cookie	the cookie value returned when the interrupt
698198134Sjhb *			was originally registered
699198134Sjhb * @param _descr	the description to associate with the interrupt
700198134Sjhb */
701198134SjhbMETHOD int describe_intr {
702198134Sjhb	device_t	_dev;
703198134Sjhb	device_t	_child;
704198134Sjhb	struct resource *_irq;
705198134Sjhb	void		*_cookie;
706198134Sjhb	const char	*_descr;
707198134Sjhb} DEFAULT bus_generic_describe_intr;
708198134Sjhb
709198134Sjhb/**
710160186Simp * @brief Notify a (bus) driver about a child that the hints mechanism
711160186Simp * believes it has discovered.
712160186Simp *
713160186Simp * The bus is responsible for then adding the child in the right order
714160186Simp * and discovering other things about the child.  The bus driver is
715160186Simp * free to ignore this hint, to do special things, etc.  It is all up
716160186Simp * to the bus driver to interpret.
717160186Simp *
718160186Simp * This method is only called in response to the parent bus asking for
719160186Simp * hinted devices to be enumerated.
720160186Simp *
721160186Simp * @param _dev		the bus device
722160186Simp * @param _dname	the name of the device w/o unit numbers
723160186Simp * @param _dunit	the unit number of the device
724160186Simp */
725160186SimpMETHOD void hinted_child {
726160186Simp	device_t	_dev;
727185059Sjhb	const char	*_dname;
728160186Simp	int		_dunit;
729160186Simp};
730161928Sjmg
731161928Sjmg/**
732161928Sjmg * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
733161928Sjmg *
734161928Sjmg * @param _dev		the parent device of @p _child
735161928Sjmg * @param _child	the device to which the tag will belong
736161928Sjmg */
737161928SjmgMETHOD bus_dma_tag_t get_dma_tag {
738161928Sjmg	device_t	_dev;
739161928Sjmg	device_t	_child;
740161928Sjmg} DEFAULT bus_generic_get_dma_tag;
741185059Sjhb
742185059Sjhb/**
743295755Szbb * @brief Returns bus_space_tag_t for use w/ devices on the bus.
744295755Szbb *
745295755Szbb * @param _dev		the parent device of @p _child
746295755Szbb * @param _child	the device to which the tag will belong
747295755Szbb */
748295755SzbbMETHOD bus_space_tag_t get_bus_tag {
749295755Szbb	device_t	_dev;
750295755Szbb	device_t	_child;
751295755Szbb} DEFAULT bus_generic_get_bus_tag;
752295755Szbb
753295755Szbb/**
754185059Sjhb * @brief Allow the bus to determine the unit number of a device.
755185059Sjhb *
756185059Sjhb * @param _dev		the parent device of @p _child
757185059Sjhb * @param _child	the device whose unit is to be wired
758185059Sjhb * @param _name		the name of the device's new devclass
759185059Sjhb * @param _unitp	a pointer to the device's new unit value
760185059Sjhb */
761185059SjhbMETHOD void hint_device_unit {
762185059Sjhb	device_t	_dev;
763185059Sjhb	device_t	_child;
764185059Sjhb	const char	*_name;
765185059Sjhb	int		*_unitp;
766185059Sjhb};
767185059Sjhb
768193833Sjhb/**
769193833Sjhb * @brief Notify a bus that the bus pass level has been changed
770193833Sjhb *
771193833Sjhb * @param _dev		the bus device
772193833Sjhb */
773193833SjhbMETHOD void new_pass {
774193833Sjhb	device_t	_dev;
775193833Sjhb} DEFAULT bus_generic_new_pass;
776209154Smav
777209154Smav/**
778209154Smav * @brief Notify a bus that specified child's IRQ should be remapped.
779209154Smav *
780209154Smav * @param _dev		the bus device
781209154Smav * @param _child	the child device
782209154Smav * @param _irq		the irq number
783209154Smav */
784209154SmavMETHOD int remap_intr {
785209154Smav	device_t	_dev;
786209154Smav	device_t	_child;
787209154Smav	u_int		_irq;
788209154Smav} DEFAULT null_remap_intr;
789272013Sjhibbits
790272013Sjhibbits/**
791272013Sjhibbits * @brief Suspend a given child
792272013Sjhibbits *
793272013Sjhibbits * @param _dev		the parent device of @p _child
794272013Sjhibbits * @param _child	the device to suspend
795272013Sjhibbits */
796272013SjhibbitsMETHOD int suspend_child {
797272013Sjhibbits	device_t	_dev;
798272013Sjhibbits	device_t	_child;
799272013Sjhibbits} DEFAULT bus_generic_suspend_child;
800272013Sjhibbits
801272013Sjhibbits/**
802272013Sjhibbits * @brief Resume a given child
803272013Sjhibbits *
804272013Sjhibbits * @param _dev		the parent device of @p _child
805272013Sjhibbits * @param _child	the device to resume
806272013Sjhibbits */
807272013SjhibbitsMETHOD int resume_child {
808272013Sjhibbits	device_t	_dev;
809272013Sjhibbits	device_t	_child;
810272013Sjhibbits} DEFAULT bus_generic_resume_child;
811272799Sadrian
812272799Sadrian/**
813272799Sadrian * @brief Get the VM domain handle for the given bus and child.
814272799Sadrian *
815272799Sadrian * @param _dev		the bus device
816272799Sadrian * @param _child	the child device
817272799Sadrian * @param _domain	a pointer to the bus's domain handle identifier
818272799Sadrian */
819272799SadrianMETHOD int get_domain {
820272799Sadrian	device_t	_dev;
821272799Sadrian	device_t	_child;
822272799Sadrian	int		*_domain;
823272799Sadrian} DEFAULT bus_generic_get_domain;
824299286Sjhb
825299286Sjhb/**
826299286Sjhb * @brief Request a set of CPUs
827299286Sjhb *
828299286Sjhb * @param _dev		the bus device
829299286Sjhb * @param _child	the child device
830299286Sjhb * @param _op		type of CPUs to request
831299286Sjhb * @param _setsize	the size of the set passed in _cpuset
832299286Sjhb * @param _cpuset	a pointer to a cpuset to receive the requested
833299286Sjhb *			set of CPUs
834299286Sjhb */
835299286SjhbMETHOD int get_cpus {
836299286Sjhb	device_t	_dev;
837299286Sjhb	device_t	_child;
838299286Sjhb	enum cpu_sets	_op;
839299286Sjhb	size_t		_setsize;
840299286Sjhb	cpuset_t	*_cpuset;
841299286Sjhb} DEFAULT bus_generic_get_cpus;
842