xref: /haiku/src/system/kernel/arch/ppc/arch_system_info.cpp (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #include <OS.h>
7 
8 #include <arch_cpu.h>
9 #include <arch/system_info.h>
10 #include <boot/kernel_args.h>
11 
12 
13 static uint64 sCPUClockFrequency;
14 static uint64 sBusClockFrequency;
15 static enum cpu_types sCPUType;
16 static uint16 sCPURevision;
17 
18 struct cpu_model {
19 	uint16			version;
20 	enum cpu_types	beos_type;
21 };
22 
23 // mapping of CPU versions to BeOS enum cpu_types
24 struct cpu_model kCPUModels[] = {
25 	{ MPC601,		B_CPU_PPC_601 },
26 	{ MPC603,		B_CPU_PPC_603 },
27 	{ MPC604,		B_CPU_PPC_604 },
28 	{ MPC602,		B_CPU_PPC_603ev },
29 	{ MPC603e,		B_CPU_PPC_603e },
30 	{ MPC603ev,		B_CPU_PPC_603ev },
31 	{ MPC750,		B_CPU_PPC_750 },
32 	{ MPC604ev,		B_CPU_PPC_604ev },
33 	{ MPC7400,		B_CPU_PPC_7400 },
34 	{ MPC620,		B_CPU_PPC_620 },
35 	{ IBM403,		B_CPU_PPC_IBM_403 },
36 	{ IBM401A1,		B_CPU_PPC_IBM_401A1 },
37 	{ IBM401B2,		B_CPU_PPC_IBM_401B2 },
38 	{ IBM401C2,		B_CPU_PPC_IBM_401C2 },
39 	{ IBM401D2,		B_CPU_PPC_IBM_401D2 },
40 	{ IBM401E2,		B_CPU_PPC_IBM_401E2 },
41 	{ IBM401F2,		B_CPU_PPC_IBM_401F2 },
42 	{ IBM401G2,		B_CPU_PPC_IBM_401G2 },
43 	{ IBMPOWER3,	B_CPU_PPC_IBM_POWER3 },
44 	{ MPC860,		B_CPU_PPC_860 },
45 	{ MPC8240,		B_CPU_PPC_8240 },
46 	{ IBM405GP,		B_CPU_PPC_IBM_405GP },
47 	{ IBM405L,		B_CPU_PPC_IBM_405L },
48 	{ IBM750FX,		B_CPU_PPC_IBM_750FX },
49 	{ MPC7450,		B_CPU_PPC_7450 },
50 	{ MPC7455,		B_CPU_PPC_7455 },
51 	{ MPC7457,		B_CPU_PPC_7457 },
52 	{ MPC7447A,		B_CPU_PPC_7447A },
53 	{ MPC7448,		B_CPU_PPC_7448 },
54 	{ MPC7410,		B_CPU_PPC_7410 },
55 	{ MPC8245,		B_CPU_PPC_8245 },
56 	{ 0,			B_CPU_PPC_UNKNOWN }
57 };
58 
59 
60 status_t
61 arch_get_system_info(system_info *info, size_t size)
62 {
63 	info->cpu_type = sCPUType;
64 	info->cpu_revision = sCPURevision;
65 
66 	info->cpu_clock_speed = sCPUClockFrequency;
67 	info->bus_clock_speed = sBusClockFrequency;
68 
69 	info->platform_type = B_MAC_PLATFORM;
70 
71 	return B_OK;
72 }
73 
74 
75 status_t
76 arch_system_info_init(struct kernel_args *args)
77 {
78 	int i;
79 
80 	sCPUClockFrequency = args->arch_args.cpu_frequency;
81 	sBusClockFrequency = args->arch_args.bus_frequency;
82 
83 	// The PVR (processor version register) contains processor version and
84 	// revision.
85 	uint32 pvr = get_pvr();
86 	uint16 version = (uint16)(pvr >> 16);
87 	sCPURevision = (uint16)(pvr & 0xffff);
88 
89 	// translate the version to a BeOS cpu_types constant
90 	sCPUType = B_CPU_PPC_UNKNOWN;
91 	for (i = 0; kCPUModels[i].beos_type != B_CPU_PPC_UNKNOWN; i++) {
92 		if (version == kCPUModels[i].version) {
93 			sCPUType = kCPUModels[i].beos_type;
94 			break;
95 		}
96 	}
97 
98 	return B_OK;
99 }
100