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