[Xen-devel] [PATCH v8 10/16] libxl/arm: Construct ACPI FADT table

2016-09-28 Thread Shannon Zhao
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index f593dab..6530f45 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -310,6 +310,25 @@ out:
 return rc;
 }
 
+static void make_acpi_fadt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[FADT].addr - GUEST_ACPI_BASE;
+struct acpi_table_fadt *fadt = (void *)dom->acpi_modules[0].data + offset;
+
+/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */
+fadt->flags = ACPI_FADT_HW_REDUCED;
+fadt->arm_boot_flags = ACPI_FADT_PSCI_COMPLIANT | ACPI_FADT_PSCI_USE_HVC;
+
+/* ACPI v5.1 (fadt->revision.fadt->minor_revision) */
+fadt->minor_revision = 0x1;
+fadt->dsdt = acpitables[DSDT].addr;
+
+make_acpi_header(>header, "FACP", acpitables[FADT].size, 5);
+calculate_checksum(fadt, offsetof(struct acpi_table_header, checksum),
+   acpitables[FADT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -338,6 +357,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
 rc = make_acpi_madt(gc, dom, info, acpitables);
+if (rc)
+goto out;
+
+make_acpi_fadt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-28 Thread Shannon Zhao
Here it adds the ACPI tables size to set the target maxmem to avoid
providing less available memory for guest.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl.c | 45 -
 tools/libxl/libxl_arch.h|  5 +
 tools/libxl/libxl_arm.c | 20 ++
 tools/libxl/libxl_arm.h |  5 +
 tools/libxl/libxl_arm_acpi.c| 23 +
 tools/libxl/libxl_arm_no_acpi.c |  7 +++
 tools/libxl/libxl_dom.c | 11 --
 tools/libxl/libxl_internal.h|  2 ++
 tools/libxl/libxl_x86.c |  9 +
 9 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 997d94c..a46b827 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -17,6 +17,7 @@
 #include "libxl_osdeps.h"
 
 #include "libxl_internal.h"
+#include "libxl_arch.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
@@ -4022,10 +4023,11 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t 
domid, uint64_t max_memkb)
 {
 GC_INIT(ctx);
 char *mem, *endptr;
-uint64_t memorykb;
+uint64_t memorykb, size;
 char *dompath = libxl__xs_get_dompath(gc, domid);
 int rc = 1;
 libxl__domain_userdata_lock *lock = NULL;
+libxl_domain_config d_config;
 
 CTX_LOCK;
 
@@ -4051,11 +4053,24 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t 
domid, uint64_t max_memkb)
  "memory_static_max must be greater than or or equal to 
memory_dynamic_max");
 goto out;
 }
-rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + 
LIBXL_MAXMEM_CONSTANT);
+
+rc = libxl_retrieve_domain_configuration(ctx, domid, _config);
+if (rc < 0) {
+LOGE(ERROR, "unable to retrieve domain configuration");
+goto out;
+}
+
+rc = libxl__arch_extra_memory(gc, _config.b_info, );
+if (rc < 0) {
+LOGE(ERROR, "Couldn't get arch extra constant memory size");
+goto out;
+}
+
+rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + size);
 if (rc != 0) {
 LOGE(ERROR,
  "xc_domain_setmaxmem domid=%d memkb=%"PRIu64" failed ""rc=%d\n",
- domid, max_memkb + LIBXL_MAXMEM_CONSTANT, rc);
+ domid, max_memkb + size, rc);
 goto out;
 }
 
@@ -4149,7 +4164,7 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t 
domid,
 {
 GC_INIT(ctx);
 int rc, r, lrc, abort_transaction = 0;
-uint64_t memorykb;
+uint64_t memorykb, size;
 uint64_t videoram = 0;
 uint64_t current_target_memkb = 0, new_target_memkb = 0;
 uint64_t current_max_memkb = 0;
@@ -4160,6 +4175,7 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t 
domid,
 char *uuid;
 xs_transaction_t t;
 libxl__domain_userdata_lock *lock;
+libxl_domain_config d_config;
 
 CTX_LOCK;
 
@@ -4169,6 +4185,18 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t 
domid,
 goto out_no_transaction;
 }
 
+rc = libxl_retrieve_domain_configuration(ctx, domid, _config);
+if (rc < 0) {
+LOGE(ERROR, "unable to retrieve domain configuration");
+goto out_no_transaction;
+}
+
+rc = libxl__arch_extra_memory(gc, _config.b_info, );
+if (rc < 0) {
+LOGE(ERROR, "Couldn't get arch extra constant memory size");
+goto out_no_transaction;
+}
+
 retry_transaction:
 t = xs_transaction_start(ctx->xsh);
 
@@ -4246,13 +4274,12 @@ retry_transaction:
 
 if (enforce) {
 memorykb = new_target_memkb + videoram;
-r = xc_domain_setmaxmem(ctx->xch, domid, memorykb +
-LIBXL_MAXMEM_CONSTANT);
+r = xc_domain_setmaxmem(ctx->xch, domid, memorykb + size);
 if (r != 0) {
 LOGE(ERROR,
  "xc_domain_setmaxmem domid=%u memkb=%"PRIu64" failed 
""rc=%d\n",
  domid,
- memorykb + LIBXL_MAXMEM_CONSTANT,
+ memorykb + size,
  r);
 abort_transaction = 1;
 rc = ERROR_FAIL;
@@ -4261,12 +4288,12 @@ retry_transaction:
 }
 
 r = xc_domain_set_pod_target(ctx->xch, domid,
-(new_target_memkb + LIBXL_MAXMEM_CONSTANT) / 4, NULL, NULL, NULL);
+(new_target_memkb + size) / 4, NULL, NULL, NULL);
 if (r != 0) {
 LOGE(ERROR,
  "xc_domain_set_pod_target domid=%d, memkb=%"PRIu64" failed 
rc=%d\n",
  domid,
- new_target_memkb / 4,
+ (new_target_memkb + size) / 4,
  r);
 abort_transaction = 1;
 rc = ERROR_FAIL;
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index fff0554..5e1fc60 100644
--- a/tools/libxl/libxl_arch.h
+++ b

[Xen-devel] [PATCH v8 15/16] libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ

2016-09-28 Thread Shannon Zhao
The guest kernel will get the event channel interrupt information via
domain param HVM_PARAM_CALLBACK_IRQ. Initialize it here.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm.c  | 14 ++
 tools/libxl/libxl_internal.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 376307e..5f5ff03 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -900,8 +900,22 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
struct xc_dom_image *dom)
 {
 int rc;
+uint64_t val;
 
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
+
+/* Set the value of domain param HVM_PARAM_CALLBACK_IRQ. */
+val = MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI,
+HVM_PARAM_CALLBACK_IRQ_TYPE_MASK);
+/* Active-low level-sensitive  */
+val |= MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL,
+ HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK);
+val |= GUEST_EVTCHN_PPI;
+rc = xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CALLBACK_IRQ,
+  val);
+if (rc)
+return rc;
+
 rc = libxl__prepare_dtb(gc, info, state, dom);
 if (rc) goto out;
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index f1ba473..cb6d9e0 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -128,6 +128,9 @@
 #define ROUNDUP(_val, _order)   \
 (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1))
 
+#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
+#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+
 #define min(X, Y) ({ \
 const typeof (X) _x = (X);   \
 const typeof (Y) _y = (Y);   \
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-09-28 Thread Shannon Zhao
Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
them in evtchn_fixup().

Also use HVM_PARAM_CALLBACK_IRQ_TYPE_MASK in hvm_set_callback_via().

Cc: Jan Beulich <jbeul...@suse.com>
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 xen/arch/arm/domain_build.c | 9 ++---
 xen/arch/x86/hvm/irq.c  | 2 +-
 xen/include/public/hvm/params.h | 3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index f1c5526..ce97359 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2064,9 +2064,12 @@ static void evtchn_fixup(struct domain *d, struct 
kernel_info *kinfo)
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;
+val = MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI,
+HVM_PARAM_CALLBACK_IRQ_TYPE_MASK);
+/* Active-low level-sensitive  */
+val |= MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL,
+ HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK);
+val |= d->arch.evtchn_irq;
 d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
 
 /*
diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c
index 5323d7c..e597114 100644
--- a/xen/arch/x86/hvm/irq.c
+++ b/xen/arch/x86/hvm/irq.c
@@ -325,7 +325,7 @@ void hvm_set_callback_via(struct domain *d, uint64_t via)
 unsigned int gsi=0, pdev=0, pintx=0;
 uint8_t via_type;
 
-via_type = (uint8_t)(via >> 56) + 1;
+via_type = (uint8_t)MASK_EXTR(via, HVM_PARAM_CALLBACK_IRQ_TYPE_MASK) + 1;
 if ( ((via_type == HVMIRQ_callback_gsi) && (via == 0)) ||
  (via_type > HVMIRQ_callback_vector) )
 via_type = HVMIRQ_callback_none;
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index f7338a3..3f54a49 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -30,6 +30,7 @@
  */
 
 #define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_MASK xen_mk_ullong(0xFF00)
 /*
  * How should CPU0 event-channel notifications be delivered?
  *
@@ -66,6 +67,8 @@
  * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to
  * the notification is handled by the interrupt controller.
  */
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK  0xFF00
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
 #endif
 
 /*
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 12/16] libxl/arm: Factor finalise_one_memory_node as a gerneric function

2016-09-28 Thread Shannon Zhao
Rename finalise_one_memory_node to finalise_one_node and pass the node
name via function parameter.

This is useful for adding ACPI module which will be added by a later
patch.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index a21dc56..19d3067 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -905,11 +905,11 @@ out:
 return rc;
 }
 
-static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
- uint64_t base, uint64_t size)
+static void finalise_one_node(libxl__gc *gc, void *fdt, const char *uname,
+  uint64_t base, uint64_t size)
 {
 int node, res;
-const char *name = GCSPRINTF("/memory@%"PRIx64, base);
+const char *name = GCSPRINTF("%s@%"PRIx64, uname, base);
 
 node = fdt_path_offset(fdt, name);
 assert(node > 0);
@@ -972,7 +972,7 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 for (i = 0; i < GUEST_RAM_BANKS; i++) {
 const uint64_t size = (uint64_t)dom->rambank_size[i] << XC_PAGE_SHIFT;
 
-finalise_one_memory_node(gc, fdt, bankbase[i], size);
+finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
 debug_dump_fdt(gc, fdt);
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 01/16] tools/libxl: Add an unified configuration option for ACPI

2016-09-28 Thread Shannon Zhao
Since the existing configuration option "u.hvm.acpi" is x86 specific and
we want to reuse it on ARM as well, add a unified option "acpi" for
x86 and ARM, and for ARM it's disabled by default.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 docs/man/xl.cfg.pod.5.in | 1 +
 tools/libxl/libxl_arch.h | 4 
 tools/libxl/libxl_arm.c  | 6 ++
 tools/libxl/libxl_create.c   | 4 +++-
 tools/libxl/libxl_dm.c   | 4 ++--
 tools/libxl/libxl_internal.h | 6 ++
 tools/libxl/libxl_types.idl  | 4 
 tools/libxl/libxl_x86.c  | 6 ++
 tools/libxl/xl_cmdimpl.c | 2 +-
 9 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index d8108e3..21b58bc 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -1249,6 +1249,7 @@ the virtual firmware to the guest Operating System. ACPI 
is required
 by most modern guest Operating Systems. This option is enabled by
 default and usually you should omit it. However it may be necessary to
 disable ACPI for compatibility with some guest Operating Systems.
+This option is true for x86 while it's false for ARM by default.
 
 =item B

[Xen-devel] [PATCH v8 11/16] libxl/arm: Construct ACPI DSDT table

2016-09-28 Thread Shannon Zhao
Copy the static DSDT table into ACPI blob.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 6530f45..6c713ac 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -329,6 +329,15 @@ static void make_acpi_fadt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[FADT].size);
 }
 
+static void make_acpi_dsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[DSDT].addr - GUEST_ACPI_BASE;
+void *dsdt = dom->acpi_modules[0].data + offset;
+
+memcpy(dsdt, dsdt_anycpu_arm, dsdt_anycpu_arm_len);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -361,6 +370,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_fadt(gc, dom, acpitables);
+make_acpi_dsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 09/16] libxl/arm: Construct ACPI MADT table

2016-09-28 Thread Shannon Zhao
According to the GIC version, construct the MADT table.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 84 
 1 file changed, 84 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index b2136fd..f593dab 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -227,6 +227,89 @@ static void make_acpi_gtdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[GTDT].size);
 }
 
+static void make_acpi_madt_gicc(void *table, int nr_cpus, uint64_t gicc_base)
+{
+int i;
+struct acpi_madt_generic_interrupt *gicc = table;
+
+for (i = 0; i < nr_cpus; i++) {
+gicc->header.type = ACPI_MADT_TYPE_GENERIC_INTERRUPT;
+gicc->header.length = ACPI_MADT_GICC_SIZE_v5;
+gicc->base_address = gicc_base;
+gicc->cpu_interface_number = i;
+gicc->arm_mpidr = libxl__compute_mpdir(i);
+gicc->uid = i;
+gicc->flags = ACPI_MADT_ENABLED;
+gicc = table + ACPI_MADT_GICC_SIZE_v5;
+}
+}
+
+static void make_acpi_madt_gicd(void *table, uint64_t gicd_base,
+uint8_t gic_version)
+{
+struct acpi_madt_generic_distributor *gicd = table;
+
+gicd->header.type = ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR;
+gicd->header.length = sizeof(*gicd);
+gicd->base_address = gicd_base;
+/* This version field has no meaning before ACPI 5.1 errata. */
+gicd->version = gic_version;
+}
+
+static void make_acpi_madt_gicr(void *table, uint64_t gicr_base,
+uint64_t gicr_size)
+{
+struct acpi_madt_generic_redistributor *gicr = table;
+
+gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR;
+gicr->header.length = sizeof(*gicr);
+gicr->base_address = gicr_base;
+gicr->length = gicr_size;
+}
+
+static int make_acpi_madt(libxl__gc *gc, struct xc_dom_image *dom,
+  libxl_domain_build_info *info,
+  struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[MADT].addr - GUEST_ACPI_BASE;
+void *table = dom->acpi_modules[0].data + offset;
+struct acpi_table_madt *madt = table;
+int rc = 0;
+
+switch (info->arch_arm.gic_version) {
+case LIBXL_GIC_VERSION_V2:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, info->max_vcpus, GUEST_GICC_BASE);
+
+table += ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus;
+make_acpi_madt_gicd(table, GUEST_GICD_BASE, ACPI_MADT_GIC_VERSION_V2);
+break;
+case LIBXL_GIC_VERSION_V3:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, info->max_vcpus, 0);
+
+table += ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus;
+make_acpi_madt_gicd(table, GUEST_GICV3_GICD_BASE,
+ACPI_MADT_GIC_VERSION_V3);
+
+table += sizeof(struct acpi_madt_generic_distributor);
+make_acpi_madt_gicr(table, GUEST_GICV3_GICR0_BASE,
+GUEST_GICV3_GICR0_SIZE);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+goto out;
+}
+
+make_acpi_header(>header, "APIC", acpitables[MADT].size, 3);
+calculate_checksum(madt, offsetof(struct acpi_table_header, checksum),
+   acpitables[MADT].size);
+
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -254,6 +337,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
+rc = make_acpi_madt(gc, dom, info, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 06/16] libxl/arm: Construct ACPI XSDT table

2016-09-28 Thread Shannon Zhao
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 0512630..ab68bf8 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -161,6 +161,35 @@ static void make_acpi_rsdp(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[RSDP].size);
 }
 
+static void make_acpi_header(struct acpi_table_header *h, const char *sig,
+ size_t len, uint8_t rev)
+{
+memcpy(h->signature, sig, 4);
+h->length = len;
+h->revision = rev;
+memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
+memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id));
+h->oem_revision = 0;
+memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
+   sizeof(h->asl_compiler_id));
+h->asl_compiler_revision = 0;
+h->checksum = 0;
+}
+
+static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[XSDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_xsdt *xsdt = (void *)dom->acpi_modules[0].data + offset;
+
+xsdt->table_offset_entry[0] = acpitables[MADT].addr;
+xsdt->table_offset_entry[1] = acpitables[GTDT].addr;
+xsdt->table_offset_entry[2] = acpitables[FADT].addr;
+make_acpi_header(>header, "XSDT", acpitables[XSDT].size, 1);
+calculate_checksum(xsdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[XSDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -186,6 +215,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_rsdp(gc, dom, acpitables);
+make_acpi_xsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 13/16] libxl/arm: Add ACPI module

2016-09-28 Thread Shannon Zhao
Add the ARM Multiboot module for ACPI, so UEFI or DomU can get the base
address of ACPI tables from it.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 docs/misc/arm/device-tree/acpi.txt | 24 
 tools/libxl/libxl_arm.c| 24 
 2 files changed, 48 insertions(+)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt

diff --git a/docs/misc/arm/device-tree/acpi.txt 
b/docs/misc/arm/device-tree/acpi.txt
new file mode 100644
index 000..3e70157
--- /dev/null
+++ b/docs/misc/arm/device-tree/acpi.txt
@@ -0,0 +1,24 @@
+DomU ACPI module
+
+
+Xen toolstack passes the domU ACPI tables via a reference in the /chosen node 
of
+the device tree.
+
+Each node contains the following properties:
+
+- compatible
+
+   "xen,guest-acpi", "multiboot,module"
+
+- reg
+
+   Specifies the physical address and the length of the module.
+   RSDP table is always located at the beginning of this region.
+
+Examples
+
+
+   module@0x2000 {
+   compatible = "xen,guest-acpi", "multiboot,module";
+   reg = <0x2000 0x1234>;
+   };
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 19d3067..376307e 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -285,6 +285,25 @@ static int make_chosen_node(libxl__gc *gc, void *fdt, bool 
ramdisk,
 if (res) return res;
 }
 
+if (libxl_defbool_val(info->acpi)) {
+const uint64_t acpi_base = GUEST_ACPI_BASE;
+const char *name = GCSPRINTF("module@%"PRIx64, acpi_base);
+
+res = fdt_begin_node(fdt, name);
+if (res) return res;
+
+res = fdt_property_compat(gc, fdt, 2, "xen,guest-acpi",
+  "multiboot,module");
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1, 0, 0);
+if (res) return res;
+
+res = fdt_end_node(fdt);
+if (res) return res;
+}
+
 res = fdt_end_node(fdt);
 if (res) return res;
 
@@ -975,6 +994,11 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
+if (dom->acpi_modules[0].data) {
+finalise_one_node(gc, fdt, "/chosen/module", GUEST_ACPI_BASE,
+  dom->acpi_modules[0].length);
+}
+
 debug_dump_fdt(gc, fdt);
 
 return 0;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 08/16] libxl/arm: Factor MPIDR computing codes out as a helper

2016-09-28 Thread Shannon Zhao
Factor MPIDR computing codes out as a helper, so it could be shared
between DT and ACPI.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm.c |  8 +---
 tools/libxl/libxl_arm.h | 11 +++
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index ec76c32..a21dc56 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -309,13 +309,7 @@ static int make_cpus_node(libxl__gc *gc, void *fdt, int 
nr_cpus,
 for (i = 0; i < nr_cpus; i++) {
 const char *name;
 
-/*
- * According to ARM CPUs bindings, the reg field should match
- * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
- * constructing the reg value of the guest at the moment, for it
- * is enough for the current max vcpu number.
- */
-mpidr_aff = (i & 0x0f) | (((i >> 4) & 0xff) << 8);
+mpidr_aff = libxl__compute_mpdir(i);
 name = GCSPRINTF("cpu@%"PRIx64, mpidr_aff);
 
 res = fdt_begin_node(fdt, name);
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index fcce405..7097def 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -23,6 +23,17 @@ _hidden
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom);
 
+static inline uint64_t libxl__compute_mpdir(unsigned int cpuid)
+{
+/*
+ * According to ARM CPUs bindings, the reg field should match
+ * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
+ * constructing the reg value of the guest at the moment, for it
+ * is enough for the current max vcpu number.
+ */
+return (cpuid & 0x0f) | (((cpuid >> 4) & 0xff) << 8);
+}
+
 /*
  * Local variables:
  * mode: C
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 00/16] Xen ARM DomU ACPI support

2016-09-28 Thread Shannon Zhao
The design of this feature is described as below.
Firstly, the toolstack (libxl) generates the ACPI tables according the
number of vcpus and gic controller.

Then, it copies these ACPI tables to DomU non-RAM memory map space and
passes them to UEFI firmware through the "ARM multiboot" protocol.

At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
and installs these tables like the usual way and passes both ACPI and DT
information to the Xen DomU.

Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
since it's enough now.

This has been tested using guest kernel with the Dom0 ACPI support
patches which could be fetched from linux master or:
https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen

The UEFI binary could be fetched from or built from edk2 master branch:
http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd

This series can be fetched from:
https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v8

Changes since v7:
* use xen_mk_ullong
* replace LIBXL_MAXMEM_CONSTANT everywhere
* do not use return value as output parameter

Changes since v5:
* Set the MADT GICC size correctly
* Add libxl__arch_memory_constant to get acpi table size and add it at
  common code
* other samll changes

Changes since v4:
* make changes in tools/configure.ac instead of tools/configure
* add libxl_arm_no_acpi.c for no acpi build
* add a function to get the acpi table size and use it to set maxmem
* drop HVM_PARAM_CALLBACK_TYPE_PPI_MASK and update hvm_set_callback_via
* add libxl__arch_domain_build_info_acpi_setdefault to set b_info->acpi
  default value separately
* update ACPI_OEM_ID
* set gtdt->counter_block_addresss and gtdt->counter_read_block_address
* add a BUILD_BUG_ON to check if GUEST_MAX_VCPUS >= MAX_VIRT_CPUS

Changes since v3:
* use goto style error handle
* unify configuration option for ACPI
* use extended_checksum instead of checksum in RSDP table
* only require iasl on arm64
* count acpi tables size for maxmem

Changes since v2:
* return error for 32bit domain with acpi enabled
* include actypes.h to reuse the definitions
* rename libxl_arm_acpi.h to libxl_arm.h
* use ACPI_MADT_ENABLED
* rebased on top of Boris's ACPI branch to reuse mk_dsdt.c

Changes since v1:
* move ACPI tables generation codes to a new file
* use static asl file to generate DSDT table and include processor
  device objects
* assign a non-RAM map for ACPI blob
* use existing ACPI table definitions under xen/include/acpi/
* add a configuration for user to enable/disable ACPI generation
* calculate the ACPI table checksum

Shannon Zhao (16):
  tools/libxl: Add an unified configuration option for ACPI
  libxl/arm: prepare for constructing ACPI tables
  libxl/arm: Generate static ACPI DSDT table
  libxl/arm: Estimate the size of ACPI tables
  libxl/arm: Construct ACPI RSDP table
  libxl/arm: Construct ACPI XSDT table
  libxl/arm: Construct ACPI GTDT table
  libxl/arm: Factor MPIDR computing codes out as a helper
  libxl/arm: Construct ACPI MADT table
  libxl/arm: Construct ACPI FADT table
  libxl/arm: Construct ACPI DSDT table
  libxl/arm: Factor finalise_one_memory_node as a gerneric function
  libxl/arm: Add ACPI module
  public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI
  libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ
  libxl/arm: Add the size of ACPI tables to maxmem

 docs/man/xl.cfg.pod.5.in   |   1 +
 docs/misc/arm/device-tree/acpi.txt |  24 +++
 tools/configure.ac |   2 +-
 tools/libacpi/Makefile |   8 +-
 tools/libacpi/mk_dsdt.c|  27 ++-
 tools/libxl/Makefile   |  10 +
 tools/libxl/libxl.c|  45 +++-
 tools/libxl/libxl_arch.h   |   9 +
 tools/libxl/libxl_arm.c| 104 --
 tools/libxl/libxl_arm.h|  48 +
 tools/libxl/libxl_arm_acpi.c   | 408 +
 tools/libxl/libxl_arm_no_acpi.c|  40 
 tools/libxl/libxl_create.c |   4 +-
 tools/libxl/libxl_dm.c |   4 +-
 tools/libxl/libxl_dom.c|  11 +-
 tools/libxl/libxl_internal.h   |  11 +
 tools/libxl/libxl_types.idl|   4 +
 tools/libxl/libxl_x86.c|  15 ++
 tools/libxl/xl_cmdimpl.c   |   2 +-
 xen/arch/arm/domain.c  |   1 +
 xen/arch/arm/domain_build.c|   9 +-
 xen/arch/x86/hvm/irq.c |   2 +-
 xen/include/acpi/actbl1.h  |   2 +
 xen/include/public/arch-arm.h  |   7 +
 xen/include/public/hvm/params.h|   3 +
 25 files changed, 767 insertions(+), 34 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c
 create mode 100644 tools/libxl/libxl_arm_no_acpi.c

-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 02/16] libxl/arm: prepare for constructing ACPI tables

2016-09-28 Thread Shannon Zhao
It only constructs the ACPI tables for 64-bit ARM DomU when user enables
acpi because 32-bit DomU doesn't support ACPI. And the generation codes
are only built for 64-bit toolstack.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/Makefile|  7 +
 tools/libxl/libxl_arm.c | 24 +++-
 tools/libxl/libxl_arm.h | 32 +
 tools/libxl/libxl_arm_acpi.c| 61 +
 tools/libxl/libxl_arm_no_acpi.c | 33 ++
 xen/include/public/arch-arm.h   |  4 +++
 6 files changed, 160 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c
 create mode 100644 tools/libxl/libxl_arm_no_acpi.c

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 3c63bf9..d8cd5f9 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -90,6 +90,13 @@ acpi:
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o 
libxl_x86_acpi.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
+ifeq ($(CONFIG_ARM_64),y)
+LIBXL_OBJS-y += libxl_arm_acpi.o
+libxl_arm_acpi.o: libxl_arm_acpi.c
+   $(CC) -c $(CFLAGS) -I../../xen/include/ -o $@ libxl_arm_acpi.c
+else
+LIBXL_OBJS-$(CONFIG_ARM) += libxl_arm_no_acpi.o
+endif
 
 ifeq ($(CONFIG_NetBSD),y)
 LIBXL_OBJS-y += libxl_netbsd.o
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 8ec5cd5..ec76c32 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -1,6 +1,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 #include "libxl_libfdt_compat.h"
+#include "libxl_arm.h"
 
 #include 
 #include 
@@ -885,8 +886,29 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
libxl__domain_build_state *state,
struct xc_dom_image *dom)
 {
+int rc;
+
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
-return libxl__prepare_dtb(gc, info, state, dom);
+rc = libxl__prepare_dtb(gc, info, state, dom);
+if (rc) goto out;
+
+if (!libxl_defbool_val(info->acpi)) {
+LOG(DEBUG, "Generating ACPI tables is disabled by user.");
+rc = 0;
+goto out;
+}
+
+if (strcmp(dom->guest_type, "xen-3.0-aarch64")) {
+/* ACPI is only supported for 64-bit guest currently. */
+LOG(ERROR, "Can not enable libxl option 'acpi' for %s", 
dom->guest_type);
+rc = ERROR_FAIL;
+goto out;
+}
+
+rc = libxl__prepare_acpi(gc, info, dom);
+
+out:
+return rc;
 }
 
 static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
