setup.c 48 KB

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