diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c index bfb069c195a5..8ec875c7bc63 100644 --- a/sys/arm64/arm64/gicv3_its.c +++ b/sys/arm64/arm64/gicv3_its.c @@ -32,6 +32,7 @@ #include "opt_acpi.h" #include "opt_platform.h" +#include "opt_iommu.h" #include __FBSDID("$FreeBSD$"); @@ -47,6 +48,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include #include #include @@ -56,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -72,6 +76,11 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef IOMMU +#include +#include +#endif + #include "pcib_if.h" #include "pic_if.h" #include "msi_if.h" @@ -269,6 +278,7 @@ struct gicv3_its_softc { #define ITS_FLAGS_ERRATA_CAVIUM_22375 0x00000004 u_int sc_its_flags; bool trace_enable; + vm_page_t ma; /* fake msi page */ }; static void *conf_base; @@ -321,6 +331,10 @@ static msi_release_msi_t gicv3_its_release_msi; static msi_alloc_msix_t gicv3_its_alloc_msix; static msi_release_msix_t gicv3_its_release_msix; static msi_map_msi_t gicv3_its_map_msi; +#ifdef IOMMU +static msi_iommu_init_t gicv3_iommu_init; +static msi_iommu_deinit_t gicv3_iommu_deinit; +#endif static void its_cmd_movi(device_t, struct gicv3_its_irqsrc *); static void its_cmd_mapc(device_t, struct its_col *, uint8_t); @@ -352,6 +366,10 @@ static device_method_t gicv3_its_methods[] = { DEVMETHOD(msi_alloc_msix, gicv3_its_alloc_msix), DEVMETHOD(msi_release_msix, gicv3_its_release_msix), DEVMETHOD(msi_map_msi, gicv3_its_map_msi), +#ifdef IOMMU + DEVMETHOD(msi_iommu_init, gicv3_iommu_init), + DEVMETHOD(msi_iommu_deinit, gicv3_iommu_deinit), +#endif /* End */ DEVMETHOD_END @@ -803,8 +821,9 @@ static int gicv3_its_attach(device_t dev) { struct gicv3_its_softc *sc; - uint32_t iidr; int domain, err, i, rid; + uint64_t phys; + uint32_t iidr; sc = device_get_softc(dev); @@ -820,6 +839,11 @@ gicv3_its_attach(device_t dev) return (ENXIO); } + phys = rounddown2(vtophys(rman_get_virtual(sc->sc_its_res)) + + GITS_TRANSLATER, PAGE_SIZE); + sc->ma = malloc(sizeof(struct vm_page), M_DEVBUF, M_WAITOK | M_ZERO); + vm_page_initfake(sc->ma, phys, VM_MEMATTR_DEFAULT); + iidr = gic_its_read_4(sc, GITS_IIDR); for (i = 0; i < nitems(its_quirks); i++) { if ((iidr & its_quirks[i].iidr_mask) == its_quirks[i].iidr) { @@ -1419,6 +1443,33 @@ gicv3_its_map_msi(device_t dev, device_t child, struct intr_irqsrc *isrc, return (0); } +#ifdef IOMMU +static int +gicv3_iommu_init(device_t dev, device_t child, struct iommu_domain **domain) +{ + struct gicv3_its_softc *sc; + struct iommu_ctx *ctx; + int error; + + sc = device_get_softc(dev); + ctx = iommu_get_dev_ctx(child); + error = iommu_map_msi(ctx, PAGE_SIZE, GITS_TRANSLATER, + IOMMU_MAP_ENTRY_WRITE, IOMMU_MF_CANWAIT, &sc->ma); + *domain = iommu_get_ctx_domain(ctx); + + return (error); +} + +static void +gicv3_iommu_deinit(device_t dev, device_t child) +{ + struct iommu_ctx *ctx; + + ctx = iommu_get_dev_ctx(child); + iommu_unmap_msi(ctx); +} +#endif + /* * Commands handling. */