Commit Graph

247 Commits

Author SHA1 Message Date
Lenny Maiorani
c6acf64558 Kernel: Change static constexpr variables to constexpr where possible
Function-local `static constexpr` variables can be `constexpr`. This
can reduce memory consumption, binary size, and offer additional
compiler optimizations.

These changes result in a stripped x86_64 kernel binary size reduction
of 592 bytes.
2022-02-09 21:04:51 +00:00
Idan Horowitz
8289727fac Kernel: Stop using the make<T> factory method in the Kernel
As make<T> is infallible, it really should not be used anywhere in the
Kernel. Instead replace with fallible `new (nothrow)` calls, that will
eventually be error-propagated.
2022-02-03 23:33:20 +01:00
Pankaj Raghav
d234e6b801 Kernel: Add polling support to NVMe
Add polling support to NVMe so that it does not use interrupt to
complete a IO but instead actively polls for completion. This probably
is not very efficient in terms of CPU usage but it does not use
interrupts to complete a IO which is beneficial at the moment as there
is no MSI(X) support and it can reduce the latency of an IO in a very
fast NVMe device.

The NVMeQueue class has been made the base class for NVMeInterruptQueue
and NVMePollQueue. The factory function `NVMeQueue::try_create` will
return the appropriate queue to the controller based on the polling
boot parameter.

The polling mode can be enabled by adding an extra boot parameter:
`nvme_poll`.
2022-02-02 18:26:59 +01:00
Andreas Kling
3845c90e08 Kernel: Remove unnecessary includes from Thread.h
...and deal with the fallout by adding missing includes everywhere.
2022-01-30 16:21:59 +01:00
Pankaj Raghav
60aa4152e9 Kernel: Optimize StorageDevice read and write function
Use shift operator with log size instead of division while calculating
the index and len.
2022-01-29 17:41:06 +02:00
Pankaj Raghav
3b27e28e67 Kernel: Cache blocks_per_page in StorageDevice class
Instead of calculating blocks_per_page in every IO, cache it to save
CPU cycles as that value will not change after initialization.
2022-01-29 17:41:06 +02:00
Liav A
308e54bc19 AK+Kernel: Implement UUID mixed endianness support
This is being used by GUID partitions so the first three dash-delimited
fields of the GUID are stored in little endian order but the last two
fields are stored in big endian order, hence it's a representation which
is mixed.
2022-01-29 13:35:54 +02:00
Idan Horowitz
e1ad9326df Kernel: Remove unimplemented AHCIPort::is_hot_pluggable declaration 2022-01-28 19:05:52 +02:00
Idan Horowitz
bd5b56cab0 Kernel: Make allocate_supervisor_physical_page OOM-fallible 2022-01-28 19:05:52 +02:00
Linus Groh
c05feaaa74 Kernel/Storage: Dump detected devices and partitions before PANIC()'ing
If we panic the kernel for a storage-related reason, we might as well be
helpful and print out a list of detected storage devices and their
partitions to help with debugging.

