]>
Commit | Line | Data |
---|---|---|
fbe96f29 SE |
1 | #include <sys/types.h> |
2 | #include <unistd.h> | |
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
531d2410 | 6 | #include <linux/stringify.h> |
fbe96f29 SE |
7 | |
8 | #define mfspr(rn) ({unsigned long rval; \ | |
9 | asm volatile("mfspr %0," __stringify(rn) \ | |
10 | : "=r" (rval)); rval; }) | |
11 | ||
12 | #define SPRN_PVR 0x11F /* Processor Version Register */ | |
13 | #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */ | |
14 | #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */ | |
15 | ||
16 | int | |
17 | get_cpuid(char *buffer, size_t sz) | |
18 | { | |
19 | unsigned long pvr; | |
20 | int nb; | |
21 | ||
22 | pvr = mfspr(SPRN_PVR); | |
23 | ||
e7f01d1e | 24 | nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); |
fbe96f29 SE |
25 | |
26 | /* look for end marker to ensure the entire data fit */ | |
27 | if (strchr(buffer, '$')) { | |
28 | buffer[nb-1] = '\0'; | |
29 | return 0; | |
30 | } | |
31 | return -1; | |
32 | } |