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