summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2023-05-19Kernel/ScatterGatherList: Add region_name as a part of try_create APIPankaj Raghav
Remove the hardcoded "AHCI Scattered DMA" for region name as it is a part of a common API. Add region_name parameter to the try_create API so that this API can be used by other drivers with the correct Memory region name.
2023-05-19Kernel/ScatterGatherList: Move constructor init code to try_createPankaj Raghav
The constructor code of ScatterGatherList had code that can return error. Move it to try_create for better error propagation. This removes one TODO() and one release_value_but_fixme_should_propagate_errors().
2023-05-19Kernel/ScatterGatherList: Return ErrorOr from try_createPankaj Raghav
This removes the TODO from the try_create API to return ErrorOr. This is also a preparation patch to move the init code in the constructor that can fail to this try_create function.
2023-05-19Kernel: Move a bunch of generic devices code into new subdirectoryLiav A
2023-05-17Kernel+Userland: Split bind-mounting and re-mounting from mount syscallLiav A
These 2 are an actual separate types of syscalls, so let's stop using special flags for bind mounting or re-mounting and instead let userspace calling directly for this kind of actions.
2023-05-17Kernel: Fix memory mapping size of the BootFramebufferConsoleDaniel Bertalan
The Multiboot header stores the framebuffer's pitch in bytes, so multiplying it by the pixel's size is not necessary. We ended up allocating 4 times as much memory as needed, which caused us to overlap the MMIO reserved memory area on the Raspberry Pi.
2023-05-17Kernel: Flush data cache before passing a buffer to the VC MailboxDaniel Bertalan
Otherwise, the message's contents might be in the cache only, so VideoCore will read stale/garbage data from main memory. This fixes framebuffer setup on bare metal with the data cache enabled.
2023-05-17Kernel: Add character device driver for the RPi "mini UART" (UART1)Daniel Bertalan
While the PL011-based UART0 is currently reserved for the kernel console, UART1 is free to be exposed to the userspace as `/dev/ttyS0`. This will be used as the stdout of `run-tests-and-shutdown.sh` when testing the AArch64 kernel.
2023-05-17Kernel: Add `RPi::Timer::get_clock_rate()`Daniel Bertalan
2023-05-17Kernel: Add RPi Watchdog and use it for system shutdownDaniel Bertalan
The Raspberry Pi hardware doesn't support a proper software-initiated shutdown, so this instead uses the watchdog to reboot to a special partition which the firmware interprets as an immediate halt on shutdown. When running under Qemu, this causes the emulator to exit.
2023-05-17Kernel: Unify x86-64 and AArch64 `__panic` implementationDaniel Bertalan
We now have everything in the AArch64 kernel to be able to use the full `__panic` implementation, so we can share the code with x86-64. I have kept `__assertion_failed` separate for now, as the x86-64 version directly executes inline assembly, thus `Kernel/Arch/aarch64/Panic.cpp` could not be removed.
2023-05-17Kernel: Alias `_SC_PAGE_SIZE` to `_SC_PAGESIZE`Tim Schumacher
Both of those are specified by POSIX.
2023-05-16Kernel: Add MSI support to AHCIPankaj Raghav
Add MSI support to AHCI. Prefer MSI interrupts over pin-based interrupts.
2023-05-16Kernel: Add MSI support in PCI DevicePankaj Raghav
Extend reserve_irqs, allocate_irq, enable_interrupt and disable_interrupt API to add MSI support in PCI device. The current changes only implement single MSI message support. TODOs have been added to support Multiple MSI Message (MME) support in the future.
2023-05-16Kernel: Implement {enable,disable}_msi interrupts in PCI DevicePankaj Raghav
Implement enabling and disabling MSI interrupts for a PCI device. Removes two more TODO()s from PCI::Device.cpp :^)
2023-05-16Kernel: Use PCIDeviceIdentifier is_msi_capable() to retrieve MSI statusPankaj Raghav
Instead of iterating through the capabilities, use the is_msi_capable() API from the PCIDeviceIdentifier class that belongs to the device.
2023-05-16Kernel: Add MSIInfo struct to PCI DeviceIdentifierPankaj Raghav
Add a struct named MSIInfo that stores all the relevant MSI information as a part of PCI DeviceIdentifier struct. Populate the MSI struct during the PCI device init.
2023-05-16Kernel: Restore kernel8.img for aarch64 buildAndrew Kaster
This was erroneously deleted in 420952a4334b05d6ac639429e876150c78866963
2023-05-15Kernel/aarch64: Make REGISTER_STATE_SIZE a multiple of 16 bytesTimon Kruiper
This ensure that the stack pointer also stays 16 byte aligned. This fixes a baremetal issue when getting an exception.
2023-05-15Kernel/aarch64: Dump registers when unknown exception occursTimon Kruiper
This is useful when debugging baremetal issues.
2023-05-15Kernel: Remove `FIFO::{attach,detach}(Direction)`Daniel Bertalan
These functions would have caused a `-Woverloaded-virtual` warning with GCC 13, as they shadow `File::{attach,detach}(OpenFileDescription&)`. Both of these functions had a single call site. This commit inlines `attach` into its only caller, `FIFO::open_direction`. Instead of explicitly checking `is_fifo()` in `~OpenFileDescription` before running the `detach(Direction)` overload, let's just override the regular `detach(OpenFileDescription&)` for `FIFO` to perform this action instead.
2023-05-14Meta: Remove unused debug flags, add missing GENERATE_DEBUGBen Wiederhake
Commands that were helpful while investigating this: ``` grep -P '^set' Meta/CMake/all_the_debug_macros.cmake \ | sed -Ee 's,set\((.+) ON\)$,\1,' > macros.lst for i in $(cat macros.lst); do echo -n "$i "; git grep -Pn '\b'"$i"'\b' | wc -l done | tee matches.lst sort -k2 -n matches.lst ```
2023-05-13Kernel/aarch64: Remove drawing of logo on the framebuffer during initLiav A
This logo was actually used as a first sign of life in the very early days of the aarch64 port. Now that we boot into the graphical mode of the system just fine there's no need to keep this.
2023-05-07Kernel: Add MSIx support to NVMePankaj Raghav
Add MSIx support to NVMe. Prefer MSIx over pin-based interrupts as they are more efficient and all modern hardware support them.
2023-05-07Kernel: Pass NVMeController reference to NVMequeuePankaj Raghav
This is in preparation for adding MSI(x) support to the NVMe device. NVMeInterruptQueue needs access to the PCI device to deal with MSI(x) interrupts. It is ok to pass the NVMeController as a reference to the NVMeQueue as NVMeController is the one that owns the NVMeQueue. This is very similar to how AHCIController passes its reference to its interrupt handler.
2023-05-07NVMe: Use an explicit Queue type instead of using an Optional irqPankaj Raghav
Add an explicit QueueType enum which could be used to create a poll or an interrupt queue. This is better than passing an Optional<irq>. This refactoring is in preparation for adding MSIx support to NVMe.
2023-05-07Kernel: Introduce PCIIRQHandlerPankaj Raghav
PCIIRQHandler is a generic IRQ handler that the device driver can inherit to use either Pin or MSI(x) based interrupt mechanism. The PCIIRQHandler can do what the existing IRQHandler can do for pin based interrupts but also deal with MSI based interrupts. We can hopefully convert all the PCI based devices to use this handler so that MSI(x) can be used.
2023-05-07Kernel: Add APIs to PCI Device to use MSI(x)Pankaj Raghav
Add reserve_irqs, allocate_irq, enable_interrupt and disable_interrupt API to a PCI device. reserve_irqs() can be used by a device driver that would like to reserve irqs for MSI(x) interrupts. The API returns the type of IRQ that was reserved by the PCI device. If the PCI device does not support MSI(x), then it is a noop. allocate_irq() API can be used to allocate an IRQ at an index. For MSIx the driver needs to map the vector table into the memory and add the corresponding IRQ at the given index. This API will return the actual IRQ that was used so that the driver can use it create interrupt handler for that IRQ. {enable, disable}_interrupt API is used to enable or disable a particular IRQ at the given index. It is a noop for pin-based interrupts. This could be used by IRQHandler to enable or disable an interrupt.
2023-05-07Kernel: Implement helpers to manipulate MSI(x) data structuresPankaj Raghav
MSIx table entry is used to program interrupt vectors and it is architecture specific. Add helper functions declaration in Arch/PCIMSI.h. The definition of the function is placed in the respective arch specific code.
2023-05-07Kernel: Implement {enable,disable}_msix interrupts in PCI DevicePankaj Raghav
Implement enabling and disabling MSIx interrupts for a PCI device. Removes two TODO()s from PCI::Device.cpp :^)
2023-05-07Kernel: Use PCIIdentifier is_msix_capable API to retrieve MSIx statusPankaj Raghav
Instead of iterating through the capabilities, use the is_msix_capable() API from the PCIIdentifier class that belongs to the device.
2023-05-07Kernel: Add MSIxInfo struct to PCI DeviceIdentifierPankaj Raghav
Add a struct named MSIxInfo that stores all the relevant MSIx information as a part of PCI DeviceIdentifier struct. Populate the MSIx struct during the PCI device init. As the DeviceIdentifier struct need to populate MSIx info, don't mark DeviceIdentifier as const in the PCI::Device class.
2023-05-07Kernel: Add write{8,16,32} to the PCI Capability structPankaj Raghav
MSI(x) mechanism requires the device to write to its Capability structure. Add write{8,16,32} similar to read{8,16,32}.
2023-05-07Kernel: Add reserve_interrupt_handlers APIPankaj Raghav
MSI(x) interrupts need to reserve IRQs so that it can be programmed by the device. Add an API to reserve contiguous ranges of interrupt handlers so that it can used by PCI devices that use MSI(x) mechanism. This API needs to be implemented by aarch64 architecture.
2023-05-07Kernel/PCI: Set IRQ as reserved for pin-based interruptsPankaj Raghav
Set pin-based interrupt handler as reserved during PCI bus init. This is required so that MSI(x) based interrupts can avoid sharing the IRQ which has been marked as reserved.
2023-05-07Kernel: Add m_reserved private variable to GenericInterruptHandlerPankaj Raghav
Pin-based PCI device are allocated an IRQ, and it could be shared with multiple devices. An interrupt handler with an IRQ for a PCI device will get registered only during the driver initialization. For MSI(x) interrupts, the driver has to allocate IRQs and this field can be used to skip IRQs that have already been reserved by pin-based interrupts so that we don't have to share IRQs, which generally will reduce the performance.
2023-05-07Everywhere: Change spelling of 'behaviour' to 'behavior'Ben Wiederhake
"The official project language is American English […]." https://github.com/SerenityOS/serenity/blob/5d2e9156239cd707a22ecea6c87d48e5fc1cbe84/CONTRIBUTING.md?plain=1#L30 Here's a short statistic of the occurrences of the word "behavio(u)r": $ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n 2 BEHAVIOR 24 Behaviour 32 behaviour 407 Behavior 992 behavior Therefore, it is clear that "behaviour" (56 occurrences) should be regarded a typo, and "behavior" (1401 occurrences) should be preferred. Note that The occurrences in LibJS are intentionally NOT changed, because there are taken verbatim from the specification. Hence: $ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n 2 BEHAVIOR 10 behaviour 24 Behaviour 407 Behavior 1014 behavior
2023-05-06Kernel/Memory: Fix UNMAP_AFTER_INIT page fault handlingLiav A
This was discovered by me during a work on USB keyboard patches, so it triggered this bug. The printing format for the VirtualAddress part is incorrect, leading to another crash when handling page fault after accessing UNMAP_AFTER_INIT code section.
2023-05-06Kernel: Promote the entry to the front during a cache hitPankaj Raghav
Whenever an entry is added to the cache, the last element is removed to make space for the new entry(if the cache is full). To make this an LRU cache, the entry needs to be moved to the front of the list when there is a cache hit so that the least recently used entry moves to the end to be evicted first.
2023-04-30Kernel/VirtIO: Use proper error propagation from the get_config methodLiav A
This allows us to drop null-checks at call-sites, thus simplifying the code and reducing the chance of nullptr-dereference errors.
2023-04-30Kernel/VirtIO: Improve error handling during device initializationLiav A
Rename the initialize method to initialize_virtio_resources so it's clear what this method is intended for. To ensure healthier device initialization, we could also return the type of ErrorOr<void> from this method, so in all overriden instances and in the original method code, we could leverage TRY() pattern which also does simplify the code a bit.
2023-04-30Kernel/VirtIO: Move declarations and definitions to a separate fileLiav A
2023-04-29Kernel/aarch64: Don't set multiboot_modules to an empty array on-stackLiav A
Since multiboot_modules_count is set to 0, we can safely set the multiboot_modules pointer to 0 (null pointer), as we don't use multiboot on aarch64 anyway.
2023-04-29Kernel/aarch64: Support reading the command line via the RPi MailboxDaniel Bertalan
This reuses the existing `RPi::Mailbox` interface to read the command line via a VideoCore-specific mailbox message. This will have to be replaced if that interface starts being smarter, as this is needed very early, and nothing guarantees that a smarter Mailbox interface wouldn't need to allocate or log, which is a no-no during early boot. As the response string can be arbitrarily long, it's the caller's job to provide a long enough buffer for `Mailbox::query_kernel_command_line`. This commit chose 512 bytes, as it provides a large enough headroom over the 150-200 characters implicitly added by the VC firmware. The portable way would be to parse the `/chosen/bootargs` property of the device tree, but we currently lack the scaffolding for doing that. Support for this in QEMU relies on a patch that has not yet been accepted upstream, but is available via our `Toolchain/BuildQEMU.sh` script. It should, however, work on bare metal. Tested-By: Timon Kruiper <timonkruiper@gmail.com>
2023-04-29Kernel: Store the kernel command line in a `StringView`Daniel Bertalan
The Raspberry Pi's mailbox interface does not guarantee that the returned command line is null-terminated. This commit removes that assumption from the current code, allowing the next commit to add support for reading it on the Pi. This also lets us eliminate a few manual `strlen()` calls :^)
2023-04-28Revert "Kernel/x86: Bake the Prekernel and the Kernel into one image"Tim Schumacher
Some hardware/software configurations crash KVM as soon as we try to start Serenity. The exact cause is currently unknown, so just fully revert it for now. This reverts commit 897c4e5145474d55b247a4a3b5e6bf5420279e2f.
2023-04-28Kernel/aarch64: Fix build after `is_sharing_with_others` API removalDaniel Bertalan
This commit fixes the build after the removal of `GenericInterruptHandler::is_sharing_with_others` in 8944ca830f0.
2023-04-28Kernel: Create all kernel processes before enabling boot profilingSamuel Bowman
Process created performance events for kernel processes are only ever emitted for the kernel processes that exist when profiling is enabled. Any new kernel processes created after profiling is enabled will not have corresponding process created performance events, so all kernel processes should be created before enabling profiling. NetworkTask was the only kernel process being created after enabling profiling, so we now just create it before enabling profiling. This fixes an issue where Profiler was failing to parse boot profiles as a result of NetworkTask not having a process created event.
2023-04-28Kernel/x86: Bake the Prekernel and the Kernel into one imageLiav A
The new baked image is a Prekernel and a Kernel baked together now, so essentially we no longer need to pass the Prekernel as -kernel and the actual kernel image as -initrd to QEMU, leaving the option to pass an actual initrd or initramfs module later on with multiboot.
2023-04-25Kernel: Colorize log message for paths which haven't been unveiledTimothy Flynn
The log message can be hard to spot in a sea of debug messages. Colorize it to make the message more immediately pop out.