x86: Reconfigure DMAR units on cell creation

Remove devices that shall be assigned to a newly created cell from
Linux. Then we can initialize the new cell regularly via vtd_cell_init.
We use a register-based cache flush on Linux cell shrinking, requesting
domain granularity for the flush. As the page table will be new and all
reassigned devices are disabled before entry of vtd_cell_init, there is
no need to flush caches after the creation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core/driver: Introduce jailhouse_cell_mem_regions helper

Given a cell configuration, this function returns a pointer to the first
memory region. Use it instead of open-coding the address calculation.
This requires marking several pointers to jailhouse_memory as
referencing a constant data structure.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Introduce jailhouse_cell_pio_bitmap helper

Given a cell configuration, this function returns a pointer to the PIO
bitmap. Use it instead of open-coding the address calculation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core/driver: Introduce jailhouse_cell_cpu_set helper

Given a cell configuration, this function returns a pointer to the CPU
set. Use it instead of open-coding the address calculation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Introduce jailhouse_cell_pci_devices helper

Given a cell configuration, this function returns a pointer to the first
PCI device. Use it instead of open-coding the address calculation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Generic memory region handling on cell destruction

Most of vmx_remap_to_linux and also the memory region loop in
vmx_cell_exit are generic and can be reused for adding VT-d support and,
later on, different architectures. So move the generic bits to the core
and provide arch_map_memory_region and arch_unmap_memory_region instead.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Release VT-d resources on cell destruction

Corresponding to VMX, implement vtd_map_memory_region,
vtd_unmap_memory_region and vtd_cell_exit so that we can drop all VT-d
related resources of a cell on its destruction and, according to the
configuration, reassign them back to Linux.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Physically reset APIC on INIT emulation and shutdown

Make sure non of the previous APIC state leaks across an INIT signal or
the shutdown of non-Linux cells.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>