-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathSPDAccessor.cpp
149 lines (129 loc) · 3.43 KB
/
SPDAccessor.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*---------------------------------------------------------*\
| SPDAccessor.cpp |
| |
| Access to SPD information on various DIMMs |
| |
| Milan Cermak (krysmanta) 09 Nov 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "DDR4DirectAccessor.h"
#include "DDR5DirectAccessor.h"
#include "LogManager.h"
#include "SPDAccessor.h"
#ifdef __linux__
#include "EE1004Accessor_Linux.h"
#include "SPD5118Accessor_Linux.h"
#endif
using namespace std::chrono_literals;
const char *spd_memory_type_name[] =
{
"Reserved",
"FPM",
"EDO",
"Nibble",
"SDR",
"Multiplex ROM",
"DDR",
"DDR",
"DDR2",
"FB",
"FB Probe",
"DDR3",
"DDR4",
"Reserved",
"DDR4e",
"LPDDR3",
"LPDDR4",
"LPDDR4X",
"DDR5",
"LPDDR5"
};
SPDAccessor::SPDAccessor(i2c_smbus_interface *bus, uint8_t spd_addr)
{
this->bus = bus;
this->address = spd_addr;
}
SPDAccessor::~SPDAccessor()
{
}
SPDAccessor *SPDAccessor::for_memory_type(SPDMemoryType type, i2c_smbus_interface *bus, uint8_t spd_addr)
{
/*-----------------------------------------------------*\
| DDR4 can use DDR4DirectAccessor or EE1004Accessor |
\*-----------------------------------------------------*/
if(type == SPD_DDR4_SDRAM)
{
#ifdef __linux__
if(EE1004Accessor::isAvailable(bus, spd_addr))
{
return(new EE1004Accessor(bus, spd_addr));
}
#endif
return(new DDR4DirectAccessor(bus, spd_addr));
}
/*-----------------------------------------------------*\
| DDR5 can use DDR5DirectAccessor or SPD5118Accessor |
\*-----------------------------------------------------*/
if(type == SPD_DDR5_SDRAM)
{
#ifdef __linux__
if(SPD5118Accessor::isAvailable(bus, spd_addr))
{
return(new SPD5118Accessor(bus, spd_addr));
}
#endif
return(new DDR5DirectAccessor(bus, spd_addr));
}
return(nullptr);
};
/*---------------------------------------------------------*\
| Internal implementation for specific memory type. |
\*---------------------------------------------------------*/
DDR4Accessor::DDR4Accessor(i2c_smbus_interface *bus, uint8_t spd_addr)
: SPDAccessor(bus, spd_addr)
{
}
DDR4Accessor::~DDR4Accessor()
{
}
SPDMemoryType DDR4Accessor::memory_type()
{
return((SPDMemoryType)(this->at(0x02)));
}
uint16_t DDR4Accessor::jedec_id()
{
return((this->at(0x140) << 8) + (this->at(0x141) & 0x7f) - 1);
}
uint8_t DDR4Accessor::manufacturer_data(uint16_t index)
{
if(index > 28)
{
return 0;
}
return this->at(0x161 + index);
}
DDR5Accessor::DDR5Accessor(i2c_smbus_interface *bus, uint8_t spd_addr)
: SPDAccessor(bus, spd_addr)
{
}
DDR5Accessor::~DDR5Accessor()
{
}
SPDMemoryType DDR5Accessor::memory_type()
{
return((SPDMemoryType)(this->at(0x02)));
}
uint16_t DDR5Accessor::jedec_id()
{
return((this->at(0x200) << 8) + (this->at(0x201) & 0x7f) - 1);
}
uint8_t DDR5Accessor::manufacturer_data(uint16_t index)
{
if(index > 84)
{
return 0;
}
return this->at(0x22B + index);
}