xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64
@ 2016-03-30 10:07 Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 01/21] arm/acpi: Estimate memory required for acpi/efi tables Shannon Zhao
                   ` (21 more replies)
  0 siblings, 22 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

These patches are Part 4 (and last part) of the previous patch set I
sent which adds ACPI support for arm64 on Xen[1]. Split them as an
individual set for convenient reviewing.

These patches create UEFI and ACPI tables which are mapped to Dom0's
space and add other preparations for Dom0 to use ACPI. Then at last
enable ACPI support on ARM64.

See individual patch for changes.

Thanks,
Shannon
[1] http://lists.xenproject.org/archives/html/xen-devel/2015-11/msg01831.html

Parth Dixit (1):
  arm/p2m: Add helper functions to map memory regions

Shannon Zhao (20):
  arm/acpi: Estimate memory required for acpi/efi tables
  arm/acpi: Add a helper function to get the acpi table offset
  arm/acpi: Prepare FADT table for Dom0
  arm/gic: Add a new callback for creating MADT table for Dom0
  arm/acpi: Prepare MADT table for Dom0
  arm/acpi: Prepare STAO table for Dom0
  arm/acpi: Prepare XSDT table for Dom0
  arm/acpi: Prepare RSDP table for Dom0
  arm/acpi: Map all other tables for Dom0
  arm/acpi: Prepare EFI system table for Dom0
  arm/acpi: Prepare EFI memory descriptor for Dom0
  arm/acpi: Map the new created EFI and ACPI tables to Dom0
  arm/acpi: Create min DT stub for Dom0
  arm/acpi: Permit access all Xen unused SPIs for Dom0
  arm/acpi: Configure SPI interrupt type and route to Dom0 dynamically
  arm/gic: Add a new callback to deny Dom0 access to GIC regions
  arm/acpi: Permit MMIO access of Xen unused devices for Dom0
  xen/acpi: Fix event-channel interrupt when booting with ACPI
  xen/arm: Add a hypercall for device mmio mapping
  xen/arm64: Add ACPI support

 docs/misc/arm/device-tree/guest.txt |  60 ++++
 xen/arch/arm/Kconfig                |   9 +
 xen/arch/arm/acpi/lib.c             |  15 +
 xen/arch/arm/domain.c               |   4 +
 xen/arch/arm/domain_build.c         | 634 +++++++++++++++++++++++++++++++++++-
 xen/arch/arm/efi/Makefile           |   1 +
 xen/arch/arm/efi/efi-boot.h         |   4 +-
 xen/arch/arm/efi/efi-dom0.c         | 187 +++++++++++
 xen/arch/arm/efi/efi-dom0.h         |   8 +
 xen/arch/arm/gic-v2.c               |  69 ++++
 xen/arch/arm/gic-v3.c               |  97 ++++++
 xen/arch/arm/gic.c                  |  10 +
 xen/arch/arm/mm.c                   |   3 +
 xen/arch/arm/p2m.c                  |  48 +++
 xen/arch/arm/vgic.c                 |  32 ++
 xen/common/efi/runtime.c            |  12 +-
 xen/common/memory.c                 |  17 +-
 xen/include/asm-arm/acpi.h          |  10 +
 xen/include/asm-arm/gic.h           |   6 +
 xen/include/asm-arm/p2m.h           |  15 +
 xen/include/asm-arm/setup.h         |  11 +
 xen/include/public/memory.h         |   1 +
 22 files changed, 1242 insertions(+), 11 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/guest.txt
 create mode 100644 xen/arch/arm/efi/efi-dom0.c
 create mode 100644 xen/arch/arm/efi/efi-dom0.h

-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v8 01/21] arm/acpi: Estimate memory required for acpi/efi tables
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 02/21] arm/acpi: Add a helper function to get the acpi table offset Shannon Zhao
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Estimate the memory required for loading acpi/efi tables in Dom0. Make
the length of each table aligned with 64bit. Alloc the pages to store
the new created EFI and ACPI tables and free these pages when
destroying domain.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
v8: fix rsdp_tbl left mapped if map XSDT failed
---
 xen/arch/arm/domain.c       |   4 ++
 xen/arch/arm/domain_build.c | 103 +++++++++++++++++++++++++++++++++++++++++++-
 xen/arch/arm/efi/Makefile   |   1 +
 xen/arch/arm/efi/efi-boot.h |   4 +-
 xen/arch/arm/efi/efi-dom0.c |  59 +++++++++++++++++++++++++
 xen/arch/arm/efi/efi-dom0.h |   8 ++++
 xen/include/asm-arm/setup.h |   2 +
 7 files changed, 177 insertions(+), 4 deletions(-)
 create mode 100644 xen/arch/arm/efi/efi-dom0.c
 create mode 100644 xen/arch/arm/efi/efi-dom0.h

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 3d274ae..1365b4a 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -640,6 +640,10 @@ void arch_domain_destroy(struct domain *d)
     domain_vgic_free(d);
     domain_vuart_free(d);
     free_xenheap_page(d->shared_info);
+#ifdef CONFIG_ACPI
+    free_xenheap_pages(d->arch.efi_acpi_table,
+                       get_order_from_bytes(d->arch.efi_acpi_len));
+#endif
 }
 
 void arch_domain_shutdown(struct domain *d)
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 83676e4..180cb1d2 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -12,6 +12,8 @@
 #include <xen/libfdt/libfdt.h>
 #include <xen/guest_access.h>
 #include <xen/iocap.h>
+#include <xen/acpi.h>
+#include <acpi/actables.h>
 #include <asm/device.h>
 #include <asm/setup.h>
 #include <asm/platform.h>
@@ -1354,6 +1356,101 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
     return -EINVAL;
 }
 
+#ifdef CONFIG_ACPI
+static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo)
+{
+    size_t efi_size, acpi_size, madt_size;
+    u64 addr;
+    struct acpi_table_rsdp *rsdp_tbl;
+    struct acpi_table_header *table;
+
+    efi_size = estimate_efi_size(kinfo->mem.nr_banks);
+
+    acpi_size = ROUNDUP(sizeof(struct acpi_table_fadt), 8);
+    acpi_size += ROUNDUP(sizeof(struct acpi_table_stao), 8);
+
+    madt_size = sizeof(struct acpi_table_madt)
+                + sizeof(struct acpi_madt_generic_interrupt) * d->max_vcpus
+                + sizeof(struct acpi_madt_generic_distributor);
+    if ( d->arch.vgic.version == GIC_V3 )
+        madt_size += sizeof(struct acpi_madt_generic_redistributor)
+                     * d->arch.vgic.nr_regions;
+    acpi_size += ROUNDUP(madt_size, 8);
+
+    addr = acpi_os_get_root_pointer();
+    if ( !addr )
+    {
+        printk("Unable to get acpi root pointer\n");
+        return -EINVAL;
+    }
+
+    rsdp_tbl = acpi_os_map_memory(addr, sizeof(struct acpi_table_rsdp));
+    if ( !rsdp_tbl )
+    {
+        printk("Unable to map RSDP table\n");
+        return -EINVAL;
+    }
+
+    table = acpi_os_map_memory(rsdp_tbl->xsdt_physical_address,
+                               sizeof(struct acpi_table_header));
+    acpi_os_unmap_memory(rsdp_tbl, sizeof(struct acpi_table_rsdp));
+    if ( !table )
+    {
+        printk("Unable to map XSDT table\n");
+        return -EINVAL;
+    }
+
+    /* Add place for STAO table in XSDT table */
+    acpi_size += ROUNDUP(table->length + sizeof(u64), 8);
+    acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
+
+    acpi_size += ROUNDUP(sizeof(struct acpi_table_rsdp), 8);
+    d->arch.efi_acpi_len = PAGE_ALIGN(ROUNDUP(efi_size, 8)
+                                      + ROUNDUP(acpi_size, 8));
+
+    return 0;
+}
+
+static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
+{
+    int rc = 0;
+    int order;
+
+    rc = estimate_acpi_efi_size(d, kinfo);
+    if ( rc != 0 )
+        return rc;
+
+    order = get_order_from_bytes(d->arch.efi_acpi_len);
+    d->arch.efi_acpi_table = alloc_xenheap_pages(order, 0);
+    if ( d->arch.efi_acpi_table == NULL )
+    {
+        printk("unable to allocate memory!\n");
+        return -ENOMEM;
+    }
+    memset(d->arch.efi_acpi_table, 0, d->arch.efi_acpi_len);
+
+    /*
+     * For ACPI, Dom0 doesn't use kinfo->gnttab_start to get the grant table
+     * region. So we use it as the ACPI table mapped address. Also it needs to
+     * check if the size of grant table region is enough for those ACPI tables.
+     */
+    d->arch.efi_acpi_gpa = kinfo->gnttab_start;
+    if ( kinfo->gnttab_size < d->arch.efi_acpi_len )
+    {
+        printk("The grant table region is not enough to fit the ACPI tables!\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
+#else
+static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
+{
+    /* Only booting with ACPI will hit here */
+    BUG();
+    return -EINVAL;
+}
+#endif
 static void dtb_load(struct kernel_info *kinfo)
 {
     void * __user dtb_virt = (void * __user)(register_t)kinfo->dtb_paddr;
@@ -1540,7 +1637,11 @@ int construct_dom0(struct domain *d)
     allocate_memory(d, &kinfo);
     find_gnttab_region(d, &kinfo);
 
-    rc = prepare_dtb(d, &kinfo);
+    if ( acpi_disabled )
+        rc = prepare_dtb(d, &kinfo);
+    else
+        rc = prepare_acpi(d, &kinfo);
+
     if ( rc < 0 )
         return rc;
 
diff --git a/xen/arch/arm/efi/Makefile b/xen/arch/arm/efi/Makefile
index 729e53e..d34c916 100644
--- a/xen/arch/arm/efi/Makefile
+++ b/xen/arch/arm/efi/Makefile
@@ -1,3 +1,4 @@
 CFLAGS += -fshort-wchar
 
 obj-y +=  boot.init.o runtime.o
+obj-$(CONFIG_ACPI) +=  efi-dom0.init.o
diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index c58caca..045d6ce 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -7,6 +7,7 @@
 #include <xen/libfdt/libfdt.h>
 #include <asm/setup.h>
 #include <asm/smp.h>
+#include "efi-dom0.h"
 
 void noreturn efi_xen_start(void *fdt_ptr, uint32_t fdt_size);
 void __flush_dcache_area(const void *vaddr, unsigned long size);
@@ -17,9 +18,6 @@ void __flush_dcache_area(const void *vaddr, unsigned long size);
 static struct file __initdata dtbfile;
 static void __initdata *fdt;
 static void __initdata *memmap;
-#ifdef CONFIG_ACPI
-static struct meminfo __initdata acpi_mem;
-#endif
 
 static int __init setup_chosen_node(void *fdt, int *addr_cells, int *size_cells)
 {
diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c
new file mode 100644
index 0000000..021aa02
--- /dev/null
+++ b/xen/arch/arm/efi/efi-dom0.c
@@ -0,0 +1,59 @@
+/*
+ *  efi-dom0.c - Domain0 EFI Boot Support
+ *
+ *  Copyright (C) 2016 Shannon Zhao <shannon.zhao@linaro.org>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+#include "efi.h"
+#include "efi-dom0.h"
+#include <asm/setup.h>
+#include <asm/acpi.h>
+
+struct meminfo __initdata acpi_mem;
+/* Constant to indicate "Xen" in unicode u16 format */
+static const CHAR16 xen_efi_fw_vendor[] = {0x0058, 0x0065, 0x006E, 0x0000};
+
+size_t __init estimate_efi_size(int mem_nr_banks)
+{
+    size_t size;
+    size_t est_size = sizeof(EFI_SYSTEM_TABLE);
+    size_t ect_size = sizeof(EFI_CONFIGURATION_TABLE);
+    size_t emd_size = sizeof(EFI_MEMORY_DESCRIPTOR);
+    size_t fw_vendor_size = sizeof(xen_efi_fw_vendor);
+    int acpi_mem_nr_banks = 0;
+
+    if ( !acpi_disabled )
+        acpi_mem_nr_banks = acpi_mem.nr_banks;
+
+    size = ROUNDUP(est_size + ect_size + fw_vendor_size, 8);
+    /* plus 1 for new created tables */
+    size += ROUNDUP(emd_size * (mem_nr_banks + acpi_mem_nr_banks + 1), 8);
+
+    return size;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/efi/efi-dom0.h b/xen/arch/arm/efi/efi-dom0.h
new file mode 100644
index 0000000..3cd4caa
--- /dev/null
+++ b/xen/arch/arm/efi/efi-dom0.h
@@ -0,0 +1,8 @@
+#ifndef __ARM_EFI_DOM0_H__
+#define __ARM_EFI_DOM0_H__
+
+#include <asm/setup.h>
+
+extern struct meminfo acpi_mem;
+
+#endif
diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
index 30ac53b..7f233a1 100644
--- a/xen/include/asm-arm/setup.h
+++ b/xen/include/asm-arm/setup.h
@@ -51,6 +51,8 @@ void arch_init_memory(void);
 
 void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
 
+size_t estimate_efi_size(int mem_nr_banks);
+
 int construct_dom0(struct domain *d);
 
 void discard_initial_modules(void);
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 02/21] arm/acpi: Add a helper function to get the acpi table offset
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 01/21] arm/acpi: Estimate memory required for acpi/efi tables Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 03/21] arm/acpi: Prepare FADT table for Dom0 Shannon Zhao
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

These tables are aligned with 64bit.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
v8: update the description of the function
---
 xen/arch/arm/acpi/lib.c    | 15 +++++++++++++++
 xen/include/asm-arm/acpi.h | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/xen/arch/arm/acpi/lib.c b/xen/arch/arm/acpi/lib.c
index db5c4d8..79f7edd 100644
--- a/xen/arch/arm/acpi/lib.c
+++ b/xen/arch/arm/acpi/lib.c
@@ -60,3 +60,18 @@ bool_t __init acpi_psci_hvc_present(void)
 {
     return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
 }
+
+paddr_t __init acpi_get_table_offset(struct membank tbl_add[],
+                                     EFI_MEM_RES index)
+{
+    int i;
+    paddr_t offset = 0;
+
+    for ( i = 0; i < index; i++ )
+    {
+        /* Aligned with 64bit (8 bytes) */
+        offset += ROUNDUP(tbl_add[i].size, 8);
+    }
+
+    return offset;
+}
diff --git a/xen/include/asm-arm/acpi.h b/xen/include/asm-arm/acpi.h
index 7f59761..9f954d3 100644
--- a/xen/include/asm-arm/acpi.h
+++ b/xen/include/asm-arm/acpi.h
@@ -25,6 +25,7 @@
 
 #include <xen/init.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 
 #define COMPILER_DEPENDENT_INT64   long long
 #define COMPILER_DEPENDENT_UINT64  unsigned long long
@@ -46,6 +47,15 @@ bool_t __init acpi_psci_present(void);
 bool_t __init acpi_psci_hvc_present(void);
 void __init acpi_smp_init_cpus(void);
 
+/*
+ * This function returns the offset of a given ACPI/EFI table in the allocated
+ * memory region. Currently, the tables should be created in the same order as
+ * their associated 'index' in the enum EFI_MEM_RES. This means the function
+ * won't return the correct offset until all the tables before a given 'index'
+ * are created.
+ */
+paddr_t acpi_get_table_offset(struct membank tbl_add[], EFI_MEM_RES index);
+
 #ifdef CONFIG_ACPI
 extern bool_t acpi_disabled;
 /* Basic configuration for ACPI */
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 03/21] arm/acpi: Prepare FADT table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 01/21] arm/acpi: Estimate memory required for acpi/efi tables Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 02/21] arm/acpi: Add a helper function to get the acpi table offset Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 04/21] arm/gic: Add a new callback for creating MADT " Shannon Zhao
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Copy and modify FADT table before passing it to Dom0. Set PSCI_COMPLIANT
and PSCI_USE_HVC.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 180cb1d2..5a2ba13 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,44 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+
+static int acpi_create_fadt(struct domain *d, struct membank tbl_add[])
+{
+    struct acpi_table_header *table = NULL;
+    struct acpi_table_fadt *fadt = NULL;
+    u64 table_size;
+    acpi_status status;
+    u8 *base_ptr;
+    u8 checksum;
+
+    status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        const char *msg = acpi_format_exception(status);
+
+        printk("Failed to get FADT table, %s\n", msg);
+        return -EINVAL;
+    }
+
+    table_size = table->length;
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_FADT);
+    ACPI_MEMCPY(base_ptr, table, table_size);
+    fadt = (struct acpi_table_fadt *)base_ptr;
+
+    /* Set PSCI_COMPLIANT and PSCI_USE_HVC */
+    fadt->arm_boot_flags |= (ACPI_FADT_PSCI_COMPLIANT | ACPI_FADT_PSCI_USE_HVC);
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, fadt), table_size);
+    fadt->header.checksum -= checksum;
+
+    tbl_add[TBL_FADT].start = d->arch.efi_acpi_gpa
+                              + acpi_get_table_offset(tbl_add, TBL_FADT);
+    tbl_add[TBL_FADT].size = table_size;
+
+    return 0;
+}
+
 static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo)
 {
     size_t efi_size, acpi_size, madt_size;
@@ -1415,6 +1453,7 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
 {
     int rc = 0;
     int order;
+    struct membank tbl_add[TBL_MMAX] = {};
 
     rc = estimate_acpi_efi_size(d, kinfo);
     if ( rc != 0 )
@@ -1441,6 +1480,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
         return -EINVAL;
     }
 
+    rc = acpi_create_fadt(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 04/21] arm/gic: Add a new callback for creating MADT table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (2 preceding siblings ...)
  2016-03-30 10:07 ` [PATCH v8 03/21] arm/acpi: Prepare FADT table for Dom0 Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 05/21] arm/acpi: Prepare " Shannon Zhao
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Add a new member in gic_hw_operations which is used to create MADT table
for Dom0.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/gic-v2.c     | 42 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic-v3.c     | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic.c        |  5 +++++
 xen/include/asm-arm/gic.h |  3 +++
 4 files changed, 106 insertions(+)

diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c
index 0fcb894..38e3216 100644
--- a/xen/arch/arm/gic-v2.c
+++ b/xen/arch/arm/gic-v2.c
@@ -685,6 +685,43 @@ static void __init gicv2_dt_init(void)
 }
 
 #ifdef CONFIG_ACPI
+static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
+{
+    struct acpi_subtable_header *header;
+    struct acpi_madt_generic_interrupt *host_gicc, *gicc;
+    u32 i, size, table_len = 0;
+    u8 *base_ptr = d->arch.efi_acpi_table + offset;
+
+    header = acpi_table_get_entry_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, 0);
+    if ( !header )
+    {
+        printk("Can't get GICC entry");
+        return -EINVAL;
+    }
+
+    host_gicc = container_of(header, struct acpi_madt_generic_interrupt,
+                             header);
+    size = sizeof(struct acpi_madt_generic_interrupt);
+    /* Add Generic Interrupt */
+    for ( i = 0; i < d->max_vcpus; i++ )
+    {
+        gicc = (struct acpi_madt_generic_interrupt *)(base_ptr + table_len);
+        ACPI_MEMCPY(gicc, host_gicc, size);
+        gicc->cpu_interface_number = i;
+        gicc->uid = i;
+        gicc->flags = ACPI_MADT_ENABLED;
+        gicc->arm_mpidr = vcpuid_to_vaffinity(i);
+        gicc->parking_version = 0;
+        gicc->performance_interrupt = 0;
+        gicc->gicv_base_address = 0;
+        gicc->gich_base_address = 0;
+        gicc->vgic_interrupt = 0;
+        table_len += size;
+    }
+
+    return table_len;
+}
+
 static int __init
 gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
                         const unsigned long end)
@@ -776,6 +813,10 @@ static void __init gicv2_acpi_init(void)
 }
 #else
 static void __init gicv2_acpi_init(void) { }
+static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
+{
+    return 0;
+}
 #endif
 
 static int __init gicv2_init(void)
@@ -868,6 +909,7 @@ const static struct gic_hw_operations gicv2_ops = {
     .read_vmcr_priority  = gicv2_read_vmcr_priority,
     .read_apr            = gicv2_read_apr,
     .make_hwdom_dt_node  = gicv2_make_hwdom_dt_node,
+    .make_hwdom_madt     = gicv2_make_hwdom_madt,
 };
 
 /* Set up the GIC */
diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
index f83fd88..52ee23c 100644
--- a/xen/arch/arm/gic-v3.c
+++ b/xen/arch/arm/gic-v3.c
@@ -1236,6 +1236,57 @@ static void __init gicv3_dt_init(void)
 }
 
 #ifdef CONFIG_ACPI
+static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
+{
+    struct acpi_subtable_header *header;
+    struct acpi_madt_generic_interrupt *host_gicc, *gicc;
+    struct acpi_madt_generic_redistributor *gicr;
+    u8 *base_ptr = d->arch.efi_acpi_table + offset;
+    u32 i, table_len = 0, size;
+
+    /* Add Generic Interrupt */
+    header = acpi_table_get_entry_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, 0);
+    if ( !header )
+    {
+        printk("Can't get GICC entry");
+        return -EINVAL;
+    }
+
+    host_gicc = container_of(header, struct acpi_madt_generic_interrupt,
+                             header);
+    size = sizeof(struct acpi_madt_generic_interrupt);
+    for ( i = 0; i < d->max_vcpus; i++ )
+    {
+        gicc = (struct acpi_madt_generic_interrupt *)(base_ptr + table_len);
+        ACPI_MEMCPY(gicc, host_gicc, size);
+        gicc->cpu_interface_number = i;
+        gicc->uid = i;
+        gicc->flags = ACPI_MADT_ENABLED;
+        gicc->arm_mpidr = vcpuid_to_vaffinity(i);
+        gicc->parking_version = 0;
+        gicc->performance_interrupt = 0;
+        gicc->gicv_base_address = 0;
+        gicc->gich_base_address = 0;
+        gicc->gicr_base_address = 0;
+        gicc->vgic_interrupt = 0;
+        table_len += size;
+    }
+
+    /* Add Generic Redistributor */
+    size = sizeof(struct acpi_madt_generic_redistributor);
+    for ( i = 0; i < d->arch.vgic.nr_regions; i++ )
+    {
+        gicr = (struct acpi_madt_generic_redistributor *)(base_ptr + table_len);
+        gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR;
+        gicr->header.length = size;
+        gicr->base_address = d->arch.vgic.rdist_regions[i].base;
+        gicr->length = d->arch.vgic.rdist_regions[i].size;
+        table_len += size;
+    }
+
+    return table_len;
+}
+
 static int __init
 gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
                         const unsigned long end)
@@ -1380,6 +1431,10 @@ static void __init gicv3_acpi_init(void)
 }
 #else
 static void __init gicv3_acpi_init(void) { }
+static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
+{
+    return 0;
+}
 #endif
 
 /* Set up the GIC */
