Commit graph

8238 commits

Author SHA1 Message Date
Daniel Bertalan bd93b4984b Kernel/aarch64: Use unsigned values in the register bitfields
This resolves the various "implicit truncation from int to a one-bit
wide bit-field changes value from 1 to -1" warnings produced by Clang
16+ when assigning to single-bit bitfields.
2023-07-05 08:17:51 +01:00
Jelle Raaijmakers 859ac200b7 Kernel: Decouple Intel HDA interrupt handling from controller
The driver would crash if it was unable to find an output route, and
subsequently the destruction of controller did not invoke
`GenericInterruptHandler::will_be_destroyed()` because on the level of
`AudioController`, that method is unavailable.

By decoupling the interrupt handling from the controller, we get a new
refcounted class that correctly cleans up after itself :^)
2023-07-04 16:24:04 +02:00
Jelle Raaijmakers 0315ee5937 Kernel: Clean up includes for Audio subsystem
Some unused, missing or misplaced includes.
2023-07-04 00:05:34 +02:00
Jelle Raaijmakers 5c64686666 Kernel+AudioServer: Use interrupts for Intel HDA audio buffer completion
We used to not care about stopping an audio output stream for Intel HDA
since AudioServer would continuously send new buffers to play. Since
707f5ac150 however, that has changed.

Intel HDA now uses interrupts to detect when each buffer was completed
by the device, and uses a simple heuristic to detect whether a buffer
underrun has occurred so it can stop the output stream.

This was tested on Qemu's Intel HDA (Linux x86_64) and a bare metal MSI
Starship/Matisse HD Audio Controller.
2023-07-04 00:05:34 +02:00
Liav A 23a7ccf607 Kernel+LibCore+LibC: Split the mount syscall into multiple syscalls
This is a preparation before we can create a usable mechanism to use
filesystem-specific mount flags.
To keep some compatibility with userland code, LibC and LibCore mount
functions are kept being usable, but now instead of doing an "atomic"
syscall, they do multiple syscalls to perform the complete procedure of
mounting a filesystem.

The FileBackedFileSystem IntrusiveList in the VFS code is now changed to
be protected by a Mutex, because when we mount a new filesystem, we need
to check if a filesystem is already created for a given source_fd so we
do a scan for that OpenFileDescription in that list. If we fail to find
an already-created filesystem we create a new one and register it in the
list if we successfully mounted it. We use a Mutex because we might need
to initiate disk access during the filesystem creation, which will take
other mutexes in other parts of the kernel, therefore making it not
possible to take a spinlock while doing this.
2023-07-02 01:04:51 +02:00
Daniel Bertalan 6eb06384b3 Kernel: Increase SD Data Timeout
Otherwise, reading will sometimes fail on the Raspberry Pi.

This is mostly a hack, the spec has some info about how the correct
divisor should be calculated and how we can recover from timeouts.
2023-06-30 23:45:47 +02:00
Daniel Bertalan bbe614c6c5 Kernel: Implement Changing Bus Width per the SDHC specification
Namely, we previously forgot to configure the SD Host Controller for
4-bit mode after issuing ACMD6, which caused data transfers to fail on
bare metal.
2023-06-30 23:45:47 +02:00
Daniel Bertalan 73228fc742 Kernel: Clear previous value before setting new clock divisor
Otherwise it would just get OR'ed together with the previous value,
leading to a slower than expected operation.
2023-06-30 23:45:47 +02:00
Daniel Bertalan 6185a19618 Kernel: Wait for transactions to complete before stopping SD clock 2023-06-30 23:45:47 +02:00
Daniel Bertalan b90a20aee6 Kernel: Make the PresentState register a bitfield in the SDHC driver 2023-06-30 23:45:47 +02:00
Pierre Delagrave 55faff80df Kernet/Net: Close a TCP connection using FIN|ACK instead of just FIN
When initiating a connection termination, the FIN should be sent with
a ACK from the last received segment even if that ACK already been sent.
2023-06-29 05:58:03 +02:00
Liav A 9b8b8c0e04 Kernel: Simplify reboot & poweroff code flow a bit
Instead of using ifdefs to use the correct platform-specific methods, we
can just use the same pattern we use for the microseconds_delay function
which has specific implementations for each Arch CPU subdirectory.

