-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel: New PCI driver subsystem design #23448
Kernel: New PCI driver subsystem design #23448
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two general questions:
- Can we get the
__matches
arrays in.rodata
, as they should not be written to afaict - I think it's unfortunate to loose a lot of UNMAP_AFTER_INIT, can we instead just delay that until we've finished PCI enumeration?
@@ -34,6 +34,7 @@ | |||
#include <Kernel/Devices/SerialDevice.h> | |||
#include <Kernel/Devices/Storage/StorageManagement.h> | |||
#include <Kernel/Devices/TTY/ConsoleManagement.h> | |||
#include <Kernel/Devices/TTY/PCI/Serial8250Device.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this include here seems unrelated
SpinlockProtected<RawPtr<PCI::Driver>, LockRank::None>& driver(Badge<Access>) { return m_driver; } | ||
|
||
template<typename T> | ||
inline ErrorOr<Memory::TypedMapping<T>> map_resource(HeaderType0BaseRegister bar, size_t size = sizeof(T), Memory::Region::Access access = IsConst<T> ? Memory::Region::Access::Read : Memory::Region::Access::ReadWrite) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not (yet) sure if this changes in a later commit,
But as it turns out fully relying on the size of the Object seems to not be correct in all cases, as some passed in objects end in flexible arrays, which don't contribute to the size
RawPtr<PCI::HostController> m_host_controller {}; | ||
RawPtr<Bus> m_parent_bus {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we need RawPtr
here?
auto registers_mapping = TRY(Memory::map_typed_writable<BochsDisplayMMIORegisters volatile>(PhysicalAddress(m_pci_device->resources()[2].physical_memory_address()))); | ||
VERIFY(registers_mapping.region); | ||
m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(TRY(PCI::get_bar_address(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0))), bar0_space_size, move(registers_mapping)); | ||
m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(m_pci_device->resources()[0].physical_memory_address()), bar0_space_size, move(registers_mapping)); | ||
} | ||
#else | ||
auto registers_mapping = TRY(PCI::map_bar<BochsDisplayMMIORegisters volatile>(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR2)); | ||
auto registers_mapping = TRY(Memory::map_typed_writable<BochsDisplayMMIORegisters volatile>(PhysicalAddress(m_pci_device->resources()[2].physical_memory_address()))); | ||
VERIFY(registers_mapping.region); | ||
m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(TRY(PCI::get_bar_address(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0))), bar0_space_size, move(registers_mapping)); | ||
m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(m_pci_device->resources()[0].physical_memory_address()), bar0_space_size, move(registers_mapping)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why m_pci_device->map_resource
would not work here?
Kernel/Boot/CommandLine.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best to update the kernel command line man page
@@ -37,7 +37,7 @@ class AsyncBlockDeviceRequest; | |||
|
|||
class IDEController; | |||
#if ARCH(X86_64) | |||
class PCIIDELegacyModeController; | |||
class PIIX4IDEController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling that this and the changes below belong to the rename commit
Sure. I will see how to do that cleanly.
It's part of how loading kernel modules work not only here, but in Linux as well. If we have UNMAP_AFTER_INIT, it means that you basically can never have PCI device hotplug capabilities. It also means that you can't insert a kernel module that needs these methods as it will fail, so loadable kernel modules are not an option as well. I rather stick to remove those UNMAP_AFTER_INIT tags now. Also, trying to synchronize PCI enumeration with the main init process is just asking for problems - it eliminates the power of multi-threading to actually allow faster boot times - I intend that in the future we will spawn the init process even before of completing the PCI enumeration, so you could reach a functional system even sooner and all system services will spawn lazily and attach to new devices when they appear even after running the service :) |
PhysicalAddress physical_memory_address() const | ||
{ | ||
VERIFY(type != SpaceType::IOSpace); | ||
return PhysicalAddress(address & PCI::bar_address_mask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If address
still contains the bottom type bits, maybe name it something like bar_value
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean to finish my review yet, idk how I accidentally finished it.
dmesgln_pci(*this, "Controller found {} @ {}", PCI::get_hardware_id(device_identifier()), device_identifier().address()); | ||
dmesgln_pci(*this, "I/O base {}", m_registers_io_window); | ||
dmesgln_pci(*this, "Interrupt line: {}", interrupt_number()); | ||
dmesgln("UHCI I/O base {}", m_registers_io_window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no dmesgln_pci here?
|
||
// IRQ from pin-based interrupt should be set as reserved as soon as possible so that the PCI device | ||
// that chooses to use MSI(x) based interrupt can avoid sharing the IRQ with other devices. | ||
MUST(PCI::enumerate([&](DeviceIdentifier const& device_identifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the FIXME at the bottom of riscv64/PCI/Initializer.cpp be removed now?
Ah no, this seems like you removed that temporarily.
} | ||
})); | ||
|
||
MUST(PCI::enumerate([&](DeviceIdentifier const& device_identifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably should also remove this printing loop from riscv64/PCI/Initializer.cpp as well.
Well RISC-V probably doesn't work at all right now, so I assume you will fix that up later.
We never used these virtual methods outside their own implementation, so let's stop pretending that we should be able to utilize this for unknown purpose.
We can just do the initialization sequence in the constructor.
This option was merely used by me in bare metal testing, but is useless for anyone else.
Prepare to remove biglock on PCI::Access in a future commit, so we can ensure we only lock a spinlock on a precise PCI HostController if needed instead of the entire subsystem.
GenericGraphicsAdapter is mouthful. Also, the idea is to move towards a more advanced subsystem that handles GPUs, not merely graphics adapters.
This code is actually for the old PIIX4 PCI host bridge, which requires to use legacy x86 IO instructions.
This file will be removed in a future commit, so let's get rid of what we can right now. Also, the ISAIDEController code as well as other places should have never included this file in the first place.
This WorkQueue will be used to probe devices from the PCI bus in asynchronous fashion.
Instead of waiting 2 seconds, wait 100 milliseconds. Do this 10000 so we wait 10 seconds for the boot device to appear. This will be used later on, as the boot device will always appear asynchronously.
It will change dramatically in the following commits, so let's remove the existence of the PCI bus from SysFS. As lspci needs /sys/bus/pci as well, we will remove it for now, as it will change as well.
The USB::Pipe is abstracted from the actual USB host controller implementation, so don't include the UHCIController.h file. Also, we missed an include to UserOrKernelBuffer.h, so this is added to ensure the code can still compile.
We do this by doing the following things: - Remove all drivers except e1000, because we need the e1000 driver to be able to connect the machine to the network. - Remove dependency on PCI::Device for removed (for now) drivers. - Remove the call to initialize from the NetworkingManagement singleton code.
We do this by doing the following things: - Remove all drivers except Intel HDA, because we need the Intel HDA driver to be able to perform audio operations. - Remove dependency on PCI::Device for removed (for now) drivers. - Remove the call to initialize from the AudioManagement singleton code.
This is a preparation before applying the new PCI subsystem design, as we will add these drivers properly afterwards.
We don't need all drivers except the NVMe driver, so remove everything until we add the drivers back after applying the new PCI subsystem design.
A friendly reminder to me to look on this: |
This PR also relies on #24210, to ensure that we can handle hotplug events, because down the road initialization for most things will happen in async fashion. :) |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
As far as I consider this, all programs should follow what I did in #24210, except that |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions! |
The rebase work is done on this branch: Once we get it all OK there I will move the patches to this PR. #24699 should be merged as well for this to be ready. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! |
This is stale and sadly I don't have the time right now to keep it open or rebasing it over and over again. |
This is the PR I talked about in the discord server. It puts the PCI subsystem inline with the USB subsystem, and I intend to expand on this to make it possible to compile some drivers as kernel modules (and maybe even loadable ones).
Still, it's incomplete as I don't have userspace interfaces to ensure we can bring back
lspci
, so it's a draft, but we will need to discuss many aspects of the design probably, to get the best shape out of this.cc @Hendiadyoin1 @spholz