From 19e810653a3c6be3bd746922f898e93b172e11c5 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Oct 2022 23:50:34 +0300 Subject: [PATCH] Added PCI support --- Core/PeripheralComponentInterconnect.cpp | 40 ++++++++++++++++++------ Kernel.cpp | 6 ++-- include/power.hpp | 3 ++ kernel.h | 13 ++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Core/PeripheralComponentInterconnect.cpp b/Core/PeripheralComponentInterconnect.cpp index ea432aa..780b7ca 100644 --- a/Core/PeripheralComponentInterconnect.cpp +++ b/Core/PeripheralComponentInterconnect.cpp @@ -1,6 +1,14 @@ #include #include +#include +#if defined(__amd64__) +#include "../Architecture/amd64/acpi.hpp" +#elif defined(__i386__) +#elif defined(__aarch64__) +#endif + +#include "../kernel.h" namespace PCI { @@ -703,6 +711,7 @@ namespace PCI switch (SubclassCode) { case 0x00: + { switch (ProgIF) { case 0x00: @@ -712,7 +721,10 @@ namespace PCI default: break; } + break; + } case 0x03: + { switch (ProgIF) { case 0x00: @@ -730,6 +742,8 @@ namespace PCI default: break; } + break; + } default: break; } @@ -826,16 +840,22 @@ namespace PCI PCI::PCI() { - // int Entries = ((MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig); - // for (int t = 0; t < Entries; t++) - // { - // DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uint64_t)MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t)); - // Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW); - // trace("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress, - // NewDeviceConfig->StartBus, NewDeviceConfig->EndBus); - // for (uint64_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++) - // EnumerateBus(NewDeviceConfig->BaseAddress, Bus); - // } +#if defined(__amd64__) + int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig); + for (int t = 0; t < Entries; t++) + { + DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uint64_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t)); + Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW); + trace("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress, + NewDeviceConfig->StartBus, NewDeviceConfig->EndBus); + for (uint64_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++) + EnumerateBus(NewDeviceConfig->BaseAddress, Bus); + } +#elif defined(__i386__) + error("PCI not implemented on i386"); +#elif defined(__aarch64__) + error("PCI not implemented on aarch64"); +#endif } PCI::~PCI() diff --git a/Kernel.cpp b/Kernel.cpp index 17e978e..00f4423 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -1,10 +1,7 @@ #include "kernel.h" #include -#include -#include #include -#include #include #include #include @@ -14,6 +11,7 @@ BootInfo *bInfo = nullptr; Video::Display *Display = nullptr; SymbolResolver::Symbols *KernelSymbolTable = nullptr; Power::Power *PowerManager = nullptr; +PCI::PCI *PCIManager = nullptr; // For the Display class. Printing on first buffer. extern "C" void putchar(char c) { Display->Print(c, 0); } @@ -58,6 +56,8 @@ EXTERNC void Entry(BootInfo *Info) KernelSymbolTable = new SymbolResolver::Symbols((uint64_t)Info->Kernel.FileBase); KPrint("Initializing Power Manager"); PowerManager = new Power::Power; + KPrint("Initializing PCI Manager"); + PCIManager = new PCI::PCI; while (1) CPU::Halt(); } diff --git a/include/power.hpp b/include/power.hpp index 3db9fd6..cdd0b11 100644 --- a/include/power.hpp +++ b/include/power.hpp @@ -14,6 +14,9 @@ namespace Power void *madt; public: + void *GetACPI() { return this->acpi; } + void *GetDSDT() { return this->dsdt; } + void *GetMADT() { return this->madt; } void Reboot(); void Shutdown(); Power(); diff --git a/kernel.h b/kernel.h index 55a47b2..5faf20c 100644 --- a/kernel.h +++ b/kernel.h @@ -2,9 +2,22 @@ #define __FENNIX_KERNEL_KERNEL_H__ #include + #include +#ifdef __cplusplus +#include +#include +#include +#include +#endif extern struct BootInfo *bInfo; +#ifdef __cplusplus +extern Video::Display *Display; +extern SymbolResolver::Symbols *KernelSymbolTable; +extern Power::Power *PowerManager; +extern PCI::PCI *PCIManager; +#endif EXTERNC void Entry(struct BootInfo *Info);