Reasons for such a panic include:
- No boot device with the given name found
- No boot device with the given UUID found
- Failing to open the root filesystem after determining a boot device
2022-01-26 21:34:26 +00:00
Linus Groh
d8fb3290d5 Kernel/Storage: Add device null check in AHCIPort::handle_interrupt()
Before attempting to remove the device while handling an AHCI port
interrupt, check if m_connected_device is even non-null.
This happened during my bare metal run and caused a kernel panic.
2022-01-26 21:34:26 +00:00
Idan Horowitz
daf6b59a01 Kernel: Make StorageDevice partial block writes OOM-fallible 2022-01-26 02:37:03 +02:00
Idan Horowitz
fa0a052fc6 Kernel: Use PARTUUID: instead of PARTUUID= as the partition uuid prefix
This makes the functionality work again, as we no longer allow any
equal signs inside boot parameter values.
2022-01-25 22:41:17 +02:00
Idan Horowitz
971ab3b919 Kernel: Use u64 instead of size_t in the STORAGE_DEVICE_GET_SIZE ioctl
This ensures the device size doesn't get truncated on i686.
2022-01-25 22:41:17 +02:00
Idan Horowitz
d1ed554dc8 Kernel: Use u64 instead of u32 and u16 in StorageDevice::{read, write}
This ensures offsets will not be truncated on large filesystems on i686
2022-01-25 22:41:17 +02:00
Idan Horowitz
b9cce82cf3 Kernel: Stop using unsigned when adjusting offsets in DiskPartition
These can only contain 32 bit values, and so will truncate very large
offsets.
2022-01-25 22:41:17 +02: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
Pankaj Raghav
4a8a3df975 Kernel: Fix index calculation in NVMeQueue submit_sync_sqe function
There was a bug while calculating the next index in submit_sync_sqe
function. Use the NVMeQueue's class variable m_qdepth instead of the
hardcoded IO_QUEUE_SIZE.
2022-01-25 20:06:19 +02:00
Sam Atkins
45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
Liav A
fc2c2c8a6d Kernel/Storage: Remove NVMeQueue DMA buffer create method
Instead, try to allocate the DMA buffer before trying to construct the
NVMeQueue. This allows us to fail early if we can't allocate the DMA
buffer before allocating and creating the heavier NVMeQueue object.
2022-01-23 20:56:28 +00:00
Liav A
0778043d73 Kernel: Use generic string when allocating DMA buffer to NVMeQueue
We don't necessarily create a DMA buffer just for "Admin CQ queue", so
don't hardcode it when allocating such buffer.
2022-01-23 20:56:28 +00:00
Liav A
0536079ad8 Kernel/Storage: Use StringView when allocating DMA buffer in NVMeQueue 2022-01-23 20:56:28 +00:00
Liav A
e0aaac970c Kernel/Storage: Don't declare NVMeQueue constructor explicit
Also, declare it as a private method.
2022-01-23 20:56:28 +00:00
Liav A
4597e980fe Kernel/Storage: Remove duplicate private declaration in NVMeQueue class
Also, the override of handle_irq method can be private too.
2022-01-23 20:56:28 +00:00
Liav A
64adb2ef96 Kernel/Storage: Declare NVMeQueue handle_irq virtual as it should be 2022-01-23 20:56:28 +00:00
Liav A
eb9c8f3895 Kernel/PCI: Add basic support for the VMD PCI bridge device 2022-01-23 01:12:55 +01:00
Pankaj Raghav
567b3a4810 Kernel: Add individual struct definitions for NVMeSubmission
Only a generic struct definition was present for NVMeSubmission. To
improve type safety and clarity, added an union of NVMeSubmission
structs that are applicable to the command being submitted.
2022-01-18 11:37:04 +02:00
Pankaj Raghav
ba7846647c Kernel: Fix m_ready_timeout calculation in NVMe
The CAP.TO is 0 based. Even though I don't see that mentioned in the
spec explicitly, all major OSs such as Linux, FreeBSD add 1 to the
CAP.TO while calculating the timeout.
2022-01-18 11:37:04 +02:00
Pankaj Raghav
3441eac960 Kernel: Remove delay during NVMe reset and start controller
IO::delay was added as a lazy alternative to looping with a timeout
error if the condition was not satisfied. Now that we have the
wait_for_ready function, remove the delay in the reset and start
controller function.
2022-01-18 11:37:04 +02:00
Pankaj Raghav
31c4c9724b Kernel: Add UNMAP_AFTER_INIT to NVMe member functions
NVMeController, NVMeQueue and NVMeNameSpace had functions which are not
used after init. So add them to UNMAP_AFTER_INIT section.
2022-01-18 11:37:04 +02:00
Tom
0d65af5e0f Kernel: Wait for NVMe controller to change enabled state
We need to wait up to CAP.TO units of 500ms when changing CC.EN to
enable or disable the controller.
2022-01-15 16:45:56 -08: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
6402840670 Kernel: Replace {KString => String}::formatted in determine_boot_device 2022-01-13 00:20:08 -08:00
Idan Horowitz
06af81fcfb Kernel: Move NonnullRefPtrVector<NVMeQueue>s instead of copying them 2022-01-12 16:09:09 +02:00
Idan Horowitz
4b74f2e3ec Kernel: Convert NVMeNameSpace::try_create() to KString 2022-01-12 16:09:09 +02:00
Andreas Kling
05ed8d1738 Kernel: Wait for the ATA busy bit to clear after switching channels
This is a speculative fix for a flaky boot crash that shows up every now
and then on CI.

