ReactOS 0.4.16-dev-1067-ge98bba2
hwide.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DEVICE_UNIT
 Data structure for the ATA device. More...
 

Macros

#define ATA_DEVICE_ATAPI   0x00000001
 
#define ATA_DEVICE_LBA   0x00000002
 
#define ATA_DEVICE_LBA48   0x00000004
 
#define ATA_DEVICE_IS_NEC_CDR260   0x00000008
 
#define ATA_DEVICE_FLAG_IO32   0x00000010
 

Typedefs

typedef struct _DEVICE_UNIT DEVICE_UNIT
 Data structure for the ATA device.
 
typedef struct _DEVICE_UNITPDEVICE_UNIT
 

Functions

BOOLEAN AtaInit (_Out_ PUCHAR DetectedCount)
 
PDEVICE_UNIT AtaGetDevice (_In_ UCHAR UnitNumber)
 
BOOLEAN AtaReadLogicalSectors (_In_ PDEVICE_UNIT DeviceUnit, _In_ ULONG64 SectorNumber, _In_ ULONG SectorCount, _Out_writes_bytes_all_(SectorCount *DeviceUnit->SectorSize) PVOID Buffer)
 

Macro Definition Documentation

◆ ATA_DEVICE_ATAPI

#define ATA_DEVICE_ATAPI   0x00000001

Definition at line 30 of file hwide.h.

◆ ATA_DEVICE_FLAG_IO32

#define ATA_DEVICE_FLAG_IO32   0x00000010

Definition at line 34 of file hwide.h.

◆ ATA_DEVICE_IS_NEC_CDR260

#define ATA_DEVICE_IS_NEC_CDR260   0x00000008

Definition at line 33 of file hwide.h.

◆ ATA_DEVICE_LBA

#define ATA_DEVICE_LBA   0x00000002

Definition at line 31 of file hwide.h.

◆ ATA_DEVICE_LBA48

#define ATA_DEVICE_LBA48   0x00000004

Definition at line 32 of file hwide.h.

Typedef Documentation

◆ DEVICE_UNIT

Data structure for the ATA device.

◆ PDEVICE_UNIT

Function Documentation

◆ AtaGetDevice()

PDEVICE_UNIT AtaGetDevice ( _In_ UCHAR  UnitNumber)

Definition at line 1254 of file hwide.c.

1256{
1257 if (UnitNumber < RTL_NUMBER_OF(AtapUnits))
1258 return (PDEVICE_UNIT)AtapUnits[UnitNumber];
1259
1260 return NULL;
1261}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define NULL
Definition: types.h:112
static PHW_DEVICE_UNIT AtapUnits[CHANNEL_MAX_CHANNELS *CHANNEL_MAX_DEVICES]
Definition: hwide.c:37
Data structure for the ATA device.
Definition: hwide.h:12

Referenced by InitIdeDrive(), Pc98DiskReadLogicalSectorsLBA(), and XboxDiskInit().

◆ AtaInit()

BOOLEAN AtaInit ( _Out_ PUCHAR  DetectedCount)

Definition at line 1264 of file hwide.c.

