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