setup.c 39 KB

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