mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
intel-iommu: add Intel IOMMU emulation to q35 and add a machine option "iommu" as a switch
Add Intel IOMMU emulation to q35 chipset and expose it to the guest. 1. Add a machine option. Users can use "-machine iommu=on|off" in the command line to enable/disable Intel IOMMU. The default is off. 2. Accroding to the machine option, q35 will initialize the Intel IOMMU and use pci_setup_iommu() to setup q35_host_dma_iommu() as the IOMMU function for the pci bus. 3. q35_host_dma_iommu() will return different address space according to the bus_num and devfn of the device. Signed-off-by: Le Tan <tamlokveer@gmail.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
d4eb911935
commit
a52a7fdfa7
6 changed files with 74 additions and 1 deletions
|
@ -347,6 +347,48 @@ static void mch_reset(DeviceState *qdev)
|
|||
mch_update(mch);
|
||||
}
|
||||
|
||||
static AddressSpace *q35_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)
|
||||
{
|
||||
IntelIOMMUState *s = opaque;
|
||||
VTDAddressSpace **pvtd_as;
|
||||
int bus_num = pci_bus_num(bus);
|
||||
|
||||
assert(0 <= bus_num && bus_num <= VTD_PCI_BUS_MAX);
|
||||
assert(0 <= devfn && devfn <= VTD_PCI_DEVFN_MAX);
|
||||
|
||||
pvtd_as = s->address_spaces[bus_num];
|
||||
if (!pvtd_as) {
|
||||
/* No corresponding free() */
|
||||
pvtd_as = g_malloc0(sizeof(VTDAddressSpace *) * VTD_PCI_DEVFN_MAX);
|
||||
s->address_spaces[bus_num] = pvtd_as;
|
||||
}
|
||||
if (!pvtd_as[devfn]) {
|
||||
pvtd_as[devfn] = g_malloc0(sizeof(VTDAddressSpace));
|
||||
|
||||
pvtd_as[devfn]->bus_num = (uint8_t)bus_num;
|
||||
pvtd_as[devfn]->devfn = (uint8_t)devfn;
|
||||
pvtd_as[devfn]->iommu_state = s;
|
||||
memory_region_init_iommu(&pvtd_as[devfn]->iommu, OBJECT(s),
|
||||
&s->iommu_ops, "intel_iommu", UINT64_MAX);
|
||||
address_space_init(&pvtd_as[devfn]->as,
|
||||
&pvtd_as[devfn]->iommu, "intel_iommu");
|
||||
}
|
||||
return &pvtd_as[devfn]->as;
|
||||
}
|
||||
|
||||
static void mch_init_dmar(MCHPCIState *mch)
|
||||
{
|
||||
PCIBus *pci_bus = PCI_BUS(qdev_get_parent_bus(DEVICE(mch)));
|
||||
|
||||
mch->iommu = INTEL_IOMMU_DEVICE(qdev_create(NULL, TYPE_INTEL_IOMMU_DEVICE));
|
||||
object_property_add_child(OBJECT(mch), "intel-iommu",
|
||||
OBJECT(mch->iommu), NULL);
|
||||
qdev_init_nofail(DEVICE(mch->iommu));
|
||||
sysbus_mmio_map(SYS_BUS_DEVICE(mch->iommu), 0, Q35_HOST_BRIDGE_IOMMU_ADDR);
|
||||
|
||||
pci_setup_iommu(pci_bus, q35_host_dma_iommu, mch->iommu);
|
||||
}
|
||||
|
||||
static int mch_init(PCIDevice *d)
|
||||
{
|
||||
int i;
|
||||
|
@ -370,6 +412,10 @@ static int mch_init(PCIDevice *d)
|
|||
&mch->pam_regions[i+1], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE,
|
||||
PAM_EXPAN_SIZE);
|
||||
}
|
||||
/* Intel IOMMU (VT-d) */
|
||||
if (qemu_opt_get_bool(qemu_get_machine_opts(), "iommu", false)) {
|
||||
mch_init_dmar(mch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue