setup.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728
  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. __get_cpu_var(current_asid) = min_asid = asid_range.start;
  1079. max_asid = asid_range.start + asid_range.size - 1;
  1080. if (hv_confstr(HV_CONFSTR_CHIP_MODEL, (HV_VirtAddr)chip_model,
  1081. sizeof(chip_model)) < 0) {
  1082. pr_err("Warning: HV_CONFSTR_CHIP_MODEL not available\n");
  1083. strlcpy(chip_model, "unknown", sizeof(chip_model));
  1084. }
  1085. }
  1086. static void __init validate_va(void)
  1087. {
  1088. #ifndef __tilegx__ /* FIXME: GX: probably some validation relevant here */
  1089. /*
  1090. * Similarly, make sure we're only using allowed VAs.
  1091. * We assume we can contiguously use MEM_USER_INTRPT .. MEM_HV_START,
  1092. * and 0 .. KERNEL_HIGH_VADDR.
  1093. * In addition, make sure we CAN'T use the end of memory, since
  1094. * we use the last chunk of each pgd for the pgd_list.
  1095. */
  1096. int i, user_kernel_ok = 0;
  1097. unsigned long max_va = 0;
  1098. unsigned long list_va =
  1099. ((PGD_LIST_OFFSET / sizeof(pgd_t)) << PGDIR_SHIFT);
  1100. for (i = 0; ; ++i) {
  1101. HV_VirtAddrRange range = hv_inquire_virtual(i);
  1102. if (range.size == 0)
  1103. break;
  1104. if (range.start <= MEM_USER_INTRPT &&
  1105. range.start + range.size >= MEM_HV_START)
  1106. user_kernel_ok = 1;
  1107. if (range.start == 0)
  1108. max_va = range.size;
  1109. BUG_ON(range.start + range.size > list_va);
  1110. }
  1111. if (!user_kernel_ok)
  1112. early_panic("Hypervisor not configured for user/kernel VAs\n");
  1113. if (max_va == 0)
  1114. early_panic("Hypervisor not configured for low VAs\n");
  1115. if (max_va < KERNEL_HIGH_VADDR)
  1116. early_panic("Hypervisor max VA %#lx smaller than %#lx\n",
  1117. max_va, KERNEL_HIGH_VADDR);
  1118. /* Kernel PCs must have their high bit set; see intvec.S. */
  1119. if ((long)VMALLOC_START >= 0)
  1120. early_panic(
  1121. "Linux VMALLOC region below the 2GB line (%#lx)!\n"
  1122. "Reconfigure the kernel with smaller VMALLOC_RESERVE.\n",
  1123. VMALLOC_START);
  1124. #endif
  1125. }
  1126. /*
  1127. * cpu_lotar_map lists all the cpus that are valid for the supervisor
  1128. * to cache data on at a page level, i.e. what cpus can be placed in
  1129. * the LOTAR field of a PTE. It is equivalent to the set of possible
  1130. * cpus plus any other cpus that are willing to share their cache.
  1131. * It is set by hv_inquire_tiles(HV_INQ_TILES_LOTAR).
  1132. */
  1133. struct cpumask __write_once cpu_lotar_map;
  1134. EXPORT_SYMBOL(cpu_lotar_map);
  1135. /*
  1136. * hash_for_home_map lists all the tiles that hash-for-home data
  1137. * will be cached on. Note that this may includes tiles that are not
  1138. * valid for this supervisor to use otherwise (e.g. if a hypervisor
  1139. * device is being shared between multiple supervisors).
  1140. * It is set by hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE).
  1141. */
  1142. struct cpumask hash_for_home_map;
  1143. EXPORT_SYMBOL(hash_for_home_map);
  1144. /*
  1145. * cpu_cacheable_map lists all the cpus whose caches the hypervisor can
  1146. * flush on our behalf. It is set to cpu_possible_mask OR'ed with
  1147. * hash_for_home_map, and it is what should be passed to
  1148. * hv_flush_remote() to flush all caches. Note that if there are
  1149. * dedicated hypervisor driver tiles that have authorized use of their
  1150. * cache, those tiles will only appear in cpu_lotar_map, NOT in
  1151. * cpu_cacheable_map, as they are a special case.
  1152. */
  1153. struct cpumask __write_once cpu_cacheable_map;
  1154. EXPORT_SYMBOL(cpu_cacheable_map);
  1155. static __initdata struct cpumask disabled_map;
  1156. static int __init disabled_cpus(char *str)
  1157. {
  1158. int boot_cpu = smp_processor_id();
  1159. if (str == NULL || cpulist_parse_crop(str, &disabled_map) != 0)
  1160. return -EINVAL;
  1161. if (cpumask_test_cpu(boot_cpu, &disabled_map)) {
  1162. pr_err("disabled_cpus: can't disable boot cpu %d\n", boot_cpu);
  1163. cpumask_clear_cpu(boot_cpu, &disabled_map);
  1164. }
  1165. return 0;
  1166. }
  1167. early_param("disabled_cpus", disabled_cpus);
  1168. void __init print_disabled_cpus(void)
  1169. {
  1170. if (!cpumask_empty(&disabled_map)) {
  1171. char buf[100];
  1172. cpulist_scnprintf(buf, sizeof(buf), &disabled_map);
  1173. pr_info("CPUs not available for Linux: %s\n", buf);
  1174. }
  1175. }
  1176. static void __init setup_cpu_maps(void)
  1177. {
  1178. struct cpumask hv_disabled_map, cpu_possible_init;
  1179. int boot_cpu = smp_processor_id();
  1180. int cpus, i, rc;
  1181. /* Learn which cpus are allowed by the hypervisor. */
  1182. rc = hv_inquire_tiles(HV_INQ_TILES_AVAIL,
  1183. (HV_VirtAddr) cpumask_bits(&cpu_possible_init),
  1184. sizeof(cpu_cacheable_map));
  1185. if (rc < 0)
  1186. early_panic("hv_inquire_tiles(AVAIL) failed: rc %d\n", rc);
  1187. if (!cpumask_test_cpu(boot_cpu, &cpu_possible_init))
  1188. early_panic("Boot CPU %d disabled by hypervisor!\n", boot_cpu);
  1189. /* Compute the cpus disabled by the hvconfig file. */
  1190. cpumask_complement(&hv_disabled_map, &cpu_possible_init);
  1191. /* Include them with the cpus disabled by "disabled_cpus". */
  1192. cpumask_or(&disabled_map, &disabled_map, &hv_disabled_map);
  1193. /*
  1194. * Disable every cpu after "setup_max_cpus". But don't mark
  1195. * as disabled the cpus that are outside of our initial rectangle,
  1196. * since that turns out to be confusing.
  1197. */
  1198. cpus = 1; /* this cpu */
  1199. cpumask_set_cpu(boot_cpu, &disabled_map); /* ignore this cpu */
  1200. for (i = 0; cpus < setup_max_cpus; ++i)
  1201. if (!cpumask_test_cpu(i, &disabled_map))
  1202. ++cpus;
  1203. for (; i < smp_height * smp_width; ++i)
  1204. cpumask_set_cpu(i, &disabled_map);
  1205. cpumask_clear_cpu(boot_cpu, &disabled_map); /* reset this cpu */
  1206. for (i = smp_height * smp_width; i < NR_CPUS; ++i)
  1207. cpumask_clear_cpu(i, &disabled_map);
  1208. /*
  1209. * Setup cpu_possible map as every cpu allocated to us, minus
  1210. * the results of any "disabled_cpus" settings.
  1211. */
  1212. cpumask_andnot(&cpu_possible_init, &cpu_possible_init, &disabled_map);
  1213. init_cpu_possible(&cpu_possible_init);
  1214. /* Learn which cpus are valid for LOTAR caching. */
  1215. rc = hv_inquire_tiles(HV_INQ_TILES_LOTAR,
  1216. (HV_VirtAddr) cpumask_bits(&cpu_lotar_map),
  1217. sizeof(cpu_lotar_map));
  1218. if (rc < 0) {
  1219. pr_err("warning: no HV_INQ_TILES_LOTAR; using AVAIL\n");
  1220. cpu_lotar_map = *cpu_possible_mask;
  1221. }
  1222. /* Retrieve set of CPUs used for hash-for-home caching */
  1223. rc = hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE,
  1224. (HV_VirtAddr) hash_for_home_map.bits,
  1225. sizeof(hash_for_home_map));
  1226. if (rc < 0)
  1227. early_panic("hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc);
  1228. cpumask_or(&cpu_cacheable_map, cpu_possible_mask, &hash_for_home_map);
  1229. }
  1230. static int __init dataplane(char *str)
  1231. {
  1232. pr_warning("WARNING: dataplane support disabled in this kernel\n");
  1233. return 0;
  1234. }
  1235. early_param("dataplane", dataplane);
  1236. #ifdef CONFIG_CMDLINE_BOOL
  1237. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  1238. #endif
  1239. void __init setup_arch(char **cmdline_p)
  1240. {
  1241. int len;
  1242. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  1243. len = hv_get_command_line((HV_VirtAddr) boot_command_line,
  1244. COMMAND_LINE_SIZE);
  1245. if (boot_command_line[0])
  1246. pr_warning("WARNING: ignoring dynamic command line \"%s\"\n",
  1247. boot_command_line);
  1248. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  1249. #else
  1250. char *hv_cmdline;
  1251. #if defined(CONFIG_CMDLINE_BOOL)
  1252. if (builtin_cmdline[0]) {
  1253. int builtin_len = strlcpy(boot_command_line, builtin_cmdline,
  1254. COMMAND_LINE_SIZE);
  1255. if (builtin_len < COMMAND_LINE_SIZE-1)
  1256. boot_command_line[builtin_len++] = ' ';
  1257. hv_cmdline = &boot_command_line[builtin_len];
  1258. len = COMMAND_LINE_SIZE - builtin_len;
  1259. } else
  1260. #endif
  1261. {
  1262. hv_cmdline = boot_command_line;
  1263. len = COMMAND_LINE_SIZE;
  1264. }
  1265. len = hv_get_command_line((HV_VirtAddr) hv_cmdline, len);
  1266. if (len < 0 || len > COMMAND_LINE_SIZE)
  1267. early_panic("hv_get_command_line failed: %d\n", len);
  1268. #endif
  1269. *cmdline_p = boot_command_line;
  1270. /* Set disabled_map and setup_max_cpus very early */
  1271. parse_early_param();
  1272. /* Make sure the kernel is compatible with the hypervisor. */
  1273. validate_hv();
  1274. validate_va();
  1275. setup_cpu_maps();
  1276. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1277. /*
  1278. * Initialize the PCI structures. This is done before memory
  1279. * setup so that we know whether or not a pci_reserve region
  1280. * is necessary.
  1281. */
  1282. if (tile_pci_init() == 0)
  1283. pci_reserve_mb = 0;
  1284. /* PCI systems reserve a region just below 4GB for mapping iomem. */
  1285. pci_reserve_end_pfn = (1 << (32 - PAGE_SHIFT));
  1286. pci_reserve_start_pfn = pci_reserve_end_pfn -
  1287. (pci_reserve_mb << (20 - PAGE_SHIFT));
  1288. #endif
  1289. init_mm.start_code = (unsigned long) _text;
  1290. init_mm.end_code = (unsigned long) _etext;
  1291. init_mm.end_data = (unsigned long) _edata;
  1292. init_mm.brk = (unsigned long) _end;
  1293. setup_memory();
  1294. store_permanent_mappings();
  1295. setup_bootmem_allocator();
  1296. /*
  1297. * NOTE: before this point _nobody_ is allowed to allocate
  1298. * any memory using the bootmem allocator.
  1299. */
  1300. #ifdef CONFIG_SWIOTLB
  1301. swiotlb_init(0);
  1302. #endif
  1303. paging_init();
  1304. setup_numa_mapping();
  1305. zone_sizes_init();
  1306. set_page_homes();
  1307. setup_cpu(1);
  1308. setup_clock();
  1309. load_hv_initrd();
  1310. }
  1311. /*
  1312. * Set up per-cpu memory.
  1313. */
  1314. unsigned long __per_cpu_offset[NR_CPUS] __write_once;
  1315. EXPORT_SYMBOL(__per_cpu_offset);
  1316. static size_t __initdata pfn_offset[MAX_NUMNODES] = { 0 };
  1317. static unsigned long __initdata percpu_pfn[NR_CPUS] = { 0 };
  1318. /*
  1319. * As the percpu code allocates pages, we return the pages from the
  1320. * end of the node for the specified cpu.
  1321. */
  1322. static void *__init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
  1323. {
  1324. int nid = cpu_to_node(cpu);
  1325. unsigned long pfn = node_percpu_pfn[nid] + pfn_offset[nid];
  1326. BUG_ON(size % PAGE_SIZE != 0);
  1327. pfn_offset[nid] += size / PAGE_SIZE;
  1328. BUG_ON(node_percpu[nid] < size);
  1329. node_percpu[nid] -= size;
  1330. if (percpu_pfn[cpu] == 0)
  1331. percpu_pfn[cpu] = pfn;
  1332. return pfn_to_kaddr(pfn);
  1333. }
  1334. /*
  1335. * Pages reserved for percpu memory are not freeable, and in any case we are
  1336. * on a short path to panic() in setup_per_cpu_area() at this point anyway.
  1337. */
  1338. static void __init pcpu_fc_free(void *ptr, size_t size)
  1339. {
  1340. }
  1341. /*
  1342. * Set up vmalloc page tables using bootmem for the percpu code.
  1343. */
  1344. static void __init pcpu_fc_populate_pte(unsigned long addr)
  1345. {
  1346. pgd_t *pgd;
  1347. pud_t *pud;
  1348. pmd_t *pmd;
  1349. pte_t *pte;
  1350. BUG_ON(pgd_addr_invalid(addr));
  1351. if (addr < VMALLOC_START || addr >= VMALLOC_END)
  1352. panic("PCPU addr %#lx outside vmalloc range %#lx..%#lx;"
  1353. " try increasing CONFIG_VMALLOC_RESERVE\n",
  1354. addr, VMALLOC_START, VMALLOC_END);
  1355. pgd = swapper_pg_dir + pgd_index(addr);
  1356. pud = pud_offset(pgd, addr);
  1357. BUG_ON(!pud_present(*pud));
  1358. pmd = pmd_offset(pud, addr);
  1359. if (pmd_present(*pmd)) {
  1360. BUG_ON(pmd_huge_page(*pmd));
  1361. } else {
  1362. pte = __alloc_bootmem(L2_KERNEL_PGTABLE_SIZE,
  1363. HV_PAGE_TABLE_ALIGN, 0);
  1364. pmd_populate_kernel(&init_mm, pmd, pte);
  1365. }
  1366. }
  1367. void __init setup_per_cpu_areas(void)
  1368. {
  1369. struct page *pg;
  1370. unsigned long delta, pfn, lowmem_va;
  1371. unsigned long size = percpu_size();
  1372. char *ptr;
  1373. int rc, cpu, i;
  1374. rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_fc_alloc,
  1375. pcpu_fc_free, pcpu_fc_populate_pte);
  1376. if (rc < 0)
  1377. panic("Cannot initialize percpu area (err=%d)", rc);
  1378. delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
  1379. for_each_possible_cpu(cpu) {
  1380. __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
  1381. /* finv the copy out of cache so we can change homecache */
  1382. ptr = pcpu_base_addr + pcpu_unit_offsets[cpu];
  1383. __finv_buffer(ptr, size);
  1384. pfn = percpu_pfn[cpu];
  1385. /* Rewrite the page tables to cache on that cpu */
  1386. pg = pfn_to_page(pfn);
  1387. for (i = 0; i < size; i += PAGE_SIZE, ++pfn, ++pg) {
  1388. /* Update the vmalloc mapping and page home. */
  1389. unsigned long addr = (unsigned long)ptr + i;
  1390. pte_t *ptep = virt_to_kpte(addr);
  1391. pte_t pte = *ptep;
  1392. BUG_ON(pfn != pte_pfn(pte));
  1393. pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_TILE_L3);
  1394. pte = set_remote_cache_cpu(pte, cpu);
  1395. set_pte_at(&init_mm, addr, ptep, pte);
  1396. /* Update the lowmem mapping for consistency. */
  1397. lowmem_va = (unsigned long)pfn_to_kaddr(pfn);
  1398. ptep = virt_to_kpte(lowmem_va);
  1399. if (pte_huge(*ptep)) {
  1400. printk(KERN_DEBUG "early shatter of huge page"
  1401. " at %#lx\n", lowmem_va);
  1402. shatter_pmd((pmd_t *)ptep);
  1403. ptep = virt_to_kpte(lowmem_va);
  1404. BUG_ON(pte_huge(*ptep));
  1405. }
  1406. BUG_ON(pfn != pte_pfn(*ptep));
  1407. set_pte_at(&init_mm, lowmem_va, ptep, pte);
  1408. }
  1409. }
  1410. /* Set our thread pointer appropriately. */
  1411. set_my_cpu_offset(__per_cpu_offset[smp_processor_id()]);
  1412. /* Make sure the finv's have completed. */
  1413. mb_incoherent();
  1414. /* Flush the TLB so we reference it properly from here on out. */
  1415. local_flush_tlb_all();
  1416. }
  1417. static struct resource data_resource = {
  1418. .name = "Kernel data",
  1419. .start = 0,
  1420. .end = 0,
  1421. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  1422. };
  1423. static struct resource code_resource = {
  1424. .name = "Kernel code",
  1425. .start = 0,
  1426. .end = 0,
  1427. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  1428. };
  1429. /*
  1430. * On Pro, we reserve all resources above 4GB so that PCI won't try to put
  1431. * mappings above 4GB.
  1432. */
  1433. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1434. static struct resource* __init
  1435. insert_non_bus_resource(void)
  1436. {
  1437. struct resource *res =
  1438. kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1439. if (!res)
  1440. return NULL;
  1441. res->name = "Non-Bus Physical Address Space";
  1442. res->start = (1ULL << 32);
  1443. res->end = -1LL;
  1444. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  1445. if (insert_resource(&iomem_resource, res)) {
  1446. kfree(res);
  1447. return NULL;
  1448. }
  1449. return res;
  1450. }
  1451. #endif
  1452. static struct resource* __init
  1453. insert_ram_resource(u64 start_pfn, u64 end_pfn, bool reserved)
  1454. {
  1455. struct resource *res =
  1456. kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1457. if (!res)
  1458. return NULL;
  1459. res->name = reserved ? "Reserved" : "System RAM";
  1460. res->start = start_pfn << PAGE_SHIFT;
  1461. res->end = (end_pfn << PAGE_SHIFT) - 1;
  1462. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  1463. if (insert_resource(&iomem_resource, res)) {
  1464. kfree(res);
  1465. return NULL;
  1466. }
  1467. return res;
  1468. }
  1469. /*
  1470. * Request address space for all standard resources
  1471. *
  1472. * If the system includes PCI root complex drivers, we need to create
  1473. * a window just below 4GB where PCI BARs can be mapped.
  1474. */
  1475. static int __init request_standard_resources(void)
  1476. {
  1477. int i;
  1478. enum { CODE_DELTA = MEM_SV_START - PAGE_OFFSET };
  1479. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1480. insert_non_bus_resource();
  1481. #endif
  1482. for_each_online_node(i) {
  1483. u64 start_pfn = node_start_pfn[i];
  1484. u64 end_pfn = node_end_pfn[i];
  1485. #if defined(CONFIG_PCI) && !defined(__tilegx__)
  1486. if (start_pfn <= pci_reserve_start_pfn &&
  1487. end_pfn > pci_reserve_start_pfn) {
  1488. if (end_pfn > pci_reserve_end_pfn)
  1489. insert_ram_resource(pci_reserve_end_pfn,
  1490. end_pfn, 0);
  1491. end_pfn = pci_reserve_start_pfn;
  1492. }
  1493. #endif
  1494. insert_ram_resource(start_pfn, end_pfn, 0);
  1495. }
  1496. code_resource.start = __pa(_text - CODE_DELTA);
  1497. code_resource.end = __pa(_etext - CODE_DELTA)-1;
  1498. data_resource.start = __pa(_sdata);
  1499. data_resource.end = __pa(_end)-1;
  1500. insert_resource(&iomem_resource, &code_resource);
  1501. insert_resource(&iomem_resource, &data_resource);
  1502. /* Mark any "memmap" regions busy for the resource manager. */
  1503. for (i = 0; i < memmap_nr; ++i) {
  1504. struct memmap_entry *m = &memmap_map[i];
  1505. insert_ram_resource(PFN_DOWN(m->addr),
  1506. PFN_UP(m->addr + m->size - 1), 1);
  1507. }
  1508. #ifdef CONFIG_KEXEC
  1509. insert_resource(&iomem_resource, &crashk_res);
  1510. #endif
  1511. return 0;
  1512. }
  1513. subsys_initcall(request_standard_resources);