Skip to content

Commit d29eff7

Browse files
awhitcroftLinus Torvalds
authored andcommitted
ppc64: SPARSEMEM_VMEMMAP support
Enable virtual memmap support for SPARSEMEM on PPC64 systems. Slice a 16th off the end of the linear mapping space and use that to hold the vmemmap. Uses the same size mapping as uses in the linear 1:1 kernel mapping. [pbadari@gmail.com: fix warning] Signed-off-by: Andy Whitcroft <apw@shadowen.org> Acked-by: Mel Gorman <mel@csn.ul.ie> Cc: Christoph Lameter <clameter@sgi.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 46644c2 commit d29eff7

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎arch/powerpc/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ config ARCH_FLATMEM_ENABLE
295295
config ARCH_SPARSEMEM_ENABLE
296296
def_bool y
297297
depends on PPC64
298+
select SPARSEMEM_VMEMMAP_ENABLE
298299

299300
config ARCH_SPARSEMEM_DEFAULT
300301
def_bool y

‎arch/powerpc/mm/init_64.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,70 @@ void pgtable_cache_init(void)
183183
zero_ctor);
184184
}
185185
}
186+
187+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
188+
/*
189+
* Given an address within the vmemmap, determine the pfn of the page that
190+
* represents the start of the section it is within. Note that we have to
191+
* do this by hand as the proffered address may not be correctly aligned.
192+
* Subtraction of non-aligned pointers produces undefined results.
193+
*/
194+
unsigned long __meminit vmemmap_section_start(unsigned long page)
195+
{
196+
unsigned long offset = page - ((unsigned long)(vmemmap));
197+
198+
/* Return the pfn of the start of the section. */
199+
return (offset / sizeof(struct page)) & PAGE_SECTION_MASK;
200+
}
201+
202+
/*
203+
* Check if this vmemmap page is already initialised. If any section
204+
* which overlaps this vmemmap page is initialised then this page is
205+
* initialised already.
206+
*/
207+
int __meminit vmemmap_populated(unsigned long start, int page_size)
208+
{
209+
unsigned long end = start + page_size;
210+
211+
for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page)))
212+
if (pfn_valid(vmemmap_section_start(start)))
213+
return 1;
214+
215+
return 0;
216+
}
217+
218+
int __meminit vmemmap_populate(struct page *start_page,
219+
unsigned long nr_pages, int node)
220+
{
221+
unsigned long mode_rw;
222+
unsigned long start = (unsigned long)start_page;
223+
unsigned long end = (unsigned long)(start_page + nr_pages);
224+
unsigned long page_size = 1 << mmu_psize_defs[mmu_linear_psize].shift;
225+
226+
mode_rw = _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_COHERENT | PP_RWXX;
227+
228+
/* Align to the page size of the linear mapping. */
229+
start = _ALIGN_DOWN(start, page_size);
230+
231+
for (; start < end; start += page_size) {
232+
int mapped;
233+
void *p;
234+
235+
if (vmemmap_populated(start, page_size))
236+
continue;
237+
238+
p = vmemmap_alloc_block(page_size, node);
239+
if (!p)
240+
return -ENOMEM;
241+
242+
printk(KERN_WARNING "vmemmap %08lx allocated at %p, "
243+
"physical %p.\n", start, p, __pa(p));
244+
245+
mapped = htab_bolt_mapping(start, start + page_size,
246+
__pa(p), mode_rw, mmu_linear_psize);
247+
BUG_ON(mapped < 0);
248+
}
249+
250+
return 0;
251+
}
252+
#endif

‎include/asm-powerpc/pgtable-ppc64.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
#define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET))
6868
#define USER_REGION_ID (0UL)
6969

70+
/*
71+
* Defines the address of the vmemap area, in the top 16th of the
72+
* kernel region.
73+
*/
74+
#define VMEMMAP_BASE (ASM_CONST(CONFIG_KERNEL_START) + \
75+
(0xfUL << (REGION_SHIFT - 4)))
76+
#define vmemmap ((struct page *)VMEMMAP_BASE)
77+
7078
/*
7179
* Common bits in a linux-style PTE. These match the bits in the
7280
* (hardware-defined) PowerPC PTE as closely as possible. Additional

0 commit comments

Comments
 (0)