new file mode 100644
index 000..fcce405
--- /dev/null
+++ b/tools/libxl/libxl_arm.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_internal.h"
+#include "libxl_arch.h"
+
+#include 
+
+_hidden
+int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
+struct xc_dom_image *dom);
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
new file mode 100644
index 000..5bf9396
--- /dev/null
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -0,0 +1,61 @@
+/*
+ * ARM DomU ACPI generation
+ *
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_arm.h"
+
+#include 
+
+/* Below typedefs are useful for the headers under acpi/ *

[Xen-devel] [PATCH v8 04/16] libxl/arm: Estimate the size of ACPI tables

2016-09-28 Thread Shannon Zhao
Estimate the size of ACPI tables and reserve a memory map space for ACPI
tables.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 95 
 xen/include/acpi/actbl1.h|  2 +
 2 files changed, 97 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 06dff5f..bc9ab84 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,11 +34,104 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+enum {
+RSDP,
+XSDT,
+GTDT,
+MADT,
+FADT,
+DSDT,
+MAX_TABLE_NUMS,
+};
+
+struct acpitable {
+uint64_t addr;
+size_t size;
+};
+
+static int libxl__estimate_madt_size(libxl__gc *gc,
+ const libxl_domain_build_info *info,
+ size_t *size)
+{
+int rc = 0;
+
+switch (info->arch_arm.gic_version) {
+case LIBXL_GIC_VERSION_V2:
+*size = sizeof(struct acpi_table_madt) +
+ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+sizeof(struct acpi_madt_generic_distributor);
+break;
+case LIBXL_GIC_VERSION_V3:
+*size = sizeof(struct acpi_table_madt) +
+ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+sizeof(struct acpi_madt_generic_distributor) +
+sizeof(struct acpi_madt_generic_redistributor);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+break;
+}
+
+return rc;
+}
+
+static int libxl__allocate_acpi_tables(libxl__gc *gc,
+   libxl_domain_build_info *info,
+   struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+int rc;
+size_t size;
+
+acpitables[RSDP].addr = GUEST_ACPI_BASE;
+acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+/*
+ * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+ * entries for them.
+ */
+acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+sizeof(uint64_t) * 2;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+rc = libxl__estimate_madt_size(gc, info, );
+if (rc < 0)
+goto out;
+
+acpitables[MADT].size = size;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[DSDT].size = dsdt_anycpu_arm_len;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+rc = 0;
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
 const libxl_version_info *vers;
 int rc = 0;
+struct acpitable acpitables[MAX_TABLE_NUMS];
 
 vers = libxl_get_version_info(CTX);
 if (vers == NULL) {
@@ -53,6 +146,8 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].length = 0;
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
+rc = libxl__allocate_acpi_tables(gc, info, dom, acpitables);
+
 out:
 return rc;
 }
diff --git a/xen/include/acpi/actbl1.h b/xen/include/acpi/actbl1.h
index ed5cd2d..e199136 100644
--- a/xen/include/acpi/actbl1.h
+++ b/xen/include/acpi/actbl1.h
@@ -786,6 +786,8 @@ struct acpi_madt_generic_interrupt {
u8 reserved2[3];
 };
 
+#define ACPI_MADT_GICC_SIZE_v5  76
+
 /* Masks for Flags field above */
 
 /* ACPI_MADT_ENABLED(1)  Processor is usable if set */
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 05/16] libxl/arm: Construct ACPI RSDP table

2016-09-28 Thread Shannon Zhao
Construct ACPI RSDP table and add a helper to calculate the ACPI table
checksum.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index bc9ab84..0512630 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,6 +34,10 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+#define ACPI_OEM_ID "Xen"
+#define ACPI_OEM_TABLE_ID "ARM"
+#define ACPI_ASL_COMPILER_ID "XL"
+
 enum {
 RSDP,
 XSDT,
@@ -126,6 +130,37 @@ out:
 return rc;
 }
 
+static void calculate_checksum(void *table, uint32_t checksum_offset,
+   uint32_t length)
+{
+uint8_t *p, sum = 0;
+
+p = table;
+p[checksum_offset] = 0;
+
+while (length--)
+sum = sum + *p++;
+
+p = table;
+p[checksum_offset] = -sum;
+}
+
+static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[RSDP].addr - GUEST_ACPI_BASE;
+struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset;
+
+memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
+memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
+rsdp->length = acpitables[RSDP].size;
+rsdp->revision = 0x02;
+rsdp->xsdt_physical_address = acpitables[XSDT].addr;
+calculate_checksum(rsdp,
+   offsetof(struct acpi_table_rsdp, extended_checksum),
+   acpitables[RSDP].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -147,6 +182,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
 rc = libxl__allocate_acpi_tables(gc, info, dom, acpitables);
+if (rc)
+goto out;
+
+make_acpi_rsdp(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v8 03/16] libxl/arm: Generate static ACPI DSDT table

2016-09-28 Thread Shannon Zhao
It uses static DSDT table like the way x86 uses. Currently the DSDT
table only contains processor device objects and it generates the
maximal objects which so far is 128.

While the GUEST_MAX_VCPUS is defined under __XEN__ or __XEN_TOOLS__, it
needs to add -D__XEN_TOOLS__ to compile mk_dsdt.c.

Also only check iasl for aarch64 in configure since ACPI on ARM32 is not
supported.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/configure.ac|  2 +-
 tools/libacpi/Makefile|  8 +++-
 tools/libacpi/mk_dsdt.c   | 27 ++-
 tools/libxl/Makefile  |  5 -
 tools/libxl/libxl_arm_acpi.c  |  5 +
 xen/arch/arm/domain.c |  1 +
 xen/include/public/arch-arm.h |  3 +++
 7 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/tools/configure.ac b/tools/configure.ac
index 5724ace..794c615 100644
--- a/tools/configure.ac
+++ b/tools/configure.ac
@@ -340,7 +340,7 @@ dnl "host" here means the platform on which the hypervisor 
and tools is
 dnl going to run, not the platform on which we are building (known as
 dnl "build" in gnu speak).
 case "$host_cpu" in
-i[[3456]]86|x86_64)
+i[[3456]]86|x86_64|aarch64)
 AX_PATH_PROG_OR_FAIL([IASL], [iasl])
 ;;
 esac
diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
index 65a540e..2502d53 100644
--- a/tools/libacpi/Makefile
+++ b/tools/libacpi/Makefile
@@ -19,6 +19,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
 
 C_SRC-$(GPL) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c
 C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_pvh.c $(C_SRC-y))
+C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
 H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h 
ssdt_tpm.h)
 
 # Suffix for temporary files.
@@ -38,7 +39,7 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl iasl
rm -f $(addprefix $(ACPI_BUILD_DIR)/, $*.aml $*.hex)
  
 $(MK_DSDT): mk_dsdt.c
-   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -o $@ mk_dsdt.c
+   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ 
mk_dsdt.c
 
 ifeq ($(GPL),y)
 $(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl 
gpl/mk_dsdt_gpl.sh $(MK_DSDT)
@@ -65,6 +66,11 @@ $(ACPI_BUILD_DIR)/dsdt_pvh.asl: dsdt_acpi_info.asl $(MK_DSDT)
cat dsdt_acpi_info.asl >> $@
$(MK_DSDT) --debug=$(debug) --maxcpu any --dm-version none >> $@
 
+$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT)
+   printf "DefinitionBlock (\"DSDT.aml\", \"DSDT\", 3, \"Xen\", \"ARM\", 
1)\n{" > $@.$(TMP_SUFFIX)
+   $(MK_DSDT) --debug=$(debug) >> $@.$(TMP_SUFFIX)
+   mv -f $@.$(TMP_SUFFIX) $@
+
 $(C_SRC): $(ACPI_BUILD_DIR)/%.c: iasl $(ACPI_BUILD_DIR)/%.asl
iasl -vs -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc 
$(ACPI_BUILD_DIR)/$*.asl
sed -e 's/AmlCode/$*/g' $(ACPI_BUILD_DIR)/$*.hex > $@.$(TMP_SUFFIX)
diff --git a/tools/libacpi/mk_dsdt.c b/tools/libacpi/mk_dsdt.c
index 8130cbd..4ae68bc 100644
--- a/tools/libacpi/mk_dsdt.c
+++ b/tools/libacpi/mk_dsdt.c
@@ -17,7 +17,11 @@
 #include 
 #include 
 #include 
+#if defined(__i386__) || defined(__x86_64__)
 #include 
+#elif defined(__aarch64__)
+#include 
+#endif
 
 static unsigned int indent_level;
 static bool debug = false;
@@ -104,9 +108,15 @@ static struct option options[] = {
 
 int main(int argc, char **argv)
 {
-unsigned int slot, cpu, max_cpus = HVM_MAX_VCPUS;
+unsigned int slot, cpu, max_cpus;
 dm_version dm_version = QEMU_XEN_TRADITIONAL;
 
+#if defined(__i386__) || defined(__x86_64__)
+max_cpus = HVM_MAX_VCPUS;
+#elif defined(__aarch64__)
+max_cpus = GUEST_MAX_VCPUS;
+#endif
+
 for ( ; ; )
 {
 int opt = getopt_long(argc, argv, "", options, NULL);
@@ -159,6 +169,7 @@ int main(int argc, char **argv)
 / Processor start /
 push_block("Scope", "\\_SB");
 
+#if defined(__i386__) || defined(__x86_64__)
 /* MADT checksum */
 stmt("OperationRegion", "MSUM, SystemMemory, \\_SB.MSUA, 1");
 push_block("Field", "MSUM, ByteAcc, NoLock, Preserve");
@@ -172,6 +183,7 @@ int main(int argc, char **argv)
 pop_block();
 stmt("Return", "Buffer() {0, 8, 0xff, 0xff, 0, 0, 0, 0}");
 pop_block();
+#endif
 
 /* Define processor objects and control methods. */
 for ( cpu = 0; cpu < max_cpus; cpu++)
@@ -180,6 +192,11 @@ int main(int argc, char **argv)
 
 stmt("Name", "_HID, \"ACPI0007\"");
 
+stmt("Name", "_UID, %d", cpu);
+#if defined(__aarch64__)
+pop_block();
+continue;
+#endif
 /* Name this processor's MADT LAPIC descriptor. */
 stmt("OperationRegion", 
  "MATR, SystemMe

[Xen-devel] [PATCH v8 07/16] libxl/arm: Construct ACPI GTDT table

2016-09-28 Thread Shannon Zhao
Construct GTDT table with the interrupt information of timers.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
Acked-by: Wei Liu <wei.l...@citrix.com>
---
 tools/libxl/libxl_arm_acpi.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index ab68bf8..b2136fd 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -25,10 +25,24 @@ typedef uint8_t u8;
 typedef uint16_t u16;
 typedef uint32_t u32;
 typedef uint64_t u64;
+typedef int64_t s64;
 
 #include 
 #include 
 
+#ifndef BITS_PER_LONG
+#ifdef _LP64
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+#endif
+#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
+#define COMPILER_DEPENDENT_INT64 int64_t
+#define COMPILER_DEPENDENT_UINT64 uint64_t
+
+#include 
+
 _hidden
 extern const unsigned char dsdt_anycpu_arm[];
 _hidden
@@ -190,6 +204,29 @@ static void make_acpi_xsdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[XSDT].size);
 }
 
+static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
+
+gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
+gtdt->non_secure_el1_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
+gtdt->virtual_timer_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+
+gtdt->counter_block_addresss = ~((uint64_t)0);
+gtdt->counter_read_block_address = ~((uint64_t)0);
+
+make_acpi_header(>header, "GTDT", acpitables[GTDT].size, 2);
+calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[GTDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 struct xc_dom_image *dom)
 {
@@ -216,6 +253,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
+make_acpi_gtdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-28 Thread Shannon Zhao



On 2016/9/28 3:00, Wei Liu wrote:

On Tue, Sep 27, 2016 at 11:43:38AM -0700, Shannon Zhao wrote:



On 2016/9/27 9:35, Wei Liu wrote:

On Tue, Sep 27, 2016 at 09:01:00AM -0700, Shannon Zhao wrote:



On 2016/9/27 2:41, Wei Liu wrote:

On Mon, Sep 26, 2016 at 02:54:55PM -0700, Shannon Zhao wrote:



On 2016/9/22 7:10, Wei Liu wrote:

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c

index 2924629..118beab 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -408,8 +408,15 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
   }
   }

+
+rc = libxl__arch_memory_constant(gc, info, state);
+if (rc < 0) {
+LOGE(ERROR, "Couldn't get arch constant memory size");
+return ERROR_FAIL;
+}
+
   if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
-LIBXL_MAXMEM_CONSTANT) < 0) {
+LIBXL_MAXMEM_CONSTANT + rc) < 0) {

I think this LIBXL_MAXMEM_CONSTANT should be pushed to your helper
function, too.

So that, we can have all LIBXL_MAXMEM_CONSTANT removed in libxl
functions (see libxl.c and libxl_dom.c)


If we push LIBXL_MAXMEM_CONSTANT to the libxl_arch_memory_constant and
remove it from libxl.c, do we need to call libxl_arch_memory_constant there
in libxl_set_memory_target()?



Yes, we need to call that function everywhere to get consistent results.
That's the reason I asked you to consolidate it to a function.


Well it's a little awkward I think, since in libxl_domain_setmaxmem() and
libxl_set_memory_target() it seems it can't get the parameters info and
state for libxl__arch_memory_constant().
I'm not sure how to solve it. Wei, any suggestion?



Hmm...

The first question is can state be derived from build_info ? From my
quick skim of the code the answer is likely yes.


I'm not familiar with the relationship between these structures and not sure
how to do this. Please give me some suggestion.



Oh, I was just reading the code in your patch series and existing code
in libxl_arm.c.  Here is my analysis of the code, please point out any
inaccuracy.

In your patch that estimates the size of ACPI table(s), xc_config is
needed. In particular, you need to know the gic version -- in fact
that's the only thing you need to know as far as I can tell.

In libxl_arm.c, the gic version is finally saved to  d_config, which
means you should be able to later extract that from d_config.

But, as I understand it, you can't use  d_config only while *building*
the domain, because the gic version might be determined only after the
domain is constructed (_NATIVE case). If you want to do so, you need to
move some code around, which might or might not be feasible -- I haven't
checked.

So based on my analysis, it would make sense to have such function:

   libxl__arch_extra_memory(gc, d_config)

This is the function that is used in libxl_set_memory_target and
friends.

Obviously x86 would only need to return a constant in that function.

Then, in arm implementation:

   libxl__get_acpi_size(gc, info, gic_version /* not build_state anymore */)

   /* also fix up libxl__estimate_madt_size */


   /* this is the function called when constructing the domain etc, only
* in libxl_arm.c */
   static acpi_extra_memory(gc, build_info, gic_version)
   {
libxl__get_acpi_size...
   }

   libxl__arch_extra_memory(gc, d_config)
   {
gic_version = d_config->..gic_version;

If user doesn't specify gic_version in xl config, the 
d_config->b_info.arch_arm.gic_version will be LIBXL_GIC_VERSION_DEFAULT, 
so we can't know the exact gic_version which will be constructed later.


Since the gic_version is now only used to determine if it should include 
acpi_madt_generic_redistributor size, can we add a function 
libxl__get_acpi_max_size which doesn't care about the gic_version and 
just returns the max acpi size. And this max size is just for setting 
the target maxmem and not for allocating the acpi tables.


What do you think about this?

Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-27 Thread Shannon Zhao



On 2016/9/27 9:35, Wei Liu wrote:

On Tue, Sep 27, 2016 at 09:01:00AM -0700, Shannon Zhao wrote:



On 2016/9/27 2:41, Wei Liu wrote:

On Mon, Sep 26, 2016 at 02:54:55PM -0700, Shannon Zhao wrote:



On 2016/9/22 7:10, Wei Liu wrote:

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c

index 2924629..118beab 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -408,8 +408,15 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
}
}

+
+rc = libxl__arch_memory_constant(gc, info, state);
+if (rc < 0) {
+LOGE(ERROR, "Couldn't get arch constant memory size");
+return ERROR_FAIL;
+}
+
if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
-LIBXL_MAXMEM_CONSTANT) < 0) {
+LIBXL_MAXMEM_CONSTANT + rc) < 0) {

I think this LIBXL_MAXMEM_CONSTANT should be pushed to your helper
function, too.

So that, we can have all LIBXL_MAXMEM_CONSTANT removed in libxl
functions (see libxl.c and libxl_dom.c)


If we push LIBXL_MAXMEM_CONSTANT to the libxl_arch_memory_constant and
remove it from libxl.c, do we need to call libxl_arch_memory_constant there
in libxl_set_memory_target()?



Yes, we need to call that function everywhere to get consistent results.
That's the reason I asked you to consolidate it to a function.


Well it's a little awkward I think, since in libxl_domain_setmaxmem() and
libxl_set_memory_target() it seems it can't get the parameters info and
state for libxl__arch_memory_constant().
I'm not sure how to solve it. Wei, any suggestion?



Hmm...

The first question is can state be derived from build_info ? From my
quick skim of the code the answer is likely yes.

I'm not familiar with the relationship between these structures and not 
sure how to do this. Please give me some suggestion.



Then, you can call libxl_retrieve_domain_configuration to get
domain_config, then domain_config->build_info, so that you can derive
state from it.

Feel free to ask more questions.

Without such arrangement, ballooning is going to be broken for ARM
guests.


I see.

Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-27 Thread Shannon Zhao



On 2016/9/27 2:41, Wei Liu wrote:

On Mon, Sep 26, 2016 at 02:54:55PM -0700, Shannon Zhao wrote:



On 2016/9/22 7:10, Wei Liu wrote:

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c

index 2924629..118beab 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -408,8 +408,15 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
 }
 }

+
+rc = libxl__arch_memory_constant(gc, info, state);
+if (rc < 0) {
+LOGE(ERROR, "Couldn't get arch constant memory size");
+return ERROR_FAIL;
+}
+
 if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
-LIBXL_MAXMEM_CONSTANT) < 0) {
+LIBXL_MAXMEM_CONSTANT + rc) < 0) {

I think this LIBXL_MAXMEM_CONSTANT should be pushed to your helper
function, too.

So that, we can have all LIBXL_MAXMEM_CONSTANT removed in libxl
functions (see libxl.c and libxl_dom.c)


If we push LIBXL_MAXMEM_CONSTANT to the libxl_arch_memory_constant and
remove it from libxl.c, do we need to call libxl_arch_memory_constant there
in libxl_set_memory_target()?



Yes, we need to call that function everywhere to get consistent results.
That's the reason I asked you to consolidate it to a function.

Well it's a little awkward I think, since in libxl_domain_setmaxmem() 
and libxl_set_memory_target() it seems it can't get the parameters info 
and state for libxl__arch_memory_constant().

I'm not sure how to solve it. Wei, any suggestion?

Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v7 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-09-27 Thread Shannon Zhao
Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
them in evtchn_fixup().

Also use HVM_PARAM_CALLBACK_IRQ_TYPE_MASK in hvm_set_callback_via().

Cc: Jan Beulich <jbeul...@suse.com>
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 xen/arch/arm/domain_build.c | 9 ++---
 xen/arch/x86/hvm/irq.c  | 2 +-
 xen/include/public/hvm/params.h | 3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 35ab08d..0cf7dc3 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2016,9 +2016,12 @@ static void evtchn_fixup(struct domain *d, struct 
kernel_info *kinfo)
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;
+val = MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI,
+HVM_PARAM_CALLBACK_IRQ_TYPE_MASK);
+/* Active-low level-sensitive  */
+val |= MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL,
+ HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK);
+val |= d->arch.evtchn_irq;
 d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
 
 /*
diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c
index 5323d7c..e597114 100644
--- a/xen/arch/x86/hvm/irq.c
+++ b/xen/arch/x86/hvm/irq.c
@@ -325,7 +325,7 @@ void hvm_set_callback_via(struct domain *d, uint64_t via)
 unsigned int gsi=0, pdev=0, pintx=0;
 uint8_t via_type;
 
-via_type = (uint8_t)(via >> 56) + 1;
+via_type = (uint8_t)MASK_EXTR(via, HVM_PARAM_CALLBACK_IRQ_TYPE_MASK) + 1;
 if ( ((via_type == HVMIRQ_callback_gsi) && (via == 0)) ||
  (via_type > HVMIRQ_callback_vector) )
 via_type = HVMIRQ_callback_none;
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index f7338a3..8b126e2 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -30,6 +30,7 @@
  */
 
 #define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_MASK 0xFF00ULL
 /*
  * How should CPU0 event-channel notifications be delivered?
  *
@@ -66,6 +67,8 @@
  * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to
  * the notification is handled by the interrupt controller.
  */
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK  0xFF00
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
 #endif
 
 /*
-- 
2.10.0.windows.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v7 04/16] libxl/arm: Estimate the size of ACPI tables

2016-09-27 Thread Shannon Zhao
Estimate the size of ACPI tables and reserve a memory map space for ACPI
tables.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 100 +++
 xen/include/acpi/actbl1.h|   2 +
 2 files changed, 102 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 0851411..33a25ff 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,12 +34,110 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+enum {
+RSDP,
+XSDT,
+GTDT,
+MADT,
+FADT,
+DSDT,
+MAX_TABLE_NUMS,
+};
+
+struct acpitable {
+uint64_t addr;
+size_t size;
+};
+
+static int libxl__estimate_madt_size(libxl__gc *gc,
+ const libxl_domain_build_info *info,
+ const xc_domain_configuration_t 
*xc_config,
+ size_t *size)
+{
+int rc = 0;
+
+switch (xc_config->gic_version) {
+case XEN_DOMCTL_CONFIG_GIC_V2:
+*size = sizeof(struct acpi_table_madt) +
+ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+sizeof(struct acpi_madt_generic_distributor);
+break;
+case XEN_DOMCTL_CONFIG_GIC_V3:
+*size = sizeof(struct acpi_table_madt) +
+ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+sizeof(struct acpi_madt_generic_distributor) +
+sizeof(struct acpi_madt_generic_redistributor);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+break;
+}
+
+return rc;
+}
+
+static int libxl__estimate_acpi_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ struct xc_dom_image *dom,
+ xc_domain_configuration_t *xc_config,
+ struct acpitable acpitables[])
+{
+int rc;
+size_t size;
+
+acpitables[RSDP].addr = GUEST_ACPI_BASE;
+acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+/*
+ * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+ * entries for them.
+ */
+acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+sizeof(uint64_t) * 2;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+rc = libxl__estimate_madt_size(gc, info, xc_config, );
+if (rc < 0)
+goto out;
+
+acpitables[MADT].size = size;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[DSDT].size = dsdt_anycpu_arm_len;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+rc = 0;
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
 {
 const libxl_version_info *vers;
 int rc = 0;
+struct acpitable acpitables[MAX_TABLE_NUMS];
+
+/* convenience aliases */
+xc_domain_configuration_t *xc_config = >config;
 
 vers = libxl_get_version_info(CTX);
 if (vers == NULL) {
@@ -54,6 +152,8 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].length = 0;
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
+rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+
 out:
 return rc;
 }
diff --git a/xen/include/acpi/actbl1.h b/xen/include/acpi/actbl1.h
index ed5cd2d..e199136 100644
--- a/xen/include/acpi/actbl1.h
+++ b/xen/include/acpi/actbl1.h
@@ -786,6 +786,8 @@ struct acpi_madt_generic_interrupt {
u8 reserved2[3];
 };
 
+#define ACPI_MADT_GICC_SIZE_v5  76
+
 /* Masks for Flags field above */
 
 /* ACPI_MADT_ENABLED(1)  Processor is usable if set */
-- 
2.10.0.windows.1

Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-26 Thread Shannon Zhao



On 2016/9/22 7:10, Wei Liu wrote:

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
> index 2924629..118beab 100644
> --- a/tools/libxl/libxl_dom.c
> +++ b/tools/libxl/libxl_dom.c
> @@ -408,8 +408,15 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
>  }
>  }
>
> +
> +rc = libxl__arch_memory_constant(gc, info, state);
> +if (rc < 0) {
> +LOGE(ERROR, "Couldn't get arch constant memory size");
> +return ERROR_FAIL;
> +}
> +
>  if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
> -LIBXL_MAXMEM_CONSTANT) < 0) {
> +LIBXL_MAXMEM_CONSTANT + rc) < 0) {

I think this LIBXL_MAXMEM_CONSTANT should be pushed to your helper
function, too.

So that, we can have all LIBXL_MAXMEM_CONSTANT removed in libxl
functions (see libxl.c and libxl_dom.c)

If we push LIBXL_MAXMEM_CONSTANT to the libxl_arch_memory_constant and 
remove it from libxl.c, do we need to call libxl_arch_memory_constant 
there in libxl_set_memory_target()?


Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-09-26 Thread Shannon Zhao



On 2016/9/22 8:00, Jan Beulich wrote:

On 22.09.16 at 14:52, <zhaoshengl...@huawei.com> wrote:

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

Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
them in evtchn_fixup().

Also use HVM_PARAM_CALLBACK_IRQ_TYPE_MASK in hvm_set_callback_via().

Cc: Jan Beulich <jbeul...@suse.com>
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 xen/arch/arm/domain_build.c | 9 ++---
 xen/arch/x86/hvm/irq.c  | 2 +-
 xen/include/public/hvm/params.h | 3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 35ab08d..0cf7dc3 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2016,9 +2016,12 @@ static void evtchn_fixup(struct domain *d, struct
kernel_info *kinfo)
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;
+val = MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI,
+HVM_PARAM_CALLBACK_IRQ_TYPE_MASK);
+/* Active-low level-sensitive  */
+val |= MASK_INSR(HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL,
+ HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK);
+val |= d->arch.evtchn_irq;
 d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;

 /*
diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c
index 5323d7c..e597114 100644
--- a/xen/arch/x86/hvm/irq.c
+++ b/xen/arch/x86/hvm/irq.c
@@ -325,7 +325,7 @@ void hvm_set_callback_via(struct domain *d, uint64_t via)
 unsigned int gsi=0, pdev=0, pintx=0;
 uint8_t via_type;

-via_type = (uint8_t)(via >> 56) + 1;
+via_type = (uint8_t)MASK_EXTR(via, HVM_PARAM_CALLBACK_IRQ_TYPE_MASK) +
1;
 if ( ((via_type == HVMIRQ_callback_gsi) && (via == 0)) ||
  (via_type > HVMIRQ_callback_vector) )
 via_type = HVMIRQ_callback_none;
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index f7338a3..5c50e2e 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -30,6 +30,7 @@
  */

 #define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_MASK 0xFF00


