2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
3 * Copyright (c) 2017 The FreeBSD Foundation
6 * Portions of this software were developed by Landon Fuller
7 * under sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGES.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * PCI-specific implementation for the BHNDB bridge driver.
40 * Provides support for bridging from a PCI parent bus to a BHND-compatible
41 * bus (e.g. bcma or siba) via a Broadcom PCI core configured in end-point
44 * This driver handles all initial generic host-level PCI interactions with a
45 * PCI/PCIe bridge core operating in endpoint mode. Once the bridged bhnd(4)
46 * bus has been enumerated, this driver works in tandem with a core-specific
47 * bhnd_pci_hostb driver to manage the PCI core.
50 #include <sys/param.h>
51 #include <sys/kernel.h>
53 #include <sys/limits.h>
54 #include <sys/malloc.h>
55 #include <sys/module.h>
56 #include <sys/systm.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
61 #include <dev/bhnd/bhnd.h>
62 #include <dev/bhnd/bhndreg.h>
64 #include <dev/bhnd/bhnd_erom.h>
65 #include <dev/bhnd/bhnd_eromvar.h>
67 #include <dev/bhnd/siba/sibareg.h>
69 #include <dev/bhnd/cores/pci/bhnd_pcireg.h>
71 #include "bhnd_pwrctl_hostb_if.h"
73 #include "bhndb_pcireg.h"
74 #include "bhndb_pcivar.h"
75 #include "bhndb_private.h"
78 struct bhndb_pci_probe;
80 static int bhndb_pci_alloc_msi(struct bhndb_pci_softc *sc,
83 static int bhndb_pci_add_children(struct bhndb_pci_softc *sc);
85 static bhnd_devclass_t bhndb_expected_pci_devclass(device_t dev);
86 static bool bhndb_is_pcie_attached(device_t dev);
88 static int bhndb_enable_pci_clocks(device_t dev);
89 static int bhndb_disable_pci_clocks(device_t dev);
91 static int bhndb_pci_compat_setregwin(device_t dev,
92 device_t pci_dev, const struct bhndb_regwin *,
94 static int bhndb_pci_fast_setregwin(device_t dev, device_t pci_dev,
95 const struct bhndb_regwin *, bhnd_addr_t);
97 static void bhndb_pci_write_core(struct bhndb_pci_softc *sc,
98 bus_size_t offset, uint32_t value, u_int width);
99 static uint32_t bhndb_pci_read_core(struct bhndb_pci_softc *sc,
100 bus_size_t offset, u_int width);
102 static int bhndb_pci_srsh_pi_war(struct bhndb_pci_softc *sc,
103 struct bhndb_pci_probe *probe);
105 static bus_addr_t bhndb_pci_sprom_addr(struct bhndb_pci_softc *sc);
106 static bus_size_t bhndb_pci_sprom_size(struct bhndb_pci_softc *sc);
108 static int bhndb_pci_probe_alloc(struct bhndb_pci_probe **probe,
109 device_t dev, bhnd_devclass_t pci_devclass);
110 static void bhndb_pci_probe_free(struct bhndb_pci_probe *probe);
112 static int bhndb_pci_probe_copy_core_table(
113 struct bhndb_pci_probe *probe,
114 struct bhnd_core_info **cores, u_int *ncores);
115 static void bhndb_pci_probe_free_core_table(
116 struct bhnd_core_info *cores);
118 static void bhndb_pci_probe_write(struct bhndb_pci_probe *sc,
119 bhnd_addr_t addr, bhnd_size_t offset,
120 uint32_t value, u_int width);
121 static uint32_t bhndb_pci_probe_read(struct bhndb_pci_probe *sc,
122 bhnd_addr_t addr, bhnd_size_t offset, u_int width);
124 static void bhndb_pci_eio_init(struct bhndb_pci_eio *eio,
125 struct bhndb_pci_probe *probe);
126 static int bhndb_pci_eio_map(struct bhnd_erom_io *eio,
127 bhnd_addr_t addr, bhnd_size_t size);
128 static int bhndb_pci_eio_tell(struct bhnd_erom_io *eio,
129 bhnd_addr_t *addr, bhnd_size_t *size);
130 static uint32_t bhndb_pci_eio_read(struct bhnd_erom_io *eio,
131 bhnd_size_t offset, u_int width);
133 #define BHNDB_PCI_MSI_COUNT 1
135 static struct bhndb_pci_quirk bhndb_pci_quirks[];
136 static struct bhndb_pci_quirk bhndb_pcie_quirks[];
137 static struct bhndb_pci_quirk bhndb_pcie2_quirks[];
139 static struct bhndb_pci_core bhndb_pci_cores[] = {
140 BHNDB_PCI_CORE(PCI, bhndb_pci_quirks),
141 BHNDB_PCI_CORE(PCIE, bhndb_pcie_quirks),
142 BHNDB_PCI_CORE(PCIE2, bhndb_pcie2_quirks),
146 /* bhndb_pci erom I/O instance state */
147 struct bhndb_pci_eio {
148 struct bhnd_erom_io eio;
149 bool mapped; /**< true if a valid mapping exists */
150 bhnd_addr_t addr; /**< mapped address */
151 bhnd_size_t size; /**< mapped size */
152 struct bhndb_pci_probe *probe; /**< borrowed probe reference */
156 * Provides early bus access to the bridged device's cores and core enumeration
159 * May be safely used during probe or early device attach, prior to calling
162 struct bhndb_pci_probe {
163 device_t dev; /**< bridge device */
164 device_t pci_dev; /**< parent PCI device */
165 struct bhnd_chipid cid; /**< chip identification */
166 struct bhnd_core_info hostb_core; /**< PCI bridge core info */
168 struct bhndb_pci_eio erom_io; /**< erom I/O instance */
169 bhnd_erom_class_t *erom_class; /**< probed erom class */
170 bhnd_erom_t *erom; /**< erom parser */
171 struct bhnd_core_info *cores; /**< erom-owned core table */
172 u_int ncores; /**< number of cores */
174 const struct bhndb_regwin *m_win; /**< mapped register window, or NULL if no mapping */
175 struct resource *m_res; /**< resource containing the register window, or NULL if no window mapped */
176 bhnd_addr_t m_target; /**< base address mapped by m_win */
177 bhnd_addr_t m_addr; /**< mapped address */
178 bhnd_size_t m_size; /**< mapped size */
179 bool m_valid; /**< true if a valid mapping exists, false otherwise */
181 struct bhndb_host_resources *hr; /**< backing host resources */
185 static struct bhndb_pci_quirk bhndb_pci_quirks[] = {
186 /* Backplane interrupt flags must be routed via siba-specific
187 * SIBA_CFG0_INTVEC configuration register; the BHNDB_PCI_INT_MASK
188 * PCI configuration register is unsupported. */
189 {{ BHND_MATCH_CHIP_TYPE (SIBA) },
190 { BHND_MATCH_CORE_REV (HWREV_LTE(5)) },
191 BHNDB_PCI_QUIRK_SIBA_INTVEC },
193 /* All PCI core revisions require the SRSH work-around */
194 BHNDB_PCI_QUIRK(HWREV_ANY, BHNDB_PCI_QUIRK_SRSH_WAR),
198 static struct bhndb_pci_quirk bhndb_pcie_quirks[] = {
199 /* All PCIe-G1 core revisions require the SRSH work-around */
200 BHNDB_PCI_QUIRK(HWREV_ANY, BHNDB_PCI_QUIRK_SRSH_WAR),
204 static struct bhndb_pci_quirk bhndb_pcie2_quirks[] = {
209 * Return the device table entry for @p ci, or NULL if none.
211 static struct bhndb_pci_core *
212 bhndb_pci_find_core(struct bhnd_core_info *ci)
214 for (size_t i = 0; !BHNDB_PCI_IS_CORE_END(&bhndb_pci_cores[i]); i++) {
215 struct bhndb_pci_core *entry = &bhndb_pci_cores[i];
217 if (bhnd_core_matches(ci, &entry->match))
225 * Return all quirk flags for the given @p cid and @p ci.
228 bhndb_pci_get_core_quirks(struct bhnd_chipid *cid, struct bhnd_core_info *ci)
230 struct bhndb_pci_core *entry;
231 struct bhndb_pci_quirk *qtable;
237 if ((entry = bhndb_pci_find_core(ci)) == NULL)
241 if ((qtable = entry->quirks) == NULL)
244 for (size_t i = 0; !BHNDB_PCI_IS_QUIRK_END(&qtable[i]); i++) {
245 struct bhndb_pci_quirk *q = &qtable[i];
247 if (!bhnd_chip_matches(cid, &q->chip_desc))
250 if (!bhnd_core_matches(ci, &q->core_desc))
260 * Default bhndb_pci implementation of device_probe().
262 * Verifies that the parent is a PCI/PCIe device.
265 bhndb_pci_probe(device_t dev)
267 struct bhndb_pci_probe *probe;
268 struct bhndb_pci_core *entry;
269 bhnd_devclass_t hostb_devclass;
270 device_t parent, parent_bus;
271 devclass_t pci, bus_devclass;
276 /* Our parent must be a PCI/PCIe device. */
277 pci = devclass_find("pci");
278 parent = device_get_parent(dev);
279 parent_bus = device_get_parent(parent);
280 if (parent_bus == NULL)
283 /* The bus device class may inherit from 'pci' */
284 for (bus_devclass = device_get_devclass(parent_bus);
285 bus_devclass != NULL;
286 bus_devclass = devclass_get_parent(bus_devclass))
288 if (bus_devclass == pci)
292 if (bus_devclass != pci)
296 if ((error = bhndb_enable_pci_clocks(dev)))
299 /* Identify the chip and enumerate the bridged cores */
300 hostb_devclass = bhndb_expected_pci_devclass(dev);
301 if ((error = bhndb_pci_probe_alloc(&probe, dev, hostb_devclass)))
304 /* Look for a matching core table entry */
305 if ((entry = bhndb_pci_find_core(&probe->hostb_core)) == NULL) {
310 device_set_desc(dev, "PCI-BHND bridge");
313 error = BUS_PROBE_DEFAULT;
317 bhndb_pci_probe_free(probe);
319 bhndb_disable_pci_clocks(dev);
325 * Attempt to allocate MSI interrupts, returning the count in @p msi_count
329 bhndb_pci_alloc_msi(struct bhndb_pci_softc *sc, int *msi_count)
333 /* Is MSI available? */
334 if (pci_msi_count(sc->parent) < BHNDB_PCI_MSI_COUNT)
337 /* Allocate expected message count */
338 count = BHNDB_PCI_MSI_COUNT;
339 if ((error = pci_alloc_msi(sc->parent, &count))) {
340 device_printf(sc->dev, "failed to allocate MSI interrupts: "
346 if (count < BHNDB_PCI_MSI_COUNT) {
347 pci_release_msi(sc->parent);
356 bhndb_pci_attach(device_t dev)
358 struct bhndb_pci_softc *sc;
359 struct bhnd_chipid cid;
360 struct bhnd_core_info *cores, hostb_core;
361 bhnd_erom_class_t *erom_class;
362 struct bhndb_pci_probe *probe;
367 sc = device_get_softc(dev);
369 sc->parent = device_get_parent(dev);
370 sc->pci_devclass = bhndb_expected_pci_devclass(dev);
372 sc->set_regwin = NULL;
374 BHNDB_PCI_LOCK_INIT(sc);
379 /* Enable PCI bus mastering */
380 pci_enable_busmaster(sc->parent);
382 /* Enable clocks (if required by this hardware) */
383 if ((error = bhndb_enable_pci_clocks(sc->dev)))
386 /* Identify the chip and enumerate the bridged cores */
387 error = bhndb_pci_probe_alloc(&probe, dev, sc->pci_devclass);
391 sc->pci_quirks = bhndb_pci_get_core_quirks(&probe->cid,
394 /* Select the appropriate register window handler */
395 if (probe->cid.chip_type == BHND_CHIPTYPE_SIBA) {
396 sc->set_regwin = bhndb_pci_compat_setregwin;
398 sc->set_regwin = bhndb_pci_fast_setregwin;
402 * Fix up our PCI base address in the SPROM shadow, if necessary.
404 * This must be done prior to accessing any static register windows
405 * that map the PCI core.
407 if ((error = bhndb_pci_srsh_pi_war(sc, probe)))
410 /* Set up PCI interrupt handling */
411 if (bhndb_pci_alloc_msi(sc, &sc->msi_count) == 0) {
412 /* MSI uses resource IDs starting at 1 */
415 device_printf(dev, "Using MSI interrupts on %s\n",
416 device_get_nameunit(sc->parent));
421 device_printf(dev, "Using INTx interrupts on %s\n",
422 device_get_nameunit(sc->parent));
425 sc->isrc = bhndb_alloc_intr_isrc(sc->parent, irq_rid, 0, RM_MAX_END, 1,
426 RF_SHAREABLE | RF_ACTIVE);
427 if (sc->isrc == NULL) {
428 device_printf(sc->dev, "failed to allocate interrupt "
435 * Copy out the probe results and then free our probe state, releasing
436 * its exclusive ownership of host bridge resources.
438 * This must be done prior to full configuration of the bridge via
442 erom_class = probe->erom_class;
443 hostb_core = probe->hostb_core;
445 error = bhndb_pci_probe_copy_core_table(probe, &cores, &ncores);
451 bhndb_pci_probe_free(probe);
454 /* Perform bridge attach */
455 error = bhndb_attach(dev, &cid, cores, ncores, &hostb_core, erom_class);
459 /* Add any additional child devices */
460 if ((error = bhndb_pci_add_children(sc)))
463 /* Probe and attach our children */
464 if ((error = bus_generic_attach(dev)))
467 bhndb_pci_probe_free_core_table(cores);
472 device_delete_children(dev);
474 if (sc->isrc != NULL)
475 bhndb_free_intr_isrc(sc->isrc);
477 if (sc->msi_count > 0)
478 pci_release_msi(sc->parent);
481 bhndb_pci_probe_free_core_table(cores);
484 bhndb_pci_probe_free(probe);
486 bhndb_disable_pci_clocks(sc->dev);
488 pci_disable_busmaster(sc->parent);
490 BHNDB_PCI_LOCK_DESTROY(sc);
496 bhndb_pci_detach(device_t dev)
498 struct bhndb_pci_softc *sc;
501 sc = device_get_softc(dev);
503 /* Attempt to detach our children */
504 if ((error = bus_generic_detach(dev)))
507 /* Perform generic bridge detach */
508 if ((error = bhndb_generic_detach(dev)))
511 /* Disable clocks (if required by this hardware) */
512 if ((error = bhndb_disable_pci_clocks(sc->dev)))
515 /* Free our interrupt resources */
516 bhndb_free_intr_isrc(sc->isrc);
518 /* Release MSI interrupts */
519 if (sc->msi_count > 0)
520 pci_release_msi(sc->parent);
522 /* Disable PCI bus mastering */
523 pci_disable_busmaster(sc->parent);
525 BHNDB_PCI_LOCK_DESTROY(sc);
531 bhndb_pci_add_children(struct bhndb_pci_softc *sc)
537 * If SPROM is mapped directly into BAR0, add child NVRAM
540 nv_sz = bhndb_pci_sprom_size(sc);
542 struct bhndb_devinfo *dinfo;
546 device_printf(sc->dev, "found SPROM (%ju bytes)\n",
550 /* Add sprom device, ordered early enough to be available
551 * before the bridged bhnd(4) bus is attached. */
552 child = BUS_ADD_CHILD(sc->dev,
553 BHND_PROBE_ROOT + BHND_PROBE_ORDER_EARLY, "bhnd_nvram", -1);
555 device_printf(sc->dev, "failed to add sprom device\n");
559 /* Initialize device address space and resource covering the
560 * BAR0 SPROM shadow. */
561 dinfo = device_get_ivars(child);
562 dinfo->addrspace = BHNDB_ADDRSPACE_NATIVE;
564 error = bus_set_resource(child, SYS_RES_MEMORY, 0,
565 bhndb_pci_sprom_addr(sc), nv_sz);
567 device_printf(sc->dev,
568 "failed to register sprom resources\n");
576 static const struct bhndb_regwin *
577 bhndb_pci_sprom_regwin(struct bhndb_pci_softc *sc)
579 struct bhndb_resources *bres;
580 const struct bhndb_hwcfg *cfg;
581 const struct bhndb_regwin *sprom_win;
583 bres = sc->bhndb.bus_res;
586 sprom_win = bhndb_regwin_find_type(cfg->register_windows,
587 BHNDB_REGWIN_T_SPROM, BHNDB_PCI_V0_BAR0_SPROM_SIZE);
593 bhndb_pci_sprom_addr(struct bhndb_pci_softc *sc)
595 const struct bhndb_regwin *sprom_win;
598 /* Fetch the SPROM register window */
599 sprom_win = bhndb_pci_sprom_regwin(sc);
600 KASSERT(sprom_win != NULL, ("requested sprom address on PCI_V2+"));
602 /* Fetch the associated resource */
603 r = bhndb_host_resource_for_regwin(sc->bhndb.bus_res->res, sprom_win);
604 KASSERT(r != NULL, ("missing resource for sprom window\n"));
606 return (rman_get_start(r) + sprom_win->win_offset);
610 bhndb_pci_sprom_size(struct bhndb_pci_softc *sc)
612 const struct bhndb_regwin *sprom_win;
616 sprom_win = bhndb_pci_sprom_regwin(sc);
618 /* PCI_V2 and later devices map SPROM/OTP via ChipCommon */
619 if (sprom_win == NULL)
622 /* Determine SPROM size */
623 sctl = pci_read_config(sc->parent, BHNDB_PCI_SPROM_CONTROL, 4);
624 if (sctl & BHNDB_PCI_SPROM_BLANK)
627 switch (sctl & BHNDB_PCI_SPROM_SZ_MASK) {
628 case BHNDB_PCI_SPROM_SZ_1KB:
629 sprom_sz = (1 * 1024);
632 case BHNDB_PCI_SPROM_SZ_4KB:
633 sprom_sz = (4 * 1024);
636 case BHNDB_PCI_SPROM_SZ_16KB:
637 sprom_sz = (16 * 1024);
640 case BHNDB_PCI_SPROM_SZ_RESERVED:
642 device_printf(sc->dev, "invalid PCI sprom size 0x%x\n", sctl);
646 /* If the device has a larger SPROM than can be addressed via our SPROM
647 * register window, the SPROM image data will still be located within
648 * the window's addressable range */
649 sprom_sz = MIN(sprom_sz, sprom_win->win_size);
655 * Return the host resource providing a static mapping of the PCI core's
658 * @param sc bhndb PCI driver state.
659 * @param offset The required readable offset within the PCI core
661 * @param size The required readable size at @p offset.
662 * @param[out] res On success, the host resource containing our PCI
663 * core's register window.
664 * @param[out] res_offset On success, the @p offset relative to @p res.
667 * @retval ENXIO if a valid static register window mapping the PCI core
668 * registers is not available.
671 bhndb_pci_get_core_regs(struct bhndb_pci_softc *sc, bus_size_t offset,
672 bus_size_t size, struct resource **res, bus_size_t *res_offset)
674 const struct bhndb_regwin *win;
677 /* Locate the static register window mapping the requested offset */
678 win = bhndb_regwin_find_core(sc->bhndb.bus_res->cfg->register_windows,
679 sc->pci_devclass, 0, BHND_PORT_DEVICE, 0, 0, offset, size);
681 device_printf(sc->dev, "missing PCI core register window\n");
685 /* Fetch the resource containing the register window */
686 r = bhndb_host_resource_for_regwin(sc->bhndb.bus_res->res, win);
688 device_printf(sc->dev, "missing PCI core register resource\n");
692 KASSERT(offset >= win->d.core.offset, ("offset %#jx outside of "
693 "register window", (uintmax_t)offset));
696 *res_offset = win->win_offset + (offset - win->d.core.offset);
702 * Write a 1, 2, or 4 byte data item to the PCI core's registers at @p offset.
704 * @param sc bhndb PCI driver state.
705 * @param offset register write offset.
706 * @param value value to be written.
707 * @param width item width (1, 2, or 4 bytes).
710 bhndb_pci_write_core(struct bhndb_pci_softc *sc, bus_size_t offset,
711 uint32_t value, u_int width)
717 error = bhndb_pci_get_core_regs(sc, offset, width, &r, &r_offset);
719 panic("no PCI register window mapping %#jx+%#x: %d",
720 (uintmax_t)offset, width, error);
725 bus_write_1(r, r_offset, value);
728 bus_write_2(r, r_offset, value);
731 bus_write_4(r, r_offset, value);
734 panic("invalid width: %u", width);
739 * Read a 1, 2, or 4 byte data item from the PCI core's registers
742 * @param sc bhndb PCI driver state.
743 * @param offset register read offset.
744 * @param width item width (1, 2, or 4 bytes).
747 bhndb_pci_read_core(struct bhndb_pci_softc *sc, bus_size_t offset, u_int width)
753 error = bhndb_pci_get_core_regs(sc, offset, width, &r, &r_offset);
755 panic("no PCI register window mapping %#jx+%#x: %d",
756 (uintmax_t)offset, width, error);
761 return (bus_read_1(r, r_offset));
763 return (bus_read_2(r, r_offset));
765 return (bus_read_4(r, r_offset));
767 panic("invalid width: %u", width);
772 * Fix-up power on defaults for SPROM-less devices.
774 * On SPROM-less devices, the PCI(e) cores will be initialized with their their
775 * Power-on-Reset defaults; this can leave the BHND_PCI_SRSH_PI value pointing
776 * to the wrong backplane address. This value is used by the PCI core when
777 * performing address translation between static register windows in BAR0 that
778 * map the PCI core's register block, and backplane address space.
780 * When translating accesses via these BAR0 regions, the PCI bridge determines
781 * the base address of the PCI core by concatenating:
784 * 31:16 bits [31:16] of the enumeration space address (e.g. 0x18000000)
785 * 15:12 value of BHND_PCI_SRSH_PI from the PCI core's SPROM shadow
786 * 11:0 bits [11:0] of the PCI bus address
788 * For example, on a PCI_V0 device, the following PCI core register offsets are
791 * [BAR0 offset] [description] [PCI core offset]
792 * 0x1000-0x17FF sprom shadow 0x800-0xFFF
793 * 0x1800-0x1DFF device registers 0x000-0x5FF
794 * 0x1E00+0x1FFF siba config registers 0xE00-0xFFF
796 * This function checks -- and if necessary, corrects -- the BHND_PCI_SRSH_PI
797 * value in the SPROM shadow.
799 * This workaround must applied prior to accessing any static register windows
800 * that map the PCI core.
802 * Applies to all PCI and PCIe-G1 core revisions.
805 bhndb_pci_srsh_pi_war(struct bhndb_pci_softc *sc,
806 struct bhndb_pci_probe *probe)
808 struct bhnd_core_match md;
809 bhnd_addr_t pci_addr;
810 bhnd_size_t pci_size;
811 bus_size_t srsh_offset;
812 uint16_t srsh_val, pci_val;
816 if ((sc->pci_quirks & BHNDB_PCI_QUIRK_SRSH_WAR) == 0)
819 /* Use an equality match descriptor to look up our PCI core's base
820 * address in the EROM */
821 md = bhnd_core_get_match_desc(&probe->hostb_core);
822 error = bhnd_erom_lookup_core_addr(probe->erom, &md, BHND_PORT_DEVICE,
823 0, 0, NULL, &pci_addr, &pci_size);
825 device_printf(sc->dev, "no base address found for the PCI host "
826 "bridge core: %d\n", error);
830 /* Fetch the SPROM SRSH_PI value */
831 srsh_offset = BHND_PCI_SPROM_SHADOW + BHND_PCI_SRSH_PI_OFFSET;
832 val = bhndb_pci_probe_read(probe, pci_addr, srsh_offset, sizeof(val));
833 srsh_val = (val & BHND_PCI_SRSH_PI_MASK) >> BHND_PCI_SRSH_PI_SHIFT;
835 /* If it doesn't match PCI core's base address, update the SPROM
837 pci_val = (pci_addr & BHND_PCI_SRSH_PI_ADDR_MASK) >>
838 BHND_PCI_SRSH_PI_ADDR_SHIFT;
839 if (srsh_val != pci_val) {
840 val &= ~BHND_PCI_SRSH_PI_MASK;
841 val |= (pci_val << BHND_PCI_SRSH_PI_SHIFT);
842 bhndb_pci_probe_write(probe, pci_addr, srsh_offset, val,
850 bhndb_pci_resume(device_t dev)
852 struct bhndb_pci_softc *sc;
855 sc = device_get_softc(dev);
857 /* Enable clocks (if supported by this hardware) */
858 if ((error = bhndb_enable_pci_clocks(sc->dev)))
862 return (bhndb_generic_resume(dev));
866 bhndb_pci_suspend(device_t dev)
868 struct bhndb_pci_softc *sc;
871 sc = device_get_softc(dev);
873 /* Disable clocks (if supported by this hardware) */
874 if ((error = bhndb_disable_pci_clocks(sc->dev)))
877 /* Perform suspend */
878 return (bhndb_generic_suspend(dev));
882 bhndb_pci_set_window_addr(device_t dev, const struct bhndb_regwin *rw,
885 struct bhndb_pci_softc *sc = device_get_softc(dev);
886 return (sc->set_regwin(sc->dev, sc->parent, rw, addr));
890 * A siba(4) and bcma(4)-compatible bhndb_set_window_addr implementation.
892 * On siba(4) devices, it's possible that writing a PCI window register may
893 * not succeed; it's necessary to immediately read the configuration register
894 * and retry if not set to the desired value.
896 * This is not necessary on bcma(4) devices, but other than the overhead of
897 * validating the register, there's no harm in performing the verification.
900 bhndb_pci_compat_setregwin(device_t dev, device_t pci_dev,
901 const struct bhndb_regwin *rw, bhnd_addr_t addr)
906 if (rw->win_type != BHNDB_REGWIN_T_DYN)
909 reg = rw->d.dyn.cfg_offset;
910 for (u_int i = 0; i < BHNDB_PCI_BARCTRL_WRITE_RETRY; i++) {
911 if ((error = bhndb_pci_fast_setregwin(dev, pci_dev, rw, addr)))
914 if (pci_read_config(pci_dev, reg, 4) == addr)
920 /* Unable to set window */
925 * A bcma(4)-only bhndb_set_window_addr implementation.
928 bhndb_pci_fast_setregwin(device_t dev, device_t pci_dev,
929 const struct bhndb_regwin *rw, bhnd_addr_t addr)
931 /* The PCI bridge core only supports 32-bit addressing, regardless
932 * of the bus' support for 64-bit addressing */
933 if (addr > UINT32_MAX)
936 switch (rw->win_type) {
937 case BHNDB_REGWIN_T_DYN:
938 /* Addresses must be page aligned */
939 if (addr % rw->win_size != 0)
942 pci_write_config(pci_dev, rw->d.dyn.cfg_offset, addr, 4);
952 bhndb_pci_populate_board_info(device_t dev, device_t child,
953 struct bhnd_board_info *info)
955 struct bhndb_pci_softc *sc;
957 sc = device_get_softc(dev);
960 * On a subset of Apple BCM4360 modules, always prefer the
961 * PCI subdevice to the SPROM-supplied boardtype.
965 * Broadcom's own drivers implement this override, and then later use
966 * the remapped BCM4360 board type to determine the required
967 * board-specific workarounds.
969 * Without access to this hardware, it's unclear why this mapping
970 * is done, and we must do the same. If we can survey the hardware
971 * in question, it may be possible to replace this behavior with
972 * explicit references to the SPROM-supplied boardtype(s) in our
975 if (pci_get_subvendor(sc->parent) == PCI_VENDOR_APPLE) {
976 switch (info->board_type) {
977 case BHND_BOARD_BCM94360X29C:
978 case BHND_BOARD_BCM94360X29CP2:
979 case BHND_BOARD_BCM94360X51:
980 case BHND_BOARD_BCM94360X51P2:
981 info->board_type = 0; /* allow override below */
988 /* If NVRAM did not supply vendor/type/devid info, provide the PCI
989 * subvendor/subdevice/device values. */
990 if (info->board_vendor == 0)
991 info->board_vendor = pci_get_subvendor(sc->parent);
993 if (info->board_type == 0)
994 info->board_type = pci_get_subdevice(sc->parent);
996 if (info->board_devid == 0)
997 info->board_devid = pci_get_device(sc->parent);
1003 * Examine the bridge device @p dev and return the expected host bridge
1006 * @param dev The bhndb bridge device
1008 static bhnd_devclass_t
1009 bhndb_expected_pci_devclass(device_t dev)
1011 if (bhndb_is_pcie_attached(dev))
1012 return (BHND_DEVCLASS_PCIE);
1014 return (BHND_DEVCLASS_PCI);
1018 * Return true if the bridge device @p dev is attached via PCIe,
1021 * @param dev The bhndb bridge device
1024 bhndb_is_pcie_attached(device_t dev)
1028 if (pci_find_cap(device_get_parent(dev), PCIY_EXPRESS, ®) == 0)
1035 * Enable externally managed clocks, if required.
1037 * Some PCI chipsets (BCM4306, possibly others) chips do not support
1038 * the idle low-power clock. Clocking must be bootstrapped at
1039 * attach/resume by directly adjusting GPIO registers exposed in the
1040 * PCI config space, and correspondingly, explicitly shutdown at
1043 * @note This function may be safely called prior to device attach, (e.g.
1044 * from DEVICE_PROBE).
1046 * @param dev The bhndb bridge device
1049 bhndb_enable_pci_clocks(device_t dev)
1052 uint32_t gpio_in, gpio_out, gpio_en;
1053 uint32_t gpio_flags;
1054 uint16_t pci_status;
1056 pci_dev = device_get_parent(dev);
1058 /* Only supported and required on PCI devices */
1059 if (bhndb_is_pcie_attached(dev))
1062 /* Read state of XTAL pin */
1063 gpio_in = pci_read_config(pci_dev, BHNDB_PCI_GPIO_IN, 4);
1064 if (gpio_in & BHNDB_PCI_GPIO_XTAL_ON)
1065 return (0); /* already enabled */
1067 /* Fetch current config */
1068 gpio_out = pci_read_config(pci_dev, BHNDB_PCI_GPIO_OUT, 4);
1069 gpio_en = pci_read_config(pci_dev, BHNDB_PCI_GPIO_OUTEN, 4);
1071 /* Set PLL_OFF/XTAL_ON pins to HIGH and enable both pins */
1072 gpio_flags = (BHNDB_PCI_GPIO_PLL_OFF|BHNDB_PCI_GPIO_XTAL_ON);
1073 gpio_out |= gpio_flags;
1074 gpio_en |= gpio_flags;
1076 pci_write_config(pci_dev, BHNDB_PCI_GPIO_OUT, gpio_out, 4);
1077 pci_write_config(pci_dev, BHNDB_PCI_GPIO_OUTEN, gpio_en, 4);
1081 gpio_out &= ~BHNDB_PCI_GPIO_PLL_OFF;
1082 pci_write_config(pci_dev, BHNDB_PCI_GPIO_OUT, gpio_out, 4);
1085 /* Clear any PCI 'sent target-abort' flag. */
1086 pci_status = pci_read_config(pci_dev, PCIR_STATUS, 2);
1087 pci_status &= ~PCIM_STATUS_STABORT;
1088 pci_write_config(pci_dev, PCIR_STATUS, pci_status, 2);
1094 * Disable externally managed clocks, if required.
1096 * This function may be safely called prior to device attach, (e.g.
1097 * from DEVICE_PROBE).
1099 * @param dev The bhndb bridge device
1102 bhndb_disable_pci_clocks(device_t dev)
1105 uint32_t gpio_out, gpio_en;
1107 pci_dev = device_get_parent(dev);
1109 /* Only supported and required on PCI devices */
1110 if (bhndb_is_pcie_attached(dev))
1113 /* Fetch current config */
1114 gpio_out = pci_read_config(pci_dev, BHNDB_PCI_GPIO_OUT, 4);
1115 gpio_en = pci_read_config(pci_dev, BHNDB_PCI_GPIO_OUTEN, 4);
1117 /* Set PLL_OFF to HIGH, XTAL_ON to LOW. */
1118 gpio_out &= ~BHNDB_PCI_GPIO_XTAL_ON;
1119 gpio_out |= BHNDB_PCI_GPIO_PLL_OFF;
1120 pci_write_config(pci_dev, BHNDB_PCI_GPIO_OUT, gpio_out, 4);
1122 /* Enable both output pins */
1123 gpio_en |= (BHNDB_PCI_GPIO_PLL_OFF|BHNDB_PCI_GPIO_XTAL_ON);
1124 pci_write_config(pci_dev, BHNDB_PCI_GPIO_OUTEN, gpio_en, 4);
1130 bhndb_pci_pwrctl_get_clksrc(device_t dev, device_t child,
1133 struct bhndb_pci_softc *sc;
1136 sc = device_get_softc(dev);
1138 /* Only supported on PCI devices */
1139 if (bhndb_is_pcie_attached(sc->dev))
1140 return (BHND_CLKSRC_UNKNOWN);
1142 /* Only ILP is supported */
1143 if (clock != BHND_CLOCK_ILP)
1144 return (BHND_CLKSRC_UNKNOWN);
1146 gpio_out = pci_read_config(sc->parent, BHNDB_PCI_GPIO_OUT, 4);
1147 if (gpio_out & BHNDB_PCI_GPIO_SCS)
1148 return (BHND_CLKSRC_PCI);
1150 return (BHND_CLKSRC_XTAL);
1154 bhndb_pci_pwrctl_gate_clock(device_t dev, device_t child,
1157 struct bhndb_pci_softc *sc = device_get_softc(dev);
1159 /* Only supported on PCI devices */
1160 if (bhndb_is_pcie_attached(sc->dev))
1163 /* Only HT is supported */
1164 if (clock != BHND_CLOCK_HT)
1167 return (bhndb_disable_pci_clocks(sc->dev));
1171 bhndb_pci_pwrctl_ungate_clock(device_t dev, device_t child,
1174 struct bhndb_pci_softc *sc = device_get_softc(dev);
1176 /* Only supported on PCI devices */
1177 if (bhndb_is_pcie_attached(sc->dev))
1180 /* Only HT is supported */
1181 if (clock != BHND_CLOCK_HT)
1184 return (bhndb_enable_pci_clocks(sc->dev));
1188 * BHNDB_MAP_INTR_ISRC()
1191 bhndb_pci_map_intr_isrc(device_t dev, struct resource *irq,
1192 struct bhndb_intr_isrc **isrc)
1194 struct bhndb_pci_softc *sc = device_get_softc(dev);
1196 /* There's only one bridged interrupt to choose from */
1201 /* siba-specific implementation of BHNDB_ROUTE_INTERRUPTS() */
1203 bhndb_pci_route_siba_interrupts(struct bhndb_pci_softc *sc, device_t child)
1209 KASSERT(sc->pci_quirks & BHNDB_PCI_QUIRK_SIBA_INTVEC,
1210 ("route_siba_interrupts not supported by this hardware"));
1212 /* Fetch the sbflag# for the child */
1213 if ((error = bhnd_get_intr_ivec(child, 0, &ivec)))
1216 if (ivec > (sizeof(sbintvec)*8) - 1 /* aka '31' */) {
1217 /* This should never be an issue in practice */
1218 device_printf(sc->dev, "cannot route interrupts to high "
1219 "sbflag# %u\n", ivec);
1225 sbintvec = bhndb_pci_read_core(sc, SB0_REG_ABS(SIBA_CFG0_INTVEC), 4);
1226 sbintvec |= (1 << ivec);
1227 bhndb_pci_write_core(sc, SB0_REG_ABS(SIBA_CFG0_INTVEC), sbintvec, 4);
1229 BHNDB_PCI_UNLOCK(sc);
1234 /* BHNDB_ROUTE_INTERRUPTS() */
1236 bhndb_pci_route_interrupts(device_t dev, device_t child)
1238 struct bhndb_pci_softc *sc;
1239 struct bhnd_core_info core;
1243 sc = device_get_softc(dev);
1245 if (sc->pci_quirks & BHNDB_PCI_QUIRK_SIBA_INTVEC)
1246 return (bhndb_pci_route_siba_interrupts(sc, child));
1248 core = bhnd_get_core_info(child);
1249 if (core.core_idx > BHNDB_PCI_SBIM_COREIDX_MAX) {
1250 /* This should never be an issue in practice */
1251 device_printf(dev, "cannot route interrupts to high core "
1252 "index %u\n", core.core_idx);
1258 core_bit = (1<<core.core_idx) << BHNDB_PCI_SBIM_SHIFT;
1259 intmask = pci_read_config(sc->parent, BHNDB_PCI_INT_MASK, 4);
1260 intmask |= core_bit;
1261 pci_write_config(sc->parent, BHNDB_PCI_INT_MASK, intmask, 4);
1263 BHNDB_PCI_UNLOCK(sc);
1269 * Using the generic PCI bridge hardware configuration, allocate, initialize
1270 * and return a new bhndb_pci probe state instance.
1272 * On success, the caller assumes ownership of the returned probe instance, and
1273 * is responsible for releasing this reference using bhndb_pci_probe_free().
1275 * @param[out] probe On success, the newly allocated probe instance.
1276 * @param dev The bhndb_pci bridge device.
1277 * @param hostb_devclass The expected device class of the bridge core.
1280 * @retval non-zero if allocating the probe state fails, a regular
1281 * unix error code will be returned.
1283 * @note This function requires exclusive ownership over allocating and
1284 * configuring host bridge resources, and should only be called prior to
1285 * completion of device attach and full configuration of the bridge.
1288 bhndb_pci_probe_alloc(struct bhndb_pci_probe **probe, device_t dev,
1289 bhnd_devclass_t hostb_devclass)
1291 struct bhndb_pci_probe *p;
1292 struct bhnd_erom_io *eio;
1293 const struct bhndb_hwcfg *hwcfg;
1294 const struct bhnd_chipid *hint;
1295 device_t parent_dev;
1298 parent_dev = device_get_parent(dev);
1301 p = malloc(sizeof(*p), M_BHND, M_ZERO|M_WAITOK);
1303 p->pci_dev = parent_dev;
1305 /* Our register window mapping state must be initialized at this point,
1306 * as bhndb_pci_eio will begin making calls into
1307 * bhndb_pci_probe_(read|write|get_mapping) */
1312 bhndb_pci_eio_init(&p->erom_io, p);
1313 eio = &p->erom_io.eio;
1315 /* Fetch our chipid hint (if any) and generic hardware configuration */
1316 hwcfg = BHNDB_BUS_GET_GENERIC_HWCFG(parent_dev, dev);
1317 hint = BHNDB_BUS_GET_CHIPID(parent_dev, dev);
1319 /* Allocate our host resources */
1320 error = bhndb_alloc_host_resources(&p->hr, dev, parent_dev, hwcfg);
1326 /* Map the first bus core from our bridged bhnd(4) bus */
1327 error = bhnd_erom_io_map(eio, BHND_DEFAULT_CHIPC_ADDR,
1328 BHND_DEFAULT_CORE_SIZE);
1332 /* Probe for a usable EROM class, and read the chip identifier */
1333 p->erom_class = bhnd_erom_probe_driver_classes(
1334 device_get_devclass(dev), eio, hint, &p->cid);
1335 if (p->erom_class == NULL) {
1336 device_printf(dev, "device enumeration unsupported; no "
1337 "compatible driver found\n");
1343 /* Allocate EROM parser */
1344 p->erom = bhnd_erom_alloc(p->erom_class, &p->cid, eio);
1345 if (p->erom == NULL) {
1346 device_printf(dev, "failed to allocate device enumeration "
1352 /* The EROM I/O instance is now owned by our EROM parser */
1355 /* Read the full core table */
1356 error = bhnd_erom_get_core_table(p->erom, &p->cores, &p->ncores);
1358 device_printf(p->dev, "error fetching core table: %d\n",
1365 /* Identify the host bridge core */
1366 error = bhndb_find_hostb_core(p->cores, p->ncores, hostb_devclass,
1369 device_printf(dev, "failed to identify the host bridge "
1370 "core: %d\n", error);
1380 KASSERT(p->erom == NULL, ("I/O instance will be freed by "
1381 "its owning parser"));
1383 bhnd_erom_io_fini(eio);
1386 if (p->erom != NULL) {
1387 if (p->cores != NULL)
1388 bhnd_erom_free_core_table(p->erom, p->cores);
1390 bhnd_erom_free(p->erom);
1392 KASSERT(p->cores == NULL, ("cannot free erom-owned core table "
1393 "without erom reference"));
1397 bhndb_release_host_resources(p->hr);
1405 * Free the given @p probe instance and any associated host bridge resources.
1408 bhndb_pci_probe_free(struct bhndb_pci_probe *probe)
1410 bhnd_erom_free_core_table(probe->erom, probe->cores);
1411 bhnd_erom_free(probe->erom);
1412 bhndb_release_host_resources(probe->hr);
1413 free(probe, M_BHND);
1417 * Return a copy of probed core table from @p probe.
1419 * @param probe The probe instance.
1420 * @param[out] cores On success, a copy of the probed core table. The
1421 * caller is responsible for freeing this table
1422 * bhndb_pci_probe_free_core_table().
1423 * @param[out] ncores On success, the number of cores found in
1427 * @retval non-zero if enumerating the bridged bhnd(4) bus fails, a regular
1428 * unix error code will be returned.
1431 bhndb_pci_probe_copy_core_table(struct bhndb_pci_probe *probe,
1432 struct bhnd_core_info **cores, u_int *ncores)
1434 size_t len = sizeof(**cores) * probe->ncores;
1436 *cores = malloc(len, M_BHND, M_WAITOK);
1437 memcpy(*cores, probe->cores, len);
1439 *ncores = probe->ncores;
1445 * Free a core table previously returned by bhndb_pci_probe_copy_core_table().
1447 * @param cores The core table to be freed.
1450 bhndb_pci_probe_free_core_table(struct bhnd_core_info *cores)
1452 free(cores, M_BHND);
1456 * Return true if @p addr and @p size are mapped by the dynamic register window
1460 bhndb_pci_probe_has_mapping(struct bhndb_pci_probe *probe, bhnd_addr_t addr,
1463 if (!probe->m_valid)
1466 KASSERT(probe->m_win != NULL, ("missing register window"));
1467 KASSERT(probe->m_res != NULL, ("missing regwin resource"));
1468 KASSERT(probe->m_win->win_type == BHNDB_REGWIN_T_DYN,
1469 ("unexpected window type %d", probe->m_win->win_type));
1471 if (addr < probe->m_target)
1474 if (addr >= probe->m_target + probe->m_win->win_size)
1477 if ((probe->m_target + probe->m_win->win_size) - addr < size)
1484 * Attempt to adjust the dynamic register window backing @p probe to permit
1485 * accessing @p size bytes at @p addr.
1487 * @param probe The bhndb_pci probe state to be modified.
1488 * @param addr The address at which @p size bytes will mapped.
1489 * @param size The number of bytes to be mapped.
1490 * @param[out] res On success, will be set to the host resource
1491 * mapping @p size bytes at @p addr.
1492 * @param[out] res_offset On success, will be set to the offset of @addr
1496 * @retval non-zero if an error occurs adjusting the backing dynamic
1500 bhndb_pci_probe_map(struct bhndb_pci_probe *probe, bhnd_addr_t addr,
1501 bhnd_size_t offset, bhnd_size_t size, struct resource **res,
1502 bus_size_t *res_offset)
1504 const struct bhndb_regwin *regwin, *regwin_table;
1505 struct resource *regwin_res;
1509 /* Determine the absolute address */
1510 if (BHND_SIZE_MAX - offset < addr) {
1511 device_printf(probe->dev, "invalid offset %#jx+%#jx\n", addr,
1518 /* Can we use the existing mapping? */
1519 if (bhndb_pci_probe_has_mapping(probe, addr, size)) {
1520 *res = probe->m_res;
1521 *res_offset = (addr - probe->m_target) +
1522 probe->m_win->win_offset;
1527 /* Locate a useable dynamic register window */
1528 regwin_table = probe->hr->cfg->register_windows;
1529 regwin = bhndb_regwin_find_type(regwin_table,
1530 BHNDB_REGWIN_T_DYN, size);
1531 if (regwin == NULL) {
1532 device_printf(probe->dev, "unable to map %#jx+%#jx; no "
1533 "usable dynamic register window found\n", addr,
1538 /* Locate the host resource mapping our register window */
1539 regwin_res = bhndb_host_resource_for_regwin(probe->hr, regwin);
1540 if (regwin_res == NULL) {
1541 device_printf(probe->dev, "unable to map %#jx+%#jx; no "
1542 "usable register resource found\n", addr, size);
1546 /* Page-align the target address */
1547 target = addr - (addr % regwin->win_size);
1549 /* Configure the register window */
1550 error = bhndb_pci_compat_setregwin(probe->dev, probe->pci_dev,
1553 device_printf(probe->dev, "failed to configure dynamic "
1554 "register window: %d\n", error);
1558 /* Update our mapping state */
1559 probe->m_win = regwin;
1560 probe->m_res = regwin_res;
1561 probe->m_addr = addr;
1562 probe->m_size = size;
1563 probe->m_target = target;
1564 probe->m_valid = true;
1567 *res_offset = (addr - target) + regwin->win_offset;
1573 * Write a data item to the bridged address space at the given @p offset from
1576 * A dynamic register window will be used to map @p addr.
1578 * @param probe The bhndb_pci probe state to be used to perform the
1580 * @param addr The base address.
1581 * @param offset The offset from @p addr at which @p value will be
1583 * @param value The data item to be written.
1584 * @param width The data item width (1, 2, or 4 bytes).
1587 bhndb_pci_probe_write(struct bhndb_pci_probe *probe, bhnd_addr_t addr,
1588 bhnd_size_t offset, uint32_t value, u_int width)
1591 bus_size_t res_offset;
1594 /* Map the target address */
1595 error = bhndb_pci_probe_map(probe, addr, offset, width, &r,
1598 device_printf(probe->dev, "error mapping %#jx+%#jx for "
1599 "writing: %d\n", addr, offset, error);
1606 return (bus_write_1(r, res_offset, value));
1608 return (bus_write_2(r, res_offset, value));
1610 return (bus_write_4(r, res_offset, value));
1612 panic("unsupported width: %u", width);
1617 * Read a data item from the bridged address space at the given @p offset
1620 * A dynamic register window will be used to map @p addr.
1622 * @param probe The bhndb_pci probe state to be used to perform the
1624 * @param addr The base address.
1625 * @param offset The offset from @p addr at which to read a data item of
1627 * @param width Item width (1, 2, or 4 bytes).
1630 bhndb_pci_probe_read(struct bhndb_pci_probe *probe, bhnd_addr_t addr,
1631 bhnd_size_t offset, u_int width)
1634 bus_size_t res_offset;
1637 /* Map the target address */
1638 error = bhndb_pci_probe_map(probe, addr, offset, width, &r,
1641 device_printf(probe->dev, "error mapping %#jx+%#jx for "
1642 "reading: %d\n", addr, offset, error);
1643 return (UINT32_MAX);
1649 return (bus_read_1(r, res_offset));
1651 return (bus_read_2(r, res_offset));
1653 return (bus_read_4(r, res_offset));
1655 panic("unsupported width: %u", width);
1660 * Initialize a new bhndb PCI bridge EROM I/O instance. All I/O will be
1661 * performed using @p probe.
1663 * @param pio The instance to be initialized.
1664 * @param probe The bhndb_pci probe state to be used to perform all
1668 bhndb_pci_eio_init(struct bhndb_pci_eio *pio, struct bhndb_pci_probe *probe)
1670 memset(pio, 0, sizeof(*pio));
1672 pio->eio.map = bhndb_pci_eio_map;
1673 pio->eio.tell = bhndb_pci_eio_tell;
1674 pio->eio.read = bhndb_pci_eio_read;
1675 pio->eio.fini = NULL;
1677 pio->mapped = false;
1683 /* bhnd_erom_io_map() implementation */
1685 bhndb_pci_eio_map(struct bhnd_erom_io *eio, bhnd_addr_t addr,
1688 struct bhndb_pci_eio *pio = (struct bhndb_pci_eio *)eio;
1690 if (BHND_ADDR_MAX - addr < size)
1691 return (EINVAL); /* addr+size would overflow */
1700 /* bhnd_erom_io_tell() implementation */
1702 bhndb_pci_eio_tell(struct bhnd_erom_io *eio, bhnd_addr_t *addr,
1705 struct bhndb_pci_eio *pio = (struct bhndb_pci_eio *)eio;
1716 /* bhnd_erom_io_read() implementation */
1718 bhndb_pci_eio_read(struct bhnd_erom_io *eio, bhnd_size_t offset, u_int width)
1720 struct bhndb_pci_eio *pio = (struct bhndb_pci_eio *)eio;
1722 /* Must have a valid mapping */
1724 panic("no active mapping");
1726 /* The requested subrange must fall within the existing mapped range */
1727 if (offset > pio->size ||
1728 width > pio->size ||
1729 pio->size - offset < width)
1731 panic("invalid offset %#jx", offset);
1734 return (bhndb_pci_probe_read(pio->probe, pio->addr, offset, width));
1737 static device_method_t bhndb_pci_methods[] = {
1738 /* Device interface */
1739 DEVMETHOD(device_probe, bhndb_pci_probe),
1740 DEVMETHOD(device_attach, bhndb_pci_attach),
1741 DEVMETHOD(device_resume, bhndb_pci_resume),
1742 DEVMETHOD(device_suspend, bhndb_pci_suspend),
1743 DEVMETHOD(device_detach, bhndb_pci_detach),
1745 /* BHNDB interface */
1746 DEVMETHOD(bhndb_set_window_addr, bhndb_pci_set_window_addr),
1747 DEVMETHOD(bhndb_populate_board_info, bhndb_pci_populate_board_info),
1748 DEVMETHOD(bhndb_map_intr_isrc, bhndb_pci_map_intr_isrc),
1749 DEVMETHOD(bhndb_route_interrupts, bhndb_pci_route_interrupts),
1751 /* BHND PWRCTL hostb interface */
1752 DEVMETHOD(bhnd_pwrctl_hostb_get_clksrc, bhndb_pci_pwrctl_get_clksrc),
1753 DEVMETHOD(bhnd_pwrctl_hostb_gate_clock, bhndb_pci_pwrctl_gate_clock),
1754 DEVMETHOD(bhnd_pwrctl_hostb_ungate_clock, bhndb_pci_pwrctl_ungate_clock),
1759 DEFINE_CLASS_1(bhndb, bhndb_pci_driver, bhndb_pci_methods,
1760 sizeof(struct bhndb_pci_softc), bhndb_driver);
1762 MODULE_VERSION(bhndb_pci, 1);
1763 MODULE_DEPEND(bhndb_pci, bhnd_pci_hostb, 1, 1, 1);
1764 MODULE_DEPEND(bhndb_pci, pci, 1, 1, 1);
1765 MODULE_DEPEND(bhndb_pci, bhndb, 1, 1, 1);
1766 MODULE_DEPEND(bhndb_pci, bhnd, 1, 1, 1);