* Acess2 IDE Harddisk Driver
* - main.c
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <modules.h>
#include <vfs.h>
} __attribute__ ((packed)) tIdentify;
// === IMPORTS ===
-extern void ATA_ParseMBR(int Disk);
+extern void ATA_ParseMBR(int Disk, tMBR *MBR);
// === PROTOTYPES ===
int ATA_Install();
int gATA_IRQSec = 15;
int giaATA_ControllerLock[2] = {0}; //!< Spinlocks for each controller
Uint8 gATA_Buffers[2][4096] __attribute__ ((section(".padata")));
- int gaATA_IRQs[2] = {0};
+volatile int gaATA_IRQs[2] = {0};
tPRDT_Ent gATA_PRDTs[2] = {
{0, 512, IDE_PRDT_LAST},
{0, 512, IDE_PRDT_LAST}
node->Write = ATA_WriteFS;
node->IOCtl = ATA_IOCtl;
-
// --- Scan Partitions ---
LOG("Reading MBR");
// Read Boot Sector
if(data.mbr.Parts[0].SystemID == 0xEE)
ATA_ParseGPT(Disk);
else // No? Just parse the MBR
- ATA_ParseMBR(Disk);
+ ATA_ParseMBR(Disk, &data.mbr);
+
+ ATA_ReadDMA( Disk, 1, 1, &data );
+ Debug_HexDump("ATA_ScanDisk", &data, 512);
LEAVE('i', 0);
return 1;
Part->Node.Read = ATA_ReadFS;
Part->Node.Write = ATA_WriteFS;
Part->Node.IOCtl = ATA_IOCtl;
+ Log_Notice("ATA", "Note '%s' at 0x%llx, 0x%llx long", Part->Name, Part->Start, Part->Length);
LOG("Made '%s' (&Node=%p)", Part->Name, &Part->Node);
LEAVE('-');
}
int disk = Node->Inode >> 8;
int part = Node->Inode & 0xFF;
+ ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
+
// Raw Disk Access
if(part == 0xFF)
{
- if( Offset >= gATA_Disks[disk].Sectors * SECTOR_SIZE )
+ if( Offset >= gATA_Disks[disk].Sectors * SECTOR_SIZE ) {
+ LEAVE('i', 0);
return 0;
+ }
if( Offset + Length > gATA_Disks[disk].Sectors*SECTOR_SIZE )
Length = gATA_Disks[disk].Sectors*SECTOR_SIZE - Offset;
}
// Partition
else
{
- if( Offset >= gATA_Disks[disk].Partitions[part].Length * SECTOR_SIZE )
+ if( Offset >= gATA_Disks[disk].Partitions[part].Length * SECTOR_SIZE ) {
+ LEAVE('i', 0);
return 0;
+ }
if( Offset + Length > gATA_Disks[disk].Partitions[part].Length * SECTOR_SIZE )
Length = gATA_Disks[disk].Partitions[part].Length * SECTOR_SIZE - Offset;
Offset += gATA_Disks[disk].Partitions[part].Start * SECTOR_SIZE;
}
- //Log("ATA_ReadFS: (Node=%p, Offset=0x%llx, Length=0x%llx, Buffer=%p)", Node, Offset, Length, Buffer);
- return DrvUtil_ReadBlock(Offset, Length, Buffer, ATA_ReadRaw, SECTOR_SIZE, disk);
+ {
+ int ret = DrvUtil_ReadBlock(Offset, Length, Buffer, ATA_ReadRaw, SECTOR_SIZE, disk);
+ Debug_HexDump("ATA_ReadFS", Buffer, Length);
+ LEAVE('i', ret);
+ return ret;
+ }
}
/**
Uint offset;
Uint done = 0;
- // Pass straight on to ATA_WriteDMA if we can
+ // Pass straight on to ATA_WriteDMA, if we can
if(Count <= MAX_DMA_SECTORS)
{
ret = ATA_WriteDMA(Disk, Address, Count, Buffer);
int cont = (Disk>>1)&1; // Controller ID
int disk = Disk & 1;
Uint16 base;
+ Uint8 val;
ENTER("iDisk XAddress iCount pBuffer", Disk, Address, Count, Buffer);
outb(base+0x6, 0x40 | (disk << 4));
outb(base+0x2, 0 >> 8); // Upper Sector Count
outb(base+0x3, Address >> 24); // Low 2 Addr
- outb(base+0x3, Address >> 28); // Mid 2 Addr
- outb(base+0x3, Address >> 32); // High 2 Addr
+ outb(base+0x4, Address >> 28); // Mid 2 Addr
+ outb(base+0x5, Address >> 32); // High 2 Addr
}
else
{
- outb(base+0x06, 0xE0 | (disk << 4) | ((Address >> 24) & 0x0F)); //Disk,Magic,High addr
+ outb(base+0x06, 0xE0 | (disk << 4) | ((Address >> 24) & 0x0F)); // Magic, Disk, High addr
}
outb(base+0x02, (Uint8) Count); // Sector Count
outb(base+0x05, (Uint8) (Address >> 16)); // High Addr
LOG("Starting Transfer");
- #if START_BEFORE_CMD
- // Start transfer
- ATA_int_BusMasterWriteByte( cont << 3, 9 ); // Read and start
- if( Address > 0x0FFFFFFF )
- outb(base+0x07, HDD_DMA_R48); // Read Command (LBA48)
- else
- outb(base+0x07, HDD_DMA_R28); // Read Command (LBA28)
- #else
if( Address > 0x0FFFFFFF )
outb(base+0x07, HDD_DMA_R48); // Read Command (LBA48)
else
outb(base+0x07, HDD_DMA_R28); // Read Command (LBA28)
// Start transfer
ATA_int_BusMasterWriteByte( cont << 3, 9 ); // Read and start
- #endif
// Wait for transfer to complete
- //ATA_int_BusMasterWriteByte( (cont << 3) + 2, 0x4 );
- while( gaATA_IRQs[cont] == 0 ) {
- //Uint8 val = ATA_int_BusMasterReadByte( (cont << 3) + 2, 0x4 );
+ val = 0;
+ while( gaATA_IRQs[cont] == 0 && !(val & 0x4) ) {
+ val = ATA_int_BusMasterReadByte( (cont << 3) + 2 );
//LOG("val = 0x%02x", val);
Threads_Yield();
}
// Complete Transfer
- ATA_int_BusMasterWriteByte( cont << 3, 0 ); // Write and stop
+ ATA_int_BusMasterWriteByte( cont << 3, 8 ); // Read and stop
LOG("Transfer Completed & Acknowledged");
#include "common.h"
// === PROTOTYPES ===
+void ATA_ParseMBR(int Disk, tMBR *MBR);
Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length);
// === GLOBALS ===
// === CODE ===
/**
- * \fn void ATA_ParseMBR(int Disk)
+ * \fn void ATA_ParseMBR(int Disk, tMBR *MBR)
*/
-void ATA_ParseMBR(int Disk)
+void ATA_ParseMBR(int Disk, tMBR *MBR)
{
int i, j = 0, k = 4;
- tMBR mbr;
Uint64 extendedLBA;
Uint64 base, len;
ENTER("iDisk", Disk);
- // Read Boot Sector
- ATA_ReadDMA( Disk, 0, 1, &mbr );
-
// Count Partitions
gATA_Disks[Disk].NumPartitions = 0;
extendedLBA = 0;
for( i = 0; i < 4; i ++ )
{
- if( mbr.Parts[i].SystemID == 0 ) continue;
- if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28
- || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48
+ if( MBR->Parts[i].SystemID == 0 ) continue;
+ if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 // LBA 28
+ || MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 // LBA 48
)
{
- if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
+ if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
LOG("Extended Partition");
if(extendedLBA != 0) {
Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
continue;
}
- extendedLBA = mbr.Parts[i].LBAStart;
+ extendedLBA = MBR->Parts[i].LBAStart;
continue;
}
LOG("Primary Partition");
extendedLBA = 0;
for( j = 0, i = 0; i < 4; i ++ )
{
- Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
- if( mbr.Parts[i].SystemID == 0 ) continue;
- if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) // LBA 28
+ LOG("MBR->Parts[%i].SystemID = 0x%02x", i, MBR->Parts[i].SystemID);
+ if( MBR->Parts[i].SystemID == 0 ) continue;
+ if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 ) // LBA 28
{
- base = mbr.Parts[i].LBAStart;
- len = mbr.Parts[i].LBALength;
+ base = MBR->Parts[i].LBAStart;
+ len = MBR->Parts[i].LBALength;
}
- else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) // LBA 58
+ else if( MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 ) // LBA 58
{
- base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
- len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
+ base = (MBR->Parts[i].StartHi << 16) | MBR->Parts[i].LBAStart;
+ len = (MBR->Parts[i].LengthHi << 16) | MBR->Parts[i].LBALength;
}
else
continue;
- if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
+ if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
if(extendedLBA != 0) {
- Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
+ Log_Warning("ATA", "Disk %i has multiple extended partitions, ignoring rest", Disk);
continue;
}
extendedLBA = base;