Skip to content

Commit 471eb80

Browse files
committed
Initial commit
1 parent 964855a commit 471eb80

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CC=gcc
2+
CFLAGS=-O3 -Wall
3+
LDFLAGS=-lpci
4+
5+
amdmeminfo: amdmeminfo.c
6+
gcc -O3 -o $@ $^ -lpci
7+
8+
clean:
9+
rm -f amdmeminfo *.o

amdmeminfo.c

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* AMDMemInfo, (c) 2014 Teemu Suikki <[email protected]>
3+
*
4+
* Loosely based on "amdmeminfo" by Joerie de Gram.
5+
*
6+
* AMDMemInfo is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* AMDMemInfo is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with AMDMemInfo. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <stdlib.h>
21+
#include <stdio.h>
22+
#include <string.h>
23+
#include <fcntl.h>
24+
#include <unistd.h>
25+
#include <sys/mman.h>
26+
#include <pci/pci.h>
27+
#include <stdbool.h>
28+
29+
/*
30+
* Find all suitable cards, then find their memory space and get memory information.
31+
*/
32+
int main()
33+
{
34+
struct pci_access *pci;
35+
struct pci_dev *dev;
36+
int i, meminfo;
37+
u32 subvendor, subdevice;
38+
off_t base;
39+
int *pcimem;
40+
int fd;
41+
char *devname;
42+
int fail =0, manufacturer, model;
43+
44+
printf("AMDMemInfo by Teemu Suikki <[email protected]>\n");
45+
46+
pci = pci_alloc();
47+
pci_init(pci);
48+
49+
pci_scan_bus(pci);
50+
51+
52+
for(dev = pci->devices; dev; dev = dev->next) {
53+
if(dev->device_class == PCI_CLASS_DISPLAY_VGA &&
54+
dev->vendor_id == 0x1002 &&
55+
( dev->device_id == 0x679a || // hd7950
56+
dev->device_id == 0x6798 || // hd7970 / r9 280x
57+
dev->device_id == 0x67b1 || // r9 290
58+
dev->device_id == 0x67b0 )) // r9 290
59+
60+
{
61+
switch (dev->device_id) {
62+
case 0x679a: devname="Radeon HD7950"; break;
63+
case 0x6798: devname="Radeon HD7970 / R9 280x"; break;
64+
case 0x67b1: devname="Radeon R9 290"; break;
65+
case 0x67b0: devname="Radeon R9 290x"; break;
66+
default: devname="Unknown"; break;
67+
}
68+
69+
subvendor = pci_read_word(dev, PCI_SUBSYSTEM_VENDOR_ID);
70+
subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID);
71+
72+
printf( "-----------------------------------\n"
73+
"Found card: %04x:%04x (AMD %s)\n"
74+
"Subvendor: 0x%x\n"
75+
"Subdevice: 0x%x\n",
76+
dev->vendor_id, dev->device_id, devname, subvendor, subdevice);
77+
78+
for (i=0;i<6;i++) {
79+
if (dev->size[i]==0x40000) {
80+
base=(dev->base_addr[i] & 0xfffffff0);
81+
82+
fd = open ( "/dev/mem", O_RDWR);
83+
pcimem = (int *) mmap(NULL, 0x20000, PROT_READ, MAP_SHARED, fd, base);
84+
if (pcimem == MAP_FAILED) {
85+
fail++;
86+
} else {
87+
meminfo=pcimem[(0x2a00)/4];
88+
manufacturer=(meminfo & 0xf00)>>8;
89+
model=(meminfo & 0xf000)>>12;
90+
printf("Memory type: ");
91+
switch(manufacturer) {
92+
case 1:
93+
printf("Samsung K4G20325FD\n"); break;
94+
case 3:
95+
printf("Elpida EDW2032BBBG\n"); break;
96+
case 6:
97+
switch(model) {
98+
case 2: printf("SK Hynix H5GQ2H24MFR\n"); break;
99+
case 3: printf("SK Hynix H5GQ2H24AFR\n"); break;
100+
default: printf("SK Hynix unknown model %d\n",model);
101+
}
102+
break;
103+
default:
104+
printf("Unknown manufacturer %d\n",manufacturer);
105+
}
106+
107+
munmap(pcimem, 0x20000);
108+
}
109+
close(fd);
110+
}
111+
}
112+
}
113+
}
114+
115+
pci_cleanup(pci);
116+
117+
if (fail) {
118+
printf("Direct PCI access failed. Run AMDMemInfo as root to get memory type information!\n");
119+
}
120+
return 0;
121+
}
122+

0 commit comments

Comments
 (0)