setup.c 42 KB

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