Bitmap filling done
[tpg/acess2.git] / Modules / Storage / ATA / main.c
index 2bb151d..376563b 100644 (file)
@@ -2,7 +2,7 @@
  * Acess2 IDE Harddisk Driver
  * - main.c
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <acess.h>
 #include <modules.h>
 #include <vfs.h>
@@ -76,7 +76,7 @@ void  ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value);
 void   ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value);
 
 // === GLOBALS ===
-MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, NULL);
+MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, "PCI", NULL);
 tDevFS_Driver  gATA_DriverInfo = {
        NULL, "ata",
        {
@@ -140,7 +140,8 @@ int ATA_SetupIO()
        LOG("ent = %i", ent);
        gATA_BusMasterBase = PCI_GetBAR4( ent );
        if( gATA_BusMasterBase == 0 ) {
-               Warning("It seems that there is no Bus Master Controller on this machine. Get one");
+               Log_Warning("ATA", "It seems that there is no Bus Master Controller on this machine. Get one");
+               // TODO: Use PIO mode instead
                LEAVE('i', MODULE_ERR_NOTNEEDED);
                return MODULE_ERR_NOTNEEDED;
        }
@@ -149,9 +150,9 @@ int ATA_SetupIO()
        if( !(gATA_BusMasterBase & 1) )
        {
                if( gATA_BusMasterBase < 0x100000 )
-                       gATA_BusMasterBasePtr = (void*)(0xC0000000|gATA_BusMasterBase);
+                       gATA_BusMasterBasePtr = (void*)(KERNEL_BASE | (tVAddr)gATA_BusMasterBase);
                else
-                       gATA_BusMasterBasePtr = (void*)( MM_MapHWPage( gATA_BusMasterBase, 1 ) + (gATA_BusMasterBase&0xFFF) );
+                       gATA_BusMasterBasePtr = (void*)( MM_MapHWPages( gATA_BusMasterBase, 1 ) + (gATA_BusMasterBase&0xFFF) );
                LOG("gATA_BusMasterBasePtr = %p", gATA_BusMasterBasePtr);
        }
        else {
@@ -163,15 +164,15 @@ int ATA_SetupIO()
        IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri );
        IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec );
 
-       gATA_PRDTs[0].PBufAddr = MM_GetPhysAddr( (Uint)&gATA_Buffers[0] );
-       gATA_PRDTs[1].PBufAddr = MM_GetPhysAddr( (Uint)&gATA_Buffers[1] );
+       gATA_PRDTs[0].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[0] );
+       gATA_PRDTs[1].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[1] );
 
        LOG("gATA_PRDTs = {PBufAddr: 0x%x, PBufAddr: 0x%x}", gATA_PRDTs[0].PBufAddr, gATA_PRDTs[1].PBufAddr);
 
-       addr = MM_GetPhysAddr( (Uint)&gATA_PRDTs[0] );
+       addr = MM_GetPhysAddr( (tVAddr)&gATA_PRDTs[0] );
        LOG("addr = 0x%x", addr);
        ATA_int_BusMasterWriteDWord(4, addr);
-       addr = MM_GetPhysAddr( (Uint)&gATA_PRDTs[1] );
+       addr = MM_GetPhysAddr( (tVAddr)&gATA_PRDTs[1] );
        LOG("addr = 0x%x", addr);
        ATA_int_BusMasterWriteDWord(12, addr);
 
@@ -237,9 +238,11 @@ void ATA_SetupVFS()
  */
 int ATA_ScanDisk(int Disk)
 {
-       Uint16  buf[256];
-       tIdentify       *identify = (void*)buf;
-       tMBR    *mbr = (void*)buf;
+       union {
+               Uint16  buf[256];
+               tIdentify       identify;
+               tMBR    mbr;
+       }       data;
        Uint16  base;
        Uint8   val;
         int    i;
@@ -274,13 +277,13 @@ int ATA_ScanDisk(int Disk)
        }
 
        // Read Data
-       for(i=0;i<256;i++)      buf[i] = inw(base);
+       for(i=0;i<256;i++)      data.buf[i] = inw(base);
 
        // Populate Disk Structure
-       if(identify->Sectors48 != 0)
-               gATA_Disks[ Disk ].Sectors = identify->Sectors48;
+       if(data.identify.Sectors48 != 0)
+               gATA_Disks[ Disk ].Sectors = data.identify.Sectors48;
        else
-               gATA_Disks[ Disk ].Sectors = identify->Sectors28;
+               gATA_Disks[ Disk ].Sectors = data.identify.Sectors28;
 
 
        LOG("gATA_Disks[ Disk ].Sectors = 0x%x", gATA_Disks[ Disk ].Sectors);
@@ -317,10 +320,10 @@ int ATA_ScanDisk(int Disk)
        // --- Scan Partitions ---
        LOG("Reading MBR");
        // Read Boot Sector
-       ATA_ReadDMA( Disk, 0, 1, mbr );
+       ATA_ReadDMA( Disk, 0, 1, &data.mbr );
 
        // Check for a GPT table
-       if(mbr->Parts[0].SystemID == 0xEE)
+       if(data.mbr.Parts[0].SystemID == 0xEE)
                ATA_ParseGPT(Disk);
        else    // No? Just parse the MBR
                ATA_ParseMBR(Disk);

UCC git Repository :: git.ucc.asn.au