I'd be surprised if this goes through on all compiler versions: This
is a constant which needs at least a UL suffix (and if intended to
be usable on 32-bit even a ULL one, which would then get us into
complications with there not being supposed to be any non-C89
constructs in the public headers).


Hi Jan,

Do I need to resend this patch or add new one to fix this on top of this 
one?


Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-26 Thread Shannon Zhao



On 2016/9/26 2:05, Wei Liu wrote:

On Mon, Sep 26, 2016 at 03:08:43PM +0800, Shannon Zhao wrote:

>
>
> On 2016/9/22 22:32, Wei Liu wrote:

> >FAOD:
> >
> >I think all the issues I found so far in this patch and other patch(es)
> >are mostly cosmetic. I would be happy to accept incremental patches on
> >top of this series to make those changes.
> >

> Ok, thanks for your review.
>

> >No need to resend just yet unless there is something substantial that
> >you need to change.

> So far do I need to resend this series for comments?

No, you don't have to resend this series at the moment. Please address
Jan's comment on patch 14 first.

Ok, I see. Do I need to resend the patch or add new one on top of that?

Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-26 Thread Shannon Zhao



On 2016/9/22 22:32, Wei Liu wrote:

FAOD:

I think all the issues I found so far in this patch and other patch(es)
are mostly cosmetic. I would be happy to accept incremental patches on
top of this series to make those changes.


Ok, thanks for your review.


No need to resend just yet unless there is something substantial that
you need to change.

So far do I need to resend this series for comments?

Thanks,
--
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 00/16] Xen ARM DomU ACPI support

2016-09-22 Thread Shannon Zhao


On 2016/9/22 21:37, Julien Grall wrote:
> 
> 
> On 22/09/16 14:32, Shannon Zhao wrote:
>>
>>
>> On 2016/9/22 21:27, Julien Grall wrote:
>>> Hi Shannon,
>>>
>>> I am not sure why, but your name on this patch series become: z00226004.
>>> You may want to give a look to your mail sender.
>>>
>> Oops, I just modified the user.name before and forgot to change back. I
>> will resend soon.
> 
> No need to resend just for that. The "From:" field is correct so we
> could apply your series if everything is ok. :)
> 
Ok, I just realized this. Thanks :)

-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v6 00/16] Xen ARM DomU ACPI support

2016-09-22 Thread Shannon Zhao


On 2016/9/22 21:27, Julien Grall wrote:
> Hi Shannon,
> 
> I am not sure why, but your name on this patch series become: z00226004.
> You may want to give a look to your mail sender.
> 
Oops, I just modified the user.name before and forgot to change back. I
will resend soon.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-14 Thread Shannon Zhao


On 2016/9/14 15:40, Julien Grall wrote:
> 
> On 14/09/2016 08:32, Shannon Zhao wrote:
>> > 
>> > 
>> > On 2016/9/14 15:14, Julien Grall wrote:
>>> >> Hello,
>>> >>
>>> >> On 14/09/2016 02:06, Stefano Stabellini wrote:
>>>> >>> On Wed, 14 Sep 2016, Shannon Zhao wrote:
>>>>> >>>> On 2016/9/13 23:17, Julien Grall wrote:
>>>>>> >>>>>
>>>>>> >>>>>
>>>>>> >>>>> On 13/09/16 14:06, Shannon Zhao wrote:
>>>>>>> >>>>>> Hi Julien,
>>>>>> >>>>>
>>>>>> >>>>> Hello Shannon,
>>>>>> >>>>>
>>>>>>> >>>>>> On 2016/9/13 19:56, Julien Grall wrote:
>>>>>>>> >>>>>>> Hi Shannon,
>>>>>>>> >>>>>>>
>>>>>>>> >>>>>>> On 02/09/16 03:55, Shannon Zhao wrote:
>>>>>>>>> >>>>>>>> From: Shannon Zhao <shannon.z...@linaro.org>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> The design of this feature is described as below.
>>>>>>>>> >>>>>>>> Firstly, the toolstack (libxl) generates the ACPI tables
>>>>>>>>> >>>>>>>> according the
>>>>>>>>> >>>>>>>> number of vcpus and gic controller.
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> Then, it copies these ACPI tables to DomU non-RAM memory map
>>>>>>>>> >>>>>>>> space and
>>>>>>>>> >>>>>>>> passes them to UEFI firmware through the "ARM multiboot" 
>>>>>>>>> >>>>>>>> protocol.
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> At last, UEFI gets the ACPI tables through the "ARM 
>>>>>>>>> >>>>>>>> multiboot"
>>>>>>>>> >>>>>>>> protocol
>>>>>>>>> >>>>>>>> and installs these tables like the usual way and passes both 
>>>>>>>>> >>>>>>>> ACPI
>>>>>>>>> >>>>>>>> and DT
>>>>>>>>> >>>>>>>> information to the Xen DomU.
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, 
>>>>>>>>> >>>>>>>> DSDT
>>>>>>>>> >>>>>>>> tables
>>>>>>>>> >>>>>>>> since it's enough now.
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> This has been tested using guest kernel with the Dom0 ACPI 
>>>>>>>>> >>>>>>>> support
>>>>>>>>> >>>>>>>> patches which could be fetched from linux master or:
>>>>>>>>> >>>>>>>> https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>> The UEFI binary could be fetched from or built from edk2 
>>>>>>>>> >>>>>>>> master
>>>>>>>>> >>>>>>>> branch:
>>>>>>>>> >>>>>>>> http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
>>>>>>>> >>>>>>>
>>>>>>>> >>>>>>> On which commit this EFI binary is based? I am trying to 
>>>>>>>> >>>>>>> rebuild

Re: [Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-14 Thread Shannon Zhao


On 2016/9/14 15:14, Julien Grall wrote:
> Hello,
> 
> On 14/09/2016 02:06, Stefano Stabellini wrote:
>> On Wed, 14 Sep 2016, Shannon Zhao wrote:
>>> On 2016/9/13 23:17, Julien Grall wrote:
>>>>
>>>>
>>>> On 13/09/16 14:06, Shannon Zhao wrote:
>>>>> Hi Julien,
>>>>
>>>> Hello Shannon,
>>>>
>>>>> On 2016/9/13 19:56, Julien Grall wrote:
>>>>>> Hi Shannon,
>>>>>>
>>>>>> On 02/09/16 03:55, Shannon Zhao wrote:
>>>>>>> From: Shannon Zhao <shannon.z...@linaro.org>
>>>>>>>
>>>>>>> The design of this feature is described as below.
>>>>>>> Firstly, the toolstack (libxl) generates the ACPI tables
>>>>>>> according the
>>>>>>> number of vcpus and gic controller.
>>>>>>>
>>>>>>> Then, it copies these ACPI tables to DomU non-RAM memory map
>>>>>>> space and
>>>>>>> passes them to UEFI firmware through the "ARM multiboot" protocol.
>>>>>>>
>>>>>>> At last, UEFI gets the ACPI tables through the "ARM multiboot"
>>>>>>> protocol
>>>>>>> and installs these tables like the usual way and passes both ACPI
>>>>>>> and DT
>>>>>>> information to the Xen DomU.
>>>>>>>
>>>>>>> Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT
>>>>>>> tables
>>>>>>> since it's enough now.
>>>>>>>
>>>>>>> This has been tested using guest kernel with the Dom0 ACPI support
>>>>>>> patches which could be fetched from linux master or:
>>>>>>> https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> The UEFI binary could be fetched from or built from edk2 master
>>>>>>> branch:
>>>>>>> http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
>>>>>>
>>>>>> On which commit this EFI binary is based? I am trying to rebuild
>>>>>> myself,
>>>>>> and go no luck to boot it so far.
>>>>>>
>>>>> I forgot the exact commit. But I just tried below commit which adds
>>>>> the
>>>>> support to edk2 and the guest can boot up successfully with ACPI.
>>>>>
>>>>> 402dde6 ArmVirtPkg/ArmVirtXen: Add ACPI support for Virt Xen ARM
>>>>
>>>> Thanks, the commit does not build on my platform. After some help for
>>>> Ard I managed to boot UEFI with the patch [1] applied.
>>>>
>>>> However Linux does not boot when passing acpi=on and abort with the
>>>> following message:
>>>>
>>>> (d86) 6RCU: Adjusting geometry for rcu_fanout_leaf=64, nr_cpu_ids=1
>>>> (d86) 6NR_IRQS:64 nr_irqs:64 0
>>>> (d86) 3No valid GICC entries exist
>>>> (d86) 0Kernel panic - not syncing: No interrupt controller found.
>>>> (d86) dCPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.0-rc6+ #420
>>>> (d86) dHardware name: XENVM-4.8 (DT)
>>>> (d86) Call trace:
>>>> (d86) [] dump_backtrace+0x0/0x1a8
>>>> (d86) [] show_stack+0x14/0x20
>>>> (d86) [] dump_stack+0x94/0xb8
>>>> (d86) [] panic+0x10c/0x250
>>>> (d86) [] init_IRQ+0x24/0x2c
>>>> (d86) [] start_kernel+0x238/0x394
>>>> (d86) [] __primary_switched+0x30/0x74
>>>> (d86) 0---[ end Kernel panic - not syncing: No interrupt controller
>>>> found.
>>>>
>>>> This is because the header.length for GICC is not valid for ACPI 5.1
>>>> (see BAD_MADT_GICC_ENTRY). So please check all the size of each table
>>>> against ACPI 5.1.
>>>>
>>> Oops. The reason is that acpi_madt_generic_interrupt in Xen is already
>>> updated to ACPI 6.0 and the length is 80 not 76 of ACPI 5.1.
>>> One solution is that we still use ACPI 5.1 and make gicc->header.length
>>> 76. Other one is that we update to ACPI 6.0 since the Xen ARM ACPI
>>> support in Linux was introduced after ACPI 6.0.
>>>
>>> Which one do you prefer?
>>
>> Certainly the versions of all tables need to be consistent. I would
>> prefer to have ACPI 6.0 but 5.1 is acceptable too (especially if
>> upgrading to 6.0 causes a large amount of changes to your patches).
> 
> I disagree on this, we should use the first version of ACPI that is
> fully supporting ARM because a guest operating system may choose to
> support the first one (there is a lot hardware platform out which only
> provides ACPI 5.1).
> 
So you prefer we should set the gicc->header.length to 76 and still use
ACPI 5.1, right?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v3 12/19] libacpi: Build DSDT for PVH guests

2016-09-13 Thread Shannon Zhao


On 2016/9/8 2:59, Boris Ostrovsky wrote:
> PVH guests require DSDT with only ACPI INFO (Xen-specific) and Processor
> objects. We separate ASL's ACPI INFO definition into dsdt_acpi_info.asl so
> that it can be included in ASLs for both HVM and PVH2.
> 
> Signed-off-by: Boris Ostrovsky 
> ---
> Changes in v3:
> * Added comment to dsdt_acpi_info.asl indicating that the structure
>   there must match struct acpi_info
> * Use QEMU_NONE in mk_dsdt.c
> * Makefile tweaks
> 
>  tools/libacpi/Makefile   | 13 ++---
>  tools/libacpi/dsdt.asl   | 20 
>  tools/libacpi/dsdt_acpi_info.asl | 26 ++
>  tools/libacpi/mk_dsdt.c  |  8 
>  4 files changed, 44 insertions(+), 23 deletions(-)
>  create mode 100644 tools/libacpi/dsdt_acpi_info.asl
> 
> diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
> index 6325cd0..12b081e 100644
> --- a/tools/libacpi/Makefile
> +++ b/tools/libacpi/Makefile
> @@ -18,7 +18,7 @@ include $(XEN_ROOT)/tools/firmware/Rules.mk
>  MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
>  
>  # Sources to be generated
> -C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c  
> dsdt_anycpu_qemu_xen.c)
> +C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c  
> dsdt_anycpu_qemu_xen.c dsdt_pvh.c)
>  H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h 
> ssdt_tpm.h)
>  
Hi Bros,

It looks like you forgot to add 'C_SRC-$(CONFIG_X86)' here. Will you add
it in your next version?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-13 Thread Shannon Zhao


On 2016/9/13 23:17, Julien Grall wrote:
> 
> 
> On 13/09/16 14:06, Shannon Zhao wrote:
>> Hi Julien,
> 
> Hello Shannon,
> 
>> On 2016/9/13 19:56, Julien Grall wrote:
>>> Hi Shannon,
>>>
>>> On 02/09/16 03:55, Shannon Zhao wrote:
>>>> From: Shannon Zhao <shannon.z...@linaro.org>
>>>>
>>>> The design of this feature is described as below.
>>>> Firstly, the toolstack (libxl) generates the ACPI tables according the
>>>> number of vcpus and gic controller.
>>>>
>>>> Then, it copies these ACPI tables to DomU non-RAM memory map space and
>>>> passes them to UEFI firmware through the "ARM multiboot" protocol.
>>>>
>>>> At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
>>>> and installs these tables like the usual way and passes both ACPI
>>>> and DT
>>>> information to the Xen DomU.
>>>>
>>>> Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT
>>>> tables
>>>> since it's enough now.
>>>>
>>>> This has been tested using guest kernel with the Dom0 ACPI support
>>>> patches which could be fetched from linux master or:
>>>> https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>>>>
>>>>
>>>>
>>>> The UEFI binary could be fetched from or built from edk2 master branch:
>>>> http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
>>>
>>> On which commit this EFI binary is based? I am trying to rebuild myself,
>>> and go no luck to boot it so far.
>>>
>> I forgot the exact commit. But I just tried below commit which adds the
>> support to edk2 and the guest can boot up successfully with ACPI.
>>
>> 402dde6 ArmVirtPkg/ArmVirtXen: Add ACPI support for Virt Xen ARM
> 
> Thanks, the commit does not build on my platform. After some help for
> Ard I managed to boot UEFI with the patch [1] applied.
> 
> However Linux does not boot when passing acpi=on and abort with the
> following message:
> 
> (d86) 6RCU: Adjusting geometry for rcu_fanout_leaf=64, nr_cpu_ids=1
> (d86) 6NR_IRQS:64 nr_irqs:64 0
> (d86) 3No valid GICC entries exist
> (d86) 0Kernel panic - not syncing: No interrupt controller found.
> (d86) dCPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.0-rc6+ #420
> (d86) dHardware name: XENVM-4.8 (DT)
> (d86) Call trace:
> (d86) [] dump_backtrace+0x0/0x1a8
> (d86) [] show_stack+0x14/0x20
> (d86) [] dump_stack+0x94/0xb8
> (d86) [] panic+0x10c/0x250
> (d86) [] init_IRQ+0x24/0x2c
> (d86) [] start_kernel+0x238/0x394
> (d86) [] __primary_switched+0x30/0x74
> (d86) 0---[ end Kernel panic - not syncing: No interrupt controller found.
> 
> This is because the header.length for GICC is not valid for ACPI 5.1
> (see BAD_MADT_GICC_ENTRY). So please check all the size of each table
> against ACPI 5.1.
> 
Oops. The reason is that acpi_madt_generic_interrupt in Xen is already
updated to ACPI 6.0 and the length is 80 not 76 of ACPI 5.1.
One solution is that we still use ACPI 5.1 and make gicc->header.length
76. Other one is that we update to ACPI 6.0 since the Xen ARM ACPI
support in Linux was introduced after ACPI 6.0.

Which one do you prefer?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-13 Thread Shannon Zhao
Hi Julien,

On 2016/9/13 19:56, Julien Grall wrote:
> Hi Shannon,
> 
> On 02/09/16 03:55, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> The design of this feature is described as below.
>> Firstly, the toolstack (libxl) generates the ACPI tables according the
>> number of vcpus and gic controller.
>>
>> Then, it copies these ACPI tables to DomU non-RAM memory map space and
>> passes them to UEFI firmware through the "ARM multiboot" protocol.
>>
>> At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
>> and installs these tables like the usual way and passes both ACPI and DT
>> information to the Xen DomU.
>>
>> Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
>> since it's enough now.
>>
>> This has been tested using guest kernel with the Dom0 ACPI support
>> patches which could be fetched from linux master or:
>> https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>>
>>
>> The UEFI binary could be fetched from or built from edk2 master branch:
>> http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
> 
> On which commit this EFI binary is based? I am trying to rebuild myself,
> and go no luck to boot it so far.
> 
I forgot the exact commit. But I just tried below commit which adds the
support to edk2 and the guest can boot up successfully with ACPI.

402dde6 ArmVirtPkg/ArmVirtXen: Add ACPI support for Virt Xen ARM

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-13 Thread Shannon Zhao


On 2016/9/12 23:22, Julien Grall wrote:
> Hi Shannon,
> 
> On 02/09/16 03:55, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> The design of this feature is described as below.
>> Firstly, the toolstack (libxl) generates the ACPI tables according the
>> number of vcpus and gic controller.
>>
>> Then, it copies these ACPI tables to DomU non-RAM memory map space and
>> passes them to UEFI firmware through the "ARM multiboot" protocol.
>>
>> At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
>> and installs these tables like the usual way and passes both ACPI and DT
>> information to the Xen DomU.
>>
>> Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
>> since it's enough now.
>>
>> This has been tested using guest kernel with the Dom0 ACPI support
>> patches which could be fetched from linux master or:
>> https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>>
>>
>> The UEFI binary could be fetched from or built from edk2 master branch:
>> http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
>>
>> This series can be fetched from:
>> https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v5
> 
> This branch is based on a fairly out of date xen. Do you have a branch
> rebased on the latest upstream + Boris ACPI v3?
> 
You can fetch the updated branch from:
https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v5_new

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-09-02 Thread Shannon Zhao


On 2016/9/2 14:18, Jan Beulich wrote:
 On 02.09.16 at 04:55,  wrote:
>> --- a/xen/include/public/hvm/params.h
>> +++ b/xen/include/public/hvm/params.h
>> @@ -30,6 +30,7 @@
>>   */
>>  
>>  #define HVM_PARAM_CALLBACK_IRQ 0
>> +#define HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT 56
> 
> This covering the top 8 bits, just the shift value might indeed be
> enough.
> 
>> @@ -66,6 +67,8 @@
>>   * This is only used by ARM/ARM64 and masking/eoi the interrupt associated 
>> to
>>   * the notification is handled by the interrupt controller.
>>   */
>> +#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT 8
>> +#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
> 
> Here, however, I don't see how the shift value alone can be of
> use when wanting to extract the relevant bits. I think this (and
> for consistency also the other) value should be specified as a
> mask, with users expected to have mechanisms like our
> MASK_EXTR() / MASK_INSR() available.
> 
Ok, will add the mask. Thanks.

-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
them in evtchn_fixup().

Also use HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT in hvm_set_callback_via().

Cc: Jan Beulich <jbeul...@suse.com>
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 xen/arch/arm/domain_build.c | 8 +---
 xen/arch/x86/hvm/irq.c  | 2 +-
 xen/include/public/hvm/params.h | 3 +++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 60db9e4..494115b 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2019,9 +2019,11 @@ static void evtchn_fixup(struct domain *d, struct 
kernel_info *kinfo)
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;
+val = (u64)HVM_PARAM_CALLBACK_TYPE_PPI << 
HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT;
+/* Active-low level-sensitive  */
+val |= (HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL <<
+HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT);
+val |= d->arch.evtchn_irq;
 d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
 
 /*
diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c
index 5323d7c..7c5836b 100644
--- a/xen/arch/x86/hvm/irq.c
+++ b/xen/arch/x86/hvm/irq.c
@@ -325,7 +325,7 @@ void hvm_set_callback_via(struct domain *d, uint64_t via)
 unsigned int gsi=0, pdev=0, pintx=0;
 uint8_t via_type;
 
-via_type = (uint8_t)(via >> 56) + 1;
+via_type = (uint8_t)(via >> HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT) + 1;
 if ( ((via_type == HVMIRQ_callback_gsi) && (via == 0)) ||
  (via_type > HVMIRQ_callback_vector) )
 via_type = HVMIRQ_callback_none;
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index f7338a3..a161de1 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -30,6 +30,7 @@
  */
 
 #define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT 56
 /*
  * How should CPU0 event-channel notifications be delivered?
  *
@@ -66,6 +67,8 @@
  * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to
  * the notification is handled by the interrupt controller.
  */
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT 8
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
 #endif
 
 /*
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 07/16] libxl/arm: Construct ACPI GTDT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Construct GTDT table with the interrupt information of timers.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 93ba2d1..ab49d57 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -25,10 +25,24 @@ typedef uint8_t u8;
 typedef uint16_t u16;
 typedef uint32_t u32;
 typedef uint64_t u64;
+typedef int64_t s64;
 
 #include 
 #include 
 
+#ifndef BITS_PER_LONG
+#ifdef _LP64
+#define BITS_PER_LONG 64
+#else
+#define BITS_PER_LONG 32
+#endif
+#endif
+#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
+#define COMPILER_DEPENDENT_INT64 int64_t
+#define COMPILER_DEPENDENT_UINT64 uint64_t
+
+#include 
+
 _hidden
 extern const unsigned char dsdt_anycpu_arm[];
 _hidden
@@ -190,6 +204,29 @@ static void make_acpi_xsdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[XSDT].size);
 }
 
+static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
+
+gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
+gtdt->non_secure_el1_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
+gtdt->virtual_timer_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+
+gtdt->counter_block_addresss = 0x;
+gtdt->counter_read_block_address = 0x;
+
+make_acpi_header(>header, "GTDT", acpitables[GTDT].size, 2);
+calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[GTDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -220,6 +257,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
+make_acpi_gtdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 06/16] libxl/arm: Construct ACPI XSDT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 83ad954..93ba2d1 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -161,6 +161,35 @@ static void make_acpi_rsdp(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[RSDP].size);
 }
 
+static void make_acpi_header(struct acpi_table_header *h, const char *sig,
+ size_t len, uint8_t rev)
+{
+memcpy(h->signature, sig, 4);
+h->length = len;
+h->revision = rev;
+memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
+memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id));
+h->oem_revision = 0;
+memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
+   sizeof(h->asl_compiler_id));
+h->asl_compiler_revision = 0;
+h->checksum = 0;
+}
+
+static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[XSDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_xsdt *xsdt = (void *)dom->acpi_modules[0].data + offset;
+
+xsdt->table_offset_entry[0] = acpitables[MADT].addr;
+xsdt->table_offset_entry[1] = acpitables[GTDT].addr;
+xsdt->table_offset_entry[2] = acpitables[FADT].addr;
+make_acpi_header(>header, "XSDT", acpitables[XSDT].size, 1);
+calculate_checksum(xsdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[XSDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -190,6 +219,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_rsdp(gc, dom, acpitables);
+make_acpi_xsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Here it adds the ACPI tables size to set the target maxmem to avoid
providing less available memory for guest.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arch.h|  2 +-
 tools/libxl/libxl_arm.c | 18 +-
 tools/libxl/libxl_arm.h |  4 
 tools/libxl/libxl_arm_acpi.c| 20 
 tools/libxl/libxl_arm_no_acpi.c |  6 ++
 tools/libxl/libxl_dom.c |  2 +-
 tools/libxl/libxl_x86.c |  2 +-
 7 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 337061f..d62fa4c 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -30,7 +30,7 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
 /* arch specific internal domain creation function */
 _hidden
 int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
-   uint32_t domid);
+  libxl__domain_build_state *state, uint32_t 
domid);
 
 /* setup arch specific hardware description, i.e. DTB on ARM */
 _hidden
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index e73d65e..c7d4f65 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -101,8 +101,24 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
 }
 
 int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
-  uint32_t domid)
+  libxl__domain_build_state *state, uint32_t domid)
 {
+libxl_domain_build_info *const info = _config->b_info;
+libxl_ctx *ctx = libxl__gc_owner(gc);
+int size;
+
+/* Add the size of ACPI tables to maxmem if ACPI is enabled for guest. */
+if (libxl_defbool_val(info->acpi)) {
+size = libxl__get_acpi_size(gc, info, state);
+if (size < 0)
+return ERROR_FAIL;
+if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
+LIBXL_MAXMEM_CONSTANT + (size + 1023) / 1024)) 
{
+LOGE(ERROR, "Couldn't set max memory");
+return ERROR_FAIL;
+}
+}
+
 return 0;
 }
 
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index a91ff93..37b1f15 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -24,6 +24,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom);
 
