summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2020-02-22 20:11:18 +0200
committerAndreas Kling <kling@serenityos.org>2020-02-24 11:27:03 +0100
commitb3c132ffb7d8d294310d3747321332074604e08d (patch)
treef59e0e43b68ac80a7be31f8f7d47d10fde4d616e
parent83aa868c17483e7ed37686461b5e2f9e8566e8c3 (diff)
downloadserenity-b3c132ffb7d8d294310d3747321332074604e08d.zip
Kernel: Update PATAChannel implementation to use the PIT class
Also, update the class implementation to use PCI::Device class accordingly. The create() helper will now search for an IDE controller in the PCI bus, allowing to simplify the initialize() method.
-rw-r--r--Kernel/Devices/PATAChannel.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/Kernel/Devices/PATAChannel.cpp b/Kernel/Devices/PATAChannel.cpp
index 6b4174a6d1..0bc54596f3 100644
--- a/Kernel/Devices/PATAChannel.cpp
+++ b/Kernel/Devices/PATAChannel.cpp
@@ -27,6 +27,7 @@
#include "PATADiskDevice.h"
#include <AK/ByteBuffer.h>
#include <Kernel/Devices/PATAChannel.h>
+#include <Kernel/Devices/PIT.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/Process.h>
#include <Kernel/VM/MemoryManager.h>
@@ -116,11 +117,18 @@ static Lock& s_lock()
OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio)
{
- return make<PATAChannel>(type, force_pio);
+ PCI::Address pci_address;
+ PCI::enumerate_all([&](const PCI::Address& address, PCI::ID id) {
+ if (PCI::get_class(address) == PCI_Mass_Storage_Class && PCI::get_subclass(address) == PCI_IDE_Controller_Subclass) {
+ pci_address = address;
+ kprintf("PATAChannel: PATA Controller found! id=%w:%w\n", id.vendor_id, id.device_id);
+ }
+ });
+ return make<PATAChannel>(pci_address, type, force_pio);
}
-PATAChannel::PATAChannel(ChannelType type, bool force_pio)
- : IRQHandler((type == ChannelType::Primary ? PATA_PRIMARY_IRQ : PATA_SECONDARY_IRQ))
+PATAChannel::PATAChannel(PCI::Address address, ChannelType type, bool force_pio)
+ : PCI::Device(address, (type == ChannelType::Primary ? PATA_PRIMARY_IRQ : PATA_SECONDARY_IRQ))
, m_channel_number((type == ChannelType::Primary ? 0 : 1))
, m_io_base((type == ChannelType::Primary ? 0x1F0 : 0x170))
, m_control_base((type == ChannelType::Primary ? 0x3f6 : 0x376))
@@ -142,17 +150,6 @@ PATAChannel::~PATAChannel()
void PATAChannel::initialize(bool force_pio)
{
- PCI::enumerate_all([this](const PCI::Address& address, PCI::ID id) {
- if (PCI::get_class(address) == PCI_Mass_Storage_Class && PCI::get_subclass(address) == PCI_IDE_Controller_Subclass) {
- m_pci_address = address;
- kprintf("PATAChannel: PATA Controller found! id=%w:%w\n", id.vendor_id, id.device_id);
- }
- });
-
- if (m_pci_address.is_null()) {
- kprintf("PATAChannel: PCI address was null; can not set up DMA\n");
- return;
- }
if (force_pio) {
kprintf("PATAChannel: Requested to force PIO mode; not setting up DMA\n");
@@ -160,9 +157,9 @@ void PATAChannel::initialize(bool force_pio)
}
// Let's try to set up DMA transfers.
- PCI::enable_bus_mastering(m_pci_address);
+ PCI::enable_bus_mastering(get_pci_address());
prdt().end_of_table = 0x8000;
- m_bus_master_base = PCI::get_BAR4(m_pci_address) & 0xfffc;
+ m_bus_master_base = PCI::get_BAR4(get_pci_address()) & 0xfffc;
m_dma_buffer_page = MM.allocate_supervisor_physical_page();
kprintf("PATAChannel: Bus master IDE: I/O @ %x\n", m_bus_master_base);
}
@@ -188,7 +185,7 @@ void PATAChannel::wait_for_irq()
disable_irq();
}
-void PATAChannel::handle_irq()
+void PATAChannel::handle_irq(RegisterState&)
{
u8 status = IO::in8(m_io_base + ATA_REG_STATUS);
if (status & ATA_SR_ERR) {