From: Franck Bui-Huu <vagabon.xyz@gmail.com>
To: ralf@linux-mips.org
Cc: linux-mips@linux-mips.org, Franck Bui-Huu <fbuihuu@gmail.com>
Subject: [PATCH 2/2] FLATMEM: introduce PHYS_OFFSET.
Date: Wed, 10 Jan 2007 09:44:05 +0100 [thread overview]
Message-ID: <11684186464085-git-send-email-fbuihuu@gmail.com> (raw)
In-Reply-To: <116841864595-git-send-email-fbuihuu@gmail.com>
From: Franck Bui-Huu <fbuihuu@gmail.com>
The old code was assuming that min_low_pfn was always 0. This
means that platforms having a big hole at their memory start
paid the price of wasting some memory for the allocation of
unused entries in mem_map[].
This patch prevents this waste.
It introduces PHYS_OFFSET define which is the start of the
physical memory and uses it wherever needed. Specially when
converting physical/virtual addresses into virtual/physical
ones.
Currently all platforms defines PHYS_OFFSET to 0.
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Conflicts:
arch/mips/kernel/setup.c
---
arch/mips/kernel/setup.c | 12 ++++++++----
include/asm-mips/io.h | 4 ++--
include/asm-mips/page.h | 25 +++++++++++++++++++++----
3 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index f352cd9..e1d76b8 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -315,13 +315,17 @@ static void __init bootmem_init(void)
if (min_low_pfn >= max_low_pfn)
panic("Incorrect memory mapping !!!");
- if (min_low_pfn > 0) {
+ if (min_low_pfn > ARCH_PFN_OFFSET) {
printk(KERN_INFO
"Wasting %lu bytes for tracking %lu unused pages\n",
- min_low_pfn * sizeof(struct page),
- min_low_pfn);
- min_low_pfn = 0;
+ (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
+ min_low_pfn - ARCH_PFN_OFFSET);
+ } else if (min_low_pfn < ARCH_PFN_OFFSET) {
+ printk(KERN_INFO
+ "%lu free pages won't be used\n",
+ ARCH_PFN_OFFSET - min_low_pfn);
}
+ min_low_pfn = ARCH_PFN_OFFSET;
/*
* Determine low and high memory ranges
diff --git a/include/asm-mips/io.h b/include/asm-mips/io.h
index 38d1399..e1592af 100644
--- a/include/asm-mips/io.h
+++ b/include/asm-mips/io.h
@@ -115,7 +115,7 @@ static inline void set_io_port_base(unsigned long base)
*/
static inline unsigned long virt_to_phys(volatile const void *address)
{
- return (unsigned long)address - PAGE_OFFSET;
+ return (unsigned long)address - PAGE_OFFSET + PHYS_OFFSET;
}
/*
@@ -132,7 +132,7 @@ static inline unsigned long virt_to_phys(volatile const void *address)
*/
static inline void * phys_to_virt(unsigned long address)
{
- return (void *)(address + PAGE_OFFSET);
+ return (void *)(address + PAGE_OFFSET - PHYS_OFFSET);
}
/*
diff --git a/include/asm-mips/page.h b/include/asm-mips/page.h
index 2f9e1a9..d3fbd83 100644
--- a/include/asm-mips/page.h
+++ b/include/asm-mips/page.h
@@ -34,6 +34,20 @@
#ifndef __ASSEMBLY__
+/*
+ * This gives the physical RAM offset.
+ */
+#ifndef PHYS_OFFSET
+#define PHYS_OFFSET 0UL
+#endif
+
+/*
+ * It's normally defined only for FLATMEM config but it's
+ * used in our early mem init code for all memory models.
+ * So always define it.
+ */
+#define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
+
#include <linux/pfn.h>
#include <asm/io.h>
@@ -132,20 +146,23 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
+/*
+ * __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)
#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 __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))
#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
#ifdef CONFIG_FLATMEM
-#define pfn_valid(pfn) ((pfn) < max_mapnr)
+#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)
#elif defined(CONFIG_SPARSEMEM)
--
1.4.4.3.ge6d4
next prev parent reply other threads:[~2007-01-10 16:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-10 8:44 [PATCH 0/2] FLATMEM: allow memory to start at pfn != 0 [take #2] Franck Bui-Huu
2007-01-10 8:44 ` [PATCH 1/2] Setup min_low_pfn/max_low_pfn correctly Franck Bui-Huu
2007-01-10 8:44 ` Franck Bui-Huu [this message]
2007-01-10 11:20 ` [PATCH 0/2] FLATMEM: allow memory to start at pfn != 0 [take #2] Ralf Baechle
2007-01-10 14:52 ` Franck Bui-Huu
2007-03-02 23:45 ` Maxime Bizon
2007-03-05 14:15 ` Franck Bui-Huu
2007-03-05 16:33 ` Maxime Bizon
2007-03-06 21:39 ` Franck Bui-Huu
2007-03-07 13:18 ` Thomas Bogendoerfer
2007-03-07 16:58 ` Maxime Bizon
2007-03-08 9:01 ` Franck Bui-Huu
2007-03-08 8:54 ` Franck Bui-Huu
2007-03-09 13:18 ` peter fuerst
2007-03-09 13:35 ` Franck Bui-Huu
2007-03-10 9:36 ` peter fuerst
2007-03-12 9:47 ` Franck Bui-Huu
2007-03-12 13:03 ` peter fuerst
2007-03-12 17:05 ` Franck Bui-Huu
2007-03-12 20:02 ` peter fuerst
2007-03-13 8:37 ` Franck Bui-Huu
2007-03-18 11:30 ` peter fuerst
-- strict thread matches above, loose matches on Subject: below --
2007-01-08 17:44 [PATCH 0/2] FLATMEM: allow memory to start at pfn != 0 Franck Bui-Huu
2007-01-08 17:44 ` [PATCH 2/2] FLATMEM: introduce PHYS_OFFSET Franck Bui-Huu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11684186464085-git-send-email-fbuihuu@gmail.com \
--to=vagabon.xyz@gmail.com \
--cc=fbuihuu@gmail.com \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox