mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:57:47 +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
|
@ -120,36 +120,6 @@ u32 get_BAR(Address address, u8 bar)
|
|||
}
|
||||
}
|
||||
|
||||
u8 get_revision_id(Address address)
|
||||
{
|
||||
return read8(address, PCI_REVISION_ID);
|
||||
}
|
||||
|
||||
u8 get_subclass(Address address)
|
||||
{
|
||||
return read8(address, PCI_SUBCLASS);
|
||||
}
|
||||
|
||||
u8 get_class(Address address)
|
||||
{
|
||||
return read8(address, PCI_CLASS);
|
||||
}
|
||||
|
||||
u8 get_programming_interface(Address address)
|
||||
{
|
||||
return read8(address, PCI_PROG_IF);
|
||||
}
|
||||
|
||||
u16 get_subsystem_id(Address address)
|
||||
{
|
||||
return read16(address, PCI_SUBSYSTEM_ID);
|
||||
}
|
||||
|
||||
u16 get_subsystem_vendor_id(Address address)
|
||||
{
|
||||
return read16(address, PCI_SUBSYSTEM_VENDOR_ID);
|
||||
}
|
||||
|
||||
void enable_bus_mastering(Address address)
|
||||
{
|
||||
auto value = read16(address, PCI_COMMAND);
|
||||
|
|
|
@ -31,12 +31,6 @@ u32 get_BAR3(Address);
|
|||
u32 get_BAR4(Address);
|
||||
u32 get_BAR5(Address);
|
||||
u32 get_BAR(Address address, u8 bar);
|
||||
u8 get_revision_id(Address);
|
||||
u8 get_programming_interface(Address);
|
||||
u8 get_subclass(Address);
|
||||
u8 get_class(Address);
|
||||
u16 get_subsystem_id(Address);
|
||||
u16 get_subsystem_vendor_id(Address);
|
||||
size_t get_BAR_space_size(Address, u8);
|
||||
void enable_bus_mastering(Address);
|
||||
void disable_bus_mastering(Address);
|
||||
|
|
|
@ -62,10 +62,10 @@ static constexpr u16 UCHI_PORTSC_NON_WRITE_CLEAR_BIT_MASK = 0x1FF5; // This is u
|
|||
static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128;
|
||||
static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024;
|
||||
|
||||
KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::Address address)
|
||||
KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
// NOTE: This assumes that address is pointing to a valid UHCI controller.
|
||||
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(address)));
|
||||
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier.address())));
|
||||
TRY(controller->initialize());
|
||||
return controller;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class UHCIController final
|
|||
|
||||
public:
|
||||
static constexpr u8 NUMBER_OF_ROOT_PORTS = 2;
|
||||
static KResultOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::Address address);
|
||||
static KResultOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier);
|
||||
virtual ~UHCIController() override;
|
||||
|
||||
virtual StringView purpose() const override { return "UHCI"; }
|
||||
|
|
|
@ -34,7 +34,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
|
|||
if (kernel_command_line().disable_uhci_controller())
|
||||
return;
|
||||
|
||||
if (auto uhci_controller_or_error = UHCIController::try_to_initialize(address); !uhci_controller_or_error.is_error())
|
||||
if (auto uhci_controller_or_error = UHCIController::try_to_initialize(device_identifier); !uhci_controller_or_error.is_error())
|
||||
m_controllers.append(uhci_controller_or_error.release_value());
|
||||
|
||||
return;
|
||||
|
|
|
@ -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