When linking a kernel image, the actual correct and platform-specific
power-state changing methods will be called in Firmware/PowerState.cpp
file.
2023-06-27 20:04:42 +02:00
implicitfield 5dfe2eb389 Everywhere: Resolve conflicts with LibC and libc++
Since https://reviews.llvm.org/D131441, libc++ must be included before
LibC. As clang includes libc++ as one of the system includes, LibC
must be included after those, and the only correct way to do that is
to install LibC's headers into the sysroot.

Targets that don't link with LibC yet require its headers for one
reason or another must add install_libc_headers as a dependency to
ensure that the correct headers have been (re)installed into the
sysroot.

LibC/stddef.h has been dropped since the built-in stddef.h receives
a higher include priority.

In addition, string.h and wchar.h must
define __CORRECT_ISO_CPP_STRING_H_PROTO and
_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS respectively in order to tell
libc++ to not try to define methods implemented by LibC.
2023-06-27 12:40:38 +02:00
implicitfield 007f3cdb00 Everywhere: Remove exceptions for using #include <LibC/...>
Once LibC is installed to the sysroot and its conflicts with libc++
are resolved, including LibC headers in such a way will cause errors
with a modern LLVM-based toolchain.
2023-06-27 12:40:38 +02:00
implicitfield 79adeb626b LibC+LibELF: Move ELF definitions from LibC to LibELF
This is needed to avoid including LibC headers in Lagom builds.
Unfortunately, we cannot rely on the build machine to provide a
fully POSIX-compatible ELF header for Lagom builds, so we have to
use our own.
2023-06-27 12:40:38 +02:00
Kristoffer Højelse 05bc98a410 Kernel: Fix panic when switching to out-of-bounds console
This was caused by an off-by-two error.
Fixes #19034
2023-06-21 23:52:34 +02:00
Liav A 89a8920764 Kernel: Untie PS2 mouse and keyboard devices from i8042 implementation
To ensure actual PS2 code is not tied to the i8042 code, we make them
separated in the following ways:
- PS2KeyboardDevice and PS2MouseDevice classes are no longer inheriting
  from the IRQHandler class. Instead we have specific IRQHandler derived
  class for the i8042 controller implementation, which is used to ensure
  that we don't end up mixing PS2 code with low-level interrupt handling
  functionality. In the future this means that we could add a driver for
  other PS2 controllers that might have only one interrupt handler but
  multiple PS2 devices are attached, therefore, making it easier to put
  the right propagation flow from the controller driver all the way to
  the HID core code.
- A simple abstraction layer is added between the PS2 command set which
  devices could use and the actual implementation low-level commands.
  This means that the code in PS2MouseDevice and PS2KeyboardDevice
  classes is no longer tied to i8042 implementation-specific commands,
  so now these objects could send PS2 commands to their PS2 controller
  and get a PS2Response which abstracts the given response too.
2023-06-21 05:02:09 -06:00
Liav A d276cac82c Kernel: Re-organize the abstractions around i8042, PS2 and HID concepts
The HIDController class is removed and instead adding SerialIOController
class. The HIDController class was a mistake - there's no such thing in
real hardware as host controller only for human interface devices
(VirtIO PCI input controller being the exception here, but it could be
technically treated as serial IO controller too).

Instead, we simply add a new abstraction layer - the SerialIO "bus",
which will hold all the code that is related to serial communications
with other devices. A PS2 controller is simply a serial IO controller,
and the Intel 8042 Controller is simply a specific implementation of a
PS2 controller.
2023-06-21 05:02:09 -06:00
Jelle Raaijmakers 4a86861a9d Kernel: Set audio sample rate to 44.1 KHz by default
Ideally, we would want the audio controller to run a channel at a
device's initial sample rate instead of hardcoding 44.1 KHz. However,
most audio is provided at 44.1 KHz and as long as `Audio::Resampler`
introduces significant audio artifacts, let's set a sensible sample
rate that offers a better experience for most users.

