Patchwork pc: Fix e820 fw_cfg for big endian

login
register
mail settings
Submitter Alex Williamson
Date Nov. 8, 2010, 3:57 a.m.
Message ID <20101108035143.26532.81891.stgit@s20.home>
Download mbox | patch
Permalink /patch/70391/
State New
Headers show

Comments

Alex Williamson - Nov. 8, 2010, 3:57 a.m.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 Compile tested only.  Only current user is kvm, no cross-arch users.

 hw/pc.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
Jes Sorensen - Nov. 9, 2010, 10:57 a.m.
On 11/08/10 04:57, Alex Williamson wrote:
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> 
>  Compile tested only.  Only current user is kvm, no cross-arch users.
> 
>  hw/pc.c |   14 +++++++-------
>  1 files changed, 7 insertions(+), 7 deletions(-)

Patch looks fine to me, but are there any systems out there using e820
on big endian hardware?

Jes
Alexander Graf - Nov. 9, 2010, 12:42 p.m.
On 09.11.2010, at 11:57, Jes Sorensen wrote:

> On 11/08/10 04:57, Alex Williamson wrote:
>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> 
>> Compile tested only.  Only current user is kvm, no cross-arch users.
>> 
>> hw/pc.c |   14 +++++++-------
>> 1 files changed, 7 insertions(+), 7 deletions(-)
> 
> Patch looks fine to me, but are there any systems out there using e820
> on big endian hardware?

This fixes things when host endianness is big endian.


Alex
Jes Sorensen - Nov. 9, 2010, 12:44 p.m.
On 11/09/10 13:42, Alexander Graf wrote:
> 
> On 09.11.2010, at 11:57, Jes Sorensen wrote:
> 
>> On 11/08/10 04:57, Alex Williamson wrote:
>>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>>> ---
>>>
>>> Compile tested only.  Only current user is kvm, no cross-arch users.
>>>
>>> hw/pc.c |   14 +++++++-------
>>> 1 files changed, 7 insertions(+), 7 deletions(-)
>>
>> Patch looks fine to me, but are there any systems out there using e820
>> on big endian hardware?
> 
> This fixes things when host endianness is big endian.

Ah right, then it's all fine :)

Cheers,
Jes
Anthony Liguori - Nov. 16, 2010, 10:26 p.m.
On 11/07/2010 09:57 PM, Alex Williamson wrote:
> Signed-off-by: Alex Williamson<alex.williamson@redhat.com>
>    

Applied.  Thanks.

Regards,

Anthony Liguori
> ---
>
>   Compile tested only.  Only current user is kvm, no cross-arch users.
>
>   hw/pc.c |   14 +++++++-------
>   1 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/pc.c b/hw/pc.c
> index 0264e3d..cc8ec14 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -467,19 +467,19 @@ static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
>
>   int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
>   {
> -    int index = e820_table.count;
> +    int index = le32_to_cpu(e820_table.count);
>       struct e820_entry *entry;
>
>       if (index>= E820_NR_ENTRIES)
>           return -EBUSY;
> -    entry =&e820_table.entry[index];
> +    entry =&e820_table.entry[index++];
>
> -    entry->address = address;
> -    entry->length = length;
> -    entry->type = type;
> +    entry->address = cpu_to_le64(address);
> +    entry->length = cpu_to_le64(length);
> +    entry->type = cpu_to_le32(type);
>
> -    e820_table.count++;
> -    return e820_table.count;
> +    e820_table.count = cpu_to_le32(index);
> +    return index;
>   }
>
>   static void *bochs_bios_init(void)
>
>
>
>

Patch

diff --git a/hw/pc.c b/hw/pc.c
index 0264e3d..cc8ec14 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -467,19 +467,19 @@  static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
 
 int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
 {
-    int index = e820_table.count;
+    int index = le32_to_cpu(e820_table.count);
     struct e820_entry *entry;
 
     if (index >= E820_NR_ENTRIES)
         return -EBUSY;
-    entry = &e820_table.entry[index];
+    entry = &e820_table.entry[index++];
 
-    entry->address = address;
-    entry->length = length;
-    entry->type = type;
+    entry->address = cpu_to_le64(address);
+    entry->length = cpu_to_le64(length);
+    entry->type = cpu_to_le32(type);
 
-    e820_table.count++;
-    return e820_table.count;
+    e820_table.count = cpu_to_le32(index);
+    return index;
 }
 
 static void *bochs_bios_init(void)