setup.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  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/crash_dump.h>
  37. #include <linux/root_dev.h>
  38. #include <linux/pci.h>
  39. #include <linux/acpi.h>
  40. #include <linux/kallsyms.h>
  41. #include <linux/edd.h>
  42. #include <linux/mmzone.h>
  43. #include <linux/kexec.h>
  44. #include <linux/cpufreq.h>
  45. #include <linux/dmi.h>
  46. #include <linux/dma-mapping.h>
  47. #include <linux/ctype.h>
  48. #include <asm/mtrr.h>
  49. #include <asm/uaccess.h>
  50. #include <asm/system.h>
  51. #include <asm/io.h>
  52. #include <asm/smp.h>
  53. #include <asm/msr.h>
  54. #include <asm/desc.h>
  55. #include <video/edid.h>
  56. #include <asm/e820.h>
  57. #include <asm/dma.h>
  58. #include <asm/mpspec.h>
  59. #include <asm/mmu_context.h>
  60. #include <asm/bootsetup.h>
  61. #include <asm/proto.h>
  62. #include <asm/setup.h>
  63. #include <asm/mach_apic.h>
  64. #include <asm/numa.h>
  65. #include <asm/swiotlb.h>
  66. #include <asm/sections.h>
  67. #include <asm/gart-mapping.h>
  68. #include <asm/dmi.h>
  69. /*
  70. * Machine setup..
  71. */
  72. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  73. unsigned long mmu_cr4_features;
  74. int acpi_disabled;
  75. EXPORT_SYMBOL(acpi_disabled);
  76. #ifdef CONFIG_ACPI
  77. extern int __initdata acpi_ht;
  78. extern acpi_interrupt_flags acpi_sci_flags;
  79. int __initdata acpi_force = 0;
  80. #endif
  81. int acpi_numa __initdata;
  82. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  83. int bootloader_type;
  84. unsigned long saved_video_mode;
  85. /*
  86. * Early DMI memory
  87. */
  88. int dmi_alloc_index;
  89. char dmi_alloc_data[DMI_MAX_DATA];
  90. /*
  91. * Setup options
  92. */
  93. struct screen_info screen_info;
  94. struct sys_desc_table_struct {
  95. unsigned short length;
  96. unsigned char table[0];
  97. };
  98. struct edid_info edid_info;
  99. struct e820map e820;
  100. extern int root_mountflags;
  101. char command_line[COMMAND_LINE_SIZE];
  102. struct resource standard_io_resources[] = {
  103. { .name = "dma1", .start = 0x00, .end = 0x1f,
  104. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  105. { .name = "pic1", .start = 0x20, .end = 0x21,
  106. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  107. { .name = "timer0", .start = 0x40, .end = 0x43,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  109. { .name = "timer1", .start = 0x50, .end = 0x53,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  111. { .name = "keyboard", .start = 0x60, .end = 0x6f,
  112. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  113. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  114. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  115. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  116. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  117. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  118. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  119. { .name = "fpu", .start = 0xf0, .end = 0xff,
  120. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  121. };
  122. #define STANDARD_IO_RESOURCES \
  123. (sizeof standard_io_resources / sizeof standard_io_resources[0])
  124. #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
  125. struct resource data_resource = {
  126. .name = "Kernel data",
  127. .start = 0,
  128. .end = 0,
  129. .flags = IORESOURCE_RAM,
  130. };
  131. struct resource code_resource = {
  132. .name = "Kernel code",
  133. .start = 0,
  134. .end = 0,
  135. .flags = IORESOURCE_RAM,
  136. };
  137. #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
  138. static struct resource system_rom_resource = {
  139. .name = "System ROM",
  140. .start = 0xf0000,
  141. .end = 0xfffff,
  142. .flags = IORESOURCE_ROM,
  143. };
  144. static struct resource extension_rom_resource = {
  145. .name = "Extension ROM",
  146. .start = 0xe0000,
  147. .end = 0xeffff,
  148. .flags = IORESOURCE_ROM,
  149. };
  150. static struct resource adapter_rom_resources[] = {
  151. { .name = "Adapter ROM", .start = 0xc8000, .end = 0,
  152. .flags = IORESOURCE_ROM },
  153. { .name = "Adapter ROM", .start = 0, .end = 0,
  154. .flags = IORESOURCE_ROM },
  155. { .name = "Adapter ROM", .start = 0, .end = 0,
  156. .flags = IORESOURCE_ROM },
  157. { .name = "Adapter ROM", .start = 0, .end = 0,
  158. .flags = IORESOURCE_ROM },
  159. { .name = "Adapter ROM", .start = 0, .end = 0,
  160. .flags = IORESOURCE_ROM },
  161. { .name = "Adapter ROM", .start = 0, .end = 0,
  162. .flags = IORESOURCE_ROM }
  163. };
  164. #define ADAPTER_ROM_RESOURCES \
  165. (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
  166. static struct resource video_rom_resource = {
  167. .name = "Video ROM",
  168. .start = 0xc0000,
  169. .end = 0xc7fff,
  170. .flags = IORESOURCE_ROM,
  171. };
  172. static struct resource video_ram_resource = {
  173. .name = "Video RAM area",
  174. .start = 0xa0000,
  175. .end = 0xbffff,
  176. .flags = IORESOURCE_RAM,
  177. };
  178. #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
  179. static int __init romchecksum(unsigned char *rom, unsigned long length)
  180. {
  181. unsigned char *p, sum = 0;
  182. for (p = rom; p < rom + length; p++)
  183. sum += *p;
  184. return sum == 0;
  185. }
  186. static void __init probe_roms(void)
  187. {
  188. unsigned long start, length, upper;
  189. unsigned char *rom;
  190. int i;
  191. /* video rom */
  192. upper = adapter_rom_resources[0].start;
  193. for (start = video_rom_resource.start; start < upper; start += 2048) {
  194. rom = isa_bus_to_virt(start);
  195. if (!romsignature(rom))
  196. continue;
  197. video_rom_resource.start = start;
  198. /* 0 < length <= 0x7f * 512, historically */
  199. length = rom[2] * 512;
  200. /* if checksum okay, trust length byte */
  201. if (length && romchecksum(rom, length))
  202. video_rom_resource.end = start + length - 1;
  203. request_resource(&iomem_resource, &video_rom_resource);
  204. break;
  205. }
  206. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  207. if (start < upper)
  208. start = upper;
  209. /* system rom */
  210. request_resource(&iomem_resource, &system_rom_resource);
  211. upper = system_rom_resource.start;
  212. /* check for extension rom (ignore length byte!) */
  213. rom = isa_bus_to_virt(extension_rom_resource.start);
  214. if (romsignature(rom)) {
  215. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  216. if (romchecksum(rom, length)) {
  217. request_resource(&iomem_resource, &extension_rom_resource);
  218. upper = extension_rom_resource.start;
  219. }
  220. }
  221. /* check for adapter roms on 2k boundaries */
  222. for (i = 0; i < ADAPTER_ROM_RESOURCES && start < upper; start += 2048) {
  223. rom = isa_bus_to_virt(start);
  224. if (!romsignature(rom))
  225. continue;
  226. /* 0 < length <= 0x7f * 512, historically */
  227. length = rom[2] * 512;
  228. /* but accept any length that fits if checksum okay */
  229. if (!length || start + length > upper || !romchecksum(rom, length))
  230. continue;
  231. adapter_rom_resources[i].start = start;
  232. adapter_rom_resources[i].end = start + length - 1;
  233. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  234. start = adapter_rom_resources[i++].end & ~2047UL;
  235. }
  236. }
  237. /* Check for full argument with no trailing characters */
  238. static int fullarg(char *p, char *arg)
  239. {
  240. int l = strlen(arg);
  241. return !memcmp(p, arg, l) && (p[l] == 0 || isspace(p[l]));
  242. }
  243. static __init void parse_cmdline_early (char ** cmdline_p)
  244. {
  245. char c = ' ', *to = command_line, *from = COMMAND_LINE;
  246. int len = 0;
  247. int userdef = 0;
  248. for (;;) {
  249. if (c != ' ')
  250. goto next_char;
  251. #ifdef CONFIG_SMP
  252. /*
  253. * If the BIOS enumerates physical processors before logical,
  254. * maxcpus=N at enumeration-time can be used to disable HT.
  255. */
  256. else if (!memcmp(from, "maxcpus=", 8)) {
  257. extern unsigned int maxcpus;
  258. maxcpus = simple_strtoul(from + 8, NULL, 0);
  259. }
  260. #endif
  261. #ifdef CONFIG_ACPI
  262. /* "acpi=off" disables both ACPI table parsing and interpreter init */
  263. if (fullarg(from,"acpi=off"))
  264. disable_acpi();
  265. if (fullarg(from, "acpi=force")) {
  266. /* add later when we do DMI horrors: */
  267. acpi_force = 1;
  268. acpi_disabled = 0;
  269. }
  270. /* acpi=ht just means: do ACPI MADT parsing
  271. at bootup, but don't enable the full ACPI interpreter */
  272. if (fullarg(from, "acpi=ht")) {
  273. if (!acpi_force)
  274. disable_acpi();
  275. acpi_ht = 1;
  276. }
  277. else if (fullarg(from, "pci=noacpi"))
  278. acpi_disable_pci();
  279. else if (fullarg(from, "acpi=noirq"))
  280. acpi_noirq_set();
  281. else if (fullarg(from, "acpi_sci=edge"))
  282. acpi_sci_flags.trigger = 1;
  283. else if (fullarg(from, "acpi_sci=level"))
  284. acpi_sci_flags.trigger = 3;
  285. else if (fullarg(from, "acpi_sci=high"))
  286. acpi_sci_flags.polarity = 1;
  287. else if (fullarg(from, "acpi_sci=low"))
  288. acpi_sci_flags.polarity = 3;
  289. /* acpi=strict disables out-of-spec workarounds */
  290. else if (fullarg(from, "acpi=strict")) {
  291. acpi_strict = 1;
  292. }
  293. #ifdef CONFIG_X86_IO_APIC
  294. else if (fullarg(from, "acpi_skip_timer_override"))
  295. acpi_skip_timer_override = 1;
  296. #endif
  297. #endif
  298. if (fullarg(from, "disable_timer_pin_1"))
  299. disable_timer_pin_1 = 1;
  300. if (fullarg(from, "enable_timer_pin_1"))
  301. disable_timer_pin_1 = -1;
  302. if (fullarg(from, "nolapic") || fullarg(from, "disableapic")) {
  303. clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
  304. disable_apic = 1;
  305. }
  306. if (fullarg(from, "noapic"))
  307. skip_ioapic_setup = 1;
  308. if (fullarg(from,"apic")) {
  309. skip_ioapic_setup = 0;
  310. ioapic_force = 1;
  311. }
  312. if (!memcmp(from, "mem=", 4))
  313. parse_memopt(from+4, &from);
  314. if (!memcmp(from, "memmap=", 7)) {
  315. /* exactmap option is for used defined memory */
  316. if (!memcmp(from+7, "exactmap", 8)) {
  317. #ifdef CONFIG_CRASH_DUMP
  318. /* If we are doing a crash dump, we
  319. * still need to know the real mem
  320. * size before original memory map is
  321. * reset.
  322. */
  323. saved_max_pfn = e820_end_of_ram();
  324. #endif
  325. from += 8+7;
  326. end_pfn_map = 0;
  327. e820.nr_map = 0;
  328. userdef = 1;
  329. }
  330. else {
  331. parse_memmapopt(from+7, &from);
  332. userdef = 1;
  333. }
  334. }
  335. #ifdef CONFIG_NUMA
  336. if (!memcmp(from, "numa=", 5))
  337. numa_setup(from+5);
  338. #endif
  339. if (!memcmp(from,"iommu=",6)) {
  340. iommu_setup(from+6);
  341. }
  342. if (fullarg(from,"oops=panic"))
  343. panic_on_oops = 1;
  344. if (!memcmp(from, "noexec=", 7))
  345. nonx_setup(from + 7);
  346. #ifdef CONFIG_KEXEC
  347. /* crashkernel=size@addr specifies the location to reserve for
  348. * a crash kernel. By reserving this memory we guarantee
  349. * that linux never set's it up as a DMA target.
  350. * Useful for holding code to do something appropriate
  351. * after a kernel panic.
  352. */
  353. else if (!memcmp(from, "crashkernel=", 12)) {
  354. unsigned long size, base;
  355. size = memparse(from+12, &from);
  356. if (*from == '@') {
  357. base = memparse(from+1, &from);
  358. /* FIXME: Do I want a sanity check
  359. * to validate the memory range?
  360. */
  361. crashk_res.start = base;
  362. crashk_res.end = base + size - 1;
  363. }
  364. }
  365. #endif
  366. #ifdef CONFIG_PROC_VMCORE
  367. /* elfcorehdr= specifies the location of elf core header
  368. * stored by the crashed kernel. This option will be passed
  369. * by kexec loader to the capture kernel.
  370. */
  371. else if(!memcmp(from, "elfcorehdr=", 11))
  372. elfcorehdr_addr = memparse(from+11, &from);
  373. #endif
  374. #ifdef CONFIG_HOTPLUG_CPU
  375. else if (!memcmp(from, "additional_cpus=", 16))
  376. setup_additional_cpus(from+16);
  377. #endif
  378. next_char:
  379. c = *(from++);
  380. if (!c)
  381. break;
  382. if (COMMAND_LINE_SIZE <= ++len)
  383. break;
  384. *(to++) = c;
  385. }
  386. if (userdef) {
  387. printk(KERN_INFO "user-defined physical RAM map:\n");
  388. e820_print_map("user");
  389. }
  390. *to = '\0';
  391. *cmdline_p = command_line;
  392. }
  393. #ifndef CONFIG_NUMA
  394. static void __init
  395. contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  396. {
  397. unsigned long bootmap_size, bootmap;
  398. bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
  399. bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
  400. if (bootmap == -1L)
  401. panic("Cannot find bootmem map of size %ld\n",bootmap_size);
  402. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
  403. e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
  404. reserve_bootmem(bootmap, bootmap_size);
  405. }
  406. #endif
  407. /* Use inline assembly to define this because the nops are defined
  408. as inline assembly strings in the include files and we cannot
  409. get them easily into strings. */
  410. asm("\t.data\nk8nops: "
  411. K8_NOP1 K8_NOP2 K8_NOP3 K8_NOP4 K8_NOP5 K8_NOP6
  412. K8_NOP7 K8_NOP8);
  413. extern unsigned char k8nops[];
  414. static unsigned char *k8_nops[ASM_NOP_MAX+1] = {
  415. NULL,
  416. k8nops,
  417. k8nops + 1,
  418. k8nops + 1 + 2,
  419. k8nops + 1 + 2 + 3,
  420. k8nops + 1 + 2 + 3 + 4,
  421. k8nops + 1 + 2 + 3 + 4 + 5,
  422. k8nops + 1 + 2 + 3 + 4 + 5 + 6,
  423. k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  424. };
  425. extern char __vsyscall_0;
  426. /* Replace instructions with better alternatives for this CPU type.
  427. This runs before SMP is initialized to avoid SMP problems with
  428. self modifying code. This implies that assymetric systems where
  429. APs have less capabilities than the boot processor are not handled.
  430. In this case boot with "noreplacement". */
  431. void apply_alternatives(void *start, void *end)
  432. {
  433. struct alt_instr *a;
  434. int diff, i, k;
  435. for (a = start; (void *)a < end; a++) {
  436. u8 *instr;
  437. if (!boot_cpu_has(a->cpuid))
  438. continue;
  439. BUG_ON(a->replacementlen > a->instrlen);
  440. instr = a->instr;
  441. /* vsyscall code is not mapped yet. resolve it manually. */
  442. if (instr >= (u8 *)VSYSCALL_START && instr < (u8*)VSYSCALL_END)
  443. instr = __va(instr - (u8*)VSYSCALL_START + (u8*)__pa_symbol(&__vsyscall_0));
  444. __inline_memcpy(instr, a->replacement, a->replacementlen);
  445. diff = a->instrlen - a->replacementlen;
  446. /* Pad the rest with nops */
  447. for (i = a->replacementlen; diff > 0; diff -= k, i += k) {
  448. k = diff;
  449. if (k > ASM_NOP_MAX)
  450. k = ASM_NOP_MAX;
  451. __inline_memcpy(instr + i, k8_nops[k], k);
  452. }
  453. }
  454. }
  455. static int no_replacement __initdata = 0;
  456. void __init alternative_instructions(void)
  457. {
  458. extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
  459. if (no_replacement)
  460. return;
  461. apply_alternatives(__alt_instructions, __alt_instructions_end);
  462. }
  463. static int __init noreplacement_setup(char *s)
  464. {
  465. no_replacement = 1;
  466. return 1;
  467. }
  468. __setup("noreplacement", noreplacement_setup);
  469. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  470. struct edd edd;
  471. #ifdef CONFIG_EDD_MODULE
  472. EXPORT_SYMBOL(edd);
  473. #endif
  474. /**
  475. * copy_edd() - Copy the BIOS EDD information
  476. * from boot_params into a safe place.
  477. *
  478. */
  479. static inline void copy_edd(void)
  480. {
  481. memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
  482. memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
  483. edd.mbr_signature_nr = EDD_MBR_SIG_NR;
  484. edd.edd_info_nr = EDD_NR;
  485. }
  486. #else
  487. static inline void copy_edd(void)
  488. {
  489. }
  490. #endif
  491. #define EBDA_ADDR_POINTER 0x40E
  492. static void __init reserve_ebda_region(void)
  493. {
  494. unsigned int addr;
  495. /**
  496. * there is a real-mode segmented pointer pointing to the
  497. * 4K EBDA area at 0x40E
  498. */
  499. addr = *(unsigned short *)phys_to_virt(EBDA_ADDR_POINTER);
  500. addr <<= 4;
  501. if (addr)
  502. reserve_bootmem_generic(addr, PAGE_SIZE);
  503. }
  504. void __init setup_arch(char **cmdline_p)
  505. {
  506. unsigned long kernel_end;
  507. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  508. screen_info = SCREEN_INFO;
  509. edid_info = EDID_INFO;
  510. saved_video_mode = SAVED_VIDEO_MODE;
  511. bootloader_type = LOADER_TYPE;
  512. #ifdef CONFIG_BLK_DEV_RAM
  513. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  514. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  515. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  516. #endif
  517. setup_memory_region();
  518. copy_edd();
  519. if (!MOUNT_ROOT_RDONLY)
  520. root_mountflags &= ~MS_RDONLY;
  521. init_mm.start_code = (unsigned long) &_text;
  522. init_mm.end_code = (unsigned long) &_etext;
  523. init_mm.end_data = (unsigned long) &_edata;
  524. init_mm.brk = (unsigned long) &_end;
  525. code_resource.start = virt_to_phys(&_text);
  526. code_resource.end = virt_to_phys(&_etext)-1;
  527. data_resource.start = virt_to_phys(&_etext);
  528. data_resource.end = virt_to_phys(&_edata)-1;
  529. parse_cmdline_early(cmdline_p);
  530. early_identify_cpu(&boot_cpu_data);
  531. /*
  532. * partially used pages are not usable - thus
  533. * we are rounding upwards:
  534. */
  535. end_pfn = e820_end_of_ram();
  536. num_physpages = end_pfn; /* for pfn_valid */
  537. check_efer();
  538. init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
  539. dmi_scan_machine();
  540. zap_low_mappings(0);
  541. #ifdef CONFIG_ACPI
  542. /*
  543. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  544. * Call this early for SRAT node setup.
  545. */
  546. acpi_boot_table_init();
  547. #endif
  548. #ifdef CONFIG_ACPI_NUMA
  549. /*
  550. * Parse SRAT to discover nodes.
  551. */
  552. acpi_numa_init();
  553. #endif
  554. #ifdef CONFIG_NUMA
  555. numa_initmem_init(0, end_pfn);
  556. #else
  557. contig_initmem_init(0, end_pfn);
  558. #endif
  559. /* Reserve direct mapping */
  560. reserve_bootmem_generic(table_start << PAGE_SHIFT,
  561. (table_end - table_start) << PAGE_SHIFT);
  562. /* reserve kernel */
  563. kernel_end = round_up(__pa_symbol(&_end),PAGE_SIZE);
  564. reserve_bootmem_generic(HIGH_MEMORY, kernel_end - HIGH_MEMORY);
  565. /*
  566. * reserve physical page 0 - it's a special BIOS page on many boxes,
  567. * enabling clean reboots, SMP operation, laptop functions.
  568. */
  569. reserve_bootmem_generic(0, PAGE_SIZE);
  570. /* reserve ebda region */
  571. reserve_ebda_region();
  572. #ifdef CONFIG_SMP
  573. /*
  574. * But first pinch a few for the stack/trampoline stuff
  575. * FIXME: Don't need the extra page at 4K, but need to fix
  576. * trampoline before removing it. (see the GDT stuff)
  577. */
  578. reserve_bootmem_generic(PAGE_SIZE, PAGE_SIZE);
  579. /* Reserve SMP trampoline */
  580. reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, PAGE_SIZE);
  581. #endif
  582. #ifdef CONFIG_ACPI_SLEEP
  583. /*
  584. * Reserve low memory region for sleep support.
  585. */
  586. acpi_reserve_bootmem();
  587. #endif
  588. #ifdef CONFIG_X86_LOCAL_APIC
  589. /*
  590. * Find and reserve possible boot-time SMP configuration:
  591. */
  592. find_smp_config();
  593. #endif
  594. #ifdef CONFIG_BLK_DEV_INITRD
  595. if (LOADER_TYPE && INITRD_START) {
  596. if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
  597. reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
  598. initrd_start =
  599. INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
  600. initrd_end = initrd_start+INITRD_SIZE;
  601. }
  602. else {
  603. printk(KERN_ERR "initrd extends beyond end of memory "
  604. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  605. (unsigned long)(INITRD_START + INITRD_SIZE),
  606. (unsigned long)(end_pfn << PAGE_SHIFT));
  607. initrd_start = 0;
  608. }
  609. }
  610. #endif
  611. #ifdef CONFIG_KEXEC
  612. if (crashk_res.start != crashk_res.end) {
  613. reserve_bootmem(crashk_res.start,
  614. crashk_res.end - crashk_res.start + 1);
  615. }
  616. #endif
  617. paging_init();
  618. check_ioapic();
  619. /*
  620. * set this early, so we dont allocate cpu0
  621. * if MADT list doesnt list BSP first
  622. * mpparse.c/MP_processor_info() allocates logical cpu numbers.
  623. */
  624. cpu_set(0, cpu_present_map);
  625. #ifdef CONFIG_ACPI
  626. /*
  627. * Read APIC and some other early information from ACPI tables.
  628. */
  629. acpi_boot_init();
  630. #endif
  631. init_cpu_to_node();
  632. #ifdef CONFIG_X86_LOCAL_APIC
  633. /*
  634. * get boot-time SMP configuration:
  635. */
  636. if (smp_found_config)
  637. get_smp_config();
  638. init_apic_mappings();
  639. #endif
  640. /*
  641. * Request address space for all standard RAM and ROM resources
  642. * and also for regions reported as reserved by the e820.
  643. */
  644. probe_roms();
  645. e820_reserve_resources();
  646. request_resource(&iomem_resource, &video_ram_resource);
  647. {
  648. unsigned i;
  649. /* request I/O space for devices used on all i[345]86 PCs */
  650. for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  651. request_resource(&ioport_resource, &standard_io_resources[i]);
  652. }
  653. e820_setup_gap();
  654. #ifdef CONFIG_GART_IOMMU
  655. iommu_hole_init();
  656. #endif
  657. #ifdef CONFIG_VT
  658. #if defined(CONFIG_VGA_CONSOLE)
  659. conswitchp = &vga_con;
  660. #elif defined(CONFIG_DUMMY_CONSOLE)
  661. conswitchp = &dummy_con;
  662. #endif
  663. #endif
  664. }
  665. static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  666. {
  667. unsigned int *v;
  668. if (c->extended_cpuid_level < 0x80000004)
  669. return 0;
  670. v = (unsigned int *) c->x86_model_id;
  671. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  672. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  673. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  674. c->x86_model_id[48] = 0;
  675. return 1;
  676. }
  677. static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  678. {
  679. unsigned int n, dummy, eax, ebx, ecx, edx;
  680. n = c->extended_cpuid_level;
  681. if (n >= 0x80000005) {
  682. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  683. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
  684. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  685. c->x86_cache_size=(ecx>>24)+(edx>>24);
  686. /* On K8 L1 TLB is inclusive, so don't count it */
  687. c->x86_tlbsize = 0;
  688. }
  689. if (n >= 0x80000006) {
  690. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  691. ecx = cpuid_ecx(0x80000006);
  692. c->x86_cache_size = ecx >> 16;
  693. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  694. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  695. c->x86_cache_size, ecx & 0xFF);
  696. }
  697. if (n >= 0x80000007)
  698. cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
  699. if (n >= 0x80000008) {
  700. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  701. c->x86_virt_bits = (eax >> 8) & 0xff;
  702. c->x86_phys_bits = eax & 0xff;
  703. }
  704. }
  705. #ifdef CONFIG_NUMA
  706. static int nearby_node(int apicid)
  707. {
  708. int i;
  709. for (i = apicid - 1; i >= 0; i--) {
  710. int node = apicid_to_node[i];
  711. if (node != NUMA_NO_NODE && node_online(node))
  712. return node;
  713. }
  714. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  715. int node = apicid_to_node[i];
  716. if (node != NUMA_NO_NODE && node_online(node))
  717. return node;
  718. }
  719. return first_node(node_online_map); /* Shouldn't happen */
  720. }
  721. #endif
  722. /*
  723. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  724. * Assumes number of cores is a power of two.
  725. */
  726. static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
  727. {
  728. #ifdef CONFIG_SMP
  729. int cpu = smp_processor_id();
  730. unsigned bits;
  731. #ifdef CONFIG_NUMA
  732. int node = 0;
  733. unsigned apicid = hard_smp_processor_id();
  734. #endif
  735. bits = 0;
  736. while ((1 << bits) < c->x86_max_cores)
  737. bits++;
  738. /* Low order bits define the core id (index of core in socket) */
  739. cpu_core_id[cpu] = phys_proc_id[cpu] & ((1 << bits)-1);
  740. /* Convert the APIC ID into the socket ID */
  741. phys_proc_id[cpu] = phys_pkg_id(bits);
  742. #ifdef CONFIG_NUMA
  743. node = phys_proc_id[cpu];
  744. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  745. node = apicid_to_node[apicid];
  746. if (!node_online(node)) {
  747. /* Two possibilities here:
  748. - The CPU is missing memory and no node was created.
  749. In that case try picking one from a nearby CPU
  750. - The APIC IDs differ from the HyperTransport node IDs
  751. which the K8 northbridge parsing fills in.
  752. Assume they are all increased by a constant offset,
  753. but in the same order as the HT nodeids.
  754. If that doesn't result in a usable node fall back to the
  755. path for the previous case. */
  756. int ht_nodeid = apicid - (phys_proc_id[0] << bits);
  757. if (ht_nodeid >= 0 &&
  758. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  759. node = apicid_to_node[ht_nodeid];
  760. /* Pick a nearby node */
  761. if (!node_online(node))
  762. node = nearby_node(apicid);
  763. }
  764. numa_set_node(cpu, node);
  765. printk(KERN_INFO "CPU %d/%x(%d) -> Node %d -> Core %d\n",
  766. cpu, apicid, c->x86_max_cores, node, cpu_core_id[cpu]);
  767. #endif
  768. #endif
  769. }
  770. static int __init init_amd(struct cpuinfo_x86 *c)
  771. {
  772. int r;
  773. unsigned level;
  774. #ifdef CONFIG_SMP
  775. unsigned long value;
  776. /*
  777. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  778. * bit 6 of msr C001_0015
  779. *
  780. * Errata 63 for SH-B3 steppings
  781. * Errata 122 for all steppings (F+ have it disabled by default)
  782. */
  783. if (c->x86 == 15) {
  784. rdmsrl(MSR_K8_HWCR, value);
  785. value |= 1 << 6;
  786. wrmsrl(MSR_K8_HWCR, value);
  787. }
  788. #endif
  789. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  790. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  791. clear_bit(0*32+31, &c->x86_capability);
  792. /* On C+ stepping K8 rep microcode works well for copy/memset */
  793. level = cpuid_eax(1);
  794. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
  795. set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
  796. r = get_model_name(c);
  797. if (!r) {
  798. switch (c->x86) {
  799. case 15:
  800. /* Should distinguish Models here, but this is only
  801. a fallback anyways. */
  802. strcpy(c->x86_model_id, "Hammer");
  803. break;
  804. }
  805. }
  806. display_cacheinfo(c);
  807. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  808. if (c->x86_power & (1<<8))
  809. set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
  810. if (c->extended_cpuid_level >= 0x80000008) {
  811. c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
  812. amd_detect_cmp(c);
  813. }
  814. return r;
  815. }
  816. static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  817. {
  818. #ifdef CONFIG_SMP
  819. u32 eax, ebx, ecx, edx;
  820. int index_msb, core_bits;
  821. int cpu = smp_processor_id();
  822. cpuid(1, &eax, &ebx, &ecx, &edx);
  823. if (!cpu_has(c, X86_FEATURE_HT) || cpu_has(c, X86_FEATURE_CMP_LEGACY))
  824. return;
  825. smp_num_siblings = (ebx & 0xff0000) >> 16;
  826. if (smp_num_siblings == 1) {
  827. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  828. } else if (smp_num_siblings > 1 ) {
  829. if (smp_num_siblings > NR_CPUS) {
  830. printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
  831. smp_num_siblings = 1;
  832. return;
  833. }
  834. index_msb = get_count_order(smp_num_siblings);
  835. phys_proc_id[cpu] = phys_pkg_id(index_msb);
  836. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  837. phys_proc_id[cpu]);
  838. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  839. index_msb = get_count_order(smp_num_siblings) ;
  840. core_bits = get_count_order(c->x86_max_cores);
  841. cpu_core_id[cpu] = phys_pkg_id(index_msb) &
  842. ((1 << core_bits) - 1);
  843. if (c->x86_max_cores > 1)
  844. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  845. cpu_core_id[cpu]);
  846. }
  847. #endif
  848. }
  849. /*
  850. * find out the number of processor cores on the die
  851. */
  852. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  853. {
  854. unsigned int eax;
  855. if (c->cpuid_level < 4)
  856. return 1;
  857. __asm__("cpuid"
  858. : "=a" (eax)
  859. : "0" (4), "c" (0)
  860. : "bx", "dx");
  861. if (eax & 0x1f)
  862. return ((eax >> 26) + 1);
  863. else
  864. return 1;
  865. }
  866. static void srat_detect_node(void)
  867. {
  868. #ifdef CONFIG_NUMA
  869. unsigned node;
  870. int cpu = smp_processor_id();
  871. /* Don't do the funky fallback heuristics the AMD version employs
  872. for now. */
  873. node = apicid_to_node[hard_smp_processor_id()];
  874. if (node == NUMA_NO_NODE)
  875. node = 0;
  876. numa_set_node(cpu, node);
  877. if (acpi_numa > 0)
  878. printk(KERN_INFO "CPU %d -> Node %d\n", cpu, node);
  879. #endif
  880. }
  881. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  882. {
  883. /* Cache sizes */
  884. unsigned n;
  885. init_intel_cacheinfo(c);
  886. n = c->extended_cpuid_level;
  887. if (n >= 0x80000008) {
  888. unsigned eax = cpuid_eax(0x80000008);
  889. c->x86_virt_bits = (eax >> 8) & 0xff;
  890. c->x86_phys_bits = eax & 0xff;
  891. /* CPUID workaround for Intel 0F34 CPU */
  892. if (c->x86_vendor == X86_VENDOR_INTEL &&
  893. c->x86 == 0xF && c->x86_model == 0x3 &&
  894. c->x86_mask == 0x4)
  895. c->x86_phys_bits = 36;
  896. }
  897. if (c->x86 == 15)
  898. c->x86_cache_alignment = c->x86_clflush_size * 2;
  899. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  900. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  901. set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
  902. set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  903. c->x86_max_cores = intel_num_cpu_cores(c);
  904. srat_detect_node();
  905. }
  906. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  907. {
  908. char *v = c->x86_vendor_id;
  909. if (!strcmp(v, "AuthenticAMD"))
  910. c->x86_vendor = X86_VENDOR_AMD;
  911. else if (!strcmp(v, "GenuineIntel"))
  912. c->x86_vendor = X86_VENDOR_INTEL;
  913. else
  914. c->x86_vendor = X86_VENDOR_UNKNOWN;
  915. }
  916. struct cpu_model_info {
  917. int vendor;
  918. int family;
  919. char *model_names[16];
  920. };
  921. /* Do some early cpuid on the boot CPU to get some parameter that are
  922. needed before check_bugs. Everything advanced is in identify_cpu
  923. below. */
  924. void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  925. {
  926. u32 tfms;
  927. c->loops_per_jiffy = loops_per_jiffy;
  928. c->x86_cache_size = -1;
  929. c->x86_vendor = X86_VENDOR_UNKNOWN;
  930. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  931. c->x86_vendor_id[0] = '\0'; /* Unset */
  932. c->x86_model_id[0] = '\0'; /* Unset */
  933. c->x86_clflush_size = 64;
  934. c->x86_cache_alignment = c->x86_clflush_size;
  935. c->x86_max_cores = 1;
  936. c->extended_cpuid_level = 0;
  937. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  938. /* Get vendor name */
  939. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  940. (unsigned int *)&c->x86_vendor_id[0],
  941. (unsigned int *)&c->x86_vendor_id[8],
  942. (unsigned int *)&c->x86_vendor_id[4]);
  943. get_cpu_vendor(c);
  944. /* Initialize the standard set of capabilities */
  945. /* Note that the vendor-specific code below might override */
  946. /* Intel-defined flags: level 0x00000001 */
  947. if (c->cpuid_level >= 0x00000001) {
  948. __u32 misc;
  949. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  950. &c->x86_capability[0]);
  951. c->x86 = (tfms >> 8) & 0xf;
  952. c->x86_model = (tfms >> 4) & 0xf;
  953. c->x86_mask = tfms & 0xf;
  954. if (c->x86 == 0xf)
  955. c->x86 += (tfms >> 20) & 0xff;
  956. if (c->x86 >= 0x6)
  957. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  958. if (c->x86_capability[0] & (1<<19))
  959. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  960. } else {
  961. /* Have CPUID level 0 only - unheard of */
  962. c->x86 = 4;
  963. }
  964. #ifdef CONFIG_SMP
  965. phys_proc_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff;
  966. #endif
  967. }
  968. /*
  969. * This does the hard work of actually picking apart the CPU stuff...
  970. */
  971. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  972. {
  973. int i;
  974. u32 xlvl;
  975. early_identify_cpu(c);
  976. /* AMD-defined flags: level 0x80000001 */
  977. xlvl = cpuid_eax(0x80000000);
  978. c->extended_cpuid_level = xlvl;
  979. if ((xlvl & 0xffff0000) == 0x80000000) {
  980. if (xlvl >= 0x80000001) {
  981. c->x86_capability[1] = cpuid_edx(0x80000001);
  982. c->x86_capability[6] = cpuid_ecx(0x80000001);
  983. }
  984. if (xlvl >= 0x80000004)
  985. get_model_name(c); /* Default name */
  986. }
  987. /* Transmeta-defined flags: level 0x80860001 */
  988. xlvl = cpuid_eax(0x80860000);
  989. if ((xlvl & 0xffff0000) == 0x80860000) {
  990. /* Don't set x86_cpuid_level here for now to not confuse. */
  991. if (xlvl >= 0x80860001)
  992. c->x86_capability[2] = cpuid_edx(0x80860001);
  993. }
  994. c->apicid = phys_pkg_id(0);
  995. /*
  996. * Vendor-specific initialization. In this section we
  997. * canonicalize the feature flags, meaning if there are
  998. * features a certain CPU supports which CPUID doesn't
  999. * tell us, CPUID claiming incorrect flags, or other bugs,
  1000. * we handle them here.
  1001. *
  1002. * At the end of this section, c->x86_capability better
  1003. * indicate the features this CPU genuinely supports!
  1004. */
  1005. switch (c->x86_vendor) {
  1006. case X86_VENDOR_AMD:
  1007. init_amd(c);
  1008. break;
  1009. case X86_VENDOR_INTEL:
  1010. init_intel(c);
  1011. break;
  1012. case X86_VENDOR_UNKNOWN:
  1013. default:
  1014. display_cacheinfo(c);
  1015. break;
  1016. }
  1017. select_idle_routine(c);
  1018. detect_ht(c);
  1019. /*
  1020. * On SMP, boot_cpu_data holds the common feature set between
  1021. * all CPUs; so make sure that we indicate which features are
  1022. * common between the CPUs. The first time this routine gets
  1023. * executed, c == &boot_cpu_data.
  1024. */
  1025. if (c != &boot_cpu_data) {
  1026. /* AND the already accumulated flags with these */
  1027. for (i = 0 ; i < NCAPINTS ; i++)
  1028. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  1029. }
  1030. #ifdef CONFIG_X86_MCE
  1031. mcheck_init(c);
  1032. #endif
  1033. if (c == &boot_cpu_data)
  1034. mtrr_bp_init();
  1035. else
  1036. mtrr_ap_init();
  1037. #ifdef CONFIG_NUMA
  1038. numa_add_cpu(smp_processor_id());
  1039. #endif
  1040. }
  1041. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  1042. {
  1043. if (c->x86_model_id[0])
  1044. printk("%s", c->x86_model_id);
  1045. if (c->x86_mask || c->cpuid_level >= 0)
  1046. printk(" stepping %02x\n", c->x86_mask);
  1047. else
  1048. printk("\n");
  1049. }
  1050. /*
  1051. * Get CPU information for use by the procfs.
  1052. */
  1053. static int show_cpuinfo(struct seq_file *m, void *v)
  1054. {
  1055. struct cpuinfo_x86 *c = v;
  1056. /*
  1057. * These flag bits must match the definitions in <asm/cpufeature.h>.
  1058. * NULL means this bit is undefined or reserved; either way it doesn't
  1059. * have meaning as far as Linux is concerned. Note that it's important
  1060. * to realize there is a difference between this table and CPUID -- if
  1061. * applications want to get the raw CPUID data, they should access
  1062. * /dev/cpu/<cpu_nr>/cpuid instead.
  1063. */
  1064. static char *x86_cap_flags[] = {
  1065. /* Intel-defined */
  1066. "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
  1067. "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
  1068. "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
  1069. "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
  1070. /* AMD-defined */
  1071. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1072. NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
  1073. NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
  1074. NULL, "fxsr_opt", "rdtscp", NULL, NULL, "lm", "3dnowext", "3dnow",
  1075. /* Transmeta-defined */
  1076. "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
  1077. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1078. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1079. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1080. /* Other (Linux-defined) */
  1081. "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
  1082. "constant_tsc", NULL, NULL,
  1083. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1084. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1085. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1086. /* Intel-defined (#2) */
  1087. "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
  1088. "tm2", NULL, "cid", NULL, NULL, "cx16", "xtpr", NULL,
  1089. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1090. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1091. /* VIA/Cyrix/Centaur-defined */
  1092. NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
  1093. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1094. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1095. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1096. /* AMD-defined (#2) */
  1097. "lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
  1098. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1099. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1100. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  1101. };
  1102. static char *x86_power_flags[] = {
  1103. "ts", /* temperature sensor */
  1104. "fid", /* frequency id control */
  1105. "vid", /* voltage id control */
  1106. "ttp", /* thermal trip */
  1107. "tm",
  1108. "stc",
  1109. NULL,
  1110. /* nothing */ /* constant_tsc - moved to flags */
  1111. };
  1112. #ifdef CONFIG_SMP
  1113. if (!cpu_online(c-cpu_data))
  1114. return 0;
  1115. #endif
  1116. seq_printf(m,"processor\t: %u\n"
  1117. "vendor_id\t: %s\n"
  1118. "cpu family\t: %d\n"
  1119. "model\t\t: %d\n"
  1120. "model name\t: %s\n",
  1121. (unsigned)(c-cpu_data),
  1122. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  1123. c->x86,
  1124. (int)c->x86_model,
  1125. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  1126. if (c->x86_mask || c->cpuid_level >= 0)
  1127. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  1128. else
  1129. seq_printf(m, "stepping\t: unknown\n");
  1130. if (cpu_has(c,X86_FEATURE_TSC)) {
  1131. unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
  1132. if (!freq)
  1133. freq = cpu_khz;
  1134. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  1135. freq / 1000, (freq % 1000));
  1136. }
  1137. /* Cache size */
  1138. if (c->x86_cache_size >= 0)
  1139. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  1140. #ifdef CONFIG_SMP
  1141. if (smp_num_siblings * c->x86_max_cores > 1) {
  1142. int cpu = c - cpu_data;
  1143. seq_printf(m, "physical id\t: %d\n", phys_proc_id[cpu]);
  1144. seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
  1145. seq_printf(m, "core id\t\t: %d\n", cpu_core_id[cpu]);
  1146. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  1147. }
  1148. #endif
  1149. seq_printf(m,
  1150. "fpu\t\t: yes\n"
  1151. "fpu_exception\t: yes\n"
  1152. "cpuid level\t: %d\n"
  1153. "wp\t\t: yes\n"
  1154. "flags\t\t:",
  1155. c->cpuid_level);
  1156. {
  1157. int i;
  1158. for ( i = 0 ; i < 32*NCAPINTS ; i++ )
  1159. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  1160. seq_printf(m, " %s", x86_cap_flags[i]);
  1161. }
  1162. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  1163. c->loops_per_jiffy/(500000/HZ),
  1164. (c->loops_per_jiffy/(5000/HZ)) % 100);
  1165. if (c->x86_tlbsize > 0)
  1166. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  1167. seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
  1168. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  1169. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  1170. c->x86_phys_bits, c->x86_virt_bits);
  1171. seq_printf(m, "power management:");
  1172. {
  1173. unsigned i;
  1174. for (i = 0; i < 32; i++)
  1175. if (c->x86_power & (1 << i)) {
  1176. if (i < ARRAY_SIZE(x86_power_flags) &&
  1177. x86_power_flags[i])
  1178. seq_printf(m, "%s%s",
  1179. x86_power_flags[i][0]?" ":"",
  1180. x86_power_flags[i]);
  1181. else
  1182. seq_printf(m, " [%d]", i);
  1183. }
  1184. }
  1185. seq_printf(m, "\n\n");
  1186. return 0;
  1187. }
  1188. static void *c_start(struct seq_file *m, loff_t *pos)
  1189. {
  1190. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  1191. }
  1192. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  1193. {
  1194. ++*pos;
  1195. return c_start(m, pos);
  1196. }
  1197. static void c_stop(struct seq_file *m, void *v)
  1198. {
  1199. }
  1200. struct seq_operations cpuinfo_op = {
  1201. .start =c_start,
  1202. .next = c_next,
  1203. .stop = c_stop,
  1204. .show = show_cpuinfo,
  1205. };