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