setup.c 40 KB

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