setup.c 39 KB

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