xref: /haiku/src/add-ons/kernel/cpu/x86/amd.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 "amd.h"
11 #include "generic_x86.h"
12 
13 #include <cpu.h>
14 
15 
16 static void
17 amd_init_mtrrs(void)
18 {
19 	generic_init_mtrrs(generic_count_mtrrs());
20 }
21 
22 
23 static status_t
24 amd_init(void)
25 {
26 	if (gCPU[0].arch.vendor != VENDOR_AMD)
27 		return B_ERROR;
28 
29 	// The K6-2 doesn't seem to support write-combining (before model 9),
30 	// so we ignore anything before that one.
31 	if (gCPU[0].arch.family < 5
32 		|| (gCPU[0].arch.family == 5 && gCPU[0].arch.model < 9))
33 		return B_ERROR;
34 
35 	generic_mtrr_compute_physical_mask();
36 	generic_dump_mtrrs(generic_count_mtrrs());
37 
38 	return B_OK;
39 }
40 
41 
42 static void
43 amd_set_mtrrs(uint8 defaultType, const x86_mtrr_info* infos, uint32 count)
44 {
45 	generic_set_mtrrs(defaultType, infos, count, generic_count_mtrrs());
46 }
47 
48 
49 static status_t
50 amd_stdops(int32 op, ...)
51 {
52 	switch (op) {
53 		case B_MODULE_INIT:
54 			return amd_init();
55 		case B_MODULE_UNINIT:
56 			return B_OK;
57 	}
58 
59 	return B_ERROR;
60 }
61 
62 
63 x86_cpu_module_info gAMDModule = {
64 	{
65 		"cpu/generic_x86/amd/v1",
66 		0,
67 		amd_stdops,
68 	},
69 
70 	generic_count_mtrrs,
71 	amd_init_mtrrs,
72 
73 	generic_set_mtrr,
74 	generic_get_mtrr,
75 	amd_set_mtrrs
76 };
77