setup.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  1. /*
  2. * linux/arch/i386/kernel/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. *
  6. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  7. *
  8. * Memory region support
  9. * David Parsons <orc@pell.chi.il.us>, July-August 1999
  10. *
  11. * Added E820 sanitization routine (removes overlapping memory regions);
  12. * Brian Moyle <bmoyle@mvista.com>, February 2001
  13. *
  14. * Moved CPU detection code to cpu/${cpu}.c
  15. * Patrick Mochel <mochel@osdl.org>, March 2002
  16. *
  17. * Provisions for empty E820 memory regions (reported by certain BIOSes).
  18. * Alex Achenbach <xela@slit.de>, December 2002.
  19. *
  20. */
  21. /*
  22. * This file handles the architecture-dependent parts of initialization
  23. */
  24. #include <linux/config.h>
  25. #include <linux/sched.h>
  26. #include <linux/mm.h>
  27. #include <linux/mmzone.h>
  28. #include <linux/tty.h>
  29. #include <linux/ioport.h>
  30. #include <linux/acpi.h>
  31. #include <linux/apm_bios.h>
  32. #include <linux/initrd.h>
  33. #include <linux/bootmem.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/console.h>
  36. #include <linux/mca.h>
  37. #include <linux/root_dev.h>
  38. #include <linux/highmem.h>
  39. #include <linux/module.h>
  40. #include <linux/efi.h>
  41. #include <linux/init.h>
  42. #include <linux/edd.h>
  43. #include <linux/nodemask.h>
  44. #include <linux/kexec.h>
  45. #include <linux/crash_dump.h>
  46. #include <linux/dmi.h>
  47. #include <linux/pfn.h>
  48. #include <video/edid.h>
  49. #include <asm/apic.h>
  50. #include <asm/e820.h>
  51. #include <asm/mpspec.h>
  52. #include <asm/setup.h>
  53. #include <asm/arch_hooks.h>
  54. #include <asm/sections.h>
  55. #include <asm/io_apic.h>
  56. #include <asm/ist.h>
  57. #include <asm/io.h>
  58. #include "setup_arch_pre.h"
  59. #include <bios_ebda.h>
  60. /* Forward Declaration. */
  61. void __init find_max_pfn(void);
  62. /* This value is set up by the early boot code to point to the value
  63. immediately after the boot time page tables. It contains a *physical*
  64. address, and must not be in the .bss segment! */
  65. unsigned long init_pg_tables_end __initdata = ~0UL;
  66. int disable_pse __devinitdata = 0;
  67. /*
  68. * Machine setup..
  69. */
  70. #ifdef CONFIG_EFI
  71. int efi_enabled = 0;
  72. EXPORT_SYMBOL(efi_enabled);
  73. #endif
  74. /* cpu data as detected by the assembly code in head.S */
  75. struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  76. /* common cpu data for all cpus */
  77. struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
  78. EXPORT_SYMBOL(boot_cpu_data);
  79. unsigned long mmu_cr4_features;
  80. #ifdef CONFIG_ACPI
  81. int acpi_disabled = 0;
  82. #else
  83. int acpi_disabled = 1;
  84. #endif
  85. EXPORT_SYMBOL(acpi_disabled);
  86. #ifdef CONFIG_ACPI
  87. int __initdata acpi_force = 0;
  88. extern acpi_interrupt_flags acpi_sci_flags;
  89. #endif
  90. /* for MCA, but anyone else can use it if they want */
  91. unsigned int machine_id;
  92. #ifdef CONFIG_MCA
  93. EXPORT_SYMBOL(machine_id);
  94. #endif
  95. unsigned int machine_submodel_id;
  96. unsigned int BIOS_revision;
  97. unsigned int mca_pentium_flag;
  98. /* For PCI or other memory-mapped resources */
  99. unsigned long pci_mem_start = 0x10000000;
  100. #ifdef CONFIG_PCI
  101. EXPORT_SYMBOL(pci_mem_start);
  102. #endif
  103. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  104. int bootloader_type;
  105. /* user-defined highmem size */
  106. static unsigned int highmem_pages = -1;
  107. /*
  108. * Setup options
  109. */
  110. struct drive_info_struct { char dummy[32]; } drive_info;
  111. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || \
  112. defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
  113. EXPORT_SYMBOL(drive_info);
  114. #endif
  115. struct screen_info screen_info;
  116. EXPORT_SYMBOL(screen_info);
  117. struct apm_info apm_info;
  118. EXPORT_SYMBOL(apm_info);
  119. struct sys_desc_table_struct {
  120. unsigned short length;
  121. unsigned char table[0];
  122. };
  123. struct edid_info edid_info;
  124. EXPORT_SYMBOL_GPL(edid_info);
  125. struct ist_info ist_info;
  126. #if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
  127. defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
  128. EXPORT_SYMBOL(ist_info);
  129. #endif
  130. struct e820map e820;
  131. extern void early_cpu_init(void);
  132. extern void generic_apic_probe(char *);
  133. extern int root_mountflags;
  134. unsigned long saved_videomode;
  135. #define RAMDISK_IMAGE_START_MASK 0x07FF
  136. #define RAMDISK_PROMPT_FLAG 0x8000
  137. #define RAMDISK_LOAD_FLAG 0x4000
  138. static char command_line[COMMAND_LINE_SIZE];
  139. unsigned char __initdata boot_params[PARAM_SIZE];
  140. static struct resource data_resource = {
  141. .name = "Kernel data",
  142. .start = 0,
  143. .end = 0,
  144. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  145. };
  146. static struct resource code_resource = {
  147. .name = "Kernel code",
  148. .start = 0,
  149. .end = 0,
  150. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  151. };
  152. static struct resource system_rom_resource = {
  153. .name = "System ROM",
  154. .start = 0xf0000,
  155. .end = 0xfffff,
  156. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  157. };
  158. static struct resource extension_rom_resource = {
  159. .name = "Extension ROM",
  160. .start = 0xe0000,
  161. .end = 0xeffff,
  162. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  163. };
  164. static struct resource adapter_rom_resources[] = { {
  165. .name = "Adapter ROM",
  166. .start = 0xc8000,
  167. .end = 0,
  168. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  169. }, {
  170. .name = "Adapter ROM",
  171. .start = 0,
  172. .end = 0,
  173. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  174. }, {
  175. .name = "Adapter ROM",
  176. .start = 0,
  177. .end = 0,
  178. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  179. }, {
  180. .name = "Adapter ROM",
  181. .start = 0,
  182. .end = 0,
  183. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  184. }, {
  185. .name = "Adapter ROM",
  186. .start = 0,
  187. .end = 0,
  188. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  189. }, {
  190. .name = "Adapter ROM",
  191. .start = 0,
  192. .end = 0,
  193. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  194. } };
  195. #define ADAPTER_ROM_RESOURCES \
  196. (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
  197. static struct resource video_rom_resource = {
  198. .name = "Video ROM",
  199. .start = 0xc0000,
  200. .end = 0xc7fff,
  201. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  202. };
  203. static struct resource video_ram_resource = {
  204. .name = "Video RAM area",
  205. .start = 0xa0000,
  206. .end = 0xbffff,
  207. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  208. };
  209. static struct resource standard_io_resources[] = { {
  210. .name = "dma1",
  211. .start = 0x0000,
  212. .end = 0x001f,
  213. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  214. }, {
  215. .name = "pic1",
  216. .start = 0x0020,
  217. .end = 0x0021,
  218. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  219. }, {
  220. .name = "timer0",
  221. .start = 0x0040,
  222. .end = 0x0043,
  223. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  224. }, {
  225. .name = "timer1",
  226. .start = 0x0050,
  227. .end = 0x0053,
  228. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  229. }, {
  230. .name = "keyboard",
  231. .start = 0x0060,
  232. .end = 0x006f,
  233. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  234. }, {
  235. .name = "dma page reg",
  236. .start = 0x0080,
  237. .end = 0x008f,
  238. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  239. }, {
  240. .name = "pic2",
  241. .start = 0x00a0,
  242. .end = 0x00a1,
  243. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  244. }, {
  245. .name = "dma2",
  246. .start = 0x00c0,
  247. .end = 0x00df,
  248. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  249. }, {
  250. .name = "fpu",
  251. .start = 0x00f0,
  252. .end = 0x00ff,
  253. .flags = IORESOURCE_BUSY | IORESOURCE_IO
  254. } };
  255. #define STANDARD_IO_RESOURCES \
  256. (sizeof standard_io_resources / sizeof standard_io_resources[0])
  257. #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
  258. static int __init romchecksum(unsigned char *rom, unsigned long length)
  259. {
  260. unsigned char *p, sum = 0;
  261. for (p = rom; p < rom + length; p++)
  262. sum += *p;
  263. return sum == 0;
  264. }
  265. static void __init probe_roms(void)
  266. {
  267. unsigned long start, length, upper;
  268. unsigned char *rom;
  269. int i;
  270. /* video rom */
  271. upper = adapter_rom_resources[0].start;
  272. for (start = video_rom_resource.start; start < upper; start += 2048) {
  273. rom = isa_bus_to_virt(start);
  274. if (!romsignature(rom))
  275. continue;
  276. video_rom_resource.start = start;
  277. /* 0 < length <= 0x7f * 512, historically */
  278. length = rom[2] * 512;
  279. /* if checksum okay, trust length byte */
  280. if (length && romchecksum(rom, length))
  281. video_rom_resource.end = start + length - 1;
  282. request_resource(&iomem_resource, &video_rom_resource);
  283. break;
  284. }
  285. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  286. if (start < upper)
  287. start = upper;
  288. /* system rom */
  289. request_resource(&iomem_resource, &system_rom_resource);
  290. upper = system_rom_resource.start;
  291. /* check for extension rom (ignore length byte!) */
  292. rom = isa_bus_to_virt(extension_rom_resource.start);
  293. if (romsignature(rom)) {
  294. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  295. if (romchecksum(rom, length)) {
  296. request_resource(&iomem_resource, &extension_rom_resource);
  297. upper = extension_rom_resource.start;
  298. }
  299. }
  300. /* check for adapter roms on 2k boundaries */
  301. for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
  302. rom = isa_bus_to_virt(start);
  303. if (!romsignature(rom))
  304. continue;
  305. /* 0 < length <= 0x7f * 512, historically */
  306. length = rom[2] * 512;
  307. /* but accept any length that fits if checksum okay */
  308. if (!length || start + length > upper || !romchecksum(rom, length))
  309. continue;
  310. adapter_rom_resources[i].start = start;
  311. adapter_rom_resources[i].end = start + length - 1;
  312. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  313. start = adapter_rom_resources[i++].end & ~2047UL;
  314. }
  315. }
  316. static void __init limit_regions(unsigned long long size)
  317. {
  318. unsigned long long current_addr = 0;
  319. int i;
  320. if (efi_enabled) {
  321. efi_memory_desc_t *md;
  322. void *p;
  323. for (p = memmap.map, i = 0; p < memmap.map_end;
  324. p += memmap.desc_size, i++) {
  325. md = p;
  326. current_addr = md->phys_addr + (md->num_pages << 12);
  327. if (md->type == EFI_CONVENTIONAL_MEMORY) {
  328. if (current_addr >= size) {
  329. md->num_pages -=
  330. (((current_addr-size) + PAGE_SIZE-1) >> PAGE_SHIFT);
  331. memmap.nr_map = i + 1;
  332. return;
  333. }
  334. }
  335. }
  336. }
  337. for (i = 0; i < e820.nr_map; i++) {
  338. current_addr = e820.map[i].addr + e820.map[i].size;
  339. if (current_addr < size)
  340. continue;
  341. if (e820.map[i].type != E820_RAM)
  342. continue;
  343. if (e820.map[i].addr >= size) {
  344. /*
  345. * This region starts past the end of the
  346. * requested size, skip it completely.
  347. */
  348. e820.nr_map = i;
  349. } else {
  350. e820.nr_map = i + 1;
  351. e820.map[i].size -= current_addr - size;
  352. }
  353. return;
  354. }
  355. }
  356. static void __init add_memory_region(unsigned long long start,
  357. unsigned long long size, int type)
  358. {
  359. int x;
  360. if (!efi_enabled) {
  361. x = e820.nr_map;
  362. if (x == E820MAX) {
  363. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  364. return;
  365. }
  366. e820.map[x].addr = start;
  367. e820.map[x].size = size;
  368. e820.map[x].type = type;
  369. e820.nr_map++;
  370. }
  371. } /* add_memory_region */
  372. #define E820_DEBUG 1
  373. static void __init print_memory_map(char *who)
  374. {
  375. int i;
  376. for (i = 0; i < e820.nr_map; i++) {
  377. printk(" %s: %016Lx - %016Lx ", who,
  378. e820.map[i].addr,
  379. e820.map[i].addr + e820.map[i].size);
  380. switch (e820.map[i].type) {
  381. case E820_RAM: printk("(usable)\n");
  382. break;
  383. case E820_RESERVED:
  384. printk("(reserved)\n");
  385. break;
  386. case E820_ACPI:
  387. printk("(ACPI data)\n");
  388. break;
  389. case E820_NVS:
  390. printk("(ACPI NVS)\n");
  391. break;
  392. default: printk("type %lu\n", e820.map[i].type);
  393. break;
  394. }
  395. }
  396. }
  397. /*
  398. * Sanitize the BIOS e820 map.
  399. *
  400. * Some e820 responses include overlapping entries. The following
  401. * replaces the original e820 map with a new one, removing overlaps.
  402. *
  403. */
  404. struct change_member {
  405. struct e820entry *pbios; /* pointer to original bios entry */
  406. unsigned long long addr; /* address for this change point */
  407. };
  408. static struct change_member change_point_list[2*E820MAX] __initdata;
  409. static struct change_member *change_point[2*E820MAX] __initdata;
  410. static struct e820entry *overlap_list[E820MAX] __initdata;
  411. static struct e820entry new_bios[E820MAX] __initdata;
  412. static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
  413. {
  414. struct change_member *change_tmp;
  415. unsigned long current_type, last_type;
  416. unsigned long long last_addr;
  417. int chgidx, still_changing;
  418. int overlap_entries;
  419. int new_bios_entry;
  420. int old_nr, new_nr, chg_nr;
  421. int i;
  422. /*
  423. Visually we're performing the following (1,2,3,4 = memory types)...
  424. Sample memory map (w/overlaps):
  425. ____22__________________
  426. ______________________4_
  427. ____1111________________
  428. _44_____________________
  429. 11111111________________
  430. ____________________33__
  431. ___________44___________
  432. __________33333_________
  433. ______________22________
  434. ___________________2222_
  435. _________111111111______
  436. _____________________11_
  437. _________________4______
  438. Sanitized equivalent (no overlap):
  439. 1_______________________
  440. _44_____________________
  441. ___1____________________
  442. ____22__________________
  443. ______11________________
  444. _________1______________
  445. __________3_____________
  446. ___________44___________
  447. _____________33_________
  448. _______________2________
  449. ________________1_______
  450. _________________4______
  451. ___________________2____
  452. ____________________33__
  453. ______________________4_
  454. */
  455. /* if there's only one memory region, don't bother */
  456. if (*pnr_map < 2)
  457. return -1;
  458. old_nr = *pnr_map;
  459. /* bail out if we find any unreasonable addresses in bios map */
  460. for (i=0; i<old_nr; i++)
  461. if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
  462. return -1;
  463. /* create pointers for initial change-point information (for sorting) */
  464. for (i=0; i < 2*old_nr; i++)
  465. change_point[i] = &change_point_list[i];
  466. /* record all known change-points (starting and ending addresses),
  467. omitting those that are for empty memory regions */
  468. chgidx = 0;
  469. for (i=0; i < old_nr; i++) {
  470. if (biosmap[i].size != 0) {
  471. change_point[chgidx]->addr = biosmap[i].addr;
  472. change_point[chgidx++]->pbios = &biosmap[i];
  473. change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
  474. change_point[chgidx++]->pbios = &biosmap[i];
  475. }
  476. }
  477. chg_nr = chgidx; /* true number of change-points */
  478. /* sort change-point list by memory addresses (low -> high) */
  479. still_changing = 1;
  480. while (still_changing) {
  481. still_changing = 0;
  482. for (i=1; i < chg_nr; i++) {
  483. /* if <current_addr> > <last_addr>, swap */
  484. /* or, if current=<start_addr> & last=<end_addr>, swap */
  485. if ((change_point[i]->addr < change_point[i-1]->addr) ||
  486. ((change_point[i]->addr == change_point[i-1]->addr) &&
  487. (change_point[i]->addr == change_point[i]->pbios->addr) &&
  488. (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
  489. )
  490. {
  491. change_tmp = change_point[i];
  492. change_point[i] = change_point[i-1];
  493. change_point[i-1] = change_tmp;
  494. still_changing=1;
  495. }
  496. }
  497. }
  498. /* create a new bios memory map, removing overlaps */
  499. overlap_entries=0; /* number of entries in the overlap table */
  500. new_bios_entry=0; /* index for creating new bios map entries */
  501. last_type = 0; /* start with undefined memory type */
  502. last_addr = 0; /* start with 0 as last starting address */
  503. /* loop through change-points, determining affect on the new bios map */
  504. for (chgidx=0; chgidx < chg_nr; chgidx++)
  505. {
  506. /* keep track of all overlapping bios entries */
  507. if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
  508. {
  509. /* add map entry to overlap list (> 1 entry implies an overlap) */
  510. overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
  511. }
  512. else
  513. {
  514. /* remove entry from list (order independent, so swap with last) */
  515. for (i=0; i<overlap_entries; i++)
  516. {
  517. if (overlap_list[i] == change_point[chgidx]->pbios)
  518. overlap_list[i] = overlap_list[overlap_entries-1];
  519. }
  520. overlap_entries--;
  521. }
  522. /* if there are overlapping entries, decide which "type" to use */
  523. /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
  524. current_type = 0;
  525. for (i=0; i<overlap_entries; i++)
  526. if (overlap_list[i]->type > current_type)
  527. current_type = overlap_list[i]->type;
  528. /* continue building up new bios map based on this information */
  529. if (current_type != last_type) {
  530. if (last_type != 0) {
  531. new_bios[new_bios_entry].size =
  532. change_point[chgidx]->addr - last_addr;
  533. /* move forward only if the new size was non-zero */
  534. if (new_bios[new_bios_entry].size != 0)
  535. if (++new_bios_entry >= E820MAX)
  536. break; /* no more space left for new bios entries */
  537. }
  538. if (current_type != 0) {
  539. new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
  540. new_bios[new_bios_entry].type = current_type;
  541. last_addr=change_point[chgidx]->addr;
  542. }
  543. last_type = current_type;
  544. }
  545. }
  546. new_nr = new_bios_entry; /* retain count for new bios entries */
  547. /* copy new bios mapping into original location */
  548. memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
  549. *pnr_map = new_nr;
  550. return 0;
  551. }
  552. /*
  553. * Copy the BIOS e820 map into a safe place.
  554. *
  555. * Sanity-check it while we're at it..
  556. *
  557. * If we're lucky and live on a modern system, the setup code
  558. * will have given us a memory map that we can use to properly
  559. * set up memory. If we aren't, we'll fake a memory map.
  560. *
  561. * We check to see that the memory map contains at least 2 elements
  562. * before we'll use it, because the detection code in setup.S may
  563. * not be perfect and most every PC known to man has two memory
  564. * regions: one from 0 to 640k, and one from 1mb up. (The IBM
  565. * thinkpad 560x, for example, does not cooperate with the memory
  566. * detection code.)
  567. */
  568. static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
  569. {
  570. /* Only one memory region (or negative)? Ignore it */
  571. if (nr_map < 2)
  572. return -1;
  573. do {
  574. unsigned long long start = biosmap->addr;
  575. unsigned long long size = biosmap->size;
  576. unsigned long long end = start + size;
  577. unsigned long type = biosmap->type;
  578. /* Overflow in 64 bits? Ignore the memory map. */
  579. if (start > end)
  580. return -1;
  581. /*
  582. * Some BIOSes claim RAM in the 640k - 1M region.
  583. * Not right. Fix it up.
  584. */
  585. if (type == E820_RAM) {
  586. if (start < 0x100000ULL && end > 0xA0000ULL) {
  587. if (start < 0xA0000ULL)
  588. add_memory_region(start, 0xA0000ULL-start, type);
  589. if (end <= 0x100000ULL)
  590. continue;
  591. start = 0x100000ULL;
  592. size = end - start;
  593. }
  594. }
  595. add_memory_region(start, size, type);
  596. } while (biosmap++,--nr_map);
  597. return 0;
  598. }
  599. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  600. struct edd edd;
  601. #ifdef CONFIG_EDD_MODULE
  602. EXPORT_SYMBOL(edd);
  603. #endif
  604. /**
  605. * copy_edd() - Copy the BIOS EDD information
  606. * from boot_params into a safe place.
  607. *
  608. */
  609. static inline void copy_edd(void)
  610. {
  611. memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
  612. memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
  613. edd.mbr_signature_nr = EDD_MBR_SIG_NR;
  614. edd.edd_info_nr = EDD_NR;
  615. }
  616. #else
  617. static inline void copy_edd(void)
  618. {
  619. }
  620. #endif
  621. /*
  622. * Do NOT EVER look at the BIOS memory size location.
  623. * It does not work on many machines.
  624. */
  625. #define LOWMEMSIZE() (0x9f000)
  626. static void __init parse_cmdline_early (char ** cmdline_p)
  627. {
  628. char c = ' ', *to = command_line, *from = saved_command_line;
  629. int len = 0;
  630. int userdef = 0;
  631. /* Save unparsed command line copy for /proc/cmdline */
  632. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  633. for (;;) {
  634. if (c != ' ')
  635. goto next_char;
  636. /*
  637. * "mem=nopentium" disables the 4MB page tables.
  638. * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
  639. * to <mem>, overriding the bios size.
  640. * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
  641. * <start> to <start>+<mem>, overriding the bios size.
  642. *
  643. * HPA tells me bootloaders need to parse mem=, so no new
  644. * option should be mem= [also see Documentation/i386/boot.txt]
  645. */
  646. if (!memcmp(from, "mem=", 4)) {
  647. if (to != command_line)
  648. to--;
  649. if (!memcmp(from+4, "nopentium", 9)) {
  650. from += 9+4;
  651. clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
  652. disable_pse = 1;
  653. } else {
  654. /* If the user specifies memory size, we
  655. * limit the BIOS-provided memory map to
  656. * that size. exactmap can be used to specify
  657. * the exact map. mem=number can be used to
  658. * trim the existing memory map.
  659. */
  660. unsigned long long mem_size;
  661. mem_size = memparse(from+4, &from);
  662. limit_regions(mem_size);
  663. userdef=1;
  664. }
  665. }
  666. else if (!memcmp(from, "memmap=", 7)) {
  667. if (to != command_line)
  668. to--;
  669. if (!memcmp(from+7, "exactmap", 8)) {
  670. #ifdef CONFIG_CRASH_DUMP
  671. /* If we are doing a crash dump, we
  672. * still need to know the real mem
  673. * size before original memory map is
  674. * reset.
  675. */
  676. find_max_pfn();
  677. saved_max_pfn = max_pfn;
  678. #endif
  679. from += 8+7;
  680. e820.nr_map = 0;
  681. userdef = 1;
  682. } else {
  683. /* If the user specifies memory size, we
  684. * limit the BIOS-provided memory map to
  685. * that size. exactmap can be used to specify
  686. * the exact map. mem=number can be used to
  687. * trim the existing memory map.
  688. */
  689. unsigned long long start_at, mem_size;
  690. mem_size = memparse(from+7, &from);
  691. if (*from == '@') {
  692. start_at = memparse(from+1, &from);
  693. add_memory_region(start_at, mem_size, E820_RAM);
  694. } else if (*from == '#') {
  695. start_at = memparse(from+1, &from);
  696. add_memory_region(start_at, mem_size, E820_ACPI);
  697. } else if (*from == '$') {
  698. start_at = memparse(from+1, &from);
  699. add_memory_region(start_at, mem_size, E820_RESERVED);
  700. } else {
  701. limit_regions(mem_size);
  702. userdef=1;
  703. }
  704. }
  705. }
  706. else if (!memcmp(from, "noexec=", 7))
  707. noexec_setup(from + 7);
  708. #ifdef CONFIG_X86_SMP
  709. /*
  710. * If the BIOS enumerates physical processors before logical,
  711. * maxcpus=N at enumeration-time can be used to disable HT.
  712. */
  713. else if (!memcmp(from, "maxcpus=", 8)) {
  714. extern unsigned int maxcpus;
  715. maxcpus = simple_strtoul(from + 8, NULL, 0);
  716. }
  717. #endif
  718. #ifdef CONFIG_ACPI
  719. /* "acpi=off" disables both ACPI table parsing and interpreter */
  720. else if (!memcmp(from, "acpi=off", 8)) {
  721. disable_acpi();
  722. }
  723. /* acpi=force to over-ride black-list */
  724. else if (!memcmp(from, "acpi=force", 10)) {
  725. acpi_force = 1;
  726. acpi_ht = 1;
  727. acpi_disabled = 0;
  728. }
  729. /* acpi=strict disables out-of-spec workarounds */
  730. else if (!memcmp(from, "acpi=strict", 11)) {
  731. acpi_strict = 1;
  732. }
  733. /* Limit ACPI just to boot-time to enable HT */
  734. else if (!memcmp(from, "acpi=ht", 7)) {
  735. if (!acpi_force)
  736. disable_acpi();
  737. acpi_ht = 1;
  738. }
  739. /* "pci=noacpi" disable ACPI IRQ routing and PCI scan */
  740. else if (!memcmp(from, "pci=noacpi", 10)) {
  741. acpi_disable_pci();
  742. }
  743. /* "acpi=noirq" disables ACPI interrupt routing */
  744. else if (!memcmp(from, "acpi=noirq", 10)) {
  745. acpi_noirq_set();
  746. }
  747. else if (!memcmp(from, "acpi_sci=edge", 13))
  748. acpi_sci_flags.trigger = 1;
  749. else if (!memcmp(from, "acpi_sci=level", 14))
  750. acpi_sci_flags.trigger = 3;
  751. else if (!memcmp(from, "acpi_sci=high", 13))
  752. acpi_sci_flags.polarity = 1;
  753. else if (!memcmp(from, "acpi_sci=low", 12))
  754. acpi_sci_flags.polarity = 3;
  755. #ifdef CONFIG_X86_IO_APIC
  756. else if (!memcmp(from, "acpi_skip_timer_override", 24))
  757. acpi_skip_timer_override = 1;
  758. if (!memcmp(from, "disable_timer_pin_1", 19))
  759. disable_timer_pin_1 = 1;
  760. if (!memcmp(from, "enable_timer_pin_1", 18))
  761. disable_timer_pin_1 = -1;
  762. /* disable IO-APIC */
  763. else if (!memcmp(from, "noapic", 6))
  764. disable_ioapic_setup();
  765. #endif /* CONFIG_X86_IO_APIC */
  766. #endif /* CONFIG_ACPI */
  767. #ifdef CONFIG_X86_LOCAL_APIC
  768. /* enable local APIC */
  769. else if (!memcmp(from, "lapic", 5))
  770. lapic_enable();
  771. /* disable local APIC */
  772. else if (!memcmp(from, "nolapic", 6))
  773. lapic_disable();
  774. #endif /* CONFIG_X86_LOCAL_APIC */
  775. #ifdef CONFIG_KEXEC
  776. /* crashkernel=size@addr specifies the location to reserve for
  777. * a crash kernel. By reserving this memory we guarantee
  778. * that linux never set's it up as a DMA target.
  779. * Useful for holding code to do something appropriate
  780. * after a kernel panic.
  781. */
  782. else if (!memcmp(from, "crashkernel=", 12)) {
  783. unsigned long size, base;
  784. size = memparse(from+12, &from);
  785. if (*from == '@') {
  786. base = memparse(from+1, &from);
  787. /* FIXME: Do I want a sanity check
  788. * to validate the memory range?
  789. */
  790. crashk_res.start = base;
  791. crashk_res.end = base + size - 1;
  792. }
  793. }
  794. #endif
  795. #ifdef CONFIG_PROC_VMCORE
  796. /* elfcorehdr= specifies the location of elf core header
  797. * stored by the crashed kernel.
  798. */
  799. else if (!memcmp(from, "elfcorehdr=", 11))
  800. elfcorehdr_addr = memparse(from+11, &from);
  801. #endif
  802. /*
  803. * highmem=size forces highmem to be exactly 'size' bytes.
  804. * This works even on boxes that have no highmem otherwise.
  805. * This also works to reduce highmem size on bigger boxes.
  806. */
  807. else if (!memcmp(from, "highmem=", 8))
  808. highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
  809. /*
  810. * vmalloc=size forces the vmalloc area to be exactly 'size'
  811. * bytes. This can be used to increase (or decrease) the
  812. * vmalloc area - the default is 128m.
  813. */
  814. else if (!memcmp(from, "vmalloc=", 8))
  815. __VMALLOC_RESERVE = memparse(from+8, &from);
  816. next_char:
  817. c = *(from++);
  818. if (!c)
  819. break;
  820. if (COMMAND_LINE_SIZE <= ++len)
  821. break;
  822. *(to++) = c;
  823. }
  824. *to = '\0';
  825. *cmdline_p = command_line;
  826. if (userdef) {
  827. printk(KERN_INFO "user-defined physical RAM map:\n");
  828. print_memory_map("user");
  829. }
  830. }
  831. /*
  832. * Callback for efi_memory_walk.
  833. */
  834. static int __init
  835. efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
  836. {
  837. unsigned long *max_pfn = arg, pfn;
  838. if (start < end) {
  839. pfn = PFN_UP(end -1);
  840. if (pfn > *max_pfn)
  841. *max_pfn = pfn;
  842. }
  843. return 0;
  844. }
  845. static int __init
  846. efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
  847. {
  848. memory_present(0, start, end);
  849. return 0;
  850. }
  851. /*
  852. * Find the highest page frame number we have available
  853. */
  854. void __init find_max_pfn(void)
  855. {
  856. int i;
  857. max_pfn = 0;
  858. if (efi_enabled) {
  859. efi_memmap_walk(efi_find_max_pfn, &max_pfn);
  860. efi_memmap_walk(efi_memory_present_wrapper, NULL);
  861. return;
  862. }
  863. for (i = 0; i < e820.nr_map; i++) {
  864. unsigned long start, end;
  865. /* RAM? */
  866. if (e820.map[i].type != E820_RAM)
  867. continue;
  868. start = PFN_UP(e820.map[i].addr);
  869. end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
  870. if (start >= end)
  871. continue;
  872. if (end > max_pfn)
  873. max_pfn = end;
  874. memory_present(0, start, end);
  875. }
  876. }
  877. /*
  878. * Determine low and high memory ranges:
  879. */
  880. unsigned long __init find_max_low_pfn(void)
  881. {
  882. unsigned long max_low_pfn;
  883. max_low_pfn = max_pfn;
  884. if (max_low_pfn > MAXMEM_PFN) {
  885. if (highmem_pages == -1)
  886. highmem_pages = max_pfn - MAXMEM_PFN;
  887. if (highmem_pages + MAXMEM_PFN < max_pfn)
  888. max_pfn = MAXMEM_PFN + highmem_pages;
  889. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  890. printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
  891. highmem_pages = 0;
  892. }
  893. max_low_pfn = MAXMEM_PFN;
  894. #ifndef CONFIG_HIGHMEM
  895. /* Maximum memory usable is what is directly addressable */
  896. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  897. MAXMEM>>20);
  898. if (max_pfn > MAX_NONPAE_PFN)
  899. printk(KERN_WARNING "Use a PAE enabled kernel.\n");
  900. else
  901. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  902. max_pfn = MAXMEM_PFN;
  903. #else /* !CONFIG_HIGHMEM */
  904. #ifndef CONFIG_X86_PAE
  905. if (max_pfn > MAX_NONPAE_PFN) {
  906. max_pfn = MAX_NONPAE_PFN;
  907. printk(KERN_WARNING "Warning only 4GB will be used.\n");
  908. printk(KERN_WARNING "Use a PAE enabled kernel.\n");
  909. }
  910. #endif /* !CONFIG_X86_PAE */
  911. #endif /* !CONFIG_HIGHMEM */
  912. } else {
  913. if (highmem_pages == -1)
  914. highmem_pages = 0;
  915. #ifdef CONFIG_HIGHMEM
  916. if (highmem_pages >= max_pfn) {
  917. printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  918. highmem_pages = 0;
  919. }
  920. if (highmem_pages) {
  921. if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
  922. printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
  923. highmem_pages = 0;
  924. }
  925. max_low_pfn -= highmem_pages;
  926. }
  927. #else
  928. if (highmem_pages)
  929. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  930. #endif
  931. }
  932. return max_low_pfn;
  933. }
  934. /*
  935. * Free all available memory for boot time allocation. Used
  936. * as a callback function by efi_memory_walk()
  937. */
  938. static int __init
  939. free_available_memory(unsigned long start, unsigned long end, void *arg)
  940. {
  941. /* check max_low_pfn */
  942. if (start >= (max_low_pfn << PAGE_SHIFT))
  943. return 0;
  944. if (end >= (max_low_pfn << PAGE_SHIFT))
  945. end = max_low_pfn << PAGE_SHIFT;
  946. if (start < end)
  947. free_bootmem(start, end - start);
  948. return 0;
  949. }
  950. /*
  951. * Register fully available low RAM pages with the bootmem allocator.
  952. */
  953. static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
  954. {
  955. int i;
  956. if (efi_enabled) {
  957. efi_memmap_walk(free_available_memory, NULL);
  958. return;
  959. }
  960. for (i = 0; i < e820.nr_map; i++) {
  961. unsigned long curr_pfn, last_pfn, size;
  962. /*
  963. * Reserve usable low memory
  964. */
  965. if (e820.map[i].type != E820_RAM)
  966. continue;
  967. /*
  968. * We are rounding up the start address of usable memory:
  969. */
  970. curr_pfn = PFN_UP(e820.map[i].addr);
  971. if (curr_pfn >= max_low_pfn)
  972. continue;
  973. /*
  974. * ... and at the end of the usable range downwards:
  975. */
  976. last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
  977. if (last_pfn > max_low_pfn)
  978. last_pfn = max_low_pfn;
  979. /*
  980. * .. finally, did all the rounding and playing
  981. * around just make the area go away?
  982. */
  983. if (last_pfn <= curr_pfn)
  984. continue;
  985. size = last_pfn - curr_pfn;
  986. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  987. }
  988. }
  989. /*
  990. * workaround for Dell systems that neglect to reserve EBDA
  991. */
  992. static void __init reserve_ebda_region(void)
  993. {
  994. unsigned int addr;
  995. addr = get_bios_ebda();
  996. if (addr)
  997. reserve_bootmem(addr, PAGE_SIZE);
  998. }
  999. #ifndef CONFIG_NEED_MULTIPLE_NODES
  1000. void __init setup_bootmem_allocator(void);
  1001. static unsigned long __init setup_memory(void)
  1002. {
  1003. /*
  1004. * partially used pages are not usable - thus
  1005. * we are rounding upwards:
  1006. */
  1007. min_low_pfn = PFN_UP(init_pg_tables_end);
  1008. find_max_pfn();
  1009. max_low_pfn = find_max_low_pfn();
  1010. #ifdef CONFIG_HIGHMEM
  1011. highstart_pfn = highend_pfn = max_pfn;
  1012. if (max_pfn > max_low_pfn) {
  1013. highstart_pfn = max_low_pfn;
  1014. }
  1015. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  1016. pages_to_mb(highend_pfn - highstart_pfn));
  1017. #endif
  1018. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  1019. pages_to_mb(max_low_pfn));
  1020. setup_bootmem_allocator();
  1021. return max_low_pfn;
  1022. }
  1023. void __init zone_sizes_init(void)
  1024. {
  1025. unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
  1026. unsigned int max_dma, low;
  1027. max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  1028. low = max_low_pfn;
  1029. if (low < max_dma)
  1030. zones_size[ZONE_DMA] = low;
  1031. else {
  1032. zones_size[ZONE_DMA] = max_dma;
  1033. zones_size[ZONE_NORMAL] = low - max_dma;
  1034. #ifdef CONFIG_HIGHMEM
  1035. zones_size[ZONE_HIGHMEM] = highend_pfn - low;
  1036. #endif
  1037. }
  1038. free_area_init(zones_size);
  1039. }
  1040. #else
  1041. extern unsigned long __init setup_memory(void);
  1042. extern void zone_sizes_init(void);
  1043. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  1044. void __init setup_bootmem_allocator(void)
  1045. {
  1046. unsigned long bootmap_size;
  1047. /*
  1048. * Initialize the boot-time allocator (with low memory only):
  1049. */
  1050. bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
  1051. register_bootmem_low_pages(max_low_pfn);
  1052. /*
  1053. * Reserve the bootmem bitmap itself as well. We do this in two
  1054. * steps (first step was init_bootmem()) because this catches
  1055. * the (very unlikely) case of us accidentally initializing the
  1056. * bootmem allocator with an invalid RAM area.
  1057. */
  1058. reserve_bootmem(__PHYSICAL_START, (PFN_PHYS(min_low_pfn) +
  1059. bootmap_size + PAGE_SIZE-1) - (__PHYSICAL_START));
  1060. /*
  1061. * reserve physical page 0 - it's a special BIOS page on many boxes,
  1062. * enabling clean reboots, SMP operation, laptop functions.
  1063. */
  1064. reserve_bootmem(0, PAGE_SIZE);
  1065. /* reserve EBDA region, it's a 4K region */
  1066. reserve_ebda_region();
  1067. /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent
  1068. PCI prefetch into it (errata #56). Usually the page is reserved anyways,
  1069. unless you have no PS/2 mouse plugged in. */
  1070. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  1071. boot_cpu_data.x86 == 6)
  1072. reserve_bootmem(0xa0000 - 4096, 4096);
  1073. #ifdef CONFIG_SMP
  1074. /*
  1075. * But first pinch a few for the stack/trampoline stuff
  1076. * FIXME: Don't need the extra page at 4K, but need to fix
  1077. * trampoline before removing it. (see the GDT stuff)
  1078. */
  1079. reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
  1080. #endif
  1081. #ifdef CONFIG_ACPI_SLEEP
  1082. /*
  1083. * Reserve low memory region for sleep support.
  1084. */
  1085. acpi_reserve_bootmem();
  1086. #endif
  1087. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  1088. /*
  1089. * Find and reserve possible boot-time SMP configuration:
  1090. */
  1091. find_smp_config();
  1092. #endif
  1093. #ifdef CONFIG_BLK_DEV_INITRD
  1094. if (LOADER_TYPE && INITRD_START) {
  1095. if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
  1096. reserve_bootmem(INITRD_START, INITRD_SIZE);
  1097. initrd_start =
  1098. INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
  1099. initrd_end = initrd_start+INITRD_SIZE;
  1100. }
  1101. else {
  1102. printk(KERN_ERR "initrd extends beyond end of memory "
  1103. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  1104. INITRD_START + INITRD_SIZE,
  1105. max_low_pfn << PAGE_SHIFT);
  1106. initrd_start = 0;
  1107. }
  1108. }
  1109. #endif
  1110. #ifdef CONFIG_KEXEC
  1111. if (crashk_res.start != crashk_res.end)
  1112. reserve_bootmem(crashk_res.start,
  1113. crashk_res.end - crashk_res.start + 1);
  1114. #endif
  1115. }
  1116. /*
  1117. * The node 0 pgdat is initialized before all of these because
  1118. * it's needed for bootmem. node>0 pgdats have their virtual
  1119. * space allocated before the pagetables are in place to access
  1120. * them, so they can't be cleared then.
  1121. *
  1122. * This should all compile down to nothing when NUMA is off.
  1123. */
  1124. void __init remapped_pgdat_init(void)
  1125. {
  1126. int nid;
  1127. for_each_online_node(nid) {
  1128. if (nid != 0)
  1129. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  1130. }
  1131. }
  1132. /*
  1133. * Request address space for all standard RAM and ROM resources
  1134. * and also for regions reported as reserved by the e820.
  1135. */
  1136. static void __init
  1137. legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
  1138. {
  1139. int i;
  1140. probe_roms();
  1141. for (i = 0; i < e820.nr_map; i++) {
  1142. struct resource *res;
  1143. res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1144. switch (e820.map[i].type) {
  1145. case E820_RAM: res->name = "System RAM"; break;
  1146. case E820_ACPI: res->name = "ACPI Tables"; break;
  1147. case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
  1148. default: res->name = "reserved";
  1149. }
  1150. res->start = e820.map[i].addr;
  1151. res->end = res->start + e820.map[i].size - 1;
  1152. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  1153. request_resource(&iomem_resource, res);
  1154. if (e820.map[i].type == E820_RAM) {
  1155. /*
  1156. * We don't know which RAM region contains kernel data,
  1157. * so we try it repeatedly and let the resource manager
  1158. * test it.
  1159. */
  1160. request_resource(res, code_resource);
  1161. request_resource(res, data_resource);
  1162. #ifdef CONFIG_KEXEC
  1163. request_resource(res, &crashk_res);
  1164. #endif
  1165. }
  1166. }
  1167. }
  1168. /*
  1169. * Request address space for all standard resources
  1170. *
  1171. * This is called just before pcibios_assign_resources(), which is also
  1172. * an fs_initcall, but is linked in later (in arch/i386/pci/i386.c).
  1173. */
  1174. static int __init request_standard_resources(void)
  1175. {
  1176. int i;
  1177. printk("Setting up standard PCI resources\n");
  1178. if (efi_enabled)
  1179. efi_initialize_iomem_resources(&code_resource, &data_resource);
  1180. else
  1181. legacy_init_iomem_resources(&code_resource, &data_resource);
  1182. /* EFI systems may still have VGA */
  1183. request_resource(&iomem_resource, &video_ram_resource);
  1184. /* request I/O space for devices used on all i[345]86 PCs */
  1185. for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  1186. request_resource(&ioport_resource, &standard_io_resources[i]);
  1187. return 0;
  1188. }
  1189. fs_initcall(request_standard_resources);
  1190. static void __init register_memory(void)
  1191. {
  1192. unsigned long gapstart, gapsize, round;
  1193. unsigned long long last;
  1194. int i;
  1195. /*
  1196. * Search for the bigest gap in the low 32 bits of the e820
  1197. * memory space.
  1198. */
  1199. last = 0x100000000ull;
  1200. gapstart = 0x10000000;
  1201. gapsize = 0x400000;
  1202. i = e820.nr_map;
  1203. while (--i >= 0) {
  1204. unsigned long long start = e820.map[i].addr;
  1205. unsigned long long end = start + e820.map[i].size;
  1206. /*
  1207. * Since "last" is at most 4GB, we know we'll
  1208. * fit in 32 bits if this condition is true
  1209. */
  1210. if (last > end) {
  1211. unsigned long gap = last - end;
  1212. if (gap > gapsize) {
  1213. gapsize = gap;
  1214. gapstart = end;
  1215. }
  1216. }
  1217. if (start < last)
  1218. last = start;
  1219. }
  1220. /*
  1221. * See how much we want to round up: start off with
  1222. * rounding to the next 1MB area.
  1223. */
  1224. round = 0x100000;
  1225. while ((gapsize >> 4) > round)
  1226. round += round;
  1227. /* Fun with two's complement */
  1228. pci_mem_start = (gapstart + round) & -round;
  1229. printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
  1230. pci_mem_start, gapstart, gapsize);
  1231. }
  1232. static char * __init machine_specific_memory_setup(void);
  1233. #ifdef CONFIG_MCA
  1234. static void set_mca_bus(int x)
  1235. {
  1236. MCA_bus = x;
  1237. }
  1238. #else
  1239. static void set_mca_bus(int x) { }
  1240. #endif
  1241. /*
  1242. * Determine if we were loaded by an EFI loader. If so, then we have also been
  1243. * passed the efi memmap, systab, etc., so we should use these data structures
  1244. * for initialization. Note, the efi init code path is determined by the
  1245. * global efi_enabled. This allows the same kernel image to be used on existing
  1246. * systems (with a traditional BIOS) as well as on EFI systems.
  1247. */
  1248. void __init setup_arch(char **cmdline_p)
  1249. {
  1250. unsigned long max_low_pfn;
  1251. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  1252. pre_setup_arch_hook();
  1253. early_cpu_init();
  1254. /*
  1255. * FIXME: This isn't an official loader_type right
  1256. * now but does currently work with elilo.
  1257. * If we were configured as an EFI kernel, check to make
  1258. * sure that we were loaded correctly from elilo and that
  1259. * the system table is valid. If not, then initialize normally.
  1260. */
  1261. #ifdef CONFIG_EFI
  1262. if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
  1263. efi_enabled = 1;
  1264. #endif
  1265. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  1266. drive_info = DRIVE_INFO;
  1267. screen_info = SCREEN_INFO;
  1268. edid_info = EDID_INFO;
  1269. apm_info.bios = APM_BIOS_INFO;
  1270. ist_info = IST_INFO;
  1271. saved_videomode = VIDEO_MODE;
  1272. if( SYS_DESC_TABLE.length != 0 ) {
  1273. set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
  1274. machine_id = SYS_DESC_TABLE.table[0];
  1275. machine_submodel_id = SYS_DESC_TABLE.table[1];
  1276. BIOS_revision = SYS_DESC_TABLE.table[2];
  1277. }
  1278. bootloader_type = LOADER_TYPE;
  1279. #ifdef CONFIG_BLK_DEV_RAM
  1280. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  1281. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  1282. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  1283. #endif
  1284. ARCH_SETUP
  1285. if (efi_enabled)
  1286. efi_init();
  1287. else {
  1288. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  1289. print_memory_map(machine_specific_memory_setup());
  1290. }
  1291. copy_edd();
  1292. if (!MOUNT_ROOT_RDONLY)
  1293. root_mountflags &= ~MS_RDONLY;
  1294. init_mm.start_code = (unsigned long) _text;
  1295. init_mm.end_code = (unsigned long) _etext;
  1296. init_mm.end_data = (unsigned long) _edata;
  1297. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  1298. code_resource.start = virt_to_phys(_text);
  1299. code_resource.end = virt_to_phys(_etext)-1;
  1300. data_resource.start = virt_to_phys(_etext);
  1301. data_resource.end = virt_to_phys(_edata)-1;
  1302. parse_cmdline_early(cmdline_p);
  1303. #ifdef CONFIG_EARLY_PRINTK
  1304. {
  1305. char *s = strstr(*cmdline_p, "earlyprintk=");
  1306. if (s) {
  1307. setup_early_printk(strchr(s, '=') + 1);
  1308. printk("early console enabled\n");
  1309. }
  1310. }
  1311. #endif
  1312. max_low_pfn = setup_memory();
  1313. /*
  1314. * NOTE: before this point _nobody_ is allowed to allocate
  1315. * any memory using the bootmem allocator. Although the
  1316. * alloctor is now initialised only the first 8Mb of the kernel
  1317. * virtual address space has been mapped. All allocations before
  1318. * paging_init() has completed must use the alloc_bootmem_low_pages()
  1319. * variant (which allocates DMA'able memory) and care must be taken
  1320. * not to exceed the 8Mb limit.
  1321. */
  1322. #ifdef CONFIG_SMP
  1323. smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
  1324. #endif
  1325. paging_init();
  1326. remapped_pgdat_init();
  1327. sparse_init();
  1328. zone_sizes_init();
  1329. /*
  1330. * NOTE: at this point the bootmem allocator is fully available.
  1331. */
  1332. dmi_scan_machine();
  1333. #ifdef CONFIG_X86_GENERICARCH
  1334. generic_apic_probe(*cmdline_p);
  1335. #endif
  1336. if (efi_enabled)
  1337. efi_map_memmap();
  1338. #ifdef CONFIG_X86_IO_APIC
  1339. check_acpi_pci(); /* Checks more than just ACPI actually */
  1340. #endif
  1341. #ifdef CONFIG_ACPI
  1342. /*
  1343. * Parse the ACPI tables for possible boot-time SMP configuration.
  1344. */
  1345. acpi_boot_table_init();
  1346. acpi_boot_init();
  1347. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  1348. if (def_to_bigsmp)
  1349. printk(KERN_WARNING "More than 8 CPUs detected and "
  1350. "CONFIG_X86_PC cannot handle it.\nUse "
  1351. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  1352. #endif
  1353. #endif
  1354. #ifdef CONFIG_X86_LOCAL_APIC
  1355. if (smp_found_config)
  1356. get_smp_config();
  1357. #endif
  1358. register_memory();
  1359. #ifdef CONFIG_VT
  1360. #if defined(CONFIG_VGA_CONSOLE)
  1361. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  1362. conswitchp = &vga_con;
  1363. #elif defined(CONFIG_DUMMY_CONSOLE)
  1364. conswitchp = &dummy_con;
  1365. #endif
  1366. #endif
  1367. }
  1368. #include "setup_arch_post.h"
  1369. /*
  1370. * Local Variables:
  1371. * mode:c
  1372. * c-file-style:"k&r"
  1373. * c-basic-offset:8
  1374. * End:
  1375. */