summaryrefslogtreecommitdiff
path: root/Kernel/Bus/PCI
AgeCommit message (Collapse)Author
2022-01-19Kernel/PCI: Don't hardcode Address domain to 0 when enumerating devicesLiav A
2022-01-19Kernel/PCI: Don't cast a domain number to u16Liav A
Found by Tom (tomuta) during a debug session of these changes.
2022-01-13Kernel: Make map_typed() & map_typed_writable() fallible using ErrorOrIdan Horowitz
This mostly just moved the problem, as a lot of the callers are not capable of propagating the errors themselves, but it's a step in the right direction.
2022-01-08Kernel/PCI: Split host bridge code from the Access singletonLiav A
Two classes are added - HostBridge and MemoryBackedHostBridge, which both derive from HostController class. This allows the kernel to map different busses from different PCI domains in the same time. Each HostController implementation doesn't take the Address object to address PCI devices but instead we take distinct numbers of the PCI bus, device and function as it allows us to specify arbitrary PCI domains in the Address structure and still to get the correct PCI devices. This also matches the hardware behavior of PCI domains - the host bridge merely takes memory operations or IO operations and translates them to addressing of three components - PCI bus, device and function. These changes also greatly simplify how enumeration of Host Bridges work now - scanning of the hardware depends on what the Host bridges can do for us, so in case we have multiple host bridges that expose a memory mapped region or IO ports to access PCI configuration space, we simply let the code of the host bridge to figure out how to fetch data for us. Another semantical change is that a PCI domain structure is no longer attached to a PhysicalAddress, so even in the case that the machine doesn't implement PCI domains, we still treat that machine to contain 1 PCI domain to treat that one host bridge in the same way, like with a machine with one or more PCI domains.
2022-01-01Kernel/NVMe: Add initial NVMe driver supportPankaj Raghav
Add a basic NVMe driver support to serenity based on NVMe spec 1.4. The driver can support multiple NVMe drives (subsystems). But in a NVMe drive, the driver can support one controller with multiple namespaces. Each core will get a separate NVMe Queue. As the system lacks MSI support, PIN based interrupts are used for IO. Tested the NVMe support by replacing IDE driver with the NVMe driver :^)
2021-12-30Kernel: Tighten String-related includesDaniel Bertalan
2021-12-28Kernel: Propagate overflow errors from Memory::page_round_upGuilherme Goncalves
Fixes #11402.
2021-12-28Kernel: Remove the KString::try_create(String::formatted(...)) patternDaniel Bertalan
We can now directly create formatted KStrings with KString::formatted. :^)
2021-12-14Kernel/SysFS: Prevent allocation for component name during constructionLiav A
Instead, allocate before constructing the object and pass NonnullOwnPtr of KString to the object if needed. Some classes can determine their names as they have a known attribute to look for or have a static name.
2021-12-11Kernel: Remove unused String.h includesHendiadyoin1
This makes searching for not yet OOM safe interfaces a bit easier.
2021-12-09Kernel: Fix some clang-tidy warnings in PCI::AccessHendiadyoin1
2021-12-09Kernel: Use AK:any_of in PCI::Device capability checksHendiadyoin1
This is equivalent to std::any_of as clang-tidy suggests.
2021-12-09Kernel: Construct PCIDeviceAttributeSysFSComponent with StringViewsHendiadyoin1
There is no use to create a temporary String of a char const* to just cast it to a StringView on SysFSComponent construction again. Also this could have lead to a UAF bug.
2021-12-09Kernel: Pass capabilities as const reference in PCI::AddressHendiadyoin1
2021-12-09Kernel: Mark PCI::Address as trivially copyableHendiadyoin1
2021-11-30Kernel: Handle string format errors in PCIDeviceAttributeSysFSComponentBrian Gianforcaro
2021-11-23Kernel: Implement AC97 audio device driverJelle Raaijmakers
2021-11-21Everywhere: Fix spelling of "offsetted"Andreas Kling
This word is actually pretty awkward in context, but this patch merely fixes the spelling instead of finding a better word.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-10Everywhere: Remove unused AK/Bitmap includesBen Wiederhake
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-10-23Kernel/PCI: Remove InterruptDisabler usageLiav A
Instead, just ensure we pick the m_access_lock and then m_scan_lock when doing a scan/re-scan of the PCI configuration space so we know nobody can actually access the PCI configuration space during the scan. The m_scan_lock is now a Spinlock, to ensure we cannot yield to other process while we do the PCI configuration space scanning.
2021-10-23Kernel/PCI: Ensure m_domains is not empty if scanning with memory accessLiav A
2021-10-23Kernel/PCI: Split Access::rescan_hardware methodLiav A
To ensure clarity, this method is essentially splitted to two methods to be called according to the access type being determined beforehand.
2021-10-23Kernel/PCI: Rename Access::scan_pci_domains methodLiav A
We rename it to scan_pci_domains_from_acpi_mcfg_table to ensure clarity, because this method relies on the ACPI MCFG table to work.
2021-10-23Kernel/PCI: Simplify detect_optimal_access_type functionLiav A
Instead of getting the kernel commandline argument as function parameter we just take internally in the function.
2021-10-14Kernel: Add per platform Processor.h headersJames Mintram
The platform independent Processor.h file includes the shared processor code and includes the specific platform header file. All references to the Arch/x86/Processor.h file have been replaced with a reference to Arch/Processor.h.
2021-10-14Kernel: Add header includes closer to their useJames Mintram
2021-10-01Kernel: Move x86 IO instructions code into the x86 specific folderLiav A
2021-10-01Kernel: Remove IO.h include from a bunch of placesLiav A
2021-09-29Kernel/PCI: Remove all macros and replace them with enum classesLiav A
2021-09-29Kernel/PCI: Remove Address from enumeration callbackLiav A
If we need that address, we can always get it from the DeviceIdentifier.
2021-09-29Kernel/PCI: Cache interrupt line and interrupt pin of a deviceLiav A
This allows us to remove the PCI::get_interrupt_line API function. As a result, this removes a bunch of not so great patterns that we used to cache PCI interrupt line in many IRQHandler derived classes instead of just using interrupt_number method of IRQHandler class.
2021-09-29Kernel/PCI: Propagate usage of DeviceIdentifier everywhereLiav A
This allows us to remove a bunch of PCI API functions, and instead to leverage the cached data from DeviceIdentifier object in many places.
2021-09-29Kernel: Rename two PCI componentsLiav A
Rename ID => HardwareID, and PhysicalID => DeviceIdentifier. This change merely does that to clarify what these objects really are.
2021-09-29Kernel/PCI: Cache more details about PCI devices when enumerating themLiav A
There's no good reason to fetch these values each time we need them.
2021-09-20Kernel: Clean up PCI::Device namespace formattingBen Wiederhake
2021-09-12Kernel: Move ACPI and BIOS code into the new Firmware directoryLiav A
This will somwhat help unify them also under the same SysFS directory in the commit. Also, it feels much more like this change reflects the reality that both ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-12Kernel/SysFS: Move the PCI bus directory to the /sys/bus directoryLiav A
The USB bus directory is already in /sys/bus directory, so I don't see a reason why the PCI bus directory shouldn't be in that directory too.
2021-09-08Kernel/ACPI: Return Optional container after table searchLiav A
This is a better pattern than returning a PhysicalAddress with a zero value, so the code is more understandable now.
2021-09-07Kernel: Make KBuffer::try_create_with_bytes() return KResultOrAndreas Kling
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-07Kernel/PCI: Simplify the entire subsystemLiav A
A couple of things were changed: 1. Semantic changes - PCI segments are now called PCI domains, to better match what they are really. It's also the name that Linux gave, and it seems that Wikipedia also uses this name. We also remove PCI::ChangeableAddress, because it was used in the past but now it's no longer being used. 2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as they made a bunch of unnecessary complexity. Instead, Windowed access is removed entirely (this was tested, but never was benchmarked), so we are left with IO access and memory access options. The memory access option is essentially mapping the PCI bus (from the chosen PCI domain), to virtual memory as-is. This means that unless needed, at any time, there is only one PCI bus being mapped, and this is changed if access to another PCI bus in the same PCI domain is needed. For now, we don't support mapping of different PCI buses from different PCI domains at the same time, because basically it's still a non-issue for most machines out there. 2. OOM-safety is increased, especially when constructing the Access object. It means that we pre-allocating any needed resources, and we try to find PCI domains (if requested to initialize memory access) after we attempt to construct the Access object, so it's possible to fail at this point "gracefully". 3. All PCI API functions are now separated into a different header file, which means only "clients" of the PCI subsystem API will need to include that header file. 4. Functional changes - we only allow now to enumerate the bus after a hardware scan. This means that the old method "enumerate_hardware" is removed, so, when initializing an Access object, the initializing function must call rescan on it to force it to find devices. This makes it possible to fail rescan, and also to defer it after construction from both OOM-safety terms and hotplug capabilities.
2021-09-06Kernel: Make kernel region allocators return KResultOr<NOP<Region>>Andreas Kling
This expands the reach of error propagation greatly throughout the kernel. Sadly, it also exposes the fact that we're allocating (and doing other fallible things) in constructors all over the place. This patch doesn't attempt to address that of course. That's work for our future selves.
2021-09-05Kernel: Make all Spinlocks use u8 for storage, remove templateBrian Gianforcaro
The default template argument is only used in one place, and it looks like it was probably just an oversight. The rest of the Kernel code all uses u8 as the type. So lets make that the default and remove the unused template argument, as there doesn't seem to be a reason to allow the size to be customizable.
2021-09-04Kernel/VirtIO: Determine VirtIO device class also with the PCI device IDLiav A
According to the VirtIO 1.0 specification: "Non-transitional devices SHOULD have a PCI Device ID in the range 0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem Device ID of 0x40 or higher." It also says that: "Transitional devices MUST have a PCI Revision ID of 0. Transitional devices MUST have the PCI Subsystem Device ID matching the Virtio Device ID, as indicated in section 5. Transitional devices MUST have the Transitional PCI Device ID in the range 0x1000 to 0x103f." So, for legacy devices, we know that revision ID in the PCI header won't be 1, so we probe for PCI_SUBSYSTEM_ID value. Instead of using the subsystem device ID, we can probe the DEVICE_ID value directly in case it's not a legacy device. This should cover all possibilities for identifying VirtIO devices, both per the specification of 0.9.5, and future revisions from 1.0 onwards.
2021-08-31Kernel/PCI: Fix offset error of the PCI_SUBSYSTEM valuesLiav A
Apparently both PCI_SUBSYSTEM_ID and PCI_SUBSYSTEM_VENDOR_ID offsets should be swapped from one to another to be correct.
2021-08-23Kernel: Rename PCI::DeviceController => PCI::DeviceLiav A
Now that the old PCI::Device was removed, we can complete the PCI changes by making the PCI::DeviceController to be named PCI::Device. Really the entire purpose and the distinction between the two was about interrupts, but since this is no longer a problem, just rename it to simplify things further.
2021-08-23Kernel/PCI: Delete PCI::Device in its current formLiav A
I created this class a long time ago just to be able to quickly make a PCI device to also represent an interrupt handler (because PCI devices have this capability for most devices). Then after a while I introduced the PCI::DeviceController, which is really almost the same thing (a PCI device class that has Address member in it), but is not tied to interrupts so it can have no interrupts, or spawn interrupt handlers however it wants to seems fit. However I decided it's time to say goodbye for this class for a couple of reasons: 1. It made a whole bunch of weird patterns where you had a PCI::Device and a PCI::DeviceController being used in the topic of implementation, where originally, they meant to be used mutually exclusively (you can't and really don't want to use both). 2. We can really make all the classes that inherit from PCI::Device to inherit from IRQHandler at this point. Later on, when we have MSI interrupts support, we can go further and untie things even more. 3. It makes it possible to simplify the VirtIO implementation to a great extent. While this commit almost doesn't change it, future changes can untangle some complexity in the VirtIO code. For UHCIController, E1000NetworkAdapter, NE2000NetworkAdapter, RTL8139NetworkAdapter, RTL8168NetworkAdapter, E1000ENetworkAdapter we are simply making them to inherit the IRQHandler. This makes some sense, because the first 3 devices will never support anything besides IRQs. For the last 2, they might have MSI support, so when we start to utilize those, we might need to untie these classes from IRQHandler and spawn IRQHandler(s) or MSIHandler(s) as needed. The VirtIODevice class is also a case where we currently need to use both PCI::DeviceController and IRQHandler classes as parents, but it could also be untied from the latter.