xref: /src/sys/kern/bus_if.m (revision bc3914737bce07a912a8024ba19983d7c388736c)
1#-
2# Copyright (c) 1998-2004 Doug Rabson
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26#
27
28#include <sys/types.h>
29#include <sys/systm.h>
30#include <sys/bus.h>
31
32/**
33 * @defgroup BUS bus - KObj methods for drivers of devices with children
34 * @brief A set of methods required for device drivers that support
35 * child devices.
36 * @{
37 */
38INTERFACE bus;
39
40#
41# Default implementations of some methods.
42#
43CODE {
44	static struct resource *
45	null_alloc_resource(device_t dev, device_t child,
46	    int type, int rid, rman_res_t start, rman_res_t end,
47	    rman_res_t count, u_int flags)
48	{
49	    return (0);
50	}
51
52	static int
53	null_remap_intr(device_t bus, device_t dev, u_int irq)
54	{
55
56		if (dev != NULL)
57			return (BUS_REMAP_INTR(dev, NULL, irq));
58		return (ENXIO);
59	}
60
61	static device_t
62	null_add_child(device_t bus, int order, const char *name,
63	    int unit)
64	{
65
66		panic("%s: bus_add_child is not implemented, name '%s', "
67		    "unit %d", device_get_nameunit(bus), name, unit);
68	}
69
70	static int
71	null_reset_post(device_t bus, device_t dev)
72	{
73		return (0);
74	}
75
76	static int
77	null_reset_prepare(device_t bus, device_t dev)
78	{
79		return (0);
80	}
81
82	static struct rman *
83	null_get_rman(device_t bus, int type, u_int flags)
84	{
85		return (NULL);
86	}
87
88	static struct resource_list *
89	null_get_resource_list(device_t bus, device_t dev)
90	{
91		return (NULL);
92	}
93};
94
95/**
96 * @brief Print a description of a child device
97 *
98 * This is called from system code which prints out a description of a
99 * device. It should describe the attachment that the child has with
100 * the parent. For instance the TurboLaser bus prints which node the
101 * device is attached to. See bus_generic_print_child() for more
102 * information.
103 *
104 * @param _dev		the device whose child is being printed
105 * @param _child	the child device to describe
106 *
107 * @returns		the number of characters output.
108 */
109METHOD int print_child {
110	device_t _dev;
111	device_t _child;
112} DEFAULT bus_generic_print_child;
113
114/**
115 * @brief Print a notification about an unprobed child device.
116 *
117 * Called for each child device that did not succeed in probing for a
118 * driver.
119 *
120 * @param _dev		the device whose child was being probed
121 * @param _child	the child device which failed to probe
122 */
123METHOD void probe_nomatch {
124        device_t _dev;
125        device_t _child;
126};
127
128/**
129 * @brief Read the value of a bus-specific attribute of a device
130 *
131 * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
132 * of instance variables of a child device.  The intention is that
133 * each different type of bus defines a set of appropriate instance
134 * variables (such as ports and irqs for ISA bus etc.)
135 *
136 * This information could be given to the child device as a struct but
137 * that makes it hard for a bus to add or remove variables without
138 * forcing an edit and recompile for all drivers which may not be
139 * possible for vendor supplied binary drivers.
140 *
141 * This method copies the value of an instance variable to the
142 * location specified by @p *_result.
143 *
144 * @param _dev		the device whose child was being examined
145 * @param _child	the child device whose instance variable is
146 *			being read
147 * @param _index	the instance variable to read
148 * @param _result	a location to receive the instance variable
149 *			value
150 *
151 * @retval 0		success
152 * @retval ENOENT	no such instance variable is supported by @p
153 *			_dev
154 */
155METHOD int read_ivar {
156	device_t _dev;
157	device_t _child;
158	int _index;
159	uintptr_t *_result;
160};
161
162/**
163 * @brief Write the value of a bus-specific attribute of a device
164 *
165 * This method sets the value of an instance variable to @p _value.
166 *
167 * @param _dev		the device whose child was being updated
168 * @param _child	the child device whose instance variable is
169 *			being written
170 * @param _index	the instance variable to write
171 * @param _value	the value to write to that instance variable
172 *
173 * @retval 0		success
174 * @retval ENOENT	no such instance variable is supported by @p
175 *			_dev
176 * @retval EINVAL	the instance variable was recognised but
177 *			contains a read-only value
178 */
179METHOD int write_ivar {
180	device_t _dev;
181	device_t _child;
182	int _indx;
183	uintptr_t _value;
184};
185
186/**
187 * @brief Notify a bus that a child was deleted
188 *
189 * Called at the beginning of device_delete_child() to allow the parent
190 * to teardown any bus-specific state for the child.
191 *
192 * @param _dev		the device whose child is being deleted
193 * @param _child	the child device which is being deleted
194 */
195METHOD void child_deleted {
196	device_t _dev;
197	device_t _child;
198};
199
200/**
201 * @brief Notify a bus that a child was detached
202 *
203 * Called after the child's DEVICE_DETACH() method to allow the parent
204 * to reclaim any resources allocated on behalf of the child.
205 *
206 * @param _dev		the device whose child changed state
207 * @param _child	the child device which changed state
208 */
209METHOD void child_detached {
210	device_t _dev;
211	device_t _child;
212};
213
214/**
215 * @brief Notify a bus that a new driver was added
216 *
217 * Called when a new driver is added to the devclass which owns this
218 * bus. The generic implementation of this method attempts to probe and
219 * attach any un-matched children of the bus.
220 *
221 * @param _dev		the device whose devclass had a new driver
222 *			added to it
223 * @param _driver	the new driver which was added
224 */
225METHOD void driver_added {
226	device_t _dev;
227	driver_t *_driver;
228} DEFAULT bus_generic_driver_added;
229
230/**
231 * @brief Create a new child device
232 *
233 * For buses which use use drivers supporting DEVICE_IDENTIFY() to
234 * enumerate their devices, this method is used to create new
235 * device instances. The new device will be added after the last
236 * existing child with the same order. Implementations of bus_add_child
237 * call device_add_child_ordered to add the child and often add
238 * a suitable ivar to the device specific to that bus.
239 *
240 * @param _dev		the bus device which will be the parent of the
241 *			new child device
242 * @param _order	a value which is used to partially sort the
243 *			children of @p _dev - devices created using
244 *			lower values of @p _order appear first in @p
245 *			_dev's list of children
246 * @param _name		devclass name for new device or @c NULL if not
247 *			specified
248 * @param _unit		unit number for new device or @c -1 if not
249 *			specified
250 */
251METHOD device_t add_child {
252	device_t _dev;
253	u_int _order;
254	const char *_name;
255	int _unit;
256} DEFAULT null_add_child;
257
258/**
259 * @brief Rescan the bus
260 *
261 * This method is called by a parent bridge or devctl to trigger a bus
262 * rescan.  The rescan should delete devices no longer present and
263 * enumerate devices that have newly arrived.
264 *
265 * @param _dev		the bus device
266 */
267METHOD int rescan {
268	device_t _dev;
269} DEFAULT bus_null_rescan;
270
271/**
272 * @brief Allocate a system resource
273 *
274 * This method is called by child devices of a bus to allocate resources.
275 * The types are defined in <machine/resource.h>; the meaning of the
276 * resource-ID field varies from bus to bus. If a resource was allocated
277 * and the caller did not use the RF_ACTIVE to specify that it should be
278 * activated immediately, the caller is responsible for calling
279 * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
280 *
281 * @param _dev		the parent device of @p _child
282 * @param _child	the device which is requesting an allocation
283 * @param _type		the type of resource to allocate
284 * @param _rid		the resource identifier
285 * @param _start	hint at the start of the resource range - pass
286 *			@c 0 for any start address
287 * @param _end		hint at the end of the resource range - pass
288 *			@c ~0 for any end address
289 * @param _count	hint at the size of range required - pass @c 1
290 *			for any size
291 * @param _flags	any extra flags to control the resource
292 *			allocation - see @c RF_XXX flags in
293 *			<sys/rman.h> for details
294 *
295 * @returns		the resource which was allocated or @c NULL if no
296 *			resource could be allocated
297 */
298METHOD struct resource * alloc_resource {
299	device_t	_dev;
300	device_t	_child;
301	int		_type;
302	int	        _rid;
303	rman_res_t	_start;
304	rman_res_t	_end;
305	rman_res_t	_count;
306	u_int		_flags;
307} DEFAULT null_alloc_resource;
308
309/**
310 * @brief Activate a resource
311 *
312 * Activate a resource previously allocated with
313 * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
314 * device for instance.  It will also establish a mapping for the resource
315 * unless RF_UNMAPPED was set when allocating the resource.
316 *
317 * @param _dev		the parent device of @p _child
318 * @param _child	the device which allocated the resource
319 * @param _r		the resource to activate
320 */
321METHOD int activate_resource {
322	device_t	_dev;
323	device_t	_child;
324	struct resource *_r;
325};
326
327
328/**
329 * @brief Map a resource
330 *
331 * Allocate a mapping for a range of an active resource.  The mapping
332 * is described by a struct resource_map object.  This may for instance
333 * map a memory region into the kernel's virtual address space.
334 *
335 * @param _dev		the parent device of @p _child
336 * @param _child	the device which allocated the resource
337 * @param _r		the resource to map
338 * @param _args		optional attributes of the mapping
339 * @param _map		the mapping
340 */
341METHOD int map_resource {
342	device_t	_dev;
343	device_t	_child;
344	struct resource *_r;
345	struct resource_map_request *_args;
346	struct resource_map *_map;
347} DEFAULT bus_generic_map_resource;
348
349
350/**
351 * @brief Unmap a resource
352 *
353 * Release a mapping previously allocated with
354 * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
355 * from the kernel's virtual address space.
356 *
357 * @param _dev		the parent device of @p _child
358 * @param _child	the device which allocated the resource
359 * @param _r		the resource
360 * @param _map		the mapping to release
361 */
362METHOD int unmap_resource {
363	device_t	_dev;
364	device_t	_child;
365	struct resource *_r;
366	struct resource_map *_map;
367} DEFAULT bus_generic_unmap_resource;
368
369
370/**
371 * @brief Deactivate a resource
372 *
373 * Deactivate a resource previously allocated with
374 * BUS_ALLOC_RESOURCE().
375 *
376 * @param _dev		the parent device of @p _child
377 * @param _child	the device which allocated the resource
378 * @param _r		the resource to deactivate
379 */
380METHOD int deactivate_resource {
381	device_t	_dev;
382	device_t	_child;
383	struct resource *_r;
384};
385
386/**
387 * @brief Adjust a resource
388 *
389 * Adjust the start and/or end of a resource allocated by
390 * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
391 * with the existing address range.  If the successful, the resource's range
392 * will be adjusted to [start, end] on return.
393 *
394 * @param _dev		the parent device of @p _child
395 * @param _child	the device which allocated the resource
396 * @param _res		the resource to adjust
397 * @param _start	the new starting address of the resource range
398 * @param _end		the new ending address of the resource range
399 */
400METHOD int adjust_resource {
401	device_t	_dev;
402	device_t	_child;
403	struct resource *_res;
404	rman_res_t	_start;
405	rman_res_t	_end;
406};
407
408/**
409 * @brief translate a resource value
410 *
411 * Give a bus driver the opportunity to translate resource ranges.  If
412 * successful, the host's view of the resource starting at @p _start is
413 * returned in @p _newstart, otherwise an error is returned.
414 *
415 * @param _dev		the device associated with the resource
416 * @param _type		the type of resource
417 * @param _start	the starting address of the resource range
418 * @param _newstart	the new starting address of the resource range
419 */
420METHOD int translate_resource {
421	device_t	_dev;
422	int		_type;
423	rman_res_t	_start;
424	rman_res_t	*_newstart;
425} DEFAULT bus_generic_translate_resource;
426
427/**
428 * @brief Release a resource
429 *
430 * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
431 * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
432 * (which is not necessarily the same as the one the client passed).
433 *
434 * @param _dev		the parent device of @p _child
435 * @param _child	the device which allocated the resource
436 * @param _r		the resource to release
437 */
438METHOD int release_resource {
439	device_t	_dev;
440	device_t	_child;
441	struct resource *_res;
442};
443
444/**
445 * @brief Install an interrupt handler
446 *
447 * This method is used to associate an interrupt handler function with
448 * an irq resource. When the interrupt triggers, the function @p _intr
449 * will be called with the value of @p _arg as its single
450 * argument. The value returned in @p *_cookiep is used to cancel the
451 * interrupt handler - the caller should save this value to use in a
452 * future call to BUS_TEARDOWN_INTR().
453 *
454 * @param _dev		the parent device of @p _child
455 * @param _child	the device which allocated the resource
456 * @param _irq		the resource representing the interrupt
457 * @param _flags	a set of bits from enum intr_type specifying
458 *			the class of interrupt
459 * @param _intr		the function to call when the interrupt
460 *			triggers
461 * @param _arg		a value to use as the single argument in calls
462 *			to @p _intr
463 * @param _cookiep	a pointer to a location to receive a cookie
464 *			value that may be used to remove the interrupt
465 *			handler
466 */
467METHOD int setup_intr {
468	device_t	_dev;
469	device_t	_child;
470	struct resource *_irq;
471	int		_flags;
472	driver_filter_t	*_filter;
473	driver_intr_t	*_intr;
474	void		*_arg;
475	void		**_cookiep;
476};
477
478/**
479 * @brief Uninstall an interrupt handler
480 *
481 * This method is used to disassociate an interrupt handler function
482 * with an irq resource. The value of @p _cookie must be the value
483 * returned from a previous call to BUS_SETUP_INTR().
484 *
485 * @param _dev		the parent device of @p _child
486 * @param _child	the device which allocated the resource
487 * @param _irq		the resource representing the interrupt
488 * @param _cookie	the cookie value returned when the interrupt
489 *			was originally registered
490 */
491METHOD int teardown_intr {
492	device_t	_dev;
493	device_t	_child;
494	struct resource	*_irq;
495	void		*_cookie;
496};
497
498/**
499 * @brief Suspend an interrupt handler
500 *
501 * This method is used to mark a handler as suspended in the case
502 * that the associated device is powered down and cannot be a source
503 * for the, typically shared, interrupt.
504 * The value of @p _irq must be the interrupt resource passed
505 * to a previous call to BUS_SETUP_INTR().
506 *
507 * @param _dev		the parent device of @p _child
508 * @param _child	the device which allocated the resource
509 * @param _irq		the resource representing the interrupt
510 */
511METHOD int suspend_intr {
512	device_t	_dev;
513	device_t	_child;
514	struct resource *_irq;
515} DEFAULT bus_generic_suspend_intr;
516
517/**
518 * @brief Resume an interrupt handler
519 *
520 * This method is used to clear suspended state of a handler when
521 * the associated device is powered up and can be an interrupt source
522 * again.
523 * The value of @p _irq must be the interrupt resource passed
524 * to a previous call to BUS_SETUP_INTR().
525 *
526 * @param _dev		the parent device of @p _child
527 * @param _child	the device which allocated the resource
528 * @param _irq		the resource representing the interrupt
529 */
530METHOD int resume_intr {
531	device_t	_dev;
532	device_t	_child;
533	struct resource *_irq;
534} DEFAULT bus_generic_resume_intr;
535
536/**
537 * @brief Define a resource which can be allocated with
538 * BUS_ALLOC_RESOURCE().
539 *
540 * This method is used by some buses (typically ISA) to allow a
541 * driver to describe a resource range that it would like to
542 * allocate. The resource defined by @p _type and @p _rid is defined
543 * to start at @p _start and to include @p _count indices in its
544 * range.
545 *
546 * @param _dev		the parent device of @p _child
547 * @param _child	the device which owns the resource
548 * @param _type		the type of resource
549 * @param _rid		the resource identifier
550 * @param _start	the start of the resource range
551 * @param _count	the size of the resource range
552 */
553METHOD int set_resource {
554	device_t	_dev;
555	device_t	_child;
556	int		_type;
557	int		_rid;
558	rman_res_t	_start;
559	rman_res_t	_count;
560};
561
562/**
563 * @brief Describe a resource
564 *
565 * This method allows a driver to examine the range used for a given
566 * resource without actually allocating it.
567 *
568 * @param _dev		the parent device of @p _child
569 * @param _child	the device which owns the resource
570 * @param _type		the type of resource
571 * @param _rid		the resource identifier
572 * @param _start	the address of a location to receive the start
573 *			index of the resource range
574 * @param _count	the address of a location to receive the size
575 *			of the resource range
576 */
577METHOD int get_resource {
578	device_t	_dev;
579	device_t	_child;
580	int		_type;
581	int		_rid;
582	rman_res_t	*_startp;
583	rman_res_t	*_countp;
584};
585
586/**
587 * @brief Delete a resource.
588 *
589 * Use this to delete a resource (possibly one previously added with
590 * BUS_SET_RESOURCE()).
591 *
592 * @param _dev		the parent device of @p _child
593 * @param _child	the device which owns the resource
594 * @param _type		the type of resource
595 * @param _rid		the resource identifier
596 */
597METHOD void delete_resource {
598	device_t	_dev;
599	device_t	_child;
600	int		_type;
601	int		_rid;
602};
603
604/**
605 * @brief Return a struct resource_list.
606 *
607 * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
608 * implement their resource handling. It should return the resource
609 * list of the given child device.
610 *
611 * @param _dev		the parent device of @p _child
612 * @param _child	the device which owns the resource list
613 */
614METHOD struct resource_list * get_resource_list {
615	device_t	_dev;
616	device_t	_child;
617} DEFAULT null_get_resource_list;
618
619/**
620 * @brief Return a struct rman.
621 *
622 * Used by drivers which use bus_generic_rman_alloc_resource() etc. to
623 * implement their resource handling. It should return the resource
624 * manager used for the given resource type.
625 *
626 * @param _dev		the bus device
627 * @param _type		the resource type
628 * @param _flags	resource flags (@c RF_XXX flags in
629 *			<sys/rman.h>)
630 */
631METHOD struct rman * get_rman {
632	device_t	_dev;
633	int		_type;
634	u_int		_flags;
635} DEFAULT null_get_rman;
636
637/**
638 * @brief Is the hardware described by @p _child still attached to the
639 * system?
640 *
641 * This method should return 0 if the device is not present.  It
642 * should return -1 if it is present.  Any errors in determining
643 * should be returned as a normal errno value.  Client drivers are to
644 * assume that the device is present, even if there is an error
645 * determining if it is there.  Buses are to try to avoid returning
646 * errors, but newcard will return an error if the device fails to
647 * implement this method.
648 *
649 * @param _dev		the parent device of @p _child
650 * @param _child	the device which is being examined
651 */
652METHOD int child_present {
653	device_t	_dev;
654	device_t	_child;
655} DEFAULT bus_generic_child_present;
656
657/**
658 * @brief Returns the pnp info for this device.
659 *
660 * Return it as a string, appended to @p _sb
661 *
662 * The string must be formatted as a space-separated list of
663 * name=value pairs.  Names may only contain alphanumeric characters,
664 * underscores ('_') and hyphens ('-').  Values can contain any
665 * non-whitespace characters.  Values containing whitespace can be
666 * quoted with double quotes ('"').  Double quotes and backslashes in
667 * quoted values can be escaped with backslashes ('\').
668 *
669 * @param _dev		the parent device of @p _child
670 * @param _child	the device which is being examined
671 * @param _sb		sbuf for results string
672 */
673METHOD int child_pnpinfo {
674	device_t	_dev;
675	device_t	_child;
676	struct sbuf	*_sb;
677} DEFAULT bus_generic_child_pnpinfo;
678
679/**
680 * @brief Returns the location for this device.
681 *
682 * Return it as a string, appended to @p _sb
683 *
684 * The string must be formatted as a space-separated list of
685 * name=value pairs.  Names may only contain alphanumeric characters,
686 * underscores ('_') and hyphens ('-').  Values can contain any
687 * non-whitespace characters.  Values containing whitespace can be
688 * quoted with double quotes ('"').  Double quotes and backslashes in
689 * quoted values can be escaped with backslashes ('\').
690 *
691 * @param _dev		the parent device of @p _child
692 * @param _child	the device which is being examined
693 * @param _sb		sbuf for results string
694 */
695METHOD int child_location {
696	device_t	_dev;
697	device_t	_child;
698	struct sbuf	*_sb;
699} DEFAULT bus_generic_child_location;
700
701/**
702 * @brief Allow drivers to request that an interrupt be bound to a specific
703 * CPU.
704 *
705 * @param _dev		the parent device of @p _child
706 * @param _child	the device which allocated the resource
707 * @param _irq		the resource representing the interrupt
708 * @param _cpu		the CPU to bind the interrupt to
709 */
710METHOD int bind_intr {
711	device_t	_dev;
712	device_t	_child;
713	struct resource *_irq;
714	int		_cpu;
715} DEFAULT bus_generic_bind_intr;
716
717/**
718 * @brief Allow (bus) drivers to specify the trigger mode and polarity
719 * of the specified interrupt.
720 *
721 * @param _dev		the bus device
722 * @param _irq		the interrupt number to modify
723 * @param _trig		the trigger mode required
724 * @param _pol		the interrupt polarity required
725 */
726METHOD int config_intr {
727	device_t	_dev;
728	int		_irq;
729	enum intr_trigger _trig;
730	enum intr_polarity _pol;
731} DEFAULT bus_generic_config_intr;
732
733/**
734 * @brief Allow drivers to associate a description with an active
735 * interrupt handler.
736 *
737 * @param _dev		the parent device of @p _child
738 * @param _child	the device which allocated the resource
739 * @param _irq		the resource representing the interrupt
740 * @param _cookie	the cookie value returned when the interrupt
741 *			was originally registered
742 * @param _descr	the description to associate with the interrupt
743 */
744METHOD int describe_intr {
745	device_t	_dev;
746	device_t	_child;
747	struct resource *_irq;
748	void		*_cookie;
749	const char	*_descr;
750} DEFAULT bus_generic_describe_intr;
751
752/**
753 * @brief Notify a (bus) driver about a child that the hints mechanism
754 * believes it has discovered.
755 *
756 * The bus is responsible for then adding the child in the right order
757 * and discovering other things about the child.  The bus driver is
758 * free to ignore this hint, to do special things, etc.  It is all up
759 * to the bus driver to interpret.
760 *
761 * This method is only called in response to the parent bus asking for
762 * hinted devices to be enumerated.
763 *
764 * @param _dev		the bus device
765 * @param _dname	the name of the device w/o unit numbers
766 * @param _dunit	the unit number of the device
767 */
768METHOD void hinted_child {
769	device_t	_dev;
770	const char	*_dname;
771	int		_dunit;
772};
773
774/**
775 * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
776 *
777 * @param _dev		the parent device of @p _child
778 * @param _child	the device to which the tag will belong
779 */
780METHOD bus_dma_tag_t get_dma_tag {
781	device_t	_dev;
782	device_t	_child;
783} DEFAULT bus_generic_get_dma_tag;
784
785/**
786 * @brief Returns bus_space_tag_t for use w/ devices on the bus.
787 *
788 * @param _dev		the parent device of @p _child
789 * @param _child	the device to which the tag will belong
790 */
791METHOD bus_space_tag_t get_bus_tag {
792	device_t	_dev;
793	device_t	_child;
794} DEFAULT bus_generic_get_bus_tag;
795
796/**
797 * @brief Allow the bus to determine the unit number of a device.
798 *
799 * @param _dev		the parent device of @p _child
800 * @param _child	the device whose unit is to be wired
801 * @param _name		the name of the device's new devclass
802 * @param _unitp	a pointer to the device's new unit value
803 */
804METHOD void hint_device_unit {
805	device_t	_dev;
806	device_t	_child;
807	const char	*_name;
808	int		*_unitp;
809};
810
811/**
812 * @brief Notify a bus that the bus pass level has been changed
813 *
814 * @param _dev		the bus device
815 */
816METHOD void new_pass {
817	device_t	_dev;
818} DEFAULT bus_generic_new_pass;
819
820/**
821 * @brief Notify a bus that specified child's IRQ should be remapped.
822 *
823 * @param _dev		the bus device
824 * @param _child	the child device
825 * @param _irq		the irq number
826 */
827METHOD int remap_intr {
828	device_t	_dev;
829	device_t	_child;
830	u_int		_irq;
831} DEFAULT null_remap_intr;
832
833/**
834 * @brief Suspend a given child
835 *
836 * @param _dev		the parent device of @p _child
837 * @param _child	the device to suspend
838 */
839METHOD int suspend_child {
840	device_t	_dev;
841	device_t	_child;
842} DEFAULT bus_generic_suspend_child;
843
844/**
845 * @brief Resume a given child
846 *
847 * @param _dev		the parent device of @p _child
848 * @param _child	the device to resume
849 */
850METHOD int resume_child {
851	device_t	_dev;
852	device_t	_child;
853} DEFAULT bus_generic_resume_child;
854
855/**
856 * @brief Get the VM domain handle for the given bus and child.
857 *
858 * @param _dev		the bus device
859 * @param _child	the child device
860 * @param _domain	a pointer to the bus's domain handle identifier
861 */
862METHOD int get_domain {
863	device_t	_dev;
864	device_t	_child;
865	int		*_domain;
866} DEFAULT bus_generic_get_domain;
867
868/**
869 * @brief Request a set of CPUs
870 *
871 * @param _dev		the bus device
872 * @param _child	the child device
873 * @param _op		type of CPUs to request
874 * @param _setsize	the size of the set passed in _cpuset
875 * @param _cpuset	a pointer to a cpuset to receive the requested
876 *			set of CPUs
877 */
878METHOD int get_cpus {
879	device_t	_dev;
880	device_t	_child;
881	enum cpu_sets	_op;
882	size_t		_setsize;
883	struct _cpuset	*_cpuset;
884} DEFAULT bus_generic_get_cpus;
885
886/**
887 * @brief Prepares the given child of the bus for reset
888 *
889 * Typically bus detaches or suspends children' drivers, and then
890 * calls this method to save bus-specific information, for instance,
891 * PCI config space, which is damaged by reset.
892 *
893 * The bus_helper_reset_prepare() helper is provided to ease
894 * implementing bus reset methods.
895 *
896 * @param _dev		the bus device
897 * @param _child	the child device
898 */
899METHOD int reset_prepare {
900	device_t _dev;
901	device_t _child;
902} DEFAULT null_reset_prepare;
903
904/**
905 * @brief Restores the child operations after the reset
906 *
907 * The bus_helper_reset_post() helper is provided to ease
908 * implementing bus reset methods.
909 *
910 * @param _dev		the bus device
911 * @param _child	the child device
912 */
913METHOD int reset_post {
914	device_t _dev;
915	device_t _child;
916} DEFAULT null_reset_post;
917
918/**
919 * @brief Performs reset of the child
920 *
921 * @param _dev		the bus device
922 * @param _child	the child device
923 * @param _flags	DEVF_RESET_ flags
924 */
925METHOD int reset_child {
926	device_t _dev;
927	device_t _child;
928	int _flags;
929};
930
931/**
932 * @brief Gets child's specific property
933 *
934 * The bus_get_property can be used to access device
935 * specific properties stored on the bus. If _propvalue
936 * is NULL or _size is 0, then method only returns size
937 * of the property.
938 *
939 * @param _dev			the bus device
940 * @param _child		the child device
941 * @param _propname		property name
942 * @param _propvalue	property value destination
943 * @param _size			property value size
944 *
945 * @returns size of property if successful otherwise -1
946 */
947METHOD ssize_t get_property {
948	device_t _dev;
949	device_t _child;
950	const char *_propname;
951	void *_propvalue;
952	size_t _size;
953	device_property_type_t type;
954} DEFAULT bus_generic_get_property;
955
956/**
957 * @brief Gets a child's full path to the device
958 *
959 * The get_device_path method retrieves a device's
960 * full path to the device using one of several
961 * locators present in the system.
962 *
963 * @param _bus			the bus device
964 * @param _child		the child device
965 * @param _locator		locator name
966 * @param _sb			buffer loaction string
967 */
968METHOD int get_device_path {
969	device_t _bus;
970	device_t _child;
971	const char *_locator;
972	struct sbuf *_sb;
973} DEFAULT bus_generic_get_device_path;
974