cyrix.c 12.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/pci.h>
#include <asm/dma.h>
#include <asm/io.h>
7
#include <asm/processor-cyrix.h>
D
Dave Jones 已提交
8
#include <asm/processor-flags.h>
L
Linus Torvalds 已提交
9
#include <asm/timer.h>
A
Alan 已提交
10
#include <asm/pci-direct.h>
A
Alexey Dobriyan 已提交
11
#include <asm/tsc.h>
L
Linus Torvalds 已提交
12 13 14 15 16 17

#include "cpu.h"

/*
 * Read NSC/Cyrix DEVID registers (DIR) to get more detailed info. about the CPU
 */
18
static void __cpuinit __do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
L
Linus Torvalds 已提交
19 20
{
	unsigned char ccr2, ccr3;
21

L
Linus Torvalds 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	/* we test for DEVID by checking whether CCR3 is writable */
	ccr3 = getCx86(CX86_CCR3);
	setCx86(CX86_CCR3, ccr3 ^ 0x80);
	getCx86(0xc0);   /* dummy to change bus */

	if (getCx86(CX86_CCR3) == ccr3) {       /* no DEVID regs. */
		ccr2 = getCx86(CX86_CCR2);
		setCx86(CX86_CCR2, ccr2 ^ 0x04);
		getCx86(0xc0);  /* dummy */

		if (getCx86(CX86_CCR2) == ccr2) /* old Cx486SLC/DLC */
			*dir0 = 0xfd;
		else {                          /* Cx486S A step */
			setCx86(CX86_CCR2, ccr2);
			*dir0 = 0xfe;
		}
38
	} else {
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46
		setCx86(CX86_CCR3, ccr3);  /* restore CCR3 */

		/* read DIR0 and DIR1 CPU registers */
		*dir0 = getCx86(CX86_DIR0);
		*dir1 = getCx86(CX86_DIR1);
	}
}

47 48 49 50 51 52 53 54
static void __cpuinit do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
{
	unsigned long flags;

	local_irq_save(flags);
	__do_cyrix_devid(dir0, dir1);
	local_irq_restore(flags);
}
L
Linus Torvalds 已提交
55 56 57 58 59 60 61
/*
 * Cx86_dir0_msb is a HACK needed by check_cx686_cpuid/slop in bugs.h in
 * order to identify the Cyrix CPU model after we're out of setup.c
 *
 * Actually since bugs.h doesn't even reference this perhaps someone should
 * fix the documentation ???
 */
62
static unsigned char Cx86_dir0_msb __cpuinitdata = 0;
L
Linus Torvalds 已提交
63

64
static char Cx86_model[][9] __cpuinitdata = {
L
Linus Torvalds 已提交
65 66 67
	"Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
	"M II ", "Unknown"
};
68
static char Cx486_name[][5] __cpuinitdata = {
L
Linus Torvalds 已提交
69 70 71
	"SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
	"SRx2", "DRx2"
};
72
static char Cx486S_name[][4] __cpuinitdata = {
L
Linus Torvalds 已提交
73 74
	"S", "S2", "Se", "S2e"
};
75
static char Cx486D_name[][4] __cpuinitdata = {
L
Linus Torvalds 已提交
76 77
	"DX", "DX2", "?", "?", "?", "DX4"
};
78 79 80
static char Cx86_cb[] __cpuinitdata = "?.5x Core/Bus Clock";
static char cyrix_model_mult1[] __cpuinitdata = "12??43";
static char cyrix_model_mult2[] __cpuinitdata = "12233445";
L
Linus Torvalds 已提交
81 82 83 84 85 86 87 88 89

/*
 * Reset the slow-loop (SLOP) bit on the 686(L) which is set by some old
 * BIOSes for compatibility with DOS games.  This makes the udelay loop
 * work correctly, and improves performance.
 *
 * FIXME: our newer udelay uses the tsc. We don't need to frob with SLOP
 */

