3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Xbox specific disk access routines
5 * COPYRIGHT: Copyright 2004 Gé van Geldorp (gvg@reactos.com)
6 * Copyright 2019 Dmitry Borisov (di.sean@protonmail.com)
9 /* INCLUDES *******************************************************************/
15 DBG_DEFAULT_CHANNEL(DISK
);
17 /* GLOBALS ********************************************************************/
19 static PDEVICE_UNIT HardDrive
= NULL
;
20 static PDEVICE_UNIT CdDrive
= NULL
;
21 static BOOLEAN AtaInitialized
= FALSE
;
23 /* FUNCTIONS ******************************************************************/
26 XboxDiskInit(BOOLEAN Init
)
30 PDEVICE_UNIT DeviceUnit
= NULL
;
32 if (Init
& !AtaInitialized
)
34 /* Find first HDD and CD */
35 AtaInit(&DetectedCount
);
36 for (UnitNumber
= 0; UnitNumber
<= DetectedCount
; UnitNumber
++)
38 DeviceUnit
= AtaGetDevice(UnitNumber
);
41 if (DeviceUnit
->Flags
& ATA_DEVICE_ATAPI
)
49 HardDrive
= DeviceUnit
;
53 AtaInitialized
= TRUE
;
64 XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber
, PDEVICE_UNIT
*DeviceUnit
)
66 /* Xbox has only 1 IDE controller and no floppy */
67 if (DriveNumber
< 0x80 || (DriveNumber
& 0x0F) >= 2)
74 if ((DriveNumber
== 0x80) && HardDrive
)
76 *DeviceUnit
= HardDrive
;
81 if ((DriveNumber
& 0xF0) > 0x80 && CdDrive
)
83 *DeviceUnit
= CdDrive
;
91 XboxDiskReadLogicalSectors(UCHAR DriveNumber
, ULONGLONG SectorNumber
, ULONG SectorCount
, PVOID Buffer
)
93 PDEVICE_UNIT DeviceUnit
= NULL
;
95 TRACE("XboxDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n",
96 DriveNumber
, SectorNumber
, SectorCount
, Buffer
);
98 if (!XboxDiskDriveNumberToDeviceUnit(DriveNumber
, &DeviceUnit
))
101 return AtaAtapiReadLogicalSectorsLBA(DeviceUnit
, SectorNumber
, SectorCount
, Buffer
);
105 XboxDiskGetDriveGeometry(UCHAR DriveNumber
, PGEOMETRY Geometry
)
107 PDEVICE_UNIT DeviceUnit
= NULL
;
109 TRACE("XboxDiskGetDriveGeometry(0x%x)\n", DriveNumber
);
111 if (!XboxDiskDriveNumberToDeviceUnit(DriveNumber
, &DeviceUnit
))
114 Geometry
->Cylinders
= DeviceUnit
->Cylinders
;
115 Geometry
->Heads
= DeviceUnit
->Heads
;
116 Geometry
->Sectors
= DeviceUnit
->Sectors
;
117 Geometry
->BytesPerSector
= DeviceUnit
->SectorSize
;
123 XboxDiskGetCacheableBlockCount(UCHAR DriveNumber
)
125 PDEVICE_UNIT DeviceUnit
= NULL
;
127 TRACE("XboxDiskGetCacheableBlockCount(0x%x)\n", DriveNumber
);
129 if (!XboxDiskDriveNumberToDeviceUnit(DriveNumber
, &DeviceUnit
))
133 * If LBA is supported then the block size will be 64 sectors (32k)
134 * If not then the block size is the size of one track.
136 if (DeviceUnit
->Flags
& ATA_DEVICE_LBA
)
139 return DeviceUnit
->Sectors
;