Fixes #10177. Hopefully.
2022-01-12 02:08:58 +01:00
Andreas Kling
8177e7eb22 Kernel: Clarify IDEChannel function that switches current channel
Rename wait_until_not_busy() => select_device_and_wait_until_not_busy()
to make it more obvious what this thing is doing.
2022-01-12 01:57:38 +01:00
Pankaj Raghav
9ae2285675 Kernel: Make enumerate_disk_partitions function not const
The enumerate_disk_partitions function doesn't need to be const. Remove
the constness and use the newly added `add_partition` function.
2022-01-09 20:18:37 -08:00
Pankaj Raghav
2c810332b6 Kernel: Add add_partition function
Until now partitions were added directly by accessing the private member
of the StorageDevice class.

Add a new member function to add partition.
2022-01-09 20:18:37 -08: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
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Brian Gianforcaro
6c66311ade Kernel: Use MUST + Vector::try_empend instead of Vector::empend
In preparation for making Vector::empend unavailable during
compilation of the Kernel.
2022-01-05 14:04:18 +01:00
Brian Gianforcaro
24066ba5ef Kernel: Use MUST + Vector::try_append instead of Vector::append
In preparation for making Vector::append unavailable during
compilation of the Kernel.
2022-01-05 14:04:18 +01:00
Brian Gianforcaro
d2ac40bcd7 Kernel: Enumerate PCI devices a single time in StorageManagement
Previously we were enumerating multiple times for each storage type.
We can easily enumerate once instead.
2022-01-03 13:26:12 +01:00
Tom
2251733744 Kernel: Allow specifying partition index with NVMe devices
Since NVME devices end with a digit that indicates the node index we
cannot simply append a partition index. Instead, there will be a "p"
character as separator, e.g. /dev/nvme0n1p3 for the 3rd partition.
So, if the early device name ends in a digit we need to add this
separater before matching for the partition index.

If the partition index is omitted (as is the default) the root file
system is on a disk without any partition table (e.g. using QEMU).

This enables booting from the correct partition on an NVMe drive by
setting the command line variable root to e.g. root=/dev/nvme0n1p1
2022-01-02 22:26:36 +01:00
Tom
d1e7b69004 Kernel: Fix NVMe register access
We need to use the volatile keyword when mapping the device registers,
or the compiler may optimize access, which lead to this QEMU error:

pci_nvme_ub_mmiord_toosmall in nvme_mmio_read: MMIO read smaller than
32-bits, offset=0x0
2022-01-01 21:05:44 +00: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
Idan Horowitz
4a3a947df3 Kernel: Rename File::{before_removing => will_be_destroyed}
This will allow File and it's descendants to use RefCounted instead of
having a custom implementation of unref. (Since RefCounted calls
will_be_destroyed automatically)

This commit also removes an erroneous call to `before_removing` in
AHCIPort, this is a duplicate call, as the only reference to the device
is immediately dropped following the call, which in turns calls
`before_removing` via File::unref.
2021-12-29 12:04:15 +01:00
Guilherme Goncalves
33b78915d3 Kernel: Propagate overflow errors from Memory::page_round_up
Fixes #11402.
2021-12-28 23:08:50 +01:00