From: John Hodge Date: Wed, 26 Jun 2013 12:44:12 +0000 (+0800) Subject: Modules/ATA - (untested) Cleanup to BM address handling X-Git-Tag: rel0.15~401 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d111142728fad9f4ab3fa2d1729d59b1892b5ade;p=tpg%2Facess2.git Modules/ATA - (untested) Cleanup to BM address handling --- diff --git a/KernelLand/Modules/Storage/ATA/io.c b/KernelLand/Modules/Storage/ATA/io.c index da0447a0..b1b96e6f 100644 --- a/KernelLand/Modules/Storage/ATA/io.c +++ b/KernelLand/Modules/Storage/ATA/io.c @@ -124,7 +124,7 @@ int ATA_SetupIO(void) LOG("ent = %i", ent); gATA_BusMasterBase = PCI_GetBAR(ent, 4); if( gATA_BusMasterBase == 0 ) { - Log_Warning("ATA", "It seems that there is no Bus Master Controller on this machine. Get one"); + Log_Warning("ATA", "Unable to find a Bus Master DMA controller"); // TODO: Use PIO mode instead LEAVE('i', MODULE_ERR_NOTNEEDED); return MODULE_ERR_NOTNEEDED; @@ -134,17 +134,16 @@ int ATA_SetupIO(void) LOG("IRQ = %i", PCI_GetIRQ(ent)); // Map memory - if( !(gATA_BusMasterBase & 1) ) + if( gATA_BusMasterBase & 1 ) { - if( gATA_BusMasterBase < 0x100000 ) - gATA_BusMasterBasePtr = (void*)(KERNEL_BASE | (tVAddr)gATA_BusMasterBase); - else - gATA_BusMasterBasePtr = (void*)( MM_MapHWPages( gATA_BusMasterBase, 1 ) + (gATA_BusMasterBase&0xFFF) ); - LOG("gATA_BusMasterBasePtr = %p", gATA_BusMasterBasePtr); + gATA_BusMasterBase &= ~1; + LOG("gATA_BusMasterBase = IO 0x%x", gATA_BusMasterBase); } - else { - // Bit 0 is left set as a flag to other functions - LOG("gATA_BusMasterBase = IO 0x%x", gATA_BusMasterBase & ~1); + else + { + // MMIO + gATA_BusMasterBasePtr = MM_MapHWPages( gATA_BusMasterBase, 1 ) + (gATA_BusMasterBase&0xFFF); + LOG("gATA_BusMasterBasePtr = %p", gATA_BusMasterBasePtr); } // Register IRQs and get Buffers @@ -534,10 +533,10 @@ void ATA_IRQHandlerSec(int UNUSED(IRQ), void *UNUSED(Ptr)) */ Uint8 ATA_int_BusMasterReadByte(int Ofs) { - if( gATA_BusMasterBase & 1 ) - return inb( (gATA_BusMasterBase & ~1) + Ofs ); - else + if( gATA_BusMasterBasePtr ) return *(Uint8*)(gATA_BusMasterBasePtr + Ofs); + else + return inb( gATA_BusMasterBase + Ofs ); } /** @@ -546,10 +545,10 @@ Uint8 ATA_int_BusMasterReadByte(int Ofs) */ Uint32 ATA_int_BusMasterReadDWord(int Ofs) { - if( gATA_BusMasterBase & 1 ) - return ind( (gATA_BusMasterBase & ~1) + Ofs ); - else + if( gATA_BusMasterBasePtr ) return *(Uint32*)(gATA_BusMasterBasePtr + Ofs); + else + return ind( gATA_BusMasterBase + Ofs ); } /** @@ -559,10 +558,10 @@ Uint32 ATA_int_BusMasterReadDWord(int Ofs) */ void ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value) { - if( gATA_BusMasterBase & 1 ) - outb( (gATA_BusMasterBase & ~1) + Ofs, Value ); - else + if( gATA_BusMasterBasePtr ) *(Uint8*)(gATA_BusMasterBasePtr + Ofs) = Value; + else + outb( gATA_BusMasterBase + Ofs, Value ); } /** @@ -572,8 +571,8 @@ void ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value) */ void ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value) { - if( gATA_BusMasterBase & 1 ) - outd( (gATA_BusMasterBase & ~1) + Ofs, Value ); - else + if( gATA_BusMasterBasePtr ) *(Uint32*)(gATA_BusMasterBasePtr + Ofs) = Value; + else + outd( gATA_BusMasterBase + Ofs, Value ); }