Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-13 12:38 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #2] Franck Bui-Huu
@ 2006-10-13 12:39 ` Franck Bui-Huu
  2006-10-13 16:27   ` Atsushi Nemoto
  2006-10-19  4:01   ` Atsushi Nemoto
  0 siblings, 2 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-13 12:39 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

During early boot mem init, some configs couldn't use __pa() to
convert virtual into physical addresses. Specially for 64 bit
kernel cases when CONFIG_BUILD_ELF64=n. This patch make __pa()
work for _all_ configs and thus make CPHYSADDR() useless.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 include/asm-mips/page.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index 0821eb0..5da4733 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -131,8 +131,13 @@ #endif /* !__ASSEMBLY__ */
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
 
-#define __pa(x)			((unsigned long) (x) - PAGE_OFFSET)
-#define __va(x)			((void *)((unsigned long) (x) + PAGE_OFFSET))
+#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
+#define __page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
+#else
+#define __page_offset(x)	PAGE_OFFSET
+#endif
+#define __pa(x)			((unsigned long)(x) - __page_offset(x))
+#define __va(x)			((void *)((unsigned long)(x) + __page_offset(x)))
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-13 12:39 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
@ 2006-10-13 16:27   ` Atsushi Nemoto
  2006-10-14  8:39     ` Franck Bui-Huu
  2006-10-19  4:01   ` Atsushi Nemoto
  1 sibling, 1 reply; 20+ messages in thread
From: Atsushi Nemoto @ 2006-10-13 16:27 UTC (permalink / raw)
  To: vagabon.xyz; +Cc: ralf, ths, linux-mips, fbuihuu

On Fri, 13 Oct 2006 14:39:01 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> -#define __pa(x)			((unsigned long) (x) - PAGE_OFFSET)
> -#define __va(x)			((void *)((unsigned long) (x) + PAGE_OFFSET))
> +#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
> +#define __page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
> +#else
> +#define __page_offset(x)	PAGE_OFFSET
> +#endif
> +#define __pa(x)			((unsigned long)(x) - __page_offset(x))
> +#define __va(x)			((void *)((unsigned long)(x) + __page_offset(x)))

In __va(), you are passing an physical address to __page_offset().

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-13 16:27   ` Atsushi Nemoto
@ 2006-10-14  8:39     ` Franck Bui-Huu
  0 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-14  8:39 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: ralf, ths, linux-mips, fbuihuu

On 10/13/06, Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:
> On Fri, 13 Oct 2006 14:39:01 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> > -#define __pa(x)                      ((unsigned long) (x) - PAGE_OFFSET)
> > -#define __va(x)                      ((void *)((unsigned long) (x) + PAGE_OFFSET))
> > +#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
> > +#define __page_offset(x)     ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
> > +#else
> > +#define __page_offset(x)     PAGE_OFFSET
> > +#endif
> > +#define __pa(x)                      ((unsigned long)(x) - __page_offset(x))
> > +#define __va(x)                      ((void *)((unsigned long)(x) + __page_offset(x)))
>
> In __va(), you are passing an physical address to __page_offset().
>

oops, good catch ! I'll change that.

thanks
-- 
               Franck

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-16 16:12 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #3] Franck Bui-Huu
@ 2006-10-16 16:12 ` Franck Bui-Huu
  0 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-16 16:12 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

During early boot mem init, some configs couldn't use __pa() to
convert virtual into physical addresses. Specially for 64 bit
kernel cases when CONFIG_BUILD_ELF64=n. This patch make __pa()
work for _all_ configs and thus make CPHYSADDR() useless.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 include/asm-mips/page.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index fa4e4d9..df3a87e 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -133,8 +133,13 @@ #endif /* !__ASSEMBLY__ */
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
 
-#define __pa(x)			((unsigned long) (x) - PAGE_OFFSET)
-#define __va(x)			((void *)((unsigned long) (x) + PAGE_OFFSET))
+#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
+#define __pa_page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
+#else
+#define __pa_page_offset(x)	PAGE_OFFSET
+#endif
+#define __pa(x)			((unsigned long)(x) - __pa_page_offset(x))
+#define __va(x)			((void *)((unsigned long)(x) + PAGE_OFFSET))
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-13 12:39 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
  2006-10-13 16:27   ` Atsushi Nemoto
@ 2006-10-19  4:01   ` Atsushi Nemoto
  2006-10-19  6:20     ` Franck Bui-Huu
  2006-10-19  6:41     ` Yoichi Yuasa
  1 sibling, 2 replies; 20+ messages in thread
From: Atsushi Nemoto @ 2006-10-19  4:01 UTC (permalink / raw)
  To: vagabon.xyz; +Cc: ralf, ths, linux-mips, fbuihuu

On Fri, 13 Oct 2006 14:39:01 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> +#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
> +#define __page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)

CONFIG_64BIT, not CONFIG_64BITS.  Sorry, my mistake.

Also since CKSEG0 is defined with _LLCONST_ macro, the final type of
__page_offset(), __pa(), __pa_sym() will be "unsigned long long", not
"unsigned long".  This raise a "comparison of distinct pointer types
lacks a cast" warning on this line.

	reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));

A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned
long" here, but it might be preferred to change _LLCONST_ definition
like this.  What do you think?


Subject: Use "long" for _ATYPE64_ and _LLCONST_ on 64-bit kernel.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

diff --git a/include/asm-mips/addrspace.h b/include/asm-mips/addrspace.h
index 45c706e..5005555 100644
--- a/include/asm-mips/addrspace.h
+++ b/include/asm-mips/addrspace.h
@@ -23,9 +23,14 @@ #define _LLCONST_(x)	x
 #else
 #define _ATYPE_		__PTRDIFF_TYPE__
 #define _ATYPE32_	int
+#ifdef CONFIG_64BIT
+#define _ATYPE64_	long
+#define _LLCONST_(x)	x ## L
+#else
 #define _ATYPE64_	long long
 #define _LLCONST_(x)	x ## LL
 #endif
+#endif
 
 /*
  *  32-bit MIPS address spaces


---
Atsushi Nemoto

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  4:01   ` Atsushi Nemoto
@ 2006-10-19  6:20     ` Franck Bui-Huu
  2006-10-19  6:41     ` Yoichi Yuasa
  1 sibling, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19  6:20 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: ralf, ths, linux-mips

On 10/19/06, Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:
>
> A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned
> long" here, but it might be preferred to change _LLCONST_ definition
> like this.  What do you think?
>

I think _LLCONST_ change is the correct thing to do. Can you please
submit your patch to Ralf ?

thanks
-- 
               Franck

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  4:01   ` Atsushi Nemoto
  2006-10-19  6:20     ` Franck Bui-Huu
@ 2006-10-19  6:41     ` Yoichi Yuasa
  2006-10-19  7:01       ` Atsushi Nemoto
  1 sibling, 1 reply; 20+ messages in thread
From: Yoichi Yuasa @ 2006-10-19  6:41 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: yoichi_yuasa, vagabon.xyz, ralf, ths, linux-mips, fbuihuu

On Thu, 19 Oct 2006 13:01:33 +0900 (JST)
Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:

> On Fri, 13 Oct 2006 14:39:01 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> > +#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64)
> > +#define __page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
> 
> CONFIG_64BIT, not CONFIG_64BITS.  Sorry, my mistake.
> 
> Also since CKSEG0 is defined with _LLCONST_ macro, the final type of
> __page_offset(), __pa(), __pa_sym() will be "unsigned long long", not
> "unsigned long".  This raise a "comparison of distinct pointer types
> lacks a cast" warning on this line.
> 
> 	reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));
> 
> A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned
> long" here, but it might be preferred to change _LLCONST_ definition
> like this.  What do you think?
> 
> 
> Subject: Use "long" for _ATYPE64_ and _LLCONST_ on 64-bit kernel.
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> 
> diff --git a/include/asm-mips/addrspace.h b/include/asm-mips/addrspace.h
> index 45c706e..5005555 100644
> --- a/include/asm-mips/addrspace.h
> +++ b/include/asm-mips/addrspace.h
> @@ -23,9 +23,14 @@ #define _LLCONST_(x)	x
>  #else
>  #define _ATYPE_		__PTRDIFF_TYPE__
>  #define _ATYPE32_	int
> +#ifdef CONFIG_64BIT
> +#define _ATYPE64_	long
> +#define _LLCONST_(x)	x ## L
            ^^               ^
The name is not corresponding to reality.
It's not so good.

Yoichi

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  6:41     ` Yoichi Yuasa
@ 2006-10-19  7:01       ` Atsushi Nemoto
  2006-10-19  7:23         ` Yoichi Yuasa
  2006-10-19  7:43         ` Franck Bui-Huu
  0 siblings, 2 replies; 20+ messages in thread
From: Atsushi Nemoto @ 2006-10-19  7:01 UTC (permalink / raw)
  To: yoichi_yuasa; +Cc: vagabon.xyz, ralf, ths, linux-mips, fbuihuu

On Thu, 19 Oct 2006 15:41:38 +0900, Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> wrote:
> > +#define _LLCONST_(x)	x ## L
>             ^^               ^
> The name is not corresponding to reality.
> It's not so good.

Indeed.  How about this?


Subject: Use "long" for 64-bit values on 64-bit kernel.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

diff --git a/include/asm-mips/addrspace.h b/include/asm-mips/addrspace.h
index 45c706e..7401711 100644
--- a/include/asm-mips/addrspace.h
+++ b/include/asm-mips/addrspace.h
@@ -19,12 +19,17 @@ #ifdef __ASSEMBLY__
 #define _ATYPE_
 #define _ATYPE32_
 #define _ATYPE64_
-#define _LLCONST_(x)	x
+#define _CONST64_(x)	x
 #else
 #define _ATYPE_		__PTRDIFF_TYPE__
 #define _ATYPE32_	int
+#ifdef CONFIG_64BIT
+#define _ATYPE64_	long
+#define _CONST64_(x)	x ## L
+#else
 #define _ATYPE64_	long long
-#define _LLCONST_(x)	x ## LL
+#define _CONST64_(x)	x ## LL
+#endif
 #endif
 
 /*
@@ -48,7 +53,7 @@ #define KSEGX(a)		((_ACAST32_ (a)) & 0xe
  */
 #define CPHYSADDR(a)		((_ACAST32_(a)) & 0x1fffffff)
 #define XPHYSADDR(a)            ((_ACAST64_(a)) &			\
-				 _LLCONST_(0x000000ffffffffff))
+				 _CONST64_(0x000000ffffffffff))
 
 #ifdef CONFIG_64BIT
 
@@ -57,14 +62,14 @@ #ifdef CONFIG_64BIT
  * The compatibility segments use the full 64-bit sign extended value.  Note
  * the R8000 doesn't have them so don't reference these in generic MIPS code.
  */
-#define XKUSEG			_LLCONST_(0x0000000000000000)
-#define XKSSEG			_LLCONST_(0x4000000000000000)
-#define XKPHYS			_LLCONST_(0x8000000000000000)
-#define XKSEG			_LLCONST_(0xc000000000000000)
-#define CKSEG0			_LLCONST_(0xffffffff80000000)
-#define CKSEG1			_LLCONST_(0xffffffffa0000000)
-#define CKSSEG			_LLCONST_(0xffffffffc0000000)
-#define CKSEG3			_LLCONST_(0xffffffffe0000000)
+#define XKUSEG			_CONST64_(0x0000000000000000)
+#define XKSSEG			_CONST64_(0x4000000000000000)
+#define XKPHYS			_CONST64_(0x8000000000000000)
+#define XKSEG			_CONST64_(0xc000000000000000)
+#define CKSEG0			_CONST64_(0xffffffff80000000)
+#define CKSEG1			_CONST64_(0xffffffffa0000000)
+#define CKSSEG			_CONST64_(0xffffffffc0000000)
+#define CKSEG3			_CONST64_(0xffffffffe0000000)
 
 #define CKSEG0ADDR(a)		(CPHYSADDR(a) | CKSEG0)
 #define CKSEG1ADDR(a)		(CPHYSADDR(a) | CKSEG1)
@@ -122,7 +127,7 @@ #define K_CALG_UNCACHED_ACCEL	7
 #define PHYS_TO_XKSEG_UNCACHED(p)	PHYS_TO_XKPHYS(K_CALG_UNCACHED,(p))
 #define PHYS_TO_XKSEG_CACHED(p)		PHYS_TO_XKPHYS(K_CALG_COH_SHAREABLE,(p))
 #define XKPHYS_TO_PHYS(p)		((p) & TO_PHYS_MASK)
-#define PHYS_TO_XKPHYS(cm,a)		(_LLCONST_(0x8000000000000000) | \
+#define PHYS_TO_XKPHYS(cm,a)		(_CONST64_(0x8000000000000000) | \
 					 ((cm)<<59) | (a))
 
 #if defined (CONFIG_CPU_R4300)						\
@@ -132,20 +137,20 @@ #if defined (CONFIG_CPU_R4300)						\
     || defined (CONFIG_CPU_NEVADA)					\
     || defined (CONFIG_CPU_TX49XX)					\
     || defined (CONFIG_CPU_MIPS64)
-#define TO_PHYS_MASK	_LLCONST_(0x0000000fffffffff)	/* 2^^36 - 1 */
+#define TO_PHYS_MASK	_CONST64_(0x0000000fffffffff)	/* 2^^36 - 1 */
 #endif
 
 #if defined (CONFIG_CPU_R8000)
 /* We keep KUSIZE consistent with R4000 for now (2^^40) instead of (2^^48) */
-#define TO_PHYS_MASK	_LLCONST_(0x000000ffffffffff)	/* 2^^40 - 1 */
+#define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif
 
 #if defined (CONFIG_CPU_R10000)
-#define TO_PHYS_MASK	_LLCONST_(0x000000ffffffffff)	/* 2^^40 - 1 */
+#define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif
 
 #if defined(CONFIG_CPU_SB1) || defined(CONFIG_CPU_SB1A)
-#define TO_PHYS_MASK	_LLCONST_(0x00000fffffffffff)	/* 2^^44 - 1 */
+#define TO_PHYS_MASK	_CONST64_(0x00000fffffffffff)	/* 2^^44 - 1 */
 #endif
 
 #ifndef CONFIG_CPU_R8000
@@ -155,7 +160,7 @@ #ifndef CONFIG_CPU_R8000
  * in order to catch bugs in the source code.
  */
 
-#define COMPAT_K1BASE32		_LLCONST_(0xffffffffa0000000)
+#define COMPAT_K1BASE32		_CONST64_(0xffffffffa0000000)
 #define PHYS_TO_COMPATK1(x)	((x) | COMPAT_K1BASE32) /* 32-bit compat k1 */
 
 #endif

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  7:01       ` Atsushi Nemoto
@ 2006-10-19  7:23         ` Yoichi Yuasa
  2006-10-19  7:43         ` Franck Bui-Huu
  1 sibling, 0 replies; 20+ messages in thread
From: Yoichi Yuasa @ 2006-10-19  7:23 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: yoichi_yuasa, vagabon.xyz, ralf, ths, linux-mips, fbuihuu

On Thu, 19 Oct 2006 16:01:45 +0900 (JST)
Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:

> On Thu, 19 Oct 2006 15:41:38 +0900, Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> wrote:
> > > +#define _LLCONST_(x)	x ## L
> >             ^^               ^
> > The name is not corresponding to reality.
> > It's not so good.
> 
> Indeed.  How about this?
> 
> 
> Subject: Use "long" for 64-bit values on 64-bit kernel.
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> 
> diff --git a/include/asm-mips/addrspace.h b/include/asm-mips/addrspace.h
> index 45c706e..7401711 100644
> --- a/include/asm-mips/addrspace.h
> +++ b/include/asm-mips/addrspace.h
> @@ -19,12 +19,17 @@ #ifdef __ASSEMBLY__
>  #define _ATYPE_
>  #define _ATYPE32_
>  #define _ATYPE64_
> -#define _LLCONST_(x)	x
> +#define _CONST64_(x)	x
>  #else
>  #define _ATYPE_		__PTRDIFF_TYPE__
>  #define _ATYPE32_	int
> +#ifdef CONFIG_64BIT
> +#define _ATYPE64_	long
> +#define _CONST64_(x)	x ## L
> +#else
>  #define _ATYPE64_	long long
> -#define _LLCONST_(x)	x ## LL
> +#define _CONST64_(x)	x ## LL
> +#endif
>  #endif

<snip>

It's good for me.

Thanks,

Yoichi

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  7:01       ` Atsushi Nemoto
  2006-10-19  7:23         ` Yoichi Yuasa
@ 2006-10-19  7:43         ` Franck Bui-Huu
  2006-10-19  7:59           ` Atsushi Nemoto
  1 sibling, 1 reply; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19  7:43 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: yoichi_yuasa, vagabon.xyz, ralf, ths, linux-mips, fbuihuu

Atsushi Nemoto wrote:
> On Thu, 19 Oct 2006 15:41:38 +0900, Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> wrote:
>>> +#define _LLCONST_(x)	x ## L
>>             ^^               ^
>> The name is not corresponding to reality.
>> It's not so good.
> 
> Indeed.  How about this?
> 

or why not simply replacing _LLCONST_ usages by _LCONST_ ? After all,
64 bits value seems to be used only for 64 bits kernels.

		Franck

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19  7:43         ` Franck Bui-Huu
@ 2006-10-19  7:59           ` Atsushi Nemoto
  0 siblings, 0 replies; 20+ messages in thread
From: Atsushi Nemoto @ 2006-10-19  7:59 UTC (permalink / raw)
  To: vagabon.xyz; +Cc: yoichi_yuasa, ralf, ths, linux-mips, fbuihuu

On Thu, 19 Oct 2006 09:43:56 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> or why not simply replacing _LLCONST_ usages by _LCONST_ ? After all,
> 64 bits value seems to be used only for 64 bits kernels.

Well, I suppose 32bit kernel might want to use 64bit values, for
example, CONFIG_64BIT_PHYS_ADDR.

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4]
@ 2006-10-19 11:19 Franck Bui-Huu
  2006-10-19 11:19 ` [PATCH 1/7] page.h: remove __pa() usages Franck Bui-Huu
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:19 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips

Changes since take #3
--------------------
  * Sign extension hack still needed by rd_start_early() (Atsushi)
  * Replace panic() by printk() in init_initrd() (Atsushi)
  * Fix CONFIG_64BITS typo (Atsushi)
  * Add a new sanity check in init_initrd():
		initrd_start < PAGE_OFFSET

Changes since take #2
--------------------
  * More initrd code clean up. It should be more readable and
    more robust now.
  * Add some missing include in page.h (Atsushi)
  * Fix a wrong use of __page_offset() in __va() (Atsushi)
  * Rename __page_offset() into __pa_page_offset()

changes since take #1
--------------------
  * Changed the definition of __pa() for 64-bits kernels to match
    the one suggested by Atsushi. It should be safer.
  * Make virt_to_page() uses virt_to_phys() instead of __pa().


Thanks to Atsushi for testing this patchset on 64 bit kernels.

Please consider,

		Franck
---

 arch/mips/kernel/setup.c   |   87 +++++++++++++++++++++++++++-----------------
 arch/mips/mm/init.c        |   42 ++++++++++-----------
 include/asm-mips/io.h      |    2 +
 include/asm-mips/page.h    |   16 ++++++--
 include/asm-mips/pgtable.h |    2 +
 5 files changed, 87 insertions(+), 62 deletions(-)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/7] page.h: remove __pa() usages.
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
@ 2006-10-19 11:19 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:19 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

__pa() was used by virt_to_page() and virt_addr_valid(). These
latter are used when kernel is initialised so __pa() is not
appropriate, we use virt_to_phys() instead.

Futhermore __pa() is going to take care of CKSEG0/XKPHYS
address mix for 64 bit kernels. This makes __pa() more complex
than virt_to_phys() and this extra work is not needed by
virt_to_page() and virt_addr_valid().

Eventually it consolidates virt_to_phys() prototype by making
its argument 'const'. this avoids some warnings that was due
to some virt_to_page() usages which pass const pointer.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/mm/init.c        |    8 ++++----
 include/asm-mips/io.h      |    2 +-
 include/asm-mips/page.h    |    6 ++++--
 include/asm-mips/pgtable.h |    2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 2f346d1..4431ea0 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -90,9 +90,9 @@ unsigned long setup_zero_pages(void)
 	if (!empty_zero_page)
 		panic("Oh boy, that early out of memory?");
 
-	page = virt_to_page(empty_zero_page);
+	page = virt_to_page((void *)empty_zero_page);
 	split_page(page, order);
-	while (page < virt_to_page(empty_zero_page + (PAGE_SIZE << order))) {
+	while (page < virt_to_page((void *)(empty_zero_page + (PAGE_SIZE << order)))) {
 		SetPageReserved(page);
 		page++;
 	}
@@ -490,8 +490,8 @@ void free_init_pages(char *what, unsigne
 	unsigned long addr;
 
 	for (addr = begin; addr < end; addr += PAGE_SIZE) {
-		ClearPageReserved(virt_to_page(addr));
-		init_page_count(virt_to_page(addr));
+		ClearPageReserved(virt_to_page((void *)addr));
+		init_page_count(virt_to_page((void *)addr));
 		memset((void *)addr, 0xcc, PAGE_SIZE);
 		free_page(addr);
 		totalram_pages++;
diff --git a/include/asm-mips/io.h b/include/asm-mips/io.h
index d5307dd..9b9f804 100644
--- a/include/asm-mips/io.h
+++ b/include/asm-mips/io.h
@@ -113,7 +113,7 @@ #endif
  *     almost all conceivable cases a device driver should not be using
  *     this function
  */
-static inline unsigned long virt_to_phys(volatile void * address)
+static inline unsigned long virt_to_phys(volatile const void *address)
 {
 	return (unsigned long)address - PAGE_OFFSET;
 }
diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index 32e5625..fa4e4d9 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -34,7 +34,9 @@ #define PAGE_MASK       (~((1 << PAGE_SH
 
 #ifndef __ASSEMBLY__
 
+#include <linux/pfn.h>
 #include <asm/cpu-features.h>
+#include <asm/io.h>
 
 extern void clear_page(void * page);
 extern void copy_page(void * to, void * from);
@@ -157,8 +159,8 @@ ({									\
 
 #endif
 
-#define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
-#define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
+#define virt_to_page(kaddr)	pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))
+#define virt_addr_valid(kaddr)	pfn_valid(PFN_DOWN(virt_to_phys(kaddr)))
 
 #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
diff --git a/include/asm-mips/pgtable.h b/include/asm-mips/pgtable.h
index 1ca4d1e..f2e1325 100644
--- a/include/asm-mips/pgtable.h
+++ b/include/asm-mips/pgtable.h
@@ -67,7 +67,7 @@ extern unsigned long empty_zero_page;
 extern unsigned long zero_page_mask;
 
 #define ZERO_PAGE(vaddr) \
-	(virt_to_page(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask)))
+	(virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
 
 #define __HAVE_ARCH_MOVE_PTE
 #define move_pte(pte, prot, old_addr, new_addr)				\
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
  2006-10-19 11:19 ` [PATCH 1/7] page.h: remove __pa() usages Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 3/7] setup.c: get ride of CPHYSADDR() Franck Bui-Huu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

During early boot mem init, some configs couldn't use __pa() to
convert virtual into physical addresses. Specially for 64 bit
kernel cases when CONFIG_BUILD_ELF64=n. This patch make __pa()
work for _all_ configs and thus make CPHYSADDR() useless.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 include/asm-mips/page.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index fa4e4d9..119daee 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -133,8 +133,13 @@ #endif /* !__ASSEMBLY__ */
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
 
-#define __pa(x)			((unsigned long) (x) - PAGE_OFFSET)
-#define __va(x)			((void *)((unsigned long) (x) + PAGE_OFFSET))
+#if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
+#define __pa_page_offset(x)	((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
+#else
+#define __pa_page_offset(x)	PAGE_OFFSET
+#endif
+#define __pa(x)			((unsigned long)(x) - __pa_page_offset(x))
+#define __va(x)			((void *)((unsigned long)(x) + PAGE_OFFSET))
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 3/7] setup.c: get ride of CPHYSADDR()
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
  2006-10-19 11:19 ` [PATCH 1/7] page.h: remove __pa() usages Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 4/7] Introduce __pa_symbol() Franck Bui-Huu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

and use new __pa() implementation instead introduced by the previous
patch. Indeed this macro can be used now even by the 64 bit kernels
with CONFIG_BUILD_ELF64=n config.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/setup.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 8f6e896..715451a 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -204,12 +204,12 @@ static void __init finalize_initrd(void)
 		printk(KERN_INFO "Initrd not found or empty");
 		goto disable;
 	}
-	if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
+	if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
 		printk("Initrd extends beyond end of memory");
 		goto disable;
 	}
 
-	reserve_bootmem(CPHYSADDR(initrd_start), size);
+	reserve_bootmem(__pa(initrd_start), size);
 	initrd_below_start_ok = 1;
 
 	printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
@@ -260,7 +260,7 @@ static void __init bootmem_init(void)
 	 * of usable memory.
 	 */
 	reserved_end = init_initrd();
-	reserved_end = PFN_UP(CPHYSADDR(max(reserved_end, (unsigned long)&_end)));
+	reserved_end = PFN_UP(__pa(max(reserved_end, (unsigned long)&_end)));
 
 	/*
 	 * Find the highest page frame number we have available.
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 4/7] Introduce __pa_symbol()
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
                   ` (2 preceding siblings ...)
  2006-10-19 11:20 ` [PATCH 3/7] setup.c: get ride of CPHYSADDR() Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 5/7] setup.c: use __pa_symbol() where needed Franck Bui-Huu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

This patch introduces __pa_symbol() macro which should be used to
calculate the physical address of kernel symbols. It also relies
on RELOC_HIDE() to avoid any compiler's oddities when doing
arithmetics on symbols.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 include/asm-mips/page.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index 119daee..5c4284b 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -139,6 +139,7 @@ #else
 #define __pa_page_offset(x)	PAGE_OFFSET
 #endif
 #define __pa(x)			((unsigned long)(x) - __pa_page_offset(x))
+#define __pa_symbol(x)		__pa(RELOC_HIDE((unsigned long)(x),0))
 #define __va(x)			((void *)((unsigned long)(x) + PAGE_OFFSET))
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 5/7] setup.c: use __pa_symbol() where needed
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
                   ` (3 preceding siblings ...)
  2006-10-19 11:20 ` [PATCH 4/7] Introduce __pa_symbol() Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 6/7] setup.c: clean up initrd related code Franck Bui-Huu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

It should fix the broken code in resource_init() too.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/setup.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 715451a..b52cc97 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -260,7 +260,7 @@ static void __init bootmem_init(void)
 	 * of usable memory.
 	 */
 	reserved_end = init_initrd();
-	reserved_end = PFN_UP(__pa(max(reserved_end, (unsigned long)&_end)));
+	reserved_end = PFN_UP(max(__pa(reserved_end), __pa_symbol(&_end)));
 
 	/*
 	 * Find the highest page frame number we have available.
@@ -432,10 +432,10 @@ static void __init resource_init(void)
 	if (UNCAC_BASE != IO_BASE)
 		return;
 
-	code_resource.start = virt_to_phys(&_text);
-	code_resource.end = virt_to_phys(&_etext) - 1;
-	data_resource.start = virt_to_phys(&_etext);
-	data_resource.end = virt_to_phys(&_edata) - 1;
+	code_resource.start = __pa_symbol(&_text);
+	code_resource.end = __pa_symbol(&_etext) - 1;
+	data_resource.start = __pa_symbol(&_etext);
+	data_resource.end = __pa_symbol(&_edata) - 1;
 
 	/*
 	 * Request address space for all standard RAM.
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 6/7] setup.c: clean up initrd related code
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
                   ` (4 preceding siblings ...)
  2006-10-19 11:20 ` [PATCH 5/7] setup.c: use __pa_symbol() where needed Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-19 11:20 ` [PATCH 7/7] Make free_init_pages() arguments to be physical addresses Franck Bui-Huu
  2006-10-20  3:19 ` [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Atsushi Nemoto
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/setup.c |   75 +++++++++++++++++++++++++++++-----------------
 arch/mips/mm/init.c      |    5 ---
 2 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index b52cc97..89440a0 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -145,13 +145,12 @@ static int __init rd_start_early(char *p
 	unsigned long start = memparse(p, &p);
 
 #ifdef CONFIG_64BIT
-	/* HACK: Guess if the sign extension was forgotten */
-	if (start > 0x0000000080000000 && start < 0x00000000ffffffff)
-		start |= 0xffffffff00000000UL;
+	/* Guess if the sign extension was forgotten by bootloader */
+	if (start < XKPHYS)
+		start = (int)start;
 #endif
 	initrd_start = start;
 	initrd_end += start;
-
 	return 0;
 }
 early_param("rd_start", rd_start_early);
@@ -159,41 +158,64 @@ early_param("rd_start", rd_start_early);
 static int __init rd_size_early(char *p)
 {
 	initrd_end += memparse(p, &p);
-
 	return 0;
 }
 early_param("rd_size", rd_size_early);
 
+/* it returns the next free pfn after initrd */
 static unsigned long __init init_initrd(void)
 {
-	unsigned long tmp, end, size;
+	unsigned long end;
 	u32 *initrd_header;
 
-	ROOT_DEV = Root_RAM0;
-
 	/*
 	 * Board specific code or command line parser should have
 	 * already set up initrd_start and initrd_end. In these cases
 	 * perfom sanity checks and use them if all looks good.
 	 */
-	size = initrd_end - initrd_start;
-	if (initrd_end == 0 || size == 0) {
-		initrd_start = 0;
-		initrd_end = 0;
-	} else
-		return initrd_end;
-
-	end = (unsigned long)&_end;
-	tmp = PAGE_ALIGN(end) - sizeof(u32) * 2;
-	if (tmp < end)
-		tmp += PAGE_SIZE;
-
-	initrd_header = (u32 *)tmp;
-	if (initrd_header[0] == 0x494E5244) {
-		initrd_start = (unsigned long)&initrd_header[2];
-		initrd_end = initrd_start + initrd_header[1];
+	if (initrd_start && initrd_end > initrd_start)
+		goto sanitize;
+
+	/*
+	 * See if initrd has been added to the kernel image by
+	 * arch/mips/boot/addinitrd.c. In that case a header is
+	 * prepended to initrd and is made up by 8 bytes. The fisrt
+	 * word is a magic number and the second one is the size of
+	 * initrd.  Initrd start must be page aligned in any cases.
+	 */
+	initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
+	if (initrd_header[0] != 0x494E5244)
+		goto disable;
+	initrd_start = (unsigned long)(initrd_header + 2);
+	initrd_end = initrd_start + initrd_header[1];
+
+sanitize:
+	if (initrd_start & ~PAGE_MASK) {
+		printk(KERN_ERR "initrd start must be page aligned\n");
+		goto disable;
 	}
-	return initrd_end;
+	if (initrd_start < PAGE_OFFSET) {
+		printk(KERN_ERR "initrd start < PAGE_OFFSET\n");
+		goto disable;
+	}
+
+	/*
+	 * Sanitize initrd addresses. For example firmware
+	 * can't guess if they need to pass them through
+	 * 64-bits values if the kernel has been built in pure
+	 * 32-bit. We need also to switch from KSEG0 to XKPHYS
+	 * addresses now, so the code can now safely use __pa().
+	 */
+	end = __pa(initrd_end);
+	initrd_end = (unsigned long)__va(end);
+	initrd_start = (unsigned long)__va(__pa(initrd_start));
+
+	ROOT_DEV = Root_RAM0;
+	return PFN_UP(end);
+disable:
+	initrd_start = 0;
+	initrd_end = 0;
+	return 0;
 }
 
 static void __init finalize_initrd(void)
@@ -259,8 +281,7 @@ static void __init bootmem_init(void)
 	 * not selected. Once that done we can determine the low bound
 	 * of usable memory.
 	 */
-	reserved_end = init_initrd();
-	reserved_end = PFN_UP(max(__pa(reserved_end), __pa_symbol(&_end)));
+	reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));
 
 	/*
 	 * Find the highest page frame number we have available.
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 4431ea0..072b3b0 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -502,11 +502,6 @@ void free_init_pages(char *what, unsigne
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-#ifdef CONFIG_64BIT
-	/* Switch from KSEG0 to XKPHYS addresses */
-	start = (unsigned long)phys_to_virt(CPHYSADDR(start));
-	end = (unsigned long)phys_to_virt(CPHYSADDR(end));
-#endif
 	free_init_pages("initrd memory", start, end);
 }
 #endif
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 7/7] Make free_init_pages() arguments to be physical addresses
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
                   ` (5 preceding siblings ...)
  2006-10-19 11:20 ` [PATCH 6/7] setup.c: clean up initrd related code Franck Bui-Huu
