mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
Kernel: Update Network adapter classes to use the PCI::Device class
Those classes will inherit from the PCI::Device class, thus, they can still implement IRQ handling.
This commit is contained in:
parent
73a7e5875e
commit
d83a3eff1f
4 changed files with 20 additions and 25 deletions
|
@ -134,21 +134,20 @@ void E1000NetworkAdapter::detect(const PCI::Address& address)
|
|||
}
|
||||
|
||||
E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 irq)
|
||||
: IRQHandler(irq)
|
||||
, m_pci_address(pci_address)
|
||||
: PCI::Device(pci_address, irq)
|
||||
{
|
||||
set_interface_name("e1k");
|
||||
|
||||
kprintf("E1000: Found at PCI address @ %w:%b:%b.%b\n", pci_address.seg(), pci_address.bus(), pci_address.slot(), pci_address.function());
|
||||
kprintf("E1000: Found at PCI address @ %w:%b:%b.%b\n", get_pci_address().seg(), get_pci_address().bus(), get_pci_address().slot(), get_pci_address().function());
|
||||
|
||||
enable_bus_mastering(m_pci_address);
|
||||
enable_bus_mastering(get_pci_address());
|
||||
|
||||
size_t mmio_base_size = PCI::get_BAR_Space_Size(pci_address, 0);
|
||||
m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(m_pci_address))), PAGE_ROUND_UP(mmio_base_size), "E1000 MMIO", Region::Access::Read | Region::Access::Write, false, false);
|
||||
m_mmio_region = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR0(get_pci_address()))), PAGE_ROUND_UP(mmio_base_size), "E1000 MMIO", Region::Access::Read | Region::Access::Write, false, false);
|
||||
m_mmio_base = m_mmio_region->vaddr();
|
||||
m_use_mmio = true;
|
||||
m_io_base = PCI::get_BAR1(m_pci_address) & ~1;
|
||||
m_interrupt_line = PCI::get_interrupt_line(m_pci_address);
|
||||
m_io_base = PCI::get_BAR1(get_pci_address()) & ~1;
|
||||
m_interrupt_line = PCI::get_interrupt_line(get_pci_address());
|
||||
kprintf("E1000: IO port base: %w\n", m_io_base);
|
||||
kprintf("E1000: MMIO base: P%x\n", PCI::get_BAR0(pci_address) & 0xfffffffc);
|
||||
kprintf("E1000: MMIO base size: %u bytes\n", mmio_base_size);
|
||||
|
@ -176,7 +175,7 @@ E1000NetworkAdapter::~E1000NetworkAdapter()
|
|||
{
|
||||
}
|
||||
|
||||
void E1000NetworkAdapter::handle_irq()
|
||||
void E1000NetworkAdapter::handle_irq(RegisterState&)
|
||||
{
|
||||
out32(REG_IMASK, 0x1);
|
||||
|
||||
|
|
|
@ -27,14 +27,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/IRQHandler.h>
|
||||
#include <Kernel/Interrupts/IRQHandler.h>
|
||||
#include <Kernel/Net/NetworkAdapter.h>
|
||||
#include <Kernel/PCI/Access.h>
|
||||
#include <Kernel/PCI/Device.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class E1000NetworkAdapter final : public NetworkAdapter
|
||||
, public IRQHandler {
|
||||
, public PCI::Device {
|
||||
public:
|
||||
static void detect(const PCI::Address&);
|
||||
|
||||
|
@ -45,7 +46,7 @@ public:
|
|||
virtual bool link_up() override;
|
||||
|
||||
private:
|
||||
virtual void handle_irq() override;
|
||||
virtual void handle_irq(RegisterState&) override;
|
||||
virtual const char* class_name() const override { return "E1000NetworkAdapter"; }
|
||||
|
||||
struct [[gnu::packed]] e1000_rx_desc
|
||||
|
@ -88,7 +89,6 @@ private:
|
|||
|
||||
void receive();
|
||||
|
||||
PCI::Address m_pci_address;
|
||||
u16 m_io_base { 0 };
|
||||
VirtualAddress m_mmio_base;
|
||||
OwnPtr<Region> m_mmio_region;
|
||||
|
@ -104,5 +104,4 @@ private:
|
|||
|
||||
WaitQueue m_wait_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -138,17 +138,16 @@ void RTL8139NetworkAdapter::detect(const PCI::Address& address)
|
|||
}
|
||||
|
||||
RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address pci_address, u8 irq)
|
||||
: IRQHandler(irq)
|
||||
, m_pci_address(pci_address)
|
||||
: PCI::Device(pci_address, irq)
|
||||
{
|
||||
set_interface_name("rtl8139");
|
||||
|
||||
kprintf("RTL8139: Found at PCI address %b:%b:%b\n", pci_address.bus(), pci_address.slot(), pci_address.function());
|
||||
kprintf("RTL8139: Found at PCI address %b:%b:%b\n", get_pci_address().bus(), get_pci_address().slot(), get_pci_address().function());
|
||||
|
||||
enable_bus_mastering(m_pci_address);
|
||||
enable_bus_mastering(get_pci_address());
|
||||
|
||||
m_io_base = PCI::get_BAR0(m_pci_address) & ~1;
|
||||
m_interrupt_line = PCI::get_interrupt_line(m_pci_address);
|
||||
m_io_base = PCI::get_BAR0(get_pci_address()) & ~1;
|
||||
m_interrupt_line = PCI::get_interrupt_line(get_pci_address());
|
||||
kprintf("RTL8139: IO port base: %w\n", m_io_base);
|
||||
kprintf("RTL8139: Interrupt line: %u\n", m_interrupt_line);
|
||||
|
||||
|
@ -179,7 +178,7 @@ RTL8139NetworkAdapter::~RTL8139NetworkAdapter()
|
|||
{
|
||||
}
|
||||
|
||||
void RTL8139NetworkAdapter::handle_irq()
|
||||
void RTL8139NetworkAdapter::handle_irq(RegisterState&)
|
||||
{
|
||||
for (;;) {
|
||||
int status = in16(REG_ISR);
|
||||
|
|
|
@ -27,16 +27,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Kernel/IRQHandler.h>
|
||||
#include <Kernel/Net/NetworkAdapter.h>
|
||||
#include <Kernel/PCI/Access.h>
|
||||
#include <Kernel/PCI/Device.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
#define RTL8139_TX_BUFFER_COUNT 4
|
||||
|
||||
class RTL8139NetworkAdapter final : public NetworkAdapter
|
||||
, public IRQHandler {
|
||||
, public PCI::Device {
|
||||
public:
|
||||
static void detect(const PCI::Address&);
|
||||
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
virtual bool link_up() override { return m_link_up; }
|
||||
|
||||
private:
|
||||
virtual void handle_irq() override;
|
||||
virtual void handle_irq(RegisterState&) override;
|
||||
virtual const char* class_name() const override { return "RTL8139NetworkAdapter"; }
|
||||
|
||||
void reset();
|
||||
|
@ -62,7 +62,6 @@ private:
|
|||
u16 in16(u16 address);
|
||||
u32 in32(u16 address);
|
||||
|
||||
PCI::Address m_pci_address;
|
||||
u16 m_io_base { 0 };
|
||||
u8 m_interrupt_line { 0 };
|
||||
u32 m_rx_buffer_addr { 0 };
|
||||
|
@ -72,5 +71,4 @@ private:
|
|||
u32 m_packet_buffer { 0 };
|
||||
bool m_link_up { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue