Skip to contentSkip to conversation

Always swap endianness in DBDMA

PATCH In review Alexander Graf 2 participants 4 messages Dec 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Always swap endianness in DBDMA

When we get an MMIO request, we always get variables in host endianness. The only time we need to actually reverse byte order is when we read bytes from guest memory.

Apparently the DBDMA implementation is different there. A lot of the logic in there depends on values being big endian. Now, qemu does all the conversion in the MMIO handlers for us already though, so it turns out that we're in the same byte order from a C point of view, but cpu_to_be32 and be32_to_cpu end up being nops.

This makes the code work differently on x86 (little endian) than on ppc (big endian). On x86 it works, on ppc it doesn't.

This patch (while being seriously hacky and ugly) makes dbdma emulation work on ppc hosts. I'll leave the real fixing to someone else.

---
 hw/mac_dbdma.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hw/mac_dbdma.c +8 -0
index 98dccfd..4dbfc16 100644
@@ -40,6 +40,14 @@
 #include "isa.h"
 #include "mac_dbdma.h"
 
+/*
+ * XXX This is just plain wrong. Apparently we don't want to have big endian
+ *     values, but reversed endian ones. The code as is doesn't work on big
+ *     endian hosts. With these defines it does.
+ */
+#define cpu_to_be32 bswap32
+#define be32_to_cpu bswap32
+
 /* debug DBDMA */
 //#define DEBUG_DBDMA
 
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 10 lines · Alexander Graf

When we get an MMIO request, we always get variables in host endianness. The only time we need to actually reverse byte order is when we read bytes from guest memory.

Apparently the DBDMA implementation is different there. A lot of the logic in there depends on values being big endian. Now, qemu does all the conversion in the MMIO handlers for us already though, so it turns out that we're in the same byte order from a C point of view, but cpu_to_be32 and be32_to_cpu end up being nops.

Quoted 5 lines

This makes the code work differently on x86 (little endian) than on ppc (big endian). On x86 it works, on ppc it doesn't.

This patch (while being seriously hacky and ugly) makes dbdma emulation work on ppc hosts. I'll leave the real fixing to someone else.

Come on,

#define cpu_to_dbdma32 bswap32
#define dbdma_to_cpu32 bswap32

and then

s/cpu_to_be32/cpu_to_dbdma32/g
s/be32_to_cpu/dbdma32_to_cpu/g

is not too hard, is it?

Quoted 29 lines
---
 hw/mac_dbdma.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
hw/mac_dbdma.c +8 -0
index 98dccfd..4dbfc16 100644
@@ -40,6 +40,14 @@
 #include "isa.h"
 #include "mac_dbdma.h"
 
+/*
+ * XXX This is just plain wrong. Apparently we don't want to have big endian
+ *     values, but reversed endian ones. The code as is doesn't work on big
+ *     endian hosts. With these defines it does.
+ */
+#define cpu_to_be32 bswap32
+#define be32_to_cpu bswap32
+
 /* debug DBDMA */
 //#define DEBUG_DBDMA
 
Signature · 1 line
1.6.0.2
#2 lore raw
Quoted 24 lines · Michael S. Tsirkin
Quoted 10 lines · Alexander Graf

When we get an MMIO request, we always get variables in host endianness. The only time we need to actually reverse byte order is when we read bytes from guest memory.

Apparently the DBDMA implementation is different there. A lot of the logic in there depends on values being big endian. Now, qemu does all the conversion in the MMIO handlers for us already though, so it turns out that we're in the same byte order from a C point of view, but cpu_to_be32 and be32_to_cpu end up being nops.

Quoted 6 lines

This makes the code work differently on x86 (little endian) than on ppc (big endian). On x86 it works, on ppc it doesn't.

This patch (while being seriously hacky and ugly) makes dbdma emulation work on ppc hosts. I'll leave the real fixing to someone else.

Come on,

#define cpu_to_dbdma32 bswap32
#define dbdma_to_cpu32 bswap32

Quoted 7 lines

and then

s/cpu_to_be32/cpu_to_dbdma32/g
s/be32_to_cpu/dbdma32_to_cpu/g

is not too hard, is it?

Well, if I'd want to do a sed'ish approach I'd just

s/cpu_to_be32/bswap32/g
s/be32_to_cpu/bswap32/g

The problem is that the whole define is just plain wrong which tells me that the code is using the bswap functions incorrectly. This really needs to be fixed by someone who knows the dbdma device. I don't see how calling incorrect calls even more incorrect makes any difference.

Alex

#3 lore raw
Quoted 30 lines · Alexander Graf
Quoted 29 lines · Michael S. Tsirkin
Quoted 10 lines · Alexander Graf

When we get an MMIO request, we always get variables in host endianness. The only time we need to actually reverse byte order is when we read bytes from guest memory.

Apparently the DBDMA implementation is different there. A lot of the logic in there depends on values being big endian. Now, qemu does all the conversion in the MMIO handlers for us already though, so it turns out that we're in the same byte order from a C point of view, but cpu_to_be32 and be32_to_cpu end up being nops.

Quoted 6 lines

This makes the code work differently on x86 (little endian) than on ppc (big endian). On x86 it works, on ppc it doesn't.

This patch (while being seriously hacky and ugly) makes dbdma emulation work on ppc hosts. I'll leave the real fixing to someone else.

Come on,

#define cpu_to_dbdma32 bswap32
#define dbdma_to_cpu32 bswap32

and then

s/cpu_to_be32/cpu_to_dbdma32/g
s/be32_to_cpu/dbdma32_to_cpu/g

Quoted 7 lines
Quoted 2 lines

is not too hard, is it?

Well, if I'd want to do a sed'ish approach I'd just

s/cpu_to_be32/bswap32/g
s/be32_to_cpu/bswap32/g

This would throw away some information: it is better to know whether you are converting from or to cpu mode. Hopefully at some point we will add sparce annotations which will make this even more important.

Quoted 6 lines

The problem is that the whole define is just plain wrong which tells me that the code is using the bswap functions incorrectly. This really needs to be fixed by someone who knows the dbdma device. I don't see how calling incorrect calls even more incorrect makes any difference.

Alex

At least build will not break in strange ways e.g. when someone changes cpu_to_be32 to a macro. I don't really know about this hardware either, but why make it more fragile than it already is?

Signature · 1 line
MST