diff mbox

[v3,42/62] arm/acpi: Prepare FADT table for Dom0

Message ID 1447753261-7552-43-git-send-email-shannon.zhao@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Shannon Zhao Nov. 17, 2015, 9:40 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

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

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 xen/arch/arm/domain_build.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Stefano Stabellini Nov. 26, 2015, 5:19 p.m. UTC | #1
On Tue, 17 Nov 2015, shannon.zhao@linaro.org wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
> 
> Copy and modify FADT table before passing it to Dom0. Set PSCI_COMPLIANT
> and PSCI_USE_HVC.
> 
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>
>  xen/arch/arm/domain_build.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index b5ed44c..5d03dc0 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1357,6 +1357,46 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
>  }
>  
>  #ifdef CONFIG_ACPI
> +#define XEN_HYPERVISOR_ID 0x000058656E564D4D  /* "XenVMM" */

This needs to be documented somewhere. A new doc under docs/ might be
enough.


> +static int acpi_create_fadt(struct domain *d, struct membank tbl_add[])
> +{
> +    struct acpi_table_header *table = NULL;
> +    struct acpi_table_fadt *fadt = NULL;
> +    u64 table_size;
> +    acpi_status status;
> +    u8 *base_ptr;
> +    u8 checksum;
> +
> +    status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
> +
> +    if ( ACPI_FAILURE(status) )
> +    {
> +        const char *msg = acpi_format_exception(status);
> +
> +        printk("Failed to get FADT table, %s\n", msg);
> +        return -EINVAL;
> +    }
> +
> +    table_size = table->length;
> +    base_ptr = d->arch.efi_acpi_table
> +               + acpi_get_table_offset(tbl_add, TBL_FADT);
> +    ACPI_MEMCPY(base_ptr, table, table_size);
> +    fadt = (struct acpi_table_fadt *)base_ptr;
> +
> +    /* Set PSCI_COMPLIANT and PSCI_USE_HVC */
> +    fadt->arm_boot_flags |= (ACPI_FADT_PSCI_COMPLIANT | ACPI_FADT_PSCI_USE_HVC);
> +    fadt->hypervisor_id = XEN_HYPERVISOR_ID;
> +    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, fadt), table_size);
> +    fadt->header.checksum -= checksum;
> +
> +    tbl_add[TBL_FADT].start = d->arch.efi_acpi_gpa
> +                              + acpi_get_table_offset(tbl_add, TBL_FADT);
> +    tbl_add[TBL_FADT].size = table_size;
> +
> +    return 0;
> +}
> +
>  static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo)
>  {
>      u64 efi_size, acpi_size = 0, addr;
> @@ -1400,6 +1440,7 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
>  {
>      int rc = 0;
>      int order;
> +    struct membank tbl_add[TBL_MMAX] = {};
>  
>      rc = estimate_acpi_efi_size(d, kinfo);
>      if ( rc != 0 )
> @@ -1418,6 +1459,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
>       * region. So we use it as the ACPI table mapped address. */
>      d->arch.efi_acpi_gpa = kinfo->gnttab_start;
>  
> +    rc = acpi_create_fadt(d, tbl_add);
> +    if ( rc != 0 )
> +        return rc;
> +
>      return 0;
>  }
>  #else
> -- 
> 2.1.0
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
>
Ian Campbell Nov. 27, 2015, 9:50 a.m. UTC | #2
On Thu, 2015-11-26 at 17:19 +0000, Stefano Stabellini wrote:
> On Tue, 17 Nov 2015, shannon.zhao@linaro.org wrote:
> > From: Shannon Zhao <shannon.zhao@linaro.org>
> > 
> > Copy and modify FADT table before passing it to Dom0. Set
> > PSCI_COMPLIANT
> > and PSCI_USE_HVC.
> > 
> > Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> > 
> >  xen/arch/arm/domain_build.c | 45
> > +++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 45 insertions(+)
> > 
> > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> > index b5ed44c..5d03dc0 100644
> > --- a/xen/arch/arm/domain_build.c
> > +++ b/xen/arch/arm/domain_build.c
> > @@ -1357,6 +1357,46 @@ static int prepare_dtb(struct domain *d, struct
> > kernel_info *kinfo)
> >  }
> >  
> >  #ifdef CONFIG_ACPI
> > +#define XEN_HYPERVISOR_ID 0x000058656E564D4D  /* "XenVMM" */
> 
> This needs to be documented somewhere. A new doc under docs/ might be
> enough.

Should (also?) probably be in xen/include/public/arch-arm.h in the same
"#if defined(__XEN__) || defined(__XEN_TOOLS__)" as the other guest non-ABI 
stuff[0] which is needed by both Xen and the toolstack.

We don't actually have ACPI guest support today, so the toolstack has no
current interest, but I think that is still a logical place for it do be
defined.

Ian.

[0] That is, stuff which is part of the current implementation but which is
exposed to guests through other means, e.g. DT or ACPI and not through the
use of the arch-arm.h public header.
diff mbox

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index b5ed44c..5d03dc0 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1357,6 +1357,46 @@  static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 }
 
 #ifdef CONFIG_ACPI
+#define XEN_HYPERVISOR_ID 0x000058656E564D4D  /* "XenVMM" */
+
+static int acpi_create_fadt(struct domain *d, struct membank tbl_add[])
+{
+    struct acpi_table_header *table = NULL;
+    struct acpi_table_fadt *fadt = NULL;
+    u64 table_size;
+    acpi_status status;
+    u8 *base_ptr;
+    u8 checksum;
+
+    status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
+
+    if ( ACPI_FAILURE(status) )
+    {
+        const char *msg = acpi_format_exception(status);
+
+        printk("Failed to get FADT table, %s\n", msg);
+        return -EINVAL;
+    }
+
+    table_size = table->length;
+    base_ptr = d->arch.efi_acpi_table
+               + acpi_get_table_offset(tbl_add, TBL_FADT);
+    ACPI_MEMCPY(base_ptr, table, table_size);
+    fadt = (struct acpi_table_fadt *)base_ptr;
+
+    /* Set PSCI_COMPLIANT and PSCI_USE_HVC */
+    fadt->arm_boot_flags |= (ACPI_FADT_PSCI_COMPLIANT | ACPI_FADT_PSCI_USE_HVC);
+    fadt->hypervisor_id = XEN_HYPERVISOR_ID;
+    checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, fadt), table_size);
+    fadt->header.checksum -= checksum;
+
+    tbl_add[TBL_FADT].start = d->arch.efi_acpi_gpa
+                              + acpi_get_table_offset(tbl_add, TBL_FADT);
+    tbl_add[TBL_FADT].size = table_size;
+
+    return 0;
+}
+
 static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo)
 {
     u64 efi_size, acpi_size = 0, addr;
@@ -1400,6 +1440,7 @@  static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
 {
     int rc = 0;
     int order;
+    struct membank tbl_add[TBL_MMAX] = {};
 
     rc = estimate_acpi_efi_size(d, kinfo);
     if ( rc != 0 )
@@ -1418,6 +1459,10 @@  static int prepare_acpi(struct domain *d, struct kernel_info *kinfo)
      * region. So we use it as the ACPI table mapped address. */
     d->arch.efi_acpi_gpa = kinfo->gnttab_start;
 
+    rc = acpi_create_fadt(d, tbl_add);
+    if ( rc != 0 )
+        return rc;
+
     return 0;
 }
 #else