1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright 2017 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Authors: Tom St Denis <tom.stdenis@amd.com>
*
*/
#include "umrapp.h"
int umr_scan_asic(struct umr_asic *asic, char *asicname, char *ipname, char *regname)
{
int r, fd;
int i, j, k;
uint64_t addr, scale;
char buf[256];
/* scan them all in order */
if (!asicname[0] || !strcmp(asicname, "*") || !strcmp(asicname, asic->asicname)) {
for (i = 0; i < asic->no_blocks; i++) {
if (!ipname[0] || !strcmp(ipname, asic->blocks[i]->ipname)) {
if (asic->blocks[i]->grant) {
r = asic->blocks[i]->grant(asic);
if (r)
continue;
}
for (j = 0; j < asic->blocks[i]->no_regs; j++) {
if (!regname[0] || !strcmp(regname, "*") || !strcmp(regname, asic->blocks[i]->regs[j].regname) ||
(options.many && strstr(asic->blocks[i]->regs[j].regname, regname))) {
if (asic->pci.mem == NULL) {
switch(asic->blocks[i]->regs[j].type) {
case REG_MMIO: fd = asic->fd.mmio; scale = 4; break;
case REG_DIDT: fd = asic->fd.didt; scale = 1; break;
case REG_PCIE: fd = asic->fd.pcie; scale = 1; break;
case REG_SMC:
if (options.read_smc) {
fd = asic->fd.smc; scale = 4;
} else {
continue;
}
break;
default: return -1;
}
if (options.use_bank && asic->blocks[i]->regs[j].type == REG_MMIO)
addr =
(1ULL << 62) |
(((uint64_t)options.se_bank) << 24) |
(((uint64_t)options.sh_bank) << 34) |
(((uint64_t)options.instance_bank) << 44);
else
addr = 0;
if (lseek(fd, addr|(asic->blocks[i]->regs[j].addr*scale), SEEK_SET) == -1) {
snprintf(buf, sizeof(buf)-1, "Could not seek reading register %s.%s.%s", asic->asicname, asic->blocks[i]->ipname, asic->blocks[i]->regs[j].regname);
perror(buf);
r = -1;
goto error;
}
if (read(fd, &asic->blocks[i]->regs[j].value, 4) != 4) {
snprintf(buf, sizeof(buf)-1, "Could not read register %s.%s.%s", asic->asicname, asic->blocks[i]->ipname, asic->blocks[i]->regs[j].regname);
perror(buf);
r = -1;
goto error;
}
} else if (asic->blocks[i]->regs[j].type == REG_MMIO) {
asic->blocks[i]->regs[j].value = asic->pci.mem[asic->blocks[i]->regs[j].addr];
}
if (regname[0]) {
if (options.named)
printf("%s%s%s => ", CYAN, asic->blocks[i]->regs[j].regname, RST);
printf("%s0x%08lx%s\n", YELLOW, (unsigned long)asic->blocks[i]->regs[j].value, RST);
if (options.bitfields)
for (k = 0; k < asic->blocks[i]->regs[j].no_bits; k++) {
uint32_t v;
v = (1UL << (asic->blocks[i]->regs[j].bits[k].stop + 1 - asic->blocks[i]->regs[j].bits[k].start)) - 1;
v &= (asic->blocks[i]->regs[j].value >> asic->blocks[i]->regs[j].bits[k].start);
asic->blocks[i]->regs[j].bits[k].bitfield_print(asic, asic->asicname, asic->blocks[i]->ipname, asic->blocks[i]->regs[j].regname, asic->blocks[i]->regs[j].bits[k].regname, asic->blocks[i]->regs[j].bits[k].start, asic->blocks[i]->regs[j].bits[k].stop, v);
}
}
}
}
if (asic->blocks[i]->release) {
r = asic->blocks[i]->release(asic);
if (r)
goto error;
}
}
}
}
r = 0;
error:
return r;
}
|