setup.c 38 KB

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