mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 06:17:34 +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:
parent
da327746a2
commit
057f5a12c2
40 changed files with 150 additions and 186 deletions
|
@ -13,9 +13,9 @@ namespace Kernel::VirtIO {
|
|||
|
||||
unsigned Console::next_device_id = 0;
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::Address address)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new Console(address)).release_nonnull();
|
||||
return adopt_ref_if_nonnull(new Console(pci_device_identifier)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void Console::initialize()
|
||||
|
@ -61,8 +61,8 @@ UNMAP_AFTER_INIT void Console::initialize()
|
|||
}
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
: VirtIO::Device(pci_device_identifier)
|
||||
, m_device_id(next_device_id++)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class Console
|
|||
friend VirtIO::ConsolePort;
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<Console> must_create(PCI::Address address);
|
||||
static NonnullRefPtr<Console> must_create(PCI::DeviceIdentifier const&);
|
||||
virtual ~Console() override = default;
|
||||
|
||||
virtual StringView purpose() const override { return class_name(); }
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual StringView class_name() const override { return "VirtIOConsole"; }
|
||||
explicit Console(PCI::Address);
|
||||
explicit Console(PCI::DeviceIdentifier const&);
|
||||
enum class ControlEvent : u16 {
|
||||
DeviceReady = 0,
|
||||
DeviceAdd = 1,
|
||||
|
|
|
@ -18,20 +18,20 @@ UNMAP_AFTER_INIT void detect()
|
|||
{
|
||||
if (kernel_command_line().disable_virtio())
|
||||
return;
|
||||
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
|
||||
if (address.is_null() || device_identifier.hardware_id().is_null())
|
||||
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
|
||||
if (device_identifier.hardware_id().is_null())
|
||||
return;
|
||||
// TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive
|
||||
if (device_identifier.hardware_id().vendor_id != PCI::VendorID::VirtIO)
|
||||
return;
|
||||
switch (device_identifier.hardware_id().device_id) {
|
||||
case PCI::DeviceID::VirtIOConsole: {
|
||||
auto& console = Console::must_create(address).leak_ref();
|
||||
auto& console = Console::must_create(device_identifier).leak_ref();
|
||||
console.initialize();
|
||||
break;
|
||||
}
|
||||
case PCI::DeviceID::VirtIOEntropy: {
|
||||
auto& rng = RNG::must_create(address).leak_ref();
|
||||
auto& rng = RNG::must_create(device_identifier).leak_ref();
|
||||
rng.initialize();
|
||||
break;
|
||||
}
|
||||
|
@ -46,12 +46,12 @@ UNMAP_AFTER_INIT void detect()
|
|||
});
|
||||
}
|
||||
|
||||
static StringView const determine_device_class(const PCI::Address& address)
|
||||
static StringView const determine_device_class(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
if (PCI::get_revision_id(address) == 0) {
|
||||
if (device_identifier.revision_id().value() == 0) {
|
||||
// Note: If the device is a legacy (or transitional) device, therefore,
|
||||
// probe the subsystem ID in the PCI header and figure out the
|
||||
auto subsystem_device_id = PCI::get_subsystem_id(address);
|
||||
auto subsystem_device_id = device_identifier.subsystem_id().value();
|
||||
switch (subsystem_device_id) {
|
||||
case 1:
|
||||
return "VirtIONetAdapter"sv;
|
||||
|
@ -67,7 +67,7 @@ static StringView const determine_device_class(const PCI::Address& address)
|
|||
}
|
||||
}
|
||||
|
||||
auto id = PCI::get_hardware_id(address);
|
||||
auto id = device_identifier.hardware_id();
|
||||
VERIFY(id.vendor_id == PCI::VendorID::VirtIO);
|
||||
switch (id.device_id) {
|
||||
case PCI::DeviceID::VirtIONetAdapter:
|
||||
|
@ -150,11 +150,11 @@ UNMAP_AFTER_INIT void Device::initialize()
|
|||
set_status_bit(DEVICE_STATUS_DRIVER);
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT VirtIO::Device::Device(PCI::Address address)
|
||||
: PCI::Device(address)
|
||||
, IRQHandler(PCI::get_interrupt_line(address))
|
||||
UNMAP_AFTER_INIT VirtIO::Device::Device(PCI::DeviceIdentifier const& device_identifier)
|
||||
: PCI::Device(device_identifier.address())
|
||||
, IRQHandler(PCI::get_interrupt_line(device_identifier.address()))
|
||||
, m_io_base(IOAddress(PCI::get_BAR0(pci_address()) & ~1))
|
||||
, m_class_name(VirtIO::determine_device_class(address))
|
||||
, m_class_name(VirtIO::determine_device_class(device_identifier))
|
||||
{
|
||||
dbgln("{}: Found @ {}", m_class_name, pci_address());
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual StringView class_name() const { return "VirtIO::Device"; }
|
||||
explicit Device(PCI::Address);
|
||||
explicit Device(PCI::DeviceIdentifier const&);
|
||||
struct MappedMMIO {
|
||||
OwnPtr<Memory::Region> base;
|
||||
size_t size { 0 };
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace Kernel::VirtIO {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<RNG> RNG::must_create(PCI::Address address)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<RNG> RNG::must_create(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new RNG(address)).release_nonnull();
|
||||
return adopt_ref_if_nonnull(new RNG(device_identifier)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void RNG::initialize()
|
||||
|
@ -33,8 +33,8 @@ UNMAP_AFTER_INIT void RNG::initialize()
|
|||
}
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT RNG::RNG(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
UNMAP_AFTER_INIT RNG::RNG(PCI::DeviceIdentifier const& device_identifier)
|
||||
: VirtIO::Device(device_identifier)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class RNG final
|
|||
: public RefCounted<RNG>
|
||||
, public VirtIO::Device {
|
||||
public:
|
||||
static NonnullRefPtr<RNG> must_create(PCI::Address address);
|
||||
static NonnullRefPtr<RNG> must_create(PCI::DeviceIdentifier const&);
|
||||
virtual StringView purpose() const override { return class_name(); }
|
||||
virtual ~RNG() override = default;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
private:
|
||||
virtual StringView class_name() const override { return "VirtIOConsole"; }
|
||||
explicit RNG(PCI::Address);
|
||||
explicit RNG(PCI::DeviceIdentifier const&);
|
||||
virtual bool handle_device_config_change() override;
|
||||
virtual void handle_queue_update(u16 queue_index) override;
|
||||
void request_entropy_from_host();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue