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