x86/tools/inmates: Account for 32-bit PM timers

Some systems may use 32-bit PM timer (as defined by TMR_VAL_EXT feature
flag in FADT), however pm_timer_read() assumes it is always 24-bit. Where
this assumption is wrong, return value becomes incorrect, and the error
grows over time leading to obscure bugs, including lockups in the hypervisor.

To fix this, TMR_VAL_EXT is made part of platform config and is passed to
inmates in the communication region. Config generator was also adapted
to parse FADT to get TMR_VAL_EXT value for target system. pm_timer_init()
function was also introduced to the inmates framework to the overflow value.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
[Jan: mark jailhouse_comm_region as packed]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
pci: fix msix device list remove-code

In pci_remove_device we want to remove only one device from the list.
The current code truncates our device list and drops the tail, fix that
by just unchaining one element.

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

Introduce a make target to remove generated documentation.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
docs: add x86 doxygen module

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
docs: x86 apic: add x86 apic doxygen submodule

Add a new doxygen submodule and convert existing documentation to
doxygen style.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
[Jan: renamed module to "APIC"]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: fix pci MSI-X support code bug

The "Message Control" field of a MSI-X capability structure starts two
bytes after the capabilty id, not just one.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools: config-create: rename parse_cmdline to parse_kernel_cmdline

`parse_cmdline` is quite missleading in the context of a script with
command-line parameters. Thus better name it for what it does, parse the
kernel command line.

Signed-off-by: Benjamin Block <bebl@mageta.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Documentation: Introduce coding style

As the number of external contributions to Jailhouse grows, the need
for some formal coding style to ease review process and integration
arise. This is the first attempt to summarize what's have been discussed
on jailhouse-dev@googlegroups.com mailing list so far.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
[Jan: clarify include block separation]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: x86: align code after last level of page tables

The header contains the page tables but the last level (pd) contained the
code right after the first entry. Calls to map_range would actually
overwrite the inmates code.
This patch makes sure the code will start on the next page.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver: Express build dependency on version.h

This fixes the issue that the driver module is not rebuilt properly when
the version header changes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Fix assembly constraints in per_cpu()

lea's second operand can only be a register. Adjust the constraints
accordingly. LLVM/clang stumbled over this.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: x86: Use .code16 instead of .code16gcc

This removes support for binutils < 2.16 but makes us more portable.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: x86: Refactor lgdt instruction expression

This expresses the intention to load from gdt_ptr using CS clearer than
via the cs prefix, and it is more portable to other assemblers (namely
that of clang).

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
gitignore: add another vim temp file extension

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates: x86: align code after 32-bit page table

Analogous to 906e53b246, fix also the 32-bit header.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Prepare for AMD-V data structures

VMX-specific data members in struct cell and struct per_cpu were "unionized"
to avoid #ifdefs later, when AMD-V members will be introduced. As a part of these
changes, I/O bitmap became heap-allocated to make this field equally-sized for
both VMX and SVM.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Introduce AMD-V code skeleton

Introduce a set of vendor-specific headers and sources that contain stubs for
functions required to support AMD-V (SVM) in Jailhouse. As AMD IOMMU support
is not planned for now, iommu_init() does nothing more than print a warning.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
makefiles: Build jailhouse-{amd,intel} together

This build system update brings an ability to build "jailhouse.bin"
firmware for different architecture "variants" (currently, AMD and
Intel on x86_64) simultaneously. Corresponding firmware files are
called 'jailhouse-$variant.bin'. Variants are introduced in
$(BUILD_VARIANTS) in hypervisor/Makefile and also in corresponding
arch Makefiles. Having per-variant compilation options inside one
architecture is not supported.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver: Support "variants" in firmware name

Jailhouse loader was also updated to locate and load a correct firmware
binary depending on a type of the system hypervisor executes on.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
[Jan: adjusted #endif to keep MODULE_VERSION unconditional]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Choose a hypercall instruction in run-time

VMX and SVM use different instructions to make a hypercall (vmcall and
vmmcall, respectively). Jailhouse abstracts hypercall instructions with
inlined functions in jailhouse_hypercall.h, and these need to be able to
differentiate between VMX and SVM. For this reason, jailhouse_use_vmcall
global variable was introduced that is stored and filled by the driver.
Inmates will require similar initialization. This is left out as inmates
do not make use of hypercalls at this point.

As jailhouse_call_*() functions are never called on a CPU without VM
extensions (the driver checks if Jailhouse is enabled before issuing a
hypercall, and inmates do not run outside cells), it is safe to assume
that the CPU without VMX support is an SVM one.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
[Jan: dropped inmate initialization,
      switched to bool for jailhouse_use_vmcall,
      refactored init_use_vmcall_flag to init_hypercall]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

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