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