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