Kernel/PCI: Delete PCI::Device in its current form

I created this class a long time ago just to be able to quickly make a
PCI device to also represent an interrupt handler (because PCI devices
have this capability for most devices).
Then after a while I introduced the PCI::DeviceController, which is
really almost the same thing (a PCI device class that has Address member
in it), but is not tied to interrupts so it can have no interrupts, or
spawn interrupt handlers however it wants to seems fit.

However I decided it's time to say goodbye for this class for
a couple of reasons:
1. It made a whole bunch of weird patterns where you had a PCI::Device
and a PCI::DeviceController being used in the topic of implementation,
where originally, they meant to be used mutually exclusively (you
can't and really don't want to use both).
2. We can really make all the classes that inherit from PCI::Device
to inherit from IRQHandler at this point. Later on, when we have MSI
interrupts support, we can go further and untie things even more.
3. It makes it possible to simplify the VirtIO implementation to a great
extent. While this commit almost doesn't change it, future changes
can untangle some complexity in the VirtIO code.

For UHCIController, E1000NetworkAdapter, NE2000NetworkAdapter,
RTL8139NetworkAdapter, RTL8168NetworkAdapter, E1000ENetworkAdapter we
are simply making them to inherit the IRQHandler. This makes some sense,
because the first 3 devices will never support anything besides IRQs.
For the last 2, they might have MSI support, so when we start to utilize
those, we might need to untie these classes from IRQHandler and spawn
IRQHandler(s) or MSIHandler(s) as needed.

The VirtIODevice class is also a case where we currently need to use
both PCI::DeviceController and IRQHandler classes as parents, but it
could also be untied from the latter.
This commit is contained in:
Liav A 2021-08-21 06:55:25 +03:00 committed by Andreas Kling
parent d071ce352c
commit 7b9c3439ec
Notes: sideshowbarker 2024-07-18 05:21:52 +09:00
18 changed files with 37 additions and 82 deletions

View file

@ -256,7 +256,6 @@ class WindowedMMIOAccess;
class IOAccess;
class MMIOSegment;
class DeviceController;
class Device;
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Bus/PCI/Device.h>
namespace Kernel {
namespace PCI {
Device::Device(Address address)
: IRQHandler(get_interrupt_line(address))
, m_pci_address(address)
{
// FIXME: Register PCI device somewhere...
}
Device::Device(Address address, u8 interrupt_vector)
: IRQHandler(interrupt_vector)
, m_pci_address(address)
{
// FIXME: Register PCI device somewhere...
}
Device::~Device()
{
// FIXME: Unregister the device
}
}
}

View file

@ -1,26 +0,0 @@
/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/Interrupts/IRQHandler.h>
namespace Kernel {
class PCI::Device : public IRQHandler {
public:
Address pci_address() const { return m_pci_address; };
protected:
Device(Address pci_address);
Device(Address pci_address, u8 interrupt_vector);
~Device();
private:
Address m_pci_address;
};
}

View file

@ -92,7 +92,8 @@ KResult UHCIController::initialize()
}
UNMAP_AFTER_INIT UHCIController::UHCIController(PCI::Address address)
: PCI::Device(address)
: PCI::DeviceController(address)
, IRQHandler(PCI::get_interrupt_line(address))
, m_io_base(PCI::get_BAR4(pci_address()) & ~1)
{
}

View file

@ -10,12 +10,13 @@
#include <AK/Platform.h>
#include <AK/NonnullOwnPtr.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h>
#include <Kernel/Bus/USB/UHCI/UHCIDescriptorTypes.h>
#include <Kernel/Bus/USB/UHCI/UHCIRootHub.h>
#include <Kernel/Bus/USB/USBController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Memory/AnonymousVMObject.h>
#include <Kernel/Process.h>
#include <Kernel/Time/TimeManagement.h>
@ -24,7 +25,8 @@ namespace Kernel::USB {
class UHCIController final
: public USBController
, public PCI::Device {
, public PCI::DeviceController
, public IRQHandler {
static constexpr u8 MAXIMUM_NUMBER_OF_TDS = 128; // Upper pool limit. This consumes the second page we have allocated
static constexpr u8 MAXIMUM_NUMBER_OF_QHS = 64;
@ -109,5 +111,4 @@ private:
// Bitfield containing whether a given port should signal a change in suspend or not.
u8 m_port_suspend_change_statuses { 0 };
};
}

View file

@ -44,7 +44,8 @@ UNMAP_AFTER_INIT void VirtIO::detect()
}
UNMAP_AFTER_INIT VirtIODevice::VirtIODevice(PCI::Address address, String class_name)
: PCI::Device(address, PCI::get_interrupt_line(address))
: PCI::DeviceController(address)
, IRQHandler(PCI::get_interrupt_line(address))
, m_class_name(move(class_name))
, m_io_base(IOAddress(PCI::get_BAR0(pci_address()) & ~1))
{

View file

@ -8,7 +8,7 @@
#include <AK/NonnullOwnPtrVector.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/Bus/VirtIO/VirtIOQueue.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
@ -84,7 +84,9 @@ public:
static void detect();
};
class VirtIODevice : public PCI::Device {
class VirtIODevice
: public PCI::DeviceController
, public IRQHandler {
public:
virtual ~VirtIODevice() override;
@ -240,5 +242,4 @@ private:
bool m_did_setup_queues { false };
u32 m_notify_multiplier { 0 };
};
}

View file

@ -25,7 +25,6 @@ set(KERNEL_SOURCES
Arch/PC/BIOS.cpp
Arch/x86/SmapDisabler.h
Bus/PCI/Access.cpp
Bus/PCI/Device.cpp
Bus/PCI/DeviceController.cpp
Bus/PCI/IOAccess.cpp
Bus/PCI/MMIOAccess.cpp

View file

@ -6,7 +6,7 @@
#pragma once
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/Bus/PCI/IDs.h>
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Devices/SerialDevice.h>

View file

@ -9,7 +9,7 @@
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Net/E1000NetworkAdapter.h>

View file

@ -220,7 +220,8 @@ UNMAP_AFTER_INIT bool E1000NetworkAdapter::initialize()
}
UNMAP_AFTER_INIT E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address address, u8 irq)
: PCI::Device(address, irq)
: PCI::DeviceController(address)
, IRQHandler(irq)
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16), "E1000 RX Descriptors", Memory::Region::Access::ReadWrite))
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16), "E1000 TX Descriptors", Memory::Region::Access::ReadWrite))
{

View file

@ -8,7 +8,7 @@
#include <AK/OwnPtr.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Net/NetworkAdapter.h>
@ -17,7 +17,8 @@
namespace Kernel {
class E1000NetworkAdapter : public NetworkAdapter
, public PCI::Device {
, public PCI::DeviceController
, public IRQHandler {
public:
static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::Address);

View file

@ -161,7 +161,8 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
}
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)
: PCI::Device(address, irq)
: PCI::DeviceController(address)
, IRQHandler(irq)
, m_io_base(PCI::get_BAR0(pci_address()) & ~3)
{
set_interface_name(address);

View file

@ -8,15 +8,17 @@
#include <AK/OwnPtr.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Random.h>
namespace Kernel {
class NE2000NetworkAdapter final : public NetworkAdapter
, public PCI::Device {
, public PCI::DeviceController
, public IRQHandler {
public:
static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::Address);

View file

@ -122,7 +122,8 @@ UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_ini
}
UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)
: PCI::Device(address, irq)
: PCI::DeviceController(address)
, IRQHandler(irq)
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
, m_rx_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(RX_BUFFER_SIZE + PACKET_SIZE_MAX), "RTL8139 RX", Memory::Region::Access::ReadWrite))
, m_packet_buffer(MM.allocate_contiguous_kernel_region(Memory::page_round_up(PACKET_SIZE_MAX), "RTL8139 Packet buffer", Memory::Region::Access::ReadWrite))

View file

@ -8,8 +8,9 @@
#include <AK/OwnPtr.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Random.h>
@ -18,7 +19,8 @@ namespace Kernel {
#define RTL8139_TX_BUFFER_COUNT 4
class RTL8139NetworkAdapter final : public NetworkAdapter
, public PCI::Device {
, public PCI::DeviceController
, public IRQHandler {
public:
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::Address);

View file

@ -192,7 +192,8 @@ UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_ini
}
UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq)
: PCI::Device(address, irq)
: PCI::DeviceController(address)
, IRQHandler(irq)
, m_io_base(PCI::get_BAR0(pci_address()) & ~1)
, m_rx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(TXDescriptor) * (number_of_rx_descriptors + 1)), "RTL8168 RX", Memory::Region::Access::ReadWrite))
, m_tx_descriptors_region(MM.allocate_contiguous_kernel_region(Memory::page_round_up(sizeof(RXDescriptor) * (number_of_tx_descriptors + 1)), "RTL8168 TX", Memory::Region::Access::ReadWrite))

View file

@ -9,8 +9,9 @@
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Bus/PCI/DeviceController.h>
#include <Kernel/IO.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Random.h>
@ -18,7 +19,8 @@ namespace Kernel {
// RTL8618 / RTL8111 Driver based on https://people.freebsd.org/~wpaul/RealTek/RTL8111B_8168B_Registers_DataSheet_1.0.pdf
class RTL8168NetworkAdapter final : public NetworkAdapter
, public PCI::Device {
, public PCI::DeviceController
, public IRQHandler {
public:
static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::Address);