Commit graph

122 commits

Author SHA1 Message Date
Alexander e9b7d58d10 Kernel/AHCI: Fix shift of 1
This makes the 1 in the shift unsigned.
This also changes the is_set_at parameter to be a u8.
2021-06-25 16:27:01 +02:00
Hendiadyoin1 62f9377656 Kernel: Move special sections into Sections.h
This also removes a lot of CPU.h includes infavor for Sections.h
2021-06-24 00:38:23 +02:00
Liav A b91df26d4a Kernel/Interrupts: Return boolean on whether we handled the interrupt
If we are in a shared interrupt handler, the called handlers might
indicate it was not their interrupt, so we should not increment the
call counter of these handlers.
2021-06-17 16:53:25 +02:00
Gunnar Beutner bc3076f894 Kernel: Remove various other uses of ssize_t 2021-06-16 21:29:36 +02:00
Luke 155f1026ce Kernel/AHCI: Don't set the C command header attribute
This has a quirk with the AMD Hudson-2 SATA controller. [1022:7801]
Having this flag set makes the controller become stuck in a busy loop.

I decided to remove the flag instead of making it a quirk as it still
works with Qemu, VirtualBox, VMware Player and the Intel Wildcat
Point-LP SATA Controller [8086:9c83] without it, thus making it simpler
to just remove it.

Partial fix for #7738 (as it still does not work in IDE mode)
2021-06-15 14:43:22 +02:00
Liav A 10c747f2be Documentation: Add explanation about AHCI locking 2021-05-31 18:28:25 +01:00
Liav A 907b3dd0f3 Kernel/Storage: Enable interrupts for AHCI ports if PHY is not enabled
This change allows the controller to utilize interrupts even if no
device was connected to a port when we initialize it, so we can support
hotplug events now.
2021-05-29 15:51:52 +02:00
Liav A d431e4cd01 Kernel/Storage: Remove the None option from AHCI reset policy
This was proved to be a problematic option. I tested this option on
bare metal AHCI controller, and if we didn't reset the controller, the
firmware (SeaBIOS) could leave the controller state not clean, so an
plugged device signature was in place although the specific port had no
plugged device after rebooting.
Therefore, we need to ensure we use the controller in a clean state
always.