90
static void __cpuinit check_cx686_slop(struct cpuinfo_x86 *c)
L
Linus Torvalds 已提交
91 92
{
	unsigned long flags;
93

L
Linus Torvalds 已提交
94 95 96 97 98
	if (Cx86_dir0_msb == 3) {
		unsigned char ccr3, ccr5;

		local_irq_save(flags);
		ccr3 = getCx86(CX86_CCR3);
M
Marcin Garski 已提交
99
		setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
L
Linus Torvalds 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
		ccr5 = getCx86(CX86_CCR5);
		if (ccr5 & 2)
			setCx86(CX86_CCR5, ccr5 & 0xfd);  /* reset SLOP */
		setCx86(CX86_CCR3, ccr3);                 /* disable MAPEN */
		local_irq_restore(flags);

		if (ccr5 & 2) { /* possible wrong calibration done */
			printk(KERN_INFO "Recalibrating delay loop with SLOP bit reset\n");
			calibrate_delay();
			c->loops_per_jiffy = loops_per_jiffy;
		}
	}
}


115
static void __cpuinit set_cx86_reorder(void)
L
Linus Torvalds 已提交
116 117 118 119 120
{
	u8 ccr3;

	printk(KERN_INFO "Enable Memory access reorder on Cyrix/NSC processor.\n");
	ccr3 = getCx86(CX86_CCR3);
121
	setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
L
Linus Torvalds 已提交
122

123
	/* Load/Store Serialize to mem access disable (=reorder it) */
I
Ingo Molnar 已提交
124
	setCx86_old(CX86_PCR0, getCx86_old(CX86_PCR0) & ~0x80);
L
Linus Torvalds 已提交
125 126 127 128 129
	/* set load/store serialize from 1GB to 4GB */
	ccr3 |= 0xe0;
	setCx86(CX86_CCR3, ccr3);
}

130
static void __cpuinit set_cx86_memwb(void)
L
Linus Torvalds 已提交
131 132 133 134
{
	printk(KERN_INFO "Enable Memory-Write-back mode on Cyrix/NSC processor.\n");

	/* CCR2 bit 2: unlock NW bit */
I
Ingo Molnar 已提交
135
	setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) & ~0x04);
L
Linus Torvalds 已提交
136
	/* set 'Not Write-through' */
D
Dave Jones 已提交
137
	write_cr0(read_cr0() | X86_CR0_NW);
L
Linus Torvalds 已提交
138
	/* CCR2 bit 2: lock NW bit and set WT1 */
I
Ingo Molnar 已提交
139
	setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x14);
L
Linus Torvalds 已提交
140 141 142 143 144 145
}

/*
 *	Configure later MediaGX and/or Geode processor.
 */

146
static void __cpuinit geode_configure(void)
L
Linus Torvalds 已提交
147 148
{
	unsigned long flags;
149
	u8 ccr3;
L
Linus Torvalds 已提交
150 151 152
	local_irq_save(flags);

	/* Suspend on halt power saving and enable #SUSP pin */
I
Ingo Molnar 已提交
153
	setCx86_old(CX86_CCR2, getCx86_old(CX86_CCR2) | 0x88);
L
Linus Torvalds 已提交
154 155

	ccr3 = getCx86(CX86_CCR3);
156
	setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);	/* enable MAPEN */
157

158 159

	/* FPU fast, DTE cache, Mem bypass */
I
Ingo Molnar 已提交
160
	setCx86_old(CX86_CCR4, getCx86_old(CX86_CCR4) | 0x38);
161
	setCx86(CX86_CCR3, ccr3);			/* disable MAPEN */
162

L
Linus Torvalds 已提交
163
	set_cx86_memwb();
164 165
	set_cx86_reorder();

