setup.c 48 KB

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