From 88933a1fbb282bf7c34e5e40982905026b06c781 Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 15 Mar 2021 22:48:57 +0000 Subject: [PATCH] Change API of acpiiort(4). It was written as a hook before, taking the PCI attach args and replacing the DMA tag inside. Our other IOMMU API though takes a DMA tag and returns the old one or a new one. To have acpiiort(4) integrate better with non-PCI ACPI devices, change the API so that it is more similar to the other API. This also makes the code easier to understand. ok kettenis@ --- sys/arch/arm64/dev/acpiiort.c | 16 ++++++++-------- sys/arch/arm64/dev/acpiiort.h | 9 ++++----- sys/arch/arm64/dev/acpipci.c | 4 ++-- sys/arch/arm64/dev/smmu.c | 14 +++----------- sys/arch/arm64/dev/smmu_acpi.c | 4 ++-- sys/arch/arm64/dev/smmu_fdt.c | 4 ++-- sys/arch/arm64/dev/smmuvar.h | 5 ++--- 7 files changed, 23 insertions(+), 33 deletions(-) diff --git a/sys/arch/arm64/dev/acpiiort.c b/sys/arch/arm64/dev/acpiiort.c index 4ce2e5438fe..710d8fdb6ec 100644 --- a/sys/arch/arm64/dev/acpiiort.c +++ b/sys/arch/arm64/dev/acpiiort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpiiort.c,v 1.1 2021/02/28 21:31:10 patrick Exp $ */ +/* $OpenBSD: acpiiort.c,v 1.2 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2021 Patrick Wildt * @@ -88,16 +88,16 @@ acpiiort_smmu_register(struct acpiiort_smmu *as) SIMPLEQ_INSERT_TAIL(&acpiiort_smmu_list, as, as_list); } -void -acpiiort_smmu_hook(struct acpi_iort_node *node, uint32_t rid, - struct pci_attach_args *pa) +bus_dma_tag_t +acpiiort_smmu_map(struct acpi_iort_node *node, uint32_t rid, + bus_dma_tag_t dmat) { struct acpiiort_smmu *as; SIMPLEQ_FOREACH(as, &acpiiort_smmu_list, as_list) { - if (as->as_node == node) { - as->as_hook(as->as_cookie, rid, pa); - break; - } + if (as->as_node == node) + return as->as_map(as->as_cookie, rid, dmat); } + + return dmat; } diff --git a/sys/arch/arm64/dev/acpiiort.h b/sys/arch/arm64/dev/acpiiort.h index 2ee15345d00..fd0c991526f 100644 --- a/sys/arch/arm64/dev/acpiiort.h +++ b/sys/arch/arm64/dev/acpiiort.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpiiort.h,v 1.1 2021/02/28 21:31:10 patrick Exp $ */ +/* $OpenBSD: acpiiort.h,v 1.2 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2021 Patrick Wildt * @@ -26,10 +26,9 @@ struct acpiiort_smmu { SIMPLEQ_ENTRY(acpiiort_smmu) as_list; struct acpi_iort_node *as_node; void *as_cookie; - void (*as_hook)(void *, uint32_t, - struct pci_attach_args *); + bus_dma_tag_t (*as_map)(void *, uint32_t, + bus_dma_tag_t); }; void acpiiort_smmu_register(struct acpiiort_smmu *); -void acpiiort_smmu_hook(struct acpi_iort_node *, uint32_t, - struct pci_attach_args *); +bus_dma_tag_t acpiiort_smmu_map(struct acpi_iort_node *, uint32_t, bus_dma_tag_t); diff --git a/sys/arch/arm64/dev/acpipci.c b/sys/arch/arm64/dev/acpipci.c index 4b63fa5f48f..08d7553d7ae 100644 --- a/sys/arch/arm64/dev/acpipci.c +++ b/sys/arch/arm64/dev/acpipci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpipci.c,v 1.26 2021/02/28 21:42:08 patrick Exp $ */ +/* $OpenBSD: acpipci.c,v 1.27 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -412,7 +412,7 @@ acpipci_probe_device_hook(void *v, struct pci_attach_args *pa) node = (struct acpi_iort_node *)((char *)iort + offset); if (node->type == ACPI_IORT_SMMU) - acpiiort_smmu_hook(node, rid, pa); + pa->pa_dmat = acpiiort_smmu_map(node, rid, pa->pa_dmat); return 0; } diff --git a/sys/arch/arm64/dev/smmu.c b/sys/arch/arm64/dev/smmu.c index 0afe7650f65..b25c4f1d58d 100644 --- a/sys/arch/arm64/dev/smmu.c +++ b/sys/arch/arm64/dev/smmu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smmu.c,v 1.9 2021/03/06 19:30:07 patrick Exp $ */ +/* $OpenBSD: smmu.c,v 1.10 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2008-2009,2014-2016 Dale Rahn * Copyright (c) 2021 Patrick Wildt @@ -500,8 +500,9 @@ smmu_cb_write_8(struct smmu_softc *sc, int idx, bus_size_t off, uint64_t val) } bus_dma_tag_t -smmu_device_hook(struct smmu_softc *sc, uint32_t sid, bus_dma_tag_t dmat) +smmu_device_map(void *cookie, uint32_t sid, bus_dma_tag_t dmat) { + struct smmu_softc *sc = cookie; struct smmu_domain *dom; dom = smmu_domain_lookup(sc, sid); @@ -527,15 +528,6 @@ smmu_device_hook(struct smmu_softc *sc, uint32_t sid, bus_dma_tag_t dmat) return dom->sd_dmat; } -void -smmu_pci_device_hook(void *cookie, uint32_t rid, struct pci_attach_args *pa) -{ - struct smmu_softc *sc = cookie; - - printf("%s: rid %x\n", sc->sc_dev.dv_xname, rid); - pa->pa_dmat = smmu_device_hook(sc, rid, pa->pa_dmat); -} - struct smmu_domain * smmu_domain_lookup(struct smmu_softc *sc, uint32_t sid) { diff --git a/sys/arch/arm64/dev/smmu_acpi.c b/sys/arch/arm64/dev/smmu_acpi.c index 9947383bbc1..10c1daf6137 100644 --- a/sys/arch/arm64/dev/smmu_acpi.c +++ b/sys/arch/arm64/dev/smmu_acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smmu_acpi.c,v 1.1 2021/02/28 21:39:31 patrick Exp $ */ +/* $OpenBSD: smmu_acpi.c,v 1.2 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2021 Patrick Wildt * @@ -125,6 +125,6 @@ smmu_acpi_attach(struct device *parent, struct device *self, void *aux) as = malloc(sizeof(*as), M_DEVBUF, M_WAITOK | M_ZERO); as->as_node = node; as->as_cookie = sc; - as->as_hook = smmu_pci_device_hook; + as->as_map = smmu_device_map; acpiiort_smmu_register(as); } diff --git a/sys/arch/arm64/dev/smmu_fdt.c b/sys/arch/arm64/dev/smmu_fdt.c index b21466abe36..75c80c8efe6 100644 --- a/sys/arch/arm64/dev/smmu_fdt.c +++ b/sys/arch/arm64/dev/smmu_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smmu_fdt.c,v 1.2 2021/03/01 21:35:03 patrick Exp $ */ +/* $OpenBSD: smmu_fdt.c,v 1.3 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2021 Patrick Wildt * @@ -117,5 +117,5 @@ smmu_fdt_map(void *cookie, uint32_t *cells, bus_dma_tag_t dmat) struct smmu_fdt_softc *fsc = (struct smmu_fdt_softc *)cookie; struct smmu_softc *sc = &fsc->sc_smmu; - return smmu_device_hook(sc, cells[0], dmat); + return smmu_device_map(sc, cells[0], dmat); } diff --git a/sys/arch/arm64/dev/smmuvar.h b/sys/arch/arm64/dev/smmuvar.h index 3d52f3c8b69..ca3a7b36d14 100644 --- a/sys/arch/arm64/dev/smmuvar.h +++ b/sys/arch/arm64/dev/smmuvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smmuvar.h,v 1.3 2021/03/05 00:55:45 patrick Exp $ */ +/* $OpenBSD: smmuvar.h,v 1.4 2021/03/15 22:48:57 patrick Exp $ */ /* * Copyright (c) 2021 Patrick Wildt * @@ -79,5 +79,4 @@ struct smmu_softc { int smmu_attach(struct smmu_softc *); int smmu_global_irq(void *); int smmu_context_irq(void *); -bus_dma_tag_t smmu_device_hook(struct smmu_softc *, uint32_t, bus_dma_tag_t); -void smmu_pci_device_hook(void *, uint32_t, struct pci_attach_args *); +bus_dma_tag_t smmu_device_map(void *, uint32_t, bus_dma_tag_t); -- 2.20.1