L
Linus Torvalds 已提交
166 167 168
	local_irq_restore(flags);
}

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
static void __cpuinit early_init_cyrix(struct cpuinfo_x86 *c)
{
	unsigned char dir0, dir0_msn, dir1 = 0;

	__do_cyrix_devid(&dir0, &dir1);
	dir0_msn = dir0 >> 4; /* identifies CPU "family"   */

	switch (dir0_msn) {
	case 3: /* 6x86/6x86L */
		/* Emulate MTRRs using Cyrix's ARRs. */
		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
		break;
	case 5: /* 6x86MX/M II */
		/* Emulate MTRRs using Cyrix's ARRs. */
		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
		break;
	}
}
L
Linus Torvalds 已提交
187

188
static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)
L
Linus Torvalds 已提交
189 190 191 192 193
{
	unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
	char *buf = c->x86_model_id;
	const char *p = NULL;

194 195 196 197
	/*
	 * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
	 * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
	 */
198
	clear_cpu_cap(c, 0*32+31);
L
Linus Torvalds 已提交
199 200

	/* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
201 202 203
	if (test_cpu_cap(c, 1*32+24)) {
		clear_cpu_cap(c, 1*32+24);
		set_cpu_cap(c, X86_FEATURE_CXMMX);
L
Linus Torvalds 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	}

	do_cyrix_devid(&dir0, &dir1);

	check_cx686_slop(c);

	Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family"   */
	dir0_lsn = dir0 & 0xf;                /* model or clock multiplier */

	/* common case step number/rev -- exceptions handled below */
	c->x86_model = (dir1 >> 4) + 1;
	c->x86_mask = dir1 & 0xf;

	/* Now cook; the original recipe is by Channing Corn, from Cyrix.
	 * We do the same thing for each generation: we work out
	 * the model, multiplier and stepping.  Black magic included,
	 * to make the silicon step/rev numbers match the printed ones.
	 */
222

L
Linus Torvalds 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	switch (dir0_msn) {
		unsigned char tmp;

	case 0: /* Cx486SLC/DLC/SRx/DRx */
		p = Cx486_name[dir0_lsn & 7];
		break;

	case 1: /* Cx486S/DX/DX2/DX4 */
		p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
			: Cx486S_name[dir0_lsn & 3];
		break;

	case 2: /* 5x86 */
		Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
		p = Cx86_cb+2;
		break;

	case 3: /* 6x86/6x86L */
		Cx86_cb[1] = ' ';
		Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
		if (dir1 > 0x21) { /* 686L */
			Cx86_cb[0] = 'L';
			p = Cx86_cb;
			(c->x86_model)++;
		} else             /* 686 */
			p = Cx86_cb+1;
		/* Emulate MTRRs using Cyrix's ARRs. */
250
		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
L
Linus Torvalds 已提交
251 252 253 254 255 256
		/* 6x86's contain this bug */
		c->coma_bug = 1;
		break;

	case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
#ifdef CONFIG_PCI
A
Alan 已提交
257 258
	{
		u32 vendor, device;
259 260 261 262 263 264 265 266 267 268 269 270
		/*
		 * It isn't really a PCI quirk directly, but the cure is the
		 * same. The MediaGX has deep magic SMM stuff that handles the
		 * SB emulation. It throws away the fifo on disable_dma() which
		 * is wrong and ruins the audio.
		 *
		 *  Bug2: VSA1 has a wrap bug so that using maximum sized DMA
		 *  causes bad things. According to NatSemi VSA2 has another
		 *  bug to do with 'hlt'. I've not seen any boards using VSA2
		 *  and X doesn't seem to support it either so who cares 8).
		 *  VSA1 we work around however.
		 */
L
Linus Torvalds 已提交
271 272 273

		printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
		isa_dma_bridge_buggy = 2;
274

A
Alan 已提交
275 276 277 278 279
		/* We do this before the PCI layer is running. However we
		   are safe here as we know the bridge must be a Cyrix
		   companion and must be present */
		vendor = read_pci_config_16(0, 0, 0x12, PCI_VENDOR_ID);
		device = read_pci_config_16(0, 0, 0x12, PCI_DEVICE_ID);
280

L
Linus Torvalds 已提交
281 282
		/*
		 *  The 5510/5520 companion chips have a funky PIT.
283
		 */
A
Alan 已提交
284 285
		if (vendor == PCI_VENDOR_ID_CYRIX &&
	 (device == PCI_DEVICE_ID_CYRIX_5510 || device == PCI_DEVICE_ID_CYRIX_5520))
286
			mark_tsc_unstable("cyrix 5510/5520 detected");
A
Alan 已提交
287
	}
288
#endif
289
		c->x86_cache_size = 16;	/* Yep 16K integrated cache thats it */
L
Linus Torvalds 已提交
290 291 292 293

		/* GXm supports extended cpuid levels 'ala' AMD */
		if (c->cpuid_level == 2) {
			/* Enable cxMMX extensions (GX1 Datasheet 54) */
I
Ingo Molnar 已提交
294
			setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7) | 1);
295

T
takada 已提交
296 297 298 299 300 301
			/*
			 * GXm : 0x30 ... 0x5f GXm  datasheet 51
			 * GXlv: 0x6x          GXlv datasheet 54
			 *  ?  : 0x7x
			 * GX1 : 0x8x          GX1  datasheet 56
			 */
302
			if ((0x30 <= dir1 && dir1 <= 0x6f) || (0x80 <= dir1 && dir1 <= 0x8f))
L
Linus Torvalds 已提交
303 304
				geode_configure();
			return;
305
		} else { /* MediaGX */
L
Linus Torvalds 已提交
306 307 308 309 310 311
			Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
			p = Cx86_cb+2;
			c->x86_model = (dir1 & 0x20) ? 1 : 2;
		}
		break;

