diff mbox

[Xen-devel,RESEND,13/14] libxl/arm: initialize memory information of ACPI blob

Message ID 1464670986-10256-14-git-send-email-zhaoshenglong@huawei.com
State New
Headers show

Commit Message

Shannon Zhao May 31, 2016, 5:03 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

Assign the guest memory space for ACPI tables and replace the reg in DT
with real values.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 tools/libxc/xc_dom_arm.c | 16 +++++++++++++++-
 tools/libxl/libxl_arm.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

Comments

Shannon Zhao June 6, 2016, 2:35 p.m. UTC | #1
On 2016年06月06日 19:40, Stefano Stabellini wrote:
> On Tue, 31 May 2016, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>
>> Assign the guest memory space for ACPI tables and replace the reg in DT
>> with real values.
>>
>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>> ---
>>  tools/libxc/xc_dom_arm.c | 16 +++++++++++++++-
>>  tools/libxl/libxl_arm.c  | 40 ++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 55 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
>> index 64a8b67..e21e3e9 100644
>> --- a/tools/libxc/xc_dom_arm.c
>> +++ b/tools/libxc/xc_dom_arm.c
>> @@ -383,9 +383,11 @@ static int meminit(struct xc_dom_image *dom)
>>      const uint64_t kernsize = kernend - kernbase;
>>      const uint64_t dtb_size = dom->devicetree_blob ?
>>          ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
>> +    const uint64_t acpi_size = dom->acpitable_blob ?
>> +        ROUNDUP(dom->acpitable_size, XC_PAGE_SHIFT) : 0;
>>      const uint64_t ramdisk_size = dom->ramdisk_blob ?
>>          ROUNDUP(dom->ramdisk_size, XC_PAGE_SHIFT) : 0;
>> -    const uint64_t modsize = dtb_size + ramdisk_size;
>> +    const uint64_t modsize = dtb_size + acpi_size + ramdisk_size;
>>      const uint64_t ram128mb = bankbase[0] + (128<<20);
>>  
>>      xen_pfn_t p2m_size;
>> @@ -500,6 +502,18 @@ static int meminit(struct xc_dom_image *dom)
>>          modbase += dtb_size;
>>      }
>>  
>> +    if ( acpi_size )
>> +    {
>> +        dom->acpi_seg.vstart = modbase;
>> +        dom->acpi_seg.vend = modbase + acpi_size;
>> +
>> +        DOMPRINTF("%s: acpi: 0x%" PRIx64 " -> 0x%" PRIx64 "",
>> +                  __FUNCTION__,
>> +                  dom->acpi_seg.vstart, dom->acpi_seg.vend);
>> +
>> +        modbase += dtb_size;
> 
> shouldn't this be 
> 
> modbase += acpi_size
> 
> ?
> 
right, will fix.

> 
>> +    }
>> +
>>      return 0;
>>  }
>>  
>> diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
>> index e7cb578..bf1eeea 100644
>> --- a/tools/libxl/libxl_arm.c
>> +++ b/tools/libxl/libxl_arm.c
>> @@ -230,6 +230,27 @@ static int fdt_property_regs(libxl__gc *gc, void *fdt,
>>      return fdt_property(fdt, "reg", regs, sizeof(regs));
>>  }
>>  
>> +static int fdt_property_inplace_regs(void *fdt, int nodeoffset,
>> +                                     unsigned addr_cells, unsigned size_cells,
>> +                                     unsigned num_regs, ...)
>> +{
>> +    uint32_t regs[num_regs*(addr_cells+size_cells)];
>> +    be32 *cells = &regs[0];
>> +    int i;
>> +    va_list ap;
>> +    uint64_t base, size;
>> +
>> +    va_start(ap, num_regs);
>> +    for (i = 0 ; i < num_regs; i++) {
>> +        base = addr_cells ? va_arg(ap, uint64_t) : 0;
>> +        size = size_cells ? va_arg(ap, uint64_t) : 0;
>> +        set_range(&cells, addr_cells, size_cells, base, size);
>> +    }
>> +    va_end(ap);
>> +
>> +    return fdt_setprop_inplace(fdt, nodeoffset, "reg", regs, sizeof(regs));
>> +}
> 
> The va_arg stuff is a bit overkill. Also, can't you call
> finalise_one_memory_node instead?
> 
OK, thank you.
diff mbox

