X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fata_x86.c;h=c8814d9a670d577f7d20a9db16cf0e6c196538fd;hb=8f14093202765d2d363584da819b68ec8c11018c;hp=837085ba641400655257b3a74a04d628238c0ddf;hpb=f119d0e5b18b7286d04fc536a94e0f96e3c51714;p=tpg%2Facess2.git diff --git a/Kernel/drv/ata_x86.c b/Kernel/drv/ata_x86.c index 837085ba..c8814d9a 100644 --- a/Kernel/drv/ata_x86.c +++ b/Kernel/drv/ata_x86.c @@ -2,12 +2,14 @@ * Acess2 IDE Harddisk Driver * drv/ide.c */ +#define DEBUG 0 #include #include #include #include #include #include +#include // === CONSTANTS === #define MAX_ATA_DISKS 4 @@ -101,10 +103,11 @@ char *ATA_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name); Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data); - int ATA_Read(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer); +Uint ATA_Read(Uint64 Address, Uint Count, void *Buffer, Uint Argument); + int ATA_ReadRaw(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer); int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer); -void ATA_IRQHandlerPri(void); -void ATA_IRQHandlerSec(void); +void ATA_IRQHandlerPri(int unused); +void ATA_IRQHandlerSec(int unused); Uint8 ATA_int_BusMasterReadByte(int Ofs); void ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value); void ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value); @@ -115,6 +118,7 @@ tDevFS_Driver gATA_DriverInfo = { NULL, "ata", { .NumACLs = 1, + .Size = -1, .Flags = VFS_FFLAG_DIRECTORY, .ACLs = &gVFS_ACL_EveryoneRX, .ReadDir = ATA_ReadDir, @@ -247,6 +251,8 @@ void ATA_SetupVFS() for( j = 0; j < gATA_Disks[i].NumPartitions; j ++ ) gATA_Nodes[ k++ ] = &gATA_Disks[i].Partitions[j].Node; } + + gATA_DriverInfo.RootNode.Size = giATA_NumNodes; } /** @@ -604,7 +610,7 @@ Uint16 ATA_GetBasePort(int Disk) char *ATA_ReadDir(tVFS_Node *Node, int Pos) { if(Pos >= giATA_NumNodes || Pos < 0) return NULL; - return gATA_Nodes[Pos]->ImplPtr; + return strdup( gATA_Nodes[Pos]->ImplPtr ); } /** @@ -642,54 +648,8 @@ tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name) */ Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { - int ret; - int disk, part; - Uint64 sector, count; - - disk = Node->Inode >> 8; - part = Node->Inode & 0xFF; - - // Aligned Read - if(Offset % SECTOR_SIZE == 0 && Length % SECTOR_SIZE == 0) - { - sector = Offset / SECTOR_SIZE; - count = Length / SECTOR_SIZE; - // Raw Disk? - if(part == 0xFF) - { - // Bounds Check - if( sector >= gATA_Disks[disk].Sectors ) return 0; - if( sector + count > gATA_Disks[disk].Sectors ) - count = gATA_Disks[disk].Sectors - sector; - // Read Data - ret = ATA_Read(disk, sector, count, Buffer); - } - else // Or a partition - { - //Log(" ATA_ReadFS: %i:%i 0x%llx + 0x%llx\n", disk, part, - // gATA_Disks[disk].Partitions[part].Start, - // gATA_Disks[disk].Partitions[part].Length ); - - // Bounds Check - if( sector >= gATA_Disks[disk].Partitions[part].Length ) return 0; - if( sector + count > gATA_Disks[disk].Partitions[part].Length ) - count = gATA_Disks[disk].Partitions[part].Length - sector; - // Read Disk - ret = ATA_Read(disk, - gATA_Disks[disk].Partitions[part].Start + sector, - count, - Buffer); - } - // Check return value - if(ret == 1) - return count * SECTOR_SIZE; - else { - Warning("ATA_ReadFS: RETURN 0 (Read failed with ret = %i)", ret); - return 0; - } - } - Warning("ATA_ReadFS: RETURN 0 (Non-Aligned Read 0x%llx 0x%llx)", Offset, Length); - return 0; + //Log("ATA_ReadFS: (Node=%p, Offset=0x%llx, Length=0x%llx, Buffer=%p)", Node, Offset, Length, Buffer); + return DrvUtil_ReadBlock(Offset, Length, Buffer, ATA_Read, SECTOR_SIZE, Node->Inode); } /** @@ -715,9 +675,46 @@ int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data) // --- Disk Access --- /** - * \fn int ATA_Read(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer) + * \fn Uint ATA_Read(Uint64 Address, Uint Count, void *Buffer, Uint Argument) + */ +Uint ATA_Read(Uint64 Address, Uint Count, void *Buffer, Uint Argument) +{ + int ret; + int disk = Argument >> 8; + int part = Argument & 0xFF; + + // Raw Disk Access + if(part == 0xFF) + { + if( Address >= gATA_Disks[disk].Sectors ) return 0; + if( Address + Count > gATA_Disks[disk].Sectors ) + Count = gATA_Disks[disk].Sectors - Address; + + ret = ATA_ReadRaw(disk, Address, Count, Buffer); + if(ret == 1) + return Count; + return 0; + } + + if( Address >= gATA_Disks[disk].Partitions[part].Length ) return 0; + if( Address + Count > gATA_Disks[disk].Partitions[part].Length ) + Count = gATA_Disks[disk].Partitions[part].Length - Address; + + ret = ATA_ReadRaw( + disk, + gATA_Disks[disk].Partitions[part].Start + Address, + Count, + Buffer); + + if(ret == 1) return Count; + + return 0; + +} +/** + * \fn int ATA_ReadRaw(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer) */ -int ATA_Read(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer) +int ATA_ReadRaw(Uint8 Disk, Uint64 Address, Uint64 Count, void *Buffer) { int ret; Uint offset; @@ -751,7 +748,7 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) Uint16 base; // Check if the count is small enough - if(Count > MAX_DMA_SECTORS) return -1; + if(Count > MAX_DMA_SECTORS) return 0; // Get exclusive access to the disk controller LOCK( &giaATA_ControllerLock[ cont ] ); @@ -808,9 +805,9 @@ int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer) } /** - * \fn void ATA_IRQHandlerPri(void) + * \fn void ATA_IRQHandlerPri(int unused) */ -void ATA_IRQHandlerPri(void) +void ATA_IRQHandlerPri(int unused) { Uint8 val; @@ -825,9 +822,9 @@ void ATA_IRQHandlerPri(void) } /** - * \fn void ATA_IRQHandlerSec(void) + * \fn void ATA_IRQHandlerSec(int unused) */ -void ATA_IRQHandlerSec(void) +void ATA_IRQHandlerSec(int unused) { Uint8 val; // IRQ bit set for Secondary Controller