setup.c 42 KB

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