diff mbox

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

Message ID 1471343113-10652-7-git-send-email-zhaoshenglong@huawei.com
State Superseded
Headers show

Commit Message

Shannon Zhao Aug. 16, 2016, 10:25 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

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

Comments

Julien Grall Aug. 29, 2016, 6:10 p.m. UTC | #1
Hi Shannon,

On 16/08/2016 06:25, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> Signed-off-by: Shannon Zhao <shannon.zhao@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)

len should be size_t.

> +{
> +    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(&xsdt->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;
>

Regards,
diff mbox

Patch

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(&xsdt->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;