2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* S390 version
|
2012-07-20 17:15:04 +08:00
|
|
|
* Copyright IBM Corp. 1999
|
2005-04-17 06:20:36 +08:00
|
|
|
* Author(s): Hartmut Penner (hp@de.ibm.com)
|
|
|
|
*
|
|
|
|
* Derived from "arch/i386/mm/init.c"
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/bootmem.h>
|
2006-07-01 19:36:31 +08:00
|
|
|
#include <linux/pfn.h>
|
2006-12-08 22:56:13 +08:00
|
|
|
#include <linux/poison.h>
|
2007-02-06 04:16:47 +08:00
|
|
|
#include <linux/initrd.h>
|
2011-07-30 15:25:15 +08:00
|
|
|
#include <linux/export.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/lowcore.h>
|
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/tlbflush.h>
|
2006-07-01 19:36:31 +08:00
|
|
|
#include <asm/sections.h>
|
2012-03-29 01:30:02 +08:00
|
|
|
#include <asm/ctl_reg.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
|
2009-03-26 22:24:04 +08:00
|
|
|
|
2010-10-25 22:10:07 +08:00
|
|
|
unsigned long empty_zero_page, zero_page_mask;
|
2009-03-26 22:24:04 +08:00
|
|
|
EXPORT_SYMBOL(empty_zero_page);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-24 14:17:58 +08:00
|
|
|
static unsigned long __init setup_zero_pages(void)
|
2010-10-25 22:10:07 +08:00
|
|
|
{
|
|
|
|
struct cpuid cpu_id;
|
|
|
|
unsigned int order;
|
|
|
|
unsigned long size;
|
|
|
|
struct page *page;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
get_cpu_id(&cpu_id);
|
|
|
|
switch (cpu_id.machine) {
|
|
|
|
case 0x9672: /* g5 */
|
|
|
|
case 0x2064: /* z900 */
|
|
|
|
case 0x2066: /* z900 */
|
|
|
|
case 0x2084: /* z990 */
|
|
|
|
case 0x2086: /* z990 */
|
|
|
|
case 0x2094: /* z9-109 */
|
|
|
|
case 0x2096: /* z9-109 */
|
|
|
|
order = 0;
|
|
|
|
break;
|
|
|
|
case 0x2097: /* z10 */
|
|
|
|
case 0x2098: /* z10 */
|
|
|
|
default:
|
|
|
|
order = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
|
|
|
|
if (!empty_zero_page)
|
|
|
|
panic("Out of memory in setup_zero_pages");
|
|
|
|
|
|
|
|
page = virt_to_page((void *) empty_zero_page);
|
|
|
|
split_page(page, order);
|
|
|
|
for (i = 1 << order; i > 0; i--) {
|
|
|
|
SetPageReserved(page);
|
|
|
|
page++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = PAGE_SIZE << order;
|
|
|
|
zero_page_mask = (size - 1) & PAGE_MASK;
|
|
|
|
|
|
|
|
return 1UL << order;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* paging_init() sets up the page tables
|
|
|
|
*/
|
|
|
|
void __init paging_init(void)
|
|
|
|
{
|
2006-12-08 22:56:10 +08:00
|
|
|
unsigned long max_zone_pfns[MAX_NR_ZONES];
|
2011-12-27 18:27:07 +08:00
|
|
|
unsigned long pgd_type, asce_bits;
|
2006-07-01 19:36:31 +08:00
|
|
|
|
2007-10-22 18:52:47 +08:00
|
|
|
init_mm.pgd = swapper_pg_dir;
|
2006-12-08 22:56:07 +08:00
|
|
|
#ifdef CONFIG_64BIT
|
2011-12-27 18:27:07 +08:00
|
|
|
if (VMALLOC_END > (1UL << 42)) {
|
|
|
|
asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
|
|
|
|
pgd_type = _REGION2_ENTRY_EMPTY;
|
|
|
|
} else {
|
|
|
|
asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
|
|
|
|
pgd_type = _REGION3_ENTRY_EMPTY;
|
|
|
|
}
|
2006-12-08 22:56:07 +08:00
|
|
|
#else
|
2011-12-27 18:27:07 +08:00
|
|
|
asce_bits = _ASCE_TABLE_LENGTH;
|
2007-10-22 18:52:47 +08:00
|
|
|
pgd_type = _SEGMENT_ENTRY_EMPTY;
|
2006-12-08 22:56:07 +08:00
|
|
|
#endif
|
2011-12-27 18:27:07 +08:00
|
|
|
S390_lowcore.kernel_asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
|
2007-10-22 18:52:47 +08:00
|
|
|
clear_table((unsigned long *) init_mm.pgd, pgd_type,
|
|
|
|
sizeof(unsigned long)*2048);
|
2006-12-08 22:56:07 +08:00
|
|
|
vmem_map_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* enable virtual mapping in kernel mode */
|
2007-10-22 18:52:47 +08:00
|
|
|
__ctl_load(S390_lowcore.kernel_asce, 1, 1);
|
|
|
|
__ctl_load(S390_lowcore.kernel_asce, 7, 7);
|
|
|
|
__ctl_load(S390_lowcore.kernel_asce, 13, 13);
|
2010-10-07 21:08:55 +08:00
|
|
|
arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-08-24 15:26:21 +08:00
|
|
|
atomic_set(&init_mm.context.attach_count, 1);
|
|
|
|
|
2008-04-30 19:38:47 +08:00
|
|
|
sparse_memory_present_with_active_regions(MAX_NUMNODES);
|
|
|
|
sparse_init();
|
2006-12-08 22:56:10 +08:00
|
|
|
memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
|
|
|
|
max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
|
|
|
|
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
|
|
|
|
free_area_init_nodes(max_zone_pfns);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
|
|
|
unsigned long codesize, reservedpages, datasize, initsize;
|
|
|
|
|
|
|
|
max_mapnr = num_physpages = max_low_pfn;
|
|
|
|
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
|
|
|
|
|
2008-05-07 15:22:59 +08:00
|
|
|
/* Setup guest page hinting */
|
|
|
|
cmma_init();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* this will put all low memory onto the freelists */
|
|
|
|
totalram_pages += free_all_bootmem();
|
2010-10-25 22:10:07 +08:00
|
|
|
totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
reservedpages = 0;
|
|
|
|
|
|
|
|
codesize = (unsigned long) &_etext - (unsigned long) &_text;
|
|
|
|
datasize = (unsigned long) &_edata - (unsigned long) &_etext;
|
|
|
|
initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
|
|
|
|
printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
|
2009-09-22 08:02:36 +08:00
|
|
|
nr_free_pages() << (PAGE_SHIFT-10),
|
2005-04-17 06:20:36 +08:00
|
|
|
max_mapnr << (PAGE_SHIFT-10),
|
|
|
|
codesize >> 10,
|
|
|
|
reservedpages << (PAGE_SHIFT-10),
|
|
|
|
datasize >>10,
|
|
|
|
initsize >> 10);
|
2006-07-01 19:36:31 +08:00
|
|
|
printk("Write protected kernel read-only data: %#lx - %#lx\n",
|
2007-02-06 04:18:41 +08:00
|
|
|
(unsigned long)&_stext,
|
|
|
|
PFN_ALIGN((unsigned long)&_eshared) - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-02-27 05:37:42 +08:00
|
|
|
void free_init_pages(char *what, unsigned long begin, unsigned long end)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-27 05:37:42 +08:00
|
|
|
unsigned long addr = begin;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-27 05:37:42 +08:00
|
|
|
if (begin >= end)
|
|
|
|
return;
|
|
|
|
for (; addr < end; addr += PAGE_SIZE) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ClearPageReserved(virt_to_page(addr));
|
2006-03-22 16:08:40 +08:00
|
|
|
init_page_count(virt_to_page(addr));
|
2010-02-27 05:37:42 +08:00
|
|
|
memset((void *)(addr & PAGE_MASK), POISON_FREE_INITMEM,
|
|
|
|
PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
free_page(addr);
|
|
|
|
totalram_pages++;
|
2010-02-27 05:37:42 +08:00
|
|
|
}
|
|
|
|
printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_initmem(void)
|
|
|
|
{
|
|
|
|
free_init_pages("unused kernel memory",
|
|
|
|
(unsigned long)&__init_begin,
|
|
|
|
(unsigned long)&__init_end);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
2012-09-24 14:17:58 +08:00
|
|
|
void __init free_initrd_mem(unsigned long start, unsigned long end)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-27 05:37:42 +08:00
|
|
|
free_init_pages("initrd memory", start, end);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
2008-07-14 15:59:18 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_MEMORY_HOTPLUG
|
|
|
|
int arch_add_memory(int nid, u64 start, u64 size)
|
|
|
|
{
|
2012-02-25 01:01:29 +08:00
|
|
|
unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
|
|
|
|
unsigned long start_pfn = PFN_DOWN(start);
|
|
|
|
unsigned long size_pages = PFN_DOWN(size);
|
2008-07-14 15:59:18 +08:00
|
|
|
struct zone *zone;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = vmem_add_mapping(start, size);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2012-02-25 01:01:29 +08:00
|
|
|
for_each_zone(zone) {
|
|
|
|
if (zone_idx(zone) != ZONE_MOVABLE) {
|
|
|
|
/* Add range within existing zone limits */
|
|
|
|
zone_start_pfn = zone->zone_start_pfn;
|
|
|
|
zone_end_pfn = zone->zone_start_pfn +
|
|
|
|
zone->spanned_pages;
|
|
|
|
} else {
|
|
|
|
/* Add remaining range to ZONE_MOVABLE */
|
|
|
|
zone_start_pfn = start_pfn;
|
|
|
|
zone_end_pfn = start_pfn + size_pages;
|
|
|
|
}
|
|
|
|
if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
|
|
|
|
continue;
|
|
|
|
nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
|
|
|
|
zone_end_pfn - start_pfn : size_pages;
|
|
|
|
rc = __add_pages(nid, zone, start_pfn, nr_pages);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
start_pfn += nr_pages;
|
|
|
|
size_pages -= nr_pages;
|
|
|
|
if (!size_pages)
|
|
|
|
break;
|
|
|
|
}
|
2008-07-14 15:59:18 +08:00
|
|
|
if (rc)
|
|
|
|
vmem_remove_mapping(start, size);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MEMORY_HOTPLUG */
|