Skip to contentSkip to conversation

MIPS: Fixup and cleanup of TO_PHYS(), TO_CAC(), TO_UNCAC()

PATCH New Wu Zhangjin 1 participant 2 messages Apr 27, 2010 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 MIPS: Fixup and cleanup of TO_PHYS(), TO_CAC(), TO_UNCAC()

From: Wu Zhangjin <[email protected]>

This patch fixes the TO_UNCAC() interface of 64bit kernel, the TO_UNCAC(0xffffffff80000000) should yield 0x9000000000000000, but the old TO_UNCAC() yield 0x97ffffff80000100 and make the kernel stop booting with a bad address exception.

BTW, to share the same interface and remove the awful #ifdef, this patch also provide the TO_PHYS(), TO_CAC(), TO_UNCAC() interfaces for the 32bit kernel, then we can substitue TO_UNCAC() for lots of old KSEG1ADDR().

Thanks very much to Ralf, David, Thomas Bogendoerfer and [email protected] for their feedbacks of the following bug report:
http://www.linux-mips.org/archives/linux-mips/2010-04/msg00055.html

This patch is almost based on their feedbacks.

---
 arch/mips/include/asm/addrspace.h           |   13 +++++++++++++
 arch/mips/include/asm/mach-generic/spaces.h |    8 ++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
arch/mips/include/asm/addrspace.h +13 -0
index 569f80a..58c3fe7 100644
@@ -136,6 +136,19 @@
  */
 #define TO_PHYS_MASK	_CONST64_(0x07ffffffffffffff)	/* 2^^59 - 1 */
 
+#ifdef CONFIG_64BIT
+#define kernel_physaddr(x) ({ \
+	u64 a = (u64)(x); \
+	if ((a & CKSEG0) == CKSEG0) \
+		a = CPHYSADDR(a); \
+	else \
+		a &= TO_PHYS_MASK; \
+	a; \
+})
+#else
+#define kernel_physaddr	CPHYSADDR
+#endif
+
 #ifndef CONFIG_CPU_R8000
 
 /*
arch/mips/include/asm/mach-generic/spaces.h +4 -4
index c9fa4b1..710f160 100644
@@ -69,12 +69,12 @@
 #define HIGHMEM_START		(_AC(1, UL) << _AC(59, UL))
 #endif
 
-#define TO_PHYS(x)		(             ((x) & TO_PHYS_MASK))
-#define TO_CAC(x)		(CAC_BASE   | ((x) & TO_PHYS_MASK))
-#define TO_UNCAC(x)		(UNCAC_BASE | ((x) & TO_PHYS_MASK))
-
 #endif /* CONFIG_64BIT */
 
+#define TO_PHYS(x)		kernel_physaddr(x)
+#define TO_CAC(x)		(CAC_BASE   | kernel_physaddr(x))
+#define TO_UNCAC(x)		(UNCAC_BASE | kernel_physaddr(x))
+
 /*
  * This handles the memory map.
  */
Signature · 1 line
1.7.0
#1 lore raw

PATCH 2/2 MIPS: Cleanup of set_uncached_handler()

From: Wu Zhangjin <[email protected]>

The commit "MIPS: Fixup and cleanup of TO_PHYS(), TO_CAC(), TO_UNCAC()" has provided a TO_UNCAC() for 32bit kernel, so, we can share the same code between 32bit and 64bit kernel in set_uncached_handler().

---
 arch/mips/kernel/traps.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
arch/mips/kernel/traps.c +0 -5
index 1a4dd65..fb8cd40 100644
@@ -1557,12 +1557,7 @@ static char panic_null_cerr[] __cpuinitdata =
 void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
 	unsigned long size)
 {
-#ifdef CONFIG_32BIT
-	unsigned long uncached_ebase = KSEG1ADDR(ebase);
-#endif
-#ifdef CONFIG_64BIT
 	unsigned long uncached_ebase = TO_UNCAC(ebase);
-#endif
 
 	if (!addr)
 		panic(panic_null_cerr);
Signature · 1 line
1.7.0