@ 2006-10-19 11:20 ` Franck Bui-Huu
  2006-10-20  3:19 ` [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Atsushi Nemoto
  7 siblings, 0 replies; 20+ messages in thread
From: Franck Bui-Huu @ 2006-10-19 11:20 UTC (permalink / raw)
  To: ralf; +Cc: anemo, ths, linux-mips, Franck Bui-Huu

It allows caller of this function to not care about CKSEG0/XKPHYS
address mixes. It's now automatically done by free_init_pages().

We can now safely remove hack needed by 64 bit kernels with
CONFIG_BUILD_ELF64=n in free_initmem().

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/mm/init.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 072b3b0..733bdec 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -485,15 +485,18 @@ #endif
 }
 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
 
-void free_init_pages(char *what, unsigned long begin, unsigned long end)
+static void free_init_pages(char *what, unsigned long begin, unsigned long end)
 {
-	unsigned long addr;
+	unsigned long pfn;
 
-	for (addr = begin; addr < end; addr += PAGE_SIZE) {
-		ClearPageReserved(virt_to_page((void *)addr));
-		init_page_count(virt_to_page((void *)addr));
-		memset((void *)addr, 0xcc, PAGE_SIZE);
-		free_page(addr);
+	for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) {
+		struct page *page = pfn_to_page(pfn);
+		void *addr = phys_to_virt(PFN_PHYS(pfn));
+
+		ClearPageReserved(page);
+		init_page_count(page);
+		memset(addr, POISON_FREE_INITMEM, PAGE_SIZE);
+		__free_page(page);
 		totalram_pages++;
 	}
 	printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
@@ -502,7 +505,9 @@ void free_init_pages(char *what, unsigne
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-	free_init_pages("initrd memory", start, end);
+	free_init_pages("initrd memory",
+			virt_to_phys((void *)start),
+			virt_to_phys((void *)end));
 }
 #endif
 
@@ -510,17 +515,13 @@ extern unsigned long prom_free_prom_memo
 
 void free_initmem(void)
 {
-	unsigned long start, end, freed;
+	unsigned long freed;
 
 	freed = prom_free_prom_memory();
 	if (freed)
 		printk(KERN_INFO "Freeing firmware memory: %ldk freed\n",freed);
 
-	start = (unsigned long)(&__init_begin);
-	end = (unsigned long)(&__init_end);
-#ifdef CONFIG_64BIT
-	start = PAGE_OFFSET | CPHYSADDR(start);
-	end = PAGE_OFFSET | CPHYSADDR(end);
-#endif
-	free_init_pages("unused kernel memory", start, end);
+	free_init_pages("unused kernel memory",
+			__pa_symbol(&__init_begin),
+			__pa_symbol(&__init_end));
 }
-- 
1.4.2.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4]
  2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
                   ` (6 preceding siblings ...)
  2006-10-19 11:20 ` [PATCH 7/7] Make free_init_pages() arguments to be physical addresses Franck Bui-Huu
