void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end) { unsigned long bootmap_pages; unsigned long start_pfn, end_pfn; unsigned long bootmem_paddr; /* Don't allow bogus node assignment */ BUG_ON(nid > MAX_NUMNODES || nid <= 0); start_pfn = start >> PAGE_SHIFT; end_pfn = end >> PAGE_SHIFT; pmb_bolt_mapping((unsigned long)__va(start), start, end - start, PAGE_KERNEL); lmb_add(start, end - start); __add_active_range(nid, start_pfn, end_pfn); /* Node-local pgdat */ NODE_DATA(nid) = __va(lmb_alloc_base(sizeof(struct pglist_data), SMP_CACHE_BYTES, end)); memset(NODE_DATA(nid), 0, sizeof(struct pglist_data)); NODE_DATA(nid)->bdata = &bootmem_node_data[nid]; NODE_DATA(nid)->node_start_pfn = start_pfn; NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; /* Node-local bootmap */ bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn); bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT, PAGE_SIZE, end); init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT, start_pfn, end_pfn); free_bootmem_with_active_regions(nid, end_pfn); /* Reserve the pgdat and bootmap space with the bootmem allocator */ reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT, sizeof(struct pglist_data), BOOTMEM_DEFAULT); reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr, bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT); /* It's up */ node_set_online(nid); /* Kick sparsemem */ sparse_memory_present_with_active_regions(nid); }
void __init allocate_pacas(void) { int nr_cpus, cpu, limit; /* * We can't take SLB misses on the paca, and we want to access them * in real mode, so allocate them within the RMA and also within * the first segment. On iSeries they must be within the area mapped * by the HV, which is HvPagesToMap * HVPAGESIZE bytes. */ limit = min(0x10000000ULL, lmb.rmo_size); if (firmware_has_feature(FW_FEATURE_ISERIES)) limit = min(limit, HvPagesToMap * HVPAGESIZE); nr_cpus = NR_CPUS; /* On iSeries we know we can never have more than 64 cpus */ if (firmware_has_feature(FW_FEATURE_ISERIES)) nr_cpus = min(64, nr_cpus); paca_size = PAGE_ALIGN(sizeof(struct paca_struct) * nr_cpus); paca = __va(lmb_alloc_base(paca_size, PAGE_SIZE, limit)); memset(paca, 0, paca_size); printk(KERN_DEBUG "Allocated %u bytes for %d pacas at %p\n", paca_size, nr_cpus, paca); /* Can't use for_each_*_cpu, as they aren't functional yet */ for (cpu = 0; cpu < nr_cpus; cpu++) initialise_paca(&paca[cpu], cpu); }
static void __init irqstack_early_init(void) { unsigned int i; /* * interrupt stacks must be under 256MB, we cannot afford to take * SLB misses on them. */ for_each_possible_cpu(i) { softirq_ctx[i] = (struct thread_info *) __va(lmb_alloc_base(THREAD_SIZE, THREAD_SIZE, 0x10000000)); hardirq_ctx[i] = (struct thread_info *) __va(lmb_alloc_base(THREAD_SIZE, THREAD_SIZE, 0x10000000)); } }
static void *early_alloc_pgtable(unsigned long size) { void *pt; if (init_bootmem_done) pt = __alloc_bootmem(size, size, __pa(MAX_DMA_ADDRESS)); else pt = __va(lmb_alloc_base(size, size, __pa(MAX_DMA_ADDRESS))); memset(pt, 0, size); return pt; }
/** * boot_get_kbd - allocate and initialize kernel copy of board info * @lmb: pointer to lmb handle, will be used for memory mgmt * @kbd: double pointer to board info data * * boot_get_kbd() allocates space for kernel copy of board info data below * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized * with the current u-boot board info data. * * returns: * 0 - success * -1 - failure */ int boot_get_kbd(struct lmb *lmb, bd_t **kbd) { *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, getenv_bootm_mapsize() + getenv_bootm_low()); if (*kbd == NULL) return -1; **kbd = *(gd->bd); debug("## kernel board info at 0x%08lx\n", (ulong)*kbd); #if defined(DEBUG) && defined(CONFIG_CMD_BDI) do_bdinfo(NULL, 0, 0, NULL); #endif return 0; }
/* * Call early during boot, before mem init or bootmem, to retrieve the RTAS * informations from the device-tree and allocate the RMO buffer for userland * accesses. */ void __init rtas_initialize(void) { unsigned long rtas_region = RTAS_INSTANTIATE_MAX; /* Get RTAS dev node and fill up our "rtas" structure with infos * about it. */ rtas.dev = of_find_node_by_name(NULL, "rtas"); if (rtas.dev) { const u32 *basep, *entryp, *sizep; basep = of_get_property(rtas.dev, "linux,rtas-base", NULL); sizep = of_get_property(rtas.dev, "rtas-size", NULL); if (basep != NULL && sizep != NULL) { rtas.base = *basep; rtas.size = *sizep; entryp = of_get_property(rtas.dev, "linux,rtas-entry", NULL); if (entryp == NULL) /* Ugh */ rtas.entry = rtas.base; else rtas.entry = *entryp; } else rtas.dev = NULL; } if (!rtas.dev) return; /* If RTAS was found, allocate the RMO buffer for it and look for * the stop-self token if any */ #ifdef CONFIG_PPC64 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR)) { rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX); ibm_suspend_me_token = rtas_token("ibm,suspend-me"); } #endif rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region); #ifdef CONFIG_RTAS_ERROR_LOGGING rtas_last_error_token = rtas_token("rtas-last-error"); #endif }
/* * Stack space used when we detect a bad kernel stack pointer, and * early in SMP boots before relocation is enabled. */ static void __init emergency_stack_init(void) { unsigned long limit; unsigned int i; /* * Emergency stacks must be under 256MB, we cannot afford to take * SLB misses on them. The ABI also requires them to be 128-byte * aligned. * * Since we use these as temporary stacks during secondary CPU * bringup, we need to get at them in real mode. This means they * must also be within the RMO region. */ limit = min(0x10000000UL, lmb.rmo_size); for_each_possible_cpu(i) paca[i].emergency_sp = __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE; }
/* * Call early during boot, before mem init or bootmem, to retreive the RTAS * informations from the device-tree and allocate the RMO buffer for userland * accesses. */ void __init rtas_initialize(void) { /* Get RTAS dev node and fill up our "rtas" structure with infos * about it. */ rtas.dev = of_find_node_by_name(NULL, "rtas"); if (rtas.dev) { u32 *basep, *entryp; u32 *sizep; basep = (u32 *)get_property(rtas.dev, "linux,rtas-base", NULL); sizep = (u32 *)get_property(rtas.dev, "rtas-size", NULL); if (basep != NULL && sizep != NULL) { rtas.base = *basep; rtas.size = *sizep; entryp = (u32 *)get_property(rtas.dev, "linux,rtas-entry", NULL); if (entryp == NULL) /* Ugh */ rtas.entry = rtas.base; else rtas.entry = *entryp; } else rtas.dev = NULL; } /* If RTAS was found, allocate the RMO buffer for it and look for * the stop-self token if any */ if (rtas.dev) { unsigned long rtas_region = RTAS_INSTANTIATE_MAX; if (systemcfg->platform == PLATFORM_PSERIES_LPAR) rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX); rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region); #ifdef CONFIG_HOTPLUG_CPU rtas_stop_self_args.token = rtas_token("stop-self"); #endif /* CONFIG_HOTPLUG_CPU */ } }
/** * boot_get_cmdline - allocate and initialize kernel cmdline * @lmb: pointer to lmb handle, will be used for memory mgmt * @cmd_start: pointer to a ulong variable, will hold cmdline start * @cmd_end: pointer to a ulong variable, will hold cmdline end * * boot_get_cmdline() allocates space for kernel command line below * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt * variable is present its contents is copied to allocated kernel * command line. * * returns: * 0 - success * -1 - failure */ int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end) { char *cmdline; char *s; cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf, getenv_bootm_mapsize() + getenv_bootm_low()); if (cmdline == NULL) return -1; if ((s = getenv("bootargs")) == NULL) s = ""; strcpy(cmdline, s); *cmd_start = (ulong) & cmdline[0]; *cmd_end = *cmd_start + strlen(cmdline); debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end); return 0; }
/** * boot_relocate_fdt - relocate flat device tree * @lmb: pointer to lmb handle, will be used for memory mgmt * @of_flat_tree: pointer to a char* variable, will hold fdt start address * @of_size: pointer to a ulong variable, will hold fdt length * * boot_relocate_fdt() allocates a region of memory within the bootmap and * relocates the of_flat_tree into that region, even if the fdt is already in * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD * bytes. * * of_flat_tree and of_size are set to final (after relocation) values * * returns: * 0 - success * 1 - failure */ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size) { void *fdt_blob = *of_flat_tree; void *of_start = NULL; char *fdt_high; ulong of_len = 0; int err; int disable_relocation = 0; /* nothing to do */ if (*of_size == 0) return 0; if (fdt_check_header(fdt_blob) != 0) { fdt_error("image is not a fdt"); goto error; } /* position on a 4K boundary before the alloc_current */ /* Pad the FDT by a specified amount */ of_len = *of_size + CONFIG_SYS_FDT_PAD; /* If fdt_high is set use it to select the relocation address */ fdt_high = getenv("fdt_high"); if (fdt_high) { void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16); if (((ulong) desired_addr) == ~0UL) { /* All ones means use fdt in place */ of_start = fdt_blob; lmb_reserve(lmb, (ulong)of_start, of_len); disable_relocation = 1; } else if (desired_addr) { of_start = (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000, (ulong)desired_addr); if (of_start == NULL) { puts("Failed using fdt_high value for Device Tree"); goto error; } } else { of_start = (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000); } } else { of_start = (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000, getenv_bootm_mapsize() + getenv_bootm_low()); } if (of_start == NULL) { puts("device tree - allocation error\n"); goto error; } if (disable_relocation) { /* * We assume there is space after the existing fdt to use * for padding */ fdt_set_totalsize(of_start, of_len); printf(" Using Device Tree in place at %p, end %p\n", of_start, of_start + of_len - 1); } else { debug("## device tree at %p ... %p (len=%ld [0x%lX])\n", fdt_blob, fdt_blob + *of_size - 1, of_len, of_len); printf(" Loading Device Tree to %p, end %p ... ", of_start, of_start + of_len - 1); err = fdt_open_into(fdt_blob, of_start, of_len); if (err != 0) { fdt_error("fdt move failed"); goto error; } puts("OK\n"); } *of_flat_tree = of_start; *of_size = of_len; set_working_fdt_addr((ulong)*of_flat_tree); return 0; error: return 1; }
/** * boot_ramdisk_high - relocate init ramdisk * @lmb: pointer to lmb handle, will be used for memory mgmt * @rd_data: ramdisk data start address * @rd_len: ramdisk data length * @initrd_start: pointer to a ulong variable, will hold final init ramdisk * start address (after possible relocation) * @initrd_end: pointer to a ulong variable, will hold final init ramdisk * end address (after possible relocation) * * boot_ramdisk_high() takes a relocation hint from "initrd_high" environment * variable and if requested ramdisk data is moved to a specified location. * * Initrd_start and initrd_end are set to final (after relocation) ramdisk * start/end addresses if ramdisk image start and len were provided, * otherwise set initrd_start and initrd_end set to zeros. * * returns: * 0 - success * -1 - failure */ int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, ulong *initrd_start, ulong *initrd_end) { char *s; ulong initrd_high; int initrd_copy_to_ram = 1; if ((s = getenv("initrd_high")) != NULL) { /* a value of "no" or a similar string will act like 0, * turning the "load high" feature off. This is intentional. */ initrd_high = simple_strtoul(s, NULL, 16); if (initrd_high == ~0) initrd_copy_to_ram = 0; } else { /* not set, no restrictions to load high */ initrd_high = ~0; } #ifdef CONFIG_LOGBUFFER /* Prevent initrd from overwriting logbuffer */ lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE); #endif debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n", initrd_high, initrd_copy_to_ram); if (rd_data) { if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ debug(" in-place initrd\n"); *initrd_start = rd_data; *initrd_end = rd_data + rd_len; lmb_reserve(lmb, rd_data, rd_len); } else { if (initrd_high) *initrd_start = (ulong)lmb_alloc_base(lmb, rd_len, 0x1000, initrd_high); else *initrd_start = (ulong)lmb_alloc(lmb, rd_len, 0x1000); if (*initrd_start == 0) { puts("ramdisk - allocation error\n"); goto error; } bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK); *initrd_end = *initrd_start + rd_len; printf(" Loading Ramdisk to %08lx, end %08lx ... ", *initrd_start, *initrd_end); memmove_wd((void *)*initrd_start, (void *)rd_data, rd_len, CHUNKSZ); #ifdef CONFIG_MP /* * Ensure the image is flushed to memory to handle * AMP boot scenarios in which we might not be * HW cache coherent */ flush_cache((unsigned long)*initrd_start, rd_len); #endif puts("OK\n"); } } else { *initrd_start = 0; *initrd_end = 0; } debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", *initrd_start, *initrd_end); return 0; error: return -1; }
phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align) { return lmb_alloc_base(lmb, size, align, LMB_ALLOC_ANYWHERE); }
u64 lmb_alloc(u64 size, u64 align) { return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE); }
unsigned long __init lmb_alloc(unsigned long size, unsigned long align) { return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE); }
void __init do_init_bootmem(void) { int nid; min_low_pfn = 0; max_low_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT; if (parse_numa_properties()) setup_nonnuma(); for (nid = 0; nid < numnodes; nid++) { unsigned long start_paddr, end_paddr; int i; unsigned long bootmem_paddr; unsigned long bootmap_pages; if (node_data[nid].node_spanned_pages == 0) continue; start_paddr = node_data[nid].node_start_pfn * PAGE_SIZE; end_paddr = start_paddr + (node_data[nid].node_spanned_pages * PAGE_SIZE); dbg("node %d\n", nid); dbg("start_paddr = %lx\n", start_paddr); dbg("end_paddr = %lx\n", end_paddr); NODE_DATA(nid)->bdata = &plat_node_bdata[nid]; bootmap_pages = bootmem_bootmap_pages((end_paddr - start_paddr) >> PAGE_SHIFT); dbg("bootmap_pages = %lx\n", bootmap_pages); bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT, PAGE_SIZE, end_paddr); dbg("bootmap_paddr = %lx\n", bootmem_paddr); init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT, start_paddr >> PAGE_SHIFT, end_paddr >> PAGE_SHIFT); for (i = 0; i < lmb.memory.cnt; i++) { unsigned long physbase, size; unsigned long type = lmb.memory.region[i].type; if (type != LMB_MEMORY_AREA) continue; physbase = lmb.memory.region[i].physbase; size = lmb.memory.region[i].size; if (physbase < end_paddr && (physbase+size) > start_paddr) { /* overlaps */ if (physbase < start_paddr) { size -= start_paddr - physbase; physbase = start_paddr; } if (size > end_paddr - start_paddr) size = end_paddr - start_paddr; dbg("free_bootmem %lx %lx\n", physbase, size); free_bootmem_node(NODE_DATA(nid), physbase, size); } } for (i = 0; i < lmb.reserved.cnt; i++) { unsigned long physbase = lmb.reserved.region[i].physbase; unsigned long size = lmb.reserved.region[i].size; if (physbase < end_paddr && (physbase+size) > start_paddr) { /* overlaps */ if (physbase < start_paddr) { size -= start_paddr - physbase; physbase = start_paddr; } if (size > end_paddr - start_paddr) size = end_paddr - start_paddr; dbg("reserve_bootmem %lx %lx\n", physbase, size); reserve_bootmem_node(NODE_DATA(nid), physbase, size); } } } }