Commit graph

756 commits

Author SHA1 Message Date
Sönke Holz facca92780 Kernel/Storage: Dump storage devices to the framebuffer console as well
This is helps bringing up bare metal devices without having to use the
serial console.
2024-06-26 08:47:00 +02:00
implicitfield ef766b0b5f Kernel/FUSE: Allow buffering multiple requests
It can be possible for a request to be blocked on another request, so
this patch allows us to send more requests even when a request is
already pending.
2024-06-01 14:47:58 -06:00
Sönke Holz 018a28cf4a Kernel/HID: Add support for virtio input devices 2024-05-23 11:16:57 -06:00
Liav A. c48d540230 Kernel: Move VGATextModeConsole code to the Arch/x86_64/ISABus directory
This code is specific to x86 machines, as virtually no other computer
architecture has any compatibility with old VGA legacy functionality.
2024-05-23 05:07:56 -06:00
Kirill Nikolaev 99f6528009 Kernel: Implement virtio-blk driver 2024-05-23 00:59:39 -06:00
Idan Horowitz 26cff62a0a Kernel: Rename Memory::PhysicalPage to Memory::PhysicalRAMPage
Since these are now only used to represent RAM pages, (and not MMIO
pages) rename them to make their purpose more obvious.
2024-05-17 15:38:28 -06:00
Idan Horowitz 827322c139 Kernel: Stop allocating physical pages for mapped MMIO regions
As MMIO is placed at fixed physical addressed, and does not need to be
backed by real RAM physical pages, there's no need to use PhysicalPage
instances to track their pages.
This results in slightly reduced allocations, but more importantly
makes MMIO addresses which end up after the normal RAM ranges work,
like 64-bit PCI BARs usually are.
2024-05-17 15:38:28 -06:00
Liav A. 5f3ef1aa9e Kernel: Remove includes of PCI API.h file
This file will be removed in a future commit, so let's get rid of what
we can right now.
2024-05-14 15:42:29 -06:00
Liav A. 69a3602237 Kernel/GPU: Rename GenericGraphicsAdapter => GPUDevice
GenericGraphicsAdapter is mouthful. Also, the idea is to move towards a
more advanced subsystem that handles GPUs, not merely graphics adapters.
2024-05-14 15:42:29 -06:00
Liav A. bbb749ab47 Kernel: Move VirtIO console code to the Devices/Serial/VirtIO directory 2024-05-14 15:42:29 -06:00
Liav A. cb558f4459 Kernel/Devices: Remove SerialDevice::initialize method
We can just do the initialization sequence in the constructor.
2024-05-14 15:42:29 -06:00
Liav A. b4c218168f Kernel/Storage: Remove StorageController reset and shutdown methods
We never used these virtual methods outside their own implementation,
so let's stop pretending that we should be able to utilize this for
unknown purpose.
2024-05-14 15:42:29 -06:00
Liav A. eadf2bf29f Kernel/Devices: Remove UNMAP_AFTER_INIT from SerialDevice code 2024-05-14 15:42:29 -06:00
Liav A. d73c82d746 Kernel: Remove UNMAP_AFTER_INIT from VGA text mode console 2024-05-14 15:42:29 -06:00
Liav A. 2cb86c1309 Kernel/Storage: Remove ATA IDE support
Nobody uses this functionality. I used this code on my old 2007 ICH7
test machine about a year ago, but bare metal is a small aspect of the
project, so it's safe to assume that nobody really tests this piece of
code.
Therefore, let's drop this for good and focus on more modern hardware.
2024-05-14 12:38:05 -06:00
Timothy Flynn 3ff1d7da59 Kernel: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There was a recent release of clang-format version 18.1.5 which fixes
errant spaces around `->` in these files.
2024-05-12 15:44:27 -04:00
Liav A. f7a85401bb Kernel/Storage: Remove a stale StorageDevice constructor method
ramdisk devices are long gone by now, so this is a stale method.
2024-05-07 17:02:09 -06:00
implicitfield a08d1637e2 Kernel: Add FUSE support
This adds both the fuse device (used for communication between the
kernel and the filesystem) and filesystem implementation itself.
2024-05-07 16:54:27 -06:00
Idan Horowitz 7339409575 Kernel: Properly initialize NVMe admin queue depth
We were reading the value instead of setting it (as required by the
specification). This worked only when we booted with a bootloader which
initialized NVMe before us.
2024-04-26 09:52:56 +02:00
Idan Horowitz a2b2209ea5 Kernel: Fix definition of CAP_TO_MASK
The default type for integer literals is signed int, so we were
accidentally smearing those bits to the upper 32 bit of the result.
This resulted in extremely unreasonable timeouts.
2024-04-26 09:52:56 +02:00
Timothy Flynn ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Dan Klishch 5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Space Meyer a721e4d507 Kernel: Track KCOVInstance via Process instead of HashMap
While this clutters Process.cpp a tiny bit, I feel that it's worth it:
- 2x speed on the kcov_loop benchmark. Likely more during fuzzing.
- Overall code complexity is going down with this change.
- By reducing the code reachable from __sanitizer_cov_trace_pc code,
  we can now instrument more code.
