Add IOMMU support to GICv3 Interrupt Translation Service (ITS) driver.

Submitted by:	andrew
Sponsored by:	Innovate DSbD
Differential Revision:	https://reviews.freebsd.org/D26878
This commit is contained in:
Ruslan Bukin 2020-10-25 10:08:46 +00:00
parent 6eb925f845
commit ba196aec7d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367037

View File

@ -32,6 +32,7 @@
#include "opt_acpi.h"
#include "opt_platform.h"
#include "opt_iommu.h"
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -47,6 +48,8 @@ __FBSDID("$FreeBSD$");
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/taskqueue.h>
#include <sys/tree.h>
#include <sys/queue.h>
#include <sys/rman.h>
#include <sys/sbuf.h>
@ -56,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_page.h>
#include <machine/bus.h>
#include <machine/intr.h>
@ -72,6 +76,11 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#ifdef IOMMU
#include <dev/iommu/iommu.h>
#include <dev/iommu/iommu_gas.h>
#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.
*/