Patchwork [22/25] PPC: e500: dt: use 64bit cell helper

login
register
mail settings
Submitter Alexander Graf
Date May 30, 2012, 11 a.m.
Message ID <1338375646-15064-23-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/161941/
State New
Headers show

Comments

Alexander Graf - May 30, 2012, 11 a.m.
We have a nice 64bit helper to ease the device tree generation and
make the code more readable when creating 64bit 2-cell parameters.
Use it when generating the device tree.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/ppce500_mpc8544ds.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
Scott Wood - May 31, 2012, 10:15 p.m.
On 05/30/2012 06:00 AM, Alexander Graf wrote:
> We have a nice 64bit helper to ease the device tree generation and
> make the code more readable when creating 64bit 2-cell parameters.
> Use it when generating the device tree.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  hw/ppce500_mpc8544ds.c |   10 ++++------
>  1 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
> index 2069891..32fbdd3 100644
> --- a/hw/ppce500_mpc8544ds.c
> +++ b/hw/ppce500_mpc8544ds.c
> @@ -91,7 +91,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>                                      const char *kernel_cmdline)
>  {
>      int ret = -1;
> -    uint32_t mem_reg_property[] = {0, cpu_to_be32(ramsize)};
>      int fdt_size;
>      void *fdt;
>      uint8_t hypercall[16];
> @@ -128,8 +127,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>  
>      qemu_devtree_add_subnode(fdt, "/memory");
>      qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory");
> -    qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
> -                         sizeof(mem_reg_property));
> +    qemu_devtree_setprop_cell64(fdt, "/memory", "reg", ramsize);

The reg property is supposed to contain an address and a size, not just
size.  You're getting away with this because address happens to be zero
and you happen to be writing a 64-bit size into a device tree that
expects a 32-bit address followed by a 32-bit size (which should be
changed to expect 64-bit of both).

-Scott
Alexander Graf - May 31, 2012, 10:19 p.m.
On 01.06.2012, at 00:15, Scott Wood wrote:

> On 05/30/2012 06:00 AM, Alexander Graf wrote:
>> We have a nice 64bit helper to ease the device tree generation and
>> make the code more readable when creating 64bit 2-cell parameters.
>> Use it when generating the device tree.
>> 
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>> hw/ppce500_mpc8544ds.c |   10 ++++------
>> 1 files changed, 4 insertions(+), 6 deletions(-)
>> 
>> diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
>> index 2069891..32fbdd3 100644
>> --- a/hw/ppce500_mpc8544ds.c
>> +++ b/hw/ppce500_mpc8544ds.c
>> @@ -91,7 +91,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>>                                     const char *kernel_cmdline)
>> {
>>     int ret = -1;
>> -    uint32_t mem_reg_property[] = {0, cpu_to_be32(ramsize)};
>>     int fdt_size;
>>     void *fdt;
>>     uint8_t hypercall[16];
>> @@ -128,8 +127,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>> 
>>     qemu_devtree_add_subnode(fdt, "/memory");
>>     qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory");
>> -    qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
>> -                         sizeof(mem_reg_property));
>> +    qemu_devtree_setprop_cell64(fdt, "/memory", "reg", ramsize);
> 
> The reg property is supposed to contain an address and a size, not just
> size.  You're getting away with this because address happens to be zero
> and you happen to be writing a 64-bit size into a device tree that
> expects a 32-bit address followed by a 32-bit size (which should be
> changed to expect 64-bit of both).

Ouch. How do I change it to mean 64-bit on both?


Alex
Scott Wood - May 31, 2012, 10:25 p.m.
On 05/31/2012 05:19 PM, Alexander Graf wrote:
> 
> On 01.06.2012, at 00:15, Scott Wood wrote:
> 
>> On 05/30/2012 06:00 AM, Alexander Graf wrote:
>>> We have a nice 64bit helper to ease the device tree generation and
>>> make the code more readable when creating 64bit 2-cell parameters.
>>> Use it when generating the device tree.
>>>
>>> Signed-off-by: Alexander Graf <agraf@suse.de>
>>> ---
>>> hw/ppce500_mpc8544ds.c |   10 ++++------
>>> 1 files changed, 4 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
>>> index 2069891..32fbdd3 100644
>>> --- a/hw/ppce500_mpc8544ds.c
>>> +++ b/hw/ppce500_mpc8544ds.c
>>> @@ -91,7 +91,6 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>>>                                     const char *kernel_cmdline)
>>> {
>>>     int ret = -1;
>>> -    uint32_t mem_reg_property[] = {0, cpu_to_be32(ramsize)};
>>>     int fdt_size;
>>>     void *fdt;
>>>     uint8_t hypercall[16];
>>> @@ -128,8 +127,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
>>>
>>>     qemu_devtree_add_subnode(fdt, "/memory");
>>>     qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory");
>>> -    qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
>>> -                         sizeof(mem_reg_property));
>>> +    qemu_devtree_setprop_cell64(fdt, "/memory", "reg", ramsize);
>>
>> The reg property is supposed to contain an address and a size, not just
>> size.  You're getting away with this because address happens to be zero
>> and you happen to be writing a 64-bit size into a device tree that
>> expects a 32-bit address followed by a 32-bit size (which should be
>> changed to expect 64-bit of both).
> 
> Ouch. How do I change it to mean 64-bit on both?

Change #address-cells and #size-cells to 2, and update all reg and
ranges to match.

-Scott

Patch

diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index 2069891..32fbdd3 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -91,7 +91,6 @@  static int mpc8544_load_device_tree(CPUPPCState *env,
                                     const char *kernel_cmdline)
 {
     int ret = -1;
-    uint32_t mem_reg_property[] = {0, cpu_to_be32(ramsize)};
     int fdt_size;
     void *fdt;
     uint8_t hypercall[16];
@@ -128,8 +127,7 @@  static int mpc8544_load_device_tree(CPUPPCState *env,
 
     qemu_devtree_add_subnode(fdt, "/memory");
     qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory");
-    qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
-                         sizeof(mem_reg_property));
+    qemu_devtree_setprop_cell64(fdt, "/memory", "reg", ramsize);
 
     qemu_devtree_add_subnode(fdt, "/chosen");
     if (initrd_size) {
@@ -174,7 +172,7 @@  static int mpc8544_load_device_tree(CPUPPCState *env,
        the first node as boot node and be happy */
     for (i = smp_cpus - 1; i >= 0; i--) {
         char cpu_name[128];
-        uint64_t cpu_release_addr = cpu_to_be64(MPC8544_SPIN_BASE + (i * 0x20));
+        uint64_t cpu_release_addr = MPC8544_SPIN_BASE + (i * 0x20);
 
         for (env = first_cpu; env != NULL; env = env->next_cpu) {
             if (env->cpu_index == i) {
@@ -202,8 +200,8 @@  static int mpc8544_load_device_tree(CPUPPCState *env,
         if (env->cpu_index) {
             qemu_devtree_setprop_string(fdt, cpu_name, "status", "disabled");
             qemu_devtree_setprop_string(fdt, cpu_name, "enable-method", "spin-table");
-            qemu_devtree_setprop(fdt, cpu_name, "cpu-release-addr",
-                                 &cpu_release_addr, sizeof(cpu_release_addr));
+            qemu_devtree_setprop_cell64(fdt, cpu_name, "cpu-release-addr",
+                                        cpu_release_addr);
         } else {
             qemu_devtree_setprop_string(fdt, cpu_name, "status", "okay");
         }