]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
fbe96f29 | 2 | #include <sys/types.h> |
f67001a4 | 3 | #include <errno.h> |
fbe96f29 SE |
4 | #include <unistd.h> |
5 | #include <stdio.h> | |
6 | #include <stdlib.h> | |
7 | #include <string.h> | |
531d2410 | 8 | #include <linux/stringify.h> |
379649cf | 9 | #include "header.h" |
1e1a873d KJ |
10 | #include "metricgroup.h" |
11 | #include <api/fs/fs.h> | |
fbe96f29 SE |
12 | |
13 | #define mfspr(rn) ({unsigned long rval; \ | |
14 | asm volatile("mfspr %0," __stringify(rn) \ | |
15 | : "=r" (rval)); rval; }) | |
16 | ||
17 | #define SPRN_PVR 0x11F /* Processor Version Register */ | |
18 | #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */ | |
19 | #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */ | |
20 | ||
21 | int | |
22 | get_cpuid(char *buffer, size_t sz) | |
23 | { | |
24 | unsigned long pvr; | |
25 | int nb; | |
26 | ||
27 | pvr = mfspr(SPRN_PVR); | |
28 | ||
e7f01d1e | 29 | nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); |
fbe96f29 SE |
30 | |
31 | /* look for end marker to ensure the entire data fit */ | |
32 | if (strchr(buffer, '$')) { | |
33 | buffer[nb-1] = '\0'; | |
34 | return 0; | |
35 | } | |
f67001a4 | 36 | return ENOBUFS; |
fbe96f29 | 37 | } |
ce88f27c SB |
38 | |
39 | char * | |
54e32dc0 | 40 | get_cpuid_str(struct perf_pmu *pmu __maybe_unused) |
ce88f27c SB |
41 | { |
42 | char *bufp; | |
43 | ||
44 | if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0) | |
45 | bufp = NULL; | |
46 | ||
47 | return bufp; | |
48 | } | |
1e1a873d KJ |
49 | |
50 | int arch_get_runtimeparam(void) | |
51 | { | |
52 | int count; | |
53 | return sysfs__read_int("/devices/hv_24x7/interface/sockets", &count) < 0 ? 1 : count; | |
54 | } |