1c37ddd93SSam Ravnborg /* 2c37ddd93SSam Ravnborg * linux/arch/sparc/mm/init.c 3c37ddd93SSam Ravnborg * 4c37ddd93SSam Ravnborg * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5c37ddd93SSam Ravnborg * Copyright (C) 1995 Eddie C. Dost (ecd@skynet.be) 6c37ddd93SSam Ravnborg * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 7c37ddd93SSam Ravnborg * Copyright (C) 2000 Anton Blanchard (anton@samba.org) 8c37ddd93SSam Ravnborg */ 9c37ddd93SSam Ravnborg 10c37ddd93SSam Ravnborg #include <linux/module.h> 11c37ddd93SSam Ravnborg #include <linux/signal.h> 12c37ddd93SSam Ravnborg #include <linux/sched.h> 13c37ddd93SSam Ravnborg #include <linux/kernel.h> 14c37ddd93SSam Ravnborg #include <linux/errno.h> 15c37ddd93SSam Ravnborg #include <linux/string.h> 16c37ddd93SSam Ravnborg #include <linux/types.h> 17c37ddd93SSam Ravnborg #include <linux/ptrace.h> 18c37ddd93SSam Ravnborg #include <linux/mman.h> 19c37ddd93SSam Ravnborg #include <linux/mm.h> 20c37ddd93SSam Ravnborg #include <linux/swap.h> 21c37ddd93SSam Ravnborg #include <linux/initrd.h> 22c37ddd93SSam Ravnborg #include <linux/init.h> 23c37ddd93SSam Ravnborg #include <linux/highmem.h> 24c37ddd93SSam Ravnborg #include <linux/bootmem.h> 25c37ddd93SSam Ravnborg #include <linux/pagemap.h> 26c37ddd93SSam Ravnborg #include <linux/poison.h> 27c37ddd93SSam Ravnborg 2886ed40bdSSam Ravnborg #include <asm/sections.h> 29c37ddd93SSam Ravnborg #include <asm/system.h> 30c37ddd93SSam Ravnborg #include <asm/vac-ops.h> 31c37ddd93SSam Ravnborg #include <asm/page.h> 32c37ddd93SSam Ravnborg #include <asm/pgtable.h> 33c37ddd93SSam Ravnborg #include <asm/vaddrs.h> 34c37ddd93SSam Ravnborg #include <asm/pgalloc.h> /* bug in asm-generic/tlb.h: check_pgt_cache */ 35c37ddd93SSam Ravnborg #include <asm/tlb.h> 36c37ddd93SSam Ravnborg #include <asm/prom.h> 37*0fd7ef1fSKonrad Eisele #include <asm/leon.h> 38c37ddd93SSam Ravnborg 39c37ddd93SSam Ravnborg DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); 40c37ddd93SSam Ravnborg 41c37ddd93SSam Ravnborg unsigned long *sparc_valid_addr_bitmap; 426943f3daSSam Ravnborg EXPORT_SYMBOL(sparc_valid_addr_bitmap); 43c37ddd93SSam Ravnborg 44c37ddd93SSam Ravnborg unsigned long phys_base; 456943f3daSSam Ravnborg EXPORT_SYMBOL(phys_base); 466943f3daSSam Ravnborg 47c37ddd93SSam Ravnborg unsigned long pfn_base; 486943f3daSSam Ravnborg EXPORT_SYMBOL(pfn_base); 49c37ddd93SSam Ravnborg 50c37ddd93SSam Ravnborg unsigned long page_kernel; 516943f3daSSam Ravnborg EXPORT_SYMBOL(page_kernel); 52c37ddd93SSam Ravnborg 53c37ddd93SSam Ravnborg struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1]; 54c37ddd93SSam Ravnborg unsigned long sparc_unmapped_base; 55c37ddd93SSam Ravnborg 56c37ddd93SSam Ravnborg struct pgtable_cache_struct pgt_quicklists; 57c37ddd93SSam Ravnborg 58c37ddd93SSam Ravnborg /* Initial ramdisk setup */ 59c37ddd93SSam Ravnborg extern unsigned int sparc_ramdisk_image; 60c37ddd93SSam Ravnborg extern unsigned int sparc_ramdisk_size; 61c37ddd93SSam Ravnborg 62c37ddd93SSam Ravnborg unsigned long highstart_pfn, highend_pfn; 63c37ddd93SSam Ravnborg 64c37ddd93SSam Ravnborg pte_t *kmap_pte; 65c37ddd93SSam Ravnborg pgprot_t kmap_prot; 66c37ddd93SSam Ravnborg 67c37ddd93SSam Ravnborg #define kmap_get_fixmap_pte(vaddr) \ 68c37ddd93SSam Ravnborg pte_offset_kernel(pmd_offset(pgd_offset_k(vaddr), (vaddr)), (vaddr)) 69c37ddd93SSam Ravnborg 70c37ddd93SSam Ravnborg void __init kmap_init(void) 71c37ddd93SSam Ravnborg { 72c37ddd93SSam Ravnborg /* cache the first kmap pte */ 73c37ddd93SSam Ravnborg kmap_pte = kmap_get_fixmap_pte(__fix_to_virt(FIX_KMAP_BEGIN)); 74c37ddd93SSam Ravnborg kmap_prot = __pgprot(SRMMU_ET_PTE | SRMMU_PRIV | SRMMU_CACHE); 75c37ddd93SSam Ravnborg } 76c37ddd93SSam Ravnborg 77c37ddd93SSam Ravnborg void show_mem(void) 78c37ddd93SSam Ravnborg { 79c37ddd93SSam Ravnborg printk("Mem-info:\n"); 80c37ddd93SSam Ravnborg show_free_areas(); 81c37ddd93SSam Ravnborg printk("Free swap: %6ldkB\n", 82c37ddd93SSam Ravnborg nr_swap_pages << (PAGE_SHIFT-10)); 83c37ddd93SSam Ravnborg printk("%ld pages of RAM\n", totalram_pages); 84c37ddd93SSam Ravnborg printk("%ld free pages\n", nr_free_pages()); 85c37ddd93SSam Ravnborg #if 0 /* undefined pgtable_cache_size, pgd_cache_size */ 86c37ddd93SSam Ravnborg printk("%ld pages in page table cache\n",pgtable_cache_size); 87c37ddd93SSam Ravnborg #ifndef CONFIG_SMP 88c37ddd93SSam Ravnborg if (sparc_cpu_model == sun4m || sparc_cpu_model == sun4d) 89c37ddd93SSam Ravnborg printk("%ld entries in page dir cache\n",pgd_cache_size); 90c37ddd93SSam Ravnborg #endif 91c37ddd93SSam Ravnborg #endif 92c37ddd93SSam Ravnborg } 93c37ddd93SSam Ravnborg 94c37ddd93SSam Ravnborg void __init sparc_context_init(int numctx) 95c37ddd93SSam Ravnborg { 96c37ddd93SSam Ravnborg int ctx; 97c37ddd93SSam Ravnborg 98c37ddd93SSam Ravnborg ctx_list_pool = __alloc_bootmem(numctx * sizeof(struct ctx_list), SMP_CACHE_BYTES, 0UL); 99c37ddd93SSam Ravnborg 100c37ddd93SSam Ravnborg for(ctx = 0; ctx < numctx; ctx++) { 101c37ddd93SSam Ravnborg struct ctx_list *clist; 102c37ddd93SSam Ravnborg 103c37ddd93SSam Ravnborg clist = (ctx_list_pool + ctx); 104c37ddd93SSam Ravnborg clist->ctx_number = ctx; 105c37ddd93SSam Ravnborg clist->ctx_mm = NULL; 106c37ddd93SSam Ravnborg } 107c37ddd93SSam Ravnborg ctx_free.next = ctx_free.prev = &ctx_free; 108c37ddd93SSam Ravnborg ctx_used.next = ctx_used.prev = &ctx_used; 109c37ddd93SSam Ravnborg for(ctx = 0; ctx < numctx; ctx++) 110c37ddd93SSam Ravnborg add_to_free_ctxlist(ctx_list_pool + ctx); 111c37ddd93SSam Ravnborg } 112c37ddd93SSam Ravnborg 113c37ddd93SSam Ravnborg extern unsigned long cmdline_memory_size; 114c37ddd93SSam Ravnborg unsigned long last_valid_pfn; 115c37ddd93SSam Ravnborg 116c37ddd93SSam Ravnborg unsigned long calc_highpages(void) 117c37ddd93SSam Ravnborg { 118c37ddd93SSam Ravnborg int i; 119c37ddd93SSam Ravnborg int nr = 0; 120c37ddd93SSam Ravnborg 121c37ddd93SSam Ravnborg for (i = 0; sp_banks[i].num_bytes != 0; i++) { 122c37ddd93SSam Ravnborg unsigned long start_pfn = sp_banks[i].base_addr >> PAGE_SHIFT; 123c37ddd93SSam Ravnborg unsigned long end_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT; 124c37ddd93SSam Ravnborg 125c37ddd93SSam Ravnborg if (end_pfn <= max_low_pfn) 126c37ddd93SSam Ravnborg continue; 127c37ddd93SSam Ravnborg 128c37ddd93SSam Ravnborg if (start_pfn < max_low_pfn) 129c37ddd93SSam Ravnborg start_pfn = max_low_pfn; 130c37ddd93SSam Ravnborg 131c37ddd93SSam Ravnborg nr += end_pfn - start_pfn; 132c37ddd93SSam Ravnborg } 133c37ddd93SSam Ravnborg 134c37ddd93SSam Ravnborg return nr; 135c37ddd93SSam Ravnborg } 136c37ddd93SSam Ravnborg 137c37ddd93SSam Ravnborg static unsigned long calc_max_low_pfn(void) 138c37ddd93SSam Ravnborg { 139c37ddd93SSam Ravnborg int i; 140c37ddd93SSam Ravnborg unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT); 141c37ddd93SSam Ravnborg unsigned long curr_pfn, last_pfn; 142c37ddd93SSam Ravnborg 143c37ddd93SSam Ravnborg last_pfn = (sp_banks[0].base_addr + sp_banks[0].num_bytes) >> PAGE_SHIFT; 144c37ddd93SSam Ravnborg for (i = 1; sp_banks[i].num_bytes != 0; i++) { 145c37ddd93SSam Ravnborg curr_pfn = sp_banks[i].base_addr >> PAGE_SHIFT; 146c37ddd93SSam Ravnborg 147c37ddd93SSam Ravnborg if (curr_pfn >= tmp) { 148c37ddd93SSam Ravnborg if (last_pfn < tmp) 149c37ddd93SSam Ravnborg tmp = last_pfn; 150c37ddd93SSam Ravnborg break; 151c37ddd93SSam Ravnborg } 152c37ddd93SSam Ravnborg 153c37ddd93SSam Ravnborg last_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT; 154c37ddd93SSam Ravnborg } 155c37ddd93SSam Ravnborg 156c37ddd93SSam Ravnborg return tmp; 157c37ddd93SSam Ravnborg } 158c37ddd93SSam Ravnborg 159c37ddd93SSam Ravnborg unsigned long __init bootmem_init(unsigned long *pages_avail) 160c37ddd93SSam Ravnborg { 161c37ddd93SSam Ravnborg unsigned long bootmap_size, start_pfn; 162c37ddd93SSam Ravnborg unsigned long end_of_phys_memory = 0UL; 163c37ddd93SSam Ravnborg unsigned long bootmap_pfn, bytes_avail, size; 164c37ddd93SSam Ravnborg int i; 165c37ddd93SSam Ravnborg 166c37ddd93SSam Ravnborg bytes_avail = 0UL; 167c37ddd93SSam Ravnborg for (i = 0; sp_banks[i].num_bytes != 0; i++) { 168c37ddd93SSam Ravnborg end_of_phys_memory = sp_banks[i].base_addr + 169c37ddd93SSam Ravnborg sp_banks[i].num_bytes; 170c37ddd93SSam Ravnborg bytes_avail += sp_banks[i].num_bytes; 171c37ddd93SSam Ravnborg if (cmdline_memory_size) { 172c37ddd93SSam Ravnborg if (bytes_avail > cmdline_memory_size) { 173c37ddd93SSam Ravnborg unsigned long slack = bytes_avail - cmdline_memory_size; 174c37ddd93SSam Ravnborg 175c37ddd93SSam Ravnborg bytes_avail -= slack; 176c37ddd93SSam Ravnborg end_of_phys_memory -= slack; 177c37ddd93SSam Ravnborg 178c37ddd93SSam Ravnborg sp_banks[i].num_bytes -= slack; 179c37ddd93SSam Ravnborg if (sp_banks[i].num_bytes == 0) { 180c37ddd93SSam Ravnborg sp_banks[i].base_addr = 0xdeadbeef; 181c37ddd93SSam Ravnborg } else { 182c37ddd93SSam Ravnborg sp_banks[i+1].num_bytes = 0; 183c37ddd93SSam Ravnborg sp_banks[i+1].base_addr = 0xdeadbeef; 184c37ddd93SSam Ravnborg } 185c37ddd93SSam Ravnborg break; 186c37ddd93SSam Ravnborg } 187c37ddd93SSam Ravnborg } 188c37ddd93SSam Ravnborg } 189c37ddd93SSam Ravnborg 190c37ddd93SSam Ravnborg /* Start with page aligned address of last symbol in kernel 191c37ddd93SSam Ravnborg * image. 192c37ddd93SSam Ravnborg */ 193c37ddd93SSam Ravnborg start_pfn = (unsigned long)__pa(PAGE_ALIGN((unsigned long) &_end)); 194c37ddd93SSam Ravnborg 195c37ddd93SSam Ravnborg /* Now shift down to get the real physical page frame number. */ 196c37ddd93SSam Ravnborg start_pfn >>= PAGE_SHIFT; 197c37ddd93SSam Ravnborg 198c37ddd93SSam Ravnborg bootmap_pfn = start_pfn; 199c37ddd93SSam Ravnborg 200c37ddd93SSam Ravnborg max_pfn = end_of_phys_memory >> PAGE_SHIFT; 201c37ddd93SSam Ravnborg 202c37ddd93SSam Ravnborg max_low_pfn = max_pfn; 203c37ddd93SSam Ravnborg highstart_pfn = highend_pfn = max_pfn; 204c37ddd93SSam Ravnborg 205c37ddd93SSam Ravnborg if (max_low_pfn > pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT)) { 206c37ddd93SSam Ravnborg highstart_pfn = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT); 207c37ddd93SSam Ravnborg max_low_pfn = calc_max_low_pfn(); 208c37ddd93SSam Ravnborg printk(KERN_NOTICE "%ldMB HIGHMEM available.\n", 209c37ddd93SSam Ravnborg calc_highpages() >> (20 - PAGE_SHIFT)); 210c37ddd93SSam Ravnborg } 211c37ddd93SSam Ravnborg 212c37ddd93SSam Ravnborg #ifdef CONFIG_BLK_DEV_INITRD 213c37ddd93SSam Ravnborg /* Now have to check initial ramdisk, so that bootmap does not overwrite it */ 214c37ddd93SSam Ravnborg if (sparc_ramdisk_image) { 215c37ddd93SSam Ravnborg if (sparc_ramdisk_image >= (unsigned long)&_end - 2 * PAGE_SIZE) 216c37ddd93SSam Ravnborg sparc_ramdisk_image -= KERNBASE; 217c37ddd93SSam Ravnborg initrd_start = sparc_ramdisk_image + phys_base; 218c37ddd93SSam Ravnborg initrd_end = initrd_start + sparc_ramdisk_size; 219c37ddd93SSam Ravnborg if (initrd_end > end_of_phys_memory) { 220c37ddd93SSam Ravnborg printk(KERN_CRIT "initrd extends beyond end of memory " 221c37ddd93SSam Ravnborg "(0x%016lx > 0x%016lx)\ndisabling initrd\n", 222c37ddd93SSam Ravnborg initrd_end, end_of_phys_memory); 223c37ddd93SSam Ravnborg initrd_start = 0; 224c37ddd93SSam Ravnborg } 225c37ddd93SSam Ravnborg if (initrd_start) { 226c37ddd93SSam Ravnborg if (initrd_start >= (start_pfn << PAGE_SHIFT) && 227c37ddd93SSam Ravnborg initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE) 228c37ddd93SSam Ravnborg bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT; 229c37ddd93SSam Ravnborg } 230c37ddd93SSam Ravnborg } 231c37ddd93SSam Ravnborg #endif 232c37ddd93SSam Ravnborg /* Initialize the boot-time allocator. */ 233c37ddd93SSam Ravnborg bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base, 234c37ddd93SSam Ravnborg max_low_pfn); 235c37ddd93SSam Ravnborg 236c37ddd93SSam Ravnborg /* Now register the available physical memory with the 237c37ddd93SSam Ravnborg * allocator. 238c37ddd93SSam Ravnborg */ 239c37ddd93SSam Ravnborg *pages_avail = 0; 240c37ddd93SSam Ravnborg for (i = 0; sp_banks[i].num_bytes != 0; i++) { 241c37ddd93SSam Ravnborg unsigned long curr_pfn, last_pfn; 242c37ddd93SSam Ravnborg 243c37ddd93SSam Ravnborg curr_pfn = sp_banks[i].base_addr >> PAGE_SHIFT; 244c37ddd93SSam Ravnborg if (curr_pfn >= max_low_pfn) 245c37ddd93SSam Ravnborg break; 246c37ddd93SSam Ravnborg 247c37ddd93SSam Ravnborg last_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT; 248c37ddd93SSam Ravnborg if (last_pfn > max_low_pfn) 249c37ddd93SSam Ravnborg last_pfn = max_low_pfn; 250c37ddd93SSam Ravnborg 251c37ddd93SSam Ravnborg /* 252c37ddd93SSam Ravnborg * .. finally, did all the rounding and playing 253c37ddd93SSam Ravnborg * around just make the area go away? 254c37ddd93SSam Ravnborg */ 255c37ddd93SSam Ravnborg if (last_pfn <= curr_pfn) 256c37ddd93SSam Ravnborg continue; 257c37ddd93SSam Ravnborg 258c37ddd93SSam Ravnborg size = (last_pfn - curr_pfn) << PAGE_SHIFT; 259c37ddd93SSam Ravnborg *pages_avail += last_pfn - curr_pfn; 260c37ddd93SSam Ravnborg 261c37ddd93SSam Ravnborg free_bootmem(sp_banks[i].base_addr, size); 262c37ddd93SSam Ravnborg } 263c37ddd93SSam Ravnborg 264c37ddd93SSam Ravnborg #ifdef CONFIG_BLK_DEV_INITRD 265c37ddd93SSam Ravnborg if (initrd_start) { 266c37ddd93SSam Ravnborg /* Reserve the initrd image area. */ 267c37ddd93SSam Ravnborg size = initrd_end - initrd_start; 268c37ddd93SSam Ravnborg reserve_bootmem(initrd_start, size, BOOTMEM_DEFAULT); 269c37ddd93SSam Ravnborg *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT; 270c37ddd93SSam Ravnborg 271c37ddd93SSam Ravnborg initrd_start = (initrd_start - phys_base) + PAGE_OFFSET; 272c37ddd93SSam Ravnborg initrd_end = (initrd_end - phys_base) + PAGE_OFFSET; 273c37ddd93SSam Ravnborg } 274c37ddd93SSam Ravnborg #endif 275c37ddd93SSam Ravnborg /* Reserve the kernel text/data/bss. */ 276c37ddd93SSam Ravnborg size = (start_pfn << PAGE_SHIFT) - phys_base; 277c37ddd93SSam Ravnborg reserve_bootmem(phys_base, size, BOOTMEM_DEFAULT); 278c37ddd93SSam Ravnborg *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT; 279c37ddd93SSam Ravnborg 280c37ddd93SSam Ravnborg /* Reserve the bootmem map. We do not account for it 281c37ddd93SSam Ravnborg * in pages_avail because we will release that memory 282c37ddd93SSam Ravnborg * in free_all_bootmem. 283c37ddd93SSam Ravnborg */ 284c37ddd93SSam Ravnborg size = bootmap_size; 285c37ddd93SSam Ravnborg reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size, BOOTMEM_DEFAULT); 286c37ddd93SSam Ravnborg *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT; 287c37ddd93SSam Ravnborg 288c37ddd93SSam Ravnborg return max_pfn; 289c37ddd93SSam Ravnborg } 290c37ddd93SSam Ravnborg 291c37ddd93SSam Ravnborg /* 292c37ddd93SSam Ravnborg * check_pgt_cache 293c37ddd93SSam Ravnborg * 294c37ddd93SSam Ravnborg * This is called at the end of unmapping of VMA (zap_page_range), 295c37ddd93SSam Ravnborg * to rescan the page cache for architecture specific things, 296c37ddd93SSam Ravnborg * presumably something like sun4/sun4c PMEGs. Most architectures 297c37ddd93SSam Ravnborg * define check_pgt_cache empty. 298c37ddd93SSam Ravnborg * 299c37ddd93SSam Ravnborg * We simply copy the 2.4 implementation for now. 300c37ddd93SSam Ravnborg */ 301c37ddd93SSam Ravnborg static int pgt_cache_water[2] = { 25, 50 }; 302c37ddd93SSam Ravnborg 303c37ddd93SSam Ravnborg void check_pgt_cache(void) 304c37ddd93SSam Ravnborg { 305c37ddd93SSam Ravnborg do_check_pgt_cache(pgt_cache_water[0], pgt_cache_water[1]); 306c37ddd93SSam Ravnborg } 307c37ddd93SSam Ravnborg 308c37ddd93SSam Ravnborg /* 309c37ddd93SSam Ravnborg * paging_init() sets up the page tables: We call the MMU specific 310c37ddd93SSam Ravnborg * init routine based upon the Sun model type on the Sparc. 311c37ddd93SSam Ravnborg * 312c37ddd93SSam Ravnborg */ 313c37ddd93SSam Ravnborg extern void sun4c_paging_init(void); 314c37ddd93SSam Ravnborg extern void srmmu_paging_init(void); 315c37ddd93SSam Ravnborg extern void device_scan(void); 316c37ddd93SSam Ravnborg 317c37ddd93SSam Ravnborg pgprot_t PAGE_SHARED __read_mostly; 318c37ddd93SSam Ravnborg EXPORT_SYMBOL(PAGE_SHARED); 319c37ddd93SSam Ravnborg 320c37ddd93SSam Ravnborg void __init paging_init(void) 321c37ddd93SSam Ravnborg { 322c37ddd93SSam Ravnborg switch(sparc_cpu_model) { 323c37ddd93SSam Ravnborg case sun4c: 324c37ddd93SSam Ravnborg case sun4e: 325c37ddd93SSam Ravnborg case sun4: 326c37ddd93SSam Ravnborg sun4c_paging_init(); 327c37ddd93SSam Ravnborg sparc_unmapped_base = 0xe0000000; 328c37ddd93SSam Ravnborg BTFIXUPSET_SETHI(sparc_unmapped_base, 0xe0000000); 329c37ddd93SSam Ravnborg break; 330*0fd7ef1fSKonrad Eisele case sparc_leon: 331*0fd7ef1fSKonrad Eisele leon_init(); 332*0fd7ef1fSKonrad Eisele /* fall through */ 333c37ddd93SSam Ravnborg case sun4m: 334c37ddd93SSam Ravnborg case sun4d: 335c37ddd93SSam Ravnborg srmmu_paging_init(); 336c37ddd93SSam Ravnborg sparc_unmapped_base = 0x50000000; 337c37ddd93SSam Ravnborg BTFIXUPSET_SETHI(sparc_unmapped_base, 0x50000000); 338c37ddd93SSam Ravnborg break; 339c37ddd93SSam Ravnborg default: 340c37ddd93SSam Ravnborg prom_printf("paging_init: Cannot init paging on this Sparc\n"); 341c37ddd93SSam Ravnborg prom_printf("paging_init: sparc_cpu_model = %d\n", sparc_cpu_model); 342c37ddd93SSam Ravnborg prom_printf("paging_init: Halting...\n"); 343c37ddd93SSam Ravnborg prom_halt(); 344c37ddd93SSam Ravnborg }; 345c37ddd93SSam Ravnborg 346c37ddd93SSam Ravnborg /* Initialize the protection map with non-constant, MMU dependent values. */ 347c37ddd93SSam Ravnborg protection_map[0] = PAGE_NONE; 348c37ddd93SSam Ravnborg protection_map[1] = PAGE_READONLY; 349c37ddd93SSam Ravnborg protection_map[2] = PAGE_COPY; 350c37ddd93SSam Ravnborg protection_map[3] = PAGE_COPY; 351c37ddd93SSam Ravnborg protection_map[4] = PAGE_READONLY; 352c37ddd93SSam Ravnborg protection_map[5] = PAGE_READONLY; 353c37ddd93SSam Ravnborg protection_map[6] = PAGE_COPY; 354c37ddd93SSam Ravnborg protection_map[7] = PAGE_COPY; 355c37ddd93SSam Ravnborg protection_map[8] = PAGE_NONE; 356c37ddd93SSam Ravnborg protection_map[9] = PAGE_READONLY; 357c37ddd93SSam Ravnborg protection_map[10] = PAGE_SHARED; 358c37ddd93SSam Ravnborg protection_map[11] = PAGE_SHARED; 359c37ddd93SSam Ravnborg protection_map[12] = PAGE_READONLY; 360c37ddd93SSam Ravnborg protection_map[13] = PAGE_READONLY; 361c37ddd93SSam Ravnborg protection_map[14] = PAGE_SHARED; 362c37ddd93SSam Ravnborg protection_map[15] = PAGE_SHARED; 363c37ddd93SSam Ravnborg btfixup(); 364c37ddd93SSam Ravnborg prom_build_devicetree(); 365890db403SDavid S. Miller of_fill_in_cpu_data(); 366c37ddd93SSam Ravnborg device_scan(); 367c37ddd93SSam Ravnborg } 368c37ddd93SSam Ravnborg 369c37ddd93SSam Ravnborg static void __init taint_real_pages(void) 370c37ddd93SSam Ravnborg { 371c37ddd93SSam Ravnborg int i; 372c37ddd93SSam Ravnborg 373c37ddd93SSam Ravnborg for (i = 0; sp_banks[i].num_bytes; i++) { 374c37ddd93SSam Ravnborg unsigned long start, end; 375c37ddd93SSam Ravnborg 376c37ddd93SSam Ravnborg start = sp_banks[i].base_addr; 377c37ddd93SSam Ravnborg end = start + sp_banks[i].num_bytes; 378c37ddd93SSam Ravnborg 379c37ddd93SSam Ravnborg while (start < end) { 380c37ddd93SSam Ravnborg set_bit(start >> 20, sparc_valid_addr_bitmap); 381c37ddd93SSam Ravnborg start += PAGE_SIZE; 382c37ddd93SSam Ravnborg } 383c37ddd93SSam Ravnborg } 384c37ddd93SSam Ravnborg } 385c37ddd93SSam Ravnborg 386c37ddd93SSam Ravnborg static void map_high_region(unsigned long start_pfn, unsigned long end_pfn) 387c37ddd93SSam Ravnborg { 388c37ddd93SSam Ravnborg unsigned long tmp; 389c37ddd93SSam Ravnborg 390c37ddd93SSam Ravnborg #ifdef CONFIG_DEBUG_HIGHMEM 391c37ddd93SSam Ravnborg printk("mapping high region %08lx - %08lx\n", start_pfn, end_pfn); 392c37ddd93SSam Ravnborg #endif 393c37ddd93SSam Ravnborg 394c37ddd93SSam Ravnborg for (tmp = start_pfn; tmp < end_pfn; tmp++) { 395c37ddd93SSam Ravnborg struct page *page = pfn_to_page(tmp); 396c37ddd93SSam Ravnborg 397c37ddd93SSam Ravnborg ClearPageReserved(page); 398c37ddd93SSam Ravnborg init_page_count(page); 399c37ddd93SSam Ravnborg __free_page(page); 400c37ddd93SSam Ravnborg totalhigh_pages++; 401c37ddd93SSam Ravnborg } 402c37ddd93SSam Ravnborg } 403c37ddd93SSam Ravnborg 404c37ddd93SSam Ravnborg void __init mem_init(void) 405c37ddd93SSam Ravnborg { 406c37ddd93SSam Ravnborg int codepages = 0; 407c37ddd93SSam Ravnborg int datapages = 0; 408c37ddd93SSam Ravnborg int initpages = 0; 409c37ddd93SSam Ravnborg int reservedpages = 0; 410c37ddd93SSam Ravnborg int i; 411c37ddd93SSam Ravnborg 412c37ddd93SSam Ravnborg if (PKMAP_BASE+LAST_PKMAP*PAGE_SIZE >= FIXADDR_START) { 413c37ddd93SSam Ravnborg prom_printf("BUG: fixmap and pkmap areas overlap\n"); 414c37ddd93SSam Ravnborg prom_printf("pkbase: 0x%lx pkend: 0x%lx fixstart 0x%lx\n", 415c37ddd93SSam Ravnborg PKMAP_BASE, 416c37ddd93SSam Ravnborg (unsigned long)PKMAP_BASE+LAST_PKMAP*PAGE_SIZE, 417c37ddd93SSam Ravnborg FIXADDR_START); 418c37ddd93SSam Ravnborg prom_printf("Please mail sparclinux@vger.kernel.org.\n"); 419c37ddd93SSam Ravnborg prom_halt(); 420c37ddd93SSam Ravnborg } 421c37ddd93SSam Ravnborg 422c37ddd93SSam Ravnborg 423c37ddd93SSam Ravnborg /* Saves us work later. */ 424c37ddd93SSam Ravnborg memset((void *)&empty_zero_page, 0, PAGE_SIZE); 425c37ddd93SSam Ravnborg 426c37ddd93SSam Ravnborg i = last_valid_pfn >> ((20 - PAGE_SHIFT) + 5); 427c37ddd93SSam Ravnborg i += 1; 428c37ddd93SSam Ravnborg sparc_valid_addr_bitmap = (unsigned long *) 429c37ddd93SSam Ravnborg __alloc_bootmem(i << 2, SMP_CACHE_BYTES, 0UL); 430c37ddd93SSam Ravnborg 431c37ddd93SSam Ravnborg if (sparc_valid_addr_bitmap == NULL) { 432c37ddd93SSam Ravnborg prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n"); 433c37ddd93SSam Ravnborg prom_halt(); 434c37ddd93SSam Ravnborg } 435c37ddd93SSam Ravnborg memset(sparc_valid_addr_bitmap, 0, i << 2); 436c37ddd93SSam Ravnborg 437c37ddd93SSam Ravnborg taint_real_pages(); 438c37ddd93SSam Ravnborg 439c37ddd93SSam Ravnborg max_mapnr = last_valid_pfn - pfn_base; 440c37ddd93SSam Ravnborg high_memory = __va(max_low_pfn << PAGE_SHIFT); 441c37ddd93SSam Ravnborg 442c37ddd93SSam Ravnborg totalram_pages = free_all_bootmem(); 443c37ddd93SSam Ravnborg 444c37ddd93SSam Ravnborg for (i = 0; sp_banks[i].num_bytes != 0; i++) { 445c37ddd93SSam Ravnborg unsigned long start_pfn = sp_banks[i].base_addr >> PAGE_SHIFT; 446c37ddd93SSam Ravnborg unsigned long end_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT; 447c37ddd93SSam Ravnborg 448c37ddd93SSam Ravnborg num_physpages += sp_banks[i].num_bytes >> PAGE_SHIFT; 449c37ddd93SSam Ravnborg 450c37ddd93SSam Ravnborg if (end_pfn <= highstart_pfn) 451c37ddd93SSam Ravnborg continue; 452c37ddd93SSam Ravnborg 453c37ddd93SSam Ravnborg if (start_pfn < highstart_pfn) 454c37ddd93SSam Ravnborg start_pfn = highstart_pfn; 455c37ddd93SSam Ravnborg 456c37ddd93SSam Ravnborg map_high_region(start_pfn, end_pfn); 457c37ddd93SSam Ravnborg } 458c37ddd93SSam Ravnborg 459c37ddd93SSam Ravnborg totalram_pages += totalhigh_pages; 460c37ddd93SSam Ravnborg 46186ed40bdSSam Ravnborg codepages = (((unsigned long) &_etext) - ((unsigned long)&_start)); 462c37ddd93SSam Ravnborg codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT; 46386ed40bdSSam Ravnborg datapages = (((unsigned long) &_edata) - ((unsigned long)&_etext)); 464c37ddd93SSam Ravnborg datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT; 465c37ddd93SSam Ravnborg initpages = (((unsigned long) &__init_end) - ((unsigned long) &__init_begin)); 466c37ddd93SSam Ravnborg initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT; 467c37ddd93SSam Ravnborg 468c37ddd93SSam Ravnborg /* Ignore memory holes for the purpose of counting reserved pages */ 469c37ddd93SSam Ravnborg for (i=0; i < max_low_pfn; i++) 470c37ddd93SSam Ravnborg if (test_bit(i >> (20 - PAGE_SHIFT), sparc_valid_addr_bitmap) 471c37ddd93SSam Ravnborg && PageReserved(pfn_to_page(i))) 472c37ddd93SSam Ravnborg reservedpages++; 473c37ddd93SSam Ravnborg 474c37ddd93SSam Ravnborg printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n", 475c37ddd93SSam Ravnborg (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), 476c37ddd93SSam Ravnborg num_physpages << (PAGE_SHIFT - 10), 477c37ddd93SSam Ravnborg codepages << (PAGE_SHIFT-10), 478c37ddd93SSam Ravnborg reservedpages << (PAGE_SHIFT - 10), 479c37ddd93SSam Ravnborg datapages << (PAGE_SHIFT-10), 480c37ddd93SSam Ravnborg initpages << (PAGE_SHIFT-10), 481c37ddd93SSam Ravnborg totalhigh_pages << (PAGE_SHIFT-10)); 482c37ddd93SSam Ravnborg } 483c37ddd93SSam Ravnborg 484c37ddd93SSam Ravnborg void free_initmem (void) 485c37ddd93SSam Ravnborg { 486c37ddd93SSam Ravnborg unsigned long addr; 48786ed40bdSSam Ravnborg unsigned long freed; 488c37ddd93SSam Ravnborg 489c37ddd93SSam Ravnborg addr = (unsigned long)(&__init_begin); 49086ed40bdSSam Ravnborg freed = (unsigned long)(&__init_end) - addr; 491c37ddd93SSam Ravnborg for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { 492c37ddd93SSam Ravnborg struct page *p; 493c37ddd93SSam Ravnborg 494c37ddd93SSam Ravnborg memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE); 495c37ddd93SSam Ravnborg p = virt_to_page(addr); 496c37ddd93SSam Ravnborg 497c37ddd93SSam Ravnborg ClearPageReserved(p); 498c37ddd93SSam Ravnborg init_page_count(p); 499c37ddd93SSam Ravnborg __free_page(p); 500c37ddd93SSam Ravnborg totalram_pages++; 501c37ddd93SSam Ravnborg num_physpages++; 502c37ddd93SSam Ravnborg } 50386ed40bdSSam Ravnborg printk(KERN_INFO "Freeing unused kernel memory: %ldk freed\n", 50486ed40bdSSam Ravnborg freed >> 10); 505c37ddd93SSam Ravnborg } 506c37ddd93SSam Ravnborg 507c37ddd93SSam Ravnborg #ifdef CONFIG_BLK_DEV_INITRD 508c37ddd93SSam Ravnborg void free_initrd_mem(unsigned long start, unsigned long end) 509c37ddd93SSam Ravnborg { 510c37ddd93SSam Ravnborg if (start < end) 511c37ddd93SSam Ravnborg printk(KERN_INFO "Freeing initrd memory: %ldk freed\n", 512c37ddd93SSam Ravnborg (end - start) >> 10); 513c37ddd93SSam Ravnborg for (; start < end; start += PAGE_SIZE) { 514c37ddd93SSam Ravnborg struct page *p; 515c37ddd93SSam Ravnborg 516c37ddd93SSam Ravnborg memset((void *)start, POISON_FREE_INITMEM, PAGE_SIZE); 517c37ddd93SSam Ravnborg p = virt_to_page(start); 518c37ddd93SSam Ravnborg 519c37ddd93SSam Ravnborg ClearPageReserved(p); 520c37ddd93SSam Ravnborg init_page_count(p); 521c37ddd93SSam Ravnborg __free_page(p); 522c37ddd93SSam Ravnborg totalram_pages++; 523c37ddd93SSam Ravnborg num_physpages++; 524c37ddd93SSam Ravnborg } 525c37ddd93SSam Ravnborg } 526c37ddd93SSam Ravnborg #endif 527c37ddd93SSam Ravnborg 528c37ddd93SSam Ravnborg void sparc_flush_page_to_ram(struct page *page) 529c37ddd93SSam Ravnborg { 530c37ddd93SSam Ravnborg unsigned long vaddr = (unsigned long)page_address(page); 531c37ddd93SSam Ravnborg 532c37ddd93SSam Ravnborg if (vaddr) 533c37ddd93SSam Ravnborg __flush_page_to_ram(vaddr); 534c37ddd93SSam Ravnborg } 5356943f3daSSam Ravnborg EXPORT_SYMBOL(sparc_flush_page_to_ram); 536