This can be removed after someone implements a higher quality
`Audio::Resampler`.
2023-06-21 12:26:32 +02:00
Jelle Raaijmakers 2133bae1a4 Kernel: Move AC'97 to its own subdirectory 2023-06-21 12:26:32 +02:00
Jelle Raaijmakers 5080419b61 Kernel: Do not set a default sample rate for AC'97
Let's use the device's initial sample rate as our active sample rate and
work from there.
2023-06-21 12:26:32 +02:00
Liav A d550b09871 Kernel: Move PC BIOS-related code to the x86_64 architecture directory
All code that is related to PC BIOS should not be in the Kernel/Firmware
directory as this directory is for abstracted and platform-agnostic code
like ACPI (and device tree parsing in the future).

This fixes a problem with the aarch64 architecure, as these machines
don't have any PC-BIOS in them so actually trying to access these memory
locations (EBDA, BIOS ROM) does not make any sense, as they're specific
to x86 machines only.
2023-06-19 23:49:00 +02:00
Liav A 5fd975da8f Kernel: Move MultiProcessor parsing code to the Arch/x86_64 directory
This code is very x86-specific, because Intel introduced the actual
MultiProcessor specification back in 1993, qouted here as a proof:

"The MP specification covers PC/AT-compatible MP platform designs based
on Intel processor architectures and Advanced Programmable Interrupt
Controller (APIC) architectures"
2023-06-19 23:49:00 +02:00
Liav A 428afca32b Kernel/ACPI: Make most of StaticParsing methods to be platform-agnostic
Most of the ACPI static parsing methods (methods that can be called
without initializing a full AML parser) are not tied to any specific
platform or CPU architecture.

The only method that is platform-specific is the one that finds the RSDP
structure. Thus, each CPU architecture/platform needs to implement it.
This means that now aarch64 can implement its own method to find the
ACPI RSDP structure, which would be hooked into the rest of the ACPI
code elegantly, but for now I just added a FIXME and that method returns
empty value of Optional<PhysicalAddress>.
2023-06-19 23:49:00 +02:00
Liav A be16a91aec Kernel: Rename FirmwareSysFSDirectory => SysFSFirmwareDirectory
This matches how we give the pattern names for other classses for SysFS
components.
2023-06-19 23:49:00 +02:00
MacDue 063efe9cf8 Kernel: Set kernel stack alignment to 8-bytes
This is already assumed by most of the assembly in the kernel, setting
this is just making it explicit (and may save some stack).
2023-06-19 21:59:35 +02:00
Robin Voetter a433cbefbe Kernel: Fix reading expansion ROM SysFS node
Previously, reads would only be successful for offset 0. For this
reason, the maximum size that could be correctly read from the PCI
expansion ROM SysFS node was limited to the block size, and
subsequent blocks would fail. This commit fixes the computation of
the number of bytes to read.
2023-06-19 21:35:37 +02:00
Optimoos e72894f23d Kernel/TCPSocket: Read window size from peer
During receive_tcp_packet(), we now set m_send_window_size for the
socket if it is different from the default.

This removes one FIXME from TCPSocket.h.
2023-06-19 13:20:36 +02:00
Tim Ledbetter 586b47cede Kernel: Put loopback adapter debug spam behind a flag
This significantly increases loopback adapter speed in normal use.
2023-06-18 08:50:33 +01:00
Ben Wiederhake 8ae60dd234 Kernel: Use AK_MAKE_DEFAULT_MOVABLE to avoid mistakes in default impls 2023-06-18 08:47:51 +01:00
Tim Ledbetter 8d721dc0f7 Kernel+LibCore+SystemMonitor: Make thread statistics values 64-bit
Thread statistics values which count bytes are now 64-bit. This avoids
overflow when these values go above 4GiB.
2023-06-11 09:26:54 +01:00
Tim Ledbetter f95dccdb45 Kernel+LibCore: Add process creation time to /sys/kernel/processes 2023-06-10 07:13:25 +02:00
Jelle Raaijmakers 81a6976e90 Kernel: De-atomicize fields for promises in Process
These 4 fields were made `Atomic` in
c3f668a758, at which time these were still
accessed unserialized and TOCTOU bugs could happen. Later, in
8ed06ad814, we serialized access to these
fields in a number of helper methods, removing the need for `Atomic`.
2023-06-09 17:15:54 +02:00
Tim Ledbetter 7f855ad6b3 Kernel: Initialize ProcFS timestamps to process creation time 2023-06-09 17:15:41 +02:00
Tim Ledbetter f25530a12d Kernel: Store creation time when creating a process 2023-06-09 17:15:41 +02:00
Daniel Bertalan c6c0ce78f5 Kernel/aarch64: Account for reserved VideoCore range in the memory map
Instead of having a single available memory range that encompasses the
whole 0x00000000-0x3EFFFFFF range of physical memory, create a separate
reserved entry for the RAM range used by the VideoCore. This fixes a
crash that happens when we try to allocate physical pages in the GPU's
reserved range.

