14cf3e70fSAxel Dörfler/*
2716a16ceSIngo Weinhold * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3716a16ceSIngo Weinhold * All rights reserved. Distributed under the terms of the MIT License.
44cf3e70fSAxel Dörfler */
54cf3e70fSAxel Dörfler
64cf3e70fSAxel Dörfler#include <OS.h>
74cf3e70fSAxel Dörfler
8716a16ceSIngo Weinhold#include <arch_cpu.h>
94cf3e70fSAxel Dörfler#include <arch/system_info.h>
104cf3e70fSAxel Dörfler#include <boot/kernel_args.h>
114cf3e70fSAxel Dörfler
12716a16ceSIngo Weinhold
1314919567SAlexander von Gluck IVenum cpu_vendor sCPUVendor;
1414919567SAlexander von Gluck IVuint32 sPVR;
1514919567SAlexander von Gluck IV
16716a16ceSIngo Weinholdstatic uint64 sCPUClockFrequency;
17716a16ceSIngo Weinholdstatic uint64 sBusClockFrequency;
18716a16ceSIngo Weinhold
19716a16ceSIngo Weinholdstruct cpu_model {
20716a16ceSIngo Weinhold	uint16			version;
2114919567SAlexander von Gluck IV	enum cpu_vendor	vendor;
22716a16ceSIngo Weinhold};
23716a16ceSIngo Weinhold
2414919567SAlexander von Gluck IV// mapping of CPU versions to vendors
25716a16ceSIngo Weinholdstruct cpu_model kCPUModels[] = {
2614919567SAlexander von Gluck IV	{ MPC601,		B_CPU_VENDOR_MOTOROLA },
2714919567SAlexander von Gluck IV	{ MPC603,		B_CPU_VENDOR_MOTOROLA },
2814919567SAlexander von Gluck IV	{ MPC604,		B_CPU_VENDOR_MOTOROLA },
2914919567SAlexander von Gluck IV	{ MPC602,		B_CPU_VENDOR_MOTOROLA },
3014919567SAlexander von Gluck IV	{ MPC603e,		B_CPU_VENDOR_MOTOROLA },
3114919567SAlexander von Gluck IV	{ MPC603ev,		B_CPU_VENDOR_MOTOROLA },
3214919567SAlexander von Gluck IV	{ MPC750,		B_CPU_VENDOR_MOTOROLA },
3314919567SAlexander von Gluck IV	{ MPC604ev,		B_CPU_VENDOR_MOTOROLA },
3414919567SAlexander von Gluck IV	{ MPC7400,		B_CPU_VENDOR_MOTOROLA },
3514919567SAlexander von Gluck IV	{ MPC620,		B_CPU_VENDOR_MOTOROLA },
3614919567SAlexander von Gluck IV	{ IBM403,		B_CPU_VENDOR_IBM },
3714919567SAlexander von Gluck IV	{ IBM401A1,		B_CPU_VENDOR_IBM },
3814919567SAlexander von Gluck IV	{ IBM401B2,		B_CPU_VENDOR_IBM },
3914919567SAlexander von Gluck IV	{ IBM401C2,		B_CPU_VENDOR_IBM },
4014919567SAlexander von Gluck IV	{ IBM401D2,		B_CPU_VENDOR_IBM },
4114919567SAlexander von Gluck IV	{ IBM401E2,		B_CPU_VENDOR_IBM },
4214919567SAlexander von Gluck IV	{ IBM401F2,		B_CPU_VENDOR_IBM },
4314919567SAlexander von Gluck IV	{ IBM401G2,		B_CPU_VENDOR_IBM },
4414919567SAlexander von Gluck IV	{ IBMPOWER3,	B_CPU_VENDOR_IBM },
4514919567SAlexander von Gluck IV	{ MPC860,		B_CPU_VENDOR_MOTOROLA },
4614919567SAlexander von Gluck IV	{ MPC8240,		B_CPU_VENDOR_MOTOROLA },
4714919567SAlexander von Gluck IV	{ IBM405GP,		B_CPU_VENDOR_IBM },
4814919567SAlexander von Gluck IV	{ IBM405L,		B_CPU_VENDOR_IBM },
4914919567SAlexander von Gluck IV	{ IBM750FX,		B_CPU_VENDOR_IBM },
5014919567SAlexander von Gluck IV	{ MPC7450,		B_CPU_VENDOR_MOTOROLA },
5114919567SAlexander von Gluck IV	{ MPC7455,		B_CPU_VENDOR_MOTOROLA },
5214919567SAlexander von Gluck IV	{ MPC7457,		B_CPU_VENDOR_MOTOROLA },
5314919567SAlexander von Gluck IV	{ MPC7447A,		B_CPU_VENDOR_MOTOROLA },
5414919567SAlexander von Gluck IV	{ MPC7448,		B_CPU_VENDOR_MOTOROLA },
5514919567SAlexander von Gluck IV	{ MPC7410,		B_CPU_VENDOR_MOTOROLA },
5614919567SAlexander von Gluck IV	{ MPC8245,		B_CPU_VENDOR_MOTOROLA },
5714919567SAlexander von Gluck IV	{ 0,			B_CPU_VENDOR_UNKNOWN }
58716a16ceSIngo Weinhold};
594cf3e70fSAxel Dörfler
604cf3e70fSAxel Dörfler
6114919567SAlexander von Gluck IVvoid
6214919567SAlexander von Gluck IVarch_fill_topology_node(cpu_topology_node_info* node, int32 cpu)
634cf3e70fSAxel Dörfler{
6414919567SAlexander von Gluck IV	switch (node->type) {
6514919567SAlexander von Gluck IV		case B_TOPOLOGY_ROOT:
6614919567SAlexander von Gluck IV#if  __powerpc64__
6714919567SAlexander von Gluck IV			node->data.root.platform = B_CPU_PPC_64;
6814919567SAlexander von Gluck IV#else
6914919567SAlexander von Gluck IV			node->data.root.platform = B_CPU_PPC;
7014919567SAlexander von Gluck IV#endif
7114919567SAlexander von Gluck IV			break;
72716a16ceSIngo Weinhold
7314919567SAlexander von Gluck IV		case B_TOPOLOGY_PACKAGE:
7414919567SAlexander von Gluck IV			node->data.package.vendor = sCPUVendor;
7514919567SAlexander von Gluck IV			node->data.package.cache_line_size = CACHE_LINE_SIZE;
7614919567SAlexander von Gluck IV			break;
774cf3e70fSAxel Dörfler
7814919567SAlexander von Gluck IV		case B_TOPOLOGY_CORE:
7914919567SAlexander von Gluck IV			node->data.core.model = sPVR;
8014919567SAlexander von Gluck IV			node->data.core.default_frequency = sCPUClockFrequency;
8114919567SAlexander von Gluck IV			break;
824cf3e70fSAxel Dörfler
8314919567SAlexander von Gluck IV		default:
8414919567SAlexander von Gluck IV			break;
8514919567SAlexander von Gluck IV	}
864cf3e70fSAxel Dörfler}
874cf3e70fSAxel Dörfler
884cf3e70fSAxel Dörfler
894cf3e70fSAxel Dörflerstatus_t
904cf3e70fSAxel Dörflerarch_system_info_init(struct kernel_args *args)
914cf3e70fSAxel Dörfler{
92716a16ceSIngo Weinhold	int i;
93716a16ceSIngo Weinhold
94716a16ceSIngo Weinhold	sCPUClockFrequency = args->arch_args.cpu_frequency;
95716a16ceSIngo Weinhold	sBusClockFrequency = args->arch_args.bus_frequency;
96716a16ceSIngo Weinhold
97716a16ceSIngo Weinhold	// The PVR (processor version register) contains processor version and
98716a16ceSIngo Weinhold	// revision.
9914919567SAlexander von Gluck IV	sPVR = get_pvr();
10014919567SAlexander von Gluck IV	uint16 model = (uint16)(sPVR >> 16);
10114919567SAlexander von Gluck IV	//sCPURevision = (uint16)(pvr & 0xffff);
10214919567SAlexander von Gluck IV
10314919567SAlexander von Gluck IV	// Populate vendor
10414919567SAlexander von Gluck IV	for (i = 0; kCPUModels[i].vendor != B_CPU_VENDOR_UNKNOWN; i++) {
10514919567SAlexander von Gluck IV		if (model == kCPUModels[i].version) {
10614919567SAlexander von Gluck IV			sCPUVendor = kCPUModels[i].vendor;
107716a16ceSIngo Weinhold			break;
108716a16ceSIngo Weinhold		}
109716a16ceSIngo Weinhold	}
11014919567SAlexander von Gluck IV
1114cf3e70fSAxel Dörfler	return B_OK;
1124cf3e70fSAxel Dörfler}
113