In addition to that, the Complete option was renamed to Aggressive, as
it represents better the consequences of choosing this option.
2021-05-29 15:51:52 +02:00
Liav A 5c1073a62d Kernel/Storage: Rename the method hba_region => default_hba_region
Also, make sure we unmap it after the init process.
2021-05-29 15:51:52 +02:00
Liav A 7078119c58 Kernel: Don't ref-count UsedMemoryRange during iteration 2021-05-16 19:58:33 +02:00
Gunnar Beutner 4b5dbc15df Kernel: Fix incorrect argument when constructing DiskPartitionMetadata
The existing code invokes operator bool for the partition_type
variable.
2021-05-16 17:49:42 +02:00
Luke 57277d8a5c Kernel/AHCI: Fix "received" => "recovered" typo in communication error
The error is actually "Recovered communications error" instead of
"Received communications error".
2021-05-15 19:45:44 +02:00
Luke 174fdddc2b Kernel/AHCI: Get BOH and NVMP from extended capabilities
It was accidentally getting it from the regular capabilities.
2021-05-15 19:45:44 +02:00
Alexander Richards 88a997871e
AHCIController: Fix off-by-one mistake (#7144)
Fixes off-by-one caused by reading the register directly
without adding a 1 to it, because AHCI reports 1 less port than
the actual number of ports supported.
2021-05-15 19:45:23 +02:00
Luke 0f35dfc694 Kernel/AHCI: Don't check for PCC during initialization
On my machine, it only sets PRC and not PCC.

Confirmed to happen on:
- 8086:9ca2 (Intel Corporation Wildcat Point-LP SATA Controller
[AHCI Mode] (rev 03))
2021-05-15 10:14:16 +02:00
Luke 84fc498b9f Kernel/AHCI: Don't enable interrupts in the AHCIPort constructor
On my bare metal machine, enabling it as this point causes it to
instantly send an interrupt, and we're too early in the process
to be able to handle AHCI interrupts. The interrupts were being
enabled in the initialize function anyway.

Confirmed to happen on:
- 8086:9ca2 (Intel Corporation Wildcat Point-LP SATA Controller
[AHCI Mode] (rev 03))
- 8086:3b22 (Intel Corporation 5 Series/3400 Series Chipset
6 port SATA AHCI Controller (rev 06))
2021-05-15 10:14:16 +02:00
Brian Gianforcaro a324d4d6a3 Kernel: Make AnonymousVMObject physical page APIs OOM safe
AnonymousVMObject::create_with_physical_page(s) can't be NonnullRefPtr
as it allocates internally. Fixing the API then surfaced an issue in
ScatterGatherList, where the code was attempting to create an
AnonymousVMObject in the constructor which will not be observable
during OOM.

Fix all of these issues and start propagating errors at the callers
of the AnonymousVMObject and ScatterGatherList APis.
2021-05-15 09:01:32 +02:00
Brian Gianforcaro f3f5a225b9 Kernel: Fix lock state corruption in AHCIPORT::start_request
This code was unlocking the lock directly, but the Locker is still
attached, causing the lock to be unlocked an extra time, hence
corrupting the internal lock state.

This is extra confusing though, as complete_current_request() runs
without a lock which also looks like a bug. But that's a task for
another day.
2021-05-15 09:01:13 +02:00
Andreas Kling e46343bf9a Kernel: Make UserOrKernelBuffer R/W helpers return KResultOr<size_t>
This makes error propagation less cumbersome (and also exposed some
places where we were not doing it.)
2021-05-13 23:28:40 +02:00
Alexander Richards 28a6a9a08f
IDEChannel: Fix wait_until_not_busy() (#7084)
The time_elapsed variable would count until milliseconds_timeout + 1,
so a != comparision won't work.
2021-05-13 19:11:14 +02:00
Sahan Fernando 8131c0de8c Kernel: Move AHCIPort::ScatterList to VM::ScatterGatherList
We want to move this out of the AHCI subsystem into the VM system,
since other parts of the kernel may need to perform scatter-gather IO.

We rename the current VM::ScatterGatherList impl that's used in the
virtio subsystem to VM::ScatterGatherRefList, since its distinguishing
feature from the AHCI scatter-gather list is that it doesn't own its
buffers.
2021-05-13 10:00:42 +02:00
Andreas Kling 3d4afe7614 Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29 22:23:52 +02:00
Linus Groh 649d2faeab Everywhere: Use "the SerenityOS developers." in copyright headers
We had some inconsistencies before:

- Sometimes "The", sometimes "the"
- Sometimes trailing ".", sometimes no trailing "."

I picked the most common one (lowecase "the", trailing ".") and applied
it to all copyright headers.

By using the exact same string everywhere we can ensure nothing gets
missed during a global search (and replace), and that these
inconsistencies are not spread any further (as copyright headers are
commonly copied to new files).
2021-04-29 00:59:26 +02:00
Liav A 161a8ea062 Kernel: Ensure IO and memory accesses are allowed for IDE channels 2021-04-26 18:44:06 +02:00
Liav A 05510e3994 Kernel/Storage: Make the IDEChannel design more robust
The overall design is the same, but we change a few things,
like decreasing the amount of blocking forever loops. The goal
is to ensure the kernel won't hang forever when dealing with
buggy hardware.
Also, we reset the channel when initializing it, just in case the
hardware was in bad state before we start use it.
2021-04-26 18:44:06 +02:00
Liav A a2a7986527 Kernel/Storage: Fix sending IOGroup parameters 2021-04-26 18:44:06 +02:00
Linus Groh dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
Brian Gianforcaro 8d6e9fad40 Kernel: Remove the now defunct LOCKER(..) macro. 2021-04-25 09:38:27 +02:00
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Linus Groh 2b0c361d04 Everywhere: Fix a bunch of typos 2021-04-18 10:30:03 +02:00
Jean-Baptiste Boric a73bd0fff8 Kernel: Remove type from StorageDevice class 2021-04-13 21:52:34 +02:00
Liav A a0be30f655 Kernel: Introduce two new boot arguments to assist with bare metal debug
The first one is for disabling the PS2 controller, the other one is for
disabling physical storage enumeration.
We can't be sure any machine will work with our implementation,
therefore this will help us to test more machines.
2021-04-08 22:17:13 +02:00
Liav A da109eeab8 Kernel/Storage: Wait a few microseconds after selecting the IDE drive
We need to do it to let real hardware to put the correct voltages
on the wire.
Apparently my ICH7 machine refused to boot, and was reading lots of
garbage from an unconnected IDE channel. It was fixed after I added a
delay of 20 microseconds. It probably can be reduced, I just took a safe
value and it seems to work correctly without any problems :)
2021-04-06 22:25:28 +02:00
Jean-Baptiste Boric 346e0f4dac Kernel: Don't crash if unable to map ramdisk inside kernel address space 2021-04-06 18:17:16 +02:00
Jean-Baptiste Boric 436ca2491d Kernel: Fix KUBSAN crash with RamdiskDevice 2021-04-06 18:17:16 +02:00
Liav A 2718d7c74c Kernel/Storage: Add support for IDE controllers in PCI native mode
Also handle native and compatibility channel modes together, so if only
one IDE channel was set to work on PCI native mode, we need to handle it
separately, so the other channel continue to operate with the legacy IO
ports and interrupt line.
2021-04-03 11:57:23 +02:00
Liav A 3547d90a0f Kernel/Storage: Select the drive before working with busmaster register
This is a "quirk" I've observed on a Intel ICH7 test machine. Apparently
we need to select the device (master or slave) before starting to work
with the bus master register.
It's very possible that other machines are requiring this step to happen
before the DMA transfer can occur correctly.

Also, when reading with DMA, we should set the transfer direction before
clearing the interrupt status.

For the sake of completeness, I added a few lines in places that I
deemed it to be reasonable to clear the interrupt status there.
2021-03-27 16:40:16 +01:00
Liav A 1d0c183388 Kernel/Storage: Add some debug printing about IDE controllers 2021-03-27 16:40:16 +01:00
Liav A 186e03b99d Kernel/Storage: Remove redundant public declaration in IDEController.h 2021-03-27 16:40:16 +01:00
Liav A b96e4c1308 Kernel/Storage: Use more locking in the IDE code
This change should make it less possible for race conditions to happen
and cause fatal errors when accessing the hardware.
2021-03-27 16:40:16 +01:00
Liav A 8b446fb579 Kernel/Storage: Add support for non-bus mastering IDE controllers
Although unlikely to happen, a user can have an IDE controller that
doesn't support bus master capability. If that's the case, we need to
check for this, and create an IDEChannel (not BMIDEChannel) to allow
IO operations with the controller.
2021-03-27 16:40:16 +01:00
Liav A 833a6bd047 Kernel/Storage: Move IDE bus master handling code into a separate class
If the user requests to force PIO mode, we just create IDEChannel
objects which are capable of sending PIO commands only.
However, if the user doesn't force PIO mode, we create BMIDEChannel
objects, which are sending DMA commands.

This change is somewhat simplifying the code, so each class is
supporting its type of operation - PIO or DMA. The PATADiskDevice
should not care if DMA is enabled or not.

Later on, we could write an IDEChannel class for UDMA modes,
that are available and documented on Intel specifications for their IDE
controllers.
2021-03-27 16:40:16 +01:00
Liav A dfb6b296cf Kernel: Make IDEChannel Ref-counted
Technically not supported by the original ATA specification, IDE
hot swapping is still in practice possible, so the only sane way
to start support it is with ref-counting the IDEChannel object so if we
remove a PATADiskDevice, it's not gone with it.
2021-03-27 16:40:16 +01:00
Liav A 531037db7e Kernel: Remove support for CHS addressing
An article about IDE limits states that:
"Hard drives over 8.4 GB are supposed to report their geometry as
16383/16/63. This in effect means that the `geometry' is obsolete, and
the total disk size can no longer be computed from the geometry, but is
found in the LBA capacity field returned by the IDENTIFY command.
Hard drives over 137.4 GB are supposed to report an LBA capacity of
0xfffffff = 268435455 sectors (137438952960 bytes). Now the actual disk
size is found in the new 48-capacity field."
(https://tldp.org/HOWTO/Large-Disk-HOWTO-4.html) which is the main
reason to not support CHS as harddrives with less than 8.4 GB capacity
are completely obsolete.

Another good reason is that virtually any harddrive in the last 20 years
or so, supports LBA mode. Therefore, it's probably OK to just ignore CHS
as it's unlikely to encounter a harddrive that doesn't support LBA.

This is somewhat simplifying the IDE initialization and access code.
Also, we should use the ATAIdentifyBlock structure if possible,
so now we do it instead of using macros to calculate offsets.

With the usage of the ATAIdentifyBlock structure, we now use the
48-bit LBA max count if the drive indicates it supports 48-bit LBA mode.
2021-03-27 16:40:16 +01:00
Liav A 4bb8986752 Kernel: Generalize the ATAIdentifyBlock structure 2021-03-27 16:40:16 +01:00
Michel Hermier 51ad3da999 Kernel: Remove unused MBRPartitionTable::m_partitions_count. 2021-03-26 16:54:05 +01:00
Michel Hermier a359f477a7 Kernel: Remove unused EBRPartitionTable::m_partitions_count. 2021-03-26 16:54:05 +01:00
Michel Hermier 37be679d6e Kernel: Remove unused AHCIPort::ScatterList::m_device_block_size. 2021-03-26 16:54:05 +01:00
Liav A b25f84daaa Revert "Kernel/AHCI: Add a boot argument to force AHCI to operate on IRQ 11"
This reverts commit cfc2f33dcb.

We can't actually change the IRQ line value and expect the device
to work with it (this was my mistake).
That register is R/W so the firmware can figure out IRQ routing and put
the correct value and write it to the Interrupt line register.
2021-03-23 19:27:00 +01:00