Skip to contentSkip to conversation

PHYS_OFFSET fix and cleanup

PATCH New Franck Bui-Huu 1 participant 5 messages Mar 27, 2007 MIPS

lore
Share & tools
lore
#0 lore raw

cover PHYS_OFFSET fix and cleanup

Ralf,

This small patchset deals with PHYS_OFFSET (last) issue.

Most of the patch are clean up and ease PHYS_OFFSET use except for the last one which is a real fix for 64-bits kernels with 32-bits symbols. Basically we now use CPHYSADDR() in __pa(). But this change implies that we could no more handle mapped kernel in this config. Do you think it's a real issue ?

Please consider,

Franck

---

 include/asm-mips/mach-generic/spaces.h |   30 +++++++++++++++++++++++++++---
 include/asm-mips/page.h                |   21 +++++++++------------
 2 files changed, 36 insertions(+), 15 deletions(-)
#1 lore raw

PATCH 1/4 Allow generic spaces.h to be included by platform specific ones

From: Franck Bui-Huu <[email protected]>

Before this patch, when a platform needed to customize one constant in spaces.h, they need to redefine all of them.

Now they can just redefine one constant and include the generic file header at the end:

	#include <asm/mach-generic/spaces.h>

This patch doesn't allow to redefine CAC_BASE, IO_BASE and UNCAC_BASE for 32 bits platforms because there's no need to do so.

This will avoid some macro duplications. It's important specially if we'll add complex macros.

---
 include/asm-mips/mach-generic/spaces.h |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
include/asm-mips/mach-generic/spaces.h +18 -0
index 0ae9997..9a3c521 100644
@@ -16,13 +16,18 @@
 #define CAC_BASE		0x80000000
 #define IO_BASE			0xa0000000
 #define UNCAC_BASE		0xa0000000
+
+#ifndef MAP_BASE
 #define MAP_BASE		0xc0000000
+#endif
 
 /*
  * This handles the memory map.
  * We handle pages at KSEG0 for kernels with 32 bit address space.
  */
+#ifndef PAGE_OFFSET
 #define PAGE_OFFSET		0x80000000UL
+#endif
 
 /*
  * Memory above this physical address will be considered highmem.
@@ -38,11 +43,13 @@
 /*
  * This handles the memory map.
  */
+#ifndef PAGE_OFFSET
 #ifdef CONFIG_DMA_NONCOHERENT
 #define PAGE_OFFSET	0x9800000000000000UL
 #else
 #define PAGE_OFFSET	0xa800000000000000UL
 #endif
+#endif
 
 /*
  * Memory above this physical address will be considered highmem.
@@ -53,14 +60,25 @@
 #define HIGHMEM_START		(1UL << 59UL)
 #endif
 
+#ifndef CAC_BASE
 #ifdef CONFIG_DMA_NONCOHERENT
 #define CAC_BASE		0x9800000000000000UL
 #else
 #define CAC_BASE		0xa800000000000000UL
 #endif
+#endif
+
+#ifndef IO_BASE
 #define IO_BASE			0x9000000000000000UL
+#endif
+
+#ifndef UNCAC_BASE
 #define UNCAC_BASE		0x9000000000000000UL
+#endif
+
+#ifndef MAP_BASE
 #define MAP_BASE		0xc000000000000000UL
+#endif
 
 #define TO_PHYS(x)		(             ((x) & TO_PHYS_MASK))
 #define TO_CAC(x)		(CAC_BASE   | ((x) & TO_PHYS_MASK))
Signature · 1 line
1.5.1.rc1.27.g1d848
#2 lore raw

PATCH 2/4 Make PAGE_OFFSET aware of PHYS_OFFSET

In reply to Franck Bui-Huu

From: Franck Bui-Huu <[email protected]>

For platforms that use PHYS_OFFSET and do not use a mapped kernel, this patch automatically adds PHYS_OFFSET into PAGE_OFFSET. Therefore there are no more needs for them to redefine PAGE_OFFSET.

For mapped kernel, they need to redefine PAGE_OFFSET anyways.

---
 include/asm-mips/mach-generic/spaces.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
include/asm-mips/mach-generic/spaces.h +3 -3
index 9a3c521..512bca5 100644
@@ -26,7 +26,7 @@
  * We handle pages at KSEG0 for kernels with 32 bit address space.
  */
 #ifndef PAGE_OFFSET