Patch

diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index 64a8b67..e21e3e9 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -383,9 +383,11 @@  static int meminit(struct xc_dom_image *dom)
     const uint64_t kernsize = kernend - kernbase;
     const uint64_t dtb_size = dom->devicetree_blob ?
         ROUNDUP(dom->devicetree_size, XC_PAGE_SHIFT) : 0;
+    const uint64_t acpi_size = dom->acpitable_blob ?
+        ROUNDUP(dom->acpitable_size, XC_PAGE_SHIFT) : 0;
     const uint64_t ramdisk_size = dom->ramdisk_blob ?
         ROUNDUP(dom->ramdisk_size, XC_PAGE_SHIFT) : 0;
-    const uint64_t modsize = dtb_size + ramdisk_size;
+    const uint64_t modsize = dtb_size + acpi_size + ramdisk_size;
     const uint64_t ram128mb = bankbase[0] + (128<<20);
 
     xen_pfn_t p2m_size;
@@ -500,6 +502,18 @@  static int meminit(struct xc_dom_image *dom)
         modbase += dtb_size;
     }
 
+    if ( acpi_size )
+    {
+        dom->acpi_seg.vstart = modbase;
+        dom->acpi_seg.vend = modbase + acpi_size;
+
+        DOMPRINTF("%s: acpi: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->acpi_seg.vstart, dom->acpi_seg.vend);
+
+        modbase += dtb_size;
+    }
+
     return 0;
 }
 
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index e7cb578..bf1eeea 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -230,6 +230,27 @@  static int fdt_property_regs(libxl__gc *gc, void *fdt,
     return fdt_property(fdt, "reg", regs, sizeof(regs));
 }
 
+static int fdt_property_inplace_regs(void *fdt, int nodeoffset,
+                                     unsigned addr_cells, unsigned size_cells,
+                                     unsigned num_regs, ...)
+{
+    uint32_t regs[num_regs*(addr_cells+size_cells)];
+    be32 *cells = &regs[0];
+    int i;
+    va_list ap;
+    uint64_t base, size;
+
+    va_start(ap, num_regs);
+    for (i = 0 ; i < num_regs; i++) {
+        base = addr_cells ? va_arg(ap, uint64_t) : 0;
+        size = size_cells ? va_arg(ap, uint64_t) : 0;
+        set_range(&cells, addr_cells, size_cells, base, size);
+    }
+    va_end(ap);
+
+    return fdt_setprop_inplace(fdt, nodeoffset, "reg", regs, sizeof(regs));
+}
+
 static int make_root_properties(libxl__gc *gc,
                                 const libxl_version_info *vers,
                                 void *fdt)
@@ -1209,6 +1230,8 @@  int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
 
     const struct xc_dom_seg *ramdisk = dom->ramdisk_blob ?
         &dom->ramdisk_seg : NULL;
+    const struct xc_dom_seg *acpi = dom->acpitable_blob ?
+        &dom->acpi_seg : NULL;
 
     if (ramdisk) {
         int chosen, res;
@@ -1238,6 +1261,23 @@  int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
 
     }
 
+    if (acpi)
+    {
+        int module, res;
+
+        module = fdt_path_offset(fdt, "/chosen/modules/module@0");
+        assert(module > 0);
+
+        LOG(DEBUG, "/chosen/modules/module@0 updating acpi properties to cover "
+            "%"PRIx64"-%"PRIx64,
+            acpi->vstart, acpi->vend);
+
+        res = fdt_property_inplace_regs(fdt, module, ROOT_ADDRESS_CELLS,
+                                        ROOT_SIZE_CELLS, 1, acpi->vstart,
+                                        acpi->vend - acpi->vstart + 1);
+        assert(!res);
+    }
+
     for (i = 0; i < GUEST_RAM_BANKS; i++) {
         const uint64_t size = (uint64_t)dom->rambank_size[i] << XC_PAGE_SHIFT;