setup.c 44 KB

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