1 // SPDX-License-Identifier: GPL-2.0-only
2 // dump_psb. (c) 2004, Dave Jones, Red Hat Inc.
15 #define LEN (0x100000 - 0xc0000)
16 #define OFFSET (0xc0000)
19 #define __packed __attribute((packed))
24 static const int fid_to_mult[32] = {
25 110, 115, 120, 125, 50, 55, 60, 65,
26 70, 75, 80, 85, 90, 95, 100, 105,
27 30, 190, 40, 200, 130, 135, 140, 210,
28 150, 225, 160, 165, 170, 180, -1, -1,
31 static const int vid_to_voltage[32] = {
32 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650,
33 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0,
34 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100,
35 1075, 1050, 1024, 1000, 975, 950, 925, 0,
59 decode_pst(char *p, int npstates)
64 for (i = 0; i < npstates; ++i) {
67 freq = 100 * fid_to_mult[fid] * fsb;
69 printf(" %2d %8dkHz FID %02x (%2d.%01d) VID %02x (%4dmV)\n",
72 fid, fid_to_mult[fid]/10, fid_to_mult[fid]%10,
73 vid, vid_to_voltage[vid]);
80 void decode_psb(char *p, int numpst)
83 struct psb_header *psb;
84 struct pst_header *pst;
86 psb = (struct psb_header*) p;
88 if (psb->version != 0x12)
91 printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
97 sgtc = psb->settlingtime * 100;
102 p = ((char *) psb) + sizeof(struct psb_header);
105 numpst = psb->numpst;
107 printf("Overriding number of pst :%d\n", numpst);
109 for (i = 0; i < numpst; i++) {
110 pst = (struct pst_header*) p;
113 if (relevant!= pst->cpuid)
117 printf(" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
126 decode_pst(p + sizeof(struct pst_header), pst->numpstates);
129 p += sizeof(struct pst_header) + 2*pst->numpstates;
134 static struct option info_opts[] = {
135 {"numpst", no_argument, NULL, 'n'},
138 void print_help(void)
140 printf ("Usage: dump_psb [options]\n");
141 printf ("Options:\n");
142 printf (" -n, --numpst Set number of PST tables to scan\n");
143 printf (" -r, --relevant Only display PSTs relevant to cpuid N\n");
147 main(int argc, char *argv[])
156 ret = getopt_long(argc, argv, "hr:n:", info_opts, NULL);
164 relevant = strtol(optarg, NULL, 16);
167 numpst = strtol(optarg, NULL, 10);
176 fd = open("/dev/mem", O_RDONLY);
178 printf ("Couldn't open /dev/mem. Are you root?\n");
182 mem = mmap(mem, 0x100000 - 0xc0000, PROT_READ, MAP_SHARED, fd, 0xc0000);
185 for (p = mem; p - mem < LEN; p+=16) {
186 if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
187 decode_psb(p, numpst);