master
h 90 lines 2.8 KB
Raw
1 /*
2 * ppc specific proc functions for linux-user
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #ifndef PPC_TARGET_PROC_H
7 #define PPC_TARGET_PROC_H
8
9 #include <time.h>
10
11 #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
12 #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
13 #define PVR_MAJ(pvr) (((pvr) >> 4) & 0xF) /* Major revision field */
14 #define PVR_MIN(pvr) (((pvr) >> 0) & 0xF) /* Minor revision field */
15
16 static int open_cpuinfo(CPUArchState *cpu_env, int fd)
17 {
18 struct timespec res;
19 double freq_mhz;
20 int i, num_cpus;
21 unsigned int maj, min, pvr;
22
23 PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
24 DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
25
26 pvr = pcc->pvr;
27
28 /* Taken from Linux kernel: */
29 /* If we are a Freescale core do a simple check so
30 * we don't have to keep adding cases in the future */
31 if (PVR_VER(pvr) & 0x8000) {
32 switch (PVR_VER(pvr)) {
33 case 0x8000: /* 7441/7450/7451, Voyager */
34 case 0x8001: /* 7445/7455, Apollo 6 */
35 case 0x8002: /* 7447/7457, Apollo 7 */
36 case 0x8003: /* 7447A, Apollo 7 PM */
37 case 0x8004: /* 7448, Apollo 8 */
38 case 0x800c: /* 7410, Nitro */
39 maj = ((pvr >> 8) & 0xF);
40 min = PVR_MIN(pvr);
41 break;
42 default: /* e500/book-e */
43 maj = PVR_MAJ(pvr);
44 min = PVR_MIN(pvr);
45 break;
46 }
47 } else {
48 switch (PVR_VER(pvr)) {
49 case 0x1008: /* 740P/750P ?? */
50 maj = ((pvr >> 8) & 0xFF) - 1;
51 min = pvr & 0xFF;
52 break;
53 case 0x004e: /* POWER9 bits 12-15 give chip type */
54 case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
55 maj = (pvr >> 8) & 0x0F;
56 min = pvr & 0xFF;
57 break;
58 default:
59 maj = (pvr >> 8) & 0xFF;
60 min = pvr & 0xFF;
61 break;
62 }
63 }
64
65 if (clock_getres(CLOCK_REALTIME, &res) == -1) {
66 res.tv_nsec = 1;
67 }
68 freq_mhz = 1000.0 / res.tv_nsec;
69
70 num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
71 for (i = 0; i < num_cpus; i++) {
72 dprintf(fd, "processor\t: %d\n", i);
73 dprintf(fd, "cpu\t\t: %s%s\n",
74 dc->desc,
75 pcc->insns_flags & PPC_ALTIVEC ? ", altivec supported":"");
76 dprintf(fd, "clock\t\t: %.3fMHz\n", freq_mhz);
77 dprintf(fd, "revision\t: %d.%d (pvr %04x %04x)\n\n",
78 maj, min, PVR_VER(pvr), PVR_REV(pvr));
79 }
80
81 dprintf(fd, "timebase\t: 1000000000\n");
82 dprintf(fd, "platform\t: pSeries\n");
83 dprintf(fd, "model\t\t: IBM pSeries (QEMU user v" QEMU_VERSION ")\n");
84 dprintf(fd, "machine\t\t: CHRP IBM pSeries\n");
85
86 return 0;
87 }
88 #define HAVE_ARCH_PROC_CPUINFO
89
90 #endif /* PPC_TARGET_PROC_H */