@@ -1474,6 +1529,7 @@ static const struct gic_hw_operations gicv3_ops = {
     .read_apr            = gicv3_read_apr,
     .secondary_init      = gicv3_secondary_cpu_init,
     .make_hwdom_dt_node  = gicv3_make_hwdom_dt_node,
+    .make_hwdom_madt     = gicv3_make_hwdom_madt,
 };
 
 static int __init gicv3_dt_preinit(struct dt_device_node *node, const void *data)
diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
index fbbe37f..b3c1eb3 100644
--- a/xen/arch/arm/gic.c
+++ b/xen/arch/arm/gic.c
@@ -739,6 +739,11 @@ int gic_make_hwdom_dt_node(const struct domain *d,
     return gic_hw_ops->make_hwdom_dt_node(d, gic, fdt);
 }
 
+int gic_make_hwdom_madt(const struct domain *d, u32 offset)
+{
+    return gic_hw_ops->make_hwdom_madt(d, offset);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h
index 7bd06e1..8130136 100644
--- a/xen/include/asm-arm/gic.h
+++ b/xen/include/asm-arm/gic.h
@@ -358,12 +358,15 @@ struct gic_hw_operations {
     /* Create GIC node for the hardware domain */
     int (*make_hwdom_dt_node)(const struct domain *d,
                               const struct dt_device_node *gic, void *fdt);
+    /* Create MADT table for the hardware domain */
+    int (*make_hwdom_madt)(const struct domain *d, u32 offset);
 };
 
 void register_gic_ops(const struct gic_hw_operations *ops);
 int gic_make_hwdom_dt_node(const struct domain *d,
                            const struct dt_device_node *gic,
                            void *fdt);
+int gic_make_hwdom_madt(const struct domain *d, u32 offset);
 
 #endif /* __ASSEMBLY__ */
 #endif
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 05/21] arm/acpi: Prepare MADT table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (3 preceding siblings ...)
  2016-03-30 10:07 ` [PATCH v8 04/21] arm/gic: Add a new callback for creating MADT " Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:07 ` [PATCH v8 06/21] arm/acpi: Prepare STAO " Shannon Zhao
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Copy main MADT table contents and distributor subtable from physical
ACPI MADT table. Make other subtables through the callback of
gic_hw_ops.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 5a2ba13..9d17295 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,62 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+static int acpi_create_madt(struct domain *d, struct membank tbl_add[])
+{
+    struct acpi_table_header *table = NULL;
+    struct acpi_table_madt *madt = NULL;
+    struct acpi_subtable_header *header;
+    struct acpi_madt_generic_distributor *gicd;
+    u32 table_size = sizeof(struct acpi_table_madt);
+    u32 offset = acpi_get_table_offset(tbl_add, TBL_MADT);
+    int ret;
+    acpi_status status;
+    u8 *base_ptr, checksum;
+
+    status = acpi_get_table(ACPI_SIG_MADT, 0, &table);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        const char *msg = acpi_format_exception(status);
+
+        printk("Failed to get MADT table, %s\n", msg);
+        return -EINVAL;
+    }
+
+    base_ptr = d->arch.efi_acpi_table + offset;
+    ACPI_MEMCPY(base_ptr, table, table_size);
+
+    /* Add Generic Distributor. */
+    header = acpi_table_get_entry_madt(ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, 0);
+    if ( !header )
+    {
+        printk("Can't get GICD entry\n");
+        return -EINVAL;
+    }
+    gicd = container_of(header, struct acpi_madt_generic_distributor, header);
+    ACPI_MEMCPY(base_ptr + table_size, gicd,
+                sizeof(struct acpi_madt_generic_distributor));
+    table_size += sizeof(struct acpi_madt_generic_distributor);
+
+    /* Add other subtables. */
+    ret = gic_make_hwdom_madt(d, offset + table_size);
+    if ( ret < 0 )
+    {
+        printk("Failed to get other subtables\n");
+        return -EINVAL;
+    }
+    table_size += ret;
+
+    madt = (struct acpi_table_madt *)base_ptr;
+    madt->header.length = table_size;
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, madt), table_size);
+    madt->header.checksum -= checksum;
+
+    tbl_add[TBL_MADT].start = d->arch.efi_acpi_gpa + offset;
+    tbl_add[TBL_MADT].size = table_size;
+
+    return 0;
+}
 
 static int acpi_create_fadt(struct domain *d, struct membank tbl_add[])
 {
@@ -1484,6 +1540,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_create_madt(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 06/21] arm/acpi: Prepare STAO table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (4 preceding siblings ...)
  2016-03-30 10:07 ` [PATCH v8 05/21] arm/acpi: Prepare " Shannon Zhao
@ 2016-03-30 10:07 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 07/21] arm/acpi: Prepare XSDT " Shannon Zhao
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:07 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Create STAO table for Dom0. This table is used to tell Dom0 whether it
should ignore UART defined in SPCR table or the ACPI namespace names.

Look at below url for details:
http://wiki.xenproject.org/mediawiki/images/0/02/Status-override-table.pdf

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 9d17295..3df2c00 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,43 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+static int acpi_create_stao(struct domain *d, struct membank tbl_add[])
+{
+    struct acpi_table_header *table = NULL;
+    struct acpi_table_stao *stao = NULL;
+    u32 table_size = sizeof(struct acpi_table_stao);
+    u32 offset = acpi_get_table_offset(tbl_add, TBL_STAO);
+    acpi_status status;
+    u8 *base_ptr, checksum;
+
+    /* Copy OEM and ASL compiler fields from another table, use MADT */
+    status = acpi_get_table(ACPI_SIG_MADT, 0, &table);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        const char *msg = acpi_format_exception(status);
+
+        printk("STAO: Failed to get MADT table, %s\n", msg);
+        return -EINVAL;
+    }
+
+    base_ptr = d->arch.efi_acpi_table + offset;
+    ACPI_MEMCPY(base_ptr, table, sizeof(struct acpi_table_header));
+
+    stao = (struct acpi_table_stao *)base_ptr;
+    ACPI_MEMCPY(stao->header.signature, ACPI_SIG_STAO, 4);
+    stao->header.revision = 1;
+    stao->header.length = table_size;
+    stao->ignore_uart = 1;
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, stao), table_size);
+    stao->header.checksum -= checksum;
+
+    tbl_add[TBL_STAO].start = d->arch.efi_acpi_gpa + offset;
+    tbl_add[TBL_STAO].size = table_size;
+
+    return 0;
+}
+
 static int acpi_create_madt(struct domain *d, struct membank tbl_add[])
 {
     struct acpi_table_header *table = NULL;
@@ -1544,6 +1581,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_create_stao(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 07/21] arm/acpi: Prepare XSDT table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (5 preceding siblings ...)
  2016-03-30 10:07 ` [PATCH v8 06/21] arm/acpi: Prepare STAO " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 08/21] arm/acpi: Prepare RSDP " Shannon Zhao
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Copy and modify XSDT table before passing it to Dom0. Replace the entry
value of the copied table. Add a new entry for STAO table as well. And
keep entry value of other reused tables unchanged.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 72 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 3df2c00..09dd0e1 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,74 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+static void acpi_xsdt_modify_entry(u64 entry[], unsigned long entry_count,
+                                   char *signature, u64 addr)
+{
+    int i;
+    struct acpi_table_header *table;
+    u64 size = sizeof(struct acpi_table_header);
+
+    for( i = 0; i < entry_count; i++ )
+    {
+        table = acpi_os_map_memory(entry[i], size);
+        if ( ACPI_COMPARE_NAME(table->signature, signature) )
+        {
+            entry[i] = addr;
+            acpi_os_unmap_memory(table, size);
+            break;
+        }
+        acpi_os_unmap_memory(table, size);
+    }
+}
+
+static int acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
+{
+    struct acpi_table_header *table = NULL;
+    struct acpi_table_rsdp *rsdp_tbl;
+    struct acpi_table_xsdt *xsdt = NULL;
+    u64 table_size, addr;
+    unsigned long entry_count;
+    u8 *base_ptr;
+    u8 checksum;
+
+    addr = acpi_os_get_root_pointer();
+    if ( !addr )
+    {
+        printk("Unable to get acpi root pointer\n");
+        return -EINVAL;
+    }
+    rsdp_tbl = acpi_os_map_memory(addr, sizeof(struct acpi_table_rsdp));
+    table = acpi_os_map_memory(rsdp_tbl->xsdt_physical_address,
+                               sizeof(struct acpi_table_header));
+
+    /* Add place for STAO table in XSDT table */
+    table_size = table->length + sizeof(u64);
+    entry_count = (table->length - sizeof(struct acpi_table_header))
+                  / sizeof(u64);
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_XSDT);
+    ACPI_MEMCPY(base_ptr, table, table->length);
+    acpi_os_unmap_memory(table, sizeof(struct acpi_table_header));
+    acpi_os_unmap_memory(rsdp_tbl, sizeof(struct acpi_table_rsdp));
+
+    xsdt = (struct acpi_table_xsdt *)base_ptr;
+    acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count,
+                           ACPI_SIG_FADT, tbl_add[TBL_FADT].start);
+    acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count,
+                           ACPI_SIG_MADT, tbl_add[TBL_MADT].start);
+    xsdt->table_offset_entry[entry_count] = tbl_add[TBL_STAO].start;
+
+    xsdt->header.length = table_size;
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, xsdt), table_size);
+    xsdt->header.checksum -= checksum;
+
+    tbl_add[TBL_XSDT].start = d->arch.efi_acpi_gpa
+                              + acpi_get_table_offset(tbl_add, TBL_XSDT);
+    tbl_add[TBL_XSDT].size = table_size;
+
+    return 0;
+}
+
 static int acpi_create_stao(struct domain *d, struct membank tbl_add[])
 {
     struct acpi_table_header *table = NULL;
@@ -1585,6 +1653,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_create_xsdt(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 08/21] arm/acpi: Prepare RSDP table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (6 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 07/21] arm/acpi: Prepare XSDT " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 09/21] arm/p2m: Add helper functions to map memory regions Shannon Zhao
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Copy RSDP table and replace rsdp->xsdt_physical_address with the address
of XSDT table, so it can point to the right XSDT table.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 09dd0e1..e025be8 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,40 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+static int acpi_create_rsdp(struct domain *d, struct membank tbl_add[])
+{
+
+    struct acpi_table_rsdp *rsdp = NULL;
+    u64 addr;
+    u64 table_size = sizeof(struct acpi_table_rsdp);
+    u8 *base_ptr;
+    u8 checksum;
+
+    addr = acpi_os_get_root_pointer();
+    if ( !addr  )
+    {
+        printk("Unable to get acpi root pointer\n");
+        return -EINVAL;
+    }
+    rsdp = acpi_os_map_memory(addr, table_size);
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_RSDP);
+    ACPI_MEMCPY(base_ptr, rsdp, table_size);
+    acpi_os_unmap_memory(rsdp, table_size);
+
+    rsdp = (struct acpi_table_rsdp *)base_ptr;
+    /* Replace xsdt_physical_address */
+    rsdp->xsdt_physical_address = tbl_add[TBL_XSDT].start;
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, rsdp), table_size);
+    rsdp->checksum = rsdp->checksum - checksum;
+
+    tbl_add[TBL_RSDP].start = d->arch.efi_acpi_gpa
+                              + acpi_get_table_offset(tbl_add, TBL_RSDP);
+    tbl_add[TBL_RSDP].size = table_size;
+
+    return 0;
+}
+
 static void acpi_xsdt_modify_entry(u64 entry[], unsigned long entry_count,
                                    char *signature, u64 addr)
 {
@@ -1657,6 +1691,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_create_rsdp(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 09/21] arm/p2m: Add helper functions to map memory regions
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (7 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 08/21] arm/acpi: Prepare RSDP " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 10/21] arm/acpi: Map all other tables for Dom0 Shannon Zhao
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Parth Dixit <parth.dixit@linaro.org>

Create a helper function for mapping with cached attributes and
read-write range.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/p2m.c        | 26 ++++++++++++++++++++++++++
 xen/include/asm-arm/p2m.h | 10 ++++++++++
 2 files changed, 36 insertions(+)

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index a2a9c4b..7e5f5d1 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -1218,6 +1218,32 @@ int p2m_populate_ram(struct domain *d,
                              d->arch.p2m.default_access);
 }
 
