]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bhnd/bhnd.h
Merge OpenSSL 1.0.2h.
[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_bus_if.h"
43
44 extern devclass_t bhnd_devclass;
45 extern devclass_t bhnd_hostb_devclass;
46 extern devclass_t bhnd_nvram_devclass;
47
48 /**
49  * bhnd child instance variables
50  */
51 enum bhnd_device_vars {
52         BHND_IVAR_VENDOR,       /**< Designer's JEP-106 manufacturer ID. */
53         BHND_IVAR_DEVICE,       /**< Part number */
54         BHND_IVAR_HWREV,        /**< Core revision */
55         BHND_IVAR_DEVICE_CLASS, /**< Core class (@sa bhnd_devclass_t) */
56         BHND_IVAR_VENDOR_NAME,  /**< Core vendor name */
57         BHND_IVAR_DEVICE_NAME,  /**< Core name */
58         BHND_IVAR_CORE_INDEX,   /**< Bus-assigned core number */
59         BHND_IVAR_CORE_UNIT,    /**< Bus-assigned core unit number,
60                                      assigned sequentially (starting at 0) for
61                                      each vendor/device pair. */
62 };
63
64 /**
65  * bhnd device probe priority bands.
66  */
67 enum {
68         BHND_PROBE_ROOT         = 0,    /**< Nexus or host bridge */
69         BHND_PROBE_BUS          = 1000, /**< Busses and bridges */
70         BHND_PROBE_CPU          = 2000, /**< CPU devices */
71         BHND_PROBE_INTERRUPT    = 3000, /**< Interrupt controllers. */
72         BHND_PROBE_TIMER        = 4000, /**< Timers and clocks. */
73         BHND_PROBE_RESOURCE     = 5000, /**< Resource discovery (including NVRAM/SPROM) */
74         BHND_PROBE_DEFAULT      = 6000, /**< Default device priority */
75 };
76
77 /**
78  * Constants defining fine grained ordering within a BHND_PROBE_* priority band.
79  * 
80  * Example:
81  * @code
82  * BHND_PROBE_BUS + BHND_PROBE_ORDER_FIRST
83  * @endcode
84  */
85 enum {
86         BHND_PROBE_ORDER_FIRST          = 0,
87         BHND_PROBE_ORDER_EARLY          = 25,
88         BHND_PROBE_ORDER_MIDDLE         = 50,
89         BHND_PROBE_ORDER_LATE           = 75,
90         BHND_PROBE_ORDER_LAST           = 100
91
92 };
93
94 /*
95  * Simplified accessors for bhnd device ivars
96  */
97 #define BHND_ACCESSOR(var, ivar, type) \
98         __BUS_ACCESSOR(bhnd, var, BHND, ivar, type)
99
100 BHND_ACCESSOR(vendor,           VENDOR,         uint16_t);
101 BHND_ACCESSOR(device,           DEVICE,         uint16_t);
102 BHND_ACCESSOR(hwrev,            HWREV,          uint8_t);
103 BHND_ACCESSOR(class,            DEVICE_CLASS,   bhnd_devclass_t);
104 BHND_ACCESSOR(vendor_name,      VENDOR_NAME,    const char *);
105 BHND_ACCESSOR(device_name,      DEVICE_NAME,    const char *);
106 BHND_ACCESSOR(core_index,       CORE_INDEX,     u_int);
107 BHND_ACCESSOR(core_unit,        CORE_UNIT,      int);
108
109 #undef  BHND_ACCESSOR
110
111 /**
112  * Chip Identification
113  * 
114  * This is read from the ChipCommon ID register; on earlier bhnd(4) devices
115  * where ChipCommon is unavailable, known values must be supplied.
116  */
117 struct bhnd_chipid {
118         uint16_t        chip_id;        /**< chip id (BHND_CHIPID_*) */
119         uint8_t         chip_rev;       /**< chip revision */
120         uint8_t         chip_pkg;       /**< chip package (BHND_PKGID_*) */
121         uint8_t         chip_type;      /**< chip type (BHND_CHIPTYPE_*) */
122
123         bhnd_addr_t     enum_addr;      /**< chip_type-specific enumeration
124                                           *  address; either the siba(4) base
125                                           *  core register block, or the bcma(4)
126                                           *  EROM core address. */
127
128         uint8_t         ncores;         /**< number of cores, if known. 0 if
129                                           *  not available. */
130 };
131
132 /**
133 * A bhnd(4) bus resource.
134
135 * This provides an abstract interface to per-core resources that may require
136 * bus-level remapping of address windows prior to access.
137 */
138 struct bhnd_resource {
139         struct resource *res;           /**< the system resource. */
140         bool             direct;        /**< false if the resource requires
141                                          *   bus window remapping before it
142                                          *   is MMIO accessible. */
143 };
144
145 /**
146  * A bhnd(4) core descriptor.
147  */
148 struct bhnd_core_info {
149         uint16_t        vendor;         /**< vendor */
150         uint16_t        device;         /**< device */
151         uint16_t        hwrev;          /**< hardware revision */
152         u_int           core_idx;       /**< bus-assigned core index */
153         int             unit;           /**< bus-assigned core unit */
154 };
155
156
157 /**
158  * A hardware revision match descriptor.
159  */
160 struct bhnd_hwrev_match {
161         uint16_t        start;  /**< first revision, or BHND_HWREV_INVALID
162                                              to match on any revision. */
163         uint16_t        end;    /**< last revision, or BHND_HWREV_INVALID
164                                              to match on any revision. */
165 };
166
167 /** 
168  * Wildcard hardware revision match descriptor.
169  */
170 #define BHND_HWREV_ANY          { BHND_HWREV_INVALID, BHND_HWREV_INVALID }
171 #define BHND_HWREV_IS_ANY(_m)   \
172         ((_m)->start == BHND_HWREV_INVALID && (_m)->end == BHND_HWREV_INVALID)
173
174 /**
175  * Hardware revision match descriptor for an inclusive range.
176  * 
177  * @param _start The first applicable hardware revision.
178  * @param _end The last applicable hardware revision, or BHND_HWREV_INVALID
179  * to match on any revision.
180  */
181 #define BHND_HWREV_RANGE(_start, _end)  { _start, _end }
182
183 /**
184  * Hardware revision match descriptor for a single revision.
185  * 
186  * @param _hwrev The hardware revision to match on.
187  */
188 #define BHND_HWREV_EQ(_hwrev)   BHND_HWREV_RANGE(_hwrev, _hwrev)
189
190 /**
191  * Hardware revision match descriptor for any revision equal to or greater
192  * than @p _start.
193  * 
194  * @param _start The first hardware revision to match on.
195  */
196 #define BHND_HWREV_GTE(_start)  BHND_HWREV_RANGE(_start, BHND_HWREV_INVALID)
197
198 /**
199  * Hardware revision match descriptor for any revision equal to or less
200  * than @p _end.
201  * 
202  * @param _end The last hardware revision to match on.
203  */
204 #define BHND_HWREV_LTE(_end)    BHND_HWREV_RANGE(0, _end)
205
206
207 /** A core match descriptor. */
208 struct bhnd_core_match {
209         uint16_t                vendor; /**< required JEP106 device vendor or BHND_MFGID_INVALID. */
210         uint16_t                device; /**< required core ID or BHND_COREID_INVALID */
211         struct bhnd_hwrev_match hwrev;  /**< matching revisions. */
212         bhnd_devclass_t         class;  /**< required class or BHND_DEVCLASS_INVALID */
213         int                     unit;   /**< required core unit, or -1 */
214 };
215
216 /**
217  * Core match descriptor matching against the given @p _vendor, @p _device,
218  * and @p _hwrev match descriptors.
219  */
220 #define BHND_CORE_MATCH(_vendor, _device, _hwrev)       \
221         { _vendor, _device, _hwrev, BHND_DEVCLASS_INVALID, -1 }
222
223 /** 
224  * Wildcard core match descriptor.
225  */
226 #define BHND_CORE_MATCH_ANY                     \
227         {                                       \
228                 .vendor = BHND_MFGID_INVALID,   \
229                 .device = BHND_COREID_INVALID,  \
230                 .hwrev = BHND_HWREV_ANY,        \
231                 .class = BHND_DEVCLASS_INVALID, \
232                 .unit = -1                      \
233         }
234
235 /**
236  * Device quirk table descriptor.
237  */
238 struct bhnd_device_quirk {
239         struct bhnd_hwrev_match  hwrev;         /**< applicable hardware revisions */
240         uint32_t                 quirks;        /**< quirk flags */
241 };
242 #define BHND_DEVICE_QUIRK_END           { BHND_HWREV_ANY, 0 }
243 #define BHND_DEVICE_QUIRK_IS_END(_q)    \
244         (BHND_HWREV_IS_ANY(&(_q)->hwrev) && (_q)->quirks == 0)
245
246 enum {
247         BHND_DF_ANY     = 0,
248         BHND_DF_HOSTB   = (1<<0)        /**< core is serving as the bus'
249                                           *  host bridge */
250 };
251
252 /** Device probe table descriptor */
253 struct bhnd_device {
254         const struct bhnd_core_match     core;                  /**< core match descriptor */ 
255         const char                      *desc;                  /**< device description, or NULL. */
256         const struct bhnd_device_quirk  *quirks_table;          /**< quirks table for this device, or NULL */
257         uint32_t                         device_flags;          /**< required BHND_DF_* flags */
258 };
259
260 #define _BHND_DEVICE(_device, _desc, _quirks, _flags, ...)      \
261         { BHND_CORE_MATCH(BHND_MFGID_BCM, BHND_COREID_ ## _device, \
262             BHND_HWREV_ANY), _desc, _quirks, _flags }
263
264 #define BHND_DEVICE(_device, _desc, _quirks, ...)       \
265         _BHND_DEVICE(_device, _desc, _quirks, ## __VA_ARGS__, 0)
266
267 #define BHND_DEVICE_END                 { BHND_CORE_MATCH_ANY, NULL, NULL, 0 }
268
269 const char                      *bhnd_vendor_name(uint16_t vendor);
270 const char                      *bhnd_port_type_name(bhnd_port_type port_type);
271
272 const char                      *bhnd_find_core_name(uint16_t vendor,
273                                      uint16_t device);
274 bhnd_devclass_t                  bhnd_find_core_class(uint16_t vendor,
275                                      uint16_t device);
276
277 const char                      *bhnd_core_name(const struct bhnd_core_info *ci);
278 bhnd_devclass_t                  bhnd_core_class(const struct bhnd_core_info *ci);
279
280
281 device_t                         bhnd_match_child(device_t dev,
282                                      const struct bhnd_core_match *desc);
283
284 device_t                         bhnd_find_child(device_t dev,
285                                      bhnd_devclass_t class, int unit);
286
287 const struct bhnd_core_info     *bhnd_match_core(
288                                      const struct bhnd_core_info *cores,
289                                      u_int num_cores,
290                                      const struct bhnd_core_match *desc);
291
292 const struct bhnd_core_info     *bhnd_find_core(
293                                      const struct bhnd_core_info *cores,
294                                      u_int num_cores, bhnd_devclass_t class);
295
296 bool                             bhnd_core_matches(
297                                      const struct bhnd_core_info *core,
298                                      const struct bhnd_core_match *desc);
299
300 bool                             bhnd_hwrev_matches(uint16_t hwrev,
301                                      const struct bhnd_hwrev_match *desc);
302
303 bool                             bhnd_device_matches(device_t dev,
304                                      const struct bhnd_core_match *desc);
305
306 const struct bhnd_device        *bhnd_device_lookup(device_t dev,
307                                      const struct bhnd_device *table,
308                                      size_t entry_size);
309
310 uint32_t                         bhnd_device_quirks(device_t dev,
311                                      const struct bhnd_device *table,
312                                      size_t entry_size);
313
314 struct bhnd_core_info            bhnd_get_core_info(device_t dev);
315
316
317 int                              bhnd_alloc_resources(device_t dev,
318                                      struct resource_spec *rs,
319                                      struct bhnd_resource **res);
320
321 void                             bhnd_release_resources(device_t dev,
322                                      const struct resource_spec *rs,
323                                      struct bhnd_resource **res);
324
325 struct bhnd_chipid               bhnd_parse_chipid(uint32_t idreg,
326                                      bhnd_addr_t enum_addr);
327
328 int                              bhnd_read_chipid(device_t dev,
329                                      struct resource_spec *rs,
330                                      bus_size_t chipc_offset,
331                                      struct bhnd_chipid *result);
332
333 void                             bhnd_set_custom_core_desc(device_t dev,
334                                      const char *name);
335 void                             bhnd_set_default_core_desc(device_t dev);
336
337
338 bool                             bhnd_bus_generic_is_hostb_device(device_t dev,
339                                      device_t child);
340 bool                             bhnd_bus_generic_is_hw_disabled(device_t dev,
341                                      device_t child);
342 bool                             bhnd_bus_generic_is_region_valid(device_t dev,
343                                      device_t child, bhnd_port_type type,
344                                      u_int port, u_int region);
345 int                              bhnd_bus_generic_read_nvram_var(device_t dev,
346                                      device_t child, const char *name,
347                                      void *buf, size_t *size);
348 const struct bhnd_chipid        *bhnd_bus_generic_get_chipid(device_t dev,
349                                      device_t child);
350 struct bhnd_resource            *bhnd_bus_generic_alloc_resource (device_t dev,
351                                      device_t child, int type, int *rid,
352                                      rman_res_t start, rman_res_t end,
353                                      rman_res_t count, u_int flags);
354 int                              bhnd_bus_generic_release_resource (device_t dev,
355                                      device_t child, int type, int rid,
356                                      struct bhnd_resource *r);
357 int                              bhnd_bus_generic_activate_resource (device_t dev,
358                                      device_t child, int type, int rid,
359                                      struct bhnd_resource *r);
360 int                              bhnd_bus_generic_deactivate_resource (device_t dev,
361                                      device_t child, int type, int rid,
362                                      struct bhnd_resource *r);
363
364
365
366 /**
367  * Return true if @p dev is serving as a host bridge for its parent bhnd
368  * bus.
369  *
370  * @param dev A bhnd bus child device.
371  */
372 static inline bool
373 bhnd_is_hostb_device(device_t dev) {
374         return (BHND_BUS_IS_HOSTB_DEVICE(device_get_parent(dev), dev));
375 }
376
377 /**
378  * Return true if the hardware components required by @p dev are known to be
379  * unpopulated or otherwise unusable.
380  *
381  * In some cases, enumerated devices may have pins that are left floating, or
382  * the hardware may otherwise be non-functional; this method allows a parent
383  * device to explicitly specify if a successfully enumerated @p dev should
384  * be disabled.
385  *
386  * @param dev A bhnd bus child device.
387  */
388 static inline bool
389 bhnd_is_hw_disabled(device_t dev) {
390         return (BHND_BUS_IS_HW_DISABLED(device_get_parent(dev), dev));
391 }
392
393 /**
394  * Allocate a resource from a device's parent bhnd(4) bus.
395  * 
396  * @param dev The device requesting resource ownership.
397  * @param type The type of resource to allocate. This may be any type supported
398  * by the standard bus APIs.
399  * @param rid The bus-specific handle identifying the resource being allocated.
400  * @param start The start address of the resource.
401  * @param end The end address of the resource.
402  * @param count The size of the resource.
403  * @param flags The flags for the resource to be allocated. These may be any
404  * values supported by the standard bus APIs.
405  * 
406  * To request the resource's default addresses, pass @p start and
407  * @p end values of @c 0 and @c ~0, respectively, and
408  * a @p count of @c 1.
409  * 
410  * @retval NULL The resource could not be allocated.
411  * @retval resource The allocated resource.
412  */
413 static inline struct bhnd_resource *
414 bhnd_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
415     rman_res_t end, rman_res_t count, u_int flags)
416 {
417         return BHND_BUS_ALLOC_RESOURCE(device_get_parent(dev), dev, type, rid,
418             start, end, count, flags);
419 }
420
421
422 /**
423  * Allocate a resource from a device's parent bhnd(4) bus, using the
424  * resource's default start, end, and count values.
425  * 
426  * @param dev The device requesting resource ownership.
427  * @param type The type of resource to allocate. This may be any type supported
428  * by the standard bus APIs.
429  * @param rid The bus-specific handle identifying the resource being allocated.
430  * @param flags The flags for the resource to be allocated. These may be any
431  * values supported by the standard bus APIs.
432  * 
433  * @retval NULL The resource could not be allocated.
434  * @retval resource The allocated resource.
435  */
436 static inline struct bhnd_resource *
437 bhnd_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
438 {
439         return bhnd_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
440 }
441
442 /**
443  * Activate a previously allocated bhnd resource.
444  *
445  * @param dev The device holding ownership of the allocated resource.
446  * @param type The type of the resource. 
447  * @param rid The bus-specific handle identifying the resource.
448  * @param r A pointer to the resource returned by bhnd_alloc_resource or
449  * BHND_BUS_ALLOC_RESOURCE.
450  * 
451  * @retval 0 success
452  * @retval non-zero an error occurred while activating the resource.
453  */
454 static inline int
455 bhnd_activate_resource(device_t dev, int type, int rid,
456    struct bhnd_resource *r)
457 {
458         return BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
459             rid, r);
460 }
461
462 /**
463  * Deactivate a previously activated bhnd resource.
464  *
465  * @param dev The device holding ownership of the activated resource.
466  * @param type The type of the resource. 
467  * @param rid The bus-specific handle identifying the resource.
468  * @param r A pointer to the resource returned by bhnd_alloc_resource or
469  * BHND_BUS_ALLOC_RESOURCE.
470  * 
471  * @retval 0 success
472  * @retval non-zero an error occurred while activating the resource.
473  */
474 static inline int
475 bhnd_deactivate_resource(device_t dev, int type, int rid,
476    struct bhnd_resource *r)
477 {
478         return BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
479             rid, r);
480 }
481
482 /**
483  * Free a resource allocated by bhnd_alloc_resource().
484  *
485  * @param dev The device holding ownership of the resource.
486  * @param type The type of the resource. 
487  * @param rid The bus-specific handle identifying the resource.
488  * @param r A pointer to the resource returned by bhnd_alloc_resource or
489  * BHND_ALLOC_RESOURCE.
490  * 
491  * @retval 0 success
492  * @retval non-zero an error occurred while activating the resource.
493  */
494 static inline int
495 bhnd_release_resource(device_t dev, int type, int rid,
496    struct bhnd_resource *r)
497 {
498         return BHND_BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
499             rid, r);
500 }
501
502 /**
503  * Return true if @p region_num is a valid region on @p port_num of
504  * @p type attached to @p dev.
505  *
506  * @param dev A bhnd bus child device.
507  * @param type The port type being queried.
508  * @param port_num The port number being queried.
509  * @param region_num The region number being queried.
510  */
511 static inline bool
512 bhnd_is_region_valid(device_t dev, bhnd_port_type type, u_int port_num,
513     u_int region_num)
514 {
515         return (BHND_BUS_IS_REGION_VALID(device_get_parent(dev), dev, type,
516             port_num, region_num));
517 }
518
519 /**
520  * Return the number of ports of type @p type attached to @p def.
521  *
522  * @param dev A bhnd bus child device.
523  * @param type The port type being queried.
524  */
525 static inline u_int
526 bhnd_get_port_count(device_t dev, bhnd_port_type type) {
527         return (BHND_BUS_GET_PORT_COUNT(device_get_parent(dev), dev, type));
528 }
529
530 /**
531  * Return the number of memory regions mapped to @p child @p port of
532  * type @p type.
533  *
534  * @param dev A bhnd bus child device.
535  * @param port The port number being queried.
536  * @param type The port type being queried.
537  */
538 static inline u_int
539 bhnd_get_region_count(device_t dev, bhnd_port_type type, u_int port) {
540         return (BHND_BUS_GET_REGION_COUNT(device_get_parent(dev), dev, type,
541             port));
542 }
543
544 /**
545  * Return the resource-ID for a memory region on the given device port.
546  *
547  * @param dev A bhnd bus child device.
548  * @param type The port type.
549  * @param port The port identifier.
550  * @param region The identifier of the memory region on @p port.
551  * 
552  * @retval int The RID for the given @p port and @p region on @p device.
553  * @retval -1 No such port/region found.
554  */
555 static inline int
556 bhnd_get_port_rid(device_t dev, bhnd_port_type type, u_int port, u_int region)
557 {
558         return BHND_BUS_GET_PORT_RID(device_get_parent(dev), dev, type, port,
559             region);
560 }
561
562 /**
563  * Decode a port / region pair on @p dev defined by @p rid.
564  *
565  * @param dev A bhnd bus child device.
566  * @param type The resource type.
567  * @param rid The resource identifier.
568  * @param[out] port_type The decoded port type.
569  * @param[out] port The decoded port identifier.
570  * @param[out] region The decoded region identifier.
571  *
572  * @retval 0 success
573  * @retval non-zero No matching port/region found.
574  */
575 static inline int
576 bhnd_decode_port_rid(device_t dev, int type, int rid, bhnd_port_type *port_type,
577     u_int *port, u_int *region)
578 {
579         return BHND_BUS_DECODE_PORT_RID(device_get_parent(dev), dev, type, rid,
580             port_type, port, region);
581 }
582
583 /**
584  * Get the address and size of @p region on @p port.
585  *
586  * @param dev A bhnd bus child device.
587  * @param port_type The port type.
588  * @param port The port identifier.
589  * @param region The identifier of the memory region on @p port.
590  * @param[out] region_addr The region's base address.
591  * @param[out] region_size The region's size.
592  *
593  * @retval 0 success
594  * @retval non-zero No matching port/region found.
595  */
596 static inline int
597 bhnd_get_region_addr(device_t dev, bhnd_port_type port_type, u_int port,
598     u_int region, bhnd_addr_t *region_addr, bhnd_size_t *region_size)
599 {
600         return BHND_BUS_GET_REGION_ADDR(device_get_parent(dev), dev, port_type,
601             port, region, region_addr, region_size);
602 }
603
604 /*
605  * bhnd bus-level equivalents of the bus_(read|write|set|barrier|...)
606  * macros (compatible with bhnd_resource).
607  *
608  * Generated with bhnd/tools/bus_macro.sh
609  */
610 #define bhnd_bus_barrier(r, o, l, f) \
611     ((r)->direct) ? \
612         bus_barrier((r)->res, (o), (l), (f)) : \
613         BHND_BUS_BARRIER(device_get_parent(rman_get_device((r)->res)),  \
614             rman_get_device((r)->res), (r), (o), (l), (f))
615 #define bhnd_bus_read_1(r, o) \
616     ((r)->direct) ? \
617         bus_read_1((r)->res, (o)) : \
618         BHND_BUS_READ_1(device_get_parent(rman_get_device((r)->res)),   \
619             rman_get_device((r)->res), (r), (o))
620 #define bhnd_bus_write_1(r, o, v) \
621     ((r)->direct) ? \
622         bus_write_1((r)->res, (o), (v)) : \
623         BHND_BUS_WRITE_1(device_get_parent(rman_get_device((r)->res)),  \
624             rman_get_device((r)->res), (r), (o), (v))
625 #define bhnd_bus_read_2(r, o) \
626     ((r)->direct) ? \
627         bus_read_2((r)->res, (o)) : \
628         BHND_BUS_READ_2(device_get_parent(rman_get_device((r)->res)),   \
629             rman_get_device((r)->res), (r), (o))
630 #define bhnd_bus_write_2(r, o, v) \
631     ((r)->direct) ? \
632         bus_write_2((r)->res, (o), (v)) : \
633         BHND_BUS_WRITE_2(device_get_parent(rman_get_device((r)->res)),  \
634             rman_get_device((r)->res), (r), (o), (v))
635 #define bhnd_bus_read_4(r, o) \
636     ((r)->direct) ? \
637         bus_read_4((r)->res, (o)) : \
638         BHND_BUS_READ_4(device_get_parent(rman_get_device((r)->res)),   \
639             rman_get_device((r)->res), (r), (o))
640 #define bhnd_bus_write_4(r, o, v) \
641     ((r)->direct) ? \
642         bus_write_4((r)->res, (o), (v)) : \
643         BHND_BUS_WRITE_4(device_get_parent(rman_get_device((r)->res)),  \
644             rman_get_device((r)->res), (r), (o), (v))
645
646 #endif /* _BHND_BHND_H_ */