xref: /haiku/src/add-ons/kernel/cpu/x86/via.cpp (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
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 <OS.h>
14 
15 
16 static uint32
17 via_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 
27 static void
28 via_init_mtrrs(void)
29 {
30 	generic_init_mtrrs(via_count_mtrrs());
31 }
32 
33 
34 static void
35 via_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 
41 static status_t
42 via_init(void)
43 {
44 	system_info info;
45 	if (get_system_info(&info) != B_OK)
46 		return B_ERROR;
47 
48 	if ((info.cpu_type & B_CPU_x86_VENDOR_MASK) != B_CPU_VIA_IDT_x86)
49 		return B_ERROR;
50 
51 	// current VIA CPUs have always 36 bit (or less?)
52 	gPhysicalMask = ((1ULL << 36) - 1) & ~(B_PAGE_SIZE - 1);
53 
54 	generic_dump_mtrrs(generic_count_mtrrs());
55 	return B_OK;
56 }
57 
58 
59 static status_t
60 via_stdops(int32 op, ...)
61 {
62 	switch (op) {
63 		case B_MODULE_INIT:
64 			return via_init();
65 		case B_MODULE_UNINIT:
66 			return B_OK;
67 	}
68 
69 	return B_ERROR;
70 }
71 
72 
73 x86_cpu_module_info gVIAModule = {
74 	{
75 		"cpu/generic_x86/via/v1",
76 		0,
77 		via_stdops,
78 	},
79 
80 	via_count_mtrrs,
81 	via_init_mtrrs,
82 
83 	generic_set_mtrr,
84 	generic_get_mtrr,
85 	via_set_mtrrs
86 };
87