312 313
	case 5: /* 6x86MX/M II */
		if (dir1 > 7) {
L
Linus Torvalds 已提交
314 315
			dir0_msn++;  /* M II */
			/* Enable MMX extensions (App note 108) */
I
Ingo Molnar 已提交
316
			setCx86_old(CX86_CCR7, getCx86_old(CX86_CCR7)|1);
317
		} else {
L
Linus Torvalds 已提交
318 319 320 321 322
			c->coma_bug = 1;      /* 6x86MX, it has the bug. */
		}
		tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
		Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
		p = Cx86_cb+tmp;
323
		if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
L
Linus Torvalds 已提交
324 325
			(c->x86_model)++;
		/* Emulate MTRRs using Cyrix's ARRs. */
326
		set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
L
Linus Torvalds 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
		break;

	case 0xf:  /* Cyrix 486 without DEVID registers */
		switch (dir0_lsn) {
		case 0xd:  /* either a 486SLC or DLC w/o DEVID */
			dir0_msn = 0;
			p = Cx486_name[(c->hard_math) ? 1 : 0];
			break;

		case 0xe:  /* a 486S A step */
			dir0_msn = 0;
			p = Cx486S_name[0];
			break;
		}
		break;

	default:  /* unknown (shouldn't happen, we know everyone ;-) */
		dir0_msn = 7;
		break;
	}
	strcpy(buf, Cx86_model[dir0_msn & 7]);
348 349
	if (p)
		strcat(buf, p);
L
Linus Torvalds 已提交
350 351 352
	return;
}

353 354 355
/*
 * Handle National Semiconductor branded processors
 */
356
static void __cpuinit init_nsc(struct cpuinfo_x86 *c)
357
{
358 359
	/*
	 * There may be GX1 processors in the wild that are branded
360 361 362 363 364
	 * NSC and not Cyrix.
	 *
	 * This function only handles the GX processor, and kicks every
	 * thing else to the Cyrix init function above - that should
	 * cover any processors that might have been branded differently
A
Andreas Mohr 已提交
365
	 * after NSC acquired Cyrix.
366 367 368 369 370 371 372 373 374 375 376 377 378
	 *
	 * If this breaks your GX1 horribly, please e-mail
	 * info-linux@ldcmail.amd.com to tell us.
	 */

	/* Handle the GX (Formally known as the GX2) */

	if (c->x86 == 5 && c->x86_model == 5)
		display_cacheinfo(c);
	else
		init_cyrix(c);
}