+_hidden
+int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info,
+ libxl__domain_build_state *state);
+
 static inline uint64_t libxl__compute_mpdir(unsigned int cpuid)
 {
 /*
diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 30e4d66..9854c7a 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -94,6 +94,26 @@ static int libxl__estimate_madt_size(libxl__gc *gc,
 return rc;
 }
 
+int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info,
+ libxl__domain_build_state *state)
+{
+int size;
+
+size = libxl__estimate_madt_size(gc, info, >config);
+if (size < 0)
+goto out;
+
+size = ROUNDUP(size, 3) +
+   ROUNDUP(sizeof(struct acpi_table_rsdp), 3) +
+   ROUNDUP(sizeof(struct acpi_table_xsdt), 3) +
+   ROUNDUP(sizeof(struct acpi_table_gtdt), 3) +
+   ROUNDUP(sizeof(struct acpi_table_fadt), 3) +
+   ROUNDUP(sizeof(dsdt_anycpu_arm_len), 3);
+
+out:
+return size;
+}
+
 static int libxl__estimate_acpi_size(libxl__gc *gc,
  libxl_domain_build_info *info,
  struct xc_dom_image *dom,
diff --git a/tools/libxl/libxl_arm_no_acpi.c b/tools/libxl/libxl_arm_no_acpi.c
index e7f7411..5eeb825 100644
--- a/tools/libxl/libxl_arm_no_acpi.c
+++ b/tools/libxl/libxl_arm_no_acpi.c
@@ -25,6 +25,12 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 return ERROR_FAIL;
 }
 
+int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info,
+ libxl__domain_build_state *state)
+{
+return ERROR_FAIL;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 7dbf614..a2cd350 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -437,7 +437,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
 #endif
 }
 
-rc = libxl__arch_domain_create(gc, d_config, domid);
+rc = libxl__arch_domain_create(gc, d_config, state, domid);
 
 return rc;
 }
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index e9127bb..c872089 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -285,7 +285,7 @@ static int libxl__e820_all

[Xen-devel] [PATCH v5 05/16] libxl/arm: Construct ACPI RSDP table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Construct ACPI RSDP table and add a helper to calculate the ACPI table
checksum.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index b91f3f6..83ad954 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,6 +34,10 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+#define ACPI_OEM_ID "Xen"
+#define ACPI_OEM_TABLE_ID "ARM"
+#define ACPI_ASL_COMPILER_ID "XL"
+
 enum {
 RSDP,
 XSDT,
@@ -126,6 +130,37 @@ out:
 return rc;
 }
 
+static void calculate_checksum(void *table, uint32_t checksum_offset,
+   uint32_t length)
+{
+uint8_t *p, sum = 0;
+
+p = table;
+p[checksum_offset] = 0;
+
+while (length--)
+sum = sum + *p++;
+
+p = table;
+p[checksum_offset] = -sum;
+}
+
+static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[RSDP].addr - GUEST_ACPI_BASE;
+struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset;
+
+memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
+memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
+rsdp->length = acpitables[RSDP].size;
+rsdp->revision = 0x02;
+rsdp->xsdt_physical_address = acpitables[XSDT].addr;
+calculate_checksum(rsdp,
+   offsetof(struct acpi_table_rsdp, extended_checksum),
+   acpitables[RSDP].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -151,6 +186,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
 rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+if (rc)
+goto out;
+
+make_acpi_rsdp(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 00/16] Xen ARM DomU ACPI support

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

The design of this feature is described as below.
Firstly, the toolstack (libxl) generates the ACPI tables according the
number of vcpus and gic controller.

Then, it copies these ACPI tables to DomU non-RAM memory map space and
passes them to UEFI firmware through the "ARM multiboot" protocol.

At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
and installs these tables like the usual way and passes both ACPI and DT
information to the Xen DomU.

Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
since it's enough now.

This has been tested using guest kernel with the Dom0 ACPI support
patches which could be fetched from linux master or:
https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen

The UEFI binary could be fetched from or built from edk2 master branch:
http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd

This series can be fetched from:
https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v5

Changes since v4:
* make changes in tools/configure.ac instead of tools/configure
* add libxl_arm_no_acpi.c for no acpi build
* add a function to get the acpi table size and use it to set maxmem
* drop HVM_PARAM_CALLBACK_TYPE_PPI_MASK and update hvm_set_callback_via
* add libxl__arch_domain_build_info_acpi_setdefault to set b_info->acpi
  default value separately
* update ACPI_OEM_ID
* set gtdt->counter_block_addresss and gtdt->counter_read_block_address
* add a BUILD_BUG_ON to check if GUEST_MAX_VCPUS >= MAX_VIRT_CPUS

Changes since v3:
* use goto style error handle
* unify configuration option for ACPI
* use extended_checksum instead of checksum in RSDP table
* only require iasl on arm64
* count acpi tables size for maxmem

Changes since v2:
* return error for 32bit domain with acpi enabled
* include actypes.h to reuse the definitions
* rename libxl_arm_acpi.h to libxl_arm.h
* use ACPI_MADT_ENABLED
* rebased on top of Boris's ACPI branch to reuse mk_dsdt.c

Changes since v1:
* move ACPI tables generation codes to a new file
* use static asl file to generate DSDT table and include processor
  device objects
* assign a non-RAM map for ACPI blob
* use existing ACPI table definitions under xen/include/acpi/
* add a configuration for user to enable/disable ACPI generation
* calculate the ACPI table checksum

Shannon Zhao (16):
  tools/libxl: Add an unified configuration option for ACPI
  libxl/arm: prepare for constructing ACPI tables
  libxl/arm: Generate static ACPI DSDT table
  libxl/arm: Estimate the size of ACPI tables
  libxl/arm: Construct ACPI RSDP table
  libxl/arm: Construct ACPI XSDT table
  libxl/arm: Construct ACPI GTDT table
  libxl/arm: Factor MPIDR computing codes out as a helper
  libxl/arm: Construct ACPI MADT table
  libxl/arm: Construct ACPI FADT table
  libxl/arm: Construct ACPI DSDT table
  libxl/arm: Factor finalise_one_memory_node as a gerneric function
  libxl/arm: Add ACPI module
  public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI
  libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ
  libxl/arm: Add the size of ACPI tables to maxmem

 docs/man/xl.cfg.pod.5.in   |   1 +
 docs/misc/arm/device-tree/acpi.txt |  24 +++
 tools/configure.ac |   2 +-
 tools/libacpi/Makefile |  13 +-
 tools/libacpi/mk_dsdt.c|  27 ++-
 tools/libxl/Makefile   |  10 +
 tools/libxl/libxl_arch.h   |   6 +-
 tools/libxl/libxl_arm.c| 101 +++--
 tools/libxl/libxl_arm.h|  48 +
 tools/libxl/libxl_arm_acpi.c   | 409 +
 tools/libxl/libxl_arm_no_acpi.c|  40 
 tools/libxl/libxl_create.c |   4 +-
 tools/libxl/libxl_dm.c |   4 +-
 tools/libxl/libxl_dom.c|   2 +-
 tools/libxl/libxl_internal.h   |   6 +
 tools/libxl/libxl_types.idl|   4 +
 tools/libxl/libxl_x86.c|   8 +-
 tools/libxl/xl_cmdimpl.c   |   2 +-
 xen/arch/arm/domain.c  |   1 +
 xen/arch/arm/domain_build.c|   8 +-
 xen/arch/x86/hvm/irq.c |   2 +-
 xen/include/public/arch-arm.h  |   7 +
 xen/include/public/hvm/params.h|   3 +
 23 files changed, 705 insertions(+), 27 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c
 create mode 100644 tools/libxl/libxl_arm_no_acpi.c

-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 04/16] libxl/arm: Estimate the size of ACPI tables

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Estimate the size of ACPI tables and reserve a memory map space for ACPI
tables.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 98 
 1 file changed, 98 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 0851411..b91f3f6 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,12 +34,108 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+enum {
+RSDP,
+XSDT,
+GTDT,
+MADT,
+FADT,
+DSDT,
+NUMS,
+};
+
+struct acpitable {
+uint64_t addr;
+size_t size;
+};
+
+static int libxl__estimate_madt_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ xc_domain_configuration_t *xc_config)
+{
+int rc;
+
+switch (xc_config->gic_version) {
+case XEN_DOMCTL_CONFIG_GIC_V2:
+rc = sizeof(struct acpi_table_madt) +
+ sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor);
+break;
+case XEN_DOMCTL_CONFIG_GIC_V3:
+rc = sizeof(struct acpi_table_madt) +
+ sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor) +
+ sizeof(struct acpi_madt_generic_redistributor);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+break;
+}
+
+return rc;
+}
+
+static int libxl__estimate_acpi_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ struct xc_dom_image *dom,
+ xc_domain_configuration_t *xc_config,
+ struct acpitable acpitables[])
+{
+int rc;
+
+acpitables[RSDP].addr = GUEST_ACPI_BASE;
+acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+/*
+ * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+ * entries for them.
+ */
+acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+sizeof(uint64_t) * 2;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+rc = libxl__estimate_madt_size(gc, info, xc_config);
+if (rc < 0)
+goto out;
+
+acpitables[MADT].size = rc;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[DSDT].size = dsdt_anycpu_arm_len;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+rc = 0;
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
 {
 const libxl_version_info *vers;
 int rc = 0;
+struct acpitable acpitables[NUMS];
+
+/* convenience aliases */
+xc_domain_configuration_t *xc_config = >config;
 
 vers = libxl_get_version_info(CTX);
 if (vers == NULL) {
@@ -54,6 +150,8 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].length = 0;
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
+rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+
 out:
 return rc;
 }
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 02/16] libxl/arm: prepare for constructing ACPI tables

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

It only constructs the ACPI tables for 64-bit ARM DomU when user enables
acpi because 32-bit DomU doesn't support ACPI. And the generation codes
are only built for 64-bit toolstack.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/Makefile|  7 +
 tools/libxl/libxl_arm.c | 24 +++-
 tools/libxl/libxl_arm.h | 33 ++
 tools/libxl/libxl_arm_acpi.c| 62 +
 tools/libxl/libxl_arm_no_acpi.c | 34 ++
 xen/include/public/arch-arm.h   |  4 +++
 6 files changed, 163 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c
 create mode 100644 tools/libxl/libxl_arm_no_acpi.c

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index a148374..afd93de 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -90,6 +90,13 @@ acpi:
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o 
libxl_x86_acpi.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
+ifeq ($(CONFIG_ARM_64),y)
+LIBXL_OBJS-y += libxl_arm_acpi.o
+libxl_arm_acpi.o: libxl_arm_acpi.c
+   $(CC) -c $(CFLAGS) -I../../xen/include/ -o $@ libxl_arm_acpi.c
+else
+LIBXL_OBJS-$(CONFIG_ARM) += libxl_arm_no_acpi.o
+endif
 
 ifeq ($(CONFIG_NetBSD),y)
 LIBXL_OBJS-y += libxl_netbsd.o
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 8ec5cd5..333c9a1 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -1,6 +1,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 #include "libxl_libfdt_compat.h"
+#include "libxl_arm.h"
 
 #include 
 #include 
@@ -885,8 +886,29 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
libxl__domain_build_state *state,
struct xc_dom_image *dom)
 {
+int rc;
+
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
-return libxl__prepare_dtb(gc, info, state, dom);
+rc = libxl__prepare_dtb(gc, info, state, dom);
+if (rc) goto out;
+
+if (!libxl_defbool_val(info->acpi)) {
+LOG(DEBUG, "Generating ACPI tables is disabled by user.");
+rc = 0;
+goto out;
+}
+
+if (strcmp(dom->guest_type, "xen-3.0-aarch64")) {
+/* ACPI is only supported for 64-bit guest currently. */
+LOG(ERROR, "Can not enable libxl option 'acpi' for %s", 
dom->guest_type);
+rc = ERROR_FAIL;
+goto out;
+}
+
+rc = libxl__prepare_acpi(gc, info, state, dom);
+
+out:
+return rc;
 }
 
 static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
new file mode 100644
index 000..1c01177
--- /dev/null
+++ b/tools/libxl/libxl_arm.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_internal.h"
+#include "libxl_arch.h"
+
+#include 
+
+_hidden
+int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
+libxl__domain_build_state *state,
+struct xc_dom_image *dom);
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
new file mode 100644
index 000..810aed8
--- /dev/null
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -0,0 +1,62 @@
+/*
+ * ARM DomU ACPI generation
+ *
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_arm.h"
+
+#include 
+
+/* Below typedefs are useful for the headers

[Xen-devel] [PATCH v5 15/16] libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

The guest kernel will get the event channel interrupt information via
domain param HVM_PARAM_CALLBACK_IRQ. Initialize it here.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 6f0bc70..e73d65e 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -900,8 +900,21 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
struct xc_dom_image *dom)
 {
 int rc;
+uint64_t val;
 
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
+
+/* Set the value of domain param HVM_PARAM_CALLBACK_IRQ. */
+val = (uint64_t)HVM_PARAM_CALLBACK_TYPE_PPI << 
HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT;
+/* Active-low level-sensitive  */
+val |= (HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL <<
+HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT);
+val |= GUEST_EVTCHN_PPI;
+rc = xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CALLBACK_IRQ,
+  val);
+if (rc)
+return rc;
+
 rc = libxl__prepare_dtb(gc, info, state, dom);
 if (rc) goto out;
 
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 01/16] tools/libxl: Add an unified configuration option for ACPI

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Since the existing configuration option "u.hvm.acpi" is x86 specific and
we want to reuse it on ARM as well, add a unified option "acpi" for
x86 and ARM, and for ARM it's disabled by default.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 docs/man/xl.cfg.pod.5.in | 1 +
 tools/libxl/libxl_arch.h | 4 
 tools/libxl/libxl_arm.c  | 6 ++
 tools/libxl/libxl_create.c   | 4 +++-
 tools/libxl/libxl_dm.c   | 4 ++--
 tools/libxl/libxl_internal.h | 6 ++
 tools/libxl/libxl_types.idl  | 4 
 tools/libxl/libxl_x86.c  | 6 ++
 tools/libxl/xl_cmdimpl.c | 2 +-
 9 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index a685b83..9242e3d 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -1237,6 +1237,7 @@ the virtual firmware to the guest Operating System. ACPI 
is required
 by most modern guest Operating Systems. This option is enabled by
 default and usually you should omit it. However it may be necessary to
 disable ACPI for compatibility with some guest Operating Systems.
+This option is true for x86 while it's false for ARM by default.
 
 =item B

[Xen-devel] [PATCH v5 03/16] libxl/arm: Generate static ACPI DSDT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

It uses static DSDT table like the way x86 uses. Currently the DSDT
table only contains processor device objects and it generates the
maximal objects which so far is 128.

While the GUEST_MAX_VCPUS is defined under __XEN__ or __XEN_TOOLS__, it
needs to add -D__XEN_TOOLS__ to compile mk_dsdt.c.

Also only check iasl for aarch64 in configure since ACPI on ARM32 is not
supported.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
Note: this patch needs to be rebased on Boris's v3 patchset for only 
generating dsdt_anycpu_arm.c for ARM64.
---
 tools/configure.ac|  2 +-
 tools/libacpi/Makefile| 13 -
 tools/libacpi/mk_dsdt.c   | 27 ++-
 tools/libxl/Makefile  |  5 -
 tools/libxl/libxl_arm_acpi.c  |  5 +
 xen/arch/arm/domain.c |  1 +
 xen/include/public/arch-arm.h |  3 +++
 7 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/tools/configure.ac b/tools/configure.ac
index 0229d44..b4e0c80 100644
--- a/tools/configure.ac
+++ b/tools/configure.ac
@@ -335,7 +335,7 @@ dnl "host" here means the platform on which the hypervisor 
and tools is
 dnl going to run, not the platform on which we are building (known as
 dnl "build" in gnu speak).
 case "$host_cpu" in
-i[[3456]]86|x86_64)
+i[[3456]]86|x86_64|aarch64)
 AX_PATH_PROG_OR_FAIL([IASL], [iasl])
 ;;
 esac
diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
index d741ac5..b1965cc 100644
--- a/tools/libacpi/Makefile
+++ b/tools/libacpi/Makefile
@@ -19,6 +19,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
 
 # Sources to be generated
 C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c  
dsdt_anycpu_qemu_xen.c dsdt_pvh.c)
+C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
 H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h 
ssdt_tpm.h)
 
 vpath iasl $(PATH)
@@ -32,7 +33,7 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl iasl
cd $(CURDIR)
 
 $(MK_DSDT): mk_dsdt.c
-   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -o $@ mk_dsdt.c
+   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ 
mk_dsdt.c
 
 $(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl 
$(MK_DSDT)
awk 'NR > 1 {print s} {s=$$0}' $< > $@
@@ -62,6 +63,16 @@ $(ACPI_BUILD_DIR)/dsdt_pvh.c: iasl 
$(ACPI_BUILD_DIR)/dsdt_pvh.asl
echo "int dsdt_pvh_len=sizeof(dsdt_pvh);" >>$@
rm -f $(ACPI_BUILD_DIR)/$*.aml $(ACPI_BUILD_DIR)/$*.hex
 
+$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT)
+   printf "DefinitionBlock (\"DSDT.aml\", \"DSDT\", 3, \"Xen\", \"ARM\", 
1)\n{" > $@
+   $(MK_DSDT) --debug=$(debug) >> $@
+
+$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c: iasl $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl
+   iasl -vs -p $(ACPI_BUILD_DIR)/$* -tc 
$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl
+   sed -e 's/AmlCode/dsdt_anycpu_arm/g' $(ACPI_BUILD_DIR)/$*.hex >$@
+   echo "int dsdt_anycpu_arm_len=sizeof(dsdt_anycpu_arm);" >>$@
+   rm -f $(ACPI_BUILD_DIR)/$*.aml $(ACPI_BUILD_DIR)/$*.hex
+
 iasl:
@echo
@echo "ACPI ASL compiler (iasl) is needed"
diff --git a/tools/libacpi/mk_dsdt.c b/tools/libacpi/mk_dsdt.c
index 7d76784..a56e0f0 100644
--- a/tools/libacpi/mk_dsdt.c
+++ b/tools/libacpi/mk_dsdt.c
@@ -17,7 +17,11 @@
 #include 
 #include 
 #include 
+#if defined(__i386__) || defined(__x86_64__)
 #include 
+#elif defined(__aarch64__)
+#include 
+#endif
 
 static unsigned int indent_level;
 static bool debug = false;
@@ -104,10 +108,16 @@ static struct option options[] = {
 
 int main(int argc, char **argv)
 {
-unsigned int slot, dev, intx, link, cpu, max_cpus = HVM_MAX_VCPUS;
+unsigned int slot, dev, intx, link, cpu, max_cpus;
 dm_version dm_version = QEMU_XEN_TRADITIONAL;
 bool no_dm = 0;
 
+#if defined(__i386__) || defined(__x86_64__)
+max_cpus = HVM_MAX_VCPUS;
+#elif defined(__aarch64__)
+max_cpus = GUEST_MAX_VCPUS;
+#endif
+
 for ( ; ; )
 {
 int opt = getopt_long(argc, argv, "", options, NULL);
@@ -161,6 +171,7 @@ int main(int argc, char **argv)
 / Processor start /
 push_block("Scope", "\\_SB");
 
+#if defined(__i386__) || defined(__x86_64__)
 /* MADT checksum */
 stmt("OperationRegion", "MSUM, SystemMemory, \\_SB.MSUA, 1");
 push_block("Field", "MSUM, ByteAcc, NoLock, Preserve");
@@ -174,6 +185,7 @@ int main(int argc, char **argv)
 pop_block();
 stmt("Return", "Buffer() {0, 8, 0xff, 0xff, 0, 0, 0, 0}");
 pop_block();
+#endif
 
 /* Define processor objects and control methods. */
 for ( cpu = 0; cpu < max_cpus; cpu++)
@@ -182,6 +194,11 @@ int main(int argc, char **argv)
 
 stmt("Name", "_HID, \"ACPI0007\&

[Xen-devel] [PATCH v5 09/16] libxl/arm: Construct ACPI MADT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

According to the GIC version, construct the MADT table.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 84 
 1 file changed, 84 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index ab49d57..d3358b3 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -227,6 +227,89 @@ static void make_acpi_gtdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[GTDT].size);
 }
 
+static void make_acpi_madt_gicc(void *table, int nr_cpus, uint64_t gicc_base)
+{
+int i;
+struct acpi_madt_generic_interrupt *gicc = table;
+
+for (i = 0; i < nr_cpus; i++) {
+gicc->header.type = ACPI_MADT_TYPE_GENERIC_INTERRUPT;
+gicc->header.length = sizeof(*gicc);
+gicc->base_address = gicc_base;
+gicc->cpu_interface_number = i;
+gicc->arm_mpidr = libxl__compute_mpdir(i);
+gicc->uid = i;
+gicc->flags = ACPI_MADT_ENABLED;
+gicc++;
+}
+}
+
+static void make_acpi_madt_gicd(void *table, uint64_t gicd_base,
+uint8_t gic_version)
+{
+struct acpi_madt_generic_distributor *gicd = table;
+
+gicd->header.type = ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR;
+gicd->header.length = sizeof(*gicd);
+gicd->base_address = gicd_base;
+/* This version field has no meaning before ACPI 5.1 errata. */
+gicd->version = gic_version;
+}
+
+static void make_acpi_madt_gicr(void *table, uint64_t gicr_base,
+uint64_t gicr_size)
+{
+struct acpi_madt_generic_redistributor *gicr = table;
+
+gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR;
+gicr->header.length = sizeof(*gicr);
+gicr->base_address = gicr_base;
+gicr->length = gicr_size;
+}
+
+static int make_acpi_madt(libxl__gc *gc, struct xc_dom_image *dom, int nr_cpus,
+  xc_domain_configuration_t *xc_config,
+  struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[MADT].addr - GUEST_ACPI_BASE;
+void *table = dom->acpi_modules[0].data + offset;
+struct acpi_table_madt *madt = table;
+int rc = 0;
+
+switch (xc_config->gic_version) {
+case XEN_DOMCTL_CONFIG_GIC_V2:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, nr_cpus, GUEST_GICC_BASE);
+
+table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus;
+make_acpi_madt_gicd(table, GUEST_GICD_BASE, ACPI_MADT_GIC_VERSION_V2);
+break;
+case XEN_DOMCTL_CONFIG_GIC_V3:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, nr_cpus, 0);
+
+table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus;
+make_acpi_madt_gicd(table, GUEST_GICV3_GICD_BASE,
+ACPI_MADT_GIC_VERSION_V3);
+
+table += sizeof(struct acpi_madt_generic_distributor);
+make_acpi_madt_gicr(table, GUEST_GICV3_GICR0_BASE,
+GUEST_GICV3_GICR0_SIZE);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+goto out;
+}
+
+make_acpi_header(>header, "APIC", acpitables[MADT].size, 3);
+calculate_checksum(madt, offsetof(struct acpi_table_header, checksum),
+   acpitables[MADT].size);
+
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -258,6 +341,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
+rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 10/16] libxl/arm: Construct ACPI FADT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index d3358b3..407f9d5 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -310,6 +310,25 @@ out:
 return rc;
 }
 
+static void make_acpi_fadt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[FADT].addr - GUEST_ACPI_BASE;
+struct acpi_table_fadt *fadt = (void *)dom->acpi_modules[0].data + offset;
+
+/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */
+fadt->flags = ACPI_FADT_HW_REDUCED;
+fadt->arm_boot_flags = ACPI_FADT_PSCI_COMPLIANT | ACPI_FADT_PSCI_USE_HVC;
+
+/* ACPI v5.1 (fadt->revision.fadt->minor_revision) */
+fadt->minor_revision = 0x1;
+fadt->dsdt = acpitables[DSDT].addr;
+
+make_acpi_header(>header, "FACP", acpitables[FADT].size, 5);
+calculate_checksum(fadt, offsetof(struct acpi_table_header, checksum),
+   acpitables[FADT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -342,6 +361,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
 rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config, acpitables);
+if (rc)
+goto out;
+
+make_acpi_fadt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 13/16] libxl/arm: Add ACPI module

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Add the ARM Multiboot module for ACPI, so UEFI or DomU can get the base
address of ACPI tables from it.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
---
 docs/misc/arm/device-tree/acpi.txt | 24 
 tools/libxl/libxl_arm.c| 24 
 2 files changed, 48 insertions(+)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt

diff --git a/docs/misc/arm/device-tree/acpi.txt 
b/docs/misc/arm/device-tree/acpi.txt
new file mode 100644
index 000..3e70157
--- /dev/null
+++ b/docs/misc/arm/device-tree/acpi.txt
@@ -0,0 +1,24 @@
+DomU ACPI module
+
+
+Xen toolstack passes the domU ACPI tables via a reference in the /chosen node 
of
+the device tree.
+
+Each node contains the following properties:
+
+- compatible
+
+   "xen,guest-acpi", "multiboot,module"
+
+- reg
+
+   Specifies the physical address and the length of the module.
+   RSDP table is always located at the beginning of this region.
+
+Examples
+
+
+   module@0x2000 {
+   compatible = "xen,guest-acpi", "multiboot,module";
+   reg = <0x2000 0x1234>;
+   };
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index f7f2c60..6f0bc70 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -285,6 +285,25 @@ static int make_chosen_node(libxl__gc *gc, void *fdt, bool 
ramdisk,
 if (res) return res;
 }
 
+if (libxl_defbool_val(info->acpi)) {
+const uint64_t acpi_base = GUEST_ACPI_BASE;
+const char *name = GCSPRINTF("module@%"PRIx64, acpi_base);
+
+res = fdt_begin_node(fdt, name);
+if (res) return res;
+
+res = fdt_property_compat(gc, fdt, 2, "xen,guest-acpi",
+  "multiboot,module");
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1, 0, 0);
+if (res) return res;
+
+res = fdt_end_node(fdt);
+if (res) return res;
+}
+
 res = fdt_end_node(fdt);
 if (res) return res;
 
@@ -975,6 +994,11 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
+if (dom->acpi_modules[0].data) {
+finalise_one_node(gc, fdt, "/chosen/module", GUEST_ACPI_BASE,
+  dom->acpi_modules[0].length);
+}
+
 debug_dump_fdt(gc, fdt);
 
 return 0;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 12/16] libxl/arm: Factor finalise_one_memory_node as a gerneric function

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Rename finalise_one_memory_node to finalise_one_node and pass the node
name via function parameter.

This is useful for adding ACPI module which will be added by a later
patch.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
---
 tools/libxl/libxl_arm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 2a4577c..f7f2c60 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -905,11 +905,11 @@ out:
 return rc;
 }
 
-static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
- uint64_t base, uint64_t size)
+static void finalise_one_node(libxl__gc *gc, void *fdt, const char *uname,
+  uint64_t base, uint64_t size)
 {
 int node, res;
-const char *name = GCSPRINTF("/memory@%"PRIx64, base);
+const char *name = GCSPRINTF("%s@%"PRIx64, uname, base);
 
 node = fdt_path_offset(fdt, name);
 assert(node > 0);
@@ -972,7 +972,7 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 for (i = 0; i < GUEST_RAM_BANKS; i++) {
 const uint64_t size = (uint64_t)dom->rambank_size[i] << XC_PAGE_SHIFT;
 
-finalise_one_memory_node(gc, fdt, bankbase[i], size);
+finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
 debug_dump_fdt(gc, fdt);
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 11/16] libxl/arm: Construct ACPI DSDT table

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Copy the static DSDT table into ACPI blob.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 407f9d5..30e4d66 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -329,6 +329,15 @@ static void make_acpi_fadt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[FADT].size);
 }
 
+static void make_acpi_dsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[DSDT].addr - GUEST_ACPI_BASE;
+void *dsdt = dom->acpi_modules[0].data + offset;
+
+memcpy(dsdt, dsdt_anycpu_arm, dsdt_anycpu_arm_len);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -365,6 +374,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_fadt(gc, dom, acpitables);
+make_acpi_dsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 08/16] libxl/arm: Factor MPIDR computing codes out as a helper

