From 541d945110751c61aff17a1fa2a747b6750e70f1 Mon Sep 17 00:00:00 2001
From: Blue Swirl <blauwirbel@gmail.com>
Date: Thu, 28 Jan 2010 21:47:28 +0000
Subject: [PATCH] QEMU changed PCI/IO port byte swapping, adapt OpenBIOS to new way

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 arch/sparc64/entry.S |    4 +-
 include/sparc64/io.h |   52 +++++++++++++++++++++++++------------------------
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/arch/sparc64/entry.S b/arch/sparc64/entry.S
index 750f7b1..91a550b 100644
--- a/arch/sparc64/entry.S
+++ b/arch/sparc64/entry.S
@@ -58,7 +58,7 @@ entry:
 
         ! Check signature "QEMU"
         setx    CFG_ADDR, %g2, %g5
-        mov     FW_CFG_SIGNATURE, %g2
+        mov     FW_CFG_SIGNATURE << 8, %g2
         stha    %g2, [%g5] ASI_PHYS_BYPASS_EC_E
         inc     %g5
         lduba   [%g5] ASI_PHYS_BYPASS_EC_E, %g2
@@ -97,7 +97,7 @@ entry:
 
         ! Get memory size from configuration device
         ! NB: little endian format
-        mov     FW_CFG_RAM_SIZE, %g2
+        mov     FW_CFG_RAM_SIZE << 8, %g2
         dec     %g5
         stha    %g2, [%g5] ASI_PHYS_BYPASS_EC_E
         inc     %g5
diff --git a/include/sparc64/io.h b/include/sparc64/io.h
index ea709d8..8b55793 100644
--- a/include/sparc64/io.h
+++ b/include/sparc64/io.h
@@ -75,29 +75,36 @@ static inline void out_8(volatile unsigned char *addr, int val)
 
 static inline int in_le16(volatile unsigned short *addr)
 {
-    int ret, tmp;
+    int ret;
 
     // XXX
     __asm__ __volatile__("lduha [%1] 0x15, %0\n\t"
                          :"=r"(ret):"r"(addr):"memory");
 
-    tmp = (ret << 8) & 0xff00;
-    tmp |= (ret >> 8) & 0xff;
-    return tmp;
+    return ret;
 }
 
 static inline int in_be16(volatile unsigned short *addr)
 {
-    int ret;
+    int ret, tmp;
 
     __asm__ __volatile__("lduha [%1] 0x15, %0\n\t"
                          :"=r"(ret):"r"(addr):"memory");
 
-    return ret;
+    tmp = (ret << 8) & 0xff00;
+    tmp |= (ret >> 8) & 0xff;
+    return tmp;
 }
 
 static inline void out_le16(volatile unsigned short *addr, int val)
 {
+
+    __asm__ __volatile__("stha %0, [%1] 0x15\n\t"
+                         : : "r"(val), "r"(addr):"memory");
+}
+
+static inline void out_be16(volatile unsigned short *addr, int val)
+{
     unsigned tmp;
 
     // XXX
@@ -107,40 +114,41 @@ static inline void out_le16(volatile unsigned short *addr, int val)
                          : : "r"(tmp), "r"(addr):"memory");
 }
 
-static inline void out_be16(volatile unsigned short *addr, int val)
+static inline unsigned in_le32(volatile unsigned *addr)
 {
-    __asm__ __volatile__("stha %0, [%1] 0x15\n\t"
-                         : : "r"(val), "r"(addr):"memory");
+    unsigned ret;
+
+    __asm__ __volatile__("lduwa [%1] 0x15, %0\n\t"
+                         :"=r"(ret):"r"(addr):"memory");
+
+    return ret;
 }
 
-static inline unsigned in_le32(volatile unsigned *addr)
+static inline unsigned in_be32(volatile unsigned *addr)
 {
     unsigned ret, tmp;
 
     // XXX
     __asm__ __volatile__("lduwa [%1] 0x15, %0\n\t"
                          :"=r"(ret):"r"(addr):"memory");
-
     tmp = ret << 24;
     tmp |= (ret << 8) & 0xff0000;
     tmp |= (ret >> 8) & 0xff00;
     tmp |= (ret >> 24) & 0xff;
+
     return tmp;
 }
 
-static inline unsigned in_be32(volatile unsigned *addr)
+static inline void out_le32(volatile unsigned *addr, int val)
 {
-    unsigned ret;
-
-    __asm__ __volatile__("lduwa [%1] 0x15, %0\n\t"
-                         :"=r"(ret):"r"(addr):"memory");
-
-    return ret;
+    __asm__ __volatile__("stwa %0, [%1] 0x15\n\t"
+                         : : "r"(val), "r"(addr):"memory");
 }
 
-static inline void out_le32(volatile unsigned *addr, int val)
+static inline void out_be32(volatile unsigned *addr, int val)
 {
     unsigned tmp;
+
     // XXX
     tmp = val << 24;
     tmp |= (val << 8) & 0xff0000;
@@ -150,12 +158,6 @@ static inline void out_le32(volatile unsigned *addr, int val)
                          : : "r"(tmp), "r"(addr):"memory");
 }
 
-static inline void out_be32(volatile unsigned *addr, int val)
-{
-    __asm__ __volatile__("stwa %0, [%1] 0x15\n\t"
-                         : : "r"(val), "r"(addr):"memory");
-}
-
 static inline void _insw_ns(volatile uint16_t * port, void *buf, int ns)
 {
 	uint16_t *b = (uint16_t *) buf;
-- 
1.5.6.5

