setup.c 41 KB

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