setup.c 40 KB

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