xref: /haiku/src/add-ons/kernel/cpu/x86/via.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*
2  * Copyright 2005, 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 <OS.h>
14 
15 
16 static uint32
17 via_count_mtrrs(void)
18 {
19 	cpuid_info cpuInfo;
20 	if (!x86_check_feature(IA32_FEATURE_MTRR, FEATURE_COMMON))
21 		return 0;
22 
23 	// IA32_MSR_MTRR_CAPABILITIES doesn't exist on VIA CPUs
24 	return 8;
25 }
26 
27 
28 static void
29 via_init_mtrrs(void)
30 {
31 	generic_init_mtrrs(via_count_mtrrs());
32 }
33 
34 
35 static status_t
36 via_init(void)
37 {
38 	system_info info;
39 	if (get_system_info(&info) != B_OK)
40 		return B_ERROR;
41 
42 	if ((info.cpu_type & B_CPU_x86_VENDOR_MASK) != B_CPU_VIA_IDT_x86)
43 		return B_ERROR;
44 
45 	// current VIA CPUs have always 36 bit (or less?)
46 	gPhysicalMask = ((1ULL << 36) - 1) & ~(B_PAGE_SIZE - 1);
47 
48 	generic_dump_mtrrs(generic_count_mtrrs());
49 	return B_OK;
50 }
51 
52 
53 static status_t
54 via_stdops(int32 op, ...)
55 {
56 	switch (op) {
57 		case B_MODULE_INIT:
58 			return via_init();
59 		case B_MODULE_UNINIT:
60 			return B_OK;
61 	}
62 
63 	return B_ERROR;
64 }
65 
66 
67 x86_cpu_module_info gVIAModule = {
68 	{
69 		"cpu/generic_x86/via/v1",
70 		0,
71 		via_stdops,
72 	},
73 
74 	via_count_mtrrs,
75 	via_init_mtrrs,
76 
77 	generic_set_mtrr,
78 	generic_get_mtrr,
79 };
80