setup.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /*
  2. * linux/arch/x86-64/kernel/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. *
  6. * Nov 2001 Dave Jones <davej@suse.de>
  7. * Forked from i386 setup code.
  8. *
  9. * $Id$
  10. */
  11. /*
  12. * This file handles the architecture-dependent parts of initialization
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/stddef.h>
  19. #include <linux/unistd.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/slab.h>
  22. #include <linux/user.h>
  23. #include <linux/a.out.h>
  24. #include <linux/tty.h>
  25. #include <linux/ioport.h>
  26. #include <linux/delay.h>
  27. #include <linux/config.h>
  28. #include <linux/init.h>
  29. #include <linux/initrd.h>
  30. #include <linux/highmem.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/module.h>
  33. #include <asm/processor.h>
  34. #include <linux/console.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/root_dev.h>
  37. #include <linux/pci.h>
  38. #include <linux/acpi.h>
  39. #include <linux/kallsyms.h>
  40. #include <linux/edd.h>
  41. #include <asm/mtrr.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/system.h>
  44. #include <asm/io.h>
  45. #include <asm/smp.h>
  46. #include <asm/msr.h>
  47. #include <asm/desc.h>
  48. #include <video/edid.h>
  49. #include <asm/e820.h>
  50. #include <asm/dma.h>
  51. #include <asm/mpspec.h>
  52. #include <asm/mmu_context.h>
  53. #include <asm/bootsetup.h>
  54. #include <asm/proto.h>
  55. #include <asm/setup.h>
  56. #include <asm/mach_apic.h>
  57. #include <asm/numa.h>
  58. /*
  59. * Machine setup..
  60. */
  61. struct cpuinfo_x86 boot_cpu_data;
  62. unsigned long mmu_cr4_features;
  63. int acpi_disabled;
  64. EXPORT_SYMBOL(acpi_disabled);
  65. #ifdef CONFIG_ACPI_BOOT
  66. extern int __initdata acpi_ht;
  67. extern acpi_interrupt_flags acpi_sci_flags;
  68. int __initdata acpi_force = 0;
  69. #endif
  70. int acpi_numa __initdata;
  71. /* For PCI or other memory-mapped resources */
  72. unsigned long pci_mem_start = 0x10000000;
  73. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  74. int bootloader_type;
  75. unsigned long saved_video_mode;
  76. #ifdef CONFIG_SWIOTLB
  77. int swiotlb;
  78. EXPORT_SYMBOL(swiotlb);
  79. #endif
  80. /*
  81. * Setup options
  82. */
  83. struct drive_info_struct { char dummy[32]; } drive_info;
  84. struct screen_info screen_info;
  85. struct sys_desc_table_struct {
  86. unsigned short length;
  87. unsigned char table[0];
  88. };
  89. struct edid_info edid_info;
  90. struct e820map e820;
  91. extern int root_mountflags;
  92. extern char _text, _etext, _edata, _end;
  93. char command_line[COMMAND_LINE_SIZE];
  94. struct resource standard_io_resources[] = {
  95. { .name = "dma1", .start = 0x00, .end = 0x1f,
  96. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  97. { .name = "pic1", .start = 0x20, .end = 0x21,
  98. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  99. { .name = "timer0", .start = 0x40, .end = 0x43,
  100. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  101. { .name = "timer1", .start = 0x50, .end = 0x53,
  102. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  103. { .name = "keyboard", .start = 0x60, .end = 0x6f,
  104. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  105. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  106. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  107. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  109. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  111. { .name = "fpu", .start = 0xf0, .end = 0xff,
  112. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  113. };
  114. #define STANDARD_IO_RESOURCES \
  115. (sizeof standard_io_resources / sizeof standard_io_resources[0])
  116. #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
  117. struct resource data_resource = {
  118. .name = "Kernel data",
  119. .start = 0,
  120. .end = 0,
  121. .flags = IORESOURCE_RAM,
  122. };
  123. struct resource code_resource = {
  124. .name = "Kernel code",
  125. .start = 0,
  126. .end = 0,
  127. .flags = IORESOURCE_RAM,
  128. };
  129. #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
  130. static struct resource system_rom_resource = {
  131. .name = "System ROM",
  132. .start = 0xf0000,
  133. .end = 0xfffff,
  134. .flags = IORESOURCE_ROM,
  135. };
  136. static struct resource extension_rom_resource = {
  137. .name = "Extension ROM",
  138. .start = 0xe0000,
  139. .end = 0xeffff,
  140. .flags = IORESOURCE_ROM,
  141. };
  142. static struct resource adapter_rom_resources[] = {
  143. { .name = "Adapter ROM", .start = 0xc8000, .end = 0,
  144. .flags = IORESOURCE_ROM },
  145. { .name = "Adapter ROM", .start = 0, .end = 0,
  146. .flags = IORESOURCE_ROM },
  147. { .name = "Adapter ROM", .start = 0, .end = 0,
  148. .flags = IORESOURCE_ROM },
  149. { .name = "Adapter ROM", .start = 0, .end = 0,
  150. .flags = IORESOURCE_ROM },
  151. { .name = "Adapter ROM", .start = 0, .end = 0,
  152. .flags = IORESOURCE_ROM },
  153. { .name = "Adapter ROM", .start = 0, .end = 0,
  154. .flags = IORESOURCE_ROM }
  155. };
  156. #define ADAPTER_ROM_RESOURCES \
  157. (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
  158. static struct resource video_rom_resource = {
  159. .name = "Video ROM",
  160. .start = 0xc0000,
  161. .end = 0xc7fff,
  162. .flags = IORESOURCE_ROM,
  163. };
  164. static struct resource video_ram_resource = {
  165. .name = "Video RAM area",
  166. .start = 0xa0000,
  167. .end = 0xbffff,
  168. .flags = IORESOURCE_RAM,
  169. };
  170. #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
  171. static int __init romchecksum(unsigned char *rom, unsigned long length)
  172. {
  173. unsigned char *p, sum = 0;
  174. for (p = rom; p < rom + length; p++)
  175. sum += *p;
  176. return sum == 0;
  177. }
  178. static void __init probe_roms(void)
  179. {
  180. unsigned long start, length, upper;
  181. unsigned char *rom;
  182. int i;
  183. /* video rom */
  184. upper = adapter_rom_resources[0].start;
  185. for (start = video_rom_resource.start; start < upper; start += 2048) {
  186. rom = isa_bus_to_virt(start);
  187. if (!romsignature(rom))
  188. continue;
  189. video_rom_resource.start = start;
  190. /* 0 < length <= 0x7f * 512, historically */
  191. length = rom[2] * 512;
  192. /* if checksum okay, trust length byte */
  193. if (length && romchecksum(rom, length))
  194. video_rom_resource.end = start + length - 1;
  195. request_resource(&iomem_resource, &video_rom_resource);
  196. break;
  197. }
  198. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  199. if (start < upper)
  200. start = upper;
  201. /* system rom */
  202. request_resource(&iomem_resource, &system_rom_resource);
  203. upper = system_rom_resource.start;
  204. /* check for extension rom (ignore length byte!) */
  205. rom = isa_bus_to_virt(extension_rom_resource.start);
  206. if (romsignature(rom)) {
  207. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  208. if (romchecksum(rom, length)) {
  209. request_resource(&iomem_resource, &extension_rom_resource);
  210. upper = extension_rom_resource.start;
  211. }
  212. }
  213. /* check for adapter roms on 2k boundaries */
  214. for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
  215. rom = isa_bus_to_virt(start);
  216. if (!romsignature(rom))
  217. continue;
  218. /* 0 < length <= 0x7f * 512, historically */
  219. length = rom[2] * 512;
  220. /* but accept any length that fits if checksum okay */
  221. if (!length || start + length > upper || !romchecksum(rom, length))
  222. continue;
  223. adapter_rom_resources[i].start = start;
  224. adapter_rom_resources[i].end = start + length - 1;
  225. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  226. start = adapter_rom_resources[i++].end & ~2047UL;
  227. }
  228. }
  229. static __init void parse_cmdline_early (char ** cmdline_p)
  230. {
  231. char c = ' ', *to = command_line, *from = COMMAND_LINE;
  232. int len = 0;
  233. /* Save unparsed command line copy for /proc/cmdline */
  234. memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  235. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  236. for (;;) {
  237. if (c != ' ')
  238. goto next_char;
  239. #ifdef CONFIG_SMP
  240. /*
  241. * If the BIOS enumerates physical processors before logical,
  242. * maxcpus=N at enumeration-time can be used to disable HT.
  243. */
  244. else if (!memcmp(from, "maxcpus=", 8)) {
  245. extern unsigned int maxcpus;
  246. maxcpus = simple_strtoul(from + 8, NULL, 0);
  247. }
  248. #endif
  249. #ifdef CONFIG_ACPI_BOOT
  250. /* "acpi=off" disables both ACPI table parsing and interpreter init */
  251. if (!memcmp(from, "acpi=off", 8))
  252. disable_acpi();
  253. if (!memcmp(from, "acpi=force", 10)) {
  254. /* add later when we do DMI horrors: */
  255. acpi_force = 1;
  256. acpi_disabled = 0;
  257. }
  258. /* acpi=ht just means: do ACPI MADT parsing
  259. at bootup, but don't enable the full ACPI interpreter */
  260. if (!memcmp(from, "acpi=ht", 7)) {
  261. if (!acpi_force)
  262. disable_acpi();
  263. acpi_ht = 1;
  264. }
  265. else if (!memcmp(from, "pci=noacpi", 10))
  266. acpi_disable_pci();
  267. else if (!memcmp(from, "acpi=noirq", 10))
  268. acpi_noirq_set();
  269. else if (!memcmp(from, "acpi_sci=edge", 13))
  270. acpi_sci_flags.trigger = 1;
  271. else if (!memcmp(from, "acpi_sci=level", 14))
  272. acpi_sci_flags.trigger = 3;
  273. else if (!memcmp(from, "acpi_sci=high", 13))
  274. acpi_sci_flags.polarity = 1;
  275. else if (!memcmp(from, "acpi_sci=low", 12))
  276. acpi_sci_flags.polarity = 3;
  277. /* acpi=strict disables out-of-spec workarounds */
  278. else if (!memcmp(from, "acpi=strict", 11)) {
  279. acpi_strict = 1;
  280. }
  281. #endif
  282. if (!memcmp(from, "nolapic", 7) ||
  283. !memcmp(from, "disableapic", 11))
  284. disable_apic = 1;
  285. if (!memcmp(from, "noapic", 6))
  286. skip_ioapic_setup = 1;
  287. if (!memcmp(from, "apic", 4)) {
  288. skip_ioapic_setup = 0;
  289. ioapic_force = 1;
  290. }
  291. if (!memcmp(from, "mem=", 4))
  292. parse_memopt(from+4, &from);
  293. #ifdef CONFIG_DISCONTIGMEM
  294. if (!memcmp(from, "numa=", 5))
  295. numa_setup(from+5);
  296. #endif
  297. #ifdef CONFIG_GART_IOMMU
  298. if (!memcmp(from,"iommu=",6)) {
  299. iommu_setup(from+6);
  300. }
  301. #endif
  302. if (!memcmp(from,"oops=panic", 10))
  303. panic_on_oops = 1;
  304. if (!memcmp(from, "noexec=", 7))
  305. nonx_setup(from + 7);
  306. next_char:
  307. c = *(from++);
  308. if (!c)
  309. break;
  310. if (COMMAND_LINE_SIZE <= ++len)
  311. break;
  312. *(to++) = c;
  313. }
  314. *to = '\0';
  315. *cmdline_p = command_line;
  316. }
  317. #ifndef CONFIG_DISCONTIGMEM
  318. static void __init contig_initmem_init(void)
  319. {
  320. unsigned long bootmap_size, bootmap;
  321. bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
  322. bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
  323. if (bootmap == -1L)
  324. panic("Cannot find bootmem map of size %ld\n",bootmap_size);
  325. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
  326. e820_bootmem_free(&contig_page_data, 0, end_pfn << PAGE_SHIFT);
  327. reserve_bootmem(bootmap, bootmap_size);
  328. }
  329. #endif
  330. /* Use inline assembly to define this because the nops are defined
  331. as inline assembly strings in the include files and we cannot
  332. get them easily into strings. */
  333. asm("\t.data\nk8nops: "
  334. K8_NOP1 K8_NOP2 K8_NOP3 K8_NOP4 K8_NOP5 K8_NOP6
  335. K8_NOP7 K8_NOP8);
  336. extern unsigned char k8nops[];
  337. static unsigned char *k8_nops[ASM_NOP_MAX+1] = {
  338. NULL,
  339. k8nops,
  340. k8nops + 1,
  341. k8nops + 1 + 2,
  342. k8nops + 1 + 2 + 3,
  343. k8nops + 1 + 2 + 3 + 4,
  344. k8nops + 1 + 2 + 3 + 4 + 5,
  345. k8nops + 1 + 2 + 3 + 4 + 5 + 6,
  346. k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  347. };
  348. /* Replace instructions with better alternatives for this CPU type.
  349. This runs before SMP is initialized to avoid SMP problems with
  350. self modifying code. This implies that assymetric systems where
  351. APs have less capabilities than the boot processor are not handled.
  352. In this case boot with "noreplacement". */
  353. void apply_alternatives(void *start, void *end)
  354. {
  355. struct alt_instr *a;
  356. int diff, i, k;
  357. for (a = start; (void *)a < end; a++) {
  358. if (!boot_cpu_has(a->cpuid))
  359. continue;
  360. BUG_ON(a->replacementlen > a->instrlen);
  361. __inline_memcpy(a->instr, a->replacement, a->replacementlen);
  362. diff = a->instrlen - a->replacementlen;
  363. /* Pad the rest with nops */
  364. for (i = a->replacementlen; diff > 0; diff -= k, i += k) {
  365. k = diff;
  366. if (k > ASM_NOP_MAX)
  367. k = ASM_NOP_MAX;
  368. __inline_memcpy(a->instr + i, k8_nops[k], k);
  369. }
  370. }
  371. }
  372. static int no_replacement __initdata = 0;
  373. void __init alternative_instructions(void)
  374. {
  375. extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
  376. if (no_replacement)
  377. return;
  378. apply_alternatives(__alt_instructions, __alt_instructions_end);
  379. }
  380. static int __init noreplacement_setup(char *s)
  381. {
  382. no_replacement = 1;
  383. return 0;
  384. }
  385. __setup("noreplacement", noreplacement_setup);
  386. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  387. struct edd edd;
  388. #ifdef CONFIG_EDD_MODULE
  389. EXPORT_SYMBOL(edd);
  390. #endif
  391. /**
  392. * copy_edd() - Copy the BIOS EDD information
  393. * from boot_params into a safe place.
  394. *
  395. */
  396. static inline void copy_edd(void)
  397. {
  398. memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
  399. memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
  400. edd.mbr_signature_nr = EDD_MBR_SIG_NR;
  401. edd.edd_info_nr = EDD_NR;
  402. }
  403. #else
  404. static inline void copy_edd(void)
  405. {
  406. }
  407. #endif
  408. #define EBDA_ADDR_POINTER 0x40E
  409. static void __init reserve_ebda_region(void)
  410. {
  411. unsigned int addr;
  412. /**
  413. * there is a real-mode segmented pointer pointing to the
  414. * 4K EBDA area at 0x40E
  415. */
  416. addr = *(unsigned short *)phys_to_virt(EBDA_ADDR_POINTER);
  417. addr <<= 4;
  418. if (addr)
  419. reserve_bootmem_generic(addr, PAGE_SIZE);
  420. }
  421. void __init setup_arch(char **cmdline_p)
  422. {
  423. unsigned long low_mem_size;
  424. unsigned long kernel_end;
  425. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  426. drive_info = DRIVE_INFO;
  427. screen_info = SCREEN_INFO;
  428. edid_info = EDID_INFO;
  429. saved_video_mode = SAVED_VIDEO_MODE;
  430. bootloader_type = LOADER_TYPE;
  431. #ifdef CONFIG_BLK_DEV_RAM
  432. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  433. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  434. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  435. #endif
  436. setup_memory_region();
  437. copy_edd();
  438. if (!MOUNT_ROOT_RDONLY)
  439. root_mountflags &= ~MS_RDONLY;
  440. init_mm.start_code = (unsigned long) &_text;
  441. init_mm.end_code = (unsigned long) &_etext;
  442. init_mm.end_data = (unsigned long) &_edata;
  443. init_mm.brk = (unsigned long) &_end;
  444. code_resource.start = virt_to_phys(&_text);
  445. code_resource.end = virt_to_phys(&_etext)-1;
  446. data_resource.start = virt_to_phys(&_etext);
  447. data_resource.end = virt_to_phys(&_edata)-1;
  448. parse_cmdline_early(cmdline_p);
  449. early_identify_cpu(&boot_cpu_data);
  450. /*
  451. * partially used pages are not usable - thus
  452. * we are rounding upwards:
  453. */
  454. end_pfn = e820_end_of_ram();
  455. check_efer();
  456. init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
  457. #ifdef CONFIG_ACPI_BOOT
  458. /*
  459. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  460. * Call this early for SRAT node setup.
  461. */
  462. acpi_boot_table_init();
  463. #endif
  464. #ifdef CONFIG_ACPI_NUMA
  465. /*
  466. * Parse SRAT to discover nodes.
  467. */
  468. acpi_numa_init();
  469. #endif
  470. #ifdef CONFIG_DISCONTIGMEM
  471. numa_initmem_init(0, end_pfn);
  472. #else
  473. contig_initmem_init();
  474. #endif
  475. /* Reserve direct mapping */
  476. reserve_bootmem_generic(table_start << PAGE_SHIFT,
  477. (table_end - table_start) << PAGE_SHIFT);
  478. /* reserve kernel */
  479. kernel_end = round_up(__pa_symbol(&_end),PAGE_SIZE);
  480. reserve_bootmem_generic(HIGH_MEMORY, kernel_end - HIGH_MEMORY);
  481. /*
  482. * reserve physical page 0 - it's a special BIOS page on many boxes,
  483. * enabling clean reboots, SMP operation, laptop functions.
  484. */
  485. reserve_bootmem_generic(0, PAGE_SIZE);
  486. /* reserve ebda region */
  487. reserve_ebda_region();
  488. #ifdef CONFIG_SMP
  489. /*
  490. * But first pinch a few for the stack/trampoline stuff
  491. * FIXME: Don't need the extra page at 4K, but need to fix
  492. * trampoline before removing it. (see the GDT stuff)
  493. */
  494. reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
  495. /* Reserve SMP trampoline */
  496. reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
  497. #endif
  498. #ifdef CONFIG_ACPI_SLEEP
  499. /*
  500. * Reserve low memory region for sleep support.
  501. */
  502. acpi_reserve_bootmem();
  503. #endif
  504. #ifdef CONFIG_X86_LOCAL_APIC
  505. /*
  506. * Find and reserve possible boot-time SMP configuration:
  507. */
  508. find_smp_config();
  509. #endif
  510. #ifdef CONFIG_BLK_DEV_INITRD
  511. if (LOADER_TYPE && INITRD_START) {
  512. if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
  513. reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
  514. initrd_start =
  515. INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
  516. initrd_end = initrd_start+INITRD_SIZE;
  517. }
  518. else {
  519. printk(KERN_ERR "initrd extends beyond end of memory "
  520. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  521. (unsigned long)(INITRD_START + INITRD_SIZE),
  522. (unsigned long)(end_pfn << PAGE_SHIFT));
  523. initrd_start = 0;
  524. }
  525. }
  526. #endif
  527. paging_init();
  528. check_ioapic();
  529. #ifdef CONFIG_ACPI_BOOT
  530. /*
  531. * Read APIC and some other early information from ACPI tables.
  532. */
  533. acpi_boot_init();
  534. #endif
  535. #ifdef CONFIG_X86_LOCAL_APIC
  536. /*
  537. * get boot-time SMP configuration:
  538. */
  539. if (smp_found_config)
  540. get_smp_config();
  541. init_apic_mappings();
  542. #endif
  543. /*
  544. * Request address space for all standard RAM and ROM resources
  545. * and also for regions reported as reserved by the e820.
  546. */
  547. probe_roms();
  548. e820_reserve_resources();
  549. request_resource(&iomem_resource, &video_ram_resource);
  550. {
  551. unsigned i;
  552. /* request I/O space for devices used on all i[345]86 PCs */
  553. for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  554. request_resource(&ioport_resource, &standard_io_resources[i]);
  555. }
  556. /* Will likely break when you have unassigned resources with more
  557. than 4GB memory and bridges that don't support more than 4GB.
  558. Doing it properly would require to use pci_alloc_consistent
  559. in this case. */
  560. low_mem_size = ((end_pfn << PAGE_SHIFT) + 0xfffff) & ~0xfffff;
  561. if (low_mem_size > pci_mem_start)
  562. pci_mem_start = low_mem_size;
  563. #ifdef CONFIG_GART_IOMMU
  564. iommu_hole_init();
  565. #endif
  566. #ifdef CONFIG_VT
  567. #if defined(CONFIG_VGA_CONSOLE)
  568. conswitchp = &vga_con;
  569. #elif defined(CONFIG_DUMMY_CONSOLE)
  570. conswitchp = &dummy_con;
  571. #endif
  572. #endif
  573. }
  574. static int __init get_model_name(struct cpuinfo_x86 *c)
  575. {
  576. unsigned int *v;
  577. if (c->x86_cpuid_level < 0x80000004)
  578. return 0;
  579. v = (unsigned int *) c->x86_model_id;
  580. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  581. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  582. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  583. c->x86_model_id[48] = 0;
  584. return 1;
  585. }
  586. static void __init display_cacheinfo(struct cpuinfo_x86 *c)
  587. {
  588. unsigned int n, dummy, eax, ebx, ecx, edx;
  589. n = c->x86_cpuid_level;
  590. if (n >= 0x80000005) {
  591. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  592. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
  593. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  594. c->x86_cache_size=(ecx>>24)+(edx>>24);
  595. /* On K8 L1 TLB is inclusive, so don't count it */
  596. c->x86_tlbsize = 0;
  597. }
  598. if (n >= 0x80000006) {
  599. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  600. ecx = cpuid_ecx(0x80000006);
  601. c->x86_cache_size = ecx >> 16;
  602. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  603. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  604. c->x86_cache_size, ecx & 0xFF);
  605. }
  606. if (n >= 0x80000007)
  607. cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
  608. if (n >= 0x80000008) {
  609. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  610. c->x86_virt_bits = (eax >> 8) & 0xff;
  611. c->x86_phys_bits = eax & 0xff;
  612. }
  613. }
  614. static int __init init_amd(struct cpuinfo_x86 *c)
  615. {
  616. int r;
  617. int level;
  618. #ifdef CONFIG_NUMA
  619. int cpu;
  620. #endif
  621. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  622. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  623. clear_bit(0*32+31, &c->x86_capability);
  624. /* C-stepping K8? */
  625. level = cpuid_eax(1);
  626. if ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
  627. set_bit(X86_FEATURE_K8_C, &c->x86_capability);
  628. r = get_model_name(c);
  629. if (!r) {
  630. switch (c->x86) {
  631. case 15:
  632. /* Should distinguish Models here, but this is only
  633. a fallback anyways. */
  634. strcpy(c->x86_model_id, "Hammer");
  635. break;
  636. }
  637. }
  638. display_cacheinfo(c);
  639. if (c->x86_cpuid_level >= 0x80000008) {
  640. c->x86_num_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
  641. if (c->x86_num_cores & (c->x86_num_cores - 1))
  642. c->x86_num_cores = 1;
  643. #ifdef CONFIG_NUMA
  644. /* On a dual core setup the lower bits of apic id
  645. distingush the cores. Fix up the CPU<->node mappings
  646. here based on that.
  647. Assumes number of cores is a power of two.
  648. When using SRAT use mapping from SRAT. */
  649. cpu = c->x86_apicid;
  650. if (acpi_numa <= 0 && c->x86_num_cores > 1) {
  651. cpu_to_node[cpu] = cpu >> hweight32(c->x86_num_cores - 1);
  652. if (!node_online(cpu_to_node[cpu]))
  653. cpu_to_node[cpu] = first_node(node_online_map);
  654. }
  655. printk(KERN_INFO "CPU %d(%d) -> Node %d\n",
  656. cpu, c->x86_num_cores, cpu_to_node[cpu]);
  657. #endif
  658. }
  659. return r;
  660. }
  661. static void __init detect_ht(struct cpuinfo_x86 *c)
  662. {
  663. #ifdef CONFIG_SMP
  664. u32 eax, ebx, ecx, edx;
  665. int index_lsb, index_msb, tmp;
  666. int cpu = smp_processor_id();
  667. if (!cpu_has(c, X86_FEATURE_HT))
  668. return;
  669. cpuid(1, &eax, &ebx, &ecx, &edx);
  670. smp_num_siblings = (ebx & 0xff0000) >> 16;
  671. if (smp_num_siblings == 1) {
  672. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  673. } else if (smp_num_siblings > 1) {
  674. index_lsb = 0;
  675. index_msb = 31;
  676. /*
  677. * At this point we only support two siblings per
  678. * processor package.
  679. */
  680. if (smp_num_siblings > NR_CPUS) {
  681. printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
  682. smp_num_siblings = 1;
  683. return;
  684. }
  685. tmp = smp_num_siblings;
  686. while ((tmp & 1) == 0) {
  687. tmp >>=1 ;
  688. index_lsb++;
  689. }
  690. tmp = smp_num_siblings;
  691. while ((tmp & 0x80000000 ) == 0) {
  692. tmp <<=1 ;
  693. index_msb--;
  694. }
  695. if (index_lsb != index_msb )
  696. index_msb++;
  697. phys_proc_id[cpu] = phys_pkg_id(index_msb);
  698. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  699. phys_proc_id[cpu]);
  700. }
  701. #endif
  702. }
  703. static void __init sched_cmp_hack(struct cpuinfo_x86 *c)
  704. {
  705. #ifdef CONFIG_SMP
  706. /* AMD dual core looks like HT but isn't really. Hide it from the
  707. scheduler. This works around problems with the domain scheduler.
  708. Also probably gives slightly better scheduling and disables
  709. SMT nice which is harmful on dual core.
  710. TBD tune the domain scheduler for dual core. */
  711. if (c->x86_vendor == X86_VENDOR_AMD && cpu_has(c, X86_FEATURE_CMP_LEGACY))
  712. smp_num_siblings = 1;
  713. #endif
  714. }
  715. static void __init init_intel(struct cpuinfo_x86 *c)
  716. {
  717. /* Cache sizes */
  718. unsigned n;
  719. init_intel_cacheinfo(c);
  720. n = c->x86_cpuid_level;
  721. if (n >= 0x80000008) {
  722. unsigned eax = cpuid_eax(0x80000008);
  723. c->x86_virt_bits = (eax >> 8) & 0xff;
  724. c->x86_phys_bits = eax & 0xff;
  725. }
  726. if (c->x86 == 15)
  727. c->x86_cache_alignment = c->x86_clflush_size * 2;
  728. }
  729. void __init get_cpu_vendor(struct cpuinfo_x86 *c)
  730. {
  731. char *v = c->x86_vendor_id;
  732. if (!strcmp(v, "AuthenticAMD"))
  733. c->x86_vendor = X86_VENDOR_AMD;
  734. else if (!strcmp(v, "GenuineIntel"))
  735. c->x86_vendor = X86_VENDOR_INTEL;
  736. else
  737. c->x86_vendor = X86_VENDOR_UNKNOWN;
  738. }
  739. struct cpu_model_info {
  740. int vendor;
  741. int family;
  742. char *model_names[16];
  743. };
  744. /* Do some early cpuid on the boot CPU to get some parameter that are
  745. needed before check_bugs. Everything advanced is in identify_cpu
  746. below. */
  747. void __init early_identify_cpu(struct cpuinfo_x86 *c)
  748. {
  749. u32 tfms;
  750. c->loops_per_jiffy = loops_per_jiffy;
  751. c->x86_cache_size = -1;
  752. c->x86_vendor = X86_VENDOR_UNKNOWN;
  753. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  754. c->x86_vendor_id[0] = '\0'; /* Unset */
  755. c->x86_model_id[0] = '\0'; /* Unset */
  756. c->x86_clflush_size = 64;
  757. c->x86_cache_alignment = c->x86_clflush_size;
  758. c->x86_num_cores = 1;
  759. c->x86_apicid = c == &boot_cpu_data ? 0 : c - cpu_data;
  760. c->x86_cpuid_level = 0;
  761. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  762. /* Get vendor name */
  763. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  764. (unsigned int *)&c->x86_vendor_id[0],
  765. (unsigned int *)&c->x86_vendor_id[8],
  766. (unsigned int *)&c->x86_vendor_id[4]);
  767. get_cpu_vendor(c);
  768. /* Initialize the standard set of capabilities */
  769. /* Note that the vendor-specific code below might override */
  770. /* Intel-defined flags: level 0x00000001 */
  771. if (c->cpuid_level >= 0x00000001) {
  772. __u32 misc;
  773. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  774. &c->x86_capability[0]);
  775. c->x86 = (tfms >> 8) & 0xf;
  776. c->x86_model = (tfms >> 4) & 0xf;
  777. c->x86_mask = tfms & 0xf;
  778. if (c->x86 == 0xf) {
  779. c->x86 += (tfms >> 20) & 0xff;
  780. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  781. }
  782. if (c->x86_capability[0] & (1<<19))
  783. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  784. c->x86_apicid = misc >> 24;
  785. } else {
  786. /* Have CPUID level 0 only - unheard of */
  787. c->x86 = 4;
  788. }
  789. }
  790. /*
  791. * This does the hard work of actually picking apart the CPU stuff...
  792. */
  793. void __init identify_cpu(struct cpuinfo_x86 *c)
  794. {
  795. int i;
  796. u32 xlvl;
  797. early_identify_cpu(c);
  798. /* AMD-defined flags: level 0x80000001 */
  799. xlvl = cpuid_eax(0x80000000);
  800. c->x86_cpuid_level = xlvl;
  801. if ((xlvl & 0xffff0000) == 0x80000000) {
  802. if (xlvl >= 0x80000001) {
  803. c->x86_capability[1] = cpuid_edx(0x80000001);
  804. c->x86_capability[5] = cpuid_ecx(0x80000001);
  805. }
  806. if (xlvl >= 0x80000004)
  807. get_model_name(c); /* Default name */
  808. }
  809. /* Transmeta-defined flags: level 0x80860001 */
  810. xlvl = cpuid_eax(0x80860000);
  811. if ((xlvl & 0xffff0000) == 0x80860000) {
  812. /* Don't set x86_cpuid_level here for now to not confuse. */
  813. if (xlvl >= 0x80860001)
  814. c->x86_capability[2] = cpuid_edx(0x80860001);
  815. }
  816. /*
  817. * Vendor-specific initialization. In this section we
  818. * canonicalize the feature flags, meaning if there are
  819. * features a certain CPU supports which CPUID doesn't
  820. * tell us, CPUID claiming incorrect flags, or other bugs,
  821. * we handle them here.
  822. *
  823. * At the end of this section, c->x86_capability better
  824. * indicate the features this CPU genuinely supports!
  825. */
  826. switch (c->x86_vendor) {
  827. case X86_VENDOR_AMD:
  828. init_amd(c);
  829. break;
  830. case X86_VENDOR_INTEL:
  831. init_intel(c);
  832. break;
  833. case X86_VENDOR_UNKNOWN:
  834. default:
  835. display_cacheinfo(c);
  836. break;
  837. }
  838. select_idle_routine(c);
  839. detect_ht(c);
  840. sched_cmp_hack(c);
  841. /*
  842. * On SMP, boot_cpu_data holds the common feature set between
  843. * all CPUs; so make sure that we indicate which features are
  844. * common between the CPUs. The first time this routine gets
  845. * executed, c == &boot_cpu_data.
  846. */
  847. if (c != &boot_cpu_data) {
  848. /* AND the already accumulated flags with these */
  849. for (i = 0 ; i < NCAPINTS ; i++)
  850. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  851. }
  852. #ifdef CONFIG_X86_MCE
  853. mcheck_init(c);
  854. #endif
  855. #ifdef CONFIG_NUMA
  856. if (c != &boot_cpu_data)
  857. numa_add_cpu(c - cpu_data);
  858. #endif
  859. }
  860. void __init print_cpu_info(struct cpuinfo_x86 *c)
  861. {
  862. if (c->x86_model_id[0])
  863. printk("%s", c->x86_model_id);
  864. if (c->x86_mask || c->cpuid_level >= 0)
  865. printk(" stepping %02x\n", c->x86_mask);
  866. else
  867. printk("\n");
  868. }
  869. /*
  870. * Get CPU information for use by the procfs.
  871. */
  872. static int show_cpuinfo(struct seq_file *m, void *v)
  873. {
  874. struct cpuinfo_x86 *c = v;
  875. /*
  876. * These flag bits must match the definitions in <asm/cpufeature.h>.
  877. * NULL means this bit is undefined or reserved; either way it doesn't
  878. * have meaning as far as Linux is concerned. Note that it's important
  879. * to realize there is a difference between this table and CPUID -- if
  880. * applications want to get the raw CPUID data, they should access
  881. * /dev/cpu/<cpu_nr>/cpuid instead.
  882. */
  883. static char *x86_cap_flags[] = {
  884. /* Intel-defined */
  885. "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
  886. "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
  887. "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
  888. "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
  889. /* AMD-defined */
  890. "pni", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  891. NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
  892. NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
  893. NULL, "fxsr_opt", NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
  894. /* Transmeta-defined */
  895. "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
  896. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  897. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  898. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  899. /* Other (Linux-defined) */
  900. "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr", NULL, NULL, NULL, NULL,
  901. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  902. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  903. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  904. /* Intel-defined (#2) */
  905. "pni", NULL, NULL, "monitor", "ds_cpl", NULL, NULL, "est",
  906. "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
  907. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  908. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  909. /* AMD-defined (#2) */
  910. "lahf_lm", "cmp_legacy", NULL, NULL, NULL, NULL, NULL, NULL,
  911. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  912. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  913. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  914. };
  915. static char *x86_power_flags[] = {
  916. "ts", /* temperature sensor */
  917. "fid", /* frequency id control */
  918. "vid", /* voltage id control */
  919. "ttp", /* thermal trip */
  920. "tm",
  921. "stc"
  922. };
  923. #ifdef CONFIG_SMP
  924. if (!cpu_online(c-cpu_data))
  925. return 0;
  926. #endif
  927. seq_printf(m,"processor\t: %u\n"
  928. "vendor_id\t: %s\n"
  929. "cpu family\t: %d\n"
  930. "model\t\t: %d\n"
  931. "model name\t: %s\n",
  932. (unsigned)(c-cpu_data),
  933. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  934. c->x86,
  935. (int)c->x86_model,
  936. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  937. if (c->x86_mask || c->cpuid_level >= 0)
  938. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  939. else
  940. seq_printf(m, "stepping\t: unknown\n");
  941. if (cpu_has(c,X86_FEATURE_TSC)) {
  942. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  943. cpu_khz / 1000, (cpu_khz % 1000));
  944. }
  945. /* Cache size */
  946. if (c->x86_cache_size >= 0)
  947. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  948. #ifdef CONFIG_SMP
  949. if (smp_num_siblings * c->x86_num_cores > 1) {
  950. int cpu = c - cpu_data;
  951. seq_printf(m, "physical id\t: %d\n", phys_proc_id[cpu]);
  952. seq_printf(m, "siblings\t: %d\n",
  953. c->x86_num_cores * smp_num_siblings);
  954. }
  955. #endif
  956. seq_printf(m,
  957. "fpu\t\t: yes\n"
  958. "fpu_exception\t: yes\n"
  959. "cpuid level\t: %d\n"
  960. "wp\t\t: yes\n"
  961. "flags\t\t:",
  962. c->cpuid_level);
  963. {
  964. int i;
  965. for ( i = 0 ; i < 32*NCAPINTS ; i++ )
  966. if ( test_bit(i, &c->x86_capability) &&
  967. x86_cap_flags[i] != NULL )
  968. seq_printf(m, " %s", x86_cap_flags[i]);
  969. }
  970. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  971. c->loops_per_jiffy/(500000/HZ),
  972. (c->loops_per_jiffy/(5000/HZ)) % 100);
  973. if (c->x86_tlbsize > 0)
  974. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  975. seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
  976. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  977. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  978. c->x86_phys_bits, c->x86_virt_bits);
  979. seq_printf(m, "power management:");
  980. {
  981. unsigned i;
  982. for (i = 0; i < 32; i++)
  983. if (c->x86_power & (1 << i)) {
  984. if (i < ARRAY_SIZE(x86_power_flags))
  985. seq_printf(m, " %s", x86_power_flags[i]);
  986. else
  987. seq_printf(m, " [%d]", i);
  988. }
  989. }
  990. seq_printf(m, "\n");
  991. if (c->x86_num_cores > 1)
  992. seq_printf(m, "cpu cores\t: %d\n", c->x86_num_cores);
  993. seq_printf(m, "\n\n");
  994. return 0;
  995. }
  996. static void *c_start(struct seq_file *m, loff_t *pos)
  997. {
  998. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  999. }
  1000. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  1001. {
  1002. ++*pos;
  1003. return c_start(m, pos);
  1004. }
  1005. static void c_stop(struct seq_file *m, void *v)
  1006. {
  1007. }
  1008. struct seq_operations cpuinfo_op = {
  1009. .start =c_start,
  1010. .next = c_next,
  1011. .stop = c_stop,
  1012. .show = show_cpuinfo,
  1013. };