@ 2006-10-20  3:19 ` Atsushi Nemoto
  7 siblings, 0 replies; 20+ messages in thread
From: Atsushi Nemoto @ 2006-10-20  3:19 UTC (permalink / raw)
  To: vagabon.xyz; +Cc: ralf, ths, linux-mips

On Thu, 19 Oct 2006 13:19:58 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> wrote:
> Changes since take #3
> --------------------
>   * Sign extension hack still needed by rd_start_early() (Atsushi)
>   * Replace panic() by printk() in init_initrd() (Atsushi)
>   * Fix CONFIG_64BITS typo (Atsushi)
>   * Add a new sanity check in init_initrd():
> 		initrd_start < PAGE_OFFSET

Works fine for me.  Thanks.

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2006-10-20  3:19 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-19 11:19 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Franck Bui-Huu
2006-10-19 11:19 ` [PATCH 1/7] page.h: remove __pa() usages Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 3/7] setup.c: get ride of CPHYSADDR() Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 4/7] Introduce __pa_symbol() Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 5/7] setup.c: use __pa_symbol() where needed Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 6/7] setup.c: clean up initrd related code Franck Bui-Huu
2006-10-19 11:20 ` [PATCH 7/7] Make free_init_pages() arguments to be physical addresses Franck Bui-Huu
2006-10-20  3:19 ` [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #4] Atsushi Nemoto
  -- strict thread matches above, loose matches on Subject: below --
2006-10-16 16:12 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #3] Franck Bui-Huu
2006-10-16 16:12 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
2006-10-13 12:38 [PATCH 0/7] Get ride of CPHYSADDR() in setup.c [take #2] Franck Bui-Huu
2006-10-13 12:39 ` [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels Franck Bui-Huu
2006-10-13 16:27   ` Atsushi Nemoto
2006-10-14  8:39     ` Franck Bui-Huu
2006-10-19  4:01   ` Atsushi Nemoto
2006-10-19  6:20     ` Franck Bui-Huu
2006-10-19  6:41     ` Yoichi Yuasa
2006-10-19  7:01       ` Atsushi Nemoto
2006-10-19  7:23         ` Yoichi Yuasa
2006-10-19  7:43         ` Franck Bui-Huu
2006-10-19  7:59           ` Atsushi Nemoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox