mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:47:35 +00:00
Kernel: Replace IRQHandler with the new InterruptHandler class
System components that need an IRQ handling are now inheriting the InterruptHandler class. In addition to that, the initialization process of PATAChannel was changed to fit the changes. PATAChannel, E1000NetworkAdapter and RTL8139NetworkAdapter are now inheriting from PCI::Device instead of InterruptHandler directly.
This commit is contained in:
parent
1ee37245cd
commit
6c72736b26
29 changed files with 193 additions and 169 deletions
|
@ -135,24 +135,23 @@ OwnPtr<E1000NetworkAdapter> E1000NetworkAdapter::autodetect()
|
|||
return make<E1000NetworkAdapter>(found_address, irq);
|
||||
}
|
||||
|
||||
E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 irq)
|
||||
: IRQHandler(irq)
|
||||
, m_pci_address(pci_address)
|
||||
E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 interrupt_vector)
|
||||
: PCI::Device(pci_address, interrupt_vector)
|
||||
{
|
||||
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());
|
||||
|
||||
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: P%x\n", PCI::get_BAR0(get_pci_address()) & 0xfffffffc);
|
||||
kprintf("E1000: MMIO base size: %u bytes\n", mmio_base_size);
|
||||
kprintf("E1000: Interrupt line: %u\n", m_interrupt_line);
|
||||
detect_eeprom();
|
||||
|
@ -171,14 +170,14 @@ E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 irq)
|
|||
out32(REG_IMASK, 0xff & ~4);
|
||||
in32(0xc0);
|
||||
|
||||
enable_irq();
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
E1000NetworkAdapter::~E1000NetworkAdapter()
|
||||
{
|
||||
}
|
||||
|
||||
void E1000NetworkAdapter::handle_irq()
|
||||
void E1000NetworkAdapter::handle_interrupt()
|
||||
{
|
||||
out32(REG_IMASK, 0x1);
|
||||
|
||||
|
@ -373,14 +372,14 @@ u32 E1000NetworkAdapter::in32(u16 address)
|
|||
|
||||
void E1000NetworkAdapter::send_raw(const u8* data, int length)
|
||||
{
|
||||
disable_irq();
|
||||
disable_interrupts();
|
||||
u32 tx_current = in32(REG_TXDESCTAIL);
|
||||
#ifdef E1000_DEBUG
|
||||
kprintf("E1000: Sending packet (%d bytes)\n", length);
|
||||
#endif
|
||||
auto& descriptor = m_tx_descriptors[tx_current];
|
||||
ASSERT(length <= 8192);
|
||||
auto *vptr = (void*)(descriptor.addr + 0xc0000000);
|
||||
auto* vptr = (void*)(descriptor.addr + 0xc0000000);
|
||||
memcpy(vptr, data, length);
|
||||
descriptor.length = length;
|
||||
descriptor.status = 0;
|
||||
|
@ -391,7 +390,7 @@ void E1000NetworkAdapter::send_raw(const u8* data, int length)
|
|||
tx_current = (tx_current + 1) % number_of_tx_descriptors;
|
||||
out32(REG_TXDESCTAIL, tx_current);
|
||||
cli();
|
||||
enable_irq();
|
||||
enable_interrupts();
|
||||
for (;;) {
|
||||
if (descriptor.status) {
|
||||
sti();
|
||||
|
|
|
@ -27,23 +27,23 @@
|
|||
#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>
|
||||
|
||||
class E1000NetworkAdapter final : public NetworkAdapter
|
||||
, public IRQHandler {
|
||||
, public PCI::Device {
|
||||
public:
|
||||
static OwnPtr<E1000NetworkAdapter> autodetect();
|
||||
|
||||
E1000NetworkAdapter(PCI::Address, u8 irq);
|
||||
E1000NetworkAdapter(PCI::Address, u8 interrupt_vector);
|
||||
virtual ~E1000NetworkAdapter() override;
|
||||
|
||||
virtual void send_raw(const u8*, int) override;
|
||||
virtual bool link_up() override;
|
||||
|
||||
private:
|
||||
virtual void handle_irq() override;
|
||||
virtual void handle_interrupt() override;
|
||||
virtual const char* class_name() const override { return "E1000NetworkAdapter"; }
|
||||
|
||||
struct [[gnu::packed]] e1000_rx_desc
|
||||
|
@ -86,7 +86,6 @@ private:
|
|||
|
||||
void receive();
|
||||
|
||||
PCI::Address m_pci_address;
|
||||
u16 m_io_base { 0 };
|
||||
VirtualAddress m_mmio_base;
|
||||
OwnPtr<Region> m_mmio_region;
|
||||
|
|
|
@ -139,18 +139,17 @@ OwnPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::autodetect()
|
|||
return make<RTL8139NetworkAdapter>(found_address, irq);
|
||||
}
|
||||
|
||||
RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address pci_address, u8 irq)
|
||||
: IRQHandler(irq)
|
||||
, m_pci_address(pci_address)
|
||||
RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address pci_address, u8 interrupt_vector)
|
||||
: PCI::Device(pci_address, interrupt_vector)
|
||||
{
|
||||
set_interface_name("rtl8139");
|
||||
|
||||
kprintf("RTL8139: Found at PCI address %b:%b:%b\n", pci_address.bus(), pci_address.slot(), 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);
|
||||
|
||||
|
@ -174,14 +173,14 @@ RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address pci_address, u8 irq)
|
|||
const auto& mac = mac_address();
|
||||
kprintf("RTL8139: MAC address: %s\n", mac.to_string().characters());
|
||||
|
||||
enable_irq();
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
RTL8139NetworkAdapter::~RTL8139NetworkAdapter()
|
||||
{
|
||||
}
|
||||
|
||||
void RTL8139NetworkAdapter::handle_irq()
|
||||
void RTL8139NetworkAdapter::handle_interrupt()
|
||||
{
|
||||
for (;;) {
|
||||
int status = in16(REG_ISR);
|
||||
|
|
|
@ -27,25 +27,25 @@
|
|||
#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>
|
||||
|
||||
#define RTL8139_TX_BUFFER_COUNT 4
|
||||
|
||||
class RTL8139NetworkAdapter final : public NetworkAdapter
|
||||
, public IRQHandler {
|
||||
, public PCI::Device {
|
||||
public:
|
||||
static OwnPtr<RTL8139NetworkAdapter> autodetect();
|
||||
|
||||
RTL8139NetworkAdapter(PCI::Address, u8 irq);
|
||||
RTL8139NetworkAdapter(PCI::Address, u8 interrupt_vector);
|
||||
virtual ~RTL8139NetworkAdapter() override;
|
||||
|
||||
virtual void send_raw(const u8*, int) override;
|
||||
virtual bool link_up() override { return m_link_up; }
|
||||
|
||||
private:
|
||||
virtual void handle_irq() override;
|
||||
virtual void handle_interrupt() override;
|
||||
virtual const char* class_name() const override { return "RTL8139NetworkAdapter"; }
|
||||
|
||||
void reset();
|
||||
|
@ -60,7 +60,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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue