From 0c73ff81299d840a3428060503677831a3dc562d Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 28 Jan 2020 12:06:21 +0100 Subject: [PATCH] iommu: Add topology structures The virtio-iommu device defines a new virtio feature allowing the topology to be discovered fully through virtio configuration. By topology, it means describing the devices attached to the virtual IOMMU. This is currently managed through ACPI with IORT and VIOT table, but this is another way of describing it. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/iommu.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vm-virtio/src/iommu.rs b/vm-virtio/src/iommu.rs index 211e0f4a7..07a80e83e 100644 --- a/vm-virtio/src/iommu.rs +++ b/vm-virtio/src/iommu.rs @@ -65,6 +65,10 @@ const VIRTIO_IOMMU_F_MAP_UNMAP: u32 = 2; #[allow(unused)] const VIRTIO_IOMMU_F_BYPASS: u32 = 3; const VIRTIO_IOMMU_F_PROBE: u32 = 4; +#[allow(unused)] +const VIRTIO_IOMMU_F_MMIO: u32 = 5; +#[allow(unused)] +const VIRTIO_IOMMU_F_TOPOLOGY: u32 = 6; // Support 2MiB and 4KiB page sizes. const VIRTIO_IOMMU_PAGE_SIZE_MASK: u64 = (2 << 20) | (4 << 10); @@ -109,6 +113,34 @@ struct VirtioIommuConfig { unsafe impl ByteValued for VirtioIommuConfig {} +#[allow(unused)] +const VIRTIO_IOMMU_TOPO_PCI_RANGE: u32 = 1; +#[allow(unused)] +const VIRTIO_IOMMU_TOPO_ENDPOINT: u32 = 2; + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +struct VirtioIommuTopoPciRange { + type_: u16, + hierarchy: u16, + requester_start: u16, + requester_end: u16, + endpoint_start: u32, +} + +unsafe impl ByteValued for VirtioIommuTopoPciRange {} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +struct VirtioIommuTopoEndpoint { + type_: u16, + reserved: u16, + endpoint: u32, + address: u64, +} + +unsafe impl ByteValued for VirtioIommuTopoEndpoint {} + /// Virtio IOMMU request type const VIRTIO_IOMMU_T_ATTACH: u8 = 1; const VIRTIO_IOMMU_T_DETACH: u8 = 2;