Permalink
Browse files

Files for part 11, https://www.youtube.com/watch?v=yqjDYF4NCXg

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 740241a commit f6a0fc8f41b1c04b3e835c1b19c776c80ec76e82
Showing with 115 additions and 4 deletions.
  1. +22 −1 include/hardwarecommunication/pci.h
  2. +92 −2 src/hardwarecommunication/pci.cpp
  3. +1 −1 src/kernel.cpp
@@ -12,6 +12,25 @@ namespace myos
namespace hardwarecommunication
{
enum BaseAddressRegisterType
{
MemoryMapping = 0,
InputOutput = 1
};
class BaseAddressRegister
{
public:
bool prefetchable;
myos::common::uint8_t* address;
myos::common::uint32_t size;
BaseAddressRegisterType type;
};
class PeripheralComponentInterconnectDeviceDescriptor
{
public:
@@ -50,8 +69,10 @@ namespace myos
void Write(myos::common::uint16_t bus, myos::common::uint16_t device, myos::common::uint16_t function, myos::common::uint32_t registeroffset, myos::common::uint32_t value);
bool DeviceHasFunctions(myos::common::uint16_t bus, myos::common::uint16_t device);
void SelectDrivers(myos::drivers::DriverManager* driverManager);
void SelectDrivers(myos::drivers::DriverManager* driverManager, myos::hardwarecommunication::InterruptManager* interrupts);
myos::drivers::Driver* GetDriver(PeripheralComponentInterconnectDeviceDescriptor dev, myos::hardwarecommunication::InterruptManager* interrupts);
PeripheralComponentInterconnectDeviceDescriptor GetDeviceDescriptor(myos::common::uint16_t bus, myos::common::uint16_t device, myos::common::uint16_t function);
BaseAddressRegister GetBaseAddressRegister(myos::common::uint16_t bus, myos::common::uint16_t device, myos::common::uint16_t function, myos::common::uint16_t bar);
};
}
@@ -64,7 +64,7 @@ bool PeripheralComponentInterconnectController::DeviceHasFunctions(common::uint1
void printf(char* str);
void printfHex(uint8_t);
void PeripheralComponentInterconnectController::SelectDrivers(DriverManager* driverManager)
void PeripheralComponentInterconnectController::SelectDrivers(DriverManager* driverManager, myos::hardwarecommunication::InterruptManager* interrupts)
{
for(int bus = 0; bus < 8; bus++)
{
@@ -76,7 +76,20 @@ void PeripheralComponentInterconnectController::SelectDrivers(DriverManager* dri
PeripheralComponentInterconnectDeviceDescriptor dev = GetDeviceDescriptor(bus, device, function);
if(dev.vendor_id == 0x0000 || dev.vendor_id == 0xFFFF)
break;
continue;
for(int barNum = 0; barNum < 6; barNum++)
{
BaseAddressRegister bar = GetBaseAddressRegister(bus, device, function, barNum);
if(bar.address && (bar.type == InputOutput))
dev.portBase = (uint32_t)bar.address;
Driver* driver = GetDriver(dev, interrupts);
if(driver != 0)
driverManager->AddDriver(driver);
}
printf("PCI BUS ");
printfHex(bus & 0xFF);
@@ -100,6 +113,83 @@ void PeripheralComponentInterconnectController::SelectDrivers(DriverManager* dri
}
BaseAddressRegister PeripheralComponentInterconnectController::GetBaseAddressRegister(uint16_t bus, uint16_t device, uint16_t function, uint16_t bar)
{
BaseAddressRegister result;
uint32_t headertype = Read(bus, device, function, 0x0E) & 0x7F;
int maxBARs = 6 - (4*headertype);
if(bar >= maxBARs)
return result;
uint32_t bar_value = Read(bus, device, function, 0x10 + 4*bar);
result.type = (bar_value & 0x1) ? InputOutput : MemoryMapping;
uint32_t temp;
if(result.type == MemoryMapping)
{
switch((bar_value >> 1) & 0x3)
{
case 0: // 32 Bit Mode
case 1: // 20 Bit Mode
case 2: // 64 Bit Mode
break;
}
}
else // InputOutput
{
result.address = (uint8_t*)(bar_value & ~0x3);
result.prefetchable = false;
}
return result;
}
Driver* PeripheralComponentInterconnectController::GetDriver(PeripheralComponentInterconnectDeviceDescriptor dev, InterruptManager* interrupts)
{
switch(dev.vendor_id)
{
case 0x1022: // AMD
switch(dev.device_id)
{
case 0x2000: // am79c973
printf("AMD am79c973 ");
break;
}
break;
case 0x8086: // Intel
break;
}
switch(dev.class_id)
{
case 0x03: // graphics
switch(dev.subclass_id)
{
case 0x00: // VGA
printf("VGA ");
break;
}
break;
}
return 0;
}
PeripheralComponentInterconnectDeviceDescriptor PeripheralComponentInterconnectController::GetDeviceDescriptor(uint16_t bus, uint16_t device, uint16_t function)
{
View
@@ -149,7 +149,7 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
drvManager.AddDriver(&mouse);
PeripheralComponentInterconnectController PCIController;
PCIController.SelectDrivers(&drvManager);
PCIController.SelectDrivers(&drvManager, &interrupts);
printf("Initializing Hardware, Stage 2\n");
drvManager.ActivateAll();

0 comments on commit f6a0fc8

Please sign in to comment.