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