-#define PAGE_OFFSET		0x80000000UL
+#define PAGE_OFFSET		(0x80000000UL + PHYS_OFFSET)
 #endif
 
 /*
@@ -45,9 +45,9 @@
  */
 #ifndef PAGE_OFFSET
 #ifdef CONFIG_DMA_NONCOHERENT
-#define PAGE_OFFSET	0x9800000000000000UL
+#define PAGE_OFFSET		(0x9800000000000000UL + PHYS_OFFSET)
 #else
-#define PAGE_OFFSET	0xa800000000000000UL
+#define PAGE_OFFSET		(0xa800000000000000UL + PHYS_OFFSET)
 #endif
 #endif
 
Signature · 1 line
1.5.1.rc1.27.g1d848
#3 lore raw

PATCH 3/4 Move PHY_OFFSET definition in spaces.h

In reply to Franck Bui-Huu

From: Franck Bui-Huu <[email protected]>

---
 include/asm-mips/mach-generic/spaces.h |    6 ++++++
 include/asm-mips/page.h                |   11 ++---------
 2 files changed, 8 insertions(+), 9 deletions(-)
include/asm-mips/mach-generic/spaces.h +6 -0
index 512bca5..8b5e432 100644
@@ -10,6 +10,12 @@
 #ifndef _ASM_MACH_GENERIC_SPACES_H
 #define _ASM_MACH_GENERIC_SPACES_H
 
+/*
+ * This gives the physical RAM offset.
+ */
+#ifndef PHYS_OFFSET
+#define PHYS_OFFSET		0UL
+#endif
 
 #ifdef CONFIG_32BIT
 
include/asm-mips/page.h +2 -9
index d3fbd83..cc28a4f 100644
@@ -34,12 +34,8 @@
 
 #ifndef __ASSEMBLY__
 
-/*
- * This gives the physical RAM offset.
- */
-#ifndef PHYS_OFFSET
-#define PHYS_OFFSET		0UL
-#endif
+#include <linux/pfn.h>
+#include <asm/io.h>
 
 /*
  * It's normally defined only for FLATMEM config but it's
@@ -48,9 +44,6 @@
  */
 #define ARCH_PFN_OFFSET		PFN_UP(PHYS_OFFSET)
 
-#include <linux/pfn.h>
-#include <asm/io.h>
-
 extern void clear_page(void * page);
 extern void copy_page(void * to, void * from);
 
Signature · 1 line
1.5.1.rc1.27.g1d848
#4 lore raw

PATCH 4/4 Fix PHYS_OFFSET for 64-bits kernels with 32-bits symbols

In reply to Franck Bui-Huu

From: Franck Bui-Huu <[email protected]>

The current implementation of __pa() for 64-bits kernels with 32-bits symbols is broken. In this configuration, we need 2 values for PAGE_OFFSET, one in XKPHYS and the other in CKSEG0 space.

When the value in CKSEG0 space is used, it doesn't take into account of PHYS_OFFSET. Even worse we can't redefine this value.

The patch restores CPHYSADDR() but in __pa()'s implementation because it removes the need of 2 PAGE_OFFSET.

OTOH, CPHYSADDR() is quite bad when dealing with mapped kernels. So this patch assumes there's no need to deal with such kernel in 64-bits world.

---
 include/asm-mips/page.h |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
include/asm-mips/page.h +7 -3
index cc28a4f..62ee3d5 100644
@@ -143,11 +143,15 @@ typedef struct { unsigned long pgprot; } pgprot_t;
  * __pa()/__va() should be used only during mem init.
  */
 #if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
-#define __pa_page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
+#define __pa(x)								\
+({									\
+    unsigned long __x = (unsigned long)(x);				\
+    __x < CKSEG0 ? XPHYSADDR(__x) : CPHYSADDR(__x);			\
+})
 #else
-#define __pa_page_offset(x)	PAGE_OFFSET
+#define __pa(x)								\
+    ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
 #endif
-#define __pa(x)		((unsigned long)(x) - __pa_page_offset(x) + PHYS_OFFSET)
 #define __va(x)		((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
 #define __pa_symbol(x)	__pa(RELOC_HIDE((unsigned long)(x),0))
 
Signature · 1 line
1.5.1.rc1.27.g1d848