Commit Graph

169 Commits

Author SHA1 Message Date
Andreas Kling
64254b5df8 Kernel: Protect PCI access with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Idan Horowitz
c131e69748 Kernel: Make UHCIController::spawn_port_process OOM-fallible 2022-01-28 19:05:52 +02:00
Idan Horowitz
ad7d4d9be1 Kernel: Rename UHCIController::{spawn_port_proc => spawn_port_process}
There's no need to use this non-standard shorthand mnemonic.
(This commit also removes the unimplemented do_debug_transfer while
we're here.)
2022-01-28 19:05:52 +02:00
Idan Horowitz
ac4583660b Kernel: Make VirtIO::ConsolePort construction OOM-fallible 2022-01-26 22:07:01 +00:00
Idan Horowitz
664ca58746 Kernel: Use u64 instead of size_t for File::can_write offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Idan Horowitz
9ce537d703 Kernel: Use u64 instead of size_t for File::can_read offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Liav A
eb9c8f3895 Kernel/PCI: Add basic support for the VMD PCI bridge device 2022-01-23 01:12:55 +01:00
Liav A
cecfd42916 Kernel/PCI: Verify Access is not initialized before initializing it
There's no valid case where we should try to initialize the Access
singleton multiple times, therefore just assert if it ever happens.
2022-01-21 19:09:16 +02:00
Idan Horowitz
c3099382b8 Kernel: Make VirtIO::Queue construction fallible 2022-01-21 16:27:21 +01:00
Idan Horowitz
17584d8a84 Kernel: Stop adopting non-heap memory into OwnPtrs in VirtIO::Queues 2022-01-21 16:27:21 +01:00
Idan Horowitz
d65347d39d Kernel: Make Memory::RingBuffer construction fallible 2022-01-21 16:27:21 +01:00
Liav A
c1d3b557d5 Kernel/PCI: Don't try to enumerate 255 functions on the host bridge
There can only be a limited number of functions (only 8).
Also, consider the start bus of the PCI domain when trying to enumerate
other host bridges on bus 0, device 0, functions 1-7 (function 0 is the
main host bridge).
2022-01-19 21:54:41 +02:00
Liav A
518473846a Kernel/PCI: Start enumeration in specified start bus of the PCI domain
Some devices, like the Intel Volume Management Device, might have bus
numbering restrictions (so numbers can be from 224 to 225, for example).
2022-01-19 21:54:41 +02:00
Liav A
0833ae0b36 Kernel/PCI: Don't hardcode Address domain to 0 when enumerating devices 2022-01-19 21:54:41 +02:00
Liav A
667a009cd7 Kernel/PCI: Don't cast a domain number to u16
Found by Tom (tomuta) during a debug session of these changes.
2022-01-19 21:54:41 +02:00
Idan Horowitz
fb3e46e930 Kernel: Make map_typed() & map_typed_writable() fallible using ErrorOr
This mostly just moved the problem, as a lot of the callers are not
capable of propagating the errors themselves, but it's a step in the
right direction.
2022-01-13 22:40:25 +01:00
Idan Horowitz
618f123463 Kernel: Use StringView instead of String in RingBuffer's constructor
This String was being copied into a KString internally anyways.
2022-01-13 00:20:08 -08:00
Idan Horowitz
a4560313eb Kernel: Replace all usages of String::number with KString::number 2022-01-12 16:09:09 +02:00
Pankaj Raghav
0a1b34c753 Kernel: Use DMA helper everywhere
Port UCHI, AC97, SB16, BMIDEChannel and AHCIPort to use the helper to
allocate DMA buffers.
2022-01-09 00:45:38 +01:00
Liav A
ac2c01320b Kernel/PCI: Split host bridge code from the Access singleton
Two classes are added - HostBridge and MemoryBackedHostBridge, which
both derive from HostController class. This allows the kernel to map
different busses from different PCI domains in the same time. Each
HostController implementation doesn't take the Address object to address
PCI devices but instead we take distinct numbers of the PCI bus, device
and function as it allows us to specify arbitrary PCI domains in the
Address structure and still to get the correct PCI devices. This also
matches the hardware behavior of PCI domains - the host bridge merely
takes memory operations or IO operations and translates them to
addressing of three components - PCI bus, device and function.

These changes also greatly simplify how enumeration of Host Bridges work
now - scanning of the hardware depends on what the Host bridges can do
for us, so in case we have multiple host bridges that expose a memory
mapped region or IO ports to access PCI configuration space, we simply
let the code of the host bridge to figure out how to fetch data for us.

Another semantical change is that a PCI domain structure is no longer
attached to a PhysicalAddress, so even in the case that the machine
doesn't implement PCI domains, we still treat that machine to contain 1
PCI domain to treat that one host bridge in the same way, like with a
machine with one or more PCI domains.
2022-01-08 23:49:26 +01:00
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Jesse Buhagiar
af31253a16 Kernel: Use try_create not must_create in SysFSUSB::create
The function `KString::must_create()` can only be enforced
during early boot (that is, when `g_in_early_boot` is true), hence
the use of this function during runtime causes a `VERIFY` to assert,
leading to a Kernel Panic.
We should instead use `TRY()` along with `try_create()` to prevent
this from crashing whenever a USB device is inserted into the system,
and we don't have enough memory to allocate the device's KString.
2022-01-03 10:39:56 +02:00
Pankaj Raghav
e99fafb683 Kernel/NVMe: Add initial NVMe driver support
Add a basic NVMe driver support to serenity
based on NVMe spec 1.4.

The driver can support multiple NVMe drives (subsystems).
But in a NVMe drive, the driver can support one controller
with multiple namespaces.

Each core will get a separate NVMe Queue.
As the system lacks MSI support, PIN based interrupts are
used for IO.

Tested the NVMe support by replacing IDE driver
with the NVMe driver :^)
2022-01-01 14:55:58 +01:00
Daniel Bertalan
8e2efe78f7 Kernel: Tighten String-related includes 2021-12-30 14:16:03 +01:00
Guilherme Goncalves
33b78915d3 Kernel: Propagate overflow errors from Memory::page_round_up
Fixes #11402.
2021-12-28 23:08:50 +01:00
Andreas Kling
ac7ce12123 Kernel: Remove the kmalloc_eternal heap :^)
This was a premature optimization from the early days of SerenityOS.
The eternal heap was a simple bump pointer allocator over a static
byte array. My original idea was to avoid heap fragmentation and improve
data locality, but both ideas were rooted in cargo culting, not data.

We would reserve 4 MiB at boot and only ended up using ~256 KiB, wasting
the rest.

This patch replaces all kmalloc_eternal() usage by regular kmalloc().
2021-12-28 21:02:38 +01:00
Daniel Bertalan
52beeebe70 Kernel: Remove the KString::try_create(String::formatted(...)) pattern
We can now directly create formatted KStrings with KString::formatted.

:^)
2021-12-28 01:55:22 -08:00
Liav A
478f543899 Kernel/SysFS: Prevent allocation for component name during construction
Instead, allocate before constructing the object and pass NonnullOwnPtr
of KString to the object if needed. Some classes can determine their
names as they have a known attribute to look for or have a static name.
2021-12-14 09:01:33 +01:00
Hendiadyoin1
e34eb3e36d Kernel: Remove unused String.h includes
This makes searching for not yet OOM safe interfaces a bit easier.
2021-12-11 13:15:26 -08:00
Hendiadyoin1
9be409585c Kernel: Some clang-tidy fixes in Bus/VirtIO 2021-12-09 22:53:42 -08:00
Hendiadyoin1
471b38db68 Kernel: Some clang-tidy fixes in Bus/USB 2021-12-09 22:53:42 -08:00
Hendiadyoin1
b03b7f806a Kernel: Mark USBTransfer's constructor as private
We have a try_create method for that.
2021-12-09 22:53:42 -08:00
Hendiadyoin1
73aa5c75d5 Kernel: Fix some clang-tidy warnings in PCI::Access 2021-12-09 22:53:42 -08:00
Hendiadyoin1
19ba32651d Kernel: Use AK:any_of in PCI::Device capability checks
This is equivalent to std::any_of as clang-tidy suggests.
2021-12-09 22:53:42 -08:00
Hendiadyoin1
5adf5f4dee Kernel: Construct PCIDeviceAttributeSysFSComponent with StringViews
There is no use to create a temporary String of a char const* to just
cast it to a StringView on SysFSComponent construction again.
Also this could have lead to a UAF bug.
2021-12-09 22:53:42 -08:00
Hendiadyoin1
de26dd253b Kernel: Pass capabilities as const reference in PCI::Address 2021-12-09 22:53:42 -08:00
Hendiadyoin1
3070252090 Kernel: Mark PCI::Address as trivially copyable 2021-12-09 22:53:42 -08:00
Sam Atkins
c6a97ea843 Kernel: Mark kernel smart-pointer classes as [[nodiscard]]
And cast the unused return values to void.
2021-12-05 15:31:03 +01:00
Brian Gianforcaro
1f65728d8b Kernel: Handle string format errors in PCIDeviceAttributeSysFSComponent 2021-11-30 11:16:35 +01:00
Jelle Raaijmakers
e187207610 Kernel: Register Virtio console ports with device management
Previously, Virtio console ports would not show up in `/sys/dev/char/`.
Also adds support to `SystemServer` to create more than one console
port device in `/dev/` in the multiport case.
2021-11-30 10:53:41 +01:00
Jelle Raaijmakers
7a2a0c1052 Kernel: Implement AC97 audio device driver 2021-11-23 10:06:24 +01:00
Andreas Kling
9387271049 Everywhere: Fix spelling of "offsetted"
This word is actually pretty awkward in context, but this patch merely
fixes the spelling instead of finding a better word.
2021-11-21 20:22:48 +01:00
Andreas Kling
e08d213830 Kernel: Use DistinctNumeric for filesystem ID's
This patch adds the FileSystemID type, which is a distinct u32.
This prevents accidental conversion from arbitrary integers.
2021-11-18 21:11:30 +01:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
5ce753b74d Kernel: Make Inode::traverse_as_directory() callback return ErrorOr
This allows us to propagate errors from inside the callback with TRY().
2021-11-10 21:58:58 +01:00
Ben Wiederhake
850db15d66 Everywhere: Remove unused AK/Bitmap includes 2021-11-10 14:39:42 +01:00
Andreas Kling
79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Liav A
8e55c4bfaf Kernel/PCI: Remove InterruptDisabler usage
Instead, just ensure we pick the m_access_lock and then m_scan_lock when
doing a scan/re-scan of the PCI configuration space so we know nobody
can actually access the PCI configuration space during the scan.

The m_scan_lock is now a Spinlock, to ensure we cannot yield to other
process while we do the PCI configuration space scanning.
2021-10-23 19:17:44 +02:00
Liav A
72e831e9e9 Kernel/PCI: Ensure m_domains is not empty if scanning with memory access 2021-10-23 19:17:44 +02:00
Liav A
40b1e6376b Kernel/PCI: Split Access::rescan_hardware method
To ensure clarity, this method is essentially splitted to two methods to
be called according to the access type being determined beforehand.
2021-10-23 19:17:44 +02:00