+int map_regions_rw_cache(struct domain *d,
+                         unsigned long start_gfn,
+                         unsigned long nr,
+                         unsigned long mfn)
+{
+    return apply_p2m_changes(d, INSERT,
+                             pfn_to_paddr(start_gfn),
+                             pfn_to_paddr(start_gfn + nr),
+                             pfn_to_paddr(mfn),
+                             MATTR_MEM, 0, p2m_mmio_direct,
+                             p2m_access_rw);
+}
+
+int unmap_regions_rw_cache(struct domain *d,
+                           unsigned long start_gfn,
+                           unsigned long nr,
+                           unsigned long mfn)
+{
+    return apply_p2m_changes(d, REMOVE,
+                             pfn_to_paddr(start_gfn),
+                             pfn_to_paddr(start_gfn + nr),
+                             pfn_to_paddr(mfn),
+                             MATTR_MEM, 0, p2m_invalid,
+                             p2m_access_rw);
+}
+
 int map_mmio_regions(struct domain *d,
                      unsigned long start_gfn,
                      unsigned long nr,
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 433952a..55626b4 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -144,6 +144,16 @@ int p2m_cache_flush(struct domain *d, xen_pfn_t start_mfn, xen_pfn_t end_mfn);
 /* Setup p2m RAM mapping for domain d from start-end. */
 int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
 
+int map_regions_rw_cache(struct domain *d,
+                         unsigned long start_gfn,
+                         unsigned long nr_mfns,
+                         unsigned long mfn);
+
+int unmap_regions_rw_cache(struct domain *d,
+                           unsigned long start_gfn,
+                           unsigned long nr_mfns,
+                           unsigned long mfn);
+
 int guest_physmap_add_entry(struct domain *d,
                             unsigned long gfn,
                             unsigned long mfn,
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 10/21] arm/acpi: Map all other tables for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (8 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 09/21] arm/p2m: Add helper functions to map memory regions Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 11/21] arm/acpi: Prepare EFI system table " Shannon Zhao
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Map all other ACPI tables into Dom0 using 1:1 mappings.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index e025be8..71fbcf6 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,30 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+static void acpi_map_other_tables(struct domain *d)
+{
+    int i;
+    unsigned long res;
+    u64 addr, size;
+
+    /* Map all ACPI tables to Dom0 using 1:1 mappings. */
+    for( i = 0; i < acpi_gbl_root_table_list.count; i++ )
+    {
+        addr = acpi_gbl_root_table_list.tables[i].address;
+        size = acpi_gbl_root_table_list.tables[i].length;
+        res = map_regions_rw_cache(d,
+                                   paddr_to_pfn(addr & PAGE_MASK),
+                                   DIV_ROUND_UP(size, PAGE_SIZE),
+                                   paddr_to_pfn(addr & PAGE_MASK));
+        if ( res )
+        {
+             panic(XENLOG_ERR "Unable to map ACPI region 0x%"PRIx64
+                   " - 0x%"PRIx64" in domain \n",
+                   addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1);
+        }
+    }
+}
+
 static int acpi_create_rsdp(struct domain *d, struct membank tbl_add[])
 {
 
@@ -1695,6 +1719,8 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    acpi_map_other_tables(d);
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 11/21] arm/acpi: Prepare EFI system table for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (9 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 10/21] arm/acpi: Map all other tables for Dom0 Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 12/21] arm/acpi: Prepare EFI memory descriptor " Shannon Zhao
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Prepare EFI system table for Dom0 to describe the information of UEFI.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c |  1 +
 xen/arch/arm/efi/efi-dom0.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/setup.h |  3 +++
 3 files changed, 49 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 71fbcf6..6780fb7 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1720,6 +1720,7 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
         return rc;
 
     acpi_map_other_tables(d);
+    acpi_create_efi_system_table(d, tbl_add);
 
     return 0;
 }
diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c
index 021aa02..f4f84b6 100644
--- a/xen/arch/arm/efi/efi-dom0.c
+++ b/xen/arch/arm/efi/efi-dom0.c
@@ -23,8 +23,12 @@
 
 #include "efi.h"
 #include "efi-dom0.h"
+#include <xen/sched.h>
 #include <asm/setup.h>
 #include <asm/acpi.h>
+#include "../../../common/decompress.h"
+#define XZ_EXTERN STATIC
+#include "../../../common/xz/crc32.c"
 
 struct meminfo __initdata acpi_mem;
 /* Constant to indicate "Xen" in unicode u16 format */
@@ -49,6 +53,47 @@ size_t __init estimate_efi_size(int mem_nr_banks)
     return size;
 }
 
+void __init acpi_create_efi_system_table(struct domain *d,
+                                         struct membank tbl_add[])
+{
+    u64 table_addr, table_size, offset = 0;
+    u8 *base_ptr;
+    EFI_CONFIGURATION_TABLE *efi_conf_tbl;
+    EFI_SYSTEM_TABLE *efi_sys_tbl;
+
+    table_addr = d->arch.efi_acpi_gpa
+                 + acpi_get_table_offset(tbl_add, TBL_EFIT);
+    table_size = sizeof(EFI_SYSTEM_TABLE) + sizeof(EFI_CONFIGURATION_TABLE)
+                 + sizeof(xen_efi_fw_vendor);
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_EFIT);
+    efi_sys_tbl = (EFI_SYSTEM_TABLE *)base_ptr;
+
+    efi_sys_tbl->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;
+    /* Specify the revision as 2.5 */
+    efi_sys_tbl->Hdr.Revision = (2 << 16 | 50);
+    efi_sys_tbl->Hdr.HeaderSize = table_size;
+
+    efi_sys_tbl->FirmwareRevision = 1;
+    efi_sys_tbl->NumberOfTableEntries = 1;
+    offset += sizeof(EFI_SYSTEM_TABLE);
+    memcpy(base_ptr + offset, xen_efi_fw_vendor, sizeof(xen_efi_fw_vendor));
+    efi_sys_tbl->FirmwareVendor = (CHAR16 *)(table_addr + offset);
+
+    offset += sizeof(xen_efi_fw_vendor);
+    efi_conf_tbl = (EFI_CONFIGURATION_TABLE *)(base_ptr + offset);
+    efi_conf_tbl->VendorGuid = (EFI_GUID)ACPI_20_TABLE_GUID;
+    efi_conf_tbl->VendorTable = (VOID *)tbl_add[TBL_RSDP].start;
+    efi_sys_tbl->ConfigurationTable = (EFI_CONFIGURATION_TABLE *)(table_addr
+                                                                  + offset);
+    xz_crc32_init();
+    efi_sys_tbl->Hdr.CRC32 = xz_crc32((uint8_t *)efi_sys_tbl,
+                                      efi_sys_tbl->Hdr.HeaderSize, 0);
+
+    tbl_add[TBL_EFIT].start = table_addr;
+    tbl_add[TBL_EFIT].size = table_size;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
index 7f233a1..fc9fd7c 100644
--- a/xen/include/asm-arm/setup.h
+++ b/xen/include/asm-arm/setup.h
@@ -53,6 +53,9 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
 
 size_t estimate_efi_size(int mem_nr_banks);
 
+void acpi_create_efi_system_table(struct domain *d,
+                                  struct membank tbl_add[]);
+
 int construct_dom0(struct domain *d);
 
 void discard_initial_modules(void);
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 12/21] arm/acpi: Prepare EFI memory descriptor for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (10 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 11/21] arm/acpi: Prepare EFI system table " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 13/21] arm/acpi: Map the new created EFI and ACPI tables to Dom0 Shannon Zhao
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Create EFI memory descriptors to tell Dom0 the RAM region information,
ACPI table regions and EFI tables reserved regions.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c |  1 +
 xen/arch/arm/efi/efi-dom0.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/setup.h |  4 ++++
 3 files changed, 49 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 6780fb7..dd4a8ba 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1721,6 +1721,7 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
 
     acpi_map_other_tables(d);
     acpi_create_efi_system_table(d, tbl_add);
+    acpi_create_efi_mmap_table(d, &kinfo->mem, tbl_add);
 
     return 0;
 }
diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c
index f4f84b6..cf71bf4 100644
--- a/xen/arch/arm/efi/efi-dom0.c
+++ b/xen/arch/arm/efi/efi-dom0.c
@@ -24,6 +24,7 @@
 #include "efi.h"
 #include "efi-dom0.h"
 #include <xen/sched.h>
+#include <xen/pfn.h>
 #include <asm/setup.h>
 #include <asm/acpi.h>
 #include "../../../common/decompress.h"
@@ -94,6 +95,49 @@ void __init acpi_create_efi_system_table(struct domain *d,
     tbl_add[TBL_EFIT].size = table_size;
 }
 
+void __init acpi_create_efi_mmap_table(struct domain *d,
+                                       const struct meminfo *mem,
+                                       struct membank tbl_add[])
+{
+    EFI_MEMORY_DESCRIPTOR *memory_map;
+    unsigned int i, offset;
+    u8 *base_ptr;
+
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_MMAP);
+    memory_map = (EFI_MEMORY_DESCRIPTOR *)base_ptr;
+
+    offset = 0;
+    for( i = 0; i < mem->nr_banks; i++, offset++ )
+    {
+        memory_map[offset].Type = EfiConventionalMemory;
+        memory_map[offset].PhysicalStart = mem->bank[i].start;
+        BUG_ON(mem->bank[i].size & EFI_PAGE_MASK);
+        memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(mem->bank[i].size);
+        memory_map[offset].Attribute = EFI_MEMORY_WB;
+    }
+
+    for( i = 0; i < acpi_mem.nr_banks; i++, offset++ )
+    {
+        memory_map[offset].Type = EfiACPIReclaimMemory;
+        memory_map[offset].PhysicalStart = acpi_mem.bank[i].start;
+        BUG_ON(acpi_mem.bank[i].size & EFI_PAGE_MASK);
+        memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(acpi_mem.bank[i].size);
+        memory_map[offset].Attribute = EFI_MEMORY_WB;
+    }
+
+    memory_map[offset].Type = EfiACPIReclaimMemory;
+    memory_map[offset].PhysicalStart = d->arch.efi_acpi_gpa;
+    BUG_ON(d->arch.efi_acpi_len & EFI_PAGE_MASK);
+    memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(d->arch.efi_acpi_len);
+    memory_map[offset].Attribute = EFI_MEMORY_WB;
+
+    tbl_add[TBL_MMAP].start = d->arch.efi_acpi_gpa
+                              + acpi_get_table_offset(tbl_add, TBL_MMAP);
+    tbl_add[TBL_MMAP].size = sizeof(EFI_MEMORY_DESCRIPTOR)
+                             * (mem->nr_banks + acpi_mem.nr_banks + 1);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
index fc9fd7c..9a71e90 100644
--- a/xen/include/asm-arm/setup.h
+++ b/xen/include/asm-arm/setup.h
@@ -56,6 +56,10 @@ size_t estimate_efi_size(int mem_nr_banks);
 void acpi_create_efi_system_table(struct domain *d,
                                   struct membank tbl_add[]);
 
