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