L
Linus Torvalds 已提交
379 380 381 382 383
/*
 * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
 * by the fact that they preserve the flags across the division of 5/2.
 * PII and PPro exhibit this behavior too, but they have cpuid available.
 */
384

L
Linus Torvalds 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
/*
 * Perform the Cyrix 5/2 test. A Cyrix won't change
 * the flags, while other 486 chips will.
 */
static inline int test_cyrix_52div(void)
{
	unsigned int test;

	__asm__ __volatile__(
	     "sahf\n\t"		/* clear flags (%eax = 0x0005) */
	     "div %b2\n\t"	/* divide 5 by 2 */
	     "lahf"		/* store flags into %ah */
	     : "=a" (test)
	     : "0" (5), "q" (2)
	     : "cc");

	/* AH is 0x02 on Cyrix after the divide.. */
	return (unsigned char) (test >> 8) == 0x02;
}

405
static void __cpuinit cyrix_identify(struct cpuinfo_x86 *c)
L
Linus Torvalds 已提交
406 407
{
	/* Detect Cyrix with disabled CPUID */
408
	if (c->x86 == 4 && test_cyrix_52div()) {
L
Linus Torvalds 已提交
409
		unsigned char dir0, dir1;
410

L
Linus Torvalds 已提交
411
		strcpy(c->x86_vendor_id, "CyrixInstead");
412 413 414 415 416 417
		c->x86_vendor = X86_VENDOR_CYRIX;

		/* Actually enable cpuid on the older cyrix */

		/* Retrieve CPU revisions */

L
Linus Torvalds 已提交
418 419
		do_cyrix_devid(&dir0, &dir1);

420 421
		dir0 >>= 4;

L
Linus Torvalds 已提交
422
		/* Check it is an affected model */
423 424

		if (dir0 == 5 || dir0 == 3) {
425
			unsigned char ccr3;
L
Linus Torvalds 已提交
426 427 428 429
			unsigned long flags;
			printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
			local_irq_save(flags);
			ccr3 = getCx86(CX86_CCR3);
430
			setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10);       /* enable MAPEN  */
I
Ingo Molnar 已提交
431
			setCx86_old(CX86_CCR4, getCx86_old(CX86_CCR4) | 0x80);  /* enable cpuid  */
432
			setCx86(CX86_CCR3, ccr3);                       /* disable MAPEN */
L
Linus Torvalds 已提交
433 434 435 436 437
			local_irq_restore(flags);
		}
	}
}

438
static struct cpu_dev cyrix_cpu_dev __cpuinitdata = {
L
Linus Torvalds 已提交
439
	.c_vendor	= "Cyrix",
440
	.c_ident	= { "CyrixInstead" },
441
	.c_early_init	= early_init_cyrix,
L
Linus Torvalds 已提交
442 443
	.c_init		= init_cyrix,
	.c_identify	= cyrix_identify,
Y
Yinghai Lu 已提交
444
	.c_x86_vendor	= X86_VENDOR_CYRIX,
L
Linus Torvalds 已提交
445 446
};

Y
Yinghai Lu 已提交
447
cpu_dev_register(cyrix_cpu_dev);
L
Linus Torvalds 已提交
448

449
static struct cpu_dev nsc_cpu_dev __cpuinitdata = {
L
Linus Torvalds 已提交
450
	.c_vendor	= "NSC",
451
	.c_ident	= { "Geode by NSC" },
452
	.c_init		= init_nsc,
Y
Yinghai Lu 已提交
453
	.c_x86_vendor	= X86_VENDOR_NSC,
L
Linus Torvalds 已提交
454 455
};

Y
Yinghai Lu 已提交
456
cpu_dev_register(nsc_cpu_dev);