xref: /freebsd/sys/dev/bhnd/bhnd.h (revision 82725ba9bf1fd59746a4006a06f24d4d61d142f2)
1 /*-
2  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
3  * Copyright (c) 2017 The FreeBSD Foundation
4  * All rights reserved.
5  *
6  * Portions of this software were developed by Landon Fuller
7  * under sponsorship from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer,
14  *    without modification.
15  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17  *    redistribution must be conditioned upon including a substantially
18  *    similar Disclaimer requirement for further binary redistribution.
19  *
20  * NO WARRANTY
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGES.
32  *
33  * $FreeBSD$
34  */
35 
36 #ifndef _BHND_BHND_H_
37 #define _BHND_BHND_H_
38 
39 #include <sys/param.h>
40 #include <sys/bus.h>
41 #include <sys/lock.h>
42 #include <sys/mutex.h>
43 
44 #include <machine/bus.h>
45 
46 #include "bhnd_ids.h"
47 #include "bhnd_types.h"
48 #include "bhnd_erom_types.h"
49 #include "bhnd_debug.h"
50 #include "bhnd_bus_if.h"
51 #include "bhnd_match.h"
52 
53 #include "nvram/bhnd_nvram.h"
54 
55 extern devclass_t bhnd_devclass;
56 extern devclass_t bhnd_hostb_devclass;
57 extern devclass_t bhnd_nvram_devclass;
58 
59 #define	BHND_CHIPID_MAX_NAMELEN	32	/**< maximum buffer required for a
60 					     bhnd_format_chip_id() */
61 
62 /**
63  * bhnd child instance variables
64  */
65 enum bhnd_device_vars {
66 	BHND_IVAR_VENDOR,	/**< Designer's JEP-106 manufacturer ID. */
67 	BHND_IVAR_DEVICE,	/**< Part number */
68 	BHND_IVAR_HWREV,	/**< Core revision */
69 	BHND_IVAR_DEVICE_CLASS,	/**< Core class (@sa bhnd_devclass_t) */
70 	BHND_IVAR_VENDOR_NAME,	/**< Core vendor name */
71 	BHND_IVAR_DEVICE_NAME,	/**< Core name */
72 	BHND_IVAR_CORE_INDEX,	/**< Bus-assigned core number */
73 	BHND_IVAR_CORE_UNIT,	/**< Bus-assigned core unit number,
74 				     assigned sequentially (starting at 0) for
75 				     each vendor/device pair. */
76 	BHND_IVAR_PMU_INFO,	/**< Internal bus-managed PMU state */
77 };
78 
79 /**
80  * bhnd device probe priority bands.
81  */
82 enum {
83 	BHND_PROBE_ROOT         = 0,    /**< Nexus or host bridge */
84 	BHND_PROBE_BUS		= 1000,	/**< Buses and bridges */
85 	BHND_PROBE_CPU		= 2000,	/**< CPU devices */
86 	BHND_PROBE_INTERRUPT	= 3000,	/**< Interrupt controllers. */
87 	BHND_PROBE_TIMER	= 4000,	/**< Timers and clocks. */
88 	BHND_PROBE_RESOURCE	= 5000,	/**< Resource discovery (including NVRAM/SPROM) */
89 	BHND_PROBE_DEFAULT	= 6000,	/**< Default device priority */
90 };
91 
92 /**
93  * Constants defining fine grained ordering within a BHND_PROBE_* priority band.
94  *
95  * Example:
96  * @code
97  * BHND_PROBE_BUS + BHND_PROBE_ORDER_FIRST
98  * @endcode
99  */
100 enum {
101 	BHND_PROBE_ORDER_FIRST		= 0,
102 	BHND_PROBE_ORDER_EARLY		= 25,
103 	BHND_PROBE_ORDER_MIDDLE		= 50,
104 	BHND_PROBE_ORDER_LATE		= 75,
105 	BHND_PROBE_ORDER_LAST		= 100
106 
107 };
108 
109 
110 /**
111  * Per-core IOCTL flags common to all bhnd(4) cores.
112  */
113 enum {
114 	BHND_IOCTL_BIST		= 0x8000,	/**< Initiate a built-in self-test (BIST). Must be cleared
115 						     after BIST results are read via BHND_IOST_BIST_* */
116 	BHND_IOCTL_PME		= 0x4000,	/**< Enable posting of power management events by the core. */
117 	BHND_IOCTL_CFLAGS	= 0x3FFC,	/**< Reserved for core-specific ioctl flags. */
118 	BHND_IOCTL_CLK_FORCE	= 0x0002,	/**< Force disable of clock gating, resulting in all clocks
119 						     being distributed within the core. Should be set when
120 						     asserting/deasserting reset to ensure the reset signal
121 						     fully propagates to the entire core. */
122 	BHND_IOCTL_CLK_EN	= 0x0001,	/**< If cleared, the core clock will be disabled. Should be
123 						     set during normal operation, and cleared when the core is
124 						     held in reset. */
125 };
126 
127 /**
128  * Per-core IOST flags common to all bhnd(4) cores.
129  */
130 enum {
131 	BHND_IOST_BIST_DONE	= 0x8000,	/**< Set upon BIST completion (see BHND_IOCTL_BIST), and cleared
132 						     if 0 is written to BHND_IOCTL_BIST. */
133 	BHND_IOST_BIST_FAIL	= 0x4000,	/**< Set upon detection of a BIST error; the value is unspecified
134 						     if BIST has not completed and BHND_IOST_BIST_DONE is not set. */
135 	BHND_IOST_CLK		= 0x2000,	/**< Set if the core has requested that gated clocks be enabled, or
136 						     cleared otherwise. The value is undefined if a core does not
137 						     support clock gating. */
138 	BHND_IOST_DMA64		= 0x1000,	/**< Set if this core supports 64-bit DMA */
139 	BHND_IOST_CFLAGS	= 0x0FFC,	/**< Reserved for core-specific status flags. */
140 };
141 
142 /*
143  * Simplified accessors for bhnd device ivars
144  */
145 #define	BHND_ACCESSOR(var, ivar, type) \
146 	__BUS_ACCESSOR(bhnd, var, BHND, ivar, type)
147 
148 BHND_ACCESSOR(vendor,		VENDOR,		uint16_t);
149 BHND_ACCESSOR(device,		DEVICE,		uint16_t);
150 BHND_ACCESSOR(hwrev,		HWREV,		uint8_t);
151 BHND_ACCESSOR(class,		DEVICE_CLASS,	bhnd_devclass_t);
152 BHND_ACCESSOR(vendor_name,	VENDOR_NAME,	const char *);
153 BHND_ACCESSOR(device_name,	DEVICE_NAME,	const char *);
154 BHND_ACCESSOR(core_index,	CORE_INDEX,	u_int);
155 BHND_ACCESSOR(core_unit,	CORE_UNIT,	int);
156 BHND_ACCESSOR(pmu_info,		PMU_INFO,	void *);
157 
158 #undef	BHND_ACCESSOR
159 
160 /**
161  * A bhnd(4) board descriptor.
162  */
163 struct bhnd_board_info {
164 	uint16_t	board_vendor;	/**< PCI-SIG vendor ID (even on non-PCI
165 					  *  devices).
166 					  *
167 					  *  On PCI devices, this will generally
168 					  *  be the subsystem vendor ID, but the
169 					  *  value may be overridden in device
170 					  *  NVRAM.
171 					  */
172 	uint16_t	board_type;	/**< Board type (See BHND_BOARD_*)
173 					  *
174 					  *  On PCI devices, this will generally
175 					  *  be the subsystem device ID, but the
176 					  *  value may be overridden in device
177 					  *  NVRAM.
178 					  */
179 	uint16_t	board_rev;	/**< Board revision. */
180 	uint8_t		board_srom_rev;	/**< Board SROM format revision */
181 
182 	uint32_t	board_flags;	/**< Board flags (see BHND_BFL_*) */
183 	uint32_t	board_flags2;	/**< Board flags 2 (see BHND_BFL2_*) */
184 	uint32_t	board_flags3;	/**< Board flags 3 (see BHND_BFL3_*) */
185 };
186 
187 
188 /**
189  * Chip Identification
190  *
191  * This is read from the ChipCommon ID register; on earlier bhnd(4) devices
192  * where ChipCommon is unavailable, known values must be supplied.
193  */
194 struct bhnd_chipid {
195 	uint16_t	chip_id;	/**< chip id (BHND_CHIPID_*) */
196 	uint8_t		chip_rev;	/**< chip revision */
197 	uint8_t		chip_pkg;	/**< chip package (BHND_PKGID_*) */
198 	uint8_t		chip_type;	/**< chip type (BHND_CHIPTYPE_*) */
199 
200 	bhnd_addr_t	enum_addr;	/**< chip_type-specific enumeration
201 					  *  address; either the siba(4) base
202 					  *  core register block, or the bcma(4)
203 					  *  EROM core address. */
204 
205 	uint8_t		ncores;		/**< number of cores, if known. 0 if
206 					  *  not available. */
207 };
208 
209 /**
210  * A bhnd(4) core descriptor.
211  */
212 struct bhnd_core_info {
213 	uint16_t	vendor;		/**< JEP-106 vendor (BHND_MFGID_*) */
214 	uint16_t	device;		/**< device */
215 	uint16_t	hwrev;		/**< hardware revision */
216 	u_int		core_idx;	/**< bus-assigned core index */
217 	int		unit;		/**< bus-assigned core unit */
218 };
219 
220 /**
221  * bhnd(4) DMA address widths.
222  */
223 typedef enum {
224 	BHND_DMA_ADDR_30BIT	= 30,	/**< 30-bit DMA */
225 	BHND_DMA_ADDR_32BIT	= 32,	/**< 32-bit DMA */
226 	BHND_DMA_ADDR_64BIT	= 64,	/**< 64-bit DMA */
227 } bhnd_dma_addrwidth;
228 
229 /**
230  * Convert an address width (in bits) to its corresponding mask.
231  */
232 #define	BHND_DMA_ADDR_BITMASK(_width)	\
233 	((_width >= 64) ? ~0ULL :	\
234 	 (_width == 0) ? 0x0 :		\
235 	 ((1ULL << (_width)) - 1))	\
236 
237 /**
238  * bhnd(4) DMA address translation descriptor.
239  */
240 struct bhnd_dma_translation {
241 	/**
242 	 * Host-to-device physical address translation.
243 	 *
244 	 * This may be added to the host physical address to produce a device
245 	 * DMA address.
246 	 */
247 	bhnd_addr_t	base_addr;
248 
249 	/**
250 	 * Device-addressable address mask.
251 	 *
252 	 * This defines the device's DMA address range, excluding any bits
253 	 * reserved for mapping the address to the base_addr.
254 	 */
255 	bhnd_addr_t	addr_mask;
256 
257 	/**
258 	 * Device-addressable extended address mask.
259 	 *
260 	 * If a per-core bhnd(4) DMA engine supports the 'addrext' control
261 	 * field, it can be used to provide address bits excluded by addr_mask.
262 	 *
263 	 * Support for DMA extended address changes – including coordination
264 	 * with the core providing DMA translation – is handled transparently by
265 	 * the DMA engine. For example, on PCI(e) Wi-Fi chipsets, the Wi-Fi
266 	 * core DMA engine will (in effect) update the PCI core's DMA
267 	 * sbtopcitranslation base address to map the full address prior to
268 	 * performing a DMA transaction.
269 	 */
270 	bhnd_addr_t	addrext_mask;
271 
272 	/**
273 	 * Translation flags (see bhnd_dma_translation_flags)
274 	 */
275 	uint32_t	flags;
276 };
277 
278 #define	BHND_DMA_TRANSLATION_TABLE_END	{ 0, 0, 0, 0 }
279 
280 #define	BHND_DMA_IS_TRANSLATION_TABLE_END(_dt)			\
281 	((_dt)->base_addr == 0 && (_dt)->addr_mask == 0 &&	\
282 	 (_dt)->addrext_mask == 0 && (_dt)->flags == 0)
283 
284 /**
285  * bhnd(4) DMA address translation flags.
286  */
287 enum bhnd_dma_translation_flags {
288 	/**
289 	 * The translation remaps the device's physical address space.
290 	 *
291 	 * This is used in conjunction with BHND_DMA_TRANSLATION_BYTESWAPPED to
292 	 * define a DMA translation that provides byteswapped access to
293 	 * physical memory on big-endian MIPS SoCs.
294 	 */
295 	BHND_DMA_TRANSLATION_PHYSMAP		= (1<<0),
296 
297 	/**
298 	 * Provides a byte-swapped mapping; write requests will be byte-swapped
299 	 * before being written to memory, and read requests will be
300 	 * byte-swapped before being returned.
301 	 *
302 	 * This is primarily used to perform efficient byte swapping of DMA
303 	 * data on embedded MIPS SoCs executing in big-endian mode.
304 	 */
305 	BHND_DMA_TRANSLATION_BYTESWAPPED	= (1<<1),
306 };
307 
308 /**
309 * A bhnd(4) bus resource.
310 *
311 * This provides an abstract interface to per-core resources that may require
312 * bus-level remapping of address windows prior to access.
313 */
314 struct bhnd_resource {
315 	struct resource	*res;		/**< the system resource. */
316 	bool		 direct;	/**< false if the resource requires
317 					 *   bus window remapping before it
318 					 *   is MMIO accessible. */
319 };
320 
321 /** Wrap the active resource @p _r in a bhnd_resource structure */
322 #define	BHND_DIRECT_RESOURCE(_r)	((struct bhnd_resource) {	\
323 	.res = (_r),							\
324 	.direct = true,							\
325 })
326 
327 /**
328  * Device quirk table descriptor.
329  */
330 struct bhnd_device_quirk {
331 	struct bhnd_device_match desc;		/**< device match descriptor */
332 	uint32_t		 quirks;	/**< quirk flags */
333 };
334 
335 #define	BHND_CORE_QUIRK(_rev, _flags)		\
336 	{{ BHND_MATCH_CORE_REV(_rev) }, (_flags) }
337 
338 #define	BHND_CHIP_QUIRK(_chip, _rev, _flags)	\
339 	{{ BHND_MATCH_CHIP_IR(BCM ## _chip, _rev) }, (_flags) }
340 
341 #define	BHND_PKG_QUIRK(_chip, _pkg, _flags)	\
342 	{{ BHND_MATCH_CHIP_IP(BCM ## _chip, BCM ## _chip ## _pkg) }, (_flags) }
343 
344 #define	BHND_BOARD_QUIRK(_board, _flags)	\
345 	{{ BHND_MATCH_BOARD_TYPE(_board) },	\
346 	    (_flags) }
347 
348 #define	BHND_DEVICE_QUIRK_END		{ { BHND_MATCH_ANY }, 0 }
349 #define	BHND_DEVICE_QUIRK_IS_END(_q)	\
350 	(((_q)->desc.m.match_flags == 0) && (_q)->quirks == 0)
351 
352 enum {
353 	BHND_DF_ANY	= 0,
354 	BHND_DF_HOSTB	= (1<<0),	/**< core is serving as the bus' host
355 					  *  bridge. implies BHND_DF_ADAPTER */
356 	BHND_DF_SOC	= (1<<1),	/**< core is attached to a native
357 					     bus (BHND_ATTACH_NATIVE) */
358 	BHND_DF_ADAPTER	= (1<<2),	/**< core is attached to a bridged
359 					  *  adapter (BHND_ATTACH_ADAPTER) */
360 };
361 
362 /** Device probe table descriptor */
363 struct bhnd_device {
364 	const struct bhnd_device_match	 core;		/**< core match descriptor */
365 	const char			*desc;		/**< device description, or NULL. */
366 	const struct bhnd_device_quirk	*quirks_table;	/**< quirks table for this device, or NULL */
367 	uint32_t			 device_flags;	/**< required BHND_DF_* flags */
368 };
369 
370 #define	_BHND_DEVICE(_vendor, _device, _desc, _quirks,		\
371      _flags, ...)						\
372 	{ { BHND_MATCH_CORE(BHND_MFGID_ ## _vendor,		\
373 	    BHND_COREID_ ## _device) }, _desc, _quirks,		\
374 	    _flags }
375 
376 #define	BHND_DEVICE(_vendor, _device, _desc, _quirks, ...)	\
377 	_BHND_DEVICE(_vendor, _device, _desc, _quirks,		\
378 	    ## __VA_ARGS__, 0)
379 
380 #define	BHND_DEVICE_END		{ { BHND_MATCH_ANY }, NULL, NULL, 0 }
381 #define	BHND_DEVICE_IS_END(_d)	\
382 	(BHND_MATCH_IS_ANY(&(_d)->core) && (_d)->desc == NULL)
383 
384 /**
385  * bhnd device sort order.
386  */
387 typedef enum {
388 	BHND_DEVICE_ORDER_ATTACH,	/**< sort by bhnd(4) device attach order;
389 					     child devices should be probed/attached
390 					     in this order */
391 	BHND_DEVICE_ORDER_DETACH,	/**< sort by bhnd(4) device detach order;
392 					     child devices should be detached, suspended,
393 					     and shutdown in this order */
394 } bhnd_device_order;
395 
396 /**
397  * A registry of bhnd service providers.
398  */
399 struct bhnd_service_registry {
400 	STAILQ_HEAD(,bhnd_service_entry)	entries;	/**< registered services */
401 	struct mtx				lock;		/**< state lock */
402 };
403 
404 /**
405  * bhnd service provider flags.
406  */
407 enum {
408 	BHND_SPF_INHERITED	= (1<<0),	/**< service provider reference was inherited from
409 						     a parent bus, and should be deregistered when the
410 						     last active reference is released */
411 };
412 
413 const char			*bhnd_vendor_name(uint16_t vendor);
414 const char			*bhnd_port_type_name(bhnd_port_type port_type);
415 const char			*bhnd_nvram_src_name(bhnd_nvram_src nvram_src);
416 
417 const char 			*bhnd_find_core_name(uint16_t vendor,
418 				     uint16_t device);
419 bhnd_devclass_t			 bhnd_find_core_class(uint16_t vendor,
420 				     uint16_t device);
421 
422 const char			*bhnd_core_name(const struct bhnd_core_info *ci);
423 bhnd_devclass_t			 bhnd_core_class(const struct bhnd_core_info *ci);
424 
425 int				 bhnd_format_chip_id(char *buffer, size_t size,
426 				     uint16_t chip_id);
427 
428 device_t			 bhnd_bus_match_child(device_t bus,
429 				     const struct bhnd_core_match *desc);
430 
431 device_t			 bhnd_bus_find_child(device_t bus,
432 				     bhnd_devclass_t class, int unit);
433 
434 int				 bhnd_bus_get_children(device_t bus,
435 				     device_t **devlistp, int *devcountp,
436 				     bhnd_device_order order);
437 
438 void				 bhnd_bus_free_children(device_t *devlist);
439 
440 int				 bhnd_bus_probe_children(device_t bus);
441 
442 int				 bhnd_sort_devices(device_t *devlist,
443 				     size_t devcount, bhnd_device_order order);
444 
445 device_t			 bhnd_find_bridge_root(device_t dev,
446 				     devclass_t bus_class);
447 
448 const struct bhnd_core_info	*bhnd_match_core(
449 				     const struct bhnd_core_info *cores,
450 				     u_int num_cores,
451 				     const struct bhnd_core_match *desc);
452 
453 const struct bhnd_core_info	*bhnd_find_core(
454 				     const struct bhnd_core_info *cores,
455 				     u_int num_cores, bhnd_devclass_t class);
456 
457 struct bhnd_core_match		 bhnd_core_get_match_desc(
458 				     const struct bhnd_core_info *core);
459 
460 bool				 bhnd_cores_equal(
461 				     const struct bhnd_core_info *lhs,
462 				     const struct bhnd_core_info *rhs);
463 
464 bool				 bhnd_core_matches(
465 				     const struct bhnd_core_info *core,
466 				     const struct bhnd_core_match *desc);
467 
468 bool				 bhnd_chip_matches(
469 				     const struct bhnd_chipid *chipid,
470 				     const struct bhnd_chip_match *desc);
471 
472 bool				 bhnd_board_matches(
473 				     const struct bhnd_board_info *info,
474 				     const struct bhnd_board_match *desc);
475 
476 bool				 bhnd_hwrev_matches(uint16_t hwrev,
477 				     const struct bhnd_hwrev_match *desc);
478 
479 bool				 bhnd_device_matches(device_t dev,
480 				     const struct bhnd_device_match *desc);
481 
482 const struct bhnd_device	*bhnd_device_lookup(device_t dev,
483 				     const struct bhnd_device *table,
484 				     size_t entry_size);
485 
486 uint32_t			 bhnd_device_quirks(device_t dev,
487 				     const struct bhnd_device *table,
488 				     size_t entry_size);
489 
490 struct bhnd_core_info		 bhnd_get_core_info(device_t dev);
491 
492 int				 bhnd_alloc_resources(device_t dev,
493 				     struct resource_spec *rs,
494 				     struct bhnd_resource **res);
495 
496 void				 bhnd_release_resources(device_t dev,
497 				     const struct resource_spec *rs,
498 				     struct bhnd_resource **res);
499 
500 struct bhnd_chipid		 bhnd_parse_chipid(uint32_t idreg,
501 				     bhnd_addr_t enum_addr);
502 
503 int				 bhnd_chipid_fixed_ncores(
504 				     const struct bhnd_chipid *cid,
505 				     uint16_t chipc_hwrev, uint8_t *ncores);
506 
507 int				 bhnd_read_chipid(device_t dev,
508 				     struct resource_spec *rs,
509 				     bus_size_t chipc_offset,
510 				     struct bhnd_chipid *result);
511 
512 void				 bhnd_set_custom_core_desc(device_t dev,
513 				     const char *name);
514 void				 bhnd_set_default_core_desc(device_t dev);
515 
516 void				 bhnd_set_default_bus_desc(device_t dev,
517 				     const struct bhnd_chipid *chip_id);
518 
519 int				 bhnd_nvram_getvar_str(device_t dev,
520 				     const char *name, char *buf, size_t len,
521 				     size_t *rlen);
522 
523 int				 bhnd_nvram_getvar_uint(device_t dev,
524 				     const char *name, void *value, int width);
525 int				 bhnd_nvram_getvar_uint8(device_t dev,
526 				     const char *name, uint8_t *value);
527 int				 bhnd_nvram_getvar_uint16(device_t dev,
528 				     const char *name, uint16_t *value);
529 int				 bhnd_nvram_getvar_uint32(device_t dev,
530 				     const char *name, uint32_t *value);
531 
532 int				 bhnd_nvram_getvar_int(device_t dev,
533 				     const char *name, void *value, int width);
534 int				 bhnd_nvram_getvar_int8(device_t dev,
535 				     const char *name, int8_t *value);
536 int				 bhnd_nvram_getvar_int16(device_t dev,
537 				     const char *name, int16_t *value);
538 int				 bhnd_nvram_getvar_int32(device_t dev,
539 				     const char *name, int32_t *value);
540 
541 int				 bhnd_nvram_getvar_array(device_t dev,
542 				     const char *name, void *buf, size_t count,
543 				     bhnd_nvram_type type);
544 
545 int				 bhnd_service_registry_init(
546 				     struct bhnd_service_registry *bsr);
547 int				 bhnd_service_registry_fini(
548 				     struct bhnd_service_registry *bsr);
549 int				 bhnd_service_registry_add(
550 				     struct bhnd_service_registry *bsr,
551 				     device_t provider,
552 				     bhnd_service_t service,
553 				     uint32_t flags);
554 int				 bhnd_service_registry_remove(
555 				     struct bhnd_service_registry *bsr,
556 				     device_t provider,
557 				     bhnd_service_t service);
558 device_t			 bhnd_service_registry_retain(
559 				     struct bhnd_service_registry *bsr,
560 				     bhnd_service_t service);
561 bool				 bhnd_service_registry_release(
562 				     struct bhnd_service_registry *bsr,
563 				     device_t provider,
564 				     bhnd_service_t service);
565 
566 int				 bhnd_bus_generic_register_provider(
567 				     device_t dev, device_t child,
568 				     device_t provider, bhnd_service_t service);
569 int				 bhnd_bus_generic_deregister_provider(
570 				     device_t dev, device_t child,
571 				     device_t provider, bhnd_service_t service);
572 device_t			 bhnd_bus_generic_retain_provider(device_t dev,
573 				     device_t child, bhnd_service_t service);
574 void				 bhnd_bus_generic_release_provider(device_t dev,
575 				     device_t child, device_t provider,
576 				     bhnd_service_t service);
577 
578 int				 bhnd_bus_generic_sr_register_provider(
579 				     device_t dev, device_t child,
580 				     device_t provider, bhnd_service_t service);
581 int				 bhnd_bus_generic_sr_deregister_provider(
582 				     device_t dev, device_t child,
583 				     device_t provider, bhnd_service_t service);
584 device_t			 bhnd_bus_generic_sr_retain_provider(device_t dev,
585 				     device_t child, bhnd_service_t service);
586 void				 bhnd_bus_generic_sr_release_provider(device_t dev,
587 				     device_t child, device_t provider,
588 				     bhnd_service_t service);
589 
590 bool				 bhnd_bus_generic_is_hw_disabled(device_t dev,
591 				     device_t child);
592 bool				 bhnd_bus_generic_is_region_valid(device_t dev,
593 				     device_t child, bhnd_port_type type,
594 				     u_int port, u_int region);
595 int				 bhnd_bus_generic_get_nvram_var(device_t dev,
596 				     device_t child, const char *name,
597 				     void *buf, size_t *size,
598 				     bhnd_nvram_type type);
599 const struct bhnd_chipid	*bhnd_bus_generic_get_chipid(device_t dev,
600 				     device_t child);
601 int				 bhnd_bus_generic_get_dma_translation(
602 				     device_t dev, device_t child, u_int width,
603 				     uint32_t flags, bus_dma_tag_t *dmat,
604 				     struct bhnd_dma_translation *translation);
605 int				 bhnd_bus_generic_read_board_info(device_t dev,
606 				     device_t child,
607 				     struct bhnd_board_info *info);
608 struct bhnd_resource		*bhnd_bus_generic_alloc_resource (device_t dev,
609 				     device_t child, int type, int *rid,
610 				     rman_res_t start, rman_res_t end,
611 				     rman_res_t count, u_int flags);
612 int				 bhnd_bus_generic_release_resource (device_t dev,
613 				     device_t child, int type, int rid,
614 				     struct bhnd_resource *r);
615 int				 bhnd_bus_generic_activate_resource (device_t dev,
616 				     device_t child, int type, int rid,
617 				     struct bhnd_resource *r);
618 int				 bhnd_bus_generic_deactivate_resource (device_t dev,
619 				     device_t child, int type, int rid,
620 				     struct bhnd_resource *r);
621 uintptr_t			 bhnd_bus_generic_get_intr_domain(device_t dev,
622 				     device_t child, bool self);
623 
624 /**
625  * Return the bhnd(4) bus driver's device enumeration parser class
626  *
627  * @param driver A bhnd bus driver instance.
628  */
629 static inline bhnd_erom_class_t *
630 bhnd_driver_get_erom_class(driver_t *driver)
631 {
632 	return (BHND_BUS_GET_EROM_CLASS(driver));
633 }
634 
635 /**
636  * Return the active host bridge core for the bhnd bus, if any, or NULL if
637  * not found.
638  *
639  * @param dev A bhnd bus device.
640  */
641 static inline device_t
642 bhnd_bus_find_hostb_device(device_t dev) {
643 	return (BHND_BUS_FIND_HOSTB_DEVICE(dev));
644 }
645 
646 /**
647  * Register a provider for a given @p service.
648  *
649  * @param dev		The device to register as a service provider
650  *			with its parent bus.
651  * @param service	The service for which @p dev will be registered.
652  *
653  * @retval 0		success
654  * @retval EEXIST	if an entry for @p service already exists.
655  * @retval non-zero	if registering @p dev otherwise fails, a regular
656  *			unix error code will be returned.
657  */
658 static inline int
659 bhnd_register_provider(device_t dev, bhnd_service_t service)
660 {
661 	return (BHND_BUS_REGISTER_PROVIDER(device_get_parent(dev), dev, dev,
662 	    service));
663 }
664 
665  /**
666  * Attempt to remove a service provider registration for @p dev.
667  *
668  * @param dev		The device to be deregistered as a service provider.
669  * @param service	The service for which @p dev will be deregistered, or
670  *			BHND_SERVICE_INVALID to remove all service registrations
671  *			for @p dev.
672  *
673  * @retval 0		success
674  * @retval EBUSY	if active references to @p dev exist; @see
675  *			bhnd_retain_provider() and bhnd_release_provider().
676  */
677 static inline int
678 bhnd_deregister_provider(device_t dev, bhnd_service_t service)
679 {
680 	return (BHND_BUS_DEREGISTER_PROVIDER(device_get_parent(dev), dev, dev,
681 	    service));
682 }
683 
684 /**
685  * Retain and return a reference to the registered @p service provider, if any.
686  *
687  * @param dev		The requesting device.
688  * @param service	The service for which a provider should be returned.
689  *
690  * On success, the caller assumes ownership the returned provider, and
691  * is responsible for releasing this reference via
692  * BHND_BUS_RELEASE_PROVIDER().
693  *
694  * @retval device_t	success
695  * @retval NULL		if no provider is registered for @p service.
696  */
697 static inline device_t
698 bhnd_retain_provider(device_t dev, bhnd_service_t service)
699 {
700 	return (BHND_BUS_RETAIN_PROVIDER(device_get_parent(dev), dev,
701 	    service));
702 }
703 
704 /**
705  * Release a reference to a provider device previously returned by
706  * bhnd_retain_provider().
707  *
708  * @param dev The requesting device.
709  * @param provider The provider to be released.
710  * @param service The service for which @p provider was previously retained.
711  */
712 static inline void
713 bhnd_release_provider(device_t dev, device_t provider,
714     bhnd_service_t service)
715 {
716 	return (BHND_BUS_RELEASE_PROVIDER(device_get_parent(dev), dev,
717 	    provider, service));
718 }
719 
720 /**
721  * Return true if the hardware components required by @p dev are known to be
722  * unpopulated or otherwise unusable.
723  *
724  * In some cases, enumerated devices may have pins that are left floating, or
725  * the hardware may otherwise be non-functional; this method allows a parent
726  * device to explicitly specify if a successfully enumerated @p dev should
727  * be disabled.
728  *
729  * @param dev A bhnd bus child device.
730  */
731 static inline bool
732 bhnd_is_hw_disabled(device_t dev) {
733 	return (BHND_BUS_IS_HW_DISABLED(device_get_parent(dev), dev));
734 }
735 
736 /**
737  * Return the BHND chip identification info for the bhnd bus.
738  *
739  * @param dev A bhnd bus child device.
740  */
741 static inline const struct bhnd_chipid *
742 bhnd_get_chipid(device_t dev) {
743 	return (BHND_BUS_GET_CHIPID(device_get_parent(dev), dev));
744 };
745 
746 
747 /**
748  * Read the current value of a bhnd(4) device's per-core I/O control register.
749  *
750  * @param dev The bhnd bus child device to be queried.
751  * @param[out] ioctl On success, the I/O control register value.
752  *
753  * @retval 0 success
754  * @retval EINVAL If @p child is not a direct child of @p dev.
755  * @retval ENODEV If agent/config space for @p child is unavailable.
756  * @retval non-zero If reading the IOCTL register otherwise fails, a regular
757  * unix error code will be returned.
758  */
759 static inline int
760 bhnd_read_ioctl(device_t dev, uint16_t *ioctl)
761 {
762 	return (BHND_BUS_READ_IOCTL(device_get_parent(dev), dev, ioctl));
763 }
764 
765 /**
766  * Write @p value and @p mask to a bhnd(4) device's per-core I/O control
767  * register.
768  *
769  * @param dev The bhnd bus child device for which the IOCTL register will be
770  * written.
771  * @param value The value to be written (see BHND_IOCTL_*).
772  * @param mask Only the bits defined by @p mask will be updated from @p value.
773  *
774  * @retval 0 success
775  * @retval EINVAL If @p child is not a direct child of @p dev.
776  * @retval ENODEV If agent/config space for @p child is unavailable.
777  * @retval non-zero If writing the IOCTL register otherwise fails, a regular
778  * unix error code will be returned.
779  */
780 static inline int
781 bhnd_write_ioctl(device_t dev, uint16_t value, uint16_t mask)
782 {
783 	return (BHND_BUS_WRITE_IOCTL(device_get_parent(dev), dev, value, mask));
784 }
785 
786 /**
787  * Read the current value of a bhnd(4) device's per-core I/O status register.
788  *
789  * @param dev The bhnd bus child device to be queried.
790  * @param[out] iost On success, the I/O status register value.
791  *
792  * @retval 0 success
793  * @retval EINVAL If @p child is not a direct child of @p dev.
794  * @retval ENODEV If agent/config space for @p child is unavailable.
795  * @retval non-zero If reading the IOST register otherwise fails, a regular
796  * unix error code will be returned.
797  */
798 static inline int
799 bhnd_read_iost(device_t dev, uint16_t *iost)
800 {
801 	return (BHND_BUS_READ_IOST(device_get_parent(dev), dev, iost));
802 }
803 
804 /**
805  * Return true if the given bhnd device's hardware is currently held
806  * in a RESET state or otherwise not clocked (BHND_IOCTL_CLK_EN).
807  *
808  * @param dev The device to query.
809  *
810  * @retval true If @p dev is held in RESET or not clocked (BHND_IOCTL_CLK_EN),
811  * or an error occured determining @p dev's hardware state.
812  * @retval false If @p dev is clocked and is not held in RESET.
813  */
814 static inline bool
815 bhnd_is_hw_suspended(device_t dev)
816 {
817 	return (BHND_BUS_IS_HW_SUSPENDED(device_get_parent(dev), dev));
818 }
819 
820 /**
821  * Place the bhnd(4) device's hardware into a reset state, and then bring the
822  * hardware out of reset with BHND_IOCTL_CLK_EN and @p ioctl flags set.
823  *
824  * Any clock or resource PMU requests previously made by @p dev will be
825  * invalidated.
826  *
827  * @param dev The device to be reset.
828  * @param ioctl Device-specific core ioctl flags to be supplied on reset
829  * (see BHND_IOCTL_*).
830  *
831  * @retval 0 success
832  * @retval non-zero error
833  */
834 static inline int
835 bhnd_reset_hw(device_t dev, uint16_t ioctl)
836 {
837 	return (BHND_BUS_RESET_HW(device_get_parent(dev), dev, ioctl));
838 }
839 
840 /**
841  * Suspend @p child's hardware in a low-power reset state.
842  *
843  * Any clock or resource PMU requests previously made by @p dev will be
844  * invalidated.
845  *
846  * The hardware may be brought out of reset via bhnd_reset_hw().
847  *
848  * @param dev The device to be suspended.
849  *
850  * @retval 0 success
851  * @retval non-zero error
852  */
853 static inline int
854 bhnd_suspend_hw(device_t dev)
855 {
856 	return (BHND_BUS_SUSPEND_HW(device_get_parent(dev), dev));
857 }
858 
859 /**
860  * Return the BHND attachment type of the parent bhnd bus.
861  *
862  * @param dev A bhnd bus child device.
863  *
864  * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter,
865  * such as a WiFi chipset.
866  * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock,
867  * CPU, etc) to a directly attached native host.
868  */
869 static inline bhnd_attach_type
870 bhnd_get_attach_type (device_t dev) {
871 	return (BHND_BUS_GET_ATTACH_TYPE(device_get_parent(dev), dev));
872 }
873 
874 /**
875  * Find the best available DMA address translation capable of mapping a
876  * physical host address to a BHND DMA device address of @p width with
877  * @p flags.
878  *
879  * @param dev A bhnd bus child device.
880  * @param width The address width within which the translation window must
881  * reside (see BHND_DMA_ADDR_*).
882  * @param flags Required translation flags (see BHND_DMA_TRANSLATION_*).
883  * @param[out] dmat On success, will be populated with a DMA tag specifying the
884  * @p translation DMA address restrictions. This argment may be NULL if the DMA
885  * tag is not desired.
886  * the set of valid host DMA addresses reachable via @p translation.
887  * @param[out] translation On success, will be populated with a DMA address
888  * translation descriptor for @p child. This argment may be NULL if the
889  * descriptor is not desired.
890  *
891  * @retval 0 success
892  * @retval ENODEV If DMA is not supported.
893  * @retval ENOENT If no DMA translation matching @p width and @p flags is
894  * available.
895  * @retval non-zero If determining the DMA address translation for @p child
896  * otherwise fails, a regular unix error code will be returned.
897  */
898 static inline int
899 bhnd_get_dma_translation(device_t dev, u_int width, uint32_t flags,
900     bus_dma_tag_t *dmat, struct bhnd_dma_translation *translation)
901 {
902 	return (BHND_BUS_GET_DMA_TRANSLATION(device_get_parent(dev), dev, width,
903 	    flags, dmat, translation));
904 }
905 
906 /**
907  * Attempt to read the BHND board identification from the bhnd bus.
908  *
909  * This relies on NVRAM access, and will fail if a valid NVRAM device cannot
910  * be found, or is not yet attached.
911  *
912  * @param dev The parent of @p child.
913  * @param child The bhnd device requesting board info.
914  * @param[out] info On success, will be populated with the bhnd(4) device's
915  * board information.
916  *
917  * @retval 0 success
918  * @retval ENODEV	No valid NVRAM source could be found.
919  * @retval non-zero	If reading @p name otherwise fails, a regular unix
920  *			error code will be returned.
921  */
922 static inline int
923 bhnd_read_board_info(device_t dev, struct bhnd_board_info *info)
924 {
925 	return (BHND_BUS_READ_BOARD_INFO(device_get_parent(dev), dev, info));
926 }
927 
928 /**
929  * Return the number of interrupt lines assigned to @p dev.
930  *
931  * @param dev A bhnd bus child device.
932  */
933 static inline u_int
934 bhnd_get_intr_count(device_t dev)
935 {
936 	return (BHND_BUS_GET_INTR_COUNT(device_get_parent(dev), dev));
937 }
938 
939 /**
940  * Get the backplane interrupt vector of the @p intr line attached to @p dev.
941  *
942  * @param dev A bhnd bus child device.
943  * @param intr The index of the interrupt line being queried.
944  * @param[out] ivec On success, the assigned hardware interrupt vector will be
945  * written to this pointer.
946  *
947  * On bcma(4) devices, this returns the OOB bus line assigned to the
948  * interrupt.
949  *
950  * On siba(4) devices, this returns the target OCP slave flag number assigned
951  * to the interrupt.
952  *
953  * @retval 0		success
954  * @retval ENXIO	If @p intr exceeds the number of interrupt lines
955  *			assigned to @p child.
956  */
957 static inline int
958 bhnd_get_intr_ivec(device_t dev, u_int intr, u_int *ivec)
959 {
960 	return (BHND_BUS_GET_INTR_IVEC(device_get_parent(dev), dev, intr,
961 	    ivec));
962 }
963 
964 /**
965  * Map the given @p intr to an IRQ number; until unmapped, this IRQ may be used
966  * to allocate a resource of type SYS_RES_IRQ.
967  *
968  * On success, the caller assumes ownership of the interrupt mapping, and
969  * is responsible for releasing the mapping via bhnd_unmap_intr().
970  *
971  * @param dev The requesting device.
972  * @param intr The interrupt being mapped.
973  * @param[out] irq On success, the bus interrupt value mapped for @p intr.
974  *
975  * @retval 0		If an interrupt was assigned.
976  * @retval non-zero	If mapping an interrupt otherwise fails, a regular
977  *			unix error code will be returned.
978  */
979 static inline int
980 bhnd_map_intr(device_t dev, u_int intr, rman_res_t *irq)
981 {
982 	return (BHND_BUS_MAP_INTR(device_get_parent(dev), dev, intr, irq));
983 }
984 
985 /**
986  * Unmap an bus interrupt previously mapped via bhnd_map_intr().
987  *
988  * @param dev The requesting device.
989  * @param intr The interrupt number being unmapped. This is equivalent to the
990  * bus resource ID for the interrupt.
991  */
992 static inline void
993 bhnd_unmap_intr(device_t dev, rman_res_t irq)
994 {
995 	return (BHND_BUS_UNMAP_INTR(device_get_parent(dev), dev, irq));
996 }
997 
998 /**
999  * Allocate and enable per-core PMU request handling for @p child.
1000  *
1001  * The region containing the core's PMU register block (if any) must be
1002  * allocated via bus_alloc_resource(9) (or bhnd_alloc_resource) before
1003  * calling bhnd_alloc_pmu(), and must not be released until after
1004  * calling bhnd_release_pmu().
1005  *
1006  * @param dev The requesting bhnd device.
1007  *
1008  * @retval 0           success
1009  * @retval non-zero    If allocating PMU request state otherwise fails, a
1010  *                     regular unix error code will be returned.
1011  */
1012 static inline int
1013 bhnd_alloc_pmu(device_t dev)
1014 {
1015 	return (BHND_BUS_ALLOC_PMU(device_get_parent(dev), dev));
1016 }
1017 
1018 /**
1019  * Release any per-core PMU resources allocated for @p child. Any outstanding
1020  * PMU requests are are discarded.
1021  *
1022  * @param dev The requesting bhnd device.
1023  *
1024  * @retval 0           success
1025  * @retval non-zero    If releasing PMU request state otherwise fails, a
1026  *                     regular unix error code will be returned, and
1027  *                     the core state will be left unmodified.
1028  */
1029 static inline int
1030 bhnd_release_pmu(device_t dev)
1031 {
1032 	return (BHND_BUS_RELEASE_PMU(device_get_parent(dev), dev));
1033 }
1034 
1035 /**
1036  * Return the transition latency required for @p clock in microseconds, if
1037  * known.
1038  *
1039  * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
1040  * 'fastpwrup_dly' value.
1041  *
1042  * @note A driver must ask the bhnd bus to allocate PMU request state
1043  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
1044  *
1045  * @param dev The requesting bhnd device.
1046  * @param clock	The clock to be queried for transition latency.
1047  * @param[out] latency On success, the transition latency of @p clock in
1048  * microseconds.
1049  *
1050  * @retval 0		success
1051  * @retval ENODEV	If the transition latency for @p clock is not available.
1052  */
1053 static inline int
1054 bhnd_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
1055 {
1056 	return (BHND_BUS_GET_CLOCK_LATENCY(device_get_parent(dev), dev, clock,
1057 	    latency));
1058 }
1059 
1060 /**
1061  * Return the frequency for @p clock in Hz, if known.
1062  *
1063  * @param dev The requesting bhnd device.
1064  * @param clock The clock to be queried.
1065  * @param[out] freq On success, the frequency of @p clock in Hz.
1066  *
1067  * @note A driver must ask the bhnd bus to allocate PMU request state
1068  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
1069  *
1070  * @retval 0		success
1071  * @retval ENODEV	If the frequency for @p clock is not available.
1072  */
1073 static inline int
1074 bhnd_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
1075 {
1076 	return (BHND_BUS_GET_CLOCK_FREQ(device_get_parent(dev), dev, clock,
1077 	    freq));
1078 }
1079 
1080 /**
1081  * Request that @p clock (or faster) be routed to @p dev.
1082  *
1083  * @note A driver must ask the bhnd bus to allocate clock request state
1084  * via bhnd_alloc_pmu() before it can request clock resources.
1085  *
1086  * @note Any outstanding PMU clock requests will be discarded upon calling
1087  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
1088  *
1089  * @param dev The bhnd(4) device to which @p clock should be routed.
1090  * @param clock The requested clock source.
1091  *
1092  * @retval 0 success
1093  * @retval ENODEV If an unsupported clock was requested.
1094  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable,
1095  */
1096 static inline int
1097 bhnd_request_clock(device_t dev, bhnd_clock clock)
1098 {
1099 	return (BHND_BUS_REQUEST_CLOCK(device_get_parent(dev), dev, clock));
1100 }
1101 
1102 /**
1103  * Request that @p clocks be powered on behalf of @p dev.
1104  *
1105  * This will power any clock sources (e.g. XTAL, PLL, etc) required for
1106  * @p clocks and wait until they are ready, discarding any previous
1107  * requests by @p dev.
1108  *
1109  * @note A driver must ask the bhnd bus to allocate clock request state
1110  * via bhnd_alloc_pmu() before it can request clock resources.
1111  *
1112  * @note Any outstanding PMU clock requests will be discarded upon calling
1113  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
1114  *
1115  * @param dev The requesting bhnd(4) device.
1116  * @param clocks The clock(s) to be enabled.
1117  *
1118  * @retval 0 success
1119  * @retval ENODEV If an unsupported clock was requested.
1120  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1121  */
1122 static inline int
1123 bhnd_enable_clocks(device_t dev, uint32_t clocks)
1124 {
1125 	return (BHND_BUS_ENABLE_CLOCKS(device_get_parent(dev), dev, clocks));
1126 }
1127 
1128 /**
1129  * Power up an external PMU-managed resource assigned to @p dev.
1130  *
1131  * @note A driver must ask the bhnd bus to allocate PMU request state
1132  * via bhnd_alloc_pmu() before it can request PMU resources.
1133  *
1134  * @note Any outstanding PMU resource requests will be released upon calling
1135  * bhnd_reset_hw() or bhnd_suspend_hw().
1136  *
1137  * @param dev The requesting bhnd(4) device.
1138  * @param rsrc The core-specific external resource identifier.
1139  *
1140  * @retval 0 success
1141  * @retval ENODEV If the PMU does not support @p rsrc.
1142  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1143  */
1144 static inline int
1145 bhnd_request_ext_rsrc(device_t dev, u_int rsrc)
1146 {
1147 	return (BHND_BUS_REQUEST_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1148 }
1149 
1150 /**
1151  * Power down an external PMU-managed resource assigned to @p dev.
1152  *
1153  * A driver must ask the bhnd bus to allocate PMU request state
1154  * via bhnd_alloc_pmu() before it can request PMU resources.
1155  *
1156  * @param dev The requesting bhnd(4) device.
1157  * @param rsrc The core-specific external resource identifier.
1158  *
1159  * @retval 0 success
1160  * @retval ENODEV If the PMU does not support @p rsrc.
1161  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1162  */
1163 static inline int
1164 bhnd_release_ext_rsrc(device_t dev, u_int rsrc)
1165 {
1166 	return (BHND_BUS_RELEASE_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1167 }
1168 
1169 /**
1170  * Read @p width bytes at @p offset from the bus-specific agent/config
1171  * space of @p dev.
1172  *
1173  * @param dev The bhnd device for which @p offset should be read.
1174  * @param offset The offset to be read.
1175  * @param[out] value On success, the will be set to the @p width value read
1176  * at @p offset.
1177  * @param width The size of the access. Must be 1, 2 or 4 bytes.
1178  *
1179  * The exact behavior of this method is bus-specific. In the case of
1180  * bcma(4), this method provides access to the first agent port of @p child.
1181  *
1182  * @note Device drivers should only use this API for functionality
1183  * that is not available via another bhnd(4) function.
1184  *
1185  * @retval 0 success
1186  * @retval EINVAL If @p child is not a direct child of @p dev.
1187  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
1188  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
1189  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
1190  * the mapped agent/config space  for @p child.
1191  */
1192 static inline uint32_t
1193 bhnd_read_config(device_t dev, bus_size_t offset, void *value, u_int width)
1194 {
1195 	return (BHND_BUS_READ_CONFIG(device_get_parent(dev), dev, offset,
1196 	    value, width));
1197 }
1198 
1199 /**
1200  * Write @p width bytes at @p offset to the bus-specific agent/config
1201  * space of @p dev.
1202  *
1203  * @param dev The bhnd device for which @p offset should be read.
1204  * @param offset The offset to be written.
1205  * @param value A pointer to the value to be written.
1206  * @param width The size of @p value. Must be 1, 2 or 4 bytes.
1207  *
1208  * The exact behavior of this method is bus-specific. In the case of
1209  * bcma(4), this method provides access to the first agent port of @p child.
1210  *
1211  * @note Device drivers should only use this API for functionality
1212  * that is not available via another bhnd(4) function.
1213  *
1214  * @retval 0 success
1215  * @retval EINVAL If @p child is not a direct child of @p dev.
1216  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
1217  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
1218  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
1219  * the mapped agent/config space  for @p child.
1220  */
1221 static inline int
1222 bhnd_write_config(device_t dev, bus_size_t offset, const void *value,
1223     u_int width)
1224 {
1225 	return (BHND_BUS_WRITE_CONFIG(device_get_parent(dev), dev, offset,
1226 	    value, width));
1227 }
1228 
1229 /**
1230  * Read an NVRAM variable, coerced to the requested @p type.
1231  *
1232  * @param 		dev	A bhnd bus child device.
1233  * @param		name	The NVRAM variable name.
1234  * @param[out]		buf	A buffer large enough to hold @p len bytes. On
1235  *				success, the requested value will be written to
1236  *				this buffer. This argment may be NULL if
1237  *				the value is not desired.
1238  * @param[in,out]	len	The maximum capacity of @p buf. On success,
1239  *				will be set to the actual size of the requested
1240  *				value.
1241  * @param		type	The desired data representation to be written
1242  *				to @p buf.
1243  *
1244  * @retval 0		success
1245  * @retval ENOENT	The requested variable was not found.
1246  * @retval ENODEV	No valid NVRAM source could be found.
1247  * @retval ENOMEM	If a buffer of @p size is too small to hold the
1248  *			requested value.
1249  * @retval EOPNOTSUPP	If the value cannot be coerced to @p type.
1250  * @retval ERANGE	If value coercion would overflow @p type.
1251  * @retval non-zero	If reading @p name otherwise fails, a regular unix
1252  *			error code will be returned.
1253  */
1254 static inline int
1255 bhnd_nvram_getvar(device_t dev, const char *name, void *buf, size_t *len,
1256      bhnd_nvram_type type)
1257 {
1258 	return (BHND_BUS_GET_NVRAM_VAR(device_get_parent(dev), dev, name, buf,
1259 	    len, type));
1260 }
1261 
1262 /**
1263  * Allocate a resource from a device's parent bhnd(4) bus.
1264  *
1265  * @param dev The device requesting resource ownership.
1266  * @param type The type of resource to allocate. This may be any type supported
1267  * by the standard bus APIs.
1268  * @param rid The bus-specific handle identifying the resource being allocated.
1269  * @param start The start address of the resource.
1270  * @param end The end address of the resource.
1271  * @param count The size of the resource.
1272  * @param flags The flags for the resource to be allocated. These may be any
1273  * values supported by the standard bus APIs.
1274  *
1275  * To request the resource's default addresses, pass @p start and
1276  * @p end values of @c 0 and @c ~0, respectively, and
1277  * a @p count of @c 1.
1278  *
1279  * @retval NULL The resource could not be allocated.
1280  * @retval resource The allocated resource.
1281  */
1282 static inline struct bhnd_resource *
1283 bhnd_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
1284     rman_res_t end, rman_res_t count, u_int flags)
1285 {
1286 	return BHND_BUS_ALLOC_RESOURCE(device_get_parent(dev), dev, type, rid,
1287 	    start, end, count, flags);
1288 }
1289 
1290 
1291 /**
1292  * Allocate a resource from a device's parent bhnd(4) bus, using the
1293  * resource's default start, end, and count values.
1294  *
1295  * @param dev The device requesting resource ownership.
1296  * @param type The type of resource to allocate. This may be any type supported
1297  * by the standard bus APIs.
1298  * @param rid The bus-specific handle identifying the resource being allocated.
1299  * @param flags The flags for the resource to be allocated. These may be any
1300  * values supported by the standard bus APIs.
1301  *
1302  * @retval NULL The resource could not be allocated.
1303  * @retval resource The allocated resource.
1304  */
1305 static inline struct bhnd_resource *
1306 bhnd_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
1307 {
1308 	return bhnd_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
1309 }
1310 
1311 /**
1312  * Activate a previously allocated bhnd resource.
1313  *
1314  * @param dev The device holding ownership of the allocated resource.
1315  * @param type The type of the resource.
1316  * @param rid The bus-specific handle identifying the resource.
1317  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1318  * BHND_BUS_ALLOC_RESOURCE.
1319  *
1320  * @retval 0 success
1321  * @retval non-zero an error occurred while activating the resource.
1322  */
1323 static inline int
1324 bhnd_activate_resource(device_t dev, int type, int rid,
1325    struct bhnd_resource *r)
1326 {
1327 	return BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
1328 	    rid, r);
1329 }
1330 
1331 /**
1332  * Deactivate a previously activated bhnd resource.
1333  *
1334  * @param dev The device holding ownership of the activated resource.
1335  * @param type The type of the resource.
1336  * @param rid The bus-specific handle identifying the resource.
1337  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1338  * BHND_BUS_ALLOC_RESOURCE.
1339  *
1340  * @retval 0 success
1341  * @retval non-zero an error occurred while activating the resource.
1342  */
1343 static inline int
1344 bhnd_deactivate_resource(device_t dev, int type, int rid,
1345    struct bhnd_resource *r)
1346 {
1347 	return BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
1348 	    rid, r);
1349 }
1350 
1351 /**
1352  * Free a resource allocated by bhnd_alloc_resource().
1353  *
1354  * @param dev The device holding ownership of the resource.
1355  * @param type The type of the resource.
1356  * @param rid The bus-specific handle identifying the resource.
1357  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1358  * BHND_ALLOC_RESOURCE.
1359  *
1360  * @retval 0 success
1361  * @retval non-zero an error occurred while activating the resource.
1362  */
1363 static inline int
1364 bhnd_release_resource(device_t dev, int type, int rid,
1365    struct bhnd_resource *r)
1366 {
1367 	return BHND_BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
1368 	    rid, r);
1369 }
1370 
1371 /**
1372  * Return true if @p region_num is a valid region on @p port_num of
1373  * @p type attached to @p dev.
1374  *
1375  * @param dev A bhnd bus child device.
1376  * @param type The port type being queried.
1377  * @param port_num The port number being queried.
1378  * @param region_num The region number being queried.
1379  */
1380 static inline bool
1381 bhnd_is_region_valid(device_t dev, bhnd_port_type type, u_int port_num,
1382     u_int region_num)
1383 {
1384 	return (BHND_BUS_IS_REGION_VALID(device_get_parent(dev), dev, type,
1385 	    port_num, region_num));
1386 }
1387 
1388 /**
1389  * Return the number of ports of type @p type attached to @p def.
1390  *
1391  * @param dev A bhnd bus child device.
1392  * @param type The port type being queried.
1393  */
1394 static inline u_int
1395 bhnd_get_port_count(device_t dev, bhnd_port_type type) {
1396 	return (BHND_BUS_GET_PORT_COUNT(device_get_parent(dev), dev, type));
1397 }
1398 
1399 /**
1400  * Return the number of memory regions mapped to @p child @p port of
1401  * type @p type.
1402  *
1403  * @param dev A bhnd bus child device.
1404  * @param port The port number being queried.
1405  * @param type The port type being queried.
1406  */
1407 static inline u_int
1408 bhnd_get_region_count(device_t dev, bhnd_port_type type, u_int port) {
1409 	return (BHND_BUS_GET_REGION_COUNT(device_get_parent(dev), dev, type,
1410 	    port));
1411 }
1412 
1413 /**
1414  * Return the resource-ID for a memory region on the given device port.
1415  *
1416  * @param dev A bhnd bus child device.
1417  * @param type The port type.
1418  * @param port The port identifier.
1419  * @param region The identifier of the memory region on @p port.
1420  *
1421  * @retval int The RID for the given @p port and @p region on @p device.
1422  * @retval -1 No such port/region found.
1423  */
1424 static inline int
1425 bhnd_get_port_rid(device_t dev, bhnd_port_type type, u_int port, u_int region)
1426 {
1427 	return BHND_BUS_GET_PORT_RID(device_get_parent(dev), dev, type, port,
1428 	    region);
1429 }
1430 
1431 /**
1432  * Decode a port / region pair on @p dev defined by @p rid.
1433  *
1434  * @param dev A bhnd bus child device.
1435  * @param type The resource type.
1436  * @param rid The resource identifier.
1437  * @param[out] port_type The decoded port type.
1438  * @param[out] port The decoded port identifier.
1439  * @param[out] region The decoded region identifier.
1440  *
1441  * @retval 0 success
1442  * @retval non-zero No matching port/region found.
1443  */
1444 static inline int
1445 bhnd_decode_port_rid(device_t dev, int type, int rid, bhnd_port_type *port_type,
1446     u_int *port, u_int *region)
1447 {
1448 	return BHND_BUS_DECODE_PORT_RID(device_get_parent(dev), dev, type, rid,
1449 	    port_type, port, region);
1450 }
1451 
1452 /**
1453  * Get the address and size of @p region on @p port.
1454  *
1455  * @param dev A bhnd bus child device.
1456  * @param port_type The port type.
1457  * @param port The port identifier.
1458  * @param region The identifier of the memory region on @p port.
1459  * @param[out] region_addr The region's base address.
1460  * @param[out] region_size The region's size.
1461  *
1462  * @retval 0 success
1463  * @retval non-zero No matching port/region found.
1464  */
1465 static inline int
1466 bhnd_get_region_addr(device_t dev, bhnd_port_type port_type, u_int port,
1467     u_int region, bhnd_addr_t *region_addr, bhnd_size_t *region_size)
1468 {
1469 	return BHND_BUS_GET_REGION_ADDR(device_get_parent(dev), dev, port_type,
1470 	    port, region, region_addr, region_size);
1471 }
1472 
1473 /*
1474  * bhnd bus-level equivalents of the bus_(read|write|set|barrier|...)
1475  * macros (compatible with bhnd_resource).
1476  *
1477  * Generated with bhnd/tools/bus_macro.sh
1478  */
1479 #define bhnd_bus_barrier(r, o, l, f) \
1480     ((r)->direct) ? \
1481 	bus_barrier((r)->res, (o), (l), (f)) : \
1482 	BHND_BUS_BARRIER( \
1483 	    device_get_parent(rman_get_device((r)->res)),	\
1484 	    rman_get_device((r)->res), (r), (o), (l), (f))
1485 #define bhnd_bus_read_1(r, o) \
1486     ((r)->direct) ? \
1487 	bus_read_1((r)->res, (o)) : \
1488 	BHND_BUS_READ_1( \
1489 	    device_get_parent(rman_get_device((r)->res)),	\
1490 	    rman_get_device((r)->res), (r), (o))
1491 #define bhnd_bus_read_multi_1(r, o, d, c) \
1492     ((r)->direct) ? \
1493 	bus_read_multi_1((r)->res, (o), (d), (c)) : \
1494 	BHND_BUS_READ_MULTI_1( \
1495 	    device_get_parent(rman_get_device((r)->res)),	\
1496 	    rman_get_device((r)->res), (r), (o), (d), (c))
1497 #define bhnd_bus_read_region_1(r, o, d, c) \
1498     ((r)->direct) ? \
1499 	bus_read_region_1((r)->res, (o), (d), (c)) : \
1500 	BHND_BUS_READ_REGION_1( \
1501 	    device_get_parent(rman_get_device((r)->res)),	\
1502 	    rman_get_device((r)->res), (r), (o), (d), (c))
1503 #define bhnd_bus_write_1(r, o, v) \
1504     ((r)->direct) ? \
1505 	bus_write_1((r)->res, (o), (v)) : \
1506 	BHND_BUS_WRITE_1( \
1507 	    device_get_parent(rman_get_device((r)->res)),	\
1508 	    rman_get_device((r)->res), (r), (o), (v))
1509 #define bhnd_bus_write_multi_1(r, o, d, c) \
1510     ((r)->direct) ? \
1511 	bus_write_multi_1((r)->res, (o), (d), (c)) : \
1512 	BHND_BUS_WRITE_MULTI_1( \
1513 	    device_get_parent(rman_get_device((r)->res)),	\
1514 	    rman_get_device((r)->res), (r), (o), (d), (c))
1515 #define bhnd_bus_write_region_1(r, o, d, c) \
1516     ((r)->direct) ? \
1517 	bus_write_region_1((r)->res, (o), (d), (c)) : \
1518 	BHND_BUS_WRITE_REGION_1( \
1519 	    device_get_parent(rman_get_device((r)->res)),	\
1520 	    rman_get_device((r)->res), (r), (o), (d), (c))
1521 #define bhnd_bus_read_stream_1(r, o) \
1522     ((r)->direct) ? \
1523 	bus_read_stream_1((r)->res, (o)) : \
1524 	BHND_BUS_READ_STREAM_1( \
1525 	    device_get_parent(rman_get_device((r)->res)),	\
1526 	    rman_get_device((r)->res), (r), (o))
1527 #define bhnd_bus_read_multi_stream_1(r, o, d, c) \
1528     ((r)->direct) ? \
1529 	bus_read_multi_stream_1((r)->res, (o), (d), (c)) : \
1530 	BHND_BUS_READ_MULTI_STREAM_1( \
1531 	    device_get_parent(rman_get_device((r)->res)),	\
1532 	    rman_get_device((r)->res), (r), (o), (d), (c))
1533 #define bhnd_bus_read_region_stream_1(r, o, d, c) \
1534     ((r)->direct) ? \
1535 	bus_read_region_stream_1((r)->res, (o), (d), (c)) : \
1536 	BHND_BUS_READ_REGION_STREAM_1( \
1537 	    device_get_parent(rman_get_device((r)->res)),	\
1538 	    rman_get_device((r)->res), (r), (o), (d), (c))
1539 #define bhnd_bus_write_stream_1(r, o, v) \
1540     ((r)->direct) ? \
1541 	bus_write_stream_1((r)->res, (o), (v)) : \
1542 	BHND_BUS_WRITE_STREAM_1( \
1543 	    device_get_parent(rman_get_device((r)->res)),	\
1544 	    rman_get_device((r)->res), (r), (o), (v))
1545 #define bhnd_bus_write_multi_stream_1(r, o, d, c) \
1546     ((r)->direct) ? \
1547 	bus_write_multi_stream_1((r)->res, (o), (d), (c)) : \
1548 	BHND_BUS_WRITE_MULTI_STREAM_1( \
1549 	    device_get_parent(rman_get_device((r)->res)),	\
1550 	    rman_get_device((r)->res), (r), (o), (d), (c))
1551 #define bhnd_bus_write_region_stream_1(r, o, d, c) \
1552     ((r)->direct) ? \
1553 	bus_write_region_stream_1((r)->res, (o), (d), (c)) : \
1554 	BHND_BUS_WRITE_REGION_STREAM_1( \
1555 	    device_get_parent(rman_get_device((r)->res)),	\
1556 	    rman_get_device((r)->res), (r), (o), (d), (c))
1557 #define bhnd_bus_set_multi_1(r, o, v, c) \
1558     ((r)->direct) ? \
1559 	bus_set_multi_1((r)->res, (o), (v), (c)) : \
1560 	BHND_BUS_SET_MULTI_1( \
1561 	    device_get_parent(rman_get_device((r)->res)),	\
1562 	    rman_get_device((r)->res), (r), (o), (v), (c))
1563 #define bhnd_bus_set_region_1(r, o, v, c) \
1564     ((r)->direct) ? \
1565 	bus_set_region_1((r)->res, (o), (v), (c)) : \
1566 	BHND_BUS_SET_REGION_1( \
1567 	    device_get_parent(rman_get_device((r)->res)),	\
1568 	    rman_get_device((r)->res), (r), (o), (v), (c))
1569 #define bhnd_bus_read_2(r, o) \
1570     ((r)->direct) ? \
1571 	bus_read_2((r)->res, (o)) : \
1572 	BHND_BUS_READ_2( \
1573 	    device_get_parent(rman_get_device((r)->res)),	\
1574 	    rman_get_device((r)->res), (r), (o))
1575 #define bhnd_bus_read_multi_2(r, o, d, c) \
1576     ((r)->direct) ? \
1577 	bus_read_multi_2((r)->res, (o), (d), (c)) : \
1578 	BHND_BUS_READ_MULTI_2( \
1579 	    device_get_parent(rman_get_device((r)->res)),	\
1580 	    rman_get_device((r)->res), (r), (o), (d), (c))
1581 #define bhnd_bus_read_region_2(r, o, d, c) \
1582     ((r)->direct) ? \
1583 	bus_read_region_2((r)->res, (o), (d), (c)) : \
1584 	BHND_BUS_READ_REGION_2( \
1585 	    device_get_parent(rman_get_device((r)->res)),	\
1586 	    rman_get_device((r)->res), (r), (o), (d), (c))
1587 #define bhnd_bus_write_2(r, o, v) \
1588     ((r)->direct) ? \
1589 	bus_write_2((r)->res, (o), (v)) : \
1590 	BHND_BUS_WRITE_2( \
1591 	    device_get_parent(rman_get_device((r)->res)),	\
1592 	    rman_get_device((r)->res), (r), (o), (v))
1593 #define bhnd_bus_write_multi_2(r, o, d, c) \
1594     ((r)->direct) ? \
1595 	bus_write_multi_2((r)->res, (o), (d), (c)) : \
1596 	BHND_BUS_WRITE_MULTI_2( \
1597 	    device_get_parent(rman_get_device((r)->res)),	\
1598 	    rman_get_device((r)->res), (r), (o), (d), (c))
1599 #define bhnd_bus_write_region_2(r, o, d, c) \
1600     ((r)->direct) ? \
1601 	bus_write_region_2((r)->res, (o), (d), (c)) : \
1602 	BHND_BUS_WRITE_REGION_2( \
1603 	    device_get_parent(rman_get_device((r)->res)),	\
1604 	    rman_get_device((r)->res), (r), (o), (d), (c))
1605 #define bhnd_bus_read_stream_2(r, o) \
1606     ((r)->direct) ? \
1607 	bus_read_stream_2((r)->res, (o)) : \
1608 	BHND_BUS_READ_STREAM_2( \
1609 	    device_get_parent(rman_get_device((r)->res)),	\
1610 	    rman_get_device((r)->res), (r), (o))
1611 #define bhnd_bus_read_multi_stream_2(r, o, d, c) \
1612     ((r)->direct) ? \
1613 	bus_read_multi_stream_2((r)->res, (o), (d), (c)) : \
1614 	BHND_BUS_READ_MULTI_STREAM_2( \
1615 	    device_get_parent(rman_get_device((r)->res)),	\
1616 	    rman_get_device((r)->res), (r), (o), (d), (c))
1617 #define bhnd_bus_read_region_stream_2(r, o, d, c) \
1618     ((r)->direct) ? \
1619 	bus_read_region_stream_2((r)->res, (o), (d), (c)) : \
1620 	BHND_BUS_READ_REGION_STREAM_2( \
1621 	    device_get_parent(rman_get_device((r)->res)),	\
1622 	    rman_get_device((r)->res), (r), (o), (d), (c))
1623 #define bhnd_bus_write_stream_2(r, o, v) \
1624     ((r)->direct) ? \
1625 	bus_write_stream_2((r)->res, (o), (v)) : \
1626 	BHND_BUS_WRITE_STREAM_2( \
1627 	    device_get_parent(rman_get_device((r)->res)),	\
1628 	    rman_get_device((r)->res), (r), (o), (v))
1629 #define bhnd_bus_write_multi_stream_2(r, o, d, c) \
1630     ((r)->direct) ? \
1631 	bus_write_multi_stream_2((r)->res, (o), (d), (c)) : \
1632 	BHND_BUS_WRITE_MULTI_STREAM_2( \
1633 	    device_get_parent(rman_get_device((r)->res)),	\
1634 	    rman_get_device((r)->res), (r), (o), (d), (c))
1635 #define bhnd_bus_write_region_stream_2(r, o, d, c) \
1636     ((r)->direct) ? \
1637 	bus_write_region_stream_2((r)->res, (o), (d), (c)) : \
1638 	BHND_BUS_WRITE_REGION_STREAM_2( \
1639 	    device_get_parent(rman_get_device((r)->res)),	\
1640 	    rman_get_device((r)->res), (r), (o), (d), (c))
1641 #define bhnd_bus_set_multi_2(r, o, v, c) \
1642     ((r)->direct) ? \
1643 	bus_set_multi_2((r)->res, (o), (v), (c)) : \
1644 	BHND_BUS_SET_MULTI_2( \
1645 	    device_get_parent(rman_get_device((r)->res)),	\
1646 	    rman_get_device((r)->res), (r), (o), (v), (c))
1647 #define bhnd_bus_set_region_2(r, o, v, c) \
1648     ((r)->direct) ? \
1649 	bus_set_region_2((r)->res, (o), (v), (c)) : \
1650 	BHND_BUS_SET_REGION_2( \
1651 	    device_get_parent(rman_get_device((r)->res)),	\
1652 	    rman_get_device((r)->res), (r), (o), (v), (c))
1653 #define bhnd_bus_read_4(r, o) \
1654     ((r)->direct) ? \
1655 	bus_read_4((r)->res, (o)) : \
1656 	BHND_BUS_READ_4( \
1657 	    device_get_parent(rman_get_device((r)->res)),	\
1658 	    rman_get_device((r)->res), (r), (o))
1659 #define bhnd_bus_read_multi_4(r, o, d, c) \
1660     ((r)->direct) ? \
1661 	bus_read_multi_4((r)->res, (o), (d), (c)) : \
1662 	BHND_BUS_READ_MULTI_4( \
1663 	    device_get_parent(rman_get_device((r)->res)),	\
1664 	    rman_get_device((r)->res), (r), (o), (d), (c))
1665 #define bhnd_bus_read_region_4(r, o, d, c) \
1666     ((r)->direct) ? \
1667 	bus_read_region_4((r)->res, (o), (d), (c)) : \
1668 	BHND_BUS_READ_REGION_4( \
1669 	    device_get_parent(rman_get_device((r)->res)),	\
1670 	    rman_get_device((r)->res), (r), (o), (d), (c))
1671 #define bhnd_bus_write_4(r, o, v) \
1672     ((r)->direct) ? \
1673 	bus_write_4((r)->res, (o), (v)) : \
1674 	BHND_BUS_WRITE_4( \
1675 	    device_get_parent(rman_get_device((r)->res)),	\
1676 	    rman_get_device((r)->res), (r), (o), (v))
1677 #define bhnd_bus_write_multi_4(r, o, d, c) \
1678     ((r)->direct) ? \
1679 	bus_write_multi_4((r)->res, (o), (d), (c)) : \
1680 	BHND_BUS_WRITE_MULTI_4( \
1681 	    device_get_parent(rman_get_device((r)->res)),	\
1682 	    rman_get_device((r)->res), (r), (o), (d), (c))
1683 #define bhnd_bus_write_region_4(r, o, d, c) \
1684     ((r)->direct) ? \
1685 	bus_write_region_4((r)->res, (o), (d), (c)) : \
1686 	BHND_BUS_WRITE_REGION_4( \
1687 	    device_get_parent(rman_get_device((r)->res)),	\
1688 	    rman_get_device((r)->res), (r), (o), (d), (c))
1689 #define bhnd_bus_read_stream_4(r, o) \
1690     ((r)->direct) ? \
1691 	bus_read_stream_4((r)->res, (o)) : \
1692 	BHND_BUS_READ_STREAM_4( \
1693 	    device_get_parent(rman_get_device((r)->res)),	\
1694 	    rman_get_device((r)->res), (r), (o))
1695 #define bhnd_bus_read_multi_stream_4(r, o, d, c) \
1696     ((r)->direct) ? \
1697 	bus_read_multi_stream_4((r)->res, (o), (d), (c)) : \
1698 	BHND_BUS_READ_MULTI_STREAM_4( \
1699 	    device_get_parent(rman_get_device((r)->res)),	\
1700 	    rman_get_device((r)->res), (r), (o), (d), (c))
1701 #define bhnd_bus_read_region_stream_4(r, o, d, c) \
1702     ((r)->direct) ? \
1703 	bus_read_region_stream_4((r)->res, (o), (d), (c)) : \
1704 	BHND_BUS_READ_REGION_STREAM_4( \
1705 	    device_get_parent(rman_get_device((r)->res)),	\
1706 	    rman_get_device((r)->res), (r), (o), (d), (c))
1707 #define bhnd_bus_write_stream_4(r, o, v) \
1708     ((r)->direct) ? \
1709 	bus_write_stream_4((r)->res, (o), (v)) : \
1710 	BHND_BUS_WRITE_STREAM_4( \
1711 	    device_get_parent(rman_get_device((r)->res)),	\
1712 	    rman_get_device((r)->res), (r), (o), (v))
1713 #define bhnd_bus_write_multi_stream_4(r, o, d, c) \
1714     ((r)->direct) ? \
1715 	bus_write_multi_stream_4((r)->res, (o), (d), (c)) : \
1716 	BHND_BUS_WRITE_MULTI_STREAM_4( \
1717 	    device_get_parent(rman_get_device((r)->res)),	\
1718 	    rman_get_device((r)->res), (r), (o), (d), (c))
1719 #define bhnd_bus_write_region_stream_4(r, o, d, c) \
1720     ((r)->direct) ? \
1721 	bus_write_region_stream_4((r)->res, (o), (d), (c)) : \
1722 	BHND_BUS_WRITE_REGION_STREAM_4( \
1723 	    device_get_parent(rman_get_device((r)->res)),	\
1724 	    rman_get_device((r)->res), (r), (o), (d), (c))
1725 #define bhnd_bus_set_multi_4(r, o, v, c) \
1726     ((r)->direct) ? \
1727 	bus_set_multi_4((r)->res, (o), (v), (c)) : \
1728 	BHND_BUS_SET_MULTI_4( \
1729 	    device_get_parent(rman_get_device((r)->res)),	\
1730 	    rman_get_device((r)->res), (r), (o), (v), (c))
1731 #define bhnd_bus_set_region_4(r, o, v, c) \
1732     ((r)->direct) ? \
1733 	bus_set_region_4((r)->res, (o), (v), (c)) : \
1734 	BHND_BUS_SET_REGION_4( \
1735 	    device_get_parent(rman_get_device((r)->res)),	\
1736 	    rman_get_device((r)->res), (r), (o), (v), (c))
1737 
1738 #endif /* _BHND_BHND_H_ */
1739