setup.c 38 KB

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