+void acpi_create_efi_mmap_table(struct domain *d,
+                                const struct meminfo *mem,
+                                struct membank tbl_add[]);
+
 int construct_dom0(struct domain *d);
 
 void discard_initial_modules(void);
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 13/21] arm/acpi: Map the new created EFI and ACPI tables to Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (11 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 12/21] arm/acpi: Prepare EFI memory descriptor " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 14/21] arm/acpi: Create min DT stub for Dom0 Shannon Zhao
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Map the UEFI and ACPI tables which we created to non-RAM space in Dom0.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
v8: update the comments
---
 xen/arch/arm/domain_build.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index dd4a8ba..ba75d3b 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1723,6 +1723,28 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     acpi_create_efi_system_table(d, tbl_add);
     acpi_create_efi_mmap_table(d, &kinfo->mem, tbl_add);
 
+    /* Map the EFI and ACPI tables to Dom0 */
+    rc = map_regions_rw_cache(d,
+                              paddr_to_pfn(d->arch.efi_acpi_gpa),
+                              PFN_UP(d->arch.efi_acpi_len),
+                              paddr_to_pfn(virt_to_maddr(d->arch.efi_acpi_table)));
+    if ( rc != 0 )
+    {
+        printk(XENLOG_ERR "Unable to map EFI/ACPI table 0x%"PRIx64
+               " - 0x%"PRIx64" in domain %d\n",
+               d->arch.efi_acpi_gpa & PAGE_MASK,
+               PAGE_ALIGN(d->arch.efi_acpi_gpa + d->arch.efi_acpi_len) - 1,
+               d->domain_id);
+        return rc;
+    }
+
+    /*
+     * Flush the cache for this region, otherwise DOM0 may read wrong data when
+     * the cache is disabled.
+     */
+    clean_and_invalidate_dcache_va_range(d->arch.efi_acpi_table,
+                                         d->arch.efi_acpi_len);
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 14/21] arm/acpi: Create min DT stub for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (12 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 13/21] arm/acpi: Map the new created EFI and ACPI tables to Dom0 Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 15/21] arm/acpi: Permit access all Xen unused SPIs " Shannon Zhao
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Create a DT for Dom0 for ACPI-case only. DT contains minimal required
information such as Dom0 bootargs, initrd, efi description table and
address of uefi memory table.

Also document this device tree bindings of "hypervisor" and
"hypervisor/uefi" node.

Signed-off-by: Naresh Bhat <naresh.bhat@linaro.org>
Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
v8: fix typo in commit message
---
 docs/misc/arm/device-tree/guest.txt |  60 +++++++++++++++
 xen/arch/arm/domain_build.c         | 142 ++++++++++++++++++++++++++++++++++++
 xen/arch/arm/efi/efi-dom0.c         |  39 ++++++++++
 xen/include/asm-arm/setup.h         |   2 +
 4 files changed, 243 insertions(+)
 create mode 100644 docs/misc/arm/device-tree/guest.txt

diff --git a/docs/misc/arm/device-tree/guest.txt b/docs/misc/arm/device-tree/guest.txt
new file mode 100644
index 0000000..418f1e9
--- /dev/null
+++ b/docs/misc/arm/device-tree/guest.txt
@@ -0,0 +1,60 @@
+* Xen hypervisor device tree bindings
+
+Xen ARM virtual platforms shall have a top-level "hypervisor" node with
+the following properties:
+
+- compatible:
+	compatible = "xen,xen-<version>", "xen,xen";
+  where <version> is the version of the Xen ABI of the platform.
+
+- reg: specifies the base physical address and size of a region in
+  memory where the grant table should be mapped to, using an
+  HYPERVISOR_memory_op hypercall. The memory region is large enough to map
+  the whole grant table (it is larger or equal to gnttab_max_grant_frames()).
+  This property is unnecessary when booting Dom0 using ACPI.
+
+- interrupts: the interrupt used by Xen to inject event notifications.
+  A GIC node is also required.
+  This property is unnecessary when booting Dom0 using ACPI.
+
+To support UEFI on Xen ARM virtual platforms, Xen populates the FDT "uefi" node
+under /hypervisor with following parameters:
+
+________________________________________________________________________________
+Name                      | Size   | Description
+================================================================================
+xen,uefi-system-table     | 64-bit | Guest physical address of the UEFI System
+                          |        | Table.
+--------------------------------------------------------------------------------
+xen,uefi-mmap-start       | 64-bit | Guest physical address of the UEFI memory
+                          |        | map.
+--------------------------------------------------------------------------------
+xen,uefi-mmap-size        | 32-bit | Size in bytes of the UEFI memory map
+                          |        | pointed to in previous entry.
+--------------------------------------------------------------------------------
+xen,uefi-mmap-desc-size   | 32-bit | Size in bytes of each entry in the UEFI
+                          |        | memory map.
+--------------------------------------------------------------------------------
+xen,uefi-mmap-desc-ver    | 32-bit | Version of the mmap descriptor format.
+--------------------------------------------------------------------------------
+
+Example (assuming #address-cells = <2> and #size-cells = <2>):
+
+hypervisor {
+	compatible = "xen,xen-4.3", "xen,xen";
+	reg = <0 0xb0000000 0 0x20000>;
+	interrupts = <1 15 0xf08>;
+	uefi {
+		xen,uefi-system-table = <0xXXXXXXXX>;
+		xen,uefi-mmap-start = <0xXXXXXXXX>;
+		xen,uefi-mmap-size = <0xXXXXXXXX>;
+		xen,uefi-mmap-desc-size = <0xXXXXXXXX>;
+		xen,uefi-mmap-desc-ver = <0xXXXXXXXX>;
+        };
+};
+
+The format and meaning of the "xen,uefi-*" parameters are similar to those in
+Documentation/arm/uefi.txt in Linux, which are provided by the regular Linux
+UEFI stub. However they differ because they are provided by the Xen hypervisor,
+together with a set of UEFI runtime services implemented via hypercalls, see
+xen/include/public/platform.h.
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index ba75d3b..756dea5 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,144 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+#define ACPI_DOM0_FDT_MIN_SIZE 4096
+
+static int acpi_make_chosen_node(const struct kernel_info *kinfo)
+{
+    int res;
+    const char *bootargs = NULL;
+    const struct bootmodule *mod = kinfo->kernel_bootmodule;
+    void *fdt = kinfo->fdt;
+
+    DPRINT("Create chosen node\n");
+    res = fdt_begin_node(fdt, "chosen");
+    if ( res )
+        return res;
+
+    if ( mod && mod->cmdline[0] )
+    {
+        bootargs = &mod->cmdline[0];
+        res = fdt_property(fdt, "bootargs", bootargs, strlen(bootargs) + 1);
+        if ( res )
+           return res;
+    }
+
+    /*
+     * If the bootloader provides an initrd, we must create a placeholder
+     * for the initrd properties. The values will be replaced later.
+     */
+    if ( mod && mod->size )
+    {
+        u64 a = 0;
+        res = fdt_property(kinfo->fdt, "linux,initrd-start", &a, sizeof(a));
+        if ( res )
+            return res;
+
+        res = fdt_property(kinfo->fdt, "linux,initrd-end", &a, sizeof(a));
+        if ( res )
+            return res;
+    }
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}
+
+static int acpi_make_hypervisor_node(const struct kernel_info *kinfo,
+                                     struct membank tbl_add[])
+{
+    const char compat[] =
+        "xen,xen-"__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)"\0"
+        "xen,xen";
+    int res;
+    /* Convenience alias */
+    void *fdt = kinfo->fdt;
+
+    DPRINT("Create hypervisor node\n");
+
+    /* See linux Documentation/devicetree/bindings/arm/xen.txt */
+    res = fdt_begin_node(fdt, "hypervisor");
+    if ( res )
+        return res;
+
+    /* Cannot use fdt_property_string due to embedded nulls */
+    res = fdt_property(fdt, "compatible", compat, sizeof(compat));
+    if ( res )
+        return res;
+
+    res = acpi_make_efi_nodes(fdt, tbl_add);
+    if ( res )
+        return res;
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}
+
+/*
+ * Prepare a minimal DTB for Dom0 which contains bootargs, initrd, memory
+ * information, EFI table.
+ */
+static int create_acpi_dtb(struct kernel_info *kinfo, struct membank tbl_add[])
+{
+    int new_size;
+    int ret;
+
+    DPRINT("Prepare a min DTB for DOM0\n");
+
+    /* Allocate min size for DT */
+    new_size = ACPI_DOM0_FDT_MIN_SIZE;
+    kinfo->fdt = xmalloc_bytes(new_size);
+
+    if ( kinfo->fdt == NULL )
+        return -ENOMEM;
+
+    /* Create a new empty DT for DOM0 */
+    ret = fdt_create(kinfo->fdt, new_size);
+    if ( ret < 0 )
+        goto err;
+
+    ret = fdt_finish_reservemap(kinfo->fdt);
+    if ( ret < 0 )
+        goto err;
+
+    ret = fdt_begin_node(kinfo->fdt, "/");
+    if ( ret < 0 )
+        goto err;
+
+    ret = fdt_property_cell(kinfo->fdt, "#address-cells", 2);
+    if ( ret )
+        return ret;
+
+    ret = fdt_property_cell(kinfo->fdt, "#size-cells", 1);
+    if ( ret )
+        return ret;
+
+    /* Create a chosen node for DOM0 */
+    ret = acpi_make_chosen_node(kinfo);
+    if ( ret )
+        goto err;
+
+    ret = acpi_make_hypervisor_node(kinfo, tbl_add);
+    if ( ret )
+        goto err;
+
+    ret = fdt_end_node(kinfo->fdt);
+    if ( ret < 0 )
+        goto err;
+
+    ret = fdt_finish(kinfo->fdt);
+    if ( ret < 0 )
+        goto err;
+
+    return 0;
+
+  err:
+    printk("Device tree generation failed (%d).\n", ret);
+    xfree(kinfo->fdt);
+    return -EINVAL;
+}
+
 static void acpi_map_other_tables(struct domain *d)
 {
     int i;
@@ -1745,6 +1883,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     clean_and_invalidate_dcache_va_range(d->arch.efi_acpi_table,
                                          d->arch.efi_acpi_len);
 
+    rc = create_acpi_dtb(kinfo, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c
index cf71bf4..c40a7c5 100644
--- a/xen/arch/arm/efi/efi-dom0.c
+++ b/xen/arch/arm/efi/efi-dom0.c
@@ -25,6 +25,7 @@
 #include "efi-dom0.h"
 #include <xen/sched.h>
 #include <xen/pfn.h>
+#include <xen/libfdt/libfdt.h>
 #include <asm/setup.h>
 #include <asm/acpi.h>
 #include "../../../common/decompress.h"
@@ -138,6 +139,44 @@ void __init acpi_create_efi_mmap_table(struct domain *d,
                              * (mem->nr_banks + acpi_mem.nr_banks + 1);
 }
 
+/* Create /hypervisor/uefi node for efi properties. */
+int __init acpi_make_efi_nodes(void *fdt, struct membank tbl_add[])
+{
+    int res;
+
+    res = fdt_begin_node(fdt, "uefi");
+    if ( res )
+        return res;
+
+    res = fdt_property_u64(fdt, "xen,uefi-system-table",
+                           tbl_add[TBL_EFIT].start);
+    if ( res )
+        return res;
+
+    res = fdt_property_u64(fdt, "xen,uefi-mmap-start",
+                           tbl_add[TBL_MMAP].start);
+    if ( res )
+        return res;
+
+    res = fdt_property_u32(fdt, "xen,uefi-mmap-size",
+                           tbl_add[TBL_MMAP].size);
+    if ( res )
+        return res;
+
+    res = fdt_property_u32(fdt, "xen,uefi-mmap-desc-size",
+                           sizeof(EFI_MEMORY_DESCRIPTOR));
+    if ( res )
+        return res;
+
+    res = fdt_property_u32(fdt, "xen,uefi-mmap-desc-ver", 1);
+    if ( res )
+        return res;
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
index 9a71e90..3da7a49 100644
--- a/xen/include/asm-arm/setup.h
+++ b/xen/include/asm-arm/setup.h
@@ -60,6 +60,8 @@ void acpi_create_efi_mmap_table(struct domain *d,
                                 const struct meminfo *mem,
                                 struct membank tbl_add[]);
 
+int acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]);
+
 int construct_dom0(struct domain *d);
 
 void discard_initial_modules(void);
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 15/21] arm/acpi: Permit access all Xen unused SPIs for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (13 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 14/21] arm/acpi: Create min DT stub for Dom0 Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 16/21] arm/acpi: Configure SPI interrupt type and route to Dom0 dynamically Shannon Zhao
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Allow DOM0 to use all SPIs but the ones used by Xen. Then when Dom0
configures the interrupt, it could set the interrupt type and route it
to Dom0.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 756dea5..6637752 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1359,6 +1359,37 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 #ifdef CONFIG_ACPI
 #define ACPI_DOM0_FDT_MIN_SIZE 4096
 
