summaryrefslogtreecommitdiff
path: root/Kernel/Storage/IDEChannel.cpp
AgeCommit message (Collapse)Author
2021-06-24Kernel: Move special sections into Sections.hHendiadyoin1
This also removes a lot of CPU.h includes infavor for Sections.h
2021-06-17Kernel/Interrupts: Return boolean on whether we handled the interruptLiav A
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-05-13Kernel: Make UserOrKernelBuffer R/W helpers return KResultOr<size_t>Andreas Kling
This makes error propagation less cumbersome (and also exposed some places where we were not doing it.)
2021-05-13IDEChannel: Fix wait_until_not_busy() (#7084)Alexander Richards
The time_elapsed variable would count until milliseconds_timeout + 1, so a != comparision won't work.
2021-04-26Kernel/Storage: Make the IDEChannel design more robustLiav A
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-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
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-18Everywhere: Fix a bunch of typosLinus Groh
2021-04-06Kernel/Storage: Wait a few microseconds after selecting the IDE driveLiav A
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-03Kernel/Storage: Add support for IDE controllers in PCI native modeLiav A
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-03-27Kernel/Storage: Use more locking in the IDE codeLiav A
This change should make it less possible for race conditions to happen and cause fatal errors when accessing the hardware.
2021-03-27Kernel/Storage: Add support for non-bus mastering IDE controllersLiav A
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-27Kernel/Storage: Move IDE bus master handling code into a separate classLiav A
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-27Kernel: Make IDEChannel Ref-countedLiav A
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-27Kernel: Remove support for CHS addressingLiav A
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-21Kernel: Add simplistic work queuesTom
We can't use deferred functions for anything that may require preemption, such as copying from/to user or accessing the disk. For those purposes we should use a work queue, which is essentially a kernel thread that may be preempted or blocked.
2021-03-17Kernel: Refactor storage stack with u64 as block indexJean-Baptiste Boric
2021-03-17Kernel: Refactor storage stack with u64 as number of blocksJean-Baptiste Boric
2021-03-15Kernel: Fix race condition completing IDEChannel async requestTom
2021-03-12Kernel: Convert klog() => AK::Format in IDEChannelAndreas Kling
2021-03-05Kernel: Use global mechanism to determine minor number of Storage DeviceLiav A
2021-03-05Kernel: Make ATA macros to be publicLiav A
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-20Kernel: Slap a handful more things with UNMAP_AFTER_INITAndreas Kling
2021-02-08Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)AnotherTest
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-05Kernel: Clear pending interrupts before enabling IRQs of IDE ChannelLiav A
Calling detect_disks() can generate interrupts, so we must clear it to allow proper function when booting with kernel argument smp=on.
2021-02-03Kernel: Restore IDE PIO functionalityLiav A
This change can be actually seen as two logical changes, the first change is about to ensure we only read the ATA Status register only once, because if we read it multiple times, we acknowledge interrupts unintentionally. To solve this issue, we always use the alternate Status register and only read the original status register in the IRQ handler. The second change is how we handle interrupts - if we use DMA, we can just complete the request and return from the IRQ handler. For PIO mode, it's more complicated. For PIO write operation, after setting the ATA registers, we send out the data to IO port, and wait for an interrupt. For PIO read operation, we set the ATA registers, and wait for an interrupt to fire, then we just read from the data IO port.
2021-01-29Kernel/Storage: Rewrite IDE disk detection and disk accessLuke
This replaces the current disk detection and disk access code with code based on https://wiki.osdev.org/IDE This allows the system to boot on VirtualBox with serial debugging enabled and VMWare Player. I believe there were several issues with the current code: - It didn't utilise the last 8 bits of the LBA in 24-bit mode. - {read,write}_sectors_with_dma was not setting the obsolete bits, which according to OSdev wiki aren't used but should be set. - The PIO and DMA methods were using slightly different copy and pasted access code, which is now put into a single function called "ata_access" - PIO mode doesn't work. This doesn't fix that and should be looked into in the future. - The detection code was not checking for ATA/ATAPI. - The detection code accidentally had cyls/heads/spt as 8-bit, when they're 16-bit. - The capabilities of the device were not considered. This is now brought in and is currently used to check if the device supports LBA. If not, use CHS.
2021-01-25Everywhere: Debug macros instead of constexpr.asynts
This was done with the following script: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25Everywhere: Use CMake to generate AK/Debug.h.asynts
This was done with the help of several scripts, I dump them here to easily find them later: awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in) do find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \; done # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list. awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-22Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
2021-01-11Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything:
2021-01-09Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything: The modifications in this commit were automatically made using the following command: find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2020-12-25AK: Remove custom %b format string specifierAndreas Kling
This was a non-standard specifier alias for %02x. This patch replaces all uses of it with new-style formatting functions instead.
2020-12-21Kernel: Add a method to gather the devices count of a Storage controllerLiav A
Also, change device() method to be const.
2020-12-21Kernel: Allow to initialize an IDE device on the secondary channelLiav A
We now use major number 3, and the minor number is set to 0 or 2 if initialized on the primary channel, otherwise 1 or 3 on the secondary channel.
2020-12-21Kernel: Introduce the new Storage subsystemLiav A
This new subsystem is somewhat replacing the IDE disk code we had with a new flexible design. StorageDevice is a generic class that represent a generic storage device. It is meant that specific storage hardware will override the interface. StorageController is a generic class that represent a storage controller that can be found in a machine. The IDEController class governs two IDEChannels. An IDEChannel is responsible to manage the master & slave devices of the channel, therefore an IDEChannel is an IRQHandler.