setup.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  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. unsigned long mb;
  198. if (str == NULL || strict_strtoul(str, 0, &mb) != 0 ||
  199. mb > 3 * 1024)
  200. return -EINVAL;
  201. pci_reserve_mb = mb;
  202. pr_info("Reserving %dMB for PCIE root complex mappings\n",
  203. pci_reserve_mb);
  204. return 0;
  205. }
  206. early_param("pci_reserve", setup_pci_reserve);
  207. #endif
  208. #ifndef __tilegx__
  209. /*
  210. * vmalloc=size forces the vmalloc area to be exactly 'size' bytes.
  211. * This can be used to increase (or decrease) the vmalloc area.
  212. */
  213. static int __init parse_vmalloc(char *arg)
  214. {
  215. if (!arg)
  216. return -EINVAL;
  217. VMALLOC_RESERVE = (memparse(arg, &arg) + PGDIR_SIZE - 1) & PGDIR_MASK;
  218. /* See validate_va() for more on this test. */
  219. if ((long)_VMALLOC_START >= 0)
  220. early_panic("\"vmalloc=%#lx\" value too large: maximum %#lx\n",
  221. VMALLOC_RESERVE, _VMALLOC_END - 0x80000000UL);
  222. return 0;
  223. }
  224. early_param("vmalloc", parse_vmalloc);
  225. #endif
  226. #ifdef CONFIG_HIGHMEM
  227. /*
  228. * Determine for each controller where its lowmem is mapped and how much of
  229. * it is mapped there. On controller zero, the first few megabytes are
  230. * already mapped in as code at MEM_SV_START, so in principle we could
  231. * start our data mappings higher up, but for now we don't bother, to avoid
  232. * additional confusion.
  233. *
  234. * One question is whether, on systems with more than 768 Mb and
  235. * controllers of different sizes, to map in a proportionate amount of
  236. * each one, or to try to map the same amount from each controller.
  237. * (E.g. if we have three controllers with 256MB, 1GB, and 256MB
  238. * respectively, do we map 256MB from each, or do we map 128 MB, 512
  239. * MB, and 128 MB respectively?) For now we use a proportionate
  240. * solution like the latter.
  241. *
  242. * The VA/PA mapping demands that we align our decisions at 16 MB
  243. * boundaries so that we can rapidly convert VA to PA.
  244. */
  245. static void *__init setup_pa_va_mapping(void)
  246. {
  247. unsigned long curr_pages = 0;
  248. unsigned long vaddr = PAGE_OFFSET;
  249. nodemask_t highonlynodes = isolnodes;
  250. int i, j;
  251. memset(pbase_map, -1, sizeof(pbase_map));
  252. memset(vbase_map, -1, sizeof(vbase_map));
  253. /* Node zero cannot be isolated for LOWMEM purposes. */
  254. node_clear(0, highonlynodes);
  255. /* Count up the number of pages on non-highonlynodes controllers. */
  256. mappable_physpages = 0;
  257. for_each_online_node(i) {
  258. if (!node_isset(i, highonlynodes))
  259. mappable_physpages +=
  260. node_end_pfn[i] - node_start_pfn[i];
  261. }
  262. for_each_online_node(i) {
  263. unsigned long start = node_start_pfn[i];
  264. unsigned long end = node_end_pfn[i];
  265. unsigned long size = end - start;
  266. unsigned long vaddr_end;
  267. if (node_isset(i, highonlynodes)) {
  268. /* Mark this controller as having no lowmem. */
  269. node_lowmem_end_pfn[i] = start;
  270. continue;
  271. }
  272. curr_pages += size;
  273. if (mappable_physpages > MAXMEM_PFN) {
  274. vaddr_end = PAGE_OFFSET +
  275. (((u64)curr_pages * MAXMEM_PFN /
  276. mappable_physpages)
  277. << PAGE_SHIFT);
  278. } else {
  279. vaddr_end = PAGE_OFFSET + (curr_pages << PAGE_SHIFT);
  280. }
  281. for (j = 0; vaddr < vaddr_end; vaddr += HPAGE_SIZE, ++j) {
  282. unsigned long this_pfn =
  283. start + (j << HUGETLB_PAGE_ORDER);
  284. pbase_map[vaddr >> HPAGE_SHIFT] = this_pfn;
  285. if (vbase_map[__pfn_to_highbits(this_pfn)] ==
  286. (void *)-1)
  287. vbase_map[__pfn_to_highbits(this_pfn)] =
  288. (void *)(vaddr & HPAGE_MASK);
  289. }
  290. node_lowmem_end_pfn[i] = start + (j << HUGETLB_PAGE_ORDER);
  291. BUG_ON(node_lowmem_end_pfn[i] > end);
  292. }
  293. /* Return highest address of any mapped memory. */
  294. return (void *)vaddr;
  295. }
  296. #endif /* CONFIG_HIGHMEM */
  297. /*
  298. * Register our most important memory mappings with the debug stub.
  299. *
  300. * This is up to 4 mappings for lowmem, one mapping per memory
  301. * controller, plus one for our text segment.
  302. */
  303. static void store_permanent_mappings(void)
  304. {
  305. int i;
  306. for_each_online_node(i) {
  307. HV_PhysAddr pa = ((HV_PhysAddr)node_start_pfn[i]) << PAGE_SHIFT;
  308. #ifdef CONFIG_HIGHMEM
  309. HV_PhysAddr high_mapped_pa = node_lowmem_end_pfn[i];
  310. #else
  311. HV_PhysAddr high_mapped_pa = node_end_pfn[i];
  312. #endif
  313. unsigned long pages = high_mapped_pa - node_start_pfn[i];
  314. HV_VirtAddr addr = (HV_VirtAddr) __va(pa);
  315. hv_store_mapping(addr, pages << PAGE_SHIFT, pa);
  316. }
  317. hv_store_mapping((HV_VirtAddr)_text,
  318. (uint32_t)(_einittext - _text), 0);
  319. }
  320. /*
  321. * Use hv_inquire_physical() to populate node_{start,end}_pfn[]
  322. * and node_online_map, doing suitable sanity-checking.
  323. * Also set min_low_pfn, max_low_pfn, and max_pfn.
  324. */
  325. static void __init setup_memory(void)
  326. {
  327. int i, j;
  328. int highbits_seen[NR_PA_HIGHBIT_VALUES] = { 0 };
  329. #ifdef CONFIG_HIGHMEM
  330. long highmem_pages;
  331. #endif
  332. #ifndef __tilegx__
  333. int cap;
  334. #endif
  335. #if defined(CONFIG_HIGHMEM) || defined(__tilegx__)
  336. long lowmem_pages;
  337. #endif
  338. unsigned long physpages = 0;
  339. /* We are using a char to hold the cpu_2_node[] mapping */
  340. BUILD_BUG_ON(MAX_NUMNODES > 127);
  341. /* Discover the ranges of memory available to us */
  342. for (i = 0; ; ++i) {
  343. unsigned long start, size, end, highbits;
  344. HV_PhysAddrRange range = hv_inquire_physical(i);
  345. if (range.size == 0)
  346. break;
  347. #ifdef CONFIG_FLATMEM
  348. if (i > 0) {
  349. pr_err("Can't use discontiguous PAs: %#llx..%#llx\n",
  350. range.size, range.start + range.size);
  351. continue;
  352. }
  353. #endif
  354. #ifndef __tilegx__
  355. if ((unsigned long)range.start) {
  356. pr_err("Range not at 4GB multiple: %#llx..%#llx\n",
  357. range.start, range.start + range.size);
  358. continue;
  359. }
  360. #endif
  361. if ((range.start & (HPAGE_SIZE-1)) != 0 ||
  362. (range.size & (HPAGE_SIZE-1)) != 0) {
  363. unsigned long long start_pa = range.start;
  364. unsigned long long orig_size = range.size;
  365. range.start = (start_pa + HPAGE_SIZE - 1) & HPAGE_MASK;
  366. range.size -= (range.start - start_pa);
  367. range.size &= HPAGE_MASK;
  368. pr_err("Range not hugepage-aligned: %#llx..%#llx:"
  369. " now %#llx-%#llx\n",
  370. start_pa, start_pa + orig_size,
  371. range.start, range.start + range.size);
  372. }
  373. highbits = __pa_to_highbits(range.start);
  374. if (highbits >= NR_PA_HIGHBIT_VALUES) {
  375. pr_err("PA high bits too high: %#llx..%#llx\n",
  376. range.start, range.start + range.size);
  377. continue;
  378. }
  379. if (highbits_seen[highbits]) {
  380. pr_err("Range overlaps in high bits: %#llx..%#llx\n",
  381. range.start, range.start + range.size);
  382. continue;
  383. }
  384. highbits_seen[highbits] = 1;
  385. if (PFN_DOWN(range.size) > maxnodemem_pfn[i]) {
  386. int max_size = maxnodemem_pfn[i];
  387. if (max_size > 0) {
  388. pr_err("Maxnodemem reduced node %d to"
  389. " %d pages\n", i, max_size);
  390. range.size = PFN_PHYS(max_size);
  391. } else {
  392. pr_err("Maxnodemem disabled node %d\n", i);
  393. continue;
  394. }
  395. }
  396. if (physpages + PFN_DOWN(range.size) > maxmem_pfn) {
  397. int max_size = maxmem_pfn - physpages;
  398. if (max_size > 0) {
  399. pr_err("Maxmem reduced node %d to %d pages\n",
  400. i, max_size);
  401. range.size = PFN_PHYS(max_size);
  402. } else {
  403. pr_err("Maxmem disabled node %d\n", i);
  404. continue;
  405. }
  406. }
  407. if (i >= MAX_NUMNODES) {
  408. pr_err("Too many PA nodes (#%d): %#llx...%#llx\n",
  409. i, range.size, range.size + range.start);
  410. continue;
  411. }
  412. start = range.start >> PAGE_SHIFT;
  413. size = range.size >> PAGE_SHIFT;
  414. end = start + size;
  415. #ifndef __tilegx__
  416. if (((HV_PhysAddr)end << PAGE_SHIFT) !=
  417. (range.start + range.size)) {
  418. pr_err("PAs too high to represent: %#llx..%#llx\n",
  419. range.start, range.start + range.size);
  420. continue;
  421. }
  422. #endif
  423. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  424. /*
  425. * Blocks that overlap the pci reserved region must
  426. * have enough space to hold the maximum percpu data
  427. * region at the top of the range. If there isn't
  428. * enough space above the reserved region, just
  429. * truncate the node.
  430. */
  431. if (start <= pci_reserve_start_pfn &&
  432. end > pci_reserve_start_pfn) {
  433. unsigned int per_cpu_size =
  434. __per_cpu_end - __per_cpu_start;
  435. unsigned int percpu_pages =
  436. NR_CPUS * (PFN_UP(per_cpu_size) >> PAGE_SHIFT);
  437. if (end < pci_reserve_end_pfn + percpu_pages) {
  438. end = pci_reserve_start_pfn;
  439. pr_err("PCI mapping region reduced node %d to"
  440. " %ld pages\n", i, end - start);
  441. }
  442. }
  443. #endif
  444. for (j = __pfn_to_highbits(start);
  445. j <= __pfn_to_highbits(end - 1); j++)
  446. highbits_to_node[j] = i;
  447. node_start_pfn[i] = start;
  448. node_end_pfn[i] = end;
  449. node_controller[i] = range.controller;
  450. physpages += size;
  451. max_pfn = end;
  452. /* Mark node as online */
  453. node_set(i, node_online_map);
  454. node_set(i, node_possible_map);
  455. }
  456. #ifndef __tilegx__
  457. /*
  458. * For 4KB pages, mem_map "struct page" data is 1% of the size
  459. * of the physical memory, so can be quite big (640 MB for
  460. * four 16G zones). These structures must be mapped in
  461. * lowmem, and since we currently cap out at about 768 MB,
  462. * it's impractical to try to use this much address space.
  463. * For now, arbitrarily cap the amount of physical memory
  464. * we're willing to use at 8 million pages (32GB of 4KB pages).
  465. */
  466. cap = 8 * 1024 * 1024; /* 8 million pages */
  467. if (physpages > cap) {
  468. int num_nodes = num_online_nodes();
  469. int cap_each = cap / num_nodes;
  470. unsigned long dropped_pages = 0;
  471. for (i = 0; i < num_nodes; ++i) {
  472. int size = node_end_pfn[i] - node_start_pfn[i];
  473. if (size > cap_each) {
  474. dropped_pages += (size - cap_each);
  475. node_end_pfn[i] = node_start_pfn[i] + cap_each;
  476. }
  477. }
  478. physpages -= dropped_pages;
  479. pr_warning("Only using %ldMB memory;"
  480. " ignoring %ldMB.\n",
  481. physpages >> (20 - PAGE_SHIFT),
  482. dropped_pages >> (20 - PAGE_SHIFT));
  483. pr_warning("Consider using a larger page size.\n");
  484. }
  485. #endif
  486. /* Heap starts just above the last loaded address. */
  487. min_low_pfn = PFN_UP((unsigned long)_end - PAGE_OFFSET);
  488. #ifdef CONFIG_HIGHMEM
  489. /* Find where we map lowmem from each controller. */
  490. high_memory = setup_pa_va_mapping();
  491. /* Set max_low_pfn based on what node 0 can directly address. */
  492. max_low_pfn = node_lowmem_end_pfn[0];
  493. lowmem_pages = (mappable_physpages > MAXMEM_PFN) ?
  494. MAXMEM_PFN : mappable_physpages;
  495. highmem_pages = (long) (physpages - lowmem_pages);
  496. pr_notice("%ldMB HIGHMEM available.\n",
  497. pages_to_mb(highmem_pages > 0 ? highmem_pages : 0));
  498. pr_notice("%ldMB LOWMEM available.\n",
  499. pages_to_mb(lowmem_pages));
  500. #else
  501. /* Set max_low_pfn based on what node 0 can directly address. */
  502. max_low_pfn = node_end_pfn[0];
  503. #ifndef __tilegx__
  504. if (node_end_pfn[0] > MAXMEM_PFN) {
  505. pr_warning("Only using %ldMB LOWMEM.\n",
  506. MAXMEM>>20);
  507. pr_warning("Use a HIGHMEM enabled kernel.\n");
  508. max_low_pfn = MAXMEM_PFN;
  509. max_pfn = MAXMEM_PFN;
  510. node_end_pfn[0] = MAXMEM_PFN;
  511. } else {
  512. pr_notice("%ldMB memory available.\n",
  513. pages_to_mb(node_end_pfn[0]));
  514. }
  515. for (i = 1; i < MAX_NUMNODES; ++i) {
  516. node_start_pfn[i] = 0;
  517. node_end_pfn[i] = 0;
  518. }
  519. high_memory = __va(node_end_pfn[0]);
  520. #else
  521. lowmem_pages = 0;
  522. for (i = 0; i < MAX_NUMNODES; ++i) {
  523. int pages = node_end_pfn[i] - node_start_pfn[i];
  524. lowmem_pages += pages;
  525. if (pages)
  526. high_memory = pfn_to_kaddr(node_end_pfn[i]);
  527. }
  528. pr_notice("%ldMB memory available.\n",
  529. pages_to_mb(lowmem_pages));
  530. #endif
  531. #endif
  532. }
  533. /*
  534. * On 32-bit machines, we only put bootmem on the low controller,
  535. * since PAs > 4GB can't be used in bootmem. In principle one could
  536. * imagine, e.g., multiple 1 GB controllers all of which could support
  537. * bootmem, but in practice using controllers this small isn't a
  538. * particularly interesting scenario, so we just keep it simple and
  539. * use only the first controller for bootmem on 32-bit machines.
  540. */
  541. static inline int node_has_bootmem(int nid)
  542. {
  543. #ifdef CONFIG_64BIT
  544. return 1;
  545. #else
  546. return nid == 0;
  547. #endif
  548. }
  549. static inline unsigned long alloc_bootmem_pfn(int nid,
  550. unsigned long size,
  551. unsigned long goal)
  552. {
  553. void *kva = __alloc_bootmem_node(NODE_DATA(nid), size,
  554. PAGE_SIZE, goal);
  555. unsigned long pfn = kaddr_to_pfn(kva);
  556. BUG_ON(goal && PFN_PHYS(pfn) != goal);
  557. return pfn;
  558. }
  559. static void __init setup_bootmem_allocator_node(int i)
  560. {
  561. unsigned long start, end, mapsize, mapstart;
  562. if (node_has_bootmem(i)) {
  563. NODE_DATA(i)->bdata = &bootmem_node_data[i];
  564. } else {
  565. /* Share controller zero's bdata for now. */
  566. NODE_DATA(i)->bdata = &bootmem_node_data[0];
  567. return;
  568. }
  569. /* Skip up to after the bss in node 0. */
  570. start = (i == 0) ? min_low_pfn : node_start_pfn[i];
  571. /* Only lowmem, if we're a HIGHMEM build. */
  572. #ifdef CONFIG_HIGHMEM
  573. end = node_lowmem_end_pfn[i];
  574. #else
  575. end = node_end_pfn[i];
  576. #endif
  577. /* No memory here. */
  578. if (end == start)
  579. return;
  580. /* Figure out where the bootmem bitmap is located. */
  581. mapsize = bootmem_bootmap_pages(end - start);
  582. if (i == 0) {
  583. /* Use some space right before the heap on node 0. */
  584. mapstart = start;
  585. start += mapsize;
  586. } else {
  587. /* Allocate bitmap on node 0 to avoid page table issues. */
  588. mapstart = alloc_bootmem_pfn(0, PFN_PHYS(mapsize), 0);
  589. }
  590. /* Initialize a node. */
  591. init_bootmem_node(NODE_DATA(i), mapstart, start, end);
  592. /* Free all the space back into the allocator. */
  593. free_bootmem(PFN_PHYS(start), PFN_PHYS(end - start));
  594. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  595. /*
  596. * Throw away any memory aliased by the PCI region.
  597. */
  598. if (pci_reserve_start_pfn < end && pci_reserve_end_pfn > start) {
  599. start = max(pci_reserve_start_pfn, start);
  600. end = min(pci_reserve_end_pfn, end);
  601. reserve_bootmem(PFN_PHYS(start), PFN_PHYS(end - start),
  602. BOOTMEM_EXCLUSIVE);
  603. }
  604. #endif
  605. }
  606. static void __init setup_bootmem_allocator(void)
  607. {
  608. int i;
  609. for (i = 0; i < MAX_NUMNODES; ++i)
  610. setup_bootmem_allocator_node(i);
  611. /* Reserve any memory excluded by "memmap" arguments. */
  612. for (i = 0; i < memmap_nr; ++i) {
  613. struct memmap_entry *m = &memmap_map[i];
  614. reserve_bootmem(m->addr, m->size, 0);
  615. }
  616. #ifdef CONFIG_BLK_DEV_INITRD
  617. if (initrd_start) {
  618. /* Make sure the initrd memory region is not modified. */
  619. if (reserve_bootmem(initrd_start, initrd_end - initrd_start,
  620. BOOTMEM_EXCLUSIVE)) {
  621. pr_crit("The initrd memory region has been polluted. Disabling it.\n");
  622. initrd_start = 0;
  623. initrd_end = 0;
  624. } else {
  625. /*
  626. * Translate initrd_start & initrd_end from PA to VA for
  627. * future access.
  628. */
  629. initrd_start += PAGE_OFFSET;
  630. initrd_end += PAGE_OFFSET;
  631. }
  632. }
  633. #endif
  634. #ifdef CONFIG_KEXEC
  635. if (crashk_res.start != crashk_res.end)
  636. reserve_bootmem(crashk_res.start, resource_size(&crashk_res), 0);
  637. #endif
  638. }
  639. void *__init alloc_remap(int nid, unsigned long size)
  640. {
  641. int pages = node_end_pfn[nid] - node_start_pfn[nid];
  642. void *map = pfn_to_kaddr(node_memmap_pfn[nid]);
  643. BUG_ON(size != pages * sizeof(struct page));
  644. memset(map, 0, size);
  645. return map;
  646. }
  647. static int __init percpu_size(void)
  648. {
  649. int size = __per_cpu_end - __per_cpu_start;
  650. size += PERCPU_MODULE_RESERVE;
  651. size += PERCPU_DYNAMIC_EARLY_SIZE;
  652. if (size < PCPU_MIN_UNIT_SIZE)
  653. size = PCPU_MIN_UNIT_SIZE;
  654. size = roundup(size, PAGE_SIZE);
  655. /* In several places we assume the per-cpu data fits on a huge page. */
  656. BUG_ON(kdata_huge && size > HPAGE_SIZE);
  657. return size;
  658. }
  659. static void __init zone_sizes_init(void)
  660. {
  661. unsigned long zones_size[MAX_NR_ZONES] = { 0 };
  662. int size = percpu_size();
  663. int num_cpus = smp_height * smp_width;
  664. const unsigned long dma_end = (1UL << (32 - PAGE_SHIFT));
  665. int i;
  666. for (i = 0; i < num_cpus; ++i)
  667. node_percpu[cpu_to_node(i)] += size;
  668. for_each_online_node(i) {
  669. unsigned long start = node_start_pfn[i];
  670. unsigned long end = node_end_pfn[i];
  671. #ifdef CONFIG_HIGHMEM
  672. unsigned long lowmem_end = node_lowmem_end_pfn[i];
  673. #else
  674. unsigned long lowmem_end = end;
  675. #endif
  676. int memmap_size = (end - start) * sizeof(struct page);
  677. node_free_pfn[i] = start;
  678. /*
  679. * Set aside pages for per-cpu data and the mem_map array.
  680. *
  681. * Since the per-cpu data requires special homecaching,
  682. * if we are in kdata_huge mode, we put it at the end of
  683. * the lowmem region. If we're not in kdata_huge mode,
  684. * we take the per-cpu pages from the bottom of the
  685. * controller, since that avoids fragmenting a huge page
  686. * that users might want. We always take the memmap
  687. * from the bottom of the controller, since with
  688. * kdata_huge that lets it be under a huge TLB entry.
  689. *
  690. * If the user has requested isolnodes for a controller,
  691. * though, there'll be no lowmem, so we just alloc_bootmem
  692. * the memmap. There will be no percpu memory either.
  693. */
  694. if (i != 0 && cpu_isset(i, isolnodes)) {
  695. node_memmap_pfn[i] =
  696. alloc_bootmem_pfn(0, memmap_size, 0);
  697. BUG_ON(node_percpu[i] != 0);
  698. } else if (node_has_bootmem(start)) {
  699. unsigned long goal = 0;
  700. node_memmap_pfn[i] =
  701. alloc_bootmem_pfn(i, memmap_size, 0);
  702. if (kdata_huge)
  703. goal = PFN_PHYS(lowmem_end) - node_percpu[i];
  704. if (node_percpu[i])
  705. node_percpu_pfn[i] =
  706. alloc_bootmem_pfn(i, node_percpu[i],
  707. goal);
  708. } else {
  709. /* In non-bootmem zones, just reserve some pages. */
  710. node_memmap_pfn[i] = node_free_pfn[i];
  711. node_free_pfn[i] += PFN_UP(memmap_size);
  712. if (!kdata_huge) {
  713. node_percpu_pfn[i] = node_free_pfn[i];
  714. node_free_pfn[i] += PFN_UP(node_percpu[i]);
  715. } else {
  716. node_percpu_pfn[i] =
  717. lowmem_end - PFN_UP(node_percpu[i]);
  718. }
  719. }
  720. #ifdef CONFIG_HIGHMEM
  721. if (start > lowmem_end) {
  722. zones_size[ZONE_NORMAL] = 0;
  723. zones_size[ZONE_HIGHMEM] = end - start;
  724. } else {
  725. zones_size[ZONE_NORMAL] = lowmem_end - start;
  726. zones_size[ZONE_HIGHMEM] = end - lowmem_end;
  727. }
  728. #else
  729. zones_size[ZONE_NORMAL] = end - start;
  730. #endif
  731. if (start < dma_end) {
  732. zones_size[ZONE_DMA] = min(zones_size[ZONE_NORMAL],
  733. dma_end - start);
  734. zones_size[ZONE_NORMAL] -= zones_size[ZONE_DMA];
  735. } else {
  736. zones_size[ZONE_DMA] = 0;
  737. }
  738. /* Take zone metadata from controller 0 if we're isolnode. */
  739. if (node_isset(i, isolnodes))
  740. NODE_DATA(i)->bdata = &bootmem_node_data[0];
  741. free_area_init_node(i, zones_size, start, NULL);
  742. printk(KERN_DEBUG " Normal zone: %ld per-cpu pages\n",
  743. PFN_UP(node_percpu[i]));
  744. /* Track the type of memory on each node */
  745. if (zones_size[ZONE_NORMAL] || zones_size[ZONE_DMA])
  746. node_set_state(i, N_NORMAL_MEMORY);
  747. #ifdef CONFIG_HIGHMEM
  748. if (end != start)
  749. node_set_state(i, N_HIGH_MEMORY);
  750. #endif
  751. node_set_online(i);
  752. }
  753. }
  754. #ifdef CONFIG_NUMA
  755. /* which logical CPUs are on which nodes */
  756. struct cpumask node_2_cpu_mask[MAX_NUMNODES] __write_once;
  757. EXPORT_SYMBOL(node_2_cpu_mask);
  758. /* which node each logical CPU is on */
  759. char cpu_2_node[NR_CPUS] __write_once __attribute__((aligned(L2_CACHE_BYTES)));
  760. EXPORT_SYMBOL(cpu_2_node);
  761. /* Return cpu_to_node() except for cpus not yet assigned, which return -1 */
  762. static int __init cpu_to_bound_node(int cpu, struct cpumask* unbound_cpus)
  763. {
  764. if (!cpu_possible(cpu) || cpumask_test_cpu(cpu, unbound_cpus))
  765. return -1;
  766. else
  767. return cpu_to_node(cpu);
  768. }
  769. /* Return number of immediately-adjacent tiles sharing the same NUMA node. */
  770. static int __init node_neighbors(int node, int cpu,
  771. struct cpumask *unbound_cpus)
  772. {
  773. int neighbors = 0;
  774. int w = smp_width;
  775. int h = smp_height;
  776. int x = cpu % w;
  777. int y = cpu / w;
  778. if (x > 0 && cpu_to_bound_node(cpu-1, unbound_cpus) == node)
  779. ++neighbors;
  780. if (x < w-1 && cpu_to_bound_node(cpu+1, unbound_cpus) == node)
  781. ++neighbors;
  782. if (y > 0 && cpu_to_bound_node(cpu-w, unbound_cpus) == node)
  783. ++neighbors;
  784. if (y < h-1 && cpu_to_bound_node(cpu+w, unbound_cpus) == node)
  785. ++neighbors;
  786. return neighbors;
  787. }
  788. static void __init setup_numa_mapping(void)
  789. {
  790. int distance[MAX_NUMNODES][NR_CPUS];
  791. HV_Coord coord;
  792. int cpu, node, cpus, i, x, y;
  793. int num_nodes = num_online_nodes();
  794. struct cpumask unbound_cpus;
  795. nodemask_t default_nodes;
  796. cpumask_clear(&unbound_cpus);
  797. /* Get set of nodes we will use for defaults */
  798. nodes_andnot(default_nodes, node_online_map, isolnodes);
  799. if (nodes_empty(default_nodes)) {
  800. BUG_ON(!node_isset(0, node_online_map));
  801. pr_err("Forcing NUMA node zero available as a default node\n");
  802. node_set(0, default_nodes);
  803. }
  804. /* Populate the distance[] array */
  805. memset(distance, -1, sizeof(distance));
  806. cpu = 0;
  807. for (coord.y = 0; coord.y < smp_height; ++coord.y) {
  808. for (coord.x = 0; coord.x < smp_width;
  809. ++coord.x, ++cpu) {
  810. BUG_ON(cpu >= nr_cpu_ids);
  811. if (!cpu_possible(cpu)) {
  812. cpu_2_node[cpu] = -1;
  813. continue;
  814. }
  815. for_each_node_mask(node, default_nodes) {
  816. HV_MemoryControllerInfo info =
  817. hv_inquire_memory_controller(
  818. coord, node_controller[node]);
  819. distance[node][cpu] =
  820. ABS(info.coord.x) + ABS(info.coord.y);
  821. }
  822. cpumask_set_cpu(cpu, &unbound_cpus);
  823. }
  824. }
  825. cpus = cpu;
  826. /*
  827. * Round-robin through the NUMA nodes until all the cpus are
  828. * assigned. We could be more clever here (e.g. create four
  829. * sorted linked lists on the same set of cpu nodes, and pull
  830. * off them in round-robin sequence, removing from all four
  831. * lists each time) but given the relatively small numbers
  832. * involved, O(n^2) seem OK for a one-time cost.
  833. */
  834. node = first_node(default_nodes);
  835. while (!cpumask_empty(&unbound_cpus)) {
  836. int best_cpu = -1;
  837. int best_distance = INT_MAX;
  838. for (cpu = 0; cpu < cpus; ++cpu) {
  839. if (cpumask_test_cpu(cpu, &unbound_cpus)) {
  840. /*
  841. * Compute metric, which is how much
  842. * closer the cpu is to this memory
  843. * controller than the others, shifted
  844. * up, and then the number of
  845. * neighbors already in the node as an
  846. * epsilon adjustment to try to keep
  847. * the nodes compact.
  848. */
  849. int d = distance[node][cpu] * num_nodes;
  850. for_each_node_mask(i, default_nodes) {
  851. if (i != node)
  852. d -= distance[i][cpu];
  853. }
  854. d *= 8; /* allow space for epsilon */
  855. d -= node_neighbors(node, cpu, &unbound_cpus);
  856. if (d < best_distance) {
  857. best_cpu = cpu;
  858. best_distance = d;
  859. }
  860. }
  861. }
  862. BUG_ON(best_cpu < 0);
  863. cpumask_set_cpu(best_cpu, &node_2_cpu_mask[node]);
  864. cpu_2_node[best_cpu] = node;
  865. cpumask_clear_cpu(best_cpu, &unbound_cpus);
  866. node = next_node(node, default_nodes);
  867. if (node == MAX_NUMNODES)
  868. node = first_node(default_nodes);
  869. }
  870. /* Print out node assignments and set defaults for disabled cpus */
  871. cpu = 0;
  872. for (y = 0; y < smp_height; ++y) {
  873. printk(KERN_DEBUG "NUMA cpu-to-node row %d:", y);
  874. for (x = 0; x < smp_width; ++x, ++cpu) {
  875. if (cpu_to_node(cpu) < 0) {
  876. pr_cont(" -");
  877. cpu_2_node[cpu] = first_node(default_nodes);
  878. } else {
  879. pr_cont(" %d", cpu_to_node(cpu));
  880. }
  881. }
  882. pr_cont("\n");
  883. }
  884. }
  885. static struct cpu cpu_devices[NR_CPUS];
  886. static int __init topology_init(void)
  887. {
  888. int i;
  889. for_each_online_node(i)
  890. register_one_node(i);
  891. for (i = 0; i < smp_height * smp_width; ++i)
  892. register_cpu(&cpu_devices[i], i);
  893. return 0;
  894. }
  895. subsys_initcall(topology_init);
  896. #else /* !CONFIG_NUMA */
  897. #define setup_numa_mapping() do { } while (0)
  898. #endif /* CONFIG_NUMA */
  899. /*
  900. * Initialize hugepage support on this cpu. We do this on all cores
  901. * early in boot: before argument parsing for the boot cpu, and after
  902. * argument parsing but before the init functions run on the secondaries.
  903. * So the values we set up here in the hypervisor may be overridden on
  904. * the boot cpu as arguments are parsed.
  905. */
  906. static void init_super_pages(void)
  907. {
  908. #ifdef CONFIG_HUGETLB_SUPER_PAGES
  909. int i;
  910. for (i = 0; i < HUGE_SHIFT_ENTRIES; ++i)
  911. hv_set_pte_super_shift(i, huge_shift[i]);
  912. #endif
  913. }
  914. /**
  915. * setup_cpu() - Do all necessary per-cpu, tile-specific initialization.
  916. * @boot: Is this the boot cpu?
  917. *
  918. * Called from setup_arch() on the boot cpu, or online_secondary().
  919. */
  920. void setup_cpu(int boot)
  921. {
  922. /* The boot cpu sets up its permanent mappings much earlier. */
  923. if (!boot)
  924. store_permanent_mappings();
  925. /* Allow asynchronous TLB interrupts. */
  926. #if CHIP_HAS_TILE_DMA()
  927. arch_local_irq_unmask(INT_DMATLB_MISS);
  928. arch_local_irq_unmask(INT_DMATLB_ACCESS);
  929. #endif
  930. #ifdef __tilegx__
  931. arch_local_irq_unmask(INT_SINGLE_STEP_K);
  932. #endif
  933. /*
  934. * Allow user access to many generic SPRs, like the cycle
  935. * counter, PASS/FAIL/DONE, INTERRUPT_CRITICAL_SECTION, etc.
  936. */
  937. __insn_mtspr(SPR_MPL_WORLD_ACCESS_SET_0, 1);
  938. #if CHIP_HAS_SN()
  939. /* Static network is not restricted. */
  940. __insn_mtspr(SPR_MPL_SN_ACCESS_SET_0, 1);
  941. #endif
  942. /*
  943. * Set the MPL for interrupt control 0 & 1 to the corresponding
  944. * values. This includes access to the SYSTEM_SAVE and EX_CONTEXT
  945. * SPRs, as well as the interrupt mask.
  946. */
  947. __insn_mtspr(SPR_MPL_INTCTRL_0_SET_0, 1);
  948. __insn_mtspr(SPR_MPL_INTCTRL_1_SET_1, 1);
  949. /* Initialize IRQ support for this cpu. */
  950. setup_irq_regs();
  951. #ifdef CONFIG_HARDWALL
  952. /* Reset the network state on this cpu. */
  953. reset_network_state();
  954. #endif
  955. init_super_pages();
  956. }
  957. #ifdef CONFIG_BLK_DEV_INITRD
  958. static int __initdata set_initramfs_file;
  959. static char __initdata initramfs_file[128] = "initramfs";
  960. static int __init setup_initramfs_file(char *str)
  961. {
  962. if (str == NULL)
  963. return -EINVAL;
  964. strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
  965. set_initramfs_file = 1;
  966. return 0;
  967. }
  968. early_param("initramfs_file", setup_initramfs_file);
  969. /*
  970. * We look for a file called "initramfs" in the hvfs. If there is one, we
  971. * allocate some memory for it and it will be unpacked to the initramfs.
  972. * If it's compressed, the initd code will uncompress it first.
  973. */
  974. static void __init load_hv_initrd(void)
  975. {
  976. HV_FS_StatInfo stat;
  977. int fd, rc;
  978. void *initrd;
  979. /* If initrd has already been set, skip initramfs file in hvfs. */
  980. if (initrd_start)
  981. return;
  982. fd = hv_fs_findfile((HV_VirtAddr) initramfs_file);
  983. if (fd == HV_ENOENT) {
  984. if (set_initramfs_file) {
  985. pr_warning("No such hvfs initramfs file '%s'\n",
  986. initramfs_file);
  987. return;
  988. } else {
  989. /* Try old backwards-compatible name. */
  990. fd = hv_fs_findfile((HV_VirtAddr)"initramfs.cpio.gz");
  991. if (fd == HV_ENOENT)
  992. return;
  993. }
  994. }
  995. BUG_ON(fd < 0);
  996. stat = hv_fs_fstat(fd);
  997. BUG_ON(stat.size < 0);
  998. if (stat.flags & HV_FS_ISDIR) {
  999. pr_warning("Ignoring hvfs file '%s': it's a directory.\n",
  1000. initramfs_file);
  1001. return;
  1002. }
  1003. initrd = alloc_bootmem_pages(stat.size);
  1004. rc = hv_fs_pread(fd, (HV_VirtAddr) initrd, stat.size, 0);
  1005. if (rc != stat.size) {
  1006. pr_err("Error reading %d bytes from hvfs file '%s': %d\n",
  1007. stat.size, initramfs_file, rc);
  1008. free_initrd_mem((unsigned long) initrd, stat.size);
  1009. return;
  1010. }
  1011. initrd_start = (unsigned long) initrd;
  1012. initrd_end = initrd_start + stat.size;
  1013. }
  1014. void __init free_initrd_mem(unsigned long begin, unsigned long end)
  1015. {
  1016. free_bootmem(__pa(begin), end - begin);
  1017. }
  1018. static int __init setup_initrd(char *str)
  1019. {
  1020. char *endp;
  1021. unsigned long initrd_size;
  1022. initrd_size = str ? simple_strtoul(str, &endp, 0) : 0;
  1023. if (initrd_size == 0 || *endp != '@')
  1024. return -EINVAL;
  1025. initrd_start = simple_strtoul(endp+1, &endp, 0);
  1026. if (initrd_start == 0)
  1027. return -EINVAL;
  1028. initrd_end = initrd_start + initrd_size;
  1029. return 0;
  1030. }
  1031. early_param("initrd", setup_initrd);
  1032. #else
  1033. static inline void load_hv_initrd(void) {}
  1034. #endif /* CONFIG_BLK_DEV_INITRD */
  1035. static void __init validate_hv(void)
  1036. {
  1037. /*
  1038. * It may already be too late, but let's check our built-in
  1039. * configuration against what the hypervisor is providing.
  1040. */
  1041. unsigned long glue_size = hv_sysconf(HV_SYSCONF_GLUE_SIZE);
  1042. int hv_page_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL);
  1043. int hv_hpage_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE);
  1044. HV_ASIDRange asid_range;
  1045. #ifndef CONFIG_SMP
  1046. HV_Topology topology = hv_inquire_topology();
  1047. BUG_ON(topology.coord.x != 0 || topology.coord.y != 0);
  1048. if (topology.width != 1 || topology.height != 1) {
  1049. pr_warning("Warning: booting UP kernel on %dx%d grid;"
  1050. " will ignore all but first tile.\n",
  1051. topology.width, topology.height);
  1052. }
  1053. #endif
  1054. if (PAGE_OFFSET + HV_GLUE_START_CPA + glue_size > (unsigned long)_text)
  1055. early_panic("Hypervisor glue size %ld is too big!\n",
  1056. glue_size);
  1057. if (hv_page_size != PAGE_SIZE)
  1058. early_panic("Hypervisor page size %#x != our %#lx\n",
  1059. hv_page_size, PAGE_SIZE);
  1060. if (hv_hpage_size != HPAGE_SIZE)
  1061. early_panic("Hypervisor huge page size %#x != our %#lx\n",
  1062. hv_hpage_size, HPAGE_SIZE);
  1063. #ifdef CONFIG_SMP
  1064. /*
  1065. * Some hypervisor APIs take a pointer to a bitmap array
  1066. * whose size is at least the number of cpus on the chip.
  1067. * We use a struct cpumask for this, so it must be big enough.
  1068. */
  1069. if ((smp_height * smp_width) > nr_cpu_ids)
  1070. early_panic("Hypervisor %d x %d grid too big for Linux"
  1071. " NR_CPUS %d\n", smp_height, smp_width,
  1072. nr_cpu_ids);
  1073. #endif
  1074. /*
  1075. * Check that we're using allowed ASIDs, and initialize the
  1076. * various asid variables to their appropriate initial states.
  1077. */
  1078. asid_range = hv_inquire_asid(0);
  1079. __get_cpu_var(current_asid) = min_asid = asid_range.start;
  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);