Skip to content

Commit

Permalink
Kernel: Rename two PCI components
Browse files Browse the repository at this point in the history
Rename ID => HardwareID, and PhysicalID => DeviceIdentifier.
This change merely does that to clarify what these objects really are.
  • Loading branch information
supercomputer7 authored and awesomekling committed Sep 29, 2021
1 parent 82bb08a commit da32774
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 97 deletions.
8 changes: 4 additions & 4 deletions Kernel/Bus/PCI/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ u8 read8(Address address, u32 field) { return Access::the().read8_field(address,
u16 read16(Address address, u32 field) { return Access::the().read16_field(address, field); }
u32 read32(Address address, u32 field) { return Access::the().read32_field(address, field); }

void enumerate(Function<void(Address, PhysicalID const&)> callback)
void enumerate(Function<void(Address, DeviceIdentifier const&)> callback)
{
Access::the().fast_enumerate(callback);
}

PhysicalID get_physical_id(Address address)
DeviceIdentifier get_device_identifier(Address address)
{
return Access::the().get_physical_id(address);
return Access::the().get_device_identifier(address);
}

ID get_id(Address address)
HardwareID get_hardware_id(Address address)
{
return { read16(address, PCI_VENDOR_ID), read16(address, PCI_DEVICE_ID) };
}
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Bus/PCI/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ u8 read8(Address address, u32 field);
u16 read16(Address address, u32 field);
u32 read32(Address address, u32 field);

ID get_id(PCI::Address);
HardwareID get_hardware_id(PCI::Address);
bool is_io_space_enabled(Address);
void enumerate(Function<void(Address, PhysicalID const&)> callback);
void enumerate(Function<void(Address, DeviceIdentifier const&)> callback);
void enable_interrupt_line(Address);
void disable_interrupt_line(Address);
u8 get_interrupt_line(Address);
Expand All @@ -44,6 +44,6 @@ void enable_io_space(Address);
void disable_io_space(Address);
void enable_memory_space(Address);
void disable_memory_space(Address);
PhysicalID get_physical_id(Address address);
DeviceIdentifier get_device_identifier(Address address);

}
28 changes: 14 additions & 14 deletions Kernel/Bus/PCI/Access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ u32 Access::read32_field(Address address, u32 field)
UNMAP_AFTER_INIT void Access::rescan_hardware()
{
MutexLocker locker(m_scan_lock);
VERIFY(m_physical_ids.is_empty());
VERIFY(m_device_identifiers.is_empty());
if (m_access_type == AccessType::IO) {
dbgln_if(PCI_DEBUG, "PCI: IO enumerating hardware");

Expand Down Expand Up @@ -381,14 +381,14 @@ UNMAP_AFTER_INIT void Access::enumerate_functions(int type, u8 bus, u8 device, u
Address address(0, bus, device, function);
auto read_type = (read8_field(address, PCI_CLASS) << 8u) | read8_field(address, PCI_SUBCLASS);
if (type == -1 || type == read_type) {
PCI::ID id = { read16_field(address, PCI_VENDOR_ID), read16_field(address, PCI_DEVICE_ID) };
HardwareID id = { read16_field(address, PCI_VENDOR_ID), read16_field(address, PCI_DEVICE_ID) };
ClassCode class_code = read8_field(address, PCI_CLASS);
SubclassCode subclass_code = read8_field(address, PCI_SUBCLASS);
ProgrammingInterface prog_if = read8_field(address, PCI_PROG_IF);
RevisionID revision_id = read8_field(address, PCI_REVISION_ID);
SubsystemID subsystem_id = read16_field(address, PCI_SUBSYSTEM_ID);
SubsystemVendorID subsystem_vendor_id = read16_field(address, PCI_SUBSYSTEM_VENDOR_ID);
m_physical_ids.append(PhysicalID { address, id, revision_id, class_code, subclass_code, prog_if, subsystem_id, subsystem_vendor_id, get_capabilities(address) });
m_device_identifiers.append(DeviceIdentifier { address, id, revision_id, class_code, subclass_code, prog_if, subsystem_id, subsystem_vendor_id, get_capabilities(address) });
}

if (read_type == PCI_TYPE_BRIDGE && recursive && (!m_enumerated_buses.get(read8_field(address, PCI_SECONDARY_BUS)))) {
Expand Down Expand Up @@ -423,23 +423,23 @@ UNMAP_AFTER_INIT void Access::enumerate_bus(int type, u8 bus, bool recursive)
enumerate_device(type, bus, device, recursive);
}

void Access::fast_enumerate(Function<void(Address, PhysicalID const&)>& callback) const
void Access::fast_enumerate(Function<void(Address, DeviceIdentifier const&)>& callback) const
{
MutexLocker locker(m_scan_lock);
VERIFY(!m_physical_ids.is_empty());
for (auto& physical_id : m_physical_ids) {
callback(physical_id.address(), physical_id);
VERIFY(!m_device_identifiers.is_empty());
for (auto& device_identifier : m_device_identifiers) {
callback(device_identifier.address(), device_identifier);
}
}

PhysicalID Access::get_physical_id(Address address) const
DeviceIdentifier Access::get_device_identifier(Address address) const
{
for (auto physical_id : m_physical_ids) {
if (physical_id.address().domain() == address.domain()
&& physical_id.address().bus() == address.bus()
&& physical_id.address().device() == address.device()
&& physical_id.address().function() == address.function()) {
return physical_id;
for (auto device_identifier : m_device_identifiers) {
if (device_identifier.address().domain() == address.domain()
&& device_identifier.address().bus() == address.bus()
&& device_identifier.address().device() == address.device()
&& device_identifier.address().function() == address.function()) {
return device_identifier;
}
}
VERIFY_NOT_REACHED();
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Bus/PCI/Access.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Access {
static bool initialize_for_memory_access(PhysicalAddress mcfg_table);
static bool initialize_for_io_access();

void fast_enumerate(Function<void(Address, PhysicalID const&)>&) const;
void fast_enumerate(Function<void(Address, DeviceIdentifier const&)>&) const;
void rescan_hardware();

static Access& the();
Expand All @@ -37,7 +37,7 @@ class Access {
u8 read8_field(Address address, u32 field);
u16 read16_field(Address address, u32 field);
u32 read32_field(Address address, u32 field);
PhysicalID get_physical_id(Address address) const;
DeviceIdentifier get_device_identifier(Address address) const;

private:
void enumerate_bus(int type, u8 bus, bool recursive);
Expand Down Expand Up @@ -80,6 +80,6 @@ class Access {
mutable Mutex m_scan_lock;
Bitmap m_enumerated_buses;
AccessType m_access_type;
Vector<PhysicalID> m_physical_ids;
Vector<DeviceIdentifier> m_device_identifiers;
};
}
22 changes: 11 additions & 11 deletions Kernel/Bus/PCI/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ namespace Kernel {
#define PCI_AHCI_IF_PROGIF 0x1

namespace PCI {
struct ID {
struct HardwareID {
u16 vendor_id { 0 };
u16 device_id { 0 };

bool is_null() const { return !vendor_id && !device_id; }

bool operator==(const ID& other) const
bool operator==(const HardwareID& other) const
{
return vendor_id == other.vendor_id && device_id == other.device_id;
}
bool operator!=(const ID& other) const
bool operator!=(const HardwareID& other) const
{
return vendor_id != other.vendor_id || device_id != other.device_id;
}
Expand Down Expand Up @@ -189,11 +189,11 @@ TYPEDEF_DISTINCT_ORDERED_ID(u16, SubsystemID);
TYPEDEF_DISTINCT_ORDERED_ID(u16, SubsystemVendorID);

class Access;
class PhysicalID {
class DeviceIdentifier {
public:
PhysicalID(Address address, ID id, RevisionID revision_id, ClassCode class_code, SubclassCode subclass_code, ProgrammingInterface prog_if, SubsystemID subsystem_id, SubsystemVendorID subsystem_vendor_id, Vector<Capability> capabilities)
DeviceIdentifier(Address address, HardwareID hardware_id, RevisionID revision_id, ClassCode class_code, SubclassCode subclass_code, ProgrammingInterface prog_if, SubsystemID subsystem_id, SubsystemVendorID subsystem_vendor_id, Vector<Capability> capabilities)
: m_address(address)
, m_id(id)
, m_hardware_id(hardware_id)
, m_revision_id(revision_id)
, m_class_code(class_code)
, m_subclass_code(subclass_code)
Expand All @@ -209,7 +209,7 @@ class PhysicalID {
}

Vector<Capability> capabilities() const { return m_capabilities; }
const ID& id() const { return m_id; }
const HardwareID& hardware_id() const { return m_hardware_id; }
const Address& address() const { return m_address; }

RevisionID revision_id() const { return m_revision_id; }
Expand All @@ -230,7 +230,7 @@ class PhysicalID {

private:
Address m_address;
ID m_id;
HardwareID m_hardware_id;

RevisionID m_revision_id;
ClassCode m_class_code;
Expand Down Expand Up @@ -259,11 +259,11 @@ struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> {
};

template<>
struct AK::Formatter<Kernel::PCI::ID> : Formatter<FormatString> {
void format(FormatBuilder& builder, Kernel::PCI::ID value)
struct AK::Formatter<Kernel::PCI::HardwareID> : Formatter<FormatString> {
void format(FormatBuilder& builder, Kernel::PCI::HardwareID value)
{
return Formatter<FormatString>::format(
builder,
"PCI::ID [{:04x}:{:04x}]", value.vendor_id, value.device_id);
"PCI::HardwareID [{:04x}:{:04x}]", value.vendor_id, value.device_id);
}
};
4 changes: 2 additions & 2 deletions Kernel/Bus/PCI/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Device::Device(Address address)

bool Device::is_msi_capable() const
{
for (const auto& capability : PCI::get_physical_id(pci_address()).capabilities()) {
for (const auto& capability : PCI::get_device_identifier(pci_address()).capabilities()) {
if (capability.id() == PCI_CAPABILITY_MSI)
return true;
}
return false;
}
bool Device::is_msix_capable() const
{
for (const auto& capability : PCI::get_physical_id(pci_address()).capabilities()) {
for (const auto& capability : PCI::get_device_identifier(pci_address()).capabilities()) {
if (capability.id() == PCI_CAPABILITY_MSIX)
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Bus/PCI/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ UNMAP_AFTER_INIT void initialize()

PCI::PCIBusSysFSDirectory::initialize();

PCI::enumerate([&](const Address& address, PhysicalID const& physical_id) {
dmesgln("{} {}", address, physical_id.id());
PCI::enumerate([&](const Address& address, DeviceIdentifier const& device_identifier) {
dmesgln("{} {}", address, device_identifier.hardware_id());
});
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bus/PCI/SysFSPCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory()
: SysFSDirectory("pci", SysFSComponentRegistry::the().buses_directory())
{
PCI::enumerate([&](const Address& address, PhysicalID const&) {
PCI::enumerate([&](const Address& address, DeviceIdentifier const&) {
auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, address);
m_components.append(pci_device);
});
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bus/USB/UHCI/UHCIController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::

KResult UHCIController::initialize()
{
dmesgln("UHCI: Controller found {} @ {}", PCI::get_id(pci_address()), pci_address());
dmesgln("UHCI: Controller found {} @ {}", PCI::get_hardware_id(pci_address()), pci_address());
dmesgln("UHCI: I/O base {}", m_io_base);
dmesgln("UHCI: Interrupt line: {}", PCI::get_interrupt_line(pci_address()));

Expand Down
14 changes: 7 additions & 7 deletions Kernel/Bus/USB/USBManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
if (kernel_command_line().disable_usb())
return;

PCI::enumerate([this](PCI::Address const& address, PCI::PhysicalID const& physical_id) {
if (!(physical_id.class_code().value() == 0xc && physical_id.subclass_code().value() == 0x3))
PCI::enumerate([this](PCI::Address const& address, PCI::DeviceIdentifier const& device_identifier) {
if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3))
return;
if (physical_id.prog_if().value() == 0x0) {
if (device_identifier.prog_if().value() == 0x0) {
if (kernel_command_line().disable_uhci_controller())
return;

Expand All @@ -40,22 +40,22 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
return;
}

if (physical_id.prog_if().value() == 0x10) {
if (device_identifier.prog_if().value() == 0x10) {
dmesgln("USBManagement: OHCI controller found at {} is not currently supported.", address);
return;
}

if (physical_id.prog_if().value() == 0x20) {
if (device_identifier.prog_if().value() == 0x20) {
dmesgln("USBManagement: EHCI controller found at {} is not currently supported.", address);
return;
}

if (physical_id.prog_if().value() == 0x30) {
if (device_identifier.prog_if().value() == 0x30) {
dmesgln("USBManagement: xHCI controller found at {} is not currently supported.", address);
return;
}

dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", address, physical_id.prog_if().value());
dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", address, device_identifier.prog_if().value());
});
}

Expand Down
14 changes: 7 additions & 7 deletions Kernel/Bus/VirtIO/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ UNMAP_AFTER_INIT void detect()
{
if (kernel_command_line().disable_virtio())
return;
PCI::enumerate([&](const PCI::Address& address, PCI::PhysicalID const& physical_id) {
if (address.is_null() || physical_id.id().is_null())
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
if (address.is_null() || device_identifier.hardware_id().is_null())
return;
// TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive
if (physical_id.id().vendor_id != PCI::VendorID::VirtIO)
if (device_identifier.hardware_id().vendor_id != PCI::VendorID::VirtIO)
return;
switch (physical_id.id().device_id) {
switch (device_identifier.hardware_id().device_id) {
case PCI::DeviceID::VirtIOConsole: {
auto& console = Console::must_create(address).leak_ref();
console.initialize();
Expand All @@ -40,7 +40,7 @@ UNMAP_AFTER_INIT void detect()
break;
}
default:
dbgln_if(VIRTIO_DEBUG, "VirtIO: Unknown VirtIO device with ID: {}", physical_id.id().device_id);
dbgln_if(VIRTIO_DEBUG, "VirtIO: Unknown VirtIO device with ID: {}", device_identifier.hardware_id().device_id);
break;
}
});
Expand All @@ -67,7 +67,7 @@ static StringView const determine_device_class(const PCI::Address& address)
}
}

auto id = PCI::get_id(address);
auto id = PCI::get_hardware_id(address);
VERIFY(id.vendor_id == PCI::VendorID::VirtIO);
switch (id.device_id) {
case PCI::DeviceID::VirtIONetAdapter:
Expand All @@ -93,7 +93,7 @@ UNMAP_AFTER_INIT void Device::initialize()
PCI::enable_interrupt_line(pci_address());
enable_irq();

auto capabilities = PCI::get_physical_id(address).capabilities();
auto capabilities = PCI::get_device_identifier(address).capabilities();
for (auto& capability : capabilities) {
if (capability.id() == PCI_CAPABILITY_VENDOR_SPECIFIC) {
// We have a virtio_pci_cap
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Devices/PCISerialDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ static SerialDevice* s_the = nullptr;
UNMAP_AFTER_INIT void PCISerialDevice::detect()
{
size_t current_device_minor = 68;
PCI::enumerate([&](const PCI::Address& address, PCI::PhysicalID const& physical_id) {
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
if (address.is_null())
return;

for (auto& board_definition : board_definitions) {
if (board_definition.device_id != physical_id.id())
if (board_definition.device_id != device_identifier.hardware_id())
continue;

auto bar_base = PCI::get_BAR(address, board_definition.pci_bar) & ~1;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/PCISerialDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PCISerialDevice {

private:
struct BoardDefinition {
PCI::ID device_id;
PCI::HardwareID device_id;
StringView name;
u32 port_count { 0 };
u32 pci_bar { 0 };
Expand Down
16 changes: 8 additions & 8 deletions Kernel/GlobalProcessExposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,19 +614,19 @@ class ProcFSPCI final : public ProcFSGlobalInformation {
virtual KResult try_generate(KBufferBuilder& builder) override
{
JsonArraySerializer array { builder };
PCI::enumerate([&array](PCI::Address address, PCI::PhysicalID const& physical_id) {
PCI::enumerate([&array](PCI::Address address, PCI::DeviceIdentifier const& device_identifier) {
auto obj = array.add_object();
obj.add("domain", address.domain());
obj.add("bus", address.bus());
obj.add("device", address.device());
obj.add("function", address.function());
obj.add("vendor_id", physical_id.id().vendor_id);
obj.add("device_id", physical_id.id().device_id);
obj.add("revision_id", physical_id.revision_id().value());
obj.add("subclass", physical_id.subclass_code().value());
obj.add("class", physical_id.class_code().value());
obj.add("subsystem_id", physical_id.subsystem_id().value());
obj.add("subsystem_vendor_id", physical_id.subsystem_vendor_id().value());
obj.add("vendor_id", device_identifier.hardware_id().vendor_id);
obj.add("device_id", device_identifier.hardware_id().device_id);
obj.add("revision_id", device_identifier.revision_id().value());
obj.add("subclass", device_identifier.subclass_code().value());
obj.add("class", device_identifier.class_code().value());
obj.add("subsystem_id", device_identifier.subsystem_id().value());
obj.add("subsystem_vendor_id", device_identifier.subsystem_vendor_id().value());
});
array.finish();
return KSuccess;
Expand Down
Loading

0 comments on commit da32774

Please sign in to comment.