Added PCI support

This commit is contained in:
Alex 2022-10-10 23:50:34 +03:00
parent 32a17c5e63
commit 19e810653a
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
4 changed files with 49 additions and 13 deletions

View File

@ -1,6 +1,14 @@
#include <pci.hpp>
#include <memory.hpp>
#include <power.hpp>
#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()

View File

@ -1,10 +1,7 @@
#include "kernel.h"
#include <interrupts.hpp>
#include <display.hpp>
#include <symbols.hpp>
#include <memory.hpp>
#include <power.hpp>
#include <string.h>
#include <printf.h>
#include <time.hpp>
@ -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();
}

View File

@ -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();

View File

@ -2,9 +2,22 @@
#define __FENNIX_KERNEL_KERNEL_H__
#include <types.h>
#include <boot/binfo.h>
#ifdef __cplusplus
#include <display.hpp>
#include <symbols.hpp>
#include <power.hpp>
#include <pci.hpp>
#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);