2016-09-01 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Factor MPIDR computing codes out as a helper, so it could be shared
between DT and ACPI.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
Acked-by: Julien Grall <julien.gr...@arm.com>
---
 tools/libxl/libxl_arm.c |  8 +---
 tools/libxl/libxl_arm.h | 11 +++
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 333c9a1..2a4577c 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -309,13 +309,7 @@ static int make_cpus_node(libxl__gc *gc, void *fdt, int 
nr_cpus,
 for (i = 0; i < nr_cpus; i++) {
 const char *name;
 
-/*
- * According to ARM CPUs bindings, the reg field should match
- * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
- * constructing the reg value of the guest at the moment, for it
- * is enough for the current max vcpu number.
- */
-mpidr_aff = (i & 0x0f) | (((i >> 4) & 0xff) << 8);
+mpidr_aff = libxl__compute_mpdir(i);
 name = GCSPRINTF("cpu@%"PRIx64, mpidr_aff);
 
 res = fdt_begin_node(fdt, name);
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index 1c01177..a91ff93 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -24,6 +24,17 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom);
 
+static inline uint64_t libxl__compute_mpdir(unsigned int cpuid)
+{
+/*
+ * According to ARM CPUs bindings, the reg field should match
+ * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
+ * constructing the reg value of the guest at the moment, for it
+ * is enough for the current max vcpu number.
+ */
+return (cpuid & 0x0f) | (((cpuid >> 4) & 0xff) << 8);
+}
+
 /*
  * Local variables:
  * mode: C
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 03/16] libxl/arm: Generate static ACPI DSDT table

2016-09-01 Thread Shannon Zhao


On 2016/9/1 20:53, Boris Ostrovsky wrote:
> On 08/31/2016 11:18 PM, Shannon Zhao wrote:
>> >
>> > On 2016/8/30 1:46, Julien Grall wrote:
>>>> >>> diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
>>>> >>> index d741ac5..7f50a33 100644
>>>> >>> --- a/tools/libacpi/Makefile
>>>> >>> +++ b/tools/libacpi/Makefile
>>>> >>> @@ -19,6 +19,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
>>>> >>>
>>>> >>>  # Sources to be generated
>>>> >>>  C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c 
>>>> >>> dsdt_anycpu_qemu_xen.c dsdt_pvh.c)
>>>> >>> +C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
>>> >> Do we really want to generate dsdt_anycpu_arm.c even for x86? Similarly,
>>> >> do we want to generate x86 dsdt for ARM
>> > No need I think.
>> > Boris, will you change this in your next version?
> You mean adding something along the lines of 'C_SRC-$(CONFIG_X86)'? Yes,
> it's probably a good idea. I can add that.
Yes. Then I'll rebase my series on your new version. BTW, when will you
send out your new series?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 03/16] libxl/arm: Generate static ACPI DSDT table

2016-08-31 Thread Shannon Zhao


On 2016/8/30 1:46, Julien Grall wrote:
>> diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
>> index d741ac5..7f50a33 100644
>> --- a/tools/libacpi/Makefile
>> +++ b/tools/libacpi/Makefile
>> @@ -19,6 +19,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
>>
>>  # Sources to be generated
>>  C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c 
>> dsdt_anycpu_qemu_xen.c dsdt_pvh.c)
>> +C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
> 
> Do we really want to generate dsdt_anycpu_arm.c even for x86? Similarly,
> do we want to generate x86 dsdt for ARM
No need I think.
Boris, will you change this in your next version?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 03/16] libxl/arm: Generate static ACPI DSDT table

2016-08-31 Thread Shannon Zhao


On 2016/8/30 1:46, Julien Grall wrote:
> Hi Shannon,
> 
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> It uses static DSDT table like the way x86 uses. Currently the DSDT
>> table only contains processor device objects and it generates the
>> maximal objects which so far is 128.
>>
>> Also only check iasl for aarch64 in configure since ACPI on ARM32 is not
>> supported.
>>
>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> ---
>>  tools/configure   |  2 +-
> 
> The file tools/configure should not be modified manually. Instead you
> have to modify tools/configure.ac.
> 
> You can regenerate tools/configure, you can call ./autegen.sh. However,
> I would recommend you to not include the changes of configure and ask
> the committer to regenerate. This is because we use always use the same
> version of autotools to do generation in order to avoid spurious change.
> 
Ok, will fix.

>> diff --git a/xen/include/public/arch-arm.h
>> b/xen/include/public/arch-arm.h
>> index 0afd654..008a2a0 100644
>> --- a/xen/include/public/arch-arm.h
>> +++ b/xen/include/public/arch-arm.h
>> @@ -435,6 +435,9 @@ typedef uint64_t xen_callback_t;
>>  #define GUEST_RAM_BANK_BASES   { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
>>  #define GUEST_RAM_BANK_SIZES   { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
>>
>> +/* Current supported guest VCPUs */
>> +#define GUEST_MAX_VCPUS 128
> 
> The number of vCPUS per guest supported depends whether Xen has been
> built for ARM32 or ARM64.
> 
> Also, because now we have two different place to define the number of
> vCPUS (here and include/asm-arm/config.h) it might be possible to have
> them differ by mistake.
> 
> I am not sure how to avoid the 2 definitions, so I would add a
> BUILD_BUG_ON in Xen to make sure that MAX_VIRT_CPUS is always <= to
> GUEST_MAX_VCPUS.
> 
It has the below check. So could we just define GUEST_MAX_VCPUS as
(GUEST_GICV3_GICR0_SIZE / GUEST_GICV3_RDIST_STRIDE)?

BUILD_BUG_ON((GUEST_GICV3_GICR0_SIZE / GUEST_GICV3_RDIST_STRIDE) <
MAX_VIRT_CPUS);

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-08-30 Thread Shannon Zhao


On 2016/8/30 3:07, Julien Grall wrote:
> Hi Shannon,
> 
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> While it defines the maximum size of guest ACPI tables in guest
>> memory layout, here it adds the size to set the target maxmem
>> to avoid providing less available memory for guest.
>>
>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> ---
>>  tools/libxl/libxl_arm.c | 11 +++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
>> index d436167..75b2589 100644
>> --- a/tools/libxl/libxl_arm.c
>> +++ b/tools/libxl/libxl_arm.c
>> @@ -103,6 +103,17 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
>>  int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config
>> *d_config,
>>uint32_t domid)
>>  {
>> +libxl_domain_build_info *const info = _config->b_info;
>> +libxl_ctx *ctx = libxl__gc_owner(gc);
>> +
>> +/* Add the size of ACPI tables to maxmem if ACPI is enabled for
>> guest. */
>> +if (libxl_defbool_val(info->acpi) &&
>> +xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
>> +LIBXL_MAXMEM_CONSTANT + GUEST_ACPI_SIZE / 1024) < 0) {
> 
> Why can't we use the estimate size here? It would be better than
> increasing by a constant again the max size (I doubt the ACPI tables
> will be 2MB every time).
> 
Rethink about this. I think it could call the
libxl__estimate_acpi_size() here.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 07/16] libxl/arm: Construct ACPI GTDT table

2016-08-29 Thread Shannon Zhao


On 2016/8/30 2:16, Julien Grall wrote:
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> Construct GTDT table with the interrupt information of timers.
>>
>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> ---
>>  tools/libxl/libxl_arm_acpi.c | 29 +
>>  1 file changed, 29 insertions(+)
>>
>> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
>> index 8cd1d9b..28fb6fe 100644
>> --- a/tools/libxl/libxl_arm_acpi.c
>> +++ b/tools/libxl/libxl_arm_acpi.c
>> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>>  typedef uint16_t u16;
>>  typedef uint32_t u32;
>>  typedef uint64_t u64;
>> +typedef int64_t s64;
>>
>>  #include 
>>  #include 
>>
>> +#include 
>> +#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
>> +#define COMPILER_DEPENDENT_INT64 int64_t
>> +#define COMPILER_DEPENDENT_UINT64 uint64_t
>> +
>> +#include 
>> +
>>  _hidden
>>  extern const unsigned char dsdt_anycpu_arm[];
>>  _hidden
>> @@ -175,6 +183,26 @@ static void make_acpi_xsdt(libxl__gc *gc, struct
>> xc_dom_image *dom,
>> acpitables[XSDT].size);
>>  }
>>
>> +static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
>> +   struct acpitable acpitables[])
>> +{
>> +uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
>> +struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data
>> + offset;
>> +
>> +gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
>> +gtdt->non_secure_el1_flags =
>> + (ACPI_LEVEL_SENSITIVE <<
>> ACPI_GTDT_INTERRUPT_MODE)
>> + |(ACPI_ACTIVE_LOW <<
>> ACPI_GTDT_INTERRUPT_POLARITY);
>> +gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
>> +gtdt->virtual_timer_flags =
>> + (ACPI_LEVEL_SENSITIVE <<
>> ACPI_GTDT_INTERRUPT_MODE)
>> + |(ACPI_ACTIVE_LOW <<
>> ACPI_GTDT_INTERRUPT_POLARITY);
>> +
> 
> I don't see any setting for the field counter_block_address. From the
> ACPI spec, the field should be 0x when the counter
> control block is not available
Oops, will add. Thanks.

-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-08-29 Thread Shannon Zhao


On 2016/8/30 3:00, Julien Grall wrote:
> Hi Shannon,
> 
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
>> them in evtchn_fixup().
>>
>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> ---
>>  xen/arch/arm/domain_build.c | 8 +---
>>  xen/include/public/hvm/params.h | 4 
>>  2 files changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>> index 60db9e4..94cd3ce 100644
>> --- a/xen/arch/arm/domain_build.c
>> +++ b/xen/arch/arm/domain_build.c
>> @@ -2019,9 +2019,11 @@ static void evtchn_fixup(struct domain *d,
>> struct kernel_info *kinfo)
>> 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;
>> +val = (u64)HVM_PARAM_CALLBACK_TYPE_PPI <<
>> HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT;
>> +/* Active-low level-sensitive  */
>> +val |= (HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL <<
>> +HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT);
>> +val |= d->arch.evtchn_irq & HVM_PARAM_CALLBACK_TYPE_PPI_MASK;
> 
> The mask is pointless and a call to make things much worse if evtchn_irq
> is not a PPI (which will never happen).
> 
>>  d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
>>
>>  /*
>> diff --git a/xen/include/public/hvm/params.h
>> b/xen/include/public/hvm/params.h
>> index f7338a3..8a0327d 100644
>> --- a/xen/include/public/hvm/params.h
>> +++ b/xen/include/public/hvm/params.h
>> @@ -30,6 +30,7 @@
>>   */
>>
>>  #define HVM_PARAM_CALLBACK_IRQ 0
>> +#define HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT 56
>>  /*
>>   * How should CPU0 event-channel notifications be delivered?
>>   *
>> @@ -66,6 +67,9 @@
>>   * This is only used by ARM/ARM64 and masking/eoi the interrupt
>> associated to
>>   * the notification is handled by the interrupt controller.
>>   */
>> +#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT 8
>> +#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
>> +#define HVM_PARAM_CALLBACK_TYPE_PPI_MASK   0xff
> 
> Please drop the PPI_MASK, it is not correctly defined (there is only 16
> PPI going from 16 - 32) and pointless.
> 
Sure. Thanks.

-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-08-29 Thread Shannon Zhao


On 2016/8/30 3:07, Julien Grall wrote:
> Hi Shannon,
> 
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.z...@linaro.org>
>>
>> While it defines the maximum size of guest ACPI tables in guest
>> memory layout, here it adds the size to set the target maxmem
>> to avoid providing less available memory for guest.
>>
>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> ---
>>  tools/libxl/libxl_arm.c | 11 +++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
>> index d436167..75b2589 100644
>> --- a/tools/libxl/libxl_arm.c
>> +++ b/tools/libxl/libxl_arm.c
>> @@ -103,6 +103,17 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
>>  int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config
>> *d_config,
>>uint32_t domid)
>>  {
>> +libxl_domain_build_info *const info = _config->b_info;
>> +libxl_ctx *ctx = libxl__gc_owner(gc);
>> +
>> +/* Add the size of ACPI tables to maxmem if ACPI is enabled for
>> guest. */
>> +if (libxl_defbool_val(info->acpi) &&
>> +xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
>> +LIBXL_MAXMEM_CONSTANT + GUEST_ACPI_SIZE / 1024) < 0) {
> 
> Why can't we use the estimate size here? It would be better than
> increasing by a constant again the max size (I doubt the ACPI tables
> will be 2MB every time).
> 
The estimate action happens after libxl__arch_domain_create(), I think.
So it can't get the estimate size here.

Also, it's better to add the max size so that it doesn't have to change
here when it adds other contents to the ACPI tables.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 05/16] libxl/arm: Construct ACPI RSDP table

2016-08-29 Thread Shannon Zhao


On 2016/8/30 2:05, Julien Grall wrote:
> Hi Shannon,
> 
> On 25/08/2016 04:05, Shannon Zhao wrote:
>>
>>
>> On 2016/8/24 20:52, Wei Liu wrote:
>>> On Tue, Aug 16, 2016 at 06:25:02PM +0800, Shannon Zhao wrote:
>>>>> From: Shannon Zhao <shannon.z...@linaro.org>
>>>>>
>>>>> Construct ACPI RSDP table and add a helper to calculate the ACPI table
>>>>> checksum.
>>>>>
>>>>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>>>>> ---
>>>>>  tools/libxl/libxl_arm_acpi.c | 38
>>>>> ++
>>>>>  1 file changed, 38 insertions(+)
>>>>>
>>>>> diff --git a/tools/libxl/libxl_arm_acpi.c
>>>>> b/tools/libxl/libxl_arm_acpi.c
>>>>> index 6be9eb0..9432e44 100644
>>>>> --- a/tools/libxl/libxl_arm_acpi.c
>>>>> +++ b/tools/libxl/libxl_arm_acpi.c
>>>>> @@ -33,6 +33,9 @@ extern const unsigned char dsdt_anycpu_arm[];
>>>>>  _hidden
>>>>>  extern const int dsdt_anycpu_arm_len;
>>>>>
>>>>> +#define ACPI_BUILD_APPNAME6 "XenARM"
>>>>> +#define ACPI_BUILD_APPNAME4 "Xen "
>>>>> +
>>> Where do these come from? If they are from a spec, could you please add
>>> a comment here?
>>>
>> Not from some spec. Just fake a OEM for these tables like the
>> ACPI_OEM_ID, ACPI_CREATOR_ID used by x86.
> 
> In this case, why don't we re-use the one from x86?
> 
While the ACPI_OEM_TABLE_ID and ACPI_CREATOR_ID of x86 are HVM specific,
I don't think it's proper for ARM.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 01/16] tools/libxl: Add an unified configuration option for ACPI

2016-08-25 Thread Shannon Zhao


On 2016/8/25 17:05, Wei Liu wrote:
> On Thu, Aug 25, 2016 at 03:54:32PM +0800, Shannon Zhao wrote:
>> > 
>> > 
>> > On 2016/8/24 20:50, Wei Liu wrote:
>>>> > >> -localents[i++] = libxl_defbool_val(info->u.hvm.acpi) ? "1" : 
>>>> > >> "0";
>>>>> > >> > +localents[i++] = (libxl_defbool_val(info->acpi) &&
>>>>> > >> > + libxl_defbool_val(info->u.hvm.acpi)) ? 
>>>>> > >> > "1" : "0";
>>> > > Please provide a function for this.
>>> > > 
>>> > > And the logic doesn't seem right. If the user sets u.hvm.acpi only,
>>> > > (s)he should still have ACPI enabled.
>> > info->acpi is true by defaut, so if user doesn't set info->acpi while
>> > sets u.hvm.acpi only, both u.hvm.acpi and info->acpi will be true IIUC.
> OK, that sounds sensible. But please could you document this expectation
> in the to-be-created helper function? Thanks
Ok, will do.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 05/16] libxl/arm: Construct ACPI RSDP table

2016-08-25 Thread Shannon Zhao


On 2016/8/24 20:52, Wei Liu wrote:
> On Tue, Aug 16, 2016 at 06:25:02PM +0800, Shannon Zhao wrote:
>> > From: Shannon Zhao <shannon.z...@linaro.org>
>> > 
>> > Construct ACPI RSDP table and add a helper to calculate the ACPI table
>> > checksum.
>> > 
>> > Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>> > ---
>> >  tools/libxl/libxl_arm_acpi.c | 38 ++
>> >  1 file changed, 38 insertions(+)
>> > 
>> > diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
>> > index 6be9eb0..9432e44 100644
>> > --- a/tools/libxl/libxl_arm_acpi.c
>> > +++ b/tools/libxl/libxl_arm_acpi.c
>> > @@ -33,6 +33,9 @@ extern const unsigned char dsdt_anycpu_arm[];
>> >  _hidden
>> >  extern const int dsdt_anycpu_arm_len;
>> >  
>> > +#define ACPI_BUILD_APPNAME6 "XenARM"
>> > +#define ACPI_BUILD_APPNAME4 "Xen "
>> > +
> Where do these come from? If they are from a spec, could you please add
> a comment here?
> 
Not from some spec. Just fake a OEM for these tables like the
ACPI_OEM_ID, ACPI_CREATOR_ID used by x86.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 07/16] libxl/arm: Construct ACPI GTDT table

2016-08-25 Thread Shannon Zhao


On 2016/8/24 22:13, Roger Pau Monné wrote:
> On Wed, Aug 24, 2016 at 01:56:04PM +0100, Wei Liu wrote:
>> On Tue, Aug 16, 2016 at 06:25:04PM +0800, Shannon Zhao wrote:
>>> From: Shannon Zhao <shannon.z...@linaro.org>
>>>
>>> Construct GTDT table with the interrupt information of timers.
>>>
>>> Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>>> ---
>>>  tools/libxl/libxl_arm_acpi.c | 29 +
>>>  1 file changed, 29 insertions(+)
>>>
>>> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
>>> index 8cd1d9b..28fb6fe 100644
>>> --- a/tools/libxl/libxl_arm_acpi.c
>>> +++ b/tools/libxl/libxl_arm_acpi.c
>>> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>>>  typedef uint16_t u16;
>>>  typedef uint32_t u32;
>>>  typedef uint64_t u64;
>>> +typedef int64_t s64;
>>>  
>>>  #include 
>>>  #include 
>>>  
>>> +#include 
>>
>> Hmm... This is likely to be Linux-centric. But I'm not sure if FreeBSD
>> or other BSDes have plan for Xen on ARM support.
> 
> I would certainly love to see that happen, but I don't see myself working on 
> that in the near future. In any case, this is a Linux-specific header, and 
> should be included in libxl_osdeps.h. I would recommend that you use 
> something like:
> 
> #ifndef BITS_PER_LONG
> #ifdef _LP64
> #define BITS_PER_LONG 64
> #else
> #define BITS_PER_LONG 32
> #endif
> #endif
> 
> So that it works on other systems also (or maybe you don't even need to 
> include bitsperlong.h at all).
> 
OK, will fix this.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 00/16] Xen ARM DomU ACPI support

2016-08-25 Thread Shannon Zhao


On 2016/8/24 20:58, Wei Liu wrote:
> On Tue, Aug 16, 2016 at 06:24:57PM +0800, Shannon Zhao wrote:
>> > From: Shannon Zhao <shannon.z...@linaro.org>
>> > 
>> > The design of this feature is described as below.
>> > Firstly, the toolstack (libxl) generates the ACPI tables according the
>> > number of vcpus and gic controller.
>> > 
>> > Then, it copies these ACPI tables to DomU non-RAM memory map space and
>> > passes them to UEFI firmware through the "ARM multiboot" protocol.
>> > 
>> > At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
>> > and installs these tables like the usual way and passes both ACPI and DT
>> > information to the Xen DomU.
>> > 
>> > Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
>> > since it's enough now.
>> > 
>> > This has been tested using guest kernel with the Dom0 ACPI support
>> > patches which could be fetched from linux master or:
>> > https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen
>> > 
>> > The UEFI binary could be fetched from or built from edk2 master branch:
>> > http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd
>> > 
>> > This series can be fetched from:
>> > https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v4
>> > 
> Thanks for posting this version and sorry for the late review.
> 
> I've skimmed the whole series and pointed out things I think should be
> improved. I will leave reviewing all the table building code to ARM
> maintainers.
Ok, thanks a lot for your help.

-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v4 01/16] tools/libxl: Add an unified configuration option for ACPI

2016-08-25 Thread Shannon Zhao


On 2016/8/24 20:50, Wei Liu wrote:
>> -localents[i++] = libxl_defbool_val(info->u.hvm.acpi) ? "1" : "0";
>> > +localents[i++] = (libxl_defbool_val(info->acpi) &&
>> > + libxl_defbool_val(info->u.hvm.acpi)) ? "1" : "0";
> Please provide a function for this.
> 
> And the logic doesn't seem right. If the user sets u.hvm.acpi only,
> (s)he should still have ACPI enabled.
info->acpi is true by defaut, so if user doesn't set info->acpi while
sets u.hvm.acpi only, both u.hvm.acpi and info->acpi will be true IIUC.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 00/16] Xen ARM DomU ACPI support

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

The design of this feature is described as below.
Firstly, the toolstack (libxl) generates the ACPI tables according the
number of vcpus and gic controller.

Then, it copies these ACPI tables to DomU non-RAM memory map space and
passes them to UEFI firmware through the "ARM multiboot" protocol.

At last, UEFI gets the ACPI tables through the "ARM multiboot" protocol
and installs these tables like the usual way and passes both ACPI and DT
information to the Xen DomU.

Currently libxl only generates RSDP, XSDT, GTDT, MADT, FADT, DSDT tables
since it's enough now.

This has been tested using guest kernel with the Dom0 ACPI support
patches which could be fetched from linux master or:
https://git.kernel.org/cgit/linux/kernel/git/mfleming/efi.git/log/?h=efi/arm-xen

The UEFI binary could be fetched from or built from edk2 master branch:
http://people.linaro.org/~shannon.zhao/DomU_ACPI/XEN_EFI.fd

This series can be fetched from:
https://git.linaro.org/people/shannon.zhao/xen.git  domu_acpi_v4

Changes since v3:
* use goto style error handle
* unify configuration option for ACPI
* use extended_checksum instead of checksum in RSDP table
* only require iasl on arm64
* count acpi tables size for maxmem

Changes since v2:
* return error for 32bit domain with acpi enabled
* include actypes.h to reuse the definitions
* rename libxl_arm_acpi.h to libxl_arm.h
* use ACPI_MADT_ENABLED
* rebased on top of Boris's ACPI branch to reuse mk_dsdt.c

Changes since v1:
* move ACPI tables generation codes to a new file
* use static asl file to generate DSDT table and include processor
  device objects
* assign a non-RAM map for ACPI blob
* use existing ACPI table definitions under xen/include/acpi/
* add a configuration for user to enable/disable ACPI generation
* calculate the ACPI table checksum

Shannon Zhao (16):
  tools/libxl: Add an unified configuration option for ACPI
  libxl/arm: prepare for constructing ACPI tables
  libxl/arm: Generate static ACPI DSDT table
  libxl/arm: Estimate the size of ACPI tables
  libxl/arm: Construct ACPI RSDP table
  libxl/arm: Construct ACPI XSDT table
  libxl/arm: Construct ACPI GTDT table
  libxl/arm: Factor MPIDR computing codes out as a helper
  libxl/arm: Construct ACPI MADT table
  libxl/arm: Construct ACPI FADT table
  libxl/arm: Construct ACPI DSDT table
  libxl/arm: Factor finalise_one_memory_node as a gerneric function
  libxl/arm: Add ACPI module
  public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI
  libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ
  libxl/arm: Add the size of ACPI tables to maxmem

 docs/misc/arm/device-tree/acpi.txt |  24 +++
 tools/configure|   2 +-
 tools/libacpi/Makefile |  15 +-
 tools/libacpi/mk_dsdt.c|  51 --
 tools/libxl/Makefile   |   7 +
 tools/libxl/libxl_arm.c|  87 +++--
 tools/libxl/libxl_arm.h|  55 ++
 tools/libxl/libxl_arm_acpi.c   | 365 +
 tools/libxl/libxl_create.c |   9 +-
 tools/libxl/libxl_dm.c |   6 +-
 tools/libxl/libxl_types.idl|   4 +
 tools/libxl/xl_cmdimpl.c   |   2 +-
 xen/arch/arm/domain_build.c|   8 +-
 xen/include/public/arch-arm.h  |   7 +
 xen/include/public/hvm/params.h|   4 +
 15 files changed, 612 insertions(+), 34 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c

-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Add macros for HVM_PARAM_CALLBACK_TYPE_PPI operation values and update
them in evtchn_fixup().

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 xen/arch/arm/domain_build.c | 8 +---
 xen/include/public/hvm/params.h | 4 
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 60db9e4..94cd3ce 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2019,9 +2019,11 @@ static void evtchn_fixup(struct domain *d, struct 
kernel_info *kinfo)
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;
+val = (u64)HVM_PARAM_CALLBACK_TYPE_PPI << 
HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT;
+/* Active-low level-sensitive  */
+val |= (HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL <<
+HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT);
+val |= d->arch.evtchn_irq & HVM_PARAM_CALLBACK_TYPE_PPI_MASK;
 d->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ] = val;
 
 /*
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index f7338a3..8a0327d 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -30,6 +30,7 @@
  */
 
 #define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT 56
 /*
  * How should CPU0 event-channel notifications be delivered?
  *
@@ -66,6 +67,9 @@
  * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to
  * the notification is handled by the interrupt controller.
  */
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT 8
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
+#define HVM_PARAM_CALLBACK_TYPE_PPI_MASK   0xff
 #endif
 
 /*
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 15/16] libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

The guest kernel will get the event channel interrupt information via
domain param HVM_PARAM_CALLBACK_IRQ. Initialize it here.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 11a6f6e..d436167 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -900,8 +900,21 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
struct xc_dom_image *dom)
 {
 int rc;
+uint64_t val;
 
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
+
+/* Set the value of domain param HVM_PARAM_CALLBACK_IRQ. */
+val = (uint64_t)HVM_PARAM_CALLBACK_TYPE_PPI << 
HVM_PARAM_CALLBACK_IRQ_TYPE_SHIFT;
+/* Active-low level-sensitive  */
+val |= (HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL <<
+HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_SHIFT);
+val |= GUEST_EVTCHN_PPI & HVM_PARAM_CALLBACK_TYPE_PPI_MASK;
+rc = xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_CALLBACK_IRQ,
+  val);
+if (rc)
+return rc;
+
 rc = libxl__prepare_dtb(gc, info, state, dom);
 if (rc) goto out;
 
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 03/16] libxl/arm: Generate static ACPI DSDT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

It uses static DSDT table like the way x86 uses. Currently the DSDT
table only contains processor device objects and it generates the
maximal objects which so far is 128.

Also only check iasl for aarch64 in configure since ACPI on ARM32 is not
supported.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/configure   |  2 +-
 tools/libacpi/Makefile| 15 -
 tools/libacpi/mk_dsdt.c   | 51 ---
 tools/libxl/Makefile  |  5 -
 tools/libxl/libxl_arm_acpi.c  |  5 +
 xen/include/public/arch-arm.h |  3 +++
 6 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/tools/configure b/tools/configure
index 5b5dcce..48239c0 100755
--- a/tools/configure
+++ b/tools/configure
@@ -7458,7 +7458,7 @@ then
 as_fn_error $? "Unable to find xgettext, please install xgettext" 
"$LINENO" 5
 fi
 case "$host_cpu" in
-i[3456]86|x86_64)
+i[3456]86|x86_64|aarch64)
 # Extract the first word of "iasl", so it can be a program name with args.
 set dummy iasl; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
index d741ac5..7f50a33 100644
--- a/tools/libacpi/Makefile
+++ b/tools/libacpi/Makefile
@@ -19,6 +19,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
 
 # Sources to be generated
 C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, dsdt_anycpu.c dsdt_15cpu.c  