+static int acpi_permit_spi_access(struct domain *d)
+{
+    int i, res;
+    struct irq_desc *desc;
+
+    /*
+     * Here just permit Dom0 to access the SPIs which Xen doesn't use. Then when
+     * Dom0 configures the interrupt, set the interrupt type and route it to
+     * Dom0.
+     */
+    for( i = NR_LOCAL_IRQS; i < vgic_num_irqs(d); i++ )
+    {
+        /*
+	 * TODO: Exclude the SPIs SMMU uses which should not be routed to Dom0.
+	 */
+        desc = irq_to_desc(i);
+        if ( desc->action != NULL)
+            continue;
+
+        res = irq_permit_access(d, i);
+        if ( res )
+        {
+            printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n",
+                   d->domain_id, i);
+            return res;
+        }
+    }
+
+    return 0;
+}
+
 static int acpi_make_chosen_node(const struct kernel_info *kinfo)
 {
     int res;
@@ -1887,6 +1918,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_permit_spi_access(d);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 16/21] arm/acpi: Configure SPI interrupt type and route to Dom0 dynamically
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (14 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 15/21] arm/acpi: Permit access all Xen unused SPIs " Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 17/21] arm/gic: Add a new callback to deny Dom0 access to GIC regions Shannon Zhao
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Interrupt information is described in DSDT and is not available at the
time of booting. Check if the interrupt is permitted to access and set
the interrupt type, route it to guest dynamically only for SPI
and Dom0.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/vgic.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
index ee35683..aa420bb 100644
--- a/xen/arch/arm/vgic.c
+++ b/xen/arch/arm/vgic.c
@@ -25,6 +25,8 @@
 #include <xen/irq.h>
 #include <xen/sched.h>
 #include <xen/perfc.h>
+#include <xen/iocap.h>
+#include <xen/acpi.h>
 
 #include <asm/current.h>
 
@@ -334,6 +336,19 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     }
 }
 
+#define VGIC_ICFG_MASK(intr) (1 << ((2 * ((intr) % 16)) + 1))
+
+static inline unsigned int get_the_irq_type(struct vcpu *v, int n, int index)
+{
+    struct vgic_irq_rank *vr = vgic_get_rank(v, n);
+    uint32_t tr = vr->icfg[index >> 4];
+
+    if ( tr & VGIC_ICFG_MASK(index) )
+        return IRQ_TYPE_EDGE_BOTH;
+    else
+        return IRQ_TYPE_LEVEL_MASK;
+}
+
 void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
 {
     const unsigned long mask = r;
@@ -342,9 +357,26 @@ void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned long flags;
     int i = 0;
     struct vcpu *v_target;
+    struct domain *d = v->domain;
+    int ret;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
+        /* Set the irq type and route it to guest only for SPI and Dom0 */
+        if( irq_access_permitted(d, irq) && is_hardware_domain(d) &&
+            ( irq >= 32 ) && ( !acpi_disabled ) )
+        {
+            ret = irq_set_spi_type(irq, get_the_irq_type(v, n, i));
+            if ( ret )
+                gprintk(XENLOG_WARNING, "The irq type is not correct\n");
+
+            vgic_reserve_virq(d, irq);
+
+            ret = route_irq_to_guest(d, irq, irq, NULL);
+            if ( ret )
+                gprintk(XENLOG_ERR, "Unable to route IRQ %u to domain %u\n",
+                        irq, d->domain_id);
+        }
         v_target = __vgic_get_target_vcpu(v, irq);
         p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 17/21] arm/gic: Add a new callback to deny Dom0 access to GIC regions
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (15 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 16/21] arm/acpi: Configure SPI interrupt type and route to Dom0 dynamically Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 18/21] arm/acpi: Permit MMIO access of Xen unused devices for Dom0 Shannon Zhao
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Add a new member in gic_hw_operations which is used to deny Dom0 access
to GIC regions.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/gic-v2.c     | 27 +++++++++++++++++++++++++++
 xen/arch/arm/gic-v3.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic.c        |  5 +++++
 xen/include/asm-arm/gic.h |  3 +++
 4 files changed, 76 insertions(+)

diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c
index 38e3216..450755f 100644
--- a/xen/arch/arm/gic-v2.c
+++ b/xen/arch/arm/gic-v2.c
@@ -22,6 +22,7 @@
 #include <xen/init.h>
 #include <xen/mm.h>
 #include <xen/irq.h>
+#include <xen/iocap.h>
 #include <xen/sched.h>
 #include <xen/errno.h>
 #include <xen/softirq.h>
@@ -684,6 +685,31 @@ static void __init gicv2_dt_init(void)
                csize, vsize);
 }
 
+static int gicv2_iomem_deny_access(const struct domain *d)
+{
+    int rc;
+    unsigned long gfn, nr;
+
+    gfn = dbase >> PAGE_SHIFT;
+    rc = iomem_deny_access(d, gfn, gfn + 1);
+    if ( rc )
+        return rc;
+
+    gfn = hbase >> PAGE_SHIFT;
+    rc = iomem_deny_access(d, gfn, gfn + 1);
+    if ( rc )
+        return rc;
+
+    gfn = cbase >> PAGE_SHIFT;
+    nr = DIV_ROUND_UP(csize, PAGE_SIZE);
+    rc = iomem_deny_access(d, gfn, gfn + nr);
+    if ( rc )
+        return rc;
+
+    gfn = vbase >> PAGE_SHIFT;
+    return iomem_deny_access(d, gfn, gfn + nr);
+}
+
 #ifdef CONFIG_ACPI
 static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset)
 {
@@ -910,6 +936,7 @@ const static struct gic_hw_operations gicv2_ops = {
     .read_apr            = gicv2_read_apr,
     .make_hwdom_dt_node  = gicv2_make_hwdom_dt_node,
     .make_hwdom_madt     = gicv2_make_hwdom_madt,
+    .iomem_deny_access   = gicv2_iomem_deny_access,
 };
 
 /* Set up the GIC */
diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
index 52ee23c..a095064 100644
--- a/xen/arch/arm/gic-v3.c
+++ b/xen/arch/arm/gic-v3.c
@@ -27,6 +27,7 @@
 #include <xen/cpu.h>
 #include <xen/mm.h>
 #include <xen/irq.h>
+#include <xen/iocap.h>
 #include <xen/sched.h>
 #include <xen/errno.h>
 #include <xen/delay.h>
@@ -1235,6 +1236,45 @@ static void __init gicv3_dt_init(void)
                           &vbase, &vsize);
 }
 
+static int gicv3_iomem_deny_access(const struct domain *d)
+{
+    int rc, i;
+    unsigned long gfn, nr;
+
+    gfn = dbase >> PAGE_SHIFT;
+    nr = DIV_ROUND_UP(SZ_64K, PAGE_SIZE);
+    rc = iomem_deny_access(d, gfn, gfn + nr);
+    if ( rc )
+        return rc;
+
+    for ( i = 0; i < gicv3.rdist_count; i++ )
+    {
+        gfn = gicv3.rdist_regions[i].base >> PAGE_SHIFT;
+        nr = DIV_ROUND_UP(gicv3.rdist_regions[i].size, PAGE_SIZE);
+        rc = iomem_deny_access(d, gfn, gfn + nr);
+        if ( rc )
+            return rc;
+    }
+
+    if ( cbase != INVALID_PADDR )
+    {
+        gfn = cbase >> PAGE_SHIFT;
+        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
+        rc = iomem_deny_access(d, gfn, gfn + nr);
+        if ( rc )
+            return rc;
+    }
+
+    if ( vbase != INVALID_PADDR )
+    {
+        gfn = vbase >> PAGE_SHIFT;
+        nr = DIV_ROUND_UP(csize, PAGE_SIZE);
+        return iomem_deny_access(d, gfn, gfn + nr);
+    }
+
+    return 0;
+}
+
 #ifdef CONFIG_ACPI
 static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset)
 {
@@ -1530,6 +1570,7 @@ static const struct gic_hw_operations gicv3_ops = {
     .secondary_init      = gicv3_secondary_cpu_init,
     .make_hwdom_dt_node  = gicv3_make_hwdom_dt_node,
     .make_hwdom_madt     = gicv3_make_hwdom_madt,
+    .iomem_deny_access   = gicv3_iomem_deny_access,
 };
 
 static int __init gicv3_dt_preinit(struct dt_device_node *node, const void *data)
diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
index b3c1eb3..2bfe4de 100644
--- a/xen/arch/arm/gic.c
+++ b/xen/arch/arm/gic.c
@@ -744,6 +744,11 @@ int gic_make_hwdom_madt(const struct domain *d, u32 offset)
     return gic_hw_ops->make_hwdom_madt(d, offset);
 }
 
+int gic_iomem_deny_access(const struct domain *d)
+{
+    return gic_hw_ops->iomem_deny_access(d);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h
index 8130136..cd97bb2 100644
--- a/xen/include/asm-arm/gic.h
+++ b/xen/include/asm-arm/gic.h
@@ -360,6 +360,8 @@ struct gic_hw_operations {
                               const struct dt_device_node *gic, void *fdt);
     /* Create MADT table for the hardware domain */
     int (*make_hwdom_madt)(const struct domain *d, u32 offset);
+    /* Deny access to GIC regions */
+    int (*iomem_deny_access)(const struct domain *d);
 };
 
 void register_gic_ops(const struct gic_hw_operations *ops);
@@ -367,6 +369,7 @@ int gic_make_hwdom_dt_node(const struct domain *d,
                            const struct dt_device_node *gic,
                            void *fdt);
 int gic_make_hwdom_madt(const struct domain *d, u32 offset);
