summaryrefslogtreecommitdiff
path: root/Kernel/PCI
AgeCommit message (Collapse)Author
2021-04-17Kernel: Add base support for VirtIO devicesIdan Horowitz
Based on pull #3236 by tomuta, this adds helper methods for generic device initialization, and partily-broken virtqueue helper methods Co-authored-by: Tom <tomut@yahoo.com> Co-authored-by: Sahan <sahan.h.fernando@gmail.com>
2021-04-17Kernel: Add PCI::get_BAR convenience methodIdan Horowitz
Based on pull #3236 by tomuta Co-authored-by: Tom <tomut@yahoo.com>
2021-04-17Kernel: Convert PCI Capability struct to class with convenience methodsIdan Horowitz
Based on pull #3236 by tomuta Co-authored-by: Tom <tomut@yahoo.com>
2021-04-15Everything: Add `-Wnon-virtual-dtor` flagNicholas-Baron
This flag warns on classes which have `virtual` functions but do not have a `virtual` destructor. This patch adds both the flag and missing destructors. The access level of the destructors was determined by a two rules of thumb: 1. A destructor should have a similar or lower access level to that of a constructor. 2. Having a `private` destructor implicitly deletes the default constructor, which is probably undesirable for "interface" types (classes with only virtual functions and no data). In short, most of the added destructors are `protected`, unless the compiler complained about access.
2021-04-06Kernel/PCI + CPU: Allow to access unaligned dataLiav A
2021-04-06Kernel/PCI: Don't expose virtual addresses on the kernel logLiav A
2021-04-03Kernel/PCI: Introduce a new ECAM access mechanismLiav A
Now the kernel supports 2 ECAM access methods. MMIOAccess was renamed to WindowedMMIOAccess and is what we had until now - each device that is detected on boot is assigned to a memory-mapped window, so IO operations on multiple devices can occur simultaneously due to creating multiple virtual mappings, hence the name is a memory-mapped window. This commit adds a new class called MMIOAccess (not to be confused with the old MMIOAccess class). This class creates one memory-mapped window. On each IO operation on a configuration space of a device, it maps the requested PCI bus region to that window. Therefore it holds a SpinLock during the operation to ensure that no other PCI bus region was mapped during the call. A user can choose to either use PCI ECAM with memory-mapped window for each device, or for an entire bus. By default, the kernel prefers to map the entire PCI bus region.
2021-04-03Kernel: Enable PCI ECAM method again if availableLiav A
Apparently we don't enable PCI ECAM (MMIO access to the PCI configuration space) even if we can. This is a regression, as it was enabled in the past and in unknown time it was regressed. The CommandLine::is_mmio_enabled method was renamed to CommandLine::is_pci_ecam_enabled to better represent the meaning of this method and what it determines. Also, an UNMAP_AFTER_INIT macro was removed from a method in the MMIOAccess class as it halted the system when the kernel tried to access devices after the boot process.
2021-04-03Revert "Kernel/PCI: Allow to set the PCI IRQ line of a device"Liav A
This reverts commit 36a82188a88c95315e03f6fcede237bc66831702. This register is write-only for the firmware (BIOS), and read-only for us so we shouldn't set the PCI IRQ line never. The firmware figured out the IRQ routing to the PIC for us, so changing it won't affect anything. I was mistaken when I thought that changing the value of this register will allow us to change its interrupt line, like when changing a PCI BAR to relocate device resources as desired with the requirements of the OS.
2021-03-21Kernel/PCI: Allow to set the PCI IRQ line of a deviceLiav A
This will be used later by the AHCI code to set the IRQ line to be 11, if hardware by mistake changed the value to be something we can't deal with.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-12Kernel: Convert klog() => AK::Format in PCIAndreas Kling
2021-03-04Everywhere: Remove unnecessary `clang-format off`sWilliam McPherson
Mostly due to the fact that clang-format allows aligned comments via AlignTrailingComments. We could also use raw string literals in inline asm, which clang-format deals with properly (and would be nicer in a lot of places).
2021-03-03Kernel: Move Kernel CommandLine parsing to strongly typed API.Brian Gianforcaro
Previously all of the CommandLine parsing was spread out around the Kernel. Instead move it all into the Kernel CommandLine class, and expose a strongly typed API for querying the state of options.
2021-02-28Kernel: Use default con/de-structorsBen Wiederhake
This may seem like a no-op change, however it shrinks down the Kernel by a bit: .text -432 .unmap_after_init -60 .data -480 .debug_info -673 .debug_aranges 8 .debug_ranges -232 .debug_line -558 .debug_str -308 .debug_frame -40 With '= default', the compiler can do more inlining, hence the savings. I intentionally omitted some opportunities for '= default', because they would increase the Kernel size.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-19Kernel: Slap UNMAP_AFTER_INIT on a bunch more functionsAndreas Kling
We're now able to unmap 100 KiB of kernel text after init. :^)
2021-02-17Kernel: Convert dbgprintf()/klog() => dbgln()/dmesgln() in UHCI codeAndreas Kling
2021-02-14Kernel: Assert if rounding-up-to-page-size would wrap around to 0Andreas Kling
If we try to align a number above 0xfffff000 to the next multiple of the page size (4 KiB), it would wrap around to 0. This is most likely never what we want, so let's assert if that happens.
2021-02-14Kernel: Use PANIC() in a bunch of places :^)Andreas Kling
2021-02-08Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)AnotherTest
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-01-31Kernel: Fix PCI bridge enumerationJean-Baptiste Boric
The enumeration code is already enumerating all buses, recursively enumerating bridges (which are buses) makes devices on bridges being enumerated multiple times. Also, the PCI code was incorrectly mixing up terminology; let's settle down on bus, device and function because ever since PCIe came along "slots" isn't really a thing anymore.
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25Everywhere: Debug macros instead of constexpr.asynts
This was done with the following script: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25Everywhere: Use CMake to generate AK/Debug.h.asynts
This was done with the help of several scripts, I dump them here to easily find them later: awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in) do find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \; done # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list. awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-22Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
2021-01-22Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
2021-01-09Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything: The modifications in this commit were automatically made using the following command: find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
2020-12-31Everywhere: Re-format with clang-format-11Linus Groh
Compared to version 10 this fixes a bunch of formatting issues, mostly around structs/classes with attributes like [[gnu::packed]], and incorrect insertion of spaces in parameter types ("T &"/"T &&"). I also removed a bunch of // clang-format off/on and FIXME comments that are no longer relevant - on the other hand it tried to destroy a couple of neatly formatted comments, so I had to add some as well.
2020-12-25AK: Remove custom %w format string specifierAndreas Kling
This was a non-standard specifier alias for %04x. This patch replaces all uses of it with new-style formatting functions instead.
2020-12-25AK: Remove custom %b format string specifierAndreas Kling
This was a non-standard specifier alias for %02x. This patch replaces all uses of it with new-style formatting functions instead.
2020-12-22Kernel/PCI: Add a bunch of debug output to accessorsLuke
This was useful for debugging this issue.
2020-12-22Kernel/PCI: Create device configuration space mapping before creating a ↵Luke
physical ID When enumerating the hardware using MMIO mode, it would attempt to create a physical ID first. To create a physical ID, it needs to retrieve the capabilities of the device. When enumerating the first device, there would be no device configuration space mappings. Access::get_capabilities_pointer calls PCI::read16, which in turn goes to MMIOAccess::read16_field. MMIOAccess::read16_field attempts to get a device configuration space and fully expects to get one. However, since this is the first device, there are none and it crashes with an m_has_value assertion failure. This fixes this by creating the device configuration space mapping before creating the physical ID. Testing with VMware Player 16.1.0.
2020-12-21Kernel: Add various methods to handle interrupts in the PCI subsystemLiav A
For now, we only are able to enable or disable pin based interrupts. Later, when implemented, we could utilize MSI & MSI-X interrupts.
2020-12-21Kernel: Add a method to retrieve the Physical ID for a PCI addressLiav A
2020-12-21PCI: Add list of capabilities for each device during first enumerationLiav A
2020-12-21Kernel: Add the DeviceController class in the PCI subsystemLiav A
Such device is not an IRQHandler by itself, but actually a controller of many IRQ or MSI devices. The purpose of this class is to manage multiple sources of interrupts. For example, a generic ISA IDE controller controls 2 IRQ sources - 14 and 15. So, when we initialize the IDE controller, it will initialize two IDE channels (also known as PATAChannels) to utilize IRQ 14 and 15, respectively. NVMe with MSI-X support can theoretically handle up to 2048 interrupts.
2020-11-01Kernel: Reduce code duplication in the PCI IO access read helpersLiav A
We just call the early helpers as they do the same thing like the IO access helpers.
2020-11-01Kernel: Map PCI devices only once during bootLiav A
Instead of mapping a 4KB region to access device configuration space each time we call one of the PCI helpers, just map them once during the boot process. Then, if we request to access one of those devices, we can ask the PCI subsystem to give us the virtual address where the device's configuration space is mapped.
2020-09-25Meta+Kernel: Make clang-format-10 cleanBen Wiederhake
2020-09-03Kernel: Add PCI::get_programming_interface(PCI::Address)Andreas Kling
This returns the programming interface at a given PCI address. This is sometimes referred to as "prog-if" on other systems.
2020-08-22Kernel: Prevent confusing silent misuse of PCI::AddressBen Wiederhake
2020-07-06Kernel: Add SMP IPI supportTom
We can now properly initialize all processors without crashing by sending SMP IPI messages to synchronize memory between processors. We now initialize the APs once we have the scheduler running. This is so that we can process IPI messages from the other cores. Also rework interrupt handling a bit so that it's more of a 1:1 mapping. We need to allocate non-sharable interrupts for IPIs. This also fixes the occasional hang/crash because all CPUs now synchronize memory with each other.
2020-05-29Meta: Add a script check the presence of "#pragma once" in header filesEmanuele Torre
.. and make travis run it. I renamed check-license-headers.sh to check-style.sh and expanded it so that it now also checks for the presence of "#pragma once" in .h files. It also checks the presence of a (single) blank line above and below the "#pragma once" line. I also added "#pragma once" to all the files that need it: even the ones we are not check. I also added/removed blank lines in order to make the script not fail. I also ran clang-format on the files I modified.
2020-05-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
This was supposed to be the foundation for some kind of pre-kernel environment, but nobody is working on it right now, so let's move everything back into the kernel and remove all the confusion.
2020-04-28Kernel: Add Region helpers for accessing underlying physical pagesAndreas Kling
Since a Region is basically a view into a potentially larger VMObject, it was always necessary to include the Region starting offset when accessing its underlying physical pages. Until now, you had to do that manually, but this patch adds a simple Region::physical_page() for read-only access and a physical_page_slot() when you want a mutable reference to the RefPtr<PhysicalPage> itself. A lot of code is simplified by making use of this.
2020-04-11Kernel: Instantiate network adapters in their own detect() methodsLiav A
This commit is one step forward for pluggable driver modules. Instead of creating instances of network adapter classes, we let their detect() methods to figure out if there are existing devices to initialize.
2020-04-11Kernel: Keep records of PCI::Address & PCI::ID pairs for enumerationLiav A