11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/arch/parisc/mm/init.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1995 Linus Torvalds 51da177e4SLinus Torvalds * Copyright 1999 SuSE GmbH 61da177e4SLinus Torvalds * changed by Philipp Rumpf 71da177e4SLinus Torvalds * Copyright 1999 Philipp Rumpf (prumpf@tux.org) 81da177e4SLinus Torvalds * Copyright 2004 Randolph Chung (tausq@debian.org) 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/config.h> 131da177e4SLinus Torvalds 141da177e4SLinus Torvalds #include <linux/module.h> 151da177e4SLinus Torvalds #include <linux/mm.h> 161da177e4SLinus Torvalds #include <linux/bootmem.h> 171da177e4SLinus Torvalds #include <linux/delay.h> 181da177e4SLinus Torvalds #include <linux/init.h> 191da177e4SLinus Torvalds #include <linux/pci.h> /* for hppa_dma_ops and pcxl_dma_ops */ 201da177e4SLinus Torvalds #include <linux/initrd.h> 211da177e4SLinus Torvalds #include <linux/swap.h> 221da177e4SLinus Torvalds #include <linux/unistd.h> 231da177e4SLinus Torvalds #include <linux/nodemask.h> /* for node_online_map */ 241da177e4SLinus Torvalds #include <linux/pagemap.h> /* for release_pages and page_cache_release */ 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include <asm/pgalloc.h> 271da177e4SLinus Torvalds #include <asm/tlb.h> 281da177e4SLinus Torvalds #include <asm/pdc_chassis.h> 291da177e4SLinus Torvalds #include <asm/mmzone.h> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds extern char _text; /* start of kernel code, defined by linker */ 341da177e4SLinus Torvalds extern int data_start; 351da177e4SLinus Torvalds extern char _end; /* end of BSS, defined by linker */ 361da177e4SLinus Torvalds extern char __init_begin, __init_end; 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #ifdef CONFIG_DISCONTIGMEM 39*8039de10SHelge Deller struct node_map_data node_data[MAX_NUMNODES] __read_mostly; 40*8039de10SHelge Deller bootmem_data_t bmem_data[MAX_NUMNODES] __read_mostly; 41*8039de10SHelge Deller unsigned char pfnnid_map[PFNNID_MAP_MAX] __read_mostly; 421da177e4SLinus Torvalds #endif 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds static struct resource data_resource = { 451da177e4SLinus Torvalds .name = "Kernel data", 461da177e4SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_MEM, 471da177e4SLinus Torvalds }; 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds static struct resource code_resource = { 501da177e4SLinus Torvalds .name = "Kernel code", 511da177e4SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_MEM, 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static struct resource pdcdata_resource = { 551da177e4SLinus Torvalds .name = "PDC data (Page Zero)", 561da177e4SLinus Torvalds .start = 0, 571da177e4SLinus Torvalds .end = 0x9ff, 581da177e4SLinus Torvalds .flags = IORESOURCE_BUSY | IORESOURCE_MEM, 591da177e4SLinus Torvalds }; 601da177e4SLinus Torvalds 61*8039de10SHelge Deller static struct resource sysram_resources[MAX_PHYSMEM_RANGES] __read_mostly; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds /* The following array is initialized from the firmware specific 641da177e4SLinus Torvalds * information retrieved in kernel/inventory.c. 651da177e4SLinus Torvalds */ 661da177e4SLinus Torvalds 67*8039de10SHelge Deller physmem_range_t pmem_ranges[MAX_PHYSMEM_RANGES] __read_mostly; 68*8039de10SHelge Deller int npmem_ranges __read_mostly; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #ifdef __LP64__ 711da177e4SLinus Torvalds #define MAX_MEM (~0UL) 721da177e4SLinus Torvalds #else /* !__LP64__ */ 731da177e4SLinus Torvalds #define MAX_MEM (3584U*1024U*1024U) 741da177e4SLinus Torvalds #endif /* !__LP64__ */ 751da177e4SLinus Torvalds 76*8039de10SHelge Deller static unsigned long mem_limit __read_mostly = MAX_MEM; 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds static void __init mem_limit_func(void) 791da177e4SLinus Torvalds { 801da177e4SLinus Torvalds char *cp, *end; 811da177e4SLinus Torvalds unsigned long limit; 821da177e4SLinus Torvalds extern char saved_command_line[]; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds /* We need this before __setup() functions are called */ 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds limit = MAX_MEM; 871da177e4SLinus Torvalds for (cp = saved_command_line; *cp; ) { 881da177e4SLinus Torvalds if (memcmp(cp, "mem=", 4) == 0) { 891da177e4SLinus Torvalds cp += 4; 901da177e4SLinus Torvalds limit = memparse(cp, &end); 911da177e4SLinus Torvalds if (end != cp) 921da177e4SLinus Torvalds break; 931da177e4SLinus Torvalds cp = end; 941da177e4SLinus Torvalds } else { 951da177e4SLinus Torvalds while (*cp != ' ' && *cp) 961da177e4SLinus Torvalds ++cp; 971da177e4SLinus Torvalds while (*cp == ' ') 981da177e4SLinus Torvalds ++cp; 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds if (limit < mem_limit) 1031da177e4SLinus Torvalds mem_limit = limit; 1041da177e4SLinus Torvalds } 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds #define MAX_GAP (0x40000000UL >> PAGE_SHIFT) 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds static void __init setup_bootmem(void) 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds unsigned long bootmap_size; 1111da177e4SLinus Torvalds unsigned long mem_max; 1121da177e4SLinus Torvalds unsigned long bootmap_pages; 1131da177e4SLinus Torvalds unsigned long bootmap_start_pfn; 1141da177e4SLinus Torvalds unsigned long bootmap_pfn; 1151da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 1161da177e4SLinus Torvalds physmem_range_t pmem_holes[MAX_PHYSMEM_RANGES - 1]; 1171da177e4SLinus Torvalds int npmem_holes; 1181da177e4SLinus Torvalds #endif 1191da177e4SLinus Torvalds int i, sysram_resource_count; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds disable_sr_hashing(); /* Turn off space register hashing */ 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds /* 1241da177e4SLinus Torvalds * Sort the ranges. Since the number of ranges is typically 1251da177e4SLinus Torvalds * small, and performance is not an issue here, just do 1261da177e4SLinus Torvalds * a simple insertion sort. 1271da177e4SLinus Torvalds */ 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds for (i = 1; i < npmem_ranges; i++) { 1301da177e4SLinus Torvalds int j; 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds for (j = i; j > 0; j--) { 1331da177e4SLinus Torvalds unsigned long tmp; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds if (pmem_ranges[j-1].start_pfn < 1361da177e4SLinus Torvalds pmem_ranges[j].start_pfn) { 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds break; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds tmp = pmem_ranges[j-1].start_pfn; 1411da177e4SLinus Torvalds pmem_ranges[j-1].start_pfn = pmem_ranges[j].start_pfn; 1421da177e4SLinus Torvalds pmem_ranges[j].start_pfn = tmp; 1431da177e4SLinus Torvalds tmp = pmem_ranges[j-1].pages; 1441da177e4SLinus Torvalds pmem_ranges[j-1].pages = pmem_ranges[j].pages; 1451da177e4SLinus Torvalds pmem_ranges[j].pages = tmp; 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds } 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 1501da177e4SLinus Torvalds /* 1511da177e4SLinus Torvalds * Throw out ranges that are too far apart (controlled by 1521da177e4SLinus Torvalds * MAX_GAP). 1531da177e4SLinus Torvalds */ 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds for (i = 1; i < npmem_ranges; i++) { 1561da177e4SLinus Torvalds if (pmem_ranges[i].start_pfn - 1571da177e4SLinus Torvalds (pmem_ranges[i-1].start_pfn + 1581da177e4SLinus Torvalds pmem_ranges[i-1].pages) > MAX_GAP) { 1591da177e4SLinus Torvalds npmem_ranges = i; 1601da177e4SLinus Torvalds printk("Large gap in memory detected (%ld pages). " 1611da177e4SLinus Torvalds "Consider turning on CONFIG_DISCONTIGMEM\n", 1621da177e4SLinus Torvalds pmem_ranges[i].start_pfn - 1631da177e4SLinus Torvalds (pmem_ranges[i-1].start_pfn + 1641da177e4SLinus Torvalds pmem_ranges[i-1].pages)); 1651da177e4SLinus Torvalds break; 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds #endif 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds if (npmem_ranges > 1) { 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds /* Print the memory ranges */ 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds printk(KERN_INFO "Memory Ranges:\n"); 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 1771da177e4SLinus Torvalds unsigned long start; 1781da177e4SLinus Torvalds unsigned long size; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds size = (pmem_ranges[i].pages << PAGE_SHIFT); 1811da177e4SLinus Torvalds start = (pmem_ranges[i].start_pfn << PAGE_SHIFT); 1821da177e4SLinus Torvalds printk(KERN_INFO "%2d) Start 0x%016lx End 0x%016lx Size %6ld MB\n", 1831da177e4SLinus Torvalds i,start, start + (size - 1), size >> 20); 1841da177e4SLinus Torvalds } 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds sysram_resource_count = npmem_ranges; 1881da177e4SLinus Torvalds for (i = 0; i < sysram_resource_count; i++) { 1891da177e4SLinus Torvalds struct resource *res = &sysram_resources[i]; 1901da177e4SLinus Torvalds res->name = "System RAM"; 1911da177e4SLinus Torvalds res->start = pmem_ranges[i].start_pfn << PAGE_SHIFT; 1921da177e4SLinus Torvalds res->end = res->start + (pmem_ranges[i].pages << PAGE_SHIFT)-1; 1931da177e4SLinus Torvalds res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; 1941da177e4SLinus Torvalds request_resource(&iomem_resource, res); 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds /* 1981da177e4SLinus Torvalds * For 32 bit kernels we limit the amount of memory we can 1991da177e4SLinus Torvalds * support, in order to preserve enough kernel address space 2001da177e4SLinus Torvalds * for other purposes. For 64 bit kernels we don't normally 2011da177e4SLinus Torvalds * limit the memory, but this mechanism can be used to 2021da177e4SLinus Torvalds * artificially limit the amount of memory (and it is written 2031da177e4SLinus Torvalds * to work with multiple memory ranges). 2041da177e4SLinus Torvalds */ 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds mem_limit_func(); /* check for "mem=" argument */ 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds mem_max = 0; 2091da177e4SLinus Torvalds num_physpages = 0; 2101da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 2111da177e4SLinus Torvalds unsigned long rsize; 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds rsize = pmem_ranges[i].pages << PAGE_SHIFT; 2141da177e4SLinus Torvalds if ((mem_max + rsize) > mem_limit) { 2151da177e4SLinus Torvalds printk(KERN_WARNING "Memory truncated to %ld MB\n", mem_limit >> 20); 2161da177e4SLinus Torvalds if (mem_max == mem_limit) 2171da177e4SLinus Torvalds npmem_ranges = i; 2181da177e4SLinus Torvalds else { 2191da177e4SLinus Torvalds pmem_ranges[i].pages = (mem_limit >> PAGE_SHIFT) 2201da177e4SLinus Torvalds - (mem_max >> PAGE_SHIFT); 2211da177e4SLinus Torvalds npmem_ranges = i + 1; 2221da177e4SLinus Torvalds mem_max = mem_limit; 2231da177e4SLinus Torvalds } 2241da177e4SLinus Torvalds num_physpages += pmem_ranges[i].pages; 2251da177e4SLinus Torvalds break; 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds num_physpages += pmem_ranges[i].pages; 2281da177e4SLinus Torvalds mem_max += rsize; 2291da177e4SLinus Torvalds } 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds printk(KERN_INFO "Total Memory: %ld MB\n",mem_max >> 20); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 2341da177e4SLinus Torvalds /* Merge the ranges, keeping track of the holes */ 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds { 2371da177e4SLinus Torvalds unsigned long end_pfn; 2381da177e4SLinus Torvalds unsigned long hole_pages; 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds npmem_holes = 0; 2411da177e4SLinus Torvalds end_pfn = pmem_ranges[0].start_pfn + pmem_ranges[0].pages; 2421da177e4SLinus Torvalds for (i = 1; i < npmem_ranges; i++) { 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds hole_pages = pmem_ranges[i].start_pfn - end_pfn; 2451da177e4SLinus Torvalds if (hole_pages) { 2461da177e4SLinus Torvalds pmem_holes[npmem_holes].start_pfn = end_pfn; 2471da177e4SLinus Torvalds pmem_holes[npmem_holes++].pages = hole_pages; 2481da177e4SLinus Torvalds end_pfn += hole_pages; 2491da177e4SLinus Torvalds } 2501da177e4SLinus Torvalds end_pfn += pmem_ranges[i].pages; 2511da177e4SLinus Torvalds } 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds pmem_ranges[0].pages = end_pfn - pmem_ranges[0].start_pfn; 2541da177e4SLinus Torvalds npmem_ranges = 1; 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds #endif 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds bootmap_pages = 0; 2591da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) 2601da177e4SLinus Torvalds bootmap_pages += bootmem_bootmap_pages(pmem_ranges[i].pages); 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds bootmap_start_pfn = PAGE_ALIGN(__pa((unsigned long) &_end)) >> PAGE_SHIFT; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds #ifdef CONFIG_DISCONTIGMEM 2651da177e4SLinus Torvalds for (i = 0; i < MAX_PHYSMEM_RANGES; i++) { 2661da177e4SLinus Torvalds memset(NODE_DATA(i), 0, sizeof(pg_data_t)); 2671da177e4SLinus Torvalds NODE_DATA(i)->bdata = &bmem_data[i]; 2681da177e4SLinus Torvalds } 2691da177e4SLinus Torvalds memset(pfnnid_map, 0xff, sizeof(pfnnid_map)); 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) 2721da177e4SLinus Torvalds node_set_online(i); 2731da177e4SLinus Torvalds #endif 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds /* 2761da177e4SLinus Torvalds * Initialize and free the full range of memory in each range. 2771da177e4SLinus Torvalds * Note that the only writing these routines do are to the bootmap, 2781da177e4SLinus Torvalds * and we've made sure to locate the bootmap properly so that they 2791da177e4SLinus Torvalds * won't be writing over anything important. 2801da177e4SLinus Torvalds */ 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds bootmap_pfn = bootmap_start_pfn; 2831da177e4SLinus Torvalds max_pfn = 0; 2841da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 2851da177e4SLinus Torvalds unsigned long start_pfn; 2861da177e4SLinus Torvalds unsigned long npages; 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds start_pfn = pmem_ranges[i].start_pfn; 2891da177e4SLinus Torvalds npages = pmem_ranges[i].pages; 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds bootmap_size = init_bootmem_node(NODE_DATA(i), 2921da177e4SLinus Torvalds bootmap_pfn, 2931da177e4SLinus Torvalds start_pfn, 2941da177e4SLinus Torvalds (start_pfn + npages) ); 2951da177e4SLinus Torvalds free_bootmem_node(NODE_DATA(i), 2961da177e4SLinus Torvalds (start_pfn << PAGE_SHIFT), 2971da177e4SLinus Torvalds (npages << PAGE_SHIFT) ); 2981da177e4SLinus Torvalds bootmap_pfn += (bootmap_size + PAGE_SIZE - 1) >> PAGE_SHIFT; 2991da177e4SLinus Torvalds if ((start_pfn + npages) > max_pfn) 3001da177e4SLinus Torvalds max_pfn = start_pfn + npages; 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds if ((bootmap_pfn - bootmap_start_pfn) != bootmap_pages) { 3041da177e4SLinus Torvalds printk(KERN_WARNING "WARNING! bootmap sizing is messed up!\n"); 3051da177e4SLinus Torvalds BUG(); 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds /* reserve PAGE0 pdc memory, kernel text/data/bss & bootmap */ 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds #define PDC_CONSOLE_IO_IODC_SIZE 32768 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds reserve_bootmem_node(NODE_DATA(0), 0UL, 3131da177e4SLinus Torvalds (unsigned long)(PAGE0->mem_free + PDC_CONSOLE_IO_IODC_SIZE)); 3141da177e4SLinus Torvalds reserve_bootmem_node(NODE_DATA(0),__pa((unsigned long)&_text), 3151da177e4SLinus Torvalds (unsigned long)(&_end - &_text)); 3161da177e4SLinus Torvalds reserve_bootmem_node(NODE_DATA(0), (bootmap_start_pfn << PAGE_SHIFT), 3171da177e4SLinus Torvalds ((bootmap_pfn - bootmap_start_pfn) << PAGE_SHIFT)); 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds /* reserve the holes */ 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds for (i = 0; i < npmem_holes; i++) { 3241da177e4SLinus Torvalds reserve_bootmem_node(NODE_DATA(0), 3251da177e4SLinus Torvalds (pmem_holes[i].start_pfn << PAGE_SHIFT), 3261da177e4SLinus Torvalds (pmem_holes[i].pages << PAGE_SHIFT)); 3271da177e4SLinus Torvalds } 3281da177e4SLinus Torvalds #endif 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 3311da177e4SLinus Torvalds if (initrd_start) { 3321da177e4SLinus Torvalds printk(KERN_INFO "initrd: %08lx-%08lx\n", initrd_start, initrd_end); 3331da177e4SLinus Torvalds if (__pa(initrd_start) < mem_max) { 3341da177e4SLinus Torvalds unsigned long initrd_reserve; 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds if (__pa(initrd_end) > mem_max) { 3371da177e4SLinus Torvalds initrd_reserve = mem_max - __pa(initrd_start); 3381da177e4SLinus Torvalds } else { 3391da177e4SLinus Torvalds initrd_reserve = initrd_end - initrd_start; 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds initrd_below_start_ok = 1; 3421da177e4SLinus Torvalds printk(KERN_INFO "initrd: reserving %08lx-%08lx (mem_max %08lx)\n", __pa(initrd_start), __pa(initrd_start) + initrd_reserve, mem_max); 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds reserve_bootmem_node(NODE_DATA(0),__pa(initrd_start), initrd_reserve); 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds } 3471da177e4SLinus Torvalds #endif 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds data_resource.start = virt_to_phys(&data_start); 3501da177e4SLinus Torvalds data_resource.end = virt_to_phys(&_end)-1; 3511da177e4SLinus Torvalds code_resource.start = virt_to_phys(&_text); 3521da177e4SLinus Torvalds code_resource.end = virt_to_phys(&data_start)-1; 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds /* We don't know which region the kernel will be in, so try 3551da177e4SLinus Torvalds * all of them. 3561da177e4SLinus Torvalds */ 3571da177e4SLinus Torvalds for (i = 0; i < sysram_resource_count; i++) { 3581da177e4SLinus Torvalds struct resource *res = &sysram_resources[i]; 3591da177e4SLinus Torvalds request_resource(res, &code_resource); 3601da177e4SLinus Torvalds request_resource(res, &data_resource); 3611da177e4SLinus Torvalds } 3621da177e4SLinus Torvalds request_resource(&sysram_resources[0], &pdcdata_resource); 3631da177e4SLinus Torvalds } 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds void free_initmem(void) 3661da177e4SLinus Torvalds { 3671da177e4SLinus Torvalds /* FIXME: */ 3681da177e4SLinus Torvalds #if 0 3691da177e4SLinus Torvalds printk(KERN_INFO "NOT FREEING INITMEM (%dk)\n", 3701da177e4SLinus Torvalds (&__init_end - &__init_begin) >> 10); 3711da177e4SLinus Torvalds return; 3721da177e4SLinus Torvalds #else 3731da177e4SLinus Torvalds unsigned long addr; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds printk(KERN_INFO "Freeing unused kernel memory: "); 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds #if 1 3781da177e4SLinus Torvalds /* Attempt to catch anyone trying to execute code here 3791da177e4SLinus Torvalds * by filling the page with BRK insns. 3801da177e4SLinus Torvalds * 3811da177e4SLinus Torvalds * If we disable interrupts for all CPUs, then IPI stops working. 3821da177e4SLinus Torvalds * Kinda breaks the global cache flushing. 3831da177e4SLinus Torvalds */ 3841da177e4SLinus Torvalds local_irq_disable(); 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds memset(&__init_begin, 0x00, 3871da177e4SLinus Torvalds (unsigned long)&__init_end - (unsigned long)&__init_begin); 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds flush_data_cache(); 3901da177e4SLinus Torvalds asm volatile("sync" : : ); 3911da177e4SLinus Torvalds flush_icache_range((unsigned long)&__init_begin, (unsigned long)&__init_end); 3921da177e4SLinus Torvalds asm volatile("sync" : : ); 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds local_irq_enable(); 3951da177e4SLinus Torvalds #endif 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds addr = (unsigned long)(&__init_begin); 3981da177e4SLinus Torvalds for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { 3991da177e4SLinus Torvalds ClearPageReserved(virt_to_page(addr)); 4001da177e4SLinus Torvalds set_page_count(virt_to_page(addr), 1); 4011da177e4SLinus Torvalds free_page(addr); 4021da177e4SLinus Torvalds num_physpages++; 4031da177e4SLinus Torvalds totalram_pages++; 4041da177e4SLinus Torvalds } 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds /* set up a new led state on systems shipped LED State panel */ 4071da177e4SLinus Torvalds pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE); 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds printk("%luk freed\n", (unsigned long)(&__init_end - &__init_begin) >> 10); 4101da177e4SLinus Torvalds #endif 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds /* 4141da177e4SLinus Torvalds * Just an arbitrary offset to serve as a "hole" between mapping areas 4151da177e4SLinus Torvalds * (between top of physical memory and a potential pcxl dma mapping 4161da177e4SLinus Torvalds * area, and below the vmalloc mapping area). 4171da177e4SLinus Torvalds * 4181da177e4SLinus Torvalds * The current 32K value just means that there will be a 32K "hole" 4191da177e4SLinus Torvalds * between mapping areas. That means that any out-of-bounds memory 4201da177e4SLinus Torvalds * accesses will hopefully be caught. The vmalloc() routines leaves 4211da177e4SLinus Torvalds * a hole of 4kB between each vmalloced area for the same reason. 4221da177e4SLinus Torvalds */ 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds /* Leave room for gateway page expansion */ 4251da177e4SLinus Torvalds #if KERNEL_MAP_START < GATEWAY_PAGE_SIZE 4261da177e4SLinus Torvalds #error KERNEL_MAP_START is in gateway reserved region 4271da177e4SLinus Torvalds #endif 4281da177e4SLinus Torvalds #define MAP_START (KERNEL_MAP_START) 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds #define VM_MAP_OFFSET (32*1024) 4311da177e4SLinus Torvalds #define SET_MAP_OFFSET(x) ((void *)(((unsigned long)(x) + VM_MAP_OFFSET) \ 4321da177e4SLinus Torvalds & ~(VM_MAP_OFFSET-1))) 4331da177e4SLinus Torvalds 434*8039de10SHelge Deller void *vmalloc_start __read_mostly; 4351da177e4SLinus Torvalds EXPORT_SYMBOL(vmalloc_start); 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds #ifdef CONFIG_PA11 438*8039de10SHelge Deller unsigned long pcxl_dma_start __read_mostly; 4391da177e4SLinus Torvalds #endif 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds void __init mem_init(void) 4421da177e4SLinus Torvalds { 4431da177e4SLinus Torvalds high_memory = __va((max_pfn << PAGE_SHIFT)); 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 4461da177e4SLinus Torvalds max_mapnr = page_to_pfn(virt_to_page(high_memory - 1)) + 1; 4471da177e4SLinus Torvalds totalram_pages += free_all_bootmem(); 4481da177e4SLinus Torvalds #else 4491da177e4SLinus Torvalds { 4501da177e4SLinus Torvalds int i; 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) 4531da177e4SLinus Torvalds totalram_pages += free_all_bootmem_node(NODE_DATA(i)); 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds #endif 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds printk(KERN_INFO "Memory: %luk available\n", num_physpages << (PAGE_SHIFT-10)); 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds #ifdef CONFIG_PA11 4601da177e4SLinus Torvalds if (hppa_dma_ops == &pcxl_dma_ops) { 4611da177e4SLinus Torvalds pcxl_dma_start = (unsigned long)SET_MAP_OFFSET(MAP_START); 4621da177e4SLinus Torvalds vmalloc_start = SET_MAP_OFFSET(pcxl_dma_start + PCXL_DMA_MAP_SIZE); 4631da177e4SLinus Torvalds } else { 4641da177e4SLinus Torvalds pcxl_dma_start = 0; 4651da177e4SLinus Torvalds vmalloc_start = SET_MAP_OFFSET(MAP_START); 4661da177e4SLinus Torvalds } 4671da177e4SLinus Torvalds #else 4681da177e4SLinus Torvalds vmalloc_start = SET_MAP_OFFSET(MAP_START); 4691da177e4SLinus Torvalds #endif 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds int do_check_pgt_cache(int low, int high) 4741da177e4SLinus Torvalds { 4751da177e4SLinus Torvalds return 0; 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds 478*8039de10SHelge Deller unsigned long *empty_zero_page __read_mostly; 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds void show_mem(void) 4811da177e4SLinus Torvalds { 4821da177e4SLinus Torvalds int i,free = 0,total = 0,reserved = 0; 4831da177e4SLinus Torvalds int shared = 0, cached = 0; 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvalds printk(KERN_INFO "Mem-info:\n"); 4861da177e4SLinus Torvalds show_free_areas(); 4871da177e4SLinus Torvalds printk(KERN_INFO "Free swap: %6ldkB\n", 4881da177e4SLinus Torvalds nr_swap_pages<<(PAGE_SHIFT-10)); 4891da177e4SLinus Torvalds #ifndef CONFIG_DISCONTIGMEM 4901da177e4SLinus Torvalds i = max_mapnr; 4911da177e4SLinus Torvalds while (i-- > 0) { 4921da177e4SLinus Torvalds total++; 4931da177e4SLinus Torvalds if (PageReserved(mem_map+i)) 4941da177e4SLinus Torvalds reserved++; 4951da177e4SLinus Torvalds else if (PageSwapCache(mem_map+i)) 4961da177e4SLinus Torvalds cached++; 4971da177e4SLinus Torvalds else if (!page_count(&mem_map[i])) 4981da177e4SLinus Torvalds free++; 4991da177e4SLinus Torvalds else 5001da177e4SLinus Torvalds shared += page_count(&mem_map[i]) - 1; 5011da177e4SLinus Torvalds } 5021da177e4SLinus Torvalds #else 5031da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 5041da177e4SLinus Torvalds int j; 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds for (j = node_start_pfn(i); j < node_end_pfn(i); j++) { 5071da177e4SLinus Torvalds struct page *p; 508208d54e5SDave Hansen unsigned long flags; 5091da177e4SLinus Torvalds 510208d54e5SDave Hansen pgdat_resize_lock(NODE_DATA(i), &flags); 511408fde81SDave Hansen p = nid_page_nr(i, j) - node_start_pfn(i); 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds total++; 5141da177e4SLinus Torvalds if (PageReserved(p)) 5151da177e4SLinus Torvalds reserved++; 5161da177e4SLinus Torvalds else if (PageSwapCache(p)) 5171da177e4SLinus Torvalds cached++; 5181da177e4SLinus Torvalds else if (!page_count(p)) 5191da177e4SLinus Torvalds free++; 5201da177e4SLinus Torvalds else 5211da177e4SLinus Torvalds shared += page_count(p) - 1; 522208d54e5SDave Hansen pgdat_resize_unlock(NODE_DATA(i), &flags); 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds #endif 5261da177e4SLinus Torvalds printk(KERN_INFO "%d pages of RAM\n", total); 5271da177e4SLinus Torvalds printk(KERN_INFO "%d reserved pages\n", reserved); 5281da177e4SLinus Torvalds printk(KERN_INFO "%d pages shared\n", shared); 5291da177e4SLinus Torvalds printk(KERN_INFO "%d pages swap cached\n", cached); 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds #ifdef CONFIG_DISCONTIGMEM 5331da177e4SLinus Torvalds { 5341da177e4SLinus Torvalds struct zonelist *zl; 5351da177e4SLinus Torvalds int i, j, k; 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 5381da177e4SLinus Torvalds for (j = 0; j < MAX_NR_ZONES; j++) { 5391da177e4SLinus Torvalds zl = NODE_DATA(i)->node_zonelists + j; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds printk("Zone list for zone %d on node %d: ", j, i); 5421da177e4SLinus Torvalds for (k = 0; zl->zones[k] != NULL; k++) 5431da177e4SLinus Torvalds printk("[%d/%s] ", zl->zones[k]->zone_pgdat->node_id, zl->zones[k]->name); 5441da177e4SLinus Torvalds printk("\n"); 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds } 5481da177e4SLinus Torvalds #endif 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds static void __init map_pages(unsigned long start_vaddr, unsigned long start_paddr, unsigned long size, pgprot_t pgprot) 5531da177e4SLinus Torvalds { 5541da177e4SLinus Torvalds pgd_t *pg_dir; 5551da177e4SLinus Torvalds pmd_t *pmd; 5561da177e4SLinus Torvalds pte_t *pg_table; 5571da177e4SLinus Torvalds unsigned long end_paddr; 5581da177e4SLinus Torvalds unsigned long start_pmd; 5591da177e4SLinus Torvalds unsigned long start_pte; 5601da177e4SLinus Torvalds unsigned long tmp1; 5611da177e4SLinus Torvalds unsigned long tmp2; 5621da177e4SLinus Torvalds unsigned long address; 5631da177e4SLinus Torvalds unsigned long ro_start; 5641da177e4SLinus Torvalds unsigned long ro_end; 5651da177e4SLinus Torvalds unsigned long fv_addr; 5661da177e4SLinus Torvalds unsigned long gw_addr; 5671da177e4SLinus Torvalds extern const unsigned long fault_vector_20; 5681da177e4SLinus Torvalds extern void * const linux_gateway_page; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds ro_start = __pa((unsigned long)&_text); 5711da177e4SLinus Torvalds ro_end = __pa((unsigned long)&data_start); 5721da177e4SLinus Torvalds fv_addr = __pa((unsigned long)&fault_vector_20) & PAGE_MASK; 5731da177e4SLinus Torvalds gw_addr = __pa((unsigned long)&linux_gateway_page) & PAGE_MASK; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds end_paddr = start_paddr + size; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds pg_dir = pgd_offset_k(start_vaddr); 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds #if PTRS_PER_PMD == 1 5801da177e4SLinus Torvalds start_pmd = 0; 5811da177e4SLinus Torvalds #else 5821da177e4SLinus Torvalds start_pmd = ((start_vaddr >> PMD_SHIFT) & (PTRS_PER_PMD - 1)); 5831da177e4SLinus Torvalds #endif 5841da177e4SLinus Torvalds start_pte = ((start_vaddr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)); 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds address = start_paddr; 5871da177e4SLinus Torvalds while (address < end_paddr) { 5881da177e4SLinus Torvalds #if PTRS_PER_PMD == 1 5891da177e4SLinus Torvalds pmd = (pmd_t *)__pa(pg_dir); 5901da177e4SLinus Torvalds #else 5911da177e4SLinus Torvalds pmd = (pmd_t *)pgd_address(*pg_dir); 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds /* 5941da177e4SLinus Torvalds * pmd is physical at this point 5951da177e4SLinus Torvalds */ 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds if (!pmd) { 5981da177e4SLinus Torvalds pmd = (pmd_t *) alloc_bootmem_low_pages_node(NODE_DATA(0),PAGE_SIZE << PMD_ORDER); 5991da177e4SLinus Torvalds pmd = (pmd_t *) __pa(pmd); 6001da177e4SLinus Torvalds } 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds pgd_populate(NULL, pg_dir, __va(pmd)); 6031da177e4SLinus Torvalds #endif 6041da177e4SLinus Torvalds pg_dir++; 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds /* now change pmd to kernel virtual addresses */ 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds pmd = (pmd_t *)__va(pmd) + start_pmd; 6091da177e4SLinus Torvalds for (tmp1 = start_pmd; tmp1 < PTRS_PER_PMD; tmp1++,pmd++) { 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds /* 6121da177e4SLinus Torvalds * pg_table is physical at this point 6131da177e4SLinus Torvalds */ 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds pg_table = (pte_t *)pmd_address(*pmd); 6161da177e4SLinus Torvalds if (!pg_table) { 6171da177e4SLinus Torvalds pg_table = (pte_t *) 6181da177e4SLinus Torvalds alloc_bootmem_low_pages_node(NODE_DATA(0),PAGE_SIZE); 6191da177e4SLinus Torvalds pg_table = (pte_t *) __pa(pg_table); 6201da177e4SLinus Torvalds } 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds pmd_populate_kernel(NULL, pmd, __va(pg_table)); 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds /* now change pg_table to kernel virtual addresses */ 6251da177e4SLinus Torvalds 6261da177e4SLinus Torvalds pg_table = (pte_t *) __va(pg_table) + start_pte; 6271da177e4SLinus Torvalds for (tmp2 = start_pte; tmp2 < PTRS_PER_PTE; tmp2++,pg_table++) { 6281da177e4SLinus Torvalds pte_t pte; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds /* 6311da177e4SLinus Torvalds * Map the fault vector writable so we can 6321da177e4SLinus Torvalds * write the HPMC checksum. 6331da177e4SLinus Torvalds */ 6341da177e4SLinus Torvalds if (address >= ro_start && address < ro_end 6351da177e4SLinus Torvalds && address != fv_addr 6361da177e4SLinus Torvalds && address != gw_addr) 6371da177e4SLinus Torvalds pte = __mk_pte(address, PAGE_KERNEL_RO); 6381da177e4SLinus Torvalds else 6391da177e4SLinus Torvalds pte = __mk_pte(address, pgprot); 6401da177e4SLinus Torvalds 6411da177e4SLinus Torvalds if (address >= end_paddr) 6421da177e4SLinus Torvalds pte_val(pte) = 0; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds set_pte(pg_table, pte); 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds address += PAGE_SIZE; 6471da177e4SLinus Torvalds } 6481da177e4SLinus Torvalds start_pte = 0; 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds if (address >= end_paddr) 6511da177e4SLinus Torvalds break; 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds start_pmd = 0; 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds /* 6581da177e4SLinus Torvalds * pagetable_init() sets up the page tables 6591da177e4SLinus Torvalds * 6601da177e4SLinus Torvalds * Note that gateway_init() places the Linux gateway page at page 0. 6611da177e4SLinus Torvalds * Since gateway pages cannot be dereferenced this has the desirable 6621da177e4SLinus Torvalds * side effect of trapping those pesky NULL-reference errors in the 6631da177e4SLinus Torvalds * kernel. 6641da177e4SLinus Torvalds */ 6651da177e4SLinus Torvalds static void __init pagetable_init(void) 6661da177e4SLinus Torvalds { 6671da177e4SLinus Torvalds int range; 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds /* Map each physical memory range to its kernel vaddr */ 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds for (range = 0; range < npmem_ranges; range++) { 6721da177e4SLinus Torvalds unsigned long start_paddr; 6731da177e4SLinus Torvalds unsigned long end_paddr; 6741da177e4SLinus Torvalds unsigned long size; 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds start_paddr = pmem_ranges[range].start_pfn << PAGE_SHIFT; 6771da177e4SLinus Torvalds end_paddr = start_paddr + (pmem_ranges[range].pages << PAGE_SHIFT); 6781da177e4SLinus Torvalds size = pmem_ranges[range].pages << PAGE_SHIFT; 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds map_pages((unsigned long)__va(start_paddr), start_paddr, 6811da177e4SLinus Torvalds size, PAGE_KERNEL); 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 6851da177e4SLinus Torvalds if (initrd_end && initrd_end > mem_limit) { 6861da177e4SLinus Torvalds printk("initrd: mapping %08lx-%08lx\n", initrd_start, initrd_end); 6871da177e4SLinus Torvalds map_pages(initrd_start, __pa(initrd_start), 6881da177e4SLinus Torvalds initrd_end - initrd_start, PAGE_KERNEL); 6891da177e4SLinus Torvalds } 6901da177e4SLinus Torvalds #endif 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds empty_zero_page = alloc_bootmem_pages(PAGE_SIZE); 6931da177e4SLinus Torvalds memset(empty_zero_page, 0, PAGE_SIZE); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds static void __init gateway_init(void) 6971da177e4SLinus Torvalds { 6981da177e4SLinus Torvalds unsigned long linux_gateway_page_addr; 6991da177e4SLinus Torvalds /* FIXME: This is 'const' in order to trick the compiler 7001da177e4SLinus Torvalds into not treating it as DP-relative data. */ 7011da177e4SLinus Torvalds extern void * const linux_gateway_page; 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds linux_gateway_page_addr = LINUX_GATEWAY_ADDR & PAGE_MASK; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds /* 7061da177e4SLinus Torvalds * Setup Linux Gateway page. 7071da177e4SLinus Torvalds * 7081da177e4SLinus Torvalds * The Linux gateway page will reside in kernel space (on virtual 7091da177e4SLinus Torvalds * page 0), so it doesn't need to be aliased into user space. 7101da177e4SLinus Torvalds */ 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds map_pages(linux_gateway_page_addr, __pa(&linux_gateway_page), 7131da177e4SLinus Torvalds PAGE_SIZE, PAGE_GATEWAY); 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds #ifdef CONFIG_HPUX 7171da177e4SLinus Torvalds void 7181da177e4SLinus Torvalds map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm) 7191da177e4SLinus Torvalds { 7201da177e4SLinus Torvalds pgd_t *pg_dir; 7211da177e4SLinus Torvalds pmd_t *pmd; 7221da177e4SLinus Torvalds pte_t *pg_table; 7231da177e4SLinus Torvalds unsigned long start_pmd; 7241da177e4SLinus Torvalds unsigned long start_pte; 7251da177e4SLinus Torvalds unsigned long address; 7261da177e4SLinus Torvalds unsigned long hpux_gw_page_addr; 7271da177e4SLinus Torvalds /* FIXME: This is 'const' in order to trick the compiler 7281da177e4SLinus Torvalds into not treating it as DP-relative data. */ 7291da177e4SLinus Torvalds extern void * const hpux_gateway_page; 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds hpux_gw_page_addr = HPUX_GATEWAY_ADDR & PAGE_MASK; 7321da177e4SLinus Torvalds 7331da177e4SLinus Torvalds /* 7341da177e4SLinus Torvalds * Setup HP-UX Gateway page. 7351da177e4SLinus Torvalds * 7361da177e4SLinus Torvalds * The HP-UX gateway page resides in the user address space, 7371da177e4SLinus Torvalds * so it needs to be aliased into each process. 7381da177e4SLinus Torvalds */ 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds pg_dir = pgd_offset(mm,hpux_gw_page_addr); 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds #if PTRS_PER_PMD == 1 7431da177e4SLinus Torvalds start_pmd = 0; 7441da177e4SLinus Torvalds #else 7451da177e4SLinus Torvalds start_pmd = ((hpux_gw_page_addr >> PMD_SHIFT) & (PTRS_PER_PMD - 1)); 7461da177e4SLinus Torvalds #endif 7471da177e4SLinus Torvalds start_pte = ((hpux_gw_page_addr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)); 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds address = __pa(&hpux_gateway_page); 7501da177e4SLinus Torvalds #if PTRS_PER_PMD == 1 7511da177e4SLinus Torvalds pmd = (pmd_t *)__pa(pg_dir); 7521da177e4SLinus Torvalds #else 7531da177e4SLinus Torvalds pmd = (pmd_t *) pgd_address(*pg_dir); 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds /* 7561da177e4SLinus Torvalds * pmd is physical at this point 7571da177e4SLinus Torvalds */ 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds if (!pmd) { 7601da177e4SLinus Torvalds pmd = (pmd_t *) get_zeroed_page(GFP_KERNEL); 7611da177e4SLinus Torvalds pmd = (pmd_t *) __pa(pmd); 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds __pgd_val_set(*pg_dir, PxD_FLAG_PRESENT | PxD_FLAG_VALID | (unsigned long) pmd); 7651da177e4SLinus Torvalds #endif 7661da177e4SLinus Torvalds /* now change pmd to kernel virtual addresses */ 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds pmd = (pmd_t *)__va(pmd) + start_pmd; 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds /* 7711da177e4SLinus Torvalds * pg_table is physical at this point 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds pg_table = (pte_t *) pmd_address(*pmd); 7751da177e4SLinus Torvalds if (!pg_table) 7761da177e4SLinus Torvalds pg_table = (pte_t *) __pa(get_zeroed_page(GFP_KERNEL)); 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds __pmd_val_set(*pmd, PxD_FLAG_PRESENT | PxD_FLAG_VALID | (unsigned long) pg_table); 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds /* now change pg_table to kernel virtual addresses */ 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds pg_table = (pte_t *) __va(pg_table) + start_pte; 7831da177e4SLinus Torvalds set_pte(pg_table, __mk_pte(address, PAGE_GATEWAY)); 7841da177e4SLinus Torvalds } 7851da177e4SLinus Torvalds EXPORT_SYMBOL(map_hpux_gateway_page); 7861da177e4SLinus Torvalds #endif 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds extern void flush_tlb_all_local(void); 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds void __init paging_init(void) 7911da177e4SLinus Torvalds { 7921da177e4SLinus Torvalds int i; 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds setup_bootmem(); 7951da177e4SLinus Torvalds pagetable_init(); 7961da177e4SLinus Torvalds gateway_init(); 7971da177e4SLinus Torvalds flush_cache_all_local(); /* start with known state */ 7981da177e4SLinus Torvalds flush_tlb_all_local(); 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds for (i = 0; i < npmem_ranges; i++) { 8011da177e4SLinus Torvalds unsigned long zones_size[MAX_NR_ZONES] = { 0, 0, 0 }; 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds /* We have an IOMMU, so all memory can go into a single 8041da177e4SLinus Torvalds ZONE_DMA zone. */ 8051da177e4SLinus Torvalds zones_size[ZONE_DMA] = pmem_ranges[i].pages; 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds #ifdef CONFIG_DISCONTIGMEM 8081da177e4SLinus Torvalds /* Need to initialize the pfnnid_map before we can initialize 8091da177e4SLinus Torvalds the zone */ 8101da177e4SLinus Torvalds { 8111da177e4SLinus Torvalds int j; 8121da177e4SLinus Torvalds for (j = (pmem_ranges[i].start_pfn >> PFNNID_SHIFT); 8131da177e4SLinus Torvalds j <= ((pmem_ranges[i].start_pfn + pmem_ranges[i].pages) >> PFNNID_SHIFT); 8141da177e4SLinus Torvalds j++) { 8151da177e4SLinus Torvalds pfnnid_map[j] = i; 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds #endif 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds free_area_init_node(i, NODE_DATA(i), zones_size, 8211da177e4SLinus Torvalds pmem_ranges[i].start_pfn, NULL); 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds } 8241da177e4SLinus Torvalds 8251da177e4SLinus Torvalds #ifdef CONFIG_PA20 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds /* 8281da177e4SLinus Torvalds * Currently, all PA20 chips have 18 bit protection id's, which is the 8291da177e4SLinus Torvalds * limiting factor (space ids are 32 bits). 8301da177e4SLinus Torvalds */ 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds #define NR_SPACE_IDS 262144 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds #else 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds /* 8371da177e4SLinus Torvalds * Currently we have a one-to-one relationship between space id's and 8381da177e4SLinus Torvalds * protection id's. Older parisc chips (PCXS, PCXT, PCXL, PCXL2) only 8391da177e4SLinus Torvalds * support 15 bit protection id's, so that is the limiting factor. 8401da177e4SLinus Torvalds * PCXT' has 18 bit protection id's, but only 16 bit spaceids, so it's 8411da177e4SLinus Torvalds * probably not worth the effort for a special case here. 8421da177e4SLinus Torvalds */ 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds #define NR_SPACE_IDS 32768 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds #endif /* !CONFIG_PA20 */ 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds #define RECYCLE_THRESHOLD (NR_SPACE_IDS / 2) 8491da177e4SLinus Torvalds #define SID_ARRAY_SIZE (NR_SPACE_IDS / (8 * sizeof(long))) 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds static unsigned long space_id[SID_ARRAY_SIZE] = { 1 }; /* disallow space 0 */ 8521da177e4SLinus Torvalds static unsigned long dirty_space_id[SID_ARRAY_SIZE]; 8531da177e4SLinus Torvalds static unsigned long space_id_index; 8541da177e4SLinus Torvalds static unsigned long free_space_ids = NR_SPACE_IDS - 1; 8551da177e4SLinus Torvalds static unsigned long dirty_space_ids = 0; 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds static DEFINE_SPINLOCK(sid_lock); 8581da177e4SLinus Torvalds 8591da177e4SLinus Torvalds unsigned long alloc_sid(void) 8601da177e4SLinus Torvalds { 8611da177e4SLinus Torvalds unsigned long index; 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds spin_lock(&sid_lock); 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds if (free_space_ids == 0) { 8661da177e4SLinus Torvalds if (dirty_space_ids != 0) { 8671da177e4SLinus Torvalds spin_unlock(&sid_lock); 8681da177e4SLinus Torvalds flush_tlb_all(); /* flush_tlb_all() calls recycle_sids() */ 8691da177e4SLinus Torvalds spin_lock(&sid_lock); 8701da177e4SLinus Torvalds } 8711da177e4SLinus Torvalds if (free_space_ids == 0) 8721da177e4SLinus Torvalds BUG(); 8731da177e4SLinus Torvalds } 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds free_space_ids--; 8761da177e4SLinus Torvalds 8771da177e4SLinus Torvalds index = find_next_zero_bit(space_id, NR_SPACE_IDS, space_id_index); 8781da177e4SLinus Torvalds space_id[index >> SHIFT_PER_LONG] |= (1L << (index & (BITS_PER_LONG - 1))); 8791da177e4SLinus Torvalds space_id_index = index; 8801da177e4SLinus Torvalds 8811da177e4SLinus Torvalds spin_unlock(&sid_lock); 8821da177e4SLinus Torvalds 8831da177e4SLinus Torvalds return index << SPACEID_SHIFT; 8841da177e4SLinus Torvalds } 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds void free_sid(unsigned long spaceid) 8871da177e4SLinus Torvalds { 8881da177e4SLinus Torvalds unsigned long index = spaceid >> SPACEID_SHIFT; 8891da177e4SLinus Torvalds unsigned long *dirty_space_offset; 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds dirty_space_offset = dirty_space_id + (index >> SHIFT_PER_LONG); 8921da177e4SLinus Torvalds index &= (BITS_PER_LONG - 1); 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds spin_lock(&sid_lock); 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds if (*dirty_space_offset & (1L << index)) 8971da177e4SLinus Torvalds BUG(); /* attempt to free space id twice */ 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds *dirty_space_offset |= (1L << index); 9001da177e4SLinus Torvalds dirty_space_ids++; 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds spin_unlock(&sid_lock); 9031da177e4SLinus Torvalds } 9041da177e4SLinus Torvalds 9051da177e4SLinus Torvalds 9061da177e4SLinus Torvalds #ifdef CONFIG_SMP 9071da177e4SLinus Torvalds static void get_dirty_sids(unsigned long *ndirtyptr,unsigned long *dirty_array) 9081da177e4SLinus Torvalds { 9091da177e4SLinus Torvalds int i; 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds /* NOTE: sid_lock must be held upon entry */ 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds *ndirtyptr = dirty_space_ids; 9141da177e4SLinus Torvalds if (dirty_space_ids != 0) { 9151da177e4SLinus Torvalds for (i = 0; i < SID_ARRAY_SIZE; i++) { 9161da177e4SLinus Torvalds dirty_array[i] = dirty_space_id[i]; 9171da177e4SLinus Torvalds dirty_space_id[i] = 0; 9181da177e4SLinus Torvalds } 9191da177e4SLinus Torvalds dirty_space_ids = 0; 9201da177e4SLinus Torvalds } 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds return; 9231da177e4SLinus Torvalds } 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds static void recycle_sids(unsigned long ndirty,unsigned long *dirty_array) 9261da177e4SLinus Torvalds { 9271da177e4SLinus Torvalds int i; 9281da177e4SLinus Torvalds 9291da177e4SLinus Torvalds /* NOTE: sid_lock must be held upon entry */ 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds if (ndirty != 0) { 9321da177e4SLinus Torvalds for (i = 0; i < SID_ARRAY_SIZE; i++) { 9331da177e4SLinus Torvalds space_id[i] ^= dirty_array[i]; 9341da177e4SLinus Torvalds } 9351da177e4SLinus Torvalds 9361da177e4SLinus Torvalds free_space_ids += ndirty; 9371da177e4SLinus Torvalds space_id_index = 0; 9381da177e4SLinus Torvalds } 9391da177e4SLinus Torvalds } 9401da177e4SLinus Torvalds 9411da177e4SLinus Torvalds #else /* CONFIG_SMP */ 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds static void recycle_sids(void) 9441da177e4SLinus Torvalds { 9451da177e4SLinus Torvalds int i; 9461da177e4SLinus Torvalds 9471da177e4SLinus Torvalds /* NOTE: sid_lock must be held upon entry */ 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds if (dirty_space_ids != 0) { 9501da177e4SLinus Torvalds for (i = 0; i < SID_ARRAY_SIZE; i++) { 9511da177e4SLinus Torvalds space_id[i] ^= dirty_space_id[i]; 9521da177e4SLinus Torvalds dirty_space_id[i] = 0; 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds free_space_ids += dirty_space_ids; 9561da177e4SLinus Torvalds dirty_space_ids = 0; 9571da177e4SLinus Torvalds space_id_index = 0; 9581da177e4SLinus Torvalds } 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds #endif 9611da177e4SLinus Torvalds 9621da177e4SLinus Torvalds /* 9631da177e4SLinus Torvalds * flush_tlb_all() calls recycle_sids(), since whenever the entire tlb is 9641da177e4SLinus Torvalds * purged, we can safely reuse the space ids that were released but 9651da177e4SLinus Torvalds * not flushed from the tlb. 9661da177e4SLinus Torvalds */ 9671da177e4SLinus Torvalds 9681da177e4SLinus Torvalds #ifdef CONFIG_SMP 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds static unsigned long recycle_ndirty; 9711da177e4SLinus Torvalds static unsigned long recycle_dirty_array[SID_ARRAY_SIZE]; 9721da177e4SLinus Torvalds static unsigned int recycle_inuse = 0; 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds void flush_tlb_all(void) 9751da177e4SLinus Torvalds { 9761da177e4SLinus Torvalds int do_recycle; 9771da177e4SLinus Torvalds 9781da177e4SLinus Torvalds do_recycle = 0; 9791da177e4SLinus Torvalds spin_lock(&sid_lock); 9801da177e4SLinus Torvalds if (dirty_space_ids > RECYCLE_THRESHOLD) { 9811da177e4SLinus Torvalds if (recycle_inuse) { 9821da177e4SLinus Torvalds BUG(); /* FIXME: Use a semaphore/wait queue here */ 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds get_dirty_sids(&recycle_ndirty,recycle_dirty_array); 9851da177e4SLinus Torvalds recycle_inuse++; 9861da177e4SLinus Torvalds do_recycle++; 9871da177e4SLinus Torvalds } 9881da177e4SLinus Torvalds spin_unlock(&sid_lock); 9891da177e4SLinus Torvalds on_each_cpu((void (*)(void *))flush_tlb_all_local, NULL, 1, 1); 9901da177e4SLinus Torvalds if (do_recycle) { 9911da177e4SLinus Torvalds spin_lock(&sid_lock); 9921da177e4SLinus Torvalds recycle_sids(recycle_ndirty,recycle_dirty_array); 9931da177e4SLinus Torvalds recycle_inuse = 0; 9941da177e4SLinus Torvalds spin_unlock(&sid_lock); 9951da177e4SLinus Torvalds } 9961da177e4SLinus Torvalds } 9971da177e4SLinus Torvalds #else 9981da177e4SLinus Torvalds void flush_tlb_all(void) 9991da177e4SLinus Torvalds { 10001da177e4SLinus Torvalds spin_lock(&sid_lock); 10011da177e4SLinus Torvalds flush_tlb_all_local(); 10021da177e4SLinus Torvalds recycle_sids(); 10031da177e4SLinus Torvalds spin_unlock(&sid_lock); 10041da177e4SLinus Torvalds } 10051da177e4SLinus Torvalds #endif 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 10081da177e4SLinus Torvalds void free_initrd_mem(unsigned long start, unsigned long end) 10091da177e4SLinus Torvalds { 10101da177e4SLinus Torvalds #if 0 10111da177e4SLinus Torvalds if (start < end) 10121da177e4SLinus Torvalds printk(KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10); 10131da177e4SLinus Torvalds for (; start < end; start += PAGE_SIZE) { 10141da177e4SLinus Torvalds ClearPageReserved(virt_to_page(start)); 10151da177e4SLinus Torvalds set_page_count(virt_to_page(start), 1); 10161da177e4SLinus Torvalds free_page(start); 10171da177e4SLinus Torvalds num_physpages++; 10181da177e4SLinus Torvalds totalram_pages++; 10191da177e4SLinus Torvalds } 10201da177e4SLinus Torvalds #endif 10211da177e4SLinus Torvalds } 10221da177e4SLinus Torvalds #endif 1023