1266{
1267 ULONG ChannelNumber;
1268
1269 *DetectedCount = 0;
1270
1271 /* Enumerate IDE channels */
1272 for (ChannelNumber = 0; ChannelNumber < CHANNEL_MAX_CHANNELS; ++ChannelNumber)
1273 {
1275 IDE_REGISTERS Registers;
1276
1277 if (!AtapIdentifyChannel(ChannelNumber, &Registers))
1278 continue;
1279
1280 /* Check for devices attached to the bus */
1282 {
1283 PHW_DEVICE_UNIT DeviceUnit;
1284 ATA_DEVICE_CLASS DeviceClass;
1285
1286 /* Allocate a new device unit structure */
1287 DeviceUnit = FrLdrTempAlloc(sizeof(*DeviceUnit), TAG_ATA_DEVICE);
1288 if (!DeviceUnit)
1289 {
1290 ERR("Failed to allocate device unit!\n");
1291 continue;
1292 }
1293 RtlZeroMemory(DeviceUnit, sizeof(*DeviceUnit));
1294
1295 /* Perform a minimal initialization */
1296 RtlCopyMemory(&DeviceUnit->Registers, &Registers, sizeof(Registers));
1297 DeviceUnit->DeviceNumber = DeviceNumber;
1298 DeviceUnit->P.SectorSize = 512;
1299 DeviceUnit->DeviceSelect = (DEV_SLAVE(DeviceNumber) << 4) | IDE_DRIVE_SELECT;
1300
1301 /* Let's see what kind of device this is */
1302 DeviceClass = AtapIdentifyDevice(DeviceUnit);
1303 if (DeviceClass == DEV_NONE)
1304 goto NextDevice;
1305
1306 TRACE("Found %lu device at %X:%u\n", DeviceClass, Registers.Data, DeviceNumber);
1307
1308 if (!AtapInitDevice(DeviceUnit, DeviceClass))
1309 goto NextDevice;
1310
1311 TRACE("Total sectors %I64u of size %lu, CHS %lu:%lu:%lu, %lx\n",
1312 DeviceUnit->P.TotalSectors,
1313 DeviceUnit->P.SectorSize,
1314 DeviceUnit->P.Cylinders,
1315 DeviceUnit->P.Heads,
1316 DeviceUnit->P.SectorsPerTrack,
1317 DeviceUnit->P.Flags);
1318
1319 AtapUnits[(*DetectedCount)++] = DeviceUnit;
1320 continue;
1321
1322NextDevice:
1323 FrLdrTempFree(DeviceUnit, TAG_ATA_DEVICE);
1324 }
1325 }
1326
1327 return (*DetectedCount > 0);
1328}
#define ERR(fmt,...)
Definition: precomp.h:57
VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: heap.c:553
PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: heap.c:545
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define CHANNEL_MAX_CHANNELS
Definition: hwide.c:35
static BOOLEAN AtapIdentifyChannel(_In_ ULONG ChannelNumber, _Out_ PIDE_REGISTERS Registers)
Definition: hwide.c:1181
static BOOLEAN AtapInitDevice(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ ATA_DEVICE_CLASS DeviceClass)
Definition: hwide.c:1166
static ATA_DEVICE_CLASS AtapIdentifyDevice(_In_ PHW_DEVICE_UNIT DeviceUnit)
Definition: hwide.c:773
enum _ATA_DEVICE_CLASS ATA_DEVICE_CLASS
@ DEV_NONE
Definition: hwidep.h:97
#define CHANNEL_MAX_DEVICES
Definition: hwidep.h:24
#define DEV_SLAVE(DeviceNumber)
Definition: hwidep.h:25
#define TAG_ATA_DEVICE
Definition: hwidep.h:10
#define IDE_DRIVE_SELECT
Definition: hwidep.h:54
#define TRACE(s)
Definition: solgame.cpp:4
ULONG Cylinders
Definition: hwide.h:14
ULONG SectorSize
Definition: hwide.h:23
ULONG SectorsPerTrack
Definition: hwide.h:20
ULONG64 TotalSectors
Definition: hwide.h:26
ULONG Flags
Definition: hwide.h:29
ULONG Heads
Definition: hwide.h:17
UCHAR DeviceNumber
Definition: hwidep.h:183
DEVICE_UNIT P
Definition: hwidep.h:176
UCHAR DeviceSelect
Definition: hwidep.h:184
IDE_REGISTERS Registers
Definition: hwidep.h:178
IDE_REG Data
Definition: hwidep.h:102
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by Pc98InitializeBootDevices(), and XboxDiskInit().

◆ AtaReadLogicalSectors()

BOOLEAN AtaReadLogicalSectors ( _In_ PDEVICE_UNIT  DeviceUnit,
_In_ ULONG64  SectorNumber,
_In_ ULONG  SectorCount,
_Out_writes_bytes_all_(SectorCount *DeviceUnit->SectorSize) PVOID  Buffer 
)

Definition at line 1215 of file hwide.c.

1220{
1221 PHW_DEVICE_UNIT Unit = (PHW_DEVICE_UNIT)DeviceUnit;
1223
1224 ASSERT((SectorNumber + SectorCount) <= Unit->P.TotalSectors);
1225 ASSERT(SectorCount != 0);
1226
1227 while (SectorCount > 0)
1228 {
1229 ULONG BlockCount;
1230
1231 BlockCount = min(SectorCount, Unit->MaximumTransferLength);
1232
1233 Request.DataBuffer = Buffer;
1234 Request.DataTransferLength = BlockCount * Unit->P.SectorSize;
1235
1236 if (Unit->P.Flags & ATA_DEVICE_ATAPI)
1237 AtapBuildReadPacketCommand(&Request, SectorNumber, BlockCount);
1238 else
1239 AtapBuildReadTaskFile(Unit, &Request, SectorNumber, BlockCount);
1240
1242 return FALSE;
1243
1244 SectorNumber += BlockCount;
1245 SectorCount -= BlockCount;
1246
1247 Buffer = (PVOID)((ULONG_PTR)Buffer + Unit->P.SectorSize);
1248 }
1249
1250 return TRUE;
1251}
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Unit
Definition: gdiplusenums.h:26
static VOID AtapBuildReadPacketCommand(_In_ PATA_DEVICE_REQUEST Request, _In_ ULONG64 Lba, _In_ ULONG SectorCount)
Definition: hwide.c:677
static VOID AtapBuildReadTaskFile(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ PATA_DEVICE_REQUEST Request, _In_ ULONG64 Lba, _In_ ULONG SectorCount)
Definition: hwide.c:606
static BOOLEAN AtapIssueCommand(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ PATA_DEVICE_REQUEST Request)
Definition: hwide.c:511
#define ATA_DEVICE_ATAPI
Definition: hwide.h:30
struct _HW_DEVICE_UNIT * PHW_DEVICE_UNIT
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
ULONG SectorCount
Definition: part_xbox.c:31
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Referenced by Pc98DiskReadLogicalSectorsLBA(), and XboxDiskReadLogicalSectors().