2024-04-15 21:16:22 -06:00
Space Meyer 106d4636a4 Revert "Kernel+SystemServer: Make KCOVDevice a character device"
This reverts commit 9dbec601b0.

For KCOV to be performant (or at least not even slower) we need to
mmap the PC buffer from both user and kernel space at the same time.
You can't mmap a character device, so this change didn't make sense.

Plus even if we did invent a new method to exfiltrate the coverage
information out of the kernel, it would be incompatible with existing
kernel fuzzers. That would be kind of annoying. 🙃
2024-04-15 21:16:22 -06:00
Sönke Holz 6daa0da3c6 Kernel/NVMe: Fix calculation of "Maximum Queue Entries Supported" field
The value of this field is incremented by one, as a value of 0 for this
field means 1 entry supported.

A value of 0xffff for CAP.MQES would incorrectly by truncated to 0x0000,
if we don't increase the bit width of the return type.
2024-03-25 14:08:28 -06:00
Liav A 11ead5c84f Kernel: Get RefPtr<Device> from the DeviceManagement::get_device method
Instead of returning a raw pointer, which could be technically invalid
when using it in the caller function, we return a valid RefPtr of such
device.

This ensures that the code in DevPtsFS is now safe from a rare race
condition in which the SlavePTY device is gone but we still have a
pointer to it.
2024-03-13 15:33:47 -06:00
Liav A 5dcf03ad9a Kernel/Devices: Introduce the LoopDevice device
This device is a block device that allows a user to effectively treat an
Inode as a block device.

