core: add memory flag ROOTSHARED and use it

This patch introduces a memory flag to express shared memory with the
root cell. Memory regions with that flag will stay mapped in the root
cell on non-root-cell creation and do not need to be mapped back into
the root cell on non-root-cell destruction.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86 apic: make sure to only send valid irqs

struct apic_irq_message has a valid field, make sure to call
apic_send_irq only in cases where this bit is set. This protects us
against sending invalid interrupts during handover when the Linux setup
should ever be broken.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: extended commit description]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
apic: extract irq validation logic from iommu_map_interrupt

Introducing a new function apic_irq_dest_in_cell that makes sure the
destination cpu of the interrupt belongs to the given cell.
So far this code was part of iommu_map_interrupt but these checks are
required in other places as well.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: trivial formatting adjustments]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: move define from pci.c to general pci header

This prepares for using the define in other C-files.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: ignore PCI bridge violations in Linux to allow bus rescans

When adding new devices Linux will access the PCI root bridge. Introduce
a HACK that will ignore the access and not treat it as a violation.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver, pci: add functions to add/del devices to/from root-cell

This patch introduces functions to add or remove PCI devices in the root
cell. The functions are not called yet, the patch prepares for virtual
PCI devices.
The original idea was to remove PCI devices from Linux on cell create
and re-add them on cell destroy. But in this case Linux could reprogram
the BARs so we ignore regular PCI devices for now.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver: add/remove virtual PCI devices to/from root-cell

Introduce a new PCI device class and make Linux discover these virtual
PCI devices on enable and remove them on disable.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: cell-config: add field to PCI device struct to refer to memory

Add shmem_region to struct jailhouse_pci_device to be able to refer to
the shared memory region used by the virtual PCI device used for
inter-cell communication.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: apic: make function non-static

Make the function pci_translate_msi_vector available for code outside of
arch/x86/pci.c.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: add a bunch of defines to pci.h

Add a few general defines to pci.h. They will be used in a later commit
by the ivshmem virtual PCI device but are not specific to it.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: add list for virtual PCI devices to cell, makes lookup faster

Add a list of virtual PCI devices to a cell, that way we do need to go
through all PCI devices when looking for virtual ones. This lookup is on
the mmio path, which should be fast.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: refactor error path of pci_cell_init()

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: add load barrier for serialization

Introduce a memory load barrier function.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci_ivshmem: add PCI shared memory device

This patch adds support for a virtio shared memory device which can be
used for inter-cell communication.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates, configs: add ivshmem virtual PCI device demo code and config

New demo to demonstrate ivshmem virtual PCI devices for shared memory
inter-cell communication.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: adjusted region location]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
configs: qemu: add a virtual PCI device to qemu config

This adds a virtual PCI device of type ivshmem to the root-cell on qemu.
Starting a cell with an ivshmem at the same bdf, refering to the same
memory will allow the two cells to connect.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: adjusted memory regions to avoid overlappings]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
docs: add documentation for inter-cell communication

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: x86: Account for rounding of region address in map_range

When feeding in a start address that is not huge-page aligned, we will
let the mapping start earlier, thus also have to extend the size.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
docs: inter-cell: Add pointer to root-cell test code

Adding a section on how to play with inter-cell communication and where
to find the Linux test code.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Fix asm-defines.h dependencies tracking

Previously, a change to headers like <asm/percpu.h> didn't trigger
a rebuild of asm-defines.s (thus asm-defines.h). This is fixed now.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>