From 2ee472d028ecbaf1d25a179e46dc4a0f63034131 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 27 Mar 2024 15:15:00 +0000 Subject: [PATCH] Support having bcmpcie(4) as both PCIe bus and simplebus to enable use of the Raspberry Pi 5's RP1 I/O controller, which is connected over PCIe. With this, the peripherals on the RP1 are enumerated and attached as well. ok kettenis@ --- sys/dev/fdt/bcm2711_pcie.c | 28 ++++++++++++++++++++++------ sys/dev/fdt/files.fdt | 4 ++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/sys/dev/fdt/bcm2711_pcie.c b/sys/dev/fdt/bcm2711_pcie.c index 044cdf9d424..1708787f8bb 100644 --- a/sys/dev/fdt/bcm2711_pcie.c +++ b/sys/dev/fdt/bcm2711_pcie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcm2711_pcie.c,v 1.12 2024/02/03 10:37:26 kettenis Exp $ */ +/* $OpenBSD: bcm2711_pcie.c,v 1.13 2024/03/27 15:15:00 patrick Exp $ */ /* * Copyright (c) 2020 Mark Kettenis * @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,7 @@ struct bcmpcie_range { }; struct bcmpcie_softc { - struct device sc_dev; + struct simplebus_softc sc_sbus; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; bus_dma_tag_t sc_dmat; @@ -97,9 +98,11 @@ bcmpcie_match(struct device *parent, void *match, void *aux) { struct fdt_attach_args *faa = aux; - return OF_is_compatible(faa->fa_node, "brcm,bcm2711-pcie"); + return OF_is_compatible(faa->fa_node, "brcm,bcm2711-pcie") || + OF_is_compatible(faa->fa_node, "brcm,bcm2712-pcie"); } +int bcmpcie_submatch(struct device *, void *, void *); void bcmpcie_attach_hook(struct device *, struct device *, struct pcibus_attach_args *); int bcmpcie_bus_maxdevs(void *, int); @@ -272,8 +275,6 @@ bcmpcie_attach(struct device *parent, struct device *self, void *aux) } } - printf("\n"); - memcpy(&sc->sc_bus_iot, sc->sc_iot, sizeof(sc->sc_bus_iot)); sc->sc_bus_iot.bus_private = sc; sc->sc_bus_iot._space_map = bcmpcie_bs_iomap; @@ -314,7 +315,22 @@ bcmpcie_attach(struct device *parent, struct device *self, void *aux) pba.pba_domain = pci_ndomains++; pba.pba_bus = 0; - config_found(self, &pba, NULL); + /* Attach device tree nodes enumerating PCIe bus */ + simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa); + + config_found_sm(self, &pba, NULL, bcmpcie_submatch); +} + +int +bcmpcie_submatch(struct device *self, void *match, void *aux) +{ + struct cfdata *cf = match; + struct pcibus_attach_args *pba = aux; + + if (strcmp(pba->pba_busname, cf->cf_driver->cd_name) != 0) + return 0; + + return (*cf->cf_attach->ca_match)(self, match, aux); } void diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index e8bc5e5f2c3..3a5a417f058 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.201 2024/03/02 19:52:41 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.202 2024/03/27 15:15:00 patrick Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -132,7 +132,7 @@ device bcmmbox attach bcmmbox at fdt file dev/fdt/bcm2835_mbox.c bcmmbox -device bcmpcie: pcibus +device bcmpcie: pcibus, fdt attach bcmpcie at fdt file dev/fdt/bcm2711_pcie.c bcmpcie -- 2.20.1