Fix SPDDetector only scanning bus 0 on Linux

This commit is contained in:
Stephen Horvath 2025-04-21 10:41:34 +10:00 committed by Adam Honse
parent 9e6a2eb94c
commit 2c4b159901
6 changed files with 18 additions and 10 deletions

View file

@ -25,9 +25,9 @@ EE1004Accessor::~EE1004Accessor()
bool EE1004Accessor::isAvailable(i2c_smbus_interface *bus, uint8_t spd_addr)
{
int size = snprintf(nullptr, 0, SPD_EE1004_PATH, bus->port_id, spd_addr);
int size = snprintf(nullptr, 0, SPD_EE1004_PATH, bus->bus_id, spd_addr);
char *path = new char[size+1];
snprintf(path, size+1, SPD_EE1004_PATH, bus->port_id, spd_addr);
snprintf(path, size+1, SPD_EE1004_PATH, bus->bus_id, spd_addr);
bool result = std::filesystem::exists(path);
delete[] path;
return result;
@ -52,9 +52,9 @@ uint8_t EE1004Accessor::at(uint16_t addr)
void EE1004Accessor::readEEPROM()
{
int size = snprintf(nullptr, 0, SPD_EE1004_PATH, bus->port_id, address);
int size = snprintf(nullptr, 0, SPD_EE1004_PATH, bus->bus_id, address);
char *filename = new char[size+1];
snprintf(filename, size+1, SPD_EE1004_PATH, bus->port_id, address);
snprintf(filename, size+1, SPD_EE1004_PATH, bus->bus_id, address);
std::ifstream eeprom_file(filename, std::ios::in | std::ios::binary);
if(eeprom_file)

View file

@ -26,9 +26,9 @@ SPD5118Accessor::~SPD5118Accessor()
bool SPD5118Accessor::isAvailable(i2c_smbus_interface *bus, uint8_t spd_addr)
{
int size = snprintf(nullptr, 0, SPD_SPD5118_PATH, bus->port_id, spd_addr);
int size = snprintf(nullptr, 0, SPD_SPD5118_PATH, bus->bus_id, spd_addr);
char *path = new char[size+1];
snprintf(path, size+1, SPD_SPD5118_PATH, bus->port_id, spd_addr);
snprintf(path, size+1, SPD_SPD5118_PATH, bus->bus_id, spd_addr);
bool result = std::filesystem::exists(path);
delete[] path;
return result;
@ -53,9 +53,9 @@ uint8_t SPD5118Accessor::at(uint16_t addr)
void SPD5118Accessor::readEEPROM()
{
int size = snprintf(nullptr, 0, SPD_SPD5118_PATH, bus->port_id, address);
int size = snprintf(nullptr, 0, SPD_SPD5118_PATH, bus->bus_id, address);
char *filename = new char[size+1];
snprintf(filename, size+1, SPD_SPD5118_PATH, bus->port_id, address);
snprintf(filename, size+1, SPD_SPD5118_PATH, bus->bus_id, address);
std::ifstream eeprom_file(filename, std::ios::in | std::ios::binary);
if(eeprom_file)

View file

@ -37,7 +37,7 @@ void SPDDetector::detect_memory_type()
{
SPDAccessor *accessor;
LOG_DEBUG("[SPDDetector] Probing DRAM on address 0x%02x", address);
LOG_DEBUG("[SPDDetector] Probing DRAM on bus %d address 0x%02x", bus->bus_id, address);
/*---------------------------------------------------------*\
| On Linux, attempt to use the ee1004 or spd5118 drivers to |

View file

@ -28,6 +28,7 @@ i2c_smbus_interface::i2c_smbus_interface()
this->pci_vendor = -1;
this->pci_subsystem_device = -1;
this->pci_subsystem_vendor = -1;
this->bus_id = -1;
i2c_smbus_thread_running = true;
i2c_smbus_thread = new std::thread(&i2c_smbus_interface::i2c_smbus_thread_function, this);
}

View file

@ -84,6 +84,8 @@ public:
int pci_subsystem_device;
int pci_subsystem_vendor;
int bus_id;
i2c_smbus_interface();
virtual ~i2c_smbus_interface();

View file

@ -82,7 +82,7 @@ bool i2c_smbus_linux_detect()
char path[1024];
char buff[100];
unsigned short pci_device, pci_vendor, pci_subsystem_device, pci_subsystem_vendor;
unsigned short port_id;
unsigned short port_id, bus_id;
char *ptr;
// Start looking for I2C adapters in /sys/bus/i2c/devices/
@ -125,10 +125,14 @@ bool i2c_smbus_linux_detect()
pci_subsystem_vendor = 0;
pci_subsystem_device = 0;
port_id = 0;
bus_id = 0;
// Get port ID for Nvidia GPUs
sscanf(device_string, "NVIDIA i2c adapter %hu at", &port_id);
// Get the Linux Bus ID
sscanf(ent->d_name, "i2c-%hu", &bus_id);
// Get device path
strcpy(path, driver_path);
strcat(path, ent->d_name);
@ -233,6 +237,7 @@ bool i2c_smbus_linux_detect()
bus->pci_subsystem_device = pci_subsystem_device;
bus->pci_subsystem_vendor = pci_subsystem_vendor;
bus->port_id = port_id;
bus->bus_id = bus_id;
ResourceManager::get()->RegisterI2CBus(bus);
}
else