-
-
Notifications
You must be signed in to change notification settings - Fork 327
Expand file tree
/
Copy pathKingstonFuryDRAMControllerDetect.cpp
More file actions
202 lines (174 loc) · 7.38 KB
/
KingstonFuryDRAMControllerDetect.cpp
File metadata and controls
202 lines (174 loc) · 7.38 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*---------------------------------------------------------*\
| KingstonFuryDRAMControllerDetect.cpp |
| |
| Detection of Kingston Fury DDR4/5 RAM modules |
| |
| Geofrey Mon (geofbot) 14 Jul 2024 |
| Milan Cermak (krysmanta) |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <vector>
#include "Detector.h"
#include "KingstonFuryDRAMController.h"
#include "LogManager.h"
#include "RGBController_KingstonFuryDRAM.h"
#include "i2c_smbus.h"
#include "pci_ids.h"
using namespace std::chrono_literals;
typedef enum
{
RESULT_PASS = 0,
RESULT_FAIL = 1,
RESULT_ERROR = 2
} TestResult;
bool TestDDR4Models(char code)
{
return (code == FURY_MODEL_BEAST_WHITE_DDR4 ||
code == FURY_MODEL_BEAST_DDR4);
}
bool TestDDR5Models(char code)
{
return (code == FURY_MODEL_BEAST_DDR5 ||
code == FURY_MODEL_BEAST2_DDR5 ||
code == FURY_MODEL_RENEGADE_DDR5 ||
code == FURY_MODEL_BEAST_RGB_WHITE_DDR5 ||
code == FURY_MODEL_BEAST_HP_DDR5);
}
// Checking Fury signature in the RGB address space
TestResult TestForFurySignature(i2c_smbus_interface *bus, unsigned int slot_addr, bool (*modelChecker)(char))
{
bool passed = true;
char test_str[] = "FURY";
int res;
LOG_DEBUG("[%s] looking at 0x%02X",
FURY_CONTROLLER_NAME, slot_addr);
// Start transaction
res = bus->i2c_smbus_write_byte_data(slot_addr, FURY_REG_APPLY, FURY_BEGIN_TRNSFER);
if(res < 0)
{
LOG_DEBUG("[%s] DIMM not present at 0x%02X",
FURY_CONTROLLER_NAME, slot_addr);
return RESULT_ERROR;
}
std::this_thread::sleep_for(FURY_DELAY);
LOG_DEBUG("[%s] %02X beginning transaction; res=%02X",
FURY_CONTROLLER_NAME, slot_addr, res);
// Read and check the signature
for(int i = 1; i <= 4; i++)
{
for(int retry = 3; retry > 0; retry--)
{
res = bus->i2c_smbus_read_word_data(slot_addr, i);
std::this_thread::sleep_for(FURY_DELAY);
LOG_DEBUG("[%s] Testing address %02X register %02X, res=%04X",
FURY_CONTROLLER_NAME, slot_addr, i, res);
// retry when there is an error or the returned value is 0xFFFF
if((res >= 0) && (res < 0xFFFF))
{
break;
}
}
if(res < 0)
{
return RESULT_ERROR;
}
char shifted = (res >> 8) & 0xFF;
if(shifted != test_str[i-1])
{
passed = false;
break;
}
}
if(passed)
{
// Get the model code
res = bus->i2c_smbus_read_word_data(slot_addr, FURY_REG_MODEL);
int model_code = res >> 8;
std::this_thread::sleep_for(FURY_DELAY);
LOG_DEBUG("[%s] Reading model code at address %02X register %02X, res=%02X",
FURY_CONTROLLER_NAME, slot_addr, FURY_REG_MODEL, res);
if(!modelChecker(model_code))
{
LOG_INFO("[%s] Unknown model code 0x%02X", FURY_CONTROLLER_NAME, model_code);
passed = false;
}
}
// Close transaction
res = bus->i2c_smbus_write_byte_data(slot_addr, FURY_REG_APPLY, FURY_END_TRNSFER);
if(res < 0)
{
return RESULT_ERROR;
}
std::this_thread::sleep_for(FURY_DELAY);
LOG_DEBUG("[%s] %02X ending transaction; res=%02X",
FURY_CONTROLLER_NAME, slot_addr, res);
return passed ? RESULT_PASS : RESULT_FAIL;
}
void DetectKingstonFuryDRAMControllers(i2c_smbus_interface* bus, std::vector<SPDWrapper*> &slots,
uint8_t fury_base_addr, bool (*modelChecker)(char), std::vector<int> &fury_slots)
{
// Are these the Kingston Fury DRAMs
for(SPDWrapper *slot : slots)
{
TestResult result;
int retries = 0;
result = RESULT_ERROR;
while(retries < 3 && result == RESULT_ERROR)
{
result = TestForFurySignature(bus, fury_base_addr + slot->index(), modelChecker);
if(result == RESULT_PASS)
{
break;
}
if(result == RESULT_ERROR)
{
// I/O error - wait for a bit and retry
retries++;
std::this_thread::sleep_for(FURY_DELAY);
}
}
// RAM module successfully detected in the slot 'slot_index'
if(result == RESULT_PASS)
{
LOG_DEBUG("[%s] detected at slot index %d",
FURY_CONTROLLER_NAME, slot->index());
fury_slots.push_back(slot->index());
}
}
}
/******************************************************************************************\
* *
* DetectKingstonFuryDRAMControllers *
* *
* Detect Kingston Fury DDR4/5 DRAM controllers on the enumerated I2C busses. *
* *
\******************************************************************************************/
void DetectKingstonFuryDDR4Controllers(i2c_smbus_interface* bus, std::vector<SPDWrapper*> &slots, const std::string &name)
{
std::vector<int> fury_slots;
DetectKingstonFuryDRAMControllers(bus, slots, FURY_BASE_ADDR_DDR4, TestDDR4Models, fury_slots);
if(!fury_slots.empty())
{
KingstonFuryDRAMController* controller = new KingstonFuryDRAMController(bus, FURY_BASE_ADDR_DDR4, fury_slots, name);
RGBController_KingstonFuryDRAM* rgb_controller = new RGBController_KingstonFuryDRAM(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
void DetectKingstonFuryDDR5Controllers(i2c_smbus_interface* bus, std::vector<SPDWrapper*> &slots, const std::string &name)
{
std::vector<int> fury_slots;
DetectKingstonFuryDRAMControllers(bus, slots, FURY_BASE_ADDR_DDR5, TestDDR5Models, fury_slots);
if(!fury_slots.empty())
{
KingstonFuryDRAMController* controller = new KingstonFuryDRAMController(bus, FURY_BASE_ADDR_DDR5, fury_slots, name);
RGBController_KingstonFuryDRAM* rgb_controller = new RGBController_KingstonFuryDRAM(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
REGISTER_I2C_DIMM_DETECTOR("Kingston Fury DDR4 DRAM", DetectKingstonFuryDDR4Controllers, JEDEC_KINGSTON, SPD_DDR4_SDRAM);
REGISTER_I2C_DIMM_DETECTOR("Kingston Fury DDR4 DRAM", DetectKingstonFuryDDR4Controllers, JEDEC_KINGSTON_2, SPD_DDR4_SDRAM);
REGISTER_I2C_DIMM_DETECTOR("Kingston Fury DDR5 DRAM", DetectKingstonFuryDDR5Controllers, JEDEC_KINGSTON, SPD_DDR5_SDRAM);
REGISTER_I2C_DIMM_DETECTOR("Kingston Fury DDR5 DRAM", DetectKingstonFuryDDR5Controllers, JEDEC_KINGSTON_2, SPD_DDR5_SDRAM);
REGISTER_I2C_DIMM_DETECTOR("Kingston Fury DDR5 DRAM", DetectKingstonFuryDDR5Controllers, JEDEC_KINGSTON_3, SPD_DDR5_SDRAM);