summaryrefslogtreecommitdiff
path: root/Kernel/Arch
AgeCommit message (Collapse)Author
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: 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-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: Remove is_sharing_with_others API from GenericInterruptHandlerPankaj Raghav
is_sharing_with_others API was never really put to use properly since it was introduced. The only place where it is used in Interrupts.cpp is in conjuction with is_shared_handler() which is only true for SharedIRQHandler and is_sharing_with_others will always return false. Remove that API.
2023-04-25Kernel: Set IRQHandler m_shared_with_others when the irq is sharedPankaj Raghav
If IRQHandler's IRQ is shared, then disable_irq() should not call the controller to disable that IRQ as some other device might be using it. IRQHandler had a private variable to indicate if it is being shared: m_shared_with_others but it was never modified even if the IRQ was shared. Add a new member function set_shared_with_others() to enable/disable m_shared_with_others member of IRQHandler class. This function is called when an IRQHandler is being added/removed as a part of SharedIRQHandler.
2023-04-17Kernel: Don't get rbp from internal context switch structuresTim Schumacher
This has been broken on x86_64 since its introduction, as it features more registers to be saved, and we never held up the "rbp has to be the last pushed register" there. Instead, just copy rbp from the thread structure, which is now properly updated since the last commit.
2023-04-17Kernel: Properly update the stored thread rbp when switching contextsTim Schumacher
2023-04-15Kernel/HID: Don't use *LockRefPtrs in the I8042Controller codeLiav A
2023-04-15Kernel: Re-organize header includes in the HID subsystem codeLiav A
Just a small clean-up in the I8042Controller and HIDManagement code so it will be easier to modify this code in future changes.
2023-04-14Kernel/Storage: Modernize ATA IDE controller initialization codeLiav A
This is done by 2 ways which both fit very well together: - We stop use LockRefPtrs. We also don't allow expansion of the m_channels member, by setting it to be a fixed Array of 2 IDEChannels. - More error propagation through the code, in the construction point of IDEChannel(s). This means that in the future we could technically do something meaningful with OOM conditions when initializing an IDE controller.
2023-04-13Kernel/aarch64: Add implementation of Processor::for_eachTimon Kruiper
2023-04-13Kernel/aarch64: Change RPi::Framebuffer::PixelOrder to BGRTimon Kruiper
This is what the WindowServer expects. Confusingly the pixel format for MULTIBOOT_FRAMEBUFFER_TYPE_RGB is actually BGRx8888.
2023-04-13Kernel/aarch64: Add volatile modifier to various asm statementsTimon Kruiper
This prevents the optimizer from reordering them, which hopefully prevents future bugs.
2023-04-13Kernel/aarch64: Make sure no reordering of DAIF::read is possibleTimon Kruiper
We were crashing on the VERIFY_INTERRUPTS_DISABLED() in RecursiveSpinlock::unlock, which was caused by the compiler reordering instructions in `sys$get_root_session_id`. In this function, a SpinLock is locked and quickly unlocked again, and since the lock and unlock functions were inlined into `sys$get_root_session_id` and the DAIF::read was missing the `volatile` keyword, the compiler was free to reorder the reads from the DAIF register to the top of this function. This caused the CPU to read the interrupts state at the beginning of the function, and storing the result on the stack, which in turn caused the VERIFY_INTERRUPTS_DISABLED() assertion to fail. By adding the `volatile` modifier to the inline assembly, the compiler will not reorder the instructions. In aa40cef2b7, I mistakenly assumed that the crash was related to the initial interrupts state of the kernel threads, but it turns out that the missing `volatile` keyword was the actual problem. This commit also removes that code again.
2023-04-09Kernel/HID: Untie the PS2 protocol, i8042 hardware and generic devicesLiav A
For a very long time, the kernel had only support for basic PS/2 devices such as the PS2 AT keyboard and regular PS2 mouse (with a scroll wheel). To adapt to this, we had very simple abstractions in place, essentially, the PS2 devices were registered as IRQ handlers (IRQ 1 and 12), and when an interrupt was triggered, we simply had to tell the I8042Controller to fetch a byte for us, then send it back to the appropriate device for further processing and queueing of either a key event, or a mouse packet so userspace can do something meaningful about it. When we added the VMWare mouse integration feature it was easily adapted to this paradigm, requiring small changes across the handling code for these devices. This patch is a major cleanup for any future advancements in the HID subsystem. It ensures we do things in a much more sane manner: - We stop using LockRefPtrs. Currently, after the initialization of the i8042 controller, we never have to change RefPtrs in that class, as we simply don't support PS2 hotplugging currently. Also, we remove the unnecessary getters for keyboard and mouse devices which also returned a LockRefPtr. - There's a clear separation between PS2 devices and the actual device nodes that normally exist in /dev. PS2 devices are not polled, because when the user uses these devices, they will trigger an IRQ which when is handled, could produce either a MousePacket or KeyEvent, depending on the device state. The separation is crucial for buses that are polled, for example - USB is a polled bus and will not generate an IRQ for HID devices. - There's a clear separation in roles of each structure. The PS2 devices which are attached to a I8042Controller object are managing the device state, while the generic MouseDevice and KeyboardDevice manage all related tasks of a CharacterDevice, as well as interpreting scan code events and mouse relative/absolute coordinates.
2023-04-09Kernel: Move HIDDevice::enable_interrupts method to I8042Device classLiav A
It happens to be that only PS/2 devices that are connected via the i8042 controller can generate interrupt events, so it makes much more sense to have those devices to implement the enable_interrupts method because of the I8042Device class and not the HIDDevice class.
2023-04-09Kernel: Introduce a new super class called HIDControllerLiav A
Use the new class in HID code, because all other HID device controllers will be using this class as their parent class. Hence, we no longer keep a reference to any PS/2 device in HIDManagement and rely on HIDController derived classes to do this for us. It also means that we removed another instance of a LockRefPtr, which is designated to be removed and is replaced by the better pattern of SpinlockProtected<RefPtr<>> instead.
2023-04-09Kernel: Remove redundant HID name from all associated filesLiav A
2023-04-08Kernel: Fix compilation of aarch64/RPi/Framebuffer.cppBrian Gianforcaro
The definitions were being defined already by `BootInfo.h` and that was being included here via transitive includes. The extern definitions of the variables do not have the `READONLY_AFTER_INIT` attribute in `BootInfo.h`. This causes conflicting definitions of the same variable. The `READONLY_AFTER_INIT` specifier is not needed for extern variables as it only effects their linkage, not their actual use, so just use the versions in `BootInfo.h` instead of re-declaring.
2023-04-07Kernel: Fix typo in the FramebufferGetPitchMboxMessage nameLiav A
2023-04-06Kernel/aarch64: Actually remove Arch/aarch64/init.cppTimon Kruiper
The idea was to remove this file in bd2011406, but that did not actually happen. Let's actually remove it.
2023-04-06Kernel/aarch64: Add getters/setters in RegisterState and ThreadRegistersTimon Kruiper
Specifically this commit implements two setters set_userspace_sp and set_ip in RegisterState.h, and also adds a stack pointer getter (sp) in ThreadRegisters.h. Contributed by konrad, thanks for that.
2023-04-06Kernel/aarch64: Implement copying of kernel regs into ptrace regsTimon Kruiper
And also vice versa. Contributed by konrad, thanks for that.
2023-04-06Kernel+LibC: Modify aarch64's __mcontext to store registers in an arrayTimon Kruiper
This commit also removes the unnecessary ifdefs from sys/arch/aarch64/regs.h. Contributed by konrad, thanks for that.
2023-04-06Kernel/aarch64: Flush entire TLB cache when changing TTBR0_EL1Timon Kruiper
Setting the page table base register (ttbr0_el1) is not enough, and will not flush the TLB caches, in contrary with x86_64 where setting the CR3 register will actually flush the caches. This commit adds the necessary code to properly flush the TLB caches when context switching. This commit also changes Processor::flush_tlb_local to use the vmalle1 variant, as previously we would be flushing the tlb's of all the cores in the inner-shareable domain.
2023-04-06Kernel: Store a pointer to the owner process in PageDirectoryIdan Horowitz
This replaces the previous owning address space pointer. This commit should not change any of the existing functionality, but it lays down the groundwork needed to let us properly access the region table under the address space spinlock during page fault handling.
2023-04-04Kernel: Simplify Process factory functionsAndreas Kling
- Instead of taking the first new thread as an out-parameter, we now bundle the process and its first thread in a struct and use that as the return value. - Make all Process factory functions return ErrorOr. Use this to convert some places to more TRY(). - Drop the "try_" prefix on Process factory functions.
2023-04-04Kernel/aarch64: Implement `Processor::time_spent_idle()`Caoimhe
2023-04-03Kernel: Merge x86_64 and aarch64 init.cpp filesTimon Kruiper
2023-04-03Kernel: Move deferred call code into separate DeferredCallPool classTimon Kruiper
This allows us to share this code between the x86_64 and aarch64 build.
2023-04-03Kernel/aarch64: Correctly implement Processor::leave_criticalTimon Kruiper
2023-04-03Kernel/aarch64: Move query_firmware_version into RPi::MailboxTimon Kruiper
This is for the upcoming commit that merges the x86_64 and aarch64 init.cpp files.
2023-04-03Kernel/aarch64: Move logo drawing and initializing into RPi::FramebufferTimon Kruiper
This is for a upcoming commit that merges the x86_64 and aarch64 init.cpp files.
2023-04-03Kernel/aarch64: Rename Processor::install to Processor::early_initializeTimon Kruiper
Also pass the cpu number to Processor::initialize. This way the init code can be shared between the x86_64 and aarch64 build.
2023-04-03Kernel: Implement Processor::assume_context for AArch64Idan Horowitz
With this implemented sys$execve should be fully working on AArch64.
2023-04-03Kernel: Call exit_trap in AArch64 restore_context_and_eretIdan Horowitz
This matches x86_64's behaviour in common_trap_exit. (called from thread_context_first_enter) Currently thread_context_first_enter is only called when creating new processes from scratch, in which case this doesn't change the actual behaviour. But once thread_context_first_enter is called as part of execve support, this will ensure the Thread's m_current_trap is set correctly to the new trap frame.
2023-04-03Kernel: Abstract Processor::assume_context flags using InterruptsStateIdan Horowitz
The details of the specific interrupt bits that must be turned on are irrelevant to the sys$execve implementation. Abstract it away to the Processor implementations using the InterruptsState enum.
2023-04-03Kernel: Stop overwriting AArch64 link register in forked processesIdan Horowitz
Forked processes already have an existing value for the link register, which we can't overwrite. But since they're forked the original link register value that points to exit_kernel_thread was already saved somewhere on the stack, so it's ok not to set it.
2023-03-25Revert "Kernel/aarch64: Embed disk image into kernel binary"Marco Cutecchia
This reverts commit 3b65fd64fc3b0a40607d45da9bc2703ac58612fd. This is no longer needed as we don't use the ramdisk anymore Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25Kernel: Add an SD card driver for the aarch64 portMarco Cutecchia
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25Kernel: Allow enabling high level detection on GPIOsMarco Cutecchia
Co-authored-by: Timon Kruiper <timonkruiper@gmail.com> Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25Kernel: Use u64 instead of int for the bitfields of CPACR_EL1Marco Cutecchia
This fixes the Clang build of the aarch64 port
2023-03-15Kernel/Storage: Use NonnullRefPtr for storage controllersPankaj Raghav
Storage controllers are initialized during init and are never modified. NonnullRefPtr can be safely used instead of the NonnullLockRefPtr. This also fixes one of the UB issue that was there when using an NVMe device because of NonnullLockRefPtr. We can add proper locking when we need to modify the storage controllers after init.