1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83#include <linux/errno.h>
84#include <linux/sched.h>
85#include <linux/kernel.h>
86#include <linux/mm.h>
87#include <linux/stddef.h>
88#include <linux/unistd.h>
89#include <linux/ptrace.h>
90#include <linux/slab.h>
91#include <linux/user.h>
92#include <linux/a.out.h>
93#include <linux/tty.h>
94#include <linux/ioport.h>
95#include <linux/delay.h>
96#include <linux/config.h>
97#include <linux/init.h>
98#include <linux/apm_bios.h>
99#ifdef CONFIG_BLK_DEV_RAM
100#include <linux/blk.h>
101#endif
102#include <linux/highmem.h>
103#include <linux/bootmem.h>
104#include <linux/pci.h>
105#include <linux/pci_ids.h>
106#include <linux/seq_file.h>
107#include <asm/processor.h>
108#include <linux/console.h>
109#include <asm/mtrr.h>
110#include <asm/uaccess.h>
111#include <asm/system.h>
112#include <asm/io.h>
113#include <asm/smp.h>
114#include <asm/cobalt.h>
115#include <asm/msr.h>
116#include <asm/desc.h>
117#include <asm/e820.h>
118#include <asm/dma.h>
119#include <asm/mpspec.h>
120#include <asm/mmu_context.h>
121
122
123
124
125char ignore_irq13;
126struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
127
128unsigned long mmu_cr4_features;
129
130
131
132
133#ifdef CONFIG_EISA
134int EISA_bus;
135#endif
136int MCA_bus;
137
138
139unsigned int machine_id;
140unsigned int machine_submodel_id;
141unsigned int BIOS_revision;
142unsigned int mca_pentium_flag;
143
144
145unsigned long pci_mem_start = 0x10000000;
146
147
148static unsigned int highmem_pages __initdata = -1;
149
150
151
152
153struct drive_info_struct { char dummy[32]; } drive_info;
154struct screen_info screen_info;
155struct apm_info apm_info;
156struct sys_desc_table_struct {
157 unsigned short length;
158 unsigned char table[0];
159};
160
161struct e820map e820;
162
163unsigned char aux_device_present;
164
165extern void mcheck_init(struct cpuinfo_x86 *c);
166extern void dmi_scan_machine(void);
167extern int root_mountflags;
168extern char _text, _etext, _edata, _end;
169
170static int have_cpuid_p(void) __init;
171
172static int disable_x86_serial_nr __initdata = 1;
173static int disable_x86_ht __initdata = 0;
174static u32 disabled_x86_caps[NCAPINTS] __initdata = { 0 };
175extern int blk_nohighio;
176
177int enable_acpi_smp_table;
178
179
180
181
182#define PARAM ((unsigned char *)empty_zero_page)
183#define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
184#define EXT_MEM_K (*(unsigned short *) (PARAM+2))
185#define ALT_MEM_K (*(unsigned long *) (PARAM+0x1e0))
186#define E820_MAP_NR (*(char*) (PARAM+E820NR))
187#define E820_MAP ((struct e820entry *) (PARAM+E820MAP))
188#define APM_BIOS_INFO (*(struct apm_bios_info *) (PARAM+0x40))
189#define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
190#define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
191#define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
192#define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8))
193#define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
194#define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
195#define LOADER_TYPE (*(unsigned char *) (PARAM+0x210))
196#define KERNEL_START (*(unsigned long *) (PARAM+0x214))
197#define INITRD_START (*(unsigned long *) (PARAM+0x218))
198#define INITRD_SIZE (*(unsigned long *) (PARAM+0x21c))
199#define COMMAND_LINE ((char *) (PARAM+2048))
200#define COMMAND_LINE_SIZE 256
201
202#define RAMDISK_IMAGE_START_MASK 0x07FF
203#define RAMDISK_PROMPT_FLAG 0x8000
204#define RAMDISK_LOAD_FLAG 0x4000
205
206#ifdef CONFIG_VISWS
207char visws_board_type = -1;
208char visws_board_rev = -1;
209
210#define PIIX_PM_START 0x0F80
211
212#define SIO_GPIO_START 0x0FC0
213
214#define SIO_PM_START 0x0FC8
215
216#define PMBASE PIIX_PM_START
217#define GPIREG0 (PMBASE+0x30)
218#define GPIREG(x) (GPIREG0+((x)/8))
219#define PIIX_GPI_BD_ID1 18
220#define PIIX_GPI_BD_REG GPIREG(PIIX_GPI_BD_ID1)
221
222#define PIIX_GPI_BD_SHIFT (PIIX_GPI_BD_ID1 % 8)
223
224#define SIO_INDEX 0x2e
225#define SIO_DATA 0x2f
226
227#define SIO_DEV_SEL 0x7
228#define SIO_DEV_ENB 0x30
229#define SIO_DEV_MSB 0x60
230#define SIO_DEV_LSB 0x61
231
232#define SIO_GP_DEV 0x7
233
234#define SIO_GP_BASE SIO_GPIO_START
235#define SIO_GP_MSB (SIO_GP_BASE>>8)
236#define SIO_GP_LSB (SIO_GP_BASE&0xff)
237
238#define SIO_GP_DATA1 (SIO_GP_BASE+0)
239
240#define SIO_PM_DEV 0x8
241
242#define SIO_PM_BASE SIO_PM_START
243#define SIO_PM_MSB (SIO_PM_BASE>>8)
244#define SIO_PM_LSB (SIO_PM_BASE&0xff)
245#define SIO_PM_INDEX (SIO_PM_BASE+0)
246#define SIO_PM_DATA (SIO_PM_BASE+1)
247
248#define SIO_PM_FER2 0x1
249
250#define SIO_PM_GP_EN 0x80
251
252static void __init visws_get_board_type_and_rev(void)
253{
254 int raw;
255
256 visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
257 >> PIIX_GPI_BD_SHIFT;
258
259
260
261
262
263
264 outb_p(SIO_DEV_SEL, SIO_INDEX);
265 outb_p(SIO_GP_DEV, SIO_DATA);
266
267 outb_p(SIO_DEV_MSB, SIO_INDEX);
268 outb_p(SIO_GP_MSB, SIO_DATA);
269
270 outb_p(SIO_DEV_LSB, SIO_INDEX);
271 outb_p(SIO_GP_LSB, SIO_DATA);
272
273 outb_p(SIO_DEV_ENB, SIO_INDEX);
274 outb_p(1, SIO_DATA);
275
276
277
278
279
280
281 outb_p(SIO_DEV_SEL, SIO_INDEX);
282 outb_p(SIO_PM_DEV, SIO_DATA);
283
284 outb_p(SIO_DEV_MSB, SIO_INDEX);
285 outb_p(SIO_PM_MSB, SIO_DATA);
286
287 outb_p(SIO_DEV_LSB, SIO_INDEX);
288 outb_p(SIO_PM_LSB, SIO_DATA);
289
290 outb_p(SIO_DEV_ENB, SIO_INDEX);
291 outb_p(1, SIO_DATA);
292
293
294
295
296 outb_p(SIO_PM_FER2, SIO_PM_INDEX);
297 outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
298
299
300
301
302
303
304
305 raw = inb_p(SIO_GP_DATA1);
306 raw &= 0x7f;
307
308 if (visws_board_type == VISWS_320) {
309 if (raw < 0x6) {
310 visws_board_rev = 4;
311 } else if (raw < 0xc) {
312 visws_board_rev = 5;
313 } else {
314 visws_board_rev = 6;
315
316 }
317 } else if (visws_board_type == VISWS_540) {
318 visws_board_rev = 2;
319 } else {
320 visws_board_rev = raw;
321 }
322
323 printk(KERN_INFO "Silicon Graphics %s (rev %d)\n",
324 visws_board_type == VISWS_320 ? "320" :
325 (visws_board_type == VISWS_540 ? "540" :
326 "unknown"),
327 visws_board_rev);
328 }
329#endif
330
331
332static char command_line[COMMAND_LINE_SIZE];
333 char saved_command_line[COMMAND_LINE_SIZE];
334
335struct resource standard_io_resources[] = {
336 { "dma1", 0x00, 0x1f, IORESOURCE_BUSY },
337 { "pic1", 0x20, 0x3f, IORESOURCE_BUSY },
338 { "timer", 0x40, 0x5f, IORESOURCE_BUSY },
339 { "keyboard", 0x60, 0x6f, IORESOURCE_BUSY },
340 { "dma page reg", 0x80, 0x8f, IORESOURCE_BUSY },
341 { "pic2", 0xa0, 0xbf, IORESOURCE_BUSY },
342 { "dma2", 0xc0, 0xdf, IORESOURCE_BUSY },
343 { "fpu", 0xf0, 0xff, IORESOURCE_BUSY }
344};
345
346#define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
347
348static struct resource code_resource = { "Kernel code", 0x100000, 0 };
349static struct resource data_resource = { "Kernel data", 0, 0 };
350static struct resource vram_resource = { "Video RAM area", 0xa0000, 0xbffff, IORESOURCE_BUSY };
351
352
353#define MAXROMS 6
354static struct resource rom_resources[MAXROMS] = {
355 { "System ROM", 0xF0000, 0xFFFFF, IORESOURCE_BUSY },
356 { "Video ROM", 0xc0000, 0xc7fff, IORESOURCE_BUSY }
357};
358
359#define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
360
361static void __init probe_roms(void)
362{
363 int roms = 1;
364 unsigned long base;
365 unsigned char *romstart;
366
367 request_resource(&iomem_resource, rom_resources+0);
368
369
370 for (base = 0xC0000; base < 0xE0000; base += 2048) {
371 romstart = bus_to_virt(base);
372 if (!romsignature(romstart))
373 continue;
374 request_resource(&iomem_resource, rom_resources + roms);
375 roms++;
376 break;
377 }
378
379
380 for (base = 0xC8000; base < 0xE0000; base += 2048) {
381 unsigned long length;
382
383 romstart = bus_to_virt(base);
384 if (!romsignature(romstart))
385 continue;
386 length = romstart[2] * 512;
387 if (length) {
388 unsigned int i;
389 unsigned char chksum;
390
391 chksum = 0;
392 for (i = 0; i < length; i++)
393 chksum += romstart[i];
394
395
396 if (!chksum) {
397 rom_resources[roms].start = base;
398 rom_resources[roms].end = base + length - 1;
399 rom_resources[roms].name = "Extension ROM";
400 rom_resources[roms].flags = IORESOURCE_BUSY;
401
402 request_resource(&iomem_resource, rom_resources + roms);
403 roms++;
404 if (roms >= MAXROMS)
405 return;
406 }
407 }
408 }
409
410
411 base = 0xE0000;
412 romstart = bus_to_virt(base);
413
414 if (romsignature(romstart)) {
415 rom_resources[roms].start = base;
416 rom_resources[roms].end = base + 65535;
417 rom_resources[roms].name = "Extension ROM";
418 rom_resources[roms].flags = IORESOURCE_BUSY;
419
420 request_resource(&iomem_resource, rom_resources + roms);
421 }
422}
423
424static void __init limit_regions (unsigned long long size)
425{
426 unsigned long long current_addr = 0;
427 int i;
428
429 for (i = 0; i < e820.nr_map; i++) {
430 if (e820.map[i].type == E820_RAM) {
431 current_addr = e820.map[i].addr + e820.map[i].size;
432 if (current_addr >= size) {
433 e820.map[i].size -= current_addr-size;
434 e820.nr_map = i + 1;
435 return;
436 }
437 }
438 }
439}
440static void __init add_memory_region(unsigned long long start,
441 unsigned long long size, int type)
442{
443 int x = e820.nr_map;
444
445 if (x == E820MAX) {
446 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
447 return;
448 }
449
450 e820.map[x].addr = start;
451 e820.map[x].size = size;
452 e820.map[x].type = type;
453 e820.nr_map++;
454}
455
456#define E820_DEBUG 1
457
458static void __init print_memory_map(char *who)
459{
460 int i;
461
462 for (i = 0; i < e820.nr_map; i++) {
463 printk(" %s: %016Lx - %016Lx ", who,
464 e820.map[i].addr,
465 e820.map[i].addr + e820.map[i].size);
466 switch (e820.map[i].type) {
467 case E820_RAM: printk("(usable)\n");
468 break;
469 case E820_RESERVED:
470 printk("(reserved)\n");
471 break;
472 case E820_ACPI:
473 printk("(ACPI data)\n");
474 break;
475 case E820_NVS:
476 printk("(ACPI NVS)\n");
477 break;
478 default: printk("type %lu\n", e820.map[i].type);
479 break;
480 }
481 }
482}
483
484
485
486
487
488
489
490
491static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
492{
493 struct change_member {
494 struct e820entry *pbios;
495 unsigned long long addr;
496 };
497 struct change_member change_point_list[2*E820MAX];
498 struct change_member *change_point[2*E820MAX];
499 struct e820entry *overlap_list[E820MAX];
500 struct e820entry new_bios[E820MAX];
501 struct change_member *change_tmp;
502 unsigned long current_type, last_type;
503 unsigned long long last_addr;
504 int chgidx, still_changing;
505 int overlap_entries;
506 int new_bios_entry;
507 int old_nr, new_nr, chg_nr;
508 int i;
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547 if (*pnr_map < 2)
548 return -1;
549
550 old_nr = *pnr_map;
551
552
553 for (i=0; i<old_nr; i++)
554 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
555 return -1;
556
557
558 for (i=0; i < 2*old_nr; i++)
559 change_point[i] = &change_point_list[i];
560
561
562
563 chgidx = 0;
564 for (i=0; i < old_nr; i++) {
565 if (biosmap[i].size != 0) {
566 change_point[chgidx]->addr = biosmap[i].addr;
567 change_point[chgidx++]->pbios = &biosmap[i];
568 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
569 change_point[chgidx++]->pbios = &biosmap[i];
570 }
571 }
572 chg_nr = chgidx;
573
574
575 still_changing = 1;
576 while (still_changing) {
577 still_changing = 0;
578 for (i=1; i < chg_nr; i++) {
579
580
581 if ((change_point[i]->addr < change_point[i-1]->addr) ||
582 ((change_point[i]->addr == change_point[i-1]->addr) &&
583 (change_point[i]->addr == change_point[i]->pbios->addr) &&
584 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
585 )
586 {
587 change_tmp = change_point[i];
588 change_point[i] = change_point[i-1];
589 change_point[i-1] = change_tmp;
590 still_changing=1;
591 }
592 }
593 }
594
595
596 overlap_entries=0;
597 new_bios_entry=0;
598 last_type = 0;
599 last_addr = 0;
600
601 for (chgidx=0; chgidx < chg_nr; chgidx++)
602 {
603
604 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
605 {
606
607 overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
608 }
609 else
610 {
611
612 for (i=0; i<overlap_entries; i++)
613 {
614 if (overlap_list[i] == change_point[chgidx]->pbios)
615 overlap_list[i] = overlap_list[overlap_entries-1];
616 }
617 overlap_entries--;
618 }
619
620
621 current_type = 0;
622 for (i=0; i<overlap_entries; i++)
623 if (overlap_list[i]->type > current_type)
624 current_type = overlap_list[i]->type;
625
626 if (current_type != last_type) {
627 if (last_type != 0) {
628 new_bios[new_bios_entry].size =
629 change_point[chgidx]->addr - last_addr;
630
631 if (new_bios[new_bios_entry].size != 0)
632 if (++new_bios_entry >= E820MAX)
633 break;
634 }
635 if (current_type != 0) {
636 new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
637 new_bios[new_bios_entry].type = current_type;
638 last_addr=change_point[chgidx]->addr;
639 }
640 last_type = current_type;
641 }
642 }
643 new_nr = new_bios_entry;
644
645
646 memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
647 *pnr_map = new_nr;
648
649 return 0;
650}
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
669{
670
671 if (nr_map < 2)
672 return -1;
673
674 do {
675 unsigned long long start = biosmap->addr;
676 unsigned long long size = biosmap->size;
677 unsigned long long end = start + size;
678 unsigned long type = biosmap->type;
679
680
681 if (start > end)
682 return -1;
683
684
685
686
687
688 if (type == E820_RAM) {
689 if (start < 0x100000ULL && end > 0xA0000ULL) {
690 if (start < 0xA0000ULL)
691 add_memory_region(start, 0xA0000ULL-start, type);
692 if (end <= 0x100000ULL)
693 continue;
694 start = 0x100000ULL;
695 size = end - start;
696 }
697 }
698 add_memory_region(start, size, type);
699 } while (biosmap++,--nr_map);
700 return 0;
701}
702
703
704
705
706
707#define LOWMEMSIZE() (0x9f000)
708
709static void __init setup_memory_region(void)
710{
711 char *who = "BIOS-e820";
712
713
714
715
716
717
718
719 sanitize_e820_map(E820_MAP, &E820_MAP_NR);
720 if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
721 unsigned long mem_size;
722
723
724 if (ALT_MEM_K < EXT_MEM_K) {
725 mem_size = EXT_MEM_K;
726 who = "BIOS-88";
727 } else {
728 mem_size = ALT_MEM_K;
729 who = "BIOS-e801";
730 }
731
732 e820.nr_map = 0;
733 add_memory_region(0, LOWMEMSIZE(), E820_RAM);
734 add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
735 }
736 printk(KERN_INFO "BIOS-provided physical RAM map:\n");
737 print_memory_map(who);
738}
739
740
741static void __init parse_cmdline_early (char ** cmdline_p)
742{
743 char c = ' ', *to = command_line, *from = COMMAND_LINE;
744 int len = 0;
745 int userdef = 0;
746
747
748 memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
749 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
750
751 for (;;) {
752 if (c != ' ')
753 goto nextchar;
754
755
756
757
758
759
760
761 if (!memcmp(from, "mem=", 4)) {
762 if (to != command_line)
763 to--;
764 if (!memcmp(from+4, "nopentium", 9)) {
765 from += 9+4;
766 clear_bit(X86_FEATURE_PSE, &boot_cpu_data.x86_capability);
767 set_bit(X86_FEATURE_PSE, &disabled_x86_caps);
768 } else if (!memcmp(from+4, "exactmap", 8)) {
769 from += 8+4;
770 e820.nr_map = 0;
771 userdef = 1;
772 } else {
773
774
775
776
777
778
779 unsigned long long start_at, mem_size;
780
781 mem_size = memparse(from+4, &from);
782 if (*from == '@') {
783 start_at = memparse(from+1, &from);
784 add_memory_region(start_at, mem_size, E820_RAM);
785 } else {
786 limit_regions(mem_size);
787 userdef=1;
788 }
789 }
790 }
791
792
793 else if (!memcmp(from, "noht", 4)) {
794 disable_x86_ht = 1;
795 set_bit(X86_FEATURE_HT, disabled_x86_caps);
796 }
797
798
799 else if (!memcmp(from, "acpismp=force", 13))
800 enable_acpi_smp_table = 1;
801
802
803
804
805
806
807 else if (!memcmp(from, "highmem=", 8))
808 highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
809nextchar:
810 c = *(from++);
811 if (!c)
812 break;
813 if (COMMAND_LINE_SIZE <= ++len)
814 break;
815 *(to++) = c;
816 }
817 *to = '\0';
818 *cmdline_p = command_line;
819 if (userdef) {
820 printk(KERN_INFO "user-defined physical RAM map:\n");
821 print_memory_map("user");
822 }
823}
824
825#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
826#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
827#define PFN_PHYS(x) ((x) << PAGE_SHIFT)
828
829
830
831
832#define MAXMEM_PFN PFN_DOWN(MAXMEM)
833#define MAX_NONPAE_PFN (1 << 20)
834
835
836
837
838static void __init find_max_pfn(void)
839{
840 int i;
841
842 max_pfn = 0;
843 for (i = 0; i < e820.nr_map; i++) {
844 unsigned long start, end;
845
846 if (e820.map[i].type != E820_RAM)
847 continue;
848 start = PFN_UP(e820.map[i].addr);
849 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
850 if (start >= end)
851 continue;
852 if (end > max_pfn)
853 max_pfn = end;
854 }
855}
856
857
858
859
860static unsigned long __init find_max_low_pfn(void)
861{
862 unsigned long max_low_pfn;
863
864 max_low_pfn = max_pfn;
865 if (max_low_pfn > MAXMEM_PFN) {
866 if (highmem_pages == -1)
867 highmem_pages = max_pfn - MAXMEM_PFN;
868 if (highmem_pages + MAXMEM_PFN < max_pfn)
869 max_pfn = MAXMEM_PFN + highmem_pages;
870 if (highmem_pages + MAXMEM_PFN > max_pfn) {
871 printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
872 highmem_pages = 0;
873 }
874 max_low_pfn = MAXMEM_PFN;
875#ifndef CONFIG_HIGHMEM
876
877 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
878 MAXMEM>>20);
879 if (max_pfn > MAX_NONPAE_PFN)
880 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
881 else
882 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
883#else
884#ifndef CONFIG_X86_PAE
885 if (max_pfn > MAX_NONPAE_PFN) {
886 max_pfn = MAX_NONPAE_PFN;
887 printk(KERN_WARNING "Warning only 4GB will be used.\n");
888 printk(KERN_WARNING "Use a PAE enabled kernel.\n");
889 }
890#endif
891#endif
892 } else {
893 if (highmem_pages == -1)
894 highmem_pages = 0;
895#if CONFIG_HIGHMEM
896 if (highmem_pages >= max_pfn) {
897 printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
898 highmem_pages = 0;
899 }
900 if (highmem_pages) {
901 if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
902 printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
903 highmem_pages = 0;
904 }
905 max_low_pfn -= highmem_pages;
906 }
907#else
908 if (highmem_pages)
909 printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
910#endif
911 }
912
913 return max_low_pfn;
914}
915
916
917
918
919static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
920{
921 int i;
922
923 for (i = 0; i < e820.nr_map; i++) {
924 unsigned long curr_pfn, last_pfn, size;
925
926
927
928 if (e820.map[i].type != E820_RAM)
929 continue;
930
931
932
933 curr_pfn = PFN_UP(e820.map[i].addr);
934 if (curr_pfn >= max_low_pfn)
935 continue;
936
937
938
939 last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
940
941 if (last_pfn > max_low_pfn)
942 last_pfn = max_low_pfn;
943
944
945
946
947
948 if (last_pfn <= curr_pfn)
949 continue;
950
951 size = last_pfn - curr_pfn;
952 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
953 }
954}
955
956static unsigned long __init setup_memory(void)
957{
958 unsigned long bootmap_size, start_pfn, max_low_pfn;
959
960
961
962
963
964 start_pfn = PFN_UP(__pa(&_end));
965
966 find_max_pfn();
967
968 max_low_pfn = find_max_low_pfn();
969
970#ifdef CONFIG_HIGHMEM
971 highstart_pfn = highend_pfn = max_pfn;
972 if (max_pfn > max_low_pfn) {
973 highstart_pfn = max_low_pfn;
974 }
975 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
976 pages_to_mb(highend_pfn - highstart_pfn));
977#endif
978 printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
979 pages_to_mb(max_low_pfn));
980
981
982
983 bootmap_size = init_bootmem(start_pfn, max_low_pfn);
984
985 register_bootmem_low_pages(max_low_pfn);
986
987
988
989
990
991
992
993 reserve_bootmem(HIGH_MEMORY, (PFN_PHYS(start_pfn) +
994 bootmap_size + PAGE_SIZE-1) - (HIGH_MEMORY));
995
996
997
998
999
1000 reserve_bootmem(0, PAGE_SIZE);
1001
1002#ifdef CONFIG_SMP
1003
1004
1005
1006
1007
1008 reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
1009#endif
1010
1011#ifdef CONFIG_X86_LOCAL_APIC
1012
1013
1014
1015 find_smp_config();
1016#endif
1017#ifdef CONFIG_BLK_DEV_INITRD
1018 if (LOADER_TYPE && INITRD_START) {
1019 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
1020 reserve_bootmem(INITRD_START, INITRD_SIZE);
1021 initrd_start =
1022 INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
1023 initrd_end = initrd_start+INITRD_SIZE;
1024 }
1025 else {
1026 printk(KERN_ERR "initrd extends beyond end of memory "
1027 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
1028 INITRD_START + INITRD_SIZE,
1029 max_low_pfn << PAGE_SHIFT);
1030 initrd_start = 0;
1031 }
1032 }
1033#endif
1034
1035 return max_low_pfn;
1036}
1037
1038
1039
1040
1041
1042static void __init register_memory(unsigned long max_low_pfn)
1043{
1044 unsigned long low_mem_size;
1045 int i;
1046
1047 probe_roms();
1048 for (i = 0; i < e820.nr_map; i++) {
1049 struct resource *res;
1050 if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
1051 continue;
1052 res = alloc_bootmem_low(sizeof(struct resource));
1053 switch (e820.map[i].type) {
1054 case E820_RAM: res->name = "System RAM"; break;
1055 case E820_ACPI: res->name = "ACPI Tables"; break;
1056 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
1057 default: res->name = "reserved";
1058 }
1059 res->start = e820.map[i].addr;
1060 res->end = res->start + e820.map[i].size - 1;
1061 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1062 request_resource(&iomem_resource, res);
1063 if (e820.map[i].type == E820_RAM) {
1064
1065
1066
1067
1068
1069 request_resource(res, &code_resource);
1070 request_resource(res, &data_resource);
1071 }
1072 }
1073 request_resource(&iomem_resource, &vram_resource);
1074
1075
1076 for (i = 0; i < STANDARD_IO_RESOURCES; i++)
1077 request_resource(&ioport_resource, standard_io_resources+i);
1078
1079
1080 low_mem_size = ((max_low_pfn << PAGE_SHIFT) + 0xfffff) & ~0xfffff;
1081 if (low_mem_size > pci_mem_start)
1082 pci_mem_start = low_mem_size;
1083}
1084
1085void __init setup_arch(char **cmdline_p)
1086{
1087 unsigned long max_low_pfn;
1088
1089#ifdef CONFIG_VISWS
1090 visws_get_board_type_and_rev();
1091#endif
1092
1093#ifndef CONFIG_HIGHIO
1094 blk_nohighio = 1;
1095#endif
1096
1097 ROOT_DEV = to_kdev_t(ORIG_ROOT_DEV);
1098 drive_info = DRIVE_INFO;
1099 screen_info = SCREEN_INFO;
1100 apm_info.bios = APM_BIOS_INFO;
1101 if( SYS_DESC_TABLE.length != 0 ) {
1102 MCA_bus = SYS_DESC_TABLE.table[3] &0x2;
1103 machine_id = SYS_DESC_TABLE.table[0];
1104 machine_submodel_id = SYS_DESC_TABLE.table[1];
1105 BIOS_revision = SYS_DESC_TABLE.table[2];
1106 }
1107 aux_device_present = AUX_DEVICE_INFO;
1108
1109#ifdef CONFIG_BLK_DEV_RAM
1110 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
1111 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
1112 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
1113#endif
1114 setup_memory_region();
1115
1116 if (!MOUNT_ROOT_RDONLY)
1117 root_mountflags &= ~MS_RDONLY;
1118 init_mm.start_code = (unsigned long) &_text;
1119 init_mm.end_code = (unsigned long) &_etext;
1120 init_mm.end_data = (unsigned long) &_edata;
1121 init_mm.brk = (unsigned long) &_end;
1122
1123 code_resource.start = virt_to_bus(&_text);
1124 code_resource.end = virt_to_bus(&_etext)-1;
1125 data_resource.start = virt_to_bus(&_etext);
1126 data_resource.end = virt_to_bus(&_edata)-1;
1127
1128 parse_cmdline_early(cmdline_p);
1129
1130 max_low_pfn = setup_memory();
1131
1132
1133
1134
1135
1136
1137
1138
1139 if (disable_x86_ht) {
1140 clear_bit(X86_FEATURE_HT, &boot_cpu_data.x86_capability[0]);
1141 set_bit(X86_FEATURE_HT, disabled_x86_caps);
1142 enable_acpi_smp_table = 0;
1143 }
1144 if (test_bit(X86_FEATURE_HT, &boot_cpu_data.x86_capability[0]))
1145 enable_acpi_smp_table = 1;
1146
1147
1148
1149
1150
1151
1152
1153#ifdef CONFIG_SMP
1154 smp_alloc_memory();
1155#endif
1156 paging_init();
1157#ifdef CONFIG_X86_LOCAL_APIC
1158
1159
1160
1161 if (smp_found_config)
1162 get_smp_config();
1163#endif
1164
1165 register_memory(max_low_pfn);
1166
1167#ifdef CONFIG_VT
1168#if defined(CONFIG_VGA_CONSOLE)
1169 conswitchp = &vga_con;
1170#elif defined(CONFIG_DUMMY_CONSOLE)
1171 conswitchp = &dummy_con;
1172#endif
1173#endif
1174 dmi_scan_machine();
1175}
1176
1177static int cachesize_override __initdata = -1;
1178static int __init cachesize_setup(char *str)
1179{
1180 get_option (&str, &cachesize_override);
1181 return 1;
1182}
1183__setup("cachesize=", cachesize_setup);
1184
1185
1186#ifndef CONFIG_X86_TSC
1187static int tsc_disable __initdata = 0;
1188
1189static int __init notsc_setup(char *str)
1190{
1191 tsc_disable = 1;
1192 return 1;
1193}
1194#else
1195static int __init notsc_setup(char *str)
1196{
1197 printk("notsc: Kernel compiled with CONFIG_X86_TSC, cannot disable TSC.\n");
1198 return 1;
1199}
1200#endif
1201__setup("notsc", notsc_setup);
1202
1203static int __init highio_setup(char *str)
1204{
1205 printk("i386: disabling HIGHMEM block I/O\n");
1206 blk_nohighio = 1;
1207 return 1;
1208}
1209__setup("nohighio", highio_setup);
1210
1211static int __init get_model_name(struct cpuinfo_x86 *c)
1212{
1213 unsigned int *v;
1214 char *p, *q;
1215
1216 if (cpuid_eax(0x80000000) < 0x80000004)
1217 return 0;
1218
1219 v = (unsigned int *) c->x86_model_id;
1220 cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
1221 cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
1222 cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
1223 c->x86_model_id[48] = 0;
1224
1225
1226
1227 p = q = &c->x86_model_id[0];
1228 while ( *p == ' ' )
1229 p++;
1230 if ( p != q ) {
1231 while ( *p )
1232 *q++ = *p++;
1233 while ( q <= &c->x86_model_id[48] )
1234 *q++ = '\0';
1235 }
1236
1237 return 1;
1238}
1239
1240
1241static void __init display_cacheinfo(struct cpuinfo_x86 *c)
1242{
1243 unsigned int n, dummy, ecx, edx, l2size;
1244
1245 n = cpuid_eax(0x80000000);
1246
1247 if (n >= 0x80000005) {
1248 cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
1249 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
1250 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
1251 c->x86_cache_size=(ecx>>24)+(edx>>24);
1252 }
1253
1254 if (n < 0x80000006)
1255 return;
1256
1257 ecx = cpuid_ecx(0x80000006);
1258 l2size = ecx >> 16;
1259
1260
1261 if ((c->x86_vendor == X86_VENDOR_AMD) && (c->x86 == 6)) {
1262 if (c->x86_model == 3 && c->x86_mask == 0)
1263 l2size = 64;
1264 if (c->x86_model == 4 &&
1265 (c->x86_mask==0 || c->x86_mask==1))
1266 l2size = 256;
1267 }
1268
1269 if (c->x86_vendor == X86_VENDOR_CENTAUR) {
1270
1271 if ((c->x86 == 6) &&
1272 ((c->x86_model == 7) || (c->x86_model == 8))) {
1273 l2size >>= 8;
1274 }
1275
1276
1277
1278
1279 if ((c->x86==6) && (c->x86_model==9) &&
1280 (c->x86_mask==1) && (l2size==65))
1281 l2size -= 1;
1282 }
1283
1284
1285 if (cachesize_override != -1)
1286 l2size = cachesize_override;
1287
1288 if ( l2size == 0 )
1289 return;
1290
1291 c->x86_cache_size = l2size;
1292
1293 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1294 l2size, ecx & 0xFF);
1295}
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310extern void vide(void);
1311__asm__(".align 4\nvide: ret");
1312
1313static int __init init_amd(struct cpuinfo_x86 *c)
1314{
1315 u32 l, h;
1316 int mbytes = max_mapnr >> (20-PAGE_SHIFT);
1317 int r;
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327 clear_bit(0*32+31, &c->x86_capability);
1328
1329 r = get_model_name(c);
1330
1331 switch(c->x86)
1332 {
1333 case 5:
1334 if( c->x86_model < 6 )
1335 {
1336
1337 if ( c->x86_model == 0 ) {
1338 clear_bit(X86_FEATURE_APIC, &c->x86_capability);
1339 set_bit(X86_FEATURE_PGE, &c->x86_capability);
1340 }
1341 break;
1342 }
1343
1344 if ( c->x86_model == 6 && c->x86_mask == 1 ) {
1345 const int K6_BUG_LOOP = 1000000;
1346 int n;
1347 void (*f_vide)(void);
1348 unsigned long d, d2;
1349
1350 printk(KERN_INFO "AMD K6 stepping B detected - ");
1351
1352
1353
1354
1355
1356
1357 n = K6_BUG_LOOP;
1358 f_vide = vide;
1359 rdtscl(d);
1360 while (n--)
1361 f_vide();
1362 rdtscl(d2);
1363 d = d2-d;
1364
1365
1366 printk(KERN_INFO "K6 BUG %ld %d (Report these if test report is incorrect)\n", d, 20*K6_BUG_LOOP);
1367 printk(KERN_INFO "AMD K6 stepping B detected - ");
1368
1369 if (d > 20*K6_BUG_LOOP)
1370 printk("system stability may be impaired when more than 32 MB are used.\n");
1371 else
1372 printk("probably OK (after B9730xxxx).\n");
1373 printk(KERN_INFO "Please see http://www.mygale.com/~poulot/k6bug.html\n");
1374 }
1375
1376
1377 if (c->x86_model < 8 ||
1378 (c->x86_model== 8 && c->x86_mask < 8)) {
1379
1380 if(mbytes>508)
1381 mbytes=508;
1382
1383 rdmsr(MSR_K6_WHCR, l, h);
1384 if ((l&0x0000FFFF)==0) {
1385 unsigned long flags;
1386 l=(1<<0)|((mbytes/4)<<1);
1387 local_irq_save(flags);
1388 wbinvd();
1389 wrmsr(MSR_K6_WHCR, l, h);
1390 local_irq_restore(flags);
1391 printk(KERN_INFO "Enabling old style K6 write allocation for %d Mb\n",
1392 mbytes);
1393 }
1394 break;
1395 }
1396
1397 if ((c->x86_model == 8 && c->x86_mask >7) ||
1398 c->x86_model == 9 || c->x86_model == 13) {
1399
1400
1401 if(mbytes>4092)
1402 mbytes=4092;
1403
1404 rdmsr(MSR_K6_WHCR, l, h);
1405 if ((l&0xFFFF0000)==0) {
1406 unsigned long flags;
1407 l=((mbytes>>2)<<22)|(1<<16);
1408 local_irq_save(flags);
1409 wbinvd();
1410 wrmsr(MSR_K6_WHCR, l, h);
1411 local_irq_restore(flags);
1412 printk(KERN_INFO "Enabling new style K6 write allocation for %d Mb\n",
1413 mbytes);
1414 }
1415
1416
1417 if (c->x86_model == 13 || c->x86_model == 9 ||
1418 (c->x86_model == 8 && c->x86_mask >= 8))
1419 set_bit(X86_FEATURE_K6_MTRR, &c->x86_capability);
1420 break;
1421 }
1422 break;
1423
1424 case 6:
1425
1426
1427
1428
1429
1430
1431 if (c->x86_model >= 6 && c->x86_model <= 10) {
1432 if (!test_bit(X86_FEATURE_XMM,
1433 &c->x86_capability)) {
1434 printk(KERN_INFO
1435 "Enabling Disabled K7/SSE Support...\n");
1436 rdmsr(MSR_K7_HWCR, l, h);
1437 l &= ~0x00008000;
1438 wrmsr(MSR_K7_HWCR, l, h);
1439 set_bit(X86_FEATURE_XMM,
1440 &c->x86_capability);
1441 }
1442 }
1443
1444
1445
1446
1447
1448 if ((c->x86_model == 8 && c->x86_mask>=1) || (c->x86_model > 8)) {
1449 rdmsr(MSR_K7_CLK_CTL, l, h);
1450 if ((l & 0xfff00000) != 0x20000000) {
1451 printk ("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", l,
1452 ((l & 0x000fffff)|0x20000000));
1453 wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
1454 }
1455 }
1456 break;
1457 }
1458
1459 display_cacheinfo(c);
1460 return r;
1461}
1462
1463
1464
1465
1466static void __init do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
1467{
1468 unsigned char ccr2, ccr3;
1469 unsigned long flags;
1470
1471
1472 local_irq_save(flags);
1473 ccr3 = getCx86(CX86_CCR3);
1474 setCx86(CX86_CCR3, ccr3 ^ 0x80);
1475 getCx86(0xc0);
1476
1477 if (getCx86(CX86_CCR3) == ccr3) {
1478 ccr2 = getCx86(CX86_CCR2);
1479 setCx86(CX86_CCR2, ccr2 ^ 0x04);
1480 getCx86(0xc0);
1481
1482 if (getCx86(CX86_CCR2) == ccr2)
1483 *dir0 = 0xfd;
1484 else {
1485 setCx86(CX86_CCR2, ccr2);
1486 *dir0 = 0xfe;
1487 }
1488 }
1489 else {
1490 setCx86(CX86_CCR3, ccr3);
1491
1492
1493 *dir0 = getCx86(CX86_DIR0);
1494 *dir1 = getCx86(CX86_DIR1);
1495 }
1496 local_irq_restore(flags);
1497}
1498
1499
1500
1501
1502
1503
1504static unsigned char Cx86_dir0_msb __initdata = 0;
1505
1506static char Cx86_model[][9] __initdata = {
1507 "Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
1508 "M II ", "Unknown"
1509};
1510static char Cx486_name[][5] __initdata = {
1511 "SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
1512 "SRx2", "DRx2"
1513};
1514static char Cx486S_name[][4] __initdata = {
1515 "S", "S2", "Se", "S2e"
1516};
1517static char Cx486D_name[][4] __initdata = {
1518 "DX", "DX2", "?", "?", "?", "DX4"
1519};
1520static char Cx86_cb[] __initdata = "?.5x Core/Bus Clock";
1521static char cyrix_model_mult1[] __initdata = "12??43";
1522static char cyrix_model_mult2[] __initdata = "12233445";
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532extern void calibrate_delay(void) __init;
1533
1534static void __init check_cx686_slop(struct cpuinfo_x86 *c)
1535{
1536 unsigned long flags;
1537
1538 if (Cx86_dir0_msb == 3) {
1539 unsigned char ccr3, ccr5;
1540
1541 local_irq_save(flags);
1542 ccr3 = getCx86(CX86_CCR3);
1543 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
1544 ccr5 = getCx86(CX86_CCR5);
1545 if (ccr5 & 2)
1546 setCx86(CX86_CCR5, ccr5 & 0xfd);
1547 setCx86(CX86_CCR3, ccr3);
1548 local_irq_restore(flags);
1549
1550 if (ccr5 & 2) {
1551 printk(KERN_INFO "Recalibrating delay loop with SLOP bit reset\n");
1552 calibrate_delay();
1553 c->loops_per_jiffy = loops_per_jiffy;
1554 }
1555 }
1556}
1557
1558static void __init init_cyrix(struct cpuinfo_x86 *c)
1559{
1560 unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
1561 char *buf = c->x86_model_id;
1562 const char *p = NULL;
1563
1564
1565
1566 clear_bit(0*32+31, &c->x86_capability);
1567
1568
1569 if ( test_bit(1*32+24, &c->x86_capability) ) {
1570 clear_bit(1*32+24, &c->x86_capability);
1571 set_bit(X86_FEATURE_CXMMX, &c->x86_capability);
1572 }
1573
1574 do_cyrix_devid(&dir0, &dir1);
1575
1576 check_cx686_slop(c);
1577
1578 Cx86_dir0_msb = dir0_msn = dir0 >> 4;
1579 dir0_lsn = dir0 & 0xf;
1580
1581
1582 c->x86_model = (dir1 >> 4) + 1;
1583 c->x86_mask = dir1 & 0xf;
1584
1585
1586
1587
1588
1589
1590
1591 switch (dir0_msn) {
1592 unsigned char tmp;
1593
1594 case 0:
1595 p = Cx486_name[dir0_lsn & 7];
1596 break;
1597
1598 case 1:
1599 p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
1600 : Cx486S_name[dir0_lsn & 3];
1601 break;
1602
1603 case 2:
1604 Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
1605 p = Cx86_cb+2;
1606 break;
1607
1608 case 3:
1609 Cx86_cb[1] = ' ';
1610 Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
1611 if (dir1 > 0x21) {
1612 Cx86_cb[0] = 'L';
1613 p = Cx86_cb;
1614 (c->x86_model)++;
1615 } else
1616 p = Cx86_cb+1;
1617
1618 set_bit(X86_FEATURE_CYRIX_ARR, &c->x86_capability);
1619
1620 c->coma_bug = 1;
1621 break;
1622
1623 case 4:
1624#ifdef CONFIG_PCI
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637 printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
1638 isa_dma_bridge_buggy = 2;
1639#endif
1640 c->x86_cache_size=16;
1641
1642
1643 if (c->cpuid_level == 2) {
1644 get_model_name(c);
1645
1646
1647
1648
1649 if(pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, NULL) ||
1650 pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, NULL))
1651 clear_bit(X86_FEATURE_TSC, c->x86_capability);
1652 return;
1653 }
1654 else {
1655 Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
1656 p = Cx86_cb+2;
1657 c->x86_model = (dir1 & 0x20) ? 1 : 2;
1658 if(pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, NULL) ||
1659 pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, NULL))
1660 clear_bit(X86_FEATURE_TSC, &c->x86_capability);
1661 }
1662 break;
1663
1664 case 5:
1665 if (dir1 > 7)
1666 {
1667 dir0_msn++;
1668
1669 setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
1670 }
1671 else
1672 {
1673 c->coma_bug = 1;
1674 }
1675 tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
1676 Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
1677 p = Cx86_cb+tmp;
1678 if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
1679 (c->x86_model)++;
1680
1681 set_bit(X86_FEATURE_CYRIX_ARR, &c->x86_capability);
1682 break;
1683
1684 case 0xf:
1685 switch (dir0_lsn) {
1686 case 0xd:
1687 dir0_msn = 0;
1688 p = Cx486_name[(c->hard_math) ? 1 : 0];
1689 break;
1690
1691 case 0xe:
1692 dir0_msn = 0;
1693 p = Cx486S_name[0];
1694 break;
1695 }
1696 break;
1697
1698 default:
1699 dir0_msn = 7;
1700 break;
1701 }
1702 strcpy(buf, Cx86_model[dir0_msn & 7]);
1703 if (p) strcat(buf, p);
1704 return;
1705}
1706
1707#ifdef CONFIG_X86_OOSTORE
1708
1709static u32 __init power2(u32 x)
1710{
1711 u32 s=1;
1712 while(s<=x)
1713 s<<=1;
1714 return s>>=1;
1715}
1716
1717
1718
1719
1720
1721static void __init winchip_mcr_insert(int reg, u32 base, u32 size, int key)
1722{
1723 u32 lo, hi;
1724
1725 hi = base & ~0xFFF;
1726 lo = ~(size-1);
1727 lo &= ~0xFFF;
1728 lo |= key;
1729 wrmsr(reg+MSR_IDT_MCR0, lo, hi);
1730 mtrr_centaur_report_mcr(reg, lo, hi);
1731}
1732
1733
1734
1735
1736
1737
1738
1739static u32 __init ramtop(void)
1740{
1741 int i;
1742 u32 top = 0;
1743 u32 clip = 0xFFFFFFFFUL;
1744
1745 for (i = 0; i < e820.nr_map; i++) {
1746 unsigned long start, end;
1747
1748 if (e820.map[i].addr > 0xFFFFFFFFUL)
1749 continue;
1750
1751
1752
1753
1754
1755 if (e820.map[i].type == E820_RESERVED)
1756 {
1757 if(e820.map[i].addr >= 0x100000UL && e820.map[i].addr < clip)
1758 clip = e820.map[i].addr;
1759 continue;
1760 }
1761 start = e820.map[i].addr;
1762 end = e820.map[i].addr + e820.map[i].size;
1763 if (start >= end)
1764 continue;
1765 if (end > top)
1766 top = end;
1767 }
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780 if(top>clip)
1781 top=clip;
1782
1783 return top;
1784}
1785
1786
1787
1788
1789
1790static int __init winchip_mcr_compute(int nr, int key)
1791{
1792 u32 mem = ramtop();
1793 u32 root = power2(mem);
1794 u32 base = root;
1795 u32 top = root;
1796 u32 floor = 0;
1797 int ct = 0;
1798
1799 while(ct<nr)
1800 {
1801 u32 fspace = 0;
1802
1803
1804
1805
1806
1807 u32 high = power2(mem-top);
1808
1809
1810
1811
1812
1813 u32 low = base/2;
1814
1815
1816
1817
1818
1819
1820 if(base <= 1024*1024)
1821 low = 0;
1822
1823
1824
1825
1826
1827
1828 if(floor == 0)
1829 fspace = 512*1024;
1830 else if(floor ==512*1024)
1831 fspace = 128*1024;
1832
1833
1834
1835
1836
1837
1838
1839 if(fspace > high && fspace > low)
1840 {
1841 winchip_mcr_insert(ct, floor, fspace, key);
1842 floor += fspace;
1843 }
1844 else if(high > low)
1845 {
1846 winchip_mcr_insert(ct, top, high, key);
1847 top += high;
1848 }
1849 else if(low > 0)
1850 {
1851 base -= low;
1852 winchip_mcr_insert(ct, base, low, key);
1853 }
1854 else break;
1855 ct++;
1856 }
1857
1858
1859
1860
1861
1862 return ct;
1863}
1864
1865static void __init winchip_create_optimal_mcr(void)
1866{
1867 int i;
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878 int used = winchip_mcr_compute(6, 31);
1879
1880
1881
1882
1883
1884 for(i=used;i<8;i++)
1885 wrmsr(MSR_IDT_MCR0+i, 0, 0);
1886}
1887
1888static void __init winchip2_create_optimal_mcr(void)
1889{
1890 u32 lo, hi;
1891 int i;
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903 int used = winchip_mcr_compute(6, 25);
1904
1905
1906
1907
1908
1909 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1910 for(i=0;i<used;i++)
1911 lo|=1<<(9+i);
1912 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1913
1914
1915
1916
1917
1918 for(i=used;i<8;i++)
1919 wrmsr(MSR_IDT_MCR0+i, 0, 0);
1920}
1921
1922
1923
1924
1925
1926static void __init winchip2_unprotect_mcr(void)
1927{
1928 u32 lo, hi;
1929 u32 key;
1930
1931 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1932 lo&=~0x1C0;
1933 key = (lo>>17) & 7;
1934 lo |= key<<6;
1935 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1936}
1937
1938static void __init winchip2_protect_mcr(void)
1939{
1940 u32 lo, hi;
1941
1942 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1943 lo&=~0x1C0;
1944 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1945}
1946
1947#endif
1948
1949static void __init init_centaur(struct cpuinfo_x86 *c)
1950{
1951 enum {
1952 ECX8=1<<1,
1953 EIERRINT=1<<2,
1954 DPM=1<<3,
1955 DMCE=1<<4,
1956 DSTPCLK=1<<5,
1957 ELINEAR=1<<6,
1958 DSMC=1<<7,
1959 DTLOCK=1<<8,
1960 EDCTLB=1<<8,
1961 EMMX=1<<9,
1962 DPDC=1<<11,
1963 EBRPRED=1<<12,
1964 DIC=1<<13,
1965 DDC=1<<14,
1966 DNA=1<<15,
1967 ERETSTK=1<<16,
1968 E2MMX=1<<19,
1969 EAMD3D=1<<20,
1970 };
1971
1972 char *name;
1973 u32 fcr_set=0;
1974 u32 fcr_clr=0;
1975 u32 lo,hi,newlo;
1976 u32 aa,bb,cc,dd;
1977
1978
1979
1980 clear_bit(0*32+31, &c->x86_capability);
1981
1982 switch (c->x86) {
1983
1984 case 5:
1985 switch(c->x86_model) {
1986 case 4:
1987 name="C6";
1988 fcr_set=ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
1989 fcr_clr=DPDC;
1990 printk(KERN_NOTICE "Disabling bugged TSC.\n");
1991 clear_bit(X86_FEATURE_TSC, &c->x86_capability);
1992#ifdef CONFIG_X86_OOSTORE
1993 winchip_create_optimal_mcr();
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003 wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
2004#endif
2005 break;
2006 case 8:
2007 switch(c->x86_mask) {
2008 default:
2009 name="2";
2010 break;
2011 case 7 ... 9:
2012 name="2A";
2013 break;
2014 case 10 ... 15:
2015 name="2B";
2016 break;
2017 }
2018 fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
2019 fcr_clr=DPDC;
2020#ifdef CONFIG_X86_OOSTORE
2021 winchip2_unprotect_mcr();
2022 winchip2_create_optimal_mcr();
2023 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
2024
2025
2026
2027
2028
2029 lo|=31;
2030 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
2031 winchip2_protect_mcr();
2032#endif
2033 break;
2034 case 9:
2035 name="3";
2036 fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
2037 fcr_clr=DPDC;
2038#ifdef CONFIG_X86_OOSTORE
2039 winchip2_unprotect_mcr();
2040 winchip2_create_optimal_mcr();
2041 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
2042
2043
2044
2045
2046
2047 lo|=31;
2048 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
2049 winchip2_protect_mcr();
2050#endif
2051 break;
2052 case 10:
2053 name="4";
2054
2055 break;
2056 default:
2057 name="??";
2058 }
2059
2060 rdmsr(MSR_IDT_FCR1, lo, hi);
2061 newlo=(lo|fcr_set) & (~fcr_clr);
2062
2063 if (newlo!=lo) {
2064 printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n", lo, newlo );
2065 wrmsr(MSR_IDT_FCR1, newlo, hi );
2066 } else {
2067 printk(KERN_INFO "Centaur FCR is 0x%X\n",lo);
2068 }
2069
2070 set_bit(X86_FEATURE_CENTAUR_MCR, &c->x86_capability);
2071
2072 set_bit(X86_FEATURE_CX8, &c->x86_capability);
2073
2074 if (c->x86_model >=8)
2075 set_bit(X86_FEATURE_3DNOW, &c->x86_capability);
2076
2077 if ( cpuid_eax(0x80000000) >= 0x80000005 ) {
2078
2079 cpuid(0x80000005,&aa,&bb,&cc,&dd);
2080
2081 c->x86_cache_size = (cc>>24)+(dd>>24);
2082 }
2083 sprintf( c->x86_model_id, "WinChip %s", name );
2084 break;
2085
2086 case 6:
2087 switch (c->x86_model) {
2088 case 6 ... 8:
2089 rdmsr (MSR_VIA_FCR, lo, hi);
2090 lo |= (1<<1 | 1<<7);
2091 wrmsr (MSR_VIA_FCR, lo, hi);
2092
2093 set_bit(X86_FEATURE_CX8, &c->x86_capability);
2094 set_bit(X86_FEATURE_3DNOW, &c->x86_capability);
2095
2096
2097
2098 case 9:
2099 default:
2100 get_model_name(c);
2101 display_cacheinfo(c);
2102 break;
2103 }
2104 break;
2105 }
2106}
2107
2108
2109static void __init init_transmeta(struct cpuinfo_x86 *c)
2110{
2111 unsigned int cap_mask, uk, max, dummy;
2112 unsigned int cms_rev1, cms_rev2;
2113 unsigned int cpu_rev, cpu_freq, cpu_flags;
2114 char cpu_info[65];
2115
2116 get_model_name(c);
2117 display_cacheinfo(c);
2118
2119
2120 max = cpuid_eax(0x80860000);
2121 if ( max >= 0x80860001 ) {
2122 cpuid(0x80860001, &dummy, &cpu_rev, &cpu_freq, &cpu_flags);
2123 printk(KERN_INFO "CPU: Processor revision %u.%u.%u.%u, %u MHz\n",
2124 (cpu_rev >> 24) & 0xff,
2125 (cpu_rev >> 16) & 0xff,
2126 (cpu_rev >> 8) & 0xff,
2127 cpu_rev & 0xff,
2128 cpu_freq);
2129 }
2130 if ( max >= 0x80860002 ) {
2131 cpuid(0x80860002, &dummy, &cms_rev1, &cms_rev2, &dummy);
2132 printk(KERN_INFO "CPU: Code Morphing Software revision %u.%u.%u-%u-%u\n",
2133 (cms_rev1 >> 24) & 0xff,
2134 (cms_rev1 >> 16) & 0xff,
2135 (cms_rev1 >> 8) & 0xff,
2136 cms_rev1 & 0xff,
2137 cms_rev2);
2138 }
2139 if ( max >= 0x80860006 ) {
2140 cpuid(0x80860003,
2141 (void *)&cpu_info[0],
2142 (void *)&cpu_info[4],
2143 (void *)&cpu_info[8],
2144 (void *)&cpu_info[12]);
2145 cpuid(0x80860004,
2146 (void *)&cpu_info[16],
2147 (void *)&cpu_info[20],
2148 (void *)&cpu_info[24],
2149 (void *)&cpu_info[28]);
2150 cpuid(0x80860005,
2151 (void *)&cpu_info[32],
2152 (void *)&cpu_info[36],
2153 (void *)&cpu_info[40],
2154 (void *)&cpu_info[44]);
2155 cpuid(0x80860006,
2156 (void *)&cpu_info[48],
2157 (void *)&cpu_info[52],
2158 (void *)&cpu_info[56],
2159 (void *)&cpu_info[60]);
2160 cpu_info[64] = '\0';
2161 printk(KERN_INFO "CPU: %s\n", cpu_info);
2162 }
2163
2164
2165 rdmsr(0x80860004, cap_mask, uk);
2166 wrmsr(0x80860004, ~0, uk);
2167 c->x86_capability[0] = cpuid_edx(0x00000001);
2168 wrmsr(0x80860004, cap_mask, uk);
2169
2170
2171#define USER686 (X86_FEATURE_TSC|X86_FEATURE_CX8|X86_FEATURE_CMOV)
2172 if ( c->x86 == 5 && (c->x86_capability[0] & USER686) == USER686 )
2173 c->x86 = 6;
2174}
2175
2176
2177static void __init init_rise(struct cpuinfo_x86 *c)
2178{
2179 printk("CPU: Rise iDragon");
2180 if (c->x86_model > 2)
2181 printk(" II");
2182 printk("\n");
2183
2184
2185
2186
2187 __asm__ (
2188 "movl $0x6363452a, %%eax\n\t"
2189 "movl $0x3231206c, %%ecx\n\t"
2190 "movl $0x2a32313a, %%edx\n\t"
2191 "cpuid\n\t"
2192 "movl $0x63634523, %%eax\n\t"
2193 "movl $0x32315f6c, %%ecx\n\t"
2194 "movl $0x2333313a, %%edx\n\t"
2195 "cpuid\n\t" : : : "eax", "ebx", "ecx", "edx"
2196 );
2197 set_bit(X86_FEATURE_CX8, &c->x86_capability);
2198}
2199
2200
2201extern void trap_init_f00f_bug(void);
2202
2203#define LVL_1_INST 1
2204#define LVL_1_DATA 2
2205#define LVL_2 3
2206#define LVL_3 4
2207#define LVL_TRACE 5
2208
2209struct _cache_table
2210{
2211 unsigned char descriptor;
2212 char cache_type;
2213 short size;
2214};
2215
2216
2217static struct _cache_table cache_table[] __initdata =
2218{
2219 { 0x06, LVL_1_INST, 8 },
2220 { 0x08, LVL_1_INST, 16 },
2221 { 0x0A, LVL_1_DATA, 8 },
2222 { 0x0C, LVL_1_DATA, 16 },
2223 { 0x22, LVL_3, 512 },
2224 { 0x23, LVL_3, 1024 },
2225 { 0x25, LVL_3, 2048 },
2226 { 0x29, LVL_3, 4096 },
2227 { 0x39, LVL_2, 128 },
2228 { 0x3b, LVL_2, 128 },
2229 { 0x3C, LVL_2, 256 },
2230 { 0x41, LVL_2, 128 },
2231 { 0x42, LVL_2, 256 },
2232 { 0x43, LVL_2, 512 },
2233 { 0x44, LVL_2, 1024 },
2234 { 0x45, LVL_2, 2048 },
2235 { 0x66, LVL_1_DATA, 8 },
2236 { 0x67, LVL_1_DATA, 16 },
2237 { 0x68, LVL_1_DATA, 32 },
2238 { 0x70, LVL_TRACE, 12 },
2239 { 0x71, LVL_TRACE, 16 },
2240 { 0x72, LVL_TRACE, 32 },
2241 { 0x79, LVL_2, 128 },
2242 { 0x7A, LVL_2, 256 },
2243 { 0x7B, LVL_2, 512 },
2244 { 0x7C, LVL_2, 1024 },
2245 { 0x82, LVL_2, 256 },
2246 { 0x83, LVL_2, 512 },
2247 { 0x84, LVL_2, 1024 },
2248 { 0x85, LVL_2, 2048 },
2249 { 0x00, 0, 0}
2250};
2251
2252static void __init init_intel(struct cpuinfo_x86 *c)
2253{
2254 unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0;
2255 char *p = NULL;
2256#ifndef CONFIG_X86_F00F_WORKS_OK
2257 static int f00f_workaround_enabled = 0;
2258
2259
2260
2261
2262
2263
2264 c->f00f_bug = 0;
2265 if (c->x86 == 5) {
2266 c->f00f_bug = 1;
2267 if (!f00f_workaround_enabled) {
2268 trap_init_f00f_bug();
2269 printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
2270 f00f_workaround_enabled = 1;
2271 }
2272 }
2273#endif
2274
2275 if (c->cpuid_level > 1) {
2276
2277 int i, j, n;
2278 int regs[4];
2279 unsigned char *dp = (unsigned char *)regs;
2280
2281
2282 n = cpuid_eax(2) & 0xFF;
2283
2284 for ( i = 0 ; i < n ; i++ ) {
2285 cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]);
2286
2287
2288 for ( j = 0 ; j < 3 ; j++ ) {
2289 if ( regs[j] < 0 ) regs[j] = 0;
2290 }
2291
2292
2293 for ( j = 1 ; j < 16 ; j++ ) {
2294 unsigned char des = dp[j];
2295 unsigned char k = 0;
2296
2297
2298 while (cache_table[k].descriptor != 0)
2299 {
2300 if (cache_table[k].descriptor == des) {
2301 switch (cache_table[k].cache_type) {
2302 case LVL_1_INST:
2303 l1i += cache_table[k].size;
2304 break;
2305 case LVL_1_DATA:
2306 l1d += cache_table[k].size;
2307 break;
2308 case LVL_2:
2309 l2 += cache_table[k].size;
2310 break;
2311 case LVL_3:
2312 l3 += cache_table[k].size;
2313 break;
2314 case LVL_TRACE:
2315 trace += cache_table[k].size;
2316 break;
2317 }
2318 break;
2319 }
2320
2321 k++;
2322 }
2323 }
2324 }
2325
2326
2327
2328
2329
2330
2331 if ((c->x86 == 6) && (c->x86_model == 11) && (l2 == 0))
2332 l2 = 256;
2333
2334 if (cachesize_override != -1)
2335 l2 = cachesize_override;
2336
2337 if ( trace )
2338 printk (KERN_INFO "CPU: Trace cache: %dK uops", trace);
2339 else if ( l1i )
2340 printk (KERN_INFO "CPU: L1 I cache: %dK", l1i);
2341 if ( l1d )
2342 printk(", L1 D cache: %dK\n", l1d);
2343
2344 if ( l2 )
2345 printk(KERN_INFO "CPU: L2 cache: %dK\n", l2);
2346 if ( l3 )
2347 printk(KERN_INFO "CPU: L3 cache: %dK\n", l3);
2348
2349
2350
2351
2352
2353
2354
2355 c->x86_cache_size = l2 ? l2 : (l1i+l1d);
2356 }
2357
2358
2359 if ( c->x86 == 6 && c->x86_model < 3 && c->x86_mask < 3 )
2360 clear_bit(X86_FEATURE_SEP, &c->x86_capability);
2361
2362
2363
2364
2365 if (c->x86 == 6) {
2366 switch (c->x86_model) {
2367 case 5:
2368 if (l2 == 0)
2369 p = "Celeron (Covington)";
2370 if (l2 == 256)
2371 p = "Mobile Pentium II (Dixon)";
2372 break;
2373
2374 case 6:
2375 if (l2 == 128)
2376 p = "Celeron (Mendocino)";
2377 break;
2378
2379 case 8:
2380 if (l2 == 128)
2381 p = "Celeron (Coppermine)";
2382 break;
2383 }
2384 }
2385
2386 if ( p )
2387 strcpy(c->x86_model_id, p);
2388
2389#ifdef CONFIG_SMP
2390 if (test_bit(X86_FEATURE_HT, &c->x86_capability) && !disable_x86_ht) {
2391 extern int phys_proc_id[NR_CPUS];
2392
2393 u32 eax, ebx, ecx, edx;
2394 int index_lsb, index_msb, tmp;
2395 int initial_apic_id;
2396 int cpu = smp_processor_id();
2397
2398 cpuid(1, &eax, &ebx, &ecx, &edx);
2399 smp_num_siblings = (ebx & 0xff0000) >> 16;
2400
2401 if (smp_num_siblings == 1) {
2402 printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
2403 } else if (smp_num_siblings > 1 ) {
2404 index_lsb = 0;
2405 index_msb = 31;
2406
2407
2408
2409
2410#define NR_SIBLINGS 2
2411 if (smp_num_siblings != NR_SIBLINGS) {
2412 printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
2413 smp_num_siblings = 1;
2414 return;
2415 }
2416 tmp = smp_num_siblings;
2417 while ((tmp & 1) == 0) {
2418 tmp >>=1 ;
2419 index_lsb++;
2420 }
2421 tmp = smp_num_siblings;
2422 while ((tmp & 0x80000000 ) == 0) {
2423 tmp <<=1 ;
2424 index_msb--;
2425 }
2426 if (index_lsb != index_msb )
2427 index_msb++;
2428 initial_apic_id = ebx >> 24 & 0xff;
2429 phys_proc_id[cpu] = initial_apic_id >> index_msb;
2430
2431 printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
2432 phys_proc_id[cpu]);
2433 }
2434
2435 }
2436#endif
2437}
2438
2439void __init get_cpu_vendor(struct cpuinfo_x86 *c)
2440{
2441 char *v = c->x86_vendor_id;
2442
2443 if (!strcmp(v, "GenuineIntel"))
2444 c->x86_vendor = X86_VENDOR_INTEL;
2445 else if (!strcmp(v, "AuthenticAMD"))
2446 c->x86_vendor = X86_VENDOR_AMD;
2447 else if (!strcmp(v, "CyrixInstead"))
2448 c->x86_vendor = X86_VENDOR_CYRIX;
2449 else if (!strcmp(v, "Geode by NSC"))
2450 c->x86_vendor = X86_VENDOR_NSC;
2451 else if (!strcmp(v, "UMC UMC UMC "))
2452 c->x86_vendor = X86_VENDOR_UMC;
2453 else if (!strcmp(v, "CentaurHauls"))
2454 c->x86_vendor = X86_VENDOR_CENTAUR;
2455 else if (!strcmp(v, "NexGenDriven"))
2456 c->x86_vendor = X86_VENDOR_NEXGEN;
2457 else if (!strcmp(v, "RiseRiseRise"))
2458 c->x86_vendor = X86_VENDOR_RISE;
2459 else if (!strcmp(v, "GenuineTMx86") ||
2460 !strcmp(v, "TransmetaCPU"))
2461 c->x86_vendor = X86_VENDOR_TRANSMETA;
2462 else if (!strcmp(v, "SiS SiS SiS "))
2463 c->x86_vendor = X86_VENDOR_SIS;
2464 else
2465 c->x86_vendor = X86_VENDOR_UNKNOWN;
2466}
2467
2468struct cpu_model_info {
2469 int vendor;
2470 int family;
2471 char *model_names[16];
2472};
2473
2474
2475
2476
2477static struct cpu_model_info cpu_models[] __initdata = {
2478 { X86_VENDOR_INTEL, 4,
2479 { "486 DX-25/33", "486 DX-50", "486 SX", "486 DX/2", "486 SL",
2480 "486 SX/2", NULL, "486 DX/2-WB", "486 DX/4", "486 DX/4-WB", NULL,
2481 NULL, NULL, NULL, NULL, NULL }},
2482 { X86_VENDOR_INTEL, 5,
2483 { "Pentium 60/66 A-step", "Pentium 60/66", "Pentium 75 - 200",
2484 "OverDrive PODP5V83", "Pentium MMX", NULL, NULL,
2485 "Mobile Pentium 75 - 200", "Mobile Pentium MMX", NULL, NULL, NULL,
2486 NULL, NULL, NULL, NULL }},
2487 { X86_VENDOR_INTEL, 6,
2488 { "Pentium Pro A-step", "Pentium Pro", NULL, "Pentium II (Klamath)",
2489 NULL, "Pentium II (Deschutes)", "Mobile Pentium II",
2490 "Pentium III (Katmai)", "Pentium III (Coppermine)", NULL,
2491 "Pentium III (Cascades)", NULL, NULL, NULL, NULL }},
2492 { X86_VENDOR_AMD, 4,
2493 { NULL, NULL, NULL, "486 DX/2", NULL, NULL, NULL, "486 DX/2-WB",
2494 "486 DX/4", "486 DX/4-WB", NULL, NULL, NULL, NULL, "Am5x86-WT",
2495 "Am5x86-WB" }},
2496 { X86_VENDOR_AMD, 5,
2497 { "K5/SSA5", "K5",
2498 "K5", "K5", NULL, NULL,
2499 "K6", "K6", "K6-2",
2500 "K6-3", NULL, NULL, NULL, NULL, NULL, NULL }},
2501 { X86_VENDOR_AMD, 6,
2502 { "Athlon", "Athlon",
2503 "Athlon", NULL, "Athlon", NULL,
2504 NULL, NULL, NULL,
2505 NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2506 { X86_VENDOR_UMC, 4,
2507 { NULL, "U5D", "U5S", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2508 NULL, NULL, NULL, NULL, NULL, NULL }},
2509 { X86_VENDOR_NEXGEN, 5,
2510 { "Nx586", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2511 NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2512 { X86_VENDOR_RISE, 5,
2513 { "iDragon", NULL, "iDragon", NULL, NULL, NULL, NULL,
2514 NULL, "iDragon II", "iDragon II", NULL, NULL, NULL, NULL, NULL, NULL }},
2515 { X86_VENDOR_SIS, 5,
2516 { NULL, NULL, NULL, NULL, "SiS55x", NULL, NULL,
2517 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2518};
2519
2520
2521static char __init *table_lookup_model(struct cpuinfo_x86 *c)
2522{
2523 struct cpu_model_info *info = cpu_models;
2524 int i;
2525
2526 if ( c->x86_model >= 16 )
2527 return NULL;
2528
2529 for ( i = 0 ; i < sizeof(cpu_models)/sizeof(struct cpu_model_info) ; i++ ) {
2530 if ( info->vendor == c->x86_vendor &&
2531 info->family == c->x86 ) {
2532 return info->model_names[c->x86_model];
2533 }
2534 info++;
2535 }
2536 return NULL;
2537}
2538
2539
2540
2541
2542
2543
2544static int __init deep_magic_nexgen_probe(void)
2545{
2546 int ret;
2547
2548 __asm__ __volatile__ (
2549 " movw $0x5555, %%ax\n"
2550 " xorw %%dx,%%dx\n"
2551 " movw $2, %%cx\n"
2552 " divw %%cx\n"
2553 " movl $0, %%eax\n"
2554 " jnz 1f\n"
2555 " movl $1, %%eax\n"
2556 "1:\n"
2557 : "=a" (ret) : : "cx", "dx" );
2558 return ret;
2559}
2560
2561static void __init squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
2562{
2563 if( test_bit(X86_FEATURE_PN, &c->x86_capability) &&
2564 disable_x86_serial_nr ) {
2565
2566 unsigned long lo,hi;
2567 rdmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
2568 lo |= 0x200000;
2569 wrmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
2570 printk(KERN_NOTICE "CPU serial number disabled.\n");
2571 clear_bit(X86_FEATURE_PN, &c->x86_capability);
2572
2573
2574 c->cpuid_level = cpuid_eax(0);
2575 }
2576}
2577
2578
2579static int __init x86_serial_nr_setup(char *s)
2580{
2581 disable_x86_serial_nr = 0;
2582 return 1;
2583}
2584__setup("serialnumber", x86_serial_nr_setup);
2585
2586static int __init x86_fxsr_setup(char * s)
2587{
2588 set_bit(X86_FEATURE_XMM, disabled_x86_caps);
2589 set_bit(X86_FEATURE_FXSR, disabled_x86_caps);
2590 return 1;
2591}
2592__setup("nofxsr", x86_fxsr_setup);
2593
2594
2595
2596static inline int flag_is_changeable_p(u32 flag)
2597{
2598 u32 f1, f2;
2599
2600 asm("pushfl\n\t"
2601 "pushfl\n\t"
2602 "popl %0\n\t"
2603 "movl %0,%1\n\t"
2604 "xorl %2,%0\n\t"
2605 "pushl %0\n\t"
2606 "popfl\n\t"
2607 "pushfl\n\t"
2608 "popl %0\n\t"
2609 "popfl\n\t"
2610 : "=&r" (f1), "=&r" (f2)
2611 : "ir" (flag));
2612
2613 return ((f1^f2) & flag) != 0;
2614}
2615
2616
2617
2618static int __init have_cpuid_p(void)
2619{
2620 return flag_is_changeable_p(X86_EFLAGS_ID);
2621}
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633static inline int test_cyrix_52div(void)
2634{
2635 unsigned int test;
2636
2637 __asm__ __volatile__(
2638 "sahf\n\t"
2639 "div %b2\n\t"
2640 "lahf"
2641 : "=a" (test)
2642 : "0" (5), "q" (2)
2643 : "cc");
2644
2645
2646 return (unsigned char) (test >> 8) == 0x02;
2647}
2648
2649
2650
2651
2652static int __init id_and_try_enable_cpuid(struct cpuinfo_x86 *c)
2653{
2654
2655
2656 if ( flag_is_changeable_p(X86_EFLAGS_AC) )
2657 c->x86 = 4;
2658 else
2659 c->x86 = 3;
2660
2661
2662 if ( c->x86 == 4 && test_cyrix_52div() ) {
2663 unsigned char dir0, dir1;
2664
2665 strcpy(c->x86_vendor_id, "CyrixInstead");
2666 c->x86_vendor = X86_VENDOR_CYRIX;
2667
2668
2669
2670
2671
2672 do_cyrix_devid(&dir0, &dir1);
2673
2674 dir0>>=4;
2675
2676
2677
2678 if (dir0 == 5 || dir0 == 3)
2679 {
2680 unsigned char ccr3, ccr4;
2681 unsigned long flags;
2682 printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
2683 local_irq_save(flags);
2684 ccr3 = getCx86(CX86_CCR3);
2685 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
2686 ccr4 = getCx86(CX86_CCR4);
2687 setCx86(CX86_CCR4, ccr4 | 0x80);
2688 setCx86(CX86_CCR3, ccr3);
2689 local_irq_restore(flags);
2690 }
2691 } else
2692
2693
2694 if ( deep_magic_nexgen_probe() ) {
2695 strcpy(c->x86_vendor_id, "NexGenDriven");
2696 }
2697
2698 return have_cpuid_p();
2699}
2700
2701
2702
2703
2704void __init identify_cpu(struct cpuinfo_x86 *c)
2705{
2706 int junk, i;
2707 u32 xlvl, tfms;
2708
2709 c->loops_per_jiffy = loops_per_jiffy;
2710 c->x86_cache_size = -1;
2711 c->x86_vendor = X86_VENDOR_UNKNOWN;
2712 c->cpuid_level = -1;
2713 c->x86_model = c->x86_mask = 0;
2714 c->x86_vendor_id[0] = '\0';
2715 c->x86_model_id[0] = '\0';
2716 memset(&c->x86_capability, 0, sizeof c->x86_capability);
2717
2718 if ( !have_cpuid_p() && !id_and_try_enable_cpuid(c) ) {
2719
2720
2721
2722
2723 } else {
2724
2725
2726
2727 cpuid(0x00000000, &c->cpuid_level,
2728 (int *)&c->x86_vendor_id[0],
2729 (int *)&c->x86_vendor_id[8],
2730 (int *)&c->x86_vendor_id[4]);
2731
2732 get_cpu_vendor(c);
2733
2734
2735
2736
2737 if ( c->cpuid_level >= 0x00000001 ) {
2738 cpuid(0x00000001, &tfms, &junk, &junk,
2739 &c->x86_capability[0]);
2740 c->x86 = (tfms >> 8) & 15;
2741 c->x86_model = (tfms >> 4) & 15;
2742 c->x86_mask = tfms & 15;
2743 } else {
2744
2745 c->x86 = 4;
2746 }
2747
2748
2749 xlvl = cpuid_eax(0x80000000);
2750 if ( (xlvl & 0xffff0000) == 0x80000000 ) {
2751 if ( xlvl >= 0x80000001 )
2752 c->x86_capability[1] = cpuid_edx(0x80000001);
2753 if ( xlvl >= 0x80000004 )
2754 get_model_name(c);
2755 }
2756
2757
2758 xlvl = cpuid_eax(0x80860000);
2759 if ( (xlvl & 0xffff0000) == 0x80860000 ) {
2760 if ( xlvl >= 0x80860001 )
2761 c->x86_capability[2] = cpuid_edx(0x80860001);
2762 }
2763 }
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775 switch ( c->x86_vendor ) {
2776 case X86_VENDOR_UNKNOWN:
2777 default:
2778
2779
2780 if (c->cpuid_level == -1)
2781 {
2782
2783 if (c->x86 == 4)
2784 strcpy(c->x86_model_id, "486");
2785 else if (c->x86 == 3)
2786 strcpy(c->x86_model_id, "386");
2787 }
2788 break;
2789
2790 case X86_VENDOR_CYRIX:
2791 init_cyrix(c);
2792 break;
2793
2794 case X86_VENDOR_NSC:
2795 init_cyrix(c);
2796 break;
2797
2798 case X86_VENDOR_AMD:
2799 init_amd(c);
2800 break;
2801
2802 case X86_VENDOR_CENTAUR:
2803 init_centaur(c);
2804 break;
2805
2806 case X86_VENDOR_INTEL:
2807 init_intel(c);
2808 break;
2809
2810 case X86_VENDOR_NEXGEN:
2811 c->x86_cache_size = 256;
2812 break;
2813
2814 case X86_VENDOR_TRANSMETA:
2815 init_transmeta(c);
2816 break;
2817
2818 case X86_VENDOR_RISE:
2819 init_rise(c);
2820 break;
2821 }
2822
2823
2824
2825
2826
2827
2828
2829#ifndef CONFIG_X86_TSC
2830 if ( tsc_disable )
2831 clear_bit(X86_FEATURE_TSC, &c->x86_capability);
2832#endif
2833
2834
2835 for (i = 0; i < NCAPINTS; i++) {
2836 c->x86_capability[i] &= ~disabled_x86_caps[i];
2837 }
2838
2839
2840 squash_the_stupid_serial_number(c);
2841
2842
2843 mcheck_init(c);
2844
2845
2846 if ( !c->x86_model_id[0] ) {
2847 char *p;
2848 p = table_lookup_model(c);
2849 if ( p )
2850 strcpy(c->x86_model_id, p);
2851 else
2852
2853 sprintf(c->x86_model_id, "%02x/%02x",
2854 c->x86_vendor, c->x86_model);
2855 }
2856
2857
2858
2859 printk(KERN_DEBUG "CPU: After generic, caps: %08x %08x %08x %08x\n",
2860 c->x86_capability[0],
2861 c->x86_capability[1],
2862 c->x86_capability[2],
2863 c->x86_capability[3]);
2864
2865
2866
2867
2868
2869
2870
2871 if ( c != &boot_cpu_data ) {
2872
2873 for ( i = 0 ; i < NCAPINTS ; i++ )
2874 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
2875 }
2876
2877 printk(KERN_DEBUG "CPU: Common caps: %08x %08x %08x %08x\n",
2878 boot_cpu_data.x86_capability[0],
2879 boot_cpu_data.x86_capability[1],
2880 boot_cpu_data.x86_capability[2],
2881 boot_cpu_data.x86_capability[3]);
2882}
2883
2884
2885
2886
2887void __init dodgy_tsc(void)
2888{
2889 get_cpu_vendor(&boot_cpu_data);
2890
2891 if ( boot_cpu_data.x86_vendor == X86_VENDOR_CYRIX ||
2892 boot_cpu_data.x86_vendor == X86_VENDOR_NSC )
2893 init_cyrix(&boot_cpu_data);
2894}
2895
2896
2897
2898static char *cpu_vendor_names[] __initdata = {
2899 "Intel", "Cyrix", "AMD", "UMC", "NexGen",
2900 "Centaur", "Rise", "Transmeta", "NSC"
2901};
2902
2903
2904void __init print_cpu_info(struct cpuinfo_x86 *c)
2905{
2906 char *vendor = NULL;
2907
2908 if (c->x86_vendor < sizeof(cpu_vendor_names)/sizeof(char *))
2909 vendor = cpu_vendor_names[c->x86_vendor];
2910 else if (c->cpuid_level >= 0)
2911 vendor = c->x86_vendor_id;
2912
2913 if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor)))
2914 printk("%s ", vendor);
2915
2916 if (!c->x86_model_id[0])
2917 printk("%d86", c->x86);
2918 else
2919 printk("%s", c->x86_model_id);
2920
2921 if (c->x86_mask || c->cpuid_level >= 0)
2922 printk(" stepping %02x\n", c->x86_mask);
2923 else
2924 printk("\n");
2925}
2926
2927
2928
2929
2930static int show_cpuinfo(struct seq_file *m, void *v)
2931{
2932
2933
2934
2935
2936
2937
2938
2939
2940 static char *x86_cap_flags[] = {
2941
2942 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
2943 "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
2944 "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
2945 "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
2946
2947
2948 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2949 NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
2950 NULL, NULL, NULL, NULL, NULL, NULL, "mmxext", NULL,
2951 NULL, NULL, NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
2952
2953
2954 "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
2955 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2956 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2957 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2958
2959
2960 "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr", NULL, NULL, NULL, NULL,
2961 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2962 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2963 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2964 };
2965 struct cpuinfo_x86 *c = v;
2966 int i, n = c - cpu_data;
2967 int fpu_exception;
2968
2969#ifdef CONFIG_SMP
2970 if (!(cpu_online_map & (1<<n)))
2971 return 0;
2972#endif
2973 seq_printf(m, "processor\t: %d\n"
2974 "vendor_id\t: %s\n"
2975 "cpu family\t: %d\n"
2976 "model\t\t: %d\n"
2977 "model name\t: %s\n",
2978 n,
2979 c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
2980 c->x86,
2981 c->x86_model,
2982 c->x86_model_id[0] ? c->x86_model_id : "unknown");
2983
2984 if (c->x86_mask || c->cpuid_level >= 0)
2985 seq_printf(m, "stepping\t: %d\n", c->x86_mask);
2986 else
2987 seq_printf(m, "stepping\t: unknown\n");
2988
2989 if ( test_bit(X86_FEATURE_TSC, &c->x86_capability) ) {
2990 seq_printf(m, "cpu MHz\t\t: %lu.%03lu\n",
2991 cpu_khz / 1000, (cpu_khz % 1000));
2992 }
2993
2994
2995 if (c->x86_cache_size >= 0)
2996 seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
2997
2998
2999 fpu_exception = c->hard_math && (ignore_irq13 || cpu_has_fpu);
3000 seq_printf(m, "fdiv_bug\t: %s\n"
3001 "hlt_bug\t\t: %s\n"
3002 "f00f_bug\t: %s\n"
3003 "coma_bug\t: %s\n"
3004 "fpu\t\t: %s\n"
3005 "fpu_exception\t: %s\n"
3006 "cpuid level\t: %d\n"
3007 "wp\t\t: %s\n"
3008 "flags\t\t:",
3009 c->fdiv_bug ? "yes" : "no",
3010 c->hlt_works_ok ? "no" : "yes",
3011 c->f00f_bug ? "yes" : "no",
3012 c->coma_bug ? "yes" : "no",
3013 c->hard_math ? "yes" : "no",
3014 fpu_exception ? "yes" : "no",
3015 c->cpuid_level,
3016 c->wp_works_ok ? "yes" : "no");
3017
3018 for ( i = 0 ; i < 32*NCAPINTS ; i++ )
3019 if ( test_bit(i, &c->x86_capability) &&
3020 x86_cap_flags[i] != NULL )
3021 seq_printf(m, " %s", x86_cap_flags[i]);
3022
3023 seq_printf(m, "\nbogomips\t: %lu.%02lu\n\n",
3024 c->loops_per_jiffy/(500000/HZ),
3025 (c->loops_per_jiffy/(5000/HZ)) % 100);
3026 return 0;
3027}
3028
3029static void *c_start(struct seq_file *m, loff_t *pos)
3030{
3031 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
3032}
3033static void *c_next(struct seq_file *m, void *v, loff_t *pos)
3034{
3035 ++*pos;
3036 return c_start(m, pos);
3037}
3038static void c_stop(struct seq_file *m, void *v)
3039{
3040}
3041struct seq_operations cpuinfo_op = {
3042 start: c_start,
3043 next: c_next,
3044 stop: c_stop,
3045 show: show_cpuinfo,
3046};
3047
3048unsigned long cpu_initialized __initdata = 0;
3049
3050
3051
3052
3053
3054
3055
3056void __init cpu_init (void)
3057{
3058 int nr = smp_processor_id();
3059 struct tss_struct * t = &init_tss[nr];
3060
3061 if (test_and_set_bit(nr, &cpu_initialized)) {
3062 printk(KERN_WARNING "CPU#%d already initialized!\n", nr);
3063 for (;;) __sti();
3064 }
3065 printk(KERN_INFO "Initializing CPU#%d\n", nr);
3066
3067 if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
3068 clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
3069#ifndef CONFIG_X86_TSC
3070 if (tsc_disable && cpu_has_tsc) {
3071 printk(KERN_NOTICE "Disabling TSC...\n");
3072
3073 clear_bit(X86_FEATURE_TSC, boot_cpu_data.x86_capability);
3074 set_in_cr4(X86_CR4_TSD);
3075 }
3076#endif
3077
3078 __asm__ __volatile__("lgdt %0": "=m" (gdt_descr));
3079 __asm__ __volatile__("lidt %0": "=m" (idt_descr));
3080
3081
3082
3083
3084 __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
3085
3086
3087
3088
3089 atomic_inc(&init_mm.mm_count);
3090 current->active_mm = &init_mm;
3091 if(current->mm)
3092 BUG();
3093 enter_lazy_tlb(&init_mm, current, nr);
3094
3095 t->esp0 = current->thread.esp0;
3096 set_tss_desc(nr,t);
3097 gdt_table[__TSS(nr)].b &= 0xfffffdff;
3098 load_TR(nr);
3099 load_LDT(&init_mm);
3100
3101
3102
3103
3104
3105#define CD(register) __asm__("movl %0,%%db" #register ::"r"(0) );
3106
3107 CD(0); CD(1); CD(2); CD(3); ; CD(6); CD(7);
3108
3109#undef CD
3110
3111
3112
3113
3114 current->flags &= ~PF_USEDFPU;
3115 current->used_math = 0;
3116 stts();
3117}
3118
3119
3120
3121
3122
3123
3124
3125int __init ppro_with_ram_bug(void)
3126{
3127 char vendor_id[16];
3128 int ident;
3129
3130
3131 if(!have_cpuid_p())
3132 return 0;
3133 if(cpuid_eax(0)<1)
3134 return 0;
3135
3136
3137 cpuid(0, &ident,
3138 (int *)&vendor_id[0],
3139 (int *)&vendor_id[8],
3140 (int *)&vendor_id[4]);
3141
3142 if(memcmp(vendor_id, "IntelInside", 12))
3143 return 0;
3144
3145 ident = cpuid_eax(1);
3146
3147
3148
3149 if(((ident>>8)&15)!=6)
3150 return 0;
3151
3152
3153
3154 if(((ident>>4)&15)!=1)
3155 return 0;
3156
3157 if((ident&15) < 8)
3158 {
3159 printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
3160 return 1;
3161 }
3162 printk(KERN_INFO "Your Pentium Pro seems ok.\n");
3163 return 0;
3164}
3165
3166
3167
3168
3169
3170
3171
3172
3173