setup.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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.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. 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. 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. 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. static void __init parse_cmdline_early (char ** cmdline_p)
  624. {
  625. char c = ' ', *to = command_line, *from = saved_command_line;
  626. int len = 0;
  627. int userdef = 0;
  628. /* Save unparsed command line copy for /proc/cmdline */
  629. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  630. for (;;) {
  631. if (c != ' ')
  632. goto next_char;
  633. /*
  634. * "mem=nopentium" disables the 4MB page tables.
  635. * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
  636. * to <mem>, overriding the bios size.
  637. * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
  638. * <start> to <start>+<mem>, overriding the bios size.
  639. *
  640. * HPA tells me bootloaders need to parse mem=, so no new
  641. * option should be mem= [also see Documentation/i386/boot.txt]
  642. */
  643. if (!memcmp(from, "mem=", 4)) {
  644. if (to != command_line)
  645. to--;
  646. if (!memcmp(from+4, "nopentium", 9)) {
  647. from += 9+4;
  648. clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
  649. disable_pse = 1;
  650. } else {
  651. /* If the user specifies memory size, we
  652. * limit the BIOS-provided memory map to
  653. * that size. exactmap can be used to specify
  654. * the exact map. mem=number can be used to
  655. * trim the existing memory map.
  656. */
  657. unsigned long long mem_size;
  658. mem_size = memparse(from+4, &from);
  659. limit_regions(mem_size);
  660. userdef=1;
  661. }
  662. }
  663. else if (!memcmp(from, "memmap=", 7)) {
  664. if (to != command_line)
  665. to--;
  666. if (!memcmp(from+7, "exactmap", 8)) {
  667. #ifdef CONFIG_CRASH_DUMP
  668. /* If we are doing a crash dump, we
  669. * still need to know the real mem
  670. * size before original memory map is
  671. * reset.
  672. */
  673. find_max_pfn();
  674. saved_max_pfn = max_pfn;
  675. #endif
  676. from += 8+7;
  677. e820.nr_map = 0;
  678. userdef = 1;
  679. } else {
  680. /* If the user specifies memory size, we
  681. * limit the BIOS-provided memory map to
  682. * that size. exactmap can be used to specify
  683. * the exact map. mem=number can be used to
  684. * trim the existing memory map.
  685. */
  686. unsigned long long start_at, mem_size;
  687. mem_size = memparse(from+7, &from);
  688. if (*from == '@') {
  689. start_at = memparse(from+1, &from);
  690. add_memory_region(start_at, mem_size, E820_RAM);
  691. } else if (*from == '#') {
  692. start_at = memparse(from+1, &from);
  693. add_memory_region(start_at, mem_size, E820_ACPI);
  694. } else if (*from == '$') {
  695. start_at = memparse(from+1, &from);
  696. add_memory_region(start_at, mem_size, E820_RESERVED);
  697. } else {
  698. limit_regions(mem_size);
  699. userdef=1;
  700. }
  701. }
  702. }
  703. else if (!memcmp(from, "noexec=", 7))
  704. noexec_setup(from + 7);
  705. #ifdef CONFIG_X86_SMP
  706. /*
  707. * If the BIOS enumerates physical processors before logical,
  708. * maxcpus=N at enumeration-time can be used to disable HT.
  709. */
  710. else if (!memcmp(from, "maxcpus=", 8)) {
  711. extern unsigned int maxcpus;
  712. maxcpus = simple_strtoul(from + 8, NULL, 0);
  713. }
  714. #endif
  715. #ifdef CONFIG_ACPI
  716. /* "acpi=off" disables both ACPI table parsing and interpreter */
  717. else if (!memcmp(from, "acpi=off", 8)) {
  718. disable_acpi();
  719. }
  720. /* acpi=force to over-ride black-list */
  721. else if (!memcmp(from, "acpi=force", 10)) {
  722. acpi_force = 1;
  723. acpi_ht = 1;
  724. acpi_disabled = 0;
  725. }
  726. /* acpi=strict disables out-of-spec workarounds */
  727. else if (!memcmp(from, "acpi=strict", 11)) {
  728. acpi_strict = 1;
  729. }
  730. /* Limit ACPI just to boot-time to enable HT */
  731. else if (!memcmp(from, "acpi=ht", 7)) {
  732. if (!acpi_force)
  733. disable_acpi();
  734. acpi_ht = 1;
  735. }
  736. /* "pci=noacpi" disable ACPI IRQ routing and PCI scan */
  737. else if (!memcmp(from, "pci=noacpi", 10)) {
  738. acpi_disable_pci();
  739. }
  740. /* "acpi=noirq" disables ACPI interrupt routing */
  741. else if (!memcmp(from, "acpi=noirq", 10)) {
  742. acpi_noirq_set();
  743. }
  744. else if (!memcmp(from, "acpi_sci=edge", 13))
  745. acpi_sci_flags.trigger = 1;
  746. else if (!memcmp(from, "acpi_sci=level", 14))
  747. acpi_sci_flags.trigger = 3;
  748. else if (!memcmp(from, "acpi_sci=high", 13))
  749. acpi_sci_flags.polarity = 1;
  750. else if (!memcmp(from, "acpi_sci=low", 12))
  751. acpi_sci_flags.polarity = 3;
  752. #ifdef CONFIG_X86_IO_APIC
  753. else if (!memcmp(from, "acpi_skip_timer_override", 24))
  754. acpi_skip_timer_override = 1;
  755. if (!memcmp(from, "disable_timer_pin_1", 19))
  756. disable_timer_pin_1 = 1;
  757. if (!memcmp(from, "enable_timer_pin_1", 18))
  758. disable_timer_pin_1 = -1;
  759. /* disable IO-APIC */
  760. else if (!memcmp(from, "noapic", 6))
  761. disable_ioapic_setup();
  762. #endif /* CONFIG_X86_IO_APIC */
  763. #endif /* CONFIG_ACPI */
  764. #ifdef CONFIG_X86_LOCAL_APIC
  765. /* enable local APIC */
  766. else if (!memcmp(from, "lapic", 5))
  767. lapic_enable();
  768. /* disable local APIC */
  769. else if (!memcmp(from, "nolapic", 6))
  770. lapic_disable();
  771. #endif /* CONFIG_X86_LOCAL_APIC */
  772. #ifdef CONFIG_KEXEC
  773. /* crashkernel=size@addr specifies the location to reserve for
  774. * a crash kernel. By reserving this memory we guarantee
  775. * that linux never set's it up as a DMA target.
  776. * Useful for holding code to do something appropriate
  777. * after a kernel panic.
  778. */
  779. else if (!memcmp(from, "crashkernel=", 12)) {
  780. unsigned long size, base;
  781. size = memparse(from+12, &from);
  782. if (*from == '@') {
  783. base = memparse(from+1, &from);
  784. /* FIXME: Do I want a sanity check
  785. * to validate the memory range?
  786. */
  787. crashk_res.start = base;
  788. crashk_res.end = base + size - 1;
  789. }
  790. }
  791. #endif
  792. #ifdef CONFIG_PROC_VMCORE
  793. /* elfcorehdr= specifies the location of elf core header
  794. * stored by the crashed kernel.
  795. */
  796. else if (!memcmp(from, "elfcorehdr=", 11))
  797. elfcorehdr_addr = memparse(from+11, &from);
  798. #endif
  799. /*
  800. * highmem=size forces highmem to be exactly 'size' bytes.
  801. * This works even on boxes that have no highmem otherwise.
  802. * This also works to reduce highmem size on bigger boxes.
  803. */
  804. else if (!memcmp(from, "highmem=", 8))
  805. highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
  806. /*
  807. * vmalloc=size forces the vmalloc area to be exactly 'size'
  808. * bytes. This can be used to increase (or decrease) the
  809. * vmalloc area - the default is 128m.
  810. */
  811. else if (!memcmp(from, "vmalloc=", 8))
  812. __VMALLOC_RESERVE = memparse(from+8, &from);
  813. next_char:
  814. c = *(from++);
  815. if (!c)
  816. break;
  817. if (COMMAND_LINE_SIZE <= ++len)
  818. break;
  819. *(to++) = c;
  820. }
  821. *to = '\0';
  822. *cmdline_p = command_line;
  823. if (userdef) {
  824. printk(KERN_INFO "user-defined physical RAM map:\n");
  825. print_memory_map("user");
  826. }
  827. }
  828. /*
  829. * Callback for efi_memory_walk.
  830. */
  831. static int __init
  832. efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
  833. {
  834. unsigned long *max_pfn = arg, pfn;
  835. if (start < end) {
  836. pfn = PFN_UP(end -1);
  837. if (pfn > *max_pfn)
  838. *max_pfn = pfn;
  839. }
  840. return 0;
  841. }
  842. static int __init
  843. efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
  844. {
  845. memory_present(0, start, end);
  846. return 0;
  847. }
  848. /*
  849. * This function checks if the entire range <start,end> is mapped with type.
  850. *
  851. * Note: this function only works correct if the e820 table is sorted and
  852. * not-overlapping, which is the case
  853. */
  854. int __init
  855. e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
  856. {
  857. u64 start = s;
  858. u64 end = e;
  859. int i;
  860. for (i = 0; i < e820.nr_map; i++) {
  861. struct e820entry *ei = &e820.map[i];
  862. if (type && ei->type != type)
  863. continue;
  864. /* is the region (part) in overlap with the current region ?*/
  865. if (ei->addr >= end || ei->addr + ei->size <= start)
  866. continue;
  867. /* if the region is at the beginning of <start,end> we move
  868. * start to the end of the region since it's ok until there
  869. */
  870. if (ei->addr <= start)
  871. start = ei->addr + ei->size;
  872. /* if start is now at or beyond end, we're done, full
  873. * coverage */
  874. if (start >= end)
  875. return 1; /* we're done */
  876. }
  877. return 0;
  878. }
  879. /*
  880. * Find the highest page frame number we have available
  881. */
  882. void __init find_max_pfn(void)
  883. {
  884. int i;
  885. max_pfn = 0;
  886. if (efi_enabled) {
  887. efi_memmap_walk(efi_find_max_pfn, &max_pfn);
  888. efi_memmap_walk(efi_memory_present_wrapper, NULL);
  889. return;
  890. }
  891. for (i = 0; i < e820.nr_map; i++) {
  892. unsigned long start, end;
  893. /* RAM? */
  894. if (e820.map[i].type != E820_RAM)
  895. continue;
  896. start = PFN_UP(e820.map[i].addr);
  897. end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
  898. if (start >= end)
  899. continue;
  900. if (end > max_pfn)
  901. max_pfn = end;
  902. memory_present(0, start, end);
  903. }
  904. }
  905. /*
  906. * Determine low and high memory ranges:
  907. */
  908. unsigned long __init find_max_low_pfn(void)
  909. {
  910. unsigned long max_low_pfn;
  911. max_low_pfn = max_pfn;
  912. if (max_low_pfn > MAXMEM_PFN) {
  913. if (highmem_pages == -1)
  914. highmem_pages = max_pfn - MAXMEM_PFN;
  915. if (highmem_pages + MAXMEM_PFN < max_pfn)
  916. max_pfn = MAXMEM_PFN + highmem_pages;
  917. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  918. printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
  919. highmem_pages = 0;
  920. }
  921. max_low_pfn = MAXMEM_PFN;
  922. #ifndef CONFIG_HIGHMEM
  923. /* Maximum memory usable is what is directly addressable */
  924. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  925. MAXMEM>>20);
  926. if (max_pfn > MAX_NONPAE_PFN)
  927. printk(KERN_WARNING "Use a PAE enabled kernel.\n");
  928. else
  929. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  930. max_pfn = MAXMEM_PFN;
  931. #else /* !CONFIG_HIGHMEM */
  932. #ifndef CONFIG_X86_PAE
  933. if (max_pfn > MAX_NONPAE_PFN) {
  934. max_pfn = MAX_NONPAE_PFN;
  935. printk(KERN_WARNING "Warning only 4GB will be used.\n");
  936. printk(KERN_WARNING "Use a PAE enabled kernel.\n");
  937. }
  938. #endif /* !CONFIG_X86_PAE */
  939. #endif /* !CONFIG_HIGHMEM */
  940. } else {
  941. if (highmem_pages == -1)
  942. highmem_pages = 0;
  943. #ifdef CONFIG_HIGHMEM
  944. if (highmem_pages >= max_pfn) {
  945. printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  946. highmem_pages = 0;
  947. }
  948. if (highmem_pages) {
  949. if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
  950. printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
  951. highmem_pages = 0;
  952. }
  953. max_low_pfn -= highmem_pages;
  954. }
  955. #else
  956. if (highmem_pages)
  957. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  958. #endif
  959. }
  960. return max_low_pfn;
  961. }
  962. /*
  963. * Free all available memory for boot time allocation. Used
  964. * as a callback function by efi_memory_walk()
  965. */
  966. static int __init
  967. free_available_memory(unsigned long start, unsigned long end, void *arg)
  968. {
  969. /* check max_low_pfn */
  970. if (start >= (max_low_pfn << PAGE_SHIFT))
  971. return 0;
  972. if (end >= (max_low_pfn << PAGE_SHIFT))
  973. end = max_low_pfn << PAGE_SHIFT;
  974. if (start < end)
  975. free_bootmem(start, end - start);
  976. return 0;
  977. }
  978. /*
  979. * Register fully available low RAM pages with the bootmem allocator.
  980. */
  981. static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
  982. {
  983. int i;
  984. if (efi_enabled) {
  985. efi_memmap_walk(free_available_memory, NULL);
  986. return;
  987. }
  988. for (i = 0; i < e820.nr_map; i++) {
  989. unsigned long curr_pfn, last_pfn, size;
  990. /*
  991. * Reserve usable low memory
  992. */
  993. if (e820.map[i].type != E820_RAM)
  994. continue;
  995. /*
  996. * We are rounding up the start address of usable memory:
  997. */
  998. curr_pfn = PFN_UP(e820.map[i].addr);
  999. if (curr_pfn >= max_low_pfn)
  1000. continue;
  1001. /*
  1002. * ... and at the end of the usable range downwards:
  1003. */
  1004. last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
  1005. if (last_pfn > max_low_pfn)
  1006. last_pfn = max_low_pfn;
  1007. /*
  1008. * .. finally, did all the rounding and playing
  1009. * around just make the area go away?
  1010. */
  1011. if (last_pfn <= curr_pfn)
  1012. continue;
  1013. size = last_pfn - curr_pfn;
  1014. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  1015. }
  1016. }
  1017. /*
  1018. * workaround for Dell systems that neglect to reserve EBDA
  1019. */
  1020. static void __init reserve_ebda_region(void)
  1021. {
  1022. unsigned int addr;
  1023. addr = get_bios_ebda();
  1024. if (addr)
  1025. reserve_bootmem(addr, PAGE_SIZE);
  1026. }
  1027. #ifndef CONFIG_NEED_MULTIPLE_NODES
  1028. void __init setup_bootmem_allocator(void);
  1029. static unsigned long __init setup_memory(void)
  1030. {
  1031. /*
  1032. * partially used pages are not usable - thus
  1033. * we are rounding upwards:
  1034. */
  1035. min_low_pfn = PFN_UP(init_pg_tables_end);
  1036. find_max_pfn();
  1037. max_low_pfn = find_max_low_pfn();
  1038. #ifdef CONFIG_HIGHMEM
  1039. highstart_pfn = highend_pfn = max_pfn;
  1040. if (max_pfn > max_low_pfn) {
  1041. highstart_pfn = max_low_pfn;
  1042. }
  1043. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  1044. pages_to_mb(highend_pfn - highstart_pfn));
  1045. #endif
  1046. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  1047. pages_to_mb(max_low_pfn));
  1048. setup_bootmem_allocator();
  1049. return max_low_pfn;
  1050. }
  1051. void __init zone_sizes_init(void)
  1052. {
  1053. unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
  1054. unsigned int max_dma, low;
  1055. max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  1056. low = max_low_pfn;
  1057. if (low < max_dma)
  1058. zones_size[ZONE_DMA] = low;
  1059. else {
  1060. zones_size[ZONE_DMA] = max_dma;
  1061. zones_size[ZONE_NORMAL] = low - max_dma;
  1062. #ifdef CONFIG_HIGHMEM
  1063. zones_size[ZONE_HIGHMEM] = highend_pfn - low;
  1064. #endif
  1065. }
  1066. free_area_init(zones_size);
  1067. }
  1068. #else
  1069. extern unsigned long __init setup_memory(void);
  1070. extern void zone_sizes_init(void);
  1071. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  1072. void __init setup_bootmem_allocator(void)
  1073. {
  1074. unsigned long bootmap_size;
  1075. /*
  1076. * Initialize the boot-time allocator (with low memory only):
  1077. */
  1078. bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
  1079. register_bootmem_low_pages(max_low_pfn);
  1080. /*
  1081. * Reserve the bootmem bitmap itself as well. We do this in two
  1082. * steps (first step was init_bootmem()) because this catches
  1083. * the (very unlikely) case of us accidentally initializing the
  1084. * bootmem allocator with an invalid RAM area.
  1085. */
  1086. reserve_bootmem(__PHYSICAL_START, (PFN_PHYS(min_low_pfn) +
  1087. bootmap_size + PAGE_SIZE-1) - (__PHYSICAL_START));
  1088. /*
  1089. * reserve physical page 0 - it's a special BIOS page on many boxes,
  1090. * enabling clean reboots, SMP operation, laptop functions.
  1091. */
  1092. reserve_bootmem(0, PAGE_SIZE);
  1093. /* reserve EBDA region, it's a 4K region */
  1094. reserve_ebda_region();
  1095. /* could be an AMD 768MPX chipset. Reserve a page before VGA to prevent
  1096. PCI prefetch into it (errata #56). Usually the page is reserved anyways,
  1097. unless you have no PS/2 mouse plugged in. */
  1098. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  1099. boot_cpu_data.x86 == 6)
  1100. reserve_bootmem(0xa0000 - 4096, 4096);
  1101. #ifdef CONFIG_SMP
  1102. /*
  1103. * But first pinch a few for the stack/trampoline stuff
  1104. * FIXME: Don't need the extra page at 4K, but need to fix
  1105. * trampoline before removing it. (see the GDT stuff)
  1106. */
  1107. reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
  1108. #endif
  1109. #ifdef CONFIG_ACPI_SLEEP
  1110. /*
  1111. * Reserve low memory region for sleep support.
  1112. */
  1113. acpi_reserve_bootmem();
  1114. #endif
  1115. #ifdef CONFIG_X86_FIND_SMP_CONFIG
  1116. /*
  1117. * Find and reserve possible boot-time SMP configuration:
  1118. */
  1119. find_smp_config();
  1120. #endif
  1121. #ifdef CONFIG_BLK_DEV_INITRD
  1122. if (LOADER_TYPE && INITRD_START) {
  1123. if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
  1124. reserve_bootmem(INITRD_START, INITRD_SIZE);
  1125. initrd_start =
  1126. INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
  1127. initrd_end = initrd_start+INITRD_SIZE;
  1128. }
  1129. else {
  1130. printk(KERN_ERR "initrd extends beyond end of memory "
  1131. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  1132. INITRD_START + INITRD_SIZE,
  1133. max_low_pfn << PAGE_SHIFT);
  1134. initrd_start = 0;
  1135. }
  1136. }
  1137. #endif
  1138. #ifdef CONFIG_KEXEC
  1139. if (crashk_res.start != crashk_res.end)
  1140. reserve_bootmem(crashk_res.start,
  1141. crashk_res.end - crashk_res.start + 1);
  1142. #endif
  1143. }
  1144. /*
  1145. * The node 0 pgdat is initialized before all of these because
  1146. * it's needed for bootmem. node>0 pgdats have their virtual
  1147. * space allocated before the pagetables are in place to access
  1148. * them, so they can't be cleared then.
  1149. *
  1150. * This should all compile down to nothing when NUMA is off.
  1151. */
  1152. void __init remapped_pgdat_init(void)
  1153. {
  1154. int nid;
  1155. for_each_online_node(nid) {
  1156. if (nid != 0)
  1157. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  1158. }
  1159. }
  1160. /*
  1161. * Request address space for all standard RAM and ROM resources
  1162. * and also for regions reported as reserved by the e820.
  1163. */
  1164. static void __init
  1165. legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
  1166. {
  1167. int i;
  1168. probe_roms();
  1169. for (i = 0; i < e820.nr_map; i++) {
  1170. struct resource *res;
  1171. if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
  1172. continue;
  1173. res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
  1174. switch (e820.map[i].type) {
  1175. case E820_RAM: res->name = "System RAM"; break;
  1176. case E820_ACPI: res->name = "ACPI Tables"; break;
  1177. case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
  1178. default: res->name = "reserved";
  1179. }
  1180. res->start = e820.map[i].addr;
  1181. res->end = res->start + e820.map[i].size - 1;
  1182. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  1183. request_resource(&iomem_resource, res);
  1184. if (e820.map[i].type == E820_RAM) {
  1185. /*
  1186. * We don't know which RAM region contains kernel data,
  1187. * so we try it repeatedly and let the resource manager
  1188. * test it.
  1189. */
  1190. request_resource(res, code_resource);
  1191. request_resource(res, data_resource);
  1192. #ifdef CONFIG_KEXEC
  1193. request_resource(res, &crashk_res);
  1194. #endif
  1195. }
  1196. }
  1197. }
  1198. /*
  1199. * Request address space for all standard resources
  1200. *
  1201. * This is called just before pcibios_init(), which is also a
  1202. * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
  1203. */
  1204. static int __init request_standard_resources(void)
  1205. {
  1206. int i;
  1207. printk("Setting up standard PCI resources\n");
  1208. if (efi_enabled)
  1209. efi_initialize_iomem_resources(&code_resource, &data_resource);
  1210. else
  1211. legacy_init_iomem_resources(&code_resource, &data_resource);
  1212. /* EFI systems may still have VGA */
  1213. request_resource(&iomem_resource, &video_ram_resource);
  1214. /* request I/O space for devices used on all i[345]86 PCs */
  1215. for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  1216. request_resource(&ioport_resource, &standard_io_resources[i]);
  1217. return 0;
  1218. }
  1219. subsys_initcall(request_standard_resources);
  1220. static void __init register_memory(void)
  1221. {
  1222. unsigned long gapstart, gapsize, round;
  1223. unsigned long long last;
  1224. int i;
  1225. /*
  1226. * Search for the bigest gap in the low 32 bits of the e820
  1227. * memory space.
  1228. */
  1229. last = 0x100000000ull;
  1230. gapstart = 0x10000000;
  1231. gapsize = 0x400000;
  1232. i = e820.nr_map;
  1233. while (--i >= 0) {
  1234. unsigned long long start = e820.map[i].addr;
  1235. unsigned long long end = start + e820.map[i].size;
  1236. /*
  1237. * Since "last" is at most 4GB, we know we'll
  1238. * fit in 32 bits if this condition is true
  1239. */
  1240. if (last > end) {
  1241. unsigned long gap = last - end;
  1242. if (gap > gapsize) {
  1243. gapsize = gap;
  1244. gapstart = end;
  1245. }
  1246. }
  1247. if (start < last)
  1248. last = start;
  1249. }
  1250. /*
  1251. * See how much we want to round up: start off with
  1252. * rounding to the next 1MB area.
  1253. */
  1254. round = 0x100000;
  1255. while ((gapsize >> 4) > round)
  1256. round += round;
  1257. /* Fun with two's complement */
  1258. pci_mem_start = (gapstart + round) & -round;
  1259. printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
  1260. pci_mem_start, gapstart, gapsize);
  1261. }
  1262. #ifdef CONFIG_MCA
  1263. static void set_mca_bus(int x)
  1264. {
  1265. MCA_bus = x;
  1266. }
  1267. #else
  1268. static void set_mca_bus(int x) { }
  1269. #endif
  1270. #ifdef CONFIG_SOFTWARE_SUSPEND
  1271. static void __init mark_nosave_page_range(unsigned long start, unsigned long end)
  1272. {
  1273. struct page *page;
  1274. while (start <= end) {
  1275. page = pfn_to_page(start);
  1276. SetPageNosave(page);
  1277. start++;
  1278. }
  1279. }
  1280. static void __init e820_nosave_reserved_pages(void)
  1281. {
  1282. int i;
  1283. unsigned long r_start = 0, r_end = 0;
  1284. /* Assume e820 map is sorted */
  1285. for (i = 0; i < e820.nr_map; i++) {
  1286. struct e820entry *ei = &e820.map[i];
  1287. unsigned long start, end;
  1288. start = PFN_DOWN(ei->addr);
  1289. end = PFN_UP(ei->addr + ei->size);
  1290. if (start >= end)
  1291. continue;
  1292. if (ei->type == E820_RESERVED)
  1293. continue;
  1294. r_end = start;
  1295. /*
  1296. * Highmem 'Reserved' pages are marked as reserved, swsusp
  1297. * will not save/restore them, so we ignore these pages here.
  1298. */
  1299. if (r_end > max_low_pfn)
  1300. r_end = max_low_pfn;
  1301. if (r_end > r_start)
  1302. mark_nosave_page_range(r_start, r_end-1);
  1303. if (r_end >= max_low_pfn)
  1304. break;
  1305. r_start = end;
  1306. }
  1307. }
  1308. static void __init e820_save_acpi_pages(void)
  1309. {
  1310. int i;
  1311. /* Assume e820 map is sorted */
  1312. for (i = 0; i < e820.nr_map; i++) {
  1313. struct e820entry *ei = &e820.map[i];
  1314. unsigned long start, end;
  1315. start = ei->addr;
  1316. end = ei->addr + ei->size;
  1317. if (start >= end)
  1318. continue;
  1319. if (ei->type != E820_ACPI && ei->type != E820_NVS)
  1320. continue;
  1321. /*
  1322. * If the region is below max_low_pfn, it will be
  1323. * saved/restored by swsusp follow 'RAM' type.
  1324. */
  1325. if (start < (max_low_pfn << PAGE_SHIFT))
  1326. start = max_low_pfn << PAGE_SHIFT;
  1327. /*
  1328. * Highmem pages (ACPI NVS/Data) are reserved, but swsusp
  1329. * highmem save/restore will not save/restore them. We marked
  1330. * them as arch saveable pages here
  1331. */
  1332. if (end > start)
  1333. swsusp_add_arch_pages(start, end);
  1334. }
  1335. }
  1336. extern char __start_rodata, __end_rodata;
  1337. /*
  1338. * BIOS reserved region/hole - no save/restore
  1339. * ACPI NVS - save/restore
  1340. * ACPI Data - this is a little tricky, the mem could be used by OS after OS
  1341. * reads tables from the region, but anyway save/restore the memory hasn't any
  1342. * side effect and Linux runtime module load/unload might use it.
  1343. * kernel rodata - no save/restore (kernel rodata isn't changed)
  1344. */
  1345. static int __init mark_nosave_pages(void)
  1346. {
  1347. unsigned long pfn_start, pfn_end;
  1348. /* FIXME: provide a version for efi BIOS */
  1349. if (efi_enabled)
  1350. return 0;
  1351. /* BIOS reserved regions & holes */
  1352. e820_nosave_reserved_pages();
  1353. /* kernel rodata */
  1354. pfn_start = PFN_UP(virt_to_phys(&__start_rodata));
  1355. pfn_end = PFN_DOWN(virt_to_phys(&__end_rodata));
  1356. mark_nosave_page_range(pfn_start, pfn_end-1);
  1357. /* record ACPI Data/NVS as saveable */
  1358. e820_save_acpi_pages();
  1359. return 0;
  1360. }
  1361. core_initcall(mark_nosave_pages);
  1362. #endif
  1363. /*
  1364. * Determine if we were loaded by an EFI loader. If so, then we have also been
  1365. * passed the efi memmap, systab, etc., so we should use these data structures
  1366. * for initialization. Note, the efi init code path is determined by the
  1367. * global efi_enabled. This allows the same kernel image to be used on existing
  1368. * systems (with a traditional BIOS) as well as on EFI systems.
  1369. */
  1370. void __init setup_arch(char **cmdline_p)
  1371. {
  1372. unsigned long max_low_pfn;
  1373. memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
  1374. pre_setup_arch_hook();
  1375. early_cpu_init();
  1376. /*
  1377. * FIXME: This isn't an official loader_type right
  1378. * now but does currently work with elilo.
  1379. * If we were configured as an EFI kernel, check to make
  1380. * sure that we were loaded correctly from elilo and that
  1381. * the system table is valid. If not, then initialize normally.
  1382. */
  1383. #ifdef CONFIG_EFI
  1384. if ((LOADER_TYPE == 0x50) && EFI_SYSTAB)
  1385. efi_enabled = 1;
  1386. #endif
  1387. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  1388. drive_info = DRIVE_INFO;
  1389. screen_info = SCREEN_INFO;
  1390. edid_info = EDID_INFO;
  1391. apm_info.bios = APM_BIOS_INFO;
  1392. ist_info = IST_INFO;
  1393. saved_videomode = VIDEO_MODE;
  1394. if( SYS_DESC_TABLE.length != 0 ) {
  1395. set_mca_bus(SYS_DESC_TABLE.table[3] & 0x2);
  1396. machine_id = SYS_DESC_TABLE.table[0];
  1397. machine_submodel_id = SYS_DESC_TABLE.table[1];
  1398. BIOS_revision = SYS_DESC_TABLE.table[2];
  1399. }
  1400. bootloader_type = LOADER_TYPE;
  1401. #ifdef CONFIG_BLK_DEV_RAM
  1402. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  1403. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  1404. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  1405. #endif
  1406. ARCH_SETUP
  1407. if (efi_enabled)
  1408. efi_init();
  1409. else {
  1410. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  1411. print_memory_map(machine_specific_memory_setup());
  1412. }
  1413. copy_edd();
  1414. if (!MOUNT_ROOT_RDONLY)
  1415. root_mountflags &= ~MS_RDONLY;
  1416. init_mm.start_code = (unsigned long) _text;
  1417. init_mm.end_code = (unsigned long) _etext;
  1418. init_mm.end_data = (unsigned long) _edata;
  1419. init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
  1420. code_resource.start = virt_to_phys(_text);
  1421. code_resource.end = virt_to_phys(_etext)-1;
  1422. data_resource.start = virt_to_phys(_etext);
  1423. data_resource.end = virt_to_phys(_edata)-1;
  1424. parse_cmdline_early(cmdline_p);
  1425. #ifdef CONFIG_EARLY_PRINTK
  1426. {
  1427. char *s = strstr(*cmdline_p, "earlyprintk=");
  1428. if (s) {
  1429. setup_early_printk(strchr(s, '=') + 1);
  1430. printk("early console enabled\n");
  1431. }
  1432. }
  1433. #endif
  1434. max_low_pfn = setup_memory();
  1435. /*
  1436. * NOTE: before this point _nobody_ is allowed to allocate
  1437. * any memory using the bootmem allocator. Although the
  1438. * alloctor is now initialised only the first 8Mb of the kernel
  1439. * virtual address space has been mapped. All allocations before
  1440. * paging_init() has completed must use the alloc_bootmem_low_pages()
  1441. * variant (which allocates DMA'able memory) and care must be taken
  1442. * not to exceed the 8Mb limit.
  1443. */
  1444. #ifdef CONFIG_SMP
  1445. smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
  1446. #endif
  1447. paging_init();
  1448. remapped_pgdat_init();
  1449. sparse_init();
  1450. zone_sizes_init();
  1451. /*
  1452. * NOTE: at this point the bootmem allocator is fully available.
  1453. */
  1454. dmi_scan_machine();
  1455. #ifdef CONFIG_X86_GENERICARCH
  1456. generic_apic_probe(*cmdline_p);
  1457. #endif
  1458. if (efi_enabled)
  1459. efi_map_memmap();
  1460. #ifdef CONFIG_ACPI
  1461. /*
  1462. * Parse the ACPI tables for possible boot-time SMP configuration.
  1463. */
  1464. acpi_boot_table_init();
  1465. #endif
  1466. #ifdef CONFIG_X86_IO_APIC
  1467. check_acpi_pci(); /* Checks more than just ACPI actually */
  1468. #endif
  1469. #ifdef CONFIG_ACPI
  1470. acpi_boot_init();
  1471. #if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
  1472. if (def_to_bigsmp)
  1473. printk(KERN_WARNING "More than 8 CPUs detected and "
  1474. "CONFIG_X86_PC cannot handle it.\nUse "
  1475. "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
  1476. #endif
  1477. #endif
  1478. #ifdef CONFIG_X86_LOCAL_APIC
  1479. if (smp_found_config)
  1480. get_smp_config();
  1481. #endif
  1482. register_memory();
  1483. #ifdef CONFIG_VT
  1484. #if defined(CONFIG_VGA_CONSOLE)
  1485. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  1486. conswitchp = &vga_con;
  1487. #elif defined(CONFIG_DUMMY_CONSOLE)
  1488. conswitchp = &dummy_con;
  1489. #endif
  1490. #endif
  1491. }
  1492. static __init int add_pcspkr(void)
  1493. {
  1494. struct platform_device *pd;
  1495. int ret;
  1496. pd = platform_device_alloc("pcspkr", -1);
  1497. if (!pd)
  1498. return -ENOMEM;
  1499. ret = platform_device_add(pd);
  1500. if (ret)
  1501. platform_device_put(pd);
  1502. return ret;
  1503. }
  1504. device_initcall(add_pcspkr);
  1505. /*
  1506. * Local Variables:
  1507. * mode:c
  1508. * c-file-style:"k&r"
  1509. * c-basic-offset:8
  1510. * End:
  1511. */