+int gic_iomem_deny_access(const struct domain *d);
 
 #endif /* __ASSEMBLY__ */
 #endif
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 18/21] arm/acpi: Permit MMIO access of Xen unused devices for Dom0
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (16 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 17/21] arm/gic: Add a new callback to deny Dom0 access to GIC regions Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 19/21] xen/acpi: Fix event-channel interrupt when booting with ACPI Shannon Zhao
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Firstly it permits full MMIO capabilities for Dom0. Then deny MMIO
access of Xen used devices, such as UART, GIC, SMMU. Currently, it only
denies the MMIO access of UART and GIC regions. For other Xen used
devices it could be added later when they are supported.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 6637752..d9957ad 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1359,6 +1359,38 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 #ifdef CONFIG_ACPI
 #define ACPI_DOM0_FDT_MIN_SIZE 4096
 
+static int acpi_iomem_deny_access(struct domain *d)
+{
+    acpi_status status;
+    struct acpi_table_spcr *spcr = NULL;
+    unsigned long gfn;
+    int rc;
+
+    /* Firstly permit full MMIO capabilities. */
+    rc = iomem_permit_access(d, 0UL, ~0UL);
+    if ( rc )
+        return rc;
+
+    /* TODO: Deny MMIO access for SMMU, GIC ITS */
+    status = acpi_get_table(ACPI_SIG_SPCR, 0,
+                            (struct acpi_table_header **)&spcr);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        printk("Failed to get SPCR table\n");
+        return -EINVAL;
+    }
+
+    gfn = spcr->serial_port.address >> PAGE_SHIFT;
+    /* Deny MMIO access for UART */
+    rc = iomem_deny_access(d, gfn, gfn + 1);
+    if ( rc )
+        return rc;
+
+    /* Deny MMIO access for GIC regions */
+    return gic_iomem_deny_access(d);
+}
+
 static int acpi_permit_spi_access(struct domain *d)
 {
     int i, res;
@@ -1922,6 +1954,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
     if ( rc != 0 )
         return rc;
 
+    rc = acpi_iomem_deny_access(d);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 19/21] xen/acpi: Fix event-channel interrupt when booting with ACPI
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (17 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 18/21] arm/acpi: Permit MMIO access of Xen unused devices for Dom0 Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 10:08 ` [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping Shannon Zhao
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Store the event-channel interrupt number and flag in HVM parameter
HVM_PARAM_CALLBACK_IRQ. Then Dom0 could get it through hypercall
HVMOP_get_param.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/domain_build.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index d9957ad..aba714c 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2050,6 +2050,7 @@ static void initrd_load(struct kernel_info *kinfo)
 static void evtchn_fixup(struct domain *d, struct kernel_info *kinfo)
 {
     int res, node;
+    u64 val;
     gic_interrupt_t intr;
 
     /*
@@ -2065,6 +2066,19 @@ static void evtchn_fixup(struct domain *d, struct kernel_info *kinfo)
     printk("Allocating PPI %u for event channel interrupt\n",
            d->arch.evtchn_irq);
 
+    /* Set the value of domain param HVM_PARAM_CALLBACK_IRQ */
+    val = (u64)HVM_PARAM_CALLBACK_TYPE_PPI << 56;
+    val |= (2 << 8); /* Active-low level-sensitive  */
+    val |= d->arch.evtchn_irq & 0xff;
+    d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
+
+    /*
+     * When booting Dom0 using ACPI, Dom0 can only get the event channel
+     * interrupt via hypercall.
+     */
+    if ( !acpi_disabled )
+        return;
+
     /* Fix up "interrupts" in /hypervisor node */
     node = fdt_path_offset(kinfo->fdt, "/hypervisor");
     if ( node < 0 )
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (18 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 19/21] xen/acpi: Fix event-channel interrupt when booting with ACPI Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 11:33   ` Jan Beulich
  2016-03-30 16:11   ` Konrad Rzeszutek Wilk
  2016-03-30 10:08 ` [PATCH v8 21/21] xen/arm64: Add ACPI support Shannon Zhao
  2016-03-30 11:58 ` [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Julien Grall
  21 siblings, 2 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, Keir Fraser, Tim Deegan, Ian Jackson,
	peter.huangpeng, julien.grall, stefano.stabellini, shannon.zhao,
	Jan Beulich, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

It needs to map platform or amba device mmio to Dom0 on ARM. But when
booting with ACPI, it can't get the mmio region in Xen due to lack of
AML interpreter to parse DSDT table. Therefore, let Dom0 call a
hypercall to map mmio region when it adds the devices.

Here we add a new map space like the XEN_DOMCTL_memory_mapping to map
mmio region for Dom0. Also add a helper to combine the
xsm_add_to_physmap and XENMAPSPACE_dev_mmio space check together.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
v8: add a helper to combine xsm_add_to_physmap and XENMAPSPACE_dev_mmio
space check together
---
 xen/arch/arm/mm.c           |  3 +++
 xen/arch/arm/p2m.c          | 22 ++++++++++++++++++++++
 xen/common/memory.c         | 17 +++++++++++++++--
 xen/include/asm-arm/p2m.h   |  5 +++++
 xen/include/public/memory.h |  1 +
 5 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 81f9e2e..0aae6c5 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1138,6 +1138,9 @@ int xenmem_add_to_physmap_one(
         rcu_unlock_domain(od);
         break;
     }
+    case XENMAPSPACE_dev_mmio:
+        rc = map_dev_mmio_region(d, gpfn, 1, idx);
+        return rc;
 
     default:
         return -ENOSYS;
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 7e5f5d1..0011708 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -7,6 +7,7 @@
 #include <xen/bitops.h>
 #include <xen/vm_event.h>
 #include <xen/mem_access.h>
+#include <xen/iocap.h>
 #include <public/vm_event.h>
 #include <asm/flushtlb.h>
 #include <asm/gic.h>
@@ -1270,6 +1271,27 @@ int unmap_mmio_regions(struct domain *d,
                              d->arch.p2m.default_access);
 }
 
+int map_dev_mmio_region(struct domain *d,
+                        unsigned long start_gfn,
+                        unsigned long nr,
+                        unsigned long mfn)
+{
+    int res;
+
+    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
+        return 0;
+
+    res = map_mmio_regions(d, start_gfn, nr, mfn);
+    if ( res < 0 )
+    {
+        printk(XENLOG_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
+               start_gfn, start_gfn + nr - 1, d->domain_id);
+        return res;
+    }
+
+    return 0;
+}
+
 int guest_physmap_add_entry(struct domain *d,
                             unsigned long gpfn,
                             unsigned long mfn,
diff --git a/xen/common/memory.c b/xen/common/memory.c
index c7fca96..644f81a 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -834,6 +834,19 @@ static int get_reserved_device_memory(xen_pfn_t start, xen_ulong_t nr,
 }
 #endif
 
+static long xatp_permission_check(struct domain *d, unsigned int space)
+{
+    /*
+     * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain
+     * to map this kind of space to itself.
+     */
+    if ( (space == XENMAPSPACE_dev_mmio) &&
+         (!is_hardware_domain(current->domain) || (d != current->domain)) )
+        return -EACCES;
+
+    return xsm_add_to_physmap(XSM_TARGET, current->domain, d);
+}
+
 long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d;
@@ -980,7 +993,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
+        rc = xatp_permission_check(d, xatp.space);
         if ( rc )
         {
             rcu_unlock_domain(d);
@@ -1024,7 +1037,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( d == NULL )
             return -ESRCH;
 
-        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
+        rc = xatp_permission_check(d, xatpb.space);
         if ( rc )
         {
             rcu_unlock_domain(d);
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 55626b4..d240d1e 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -154,6 +154,11 @@ int unmap_regions_rw_cache(struct domain *d,
                            unsigned long nr_mfns,
                            unsigned long mfn);
 
+int map_dev_mmio_region(struct domain *d,
+                        unsigned long start_gfn,
+                        unsigned long nr,
+                        unsigned long mfn);
+
 int guest_physmap_add_entry(struct domain *d,
                             unsigned long gfn,
                             unsigned long mfn,
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index f69e92f..fe52ee1 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -220,6 +220,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
 #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
 #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
                                     * XENMEM_add_to_physmap_batch only. */
+#define XENMAPSPACE_dev_mmio     5 /* device mmio region */
 /* ` } */
 
 /*
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v8 21/21] xen/arm64: Add ACPI support
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (19 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping Shannon Zhao
@ 2016-03-30 10:08 ` Shannon Zhao
  2016-03-30 11:58 ` [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Julien Grall
  21 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-30 10:08 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, peter.huangpeng, julien.grall, stefano.stabellini,
	shannon.zhao, Jan Beulich, zhaoshenglong

From: Shannon Zhao <shannon.zhao@linaro.org>

Add ACPI support on arm64 xen hypervisor. Enable EFI support on ARM.

Cc: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/Kconfig     |  9 +++++++++
 xen/common/efi/runtime.c | 12 +++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index cb99df5..6231cd5 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -33,6 +33,15 @@ menu "Architecture Features"
 
 source "arch/Kconfig"
 
+config ACPI
+	bool
+	prompt "ACPI (Advanced Configuration and Power Interface) Support" if EXPERT = "y"
+	depends on ARM_64
+	---help---
+
+	  Advanced Configuration and Power Interface (ACPI) support for Xen is
+	  an alternative to device tree on ARM64.
+
 # Select HAS_GICV3 if GICv3 is supported
 config HAS_GICV3
 	bool
diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c
index ae87557..c256814 100644
--- a/xen/common/efi/runtime.c
+++ b/xen/common/efi/runtime.c
@@ -10,14 +10,16 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 
-#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
-const bool_t efi_enabled = 0;
-#else
+/*
+ * Currently runtime services are not implemented on ARM. To boot Xen with ACPI,
+ * set efi_enabled to 1, so that Xen can get the ACPI root pointer from EFI.
+ */
+const bool_t efi_enabled = 1;
+
+#ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
 # include <public/platform.h>
-
-const bool_t efi_enabled = 1;
 #endif
 
 unsigned int __read_mostly efi_num_ct;
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping
  2016-03-30 10:08 ` [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping Shannon Zhao
@ 2016-03-30 11:33   ` Jan Beulich
  2016-03-30 16:11   ` Konrad Rzeszutek Wilk
  1 sibling, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2016-03-30 11:33 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: sstabellini, Keir Fraser, Tim Deegan, Ian Jackson,
	peter.huangpeng, xen-devel, julien.grall, stefano.stabellini,
	shannon.zhao

>>> On 30.03.16 at 12:08, <zhaoshenglong@huawei.com> wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
> 
> It needs to map platform or amba device mmio to Dom0 on ARM. But when
> booting with ACPI, it can't get the mmio region in Xen due to lack of
> AML interpreter to parse DSDT table. Therefore, let Dom0 call a
> hypercall to map mmio region when it adds the devices.
> 
> Here we add a new map space like the XEN_DOMCTL_memory_mapping to map
> mmio region for Dom0. Also add a helper to combine the
> xsm_add_to_physmap and XENMAPSPACE_dev_mmio space check together.
> 
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>

Acked-by: Jan Beulich <jbeulich@suse.com>




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64
  2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
                   ` (20 preceding siblings ...)
  2016-03-30 10:08 ` [PATCH v8 21/21] xen/arm64: Add ACPI support Shannon Zhao
@ 2016-03-30 11:58 ` Julien Grall
  21 siblings, 0 replies; 27+ messages in thread
From: Julien Grall @ 2016-03-30 11:58 UTC (permalink / raw)
  To: Shannon Zhao, xen-devel
  Cc: sstabellini, stefano.stabellini, shannon.zhao, Jan Beulich,
	peter.huangpeng

Hi,

