xref: /freebsd/sys/dev/bhnd/bhnd.h (revision 8e3e3a7ae841ccf6f6ac30a2eeab85df5d7f04bc)
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 low-power RESET state with
822  * the @p reset_ioctl I/O control flags set, and then bring the hardware out of
823  * RESET with the @p ioctl I/O control flags set.
824  *
825  * Any clock or resource PMU requests previously made by @p child will be
826  * invalidated.
827  *
828  * @param dev The device to be reset.
829  * @param ioctl Device-specific I/O control flags to be set when bringing
830  * the core out of its RESET state (see BHND_IOCTL_*).
831  * @param reset_ioctl Device-specific I/O control flags to be set when placing
832  * the core into its RESET state.
833  *
834  * @retval 0 success
835  * @retval non-zero error
836  */
837 static inline int
838 bhnd_reset_hw(device_t dev, uint16_t ioctl, uint16_t reset_ioctl)
839 {
840 	return (BHND_BUS_RESET_HW(device_get_parent(dev), dev, ioctl,
841 	    reset_ioctl));
842 }
843 
844 /**
845  * Suspend @p child's hardware in a low-power reset state.
846  *
847  * Any clock or resource PMU requests previously made by @p dev will be
848  * invalidated.
849  *
850  * The hardware may be brought out of reset via bhnd_reset_hw().
851  *
852  * @param dev The device to be suspended.
853  *
854  * @retval 0 success
855  * @retval non-zero error
856  */
857 static inline int
858 bhnd_suspend_hw(device_t dev, uint16_t ioctl)
859 {
860 	return (BHND_BUS_SUSPEND_HW(device_get_parent(dev), dev, ioctl));
861 }
862 
863 /**
864  * Return the BHND attachment type of the parent bhnd bus.
865  *
866  * @param dev A bhnd bus child device.
867  *
868  * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter,
869  * such as a WiFi chipset.
870  * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock,
871  * CPU, etc) to a directly attached native host.
872  */
873 static inline bhnd_attach_type
874 bhnd_get_attach_type (device_t dev) {
875 	return (BHND_BUS_GET_ATTACH_TYPE(device_get_parent(dev), dev));
876 }
877 
878 /**
879  * Find the best available DMA address translation capable of mapping a
880  * physical host address to a BHND DMA device address of @p width with
881  * @p flags.
882  *
883  * @param dev A bhnd bus child device.
884  * @param width The address width within which the translation window must
885  * reside (see BHND_DMA_ADDR_*).
886  * @param flags Required translation flags (see BHND_DMA_TRANSLATION_*).
887  * @param[out] dmat On success, will be populated with a DMA tag specifying the
888  * @p translation DMA address restrictions. This argment may be NULL if the DMA
889  * tag is not desired.
890  * the set of valid host DMA addresses reachable via @p translation.
891  * @param[out] translation On success, will be populated with a DMA address
892  * translation descriptor for @p child. This argment may be NULL if the
893  * descriptor is not desired.
894  *
895  * @retval 0 success
896  * @retval ENODEV If DMA is not supported.
897  * @retval ENOENT If no DMA translation matching @p width and @p flags is
898  * available.
899  * @retval non-zero If determining the DMA address translation for @p child
900  * otherwise fails, a regular unix error code will be returned.
901  */
902 static inline int
903 bhnd_get_dma_translation(device_t dev, u_int width, uint32_t flags,
904     bus_dma_tag_t *dmat, struct bhnd_dma_translation *translation)
905 {
906 	return (BHND_BUS_GET_DMA_TRANSLATION(device_get_parent(dev), dev, width,
907 	    flags, dmat, translation));
908 }
909 
910 /**
911  * Attempt to read the BHND board identification from the bhnd bus.
912  *
913  * This relies on NVRAM access, and will fail if a valid NVRAM device cannot
914  * be found, or is not yet attached.
915  *
916  * @param dev The bhnd device requesting board info.
917  * @param[out] info On success, will be populated with the bhnd(4) device's
918  * board information.
919  *
920  * @retval 0 success
921  * @retval ENODEV	No valid NVRAM source could be found.
922  * @retval non-zero	If reading @p name otherwise fails, a regular unix
923  *			error code will be returned.
924  */
925 static inline int
926 bhnd_read_board_info(device_t dev, struct bhnd_board_info *info)
927 {
928 	return (BHND_BUS_READ_BOARD_INFO(device_get_parent(dev), dev, info));
929 }
930 
931 /**
932  * Return the number of interrupt lines assigned to @p dev.
933  *
934  * @param dev A bhnd bus child device.
935  */
936 static inline u_int
937 bhnd_get_intr_count(device_t dev)
938 {
939 	return (BHND_BUS_GET_INTR_COUNT(device_get_parent(dev), dev));
940 }
941 
942 /**
943  * Get the backplane interrupt vector of the @p intr line attached to @p dev.
944  *
945  * @param dev A bhnd bus child device.
946  * @param intr The index of the interrupt line being queried.
947  * @param[out] ivec On success, the assigned hardware interrupt vector will be
948  * written to this pointer.
949  *
950  * On bcma(4) devices, this returns the OOB bus line assigned to the
951  * interrupt.
952  *
953  * On siba(4) devices, this returns the target OCP slave flag number assigned
954  * to the interrupt.
955  *
956  * @retval 0		success
957  * @retval ENXIO	If @p intr exceeds the number of interrupt lines
958  *			assigned to @p child.
959  */
960 static inline int
961 bhnd_get_intr_ivec(device_t dev, u_int intr, u_int *ivec)
962 {
963 	return (BHND_BUS_GET_INTR_IVEC(device_get_parent(dev), dev, intr,
964 	    ivec));
965 }
966 
967 /**
968  * Map the given @p intr to an IRQ number; until unmapped, this IRQ may be used
969  * to allocate a resource of type SYS_RES_IRQ.
970  *
971  * On success, the caller assumes ownership of the interrupt mapping, and
972  * is responsible for releasing the mapping via bhnd_unmap_intr().
973  *
974  * @param dev The requesting device.
975  * @param intr The interrupt being mapped.
976  * @param[out] irq On success, the bus interrupt value mapped for @p intr.
977  *
978  * @retval 0		If an interrupt was assigned.
979  * @retval non-zero	If mapping an interrupt otherwise fails, a regular
980  *			unix error code will be returned.
981  */
982 static inline int
983 bhnd_map_intr(device_t dev, u_int intr, rman_res_t *irq)
984 {
985 	return (BHND_BUS_MAP_INTR(device_get_parent(dev), dev, intr, irq));
986 }
987 
988 /**
989  * Unmap an bus interrupt previously mapped via bhnd_map_intr().
990  *
991  * @param dev The requesting device.
992  * @param irq The interrupt value being unmapped.
993  */
994 static inline void
995 bhnd_unmap_intr(device_t dev, rman_res_t irq)
996 {
997 	return (BHND_BUS_UNMAP_INTR(device_get_parent(dev), dev, irq));
998 }
999 
1000 /**
1001  * Allocate and enable per-core PMU request handling for @p child.
1002  *
1003  * The region containing the core's PMU register block (if any) must be
1004  * allocated via bus_alloc_resource(9) (or bhnd_alloc_resource) before
1005  * calling bhnd_alloc_pmu(), and must not be released until after
1006  * calling bhnd_release_pmu().
1007  *
1008  * @param dev The requesting bhnd device.
1009  *
1010  * @retval 0           success
1011  * @retval non-zero    If allocating PMU request state otherwise fails, a
1012  *                     regular unix error code will be returned.
1013  */
1014 static inline int
1015 bhnd_alloc_pmu(device_t dev)
1016 {
1017 	return (BHND_BUS_ALLOC_PMU(device_get_parent(dev), dev));
1018 }
1019 
1020 /**
1021  * Release any per-core PMU resources allocated for @p child. Any outstanding
1022  * PMU requests are are discarded.
1023  *
1024  * @param dev The requesting bhnd device.
1025  *
1026  * @retval 0           success
1027  * @retval non-zero    If releasing PMU request state otherwise fails, a
1028  *                     regular unix error code will be returned, and
1029  *                     the core state will be left unmodified.
1030  */
1031 static inline int
1032 bhnd_release_pmu(device_t dev)
1033 {
1034 	return (BHND_BUS_RELEASE_PMU(device_get_parent(dev), dev));
1035 }
1036 
1037 /**
1038  * Return the transition latency required for @p clock in microseconds, if
1039  * known.
1040  *
1041  * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
1042  * 'fastpwrup_dly' value.
1043  *
1044  * @note A driver must ask the bhnd bus to allocate PMU request state
1045  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
1046  *
1047  * @param dev The requesting bhnd device.
1048  * @param clock	The clock to be queried for transition latency.
1049  * @param[out] latency On success, the transition latency of @p clock in
1050  * microseconds.
1051  *
1052  * @retval 0		success
1053  * @retval ENODEV	If the transition latency for @p clock is not available.
1054  */
1055 static inline int
1056 bhnd_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
1057 {
1058 	return (BHND_BUS_GET_CLOCK_LATENCY(device_get_parent(dev), dev, clock,
1059 	    latency));
1060 }
1061 
1062 /**
1063  * Return the frequency for @p clock in Hz, if known.
1064  *
1065  * @param dev The requesting bhnd device.
1066  * @param clock The clock to be queried.
1067  * @param[out] freq On success, the frequency of @p clock in Hz.
1068  *
1069  * @note A driver must ask the bhnd bus to allocate PMU request state
1070  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
1071  *
1072  * @retval 0		success
1073  * @retval ENODEV	If the frequency for @p clock is not available.
1074  */
1075 static inline int
1076 bhnd_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
1077 {
1078 	return (BHND_BUS_GET_CLOCK_FREQ(device_get_parent(dev), dev, clock,
1079 	    freq));
1080 }
1081 
1082 /**
1083  * Request that @p clock (or faster) be routed to @p dev.
1084  *
1085  * @note A driver must ask the bhnd bus to allocate clock request state
1086  * via bhnd_alloc_pmu() before it can request clock resources.
1087  *
1088  * @note Any outstanding PMU clock requests will be discarded upon calling
1089  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
1090  *
1091  * @param dev The bhnd(4) device to which @p clock should be routed.
1092  * @param clock The requested clock source.
1093  *
1094  * @retval 0 success
1095  * @retval ENODEV If an unsupported clock was requested.
1096  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable,
1097  */
1098 static inline int
1099 bhnd_request_clock(device_t dev, bhnd_clock clock)
1100 {
1101 	return (BHND_BUS_REQUEST_CLOCK(device_get_parent(dev), dev, clock));
1102 }
1103 
1104 /**
1105  * Request that @p clocks be powered on behalf of @p dev.
1106  *
1107  * This will power any clock sources (e.g. XTAL, PLL, etc) required for
1108  * @p clocks and wait until they are ready, discarding any previous
1109  * requests by @p dev.
1110  *
1111  * @note A driver must ask the bhnd bus to allocate clock request state
1112  * via bhnd_alloc_pmu() before it can request clock resources.
1113  *
1114  * @note Any outstanding PMU clock requests will be discarded upon calling
1115  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
1116  *
1117  * @param dev The requesting bhnd(4) device.
1118  * @param clocks The clock(s) to be enabled.
1119  *
1120  * @retval 0 success
1121  * @retval ENODEV If an unsupported clock was requested.
1122  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1123  */
1124 static inline int
1125 bhnd_enable_clocks(device_t dev, uint32_t clocks)
1126 {
1127 	return (BHND_BUS_ENABLE_CLOCKS(device_get_parent(dev), dev, clocks));
1128 }
1129 
1130 /**
1131  * Power up an external PMU-managed resource assigned to @p dev.
1132  *
1133  * @note A driver must ask the bhnd bus to allocate PMU request state
1134  * via bhnd_alloc_pmu() before it can request PMU resources.
1135  *
1136  * @note Any outstanding PMU resource requests will be released upon calling
1137  * bhnd_reset_hw() or bhnd_suspend_hw().
1138  *
1139  * @param dev The requesting bhnd(4) device.
1140  * @param rsrc The core-specific external resource identifier.
1141  *
1142  * @retval 0 success
1143  * @retval ENODEV If the PMU does not support @p rsrc.
1144  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1145  */
1146 static inline int
1147 bhnd_request_ext_rsrc(device_t dev, u_int rsrc)
1148 {
1149 	return (BHND_BUS_REQUEST_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1150 }
1151 
1152 /**
1153  * Power down an external PMU-managed resource assigned to @p dev.
1154  *
1155  * A driver must ask the bhnd bus to allocate PMU request state
1156  * via bhnd_alloc_pmu() before it can request PMU resources.
1157  *
1158  * @param dev The requesting bhnd(4) device.
1159  * @param rsrc The core-specific external resource identifier.
1160  *
1161  * @retval 0 success
1162  * @retval ENODEV If the PMU does not support @p rsrc.
1163  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1164  */
1165 static inline int
1166 bhnd_release_ext_rsrc(device_t dev, u_int rsrc)
1167 {
1168 	return (BHND_BUS_RELEASE_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1169 }
1170 
1171 /**
1172  * Read @p width bytes at @p offset from the bus-specific agent/config
1173  * space of @p dev.
1174  *
1175  * @param dev The bhnd device for which @p offset should be read.
1176  * @param offset The offset to be read.
1177  * @param[out] value On success, the will be set to the @p width value read
1178  * at @p offset.
1179  * @param width The size of the access. Must be 1, 2 or 4 bytes.
1180  *
1181  * The exact behavior of this method is bus-specific. In the case of
1182  * bcma(4), this method provides access to the first agent port of @p child.
1183  *
1184  * @note Device drivers should only use this API for functionality
1185  * that is not available via another bhnd(4) function.
1186  *
1187  * @retval 0 success
1188  * @retval EINVAL If @p child is not a direct child of @p dev.
1189  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
1190  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
1191  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
1192  * the mapped agent/config space  for @p child.
1193  */
1194 static inline uint32_t
1195 bhnd_read_config(device_t dev, bus_size_t offset, void *value, u_int width)
1196 {
1197 	return (BHND_BUS_READ_CONFIG(device_get_parent(dev), dev, offset,
1198 	    value, width));
1199 }
1200 
1201 /**
1202  * Write @p width bytes at @p offset to the bus-specific agent/config
1203  * space of @p dev.
1204  *
1205  * @param dev The bhnd device for which @p offset should be read.
1206  * @param offset The offset to be written.
1207  * @param value A pointer to the value to be written.
1208  * @param width The size of @p value. Must be 1, 2 or 4 bytes.
1209  *
1210  * The exact behavior of this method is bus-specific. In the case of
1211  * bcma(4), this method provides access to the first agent port of @p child.
1212  *
1213  * @note Device drivers should only use this API for functionality
1214  * that is not available via another bhnd(4) function.
1215  *
1216  * @retval 0 success
1217  * @retval EINVAL If @p child is not a direct child of @p dev.
1218  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
1219  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
1220  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
1221  * the mapped agent/config space  for @p child.
1222  */
1223 static inline int
1224 bhnd_write_config(device_t dev, bus_size_t offset, const void *value,
1225     u_int width)
1226 {
1227 	return (BHND_BUS_WRITE_CONFIG(device_get_parent(dev), dev, offset,
1228 	    value, width));
1229 }
1230 
1231 /**
1232  * Read an NVRAM variable, coerced to the requested @p type.
1233  *
1234  * @param 		dev	A bhnd bus child device.
1235  * @param		name	The NVRAM variable name.
1236  * @param[out]		buf	A buffer large enough to hold @p len bytes. On
1237  *				success, the requested value will be written to
1238  *				this buffer. This argment may be NULL if
1239  *				the value is not desired.
1240  * @param[in,out]	len	The maximum capacity of @p buf. On success,
1241  *				will be set to the actual size of the requested
1242  *				value.
1243  * @param		type	The desired data representation to be written
1244  *				to @p buf.
1245  *
1246  * @retval 0		success
1247  * @retval ENOENT	The requested variable was not found.
1248  * @retval ENODEV	No valid NVRAM source could be found.
1249  * @retval ENOMEM	If a buffer of @p size is too small to hold the
1250  *			requested value.
1251  * @retval EOPNOTSUPP	If the value cannot be coerced to @p type.
1252  * @retval ERANGE	If value coercion would overflow @p type.
1253  * @retval non-zero	If reading @p name otherwise fails, a regular unix
1254  *			error code will be returned.
1255  */
1256 static inline int
1257 bhnd_nvram_getvar(device_t dev, const char *name, void *buf, size_t *len,
1258      bhnd_nvram_type type)
1259 {
1260 	return (BHND_BUS_GET_NVRAM_VAR(device_get_parent(dev), dev, name, buf,
1261 	    len, type));
1262 }
1263 
1264 /**
1265  * Allocate a resource from a device's parent bhnd(4) bus.
1266  *
1267  * @param dev The device requesting resource ownership.
1268  * @param type The type of resource to allocate. This may be any type supported
1269  * by the standard bus APIs.
1270  * @param rid The bus-specific handle identifying the resource being allocated.
1271  * @param start The start address of the resource.
1272  * @param end The end address of the resource.
1273  * @param count The size of the resource.
1274  * @param flags The flags for the resource to be allocated. These may be any
1275  * values supported by the standard bus APIs.
1276  *
1277  * To request the resource's default addresses, pass @p start and
1278  * @p end values of @c 0 and @c ~0, respectively, and
1279  * a @p count of @c 1.
1280  *
1281  * @retval NULL The resource could not be allocated.
1282  * @retval resource The allocated resource.
1283  */
1284 static inline struct bhnd_resource *
1285 bhnd_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
1286     rman_res_t end, rman_res_t count, u_int flags)
1287 {
1288 	return BHND_BUS_ALLOC_RESOURCE(device_get_parent(dev), dev, type, rid,
1289 	    start, end, count, flags);
1290 }
1291 
1292 
1293 /**
1294  * Allocate a resource from a device's parent bhnd(4) bus, using the
1295  * resource's default start, end, and count values.
1296  *
1297  * @param dev The device requesting resource ownership.
1298  * @param type The type of resource to allocate. This may be any type supported
1299  * by the standard bus APIs.
1300  * @param rid The bus-specific handle identifying the resource being allocated.
1301  * @param flags The flags for the resource to be allocated. These may be any
1302  * values supported by the standard bus APIs.
1303  *
1304  * @retval NULL The resource could not be allocated.
1305  * @retval resource The allocated resource.
1306  */
1307 static inline struct bhnd_resource *
1308 bhnd_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
1309 {
1310 	return bhnd_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
1311 }
1312 
1313 /**
1314  * Activate a previously allocated bhnd resource.
1315  *
1316  * @param dev The device holding ownership of the allocated resource.
1317  * @param type The type of the resource.
1318  * @param rid The bus-specific handle identifying the resource.
1319  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1320  * BHND_BUS_ALLOC_RESOURCE.
1321  *
1322  * @retval 0 success
1323  * @retval non-zero an error occurred while activating the resource.
1324  */
1325 static inline int
1326 bhnd_activate_resource(device_t dev, int type, int rid,
1327    struct bhnd_resource *r)
1328 {
1329 	return BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
1330 	    rid, r);
1331 }
1332 
1333 /**
1334  * Deactivate a previously activated bhnd resource.
1335  *
1336  * @param dev The device holding ownership of the activated resource.
1337  * @param type The type of the resource.
1338  * @param rid The bus-specific handle identifying the resource.
1339  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1340  * BHND_BUS_ALLOC_RESOURCE.
1341  *
1342  * @retval 0 success
1343  * @retval non-zero an error occurred while activating the resource.
1344  */
1345 static inline int
1346 bhnd_deactivate_resource(device_t dev, int type, int rid,
1347    struct bhnd_resource *r)
1348 {
1349 	return BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
1350 	    rid, r);
1351 }
1352 
1353 /**
1354  * Free a resource allocated by bhnd_alloc_resource().
1355  *
1356  * @param dev The device holding ownership of the resource.
1357  * @param type The type of the resource.
1358  * @param rid The bus-specific handle identifying the resource.
1359  * @param r A pointer to the resource returned by bhnd_alloc_resource or
1360  * BHND_ALLOC_RESOURCE.
1361  *
1362  * @retval 0 success
1363  * @retval non-zero an error occurred while activating the resource.
1364  */
1365 static inline int
1366 bhnd_release_resource(device_t dev, int type, int rid,
1367    struct bhnd_resource *r)
1368 {
1369 	return BHND_BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
1370 	    rid, r);
1371 }
1372 
1373 /**
1374  * Return true if @p region_num is a valid region on @p port_num of
1375  * @p type attached to @p dev.
1376  *
1377  * @param dev A bhnd bus child device.
1378  * @param type The port type being queried.
1379  * @param port The port number being queried.
1380  * @param region The region number being queried.
1381  */
1382 static inline bool
1383 bhnd_is_region_valid(device_t dev, bhnd_port_type type, u_int port,
1384     u_int region)
1385 {
1386 	return (BHND_BUS_IS_REGION_VALID(device_get_parent(dev), dev, type,
1387 	    port, region));
1388 }
1389 
1390 /**
1391  * Return the number of ports of type @p type attached to @p def.
1392  *
1393  * @param dev A bhnd bus child device.
1394  * @param type The port type being queried.
1395  */
1396 static inline u_int
1397 bhnd_get_port_count(device_t dev, bhnd_port_type type) {
1398 	return (BHND_BUS_GET_PORT_COUNT(device_get_parent(dev), dev, type));
1399 }
1400 
1401 /**
1402  * Return the number of memory regions mapped to @p child @p port of
1403  * type @p type.
1404  *
1405  * @param dev A bhnd bus child device.
1406  * @param port The port number being queried.
1407  * @param type The port type being queried.
1408  */
1409 static inline u_int
1410 bhnd_get_region_count(device_t dev, bhnd_port_type type, u_int port) {
1411 	return (BHND_BUS_GET_REGION_COUNT(device_get_parent(dev), dev, type,
1412 	    port));
1413 }
1414 
1415 /**
1416  * Return the resource-ID for a memory region on the given device port.
1417  *
1418  * @param dev A bhnd bus child device.
1419  * @param type The port type.
1420  * @param port The port identifier.
1421  * @param region The identifier of the memory region on @p port.
1422  *
1423  * @retval int The RID for the given @p port and @p region on @p device.
1424  * @retval -1 No such port/region found.
1425  */
1426 static inline int
1427 bhnd_get_port_rid(device_t dev, bhnd_port_type type, u_int port, u_int region)
1428 {
1429 	return BHND_BUS_GET_PORT_RID(device_get_parent(dev), dev, type, port,
1430 	    region);
1431 }
1432 
1433 /**
1434  * Decode a port / region pair on @p dev defined by @p rid.
1435  *
1436  * @param dev A bhnd bus child device.
1437  * @param type The resource type.
1438  * @param rid The resource identifier.
1439  * @param[out] port_type The decoded port type.
1440  * @param[out] port The decoded port identifier.
1441  * @param[out] region The decoded region identifier.
1442  *
1443  * @retval 0 success
1444  * @retval non-zero No matching port/region found.
1445  */
1446 static inline int
1447 bhnd_decode_port_rid(device_t dev, int type, int rid, bhnd_port_type *port_type,
1448     u_int *port, u_int *region)
1449 {
1450 	return BHND_BUS_DECODE_PORT_RID(device_get_parent(dev), dev, type, rid,
1451 	    port_type, port, region);
1452 }
1453 
1454 /**
1455  * Get the address and size of @p region on @p port.
1456  *
1457  * @param dev A bhnd bus child device.
1458  * @param port_type The port type.
1459  * @param port The port identifier.
1460  * @param region The identifier of the memory region on @p port.
1461  * @param[out] region_addr The region's base address.
1462  * @param[out] region_size The region's size.
1463  *
1464  * @retval 0 success
1465  * @retval non-zero No matching port/region found.
1466  */
1467 static inline int
1468 bhnd_get_region_addr(device_t dev, bhnd_port_type port_type, u_int port,
1469     u_int region, bhnd_addr_t *region_addr, bhnd_size_t *region_size)
1470 {
1471 	return BHND_BUS_GET_REGION_ADDR(device_get_parent(dev), dev, port_type,
1472 	    port, region, region_addr, region_size);
1473 }
1474 
1475 /*
1476  * bhnd bus-level equivalents of the bus_(read|write|set|barrier|...)
1477  * macros (compatible with bhnd_resource).
1478  *
1479  * Generated with bhnd/tools/bus_macro.sh
1480  */
1481 #define bhnd_bus_barrier(r, o, l, f) \
1482     ((r)->direct) ? \
1483 	bus_barrier((r)->res, (o), (l), (f)) : \
1484 	BHND_BUS_BARRIER( \
1485 	    device_get_parent(rman_get_device((r)->res)),	\
1486 	    rman_get_device((r)->res), (r), (o), (l), (f))
1487 #define bhnd_bus_read_1(r, o) \
1488     ((r)->direct) ? \
1489 	bus_read_1((r)->res, (o)) : \
1490 	BHND_BUS_READ_1( \
1491 	    device_get_parent(rman_get_device((r)->res)),	\
1492 	    rman_get_device((r)->res), (r), (o))
1493 #define bhnd_bus_read_multi_1(r, o, d, c) \
1494     ((r)->direct) ? \
1495 	bus_read_multi_1((r)->res, (o), (d), (c)) : \
1496 	BHND_BUS_READ_MULTI_1( \
1497 	    device_get_parent(rman_get_device((r)->res)),	\
1498 	    rman_get_device((r)->res), (r), (o), (d), (c))
1499 #define bhnd_bus_read_region_1(r, o, d, c) \
1500     ((r)->direct) ? \
1501 	bus_read_region_1((r)->res, (o), (d), (c)) : \
1502 	BHND_BUS_READ_REGION_1( \
1503 	    device_get_parent(rman_get_device((r)->res)),	\
1504 	    rman_get_device((r)->res), (r), (o), (d), (c))
1505 #define bhnd_bus_write_1(r, o, v) \
1506     ((r)->direct) ? \
1507 	bus_write_1((r)->res, (o), (v)) : \
1508 	BHND_BUS_WRITE_1( \
1509 	    device_get_parent(rman_get_device((r)->res)),	\
1510 	    rman_get_device((r)->res), (r), (o), (v))
1511 #define bhnd_bus_write_multi_1(r, o, d, c) \
1512     ((r)->direct) ? \
1513 	bus_write_multi_1((r)->res, (o), (d), (c)) : \
1514 	BHND_BUS_WRITE_MULTI_1( \
1515 	    device_get_parent(rman_get_device((r)->res)),	\
1516 	    rman_get_device((r)->res), (r), (o), (d), (c))
1517 #define bhnd_bus_write_region_1(r, o, d, c) \
1518     ((r)->direct) ? \
1519 	bus_write_region_1((r)->res, (o), (d), (c)) : \
1520 	BHND_BUS_WRITE_REGION_1( \
1521 	    device_get_parent(rman_get_device((r)->res)),	\
1522 	    rman_get_device((r)->res), (r), (o), (d), (c))
1523 #define bhnd_bus_read_stream_1(r, o) \
1524     ((r)->direct) ? \
1525 	bus_read_stream_1((r)->res, (o)) : \
1526 	BHND_BUS_READ_STREAM_1( \
1527 	    device_get_parent(rman_get_device((r)->res)),	\
1528 	    rman_get_device((r)->res), (r), (o))
1529 #define bhnd_bus_read_multi_stream_1(r, o, d, c) \
1530     ((r)->direct) ? \
1531 	bus_read_multi_stream_1((r)->res, (o), (d), (c)) : \
1532 	BHND_BUS_READ_MULTI_STREAM_1( \
1533 	    device_get_parent(rman_get_device((r)->res)),	\
1534 	    rman_get_device((r)->res), (r), (o), (d), (c))
1535 #define bhnd_bus_read_region_stream_1(r, o, d, c) \
1536     ((r)->direct) ? \
1537 	bus_read_region_stream_1((r)->res, (o), (d), (c)) : \
1538 	BHND_BUS_READ_REGION_STREAM_1( \
1539 	    device_get_parent(rman_get_device((r)->res)),	\
1540 	    rman_get_device((r)->res), (r), (o), (d), (c))
1541 #define bhnd_bus_write_stream_1(r, o, v) \
1542     ((r)->direct) ? \
1543 	bus_write_stream_1((r)->res, (o), (v)) : \
1544 	BHND_BUS_WRITE_STREAM_1( \
1545 	    device_get_parent(rman_get_device((r)->res)),	\
1546 	    rman_get_device((r)->res), (r), (o), (v))
1547 #define bhnd_bus_write_multi_stream_1(r, o, d, c) \
1548     ((r)->direct) ? \
1549 	bus_write_multi_stream_1((r)->res, (o), (d), (c)) : \
1550 	BHND_BUS_WRITE_MULTI_STREAM_1( \
1551 	    device_get_parent(rman_get_device((r)->res)),	\
1552 	    rman_get_device((r)->res), (r), (o), (d), (c))
1553 #define bhnd_bus_write_region_stream_1(r, o, d, c) \
1554     ((r)->direct) ? \
1555 	bus_write_region_stream_1((r)->res, (o), (d), (c)) : \
1556 	BHND_BUS_WRITE_REGION_STREAM_1( \
1557 	    device_get_parent(rman_get_device((r)->res)),	\
1558 	    rman_get_device((r)->res), (r), (o), (d), (c))
1559 #define bhnd_bus_set_multi_1(r, o, v, c) \
1560     ((r)->direct) ? \
1561 	bus_set_multi_1((r)->res, (o), (v), (c)) : \
1562 	BHND_BUS_SET_MULTI_1( \
1563 	    device_get_parent(rman_get_device((r)->res)),	\
1564 	    rman_get_device((r)->res), (r), (o), (v), (c))
1565 #define bhnd_bus_set_region_1(r, o, v, c) \
1566     ((r)->direct) ? \
1567 	bus_set_region_1((r)->res, (o), (v), (c)) : \
1568 	BHND_BUS_SET_REGION_1( \
1569 	    device_get_parent(rman_get_device((r)->res)),	\
1570 	    rman_get_device((r)->res), (r), (o), (v), (c))
1571 #define bhnd_bus_read_2(r, o) \
1572     ((r)->direct) ? \
1573 	bus_read_2((r)->res, (o)) : \
1574 	BHND_BUS_READ_2( \
1575 	    device_get_parent(rman_get_device((r)->res)),	\
1576 	    rman_get_device((r)->res), (r), (o))
1577 #define bhnd_bus_read_multi_2(r, o, d, c) \
1578     ((r)->direct) ? \
1579 	bus_read_multi_2((r)->res, (o), (d), (c)) : \
1580 	BHND_BUS_READ_MULTI_2( \
1581 	    device_get_parent(rman_get_device((r)->res)),	\
1582 	    rman_get_device((r)->res), (r), (o), (d), (c))
1583 #define bhnd_bus_read_region_2(r, o, d, c) \
1584     ((r)->direct) ? \
1585 	bus_read_region_2((r)->res, (o), (d), (c)) : \
1586 	BHND_BUS_READ_REGION_2( \
1587 	    device_get_parent(rman_get_device((r)->res)),	\
1588 	    rman_get_device((r)->res), (r), (o), (d), (c))
1589 #define bhnd_bus_write_2(r, o, v) \
1590     ((r)->direct) ? \
1591 	bus_write_2((r)->res, (o), (v)) : \
1592 	BHND_BUS_WRITE_2( \
1593 	    device_get_parent(rman_get_device((r)->res)),	\
1594 	    rman_get_device((r)->res), (r), (o), (v))
1595 #define bhnd_bus_write_multi_2(r, o, d, c) \
1596     ((r)->direct) ? \
1597 	bus_write_multi_2((r)->res, (o), (d), (c)) : \
1598 	BHND_BUS_WRITE_MULTI_2( \
1599 	    device_get_parent(rman_get_device((r)->res)),	\
1600 	    rman_get_device((r)->res), (r), (o), (d), (c))
1601 #define bhnd_bus_write_region_2(r, o, d, c) \
1602     ((r)->direct) ? \
1603 	bus_write_region_2((r)->res, (o), (d), (c)) : \
1604 	BHND_BUS_WRITE_REGION_2( \
1605 	    device_get_parent(rman_get_device((r)->res)),	\
1606 	    rman_get_device((r)->res), (r), (o), (d), (c))
1607 #define bhnd_bus_read_stream_2(r, o) \
1608     ((r)->direct) ? \
1609 	bus_read_stream_2((r)->res, (o)) : \
1610 	BHND_BUS_READ_STREAM_2( \
1611 	    device_get_parent(rman_get_device((r)->res)),	\
1612 	    rman_get_device((r)->res), (r), (o))
1613 #define bhnd_bus_read_multi_stream_2(r, o, d, c) \
1614     ((r)->direct) ? \
1615 	bus_read_multi_stream_2((r)->res, (o), (d), (c)) : \
1616 	BHND_BUS_READ_MULTI_STREAM_2( \
1617 	    device_get_parent(rman_get_device((r)->res)),	\
1618 	    rman_get_device((r)->res), (r), (o), (d), (c))
1619 #define bhnd_bus_read_region_stream_2(r, o, d, c) \
1620     ((r)->direct) ? \
1621 	bus_read_region_stream_2((r)->res, (o), (d), (c)) : \
1622 	BHND_BUS_READ_REGION_STREAM_2( \
1623 	    device_get_parent(rman_get_device((r)->res)),	\
1624 	    rman_get_device((r)->res), (r), (o), (d), (c))
1625 #define bhnd_bus_write_stream_2(r, o, v) \
1626     ((r)->direct) ? \
1627 	bus_write_stream_2((r)->res, (o), (v)) : \
1628 	BHND_BUS_WRITE_STREAM_2( \
1629 	    device_get_parent(rman_get_device((r)->res)),	\
1630 	    rman_get_device((r)->res), (r), (o), (v))
1631 #define bhnd_bus_write_multi_stream_2(r, o, d, c) \
1632     ((r)->direct) ? \
1633 	bus_write_multi_stream_2((r)->res, (o), (d), (c)) : \
1634 	BHND_BUS_WRITE_MULTI_STREAM_2( \
1635 	    device_get_parent(rman_get_device((r)->res)),	\
1636 	    rman_get_device((r)->res), (r), (o), (d), (c))
1637 #define bhnd_bus_write_region_stream_2(r, o, d, c) \
1638     ((r)->direct) ? \
1639 	bus_write_region_stream_2((r)->res, (o), (d), (c)) : \
1640 	BHND_BUS_WRITE_REGION_STREAM_2( \
1641 	    device_get_parent(rman_get_device((r)->res)),	\
1642 	    rman_get_device((r)->res), (r), (o), (d), (c))
1643 #define bhnd_bus_set_multi_2(r, o, v, c) \
1644     ((r)->direct) ? \
1645 	bus_set_multi_2((r)->res, (o), (v), (c)) : \
1646 	BHND_BUS_SET_MULTI_2( \
1647 	    device_get_parent(rman_get_device((r)->res)),	\
1648 	    rman_get_device((r)->res), (r), (o), (v), (c))
1649 #define bhnd_bus_set_region_2(r, o, v, c) \
1650     ((r)->direct) ? \
1651 	bus_set_region_2((r)->res, (o), (v), (c)) : \
1652 	BHND_BUS_SET_REGION_2( \
1653 	    device_get_parent(rman_get_device((r)->res)),	\
1654 	    rman_get_device((r)->res), (r), (o), (v), (c))
1655 #define bhnd_bus_read_4(r, o) \
1656     ((r)->direct) ? \
1657 	bus_read_4((r)->res, (o)) : \
1658 	BHND_BUS_READ_4( \
1659 	    device_get_parent(rman_get_device((r)->res)),	\
1660 	    rman_get_device((r)->res), (r), (o))
1661 #define bhnd_bus_read_multi_4(r, o, d, c) \
1662     ((r)->direct) ? \
1663 	bus_read_multi_4((r)->res, (o), (d), (c)) : \
1664 	BHND_BUS_READ_MULTI_4( \
1665 	    device_get_parent(rman_get_device((r)->res)),	\
1666 	    rman_get_device((r)->res), (r), (o), (d), (c))
1667 #define bhnd_bus_read_region_4(r, o, d, c) \
1668     ((r)->direct) ? \
1669 	bus_read_region_4((r)->res, (o), (d), (c)) : \
1670 	BHND_BUS_READ_REGION_4( \
1671 	    device_get_parent(rman_get_device((r)->res)),	\
1672 	    rman_get_device((r)->res), (r), (o), (d), (c))
1673 #define bhnd_bus_write_4(r, o, v) \
1674     ((r)->direct) ? \
1675 	bus_write_4((r)->res, (o), (v)) : \
1676 	BHND_BUS_WRITE_4( \
1677 	    device_get_parent(rman_get_device((r)->res)),	\
1678 	    rman_get_device((r)->res), (r), (o), (v))
1679 #define bhnd_bus_write_multi_4(r, o, d, c) \
1680     ((r)->direct) ? \
1681 	bus_write_multi_4((r)->res, (o), (d), (c)) : \
1682 	BHND_BUS_WRITE_MULTI_4( \
1683 	    device_get_parent(rman_get_device((r)->res)),	\
1684 	    rman_get_device((r)->res), (r), (o), (d), (c))
1685 #define bhnd_bus_write_region_4(r, o, d, c) \
1686     ((r)->direct) ? \
1687 	bus_write_region_4((r)->res, (o), (d), (c)) : \
1688 	BHND_BUS_WRITE_REGION_4( \
1689 	    device_get_parent(rman_get_device((r)->res)),	\
1690 	    rman_get_device((r)->res), (r), (o), (d), (c))
1691 #define bhnd_bus_read_stream_4(r, o) \
1692     ((r)->direct) ? \
1693 	bus_read_stream_4((r)->res, (o)) : \
1694 	BHND_BUS_READ_STREAM_4( \
1695 	    device_get_parent(rman_get_device((r)->res)),	\
1696 	    rman_get_device((r)->res), (r), (o))
1697 #define bhnd_bus_read_multi_stream_4(r, o, d, c) \
1698     ((r)->direct) ? \
1699 	bus_read_multi_stream_4((r)->res, (o), (d), (c)) : \
1700 	BHND_BUS_READ_MULTI_STREAM_4( \
1701 	    device_get_parent(rman_get_device((r)->res)),	\
1702 	    rman_get_device((r)->res), (r), (o), (d), (c))
1703 #define bhnd_bus_read_region_stream_4(r, o, d, c) \
1704     ((r)->direct) ? \
1705 	bus_read_region_stream_4((r)->res, (o), (d), (c)) : \
1706 	BHND_BUS_READ_REGION_STREAM_4( \
1707 	    device_get_parent(rman_get_device((r)->res)),	\
1708 	    rman_get_device((r)->res), (r), (o), (d), (c))
1709 #define bhnd_bus_write_stream_4(r, o, v) \
1710     ((r)->direct) ? \
1711 	bus_write_stream_4((r)->res, (o), (v)) : \
1712 	BHND_BUS_WRITE_STREAM_4( \
1713 	    device_get_parent(rman_get_device((r)->res)),	\
1714 	    rman_get_device((r)->res), (r), (o), (v))
1715 #define bhnd_bus_write_multi_stream_4(r, o, d, c) \
1716     ((r)->direct) ? \
1717 	bus_write_multi_stream_4((r)->res, (o), (d), (c)) : \
1718 	BHND_BUS_WRITE_MULTI_STREAM_4( \
1719 	    device_get_parent(rman_get_device((r)->res)),	\
1720 	    rman_get_device((r)->res), (r), (o), (d), (c))
1721 #define bhnd_bus_write_region_stream_4(r, o, d, c) \
1722     ((r)->direct) ? \
1723 	bus_write_region_stream_4((r)->res, (o), (d), (c)) : \
1724 	BHND_BUS_WRITE_REGION_STREAM_4( \
1725 	    device_get_parent(rman_get_device((r)->res)),	\
1726 	    rman_get_device((r)->res), (r), (o), (d), (c))
1727 #define bhnd_bus_set_multi_4(r, o, v, c) \
1728     ((r)->direct) ? \
1729 	bus_set_multi_4((r)->res, (o), (v), (c)) : \
1730 	BHND_BUS_SET_MULTI_4( \
1731 	    device_get_parent(rman_get_device((r)->res)),	\
1732 	    rman_get_device((r)->res), (r), (o), (v), (c))
1733 #define bhnd_bus_set_region_4(r, o, v, c) \
1734     ((r)->direct) ? \
1735 	bus_set_region_4((r)->res, (o), (v), (c)) : \
1736 	BHND_BUS_SET_REGION_4( \
1737 	    device_get_parent(rman_get_device((r)->res)),	\
1738 	    rman_get_device((r)->res), (r), (o), (v), (c))
1739 
1740 #endif /* _BHND_BHND_H_ */
1741