Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/apple Use fdt_iommu instead of calling appledar...
details: https://anonhg.NetBSD.org/src/rev/7e1f6ba7042d
branches: trunk
changeset: 1023348:7e1f6ba7042d
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sat Sep 04 12:35:31 2021 +0000
description:
Use fdt_iommu instead of calling appledart directly from applepcie
diffstat:
sys/arch/arm/apple/apple_dart.c | 58 ++++++++++------------------------------
sys/arch/arm/apple/apple_pcie.c | 38 ++++---------------------
2 files changed, 22 insertions(+), 74 deletions(-)
diffs (163 lines):
diff -r 27e9ae108cd3 -r 7e1f6ba7042d sys/arch/arm/apple/apple_dart.c
--- a/sys/arch/arm/apple/apple_dart.c Sat Sep 04 12:34:39 2021 +0000
+++ b/sys/arch/arm/apple/apple_dart.c Sat Sep 04 12:35:31 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_dart.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $ */
+/* $NetBSD: apple_dart.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Mark Kettenis <kettenis%openbsd.org@localhost>
@@ -20,7 +20,7 @@
//#define APPLE_DART_DEBUG
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_dart.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_dart.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -36,46 +36,6 @@
#include <dev/fdt/fdtvar.h>
/*
- * DT node to bus_dma tag mappings
- */
-
-bus_dma_tag_t apple_dart_iommu_lookup(int);
-
-struct apple_dart_iommu {
- int phandle;
- bus_dma_tag_t dmat;
- LIST_ENTRY(apple_dart_iommu) next;
-};
-
-static LIST_HEAD(, apple_dart_iommu) apple_dart_iommus =
- LIST_HEAD_INITIALIZER(apple_dart_iommus);
-
-static void
-apple_dart_iommu_register(int phandle, bus_dma_tag_t dmat)
-{
- struct apple_dart_iommu *iommu;
-
- iommu = kmem_alloc(sizeof(*iommu), KM_SLEEP);
- iommu->phandle = phandle;
- iommu->dmat = dmat;
- LIST_INSERT_HEAD(&apple_dart_iommus, iommu, next);
-}
-
-bus_dma_tag_t
-apple_dart_iommu_lookup(int phandle)
-{
- struct apple_dart_iommu *iommu;
-
- LIST_FOREACH(iommu, &apple_dart_iommus, next) {
- if (iommu->phandle == phandle) {
- return iommu->dmat;
- }
- }
-
- panic("Couldn't find IOMMU for node 0x%x", phandle);
-}
-
-/*
* DART registers
*/
#define DART_TLB_OP 0x0020
@@ -473,6 +433,18 @@
sc->sc_dmat->_dmamap_unload(sc->sc_dmat, map);
}
+static bus_dma_tag_t
+apple_dart_iommu_map(device_t dev, const u_int *data, bus_dma_tag_t dmat)
+{
+ struct apple_dart_softc * const sc = device_private(dev);
+
+ return &sc->sc_bus_dmat;
+}
+
+const struct fdtbus_iommu_func apple_dart_iommu_funcs = {
+ .map = apple_dart_iommu_map,
+};
+
static int
apple_dart_match(device_t parent, cfdata_t cf, void *aux)
{
@@ -623,7 +595,7 @@
sc->sc_bus_dmat._dmamap_load_raw = apple_dart_dmamap_load_raw;
sc->sc_bus_dmat._dmamap_unload = apple_dart_dmamap_unload;
- apple_dart_iommu_register(phandle, &sc->sc_bus_dmat);
+ fdtbus_register_iommu(self, phandle, &apple_dart_iommu_funcs);
}
CFATTACH_DECL_NEW(apple_dart, sizeof(struct apple_dart_softc),
diff -r 27e9ae108cd3 -r 7e1f6ba7042d sys/arch/arm/apple/apple_pcie.c
--- a/sys/arch/arm/apple/apple_pcie.c Sat Sep 04 12:34:39 2021 +0000
+++ b/sys/arch/arm/apple/apple_pcie.c Sat Sep 04 12:35:31 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_pcie.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $ */
+/* $NetBSD: apple_pcie.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $ */
/*-
* Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_pcie.c,v 1.1 2021/08/30 23:26:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_pcie.c,v 1.2 2021/09/04 12:35:31 jmcneill Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -52,9 +52,6 @@
#define PCIE_MSI_REMAP 0x0128
#define PCIE_MSI_DOORBELL 0x0168
-/* XXX apple_dart.c */
-extern bus_dma_tag_t apple_dart_iommu_lookup(int);
-
struct apple_pcie_softc {
struct pcihost_softc sc_pcihost;
@@ -174,36 +171,15 @@
{
struct apple_pcie_softc *sc = pba->pba_pc->pc_conf_v;
const int phandle = sc->sc_pcihost.sc_phandle;
- const u_int *iommu_map;
- int len;
+ bus_dma_tag_t dmat;
KASSERT(device_is_a(sc->sc_pcihost.sc_dev, "applepcie"));
- iommu_map = fdtbus_get_prop(phandle, "iommu-map", &len);
- if (iommu_map == NULL) {
- panic("%s: no iommu-map?!",
- device_xname(sc->sc_pcihost.sc_dev));
- return;
- }
-
- while (len >= 16) {
- const u_int ridbase = be32toh(iommu_map[0]);
- const u_int xref = fdtbus_get_phandle_from_native(
- be32toh(iommu_map[1]));
+ /* XXX this should be per-device, not per-bus */
+ const uint32_t rid = pba->pba_bus << 8;
- const int bus = (ridbase >> 8) & 0xff;
- if (bus == pba->pba_bus) {
- pba->pba_dmat = apple_dart_iommu_lookup(xref);
- pba->pba_dmat64 = pba->pba_dmat;
- return;
- }
-
- iommu_map += 4;
- len -= 16;
- }
-
- //panic("no iommu for bus %d\n", pba->pba_bus);
- pba->pba_dmat = pba->pba_dmat64 = sc->sc_pcihost.sc_dmat;
+ dmat = fdtbus_iommu_map_pci(phandle, rid, sc->sc_pcihost.sc_dmat);
+ pba->pba_dmat = pba->pba_dmat64 = dmat;
}
static int
Home |
Main Index |
Thread Index |
Old Index