Commit graph

8277 commits

Author SHA1 Message Date
Pankaj Raghav f0b6eb6932 Kernel: Implement helpers to manipulate MSI(x) data structures
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-07 21:16:41 +02:00
Pankaj Raghav bf7ac06d7b Kernel: Implement {enable,disable}_msix interrupts in PCI Device
Implement enabling and disabling MSIx interrupts for a PCI device.

Removes two TODO()s from PCI::Device.cpp :^)
2023-05-07 21:16:41 +02:00
Pankaj Raghav d3bb63afff Kernel: Use PCIIdentifier is_msix_capable API to retrieve MSIx status
Instead of iterating through the capabilities, use the
is_msix_capable() API from the PCIIdentifier class that belongs to the
device.
2023-05-07 21:16:41 +02:00
Pankaj Raghav d0fbaf790a Kernel: Add MSIxInfo struct to PCI DeviceIdentifier
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-07 21:16:41 +02:00
Pankaj Raghav 71c75873c9 Kernel: Add write{8,16,32} to the PCI Capability struct
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-07 21:16:41 +02:00
Pankaj Raghav 91da264a4c Kernel: Add reserve_interrupt_handlers API
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-07 21:16:41 +02:00
Pankaj Raghav a5ec5f07fa Kernel/PCI: Set IRQ as reserved for pin-based interrupts
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-07 21:16:41 +02:00
Pankaj Raghav e5cc78e9db Kernel: Add m_reserved private variable to GenericInterruptHandler
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-07 21:16:41 +02:00
Ben Wiederhake 36ff6187f6 Everywhere: Change spelling of 'behaviour' to 'behavior'
"The official project language is American English […]."
5d2e915623/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-07 01:05:09 +02:00
Liav A 36bb04d792 Kernel/Memory: Fix UNMAP_AFTER_INIT page fault handling
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-06 08:03:34 +02:00
Pankaj Raghav ac9d60bb13 Kernel: Promote the entry to the front during a cache hit
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-05-06 08:00:55 +02:00
Liav A bc3eb6d65f Kernel/VirtIO: Use proper error propagation from the get_config method
This allows us to drop null-checks at call-sites, thus simplifying the
code and reducing the chance of nullptr-dereference errors.
2023-04-30 06:03:47 +02:00
Liav A 87a32ab869 Kernel/VirtIO: Improve error handling during device initialization
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-30 06:03:47 +02:00
Liav A aa985a0570 Kernel/VirtIO: Move declarations and definitions to a separate file 2023-04-30 06:03:47 +02:00
Liav A d430ee8bec Kernel/aarch64: Don't set multiboot_modules to an empty array on-stack
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-29 08:53:29 -06:00
Daniel Bertalan 81dd29f713 Kernel/aarch64: Support reading the command line via the RPi Mailbox
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-29 08:24:18 +02:00
Daniel Bertalan 6aa392f6e4 Kernel: Store the kernel command line in a StringView
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-29 08:24:18 +02:00
Tim Schumacher 9ab598af49 Revert "Kernel/x86: Bake the Prekernel and the Kernel into one image"
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 897c4e5145.
2023-04-28 23:24:19 +02:00
Daniel Bertalan a0356a0302 Kernel/aarch64: Fix build after is_sharing_with_others API removal
This commit fixes the build after the removal of
`GenericInterruptHandler::is_sharing_with_others` in 8944ca830f.
2023-04-28 15:00:06 +02:00
Samuel Bowman fc1fd907b4 Kernel: Create all kernel processes before enabling boot profiling
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-28 09:27:55 +02:00
Liav A 897c4e5145 Kernel/x86: Bake the Prekernel and the Kernel into one image
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-28 09:23:30 +02:00
Timothy Flynn 3d4d0a1243 Kernel: Colorize log message for paths which haven't been unveiled
The log message can be hard to spot in a sea of debug messages. Colorize
it to make the message more immediately pop out.
2023-04-25 18:04:15 +02:00
Pankaj Raghav 8944ca830f Kernel: Remove is_sharing_with_others API from GenericInterruptHandler
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-25 10:18:39 +02:00
Pankaj Raghav 756a73471e Kernel: Use SpinlockProtected list in SharedIRQHandler
Adding handlers to the SharedIRQHandler without any lock is not thread
safe. Use SpinlockProtected list instead.
2023-04-25 10:18:39 +02:00
Pankaj Raghav fd8a154f8c Kernel: Set IRQHandler m_shared_with_others when the irq is shared
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-25 10:18:39 +02:00
Pankaj Raghav 83b87a5ade Kernel: Add bar_address_mask to mask the last 4 bits of a BAR address
Create a bar_address_mask constant to mask the last 4 bits of a BAR
address instead of hand coding the mask all over the kernel.
2023-04-24 21:41:54 +02:00
Liav A 7b6cea9ef4 Kernel: Improve context state keeping in the VirtIOGPU3DDevice class
This is done mainly by implementing safe locking on the data structure
keeping the pointers to the PerContextState objects. Therefore, this now
eliminates the need for using LockRefPtr, as SpinlockProtected is enough
for the whole list.

The usage of HashMap in this class was questionable, and according to
Sahan Fernando (the original contributor to the VirGL work also known as
ccapitalK) there was no deep research on which data structure to use for
keeping all pointers to PerContextState objects.
Therefore, this structure is changed to IntrusiveList as the main reason
and advantage to use it is that handling OOM conditions is much more
simple, because if we succeeded to create a PerContextState object, we
can be sure now that inserting it to the list will not cause OOM error
condition.
2023-04-24 13:09:22 +02:00
Liav A 8289759f1d Kernel: Allow configuring a Jail to not impose PID isolation restriction
This is quite useful for userspace applications that can't cope with the
restriction, but it's still useful to impose other non-configurable
restrictions by using jails.
2023-04-24 12:15:29 +02:00
Daniel Bertalan d205814da6 Kernel+LibC: Implement pthread_create for AArch64
Instead of storing x86_64 register names in `SC_create_thread_params`,
let the Kernel figure out how to pass the parameters to
`pthread_create_helper`.
2023-04-23 14:30:59 +02:00
Liav A ee4e9b807a Kernel: Protect internal structures in InodeWatcher with spinlocks
This was the last change that was needed to be able boot with the flag
of LOCK_IN_CRITICAL_DEBUG. That flag is not always enabled because there
are still other issues in which we hold a spinlock and still try to lock
a mutex.

