Skip to content

Commit

Permalink
DEV9: various fixes for ATA Identify
Browse files Browse the repository at this point in the history
48-bit size corrected
UDMA mode now set correctly
MDMA0 mode now set correctly
fixed user addressable sectors limit
  • Loading branch information
AKuHAK committed Jan 3, 2024
1 parent 714e355 commit 8307edd
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions pcsx2/DEV9/ATA/ATA_Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ void ATA::WritePaddedString(u8* data, int* index, const std::string& value, u32

void ATA::CreateHDDinfo(u64 sizeSectors)
{
//PS2 is limited to 32bit size HDD (2TB), however,
//PS2 is limited to 48bit size HDD (2TB), however,
//we don't yet support 48bit, so limit to 28bit size
constexpr u32 maxSize = (1 << 28) - 1; // 128Gb
sizeSectors = std::min<u32>(sizeSectors, maxSize);
u64 maxSize = (1 << 28) - 1; // 128Gb
if (lba48Supported)
maxSize = (1ULL << 48) - 1; // 128PiB


constexpr u16 sectorSize = 512;
DevCon.WriteLn("DEV9: HddSize : %i", sizeSectors * sectorSize / (1024 * 1024));
const u64 nbSectors = sizeSectors;
DevCon.WriteLn("DEV9: nbSectors : %i", nbSectors);
const u32 nbSectors = std::min<u32>(sizeSectors, maxSize); // nbSectors will hold 28-bit size
DevCon.WriteLn("DEV9: sizeSectors : %i", sizeSectors); // SizeSectors will keep 48-bit size

memset(&identifyData, 0, sizeof(identifyData));
//Defualt CHS translation
Expand Down Expand Up @@ -150,7 +152,7 @@ void ATA::CreateHDDinfo(u64 sizeSectors)
*/
WriteUInt16(identifyData, &index, static_cast<u16>(curMultipleSectorsSetting | (1 << 8))); //word 59
//Total number of user addressable logical sectors
WriteUInt32(identifyData, &index, static_cast<u32>(nbSectors < 268435456 ? nbSectors : 268435456)); //word 60-61
WriteUInt32(identifyData, &index, nbSectors); //word 60-61
//DMA modes
/*
* bits 0-7: Singleword modes supported (0,1,2)
Expand All @@ -165,7 +167,7 @@ void ATA::CreateHDDinfo(u64 sizeSectors)
* bits 0-7: Multiword modes supported (0,1,2)
* bits 8-15: Transfer mode active
*/
if (mdmaMode > 0)
if (mdmaMode >= 0)
WriteUInt16(identifyData, &index, static_cast<u16>(0x07 | (1 << (mdmaMode + 8)))); //word 63
else
WriteUInt16(identifyData, &index, 0x07); //word 63
Expand Down Expand Up @@ -254,21 +256,21 @@ void ATA::CreateHDDinfo(u64 sizeSectors)
// clang-format off
WriteUInt16(identifyData, &index, static_cast<u16>(
/*(1 << 8) | //SET MAX */
((lba48Supported ? 1 : 0) << 10) | //Fixed
(lba48Supported << 10) | //Fixed

Check warning on line 259 in pcsx2/DEV9/ATA/ATA_Info.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/DEV9/ATA/ATA_Info.cpp#L259

Operator '|' with one operand equal to zero is redundant.
(1 << 12) | //Fixed
(1 << 13))); //Fixed //word 86
//Command set/feature enabled/supported (See word 84)
WriteUInt16(identifyData, &index, static_cast<u16>((1 << 14) | (1 << 1) | 1));
WriteUInt16(identifyData, &index, static_cast<u16>(
(1) | //Fixed
((1) << 1))); //Fixed //word 87
WriteUInt16(identifyData, &index, ( //word 87
(1) | // Fixed
(1 << 1) | // Fixed
(1 << 14))); // Fixed
// clang-format on
//UDMA modes
/*
* bits 0-7: ultraword modes supported (0,1,2,4,5,6,7)
* bits 8-15: Transfer mode active
*/
if (udmaMode > 0)
if (udmaMode >= 0)
WriteUInt16(identifyData, &index, static_cast<u16>(0x7f | (1 << (udmaMode + 8)))); //word 88
else
WriteUInt16(identifyData, &index, 0x7f); //word 88
Expand Down Expand Up @@ -310,9 +312,14 @@ void ATA::CreateHDDinfo(u64 sizeSectors)
//98-99
//Total Number of User Addressable Sectors for the 48-bit Address feature set.
index = 100 * 2;
WriteUInt64(identifyData, &index, static_cast<u16>(nbSectors));
index -= 2;
WriteUInt16(identifyData, &index, 0); //truncate to 48bits
if (lba48Supported)
{
WriteUInt64(identifyData, &index, sizeSectors);
index -= 2;
WriteUInt16(identifyData, &index, 0); //truncate to 48-bit
}
else
WriteUInt64(identifyData, &index, 0); // for 28-bit only this area is empty
//Streaming Transfer Time - PIO
//104
//Reserved
Expand Down Expand Up @@ -365,7 +372,7 @@ void ATA::CreateHDDinfo(u64 sizeSectors)
//15:8 Checksum, 7:0 Signature
CreateHDDinfoCsum();
}
void ATA::CreateHDDinfoCsum() //Is this correct?
void ATA::CreateHDDinfoCsum()
{
u8 counter = 0;

Expand Down

0 comments on commit 8307edd

Please sign in to comment.