On 30/03/16 11:07, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> These patches are Part 4 (and last part) of the previous patch set I
> sent which adds ACPI support for arm64 on Xen[1]. Split them as an
> individual set for convenient reviewing.
>
> These patches create UEFI and ACPI tables which are mapped to Dom0's
> space and add other preparations for Dom0 to use ACPI. Then at last
> enable ACPI support on ARM64.
>
> See individual patch for changes.

For the rest of the patches:

Acked-by: Julien Grall <julien.grall@arm.com>

Regards,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping
  2016-03-30 10:08 ` [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping Shannon Zhao
  2016-03-30 11:33   ` Jan Beulich
@ 2016-03-30 16:11   ` Konrad Rzeszutek Wilk
  2016-03-30 16:47     ` Julien Grall
  1 sibling, 1 reply; 27+ messages in thread
From: Konrad Rzeszutek Wilk @ 2016-03-30 16:11 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: sstabellini, Keir Fraser, Ian Jackson, Tim Deegan,
	peter.huangpeng, xen-devel, julien.grall, stefano.stabellini,
	shannon.zhao, Jan Beulich

On Wed, Mar 30, 2016 at 06:08:13PM +0800, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
> 
> It needs to map platform or amba device mmio to Dom0 on ARM. But when
> booting with ACPI, it can't get the mmio region in Xen due to lack of
> AML interpreter to parse DSDT table. Therefore, let Dom0 call a
> hypercall to map mmio region when it adds the devices.
> 
> Here we add a new map space like the XEN_DOMCTL_memory_mapping to map
> mmio region for Dom0. Also add a helper to combine the
> xsm_add_to_physmap and XENMAPSPACE_dev_mmio space check together.
> 
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Keir Fraser <keir@xen.org>
> Cc: Tim Deegan <tim@xen.org>
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
> v8: add a helper to combine xsm_add_to_physmap and XENMAPSPACE_dev_mmio
> space check together

I was by accident reviewing the earlier ersion. So let me give comments
here as well.
.. snipp.
> +int map_dev_mmio_region(struct domain *d,
> +                        unsigned long start_gfn,
> +                        unsigned long nr,
> +                        unsigned long mfn)
> +{
> +    int res;
> +
> +    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
> +        return 0;
> +
> +    res = map_mmio_regions(d, start_gfn, nr, mfn);
> +    if ( res < 0 )
> +    {
> +        printk(XENLOG_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",

Should this be printk ratelimited?
> +               start_gfn, start_gfn + nr - 1, d->domain_id);
> +        return res;
> +    }
> +
> +    return 0;
> +}
> +
>  int guest_physmap_add_entry(struct domain *d,
>                              unsigned long gpfn,
>                              unsigned long mfn,
> diff --git a/xen/common/memory.c b/xen/common/memory.c
> index c7fca96..644f81a 100644
> --- a/xen/common/memory.c
> +++ b/xen/common/memory.c
> @@ -834,6 +834,19 @@ static int get_reserved_device_memory(xen_pfn_t start, xen_ulong_t nr,
>  }
>  #endif
>  
> +static long xatp_permission_check(struct domain *d, unsigned int space)
> +{
> +    /*
> +     * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain

s/Domain/domain/
> +     * to map this kind of space to itself.
> +     */
> +    if ( (space == XENMAPSPACE_dev_mmio) &&
> +         (!is_hardware_domain(current->domain) || (d != current->domain)) )
> +        return -EACCES;

Why not -EPERM?

> +
> +    return xsm_add_to_physmap(XSM_TARGET, current->domain, d);
> +}
> +
>  long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>  {
>      struct domain *d;
> @@ -980,7 +993,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>          if ( d == NULL )
>              return -ESRCH;
>  
> -        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
> +        rc = xatp_permission_check(d, xatp.space);

Ah, which nicely takes care of rcu_unlock_domain.
>          if ( rc )
>          {
>              rcu_unlock_domain(d);
> @@ -1024,7 +1037,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>          if ( d == NULL )
>              return -ESRCH;
>  
> -        rc = xsm_add_to_physmap(XSM_TARGET, current->domain, d);
> +        rc = xatp_permission_check(d, xatpb.space);
>          if ( rc )
>          {
>              rcu_unlock_domain(d);
> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
> index 55626b4..d240d1e 100644
> --- a/xen/include/asm-arm/p2m.h
> +++ b/xen/include/asm-arm/p2m.h
> @@ -154,6 +154,11 @@ int unmap_regions_rw_cache(struct domain *d,
>                             unsigned long nr_mfns,
>                             unsigned long mfn);
>  
> +int map_dev_mmio_region(struct domain *d,
> +                        unsigned long start_gfn,
> +                        unsigned long nr,
> +                        unsigned long mfn);
> +
>  int guest_physmap_add_entry(struct domain *d,
>                              unsigned long gfn,
>                              unsigned long mfn,
> diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
> index f69e92f..fe52ee1 100644
> --- a/xen/include/public/memory.h
> +++ b/xen/include/public/memory.h
> @@ -220,6 +220,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
>  #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
>  #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
>                                      * XENMEM_add_to_physmap_batch only. */
> +#define XENMAPSPACE_dev_mmio     5 /* device mmio region */

s/device/Device/ And maybe an full stop at the end?

>  /* ` } */
>  
>  /*
> -- 
> 2.0.4
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping
  2016-03-30 16:11   ` Konrad Rzeszutek Wilk
@ 2016-03-30 16:47     ` Julien Grall
  2016-03-31  8:39       ` Shannon Zhao
  0 siblings, 1 reply; 27+ messages in thread
From: Julien Grall @ 2016-03-30 16:47 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk, Shannon Zhao
  Cc: sstabellini, Keir Fraser, Ian Jackson, Tim Deegan,
	peter.huangpeng, xen-devel, stefano.stabellini, shannon.zhao,
	Jan Beulich

Hi,

On 30/03/16 17:11, Konrad Rzeszutek Wilk wrote:
> On Wed, Mar 30, 2016 at 06:08:13PM +0800, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>
>> It needs to map platform or amba device mmio to Dom0 on ARM. But when
>> booting with ACPI, it can't get the mmio region in Xen due to lack of
>> AML interpreter to parse DSDT table. Therefore, let Dom0 call a
>> hypercall to map mmio region when it adds the devices.
>>
>> Here we add a new map space like the XEN_DOMCTL_memory_mapping to map
>> mmio region for Dom0. Also add a helper to combine the
>> xsm_add_to_physmap and XENMAPSPACE_dev_mmio space check together.
>>
>> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
>> Cc: Jan Beulich <jbeulich@suse.com>
>> Cc: Keir Fraser <keir@xen.org>
>> Cc: Tim Deegan <tim@xen.org>
>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>> ---
>> v8: add a helper to combine xsm_add_to_physmap and XENMAPSPACE_dev_mmio
>> space check together
>
> I was by accident reviewing the earlier ersion. So let me give comments
> here as well.
> .. snipp.

Jan already applied the patch series to xengit/staging. Shannon, can you 
send a follow-up patch to fix at least the printk?

>> +int map_dev_mmio_region(struct domain *d,
>> +                        unsigned long start_gfn,
>> +                        unsigned long nr,
>> +                        unsigned long mfn)
>> +{
>> +    int res;
>> +
>> +    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
>> +        return 0;
>> +
>> +    res = map_mmio_regions(d, start_gfn, nr, mfn);
>> +    if ( res < 0 )
>> +    {
>> +        printk(XENLOG_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
>
> Should this be printk ratelimited?

I think so. Today the domain can only be the hardware domain but it may 
change in the future.

>> +               start_gfn, start_gfn + nr - 1, d->domain_id);
>> +        return res;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>   int guest_physmap_add_entry(struct domain *d,
>>                               unsigned long gpfn,
>>                               unsigned long mfn,

Regards,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping
  2016-03-30 16:47     ` Julien Grall
@ 2016-03-31  8:39       ` Shannon Zhao
  0 siblings, 0 replies; 27+ messages in thread
From: Shannon Zhao @ 2016-03-31  8:39 UTC (permalink / raw)
  To: Julien Grall, Konrad Rzeszutek Wilk
  Cc: sstabellini, Keir Fraser, Ian Jackson, Tim Deegan,
	peter.huangpeng, xen-devel, stefano.stabellini, shannon.zhao,
	Jan Beulich



On 2016/3/31 0:47, Julien Grall wrote:
> Hi,
> 
> On 30/03/16 17:11, Konrad Rzeszutek Wilk wrote:
>> On Wed, Mar 30, 2016 at 06:08:13PM +0800, Shannon Zhao wrote:
>>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>>
>>> It needs to map platform or amba device mmio to Dom0 on ARM. But when
>>> booting with ACPI, it can't get the mmio region in Xen due to lack of
>>> AML interpreter to parse DSDT table. Therefore, let Dom0 call a
>>> hypercall to map mmio region when it adds the devices.
>>>
>>> Here we add a new map space like the XEN_DOMCTL_memory_mapping to map
>>> mmio region for Dom0. Also add a helper to combine the
>>> xsm_add_to_physmap and XENMAPSPACE_dev_mmio space check together.
>>>
>>> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
>>> Cc: Jan Beulich <jbeulich@suse.com>
>>> Cc: Keir Fraser <keir@xen.org>
>>> Cc: Tim Deegan <tim@xen.org>
>>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>>> ---
>>> v8: add a helper to combine xsm_add_to_physmap and XENMAPSPACE_dev_mmio
>>> space check together
>>
>> I was by accident reviewing the earlier ersion. So let me give comments
>> here as well.
>> .. snipp.
> 
> Jan already applied the patch series to xengit/staging. Shannon, can you
> send a follow-up patch to fix at least the printk?
> 
Ok, will send a patch to fix the printk.

Thanks,
-- 
Shannon


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2016-03-31  8:39 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-30 10:07 [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 01/21] arm/acpi: Estimate memory required for acpi/efi tables Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 02/21] arm/acpi: Add a helper function to get the acpi table offset Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 03/21] arm/acpi: Prepare FADT table for Dom0 Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 04/21] arm/gic: Add a new callback for creating MADT " Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 05/21] arm/acpi: Prepare " Shannon Zhao
2016-03-30 10:07 ` [PATCH v8 06/21] arm/acpi: Prepare STAO " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 07/21] arm/acpi: Prepare XSDT " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 08/21] arm/acpi: Prepare RSDP " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 09/21] arm/p2m: Add helper functions to map memory regions Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 10/21] arm/acpi: Map all other tables for Dom0 Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 11/21] arm/acpi: Prepare EFI system table " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 12/21] arm/acpi: Prepare EFI memory descriptor " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 13/21] arm/acpi: Map the new created EFI and ACPI tables to Dom0 Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 14/21] arm/acpi: Create min DT stub for Dom0 Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 15/21] arm/acpi: Permit access all Xen unused SPIs " Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 16/21] arm/acpi: Configure SPI interrupt type and route to Dom0 dynamically Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 17/21] arm/gic: Add a new callback to deny Dom0 access to GIC regions Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 18/21] arm/acpi: Permit MMIO access of Xen unused devices for Dom0 Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 19/21] xen/acpi: Fix event-channel interrupt when booting with ACPI Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 20/21] xen/arm: Add a hypercall for device mmio mapping Shannon Zhao
2016-03-30 11:33   ` Jan Beulich
2016-03-30 16:11   ` Konrad Rzeszutek Wilk
2016-03-30 16:47     ` Julien Grall
2016-03-31  8:39       ` Shannon Zhao
2016-03-30 10:08 ` [PATCH v8 21/21] xen/arm64: Add ACPI support Shannon Zhao
2016-03-30 11:58 ` [PATCH v8 00/21] Prepare UEFI and ACPI tables for Dom0 on ARM64 Julien Grall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).