setup.c 42 KB

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