xref: /openbmc/linux/arch/x86/kernel/cpu/cyrix.c (revision d63ed7fe)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2f7627e25SThomas Gleixner #include <linux/bitops.h>
3f7627e25SThomas Gleixner #include <linux/delay.h>
4*d63ed7feSRandy Dunlap #include <linux/isa-dma.h>
5f7627e25SThomas Gleixner #include <linux/pci.h>
6f7627e25SThomas Gleixner #include <asm/dma.h>
78bdbd962SAlan Cox #include <linux/io.h>
8f7627e25SThomas Gleixner #include <asm/processor-cyrix.h>
97ebad705SDave Jones #include <asm/processor-flags.h>
108bdbd962SAlan Cox #include <linux/timer.h>
11f7627e25SThomas Gleixner #include <asm/pci-direct.h>
12f7627e25SThomas Gleixner #include <asm/tsc.h>
13cd4d09ecSBorislav Petkov #include <asm/cpufeature.h>
14acb04058SPeter Zijlstra #include <linux/sched.h>
15e6017571SIngo Molnar #include <linux/sched/clock.h>
16f7627e25SThomas Gleixner 
17f7627e25SThomas Gleixner #include "cpu.h"
18f7627e25SThomas Gleixner 
19f7627e25SThomas Gleixner /*
20f7627e25SThomas Gleixner  * Read NSC/Cyrix DEVID registers (DIR) to get more detailed info. about the CPU
21f7627e25SThomas Gleixner  */
__do_cyrix_devid(unsigned char * dir0,unsigned char * dir1)22148f9bb8SPaul Gortmaker static void __do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
23f7627e25SThomas Gleixner {
24f7627e25SThomas Gleixner 	unsigned char ccr2, ccr3;
25f7627e25SThomas Gleixner 
26f7627e25SThomas Gleixner 	/* we test for DEVID by checking whether CCR3 is writable */
27f7627e25SThomas Gleixner 	ccr3 = getCx86(CX86_CCR3);
28f7627e25SThomas Gleixner 	setCx86(CX86_CCR3, ccr3 ^ 0x80);
29f7627e25SThomas Gleixner 	getCx86(0xc0);   /* dummy to change bus */
30f7627e25SThomas Gleixner 
31f7627e25SThomas Gleixner 	if (getCx86(CX86_CCR3) == ccr3) {       /* no DEVID regs. */
32f7627e25SThomas Gleixner 		ccr2 = getCx86(CX86_CCR2);
33f7627e25SThomas Gleixner 		setCx86(CX86_CCR2, ccr2 ^ 0x04);
34f7627e25SThomas Gleixner 		getCx86(0xc0);  /* dummy */
35f7627e25SThomas Gleixner 
36f7627e25SThomas Gleixner 		if (getCx86(CX86_CCR2) == ccr2) /* old Cx486SLC/DLC */
37f7627e25SThomas Gleixner 			*dir0 = 0xfd;
38f7627e25SThomas Gleixner 		else {                          /* Cx486S A step */
39f7627e25SThomas Gleixner 			setCx86(CX86_CCR2, ccr2);
40f7627e25SThomas Gleixner 			*dir0 = 0xfe;
41f7627e25SThomas Gleixner 		}
42adf85265SPaolo Ciarrocchi 	} else {
43f7627e25SThomas Gleixner 		setCx86(CX86_CCR3, ccr3);  /* restore CCR3 */
44f7627e25SThomas Gleixner 
45f7627e25SThomas Gleixner 		/* read DIR0 and DIR1 CPU registers */
46f7627e25SThomas Gleixner 		*dir0 = getCx86(CX86_DIR0);
47f7627e25SThomas Gleixner 		*dir1 = getCx86(CX86_DIR1);
48f7627e25SThomas Gleixner 	}
49f7627e25SThomas Gleixner }
50f7627e25SThomas Gleixner 
do_cyrix_devid(unsigned char * dir0,unsigned char * dir1)51148f9bb8SPaul Gortmaker static void do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
525fef55fdSYinghai Lu {
535fef55fdSYinghai Lu 	unsigned long flags;
545fef55fdSYinghai Lu 
555fef55fdSYinghai Lu 	local_irq_save(flags);
565fef55fdSYinghai Lu 	__do_cyrix_devid(dir0, dir1);
575fef55fdSYinghai Lu 	local_irq_restore(flags);
585fef55fdSYinghai Lu }
59f7627e25SThomas Gleixner /*
60f7627e25SThomas Gleixner  * Cx86_dir0_msb is a HACK needed by check_cx686_cpuid/slop in bugs.h in
61f7627e25SThomas Gleixner  * order to identify the Cyrix CPU model after we're out of setup.c
62f7627e25SThomas Gleixner  *
63f7627e25SThomas Gleixner  * Actually since bugs.h doesn't even reference this perhaps someone should
64f7627e25SThomas Gleixner  * fix the documentation ???
65f7627e25SThomas Gleixner  */
66148f9bb8SPaul Gortmaker static unsigned char Cx86_dir0_msb = 0;
67f7627e25SThomas Gleixner 
68148f9bb8SPaul Gortmaker static const char Cx86_model[][9] = {
69f7627e25SThomas Gleixner 	"Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
70f7627e25SThomas Gleixner 	"M II ", "Unknown"
71f7627e25SThomas Gleixner };
72148f9bb8SPaul Gortmaker static const char Cx486_name[][5] = {
73f7627e25SThomas Gleixner 	"SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
74f7627e25SThomas Gleixner 	"SRx2", "DRx2"
75f7627e25SThomas Gleixner };
76148f9bb8SPaul Gortmaker static const char Cx486S_name[][4] = {
77f7627e25SThomas Gleixner 	"S", "S2", "Se", "S2e"
78f7627e25SThomas Gleixner };
79148f9bb8SPaul Gortmaker static const char Cx486D_name[][4] = {
80f7627e25SThomas Gleixner 	"DX", "DX2", "?", "?", "?", "DX4"
81f7627e25SThomas Gleixner };
82148f9bb8SPaul Gortmaker static char Cx86_cb[] = "?.5x Core/Bus Clock";
83148f9bb8SPaul Gortmaker static const char cyrix_model_mult1[] = "12??43";
84148f9bb8SPaul Gortmaker static const char cyrix_model_mult2[] = "12233445";
85f7627e25SThomas Gleixner 
86f7627e25SThomas Gleixner /*
87f7627e25SThomas Gleixner  * Reset the slow-loop (SLOP) bit on the 686(L) which is set by some old
88f7627e25SThomas Gleixner  * BIOSes for compatibility with DOS games.  This makes the udelay loop
89f7627e25SThomas Gleixner  * work correctly, and improves performance.
90f7627e25SThomas Gleixner  *
91f7627e25SThomas Gleixner  * FIXME: our newer udelay uses the tsc. We don't need to frob with SLOP
92f7627e25SThomas Gleixner  */
93f7627e25SThomas Gleixner 
check_cx686_slop(struct cpuinfo_x86 * c)94148f9bb8SPaul Gortmaker static void check_cx686_slop(struct cpuinfo_x86 *c)
95f7627e25SThomas Gleixner {
96f7627e25SThomas Gleixner 	unsigned long flags;
97f7627e25SThomas Gleixner 
98f7627e25SThomas Gleixner 	if (Cx86_dir0_msb == 3) {
99f7627e25SThomas Gleixner 		unsigned char ccr3, ccr5;
100f7627e25SThomas Gleixner 
101f7627e25SThomas Gleixner 		local_irq_save(flags);
102f7627e25SThomas Gleixner 		ccr3 = getCx86(CX86_CCR3);
103f7627e25SThomas Gleixner 		setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
104f7627e25SThomas Gleixner 		ccr5 = getCx86(CX86_CCR5);
105f7627e25SThomas Gleixner 		if (ccr5 & 2)
106f7627e25SThomas Gleixner 			setCx86(CX86_CCR5, ccr5 & 0xfd);  /* reset SLOP */
107f7627e25SThomas Gleixner 		setCx86(CX86_CCR3, ccr3);                 /* disable MAPEN */
108f7627e25SThomas Gleixner 		local_irq_restore(flags);
109f7627e25SThomas Gleixner 
110f7627e25SThomas Gleixner 		if (ccr5 & 2) { /* possible wrong calibration done */
1111b74dde7SChen Yucong 			pr_info("Recalibrating delay loop with SLOP bit reset\n");
112f7627e25SThomas Gleixner 			calibrate_delay();
113f7627e25SThomas Gleixner 			c->loops_per_jiffy = loops_per_jiffy;
114f7627e25SThomas Gleixner 		}
115f7627e25SThomas Gleixner 	}
116f7627e25SThomas Gleixner }
117f7627e25SThomas Gleixner 
118f7627e25SThomas Gleixner 
set_cx86_reorder(void)119148f9bb8SPaul Gortmaker static void set_cx86_reorder(void)
120f7627e25SThomas Gleixner {
121f7627e25SThomas Gleixner 	u8 ccr3;
122f7627e25SThomas Gleixner 
1231b74dde7SChen Yucong 	pr_info("Enable Memory access reorder on Cyrix/NSC processor.\n");
124f7627e25SThomas Gleixner 	ccr3 = getCx86(CX86_CCR3);
12596de0e25SJan Engelhardt 	setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
126f7627e25SThomas Gleixner 
12796de0e25SJan Engelhardt 	/* Load/Store Serialize to mem access disable (=reorder it) */
12818fb053fSMatthew Whitehead 	setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80);
129f7627e25SThomas Gleixner 	/* set load/store serialize from 1GB to 4GB */
130f7627e25SThomas Gleixner 	ccr3 |= 0xe0;
131f7627e25SThomas Gleixner 	setCx86(CX86_CCR3, ccr3);
132f7627e25SThomas Gleixner }
133f7627e25SThomas Gleixner 
set_cx86_memwb(void)134148f9bb8SPaul Gortmaker static void set_cx86_memwb(void)
135f7627e25SThomas Gleixner {
1361b74dde7SChen Yucong 	pr_info("Enable Memory-Write-back mode on Cyrix/NSC processor.\n");
137f7627e25SThomas Gleixner 
138f7627e25SThomas Gleixner 	/* CCR2 bit 2: unlock NW bit */
13918fb053fSMatthew Whitehead 	setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04);
140f7627e25SThomas Gleixner 	/* set 'Not Write-through' */
1417ebad705SDave Jones 	write_cr0(read_cr0() | X86_CR0_NW);
142f7627e25SThomas Gleixner 	/* CCR2 bit 2: lock NW bit and set WT1 */
14318fb053fSMatthew Whitehead 	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14);
144f7627e25SThomas Gleixner }
145f7627e25SThomas Gleixner 
146f7627e25SThomas Gleixner /*
147f7627e25SThomas Gleixner  *	Configure later MediaGX and/or Geode processor.
148f7627e25SThomas Gleixner  */
149f7627e25SThomas Gleixner 
geode_configure(void)150148f9bb8SPaul Gortmaker static void geode_configure(void)
151f7627e25SThomas Gleixner {
152f7627e25SThomas Gleixner 	unsigned long flags;
153f7627e25SThomas Gleixner 	u8 ccr3;
154f7627e25SThomas Gleixner 	local_irq_save(flags);
155f7627e25SThomas Gleixner 
156f7627e25SThomas Gleixner 	/* Suspend on halt power saving and enable #SUSP pin */
15718fb053fSMatthew Whitehead 	setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
158f7627e25SThomas Gleixner 
159f7627e25SThomas Gleixner 	ccr3 = getCx86(CX86_CCR3);
160f7627e25SThomas Gleixner 	setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);	/* enable MAPEN */
161f7627e25SThomas Gleixner 
162f7627e25SThomas Gleixner 
163f7627e25SThomas Gleixner 	/* FPU fast, DTE cache, Mem bypass */
16418fb053fSMatthew Whitehead 	setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x38);
165f7627e25SThomas Gleixner 	setCx86(CX86_CCR3, ccr3);			/* disable MAPEN */
166f7627e25SThomas Gleixner 
167f7627e25SThomas Gleixner 	set_cx86_memwb();
168f7627e25SThomas Gleixner 	set_cx86_reorder();
169f7627e25SThomas Gleixner 
170f7627e25SThomas Gleixner 	local_irq_restore(flags);
171f7627e25SThomas Gleixner }
172f7627e25SThomas Gleixner 
early_init_cyrix(struct cpuinfo_x86 * c)173148f9bb8SPaul Gortmaker static void early_init_cyrix(struct cpuinfo_x86 *c)
1745fef55fdSYinghai Lu {
1755fef55fdSYinghai Lu 	unsigned char dir0, dir0_msn, dir1 = 0;
1765fef55fdSYinghai Lu 
1775fef55fdSYinghai Lu 	__do_cyrix_devid(&dir0, &dir1);
1785fef55fdSYinghai Lu 	dir0_msn = dir0 >> 4; /* identifies CPU "family"   */
1795fef55fdSYinghai Lu 
1805fef55fdSYinghai Lu 	switch (dir0_msn) {
1815fef55fdSYinghai Lu 	case 3: /* 6x86/6x86L */
1825fef55fdSYinghai Lu 		/* Emulate MTRRs using Cyrix's ARRs. */
1835fef55fdSYinghai Lu 		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
1845fef55fdSYinghai Lu 		break;
1855fef55fdSYinghai Lu 	case 5: /* 6x86MX/M II */
1865fef55fdSYinghai Lu 		/* Emulate MTRRs using Cyrix's ARRs. */
1875fef55fdSYinghai Lu 		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
1885fef55fdSYinghai Lu 		break;
1895fef55fdSYinghai Lu 	}
1905fef55fdSYinghai Lu }
191f7627e25SThomas Gleixner 
init_cyrix(struct cpuinfo_x86 * c)192148f9bb8SPaul Gortmaker static void init_cyrix(struct cpuinfo_x86 *c)
193f7627e25SThomas Gleixner {
194f7627e25SThomas Gleixner 	unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
195f7627e25SThomas Gleixner 	char *buf = c->x86_model_id;
196f7627e25SThomas Gleixner 	const char *p = NULL;
197f7627e25SThomas Gleixner 
198adf85265SPaolo Ciarrocchi 	/*
199adf85265SPaolo Ciarrocchi 	 * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
200adf85265SPaolo Ciarrocchi 	 * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
201adf85265SPaolo Ciarrocchi 	 */
2021d007cd5SIngo Molnar 	clear_cpu_cap(c, 0*32+31);
203f7627e25SThomas Gleixner 
204f7627e25SThomas Gleixner 	/* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
2051d007cd5SIngo Molnar 	if (test_cpu_cap(c, 1*32+24)) {
2061d007cd5SIngo Molnar 		clear_cpu_cap(c, 1*32+24);
2071d007cd5SIngo Molnar 		set_cpu_cap(c, X86_FEATURE_CXMMX);
208f7627e25SThomas Gleixner 	}
209f7627e25SThomas Gleixner 
210f7627e25SThomas Gleixner 	do_cyrix_devid(&dir0, &dir1);
211f7627e25SThomas Gleixner 
212f7627e25SThomas Gleixner 	check_cx686_slop(c);
213f7627e25SThomas Gleixner 
214f7627e25SThomas Gleixner 	Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family"   */
215f7627e25SThomas Gleixner 	dir0_lsn = dir0 & 0xf;                /* model or clock multiplier */
216f7627e25SThomas Gleixner 
217f7627e25SThomas Gleixner 	/* common case step number/rev -- exceptions handled below */
218f7627e25SThomas Gleixner 	c->x86_model = (dir1 >> 4) + 1;
219b399151cSJia Zhang 	c->x86_stepping = dir1 & 0xf;
220f7627e25SThomas Gleixner 
221f7627e25SThomas Gleixner 	/* Now cook; the original recipe is by Channing Corn, from Cyrix.
222f7627e25SThomas Gleixner 	 * We do the same thing for each generation: we work out
223f7627e25SThomas Gleixner 	 * the model, multiplier and stepping.  Black magic included,
224f7627e25SThomas Gleixner 	 * to make the silicon step/rev numbers match the printed ones.
225f7627e25SThomas Gleixner 	 */
226f7627e25SThomas Gleixner 
227f7627e25SThomas Gleixner 	switch (dir0_msn) {
228f7627e25SThomas Gleixner 		unsigned char tmp;
229f7627e25SThomas Gleixner 
230f7627e25SThomas Gleixner 	case 0: /* Cx486SLC/DLC/SRx/DRx */
231f7627e25SThomas Gleixner 		p = Cx486_name[dir0_lsn & 7];
232f7627e25SThomas Gleixner 		break;
233f7627e25SThomas Gleixner 
234f7627e25SThomas Gleixner 	case 1: /* Cx486S/DX/DX2/DX4 */
235f7627e25SThomas Gleixner 		p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
236f7627e25SThomas Gleixner 			: Cx486S_name[dir0_lsn & 3];
237f7627e25SThomas Gleixner 		break;
238f7627e25SThomas Gleixner 
239f7627e25SThomas Gleixner 	case 2: /* 5x86 */
240f7627e25SThomas Gleixner 		Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
241f7627e25SThomas Gleixner 		p = Cx86_cb+2;
242f7627e25SThomas Gleixner 		break;
243f7627e25SThomas Gleixner 
244f7627e25SThomas Gleixner 	case 3: /* 6x86/6x86L */
245f7627e25SThomas Gleixner 		Cx86_cb[1] = ' ';
246f7627e25SThomas Gleixner 		Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
247f7627e25SThomas Gleixner 		if (dir1 > 0x21) { /* 686L */
248f7627e25SThomas Gleixner 			Cx86_cb[0] = 'L';
249f7627e25SThomas Gleixner 			p = Cx86_cb;
250f7627e25SThomas Gleixner 			(c->x86_model)++;
251f7627e25SThomas Gleixner 		} else             /* 686 */
252f7627e25SThomas Gleixner 			p = Cx86_cb+1;
253f7627e25SThomas Gleixner 		/* Emulate MTRRs using Cyrix's ARRs. */
2541d007cd5SIngo Molnar 		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
255f7627e25SThomas Gleixner 		/* 6x86's contain this bug */
256c5b41a67SBorislav Petkov 		set_cpu_bug(c, X86_BUG_COMA);
257f7627e25SThomas Gleixner 		break;
258f7627e25SThomas Gleixner 
259f7627e25SThomas Gleixner 	case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
260ae1d557dSChristian Sünkenberg 	case 11: /* GX1 with inverted Device ID */
261f7627e25SThomas Gleixner #ifdef CONFIG_PCI
262f7627e25SThomas Gleixner 	{
263f7627e25SThomas Gleixner 		u32 vendor, device;
264adf85265SPaolo Ciarrocchi 		/*
265adf85265SPaolo Ciarrocchi 		 * It isn't really a PCI quirk directly, but the cure is the
266adf85265SPaolo Ciarrocchi 		 * same. The MediaGX has deep magic SMM stuff that handles the
267adf85265SPaolo Ciarrocchi 		 * SB emulation. It throws away the fifo on disable_dma() which
268adf85265SPaolo Ciarrocchi 		 * is wrong and ruins the audio.
269adf85265SPaolo Ciarrocchi 		 *
270adf85265SPaolo Ciarrocchi 		 *  Bug2: VSA1 has a wrap bug so that using maximum sized DMA
271adf85265SPaolo Ciarrocchi 		 *  causes bad things. According to NatSemi VSA2 has another
272adf85265SPaolo Ciarrocchi 		 *  bug to do with 'hlt'. I've not seen any boards using VSA2
273adf85265SPaolo Ciarrocchi 		 *  and X doesn't seem to support it either so who cares 8).
274adf85265SPaolo Ciarrocchi 		 *  VSA1 we work around however.
275f7627e25SThomas Gleixner 		 */
276f7627e25SThomas Gleixner 
2771b74dde7SChen Yucong 		pr_info("Working around Cyrix MediaGX virtual DMA bugs.\n");
278f7627e25SThomas Gleixner 		isa_dma_bridge_buggy = 2;
279f7627e25SThomas Gleixner 
280f7627e25SThomas Gleixner 		/* We do this before the PCI layer is running. However we
281f7627e25SThomas Gleixner 		   are safe here as we know the bridge must be a Cyrix
282f7627e25SThomas Gleixner 		   companion and must be present */
283f7627e25SThomas Gleixner 		vendor = read_pci_config_16(0, 0, 0x12, PCI_VENDOR_ID);
284f7627e25SThomas Gleixner 		device = read_pci_config_16(0, 0, 0x12, PCI_DEVICE_ID);
285f7627e25SThomas Gleixner 
286f7627e25SThomas Gleixner 		/*
287f7627e25SThomas Gleixner 		 *  The 5510/5520 companion chips have a funky PIT.
288f7627e25SThomas Gleixner 		 */
289f7627e25SThomas Gleixner 		if (vendor == PCI_VENDOR_ID_CYRIX &&
2908bdbd962SAlan Cox 			(device == PCI_DEVICE_ID_CYRIX_5510 ||
2918bdbd962SAlan Cox 					device == PCI_DEVICE_ID_CYRIX_5520))
292f7627e25SThomas Gleixner 			mark_tsc_unstable("cyrix 5510/5520 detected");
293f7627e25SThomas Gleixner 	}
294f7627e25SThomas Gleixner #endif
295d9f6e12fSIngo Molnar 		c->x86_cache_size = 16;	/* Yep 16K integrated cache that's it */
296f7627e25SThomas Gleixner 
297f7627e25SThomas Gleixner 		/* GXm supports extended cpuid levels 'ala' AMD */
298f7627e25SThomas Gleixner 		if (c->cpuid_level == 2) {
299f7627e25SThomas Gleixner 			/* Enable cxMMX extensions (GX1 Datasheet 54) */
30018fb053fSMatthew Whitehead 			setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1);
301f7627e25SThomas Gleixner 
302f7627e25SThomas Gleixner 			/*
303f7627e25SThomas Gleixner 			 * GXm : 0x30 ... 0x5f GXm  datasheet 51
304f7627e25SThomas Gleixner 			 * GXlv: 0x6x          GXlv datasheet 54
305f7627e25SThomas Gleixner 			 *  ?  : 0x7x
306f7627e25SThomas Gleixner 			 * GX1 : 0x8x          GX1  datasheet 56
307f7627e25SThomas Gleixner 			 */
3088bdbd962SAlan Cox 			if ((0x30 <= dir1 && dir1 <= 0x6f) ||
3098bdbd962SAlan Cox 					(0x80 <= dir1 && dir1 <= 0x8f))
310f7627e25SThomas Gleixner 				geode_configure();
311f7627e25SThomas Gleixner 			return;
312adf85265SPaolo Ciarrocchi 		} else { /* MediaGX */
313f7627e25SThomas Gleixner 			Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
314f7627e25SThomas Gleixner 			p = Cx86_cb+2;
315f7627e25SThomas Gleixner 			c->x86_model = (dir1 & 0x20) ? 1 : 2;
316f7627e25SThomas Gleixner 		}
317f7627e25SThomas Gleixner 		break;
318f7627e25SThomas Gleixner 
319f7627e25SThomas Gleixner 	case 5: /* 6x86MX/M II */
320adf85265SPaolo Ciarrocchi 		if (dir1 > 7) {
321f7627e25SThomas Gleixner 			dir0_msn++;  /* M II */
322f7627e25SThomas Gleixner 			/* Enable MMX extensions (App note 108) */
32318fb053fSMatthew Whitehead 			setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
324adf85265SPaolo Ciarrocchi 		} else {
325c5b41a67SBorislav Petkov 			/* A 6x86MX - it has the bug. */
326c5b41a67SBorislav Petkov 			set_cpu_bug(c, X86_BUG_COMA);
327f7627e25SThomas Gleixner 		}
328f7627e25SThomas Gleixner 		tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
329f7627e25SThomas Gleixner 		Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
330f7627e25SThomas Gleixner 		p = Cx86_cb+tmp;
331f7627e25SThomas Gleixner 		if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
332f7627e25SThomas Gleixner 			(c->x86_model)++;
333f7627e25SThomas Gleixner 		/* Emulate MTRRs using Cyrix's ARRs. */
3341d007cd5SIngo Molnar 		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
335f7627e25SThomas Gleixner 		break;
336f7627e25SThomas Gleixner 
337f7627e25SThomas Gleixner 	case 0xf:  /* Cyrix 486 without DEVID registers */
338f7627e25SThomas Gleixner 		switch (dir0_lsn) {
339f7627e25SThomas Gleixner 		case 0xd:  /* either a 486SLC or DLC w/o DEVID */
340f7627e25SThomas Gleixner 			dir0_msn = 0;
341a402a8dfSBorislav Petkov 			p = Cx486_name[!!boot_cpu_has(X86_FEATURE_FPU)];
342f7627e25SThomas Gleixner 			break;
343f7627e25SThomas Gleixner 
344f7627e25SThomas Gleixner 		case 0xe:  /* a 486S A step */
345f7627e25SThomas Gleixner 			dir0_msn = 0;
346f7627e25SThomas Gleixner 			p = Cx486S_name[0];
347f7627e25SThomas Gleixner 			break;
348f7627e25SThomas Gleixner 		}
349f7627e25SThomas Gleixner 		break;
350f7627e25SThomas Gleixner 
351f7627e25SThomas Gleixner 	default:  /* unknown (shouldn't happen, we know everyone ;-) */
352f7627e25SThomas Gleixner 		dir0_msn = 7;
353f7627e25SThomas Gleixner 		break;
354f7627e25SThomas Gleixner 	}
355f7627e25SThomas Gleixner 	strcpy(buf, Cx86_model[dir0_msn & 7]);
356adf85265SPaolo Ciarrocchi 	if (p)
357adf85265SPaolo Ciarrocchi 		strcat(buf, p);
358f7627e25SThomas Gleixner 	return;
359f7627e25SThomas Gleixner }
360f7627e25SThomas Gleixner 
361f7627e25SThomas Gleixner /*
362f7627e25SThomas Gleixner  * Handle National Semiconductor branded processors
363f7627e25SThomas Gleixner  */
init_nsc(struct cpuinfo_x86 * c)364148f9bb8SPaul Gortmaker static void init_nsc(struct cpuinfo_x86 *c)
365f7627e25SThomas Gleixner {
366adf85265SPaolo Ciarrocchi 	/*
367adf85265SPaolo Ciarrocchi 	 * There may be GX1 processors in the wild that are branded
368f7627e25SThomas Gleixner 	 * NSC and not Cyrix.
369f7627e25SThomas Gleixner 	 *
370f7627e25SThomas Gleixner 	 * This function only handles the GX processor, and kicks every
371f7627e25SThomas Gleixner 	 * thing else to the Cyrix init function above - that should
372f7627e25SThomas Gleixner 	 * cover any processors that might have been branded differently
373f7627e25SThomas Gleixner 	 * after NSC acquired Cyrix.
374f7627e25SThomas Gleixner 	 *
375f7627e25SThomas Gleixner 	 * If this breaks your GX1 horribly, please e-mail
376f7627e25SThomas Gleixner 	 * info-linux@ldcmail.amd.com to tell us.
377f7627e25SThomas Gleixner 	 */
378f7627e25SThomas Gleixner 
379f7627e25SThomas Gleixner 	/* Handle the GX (Formally known as the GX2) */
380f7627e25SThomas Gleixner 
381f7627e25SThomas Gleixner 	if (c->x86 == 5 && c->x86_model == 5)
38227c13eceSBorislav Petkov 		cpu_detect_cache_sizes(c);
383f7627e25SThomas Gleixner 	else
384f7627e25SThomas Gleixner 		init_cyrix(c);
385f7627e25SThomas Gleixner }
386f7627e25SThomas Gleixner 
387f7627e25SThomas Gleixner /*
388f7627e25SThomas Gleixner  * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
389f7627e25SThomas Gleixner  * by the fact that they preserve the flags across the division of 5/2.
390f7627e25SThomas Gleixner  * PII and PPro exhibit this behavior too, but they have cpuid available.
391f7627e25SThomas Gleixner  */
392f7627e25SThomas Gleixner 
393f7627e25SThomas Gleixner /*
394f7627e25SThomas Gleixner  * Perform the Cyrix 5/2 test. A Cyrix won't change
395f7627e25SThomas Gleixner  * the flags, while other 486 chips will.
396f7627e25SThomas Gleixner  */
test_cyrix_52div(void)397f7627e25SThomas Gleixner static inline int test_cyrix_52div(void)
398f7627e25SThomas Gleixner {
399f7627e25SThomas Gleixner 	unsigned int test;
400f7627e25SThomas Gleixner 
401f7627e25SThomas Gleixner 	__asm__ __volatile__(
402f7627e25SThomas Gleixner 	     "sahf\n\t"		/* clear flags (%eax = 0x0005) */
403f7627e25SThomas Gleixner 	     "div %b2\n\t"	/* divide 5 by 2 */
404f7627e25SThomas Gleixner 	     "lahf"		/* store flags into %ah */
405f7627e25SThomas Gleixner 	     : "=a" (test)
406f7627e25SThomas Gleixner 	     : "0" (5), "q" (2)
407f7627e25SThomas Gleixner 	     : "cc");
408f7627e25SThomas Gleixner 
409f7627e25SThomas Gleixner 	/* AH is 0x02 on Cyrix after the divide.. */
410f7627e25SThomas Gleixner 	return (unsigned char) (test >> 8) == 0x02;
411f7627e25SThomas Gleixner }
412f7627e25SThomas Gleixner 
cyrix_identify(struct cpuinfo_x86 * c)413148f9bb8SPaul Gortmaker static void cyrix_identify(struct cpuinfo_x86 *c)
414f7627e25SThomas Gleixner {
415f7627e25SThomas Gleixner 	/* Detect Cyrix with disabled CPUID */
416f7627e25SThomas Gleixner 	if (c->x86 == 4 && test_cyrix_52div()) {
417f7627e25SThomas Gleixner 		unsigned char dir0, dir1;
418f7627e25SThomas Gleixner 
419f7627e25SThomas Gleixner 		strcpy(c->x86_vendor_id, "CyrixInstead");
420f7627e25SThomas Gleixner 		c->x86_vendor = X86_VENDOR_CYRIX;
421f7627e25SThomas Gleixner 
422f7627e25SThomas Gleixner 		/* Actually enable cpuid on the older cyrix */
423f7627e25SThomas Gleixner 
424f7627e25SThomas Gleixner 		/* Retrieve CPU revisions */
425f7627e25SThomas Gleixner 
426f7627e25SThomas Gleixner 		do_cyrix_devid(&dir0, &dir1);
427f7627e25SThomas Gleixner 
428f7627e25SThomas Gleixner 		dir0 >>= 4;
429f7627e25SThomas Gleixner 
430f7627e25SThomas Gleixner 		/* Check it is an affected model */
431f7627e25SThomas Gleixner 
432adf85265SPaolo Ciarrocchi 		if (dir0 == 5 || dir0 == 3) {
433f7627e25SThomas Gleixner 			unsigned char ccr3;
434f7627e25SThomas Gleixner 			unsigned long flags;
4351b74dde7SChen Yucong 			pr_info("Enabling CPUID on Cyrix processor.\n");
436f7627e25SThomas Gleixner 			local_irq_save(flags);
437f7627e25SThomas Gleixner 			ccr3 = getCx86(CX86_CCR3);
4388bdbd962SAlan Cox 			/* enable MAPEN  */
4398bdbd962SAlan Cox 			setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);
4408bdbd962SAlan Cox 			/* enable cpuid  */
44103b099bdSMatthew Whitehead 			setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x80);
4428bdbd962SAlan Cox 			/* disable MAPEN */
4438bdbd962SAlan Cox 			setCx86(CX86_CCR3, ccr3);
444f7627e25SThomas Gleixner 			local_irq_restore(flags);
445f7627e25SThomas Gleixner 		}
446f7627e25SThomas Gleixner 	}
447f7627e25SThomas Gleixner }
448f7627e25SThomas Gleixner 
449148f9bb8SPaul Gortmaker static const struct cpu_dev cyrix_cpu_dev = {
450f7627e25SThomas Gleixner 	.c_vendor	= "Cyrix",
451f7627e25SThomas Gleixner 	.c_ident	= { "CyrixInstead" },
4525fef55fdSYinghai Lu 	.c_early_init	= early_init_cyrix,
453f7627e25SThomas Gleixner 	.c_init		= init_cyrix,
454f7627e25SThomas Gleixner 	.c_identify	= cyrix_identify,
45510a434fcSYinghai Lu 	.c_x86_vendor	= X86_VENDOR_CYRIX,
456f7627e25SThomas Gleixner };
457f7627e25SThomas Gleixner 
45810a434fcSYinghai Lu cpu_dev_register(cyrix_cpu_dev);
459f7627e25SThomas Gleixner 
460148f9bb8SPaul Gortmaker static const struct cpu_dev nsc_cpu_dev = {
461f7627e25SThomas Gleixner 	.c_vendor	= "NSC",
462f7627e25SThomas Gleixner 	.c_ident	= { "Geode by NSC" },
463f7627e25SThomas Gleixner 	.c_init		= init_nsc,
46410a434fcSYinghai Lu 	.c_x86_vendor	= X86_VENDOR_NSC,
465f7627e25SThomas Gleixner };
466f7627e25SThomas Gleixner 
46710a434fcSYinghai Lu cpu_dev_register(nsc_cpu_dev);
468