feat: make kernel architecture-agnostic; primitive work on arm port
This commit is contained in:
1 parent
dab7d5427b
commit
1bae77ec84
164 files changed
+3664
-1641
No files matched your search
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "E1000E.hpp"
|
||||
#include <Arch/Cpu.hpp>
|
||||
#include <Pci/Pci.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <CppLib/Stream.hpp>
|
||||
@@ -12,8 +13,7 @@
|
||||
#include <Memory/Paging.hpp>
|
||||
#include <Memory/PageFrameAllocator.hpp>
|
||||
#include <Libraries/Memory.hpp>
|
||||
#include <Hal/Apic/Interrupts.hpp>
|
||||
#include <Hal/Apic/IoApic.hpp>
|
||||
#include <Arch/Interrupts.hpp>
|
||||
#include <CppLib/Spinlock.hpp>
|
||||
#include <atomic>
|
||||
|
||||
@@ -80,9 +80,7 @@ namespace Drivers::Net::E1000E {
|
||||
static constexpr uint32_t g_deviceTableSize = sizeof(g_deviceTable) / sizeof(g_deviceTable[0]);
|
||||
|
||||
// MSI configuration
|
||||
static constexpr uint8_t MSI_IRQ = 24; // IRQ slot 24 = vector 56 (first MSI slot)
|
||||
static constexpr uint32_t MSI_VECTOR = 56; // IRQ_VECTOR_BASE + MSI_IRQ
|
||||
static constexpr uint32_t MSI_ADDR_BASE = 0xFEE00000; // Local APIC message address range
|
||||
static constexpr uint8_t MSI_IRQ = 24; // first MSI IRQ slot
|
||||
|
||||
// Driver state
|
||||
static bool g_initialized = false;
|
||||
@@ -434,17 +432,9 @@ namespace Drivers::Net::E1000E {
|
||||
uint16_t msgCtrl = Pci::LegacyRead16(bus, dev, func, cap + 2);
|
||||
bool is64bit = (msgCtrl & (1 << 7)) != 0;
|
||||
|
||||
// Write Message Address (cap+4): BSP APIC ID 0, physical destination, fixed delivery
|
||||
Pci::LegacyWrite32(bus, dev, func, cap + 4, MSI_ADDR_BASE);
|
||||
|
||||
// Write Message Data (vector number, edge-triggered, fixed delivery)
|
||||
if (is64bit) {
|
||||
// 64-bit: Upper Address at cap+8, Data at cap+12
|
||||
Pci::LegacyWrite32(bus, dev, func, cap + 8, 0);
|
||||
Pci::LegacyWrite16(bus, dev, func, cap + 12, MSI_VECTOR);
|
||||
} else {
|
||||
// 32-bit: Data at cap+8
|
||||
Pci::LegacyWrite16(bus, dev, func, cap + 8, MSI_VECTOR);
|
||||
// Message Address/Data: IRQ slot MSI_IRQ on the boot CPU
|
||||
if (!Pci::WriteMsiMessage(bus, dev, func, cap, MSI_IRQ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enable MSI: set bit 0 (MSI Enable), clear bits 6:4 (single message)
|
||||
@@ -458,10 +448,9 @@ namespace Drivers::Net::E1000E {
|
||||
Pci::LegacyWrite16(bus, dev, func, (uint8_t)Pci::PCI_REG_COMMAND, pciCmd);
|
||||
|
||||
// Register the interrupt handler for MSI vector
|
||||
Hal::RegisterIrqHandler(MSI_IRQ, HandleInterrupt);
|
||||
Arch::RegisterIrqHandler(MSI_IRQ, HandleInterrupt);
|
||||
|
||||
KernelLogStream(OK, "E1000E") << "MSI enabled: vector " << base::dec << (uint64_t)MSI_VECTOR
|
||||
<< " (IRQ slot " << (uint64_t)MSI_IRQ << ")" << (is64bit ? " [64-bit]" : " [32-bit]");
|
||||
KernelLogStream(OK, "E1000E") << "MSI enabled: IRQ slot " << base::dec << (uint64_t)MSI_IRQ << (is64bit ? " [64-bit]" : " [32-bit]");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -545,7 +534,7 @@ namespace Drivers::Net::E1000E {
|
||||
WriteReg(REG_CTRL, ctrl | CTRL_RST);
|
||||
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
asm volatile("" ::: "memory");
|
||||
Arch::CompilerBarrier();
|
||||
}
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
if (!(ReadReg(REG_CTRL) & CTRL_RST)) break;
|
||||
@@ -592,8 +581,8 @@ namespace Drivers::Net::E1000E {
|
||||
(uint8_t)Pci::PCI_REG_COMMAND);
|
||||
Pci::LegacyWrite16(bus, device, function,
|
||||
(uint8_t)Pci::PCI_REG_COMMAND, command & ~Pci::PCI_CMD_INTX_DISABLE);
|
||||
Hal::RegisterIrqHandler(g_irqLine, HandleInterrupt);
|
||||
Hal::IoApic::UnmaskIrq(Hal::IoApic::GetGsiForIrq(g_irqLine));
|
||||
Arch::RegisterIrqHandler(g_irqLine, HandleInterrupt);
|
||||
Arch::EnableLegacyIrq(g_irqLine);
|
||||
WriteReg(REG_IMS, RX_INTERRUPT_MASK | ICR_LSC);
|
||||
} else {
|
||||
KernelLogStream(WARNING, "E1000E") << "No MSI or legacy IRQ available, using polling mode";
|
||||
|
||||
Reference in new issue
Block a user