15 #include <linux/sched.h>
16 #include <linux/kernel.h>
19 #include <linux/module.h>
24 #include <linux/kexec.h>
25 #include <linux/pci.h>
31 #include <linux/timex.h>
34 #include <asm/setup.h>
35 #include <asm/sections.h>
36 #include <asm/cacheflush.h>
37 #include <asm/pgalloc.h>
38 #include <asm/mmu_context.h>
44 #define setup_max_cpus 1
47 static inline int ABS(
int x) {
return x >= 0 ? x : -
x; }
85 static unsigned long __initdata mappable_physpages;
113 #if defined(CONFIG_PCI) && !defined(__tilegx__)
114 enum { DEFAULT_PCI_RESERVE_MB = 64 };
115 static unsigned int __initdata pci_reserve_mb = DEFAULT_PCI_RESERVE_MB;
116 unsigned long __initdata pci_reserve_start_pfn = -1
U;
117 unsigned long __initdata pci_reserve_end_pfn = -1
U;
120 static int __init setup_maxmem(
char *
str)
122 unsigned long long maxmem;
127 pr_info(
"Forcing RAM used to no more than %dMB\n",
133 static int __init setup_maxnodemem(
char *str)
136 unsigned long long maxnodemem;
146 pr_info(
"Forcing RAM used on node %ld to no more than %dMB\n",
147 node, maxnodemem_pfn[node] >> (20 -
PAGE_SHIFT));
152 static int __init setup_isolnodes(
char *str)
159 pr_info(
"Set isolnodes value to '%s'\n", buf);
164 #if defined(CONFIG_PCI) && !defined(__tilegx__)
165 static int __init setup_pci_reserve(
char* str)
174 pr_info(
"Reserving %dMB for PCIE root complex mappings\n",
186 static int __init parse_vmalloc(
char *
arg)
195 early_panic(
"\"vmalloc=%#lx\" value too large: maximum %#lx\n",
203 #ifdef CONFIG_HIGHMEM
222 static void *
__init setup_pa_va_mapping(
void)
224 unsigned long curr_pages = 0;
229 memset(pbase_map, -1,
sizeof(pbase_map));
230 memset(vbase_map, -1,
sizeof(vbase_map));
236 mappable_physpages = 0;
239 mappable_physpages +=
247 unsigned long vaddr_end;
251 node_lowmem_end_pfn[
i] =
start;
264 for (j = 0; vaddr < vaddr_end; vaddr +=
HPAGE_SIZE, ++
j) {
265 unsigned long this_pfn =
274 BUG_ON(node_lowmem_end_pfn[i] > end);
278 return (
void *)
vaddr;
288 static void __cpuinit store_permanent_mappings(
void)
294 #ifdef CONFIG_HIGHMEM
306 (
uint32_t)(_einittext - _stext), 0);
318 #ifdef CONFIG_HIGHMEM
324 #if defined(CONFIG_HIGHMEM) || defined(__tilegx__)
337 #ifdef CONFIG_FLATMEM
339 pr_err(
"Can't use discontiguous PAs: %#llx..%#llx\n",
345 if ((
unsigned long)range.
start) {
346 pr_err(
"Range not at 4GB multiple: %#llx..%#llx\n",
353 unsigned long long start_pa = range.
start;
354 unsigned long long orig_size = range.
size;
358 pr_err(
"Range not hugepage-aligned: %#llx..%#llx:"
359 " now %#llx-%#llx\n",
360 start_pa, start_pa + orig_size,
365 pr_err(
"PA high bits too high: %#llx..%#llx\n",
369 if (highbits_seen[highbits]) {
370 pr_err(
"Range overlaps in high bits: %#llx..%#llx\n",
374 highbits_seen[highbits] = 1;
378 pr_err(
"Maxnodemem reduced node %d to"
379 " %d pages\n", i, max_size);
382 pr_err(
"Maxnodemem disabled node %d\n", i);
389 pr_err(
"Maxmem reduced node %d to %d pages\n",
393 pr_err(
"Maxmem disabled node %d\n", i);
398 pr_err(
"Too many PA nodes (#%d): %#llx...%#llx\n",
410 pr_err(
"PAs too high to represent: %#llx..%#llx\n",
415 #if defined(CONFIG_PCI) && !defined(__tilegx__)
423 if (start <= pci_reserve_start_pfn &&
424 end > pci_reserve_start_pfn) {
427 unsigned int percpu_pages =
429 if (end < pci_reserve_end_pfn + percpu_pages) {
430 end = pci_reserve_start_pfn;
431 pr_err(
"PCI mapping region reduced node %d to"
432 " %ld pages\n", i, end - start);
439 highbits_to_node[j] = i;
441 node_start_pfn[
i] =
start;
444 num_physpages +=
size;
462 cap = 8 * 1024 * 1024;
463 if (num_physpages > cap) {
466 unsigned long dropped_pages = 0;
469 if (size > cap_each) {
470 dropped_pages += (size - cap_each);
474 num_physpages -= dropped_pages;
476 " ignoring %ldMB.\n",
479 pr_warning(
"Consider using a larger page size.\n");
486 #ifdef CONFIG_HIGHMEM
493 lowmem_pages = (mappable_physpages >
MAXMEM_PFN) ?
495 highmem_pages = (
long) (num_physpages - lowmem_pages);
498 pages_to_mb(highmem_pages > 0 ? highmem_pages : 0));
509 pr_warning(
"Use a HIGHMEM enabled kernel.\n");
519 node_start_pfn[
i] = 0;
527 lowmem_pages +=
pages;
545 static inline int node_has_bootmem(
int nid)
554 static inline unsigned long alloc_bootmem_pfn(
int nid,
560 unsigned long pfn = kaddr_to_pfn(kva);
565 static void __init setup_bootmem_allocator_node(
int i)
567 unsigned long start,
end, mapsize, mapstart;
569 if (node_has_bootmem(i)) {
578 start = (i == 0) ?
min_low_pfn : node_start_pfn[i];
581 #ifdef CONFIG_HIGHMEM
582 end = node_lowmem_end_pfn[
i];
599 mapstart = alloc_bootmem_pfn(0,
PFN_PHYS(mapsize), 0);
608 #if defined(CONFIG_PCI) && !defined(__tilegx__)
612 if (pci_reserve_start_pfn < end && pci_reserve_end_pfn > start)
615 pci_reserve_start_pfn),
620 static void __init setup_bootmem_allocator(
void)
624 setup_bootmem_allocator_node(i);
641 static int __init percpu_size(
void)
657 unsigned long zones_size[MAX_NR_ZONES] = { 0 };
658 int size = percpu_size();
660 const unsigned long dma_end = (1
UL << (32 -
PAGE_SHIFT));
664 for (i = 0; i < num_cpus; ++
i)
668 unsigned long start = node_start_pfn[
i];
670 #ifdef CONFIG_HIGHMEM
671 unsigned long lowmem_end = node_lowmem_end_pfn[
i];
673 unsigned long lowmem_end =
end;
675 int memmap_size = (end -
start) *
sizeof(
struct page);
696 alloc_bootmem_pfn(0, memmap_size, 0);
697 BUG_ON(node_percpu[i] != 0);
698 }
else if (node_has_bootmem(start)) {
699 unsigned long goal = 0;
701 alloc_bootmem_pfn(i, memmap_size, 0);
703 goal =
PFN_PHYS(lowmem_end) - node_percpu[
i];
706 alloc_bootmem_pfn(i, node_percpu[i],
717 lowmem_end -
PFN_UP(node_percpu[i]);
721 #ifdef CONFIG_HIGHMEM
722 if (start > lowmem_end) {
724 zones_size[ZONE_HIGHMEM] = end -
start;
727 zones_size[ZONE_HIGHMEM] = end - lowmem_end;
733 if (start < dma_end) {
738 zones_size[ZONE_DMA] = 0;
750 if (zones_size[
ZONE_NORMAL] || zones_size[ZONE_DMA])
752 #ifdef CONFIG_HIGHMEM
764 struct cpumask node_2_cpu_mask[MAX_NUMNODES] __write_once;
781 static int __init node_neighbors(
int node,
int cpu,
789 if (x > 0 && cpu_to_bound_node(cpu-1, unbound_cpus) == node)
791 if (x < w-1 && cpu_to_bound_node(cpu+1, unbound_cpus) == node)
793 if (y > 0 && cpu_to_bound_node(cpu-w, unbound_cpus) == node)
795 if (y < h-1 && cpu_to_bound_node(cpu+w, unbound_cpus) == node)
809 cpumask_clear(&unbound_cpus);
815 pr_err(
"Forcing NUMA node zero available as a default node\n");
820 memset(distance, -1,
sizeof(distance));
823 for (coord.
x = 0; coord.
x < smp_width;
825 BUG_ON(cpu >= nr_cpu_ids);
827 cpu_2_node[
cpu] = -1;
837 cpumask_set_cpu(cpu, &unbound_cpus);
851 while (!cpumask_empty(&unbound_cpus)) {
854 for (cpu = 0; cpu <
cpus; ++
cpu) {
868 d -= distance[
i][
cpu];
871 d -= node_neighbors(node, cpu, &unbound_cpus);
872 if (d < best_distance) {
879 cpumask_set_cpu(best_cpu, &node_2_cpu_mask[node]);
880 cpu_2_node[best_cpu] =
node;
881 cpumask_clear_cpu(best_cpu, &unbound_cpus);
883 if (node == MAX_NUMNODES)
903 static struct cpu cpu_devices[
NR_CPUS];
905 static int __init topology_init(
void)
912 for (i = 0; i < smp_height * smp_width; ++i)
922 #define setup_numa_mapping() do { } while (0)
933 static __cpuinit void init_super_pages(
void)
935 #ifdef CONFIG_HUGETLB_SUPER_PAGES
937 for (i = 0; i < HUGE_SHIFT_ENTRIES; ++
i)
952 store_permanent_mappings();
955 #if CHIP_HAS_TILE_DMA()
959 #if CHIP_HAS_SN_PROC()
976 #if CHIP_HAS_SN_PROC()
992 #ifdef CONFIG_HARDWALL
1000 #ifdef CONFIG_BLK_DEV_INITRD
1010 static char __initdata initramfs_file[128] =
"initramfs.cpio.gz";
1012 static int __init setup_initramfs_file(
char *str)
1016 strncpy(initramfs_file, str,
sizeof(initramfs_file) - 1);
1017 set_initramfs_file = 1;
1021 early_param(
"initramfs_file", setup_initramfs_file);
1028 static void __init load_hv_initrd(
void)
1036 if (set_initramfs_file)
1037 pr_warning(
"No such hvfs initramfs file '%s'\n",
1045 pr_warning(
"Ignoring hvfs file '%s': it's a directory.\n",
1051 if (rc != stat.
size) {
1052 pr_err(
"Error reading %d bytes from hvfs file '%s': %d\n",
1053 stat.
size, initramfs_file, rc);
1067 static inline void load_hv_initrd(
void) {}
1070 static void __init validate_hv(
void)
1084 if (topology.
width != 1 || topology.
height != 1) {
1085 pr_warning(
"Warning: booting UP kernel on %dx%d grid;"
1086 " will ignore all but first tile.\n",
1092 early_panic(
"Hypervisor glue size %ld is too big!\n",
1095 early_panic(
"Hypervisor page size %#x != our %#lx\n",
1098 early_panic(
"Hypervisor huge page size %#x != our %#lx\n",
1107 if ((smp_height * smp_width) > nr_cpu_ids)
1108 early_panic(
"Hypervisor %d x %d grid too big for Linux"
1109 " NR_CPUS %d\n", smp_height, smp_width,
1122 sizeof(chip_model)) < 0) {
1123 pr_err(
"Warning: HV_CONFSTR_CHIP_MODEL not available\n");
1124 strlcpy(chip_model,
"unknown",
sizeof(chip_model));
1128 static void __init validate_va(
void)
1138 int i, user_kernel_ok = 0;
1139 unsigned long max_va = 0;
1140 unsigned long list_va =
1143 for (i = 0; ; ++
i) {
1145 if (range.
size == 0)
1150 if (range.
start == 0)
1151 max_va = range.
size;
1154 if (!user_kernel_ok)
1155 early_panic(
"Hypervisor not configured for user/kernel VAs\n");
1157 early_panic(
"Hypervisor not configured for low VAs\n");
1159 early_panic(
"Hypervisor max VA %#lx smaller than %#lx\n",
1165 "Linux VMALLOC region below the 2GB line (%#lx)!\n"
1166 "Reconfigure the kernel with fewer NR_HUGE_VMAPS\n"
1167 "or smaller VMALLOC_RESERVE.\n",
1182 #if CHIP_HAS_CBOX_HOME_MAP()
1190 struct cpumask hash_for_home_map;
1208 static int __init disabled_cpus(
char *str)
1215 pr_err(
"disabled_cpus: can't disable boot cpu %d\n", boot_cpu);
1216 cpumask_clear_cpu(boot_cpu, &disabled_map);
1225 if (!cpumask_empty(&disabled_map)) {
1227 cpulist_scnprintf(buf,
sizeof(buf), &disabled_map);
1228 pr_info(
"CPUs not available for Linux: %s\n", buf);
1232 static void __init setup_cpu_maps(
void)
1234 struct cpumask hv_disabled_map, cpu_possible_init;
1243 early_panic(
"hv_inquire_tiles(AVAIL) failed: rc %d\n", rc);
1245 early_panic(
"Boot CPU %d disabled by hypervisor!\n", boot_cpu);
1248 cpumask_complement(&hv_disabled_map, &cpu_possible_init);
1251 cpumask_or(&disabled_map, &disabled_map, &hv_disabled_map);
1259 cpumask_set_cpu(boot_cpu, &disabled_map);
1264 cpumask_set_cpu(i, &disabled_map);
1265 cpumask_clear_cpu(boot_cpu, &disabled_map);
1266 for (i = smp_height * smp_width; i <
NR_CPUS; ++
i)
1267 cpumask_clear_cpu(i, &disabled_map);
1273 cpumask_andnot(&cpu_possible_init, &cpu_possible_init, &disabled_map);
1281 pr_err(
"warning: no HV_INQ_TILES_LOTAR; using AVAIL\n");
1285 #if CHIP_HAS_CBOX_HOME_MAP()
1289 sizeof(hash_for_home_map));
1291 early_panic(
"hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc);
1299 static int __init dataplane(
char *str)
1301 pr_warning(
"WARNING: dataplane support disabled in this kernel\n");
1307 #ifdef CONFIG_CMDLINE_BOOL
1315 #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
1318 if (boot_command_line[0])
1319 pr_warning(
"WARNING: ignoring dynamic command line \"%s\"\n",
1324 #if defined(CONFIG_CMDLINE_BOOL)
1325 if (builtin_cmdline[0]) {
1326 int builtin_len =
strlcpy(boot_command_line, builtin_cmdline,
1329 boot_command_line[builtin_len++] =
' ';
1330 hv_cmdline = &boot_command_line[builtin_len];
1340 early_panic(
"hv_get_command_line failed: %d\n", len);
1355 #if defined(CONFIG_PCI) && !defined(__tilegx__)
1365 pci_reserve_end_pfn = (1 << (32 -
PAGE_SHIFT));
1366 pci_reserve_start_pfn = pci_reserve_end_pfn -
1376 store_permanent_mappings();
1377 setup_bootmem_allocator();
1384 #ifdef CONFIG_SWIOTLB
1412 static void *
__init pcpu_fc_alloc(
unsigned int cpu,
size_t size,
size_t align)
1419 BUG_ON(node_percpu[nid] < size);
1420 node_percpu[nid] -=
size;
1421 if (percpu_pfn[cpu] == 0)
1422 percpu_pfn[
cpu] = pfn;
1430 static void __init pcpu_fc_free(
void *
ptr,
size_t size)
1437 static void __init pcpu_fc_populate_pte(
unsigned long addr)
1444 BUG_ON(pgd_addr_invalid(addr));
1446 panic(
"PCPU addr %#lx outside vmalloc range %#lx..%#lx;"
1447 " try increasing CONFIG_VMALLOC_RESERVE\n",
1466 unsigned long delta, pfn, lowmem_va;
1467 unsigned long size = percpu_size();
1472 pcpu_fc_free, pcpu_fc_populate_pte);
1474 panic(
"Cannot initialize percpu area (err=%d)", rc);
1482 __finv_buffer(ptr, size);
1483 pfn = percpu_pfn[
cpu];
1490 unsigned long addr = (
unsigned long)ptr + i;
1503 " at %#lx\n", lowmem_va);
1523 static struct resource data_resource = {
1524 .name =
"Kernel data",
1530 static struct resource code_resource = {
1531 .name =
"Kernel code",
1541 #if defined(CONFIG_PCI) && !defined(__tilegx__)
1543 insert_non_bus_resource(
void)
1547 res->
name =
"Non-Bus Physical Address Space";
1548 res->
start = (1ULL << 32);
1560 insert_ram_resource(
u64 start_pfn,
u64 end_pfn)
1564 res->
name =
"System RAM";
1581 static int __init request_standard_resources(
void)
1586 #if defined(CONFIG_PCI) && !defined(__tilegx__)
1587 insert_non_bus_resource();
1591 u64 start_pfn = node_start_pfn[
i];
1594 #if defined(CONFIG_PCI) && !defined(__tilegx__)
1595 if (start_pfn <= pci_reserve_start_pfn &&
1596 end_pfn > pci_reserve_start_pfn) {
1597 if (end_pfn > pci_reserve_end_pfn)
1598 insert_ram_resource(pci_reserve_end_pfn,
1600 end_pfn = pci_reserve_start_pfn;
1603 insert_ram_resource(start_pfn, end_pfn);
1606 code_resource.
start =
__pa(_text - CODE_DELTA);
1607 code_resource.
end =
__pa(_etext - CODE_DELTA)-1;
1609 data_resource.
end =
__pa(_end)-1;