x86: Fix emulated X2APIC ID reading

The xAPIC reports its ID in different bits than the x2APIC. Account for
this when emulating x2APIC accesses by calling the read_id handler.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Handle more SIB cases in MMIO instruction parser

This adds, among other things, support for using r12 as address register
in MMIO accesses. And it actually simplifies the code. We can ignore SS
and index in MOD 0 as these only affect the memory address we obtain
differently.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Refactor folder structure

Move common code into inmates/lib and showcases into a inmates/demos to
prepare for a reusable and extensible inmates framework. Also split
along architecture dependencies, we will get code for non-x86 as well
one day.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Map Comm Region always at 0x100000 for inmates framework

Standardize mapping and access to the Comm Region within the inmates
framework. Reduces the work to be done for new inmates. We will move it
higher once paging services are available so that larger inmates can be
created.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Factor our interrupt library services

This simplifies registering interrupt handlers and also moves the EOI
ACK into library code. Only 64-bit support so far. Still, we need to fix
the definition of s64/u64 and make read/write_msr compatible with 32-bit
builds.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Factor out timing services

Move the APIC timer services together with PM timer access into a timing
library module.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Truly terminate apic-demo on second attempt

More consistent demo: Reject the first shutdown request and keep running
until the second arrives. Then terminate directly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add memory services to inmates framework

This adds a primitive memory allocator (without release) and a page
mapper (without unmap) to the inmates library. MMIO accessors are also
included. Those used for intercepted resources are encoded in assembly
to ensure that only supported instructions are used. With these
services, inmates can now access memory-mapped devices.

The allocator uses the lower memory starting from the first page.
Document this as well as the remaining memory layout.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Provide missing PIO accessors

Add inw, outw and outl.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add IOAPIC service to inmates framework

This provides the functionality for programing an assigned IOAPIC pin to
send standard IRQs to the caller's CPU. Just enough for basic IOAPIC
usage.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add IOAPIC demo

Simply demonstration and test for using the IOAPIC within an non-root
cell: Rob the ACPI IRQ and wait for events on this line, e.g. a power
button push. Read the warning before using it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Halt on return from inmate_main

Remove the need for explicit clt;hlt from the inmates, moving this to
header code.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add primitive 32-bit demo

This only demonstrates the capability to build inmates which come up in
32-bit mode. Note that not all library services support this already.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add PCI services to inmates framework

Provide library services for PCI config space access, bus scanning,
capability scanning (non-extended only so far) and MSI vector
programming (MSI-X to be added later).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add delay_us service to timing library

This performs a busy-wait for the specified microseconds.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: Add PCI demo using an Intel HDA

This demonstrates the setup of a PCI device including MSI.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools: config-create: fix cpu counting

Count the number of cpus based on another file to detect offline ones as
well. (cpu*/topology/core_id does not exists for offline cpus)

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools: config-create: refuse to generate config if jailhouse is enabled

The input files used by the configuration generator might look different
on a system where jailhouse is enabled. Think missing cpus, pci devices etc.
Refuse to work with potentially corrupt input data.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: add python2 compatibility]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools: cell-list: make python3 compatible

Another version of the patch in which i rely on the fact that python
should garbarge collect file objects that are not referenced anymore.

Henning

Subject: [PATCH] tools: cell-list: make python3 compatible

Avoid python2 only functions.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools: config-create: set default root cell name to RootCell

The cell name could end up as an empty string because it was derived
from optional input files. In fact just giving the root cell a fixed
default name seems to make more sense than to generate a name or require
users to provide one.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>