The static construction method is given an OpenFileDescription reference
but validates that:
- The description has a valid custody (so it's not some arbitrary file).
  Failing this requirement will yield EINVAL.
- The description custody points to an Inode which is a regular file, as
  we only support (seekable) regular files. Failing this requirement
  will yield ENOTSUP.

LoopDevice can be used to mount a regular file on the filesystem like
other supported types of (physical) block devices.
2024-03-13 15:33:47 -06:00
Hendiadyoin1 3e3b34ab8a Kernel/NVMe: Use a struct for the namespace features, instead of a Tuple 2024-03-01 14:05:53 -07:00
Sönke Holz cdc0c9f094 Kernel/Storage: Don't allocate IRQs in NVMeCntlr when nvme_poll passed 2024-02-25 17:20:40 -07:00
Sönke Holz f6151b3c9e Kernel/Storage: Add AssertSizes to AHCI structs 2024-02-24 16:36:47 -07:00
Sönke Holz f85099ea47 Kernel/Storage: Make AHCI::HBA::port_regs a flexible array member
Some real hardware apparently uses smaller BAR sizes than sizeof(HBA)
with a completely filled port_regs member.
Change the port_regs array to a flexible array member, so we don't panic
while verifying that the BAR size is large enough to map this struct.
Accesses to this array are already bounds checked against
AHCI::Limits::MaxPorts.
2024-02-24 16:36:47 -07:00
Liav A c216e7439f Kernel: Require StorageDevice reference for StorageDevicePartition
Allowing creation of StorageDevicePartition objects for any arbitrary
BlockDevice objects means that we could technically create a
StorageDevicePartition for another StorageDevicePartition which is
obviously not the intention for this code. Instead, require to pass a
StorageDevice reference to ensure this cannot happen.
2024-02-24 16:01:26 -07:00
Liav A f08f339e9a Kernel: Return EIO if attached device is gone in StorageDevicePartition
The previous code will just do a nullptr-dereference if the underlying
device is gone, so instead gracefully return EIO error.
2024-02-24 16:01:26 -07:00
Liav A 67e028e4f4 Kernel: Declare proper blocking support for StorageDevicePartitions 2024-02-24 16:01:26 -07:00
Liav A 42ed0a6c94 Kernel/Storage: Rename DiskPartition => StorageDevicePartition
We deal with partitions for storage devices, not only for disk devices,
originally harddrives.
2024-02-24 16:01:26 -07:00
Liav A 4e651d0e4f Kernel/Storage: Convert StorageDevice class members to be const
It is expected that these class members will be set when the object is
created (so they're set in the class constructor method) and never
change again, as its the driver responsibility to find these values
before creating a StorageDevice object.

This makes it easier to rely on these values later on as we don't expect
them to ever change for a StorageDevice object during its lifetime.
2024-02-24 16:01:26 -07:00
Liav A c8bdcd90a8 Kernel/Storage: Fix StorageDevice STORAGE_DEVICE_GET_SIZE ioctl option
It calculated the disk size with the zero-based max addressable block
value.
For example, for a disk device with a block size of 512 bytes that has 2
LBAs so it can address LBA 0 and LBA 1 (so m_max_addressable_block is 1)
the calculated disk size will be 512 instead of 1024 bytes.
2024-02-24 16:01:26 -07:00
Liav A 763ef690c6 Kernel/Storage: Declare proper blocking support for StorageDevices
We remove can_read() and can_write(), as both of these methods should be
implemented for proper blocking support.
For our case, the previous code will simply block the user if they tries
to read beyond the max addressable offset, which is not a correct
behavior.

Instead, just do proper EOF guarding when calling read() and write() on
such objects.
2024-02-24 16:01:26 -07:00
Liav A c33246235a Kernel/Storage: Change semantics for addressing block methods
Add a method for matehmatical operations when verifying IO operation
boundaries.
Also, make max_addressable_block method non-virtual, since no other
derived class actually has ever overrided this method.
2024-02-24 16:01:26 -07:00
Sönke Holz ecf41e13ad Kernel/Graphics: Probe PCI graphics adapters on all architectures 2024-02-21 22:36:00 +01:00
John te Bokkel 9d62dfabbb Kernel/HID: Modify index for shifted scan codes of non-printing chars
Several non-printing keys were assigned key map index values when they
should have been ignored using index 0xFF. This resolves issue 23185.
2024-02-19 00:03:50 +01:00
Tim Ledbetter 532f2b644c Kernel: Propagate errors with TRY() where possible 2024-02-14 17:46:06 -05:00
Jelle Raaijmakers 96675e61cd Kernel/TTY: Support non-blocking reads with termios VMIN == 0
In a TTY's non-canonical mode, data availability can be configured by
setting VMIN and VTIME to determine the minimum amount of bytes to read
and the timeout between bytes, respectively. Some ports (such as SRB2)
set VMIN to 0 which effectively makes reading a TTY such as stdin a
non-blocking read. We didn't support this, causing ports to hang as soon
as they try to read stdin without any data available.

Add a very duct-tapey implementation for the case where VMIN == 0 by
overwriting the TTY's description's blocking status; 3 FIXMEs are
included to make sure we clean this up some day.
2024-02-13 19:48:39 +01:00
Nico Weber 4409b33145 AK: Make IndexSequence use size_t
This makes it possible to use MakeIndexSequqnce in functions like:

    template<typename T, size_t N>
    constexpr auto foo(T (&a)[N])

This means AK/StdLibExtraDetails.h must now include AK/Types.h
for size_t, which means AK/Types.h can no longer include
AK/StdLibExtras.h (which arguably it shouldn't do anyways),
which requires rejiggering some things.

(IMHO Types.h shouldn't use AK::Details metaprogramming at all.
FlatPtr doesn't necessarily have to use Conditional<> and ssize_t could
maybe be in its own header or something. But since it's tangential to
this PR, going with the tried and true "lift things that cause the
cycle up to the top" approach.)
2024-02-11 18:53:00 +01:00
Idan Horowitz 03cb3e5370 Kernel: Move NVMeQueue's m_cq_lock to NVMePollQueue
It's only used by that subclass, so there's no reason for it to be
defined as part of the parent class.
2024-02-10 08:42:53 +01:00
Idan Horowitz 45aee20ea9 Kernel: Switch to SpinlockProtected to protect NVMeQueue's requests map
This helps ensure no one accidentally accesses m_requests without first
locking it's spinlock. In fact this change fixed such a case, since
process_cq() implicitly assumed the caller locked the lock, which was
not the case for NVMePollQueue::submit_sqe().
2024-02-10 08:42:53 +01:00
Idan Horowitz 263127f21a Kernel: Actually report nvme request status
Due to an incorrect lambda scope capture declaration, we would copy the
result status at the start of the function, before it actually got
updated with the final status. Capture it by reference instead to
ensure we report the updated result.
2024-02-10 08:42:53 +01:00
Idan Horowitz 38dad2e27f Kernel: Replace bespoke & rickety NVMeIO synchronization mechanism
Instead of assuming data races won't occur and trying to somehow verify
it with manual un-atomic tracking, we can just use a recursive spinlock
instead of a normal one, to resolve the original deadlock.
2024-02-10 08:42:53 +01:00
Idan Horowitz a957907f4b Kernel: Merge NVME Queue complete_current_request implementations
Most of the actual logic is identical, with the only real difference
being that one wraps it with an async work item.
Merge the implementations to reduce duplications (which will also
require the fixes in the next commits to only be done once).
2024-02-10 08:42:53 +01:00
Tim Ledbetter a580118e53 Kernel/HID: Set Caps Lock state before doing code point remapping
This restores Caps Lock functionality, while still ensuring that
shortcut keys are remapped correctly.
2024-02-09 12:28:08 -07:00