void __init paging_init(void) { #ifdef CONFIG_HIGHMEM fixedrange_init(); pkmap_page_table = init_pmd(PKMAP_BASE, LAST_PKMAP); kmap_init(); #endif }
/* * paging_init() sets up the page tables - note that the first 8MB are * already mapped by head.S. * * This routines also unmaps the page at virtual kernel address 0, so * that we can trap those pesky NULL-reference errors in the kernel. */ void __init paging_init(void) { #ifdef CONFIG_X86_PAE set_nx(); if (nx_enabled) printk("NX (Execute Disable) protection: active\n"); #endif pagetable_init(); load_cr3(swapper_pg_dir); #ifdef CONFIG_X86_PAE /* * We will bail out later - printk doesn't work right now so * the user would just see a hanging kernel. */ if (cpu_has_pae) set_in_cr4(X86_CR4_PAE); #endif __flush_tlb_all(); kmap_init(); }
/* * First memory setup routine called from setup_arch() * 1. setup swapper's mm @init_mm * 2. Count the pages we have and setup bootmem allocator * 3. zone setup */ void __init setup_arch_memory(void) { unsigned long zones_size[MAX_NR_ZONES]; unsigned long zones_holes[MAX_NR_ZONES]; init_mm.start_code = (unsigned long)_text; init_mm.end_code = (unsigned long)_etext; init_mm.end_data = (unsigned long)_edata; init_mm.brk = (unsigned long)_end; /* first page of system - kernel .vector starts here */ min_low_pfn = ARCH_PFN_OFFSET; /* Last usable page of low mem */ max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz); #ifdef CONFIG_HIGHMEM min_high_pfn = PFN_DOWN(high_mem_start); max_pfn = PFN_DOWN(high_mem_start + high_mem_sz); #endif max_mapnr = max_pfn - min_low_pfn; /*------------- bootmem allocator setup -----------------------*/ /* * seed the bootmem allocator after any DT memory node parsing or * "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz * * Only low mem is added, otherwise we have crashes when allocating * mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of * avail memory, ending in highmem with a > 32-bit address. However * it then tries to memset it with a truncaed 32-bit handle, causing * the crash */ memblock_add(low_mem_start, low_mem_sz); memblock_reserve(low_mem_start, __pa(_end) - low_mem_start); #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start) memblock_reserve(__pa(initrd_start), initrd_end - initrd_start); #endif memblock_dump_all(); /*----------------- node/zones setup --------------------------*/ memset(zones_size, 0, sizeof(zones_size)); memset(zones_holes, 0, sizeof(zones_holes)); zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn; zones_holes[ZONE_NORMAL] = 0; #ifdef CONFIG_HIGHMEM zones_size[ZONE_HIGHMEM] = max_pfn - max_low_pfn; /* This handles the peripheral address space hole */ zones_holes[ZONE_HIGHMEM] = min_high_pfn - max_low_pfn; #endif /* * We can't use the helper free_area_init(zones[]) because it uses * PAGE_OFFSET to compute the @min_low_pfn which would be wrong * when our kernel doesn't start at PAGE_OFFSET, i.e. * PAGE_OFFSET != CONFIG_LINUX_LINK_BASE */ free_area_init_node(0, /* node-id */ zones_size, /* num pages per zone */ min_low_pfn, /* first pfn of node */ zones_holes); /* holes */ #ifdef CONFIG_HIGHMEM high_memory = (void *)(min_high_pfn << PAGE_SHIFT); kmap_init(); #endif }
/* * First memory setup routine called from setup_arch() * 1. setup swapper's mm @init_mm * 2. Count the pages we have and setup bootmem allocator * 3. zone setup */ void __init setup_arch_memory(void) { unsigned long zones_size[MAX_NR_ZONES]; unsigned long zones_holes[MAX_NR_ZONES]; init_mm.start_code = (unsigned long)_text; init_mm.end_code = (unsigned long)_etext; init_mm.end_data = (unsigned long)_edata; init_mm.brk = (unsigned long)_end; /* first page of system - kernel .vector starts here */ min_low_pfn = ARCH_PFN_OFFSET; /* Last usable page of low mem */ max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz); #ifdef CONFIG_FLATMEM /* pfn_valid() uses this */ max_mapnr = max_low_pfn - min_low_pfn; #endif /*------------- bootmem allocator setup -----------------------*/ /* * seed the bootmem allocator after any DT memory node parsing or * "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz * * Only low mem is added, otherwise we have crashes when allocating * mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of * avail memory, ending in highmem with a > 32-bit address. However * it then tries to memset it with a truncaed 32-bit handle, causing * the crash */ memblock_add_node(low_mem_start, low_mem_sz, 0); memblock_reserve(CONFIG_LINUX_LINK_BASE, __pa(_end) - CONFIG_LINUX_LINK_BASE); #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start) memblock_reserve(__pa(initrd_start), initrd_end - initrd_start); #endif early_init_fdt_reserve_self(); early_init_fdt_scan_reserved_mem(); memblock_dump_all(); /*----------------- node/zones setup --------------------------*/ memset(zones_size, 0, sizeof(zones_size)); memset(zones_holes, 0, sizeof(zones_holes)); zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn; zones_holes[ZONE_NORMAL] = 0; /* * We can't use the helper free_area_init(zones[]) because it uses * PAGE_OFFSET to compute the @min_low_pfn which would be wrong * when our kernel doesn't start at PAGE_OFFSET, i.e. * PAGE_OFFSET != CONFIG_LINUX_RAM_BASE */ free_area_init_node(0, /* node-id */ zones_size, /* num pages per zone */ min_low_pfn, /* first pfn of node */ zones_holes); /* holes */ #ifdef CONFIG_HIGHMEM /* * Populate a new node with highmem * * On ARC (w/o PAE) HIGHMEM addresses are actually smaller (0 based) * than addresses in normal ala low memory (0x8000_0000 based). * Even with PAE, the huge peripheral space hole would waste a lot of * mem with single mem_map[]. This warrants a mem_map per region design. * Thus HIGHMEM on ARC is imlemented with DISCONTIGMEM. * * DISCONTIGMEM in turns requires multiple nodes. node 0 above is * populated with normal memory zone while node 1 only has highmem */ node_set_online(1); min_high_pfn = PFN_DOWN(high_mem_start); max_high_pfn = PFN_DOWN(high_mem_start + high_mem_sz); zones_size[ZONE_NORMAL] = 0; zones_holes[ZONE_NORMAL] = 0; zones_size[ZONE_HIGHMEM] = max_high_pfn - min_high_pfn; zones_holes[ZONE_HIGHMEM] = 0; free_area_init_node(1, /* node-id */ zones_size, /* num pages per zone */ min_high_pfn, /* first pfn of node */ zones_holes); /* holes */ high_memory = (void *)(min_high_pfn << PAGE_SHIFT); kmap_init(); #endif }