Instead of using one global mutex we can protect internal structures of
the InodeWatcher class with SpinlockProtected wrappers. This in turn
allows the InodeWatcher code to be called from other parts in the kernel
while holding a prior spinlock properly.
2023-04-22 07:16:41 +02:00
Tim Schumacher 12ce6ef3d7 Kernel+Userland: Remove the nfds entry from /sys/kernel/processes
`process.fds()` is protected by a Mutex, which causes issues when we try
to acquire it while holding a Spinlock. Since nothing seems to use this
value, let's just remove it entirely for now.
2023-04-21 13:55:23 +02:00
Hendiadyoin1 d10e838efd Kernel: Add a FIXME about SD card synchronicity
This is a major bottleneck when booting the system, especially in
non-smp mode.
2023-04-19 10:53:33 +01:00
Hendiadyoin1 863d0ac260 Kernel: Add High Speed support to the SDHC driver
This should not affect boot times on qemu, as that does not use
dynamic transfer delays in its adma code path.
On real hardware this could potentially double the data throughput,
decreasing load times.
2023-04-19 10:53:33 +01:00
Hendiadyoin1 857c9b4558 Kernel: Add basic ADMA2 support to the SD card driver
It only takes ~10s to fully boot with smp enabled!
2023-04-19 10:53:33 +01:00
Hendiadyoin1 daf85732bc Kernel: Make SDHC InterruptStatus a bitfield
A raw accessor was left as a means to use already existing codepaths.
2023-04-19 10:53:33 +01:00
Hendiadyoin1 35ec96fd28 Kernel: Add V4.10 fields to SDHC Command struct
They are not used yet but might become helpful in the future
2023-04-19 10:53:33 +01:00
Hendiadyoin1 fb79b09688 Kernel: Turn SD CapabilitiesRegister into a bit-field 2023-04-19 10:53:33 +01:00
Tim Schumacher aefd6e9ee1 Kernel: Don't get rbp from internal context switch structures
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-17 20:30:17 +02:00
Tim Schumacher 0ee476948b Kernel: Properly update the stored thread rbp when switching contexts 2023-04-17 20:30:17 +02:00
Tim Schumacher 50b7183bd1 Kernel: Mark the idle thread as active before switching it in
Otherwise, our code for dumping all thread stacks gets confused if it
finds a thread that is in a 'running' state, but that isn't marked
active.
2023-04-17 20:30:17 +02:00
Tim Schumacher d4e114a31e Kernel: Remove unused functions related to reading full inodes 2023-04-17 01:20:23 +02:00
Tim Schumacher f5010f7263 Kernel: Use purpose-sized buffers for holding readlink results 2023-04-17 01:20:23 +02:00
Tim Schumacher 6f524e35a7 Kernel: Use purpose-sized buffers when resolving inodes as links 2023-04-17 01:20:23 +02:00
Tim Schumacher acd8c8dba4 Kernel: Add Inode::read_until_filled_or_end
The existing `read_entire` is quite slow due to allocating and copying
multiple times, but it is simultaneously quite hard to get rid of in a
single step. As a replacement, add a new function that reads as much as
possible directly into a user-provided buffer.
2023-04-17 01:20:23 +02:00
Liav A 32557be930 Kernel/HID: Don't use *LockRefPtrs in the I8042Controller code 2023-04-15 12:53:31 +02:00
Liav A 747efc5265 Kernel: Re-organize header includes in the HID subsystem code
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-15 12:53:31 +02:00
Marco Cutecchia 75cc670bcb Kernel: Disable interrupt signaling for the SD driver
Currently we do not use interrupts for the SD driver, yet we
had enabled the signaling of all of them.
Since we were never acknowledging them, we were getting spammed by
unnecessary interrupts, causing the system to slow down to a crawl.

This commit makes the system boot in less than 1 minute with PIO,
compared to the old 30+ minute boot.
2023-04-15 11:16:22 +01:00
Liav A 7c1f645e27 Kernel/Net: Iron out the locking mechanism across the subsystem
There is a big mix of LockRefPtrs all over the Networking subsystem, as
well as lots of room for improvements with our locking patterns, which
this commit will not pursue, but will give a good start for such work.

To deal with this situation, we change the following things:
- Creating instances of NetworkAdapter should always yield a non-locking
  NonnullRefPtr. Acquiring an instance from the NetworkingManagement
  should give a simple RefPtr,as giving LockRefPtr does not really
  protect from concurrency problems in such case.
- Since NetworkingManagement works with normal RefPtrs we should
  protect all instances of RefPtr<NetworkAdapter> with SpinlockProtected
  to ensure references are gone unexpectedly.
- Protect the so_error class member with a proper spinlock. This happens
  to be important because the clear_so_error() method lacked any proper
  locking measures. It also helps preventing a possible TOCTOU when we
  might do a more fine-grained locking in the Socket code, so this could
  be definitely a start for this.
- Change unnecessary LockRefPtr<PacketWithTimestamp> in the structure
  of OutgoingPacket to a simple RefPtr<PacketWithTimestamp> as the whole
  list should be MutexProtected.
2023-04-14 19:27:56 +02:00
Liav A bd7d4513bf Kernel/Net: Make the LoopbackAdapter initializer to use ErrorOr pattern
This looks much more nice, and also matches our pattern for other types
of network adapters' initializers.
2023-04-14 19:27:56 +02:00
Liav A 9f011592be Kernel/Net: Convert initializers to return NonnullRefPtr<NetworkAdapter>
There's no need for using NonnullLockRefPtr here.
2023-04-14 19:27:56 +02:00
Liav A b02ee664e7 Kernel: Get rid of *LockRefPtr in the SysFS filesystem code
To do this we also need to get rid of LockRefPtrs in the USB code as
well.
Most of the SysFS nodes are statically generated during boot and are not
mutated afterwards.

The same goes for general device code - once we generate the appropriate
SysFS nodes, we almost never mutate the node pointers afterwards, making
locking unnecessary.
2023-04-14 19:24:54 +02:00
Liav A dd7633c5f4 Kernel/Audio: Propagate errors when creating AudioChannels
While doing this, we can also just return a normal RefPtr instead of a
LockRefPtr, because we create these channels when initializing an audio
controller, and never change the pointer in AudioController instances
after their initialization, hence no locking is necessary.
2023-04-14 19:23:12 +02:00
Liav A 4921561687 Kernel/Audio: Simplify initialization sequence for drivers
Instead of enumerating all available controllers and then ask each to
find its audio channels, we change the initialization sequence to match
what happens in the Networking subsystem and Graphics subsystem - we
essentially probe for a matching driver on a PCI device, create a device
instance, and immediately initialize it.

This in fact allows us to immediately find any hardware initialization
issues and report it, and then dropping the created instance, as usually
being done in other initialization paths in the Kernel.

This also opens the opportunity to propagate errors when failed to
initialize an AudioChannel instance, and it will be addressed in a
future commit.
2023-04-14 19:23:12 +02:00
Liav A 0050358cd3 Kernel/Storage: Modernize ATA IDE controller initialization code
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-14 19:20:43 +02:00
Liav A dac7e911e6 Kernel/Storage: Remove unused IDEController::initialize() method 2023-04-14 19:20:43 +02:00
Liav A 93fceb1890 Kernel: Stop using LockRefPtrs in the Jail code
Each Jail object within the list is already protected by the global list
spinlock, therefore there's no need for using LockRefPtrs at all.
2023-04-14 19:17:49 +02:00
Liav A e8510b6415 Kernel: Make Jail class to be AtomicRefCounted instead of RefCounted
This will help ensuring that taking and dropping a reference, hence
changing the ref-count, will be done in a safe manner in terms of
concurrency.
2023-04-14 19:17:49 +02:00
Tim Schumacher 9be5dcfd89 Kernel: Also search the main program for stack size requests 2023-04-14 16:12:04 +01:00
Tim Schumacher ed74f792e2 Kernel: Pick the maximum out of the requested stack sizes 2023-04-14 16:12:04 +01:00
Arda Cinar 38dc54317c Kernel/Net: Implement SIOCGIFINDEX and SIOCGIFNAME for sockets
These ioctls exist on Linux and can be used to implement libc functions
if_indextoname and if_nametoindex (without needing to parse any JSON).
2023-04-14 12:29:03 +01:00
Timon Kruiper 9ed04bdb33 Kernel/aarch64: Add implementation of Processor::for_each 2023-04-13 20:24:25 +02:00
Timon Kruiper 4927eb5396 Kernel/aarch64: Change RPi::Framebuffer::PixelOrder to BGR
This is what the WindowServer expects. Confusingly the pixel format for
MULTIBOOT_FRAMEBUFFER_TYPE_RGB is actually BGRx8888.
2023-04-13 20:22:08 +02:00
Timon Kruiper baa5cb9e30 Kernel/aarch64: Add volatile modifier to various asm statements
This prevents the optimizer from reordering them, which hopefully
prevents future bugs.
2023-04-13 20:22:08 +02:00
Timon Kruiper 10030038e9 Kernel/aarch64: Make sure no reordering of DAIF::read is possible
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-13 20:22:08 +02:00
Liav A cbf78975f1 Kernel: Add the futimens syscall
We have a problem with the original utimensat syscall because when we
do call LibC futimens function, internally we provide an empty path,
and the Kernel get_syscall_path_argument method will detect this as an
invalid path.

This happens to spit an error for example in the touch utility, so if a
user is running "touch non_existing_file", it will create that file, but
the user will still see an error coming from LibC futimens function.

This new syscall gets an open file description and it provides the same
functionality as utimensat, on the specified open file description.
The new syscall will be used later by LibC to properly implement LibC
futimens function so the situation described with relation to the
"touch" utility could be fixed.
2023-04-10 10:21:28 +02:00
Liav A fb8d4b7032 Kernel/Memory: Explain better why we don't use the first 1 MiB on x86_64 2023-04-09 19:40:45 -06:00
Liav A 5a94e8dfd0 Kernel: Ensure jailed processes can be reaped by a jailed parent process
We were detaching from the jail process list too early. To ensure we
detach properly, leverage the remove_from_secondary_lists method
so the possibly jailed parent process can still see the dying process
and therefore clean it properly.
2023-04-09 18:49:01 +02:00
Liav A bfffe88de5 Kernel/HID: Untie the PS2 protocol, i8042 hardware and generic devices
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-09 18:11:37 +02:00
Liav A 3a261f5ee8 Kernel: Stop lock & unlock repeatedly while reading from a mouse device
This was a thing we needed to do in the days where we didn't have
safe_memcpy and some wrappers around it to handle possible page faults
safely.
2023-04-09 18:11:37 +02:00
Liav A d8cbda6950 Kernel: Move HIDDevice::enable_interrupts method to I8042Device class
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-09 18:11:37 +02:00
Liav A d76c08c9b0 Kernel: Introduce a new super class called HIDController
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-09 18:11:37 +02:00
Liav A 6c4a47d916 Kernel: Remove redundant HID name from all associated files 2023-04-09 18:11:37 +02:00
Idan Horowitz 01318d8f9b Kernel: Check flags for MAP_FIXED instead of prot in sys$mmap
We were accidentally not enforcing the map_fixed pledge
2023-04-09 11:10:37 +03:00
Idan Horowitz 6b08b18a9a Kernel: Crash process instead of panicking on KSYMS access
Also do the same for READONLY_AFTER_INIT and UNMAP_AFTER_INIT.
2023-04-09 11:10:37 +03:00
Brian Gianforcaro e891f13c84 Kernel: Fix compilation of aarch64/RPi/Framebuffer.cpp
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-08 19:16:35 -07:00
Liav A 7b745a20f1 Kernel: Mark a bunch of NonnullRefPtrs also const to ensure immutability
These were easy to pick-up as these pointers are assigned during the
construction point and are never changed afterwards.

This small change to these pointers will ensure that our code will not
accidentally assign these pointers with a new object which is always a
kind of bug we will want to prevent.
2023-04-08 13:44:21 +02:00
Andreas Kling 9264303f5d Kernel: Don't reuse old master TLS region data in sys$execve()
When switching to the new address space, we also have to switch the
Process::m_master_tls_* variables as they may refer to a region in
the old address space.

This was causing `su` to not run correctly.

Regression from 65641187ff.
2023-04-08 07:28:27 +02:00
Liav A b87747fa64 Kernel: Fix typo in the FramebufferGetPitchMboxMessage name 2023-04-07 10:43:45 +02:00
Timon Kruiper 2b6c44852c Kernel/aarch64: Actually remove Arch/aarch64/init.cpp
The idea was to remove this file in bd2011406, but that did not actually
happen. Let's actually remove it.
2023-04-06 22:06:03 +03:00
Timon Kruiper e9b40863ab Kernel: Make dispatch_signal work for aarch64 2023-04-06 21:19:58 +03:00
Timon Kruiper 00df1fc060 Kernel: Store FPU state when dispatching signal on aarch64
And make sure to also restore it in sys$sigreturn.
2023-04-06 21:19:58 +03:00
Timon Kruiper 4e00c63897 Kernel: Implement signal trampoline for aarch64
With this change, we are now able to successfully boot into the text
mode! :^)
2023-04-06 21:19:58 +03:00
Timon Kruiper ec765544a5 Kernel/aarch64: Add getters/setters in RegisterState and ThreadRegisters
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-06 21:19:58 +03:00
Timon Kruiper 36362b9679 Kernel/aarch64: Implement copying of kernel regs into ptrace regs
And also vice versa. Contributed by konrad, thanks for that.
2023-04-06 21:19:58 +03:00
Timon Kruiper 200e91cd7f Kernel+LibC: Modify aarch64's __mcontext to store registers in an array
This commit also removes the unnecessary ifdefs from
sys/arch/aarch64/regs.h. Contributed by konrad, thanks for that.
2023-04-06 21:19:58 +03:00
Timon Kruiper 7440112cd9 Kernel: Implement ScopedAddressSpaceSwitcher using PageDirectory
This makes the code architecture independent, and thus makes it work for
aarch64.
2023-04-06 21:19:58 +03:00
Timon Kruiper 6a8581855d Kernel/aarch64: Flush entire TLB cache when changing TTBR0_EL1
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-06 21:19:58 +03:00
Timon Kruiper 188a52db01 Kernel: Implement TimeManagement::boot_time() for aarch64
For now just return 0 as we have no RTC support on aarch64 yet, and add
a FIXME to return the correct value.
2023-04-06 21:19:58 +03:00
Idan Horowitz 1c2dbed38a Kernel: Extend the lifetime of Regions during page fault handling
Previously we had a race condition in the page fault handling: We were
relying on the affected Region staying alive while handling the page
fault, but this was not actually guaranteed, as an munmap from another
thread could result in the region being removed concurrently.

This commit closes that hole by extending the lifetime of the region
affected by the page fault until the handling of the page fault is
complete. This is achieved by maintaing a psuedo-reference count on the
region which counts the number of in-progress page faults being handled
on this region, and extending the lifetime of the region while this
counter is non zero.
Since both the increment of the counter by the page fault handler and
the spin loop waiting for it to reach 0 during Region destruction are
serialized using the appropriate AddressSpace spinlock, eventual
progress is guaranteed: As soon as the region is removed from the tree
no more page faults on the region can start.
And similarly correctness is ensured: The counter is incremented under
the same lock, so any page faults that are being handled will have
already incremented the counter before the region is deallocated.
2023-04-06 20:30:03 +03:00
Idan Horowitz 003989e1b0 Kernel: Store a pointer to the owner process in PageDirectory
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-06 20:30:03 +03:00
Idan Horowitz 65641187ff Kernel: Restructure execve to ensure Process::m_space is always in use
Instead of setting up the new address space on it's own, and only swap
to the new address space at the end, we now immediately swap to the new
address space (while still keeping the old one alive) and only revert
back to the old one if we fail at any point.

This is done to ensure that the process' active address space (aka the
contents of m_space) always matches actual address space in use by it.
That should allow us to eventually make the page fault handler process-
aware, which will let us properly lock the process address space lock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 3f89a1b131 Kernel: Mark sys$msync as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 1dae6a2e4a Kernel: Mark sys$mremap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz db10f201c8 Kernel: Mark sys$munmap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz d1082a00b7 Kernel: Mark sys$set_mmap_name as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 2f79d0e8b9 Kernel: Mark sys$mprotect as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 3697214166 Kernel: Mark sys$mmap as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz dcdcab0099 Kernel: Remove unused credentials() call in validate_inode_mmap_prot
For some reason GCC did not complain about this.
2023-04-06 20:30:03 +03:00
Idan Horowitz 0b14081ae1 Kernel: Mark sys$map_time_page as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Idan Horowitz 0e564240a6 Kernel: Mark sys$madvise as not needing the big lock
All accesses to shared mutable data are already serialized behind the
process address space spinlock.
2023-04-06 20:30:03 +03:00
Pankaj Raghav a65b0cbe4a Kernel/NVMeQueue: Use waitqueue in submit_sync_sqe
The current way we handle sync commands is very ugly and depends on lot
of preconditions. Now that we have an end_io handler for a request, we
can use WaitQueue to do sync commands more elegantly.

This does depend on block layer sending one request at a time but this
change is a step forward towards better IO handling.
2023-04-05 12:45:27 +02:00
Pankaj Raghav 0096eadf40 Kernel/NVMe: Redesign the tracking of requests in an NVMe Queue
There was a private variable named m_current_request which was used to
track a single request at a time. This guarantee is given by the block
layer where we wait on each IO. This design will break down in the
driver once the block layer removes that constraint.

Redesign the IO handling in a completely asynchronous way by maintaining
requests up to queue depth. NVMeIO struct is introduced to track an IO
submitted along with other information such whether the IO is still
being processed and an endio callback which will be called during the
end of a request.

A hashmap private variable is created which will key based on the
command id of a request with a value of NVMeIO. endio handler will come
in handy if we are doing a sync request and we want to wake up the wait
queue during the end.

This change also simplified the code by removing some special condition
in submit_sqe function, etc that were marked as FIXME for a long time.
2023-04-05 12:45:27 +02:00
Pankaj Raghav 3fe7bda021 Kernel/NVMe: Use an Atomic for command id instead of sq index
Using sq_tail as cid makes an inherent assumption that we send only
one IO at a time. Use an atomic variable instead for command id of a
submission queue entry.

As sq_tail is not used as cid anymore, remove m_prev_sq_tail which used
to hold the last used sq_tail value.
2023-04-05 12:45:27 +02:00
Andreas Kling e219662ce0 Kernel: Mark sys$setpgid as not needing the big lock
This function is already serialized by access to process protected data.
2023-04-05 11:37:27 +02:00
Andreas Kling 84ac957d7a Kernel: Make Credentials the authority on process SID
The SID was duplicated between the process credentials and protected
data. And to make matters worse, the credentials SID was not updated in
sys$setsid.

This patch fixes this by removing the SID from protected data and
updating the credentials SID everywhere.
2023-04-05 11:37:27 +02:00
Andreas Kling f764b8b113 Kernel: Mark sys$setsid as not needing the big lock
This function is now serialized by access to the process group list,
and to the current process's protected data.
2023-04-05 11:37:27 +02:00
Andreas Kling 3e30d9bc99 Kernel: Make ProcessGroup a ListedRefCounted and fix two races
This closes two race windows:

- ProcessGroup removed itself from the "all process groups" list in its
  destructor. It was possible to walk the list between the last unref()
  and the destructor invocation, and grab a pointer to a ProcessGroup
  that was about to get deleted.

- sys$setsid() could end up creating a process group that already
  existed, as there was a race window between checking if the PGID
  is used, and actually creating a ProcessGroup with that PGID.
2023-04-05 11:37:27 +02:00
Andreas Kling 37bfc36601 Kernel: Make SlavePTY store pointer to MasterPTY as NonnullRefPtr
No need for LockRefPtr here, as the pointer never changes after
initialization.
2023-04-05 11:37:27 +02:00
Andreas Kling e69b2572a6 Kernel: Move Process's TTY pointer into protected data 2023-04-05 11:37:27 +02:00
Andreas Kling 1e2ef59965 Kernel: Move Process's process group pointer into protected data
Now that it's no longer using LockRefPtr, we can actually move it into
protected data. (LockRefPtr couldn't be stored there because protected
data is immutable at times, and LockRefPtr uses some of its own bits
for locking.)
2023-04-05 11:37:27 +02:00
Andreas Kling 1c77803845 Kernel: Stop using *LockRefPtr for TTY
TTY was only stored in Process::m_tty, so make that a SpinlockProtected.
2023-04-05 11:37:27 +02:00
Andreas Kling 350e5f9261 Kernel: Remove ancient InterruptDisabler in sys$setsid
This was some pre-SMP historical artifact.
2023-04-05 11:37:27 +02:00
Andreas Kling ca1f8cac66 Kernel: Mark sys$faccessat as not needing the big lock 2023-04-05 11:37:27 +02:00
Andreas Kling bd46397e1f Kernel: Mark inode watcher syscalls as not needing the big lock
These syscalls are already protected by existing locking mechanisms,
including the mutex inside InodeWatcher.
2023-04-04 10:33:42 +02:00
Andreas Kling 08d79c757a Kernel: Mark sys$killpg as not needing the big lock
Same as sys$kill, nothing here that isn't already protected by existing
locks.
2023-04-04 10:33:42 +02:00
Andreas Kling e71b84228e Kernel: Mark sys$kill as not needing the big lock
This syscall sends a signal to other threads or itself. This mechanism
is already guarded by locking mechanisms, and widely used within the
kernel without help from the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 3108daecc5 Kernel: Remove ancient InterruptDisablers in the kill/killpg syscalls
These are artifacts from the pre-SMP times.
2023-04-04 10:33:42 +02:00
Andreas Kling 46ab245e74 Kernel: Mark sys$getrusage as not needing the big lock
Same deal as sys$times, nothing here that needs locking at the moment.
2023-04-04 10:33:42 +02:00
Andreas Kling 3371165588 Kernel: Make the getsockname/getpeername syscall helper a bit nicer
Instead of templatizing on a bool parameter, use an enum for clarity.
2023-04-04 10:33:42 +02:00
Andreas Kling 5bc7882b68 Kernel: Make sys$times not use the big lock
...and also make the Process tick counters clock_t instead of u32.
It seems harmless to get interrupted in the middle of reading these
counters and reporting slightly fewer ticks in some category.
2023-04-04 10:33:42 +02:00
Andreas Kling b98f537f11 Kernel+Userland: Make some of the POSIX types larger
Expand the following types from 32-bit to 64-bit:
- blkcnt_t
- blksize_t
- dev_t
- nlink_t
- suseconds_t
- clock_t

This matches their size on other 64-bit systems.
2023-04-04 10:33:42 +02:00
Andreas Kling d8bb32117e Kernel: Mark sys$umask as not needing the big lock
The body of this syscall is already serialized by calling
with_mutable_protected_data().
2023-04-04 10:33:42 +02:00
Andreas Kling 6c02c493f1 Kernel: Mark sys$sigtimedwait as not needing the big lock
Yet another syscall that only messes with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling f0b5c585f2 Kernel: Mark sys$sigpending as not needing the big lock
Another one that only touches the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling e9fe0ecbae Kernel: Mark sys$sigprocmask as not needing the big lock
Another one that only messes with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling d1fae8b09c Kernel: Mark sys$sigsuspend as not needing the big lock
This syscall is only concerned with the current thread.
2023-04-04 10:33:42 +02:00
Andreas Kling 374f4aeab9 Kernel: Mark sys$sigreturn as not needing the big lock
This syscall is only concerned with the current thread (except in the
case of a pledge violation, when it will add some details about that
to the process coredump metadata. That stuff is already serialized.)
2023-04-04 10:33:42 +02:00
Andreas Kling a7212a7488 Kernel: Mark sys$open as not needing the big lock
All the individual sub-operations of this syscall are protected by their
own locking mechanisms, so it should be okay to get it off the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 97ac4601f5 Kernel: Use custody_for_dirfd() in more syscalls
This simplifies a lot of syscalls, some of which were doing very
unnecessarily verbose things instead of calling this.
2023-04-04 10:33:42 +02:00
Andreas Kling f0c9c5e076 Kernel: Make custody_for_dirfd() fail on files other than directories 2023-04-04 10:33:42 +02:00
Andreas Kling 41f5598516 Kernel: Make sys$getsid not require the big lock
Reorganize the code slightly to avoid creating a TOCTOU bug, then mark
the syscall as not needing the big lock anymore.
2023-04-04 10:33:42 +02:00
Andreas Kling 1382439267 Kernel: Mark sys$getpgrp as not needing the big lock
Access to the process's process group is already serialized by
SpinlockProtected.
2023-04-04 10:33:42 +02:00
Andreas Kling 2ddd69260c Kernel: Mark sys$getpgid as not needing the big lock
Access to the process's process group is already serialized by
SpinlockProtected.
2023-04-04 10:33:42 +02:00
Andreas Kling 775e6d6865 Kernel: Mark sys$fcntl as not needing the big lock
This syscall operates on the file descriptor table, and on individual
open file descriptions. Both of those are already protected by scoped
locking mechanisms.
2023-04-04 10:33:42 +02:00
Andreas Kling 6132193bd4 Kernel: Make sys$disown not require the big lock
This syscall had a TOCTOU where it checked the peer's PPID before
locking the protected data (where the PPID is stored).

After closing the race window, we can mark the syscall as not needing
the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 5759ea19fb Kernel: Mark sys$alarm as not needing the big lock
Access to Process::m_alarm_timer is serialized via SpinlockProtected,
so there's no longer need for this syscall to use the big lock.
2023-04-04 10:33:42 +02:00
Andreas Kling 496d918e92 Kernel: Stop using *LockRefPtr for Kernel::Timer 2023-04-04 10:33:42 +02:00
Andreas Kling 83b409083b Kernel: Stop using *LockRefPtr for ProcessGroup
Had to wrap Process::m_pg in a SpinlockProtected for this to be safe.
2023-04-04 10:33:42 +02:00
Andreas Kling ed1253ab90 Kernel: Don't ref/unref the holder thread in Mutex
There was a whole bunch of ref counting churn coming from Mutex, which
had a RefPtr<Thread> m_holder to (mostly) point at the thread holding
the mutex.

Since we never actually dereference the m_holder value, but only use it
for identity checks against thread pointers, we can store it as an
uintptr_t and skip the ref counting entirely.

Threads can't die while holding a mutex anyway, so there's no risk of
them going missing on us.
2023-04-04 10:33:42 +02:00
Andreas Kling c3915e4058 Kernel: Stop using *LockRefPtr for Thread
These were stored in a bunch of places. The main one that's a bit iffy
is the Mutex::m_holder one, which I'm going to simplify in a subsequent
commit.

In Plan9FS and WorkQueue, we can't make the NNRPs const due to
initialization order problems. That's probably doable with further
cleanup, but left as an exercise for our future selves.

Before starting this, I expected the thread blockers to be a problem,
but as it turns out they were super straightforward (for once!) as they
don't mutate the thread after initiating a block, so they can just use
simple const-ified NNRPs.
2023-04-04 10:33:42 +02:00
Andreas Kling a098266ff5 Kernel: Simplify Process factory functions
- 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-04 10:33:42 +02:00
Andreas Kling 65438d8a85 Kernel: Stop using *LockRefPtr for Process pointers
The only persistent one of these was Thread::m_process and that never
changes after initialization. Make it const to enforce this and switch
everything over to RefPtr & NonnullRefPtr.
2023-04-04 10:33:42 +02:00
Andreas Kling 19084ef743 Kernel: Simplify Mount internals
- The host custody never changes after initialization, so there's no
  need to protect it with a spinlock.

- To enforce the fact that some members don't change after
  initialization, make them const.
2023-04-04 10:33:42 +02:00
Andreas Kling 673592dea8 Kernel: Stop using *LockRefPtr for FileSystem pointers
There was only one permanent storage location for these: as a member
in the Mount class.

That member is never modified after Mount initialization, so we don't
need to worry about races there.
2023-04-04 10:33:42 +02:00
Caoimhe 3f69ef86c2 Kernel/aarch64: Implement Processor::time_spent_idle() 2023-04-04 10:30:09 +02:00
Timon Kruiper bd2011406e Kernel: Merge x86_64 and aarch64 init.cpp files 2023-04-03 20:01:28 -06:00
Timon Kruiper c31dc82b17 Kernel: Move deferred call code into separate DeferredCallPool class
This allows us to share this code between the x86_64 and aarch64 build.
2023-04-03 20:01:28 -06:00
Timon Kruiper 1f68ac600c Kernel/aarch64: Correctly implement Processor::leave_critical 2023-04-03 20:01:28 -06:00
Timon Kruiper 1fa1f09c38 Kernel/Graphics: Only search for PCI graphics cards on x86_64
This is for the upcoming commit that merges the x86_64 and aarch64
init.cpp files.
2023-04-03 20:01:28 -06:00
Timon Kruiper 14d20618f1 Kernel/aarch64: Move query_firmware_version into RPi::Mailbox
This is for the upcoming commit that merges the x86_64 and aarch64
init.cpp files.
2023-04-03 20:01:28 -06:00
Timon Kruiper 2613ac4cb4 Kernel/aarch64: Move logo drawing and initializing into RPi::Framebuffer
This is for a upcoming commit that merges the x86_64 and aarch64
init.cpp files.
2023-04-03 20:01:28 -06:00
Timon Kruiper aa40cef2b7 Kernel: Disable interrupts for aarch64 in WorkQueue's main loop
This code expects to be executed with interrupts disabled, however we
currently spawn (kernel) threads with interrupts enabled on aarch64.
2023-04-03 20:01:28 -06:00
Timon Kruiper 05b9eb7feb Kernel/aarch64: Rename Processor::install to Processor::early_initialize
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-03 20:01:28 -06:00
Idan Horowitz 402c9e5e23 Kernel: Implement Processor::assume_context for AArch64
With this implemented sys$execve should be fully working on AArch64.
2023-04-03 02:59:37 -06:00
Idan Horowitz 0dc5c49938 Kernel: Call exit_trap in AArch64 restore_context_and_eret
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-03 02:59:37 -06:00
Idan Horowitz a349570a04 Kernel: Abstract Processor::assume_context flags using InterruptsState
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-03 02:59:37 -06:00
Idan Horowitz 6ad8f4bb11 Kernel: Stop overwriting AArch64 link register in forked processes
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-04-03 02:59:37 -06:00
Idan Horowitz 8669f4ce45 Kernel: Add AArch64 support to sys$fork 2023-04-03 02:59:37 -06:00
Marco Cutecchia 425acb513e Kernel: Allow booting from an SD card 2023-04-02 12:43:17 -06:00
Marco Cutecchia 5fe6c6fc24 Kernel: Add support for SD host controllers on the PCI bus 2023-04-02 12:43:17 -06:00
Marco Cutecchia 47cae8005f Kernel: Add support for version 2 SD host controllers 2023-04-02 12:43:17 -06:00
Marco Cutecchia 1b04c43690 Kernel: Initialize DiskCache's buffer before the dirty&clean lists
This commit fixes a kernel panic that happened when unmounting
a disk due to an invalid memory access.
This was because `DiskCache` initializes two linked lists that use
an argument `KBuffer` as the storage for their elements.
Since the member `KBuffer` was declared after the two lists,
when `DiskCache`'s destructor was called, then `KBuffer`'s destructor
was called before the ones of the two lists, causing a page fault in
the kernel.
2023-04-02 12:43:17 -06:00
Liav A 07b83cf3fa Kernel/HID: Don't update the remapped Ctrl modifier unconditionally
Instead, only update it when the Caps Lock key event is generated and
remapping to the Ctrl key is enabled.

This fixes a bug that when enabling remapping Caps Lock key to the Ctrl
key, the original Ctrl key is no longer usable.
2023-03-31 12:45:12 -04:00
Jelle Raaijmakers dd8fa73da1 Kernel: Add support for Intel HDA
This is an implementation that tries to follow the spec as closely as
possible, and works with Qemu's Intel HDA and some bare metal HDA
controllers out there. Compiling with `INTEL_HDA_DEBUG=on` will provide
a lot of detailed information that could help us getting this to work
on more bare metal controllers as well :^)

Output format is limited to `i16` samples for now.
2023-03-25 21:27:03 +01:00
Jelle Raaijmakers c530f74e2f Kernel: Mention right parent class for AC'97's device_name 2023-03-25 21:27:03 +01:00
Marco Cutecchia 36c5afdfb2 Revert "Revert "Kernel/Storage: Remove the ramdisk implementation""
This reverts commit 187723776a.

This was reverted because it was needed until the aarch64 port
got an SD card driver

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia d09852642c Revert "Kernel/aarch64: Embed disk image into kernel binary"
This reverts commit 3b65fd64fc.

This is no longer needed as we don't use the ramdisk anymore

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia c91db6ec97 Kernel: Add an SD card driver for the aarch64 port
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia bb8092d6a1 Kernel: Allow enabling high level detection on GPIOs
Co-authored-by: Timon Kruiper <timonkruiper@gmail.com>
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia 28acf25035 Kernel: Use u64 instead of int for the bitfields of CPACR_EL1
This fixes the Clang build of the aarch64 port
2023-03-25 16:50:36 +00:00
Marco Cutecchia d0403d24d4 Kernel: Add missing include to Jail.h 2023-03-25 16:50:36 +00:00
Liav A 59a76b1279 Kernel: Remove 2 duplicated listings of cpp files in CMakeLists.txt file 2023-03-25 08:46:54 +00:00
Pankaj Raghav d0ac24ddbf Kernel/Syscalls: Use copy_n_to_user when applicable
copy_to_user() with bytes as the last argument could be changed to using
copy_n_to_user() with a count.
2023-03-24 18:25:12 +01:00
Pankaj Raghav f32fde6152 Kernel/StdLib: Change try_copy_n_to_user to copy_n_to_user
Let us keep the naming consistent between copy_n_from_user() and
copy_n_to_user()
2023-03-24 18:25:12 +01:00
Liav A fdab8a24f5 Kernel/Graphics: Use longer timeout settings in VirtIO GPU commands
It appeared that we sometimes failed to invoke synchronous commands on
the GPU. To temporarily fix this, wait 10 milliseconds for commands to
complete before failing.
2023-03-19 00:19:06 +00:00
Liav A 3337a5722a Kernel: Simplify VirtIOGPU attach_physical_range_to_framebuffer method
According to the specification, modesetting can be invoked with no need
for flushing the framebuffer nor with DMA to transfer the framebuffer
rendering.
2023-03-19 00:19:06 +00:00
Liav A 657bc71247 Kernel/VirtIO: Ignore the VIRTIO_PCI_CAP_PCI_CFG configuration type
This configuration exposes a suboptimal mechanism to access other
VirtIO device configurations. It is also the only configuration to use a
zero length for a configuration structure, and specify a valid BAR which
triggered a kernel panic when attaching a virtio-gpu-pci device before
95b15e4901 was applied.

The real solution for that problem is to ignore this configuration type
because we never actually use it. It means that we can VERIFY that all
other configuration types have a valid length, as being expected.
2023-03-19 00:19:06 +00:00
Julian Offenhäuser f31a9e9374 Kernel: Refactor AHCIController to propagate more errors
Before, the mapping of our HBA region would be done in the constructor.
Since this can fail, I moved it into initialize().

Additionally, we now use the TypedMapping helper for mapping the HBA
instead of doing it manually. This actually uncovered a bug where we
would ignore any possible offset into the page we were mapping, which
caused us to miss the mapped registers entirely.
2023-03-16 09:55:15 +01:00
Julian Offenhäuser 5541dfd9f8 Kernel: Allow AHCIController::initialize() to fail
If we fail to initialize an AHCI controller, we now skip adding it to
the list of storage controllers in StorageManagement.
2023-03-16 09:55:15 +01:00
Julian Offenhäuser d1e88a5141 Kernel: Propagate errors in StorageController reset() and shutdown()
These used to signal an error with a boolean return type. We now return
a sensible errno instead.
2023-03-16 09:55:15 +01:00
Liav A d16d805d96 Kernel: Merge {get,set}_process_name syscalls to the prctl syscall
It makes much more sense to have these actions being performed via the
prctl syscall, as they both require 2 plain arguments to be passed to
the syscall layer, and in contrast to most syscalls, we don't get in
these removed syscalls an automatic representation of Userspace<T>, but
two FlatPtr(s) to perform casting on them in the prctl syscall which is
suited to what has been done in the removed syscalls.

Also, it makes sense to have these actions in the prctl syscall, because
they are strongly related to the process control concept of the prctl
syscall.
2023-03-15 20:10:48 +01:00
Pankaj Raghav 6ff85aa19a Kernel/Ramdisk: Propagate error during Ramdisk initialize
Use the same pattern for Ramdisk similar to other storage devices during
device initialization. This will propagate errors if the Ramdisk fails
to initialize.
2023-03-15 11:25:59 +01:00
Pankaj Raghav b204da94b0 Kernel/Storage: Use NonnullRefPtr for storage controllers
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.
2023-03-15 11:25:59 +01:00
Tim Schumacher ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Andrew Kaster 6ce7257ad7 Kernel: Don't include Kernel/Arch/RegisterState from userspace
Any userspace cpp file that included <syscall.h> would end up with
a large glob of Kernel headers included, all the way down to
Kernel/Arch/x86_64/CPU.h and friends.

Only the kernel needs RegisterState, so hide it from userspace.
2023-03-13 07:23:53 +00:00
Liav A 633006926f Kernel: Make the Jails' internal design a lot more sane
This is done with 2 major steps:
1. Remove JailManagement singleton and use a structure that resembles
    what we have with the Process object. This is required later for the
    second step in this commit, but on its own, is a major change that
    removes this clunky singleton that had no real usage by itself.
2. Use IntrusiveLists to keep references to Process objects in the same
    Jail so it will be much more straightforward to iterate on this kind
    of objects when needed. Previously we locked the entire Process list
    and we did a simple pointer comparison to check if the checked
    Process we iterate on is in the same Jail or not, which required
    taking multiple Spinlocks in a very clumsy and heavyweight way.
2023-03-12 10:21:59 -06:00
Pankaj Raghav f8b67e1596 Kernel/Storage+Base: Fix boot_device_addressing document for NVMe
The LUN.target_id parameter points to a NVMe Namespace which starts from
1 and not 0. Fix the document to reflect the same while addressing a
nvme device in the boot parameters
2023-03-11 13:15:00 +00:00
Fabian Dellwing 7c0b360881 Kernel: Add non standard value to sys$sysconf
Add `_SC_PHYS_PAGES` to sys$sysconf syscall. This value is needed
for a port I'm working on.
2023-03-11 13:06:36 +00:00
Julian Offenhäuser c705afa43a Kernel: Fix variable shadowing issue in PCIIDELegacyModeController
In this specific else case, primary_base_io_window would not be assigned
in the outer scope, leading to a crash immediately after.
2023-03-11 06:06:01 -07:00
Andreas Kling 03cc45e5a2 Kernel: Use RefPtr instead of LockRefPtr for File and subclasses
This was mostly straightforward, as all the storage locations are
guarded by some related mutex.

The use of old-school associated mutexes instead of MutexProtected
is unfortunate, but the process to modernize such code is ongoing.
2023-03-10 13:15:44 +01:00
Andreas Kling e6fc7b3ff7 Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode>
The main place where this is a little iffy is in RAMFS where inodes
have a LockWeakPtr to their parent inode. I've left that as a
LockWeakPtr for now.
2023-03-09 21:54:59 +01:00
Marco Cutecchia f61e65a609 Kernel: Add missing include that broke the AARCH64 build 2023-03-08 14:20:29 +01:00
Marco Cutecchia a7144a47ab Kernel: Fix mispellings of AARCH64 that broke the build 2023-03-08 14:20:29 +01:00
Liav A 736f9f38ae Kernel/Storage: Remove indication for possible future support of ATAPI
There's no plan to support ATAPI in the foreseeable future. ATAPI is
considered mostly as an extension to pass SCSI commands over ATA-link
compatible channel (which could be a physical SATA or PATA).

ATAPI is mostly used for controlling optical drives which are considered
obsolete in 2023, and require an entire SCSI abstraction layer we don't
exhibit with bypassing ioctls for sending specific SCSI commands in many
control-flow sequences for actions being taken for such hardware.

Therefore, let's make it clear we don't support ATAPI (SCSI over ATA)
unless someone picks it up and proves otherwise that this can be done
cleanly and also in a relevant way to our project.
2023-03-08 01:41:51 +01:00
Liav A db72467e31 Kernel: Remove ATAPI eject method from the AHCIPort class
We never actually used it. It never has been proved to work reliably,
therefore it should be removed.
2023-03-08 01:41:51 +01:00
Liav A 95b15e4901 Kernel/VirtIO: Ignore Configurations that have length of zero bytes
These configurations are simply invalid. Ignoring those allow us to boot
with the virtio-gpu-pci device (in addition to the already supported
virtio-vga PCI device).
2023-03-08 01:38:13 +01:00
Andreas Kling d1371d66f7 Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescription
This patch switches away from {Nonnull,}LockRefPtr to the non-locking
smart pointers throughout the kernel.

I've looked at the handful of places where these were being persisted
and I don't see any race situations.

Note that the process file descriptor table (Process::m_fds) was already
guarded via MutexProtected.
2023-03-07 00:30:12 +01:00
Andreas Kling 36b0ecfe9e Kernel: Remove two outdated FIXMEs about the file descriptor table mutex
These functions cannot be called without already holding the relevant
mutex these days, since m_fds is a MutexProtected object. :^)
2023-03-06 23:46:36 +01:00
Andreas Kling 5aa12da959 AK+Kernel: Remove all the Nonnull*PtrVector classes 2023-03-06 23:46:36 +01:00
Andreas Kling 7369d0ab5f Kernel: Stop using NonnullLockRefPtrVector 2023-03-06 23:46:36 +01:00