2 * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/types.h>
34 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <machine/bus.h>
40 #include <machine/resource.h>
42 #include <dev/bhnd/cores/chipc/chipcreg.h>
47 /* BHND core device description table. */
48 static const struct bhnd_core_desc {
51 bhnd_devclass_t class;
53 } bhnd_core_descs[] = {
54 #define BHND_CDESC(_mfg, _cid, _cls, _desc) \
55 { BHND_MFGID_ ## _mfg, BHND_COREID_ ## _cid, \
56 BHND_DEVCLASS_ ## _cls, _desc }
58 BHND_CDESC(BCM, CC, CC, "ChipCommon I/O Controller"),
59 BHND_CDESC(BCM, ILINE20, OTHER, "iLine20 HPNA"),
60 BHND_CDESC(BCM, SRAM, RAM, "SRAM"),
61 BHND_CDESC(BCM, SDRAM, RAM, "SDRAM"),
62 BHND_CDESC(BCM, PCI, PCI, "PCI Bridge"),
63 BHND_CDESC(BCM, MIPS, CPU, "MIPS Core"),
64 BHND_CDESC(BCM, ENET, ENET_MAC, "Fast Ethernet MAC"),
65 BHND_CDESC(BCM, CODEC, OTHER, "V.90 Modem Codec"),
66 BHND_CDESC(BCM, USB, OTHER, "USB 1.1 Device/Host Controller"),
67 BHND_CDESC(BCM, ADSL, OTHER, "ADSL Core"),
68 BHND_CDESC(BCM, ILINE100, OTHER, "iLine100 HPNA"),
69 BHND_CDESC(BCM, IPSEC, OTHER, "IPsec Accelerator"),
70 BHND_CDESC(BCM, UTOPIA, OTHER, "UTOPIA ATM Core"),
71 BHND_CDESC(BCM, PCMCIA, PCCARD, "PCMCIA Bridge"),
72 BHND_CDESC(BCM, SOCRAM, RAM, "Internal Memory"),
73 BHND_CDESC(BCM, MEMC, MEMC, "MEMC SDRAM Controller"),
74 BHND_CDESC(BCM, OFDM, OTHER, "OFDM PHY"),
75 BHND_CDESC(BCM, EXTIF, OTHER, "External Interface"),
76 BHND_CDESC(BCM, D11, WLAN, "802.11 MAC/PHY/Radio"),
77 BHND_CDESC(BCM, APHY, WLAN_PHY, "802.11a PHY"),
78 BHND_CDESC(BCM, BPHY, WLAN_PHY, "802.11b PHY"),
79 BHND_CDESC(BCM, GPHY, WLAN_PHY, "802.11g PHY"),
80 BHND_CDESC(BCM, MIPS33, CPU, "MIPS 3302 Core"),
81 BHND_CDESC(BCM, USB11H, OTHER, "USB 1.1 Host Controller"),
82 BHND_CDESC(BCM, USB11D, OTHER, "USB 1.1 Device Core"),
83 BHND_CDESC(BCM, USB20H, OTHER, "USB 2.0 Host Controller"),
84 BHND_CDESC(BCM, USB20D, OTHER, "USB 2.0 Device Core"),
85 BHND_CDESC(BCM, SDIOH, OTHER, "SDIO Host Controller"),
86 BHND_CDESC(BCM, ROBO, OTHER, "RoboSwitch"),
87 BHND_CDESC(BCM, ATA100, OTHER, "Parallel ATA Controller"),
88 BHND_CDESC(BCM, SATAXOR, OTHER, "SATA DMA/XOR Controller"),
89 BHND_CDESC(BCM, GIGETH, ENET_MAC, "Gigabit Ethernet MAC"),
90 BHND_CDESC(BCM, PCIE, PCIE, "PCIe Bridge"),
91 BHND_CDESC(BCM, NPHY, WLAN_PHY, "802.11n 2x2 PHY"),
92 BHND_CDESC(BCM, SRAMC, MEMC, "SRAM Controller"),
93 BHND_CDESC(BCM, MINIMAC, OTHER, "MINI MAC/PHY"),
94 BHND_CDESC(BCM, ARM11, CPU, "ARM1176 CPU"),
95 BHND_CDESC(BCM, ARM7S, CPU, "ARM7TDMI-S CPU"),
96 BHND_CDESC(BCM, LPPHY, WLAN_PHY, "802.11a/b/g PHY"),
97 BHND_CDESC(BCM, PMU, PMU, "PMU"),
98 BHND_CDESC(BCM, SSNPHY, WLAN_PHY, "802.11n Single-Stream PHY"),
99 BHND_CDESC(BCM, SDIOD, OTHER, "SDIO Device Core"),
100 BHND_CDESC(BCM, ARMCM3, CPU, "ARM Cortex-M3 CPU"),
101 BHND_CDESC(BCM, HTPHY, WLAN_PHY, "802.11n 4x4 PHY"),
102 BHND_CDESC(BCM, MIPS74K, CPU, "MIPS74k CPU"),
103 BHND_CDESC(BCM, GMAC, ENET_MAC, "Gigabit MAC core"),
104 BHND_CDESC(BCM, DMEMC, MEMC, "DDR1/DDR2 Memory Controller"),
105 BHND_CDESC(BCM, PCIERC, OTHER, "PCIe Root Complex"),
106 BHND_CDESC(BCM, OCP, SOC_BRIDGE, "OCP to OCP Bridge"),
107 BHND_CDESC(BCM, SC, OTHER, "Shared Common Core"),
108 BHND_CDESC(BCM, AHB, SOC_BRIDGE, "OCP to AHB Bridge"),
109 BHND_CDESC(BCM, SPIH, OTHER, "SPI Host Controller"),
110 BHND_CDESC(BCM, I2S, OTHER, "I2S Digital Audio Interface"),
111 BHND_CDESC(BCM, DMEMS, MEMC, "SDR/DDR1 Memory Controller"),
112 BHND_CDESC(BCM, UBUS_SHIM, OTHER, "BCM6362/UBUS WLAN SHIM"),
113 BHND_CDESC(BCM, PCIE2, PCIE, "PCIe Bridge (Gen2)"),
115 BHND_CDESC(ARM, APB_BRIDGE, SOC_BRIDGE, "BP135 AMBA3 AXI to APB Bridge"),
116 BHND_CDESC(ARM, PL301, SOC_ROUTER, "PL301 AMBA3 Interconnect"),
117 BHND_CDESC(ARM, EROM, EROM, "PL366 Device Enumeration ROM"),
118 BHND_CDESC(ARM, OOB_ROUTER, OTHER, "PL367 OOB Interrupt Router"),
119 BHND_CDESC(ARM, AXI_UNMAPPED, OTHER, "Unmapped Address Ranges"),
121 BHND_CDESC(BCM, 4706_CC, CC, "ChipCommon I/O Controller"),
122 BHND_CDESC(BCM, NS_PCIE2, PCIE, "PCIe Bridge (Gen2)"),
123 BHND_CDESC(BCM, NS_DMA, OTHER, "DMA engine"),
124 BHND_CDESC(BCM, NS_SDIO, OTHER, "SDIO 3.0 Host Controller"),
125 BHND_CDESC(BCM, NS_USB20H, OTHER, "USB 2.0 Host Controller"),
126 BHND_CDESC(BCM, NS_USB30H, OTHER, "USB 3.0 Host Controller"),
127 BHND_CDESC(BCM, NS_A9JTAG, OTHER, "ARM Cortex A9 JTAG Interface"),
128 BHND_CDESC(BCM, NS_DDR23_MEMC, MEMC, "Denali DDR2/DD3 Memory Controller"),
129 BHND_CDESC(BCM, NS_ROM, NVRAM, "System ROM"),
130 BHND_CDESC(BCM, NS_NAND, NVRAM, "NAND Flash Controller"),
131 BHND_CDESC(BCM, NS_QSPI, NVRAM, "QSPI Flash Controller"),
132 BHND_CDESC(BCM, NS_CC_B, CC_B, "ChipCommon B Auxiliary I/O Controller"),
133 BHND_CDESC(BCM, 4706_SOCRAM, RAM, "Internal Memory"),
134 BHND_CDESC(BCM, IHOST_ARMCA9, CPU, "ARM Cortex A9 CPU"),
135 BHND_CDESC(BCM, 4706_GMAC_CMN, ENET, "Gigabit MAC (Common)"),
136 BHND_CDESC(BCM, 4706_GMAC, ENET_MAC, "Gigabit MAC"),
137 BHND_CDESC(BCM, AMEMC, MEMC, "Denali DDR1/DDR2 Memory Controller"),
140 /* Derived from inspection of the BCM4331 cores that provide PrimeCell
141 * IDs. Due to lack of documentation, the surmised device name/purpose
142 * provided here may be incorrect. */
143 { BHND_MFGID_ARM, BHND_PRIMEID_EROM, BHND_DEVCLASS_OTHER,
144 "PL364 Device Enumeration ROM" },
145 { BHND_MFGID_ARM, BHND_PRIMEID_SWRAP, BHND_DEVCLASS_OTHER,
146 "PL368 Device Management Interface" },
147 { BHND_MFGID_ARM, BHND_PRIMEID_MWRAP, BHND_DEVCLASS_OTHER,
148 "PL369 Device Management Interface" },
154 * Return the name for a given JEP106 manufacturer ID.
156 * @param vendor A JEP106 Manufacturer ID, including the non-standard ARM 4-bit
157 * JEP106 continuation code.
160 bhnd_vendor_name(uint16_t vendor)
167 case BHND_MFGID_MIPS:
175 * Return the name of a port type.
178 bhnd_port_type_name(bhnd_port_type port_type)
181 case BHND_PORT_DEVICE:
183 case BHND_PORT_BRIDGE:
185 case BHND_PORT_AGENT:
193 static const struct bhnd_core_desc *
194 bhnd_find_core_desc(uint16_t vendor, uint16_t device)
196 for (u_int i = 0; bhnd_core_descs[i].desc != NULL; i++) {
197 if (bhnd_core_descs[i].vendor != vendor)
200 if (bhnd_core_descs[i].device != device)
203 return (&bhnd_core_descs[i]);
210 * Return a human-readable name for a BHND core.
212 * @param vendor The core designer's JEDEC-106 Manufacturer ID
213 * @param device The core identifier.
216 bhnd_find_core_name(uint16_t vendor, uint16_t device)
218 const struct bhnd_core_desc *desc;
220 if ((desc = bhnd_find_core_desc(vendor, device)) == NULL)
227 * Return the device class for a BHND core.
229 * @param vendor The core designer's JEDEC-106 Manufacturer ID
230 * @param device The core identifier.
233 bhnd_find_core_class(uint16_t vendor, uint16_t device)
235 const struct bhnd_core_desc *desc;
237 if ((desc = bhnd_find_core_desc(vendor, device)) == NULL)
238 return (BHND_DEVCLASS_OTHER);
244 * Return a human-readable name for a BHND core.
246 * @param ci The core's info record.
249 bhnd_core_name(const struct bhnd_core_info *ci)
251 return bhnd_find_core_name(ci->vendor, ci->device);
255 * Return the device class for a BHND core.
257 * @param ci The core's info record.
260 bhnd_core_class(const struct bhnd_core_info *ci)
262 return bhnd_find_core_class(ci->vendor, ci->device);
266 * Initialize a core info record with data from from a bhnd-attached @p dev.
268 * @param dev A bhnd device.
269 * @param core The record to be initialized.
271 struct bhnd_core_info
272 bhnd_get_core_info(device_t dev) {
273 return (struct bhnd_core_info) {
274 .vendor = bhnd_get_vendor(dev),
275 .device = bhnd_get_device(dev),
276 .hwrev = bhnd_get_hwrev(dev),
277 .core_idx = bhnd_get_core_index(dev),
278 .unit = bhnd_get_core_unit(dev)
283 * Find a @p class child device with @p unit on @p dev.
285 * @param parent The bhnd-compatible bus to be searched.
286 * @param class The device class to match on.
287 * @param unit The device unit number; specify -1 to return the first match
288 * regardless of unit number.
290 * @retval device_t if a matching child device is found.
291 * @retval NULL if no matching child device is found.
294 bhnd_find_child(device_t dev, bhnd_devclass_t class, int unit)
296 struct bhnd_core_match md = {
297 .vendor = BHND_MFGID_INVALID,
298 .device = BHND_COREID_INVALID,
299 .hwrev.start = BHND_HWREV_INVALID,
300 .hwrev.end = BHND_HWREV_INVALID,
305 return bhnd_match_child(dev, &md);
309 * Find the first child device on @p dev that matches @p desc.
311 * @param parent The bhnd-compatible bus to be searched.
312 * @param desc A match descriptor.
314 * @retval device_t if a matching child device is found.
315 * @retval NULL if no matching child device is found.
318 bhnd_match_child(device_t dev, const struct bhnd_core_match *desc)
325 error = device_get_children(dev, &devlistp, &devcnt);
330 for (int i = 0; i < devcnt; i++) {
331 device_t dev = devlistp[i];
332 if (bhnd_device_matches(dev, desc)) {
339 free(devlistp, M_TEMP);
344 * Find the first core in @p cores that matches @p desc.
346 * @param cores The table to search.
347 * @param num_cores The length of @p cores.
348 * @param desc A match descriptor.
350 * @retval bhnd_core_info if a matching core is found.
351 * @retval NULL if no matching core is found.
353 const struct bhnd_core_info *
354 bhnd_match_core(const struct bhnd_core_info *cores, u_int num_cores,
355 const struct bhnd_core_match *desc)
357 for (u_int i = 0; i < num_cores; i++) {
358 if (bhnd_core_matches(&cores[i], desc))
367 * Find the first core in @p cores with the given @p class.
369 * @param cores The table to search.
370 * @param num_cores The length of @p cores.
371 * @param desc A match descriptor.
373 * @retval bhnd_core_info if a matching core is found.
374 * @retval NULL if no matching core is found.
376 const struct bhnd_core_info *
377 bhnd_find_core(const struct bhnd_core_info *cores, u_int num_cores,
378 bhnd_devclass_t class)
380 struct bhnd_core_match md = {
381 .vendor = BHND_MFGID_INVALID,
382 .device = BHND_COREID_INVALID,
383 .hwrev.start = BHND_HWREV_INVALID,
384 .hwrev.end = BHND_HWREV_INVALID,
389 return bhnd_match_core(cores, num_cores, &md);
393 * Return true if the @p core matches @p desc.
395 * @param core A bhnd core descriptor.
396 * @param desc A match descriptor to compare against @p core.
398 * @retval true if @p core matches @p match
399 * @retval false if @p core does not match @p match.
402 bhnd_core_matches(const struct bhnd_core_info *core,
403 const struct bhnd_core_match *desc)
405 if (desc->vendor != BHND_MFGID_INVALID &&
406 desc->vendor != core->vendor)
409 if (desc->device != BHND_COREID_INVALID &&
410 desc->device != core->device)
413 if (desc->unit != -1 && desc->unit != core->unit)
416 if (!bhnd_hwrev_matches(core->hwrev, &desc->hwrev))
419 if (desc->hwrev.end != BHND_HWREV_INVALID &&
420 desc->hwrev.end < core->hwrev)
423 if (desc->class != BHND_DEVCLASS_INVALID &&
424 desc->class != bhnd_core_class(core))
431 * Return true if the @p hwrev matches @p desc.
433 * @param hwrev A bhnd hardware revision.
434 * @param desc A match descriptor to compare against @p core.
436 * @retval true if @p hwrev matches @p match
437 * @retval false if @p hwrev does not match @p match.
440 bhnd_hwrev_matches(uint16_t hwrev, const struct bhnd_hwrev_match *desc)
442 if (desc->start != BHND_HWREV_INVALID &&
446 if (desc->end != BHND_HWREV_INVALID &&
454 * Return true if the @p dev matches @p desc.
456 * @param dev A bhnd device.
457 * @param desc A match descriptor to compare against @p dev.
459 * @retval true if @p dev matches @p match
460 * @retval false if @p dev does not match @p match.
463 bhnd_device_matches(device_t dev, const struct bhnd_core_match *desc)
465 struct bhnd_core_info ci = {
466 .vendor = bhnd_get_vendor(dev),
467 .device = bhnd_get_device(dev),
468 .unit = bhnd_get_core_unit(dev),
469 .hwrev = bhnd_get_hwrev(dev)
472 return bhnd_core_matches(&ci, desc);
476 * Search @p table for an entry matching @p dev.
478 * @param dev A bhnd device to match against @p table.
479 * @param table The device table to search.
480 * @param entry_size The @p table entry size, in bytes.
482 * @retval bhnd_device the first matching device, if any.
483 * @retval NULL if no matching device is found in @p table.
485 const struct bhnd_device *
486 bhnd_device_lookup(device_t dev, const struct bhnd_device *table,
489 const struct bhnd_device *entry;
491 for (entry = table; entry->desc != NULL; entry =
492 (const struct bhnd_device *) ((const char *) entry + entry_size))
494 /* match core info */
495 if (!bhnd_device_matches(dev, &entry->core))
498 /* match device flags */
499 if (entry->device_flags & BHND_DF_HOSTB) {
500 if (!bhnd_is_hostb_device(dev))
513 * Scan @p table for all quirk flags applicable to @p dev.
515 * @param dev A bhnd device to match against @p table.
516 * @param table The device table to search.
517 * @param entry_size The @p table entry size, in bytes.
519 * @return returns all matching quirk flags.
522 bhnd_device_quirks(device_t dev, const struct bhnd_device *table,
525 const struct bhnd_device *dent;
526 const struct bhnd_device_quirk *qtable, *qent;
530 hwrev = bhnd_get_hwrev(dev);
533 /* Find the quirk table */
534 if ((dent = bhnd_device_lookup(dev, table, entry_size)) == NULL) {
535 /* This is almost certainly a (caller) implementation bug */
536 device_printf(dev, "quirk lookup did not match any device\n");
540 /* Quirks aren't a mandatory field */
541 if ((qtable = dent->quirks_table) == NULL)
544 /* Collect matching quirk entries */
545 for (qent = qtable; !BHND_DEVICE_QUIRK_IS_END(qent); qent++) {
546 if (bhnd_hwrev_matches(hwrev, &qent->hwrev))
547 quirks |= qent->quirks;
555 * Allocate bhnd(4) resources defined in @p rs from a parent bus.
557 * @param dev The device requesting ownership of the resources.
558 * @param rs A standard bus resource specification. This will be updated
559 * with the allocated resource's RIDs.
560 * @param res On success, the allocated bhnd resources.
563 * @retval non-zero if allocation of any non-RF_OPTIONAL resource fails,
564 * all allocated resources will be released and a regular
565 * unix error code will be returned.
568 bhnd_alloc_resources(device_t dev, struct resource_spec *rs,
569 struct bhnd_resource **res)
571 /* Initialize output array */
572 for (u_int i = 0; rs[i].type != -1; i++)
575 for (u_int i = 0; rs[i].type != -1; i++) {
576 res[i] = bhnd_alloc_resource_any(dev, rs[i].type, &rs[i].rid,
579 /* Clean up all allocations on failure */
580 if (res[i] == NULL && !(rs[i].flags & RF_OPTIONAL)) {
581 bhnd_release_resources(dev, rs, res);
590 * Release bhnd(4) resources defined in @p rs from a parent bus.
592 * @param dev The device that owns the resources.
593 * @param rs A standard bus resource specification previously initialized
594 * by @p bhnd_alloc_resources.
595 * @param res The bhnd resources to be released.
598 bhnd_release_resources(device_t dev, const struct resource_spec *rs,
599 struct bhnd_resource **res)
601 for (u_int i = 0; rs[i].type != -1; i++) {
605 bhnd_release_resource(dev, rs[i].type, rs[i].rid, res[i]);
611 * Parse the CHIPC_ID_* fields from the ChipCommon CHIPC_ID
612 * register, returning its bhnd_chipid representation.
614 * @param idreg The CHIPC_ID register value.
615 * @param enum_addr The enumeration address to include in the result.
618 * On early siba(4) devices, the ChipCommon core does not provide
619 * a valid CHIPC_ID_NUMCORE field. On these ChipCommon revisions
620 * (see CHIPC_NCORES_MIN_HWREV()), this function will parse and return
621 * an invalid `ncores` value.
624 bhnd_parse_chipid(uint32_t idreg, bhnd_addr_t enum_addr)
626 struct bhnd_chipid result;
628 /* Fetch the basic chip info */
629 result.chip_id = CHIPC_GET_ATTR(idreg, ID_CHIP);
630 result.chip_pkg = CHIPC_GET_ATTR(idreg, ID_PKG);
631 result.chip_rev = CHIPC_GET_ATTR(idreg, ID_REV);
632 result.chip_type = CHIPC_GET_ATTR(idreg, ID_BUS);
633 result.ncores = CHIPC_GET_ATTR(idreg, ID_NUMCORE);
635 result.enum_addr = enum_addr;
641 * Allocate the resource defined by @p rs via @p dev, use it
642 * to read the ChipCommon ID register relative to @p chipc_offset,
643 * then release the resource.
645 * @param dev The device owning @p rs.
646 * @param rs A resource spec that encompasses the ChipCommon register block.
647 * @param chipc_offset The offset of the ChipCommon registers within @p rs.
648 * @param[out] result the chip identification data.
651 * @retval non-zero if the ChipCommon identification data could not be read.
654 bhnd_read_chipid(device_t dev, struct resource_spec *rs,
655 bus_size_t chipc_offset, struct bhnd_chipid *result)
657 struct resource *res;
659 int error, rid, rtype;
661 /* Allocate the ChipCommon window resource and fetch the chipid data */
664 res = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE);
667 "failed to allocate bhnd chipc resource\n");
671 /* Fetch the basic chip info */
672 reg = bus_read_4(res, chipc_offset + CHIPC_ID);
673 *result = bhnd_parse_chipid(reg, 0x0);
675 /* Fetch the enum base address */
677 switch (result->chip_type) {
678 case BHND_CHIPTYPE_SIBA:
679 result->enum_addr = BHND_DEFAULT_CHIPC_ADDR;
681 case BHND_CHIPTYPE_BCMA:
682 case BHND_CHIPTYPE_BCMA_ALT:
683 result->enum_addr = bus_read_4(res, chipc_offset +
686 case BHND_CHIPTYPE_UBUS:
687 device_printf(dev, "unsupported ubus/bcm63xx chip type");
691 device_printf(dev, "unknown chip type %hhu\n",
699 bus_release_resource(dev, rtype, rid, res);
704 * Using the bhnd(4) bus-level core information and a custom core name,
705 * populate @p dev's device description.
707 * @param dev A bhnd-bus attached device.
708 * @param dev_name The core's name (e.g. "SDIO Device Core")
711 bhnd_set_custom_core_desc(device_t dev, const char *dev_name)
713 const char *vendor_name;
716 vendor_name = bhnd_get_vendor_name(dev);
717 asprintf(&desc, M_BHND, "%s %s, rev %hhu", vendor_name, dev_name,
718 bhnd_get_hwrev(dev));
721 device_set_desc_copy(dev, desc);
724 device_set_desc(dev, dev_name);
729 * Using the bhnd(4) bus-level core information, populate @p dev's device
732 * @param dev A bhnd-bus attached device.
735 bhnd_set_default_core_desc(device_t dev)
737 bhnd_set_custom_core_desc(dev, bhnd_get_device_name(dev));
741 * Helper function for implementing BHND_BUS_IS_HOSTB_DEVICE().
743 * If a parent device is available, this implementation delegates the
744 * request to the BHND_BUS_IS_HOSTB_DEVICE() method on the parent of @p dev.
746 * If no parent device is available (i.e. on a the bus root), false
750 bhnd_bus_generic_is_hostb_device(device_t dev, device_t child) {
751 if (device_get_parent(dev) != NULL)
752 return (BHND_BUS_IS_HOSTB_DEVICE(device_get_parent(dev),
759 * Helper function for implementing BHND_BUS_IS_HW_DISABLED().
761 * If a parent device is available, this implementation delegates the
762 * request to the BHND_BUS_IS_HW_DISABLED() method on the parent of @p dev.
764 * If no parent device is available (i.e. on a the bus root), the hardware
765 * is assumed to be usable and false is returned.
768 bhnd_bus_generic_is_hw_disabled(device_t dev, device_t child)
770 if (device_get_parent(dev) != NULL)
771 return (BHND_BUS_IS_HW_DISABLED(device_get_parent(dev), child));
777 * Helper function for implementing BHND_BUS_GET_CHIPID().
779 * This implementation delegates the request to the BHND_BUS_GET_CHIPID()
780 * method on the parent of @p dev. If no parent exists, the implementation
783 const struct bhnd_chipid *
784 bhnd_bus_generic_get_chipid(device_t dev, device_t child)
786 if (device_get_parent(dev) != NULL)
787 return (BHND_BUS_GET_CHIPID(device_get_parent(dev), child));
789 panic("missing BHND_BUS_GET_CHIPID()");
793 * Helper function for implementing BHND_BUS_ALLOC_RESOURCE().
795 * This implementation of BHND_BUS_ALLOC_RESOURCE() delegates allocation
796 * of the underlying resource to BUS_ALLOC_RESOURCE(), and activation
797 * to @p dev's BHND_BUS_ACTIVATE_RESOURCE().
799 struct bhnd_resource *
800 bhnd_bus_generic_alloc_resource(device_t dev, device_t child, int type,
801 int *rid, rman_res_t start, rman_res_t end, rman_res_t count,
804 struct bhnd_resource *br;
805 struct resource *res;
811 /* Allocate the real bus resource (without activating it) */
812 res = BUS_ALLOC_RESOURCE(dev, child, type, rid, start, end, count,
813 (flags & ~RF_ACTIVE));
817 /* Allocate our bhnd resource wrapper. */
818 br = malloc(sizeof(struct bhnd_resource), M_BHND, M_NOWAIT);
825 /* Attempt activation */
826 if (flags & RF_ACTIVE) {
827 error = BHND_BUS_ACTIVATE_RESOURCE(dev, child, type, *rid, br);
836 BUS_RELEASE_RESOURCE(dev, child, type, *rid, res);
843 * Helper function for implementing BHND_BUS_RELEASE_RESOURCE().
845 * This implementation of BHND_BUS_RELEASE_RESOURCE() delegates release of
846 * the backing resource to BUS_RELEASE_RESOURCE().
849 bhnd_bus_generic_release_resource(device_t dev, device_t child, int type,
850 int rid, struct bhnd_resource *r)
854 if ((error = BUS_RELEASE_RESOURCE(dev, child, type, rid, r->res)))
863 * Helper function for implementing BHND_BUS_ACTIVATE_RESOURCE().
865 * This implementation of BHND_BUS_ACTIVATE_RESOURCE() simply calls the
866 * BHND_BUS_ACTIVATE_RESOURCE() method of the parent of @p dev.
869 bhnd_bus_generic_activate_resource(device_t dev, device_t child, int type,
870 int rid, struct bhnd_resource *r)
872 /* Try to delegate to the parent */
873 if (device_get_parent(dev) != NULL)
874 return (BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev),
875 child, type, rid, r));
881 * Helper function for implementing BHND_BUS_DEACTIVATE_RESOURCE().
883 * This implementation of BHND_BUS_ACTIVATE_RESOURCE() simply calls the
884 * BHND_BUS_ACTIVATE_RESOURCE() method of the parent of @p dev.
887 bhnd_bus_generic_deactivate_resource(device_t dev, device_t child,
888 int type, int rid, struct bhnd_resource *r)
890 if (device_get_parent(dev) != NULL)
891 return (BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev),
892 child, type, rid, r));