ReactOS 0.4.16-dev-2207-geb15453
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
 

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_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 1270 of file hwide.c.

1272{
1273 if (UnitNumber < RTL_NUMBER_OF(AtapUnits))
1274 return (PDEVICE_UNIT)AtapUnits[UnitNumber];
1275
1276 return NULL;
1277}
#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 1280 of file hwide.c.

1282{
1283 ULONG ChannelNumber;
1284
1285 *DetectedCount = 0;
1286
1287 /* Enumerate IDE channels */
1288 for (ChannelNumber = 0; ChannelNumber < CHANNEL_MAX_CHANNELS; ++ChannelNumber)
1289 {
1291 IDE_REGISTERS Registers;
1292
1293 if (!AtapIdentifyChannel(ChannelNumber, &Registers))
1294 continue;
1295
1296 /* Check for devices attached to the bus */
1298 {
1299 PHW_DEVICE_UNIT DeviceUnit;
1300 ATA_DEVICE_CLASS DeviceClass;
1301
1302 /* Allocate a new device unit structure */
1303 DeviceUnit = FrLdrTempAlloc(sizeof(*DeviceUnit), TAG_ATA_DEVICE);
1304 if (!DeviceUnit)
1305 {
1306 ERR("Failed to allocate device unit!\n");
1307 continue;
1308 }
1309 RtlZeroMemory(DeviceUnit, sizeof(*DeviceUnit));
1310
1311 /* Perform a minimal initialization */
1312 RtlCopyMemory(&DeviceUnit->Registers, &Registers, sizeof(Registers));
1313 DeviceUnit->DeviceNumber = DeviceNumber;
1314 DeviceUnit->P.SectorSize = 512;
1315 DeviceUnit->DeviceSelect = (DEV_SLAVE(DeviceNumber) << 4) | IDE_DRIVE_SELECT;
1316
1317 /* Let's see what kind of device this is */
1318 DeviceClass = AtapIdentifyDevice(DeviceUnit);
1319 if (DeviceClass == DEV_NONE)
1320 goto NextDevice;
1321
1322 TRACE("Found %lu device at %X:%u\n", DeviceClass, Registers.Data, DeviceNumber);
1323
1324 if (!AtapInitDevice(DeviceUnit, DeviceClass))
1325 goto NextDevice;
1326
1327 TRACE("Total sectors %I64u of size %lu, CHS %lu:%lu:%lu, %lx\n",
1328 DeviceUnit->P.TotalSectors,
1329 DeviceUnit->P.SectorSize,
1330 DeviceUnit->P.Cylinders,
1331 DeviceUnit->P.Heads,
1332 DeviceUnit->P.SectorsPerTrack,
1333 DeviceUnit->P.Flags);
1334
1335 AtapUnits[(*DetectedCount)++] = DeviceUnit;
1336 continue;
1337
1338NextDevice:
1339 FrLdrTempFree(DeviceUnit, TAG_ATA_DEVICE);
1340 }
1341 }
1342
1343 return (*DetectedCount > 0);
1344}
#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:1196
static BOOLEAN AtapInitDevice(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ ATA_DEVICE_CLASS DeviceClass)
Definition: hwide.c:1181
static ATA_DEVICE_CLASS AtapIdentifyDevice(_In_ PHW_DEVICE_UNIT DeviceUnit)
Definition: hwide.c:788
enum _ATA_DEVICE_CLASS ATA_DEVICE_CLASS
@ DEV_NONE
Definition: hwidep.h:102
#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:56
#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:188
DEVICE_UNIT P
Definition: hwidep.h:181
UCHAR DeviceSelect
Definition: hwidep.h:189
IDE_REGISTERS Registers
Definition: hwidep.h:183
IDE_REG Data
Definition: hwidep.h:107
#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 1230 of file hwide.c.

1235{
1236 PHW_DEVICE_UNIT Unit = (PHW_DEVICE_UNIT)DeviceUnit;
1238
1239 ASSERT(Unit);
1240 ASSERT((SectorNumber + SectorCount) <= Unit->P.TotalSectors);
1241 ASSERT(SectorCount != 0);
1242
1243 while (SectorCount > 0)
1244 {
1245 ULONG BlockCount;
1246
1247 BlockCount = min(SectorCount, Unit->MaximumTransferLength);
1248
1249 Request.DataBuffer = Buffer;
1250 Request.DataTransferLength = BlockCount * Unit->P.SectorSize;
1251
1252 if (Unit->P.Flags & ATA_DEVICE_ATAPI)
1253 AtapBuildReadPacketCommand(&Request, SectorNumber, BlockCount);
1254 else
1255 AtapBuildReadTaskFile(Unit, &Request, SectorNumber, BlockCount);
1256
1258 return FALSE;
1259
1260 SectorNumber += BlockCount;
1261 SectorCount -= BlockCount;
1262
1263 Buffer = (PVOID)((ULONG_PTR)Buffer + Unit->P.SectorSize);
1264 }
1265
1266 return TRUE;
1267}
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:691
static VOID AtapBuildReadTaskFile(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ PATA_DEVICE_REQUEST Request, _In_ ULONG64 Lba, _In_ ULONG SectorCount)
Definition: hwide.c:620
static BOOLEAN AtapIssueCommand(_In_ PHW_DEVICE_UNIT DeviceUnit, _In_ PATA_DEVICE_REQUEST Request)
Definition: hwide.c:529
#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().