setup.c 42 KB

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