Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 45 additions & 42 deletions RAMSPDToolkit/I2CSMBus/SMBusPawnIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected override int I2CSMBusXfer(byte addr, byte read_write, byte command, in

using (var guard = new WorldMutexGuard(WorldMutexManager.WorldSMBusMutex))
{
status = PawnIO.Execute("ioctl_smbus_xfer", inBuffer, inSize, outBuffer, outSize, out var retSize);
status = PawnIO.Execute("ioctl_smbus_xfer", inBuffer, inSize, outBuffer, outSize, out _);
}

if (data != null)
Expand Down Expand Up @@ -142,48 +142,37 @@ public static bool SMBusDetect()
}

//Lock SMBus mutex
using (var smbm = new WorldMutexGuard(WorldMutexManager.WorldSMBusMutex))
using var smbm = new WorldMutexGuard(WorldMutexManager.WorldSMBusMutex);
//Lock PCI mutex
using var pci = new WorldMutexGuard(WorldMutexManager.WorldPCIMutex);

//I801
if (LoadModuleAndAddSMBus(pawnIO, PawnIOSMBusIdentifier.I801))
{
return true;
}

//Piix4
bool loadedPiix4 = false;
for (int port = 0; port < 2; port++)
{
//Lock PCI mutex
using (var pci = new WorldMutexGuard(WorldMutexManager.WorldPCIMutex))
if (!LoadModuleAndAddSMBus(pawnIO, PawnIOSMBusIdentifier.Piix4, (m) => Piix4PortSelect(m, port)))
{
//I801
var i801 = pawnIO.LoadModule(PawnIOSMBusIdentifier.I801);
if (i801 != null)
{
SMBusManager.AddSMBus(new SMBusPawnIO(i801, PawnIOSMBusIdentifier.I801));
return true;
}
break;
}

//Piix4
var piix4 = pawnIO.LoadModule(PawnIOSMBusIdentifier.Piix4);
if (piix4 != null)
{
if (Piix4PortSelect(piix4, 0))
{
SMBusManager.AddSMBus(new SMBusPawnIO(piix4, PawnIOSMBusIdentifier.Piix4));
}

piix4 = pawnIO.LoadModule(PawnIOSMBusIdentifier.Piix4);
if (piix4 != null)
{
if (Piix4PortSelect(piix4, 1))
{
SMBusManager.AddSMBus(new SMBusPawnIO(piix4, PawnIOSMBusIdentifier.Piix4));
}
}

return true;
}
loadedPiix4 = true;
}

//NCT6793
var nct6793 = pawnIO.LoadModule(PawnIOSMBusIdentifier.NCT6793);
if (nct6793 != null)
{
SMBusManager.AddSMBus(new SMBusPawnIO(nct6793, PawnIOSMBusIdentifier.NCT6793));
return true;
}
}
if (loadedPiix4)
{
return true;
}

//NCT6793
if (LoadModuleAndAddSMBus(pawnIO, PawnIOSMBusIdentifier.NCT6793))
{
return true;
}

return false;
Expand All @@ -193,6 +182,20 @@ public static bool SMBusDetect()

#region Private

static bool LoadModuleAndAddSMBus(IPawnIODriver pawnIO, PawnIOSMBusIdentifier pawnIOSMBusIdentifier, Func<IPawnIOModule, bool> addBusCondition = null)
{
var module = pawnIO.LoadModule(pawnIOSMBusIdentifier);
if (module != null)
{
if (addBusCondition == null || addBusCondition(module))
{
SMBusManager.AddSMBus(new SMBusPawnIO(module, pawnIOSMBusIdentifier));
}
return true;
}
return false;
}

static bool Piix4PortSelect(IPawnIOModule pawnIO, int port)
{
uint inSize = 1;
Expand All @@ -203,7 +206,7 @@ static bool Piix4PortSelect(IPawnIOModule pawnIO, int port)

inBuffer[0] = port;

return pawnIO.Execute("ioctl_piix4_port_sel", inBuffer, inSize, outBuffer, outSize, out var returnSize) == 0;
return pawnIO.Execute("ioctl_piix4_port_sel", inBuffer, inSize, outBuffer, outSize, out _) == 0;
}

void GetIdentity(IPawnIOModule pawnIO)
Expand All @@ -216,7 +219,7 @@ void GetIdentity(IPawnIOModule pawnIO)
var inBuffer = new long[inSize];
var outBuffer = new long[outSize];

if (pawnIO.Execute("ioctl_identity", inBuffer, inSize, outBuffer, outSize, out var returnSize) == 0)
if (pawnIO.Execute("ioctl_identity", inBuffer, inSize, outBuffer, outSize, out _) == 0)
{
PortID = SMBusManager.RegisteredSMBuses.Count; // Assign next available port ID

Expand Down Expand Up @@ -253,7 +256,7 @@ void CheckWriteProtection(IPawnIOModule pawnIO)

bool writeProtectionEnabled = false;

if (pawnIO.Execute("ioctl_write_protection", inBuffer, inSize, outBuffer, outSize, out var returnSize) == 0)
if (pawnIO.Execute("ioctl_write_protection", inBuffer, inSize, outBuffer, outSize, out _) == 0)
{
writeProtectionEnabled = outBuffer[0] == 1;
}
Expand Down
Loading