BarinkOS/source/kernel/drivers/ide/ide.h

99 lines
2.4 KiB
C
Raw Normal View History

#pragma once
#include <stdint.h>
#include "../pci/pciDevice.h"
#include "../pci/pci.h"
#include "../../terminal/kterm.h"
#include "ideCommands.h"
#include "sampleIDE.h"
#define IS_BIT_SET(x, bit) ((x >> bit & 0x1) == 1)
2021-11-30 23:00:45 +00:00
IDEChannelRegisters channels[2];
IDE_DEVICE ide_devices[4];
inline void CheckProgIF(uint8_t ProgIF){
if( IS_BIT_SET(ProgIF, 0) ) // Is the 0th bit set
{
printf ("Primary Channel is in PCI native mode\n");
} else{
printf("Primary Channel is in Compatibility mode\n");
}
if( IS_BIT_SET(ProgIF, 1)){
printf("Bit 0 can be modified\n");
}else{
printf("Bit 0 cannot be modified\n");
}
if( IS_BIT_SET(ProgIF, 2)){
printf("Secondary channel is in PCI native mode\n");
}else{
printf("Secondary channel is in Compatibility mode\n");
}
if( IS_BIT_SET(ProgIF, 3)){
printf("Bit 2 can be modified\n");
}else{
printf("Bit 2 cannot be modified\n");
}
if( IS_BIT_SET(ProgIF , 7)){
printf("This is a bus master IDE Controller\n");
} else{
printf("This controller doesn't support DMA!\n");
}
}
inline void TestIDEController(){
// Do stuff
printf("Testing IDE controllers\n");
// NOTE: Testing done with a hard coded known PCI addres
// Of an intel PIIX3 IDE Controller
int bus = 0;
int device =1 , function = 1;
PCIBusAddress IDEControllerPCIAddress = PCIBusAddress{bus,device, function};
2023-02-17 13:42:42 +00:00
uint8_t ProgIF = PCI::GetProgIF(IDEControllerPCIAddress);
printf( "ProgIF: 0x%x\n" ,ProgIF);
//CheckProgIF(ProgIF);
// For this test will just assume all bits are set
// the CheckProgIF can check but on the test machine all bits are set anyways
uint32_t BAR0,BAR1,BAR2,BAR3, BAR4;
2023-02-17 13:42:42 +00:00
BAR0 = PCI::ReadBAR(IDEControllerPCIAddress, 0);
2023-02-17 13:42:42 +00:00
BAR1 = PCI::ReadBAR(IDEControllerPCIAddress, 1);
2023-02-17 13:42:42 +00:00
BAR2 = PCI::ReadBAR(IDEControllerPCIAddress, 2);
2023-02-17 13:42:42 +00:00
BAR3 = PCI::ReadBAR(IDEControllerPCIAddress, 3);
2023-02-17 13:42:42 +00:00
BAR4 = PCI::ReadBAR(IDEControllerPCIAddress, 4);
// All bars are return 0xffffff for some as of yet mysterious reason!
printf( "BAR 0: 0x%x\n", BAR0);
printf( "BAR 1: 0x%x\n", BAR1);
printf( "BAR 2: 0x%x\n", BAR2);
printf( "BAR 3: 0x%x\n", BAR3);
printf( "BAR 4: 0x%x\n", BAR4);
init_IDE(BAR0, BAR1, BAR2, BAR3, BAR4);
// Read Something from disc
unsigned int maxByteCount = 20 ;
void* MDA_buffer = (void*)0xC0000000;
}