This source file includes following definitions.
- get_cpuid
- get_cpuid_str
1
2 #include <sys/types.h>
3 #include <errno.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <linux/stringify.h>
9 #include "header.h"
10
11 #define mfspr(rn) ({unsigned long rval; \
12 asm volatile("mfspr %0," __stringify(rn) \
13 : "=r" (rval)); rval; })
14
15 #define SPRN_PVR 0x11F
16 #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF)
17 #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF)
18
19 int
20 get_cpuid(char *buffer, size_t sz)
21 {
22 unsigned long pvr;
23 int nb;
24
25 pvr = mfspr(SPRN_PVR);
26
27 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
28
29
30 if (strchr(buffer, '$')) {
31 buffer[nb-1] = '\0';
32 return 0;
33 }
34 return ENOBUFS;
35 }
36
37 char *
38 get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
39 {
40 char *bufp;
41
42 if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0)
43 bufp = NULL;
44
45 return bufp;
46 }