1/*
2 * Copyright 2005-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel D��rfler, axeld@pinc-software.de
7 */
8
9
10#include "via.h"
11#include "generic_x86.h"
12
13#include <cpu.h>
14
15
16static uint32
17via_count_mtrrs(void)
18{
19	if (!x86_check_feature(IA32_FEATURE_MTRR, FEATURE_COMMON))
20		return 0;
21
22	// IA32_MSR_MTRR_CAPABILITIES doesn't exist on VIA CPUs
23	return 8;
24}
25
26
27static void
28via_init_mtrrs(void)
29{
30	generic_init_mtrrs(via_count_mtrrs());
31}
32
33
34static void
35via_set_mtrrs(uint8 defaultType, const x86_mtrr_info* infos, uint32 count)
36{
37	generic_set_mtrrs(defaultType, infos, count, via_count_mtrrs());
38}
39
40
41static status_t
42via_init(void)
43{
44	if (gCPU[0].arch.vendor != VENDOR_CENTAUR)
45		return B_ERROR;
46
47	// current VIA CPUs have always 36 bit (or less?)
48	gPhysicalMask = ((1ULL << 36) - 1) & ~(B_PAGE_SIZE - 1);
49
50	generic_dump_mtrrs(generic_count_mtrrs());
51	return B_OK;
52}
53
54
55static status_t
56via_stdops(int32 op, ...)
57{
58	switch (op) {
59		case B_MODULE_INIT:
60			return via_init();
61		case B_MODULE_UNINIT:
62			return B_OK;
63	}
64
65	return B_ERROR;
66}
67
68
69x86_cpu_module_info gVIAModule = {
70	{
71		"cpu/generic_x86/via/v1",
72		0,
73		via_stdops,
74	},
75
76	via_count_mtrrs,
77	via_init_mtrrs,
78
79	generic_set_mtrr,
80	generic_get_mtrr,
81	via_set_mtrrs
82};
83