]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bhnd/bhnd.h
bhnd(4): Include the chip model (e.g. BCM4xxx) in bhnd(4) bus's device
[FreeBSD/FreeBSD.git] / sys / dev / bhnd / bhnd.h
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_debug.h"
43 #include "bhnd_bus_if.h"
44 #include "bhnd_match.h"
45
46 #include "nvram/bhnd_nvram.h"
47
48 extern devclass_t bhnd_devclass;
49 extern devclass_t bhnd_hostb_devclass;
50 extern devclass_t bhnd_nvram_devclass;
51
52 #define BHND_CHIPID_MAX_NAMELEN 32      /**< maximum buffer required for a
53                                              bhnd_format_chip_id() */
54
55 /**
56  * bhnd child instance variables
57  */
58 enum bhnd_device_vars {
59         BHND_IVAR_VENDOR,       /**< Designer's JEP-106 manufacturer ID. */
60         BHND_IVAR_DEVICE,       /**< Part number */
61         BHND_IVAR_HWREV,        /**< Core revision */
62         BHND_IVAR_DEVICE_CLASS, /**< Core class (@sa bhnd_devclass_t) */
63         BHND_IVAR_VENDOR_NAME,  /**< Core vendor name */
64         BHND_IVAR_DEVICE_NAME,  /**< Core name */
65         BHND_IVAR_CORE_INDEX,   /**< Bus-assigned core number */
66         BHND_IVAR_CORE_UNIT,    /**< Bus-assigned core unit number,
67                                      assigned sequentially (starting at 0) for
68                                      each vendor/device pair. */
69 };
70
71 /**
72  * bhnd device probe priority bands.
73  */
74 enum {
75         BHND_PROBE_ROOT         = 0,    /**< Nexus or host bridge */
76         BHND_PROBE_BUS          = 1000, /**< Busses and bridges */
77         BHND_PROBE_CPU          = 2000, /**< CPU devices */
78         BHND_PROBE_INTERRUPT    = 3000, /**< Interrupt controllers. */
79         BHND_PROBE_TIMER        = 4000, /**< Timers and clocks. */
80         BHND_PROBE_RESOURCE     = 5000, /**< Resource discovery (including NVRAM/SPROM) */
81         BHND_PROBE_DEFAULT      = 6000, /**< Default device priority */
82 };
83
84 /**
85  * Constants defining fine grained ordering within a BHND_PROBE_* priority band.
86  * 
87  * Example:
88  * @code
89  * BHND_PROBE_BUS + BHND_PROBE_ORDER_FIRST
90  * @endcode
91  */
92 enum {
93         BHND_PROBE_ORDER_FIRST          = 0,
94         BHND_PROBE_ORDER_EARLY          = 25,
95         BHND_PROBE_ORDER_MIDDLE         = 50,
96         BHND_PROBE_ORDER_LATE           = 75,
97         BHND_PROBE_ORDER_LAST           = 100
98
99 };
100
101 /*
102  * Simplified accessors for bhnd device ivars
103  */
104 #define BHND_ACCESSOR(var, ivar, type) \
105         __BUS_ACCESSOR(bhnd, var, BHND, ivar, type)
106
107 BHND_ACCESSOR(vendor,           VENDOR,         uint16_t);
108 BHND_ACCESSOR(device,           DEVICE,         uint16_t);
109 BHND_ACCESSOR(hwrev,            HWREV,          uint8_t);
110 BHND_ACCESSOR(class,            DEVICE_CLASS,   bhnd_devclass_t);
111 BHND_ACCESSOR(vendor_name,      VENDOR_NAME,    const char *);
112 BHND_ACCESSOR(device_name,      DEVICE_NAME,    const char *);
113 BHND_ACCESSOR(core_index,       CORE_INDEX,     u_int);
114 BHND_ACCESSOR(core_unit,        CORE_UNIT,      int);
115
116 #undef  BHND_ACCESSOR
117
118 /**
119  * A bhnd(4) board descriptor.
120  */
121 struct bhnd_board_info {
122         uint16_t        board_vendor;   /**< PCI-SIG vendor ID (even on non-PCI
123                                           *  devices).
124                                           *
125                                           *  On PCI devices, this will generally
126                                           *  be the subsystem vendor ID, but the
127                                           *  value may be overridden in device
128                                           *  NVRAM.
129                                           */
130         uint16_t        board_type;     /**< Board type (See BHND_BOARD_*)
131                                           *
132                                           *  On PCI devices, this will generally
133                                           *  be the subsystem device ID, but the
134                                           *  value may be overridden in device
135                                           *  NVRAM.
136                                           */
137         uint16_t        board_rev;      /**< Board revision. */
138         uint8_t         board_srom_rev; /**< Board SROM format revision */
139
140         uint32_t        board_flags;    /**< Board flags (see BHND_BFL_*) */
141         uint32_t        board_flags2;   /**< Board flags 2 (see BHND_BFL2_*) */
142         uint32_t        board_flags3;   /**< Board flags 3 (see BHND_BFL3_*) */
143 };
144
145
146 /**
147  * Chip Identification
148  * 
149  * This is read from the ChipCommon ID register; on earlier bhnd(4) devices
150  * where ChipCommon is unavailable, known values must be supplied.
151  */
152 struct bhnd_chipid {
153         uint16_t        chip_id;        /**< chip id (BHND_CHIPID_*) */
154         uint8_t         chip_rev;       /**< chip revision */
155         uint8_t         chip_pkg;       /**< chip package (BHND_PKGID_*) */
156         uint8_t         chip_type;      /**< chip type (BHND_CHIPTYPE_*) */
157
158         bhnd_addr_t     enum_addr;      /**< chip_type-specific enumeration
159                                           *  address; either the siba(4) base
160                                           *  core register block, or the bcma(4)
161                                           *  EROM core address. */
162
163         uint8_t         ncores;         /**< number of cores, if known. 0 if
164                                           *  not available. */
165 };
166
167 /**
168  * A bhnd(4) core descriptor.
169  */
170 struct bhnd_core_info {
171         uint16_t        vendor;         /**< JEP-106 vendor (BHND_MFGID_*) */
172         uint16_t        device;         /**< device */
173         uint16_t        hwrev;          /**< hardware revision */
174         u_int           core_idx;       /**< bus-assigned core index */
175         int             unit;           /**< bus-assigned core unit */
176 };
177
178 /**
179 * A bhnd(4) bus resource.
180
181 * This provides an abstract interface to per-core resources that may require
182 * bus-level remapping of address windows prior to access.
183 */
184 struct bhnd_resource {
185         struct resource *res;           /**< the system resource. */
186         bool             direct;        /**< false if the resource requires
187                                          *   bus window remapping before it
188                                          *   is MMIO accessible. */
189 };
190
191 /**
192  * Device quirk table descriptor.
193  */
194 struct bhnd_device_quirk {
195         struct bhnd_device_match desc;          /**< device match descriptor */
196         uint32_t                 quirks;        /**< quirk flags */
197 };
198
199 #define BHND_CORE_QUIRK(_rev, _flags)           \
200         {{ BHND_MATCH_CORE_REV(_rev) }, (_flags) }
201
202 #define BHND_CHIP_QUIRK(_chip, _rev, _flags)    \
203         {{ BHND_CHIP_IR(BCM ## _chip, _rev) }, (_flags) }
204
205 #define BHND_PKG_QUIRK(_chip, _pkg, _flags)     \
206         {{ BHND_CHIP_IP(BCM ## _chip, BCM ## _chip ## _pkg) }, (_flags) }
207
208 #define BHND_BOARD_QUIRK(_board, _flags)        \
209         {{ BHND_MATCH_BOARD_TYPE(_board) },     \
210             (_flags) }
211
212 #define BHND_DEVICE_QUIRK_END           { { BHND_MATCH_ANY }, 0 }
213 #define BHND_DEVICE_QUIRK_IS_END(_q)    \
214         (((_q)->desc.m.match_flags == 0) && (_q)->quirks == 0)
215
216 enum {
217         BHND_DF_ANY     = 0,
218         BHND_DF_HOSTB   = (1<<0),       /**< core is serving as the bus' host
219                                           *  bridge. implies BHND_DF_ADAPTER */
220         BHND_DF_SOC     = (1<<1),       /**< core is attached to a native
221                                              bus (BHND_ATTACH_NATIVE) */
222         BHND_DF_ADAPTER = (1<<2),       /**< core is attached to a bridged
223                                           *  adapter (BHND_ATTACH_ADAPTER) */
224 };
225
226 /** Device probe table descriptor */
227 struct bhnd_device {
228         const struct bhnd_device_match   core;          /**< core match descriptor */ 
229         const char                      *desc;          /**< device description, or NULL. */
230         const struct bhnd_device_quirk  *quirks_table;  /**< quirks table for this device, or NULL */
231         uint32_t                         device_flags;  /**< required BHND_DF_* flags */
232 };
233
234 #define _BHND_DEVICE(_vendor, _device, _desc, _quirks,          \
235      _flags, ...)                                               \
236         { { BHND_MATCH_CORE(BHND_MFGID_ ## _vendor,             \
237             BHND_COREID_ ## _device) }, _desc, _quirks,         \
238             _flags }
239
240 #define BHND_DEVICE(_vendor, _device, _desc, _quirks, ...)      \
241         _BHND_DEVICE(_vendor, _device, _desc, _quirks,          \
242             ## __VA_ARGS__, 0)
243
244 #define BHND_DEVICE_END         { { BHND_MATCH_ANY }, NULL, NULL, 0 }
245 #define BHND_DEVICE_IS_END(_d)  \
246         (BHND_MATCH_IS_ANY(&(_d)->core) && (_d)->desc == NULL)
247
248 const char                      *bhnd_vendor_name(uint16_t vendor);
249 const char                      *bhnd_port_type_name(bhnd_port_type port_type);
250 const char                      *bhnd_nvram_src_name(bhnd_nvram_src nvram_src);
251
252 const char                      *bhnd_find_core_name(uint16_t vendor,
253                                      uint16_t device);
254 bhnd_devclass_t                  bhnd_find_core_class(uint16_t vendor,
255                                      uint16_t device);
256
257 const char                      *bhnd_core_name(const struct bhnd_core_info *ci);
258 bhnd_devclass_t                  bhnd_core_class(const struct bhnd_core_info *ci);
259
260 int                              bhnd_format_chip_id(char *buffer, size_t size,
261                                      uint16_t chip_id);
262
263 device_t                         bhnd_match_child(device_t dev,
264                                      const struct bhnd_core_match *desc);
265
266 device_t                         bhnd_find_child(device_t dev,
267                                      bhnd_devclass_t class, int unit);
268
269 device_t                         bhnd_find_bridge_root(device_t dev,
270                                      devclass_t bus_class);
271
272 const struct bhnd_core_info     *bhnd_match_core(
273                                      const struct bhnd_core_info *cores,
274                                      u_int num_cores,
275                                      const struct bhnd_core_match *desc);
276
277 const struct bhnd_core_info     *bhnd_find_core(
278                                      const struct bhnd_core_info *cores,
279                                      u_int num_cores, bhnd_devclass_t class);
280
281 bool                             bhnd_core_matches(
282                                      const struct bhnd_core_info *core,
283                                      const struct bhnd_core_match *desc);
284
285 bool                             bhnd_chip_matches(
286                                      const struct bhnd_chipid *chipid,
287                                      const struct bhnd_chip_match *desc);
288
289 bool                             bhnd_board_matches(
290                                      const struct bhnd_board_info *info,
291                                      const struct bhnd_board_match *desc);
292
293 bool                             bhnd_hwrev_matches(uint16_t hwrev,
294                                      const struct bhnd_hwrev_match *desc);
295
296 bool                             bhnd_device_matches(device_t dev,
297                                      const struct bhnd_device_match *desc);
298
299 const struct bhnd_device        *bhnd_device_lookup(device_t dev,
300                                      const struct bhnd_device *table,
301                                      size_t entry_size);
302
303 uint32_t                         bhnd_device_quirks(device_t dev,
304                                      const struct bhnd_device *table,
305                                      size_t entry_size);
306
307 struct bhnd_core_info            bhnd_get_core_info(device_t dev);
308
309 int                              bhnd_alloc_resources(device_t dev,
310                                      struct resource_spec *rs,
311                                      struct bhnd_resource **res);
312
313 void                             bhnd_release_resources(device_t dev,
314                                      const struct resource_spec *rs,
315                                      struct bhnd_resource **res);
316
317 struct bhnd_chipid               bhnd_parse_chipid(uint32_t idreg,
318                                      bhnd_addr_t enum_addr);
319
320 int                              bhnd_read_chipid(device_t dev,
321                                      struct resource_spec *rs,
322                                      bus_size_t chipc_offset,
323                                      struct bhnd_chipid *result);
324
325 void                             bhnd_set_custom_core_desc(device_t dev,
326                                      const char *name);
327 void                             bhnd_set_default_core_desc(device_t dev);
328
329 void                             bhnd_set_default_bus_desc(device_t dev,
330                                      const struct bhnd_chipid *chip_id);
331
332 int                              bhnd_nvram_getvar_str(device_t dev,
333                                      const char *name, char *buf, size_t len,
334                                      size_t *rlen);
335
336 int                              bhnd_nvram_getvar_uint(device_t dev,
337                                      const char *name, void *value, int width);
338 int                              bhnd_nvram_getvar_uint8(device_t dev,
339                                      const char *name, uint8_t *value);
340 int                              bhnd_nvram_getvar_uint16(device_t dev,
341                                      const char *name, uint16_t *value);
342 int                              bhnd_nvram_getvar_uint32(device_t dev,
343                                      const char *name, uint32_t *value);
344
345 int                              bhnd_nvram_getvar_int(device_t dev,
346                                      const char *name, void *value, int width);
347 int                              bhnd_nvram_getvar_int8(device_t dev,
348                                      const char *name, int8_t *value);
349 int                              bhnd_nvram_getvar_int16(device_t dev,
350                                      const char *name, int16_t *value);
351 int                              bhnd_nvram_getvar_int32(device_t dev,
352                                      const char *name, int32_t *value);
353
354 int                              bhnd_nvram_getvar_array(device_t dev,
355                                      const char *name, void *buf, size_t count,
356                                      bhnd_nvram_type type);
357
358 bool                             bhnd_bus_generic_is_hw_disabled(device_t dev,
359                                      device_t child);
360 bool                             bhnd_bus_generic_is_region_valid(device_t dev,
361                                      device_t child, bhnd_port_type type,
362                                      u_int port, u_int region);
363 int                              bhnd_bus_generic_get_nvram_var(device_t dev,
364                                      device_t child, const char *name,
365                                      void *buf, size_t *size,
366                                      bhnd_nvram_type type);
367 const struct bhnd_chipid        *bhnd_bus_generic_get_chipid(device_t dev,
368                                      device_t child);
369 int                              bhnd_bus_generic_read_board_info(device_t dev,
370                                      device_t child,
371                                      struct bhnd_board_info *info);
372 struct bhnd_resource            *bhnd_bus_generic_alloc_resource (device_t dev,
373                                      device_t child, int type, int *rid,
374                                      rman_res_t start, rman_res_t end,
375                                      rman_res_t count, u_int flags);
376 int                              bhnd_bus_generic_release_resource (device_t dev,
377                                      device_t child, int type, int rid,
378                                      struct bhnd_resource *r);
379 int                              bhnd_bus_generic_activate_resource (device_t dev,
380                                      device_t child, int type, int rid,
381                                      struct bhnd_resource *r);
382 int                              bhnd_bus_generic_deactivate_resource (device_t dev,
383                                      device_t child, int type, int rid,
384                                      struct bhnd_resource *r);
385 bhnd_attach_type                 bhnd_bus_generic_get_attach_type(device_t dev,
386                                      device_t child);
387
388
389
390 /**
391  * Return the active host bridge core for the bhnd bus, if any, or NULL if
392  * not found.
393  *
394  * @param dev A bhnd bus device.
395  */
396 static inline device_t
397 bhnd_find_hostb_device(device_t dev) {
398         return (BHND_BUS_FIND_HOSTB_DEVICE(dev));
399 }
400
401 /**
402  * Return true if the hardware components required by @p dev are known to be
403  * unpopulated or otherwise unusable.
404  *
405  * In some cases, enumerated devices may have pins that are left floating, or
406  * the hardware may otherwise be non-functional; this method allows a parent
407  * device to explicitly specify if a successfully enumerated @p dev should
408  * be disabled.
409  *
410  * @param dev A bhnd bus child device.
411  */
412 static inline bool
413 bhnd_is_hw_disabled(device_t dev) {
414         return (BHND_BUS_IS_HW_DISABLED(device_get_parent(dev), dev));
415 }
416
417 /**
418  * Return the BHND chip identification info for the bhnd bus.
419  *
420  * @param dev A bhnd bus child device.
421  */
422 static inline const struct bhnd_chipid *
423 bhnd_get_chipid(device_t dev) {
424         return (BHND_BUS_GET_CHIPID(device_get_parent(dev), dev));
425 };
426
427 /**
428  * If supported by the chipset, return the clock source for the given clock.
429  *
430  * This function is only supported on early PWRCTL-equipped chipsets
431  * that expose clock management via their host bridge interface. Currently,
432  * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
433  *
434  * @param dev A bhnd bus child device.
435  * @param clock The clock for which a clock source will be returned.
436  *
437  * @retval      bhnd_clksrc             The clock source for @p clock.
438  * @retval      BHND_CLKSRC_UNKNOWN     If @p clock is unsupported, or its
439  *                                      clock source is not known to the bus.
440  */
441 static inline bhnd_clksrc
442 bhnd_pwrctl_get_clksrc(device_t dev, bhnd_clock clock)
443 {
444         return (BHND_BUS_PWRCTL_GET_CLKSRC(device_get_parent(dev), dev, clock));
445 }
446
447 /**
448  * If supported by the chipset, gate @p clock
449  *
450  * This function is only supported on early PWRCTL-equipped chipsets
451  * that expose clock management via their host bridge interface. Currently,
452  * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
453  *
454  * @param dev A bhnd bus child device.
455  * @param clock The clock to be disabled.
456  *
457  * @retval 0 success
458  * @retval ENODEV If bus-level clock source management is not supported.
459  * @retval ENXIO If bus-level management of @p clock is not supported.
460  */
461 static inline int
462 bhnd_pwrctl_gate_clock(device_t dev, bhnd_clock clock)
463 {
464         return (BHND_BUS_PWRCTL_GATE_CLOCK(device_get_parent(dev), dev, clock));
465 }
466
467 /**
468  * If supported by the chipset, ungate @p clock
469  *
470  * This function is only supported on early PWRCTL-equipped chipsets
471  * that expose clock management via their host bridge interface. Currently,
472  * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
473  *
474  * @param dev A bhnd bus child device.
475  * @param clock The clock to be enabled.
476  *
477  * @retval 0 success
478  * @retval ENODEV If bus-level clock source management is not supported.
479  * @retval ENXIO If bus-level management of @p clock is not supported.
480  */
481 static inline int
482 bhnd_pwrctl_ungate_clock(device_t dev, bhnd_clock clock)
483 {
484         return (BHND_BUS_PWRCTL_UNGATE_CLOCK(device_get_parent(dev), dev,
485             clock));
486 }
487
488 /**
489  * Return the BHND attachment type of the parent bhnd bus.
490  *
491  * @param dev A bhnd bus child device.
492  *
493  * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter,
494  * such as a WiFi chipset.
495  * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock,
496  * CPU, etc) to a directly attached native host.
497  */
498 static inline bhnd_attach_type
499 bhnd_get_attach_type (device_t dev) {
500         return (BHND_BUS_GET_ATTACH_TYPE(device_get_parent(dev), dev));
501 }
502
503 /**
504  * Attempt to read the BHND board identification from the bhnd bus.
505  *
506  * This relies on NVRAM access, and will fail if a valid NVRAM device cannot
507  * be found, or is not yet attached.
508  *
509  * @param dev The parent of @p child.
510  * @param child The bhnd device requesting board info.
511  * @param[out] info On success, will be populated with the bhnd(4) device's
512  * board information.
513  *
514  * @retval 0 success
515  * @retval ENODEV       No valid NVRAM source could be found.
516  * @retval non-zero     If reading @p name otherwise fails, a regular unix
517  *                      error code will be returned.
518  */
519 static inline int
520 bhnd_read_board_info(device_t dev, struct bhnd_board_info *info)
521 {
522         return (BHND_BUS_READ_BOARD_INFO(device_get_parent(dev), dev, info));
523 }
524
525 /**
526  * Allocate and enable per-core PMU request handling for @p child.
527  *
528  * The region containing the core's PMU register block (if any) must be
529  * allocated via bus_alloc_resource(9) (or bhnd_alloc_resource) before
530  * calling bhnd_alloc_pmu(), and must not be released until after
531  * calling bhnd_release_pmu().
532  *
533  * @param dev The parent of @p child.
534  * @param child The requesting bhnd device.
535  * 
536  * @retval 0           success
537  * @retval non-zero    If allocating PMU request state otherwise fails, a
538  *                     regular unix error code will be returned.
539  */
540 static inline int
541 bhnd_alloc_pmu(device_t dev)
542 {
543         return (BHND_BUS_ALLOC_PMU(device_get_parent(dev), dev));
544 }
545
546 /**
547  * Release any per-core PMU resources allocated for @p child. Any outstanding
548  * PMU requests are are discarded.
549  *
550  * @param dev The parent of @p child.
551  * @param child The requesting bhnd device.
552  * 
553  * @retval 0           success
554  * @retval non-zero    If releasing PMU request state otherwise fails, a
555  *                     regular unix error code will be returned, and
556  *                     the core state will be left unmodified.
557  */
558 static inline int
559 bhnd_release_pmu(device_t dev)
560 {
561         return (BHND_BUS_RELEASE_PMU(device_get_parent(dev), dev));
562 }
563
564 /** 
565  * Request that @p clock (or faster) be routed to @p dev.
566  * 
567  * A driver must ask the bhnd bus to allocate clock request state
568  * via bhnd_alloc_pmu() before it can request clock resources.
569  * 
570  * Request multiplexing is managed by the bus.
571  *
572  * @param dev The bhnd(4) device to which @p clock should be routed.
573  * @param clock The requested clock source. 
574  *
575  * @retval 0 success
576  * @retval ENODEV If an unsupported clock was requested.
577  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
578  */
579 static inline int
580 bhnd_request_clock(device_t dev, bhnd_clock clock)
581 {
582         return (BHND_BUS_REQUEST_CLOCK(device_get_parent(dev), dev, clock));
583 }
584
585 /**
586  * Request that @p clocks be powered on behalf of @p dev.
587  *
588  * This will power any clock sources (e.g. XTAL, PLL, etc) required for
589  * @p clocks and wait until they are ready, discarding any previous
590  * requests by @p dev.
591  *
592  * Request multiplexing is managed by the bus.
593  * 
594  * A driver must ask the bhnd bus to allocate clock request state
595  * via bhnd_alloc_pmu() before it can request clock resources.
596  *
597  * @param dev The requesting bhnd(4) device.
598  * @param clocks The clock(s) to be enabled.
599  *
600  * @retval 0 success
601  * @retval ENODEV If an unsupported clock was requested.
602  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
603  */
604 static inline int
605 bhnd_enable_clocks(device_t dev, uint32_t clocks)
606 {
607         return (BHND_BUS_ENABLE_CLOCKS(device_get_parent(dev), dev, clocks));
608 }
609
610 /**
611  * Power up an external PMU-managed resource assigned to @p dev.
612  * 
613  * A driver must ask the bhnd bus to allocate PMU request state
614  * via bhnd_alloc_pmu() before it can request PMU resources.
615  *
616  * @param dev The requesting bhnd(4) device.
617  * @param rsrc The core-specific external resource identifier.
618  *
619  * @retval 0 success
620  * @retval ENODEV If the PMU does not support @p rsrc.
621  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
622  */
623 static inline int
624 bhnd_request_ext_rsrc(device_t dev, u_int rsrc)
625 {
626         return (BHND_BUS_REQUEST_EXT_RSRC(device_get_parent(dev), dev, rsrc));
627 }
628
629 /**
630  * Power down an external PMU-managed resource assigned to @p dev.
631  * 
632  * A driver must ask the bhnd bus to allocate PMU request state
633  * via bhnd_alloc_pmu() before it can request PMU resources.
634  *
635  * @param dev The requesting bhnd(4) device.
636  * @param rsrc The core-specific external resource identifier.
637  *
638  * @retval 0 success
639  * @retval ENODEV If the PMU does not support @p rsrc.
640  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
641  */
642 static inline int
643 bhnd_release_ext_rsrc(device_t dev, u_int rsrc)
644 {
645         return (BHND_BUS_RELEASE_EXT_RSRC(device_get_parent(dev), dev, rsrc));
646 }
647
648
649 /**
650  * Read @p width bytes at @p offset from the bus-specific agent/config
651  * space of @p dev.
652  *
653  * @param dev The bhnd device for which @p offset should be read.
654  * @param offset The offset to be read.
655  * @param width The size of the access. Must be 1, 2 or 4 bytes.
656  *
657  * The exact behavior of this method is bus-specific. In the case of
658  * bcma(4), this method provides access to the first agent port of @p child.
659  *
660  * @note Device drivers should only use this API for functionality
661  * that is not available via another bhnd(4) function.
662  */
663 static inline uint32_t
664 bhnd_read_config(device_t dev, bus_size_t offset, u_int width)
665 {
666         return (BHND_BUS_READ_CONFIG(device_get_parent(dev), dev, offset,
667             width));
668 }
669
670 /**
671  * Read @p width bytes at @p offset from the bus-specific agent/config
672  * space of @p dev.
673  *
674  * @param dev The bhnd device for which @p offset should be read.
675  * @param offset The offset to be written.
676  * @param width The size of the access. Must be 1, 2 or 4 bytes.
677  *
678  * The exact behavior of this method is bus-specific. In the case of
679  * bcma(4), this method provides access to the first agent port of @p child.
680  *
681  * @note Device drivers should only use this API for functionality
682  * that is not available via another bhnd(4) function.
683  */
684 static inline void
685 bhnd_write_config(device_t dev, bus_size_t offset, uint32_t val, u_int width)
686 {
687         BHND_BUS_WRITE_CONFIG(device_get_parent(dev), dev, offset, val, width);
688 }
689
690 /**
691  * Read an NVRAM variable, coerced to the requested @p type.
692  *
693  * @param               dev     A bhnd bus child device.
694  * @param               name    The NVRAM variable name.
695  * @param[out]          buf     A buffer large enough to hold @p len bytes. On
696  *                              success, the requested value will be written to
697  *                              this buffer. This argment may be NULL if
698  *                              the value is not desired.
699  * @param[in,out]       len     The maximum capacity of @p buf. On success,
700  *                              will be set to the actual size of the requested
701  *                              value.
702  * @param               type    The desired data representation to be written
703  *                              to @p buf.
704  * 
705  * @retval 0            success
706  * @retval ENOENT       The requested variable was not found.
707  * @retval ENODEV       No valid NVRAM source could be found.
708  * @retval ENOMEM       If a buffer of @p size is too small to hold the
709  *                      requested value.
710  * @retval EOPNOTSUPP   If the value cannot be coerced to @p type.
711  * @retval ERANGE       If value coercion would overflow @p type.
712  * @retval non-zero     If reading @p name otherwise fails, a regular unix
713  *                      error code will be returned.
714  */
715 static inline int
716 bhnd_nvram_getvar(device_t dev, const char *name, void *buf, size_t *len,
717      bhnd_nvram_type type)
718 {
719         return (BHND_BUS_GET_NVRAM_VAR(device_get_parent(dev), dev, name, buf,
720             len, type));
721 }
722
723 /**
724  * Allocate a resource from a device's parent bhnd(4) bus.
725  * 
726  * @param dev The device requesting resource ownership.
727  * @param type The type of resource to allocate. This may be any type supported
728  * by the standard bus APIs.
729  * @param rid The bus-specific handle identifying the resource being allocated.
730  * @param start The start address of the resource.
731  * @param end The end address of the resource.
732  * @param count The size of the resource.
733  * @param flags The flags for the resource to be allocated. These may be any
734  * values supported by the standard bus APIs.
735  * 
736  * To request the resource's default addresses, pass @p start and
737  * @p end values of @c 0 and @c ~0, respectively, and
738  * a @p count of @c 1.
739  * 
740  * @retval NULL The resource could not be allocated.
741  * @retval resource The allocated resource.
742  */
743 static inline struct bhnd_resource *
744 bhnd_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
745     rman_res_t end, rman_res_t count, u_int flags)
746 {
747         return BHND_BUS_ALLOC_RESOURCE(device_get_parent(dev), dev, type, rid,
748             start, end, count, flags);
749 }
750
751
752 /**
753  * Allocate a resource from a device's parent bhnd(4) bus, using the
754  * resource's default start, end, and count values.
755  * 
756  * @param dev The device requesting resource ownership.
757  * @param type The type of resource to allocate. This may be any type supported
758  * by the standard bus APIs.
759  * @param rid The bus-specific handle identifying the resource being allocated.
760  * @param flags The flags for the resource to be allocated. These may be any
761  * values supported by the standard bus APIs.
762  * 
763  * @retval NULL The resource could not be allocated.
764  * @retval resource The allocated resource.
765  */
766 static inline struct bhnd_resource *
767 bhnd_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
768 {
769         return bhnd_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
770 }
771
772 /**
773  * Activate a previously allocated bhnd resource.
774  *
775  * @param dev The device holding ownership of the allocated resource.
776  * @param type The type of the resource. 
777  * @param rid The bus-specific handle identifying the resource.
778  * @param r A pointer to the resource returned by bhnd_alloc_resource or
779  * BHND_BUS_ALLOC_RESOURCE.
780  * 
781  * @retval 0 success
782  * @retval non-zero an error occurred while activating the resource.
783  */
784 static inline int
785 bhnd_activate_resource(device_t dev, int type, int rid,
786    struct bhnd_resource *r)
787 {
788         return BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
789             rid, r);
790 }
791
792 /**
793  * Deactivate a previously activated bhnd resource.
794  *
795  * @param dev The device holding ownership of the activated resource.
796  * @param type The type of the resource. 
797  * @param rid The bus-specific handle identifying the resource.
798  * @param r A pointer to the resource returned by bhnd_alloc_resource or
799  * BHND_BUS_ALLOC_RESOURCE.
800  * 
801  * @retval 0 success
802  * @retval non-zero an error occurred while activating the resource.
803  */
804 static inline int
805 bhnd_deactivate_resource(device_t dev, int type, int rid,
806    struct bhnd_resource *r)
807 {
808         return BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
809             rid, r);
810 }
811
812 /**
813  * Free a resource allocated by bhnd_alloc_resource().
814  *
815  * @param dev The device holding ownership of the resource.
816  * @param type The type of the resource. 
817  * @param rid The bus-specific handle identifying the resource.
818  * @param r A pointer to the resource returned by bhnd_alloc_resource or
819  * BHND_ALLOC_RESOURCE.
820  * 
821  * @retval 0 success
822  * @retval non-zero an error occurred while activating the resource.
823  */
824 static inline int
825 bhnd_release_resource(device_t dev, int type, int rid,
826    struct bhnd_resource *r)
827 {
828         return BHND_BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
829             rid, r);
830 }
831
832 /**
833  * Return true if @p region_num is a valid region on @p port_num of
834  * @p type attached to @p dev.
835  *
836  * @param dev A bhnd bus child device.
837  * @param type The port type being queried.
838  * @param port_num The port number being queried.
839  * @param region_num The region number being queried.
840  */
841 static inline bool
842 bhnd_is_region_valid(device_t dev, bhnd_port_type type, u_int port_num,
843     u_int region_num)
844 {
845         return (BHND_BUS_IS_REGION_VALID(device_get_parent(dev), dev, type,
846             port_num, region_num));
847 }
848
849 /**
850  * Return the number of ports of type @p type attached to @p def.
851  *
852  * @param dev A bhnd bus child device.
853  * @param type The port type being queried.
854  */
855 static inline u_int
856 bhnd_get_port_count(device_t dev, bhnd_port_type type) {
857         return (BHND_BUS_GET_PORT_COUNT(device_get_parent(dev), dev, type));
858 }
859
860 /**
861  * Return the number of memory regions mapped to @p child @p port of
862  * type @p type.
863  *
864  * @param dev A bhnd bus child device.
865  * @param port The port number being queried.
866  * @param type The port type being queried.
867  */
868 static inline u_int
869 bhnd_get_region_count(device_t dev, bhnd_port_type type, u_int port) {
870         return (BHND_BUS_GET_REGION_COUNT(device_get_parent(dev), dev, type,
871             port));
872 }
873
874 /**
875  * Return the resource-ID for a memory region on the given device port.
876  *
877  * @param dev A bhnd bus child device.
878  * @param type The port type.
879  * @param port The port identifier.
880  * @param region The identifier of the memory region on @p port.
881  * 
882  * @retval int The RID for the given @p port and @p region on @p device.
883  * @retval -1 No such port/region found.
884  */
885 static inline int
886 bhnd_get_port_rid(device_t dev, bhnd_port_type type, u_int port, u_int region)
887 {
888         return BHND_BUS_GET_PORT_RID(device_get_parent(dev), dev, type, port,
889             region);
890 }
891
892 /**
893  * Decode a port / region pair on @p dev defined by @p rid.
894  *
895  * @param dev A bhnd bus child device.
896  * @param type The resource type.
897  * @param rid The resource identifier.
898  * @param[out] port_type The decoded port type.
899  * @param[out] port The decoded port identifier.
900  * @param[out] region The decoded region identifier.
901  *
902  * @retval 0 success
903  * @retval non-zero No matching port/region found.
904  */
905 static inline int
906 bhnd_decode_port_rid(device_t dev, int type, int rid, bhnd_port_type *port_type,
907     u_int *port, u_int *region)
908 {
909         return BHND_BUS_DECODE_PORT_RID(device_get_parent(dev), dev, type, rid,
910             port_type, port, region);
911 }
912
913 /**
914  * Get the address and size of @p region on @p port.
915  *
916  * @param dev A bhnd bus child device.
917  * @param port_type The port type.
918  * @param port The port identifier.
919  * @param region The identifier of the memory region on @p port.
920  * @param[out] region_addr The region's base address.
921  * @param[out] region_size The region's size.
922  *
923  * @retval 0 success
924  * @retval non-zero No matching port/region found.
925  */
926 static inline int
927 bhnd_get_region_addr(device_t dev, bhnd_port_type port_type, u_int port,
928     u_int region, bhnd_addr_t *region_addr, bhnd_size_t *region_size)
929 {
930         return BHND_BUS_GET_REGION_ADDR(device_get_parent(dev), dev, port_type,
931             port, region, region_addr, region_size);
932 }
933
934 /*
935  * bhnd bus-level equivalents of the bus_(read|write|set|barrier|...)
936  * macros (compatible with bhnd_resource).
937  *
938  * Generated with bhnd/tools/bus_macro.sh
939  */
940 #define bhnd_bus_barrier(r, o, l, f) \
941     ((r)->direct) ? \
942         bus_barrier((r)->res, (o), (l), (f)) : \
943         BHND_BUS_BARRIER( \
944             device_get_parent(rman_get_device((r)->res)),       \
945             rman_get_device((r)->res), (r), (o), (l), (f))
946 #define bhnd_bus_read_1(r, o) \
947     ((r)->direct) ? \
948         bus_read_1((r)->res, (o)) : \
949         BHND_BUS_READ_1( \
950             device_get_parent(rman_get_device((r)->res)),       \
951             rman_get_device((r)->res), (r), (o))
952 #define bhnd_bus_read_multi_1(r, o, d, c) \
953     ((r)->direct) ? \
954         bus_read_multi_1((r)->res, (o), (d), (c)) : \
955         BHND_BUS_READ_MULTI_1( \
956             device_get_parent(rman_get_device((r)->res)),       \
957             rman_get_device((r)->res), (r), (o), (d), (c))
958 #define bhnd_bus_read_region_1(r, o, d, c) \
959     ((r)->direct) ? \
960         bus_read_region_1((r)->res, (o), (d), (c)) : \
961         BHND_BUS_READ_REGION_1( \
962             device_get_parent(rman_get_device((r)->res)),       \
963             rman_get_device((r)->res), (r), (o), (d), (c))
964 #define bhnd_bus_write_1(r, o, v) \
965     ((r)->direct) ? \
966         bus_write_1((r)->res, (o), (v)) : \
967         BHND_BUS_WRITE_1( \
968             device_get_parent(rman_get_device((r)->res)),       \
969             rman_get_device((r)->res), (r), (o), (v))
970 #define bhnd_bus_write_multi_1(r, o, d, c) \
971     ((r)->direct) ? \
972         bus_write_multi_1((r)->res, (o), (d), (c)) : \
973         BHND_BUS_WRITE_MULTI_1( \
974             device_get_parent(rman_get_device((r)->res)),       \
975             rman_get_device((r)->res), (r), (o), (d), (c))
976 #define bhnd_bus_write_region_1(r, o, d, c) \
977     ((r)->direct) ? \
978         bus_write_region_1((r)->res, (o), (d), (c)) : \
979         BHND_BUS_WRITE_REGION_1( \
980             device_get_parent(rman_get_device((r)->res)),       \
981             rman_get_device((r)->res), (r), (o), (d), (c))
982 #define bhnd_bus_read_stream_1(r, o) \
983     ((r)->direct) ? \
984         bus_read_stream_1((r)->res, (o)) : \
985         BHND_BUS_READ_STREAM_1( \
986             device_get_parent(rman_get_device((r)->res)),       \
987             rman_get_device((r)->res), (r), (o))
988 #define bhnd_bus_read_multi_stream_1(r, o, d, c) \
989     ((r)->direct) ? \
990         bus_read_multi_stream_1((r)->res, (o), (d), (c)) : \
991         BHND_BUS_READ_MULTI_STREAM_1( \
992             device_get_parent(rman_get_device((r)->res)),       \
993             rman_get_device((r)->res), (r), (o), (d), (c))
994 #define bhnd_bus_read_region_stream_1(r, o, d, c) \
995     ((r)->direct) ? \
996         bus_read_region_stream_1((r)->res, (o), (d), (c)) : \
997         BHND_BUS_READ_REGION_STREAM_1( \
998             device_get_parent(rman_get_device((r)->res)),       \
999             rman_get_device((r)->res), (r), (o), (d), (c))
1000 #define bhnd_bus_write_stream_1(r, o, v) \
1001     ((r)->direct) ? \
1002         bus_write_stream_1((r)->res, (o), (v)) : \
1003         BHND_BUS_WRITE_STREAM_1( \
1004             device_get_parent(rman_get_device((r)->res)),       \
1005             rman_get_device((r)->res), (r), (o), (v))
1006 #define bhnd_bus_write_multi_stream_1(r, o, d, c) \
1007     ((r)->direct) ? \
1008         bus_write_multi_stream_1((r)->res, (o), (d), (c)) : \
1009         BHND_BUS_WRITE_MULTI_STREAM_1( \
1010             device_get_parent(rman_get_device((r)->res)),       \
1011             rman_get_device((r)->res), (r), (o), (d), (c))
1012 #define bhnd_bus_write_region_stream_1(r, o, d, c) \
1013     ((r)->direct) ? \
1014         bus_write_region_stream_1((r)->res, (o), (d), (c)) : \
1015         BHND_BUS_WRITE_REGION_STREAM_1( \
1016             device_get_parent(rman_get_device((r)->res)),       \
1017             rman_get_device((r)->res), (r), (o), (d), (c))
1018 #define bhnd_bus_set_multi_1(r, o, v, c) \
1019     ((r)->direct) ? \
1020         bus_set_multi_1((r)->res, (o), (v), (c)) : \
1021         BHND_BUS_SET_MULTI_1( \
1022             device_get_parent(rman_get_device((r)->res)),       \
1023             rman_get_device((r)->res), (r), (o), (v), (c))
1024 #define bhnd_bus_set_region_1(r, o, v, c) \
1025     ((r)->direct) ? \
1026         bus_set_region_1((r)->res, (o), (v), (c)) : \
1027         BHND_BUS_SET_REGION_1( \
1028             device_get_parent(rman_get_device((r)->res)),       \
1029             rman_get_device((r)->res), (r), (o), (v), (c))
1030 #define bhnd_bus_read_2(r, o) \
1031     ((r)->direct) ? \
1032         bus_read_2((r)->res, (o)) : \
1033         BHND_BUS_READ_2( \
1034             device_get_parent(rman_get_device((r)->res)),       \
1035             rman_get_device((r)->res), (r), (o))
1036 #define bhnd_bus_read_multi_2(r, o, d, c) \
1037     ((r)->direct) ? \
1038         bus_read_multi_2((r)->res, (o), (d), (c)) : \
1039         BHND_BUS_READ_MULTI_2( \
1040             device_get_parent(rman_get_device((r)->res)),       \
1041             rman_get_device((r)->res), (r), (o), (d), (c))
1042 #define bhnd_bus_read_region_2(r, o, d, c) \
1043     ((r)->direct) ? \
1044         bus_read_region_2((r)->res, (o), (d), (c)) : \
1045         BHND_BUS_READ_REGION_2( \
1046             device_get_parent(rman_get_device((r)->res)),       \
1047             rman_get_device((r)->res), (r), (o), (d), (c))
1048 #define bhnd_bus_write_2(r, o, v) \
1049     ((r)->direct) ? \
1050         bus_write_2((r)->res, (o), (v)) : \
1051         BHND_BUS_WRITE_2( \
1052             device_get_parent(rman_get_device((r)->res)),       \
1053             rman_get_device((r)->res), (r), (o), (v))
1054 #define bhnd_bus_write_multi_2(r, o, d, c) \
1055     ((r)->direct) ? \
1056         bus_write_multi_2((r)->res, (o), (d), (c)) : \
1057         BHND_BUS_WRITE_MULTI_2( \
1058             device_get_parent(rman_get_device((r)->res)),       \
1059             rman_get_device((r)->res), (r), (o), (d), (c))
1060 #define bhnd_bus_write_region_2(r, o, d, c) \
1061     ((r)->direct) ? \
1062         bus_write_region_2((r)->res, (o), (d), (c)) : \
1063         BHND_BUS_WRITE_REGION_2( \
1064             device_get_parent(rman_get_device((r)->res)),       \
1065             rman_get_device((r)->res), (r), (o), (d), (c))
1066 #define bhnd_bus_read_stream_2(r, o) \
1067     ((r)->direct) ? \
1068         bus_read_stream_2((r)->res, (o)) : \
1069         BHND_BUS_READ_STREAM_2( \
1070             device_get_parent(rman_get_device((r)->res)),       \
1071             rman_get_device((r)->res), (r), (o))
1072 #define bhnd_bus_read_multi_stream_2(r, o, d, c) \
1073     ((r)->direct) ? \
1074         bus_read_multi_stream_2((r)->res, (o), (d), (c)) : \
1075         BHND_BUS_READ_MULTI_STREAM_2( \
1076             device_get_parent(rman_get_device((r)->res)),       \
1077             rman_get_device((r)->res), (r), (o), (d), (c))
1078 #define bhnd_bus_read_region_stream_2(r, o, d, c) \
1079     ((r)->direct) ? \
1080         bus_read_region_stream_2((r)->res, (o), (d), (c)) : \
1081         BHND_BUS_READ_REGION_STREAM_2( \
1082             device_get_parent(rman_get_device((r)->res)),       \
1083             rman_get_device((r)->res), (r), (o), (d), (c))
1084 #define bhnd_bus_write_stream_2(r, o, v) \
1085     ((r)->direct) ? \
1086         bus_write_stream_2((r)->res, (o), (v)) : \
1087         BHND_BUS_WRITE_STREAM_2( \
1088             device_get_parent(rman_get_device((r)->res)),       \
1089             rman_get_device((r)->res), (r), (o), (v))
1090 #define bhnd_bus_write_multi_stream_2(r, o, d, c) \
1091     ((r)->direct) ? \
1092         bus_write_multi_stream_2((r)->res, (o), (d), (c)) : \
1093         BHND_BUS_WRITE_MULTI_STREAM_2( \
1094             device_get_parent(rman_get_device((r)->res)),       \
1095             rman_get_device((r)->res), (r), (o), (d), (c))
1096 #define bhnd_bus_write_region_stream_2(r, o, d, c) \
1097     ((r)->direct) ? \
1098         bus_write_region_stream_2((r)->res, (o), (d), (c)) : \
1099         BHND_BUS_WRITE_REGION_STREAM_2( \
1100             device_get_parent(rman_get_device((r)->res)),       \
1101             rman_get_device((r)->res), (r), (o), (d), (c))
1102 #define bhnd_bus_set_multi_2(r, o, v, c) \
1103     ((r)->direct) ? \
1104         bus_set_multi_2((r)->res, (o), (v), (c)) : \
1105         BHND_BUS_SET_MULTI_2( \
1106             device_get_parent(rman_get_device((r)->res)),       \
1107             rman_get_device((r)->res), (r), (o), (v), (c))
1108 #define bhnd_bus_set_region_2(r, o, v, c) \
1109     ((r)->direct) ? \
1110         bus_set_region_2((r)->res, (o), (v), (c)) : \
1111         BHND_BUS_SET_REGION_2( \
1112             device_get_parent(rman_get_device((r)->res)),       \
1113             rman_get_device((r)->res), (r), (o), (v), (c))
1114 #define bhnd_bus_read_4(r, o) \
1115     ((r)->direct) ? \
1116         bus_read_4((r)->res, (o)) : \
1117         BHND_BUS_READ_4( \
1118             device_get_parent(rman_get_device((r)->res)),       \
1119             rman_get_device((r)->res), (r), (o))
1120 #define bhnd_bus_read_multi_4(r, o, d, c) \
1121     ((r)->direct) ? \
1122         bus_read_multi_4((r)->res, (o), (d), (c)) : \
1123         BHND_BUS_READ_MULTI_4( \
1124             device_get_parent(rman_get_device((r)->res)),       \
1125             rman_get_device((r)->res), (r), (o), (d), (c))
1126 #define bhnd_bus_read_region_4(r, o, d, c) \
1127     ((r)->direct) ? \
1128         bus_read_region_4((r)->res, (o), (d), (c)) : \
1129         BHND_BUS_READ_REGION_4( \
1130             device_get_parent(rman_get_device((r)->res)),       \
1131             rman_get_device((r)->res), (r), (o), (d), (c))
1132 #define bhnd_bus_write_4(r, o, v) \
1133     ((r)->direct) ? \
1134         bus_write_4((r)->res, (o), (v)) : \
1135         BHND_BUS_WRITE_4( \
1136             device_get_parent(rman_get_device((r)->res)),       \
1137             rman_get_device((r)->res), (r), (o), (v))
1138 #define bhnd_bus_write_multi_4(r, o, d, c) \
1139     ((r)->direct) ? \
1140         bus_write_multi_4((r)->res, (o), (d), (c)) : \
1141         BHND_BUS_WRITE_MULTI_4( \
1142             device_get_parent(rman_get_device((r)->res)),       \
1143             rman_get_device((r)->res), (r), (o), (d), (c))
1144 #define bhnd_bus_write_region_4(r, o, d, c) \
1145     ((r)->direct) ? \
1146         bus_write_region_4((r)->res, (o), (d), (c)) : \
1147         BHND_BUS_WRITE_REGION_4( \
1148             device_get_parent(rman_get_device((r)->res)),       \
1149             rman_get_device((r)->res), (r), (o), (d), (c))
1150 #define bhnd_bus_read_stream_4(r, o) \
1151     ((r)->direct) ? \
1152         bus_read_stream_4((r)->res, (o)) : \
1153         BHND_BUS_READ_STREAM_4( \
1154             device_get_parent(rman_get_device((r)->res)),       \
1155             rman_get_device((r)->res), (r), (o))
1156 #define bhnd_bus_read_multi_stream_4(r, o, d, c) \
1157     ((r)->direct) ? \
1158         bus_read_multi_stream_4((r)->res, (o), (d), (c)) : \
1159         BHND_BUS_READ_MULTI_STREAM_4( \
1160             device_get_parent(rman_get_device((r)->res)),       \
1161             rman_get_device((r)->res), (r), (o), (d), (c))
1162 #define bhnd_bus_read_region_stream_4(r, o, d, c) \
1163     ((r)->direct) ? \
1164         bus_read_region_stream_4((r)->res, (o), (d), (c)) : \
1165         BHND_BUS_READ_REGION_STREAM_4( \
1166             device_get_parent(rman_get_device((r)->res)),       \
1167             rman_get_device((r)->res), (r), (o), (d), (c))
1168 #define bhnd_bus_write_stream_4(r, o, v) \
1169     ((r)->direct) ? \
1170         bus_write_stream_4((r)->res, (o), (v)) : \
1171         BHND_BUS_WRITE_STREAM_4( \
1172             device_get_parent(rman_get_device((r)->res)),       \
1173             rman_get_device((r)->res), (r), (o), (v))
1174 #define bhnd_bus_write_multi_stream_4(r, o, d, c) \
1175     ((r)->direct) ? \
1176         bus_write_multi_stream_4((r)->res, (o), (d), (c)) : \
1177         BHND_BUS_WRITE_MULTI_STREAM_4( \
1178             device_get_parent(rman_get_device((r)->res)),       \
1179             rman_get_device((r)->res), (r), (o), (d), (c))
1180 #define bhnd_bus_write_region_stream_4(r, o, d, c) \
1181     ((r)->direct) ? \
1182         bus_write_region_stream_4((r)->res, (o), (d), (c)) : \
1183         BHND_BUS_WRITE_REGION_STREAM_4( \
1184             device_get_parent(rman_get_device((r)->res)),       \
1185             rman_get_device((r)->res), (r), (o), (d), (c))
1186 #define bhnd_bus_set_multi_4(r, o, v, c) \
1187     ((r)->direct) ? \
1188         bus_set_multi_4((r)->res, (o), (v), (c)) : \
1189         BHND_BUS_SET_MULTI_4( \
1190             device_get_parent(rman_get_device((r)->res)),       \
1191             rman_get_device((r)->res), (r), (o), (v), (c))
1192 #define bhnd_bus_set_region_4(r, o, v, c) \
1193     ((r)->direct) ? \
1194         bus_set_region_4((r)->res, (o), (v), (c)) : \
1195         BHND_BUS_SET_REGION_4( \
1196             device_get_parent(rman_get_device((r)->res)),       \
1197             rman_get_device((r)->res), (r), (o), (v), (c))
1198
1199 #endif /* _BHND_BHND_H_ */