···49495050 int (*mv_clk_init)(void);5151 int (*mv_mode_pins)(void);5252+5353+ void (*mv_mem_init)(void);5254};53555456extern struct sh_machine_vector sh_mv;
+2-1
arch/sh/include/asm/mmzone.h
···4242void __init plat_mem_setup(void);43434444/* arch/sh/kernel/setup.c */4545-void __init setup_bootmem_allocator(unsigned long start_pfn);4645void __init __add_active_range(unsigned int nid, unsigned long start_pfn,4746 unsigned long end_pfn);4747+/* arch/sh/mm/init.c */4848+void __init allocate_pgdat(unsigned int nid);48494950#endif /* __KERNEL__ */5051#endif /* __ASM_SH_MMZONE_H */
+1-1
arch/sh/include/asm/page.h
···49495050extern unsigned long shm_align_mask;5151extern unsigned long max_low_pfn, min_low_pfn;5252-extern unsigned long memory_start, memory_end;5252+extern unsigned long memory_start, memory_end, memory_limit;53535454static inline unsigned long5555pages_do_alias(unsigned long addr1, unsigned long addr2)
···88 * This source code is licensed under the GNU General Public License,99 * Version 2. See the file COPYING for more details.1010 */1111-1211#include <linux/mm.h>1312#include <linux/kexec.h>1413#include <linux/delay.h>···1516#include <linux/numa.h>1617#include <linux/ftrace.h>1718#include <linux/suspend.h>1919+#include <linux/lmb.h>1820#include <asm/pgtable.h>1921#include <asm/pgalloc.h>2022#include <asm/mmu_context.h>···150150#ifdef CONFIG_X2TLB151151 VMCOREINFO_CONFIG(X2TLB);152152#endif153153+}154154+155155+void __init reserve_crashkernel(void)156156+{157157+ unsigned long long crash_size, crash_base;158158+ int ret;159159+160160+ /* this is necessary because of lmb_phys_mem_size() */161161+ lmb_analyze();162162+163163+ ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),164164+ &crash_size, &crash_base);165165+ if (ret == 0 && crash_size > 0) {166166+ crashk_res.start = crash_base;167167+ crashk_res.end = crash_base + crash_size - 1;168168+ }169169+170170+ if (crashk_res.end == crashk_res.start)171171+ goto disable;172172+173173+ crash_size = PAGE_ALIGN(crashk_res.end - crashk_res.start + 1);174174+ if (!crashk_res.start) {175175+ unsigned long max = lmb_end_of_DRAM() - memory_limit;176176+ crashk_res.start = __lmb_alloc_base(crash_size, PAGE_SIZE, max);177177+ if (!crashk_res.start) {178178+ pr_err("crashkernel allocation failed\n");179179+ goto disable;180180+ }181181+ } else {182182+ ret = lmb_reserve(crashk_res.start, crash_size);183183+ if (unlikely(ret < 0)) {184184+ pr_err("crashkernel reservation failed - "185185+ "memory is in use\n");186186+ goto disable;187187+ }188188+ }189189+190190+ crashk_res.end = crashk_res.start + crash_size - 1;191191+192192+ /*193193+ * Crash kernel trumps memory limit194194+ */195195+ if ((lmb_end_of_DRAM() - memory_limit) <= crashk_res.end) {196196+ memory_limit = 0;197197+ pr_info("Disabled memory limit for crashkernel\n");198198+ }199199+200200+ pr_info("Reserving %ldMB of memory at 0x%08lx "201201+ "for crashkernel (System RAM: %ldMB)\n",202202+ (unsigned long)(crash_size >> 20),203203+ (unsigned long)(crashk_res.start),204204+ (unsigned long)(lmb_phys_mem_size() >> 20));205205+206206+ return;207207+208208+disable:209209+ crashk_res.start = crashk_res.end = 0;153210}
+1
arch/sh/kernel/machvec.c
···131131 mv_set(ioport_unmap);132132 mv_set(irq_demux);133133 mv_set(mode_pins);134134+ mv_set(mem_init);134135135136 if (!sh_mv.mv_nr_irqs)136137 sh_mv.mv_nr_irqs = NR_IRQS;
+28-204
arch/sh/kernel/setup.c
···44 * This file handles the architecture-dependent parts of initialization55 *66 * Copyright (C) 1999 Niibe Yutaka77- * Copyright (C) 2002 - 2007 Paul Mundt77+ * Copyright (C) 2002 - 2010 Paul Mundt88 */99#include <linux/screen_info.h>1010#include <linux/ioport.h>···4141#include <asm/clock.h>4242#include <asm/smp.h>4343#include <asm/mmu_context.h>4444+#include <asm/mmzone.h>44454546/*4647 * Initialize loops_per_jiffy as 10000000 (1000MIPS).···9594EXPORT_SYMBOL(memory_start);9695unsigned long memory_end = 0;9796EXPORT_SYMBOL(memory_end);9797+unsigned long memory_limit = 0;98989999static struct resource mem_resources[MAX_NUMNODES];100100···103101104102static int __init early_parse_mem(char *p)105103{106106- unsigned long size;104104+ if (!p)105105+ return 1;107106108108- memory_start = (unsigned long)__va(__MEMORY_START);109109- size = memparse(p, &p);107107+ memory_limit = PAGE_ALIGN(memparse(p, &p));110108111111- if (size > __MEMORY_SIZE) {112112- printk(KERN_ERR113113- "Using mem= to increase the size of kernel memory "114114- "is not allowed.\n"115115- " Recompile the kernel with the correct value for "116116- "CONFIG_MEMORY_SIZE.\n");117117- return 0;118118- }119119-120120- memory_end = memory_start + size;109109+ pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);121110122111 return 0;123112}124113early_param("mem", early_parse_mem);125114126126-/*127127- * Register fully available low RAM pages with the bootmem allocator.128128- */129129-static void __init register_bootmem_low_pages(void)130130-{131131- unsigned long curr_pfn, last_pfn, pages;132132-133133- /*134134- * We are rounding up the start address of usable memory:135135- */136136- curr_pfn = PFN_UP(__MEMORY_START);137137-138138- /*139139- * ... and at the end of the usable range downwards:140140- */141141- last_pfn = PFN_DOWN(__pa(memory_end));142142-143143- if (last_pfn > max_low_pfn)144144- last_pfn = max_low_pfn;145145-146146- pages = last_pfn - curr_pfn;147147- free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages));148148-}149149-150150-#ifdef CONFIG_KEXEC151151-static void __init reserve_crashkernel(void)152152-{153153- unsigned long long free_mem;154154- unsigned long long crash_size, crash_base;155155- void *vp;156156- int ret;157157-158158- free_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;159159-160160- ret = parse_crashkernel(boot_command_line, free_mem,161161- &crash_size, &crash_base);162162- if (ret == 0 && crash_size) {163163- if (crash_base <= 0) {164164- vp = alloc_bootmem_nopanic(crash_size);165165- if (!vp) {166166- printk(KERN_INFO "crashkernel allocation "167167- "failed\n");168168- return;169169- }170170- crash_base = __pa(vp);171171- } else if (reserve_bootmem(crash_base, crash_size,172172- BOOTMEM_EXCLUSIVE) < 0) {173173- printk(KERN_INFO "crashkernel reservation failed - "174174- "memory is in use\n");175175- return;176176- }177177-178178- printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "179179- "for crashkernel (System RAM: %ldMB)\n",180180- (unsigned long)(crash_size >> 20),181181- (unsigned long)(crash_base >> 20),182182- (unsigned long)(free_mem >> 20));183183- crashk_res.start = crash_base;184184- crashk_res.end = crash_base + crash_size - 1;185185- insert_resource(&iomem_resource, &crashk_res);186186- }187187-}188188-#else189189-static inline void __init reserve_crashkernel(void)190190-{}191191-#endif192192-193193-static void __init check_for_initrd(void)115115+void __init check_for_initrd(void)194116{195117#ifdef CONFIG_BLK_DEV_INITRD196118 unsigned long start, end;···161235 initrd_start = (unsigned long)__va(__pa(start));162236 initrd_end = initrd_start + INITRD_SIZE;163237164164- reserve_bootmem(__pa(initrd_start), INITRD_SIZE, BOOTMEM_DEFAULT);238238+ lmb_reserve(__pa(initrd_start), INITRD_SIZE);165239166240 return;167241···191265 unsigned long end_pfn)192266{193267 struct resource *res = &mem_resources[nid];268268+ unsigned long start, end;194269195270 WARN_ON(res->name); /* max one active range per node for now */196271272272+ start = start_pfn << PAGE_SHIFT;273273+ end = end_pfn << PAGE_SHIFT;274274+197275 res->name = "System RAM";198198- res->start = start_pfn << PAGE_SHIFT;199199- res->end = (end_pfn << PAGE_SHIFT) - 1;276276+ res->start = start;277277+ res->end = end - 1;200278 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;279279+201280 if (request_resource(&iomem_resource, res)) {202281 pr_err("unable to request memory_resource 0x%lx 0x%lx\n",203282 start_pfn, end_pfn);···218287 request_resource(res, &data_resource);219288 request_resource(res, &bss_resource);220289290290+ /*291291+ * Also make sure that there is a PMB mapping that covers this292292+ * range before we attempt to activate it, to avoid reset by MMU.293293+ * We can hit this path with NUMA or memory hot-add.294294+ */295295+ pmb_bolt_mapping((unsigned long)__va(start), start, end - start,296296+ PAGE_KERNEL);297297+221298 add_active_range(nid, start_pfn, end_pfn);222299}223300224224-void __init setup_bootmem_allocator(unsigned long free_pfn)225225-{226226- unsigned long bootmap_size;227227- unsigned long bootmap_pages, bootmem_paddr;228228- u64 total_pages = (lmb_end_of_DRAM() - __MEMORY_START) >> PAGE_SHIFT;229229- int i;230230-231231- bootmap_pages = bootmem_bootmap_pages(total_pages);232232-233233- bootmem_paddr = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);234234-235235- /*236236- * Find a proper area for the bootmem bitmap. After this237237- * bootstrap step all allocations (until the page allocator238238- * is intact) must be done via bootmem_alloc().239239- */240240- bootmap_size = init_bootmem_node(NODE_DATA(0),241241- bootmem_paddr >> PAGE_SHIFT,242242- min_low_pfn, max_low_pfn);243243-244244- /* Add active regions with valid PFNs. */245245- for (i = 0; i < lmb.memory.cnt; i++) {246246- unsigned long start_pfn, end_pfn;247247- start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;248248- end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);249249- __add_active_range(0, start_pfn, end_pfn);250250- }251251-252252- /*253253- * Add all physical memory to the bootmem map and mark each254254- * area as present.255255- */256256- register_bootmem_low_pages();257257-258258- /* Reserve the sections we're already using. */259259- for (i = 0; i < lmb.reserved.cnt; i++)260260- reserve_bootmem(lmb.reserved.region[i].base,261261- lmb_size_bytes(&lmb.reserved, i),262262- BOOTMEM_DEFAULT);263263-264264- node_set_online(0);265265-266266- sparse_memory_present_with_active_regions(0);267267-268268- check_for_initrd();269269-270270- reserve_crashkernel();271271-}272272-273273-#ifndef CONFIG_NEED_MULTIPLE_NODES274274-static void __init setup_memory(void)275275-{276276- unsigned long start_pfn;277277- u64 base = min_low_pfn << PAGE_SHIFT;278278- u64 size = (max_low_pfn << PAGE_SHIFT) - base;279279-280280- /*281281- * Partially used pages are not usable - thus282282- * we are rounding upwards:283283- */284284- start_pfn = PFN_UP(__pa(_end));285285-286286- lmb_add(base, size);287287-288288- /*289289- * Reserve the kernel text and290290- * Reserve the bootmem bitmap. We do this in two steps (first step291291- * was init_bootmem()), because this catches the (definitely buggy)292292- * case of us accidentally initializing the bootmem allocator with293293- * an invalid RAM area.294294- */295295- lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,296296- (PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -297297- (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));298298-299299- /*300300- * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.301301- */302302- if (CONFIG_ZERO_PAGE_OFFSET != 0)303303- lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);304304-305305- lmb_analyze();306306- lmb_dump_all();307307-308308- setup_bootmem_allocator(start_pfn);309309-}310310-#else311311-extern void __init setup_memory(void);312312-#endif313313-314314-void __init __attribute__ ((weak)) plat_early_device_setup(void)301301+void __init __weak plat_early_device_setup(void)315302{316303}317304···270421 bss_resource.start = virt_to_phys(__bss_start);271422 bss_resource.end = virt_to_phys(_ebss)-1;272423273273- memory_start = (unsigned long)__va(__MEMORY_START);274274- if (!memory_end)275275- memory_end = memory_start + __MEMORY_SIZE;276276-277424#ifdef CONFIG_CMDLINE_OVERWRITE278425 strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));279426#else···286441287442 parse_early_param();288443289289- uncached_init();290290-291444 plat_early_device_setup();445445+446446+ sh_mv_setup();292447293448 /* Let earlyprintk output early console messages */294449 early_platform_driver_probe("earlyprintk", 1, 1);295450296296- sh_mv_setup();297297-298298- /*299299- * Find the highest page frame number we have available300300- */301301- max_pfn = PFN_DOWN(__pa(memory_end));302302-303303- /*304304- * Determine low and high memory ranges:305305- */306306- max_low_pfn = max_pfn;307307- min_low_pfn = __MEMORY_START >> PAGE_SHIFT;308308-309309- nodes_clear(node_online_map);310310-311311- pmb_init();312312- lmb_init();313313- setup_memory();314314- sparse_init();451451+ paging_init();315452316453#ifdef CONFIG_DUMMY_CONSOLE317454 conswitchp = &dummy_con;318455#endif319319- paging_init();320320-321321- ioremap_fixed_init();322456323457 /* Perform the machine specific initialisation */324458 if (likely(sh_mv.mv_setup))
+169-4
arch/sh/mm/init.c
···22 * linux/arch/sh/mm/init.c33 *44 * Copyright (C) 1999 Niibe Yutaka55- * Copyright (C) 2002 - 2007 Paul Mundt55+ * Copyright (C) 2002 - 2010 Paul Mundt66 *77 * Based on linux/arch/i386/mm/init.c:88 * Copyright (C) 1995 Linus Torvalds···1616#include <linux/pagemap.h>1717#include <linux/percpu.h>1818#include <linux/io.h>1919+#include <linux/lmb.h>2020+#include <linux/kexec.h>1921#include <linux/dma-mapping.h>2022#include <asm/mmu_context.h>2323+#include <asm/mmzone.h>2124#include <asm/tlb.h>2225#include <asm/cacheflush.h>2326#include <asm/sections.h>2727+#include <asm/setup.h>2428#include <asm/cache.h>2529#include <asm/sizes.h>26302731DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);2832pgd_t swapper_pg_dir[PTRS_PER_PGD];3333+3434+void __init generic_mem_init(void)3535+{3636+ lmb_add(__MEMORY_START, __MEMORY_SIZE);3737+}3838+3939+void __init __weak plat_mem_setup(void)4040+{4141+ /* Nothing to see here, move along. */4242+}29433044#ifdef CONFIG_MMU3145static pte_t *__get_pte_phys(unsigned long addr)···166152}167153#endif /* CONFIG_MMU */168154169169-/*170170- * paging_init() sets up the page tables171171- */155155+void __init allocate_pgdat(unsigned int nid)156156+{157157+ unsigned long start_pfn, end_pfn;158158+#ifdef CONFIG_NEED_MULTIPLE_NODES159159+ unsigned long phys;160160+#endif161161+162162+ get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);163163+164164+#ifdef CONFIG_NEED_MULTIPLE_NODES165165+ phys = __lmb_alloc_base(sizeof(struct pglist_data),166166+ SMP_CACHE_BYTES, end_pfn << PAGE_SHIFT);167167+ /* Retry with all of system memory */168168+ if (!phys)169169+ phys = __lmb_alloc_base(sizeof(struct pglist_data),170170+ SMP_CACHE_BYTES, lmb_end_of_DRAM());171171+ if (!phys)172172+ panic("Can't allocate pgdat for node %d\n", nid);173173+174174+ NODE_DATA(nid) = __va(phys);175175+ memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));176176+177177+ NODE_DATA(nid)->bdata = &bootmem_node_data[nid];178178+#endif179179+180180+ NODE_DATA(nid)->node_start_pfn = start_pfn;181181+ NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;182182+}183183+184184+static void __init bootmem_init_one_node(unsigned int nid)185185+{186186+ unsigned long total_pages, paddr;187187+ unsigned long end_pfn;188188+ struct pglist_data *p;189189+ int i;190190+191191+ p = NODE_DATA(nid);192192+193193+ /* Nothing to do.. */194194+ if (!p->node_spanned_pages)195195+ return;196196+197197+ end_pfn = p->node_start_pfn + p->node_spanned_pages;198198+199199+ total_pages = bootmem_bootmap_pages(p->node_spanned_pages);200200+201201+ paddr = lmb_alloc(total_pages << PAGE_SHIFT, PAGE_SIZE);202202+ if (!paddr)203203+ panic("Can't allocate bootmap for nid[%d]\n", nid);204204+205205+ init_bootmem_node(p, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);206206+207207+ free_bootmem_with_active_regions(nid, end_pfn);208208+209209+ /*210210+ * XXX Handle initial reservations for the system memory node211211+ * only for the moment, we'll refactor this later for handling212212+ * reservations in other nodes.213213+ */214214+ if (nid == 0) {215215+ /* Reserve the sections we're already using. */216216+ for (i = 0; i < lmb.reserved.cnt; i++)217217+ reserve_bootmem(lmb.reserved.region[i].base,218218+ lmb_size_bytes(&lmb.reserved, i),219219+ BOOTMEM_DEFAULT);220220+ }221221+222222+ sparse_memory_present_with_active_regions(nid);223223+}224224+225225+static void __init do_init_bootmem(void)226226+{227227+ int i;228228+229229+ /* Add active regions with valid PFNs. */230230+ for (i = 0; i < lmb.memory.cnt; i++) {231231+ unsigned long start_pfn, end_pfn;232232+ start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;233233+ end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);234234+ __add_active_range(0, start_pfn, end_pfn);235235+ }236236+237237+ /* All of system RAM sits in node 0 for the non-NUMA case */238238+ allocate_pgdat(0);239239+ node_set_online(0);240240+241241+ plat_mem_setup();242242+243243+ for_each_online_node(i)244244+ bootmem_init_one_node(i);245245+246246+ sparse_init();247247+}248248+249249+static void __init early_reserve_mem(void)250250+{251251+ unsigned long start_pfn;252252+253253+ /*254254+ * Partially used pages are not usable - thus255255+ * we are rounding upwards:256256+ */257257+ start_pfn = PFN_UP(__pa(_end));258258+259259+ /*260260+ * Reserve the kernel text and Reserve the bootmem bitmap. We do261261+ * this in two steps (first step was init_bootmem()), because262262+ * this catches the (definitely buggy) case of us accidentally263263+ * initializing the bootmem allocator with an invalid RAM area.264264+ */265265+ lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,266266+ (PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -267267+ (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));268268+269269+ /*270270+ * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.271271+ */272272+ if (CONFIG_ZERO_PAGE_OFFSET != 0)273273+ lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);274274+275275+ /*276276+ * Handle additional early reservations277277+ */278278+ check_for_initrd();279279+ reserve_crashkernel();280280+}281281+172282void __init paging_init(void)173283{174284 unsigned long max_zone_pfns[MAX_NR_ZONES];175285 unsigned long vaddr, end;176286 int nid;287287+288288+ lmb_init();289289+290290+ sh_mv.mv_mem_init();291291+292292+ early_reserve_mem();293293+294294+ lmb_enforce_memory_limit(memory_limit);295295+ lmb_analyze();296296+297297+ lmb_dump_all();298298+299299+ /*300300+ * Determine low and high memory ranges:301301+ */302302+ max_low_pfn = max_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;303303+ min_low_pfn = __MEMORY_START >> PAGE_SHIFT;304304+305305+ nodes_clear(node_online_map);306306+307307+ memory_start = (unsigned long)__va(__MEMORY_START);308308+ memory_end = memory_start + (memory_limit ?: lmb_phys_mem_size());309309+310310+ uncached_init();311311+ pmb_init();312312+ do_init_bootmem();313313+ ioremap_fixed_init();177314178315 /* We don't need to map the kernel through the TLB, as179316 * it is permanatly mapped using P1. So clear the
+2
arch/sh/mm/pmb.c
···341341 unsigned long flags, pmb_flags;342342 int i, mapped;343343344344+ if (size < SZ_16M)345345+ return -EINVAL;344346 if (!pmb_addr_valid(vaddr, size))345347 return -EFAULT;346348 if (pmb_mapping_exists(vaddr, phys, size))