From 8721a9a3c2b02841016eb1670e7bd9b185a18ba4 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Thu, 18 Feb 2016 07:13:02 +0100 Subject: [PATCH] core, configs, tools: Introduce struct jailhouse_iommu For both AMD and Intel, we need to store not only base address but also a size to map the complete MMIO region. Moreover, AMD requires a number of PCI device parameters for the IOMMU. Introduce struct jailhouse_iommu that will encapsulate all required data. Based on patches by Valentine Sinitsyn. Signed-off-by: Jan Kiszka --- configs/f2a88xm-hd3.c | 6 ++++-- configs/h87i.c | 10 +++++++--- configs/qemu-vm.c | 6 ++++-- hypervisor/arch/x86/iommu.c | 2 +- hypervisor/arch/x86/vtd.c | 10 +++++----- hypervisor/include/jailhouse/cell-config.h | 7 ++++++- tools/root-cell-config.c.tmpl | 8 +++++--- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/configs/f2a88xm-hd3.c b/configs/f2a88xm-hd3.c index 545da80..825452a 100644 --- a/configs/f2a88xm-hd3.c +++ b/configs/f2a88xm-hd3.c @@ -44,8 +44,10 @@ struct { .mmconfig_base = 0xe0000000, .mmconfig_end_bus = 0xff, .pm_timer_address = 0x808, - .iommu_base = { - 0xfeb80000, + .iommu_units = { + { + .base = 0xfeb80000, + }, }, }, .device_limit = 128, diff --git a/configs/h87i.c b/configs/h87i.c index 521d274..2015729 100644 --- a/configs/h87i.c +++ b/configs/h87i.c @@ -39,9 +39,13 @@ struct { .mmconfig_base = 0xf8000000, .mmconfig_end_bus = 0x3f, .pm_timer_address = 0x1808, - .iommu_base = { - 0xfed90000, - 0xfed91000, + .iommu_units = { + { + .base = 0xfed90000, + }, + { + .base = 0xfed91000, + }, }, }, .interrupt_limit = 256, diff --git a/configs/qemu-vm.c b/configs/qemu-vm.c index 1f9966e..1d7481e 100644 --- a/configs/qemu-vm.c +++ b/configs/qemu-vm.c @@ -53,8 +53,10 @@ struct { .mmconfig_base = 0xb0000000, .mmconfig_end_bus = 0xff, .pm_timer_address = 0x608, - .iommu_base = { - 0xfed90000, + .iommu_units = { + { + .base = 0xfed90000, + }, }, }, .interrupt_limit = 256, diff --git a/hypervisor/arch/x86/iommu.c b/hypervisor/arch/x86/iommu.c index 3da61d6..11f35bc 100644 --- a/hypervisor/arch/x86/iommu.c +++ b/hypervisor/arch/x86/iommu.c @@ -18,7 +18,7 @@ unsigned int iommu_count_units(void) unsigned int units = 0; while (units < JAILHOUSE_MAX_IOMMU_UNITS && - system_config->platform_info.x86.iommu_base[units]) + system_config->platform_info.x86.iommu_units[units].base) units++; return units; } diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index 18d6e4c..5826b87 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -421,7 +421,7 @@ static int vtd_init_ir_emulation(unsigned int unit_no, void *reg_base) root_cell.arch.vtd.ir_emulation = true; - base = system_config->platform_info.x86.iommu_base[unit_no]; + base = system_config->platform_info.x86.iommu_units[unit_no].base; mmio_region_register(&root_cell, base, PAGE_SIZE, vtd_unit_access_handler, unit); @@ -454,8 +454,8 @@ int iommu_init(void) { unsigned long version, caps, ecaps, ctrls, sllps_caps = ~0UL; unsigned int units, pt_levels, num_did, n; + struct jailhouse_iommu *unit; void *reg_base; - u64 base_addr; int err; /* n = roundup(log2(system_config->interrupt_limit)) */ @@ -484,11 +484,11 @@ int iommu_init(void) return -ENOMEM; for (n = 0; n < units; n++) { - base_addr = system_config->platform_info.x86.iommu_base[n]; + unit = &system_config->platform_info.x86.iommu_units[n]; reg_base = dmar_reg_base + n * PAGE_SIZE; - err = paging_create(&hv_paging_structs, base_addr, PAGE_SIZE, + err = paging_create(&hv_paging_structs, unit->base, PAGE_SIZE, (unsigned long)reg_base, PAGE_DEFAULT_FLAGS | PAGE_FLAG_DEVICE, PAGING_NON_COHERENT); @@ -503,7 +503,7 @@ int iommu_init(void) return 0; } - printk("Found DMAR @%p\n", base_addr); + printk("Found DMAR @%p\n", unit->base); caps = mmio_read64(reg_base + VTD_CAP_REG); if (caps & VTD_CAP_SAGAW39) diff --git a/hypervisor/include/jailhouse/cell-config.h b/hypervisor/include/jailhouse/cell-config.h index 169e3ca..84ffa5c 100644 --- a/hypervisor/include/jailhouse/cell-config.h +++ b/hypervisor/include/jailhouse/cell-config.h @@ -139,6 +139,10 @@ struct jailhouse_pci_capability { #define JAILHOUSE_MAX_IOMMU_UNITS 8 +struct jailhouse_iommu { + __u64 base; +} __attribute__((packed)); + #define JAILHOUSE_SYSTEM_SIGNATURE "JAILSYST" struct jailhouse_system { @@ -151,7 +155,8 @@ struct jailhouse_system { __u8 mmconfig_end_bus; __u8 padding[5]; __u16 pm_timer_address; - __u64 iommu_base[JAILHOUSE_MAX_IOMMU_UNITS]; + struct jailhouse_iommu + iommu_units[JAILHOUSE_MAX_IOMMU_UNITS]; } __attribute__((packed)) x86; } __attribute__((packed)) platform_info; __u32 device_limit; diff --git a/tools/root-cell-config.c.tmpl b/tools/root-cell-config.c.tmpl index a15fbfe..631fcd9 100644 --- a/tools/root-cell-config.c.tmpl +++ b/tools/root-cell-config.c.tmpl @@ -1,7 +1,7 @@ /* * Jailhouse, a Linux-based partitioning hypervisor * - * Copyright (c) Siemens AG, 2014, 2015 + * Copyright (c) Siemens AG, 2014-2016 * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. @@ -67,9 +67,11 @@ struct { .mmconfig_end_bus = ${hex(mmconfig.end_bus)}, .pm_timer_address = ${hex(pm_timer_base)}, % if iommu_units: - .iommu_base = { + .iommu_units = { % for d in iommu_units: - ${hex(d)}, + { + .base = ${hex(d)}, + }, % endfor }, % endif -- 2.39.2