1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:17:46 +00:00

Kernel/PCI: Propagate usage of DeviceIdentifier everywhere

This allows us to remove a bunch of PCI API functions, and instead to
leverage the cached data from DeviceIdentifier object in many places.
This commit is contained in:
Liav A 2021-09-23 10:20:54 +03:00 committed by Andreas Kling
parent da327746a2
commit 057f5a12c2
40 changed files with 150 additions and 186 deletions

View file

@ -180,15 +180,14 @@ static bool is_valid_device_id(u16 device_id)
}
}
UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::Address address)
UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto id = PCI::get_hardware_id(address);
if (id.vendor_id != PCI::VendorID::Intel)
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
return {};
if (!is_valid_device_id(id.device_id))
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(address, irq));
u8 irq = PCI::get_interrupt_line(pci_device_identifier.address());
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq));
if (!adapter)
return {};
if (adapter->initialize())

View file

@ -21,7 +21,7 @@ namespace Kernel {
class E1000ENetworkAdapter final
: public E1000NetworkAdapter {
public:
static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::Address);
static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
virtual bool initialize() override;

View file

@ -158,15 +158,14 @@ UNMAP_AFTER_INIT static bool is_valid_device_id(u16 device_id)
}
}
UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::Address address)
UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto id = PCI::get_hardware_id(address);
if (id.vendor_id != PCI::VendorID::Intel)
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel)
return {};
if (!is_valid_device_id(id.device_id))
if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(address, irq));
u8 irq = PCI::get_interrupt_line(pci_device_identifier.address());
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq));
if (!adapter)
return {};
if (adapter->initialize())

View file

@ -20,7 +20,7 @@ class E1000NetworkAdapter : public NetworkAdapter
, public PCI::Device
, public IRQHandler {
public:
static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::Address);
static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
virtual bool initialize();

View file

@ -137,7 +137,7 @@ struct [[gnu::packed]] received_packet_header {
u16 length;
};
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::Address address)
UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
constexpr auto ne2k_ids = Array {
PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS)
@ -154,11 +154,10 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
PCI::HardwareID { 0x12c3, 0x5598 }, // Holtek HT80229
PCI::HardwareID { 0x8c4a, 0x1980 }, // Winbond W89C940 (misprogrammed)
};
auto id = PCI::get_hardware_id(address);
if (!ne2k_ids.span().contains_slow(id))
if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id()))
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(address, irq));
u8 irq = PCI::get_interrupt_line(pci_device_identifier.address());
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq));
}
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)

View file

@ -20,7 +20,7 @@ class NE2000NetworkAdapter final : public NetworkAdapter
, public PCI::Device
, public IRQHandler {
public:
static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::Address);
static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
virtual ~NE2000NetworkAdapter() override;

View file

@ -73,17 +73,17 @@ RefPtr<NetworkAdapter> NetworkingManagement::lookup_by_name(const StringView& na
return found_adapter;
}
UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::Address address) const
UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::DeviceIdentifier const& device_identifier) const
{
if (auto candidate = E1000NetworkAdapter::try_to_initialize(address); !candidate.is_null())
if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
return candidate;
if (auto candidate = E1000ENetworkAdapter::try_to_initialize(address); !candidate.is_null())
if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
return candidate;
if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(address); !candidate.is_null())
if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
return candidate;
if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(address); !candidate.is_null())
if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
return candidate;
if (auto candidate = NE2000NetworkAdapter::try_to_initialize(address); !candidate.is_null())
if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null())
return candidate;
return {};
}
@ -91,11 +91,11 @@ UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_
bool NetworkingManagement::initialize()
{
if (!kernel_command_line().is_physical_networking_disabled()) {
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
// Note: PCI class 2 is the class of Network devices
if (device_identifier.class_code().value() != 0x02)
return;
if (auto adapter = determine_network_device(address); !adapter.is_null())
if (auto adapter = determine_network_device(device_identifier); !adapter.is_null())
m_adapters.append(adapter.release_nonnull());
});
}

View file

@ -36,7 +36,7 @@ public:
NonnullRefPtr<NetworkAdapter> loopback_adapter() const;
private:
RefPtr<NetworkAdapter> determine_network_device(PCI::Address address) const;
RefPtr<NetworkAdapter> determine_network_device(PCI::DeviceIdentifier const&) const;
NonnullRefPtrVector<NetworkAdapter> m_adapters;
RefPtr<NetworkAdapter> m_loopback_adapter;

View file

@ -112,14 +112,13 @@ namespace Kernel {
#define RX_BUFFER_SIZE 32768
#define TX_BUFFER_SIZE PACKET_SIZE_MAX
UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::Address address)
UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
constexpr PCI::HardwareID rtl8139_id = { 0x10EC, 0x8139 };
auto id = PCI::get_hardware_id(address);
if (id != rtl8139_id)
if (pci_device_identifier.hardware_id() != rtl8139_id)
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(address, irq));
u8 irq = PCI::get_interrupt_line(pci_device_identifier.address());
return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq));
}
UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)

View file

@ -22,7 +22,7 @@ class RTL8139NetworkAdapter final : public NetworkAdapter
, public PCI::Device
, public IRQHandler {
public:
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::Address);
static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
virtual ~RTL8139NetworkAdapter() override;

View file

@ -181,15 +181,14 @@ namespace Kernel {
#define TX_BUFFER_SIZE 0x1FF8
#define RX_BUFFER_SIZE 0x1FF8 // FIXME: this should be increased (0x3FFF)
UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::Address address)
UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto id = PCI::get_hardware_id(address);
if (id.vendor_id != PCI::VendorID::Realtek)
if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Realtek)
return {};
if (id.device_id != 0x8168)
if (pci_device_identifier.hardware_id().device_id != 0x8168)
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(address, irq));
u8 irq = PCI::get_interrupt_line(pci_device_identifier.address());
return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq));
}
bool RTL8168NetworkAdapter::determine_supported_version() const

View file

@ -22,7 +22,7 @@ class RTL8168NetworkAdapter final : public NetworkAdapter
, public PCI::Device
, public IRQHandler {
public:
static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::Address);
static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&);
virtual ~RTL8168NetworkAdapter() override;