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
13enum cpu_vendor sCPUVendor;
14uint32 sPVR;
15
16static uint64 sCPUClockFrequency;
17static uint64 sBusClockFrequency;
18
19struct cpu_model {
20	uint16			version;
21	enum cpu_vendor	vendor;
22};
23
24// mapping of CPU versions to vendors
25struct cpu_model kCPUModels[] = {
26	{ MPC601,		B_CPU_VENDOR_MOTOROLA },
27	{ MPC603,		B_CPU_VENDOR_MOTOROLA },
28	{ MPC604,		B_CPU_VENDOR_MOTOROLA },
29	{ MPC602,		B_CPU_VENDOR_MOTOROLA },
30	{ MPC603e,		B_CPU_VENDOR_MOTOROLA },
31	{ MPC603ev,		B_CPU_VENDOR_MOTOROLA },
32	{ MPC750,		B_CPU_VENDOR_MOTOROLA },
33	{ MPC604ev,		B_CPU_VENDOR_MOTOROLA },
34	{ MPC7400,		B_CPU_VENDOR_MOTOROLA },
35	{ MPC620,		B_CPU_VENDOR_MOTOROLA },
36	{ IBM403,		B_CPU_VENDOR_IBM },
37	{ IBM401A1,		B_CPU_VENDOR_IBM },
38	{ IBM401B2,		B_CPU_VENDOR_IBM },
39	{ IBM401C2,		B_CPU_VENDOR_IBM },
40	{ IBM401D2,		B_CPU_VENDOR_IBM },
41	{ IBM401E2,		B_CPU_VENDOR_IBM },
42	{ IBM401F2,		B_CPU_VENDOR_IBM },
43	{ IBM401G2,		B_CPU_VENDOR_IBM },
44	{ IBMPOWER3,	B_CPU_VENDOR_IBM },
45	{ MPC860,		B_CPU_VENDOR_MOTOROLA },
46	{ MPC8240,		B_CPU_VENDOR_MOTOROLA },
47	{ IBM405GP,		B_CPU_VENDOR_IBM },
48	{ IBM405L,		B_CPU_VENDOR_IBM },
49	{ IBM750FX,		B_CPU_VENDOR_IBM },
50	{ MPC7450,		B_CPU_VENDOR_MOTOROLA },
51	{ MPC7455,		B_CPU_VENDOR_MOTOROLA },
52	{ MPC7457,		B_CPU_VENDOR_MOTOROLA },
53	{ MPC7447A,		B_CPU_VENDOR_MOTOROLA },
54	{ MPC7448,		B_CPU_VENDOR_MOTOROLA },
55	{ MPC7410,		B_CPU_VENDOR_MOTOROLA },
56	{ MPC8245,		B_CPU_VENDOR_MOTOROLA },
57	{ 0,			B_CPU_VENDOR_UNKNOWN }
58};
59
60
61void
62arch_fill_topology_node(cpu_topology_node_info* node, int32 cpu)
63{
64	switch (node->type) {
65		case B_TOPOLOGY_ROOT:
66#if  __powerpc64__
67			node->data.root.platform = B_CPU_PPC_64;
68#else
69			node->data.root.platform = B_CPU_PPC;
70#endif
71			break;
72
73		case B_TOPOLOGY_PACKAGE:
74			node->data.package.vendor = sCPUVendor;
75			node->data.package.cache_line_size = CACHE_LINE_SIZE;
76			break;
77
78		case B_TOPOLOGY_CORE:
79			node->data.core.model = sPVR;
80			node->data.core.default_frequency = sCPUClockFrequency;
81			break;
82
83		default:
84			break;
85	}
86}
87
88
89status_t
90arch_system_info_init(struct kernel_args *args)
91{
92	int i;
93
94	sCPUClockFrequency = args->arch_args.cpu_frequency;
95	sBusClockFrequency = args->arch_args.bus_frequency;
96
97	// The PVR (processor version register) contains processor version and
98	// revision.
99	sPVR = get_pvr();
100	uint16 model = (uint16)(sPVR >> 16);
101	//sCPURevision = (uint16)(pvr & 0xffff);
102
103	// Populate vendor
104	for (i = 0; kCPUModels[i].vendor != B_CPU_VENDOR_UNKNOWN; i++) {
105		if (model == kCPUModels[i].version) {
106			sCPUVendor = kCPUModels[i].vendor;
107			break;
108		}
109	}
110
111	return B_OK;
112}
113
114
115status_t
116arch_get_frequency(uint64 *frequency, int32 cpu)
117{
118	*frequency = sCPUClockFrequency;
119	return B_OK;
120}
121