setup.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mmzone.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/module.h>
  19. #include <linux/node.h>
  20. #include <linux/cpu.h>
  21. #include <linux/ioport.h>
  22. #include <linux/irq.h>
  23. #include <linux/kexec.h>
  24. #include <linux/pci.h>
  25. #include <linux/swiotlb.h>
  26. #include <linux/initrd.h>
  27. #include <linux/io.h>
  28. #include <linux/highmem.h>
  29. #include <linux/smp.h>
  30. #include <linux/timex.h>
  31. #include <linux/hugetlb.h>
  32. #include <linux/start_kernel.h>
  33. #include <linux/screen_info.h>
  34. #include <linux/tick.h>
  35. #include <asm/setup.h>
  36. #include <asm/sections.h>
  37. #include <asm/cacheflush.h>
  38. #include <asm/pgalloc.h>
  39. #include <asm/mmu_context.h>
  40. #include <hv/hypervisor.h>
  41. #include <arch/interrupts.h>
  42. /* <linux/smp.h> doesn't provide this definition. */
  43. #ifndef CONFIG_SMP
  44. #define setup_max_cpus 1
  45. #endif
  46. static inline int ABS(int x) { return x >= 0 ? x : -x; }
  47. /* Chip information */
  48. char chip_model[64] __write_once;
  49. #ifdef CONFIG_VT
  50. struct screen_info screen_info;
  51. #endif
  52. struct pglist_data node_data[MAX_NUMNODES] __read_mostly;
  53. EXPORT_SYMBOL(node_data);
  54. /* Information on the NUMA nodes that we compute early */
  55. unsigned long node_start_pfn[MAX_NUMNODES];
  56. unsigned long node_end_pfn[MAX_NUMNODES];
  57. unsigned long __initdata node_memmap_pfn[MAX_NUMNODES];
  58. unsigned long __initdata node_percpu_pfn[MAX_NUMNODES];
  59. unsigned long __initdata node_free_pfn[MAX_NUMNODES];
  60. static unsigned long __initdata node_percpu[MAX_NUMNODES];
  61. /*
  62. * per-CPU stack and boot info.
  63. */
  64. DEFINE_PER_CPU(unsigned long, boot_sp) =
  65. (unsigned long)init_stack + THREAD_SIZE - STACK_TOP_DELTA;
  66. #ifdef CONFIG_SMP
  67. DEFINE_PER_CPU(unsigned long, boot_pc) = (unsigned long)start_kernel;
  68. #else
  69. /*
  70. * The variable must be __initdata since it references __init code.
  71. * With CONFIG_SMP it is per-cpu data, which is exempt from validation.
  72. */
  73. unsigned long __initdata boot_pc = (unsigned long)start_kernel;
  74. #endif
  75. #ifdef CONFIG_HIGHMEM
  76. /* Page frame index of end of lowmem on each controller. */
  77. unsigned long node_lowmem_end_pfn[MAX_NUMNODES];
  78. /* Number of pages that can be mapped into lowmem. */
  79. static unsigned long __initdata mappable_physpages;
  80. #endif
  81. /* Data on which physical memory controller corresponds to which NUMA node */
  82. int node_controller[MAX_NUMNODES] = { [0 ... MAX_NUMNODES-1] = -1 };
  83. #ifdef CONFIG_HIGHMEM
  84. /* Map information from VAs to PAs */
  85. unsigned long pbase_map[1 << (32 - HPAGE_SHIFT)]
  86. __write_once __attribute__((aligned(L2_CACHE_BYTES)));
  87. EXPORT_SYMBOL(pbase_map);
  88. /* Map information from PAs to VAs */
  89. void *vbase_map[NR_PA_HIGHBIT_VALUES]
  90. __write_once __attribute__((aligned(L2_CACHE_BYTES)));
  91. EXPORT_SYMBOL(vbase_map);
  92. #endif
  93. /* Node number as a function of the high PA bits */
  94. int highbits_to_node[NR_PA_HIGHBIT_VALUES] __write_once;
  95. EXPORT_SYMBOL(highbits_to_node);
  96. static unsigned int __initdata maxmem_pfn = -1U;
  97. static unsigned int __initdata maxnodemem_pfn[MAX_NUMNODES] = {
  98. [0 ... MAX_NUMNODES-1] = -1U
  99. };
  100. static nodemask_t __initdata isolnodes;
  101. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  102. enum { DEFAULT_PCI_RESERVE_MB = 64 };
  103. static unsigned int __initdata pci_reserve_mb = DEFAULT_PCI_RESERVE_MB;
  104. unsigned long __initdata pci_reserve_start_pfn = -1U;
  105. unsigned long __initdata pci_reserve_end_pfn = -1U;
  106. #endif
  107. static int __init setup_maxmem(char *str)
  108. {
  109. unsigned long long maxmem;
  110. if (str == NULL || (maxmem = memparse(str, NULL)) == 0)
  111. return -EINVAL;
  112. maxmem_pfn = (maxmem >> HPAGE_SHIFT) << (HPAGE_SHIFT - PAGE_SHIFT);
  113. pr_info("Forcing RAM used to no more than %dMB\n",
  114. maxmem_pfn >> (20 - PAGE_SHIFT));
  115. return 0;
  116. }
  117. early_param("maxmem", setup_maxmem);
  118. static int __init setup_maxnodemem(char *str)
  119. {
  120. char *endp;
  121. unsigned long long maxnodemem;
  122. long node;
  123. node = str ? simple_strtoul(str, &endp, 0) : INT_MAX;
  124. if (node >= MAX_NUMNODES || *endp != ':')
  125. return -EINVAL;
  126. maxnodemem = memparse(endp+1, NULL);
  127. maxnodemem_pfn[node] = (maxnodemem >> HPAGE_SHIFT) <<
  128. (HPAGE_SHIFT - PAGE_SHIFT);
  129. pr_info("Forcing RAM used on node %ld to no more than %dMB\n",
  130. node, maxnodemem_pfn[node] >> (20 - PAGE_SHIFT));
  131. return 0;
  132. }
  133. early_param("maxnodemem", setup_maxnodemem);
  134. struct memmap_entry {
  135. u64 addr; /* start of memory segment */
  136. u64 size; /* size of memory segment */
  137. };
  138. static struct memmap_entry memmap_map[64];
  139. static int memmap_nr;
  140. static void add_memmap_region(u64 addr, u64 size)
  141. {
  142. if (memmap_nr >= ARRAY_SIZE(memmap_map)) {
  143. pr_err("Ooops! Too many entries in the memory map!\n");
  144. return;
  145. }
  146. memmap_map[memmap_nr].addr = addr;
  147. memmap_map[memmap_nr].size = size;
  148. memmap_nr++;
  149. }
  150. static int __init setup_memmap(char *p)
  151. {
  152. char *oldp;
  153. u64 start_at, mem_size;
  154. if (!p)
  155. return -EINVAL;
  156. if (!strncmp(p, "exactmap", 8)) {
  157. pr_err("\"memmap=exactmap\" not valid on tile\n");
  158. return 0;
  159. }
  160. oldp = p;
  161. mem_size = memparse(p, &p);
  162. if (p == oldp)
  163. return -EINVAL;
  164. if (*p == '@') {
  165. pr_err("\"memmap=nn@ss\" (force RAM) invalid on tile\n");
  166. } else if (*p == '#') {
  167. pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on tile\n");
  168. } else if (*p == '$') {
  169. start_at = memparse(p+1, &p);
  170. add_memmap_region(start_at, mem_size);
  171. } else {
  172. if (mem_size == 0)
  173. return -EINVAL;
  174. maxmem_pfn = (mem_size >> HPAGE_SHIFT) <<
  175. (HPAGE_SHIFT - PAGE_SHIFT);
  176. }
  177. return *p == '\0' ? 0 : -EINVAL;
  178. }
  179. early_param("memmap", setup_memmap);
  180. static int __init setup_mem(char *str)
  181. {
  182. return setup_maxmem(str);
  183. }
  184. early_param("mem", setup_mem); /* compatibility with x86 */
  185. static int __init setup_isolnodes(char *str)
  186. {
  187. if (str == NULL || nodelist_parse(str, isolnodes) != 0)
  188. return -EINVAL;
  189. pr_info("Set isolnodes value to '%*pbl'\n",
  190. nodemask_pr_args(&isolnodes));
  191. return 0;
  192. }
  193. early_param("isolnodes", setup_isolnodes);
  194. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  195. static int __init setup_pci_reserve(char* str)
  196. {
  197. if (str == NULL || kstrtouint(str, 0, &pci_reserve_mb) != 0 ||
  198. pci_reserve_mb > 3 * 1024)
  199. return -EINVAL;
  200. pr_info("Reserving %dMB for PCIE root complex mappings\n",
  201. pci_reserve_mb);
  202. return 0;
  203. }
  204. early_param("pci_reserve", setup_pci_reserve);
  205. #endif
  206. #ifndef __tilegx__
  207. /*
  208. * vmalloc=size forces the vmalloc area to be exactly 'size' bytes.
  209. * This can be used to increase (or decrease) the vmalloc area.
  210. */
  211. static int __init parse_vmalloc(char *arg)
  212. {
  213. if (!arg)
  214. return -EINVAL;
  215. VMALLOC_RESERVE = (memparse(arg, &arg) + PGDIR_SIZE - 1) & PGDIR_MASK;
  216. /* See validate_va() for more on this test. */
  217. if ((long)_VMALLOC_START >= 0)
  218. early_panic("\"vmalloc=%#lx\" value too large: maximum %#lx\n",
  219. VMALLOC_RESERVE, _VMALLOC_END - 0x80000000UL);
  220. return 0;
  221. }
  222. early_param("vmalloc", parse_vmalloc);
  223. #endif
  224. #ifdef CONFIG_HIGHMEM
  225. /*
  226. * Determine for each controller where its lowmem is mapped and how much of
  227. * it is mapped there. On controller zero, the first few megabytes are
  228. * already mapped in as code at MEM_SV_START, so in principle we could
  229. * start our data mappings higher up, but for now we don't bother, to avoid
  230. * additional confusion.
  231. *
  232. * One question is whether, on systems with more than 768 Mb and
  233. * controllers of different sizes, to map in a proportionate amount of
  234. * each one, or to try to map the same amount from each controller.
  235. * (E.g. if we have three controllers with 256MB, 1GB, and 256MB
  236. * respectively, do we map 256MB from each, or do we map 128 MB, 512
  237. * MB, and 128 MB respectively?) For now we use a proportionate
  238. * solution like the latter.
  239. *
  240. * The VA/PA mapping demands that we align our decisions at 16 MB
  241. * boundaries so that we can rapidly convert VA to PA.
  242. */
  243. static void *__init setup_pa_va_mapping(void)
  244. {
  245. unsigned long curr_pages = 0;
  246. unsigned long vaddr = PAGE_OFFSET;
  247. nodemask_t highonlynodes = isolnodes;
  248. int i, j;
  249. memset(pbase_map, -1, sizeof(pbase_map));
  250. memset(vbase_map, -1, sizeof(vbase_map));
  251. /* Node zero cannot be isolated for LOWMEM purposes. */
  252. node_clear(0, highonlynodes);
  253. /* Count up the number of pages on non-highonlynodes controllers. */
  254. mappable_physpages = 0;
  255. for_each_online_node(i) {
  256. if (!node_isset(i, highonlynodes))
  257. mappable_physpages +=
  258. node_end_pfn[i] - node_start_pfn[i];
  259. }
  260. for_each_online_node(i) {
  261. unsigned long start = node_start_pfn[i];
  262. unsigned long end = node_end_pfn[i];
  263. unsigned long size = end - start;
  264. unsigned long vaddr_end;
  265. if (node_isset(i, highonlynodes)) {
  266. /* Mark this controller as having no lowmem. */
  267. node_lowmem_end_pfn[i] = start;
  268. continue;
  269. }
  270. curr_pages += size;
  271. if (mappable_physpages > MAXMEM_PFN) {
  272. vaddr_end = PAGE_OFFSET +
  273. (((u64)curr_pages * MAXMEM_PFN /
  274. mappable_physpages)
  275. << PAGE_SHIFT);
  276. } else {
  277. vaddr_end = PAGE_OFFSET + (curr_pages << PAGE_SHIFT);
  278. }
  279. for (j = 0; vaddr < vaddr_end; vaddr += HPAGE_SIZE, ++j) {
  280. unsigned long this_pfn =
  281. start + (j << HUGETLB_PAGE_ORDER);
  282. pbase_map[vaddr >> HPAGE_SHIFT] = this_pfn;
  283. if (vbase_map[__pfn_to_highbits(this_pfn)] ==
  284. (void *)-1)
  285. vbase_map[__pfn_to_highbits(this_pfn)] =
  286. (void *)(vaddr & HPAGE_MASK);
  287. }
  288. node_lowmem_end_pfn[i] = start + (j << HUGETLB_PAGE_ORDER);
  289. BUG_ON(node_lowmem_end_pfn[i] > end);
  290. }
  291. /* Return highest address of any mapped memory. */
  292. return (void *)vaddr;
  293. }
  294. #endif /* CONFIG_HIGHMEM */
  295. /*
  296. * Register our most important memory mappings with the debug stub.
  297. *
  298. * This is up to 4 mappings for lowmem, one mapping per memory
  299. * controller, plus one for our text segment.
  300. */
  301. static void store_permanent_mappings(void)
  302. {
  303. int i;
  304. for_each_online_node(i) {
  305. HV_PhysAddr pa = ((HV_PhysAddr)node_start_pfn[i]) << PAGE_SHIFT;
  306. #ifdef CONFIG_HIGHMEM
  307. HV_PhysAddr high_mapped_pa = node_lowmem_end_pfn[i];
  308. #else
  309. HV_PhysAddr high_mapped_pa = node_end_pfn[i];
  310. #endif
  311. unsigned long pages = high_mapped_pa - node_start_pfn[i];
  312. HV_VirtAddr addr = (HV_VirtAddr) __va(pa);
  313. hv_store_mapping(addr, pages << PAGE_SHIFT, pa);
  314. }
  315. hv_store_mapping((HV_VirtAddr)_text,
  316. (uint32_t)(_einittext - _text), 0);
  317. }
  318. /*
  319. * Use hv_inquire_physical() to populate node_{start,end}_pfn[]
  320. * and node_online_map, doing suitable sanity-checking.
  321. * Also set min_low_pfn, max_low_pfn, and max_pfn.
  322. */
  323. static void __init setup_memory(void)
  324. {
  325. int i, j;
  326. int highbits_seen[NR_PA_HIGHBIT_VALUES] = { 0 };
  327. #ifdef CONFIG_HIGHMEM
  328. long highmem_pages;
  329. #endif
  330. #ifndef __tilegx__
  331. int cap;
  332. #endif
  333. #if defined(CONFIG_HIGHMEM) || defined(__tilegx__)
  334. long lowmem_pages;
  335. #endif
  336. unsigned long physpages = 0;
  337. /* We are using a char to hold the cpu_2_node[] mapping */
  338. BUILD_BUG_ON(MAX_NUMNODES > 127);
  339. /* Discover the ranges of memory available to us */
  340. for (i = 0; ; ++i) {
  341. unsigned long start, size, end, highbits;
  342. HV_PhysAddrRange range = hv_inquire_physical(i);
  343. if (range.size == 0)
  344. break;
  345. #ifdef CONFIG_FLATMEM
  346. if (i > 0) {
  347. pr_err("Can't use discontiguous PAs: %#llx..%#llx\n",
  348. range.size, range.start + range.size);
  349. continue;
  350. }
  351. #endif
  352. #ifndef __tilegx__
  353. if ((unsigned long)range.start) {
  354. pr_err("Range not at 4GB multiple: %#llx..%#llx\n",
  355. range.start, range.start + range.size);
  356. continue;
  357. }
  358. #endif
  359. if ((range.start & (HPAGE_SIZE-1)) != 0 ||
  360. (range.size & (HPAGE_SIZE-1)) != 0) {
  361. unsigned long long start_pa = range.start;
  362. unsigned long long orig_size = range.size;
  363. range.start = (start_pa + HPAGE_SIZE - 1) & HPAGE_MASK;
  364. range.size -= (range.start - start_pa);
  365. range.size &= HPAGE_MASK;
  366. pr_err("Range not hugepage-aligned: %#llx..%#llx: now %#llx-%#llx\n",
  367. start_pa, start_pa + orig_size,
  368. range.start, range.start + range.size);
  369. }
  370. highbits = __pa_to_highbits(range.start);
  371. if (highbits >= NR_PA_HIGHBIT_VALUES) {
  372. pr_err("PA high bits too high: %#llx..%#llx\n",
  373. range.start, range.start + range.size);
  374. continue;
  375. }
  376. if (highbits_seen[highbits]) {
  377. pr_err("Range overlaps in high bits: %#llx..%#llx\n",
  378. range.start, range.start + range.size);
  379. continue;
  380. }
  381. highbits_seen[highbits] = 1;
  382. if (PFN_DOWN(range.size) > maxnodemem_pfn[i]) {
  383. int max_size = maxnodemem_pfn[i];
  384. if (max_size > 0) {
  385. pr_err("Maxnodemem reduced node %d to %d pages\n",
  386. i, max_size);
  387. range.size = PFN_PHYS(max_size);
  388. } else {
  389. pr_err("Maxnodemem disabled node %d\n", i);
  390. continue;
  391. }
  392. }
  393. if (physpages + PFN_DOWN(range.size) > maxmem_pfn) {
  394. int max_size = maxmem_pfn - physpages;
  395. if (max_size > 0) {
  396. pr_err("Maxmem reduced node %d to %d pages\n",
  397. i, max_size);
  398. range.size = PFN_PHYS(max_size);
  399. } else {
  400. pr_err("Maxmem disabled node %d\n", i);
  401. continue;
  402. }
  403. }
  404. if (i >= MAX_NUMNODES) {
  405. pr_err("Too many PA nodes (#%d): %#llx...%#llx\n",
  406. i, range.size, range.size + range.start);
  407. continue;
  408. }
  409. start = range.start >> PAGE_SHIFT;
  410. size = range.size >> PAGE_SHIFT;
  411. end = start + size;
  412. #ifndef __tilegx__
  413. if (((HV_PhysAddr)end << PAGE_SHIFT) !=
  414. (range.start + range.size)) {
  415. pr_err("PAs too high to represent: %#llx..%#llx\n",
  416. range.start, range.start + range.size);
  417. continue;
  418. }
  419. #endif
  420. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  421. /*
  422. * Blocks that overlap the pci reserved region must
  423. * have enough space to hold the maximum percpu data
  424. * region at the top of the range. If there isn't
  425. * enough space above the reserved region, just
  426. * truncate the node.
  427. */
  428. if (start <= pci_reserve_start_pfn &&
  429. end > pci_reserve_start_pfn) {
  430. unsigned int per_cpu_size =
  431. __per_cpu_end - __per_cpu_start;
  432. unsigned int percpu_pages =
  433. NR_CPUS * (PFN_UP(per_cpu_size) >> PAGE_SHIFT);
  434. if (end < pci_reserve_end_pfn + percpu_pages) {
  435. end = pci_reserve_start_pfn;
  436. pr_err("PCI mapping region reduced node %d to %ld pages\n",
  437. i, end - start);
  438. }
  439. }
  440. #endif
  441. for (j = __pfn_to_highbits(start);
  442. j <= __pfn_to_highbits(end - 1); j++)
  443. highbits_to_node[j] = i;
  444. node_start_pfn[i] = start;
  445. node_end_pfn[i] = end;
  446. node_controller[i] = range.controller;
  447. physpages += size;
  448. max_pfn = end;
  449. /* Mark node as online */
  450. node_set(i, node_online_map);
  451. node_set(i, node_possible_map);
  452. }
  453. #ifndef __tilegx__
  454. /*
  455. * For 4KB pages, mem_map "struct page" data is 1% of the size
  456. * of the physical memory, so can be quite big (640 MB for
  457. * four 16G zones). These structures must be mapped in
  458. * lowmem, and since we currently cap out at about 768 MB,
  459. * it's impractical to try to use this much address space.
  460. * For now, arbitrarily cap the amount of physical memory
  461. * we're willing to use at 8 million pages (32GB of 4KB pages).
  462. */
  463. cap = 8 * 1024 * 1024; /* 8 million pages */
  464. if (physpages > cap) {
  465. int num_nodes = num_online_nodes();
  466. int cap_each = cap / num_nodes;
  467. unsigned long dropped_pages = 0;
  468. for (i = 0; i < num_nodes; ++i) {
  469. int size = node_end_pfn[i] - node_start_pfn[i];
  470. if (size > cap_each) {
  471. dropped_pages += (size - cap_each);
  472. node_end_pfn[i] = node_start_pfn[i] + cap_each;
  473. }
  474. }
  475. physpages -= dropped_pages;
  476. pr_warn("Only using %ldMB memory - ignoring %ldMB\n",
  477. physpages >> (20 - PAGE_SHIFT),
  478. dropped_pages >> (20 - PAGE_SHIFT));
  479. pr_warn("Consider using a larger page size\n");
  480. }
  481. #endif
  482. /* Heap starts just above the last loaded address. */
  483. min_low_pfn = PFN_UP((unsigned long)_end - PAGE_OFFSET);
  484. #ifdef CONFIG_HIGHMEM
  485. /* Find where we map lowmem from each controller. */
  486. high_memory = setup_pa_va_mapping();
  487. /* Set max_low_pfn based on what node 0 can directly address. */
  488. max_low_pfn = node_lowmem_end_pfn[0];
  489. lowmem_pages = (mappable_physpages > MAXMEM_PFN) ?
  490. MAXMEM_PFN : mappable_physpages;
  491. highmem_pages = (long) (physpages - lowmem_pages);
  492. pr_notice("%ldMB HIGHMEM available\n",
  493. pages_to_mb(highmem_pages > 0 ? highmem_pages : 0));
  494. pr_notice("%ldMB LOWMEM available\n", pages_to_mb(lowmem_pages));
  495. #else
  496. /* Set max_low_pfn based on what node 0 can directly address. */
  497. max_low_pfn = node_end_pfn[0];
  498. #ifndef __tilegx__
  499. if (node_end_pfn[0] > MAXMEM_PFN) {
  500. pr_warn("Only using %ldMB LOWMEM\n", MAXMEM >> 20);
  501. pr_warn("Use a HIGHMEM enabled kernel\n");
  502. max_low_pfn = MAXMEM_PFN;
  503. max_pfn = MAXMEM_PFN;
  504. node_end_pfn[0] = MAXMEM_PFN;
  505. } else {
  506. pr_notice("%ldMB memory available\n",
  507. pages_to_mb(node_end_pfn[0]));
  508. }
  509. for (i = 1; i < MAX_NUMNODES; ++i) {
  510. node_start_pfn[i] = 0;
  511. node_end_pfn[i] = 0;
  512. }
  513. high_memory = __va(node_end_pfn[0]);
  514. #else
  515. lowmem_pages = 0;
  516. for (i = 0; i < MAX_NUMNODES; ++i) {
  517. int pages = node_end_pfn[i] - node_start_pfn[i];
  518. lowmem_pages += pages;
  519. if (pages)
  520. high_memory = pfn_to_kaddr(node_end_pfn[i]);
  521. }
  522. pr_notice("%ldMB memory available\n", pages_to_mb(lowmem_pages));
  523. #endif
  524. #endif
  525. }
  526. /*
  527. * On 32-bit machines, we only put bootmem on the low controller,
  528. * since PAs > 4GB can't be used in bootmem. In principle one could
  529. * imagine, e.g., multiple 1 GB controllers all of which could support
  530. * bootmem, but in practice using controllers this small isn't a
  531. * particularly interesting scenario, so we just keep it simple and
  532. * use only the first controller for bootmem on 32-bit machines.
  533. */
  534. static inline int node_has_bootmem(int nid)
  535. {
  536. #ifdef CONFIG_64BIT
  537. return 1;
  538. #else
  539. return nid == 0;
  540. #endif
  541. }
  542. static inline unsigned long alloc_bootmem_pfn(int nid,
  543. unsigned long size,
  544. unsigned long goal)
  545. {
  546. void *kva = __alloc_bootmem_node(NODE_DATA(nid), size,
  547. PAGE_SIZE, goal);
  548. unsigned long pfn = kaddr_to_pfn(kva);
  549. BUG_ON(goal && PFN_PHYS(pfn) != goal);
  550. return pfn;
  551. }
  552. static void __init setup_bootmem_allocator_node(int i)
  553. {
  554. unsigned long start, end, mapsize, mapstart;
  555. if (node_has_bootmem(i)) {
  556. NODE_DATA(i)->bdata = &bootmem_node_data[i];
  557. } else {
  558. /* Share controller zero's bdata for now. */
  559. NODE_DATA(i)->bdata = &bootmem_node_data[0];
  560. return;
  561. }
  562. /* Skip up to after the bss in node 0. */
  563. start = (i == 0) ? min_low_pfn : node_start_pfn[i];
  564. /* Only lowmem, if we're a HIGHMEM build. */
  565. #ifdef CONFIG_HIGHMEM
  566. end = node_lowmem_end_pfn[i];
  567. #else
  568. end = node_end_pfn[i];
  569. #endif
  570. /* No memory here. */
  571. if (end == start)
  572. return;
  573. /* Figure out where the bootmem bitmap is located. */
  574. mapsize = bootmem_bootmap_pages(end - start);
  575. if (i == 0) {
  576. /* Use some space right before the heap on node 0. */
  577. mapstart = start;
  578. start += mapsize;
  579. } else {
  580. /* Allocate bitmap on node 0 to avoid page table issues. */
  581. mapstart = alloc_bootmem_pfn(0, PFN_PHYS(mapsize), 0);
  582. }
  583. /* Initialize a node. */
  584. init_bootmem_node(NODE_DATA(i), mapstart, start, end);
  585. /* Free all the space back into the allocator. */
  586. free_bootmem(PFN_PHYS(start), PFN_PHYS(end - start));
  587. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  588. /*
  589. * Throw away any memory aliased by the PCI region.
  590. */
  591. if (pci_reserve_start_pfn < end && pci_reserve_end_pfn > start) {
  592. start = max(pci_reserve_start_pfn, start);
  593. end = min(pci_reserve_end_pfn, end);
  594. reserve_bootmem(PFN_PHYS(start), PFN_PHYS(end - start),
  595. BOOTMEM_EXCLUSIVE);
  596. }
  597. #endif
  598. }
  599. static void __init setup_bootmem_allocator(void)
  600. {
  601. int i;
  602. for (i = 0; i < MAX_NUMNODES; ++i)
  603. setup_bootmem_allocator_node(i);
  604. /* Reserve any memory excluded by "memmap" arguments. */
  605. for (i = 0; i < memmap_nr; ++i) {
  606. struct memmap_entry *m = &memmap_map[i];
  607. reserve_bootmem(m->addr, m->size, BOOTMEM_DEFAULT);
  608. }
  609. #ifdef CONFIG_BLK_DEV_INITRD
  610. if (initrd_start) {
  611. /* Make sure the initrd memory region is not modified. */
  612. if (reserve_bootmem(initrd_start, initrd_end - initrd_start,
  613. BOOTMEM_EXCLUSIVE)) {
  614. pr_crit("The initrd memory region has been polluted. Disabling it.\n");
  615. initrd_start = 0;
  616. initrd_end = 0;
  617. } else {
  618. /*
  619. * Translate initrd_start & initrd_end from PA to VA for
  620. * future access.
  621. */
  622. initrd_start += PAGE_OFFSET;
  623. initrd_end += PAGE_OFFSET;
  624. }
  625. }
  626. #endif
  627. #ifdef CONFIG_KEXEC
  628. if (crashk_res.start != crashk_res.end)
  629. reserve_bootmem(crashk_res.start, resource_size(&crashk_res),
  630. BOOTMEM_DEFAULT);
  631. #endif
  632. }
  633. void *__init alloc_remap(int nid, unsigned long size)
  634. {
  635. int pages = node_end_pfn[nid] - node_start_pfn[nid];
  636. void *map = pfn_to_kaddr(node_memmap_pfn[nid]);
  637. BUG_ON(size != pages * sizeof(struct page));
  638. memset(map, 0, size);
  639. return map;
  640. }
  641. static int __init percpu_size(void)
  642. {
  643. int size = __per_cpu_end - __per_cpu_start;
  644. size += PERCPU_MODULE_RESERVE;
  645. size += PERCPU_DYNAMIC_EARLY_SIZE;
  646. if (size < PCPU_MIN_UNIT_SIZE)
  647. size = PCPU_MIN_UNIT_SIZE;
  648. size = roundup(size, PAGE_SIZE);
  649. /* In several places we assume the per-cpu data fits on a huge page. */
  650. BUG_ON(kdata_huge && size > HPAGE_SIZE);
  651. return size;
  652. }
  653. static void __init zone_sizes_init(void)
  654. {
  655. unsigned long zones_size[MAX_NR_ZONES] = { 0 };
  656. int size = percpu_size();
  657. int num_cpus = smp_height * smp_width;
  658. const unsigned long dma_end = (1UL << (32 - PAGE_SHIFT));
  659. int i;
  660. for (i = 0; i < num_cpus; ++i)
  661. node_percpu[cpu_to_node(i)] += size;
  662. for_each_online_node(i) {
  663. unsigned long start = node_start_pfn[i];
  664. unsigned long end = node_end_pfn[i];
  665. #ifdef CONFIG_HIGHMEM
  666. unsigned long lowmem_end = node_lowmem_end_pfn[i];
  667. #else
  668. unsigned long lowmem_end = end;
  669. #endif
  670. int memmap_size = (end - start) * sizeof(struct page);
  671. node_free_pfn[i] = start;
  672. /*
  673. * Set aside pages for per-cpu data and the mem_map array.
  674. *
  675. * Since the per-cpu data requires special homecaching,
  676. * if we are in kdata_huge mode, we put it at the end of
  677. * the lowmem region. If we're not in kdata_huge mode,
  678. * we take the per-cpu pages from the bottom of the
  679. * controller, since that avoids fragmenting a huge page
  680. * that users might want. We always take the memmap
  681. * from the bottom of the controller, since with
  682. * kdata_huge that lets it be under a huge TLB entry.
  683. *
  684. * If the user has requested isolnodes for a controller,
  685. * though, there'll be no lowmem, so we just alloc_bootmem
  686. * the memmap. There will be no percpu memory either.
  687. */
  688. if (i != 0 && node_isset(i, isolnodes)) {
  689. node_memmap_pfn[i] =
  690. alloc_bootmem_pfn(0, memmap_size, 0);
  691. BUG_ON(node_percpu[i] != 0);
  692. } else if (node_has_bootmem(start)) {
  693. unsigned long goal = 0;
  694. node_memmap_pfn[i] =
  695. alloc_bootmem_pfn(i, memmap_size, 0);
  696. if (kdata_huge)
  697. goal = PFN_PHYS(lowmem_end) - node_percpu[i];
  698. if (node_percpu[i])
  699. node_percpu_pfn[i] =
  700. alloc_bootmem_pfn(i, node_percpu[i],
  701. goal);
  702. } else {
  703. /* In non-bootmem zones, just reserve some pages. */
  704. node_memmap_pfn[i] = node_free_pfn[i];
  705. node_free_pfn[i] += PFN_UP(memmap_size);
  706. if (!kdata_huge) {
  707. node_percpu_pfn[i] = node_free_pfn[i];
  708. node_free_pfn[i] += PFN_UP(node_percpu[i]);
  709. } else {
  710. node_percpu_pfn[i] =
  711. lowmem_end - PFN_UP(node_percpu[i]);
  712. }
  713. }
  714. #ifdef CONFIG_HIGHMEM
  715. if (start > lowmem_end) {
  716. zones_size[ZONE_NORMAL] = 0;
  717. zones_size[ZONE_HIGHMEM] = end - start;
  718. } else {
  719. zones_size[ZONE_NORMAL] = lowmem_end - start;
  720. zones_size[ZONE_HIGHMEM] = end - lowmem_end;
  721. }
  722. #else
  723. zones_size[ZONE_NORMAL] = end - start;
  724. #endif
  725. if (start < dma_end) {
  726. zones_size[ZONE_DMA] = min(zones_size[ZONE_NORMAL],
  727. dma_end - start);
  728. zones_size[ZONE_NORMAL] -= zones_size[ZONE_DMA];
  729. } else {
  730. zones_size[ZONE_DMA] = 0;
  731. }
  732. /* Take zone metadata from controller 0 if we're isolnode. */
  733. if (node_isset(i, isolnodes))
  734. NODE_DATA(i)->bdata = &bootmem_node_data[0];
  735. free_area_init_node(i, zones_size, start, NULL);
  736. printk(KERN_DEBUG " Normal zone: %ld per-cpu pages\n",
  737. PFN_UP(node_percpu[i]));
  738. /* Track the type of memory on each node */
  739. if (zones_size[ZONE_NORMAL] || zones_size[ZONE_DMA])
  740. node_set_state(i, N_NORMAL_MEMORY);
  741. #ifdef CONFIG_HIGHMEM
  742. if (end != start)
  743. node_set_state(i, N_HIGH_MEMORY);
  744. #endif
  745. node_set_online(i);
  746. }
  747. }
  748. #ifdef CONFIG_NUMA
  749. /* which logical CPUs are on which nodes */
  750. struct cpumask node_2_cpu_mask[MAX_NUMNODES] __write_once;
  751. EXPORT_SYMBOL(node_2_cpu_mask);
  752. /* which node each logical CPU is on */
  753. char cpu_2_node[NR_CPUS] __write_once __attribute__((aligned(L2_CACHE_BYTES)));
  754. EXPORT_SYMBOL(cpu_2_node);
  755. /* Return cpu_to_node() except for cpus not yet assigned, which return -1 */
  756. static int __init cpu_to_bound_node(int cpu, struct cpumask* unbound_cpus)
  757. {
  758. if (!cpu_possible(cpu) || cpumask_test_cpu(cpu, unbound_cpus))
  759. return -1;
  760. else
  761. return cpu_to_node(cpu);
  762. }
  763. /* Return number of immediately-adjacent tiles sharing the same NUMA node. */
  764. static int __init node_neighbors(int node, int cpu,
  765. struct cpumask *unbound_cpus)
  766. {
  767. int neighbors = 0;
  768. int w = smp_width;
  769. int h = smp_height;
  770. int x = cpu % w;
  771. int y = cpu / w;
  772. if (x > 0 && cpu_to_bound_node(cpu-1, unbound_cpus) == node)
  773. ++neighbors;
  774. if (x < w-1 && cpu_to_bound_node(cpu+1, unbound_cpus) == node)
  775. ++neighbors;
  776. if (y > 0 && cpu_to_bound_node(cpu-w, unbound_cpus) == node)
  777. ++neighbors;
  778. if (y < h-1 && cpu_to_bound_node(cpu+w, unbound_cpus) == node)
  779. ++neighbors;
  780. return neighbors;
  781. }
  782. static void __init setup_numa_mapping(void)
  783. {
  784. u8 distance[MAX_NUMNODES][NR_CPUS];
  785. HV_Coord coord;
  786. int cpu, node, cpus, i, x, y;
  787. int num_nodes = num_online_nodes();
  788. struct cpumask unbound_cpus;
  789. nodemask_t default_nodes;
  790. cpumask_clear(&unbound_cpus);
  791. /* Get set of nodes we will use for defaults */
  792. nodes_andnot(default_nodes, node_online_map, isolnodes);
  793. if (nodes_empty(default_nodes)) {
  794. BUG_ON(!node_isset(0, node_online_map));
  795. pr_err("Forcing NUMA node zero available as a default node\n");
  796. node_set(0, default_nodes);
  797. }
  798. /* Populate the distance[] array */
  799. memset(distance, -1, sizeof(distance));
  800. cpu = 0;
  801. for (coord.y = 0; coord.y < smp_height; ++coord.y) {
  802. for (coord.x = 0; coord.x < smp_width;
  803. ++coord.x, ++cpu) {
  804. BUG_ON(cpu >= nr_cpu_ids);
  805. if (!cpu_possible(cpu)) {
  806. cpu_2_node[cpu] = -1;
  807. continue;
  808. }
  809. for_each_node_mask(node, default_nodes) {
  810. HV_MemoryControllerInfo info =
  811. hv_inquire_memory_controller(
  812. coord, node_controller[node]);
  813. distance[node][cpu] =
  814. ABS(info.coord.x) + ABS(info.coord.y);
  815. }
  816. cpumask_set_cpu(cpu, &unbound_cpus);
  817. }
  818. }
  819. cpus = cpu;
  820. /*
  821. * Round-robin through the NUMA nodes until all the cpus are
  822. * assigned. We could be more clever here (e.g. create four
  823. * sorted linked lists on the same set of cpu nodes, and pull
  824. * off them in round-robin sequence, removing from all four
  825. * lists each time) but given the relatively small numbers
  826. * involved, O(n^2) seem OK for a one-time cost.
  827. */
  828. node = first_node(default_nodes);
  829. while (!cpumask_empty(&unbound_cpus)) {
  830. int best_cpu = -1;
  831. int best_distance = INT_MAX;
  832. for (cpu = 0; cpu < cpus; ++cpu) {
  833. if (cpumask_test_cpu(cpu, &unbound_cpus)) {
  834. /*
  835. * Compute metric, which is how much
  836. * closer the cpu is to this memory
  837. * controller than the others, shifted
  838. * up, and then the number of
  839. * neighbors already in the node as an
  840. * epsilon adjustment to try to keep
  841. * the nodes compact.
  842. */
  843. int d = distance[node][cpu] * num_nodes;
  844. for_each_node_mask(i, default_nodes) {
  845. if (i != node)
  846. d -= distance[i][cpu];
  847. }
  848. d *= 8; /* allow space for epsilon */
  849. d -= node_neighbors(node, cpu, &unbound_cpus);
  850. if (d < best_distance) {
  851. best_cpu = cpu;
  852. best_distance = d;
  853. }
  854. }
  855. }
  856. BUG_ON(best_cpu < 0);
  857. cpumask_set_cpu(best_cpu, &node_2_cpu_mask[node]);
  858. cpu_2_node[best_cpu] = node;
  859. cpumask_clear_cpu(best_cpu, &unbound_cpus);
  860. node = next_node_in(node, default_nodes);
  861. }
  862. /* Print out node assignments and set defaults for disabled cpus */
  863. cpu = 0;
  864. for (y = 0; y < smp_height; ++y) {
  865. printk(KERN_DEBUG "NUMA cpu-to-node row %d:", y);
  866. for (x = 0; x < smp_width; ++x, ++cpu) {
  867. if (cpu_to_node(cpu) < 0) {
  868. pr_cont(" -");
  869. cpu_2_node[cpu] = first_node(default_nodes);
  870. } else {
  871. pr_cont(" %d", cpu_to_node(cpu));
  872. }
  873. }
  874. pr_cont("\n");
  875. }
  876. }
  877. static struct cpu cpu_devices[NR_CPUS];
  878. static int __init topology_init(void)
  879. {
  880. int i;
  881. for_each_online_node(i)
  882. register_one_node(i);
  883. for (i = 0; i < smp_height * smp_width; ++i)
  884. register_cpu(&cpu_devices[i], i);
  885. return 0;
  886. }
  887. subsys_initcall(topology_init);
  888. #else /* !CONFIG_NUMA */
  889. #define setup_numa_mapping() do { } while (0)
  890. #endif /* CONFIG_NUMA */
  891. /*
  892. * Initialize hugepage support on this cpu. We do this on all cores
  893. * early in boot: before argument parsing for the boot cpu, and after
  894. * argument parsing but before the init functions run on the secondaries.
  895. * So the values we set up here in the hypervisor may be overridden on
  896. * the boot cpu as arguments are parsed.
  897. */
  898. static void init_super_pages(void)
  899. {
  900. #ifdef CONFIG_HUGETLB_SUPER_PAGES
  901. int i;
  902. for (i = 0; i < HUGE_SHIFT_ENTRIES; ++i)
  903. hv_set_pte_super_shift(i, huge_shift[i]);
  904. #endif
  905. }
  906. /**
  907. * setup_cpu() - Do all necessary per-cpu, tile-specific initialization.
  908. * @boot: Is this the boot cpu?
  909. *
  910. * Called from setup_arch() on the boot cpu, or online_secondary().
  911. */
  912. void setup_cpu(int boot)
  913. {
  914. /* The boot cpu sets up its permanent mappings much earlier. */
  915. if (!boot)
  916. store_permanent_mappings();
  917. /* Allow asynchronous TLB interrupts. */
  918. #if CHIP_HAS_TILE_DMA()
  919. arch_local_irq_unmask(INT_DMATLB_MISS);
  920. arch_local_irq_unmask(INT_DMATLB_ACCESS);
  921. #endif
  922. #ifdef __tilegx__
  923. arch_local_irq_unmask(INT_SINGLE_STEP_K);
  924. #endif
  925. /*
  926. * Allow user access to many generic SPRs, like the cycle
  927. * counter, PASS/FAIL/DONE, INTERRUPT_CRITICAL_SECTION, etc.
  928. */
  929. __insn_mtspr(SPR_MPL_WORLD_ACCESS_SET_0, 1);
  930. #if CHIP_HAS_SN()
  931. /* Static network is not restricted. */
  932. __insn_mtspr(SPR_MPL_SN_ACCESS_SET_0, 1);
  933. #endif
  934. /*
  935. * Set the MPL for interrupt control 0 & 1 to the corresponding
  936. * values. This includes access to the SYSTEM_SAVE and EX_CONTEXT
  937. * SPRs, as well as the interrupt mask.
  938. */
  939. __insn_mtspr(SPR_MPL_INTCTRL_0_SET_0, 1);
  940. __insn_mtspr(SPR_MPL_INTCTRL_1_SET_1, 1);
  941. /* Initialize IRQ support for this cpu. */
  942. setup_irq_regs();
  943. #ifdef CONFIG_HARDWALL
  944. /* Reset the network state on this cpu. */
  945. reset_network_state();
  946. #endif
  947. init_super_pages();
  948. }
  949. #ifdef CONFIG_BLK_DEV_INITRD
  950. static int __initdata set_initramfs_file;
  951. static char __initdata initramfs_file[128] = "initramfs";
  952. static int __init setup_initramfs_file(char *str)
  953. {
  954. if (str == NULL)
  955. return -EINVAL;
  956. strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
  957. set_initramfs_file = 1;
  958. return 0;
  959. }
  960. early_param("initramfs_file", setup_initramfs_file);
  961. /*
  962. * We look for a file called "initramfs" in the hvfs. If there is one, we
  963. * allocate some memory for it and it will be unpacked to the initramfs.
  964. * If it's compressed, the initd code will uncompress it first.
  965. */
  966. static void __init load_hv_initrd(void)
  967. {
  968. HV_FS_StatInfo stat;
  969. int fd, rc;
  970. void *initrd;
  971. /* If initrd has already been set, skip initramfs file in hvfs. */
  972. if (initrd_start)
  973. return;
  974. fd = hv_fs_findfile((HV_VirtAddr) initramfs_file);
  975. if (fd == HV_ENOENT) {
  976. if (set_initramfs_file) {
  977. pr_warn("No such hvfs initramfs file '%s'\n",
  978. initramfs_file);
  979. return;
  980. } else {
  981. /* Try old backwards-compatible name. */
  982. fd = hv_fs_findfile((HV_VirtAddr)"initramfs.cpio.gz");
  983. if (fd == HV_ENOENT)
  984. return;
  985. }
  986. }
  987. BUG_ON(fd < 0);
  988. stat = hv_fs_fstat(fd);
  989. BUG_ON(stat.size < 0);
  990. if (stat.flags & HV_FS_ISDIR) {
  991. pr_warn("Ignoring hvfs file '%s': it's a directory\n",
  992. initramfs_file);
  993. return;
  994. }
  995. initrd = alloc_bootmem_pages(stat.size);
  996. rc = hv_fs_pread(fd, (HV_VirtAddr) initrd, stat.size, 0);
  997. if (rc != stat.size) {
  998. pr_err("Error reading %d bytes from hvfs file '%s': %d\n",
  999. stat.size, initramfs_file, rc);
  1000. free_initrd_mem((unsigned long) initrd, stat.size);
  1001. return;
  1002. }
  1003. initrd_start = (unsigned long) initrd;
  1004. initrd_end = initrd_start + stat.size;
  1005. }
  1006. void __init free_initrd_mem(unsigned long begin, unsigned long end)
  1007. {
  1008. free_bootmem_late(__pa(begin), end - begin);
  1009. }
  1010. static int __init setup_initrd(char *str)
  1011. {
  1012. char *endp;
  1013. unsigned long initrd_size;
  1014. initrd_size = str ? simple_strtoul(str, &endp, 0) : 0;
  1015. if (initrd_size == 0 || *endp != '@')
  1016. return -EINVAL;
  1017. initrd_start = simple_strtoul(endp+1, &endp, 0);
  1018. if (initrd_start == 0)
  1019. return -EINVAL;
  1020. initrd_end = initrd_start + initrd_size;
  1021. return 0;
  1022. }
  1023. early_param("initrd", setup_initrd);
  1024. #else
  1025. static inline void load_hv_initrd(void) {}
  1026. #endif /* CONFIG_BLK_DEV_INITRD */
  1027. static void __init validate_hv(void)
  1028. {
  1029. /*
  1030. * It may already be too late, but let's check our built-in
  1031. * configuration against what the hypervisor is providing.
  1032. */
  1033. unsigned long glue_size = hv_sysconf(HV_SYSCONF_GLUE_SIZE);
  1034. int hv_page_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL);
  1035. int hv_hpage_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE);
  1036. HV_ASIDRange asid_range;
  1037. #ifndef CONFIG_SMP
  1038. HV_Topology topology = hv_inquire_topology();
  1039. BUG_ON(topology.coord.x != 0 || topology.coord.y != 0);
  1040. if (topology.width != 1 || topology.height != 1) {
  1041. pr_warn("Warning: booting UP kernel on %dx%d grid; will ignore all but first tile\n",
  1042. topology.width, topology.height);
  1043. }
  1044. #endif
  1045. if (PAGE_OFFSET + HV_GLUE_START_CPA + glue_size > (unsigned long)_text)
  1046. early_panic("Hypervisor glue size %ld is too big!\n",
  1047. glue_size);
  1048. if (hv_page_size != PAGE_SIZE)
  1049. early_panic("Hypervisor page size %#x != our %#lx\n",
  1050. hv_page_size, PAGE_SIZE);
  1051. if (hv_hpage_size != HPAGE_SIZE)
  1052. early_panic("Hypervisor huge page size %#x != our %#lx\n",
  1053. hv_hpage_size, HPAGE_SIZE);
  1054. #ifdef CONFIG_SMP
  1055. /*
  1056. * Some hypervisor APIs take a pointer to a bitmap array
  1057. * whose size is at least the number of cpus on the chip.
  1058. * We use a struct cpumask for this, so it must be big enough.
  1059. */
  1060. if ((smp_height * smp_width) > nr_cpu_ids)
  1061. early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %d\n",
  1062. smp_height, smp_width, nr_cpu_ids);
  1063. #endif
  1064. /*
  1065. * Check that we're using allowed ASIDs, and initialize the
  1066. * various asid variables to their appropriate initial states.
  1067. */
  1068. asid_range = hv_inquire_asid(0);
  1069. min_asid = asid_range.start;
  1070. __this_cpu_write(current_asid, min_asid);
  1071. max_asid = asid_range.start + asid_range.size - 1;
  1072. if (hv_confstr(HV_CONFSTR_CHIP_MODEL, (HV_VirtAddr)chip_model,
  1073. sizeof(chip_model)) < 0) {
  1074. pr_err("Warning: HV_CONFSTR_CHIP_MODEL not available\n");
  1075. strlcpy(chip_model, "unknown", sizeof(chip_model));
  1076. }
  1077. }
  1078. static void __init validate_va(void)
  1079. {
  1080. #ifndef __tilegx__ /* FIXME: GX: probably some validation relevant here */
  1081. /*
  1082. * Similarly, make sure we're only using allowed VAs.
  1083. * We assume we can contiguously use MEM_USER_INTRPT .. MEM_HV_START,
  1084. * and 0 .. KERNEL_HIGH_VADDR.
  1085. * In addition, make sure we CAN'T use the end of memory, since
  1086. * we use the last chunk of each pgd for the pgd_list.
  1087. */
  1088. int i, user_kernel_ok = 0;
  1089. unsigned long max_va = 0;
  1090. unsigned long list_va =
  1091. ((PGD_LIST_OFFSET / sizeof(pgd_t)) << PGDIR_SHIFT);
  1092. for (i = 0; ; ++i) {
  1093. HV_VirtAddrRange range = hv_inquire_virtual(i);
  1094. if (range.size == 0)
  1095. break;
  1096. if (range.start <= MEM_USER_INTRPT &&
  1097. range.start + range.size >= MEM_HV_START)
  1098. user_kernel_ok = 1;
  1099. if (range.start == 0)
  1100. max_va = range.size;
  1101. BUG_ON(range.start + range.size > list_va);
  1102. }
  1103. if (!user_kernel_ok)
  1104. early_panic("Hypervisor not configured for user/kernel VAs\n");
  1105. if (max_va == 0)
  1106. early_panic("Hypervisor not configured for low VAs\n");
  1107. if (max_va < KERNEL_HIGH_VADDR)
  1108. early_panic("Hypervisor max VA %#lx smaller than %#lx\n",
  1109. max_va, KERNEL_HIGH_VADDR);
  1110. /* Kernel PCs must have their high bit set; see intvec.S. */
  1111. if ((long)VMALLOC_START >= 0)
  1112. early_panic("Linux VMALLOC region below the 2GB line (%#lx)!\n"
  1113. "Reconfigure the kernel with smaller VMALLOC_RESERVE\n",
  1114. VMALLOC_START);
  1115. #endif
  1116. }
  1117. /*
  1118. * cpu_lotar_map lists all the cpus that are valid for the supervisor
  1119. * to cache data on at a page level, i.e. what cpus can be placed in
  1120. * the LOTAR field of a PTE. It is equivalent to the set of possible
  1121. * cpus plus any other cpus that are willing to share their cache.
  1122. * It is set by hv_inquire_tiles(HV_INQ_TILES_LOTAR).
  1123. */
  1124. struct cpumask __write_once cpu_lotar_map;
  1125. EXPORT_SYMBOL(cpu_lotar_map);
  1126. /*
  1127. * hash_for_home_map lists all the tiles that hash-for-home data
  1128. * will be cached on. Note that this may includes tiles that are not
  1129. * valid for this supervisor to use otherwise (e.g. if a hypervisor
  1130. * device is being shared between multiple supervisors).
  1131. * It is set by hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE).
  1132. */
  1133. struct cpumask hash_for_home_map;
  1134. EXPORT_SYMBOL(hash_for_home_map);
  1135. /*
  1136. * cpu_cacheable_map lists all the cpus whose caches the hypervisor can
  1137. * flush on our behalf. It is set to cpu_possible_mask OR'ed with
  1138. * hash_for_home_map, and it is what should be passed to
  1139. * hv_flush_remote() to flush all caches. Note that if there are
  1140. * dedicated hypervisor driver tiles that have authorized use of their
  1141. * cache, those tiles will only appear in cpu_lotar_map, NOT in
  1142. * cpu_cacheable_map, as they are a special case.
  1143. */
  1144. struct cpumask __write_once cpu_cacheable_map;
  1145. EXPORT_SYMBOL(cpu_cacheable_map);
  1146. static __initdata struct cpumask disabled_map;
  1147. static int __init disabled_cpus(char *str)
  1148. {
  1149. int boot_cpu = smp_processor_id();
  1150. if (str == NULL || cpulist_parse_crop(str, &disabled_map) != 0)
  1151. return -EINVAL;
  1152. if (cpumask_test_cpu(boot_cpu, &disabled_map)) {
  1153. pr_err("disabled_cpus: can't disable boot cpu %d\n", boot_cpu);
  1154. cpumask_clear_cpu(boot_cpu, &disabled_map);
  1155. }
  1156. return 0;
  1157. }
  1158. early_param("disabled_cpus", disabled_cpus);
  1159. void __init print_disabled_cpus(void)
  1160. {
  1161. if (!cpumask_empty(&disabled_map))
  1162. pr_info("CPUs not available for Linux: %*pbl\n",
  1163. cpumask_pr_args(&disabled_map));
  1164. }
  1165. static void __init setup_cpu_maps(void)
  1166. {
  1167. struct cpumask hv_disabled_map, cpu_possible_init;
  1168. int boot_cpu = smp_processor_id();
  1169. int cpus, i, rc;
  1170. /* Learn which cpus are allowed by the hypervisor. */
  1171. rc = hv_inquire_tiles(HV_INQ_TILES_AVAIL,
  1172. (HV_VirtAddr) cpumask_bits(&cpu_possible_init),
  1173. sizeof(cpu_cacheable_map));
  1174. if (rc < 0)
  1175. early_panic("hv_inquire_tiles(AVAIL) failed: rc %d\n", rc);
  1176. if (!cpumask_test_cpu(boot_cpu, &cpu_possible_init))
  1177. early_panic("Boot CPU %d disabled by hypervisor!\n", boot_cpu);
  1178. /* Compute the cpus disabled by the hvconfig file. */
  1179. cpumask_complement(&hv_disabled_map, &cpu_possible_init);
  1180. /* Include them with the cpus disabled by "disabled_cpus". */
  1181. cpumask_or(&disabled_map, &disabled_map, &hv_disabled_map);
  1182. /*
  1183. * Disable every cpu after "setup_max_cpus". But don't mark
  1184. * as disabled the cpus that are outside of our initial rectangle,
  1185. * since that turns out to be confusing.
  1186. */
  1187. cpus = 1; /* this cpu */
  1188. cpumask_set_cpu(boot_cpu, &disabled_map); /* ignore this cpu */
  1189. for (i = 0; cpus < setup_max_cpus; ++i)
  1190. if (!cpumask_test_cpu(i, &disabled_map))
  1191. ++cpus;
  1192. for (; i < smp_height * smp_width; ++i)
  1193. cpumask_set_cpu(i, &disabled_map);
  1194. cpumask_clear_cpu(boot_cpu, &disabled_map); /* reset this cpu */
  1195. for (i = smp_height * smp_width; i < NR_CPUS; ++i)
  1196. cpumask_clear_cpu(i, &disabled_map);
  1197. /*
  1198. * Setup cpu_possible map as every cpu allocated to us, minus
  1199. * the results of any "disabled_cpus" settings.
  1200. */
  1201. cpumask_andnot(&cpu_possible_init, &cpu_possible_init, &disabled_map);
  1202. init_cpu_possible(&cpu_possible_init);
  1203. /* Learn which cpus are valid for LOTAR caching. */
  1204. rc = hv_inquire_tiles(HV_INQ_TILES_LOTAR,
  1205. (HV_VirtAddr) cpumask_bits(&cpu_lotar_map),
  1206. sizeof(cpu_lotar_map));
  1207. if (rc < 0) {
  1208. pr_err("warning: no HV_INQ_TILES_LOTAR; using AVAIL\n");
  1209. cpu_lotar_map = *cpu_possible_mask;
  1210. }
  1211. /* Retrieve set of CPUs used for hash-for-home caching */
  1212. rc = hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE,
  1213. (HV_VirtAddr) hash_for_home_map.bits,
  1214. sizeof(hash_for_home_map));
  1215. if (rc < 0)
  1216. early_panic("hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc);
  1217. cpumask_or(&cpu_cacheable_map, cpu_possible_mask, &hash_for_home_map);
  1218. }
  1219. static int __init dataplane(char *str)
  1220. {
  1221. pr_warn("WARNING: dataplane support disabled in this kernel\n");
  1222. return 0;
  1223. }
  1224. early_param("dataplane", dataplane);
  1225. #ifdef CONFIG_NO_HZ_FULL
  1226. /* Warn if hypervisor shared cpus are marked as nohz_full. */
  1227. static int __init check_nohz_full_cpus(void)
  1228. {
  1229. struct cpumask shared;
  1230. int cpu;
  1231. if (hv_inquire_tiles(HV_INQ_TILES_SHARED,
  1232. (HV_VirtAddr) shared.bits, sizeof(shared)) < 0) {
  1233. pr_warn("WARNING: No support for inquiring hv shared tiles\n");
  1234. return 0;
  1235. }
  1236. for_each_cpu(cpu, &shared) {
  1237. if (tick_nohz_full_cpu(cpu))
  1238. pr_warn("WARNING: nohz_full cpu %d receives hypervisor interrupts!\n",
  1239. cpu);
  1240. }
  1241. return 0;
  1242. }
  1243. arch_initcall(check_nohz_full_cpus);
  1244. #endif
  1245. #ifdef CONFIG_CMDLINE_BOOL
  1246. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  1247. #endif
  1248. void __init setup_arch(char **cmdline_p)
  1249. {
  1250. int len;
  1251. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  1252. len = hv_get_command_line((HV_VirtAddr) boot_command_line,
  1253. COMMAND_LINE_SIZE);
  1254. if (boot_command_line[0])
  1255. pr_warn("WARNING: ignoring dynamic command line \"%s\"\n",
  1256. boot_command_line);
  1257. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  1258. #else
  1259. char *hv_cmdline;
  1260. #if defined(CONFIG_CMDLINE_BOOL)
  1261. if (builtin_cmdline[0]) {
  1262. int builtin_len = strlcpy(boot_command_line, builtin_cmdline,
  1263. COMMAND_LINE_SIZE);
  1264. if (builtin_len < COMMAND_LINE_SIZE-1)
  1265. boot_command_line[builtin_len++] = ' ';
  1266. hv_cmdline = &boot_command_line[builtin_len];
  1267. len = COMMAND_LINE_SIZE - builtin_len;
  1268. } else
  1269. #endif
  1270. {
  1271. hv_cmdline = boot_command_line;
  1272. len = COMMAND_LINE_SIZE;
  1273. }
  1274. len = hv_get_command_line((HV_VirtAddr) hv_cmdline, len);
  1275. if (len < 0 || len > COMMAND_LINE_SIZE)
  1276. early_panic("hv_get_command_line failed: %d\n", len);
  1277. #endif
  1278. *cmdline_p = boot_command_line;
  1279. /* Set disabled_map and setup_max_cpus very early */
  1280. parse_early_param();
  1281. /* Make sure the kernel is compatible with the hypervisor. */
  1282. validate_hv();
  1283. validate_va();
  1284. setup_cpu_maps();
  1285. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1286. /*
  1287. * Initialize the PCI structures. This is done before memory
  1288. * setup so that we know whether or not a pci_reserve region
  1289. * is necessary.
  1290. */
  1291. if (tile_pci_init() == 0)
  1292. pci_reserve_mb = 0;
  1293. /* PCI systems reserve a region just below 4GB for mapping iomem. */
  1294. pci_reserve_end_pfn = (1 << (32 - PAGE_SHIFT));
  1295. pci_reserve_start_pfn = pci_reserve_end_pfn -
  1296. (pci_reserve_mb << (20 - PAGE_SHIFT));
  1297. #endif
  1298. init_mm.start_code = (unsigned long) _text;
  1299. init_mm.end_code = (unsigned long) _etext;
  1300. init_mm.end_data = (unsigned long) _edata;
  1301. init_mm.brk = (unsigned long) _end;
  1302. setup_memory();
  1303. store_permanent_mappings();
  1304. setup_bootmem_allocator();
  1305. /*
  1306. * NOTE: before this point _nobody_ is allowed to allocate
  1307. * any memory using the bootmem allocator.
  1308. */
  1309. #ifdef CONFIG_SWIOTLB
  1310. swiotlb_init(0);
  1311. #endif
  1312. paging_init();
  1313. setup_numa_mapping();
  1314. zone_sizes_init();
  1315. set_page_homes();
  1316. setup_cpu(1);
  1317. setup_clock();
  1318. load_hv_initrd();
  1319. }
  1320. /*
  1321. * Set up per-cpu memory.
  1322. */
  1323. unsigned long __per_cpu_offset[NR_CPUS] __write_once;
  1324. EXPORT_SYMBOL(__per_cpu_offset);
  1325. static size_t __initdata pfn_offset[MAX_NUMNODES] = { 0 };
  1326. static unsigned long __initdata percpu_pfn[NR_CPUS] = { 0 };
  1327. /*
  1328. * As the percpu code allocates pages, we return the pages from the
  1329. * end of the node for the specified cpu.
  1330. */
  1331. static void *__init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
  1332. {
  1333. int nid = cpu_to_node(cpu);
  1334. unsigned long pfn = node_percpu_pfn[nid] + pfn_offset[nid];
  1335. BUG_ON(size % PAGE_SIZE != 0);
  1336. pfn_offset[nid] += size / PAGE_SIZE;
  1337. BUG_ON(node_percpu[nid] < size);
  1338. node_percpu[nid] -= size;
  1339. if (percpu_pfn[cpu] == 0)
  1340. percpu_pfn[cpu] = pfn;
  1341. return pfn_to_kaddr(pfn);
  1342. }
  1343. /*
  1344. * Pages reserved for percpu memory are not freeable, and in any case we are
  1345. * on a short path to panic() in setup_per_cpu_area() at this point anyway.
  1346. */
  1347. static void __init pcpu_fc_free(void *ptr, size_t size)
  1348. {
  1349. }
  1350. /*
  1351. * Set up vmalloc page tables using bootmem for the percpu code.
  1352. */
  1353. static void __init pcpu_fc_populate_pte(unsigned long addr)
  1354. {
  1355. pgd_t *pgd;
  1356. pud_t *pud;
  1357. pmd_t *pmd;
  1358. pte_t *pte;
  1359. BUG_ON(pgd_addr_invalid(addr));
  1360. if (addr < VMALLOC_START || addr >= VMALLOC_END)
  1361. panic("PCPU addr %#lx outside vmalloc range %#lx..%#lx; try increasing CONFIG_VMALLOC_RESERVE\n",
  1362. addr, VMALLOC_START, VMALLOC_END);
  1363. pgd = swapper_pg_dir + pgd_index(addr);
  1364. pud = pud_offset(pgd, addr);
  1365. BUG_ON(!pud_present(*pud));
  1366. pmd = pmd_offset(pud, addr);
  1367. if (pmd_present(*pmd)) {
  1368. BUG_ON(pmd_huge_page(*pmd));
  1369. } else {
  1370. pte = __alloc_bootmem(L2_KERNEL_PGTABLE_SIZE,
  1371. HV_PAGE_TABLE_ALIGN, 0);
  1372. pmd_populate_kernel(&init_mm, pmd, pte);
  1373. }
  1374. }
  1375. void __init setup_per_cpu_areas(void)
  1376. {
  1377. struct page *pg;
  1378. unsigned long delta, pfn, lowmem_va;
  1379. unsigned long size = percpu_size();
  1380. char *ptr;
  1381. int rc, cpu, i;
  1382. rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_fc_alloc,
  1383. pcpu_fc_free, pcpu_fc_populate_pte);
  1384. if (rc < 0)
  1385. panic("Cannot initialize percpu area (err=%d)", rc);
  1386. delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
  1387. for_each_possible_cpu(cpu) {
  1388. __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
  1389. /* finv the copy out of cache so we can change homecache */
  1390. ptr = pcpu_base_addr + pcpu_unit_offsets[cpu];
  1391. __finv_buffer(ptr, size);
  1392. pfn = percpu_pfn[cpu];
  1393. /* Rewrite the page tables to cache on that cpu */
  1394. pg = pfn_to_page(pfn);
  1395. for (i = 0; i < size; i += PAGE_SIZE, ++pfn, ++pg) {
  1396. /* Update the vmalloc mapping and page home. */
  1397. unsigned long addr = (unsigned long)ptr + i;
  1398. pte_t *ptep = virt_to_kpte(addr);
  1399. pte_t pte = *ptep;
  1400. BUG_ON(pfn != pte_pfn(pte));
  1401. pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_TILE_L3);
  1402. pte = set_remote_cache_cpu(pte, cpu);
  1403. set_pte_at(&init_mm, addr, ptep, pte);
  1404. /* Update the lowmem mapping for consistency. */
  1405. lowmem_va = (unsigned long)pfn_to_kaddr(pfn);
  1406. ptep = virt_to_kpte(lowmem_va);
  1407. if (pte_huge(*ptep)) {
  1408. printk(KERN_DEBUG "early shatter of huge page at %#lx\n",
  1409. lowmem_va);
  1410. shatter_pmd((pmd_t *)ptep);
  1411. ptep = virt_to_kpte(lowmem_va);
  1412. BUG_ON(pte_huge(*ptep));
  1413. }
  1414. BUG_ON(pfn != pte_pfn(*ptep));
  1415. set_pte_at(&init_mm, lowmem_va, ptep, pte);
  1416. }
  1417. }
  1418. /* Set our thread pointer appropriately. */
  1419. set_my_cpu_offset(__per_cpu_offset[smp_processor_id()]);
  1420. /* Make sure the finv's have completed. */
  1421. mb_incoherent();
  1422. /* Flush the TLB so we reference it properly from here on out. */
  1423. local_flush_tlb_all();
  1424. }
  1425. static struct resource data_resource = {
  1426. .name = "Kernel data",
  1427. .start = 0,
  1428. .end = 0,
  1429. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  1430. };
  1431. static struct resource code_resource = {
  1432. .name = "Kernel code",
  1433. .start = 0,
  1434. .end = 0,
  1435. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  1436. };
  1437. /*
  1438. * On Pro, we reserve all resources above 4GB so that PCI won't try to put
  1439. * mappings above 4GB.
  1440. */
  1441. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1442. static struct resource* __init
  1443. insert_non_bus_resource(void)
  1444. {
  1445. struct resource *res =
  1446. kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1447. if (!res)
  1448. return NULL;
  1449. res->name = "Non-Bus Physical Address Space";
  1450. res->start = (1ULL << 32);
  1451. res->end = -1LL;
  1452. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  1453. if (insert_resource(&iomem_resource, res)) {
  1454. kfree(res);
  1455. return NULL;
  1456. }
  1457. return res;
  1458. }
  1459. #endif
  1460. static struct resource* __init
  1461. insert_ram_resource(u64 start_pfn, u64 end_pfn, bool reserved)
  1462. {
  1463. struct resource *res =
  1464. kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1465. if (!res)
  1466. return NULL;
  1467. res->start = start_pfn << PAGE_SHIFT;
  1468. res->end = (end_pfn << PAGE_SHIFT) - 1;
  1469. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  1470. if (reserved) {
  1471. res->name = "Reserved";
  1472. } else {
  1473. res->name = "System RAM";
  1474. res->flags |= IORESOURCE_SYSRAM;
  1475. }
  1476. if (insert_resource(&iomem_resource, res)) {
  1477. kfree(res);
  1478. return NULL;
  1479. }
  1480. return res;
  1481. }
  1482. /*
  1483. * Request address space for all standard resources
  1484. *
  1485. * If the system includes PCI root complex drivers, we need to create
  1486. * a window just below 4GB where PCI BARs can be mapped.
  1487. */
  1488. static int __init request_standard_resources(void)
  1489. {
  1490. int i;
  1491. enum { CODE_DELTA = MEM_SV_START - PAGE_OFFSET };
  1492. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1493. insert_non_bus_resource();
  1494. #endif
  1495. for_each_online_node(i) {
  1496. u64 start_pfn = node_start_pfn[i];
  1497. u64 end_pfn = node_end_pfn[i];
  1498. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1499. if (start_pfn <= pci_reserve_start_pfn &&
  1500. end_pfn > pci_reserve_start_pfn) {
  1501. if (end_pfn > pci_reserve_end_pfn)
  1502. insert_ram_resource(pci_reserve_end_pfn,
  1503. end_pfn, 0);
  1504. end_pfn = pci_reserve_start_pfn;
  1505. }
  1506. #endif
  1507. insert_ram_resource(start_pfn, end_pfn, 0);
  1508. }
  1509. code_resource.start = __pa(_text - CODE_DELTA);
  1510. code_resource.end = __pa(_etext - CODE_DELTA)-1;
  1511. data_resource.start = __pa(_sdata);
  1512. data_resource.end = __pa(_end)-1;
  1513. insert_resource(&iomem_resource, &code_resource);
  1514. insert_resource(&iomem_resource, &data_resource);
  1515. /* Mark any "memmap" regions busy for the resource manager. */
  1516. for (i = 0; i < memmap_nr; ++i) {
  1517. struct memmap_entry *m = &memmap_map[i];
  1518. insert_ram_resource(PFN_DOWN(m->addr),
  1519. PFN_UP(m->addr + m->size - 1), 1);
  1520. }
  1521. #ifdef CONFIG_KEXEC
  1522. insert_resource(&iomem_resource, &crashk_res);
  1523. #endif
  1524. return 0;
  1525. }
  1526. subsys_initcall(request_standard_resources);