This will eventually be replaced with parsing the data from the device
tree, but for now, this should solve some of the recurring CI failures.
2023-06-06 15:45:52 +02:00
Daniel Bertalan 9359e49383 Kernel: Add query for VideoCore and ARM physical memory ranges 2023-06-06 15:45:52 +02:00
Liav A 9ee098b119 Kernel: Move all Graphics-related code into Devices/GPU directory
Like the HID, Audio and Storage subsystem, the Graphics subsystem (which
handles GPUs technically) exposes unix device files (typically in /dev).
To ensure consistency across the repository, move all related files to a
new directory under Kernel/Devices called "GPU".

Also remove the redundant "GPU" word from the VirtIO driver directory,
and the word "Graphics" from GraphicsManagement.{h,cpp} filenames.
2023-06-06 00:40:32 +02:00
Ben Wiederhake 3d6b838df3 LibPartition: Migrate from DeprecatedFile to File
The implemented cloning mechanism should be sound:
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::Yes, then it will keep it alive until the
  PartitionTable is destroyed.
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::No, then the caller has to ensure that the
  file descriptor remains alive.
If the caller is EBRPartitionTable, the same consideration holds.
If the caller is PartitionEditor::PartitionModel, this is satisfied by
keeping an OwnPtr<Core::File> around which is the originally opened
file.

Therefore, we never leak any fds, and never access a Core::File or fd
after destroying it.
2023-06-05 14:50:09 +02:00
Liav A 59cab85002 Kernel: Rename Syscall.cpp => Syscalls/SyscallHandler.cpp 2023-06-04 21:32:34 +02:00
Liav A 336fb4f313 Kernel: Move InterruptDisabler to the Interrupts subdirectory 2023-06-04 21:32:34 +02:00
Liav A 927926b924 Kernel: Move Performance-measurement code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Liav A b88c1d90e1 Kernel: Move TimerQueue code to the Time subdirectory 2023-06-04 21:32:34 +02:00
Liav A 8f21420a1d Kernel: Move all boot-related code to the new Boot subdirectory 2023-06-04 21:32:34 +02:00
Liav A c9a34cae66 Kernel: Move ExecutionMode.h to the Security subdirectory 2023-06-04 21:32:34 +02:00
Liav A 7c0540a229 Everywhere: Move global Kernel pattern code to Kernel/Library directory
This has KString, KBuffer, DoubleBuffer, KBufferBuilder, IOWindow,
UserOrKernelBuffer and ScopedCritical classes being moved to the
Kernel/Library subdirectory.

Also, move the panic and assertions handling code to that directory.
2023-06-04 21:32:34 +02:00
Liav A f1cbfc5a6e Kernel: Move task-crash related code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Liav A ee0ccdaebe Kernel: Move Credentials.{cpp,h} to the Security subdirectory 2023-06-04 21:32:34 +02:00
Liav A aaa1de7878 Kernel: Move {Virtual,Physical}Address classes to the Memory directory 2023-06-04 21:32:34 +02:00
Liav A 64af4953c2 Kernel: Move UBSanitizer and AddressSanitizer to Security subdirectory 2023-06-04 21:32:34 +02:00