centaur.c 3.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2
#include <linux/init.h>
#include <linux/mm.h>
3

L
Linus Torvalds 已提交
4 5
#include <asm/mtrr.h>
#include <asm/msr.h>
6

L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16
#include "mtrr.h"

static struct {
	unsigned long high;
	unsigned long low;
} centaur_mcr[8];

static u8 centaur_mcr_reserved;
static u8 centaur_mcr_type;	/* 0 for winchip, 1 for winchip2 */

17 18 19 20 21 22 23
/**
 * centaur_get_free_region - Get a free MTRR.
 *
 * @base: The starting (base) address of the region.
 * @size: The size (in bytes) of the region.
 *
 * Returns: the index of the region on success, else -1 on error.
L
Linus Torvalds 已提交
24 25
 */
static int
J
Jan Beulich 已提交
26
centaur_get_free_region(unsigned long base, unsigned long size, int replace_reg)
L
Linus Torvalds 已提交
27
{
J
Jan Beulich 已提交
28
	unsigned long lbase, lsize;
29 30
	mtrr_type ltype;
	int i, max;
L
Linus Torvalds 已提交
31 32

	max = num_var_ranges;
J
Jan Beulich 已提交
33 34
	if (replace_reg >= 0 && replace_reg < max)
		return replace_reg;
35

L
Linus Torvalds 已提交
36 37 38 39 40 41 42
	for (i = 0; i < max; ++i) {
		if (centaur_mcr_reserved & (1 << i))
			continue;
		mtrr_if->get(i, &lbase, &lsize, &ltype);
		if (lsize == 0)
			return i;
	}
43

L
Linus Torvalds 已提交
44 45 46
	return -ENOSPC;
}

47 48 49 50
/*
 * Report boot time MCR setups
 */
void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
L
Linus Torvalds 已提交
51 52 53 54 55 56 57
{
	centaur_mcr[mcr].low = lo;
	centaur_mcr[mcr].high = hi;
}

static void
centaur_get_mcr(unsigned int reg, unsigned long *base,
J
Jan Beulich 已提交
58
		unsigned long *size, mtrr_type * type)
L
Linus Torvalds 已提交
59 60 61
{
	*base = centaur_mcr[reg].high >> PAGE_SHIFT;
	*size = -(centaur_mcr[reg].low & 0xfffff000) >> PAGE_SHIFT;
62 63
	*type = MTRR_TYPE_WRCOMB;		/* write-combining  */

L
Linus Torvalds 已提交
64 65 66 67 68 69 70 71
	if (centaur_mcr_type == 1 && ((centaur_mcr[reg].low & 31) & 2))
		*type = MTRR_TYPE_UNCACHABLE;
	if (centaur_mcr_type == 1 && (centaur_mcr[reg].low & 31) == 25)
		*type = MTRR_TYPE_WRBACK;
	if (centaur_mcr_type == 0 && (centaur_mcr[reg].low & 31) == 31)
		*type = MTRR_TYPE_WRBACK;
}

72 73 74
static void
centaur_set_mcr(unsigned int reg, unsigned long base,
		unsigned long size, mtrr_type type)
L
Linus Torvalds 已提交
75 76 77 78
{
	unsigned long low, high;

	if (size == 0) {
79
		/* Disable */
L
Linus Torvalds 已提交
80 81 82
		high = low = 0;
	} else {
		high = base << PAGE_SHIFT;
83 84 85 86
		if (centaur_mcr_type == 0) {
			/* Only support write-combining... */
			low = -size << PAGE_SHIFT | 0x1f;
		} else {
L
Linus Torvalds 已提交
87
			if (type == MTRR_TYPE_UNCACHABLE)
88
				low = -size << PAGE_SHIFT | 0x02; /* NC */
L
Linus Torvalds 已提交
89
			else
90
				low = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
L
Linus Torvalds 已提交
91 92 93 94 95 96 97
		}
	}
	centaur_mcr[reg].high = high;
	centaur_mcr[reg].low = low;
	wrmsr(MSR_IDT_MCR0 + reg, low, high);
}

98 99
static int
centaur_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
L
Linus Torvalds 已提交
100 101
{
	/*
102
	 * FIXME: Winchip2 supports uncached
L
Linus Torvalds 已提交
103
	 */
104
	if (type != MTRR_TYPE_WRCOMB &&
L
Linus Torvalds 已提交
105
	    (centaur_mcr_type == 0 || type != MTRR_TYPE_UNCACHABLE)) {
106
		pr_warn("mtrr: only write-combining%s supported\n",
107
			   centaur_mcr_type ? " and uncacheable are" : " is");
L
Linus Torvalds 已提交
108 109 110 111 112
		return -EINVAL;
	}
	return 0;
}

113
static const struct mtrr_ops centaur_mtrr_ops = {
L
Linus Torvalds 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126
	.vendor            = X86_VENDOR_CENTAUR,
	.set               = centaur_set_mcr,
	.get               = centaur_get_mcr,
	.get_free_region   = centaur_get_free_region,
	.validate_add_page = centaur_validate_add_page,
	.have_wrcomb       = positive_have_wrcomb,
};

int __init centaur_init_mtrr(void)
{
	set_mtrr_ops(&centaur_mtrr_ops);
	return 0;
}