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