dsdt_anycpu_qemu_xen.c dsdt_pvh.c)
+C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
 H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h 
ssdt_tpm.h)
 
 vpath iasl $(PATH)
@@ -32,7 +33,7 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl iasl
cd $(CURDIR)
 
 $(MK_DSDT): mk_dsdt.c
-   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -o $@ mk_dsdt.c
+   $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ 
mk_dsdt.c
 
 $(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl 
$(MK_DSDT)
awk 'NR > 1 {print s} {s=$$0}' $< > $@
@@ -62,6 +63,18 @@ $(ACPI_BUILD_DIR)/dsdt_pvh.c: iasl 
$(ACPI_BUILD_DIR)/dsdt_pvh.asl
echo "int dsdt_pvh_len=sizeof(dsdt_pvh);" >>$@
rm -f $(ACPI_BUILD_DIR)/$*.aml $(ACPI_BUILD_DIR)/$*.hex
 
+$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT)
+   printf "DefinitionBlock (\"DSDT.aml\", \"DSDT\", 3, \"XenARM\", \"Xen 
DSDT\", 1)\n{" > $@
+   $(MK_DSDT) --debug=$(debug) --arch arm >> $@
+
+$(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c: iasl $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl
+   cd $(ACPI_BUILD_DIR)
+   iasl -vs -p $* -tc $(ACPI_BUILD_DIR)/$*.asl
+   sed -e 's/AmlCode/$*/g' $*.hex >$@
+   echo "int $*_len=sizeof($*);" >>$@
+   rm -f $*.aml $*.hex
+   cd $(CURDIR)
+
 iasl:
@echo
@echo "ACPI ASL compiler (iasl) is needed"
diff --git a/tools/libacpi/mk_dsdt.c b/tools/libacpi/mk_dsdt.c
index 7d76784..f3ab28f 100644
--- a/tools/libacpi/mk_dsdt.c
+++ b/tools/libacpi/mk_dsdt.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static unsigned int indent_level;
 static bool debug = false;
@@ -99,6 +100,7 @@ static struct option options[] = {
 { "dm-version", 1, 0, 'q' },
 { "debug", 1, 0, 'd' },
 { "no-dm", 0, 0, 'n' },
+{ "arch", 1, 0, 'a' },
 { 0, 0, 0, 0 }
 };
 
@@ -106,7 +108,7 @@ int main(int argc, char **argv)
 {
 unsigned int slot, dev, intx, link, cpu, max_cpus = HVM_MAX_VCPUS;
 dm_version dm_version = QEMU_XEN_TRADITIONAL;
-bool no_dm = 0;
+bool no_dm = 0, arch_is_arm = false;
 
 for ( ; ; )
 {
@@ -145,6 +147,10 @@ int main(int argc, char **argv)
 case 'n':
 no_dm = 1;
 break;
+case 'a':
+if (strcmp(optarg, "arm") == 0)
+arch_is_arm = true;
+break;
 case 'd':
 if (*optarg == 'y')
 debug = true;
@@ -154,6 +160,9 @@ int main(int argc, char **argv)
 }
 }
 
+if (arch_is_arm)
+max_cpus = GUEST_MAX_VCPUS;
+
 / DSDT DefinitionBlock start /
 /* (we append to existing DSDT definition block) */
 indent_level++;
@@ -161,19 +170,21 @@ int main(int argc, char **argv)
 / Processor start /
 push_block("Scope", "\\_SB");
 
-/* MADT checksum */
-stmt("OperationRegion", "MSUM, SystemMemory, \\_SB.MSUA, 1");
-push_block("Field", "MSUM, ByteAcc, NoLock, Preserve");
-indent(); printf("MSU, 8\n");
-pop_block();
+if (!arch_is_arm) {
+/* MADT checksum */
+stmt("OperationRegion", "MSUM, SystemMemory, \\_SB.MSUA, 1");
+push_block("Field", &q

[Xen-devel] [PATCH v4 01/16] tools/libxl: Add an unified configuration option for ACPI

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Since the existing configuration option "u.hvm.acpi" is x86 specific and
we want to reuse it on ARM as well, add a unified option "acpi" for
x86 and ARM, and for ARM it's disabled by default.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_create.c  | 9 -
 tools/libxl/libxl_dm.c  | 6 --
 tools/libxl/libxl_types.idl | 4 
 tools/libxl/xl_cmdimpl.c| 2 +-
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 08822e3..3043b1f 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -215,6 +215,12 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
 if (!b_info->event_channels)
 b_info->event_channels = 1023;
 
+#if defined(__arm__) || defined(__aarch64__)
+libxl_defbool_setdefault(_info->acpi, false);
+#else
+libxl_defbool_setdefault(_info->acpi, true);
+#endif
+
 switch (b_info->type) {
 case LIBXL_DOMAIN_TYPE_HVM:
 if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT)
@@ -454,7 +460,8 @@ int libxl__domain_build(libxl__gc *gc,
 localents = libxl__calloc(gc, 9, sizeof(char *));
 i = 0;
 localents[i++] = "platform/acpi";
-localents[i++] = libxl_defbool_val(info->u.hvm.acpi) ? "1" : "0";
+localents[i++] = (libxl_defbool_val(info->acpi) &&
+ libxl_defbool_val(info->u.hvm.acpi)) ? "1" : "0";
 localents[i++] = "platform/acpi_s3";
 localents[i++] = libxl_defbool_val(info->u.hvm.acpi_s3) ? "1" : "0";
 localents[i++] = "platform/acpi_s4";
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index de16a59..12e4084 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -583,7 +583,8 @@ static int libxl__build_device_model_args_old(libxl__gc *gc,
 if (b_info->u.hvm.soundhw) {
 flexarray_vappend(dm_args, "-soundhw", b_info->u.hvm.soundhw, 
NULL);
 }
-if (libxl_defbool_val(b_info->u.hvm.acpi)) {
+if (libxl_defbool_val(b_info->acpi) &&
+libxl_defbool_val(b_info->u.hvm.acpi)) {
 flexarray_append(dm_args, "-acpi");
 }
 if (b_info->max_vcpus > 1) {
@@ -1204,7 +1205,8 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 if (b_info->u.hvm.soundhw) {
 flexarray_vappend(dm_args, "-soundhw", b_info->u.hvm.soundhw, 
NULL);
 }
-if (!libxl_defbool_val(b_info->u.hvm.acpi)) {
+if (!(libxl_defbool_val(b_info->acpi) &&
+ libxl_defbool_val(b_info->u.hvm.acpi))) {
 flexarray_append(dm_args, "-no-acpi");
 }
 if (b_info->max_vcpus > 1) {
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 98bfc3a..a02446f 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -494,11 +494,15 @@ libxl_domain_build_info = Struct("domain_build_info",[
 # Note that the partial device tree should avoid to use the phandle
 # 65000 which is reserved by the toolstack.
 ("device_tree",  string),
+("acpi", libxl_defbool),
 ("u", KeyedUnion(None, libxl_domain_type, "type",
 [("hvm", Struct(None, [("firmware", string),
("bios", libxl_bios_type),
("pae",  libxl_defbool),
("apic", libxl_defbool),
+   # The following acpi field is 
deprecated.
+   # Please use the unified acpi field 
above
+   # which works for both x86 and ARM.
("acpi", libxl_defbool),
("acpi_s3",  libxl_defbool),
("acpi_s4",  libxl_defbool),
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 1d06598..be17702 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1547,6 +1547,7 @@ static void parse_config_data(const char *config_source,
 b_info->cmdline = parse_cmdline(config);
 
 xlu_cfg_get_defbool(config, "driver_domain", _info->driver_domain, 0);
+xlu_cfg_get_defbool(config, "acpi", _info->acpi, 0);
 
 switch(b_info->type) {
 case LIBXL_DOMAIN_TYPE_HVM:
@@ -1576,7 +1577,6 @@ static void parse_config_data(const c

[Xen-devel] [PATCH v4 16/16] libxl/arm: Add the size of ACPI tables to maxmem

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

While it defines the maximum size of guest ACPI tables in guest
memory layout, here it adds the size to set the target maxmem
to avoid providing less available memory for guest.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index d436167..75b2589 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -103,6 +103,17 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
 int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
   uint32_t domid)
 {
+libxl_domain_build_info *const info = _config->b_info;
+libxl_ctx *ctx = libxl__gc_owner(gc);
+
+/* Add the size of ACPI tables to maxmem if ACPI is enabled for guest. */
+if (libxl_defbool_val(info->acpi) &&
+xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
+LIBXL_MAXMEM_CONSTANT + GUEST_ACPI_SIZE / 1024) < 0) {
+LOGE(ERROR, "Couldn't set max memory");
+return ERROR_FAIL;
+}
+
 return 0;
 }
 
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 13/16] libxl/arm: Add ACPI module

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Add the ARM Multiboot module for ACPI, so UEFI or DomU can get the base
address of ACPI tables from it.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 docs/misc/arm/device-tree/acpi.txt | 24 
 tools/libxl/libxl_arm.c| 24 
 2 files changed, 48 insertions(+)
 create mode 100644 docs/misc/arm/device-tree/acpi.txt

diff --git a/docs/misc/arm/device-tree/acpi.txt 
b/docs/misc/arm/device-tree/acpi.txt
new file mode 100644
index 000..3e70157
--- /dev/null
+++ b/docs/misc/arm/device-tree/acpi.txt
@@ -0,0 +1,24 @@
+DomU ACPI module
+
+
+Xen toolstack passes the domU ACPI tables via a reference in the /chosen node 
of
+the device tree.
+
+Each node contains the following properties:
+
+- compatible
+
+   "xen,guest-acpi", "multiboot,module"
+
+- reg
+
+   Specifies the physical address and the length of the module.
+   RSDP table is always located at the beginning of this region.
+
+Examples
+
+
+   module@0x2000 {
+   compatible = "xen,guest-acpi", "multiboot,module";
+   reg = <0x2000 0x1234>;
+   };
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index b95fdf5..11a6f6e 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -285,6 +285,25 @@ static int make_chosen_node(libxl__gc *gc, void *fdt, bool 
ramdisk,
 if (res) return res;
 }
 
+if (libxl_defbool_val(info->acpi)) {
+const uint64_t acpi_base = GUEST_ACPI_BASE;
+const char *name = GCSPRINTF("module@%"PRIx64, acpi_base);
+
+res = fdt_begin_node(fdt, name);
+if (res) return res;
+
+res = fdt_property_compat(gc, fdt, 2, "xen,guest-acpi",
+  "multiboot,module");
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1, 0, 0);
+if (res) return res;
+
+res = fdt_end_node(fdt);
+if (res) return res;
+}
+
 res = fdt_end_node(fdt);
 if (res) return res;
 
@@ -974,6 +993,11 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
+if (dom->acpi_modules[0].data) {
+finalise_one_node(gc, fdt, "/chosen/module", GUEST_ACPI_BASE,
+  dom->acpi_modules[0].length);
+}
+
 debug_dump_fdt(gc, fdt);
 
 return 0;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 10/16] libxl/arm: Construct ACPI FADT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 75dfcc2..cb1c9df 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -286,6 +286,25 @@ out:
 return rc;
 }
 
+static void make_acpi_fadt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[FADT].addr - GUEST_ACPI_BASE;
+struct acpi_table_fadt *fadt = (void *)dom->acpi_modules[0].data + offset;
+
+/* Hardware Reduced = 1 and use PSCI 0.2+ and with HVC */
+fadt->flags = ACPI_FADT_HW_REDUCED;
+fadt->arm_boot_flags = (ACPI_FADT_PSCI_COMPLIANT) | ACPI_FADT_PSCI_USE_HVC;
+
+/* ACPI v5.1 (fadt->revision.fadt->minor_revision) */
+fadt->minor_revision = 0x1;
+fadt->dsdt = acpitables[DSDT].addr;
+
+make_acpi_header(>header, "FACP", acpitables[FADT].size, 5);
+calculate_checksum(fadt, offsetof(struct acpi_table_header, checksum),
+   acpitables[FADT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -318,6 +337,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
 rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config, acpitables);
+if (rc)
+goto out;
+
+make_acpi_fadt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 06/16] libxl/arm: Construct ACPI XSDT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 9432e44..8cd1d9b 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -146,6 +146,35 @@ static void make_acpi_rsdp(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[RSDP].size);
 }
 
+static void make_acpi_header(struct acpi_table_header *h, const char *sig,
+ int len, uint8_t rev)
+{
+memcpy(h->signature, sig, 4);
+h->length = len;
+h->revision = rev;
+memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
+memcpy(h->oem_table_id, ACPI_BUILD_APPNAME4, 4);
+memcpy(h->oem_table_id + 4, sig, 4);
+h->oem_revision = 1;
+memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4);
+h->asl_compiler_revision = 1;
+h->checksum = 0;
+}
+
+static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[XSDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_xsdt *xsdt = (void *)dom->acpi_modules[0].data + offset;
+
+xsdt->table_offset_entry[0] = acpitables[MADT].addr;
+xsdt->table_offset_entry[1] = acpitables[GTDT].addr;
+xsdt->table_offset_entry[2] = acpitables[FADT].addr;
+make_acpi_header(>header, "XSDT", acpitables[XSDT].size, 1);
+calculate_checksum(xsdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[XSDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -175,6 +204,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_rsdp(gc, dom, acpitables);
+make_acpi_xsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 05/16] libxl/arm: Construct ACPI RSDP table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Construct ACPI RSDP table and add a helper to calculate the ACPI table
checksum.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 6be9eb0..9432e44 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -33,6 +33,9 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+#define ACPI_BUILD_APPNAME6 "XenARM"
+#define ACPI_BUILD_APPNAME4 "Xen "
+
 enum {
 RSDP,
 XSDT,
@@ -112,6 +115,37 @@ out:
 return rc;
 }
 
+static void calculate_checksum(void *table, uint32_t checksum_offset,
+   uint32_t length)
+{
+uint8_t *p, sum = 0;
+
+p = table;
+p[checksum_offset] = 0;
+
+while ( length-- )
+sum = sum + *p++;
+
+p = table;
+p[checksum_offset] = -sum;
+}
+
+static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[RSDP].addr - GUEST_ACPI_BASE;
+struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset;
+
+memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
+memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
+rsdp->length = acpitables[RSDP].size;
+rsdp->revision = 0x02;
+rsdp->xsdt_physical_address = acpitables[XSDT].addr;
+calculate_checksum(rsdp,
+   offsetof(struct acpi_table_rsdp, extended_checksum),
+   acpitables[RSDP].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -137,6 +171,10 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
 rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+if (rc)
+goto out;
+
+make_acpi_rsdp(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 07/16] libxl/arm: Construct ACPI GTDT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Construct GTDT table with the interrupt information of timers.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 8cd1d9b..28fb6fe 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -24,10 +24,18 @@ typedef uint8_t u8;
 typedef uint16_t u16;
 typedef uint32_t u32;
 typedef uint64_t u64;
+typedef int64_t s64;
 
 #include 
 #include 
 
+#include 
+#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
+#define COMPILER_DEPENDENT_INT64 int64_t
+#define COMPILER_DEPENDENT_UINT64 uint64_t
+
+#include 
+
 _hidden
 extern const unsigned char dsdt_anycpu_arm[];
 _hidden
@@ -175,6 +183,26 @@ static void make_acpi_xsdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[XSDT].size);
 }
 
+static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
+struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
+
+gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
+gtdt->non_secure_el1_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
+gtdt->virtual_timer_flags =
+ (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+ |(ACPI_ACTIVE_LOW << 
ACPI_GTDT_INTERRUPT_POLARITY);
+
+make_acpi_header(>header, "GTDT", acpitables[GTDT].size, 2);
+calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
+   acpitables[GTDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -205,6 +233,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
+make_acpi_gtdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 09/16] libxl/arm: Construct ACPI MADT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

According to the GIC version, construct the MADT table.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 84 
 1 file changed, 84 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 28fb6fe..75dfcc2 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -203,6 +203,89 @@ static void make_acpi_gtdt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[GTDT].size);
 }
 
+static void make_acpi_madt_gicc(void *table, int nr_cpus, uint64_t gicc_base)
+{
+uint32_t i;
+struct acpi_madt_generic_interrupt *gicc = table;
+
+for (i = 0; i < nr_cpus; i++) {
+gicc->header.type = ACPI_MADT_TYPE_GENERIC_INTERRUPT;
+gicc->header.length = sizeof(*gicc);
+gicc->base_address = gicc_base;
+gicc->cpu_interface_number = i;
+gicc->arm_mpidr = libxl__compute_mpdir(i);
+gicc->uid = i;
+gicc->flags = ACPI_MADT_ENABLED;
+gicc++;
+}
+}
+
+static void make_acpi_madt_gicd(void *table, uint64_t gicd_base,
+uint8_t gic_version)
+{
+struct acpi_madt_generic_distributor *gicd = table;
+
+gicd->header.type = ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR;
+gicd->header.length = sizeof(*gicd);
+gicd->base_address = gicd_base;
+/* This version field has no meaning before ACPI 5.1 errata. */
+gicd->version = gic_version;
+}
+
+static void make_acpi_madt_gicr(void *table, uint64_t gicr_base,
+uint64_t gicr_size)
+{
+struct acpi_madt_generic_redistributor *gicr = table;
+
+gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR;
+gicr->header.length = sizeof(*gicr);
+gicr->base_address = gicr_base;
+gicr->length = gicr_size;
+}
+
+static int make_acpi_madt(libxl__gc *gc, struct xc_dom_image *dom, int nr_cpus,
+  xc_domain_configuration_t *xc_config,
+  struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[MADT].addr - GUEST_ACPI_BASE;
+void *table = dom->acpi_modules[0].data + offset;
+struct acpi_table_madt *madt = table;
+int rc = 0;
+
+switch (xc_config->gic_version) {
+case XEN_DOMCTL_CONFIG_GIC_V2:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, nr_cpus, GUEST_GICC_BASE);
+
+table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus;
+make_acpi_madt_gicd(table, GUEST_GICD_BASE, ACPI_MADT_GIC_VERSION_V2);
+break;
+case XEN_DOMCTL_CONFIG_GIC_V3:
+table += sizeof(struct acpi_table_madt);
+make_acpi_madt_gicc(table, nr_cpus, 0);
+
+table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus;
+make_acpi_madt_gicd(table, GUEST_GICV3_GICD_BASE,
+ACPI_MADT_GIC_VERSION_V3);
+
+table += sizeof(struct acpi_madt_generic_distributor);
+make_acpi_madt_gicr(table, GUEST_GICV3_GICR0_BASE,
+GUEST_GICV3_GICR0_SIZE);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+goto out;
+}
+
+make_acpi_header(>header, "APIC", acpitables[MADT].size, 3);
+calculate_checksum(madt, offsetof(struct acpi_table_header, checksum),
+   acpitables[MADT].size);
+
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -234,6 +317,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 make_acpi_rsdp(gc, dom, acpitables);
 make_acpi_xsdt(gc, dom, acpitables);
 make_acpi_gtdt(gc, dom, acpitables);
+rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 04/16] libxl/arm: Estimate the size of ACPI tables

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Estimate the size of ACPI tables and reserve a memory map space for ACPI
tables.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 85 
 1 file changed, 85 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 087d028..6be9eb0 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -33,12 +33,95 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+enum {
+RSDP,
+XSDT,
+GTDT,
+MADT,
+FADT,
+DSDT,
+NUMS,
+};
+
+struct acpitable {
+uint64_t addr;
+size_t size;
+};
+
+static int libxl__estimate_acpi_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ struct xc_dom_image *dom,
+ xc_domain_configuration_t *xc_config,
+ struct acpitable acpitables[])
+{
+uint64_t size;
+int rc = 0;
+
+acpitables[RSDP].addr = GUEST_ACPI_BASE;
+acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+/*
+ * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+ * entries for them.
+ */
+acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+sizeof(uint64_t) * 2;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+switch (xc_config->gic_version) {
+case XEN_DOMCTL_CONFIG_GIC_V2:
+size = sizeof(struct acpi_table_madt) +
+   sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+   sizeof(struct acpi_madt_generic_distributor);
+break;
+case XEN_DOMCTL_CONFIG_GIC_V3:
+size = sizeof(struct acpi_table_madt) +
+   sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+   sizeof(struct acpi_madt_generic_distributor) +
+   sizeof(struct acpi_madt_generic_redistributor);
+break;
+default:
+LOG(ERROR, "Unknown GIC version");
+rc = ERROR_FAIL;
+goto out;
+}
+
+acpitables[MADT].size = size;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+acpitables[DSDT].size = dsdt_anycpu_arm_len;
+dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+out:
+return rc;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
 {
 const libxl_version_info *vers;
 int rc = 0;
+struct acpitable acpitables[NUMS];
+
+/* convenience aliases */
+xc_domain_configuration_t *xc_config = >config;
 
 vers = libxl_get_version_info(CTX);
 if (vers == NULL) {
@@ -53,6 +136,8 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 dom->acpi_modules[0].length = 0;
 dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
 
+rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+
 out:
 return rc;
 }
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 02/16] libxl/arm: prepare for constructing ACPI tables

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

It only constructs the ACPI tables for 64-bit ARM DomU when user enables
acpi because 32-bit DomU doesn't support ACPI.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/Makefile  |  4 +++
 tools/libxl/libxl_arm.c   | 23 +++-
 tools/libxl/libxl_arm.h   | 44 +++
 tools/libxl/libxl_arm_acpi.c  | 61 +++
 xen/include/public/arch-arm.h |  4 +++
 5 files changed, 135 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_arm.h
 create mode 100644 tools/libxl/libxl_arm_acpi.c

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index a148374..6139bed 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -90,6 +90,10 @@ acpi:
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o 
libxl_x86_acpi.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
+LIBXL_OBJS-$(CONFIG_ARM_64) += libxl_arm_acpi.o
+
+libxl_arm_acpi.o: libxl_arm_acpi.c
+   $(CC) -c $(CFLAGS) -I../../xen/include/ -o $@ libxl_arm_acpi.c
 
 ifeq ($(CONFIG_NetBSD),y)
 LIBXL_OBJS-y += libxl_netbsd.o
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index bd3d611..8c7fc09 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -1,6 +1,7 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 #include "libxl_libfdt_compat.h"
+#include "libxl_arm.h"
 
 #include 
 #include 
@@ -885,8 +886,28 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
libxl__domain_build_state *state,
struct xc_dom_image *dom)
 {
+int rc;
+
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
-return libxl__prepare_dtb(gc, info, state, dom);
+rc = libxl__prepare_dtb(gc, info, state, dom);
+if (rc) goto out;
+
+if (!libxl_defbool_val(info->acpi)) {
+LOG(DEBUG, "Generating ACPI tables is disabled by user.");
+rc = 0;
+goto out;
+}
+
+if (strcmp(dom->guest_type, "xen-3.0-aarch64")) {
+LOG(ERROR, "Can not enable libxl option 'acpi' for %s", 
dom->guest_type);
+rc = ERROR_FAIL;
+goto out;
+}
+
+rc = libxl__prepare_acpi(gc, info, state, dom);
+
+out:
+return rc;
 }
 
 static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
new file mode 100644
index 000..fe1c05f
--- /dev/null
+++ b/tools/libxl/libxl_arm.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_internal.h"
+#include "libxl_arch.h"
+
+#include 
+
+#if defined(__aarch64__)
+_hidden
+int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
+libxl__domain_build_state *state,
+struct xc_dom_image *dom);
+#else
+_hidden
+static inline int libxl__prepare_acpi(libxl__gc *gc,
+  libxl_domain_build_info *info,
+  libxl__domain_build_state *state,
+  struct xc_dom_image *dom)
+{
+return 0;
+}
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
new file mode 100644
index 000..ec6cf08
--- /dev/null
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -0,0 +1,61 @@
+/*
+ * ARM DomU ACPI generation
+ *
+ * Copyright (C) 2016  Linaro Ltd.
+ *
+ * Author: Shannon Zhao <shannon.z...@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * 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 Lesser General Public License for more details.
+ */
+
+#include "libxl_arm.h"
+
+#include 
+
+typedef uint8_t u

[Xen-devel] [PATCH v4 12/16] libxl/arm: Factor finalise_one_memory_node as a gerneric function

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Rename finalise_one_memory_node to finalise_one_node and pass the node
name via function parameter.

This is useful for adding ACPI module which will be added by a later
patch.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index fa0497c..b95fdf5 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -904,11 +904,11 @@ out:
 return rc;
 }
 
-static void finalise_one_memory_node(libxl__gc *gc, void *fdt,
- uint64_t base, uint64_t size)
+static void finalise_one_node(libxl__gc *gc, void *fdt, const char *uname,
+  uint64_t base, uint64_t size)
 {
 int node, res;
-const char *name = GCSPRINTF("/memory@%"PRIx64, base);
+const char *name = GCSPRINTF("%s@%"PRIx64, uname, base);
 
 node = fdt_path_offset(fdt, name);
 assert(node > 0);
@@ -971,7 +971,7 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc 
*gc,
 for (i = 0; i < GUEST_RAM_BANKS; i++) {
 const uint64_t size = (uint64_t)dom->rambank_size[i] << XC_PAGE_SHIFT;
 
-finalise_one_memory_node(gc, fdt, bankbase[i], size);
+finalise_one_node(gc, fdt, "/memory", bankbase[i], size);
 }
 
 debug_dump_fdt(gc, fdt);
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 08/16] libxl/arm: Factor MPIDR computing codes out as a helper

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Factor MPIDR computing codes out as a helper, so it could be shared
between DT and ACPI.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm.c |  8 +---
 tools/libxl/libxl_arm.h | 11 +++
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 8c7fc09..fa0497c 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -309,13 +309,7 @@ static int make_cpus_node(libxl__gc *gc, void *fdt, int 
nr_cpus,
 for (i = 0; i < nr_cpus; i++) {
 const char *name;
 
-/*
- * According to ARM CPUs bindings, the reg field should match
- * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
- * constructing the reg value of the guest at the moment, for it
- * is enough for the current max vcpu number.
- */
-mpidr_aff = (i & 0x0f) | (((i >> 4) & 0xff) << 8);
+mpidr_aff = libxl__compute_mpdir(i);
 name = GCSPRINTF("cpu@%"PRIx64, mpidr_aff);
 
 res = fdt_begin_node(fdt, name);
diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h
index fe1c05f..5c8fbc6 100644
--- a/tools/libxl/libxl_arm.h
+++ b/tools/libxl/libxl_arm.h
@@ -35,6 +35,17 @@ static inline int libxl__prepare_acpi(libxl__gc *gc,
 }
 #endif
 
+static inline uint64_t libxl__compute_mpdir(unsigned int cpuid)
+{
+/*
+ * According to ARM CPUs bindings, the reg field should match
+ * the MPIDR's affinity bits. We will use AFF0 and AFF1 when
+ * constructing the reg value of the guest at the moment, for it
+ * is enough for the current max vcpu number.
+ */
+return (cpuid & 0x0f) | (((cpuid >> 4) & 0xff) << 8);
+}
+
 /*
  * Local variables:
  * mode: C
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 11/16] libxl/arm: Construct ACPI DSDT table

2016-08-16 Thread Shannon Zhao
From: Shannon Zhao <shannon.z...@linaro.org>

Copy the static DSDT table into ACPI blob.

Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index cb1c9df..3154e0c 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -305,6 +305,15 @@ static void make_acpi_fadt(libxl__gc *gc, struct 
xc_dom_image *dom,
acpitables[FADT].size);
 }
 
+static void make_acpi_dsdt(libxl__gc *gc, struct xc_dom_image *dom,
+   struct acpitable acpitables[])
+{
+uint64_t offset = acpitables[DSDT].addr - GUEST_ACPI_BASE;
+void *dsdt = dom->acpi_modules[0].data + offset;
+
+memcpy(dsdt, dsdt_anycpu_arm, dsdt_anycpu_arm_len);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom)
@@ -341,6 +350,7 @@ int libxl__prepare_acpi(libxl__gc *gc, 
libxl_domain_build_info *info,
 goto out;
 
 make_acpi_fadt(gc, dom, acpitables);
+make_acpi_dsdt(gc, dom, acpitables);
 
 out:
 return rc;
-- 
2.0.4



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 14/23] acpi: Move ACPI code to tools/libacpi

2016-08-16 Thread Shannon Zhao


On 2016/8/16 16:29, Wei Liu wrote:
> On Tue, Aug 16, 2016 at 04:13:06PM +0800, Shannon Zhao wrote:
> [...]
>> > Not sure if I do something wrong, but I got bellow errors when compiling
>> > this series on x86 just using "./autogen.sh;./configure;make tools".
>> > 
>> > In file included from tcgbios.c:26:0:
>> > ../util.h:4:39: fatal error: ../hvmloader/acpi/acpi2_0.h: No such file
>> > or directory
>> >  #include "../hvmloader/acpi/acpi2_0.h"
>> > 
>> > In file included from tpm_drivers.c:24:0:
>> > ../util.h:4:39: fatal error: ../hvmloader/acpi/acpi2_0.h: No such file
>> > or directory
>> >  #include "../hvmloader/acpi/acpi2_0.h"
>> > 
> I don't think this is caused by your environment.
> 
> Please rebase everything on top of staging. There is a fix there.
You mean the commit "cc38370 hvmloader: include libacpi.h instead of
acpi2_0.h in rombios.c", right?

If so, I don't think it's relevant to this problem because this patch
moves acpi2_0.h under tools/libacpi/ but it doesn't update in the path
in tools/firmware/rombios/32bit/util.h

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 14/23] acpi: Move ACPI code to tools/libacpi

2016-08-16 Thread Shannon Zhao
Hi,

On 2016/8/5 5:06, Boris Ostrovsky wrote:
> Signed-off-by: Boris Ostrovsky 
> Acked-by: Jan Beulich 
> ---
> v2:
> * Minor cleanup of hvmloader's Makefile
> 
>  tools/firmware/hvmloader/Makefile  | 14 
> --
>  tools/firmware/hvmloader/ovmf.c|  2 +-
>  tools/{firmware/hvmloader/acpi => libacpi}/Makefile|  2 +-
>  tools/{firmware/hvmloader/acpi => libacpi}/README  |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/acpi2_0.h   |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/build.c |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/dsdt.asl|  0
>  tools/{firmware/hvmloader/acpi => libacpi}/libacpi.h   |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/mk_dsdt.c   |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/ssdt_pm.asl |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/ssdt_s3.asl |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/ssdt_s4.asl |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/ssdt_tpm.asl|  0
>  tools/{firmware/hvmloader/acpi => libacpi}/static_tables.c |  0
>  tools/{firmware/hvmloader/acpi => libacpi}/x86.h   |  0
>  15 files changed, 10 insertions(+), 8 deletions(-)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/Makefile (98%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/README (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/acpi2_0.h (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/build.c (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/dsdt.asl (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/libacpi.h (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/mk_dsdt.c (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/ssdt_pm.asl (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/ssdt_s3.asl (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/ssdt_s4.asl (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/ssdt_tpm.asl (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/static_tables.c (100%)
>  rename tools/{firmware/hvmloader/acpi => libacpi}/x86.h (100%)
> 
> diff --git a/tools/firmware/hvmloader/Makefile 
> b/tools/firmware/hvmloader/Makefile
> index db64a61..694d9f1 100644
> --- a/tools/firmware/hvmloader/Makefile
> +++ b/tools/firmware/hvmloader/Makefile
> @@ -20,9 +20,6 @@
>  XEN_ROOT = $(CURDIR)/../../..
>  include $(XEN_ROOT)/tools/firmware/Rules.mk
>  
> -export ACPI_BUILD_DIR=$(shell pwd)
> -SUBDIRS := acpi
> -
>  # The HVM loader is started in 32-bit mode at the address below:
>  LOADADDR = 0x10
>  
> @@ -67,16 +64,20 @@ ROMS += $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) 
> $(ETHERBOOT_ROMS)
>  endif
>  
>  .PHONY: all
> -all: subdirs-all
> +all: acpi subdirs-all
>   $(MAKE) hvmloader
>  
> +.PHONY: acpi
> +acpi:
> + $(MAKE) -C $(ACPI_PATH)  ACPI_BUILD_DIR=$(CURDIR)
> +
>  rombios.o: roms.inc
>  smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\""
>  
> -ACPI_PATH = ./acpi
> +ACPI_PATH = ../../libacpi
>  ACPI_FILES = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c
>  ACPI_OBJS = $(patsubst %.c,%.o,$(ACPI_FILES)) build.o static_tables.o
> -$(ACPI_OBJS): CFLAGS += -I. -DSTDUTILS=\"../util.h\"
> +$(ACPI_OBJS): CFLAGS += -I. -DSTDUTILS=\"$(CURDIR)/util.h\"

Not sure if I do something wrong, but I got bellow errors when compiling
this series on x86 just using "./autogen.sh;./configure;make tools".

In file included from tcgbios.c:26:0:
../util.h:4:39: fatal error: ../hvmloader/acpi/acpi2_0.h: No such file
or directory
 #include "../hvmloader/acpi/acpi2_0.h"

In file included from tpm_drivers.c:24:0:
../util.h:4:39: fatal error: ../hvmloader/acpi/acpi2_0.h: No such file
or directory
 #include "../hvmloader/acpi/acpi2_0.h"

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 23/23] libxc/xc_dom_core: Copy ACPI tables to guest space

2016-08-15 Thread Shannon Zhao


On 2016/8/15 20:49, Boris Ostrovsky wrote:
> On 08/15/2016 03:48 AM, Shannon Zhao wrote:
>> Hi Boris
>>
>> On 2016/8/5 5:06, Boris Ostrovsky wrote:
>>> Load ACPI modules into guest space
>>>
>>> Signed-off-by: Boris Ostrovsky <boris.ostrov...@oracle.com>
>>> ---
>>> v2:
>>> * New patch, loosely based on Shannon's ARM patch
>>>
>>>  tools/libxc/xc_dom_core.c | 92 
>>> +++
>>>  1 file changed, 92 insertions(+)
>>>
>>> diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c
>>> index ebada89..00d870f 100644
>>> --- a/tools/libxc/xc_dom_core.c
>>> +++ b/tools/libxc/xc_dom_core.c
>>> @@ -1040,6 +1040,94 @@ static int xc_dom_build_ramdisk(struct xc_dom_image 
>>> *dom)
>>>  return -1;
>>>  }
>>>  
>>> +static int populate_acpi_pages(struct xc_dom_image *dom,
>>> +   xen_pfn_t *extents,
>>> +   unsigned int num_pages)
>>> +{
>>> +int rc;
>>> +xc_interface *xch = dom->xch;
>>> +uint32_t domid = dom->guest_domid;
>>> +unsigned long idx, first_high_idx = (1ull << (32 - 12));
>>> +
>>> +for ( ; num_pages; num_pages--, extents++ )
>>> +{
>>> +
>>> +if ( xc_domain_populate_physmap(xch, domid, 1, 0, 0, extents) == 1 
>>> )
>>> +continue;
>>> +
>>> +if (dom->highmem_end)
>>> +{
>>> +idx = --dom->highmem_end;
>>> +if ( idx == first_high_idx )
>>> +dom->highmem_end = 0;
>>> +}
>>> +else
>>> +idx = --dom->lowmem_end;
>>> +
>>> +rc = xc_domain_add_to_physmap(xch, domid,
>>> +  XENMAPSPACE_gmfn,
>>> +  idx, *extents);
>>> +if (rc)
>>> +return rc;
>>> +}
>>> +
>>> +return 0;
>>> +}
>>> +
>>> +static int xc_dom_load_acpi(struct xc_dom_image *dom)
>>> +{
>>> +int j, i = 0;
>>> +unsigned num_pages;
>>> +xen_pfn_t *extents, base;
>>> +void *ptr;
>>> +
>>> +while ( (i < MAX_ACPI_MODULES) && dom->acpi_modules[i].length )
>>> +{
>>> +DOMPRINTF("%s: %d bytes at address %lx\n", __FUNCTION__,
>>> +  dom->acpi_modules[i].length,
>>> +  dom->acpi_modules[i].guest_addr_out);
>>> +
>>> +num_pages = (dom->acpi_modules[i].length + (XC_PAGE_SIZE - 1)) >>
>>> +   XC_PAGE_SHIFT;
>>> +extents = malloc(num_pages * sizeof(*extents));
>>> +if ( !extents )
>>> +{
>>> +DOMPRINTF("%s: Out of memory", __FUNCTION__);
>>> +goto err;
>>> +}
>>> +
>>> +base = dom->acpi_modules[i].guest_addr_out >> XC_PAGE_SHIFT;
>>> +for (j=0; j<num_pages; j++)
>>> +extents[j] = base + j;
>>> +if ( populate_acpi_pages(dom, extents, num_pages) )
>>> +{
>>> +DOMPRINTF("%s: Can populate ACPI pages", __FUNCTION__);
>>> +goto err;
>>> +}
>>> +
>>> +ptr = xc_map_foreign_range(dom->xch, dom->guest_domid,
>>> +  XC_PAGE_SIZE * num_pages,
>>> +  PROT_READ | PROT_WRITE, base);
>>> +if ( !ptr )
>>> +{
>>> +DOMPRINTF("%s: Can't map %d pages at 0x%lx",
>>> +  __FUNCTION__, num_pages, base);
>>> +goto err;
>>> +}
>>> +
>>> +memcpy(ptr, dom->acpi_modules[i].data, 
>>> dom->acpi_modules[i].length);
>>> +
>>> +free(extents);
>>> +i++;
>>> +}
>>> +
>>> +return 0;
>>> +
>>> +err:
>>> +free(extents);
>>> +return -1;
>>> +}
>>> +
>>>  int xc_dom_build_image(struct xc_dom_image *dom)
>>>  {
>>>  unsigned int page_size;
>>> @@ -1097,6 +1185,10 @@ int xc_dom_build_image(struct xc_dom_image *dom)
>>>  memcpy(devicetreemap, dom->devicetree_blob, dom->devicetree_size);
>>>  }
>>>  
>>> +/* load ACPI tables */
>>> +if ( xc_dom_load_acpi(dom) != 0 )
>>> +goto err;
>> I think it needs to move the definition of xc_dom_load_acpi() to
>> xc_dom_x86.c while I will move the corresponding one of ARM to xc_dom_arm.c.
> 
> 
> You don't think both x86 and ARM can use the same definition?  This
> looks very similar to what you had in your series.
> 
So I have to use dom->acpi_modules[i] in my series instead of
dom->acpitable_blob. I think it's fine to reuse what x86 uses.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v7 05/15] libxl: Load guest BIOS from file

2016-08-15 Thread Shannon Zhao


On 2016/8/15 17:09, Wei Liu wrote:
> On Mon, Aug 15, 2016 at 05:04:20PM +0800, Shannon Zhao wrote:
> [...]
>>> > >  
>>> > > +const char *libxl__seabios_path(void)
>>> > > +{
>>> > > +return SEABIOS_PATH;
>>> > > +}
>>> > > +
>>> > > +const char *libxl__ovmf_path(void)
>>> > > +{
>>> > > +return OVMF_PATH;
>>> > > +}
>>> > > +
>> > Hi, I got bellow errors when compiling on ARM.
>> > 
>> > libxl_paths.c: In function 'libxl__seabios_path':
>> > libxl_paths.c:40:12: error: 'SEABIOS_PATH' undeclared (first use in this
>> > function)
>> >  return SEABIOS_PATH;
>> > ^
>> > libxl_paths.c:40:12: note: each undeclared identifier is reported only
>> > once for each function it appears in
>> > libxl_paths.c: In function 'libxl__ovmf_path':
>> > libxl_paths.c:45:12: error: 'OVMF_PATH' undeclared (first use in this
>> > function)
>> >  return OVMF_PATH;
>> > ^
>> > libxl_paths.c: In function 'libxl__seabios_path':
>> > libxl_paths.c:41:1: error: control reaches end of non-void function
>> > [-Werror=return-type]
>> >  }
>> >  ^
>> > libxl_paths.c: In function 'libxl__ovmf_path':
>> > libxl_paths.c:46:1: error: control reaches end of non-void function
>> > [-Werror=return-type]
>> >  }
>> >  ^
>> > cc1: all warnings being treated as errors
>> > 
> Have you tried to run ./autogen.sh in xen.git top-level directory?
Eh, I only ran ./configure and make dist-tools as before. ./autogen.sh
makes it work.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v7 05/15] libxl: Load guest BIOS from file

2016-08-15 Thread Shannon Zhao


On 2016/7/28 18:50, Anthony PERARD wrote:
> The path to the BIOS blob can be overriden by the xl's
> bios_path_override option, or provided by u.hvm.bios_firmware in the
> domain_build_info struct by other libxl user.
> 
> Signed-off-by: Anthony PERARD 
> Acked-by: Wei Liu 
> 
> ---
> Changes in V6:
> - use goto for error handling of libxl__load_hvm_firmware_module()
> 
> Changes in V5:
> - man page, use B<> to highlight config option in description.
> - rename config option from `bios_override` to `bios_path_override`
> - store libxl_read_file_contents() return value into r instead of e
>   (just renamed the variable)
> - rename domain_build_info.u.hvm.bios_firmware to system_firmware
> 
> Changes in V4:
> - updating man page to have bios_override described.
> - return ERROR_INVAL in libxl__load_hvm_firmware_module when the file is
>   empty.
> 
> Changes in V3:
> - move seabios_path and ovmf_path to libxl_path.c (with renaming)
> - fix some coding style
> - warn for empty file
> - remove rombios stuff (will still be built-in hvmloader)
> - rename field bios_filename in domain_build_info to bios_firmware to
>   follow naming of acpi and smbios.
> - log an error after libxl_read_file_contents() only when it return ENOENT
> - return an error on empty file.
> - added #define LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE
> ---
>  docs/man/xl.cfg.pod.5.in |  9 +++
>  tools/libxl/libxl.h  |  8 ++
>  tools/libxl/libxl_dom.c  | 61 
> 
>  tools/libxl/libxl_internal.h |  2 ++
>  tools/libxl/libxl_paths.c| 10 
>  tools/libxl/libxl_types.idl  |  1 +
>  tools/libxl/xl_cmdimpl.c | 11 +---
>  7 files changed, 99 insertions(+), 3 deletions(-)
> 
> diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
> index 3bb27d0..a685b83 100644
> --- a/docs/man/xl.cfg.pod.5.in
> +++ b/docs/man/xl.cfg.pod.5.in
> @@ -1212,6 +1212,15 @@ Requires device_model_version=qemu-xen.
>  
>  =back
>  
> +=item 

Re: [Xen-devel] [PATCH v2 23/23] libxc/xc_dom_core: Copy ACPI tables to guest space

2016-08-15 Thread Shannon Zhao
Hi Boris

On 2016/8/5 5:06, Boris Ostrovsky wrote:
> Load ACPI modules into guest space
> 
> Signed-off-by: Boris Ostrovsky 
> ---
> v2:
> * New patch, loosely based on Shannon's ARM patch
> 
>  tools/libxc/xc_dom_core.c | 92 
> +++
>  1 file changed, 92 insertions(+)
> 
> diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c
> index ebada89..00d870f 100644
> --- a/tools/libxc/xc_dom_core.c
> +++ b/tools/libxc/xc_dom_core.c
> @@ -1040,6 +1040,94 @@ static int xc_dom_build_ramdisk(struct xc_dom_image 
> *dom)
>  return -1;
>  }
>  
> +static int populate_acpi_pages(struct xc_dom_image *dom,
> +   xen_pfn_t *extents,
> +   unsigned int num_pages)
> +{
> +int rc;
> +xc_interface *xch = dom->xch;
> +uint32_t domid = dom->guest_domid;
> +unsigned long idx, first_high_idx = (1ull << (32 - 12));
> +
> +for ( ; num_pages; num_pages--, extents++ )
> +{
> +
> +if ( xc_domain_populate_physmap(xch, domid, 1, 0, 0, extents) == 1 )
> +continue;
> +
> +if (dom->highmem_end)
> +{
> +idx = --dom->highmem_end;
> +if ( idx == first_high_idx )
> +dom->highmem_end = 0;
> +}
> +else
> +idx = --dom->lowmem_end;
> +
> +rc = xc_domain_add_to_physmap(xch, domid,
> +  XENMAPSPACE_gmfn,
> +  idx, *extents);
> +if (rc)
> +return rc;
> +}
> +
> +return 0;
> +}
> +
> +static int xc_dom_load_acpi(struct xc_dom_image *dom)
> +{
> +int j, i = 0;
> +unsigned num_pages;
> +xen_pfn_t *extents, base;
> +void *ptr;
> +
> +while ( (i < MAX_ACPI_MODULES) && dom->acpi_modules[i].length )
> +{
> +DOMPRINTF("%s: %d bytes at address %lx\n", __FUNCTION__,
> +  dom->acpi_modules[i].length,
> +  dom->acpi_modules[i].guest_addr_out);
> +
> +num_pages = (dom->acpi_modules[i].length + (XC_PAGE_SIZE - 1)) >>
> +   XC_PAGE_SHIFT;
> +extents = malloc(num_pages * sizeof(*extents));
> +if ( !extents )
> +{
> +DOMPRINTF("%s: Out of memory", __FUNCTION__);
> +goto err;
> +}
> +
> +base = dom->acpi_modules[i].guest_addr_out >> XC_PAGE_SHIFT;
> +for (j=0; j +extents[j] = base + j;
> +if ( populate_acpi_pages(dom, extents, num_pages) )
> +{
> +DOMPRINTF("%s: Can populate ACPI pages", __FUNCTION__);
> +goto err;
> +}
> +
> +ptr = xc_map_foreign_range(dom->xch, dom->guest_domid,
> +  XC_PAGE_SIZE * num_pages,
> +  PROT_READ | PROT_WRITE, base);
> +if ( !ptr )
> +{
> +DOMPRINTF("%s: Can't map %d pages at 0x%lx",
> +  __FUNCTION__, num_pages, base);
> +goto err;
> +}
> +
> +memcpy(ptr, dom->acpi_modules[i].data, dom->acpi_modules[i].length);
> +
> +free(extents);
> +i++;
> +}
> +
> +return 0;
> +
> +err:
> +free(extents);
> +return -1;
> +}
> +
>  int xc_dom_build_image(struct xc_dom_image *dom)
>  {
>  unsigned int page_size;
> @@ -1097,6 +1185,10 @@ int xc_dom_build_image(struct xc_dom_image *dom)
>  memcpy(devicetreemap, dom->devicetree_blob, dom->devicetree_size);
>  }
>  
> +/* load ACPI tables */
> +if ( xc_dom_load_acpi(dom) != 0 )
> +goto err;
I think it needs to move the definition of xc_dom_load_acpi() to
xc_dom_x86.c while I will move the corresponding one of ARM to xc_dom_arm.c.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 00/23] Make ACPI builder available to components other than hvmloader

2016-08-15 Thread Shannon Zhao


On 2016/8/5 5:06, Boris Ostrovsky wrote:
> The goal here is to build ACPI tables for PVHv2/HVMlite guests while reusing 
> existing
> hvmloader's ACPI builder code. The builder is provided as a library in 
> tools/libacpi.
> 
> This version is built on top of Anthony's 
> git://xenbits.xen.org/people/aperard/xen-unstable.git:hvmloader-with-separated-bios-v7
> 
> It also requires (still not fully ACKed, sigh) ACPI relicensing patch
> https://lists.xenproject.org/archives/html/xen-devel/2016-07/msg01975.html
> 
Hi Boris,
Is there a git repo from which I cloud fetch this series? I didn't find
them in https://oss.oracle.com/git/?p=bostrovs/xen.git;a=summary

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 16/17] libxc/xc_dom_arm: Copy ACPI tables to guest space

2016-07-28 Thread Shannon Zhao
On 2016年07月28日 19:06, Julien Grall wrote:
> On 26/07/16 02:17, Boris Ostrovsky wrote:
>> On 07/25/2016 07:40 PM, Stefano Stabellini wrote:
>>> On Mon, 25 Jul 2016, Boris Ostrovsky wrote:
 On 07/25/2016 06:06 PM, Stefano Stabellini wrote:
> On Mon, 25 Jul 2016, George Dunlap wrote:
>> On Thu, Jul 21, 2016 at 10:15 PM, Stefano Stabellini
>>  wrote:
> Going back to the discussion about how to account for the ACPI blob in
> maxmem, let's make this simple, if we increase maxmem by the size of
> the
> ACPI blob:
>
> - the toolstack allocates more RAM than expected (bad)
> - when the admin specifies 1GB of RAM, the guest actually gets 1GB of
>usable RAM (good)
> - things are faster as Xen and the guest can exploit superpage
> mappings
>more easily at stage-1 and stage-2 (good)
>
> Let's call this option A.
>
> If we do not increase maxmem:
>
> - the toolstack allocates less RAM, closer to the size specified in
> the
>VM config file (good)
> - the guest gets less usable memory than expected, less than what was
>specified in the VM config file (bad)

 Not sure I agree with this, at least for x86/Linux: guest gets 1GB of
 usable RAM and part of that RAM stores ACPI stuff. Guest is free to
 stash ACPI tables somewhere else or ignore them altogether and use that
 memory for whatever it wants.
>>> On ARM it will be a ROM (from guest POV)
>>
>>
>> In which case I don't see why we should take it from maxmem allocation.
>> I somehow thought that there was a choice of whether to put it in ROM or
>> RAM on ARM but if it's ROM only then I don't think there is an option.
> 
> We have option to do the both on ARM. I just feel that the ROM option is
> a cleaner interface because the ACPI tables are not supposed be modified
> by the guest, so we can prevent to be overridden (+ all the advantages
> mentioned by Stefano with option A).
> 
>> IIUIC the toolstack pretends that the blob goes to memory because that's
>> how its interfaces work but that space is not really what we think about
>> when we set memory/maxmem in the configuration file. Unlike x86.
> 
> I think we need to draw a conclusion for Shannon to continue to do the
> work and I would like to see this series in Xen 4.8. From my
> understanding you are for option B, so does George.
> 
> Stefano votes for option A, but find B acceptable. Any other opinions?
I agree with Stefano, both are fine.

Thanks,
-- 
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 16/17] libxc/xc_dom_arm: Copy ACPI tables to guest space

2016-07-25 Thread Shannon Zhao


On 2016/7/20 17:32, Wei Liu wrote:
> On Wed, Jul 20, 2016 at 02:52:05PM +0800, Shannon Zhao wrote:
>> > 
>> > 
>> > On 2016/7/19 18:38, Wei Liu wrote:
>>> > > On Fri, Jul 15, 2016 at 05:39:32PM +0800, Shannon Zhao wrote:
>>> > > [...]
>>>>>>> > >>> > > 
>>>>>>> > >>> > > It would be trivial to have another option in xl.cfg to allow 
>>>>>>> > >>> > > MB
>>>>>>> > >>> > > granularity. But I don't think that's a good idea. Asking for 
>>>>>>> > >>> > > more
>>>>>>> > >>> > > memory when you don't really know how much is enough is not 
>>>>>>> > >>> > > very useful.
>>>>>>> > >>> > > If an admin can know how much is needed, surely the library 
>>>>>>> > >>> > > can be
>>>>>>> > >>> > > taught to obtain that knowledge, too.
>>>>>>> > >>> > > 
>>>>>>> > >>> > > We need to decide which model we should go with. And, if we 
>>>>>>> > >>> > > decide to
>>>>>>> > >>> > > diverge, document the difference between x86 and ARM model.
>>>>>>> > >>> > > 
>>>>> > >> > Hi Wei,
>>>>> > >> > 
>>>>> > >> > Do you decide how to add the size of ACPI blob to max_memkb?
>>>>> > >> > 
>>> > > AFAICT ARM and x86 maintainers hold different opinions on how memory
>>> > > should be accounted.
>>> > > 
>>> > > I would like to have a unified memory accounting model. But if we can't
>>> > > have that at the moment, I'm fine with divergence, but please document
>>> > > it somewhere (comment near code snippet, in header, or a file under docs
>>> > > etc). And the amount added to max_memkb needs to be properly calculated,
>>> > > not some magic number, so that we have a chance in the future to
>>> > > confidently change how we do thing.
>> > If it's only allowed to add the size to max_memkb in
>> > libxl__domain_build_info_setdefault(), it only can use a const number
>> > since the tables are not generted and we don;t know the size. But the
>> > const number could be chosen properly since we could know the maximum
>> > ACPI tables size of current ARM approach.
>> > 
>> > But maybe in the future, if we add some new ACPI tables, it should
>> > increase the size as well. So I think this should be documented.
>> > 
>> > As I asked before, is it ok to add the size to max_memkb after
>> > generating the ACPI tables and before loading the tables to guest space?
>> > 
> Yes. I don't think shoehorning everything into setdefault is a good
> idea.
> 
> I think libxl_arm.c:libxl__arch_domain_create would be the right place
> to do it.
> 
> I am thinking about calling xc_domain_setmaxmem there, but not adding a
> number to d_config->b_info.max_memkb. Adding that to ->max_memkb would
> be wrong because the bigger ->max_memkb will be recored and the same
> algorithm will be applied every time you migrate your guest, so the
> max_memkb will grow bigger and bigger.
> 
> Given the different approach taken by ARM and x86, maybe we need to also
> record the size of acpi blobs somewhere in xenstore (also needs to be
> documented) so that subsequent libxl_domain_setmaxmem can extract that
> number again.
> 
> Please wait a bit for Stefano and Julien to comment before you do work.
> 
Stefano, Julien,
Any comments regarding how to add the ACPI size to max_memkb?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 16/17] libxc/xc_dom_arm: Copy ACPI tables to guest space

2016-07-20 Thread Shannon Zhao


On 2016/7/19 18:38, Wei Liu wrote:
> On Fri, Jul 15, 2016 at 05:39:32PM +0800, Shannon Zhao wrote:
> [...]
>>> > > 
>>> > > It would be trivial to have another option in xl.cfg to allow MB
>>> > > granularity. But I don't think that's a good idea. Asking for more
>>> > > memory when you don't really know how much is enough is not very useful.
>>> > > If an admin can know how much is needed, surely the library can be
>>> > > taught to obtain that knowledge, too.
>>> > > 
>>> > > We need to decide which model we should go with. And, if we decide to
>>> > > diverge, document the difference between x86 and ARM model.
>>> > > 
>> > Hi Wei,
>> > 
>> > Do you decide how to add the size of ACPI blob to max_memkb?
>> > 
> AFAICT ARM and x86 maintainers hold different opinions on how memory
> should be accounted.
> 
> I would like to have a unified memory accounting model. But if we can't
> have that at the moment, I'm fine with divergence, but please document
> it somewhere (comment near code snippet, in header, or a file under docs
> etc). And the amount added to max_memkb needs to be properly calculated,
> not some magic number, so that we have a chance in the future to
> confidently change how we do thing.
If it's only allowed to add the size to max_memkb in
libxl__domain_build_info_setdefault(), it only can use a const number
since the tables are not generted and we don;t know the size. But the
const number could be chosen properly since we could know the maximum
ACPI tables size of current ARM approach.

But maybe in the future, if we add some new ACPI tables, it should
increase the size as well. So I think this should be documented.

As I asked before, is it ok to add the size to max_memkb after
generating the ACPI tables and before loading the tables to guest space?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 16/17] libxc/xc_dom_arm: Copy ACPI tables to guest space

2016-07-15 Thread Shannon Zhao


On 2016/7/14 19:15, Wei Liu wrote:
> On Wed, Jul 13, 2016 at 01:08:57PM -0400, Boris Ostrovsky wrote:
>> On 07/13/2016 11:22 AM, Julien Grall wrote:
>>> Hello,
>>>
>>> On 12/07/2016 17:58, Boris Ostrovsky wrote:
>>>> On 07/12/2016 12:10 PM, Julien Grall wrote:
>>>>> On 12/07/2016 16:08, Boris Ostrovsky wrote:
>>>>>> On 07/12/2016 10:57 AM, Shannon Zhao wrote:
>>>>>>> On 2016年07月12日 22:50, Wei Liu wrote:
>>>>>>>> On Tue, Jul 12, 2016 at 10:42:07PM +0800, Shannon Zhao wrote:
>>>>>>>>>>>>>>>>>>>>>>>>>>>> Does it mean we would need to update the slack
>>>>>>>>>>>>>>>>>>>>>>>>>>>> to take into account the ACPI
>>>>>>>>>>>>>>>>>>>>>>>>>>>> blob?
>>>>>>>>>>>>>>>>>>>> Yes, we need to take into account the ACPI blob.
>>>>>>>>>>>>>>>>>>>> Probably not in the
>>>>>>>>>>>>>>>>>>>> slack but directly in mam_memkb.
>>>>>>>>>>>>>>>> Sorry, I'm not sure understand this. I found the
>>>>>>>>>>>>>>>> b_info->max_memkb but
>>>>>>>>>>>>>>>> didn't find the slack you said. And how to fix this? Update
>>>>>>>>>>>>>>>> b_info->max_memkb or the slack?
>>>>>>>>>>>> Can you calculate the size of your payload and add that to
>>>>>>>>>>>> max_memkb?
>>>>>>>>>>>>
>>>>>>>>>> Yeah, but the size will be changed if we change the tables in the
>>>>>>>>>> future
>>>>>>>>>> and this also should consider x86, right?
>>>>>>>> That could easily be solved by introducing a function to
>>>>>>>> calculate the
>>>>>>>> size, right?
>>>>>>> Oh, I'm not familiar with this. Let's clarify on this. It can add the
>>>>>>> size to max_memkb after generating the ACPI tables and before loading
>>>>>>> the tables to guest space and it doesn't have to add the size at
>>>>>>> libxl__domain_build_info_setdefault(), right?
>>>>>>
>>>>>> This was discussed before: ACPI tables are part of RAM whose size is
>>>>>> specified by the config file (and is reflected in max_memkb I
>>>>>> believe).
>>>>>> It may not be presented to the guest as RAM (i.e. on x86 it is labeled
>>>>>> by BIOS (or whoever) as a dedicated type in e820) but it still resides
>>>>>> in DIMMs.
>>>>>
>>>>> I don't think this was the conclusion of the thread. IHMO, "maxmem" is
>>>>> the amount of RAM a guest could effectively use.
>>>>>
>>>>> Whilst the ACPI tables will be in the DIMM from the host point of
>>>>> view. From a guest point of view it will be a ROM.
>>>>
>>>> The config file specifies resources provided by the host. How the guest
>>>> views those resources is not important, I think.
>>>
>>> This would need to be clarified. For instance special pages (Xenstore,
>>> Console...) are RAM from the host point of view but not taken into
>>> account in the "maxmem" provided by the user. For my understanding,
>>> some kB of the slack is used for that.
>>
>>
>> Are these pages part of guest's address space?
>>
>>
>>>
>>>>
>>>>>
>>>>> It will affect some others part of the guest if we don't increment the
>>>>> "maxmem" requested by the user. For ARM the ACPI blob will be exposed
>>>>> at a specific address that is outside of the guest RAM (see the guest
>>>>> memory layout in public/arch-arm.h).
>>>>>
>>>>> We chose this solution over putting in the RAM because the ACPI tables
>>>>> are not easily relocatable (compare to the device tree, initrd and
>>>>> kernel) so we could not take advantage of superpage in both stage-2
>>>>> (hypervisor) and stage-1 (kernel) page table.
>>>>
>>>> Maybe this is something ARM-specific then. For x86 we will want to keep
>>>> maxmem unchanged.
>>>
>>> I don't think what I described in my previous mail is ARM-specific.
>>> The pressure will be more important on the TLBs, if Xen does not use
>>> superpage in the stage 2 page tables (i.e EPT for x86) no matter the
>>> architecture.
>>>
>>> IHMO, this seems to be a bigger drawback compare to add few more
>>> kilobytes to maxmem in the toolstack for the ACPI blob. You will loose
>>> them when creating the intermediate page table in any case.
>>
>>
>> Why not have the guest ask for more memory in the config file then?
>>
>> (OK, I can see that they can't ask for a few KB since we have MB
>> resolution but they can ask for an extra 1MB)
>>
> 
> It would be trivial to have another option in xl.cfg to allow MB
> granularity. But I don't think that's a good idea. Asking for more
> memory when you don't really know how much is enough is not very useful.
> If an admin can know how much is needed, surely the library can be
> taught to obtain that knowledge, too.
> 
> We need to decide which model we should go with. And, if we decide to
> diverge, document the difference between x86 and ARM model.
> 
Hi Wei,

Do you decide how to add the size of ACPI blob to max_memkb?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI

2016-07-15 Thread Shannon Zhao


On 2016/7/15 16:00, Shannon Zhao wrote:
> 
> 
> On 2016/7/13 18:03, Julien Grall wrote:
>>
>>
>> On 13/07/2016 10:48, Shannon Zhao wrote:
>>>
>>>
>>> On 2016/7/13 17:20, Julien Grall wrote:
>>>> On 13/07/2016 08:54, Shannon Zhao wrote:
>>>>> On 2016/7/12 19:33, Wei Liu wrote:
>>>>>> On Tue, Jul 12, 2016 at 10:22:39AM +0100, Julien Grall wrote:
>>>>>> [...]
>>>>>>>>> Yeah, we can deprecate that field. But we need to take care to not
>>>>>>>>> break
>>>>>>>>> users of the old field.
>>>>>>>> Ok, what name would you suggest?
>>>>>>>
>>>>>>> I would suggest b_info->u.acpi
>>>>>>>
>>>>>>
>>>>>> b_info->acpi would be more appropriate.
>>>>>>
>>>>>> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>>>>>> index ef614be..a57823d 100644
>>>>>> --- a/tools/libxl/libxl_types.idl
>>>>>> +++ b/tools/libxl/libxl_types.idl
>>>>>> @@ -494,11 +494,16 @@ libxl_domain_build_info =
>>>>>> Struct("domain_build_info",[
>>>>>>  # Note that the partial device tree should avoid to use the
>>>>>> phandle
>>>>>>  # 65000 which is reserved by the toolstack.
>>>>>>  ("device_tree",  string),
>>>>>> +("acpi", libxl_defbool),
>>>>>>  ("u", KeyedUnion(None, libxl_domain_type, "type",
>>>>>>  [("hvm", Struct(None, [("firmware", string),
>>>>>> ("bios",
>>>>>> libxl_bios_type),
>>>>>> ("pae",
>>>>>> libxl_defbool),
>>>>>> ("apic",
>>>>>> libxl_defbool),
>>>>>> +   # The following acpi field is
>>>>>> +   # deprecated. Please use the
>>>>>> unified
>>>>>> +   # acpi field above which
>>>>>> works for both
>>>>>> +   # x86 and ARM.
>>>>>> ("acpi",
>>>>>> libxl_defbool),
>>>>>> ("acpi_s3",
>>>>>> libxl_defbool),
>>>>>> ("acpi_s4",
>>>>>> libxl_defbool),
>>>>>>
>>>>>>
>>>>>> And then:
>>>>>>
>>>>>> 1. modify xl to set the new field.
>>>>>> 2. modify libxl to handle compatibility: user of the old field should
>>>>>>continue to work.
>>>>>>
>>>>> I found that the default value of acpi is true on x86. But we decided
>>>>> before it's should be false by default on ARM. How to deal with this?
>>>>> Julien, Stefano, can we make acpi true by default?
>>>>
>>>> I already said that I am not in favor of making ACPI true by default at
>>>> least for ARM 32-bit guest.
>>>>
>>>> ARM 32-bit guest will not use ACPI, if we decide to enable it by
>>>> default, we will require the user to install iasl for nothing.
>>>>
>>>> IHMO, ACPI should be disabled by default for any ARM guests. Libxl can
>>>> take this decision easily.
>>> I know but here we want to unify the acpi option for x86 and ARM while
>>> on x86 it's true by default. What I want to ask is that how to
>>> distinguish x86 and ARM in libxl__domain_build_info_setdefault(), so we
>>> can assign acpi with different default value for x86 and ARM.
>>
>> By using #ifdef in the code?
> Maybe this could not work since CONFIG_ARM can not be accessed in libxl
> in current codes. I'm not sure why it can't work. Wei, do you have any
> suggestion?
> 
And is it ok to use
#if defined(__arm__) || defined(__aarch64__)
?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI

2016-07-15 Thread Shannon Zhao


On 2016/7/13 18:03, Julien Grall wrote:
> 
> 
> On 13/07/2016 10:48, Shannon Zhao wrote:
>>
>>
>> On 2016/7/13 17:20, Julien Grall wrote:
>>> On 13/07/2016 08:54, Shannon Zhao wrote:
>>>> On 2016/7/12 19:33, Wei Liu wrote:
>>>>> On Tue, Jul 12, 2016 at 10:22:39AM +0100, Julien Grall wrote:
>>>>> [...]
>>>>>>>> Yeah, we can deprecate that field. But we need to take care to not
>>>>>>>> break
>>>>>>>> users of the old field.
>>>>>>> Ok, what name would you suggest?
>>>>>>
>>>>>> I would suggest b_info->u.acpi
>>>>>>
>>>>>
>>>>> b_info->acpi would be more appropriate.
>>>>>
>>>>> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>>>>> index ef614be..a57823d 100644
>>>>> --- a/tools/libxl/libxl_types.idl
>>>>> +++ b/tools/libxl/libxl_types.idl
>>>>> @@ -494,11 +494,16 @@ libxl_domain_build_info =
>>>>> Struct("domain_build_info",[
>>>>>  # Note that the partial device tree should avoid to use the
>>>>> phandle
>>>>>  # 65000 which is reserved by the toolstack.
>>>>>  ("device_tree",  string),
>>>>> +("acpi", libxl_defbool),
>>>>>  ("u", KeyedUnion(None, libxl_domain_type, "type",
>>>>>  [("hvm", Struct(None, [("firmware", string),
>>>>> ("bios",
>>>>> libxl_bios_type),
>>>>> ("pae",
>>>>> libxl_defbool),
>>>>> ("apic",
>>>>> libxl_defbool),
>>>>> +   # The following acpi field is
>>>>> +   # deprecated. Please use the
>>>>> unified
>>>>> +   # acpi field above which
>>>>> works for both
>>>>> +   # x86 and ARM.
>>>>> ("acpi",
>>>>> libxl_defbool),
>>>>> ("acpi_s3",
>>>>> libxl_defbool),
>>>>> ("acpi_s4",
>>>>> libxl_defbool),
>>>>>
>>>>>
>>>>> And then:
>>>>>
>>>>> 1. modify xl to set the new field.
>>>>> 2. modify libxl to handle compatibility: user of the old field should
>>>>>continue to work.
>>>>>
>>>> I found that the default value of acpi is true on x86. But we decided
>>>> before it's should be false by default on ARM. How to deal with this?
>>>> Julien, Stefano, can we make acpi true by default?
>>>
>>> I already said that I am not in favor of making ACPI true by default at
>>> least for ARM 32-bit guest.
>>>
>>> ARM 32-bit guest will not use ACPI, if we decide to enable it by
>>> default, we will require the user to install iasl for nothing.
>>>
>>> IHMO, ACPI should be disabled by default for any ARM guests. Libxl can
>>> take this decision easily.
>> I know but here we want to unify the acpi option for x86 and ARM while
>> on x86 it's true by default. What I want to ask is that how to
>> distinguish x86 and ARM in libxl__domain_build_info_setdefault(), so we
>> can assign acpi with different default value for x86 and ARM.
> 
> By using #ifdef in the code?
Maybe this could not work since CONFIG_ARM can not be accessed in libxl
in current codes. I'm not sure why it can't work. Wei, do you have any
suggestion?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI

2016-07-13 Thread Shannon Zhao


On 2016/7/13 17:20, Julien Grall wrote:
> On 13/07/2016 08:54, Shannon Zhao wrote:
>> On 2016/7/12 19:33, Wei Liu wrote:
>>> On Tue, Jul 12, 2016 at 10:22:39AM +0100, Julien Grall wrote:
>>> [...]
>>>>>> Yeah, we can deprecate that field. But we need to take care to not
>>>>>> break
>>>>>> users of the old field.
>>>>> Ok, what name would you suggest?
>>>>
>>>> I would suggest b_info->u.acpi
>>>>
>>>
>>> b_info->acpi would be more appropriate.
>>>
>>> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>>> index ef614be..a57823d 100644
>>> --- a/tools/libxl/libxl_types.idl
>>> +++ b/tools/libxl/libxl_types.idl
>>> @@ -494,11 +494,16 @@ libxl_domain_build_info =
>>> Struct("domain_build_info",[
>>>  # Note that the partial device tree should avoid to use the phandle
>>>  # 65000 which is reserved by the toolstack.
>>>  ("device_tree",  string),
>>> +("acpi", libxl_defbool),
>>>  ("u", KeyedUnion(None, libxl_domain_type, "type",
>>>  [("hvm", Struct(None, [("firmware", string),
>>> ("bios",
>>> libxl_bios_type),
>>> ("pae", 
>>> libxl_defbool),
>>> ("apic",
>>> libxl_defbool),
>>> +   # The following acpi field is
>>> +   # deprecated. Please use the
>>> unified
>>> +   # acpi field above which
>>> works for both
>>> +   # x86 and ARM.
>>> ("acpi",
>>> libxl_defbool),
>>> ("acpi_s3", 
>>> libxl_defbool),
>>> ("acpi_s4", 
>>> libxl_defbool),
>>>
>>>
>>> And then:
>>>
>>> 1. modify xl to set the new field.
>>> 2. modify libxl to handle compatibility: user of the old field should
>>>continue to work.
>>>
>> I found that the default value of acpi is true on x86. But we decided
>> before it's should be false by default on ARM. How to deal with this?
>> Julien, Stefano, can we make acpi true by default?
> 
> I already said that I am not in favor of making ACPI true by default at
> least for ARM 32-bit guest.
> 
> ARM 32-bit guest will not use ACPI, if we decide to enable it by
> default, we will require the user to install iasl for nothing.
> 
> IHMO, ACPI should be disabled by default for any ARM guests. Libxl can
> take this decision easily.
I know but here we want to unify the acpi option for x86 and ARM while
on x86 it's true by default. What I want to ask is that how to
distinguish x86 and ARM in libxl__domain_build_info_setdefault(), so we
can assign acpi with different default value for x86 and ARM.

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI

2016-07-13 Thread Shannon Zhao


On 2016/7/12 19:33, Wei Liu wrote:
> On Tue, Jul 12, 2016 at 10:22:39AM +0100, Julien Grall wrote:
> [...]
 Yeah, we can deprecate that field. But we need to take care to not break
 users of the old field.
>>> Ok, what name would you suggest?
>>
>> I would suggest b_info->u.acpi
>>
> 
> b_info->acpi would be more appropriate.
> 
> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
> index ef614be..a57823d 100644
> --- a/tools/libxl/libxl_types.idl
> +++ b/tools/libxl/libxl_types.idl
> @@ -494,11 +494,16 @@ libxl_domain_build_info = Struct("domain_build_info",[
>  # Note that the partial device tree should avoid to use the phandle
>  # 65000 which is reserved by the toolstack.
>  ("device_tree",  string),
> +("acpi", libxl_defbool),
>  ("u", KeyedUnion(None, libxl_domain_type, "type",
>  [("hvm", Struct(None, [("firmware", string),
> ("bios", libxl_bios_type),
> ("pae",  libxl_defbool),
> ("apic", libxl_defbool),
> +   # The following acpi field is
> +   # deprecated. Please use the unified
> +   # acpi field above which works for 
> both
> +   # x86 and ARM.
> ("acpi", libxl_defbool),
> ("acpi_s3",  libxl_defbool),
> ("acpi_s4",  libxl_defbool),
> 
> 
> And then:
> 
> 1. modify xl to set the new field.
> 2. modify libxl to handle compatibility: user of the old field should
>continue to work.
> 
I found that the default value of acpi is true on x86. But we decided
before it's should be false by default on ARM. How to deal with this?
Julien, Stefano, can we make acpi true by default?

Thanks,
-- 
Shannon


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 16/17] libxc/xc_dom_arm: Copy ACPI tables to guest space

2016-07-12 Thread Shannon Zhao
On 2016年07月12日 22:50, Wei Liu wrote:
> On Tue, Jul 12, 2016 at 10:42:07PM +0800, Shannon Zhao wrote:
>>>>>>>>>>> > >>>>> > >> > 
>>>>>>>>>>> > >>>>> > >> > Does it mean we would need to update the slack to 
>>>>>>>>>>> > >>>>> > >> > take into account the ACPI
>>>>>>>>>>> > >>>>> > >> > blob?
>>>>>>> > >>> > > Yes, we need to take into account the ACPI blob. Probably not 
>>>>>>> > >>> > > in the
>>>>>>> > >>> > > slack but directly in mam_memkb.
>>>>> > >> > Sorry, I'm not sure understand this. I found the b_info->max_memkb 
>>>>> > >> > but
>>>>> > >> > didn't find the slack you said. And how to fix this? Update
>>>>> > >> > b_info->max_memkb or the slack?
>>> > > Can you calculate the size of your payload and add that to max_memkb?
>>> > > 
>> > Yeah, but the size will be changed if we change the tables in the future
>> > and this also should consider x86, right?
> That could easily be solved by introducing a function to calculate the
> size, right?
Oh, I'm not familiar with this. Let's clarify on this. It can add the
size to max_memkb after generating the ACPI tables and before loading
the tables to guest space and it doesn't have to add the size at
libxl__domain_build_info_setdefault(), right?

Thanks,
-- 
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v3 05/17] libxl/arm: Generate static ACPI DSDT table

2016-07-12 Thread Shannon Zhao
On 2016年07月12日 19:38, Wei Liu wrote:
> On Tue, Jul 12, 2016 at 11:50:32AM +0800, Shannon Zhao wrote:
>> > 
>> > 
>> > On 2016/7/7 23:52, Wei Liu wrote:
>>> > > On Tue, Jul 05, 2016 at 11:12:35AM +0800, Shannon Zhao wrote:
>>>>> > >> > From: Shannon Zhao <shannon.z...@linaro.org>
>>>>> > >> > 
>>>>> > >> > It uses static DSDT table like the way x86 uses. Currently the DSDT
>>>>> > >> > table only contains processor device objects and it generates the
>>>>> > >> > maximal objects which so far is 128.
>>>>> > >> > 
>>>>> > >> > Signed-off-by: Shannon Zhao <shannon.z...@linaro.org>
>>>>> > >> > ---
>>>>> > >> >  tools/libacpi/Makefile| 15 -
>>>>> > >> >  tools/libacpi/mk_dsdt.c   | 51 
>>>>> > >> > ---
>>>>> > >> >  tools/libxl/Makefile  |  5 -
>>>>> > >> >  tools/libxl/libxl_arm_acpi.c  |  5 +
>>>>> > >> >  xen/include/public/arch-arm.h |  3 +++
>>>>> > >> >  5 files changed, 64 insertions(+), 15 deletions(-)
>>>>> > >> > 
>>>>> > >> > diff --git a/tools/libacpi/Makefile b/tools/libacpi/Makefile
>>>>> > >> > index 4068d9a..0401810 100644
>>>>> > >> > --- a/tools/libacpi/Makefile
>>>>> > >> > +++ b/tools/libacpi/Makefile
>>>>> > >> > @@ -22,6 +22,7 @@ MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt
>>>>> > >> >  # Sources to be generated
>>>>> > >> >  C_SRC = $(ACPI_BUILD_DIR)/dsdt_anycpu.c 
>>>>> > >> > $(ACPI_BUILD_DIR)/dsdt_15cpu.c 
>>>>> > >> >  C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.c 
>>>>> > >> > $(ACPI_BUILD_DIR)/dsdt_pvh.c
>>>>> > >> > +C_SRC += $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.c
>>>>> > >> >  H_SRC = $(ACPI_BUILD_DIR)/ssdt_s3.h $(ACPI_BUILD_DIR)/ssdt_s4.h 
>>>>> > >> > $(ACPI_BUILD_DIR)/ssdt_pm.h $(ACPI_BUILD_DIR)/ssdt_tpm.h
>>>>> > >> >  
>>>>> > >> >  vpath iasl $(PATH)
>>>>> > >> > @@ -35,7 +36,7 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl iasl
>>>>> > >> >cd $(CURDIR)
>>>>> > >> >  
>>>>> > >> >  $(MK_DSDT): mk_dsdt.c
>>>>> > >> > -  $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -o $@ mk_dsdt.c
>>>>> > >> > +  $(HOSTCC) $(HOSTCFLAGS) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o 
>>>>> > >> > $@ mk_dsdt.c
>>> > > Why is this needed? Which unstable hypervisor interface you need in
>>> > > order to build this?
>> > It needs GUEST_MAX_VCPUS in mk_dsdt.c while the GUEST_MAX_VCPUS is
>> > defined under #if defined(__XEN__) || defined(__XEN_TOOLS__) in
>> > xen/include/public/arch-arm.h
>> > 
> OK. Let me elaborate a bit on this.
> 
> The two macros basically imply everything enclosed in them is subject to
> change. I guess I can live with this because this is not a public facing
> interface for library users.
> 
> Can you ack or nack my assessment?
Yeah, the mk_dsdt is just a middle result of compilation which is used
to generate DSDT table.

Thanks,
-- 
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v2 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI

2016-07-12 Thread Shannon Zhao
On 2016年07月12日 22:33, Wei Liu wrote:
> On Tue, Jul 12, 2016 at 10:17:20PM +0800, Shannon Zhao wrote:
>> > On 2016年07月12日 19:33, Wei Liu wrote:
>>> > > On Tue, Jul 12, 2016 at 10:22:39AM +0100, Julien Grall wrote:
>>> > > [...]
>>>>>>>>> > >>>> > >>Yeah, we can deprecate that field. But we need to take 
>>>>>>>>> > >>>> > >>care to not break
>>>>>>>>> > >>>> > >>users of the old field.
>>>>>>> > >>> > >Ok, what name would you suggest?
>>>>> > >> > 
>>>>> > >> > I would suggest b_info->u.acpi
>>>>> > >> > 
>>> > > b_info->acpi would be more appropriate.
>>> > > 
>>> > > diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>>> > > index ef614be..a57823d 100644
>>> > > --- a/tools/libxl/libxl_types.idl
>>> > > +++ b/tools/libxl/libxl_types.idl
>>> > > @@ -494,11 +494,16 @@ libxl_domain_build_info = 
>>> > > Struct("domain_build_info",[
>>> > >  # Note that the partial device tree should avoid to use the phandle
>>> > >  # 65000 which is reserved by the toolstack.
>>> > >  ("device_tree",  string),
>>> > > +("acpi", libxl_defbool),
>>> > >  ("u", KeyedUnion(None, libxl_domain_type, "type",
>>> > >  [("hvm", Struct(None, [("firmware", string),
>>> > > ("bios", 
>>> > > libxl_bios_type),
>>> > > ("pae",  
>>> > > libxl_defbool),
>>> > > ("apic", 
>>> > > libxl_defbool),
>>> > > +   # The following acpi field is
>>> > > +   # deprecated. Please use the 
>>> > > unified
>>> > > +   # acpi field above which works 
>>> > > for both
>>> > > +   # x86 and ARM.
>>> > > ("acpi", 
>>> > > libxl_defbool),
>>> > > ("acpi_s3",  
>>> > > libxl_defbool),
>>> > > ("acpi_s4",  
>>> > > libxl_defbool),
>>> > > 
>>> > > 
>>> > > And then:
>>> > > 
>>> > > 1. modify xl to set the new field.
>>> > > 2. modify libxl to handle compatibility: user of the old field should
>>> > >continue to work.
>>> > > 
>>> > > I know this is a bit terse. Feel free to ask questions if you have any
>>> > > doubt.
>> > I'm not sure I understand correctly. While xl is always matching libxl,
>> > so can we just let xl set the new field and libxl to use the new field?
>> > To users, they will still use the configure option "acpi".
>> > 
> We need to distinguish between the library to control Xen (libxl) and
> the user of that library (xl). Xl is just one of the possibly users of
> libxl. For example, libvirt uses libxl APIs without involving xl at all,
> hence my second point.
Oh, I see. Thanks for the clarification.

-- 
Shannon

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


  1   2   3   4   5   6   7   8   9   10   >