From 0b3a8687299fddb65ab6c1966ad82dde8fa26187 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Fri, 27 Dec 2019 08:57:58 +1100 Subject: [PATCH] Kernel: Simplify force_pio logic in PATA driver (#923) --- Kernel/Devices/PATAChannel.cpp | 28 ++++++++++++++++------------ Kernel/Devices/PATAChannel.h | 1 - Kernel/Devices/PATADiskDevice.cpp | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Kernel/Devices/PATAChannel.cpp b/Kernel/Devices/PATAChannel.cpp index 1085e1f10fa..6866139e060 100644 --- a/Kernel/Devices/PATAChannel.cpp +++ b/Kernel/Devices/PATAChannel.cpp @@ -118,19 +118,23 @@ void PATAChannel::initialize(bool force_pio) kprintf("PATAChannel: PATA Controller found! id=%w:%w\n", id.vendor_id, id.device_id); } }); - m_force_pio.resource() = false; - if (!m_pci_address.is_null()) { - // Let's try to set up DMA transfers. - PCI::enable_bus_mastering(m_pci_address); - m_prdt.end_of_table = 0x8000; - m_bus_master_base = PCI::get_BAR4(m_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); - if (force_pio) { - m_force_pio.resource() = true; - kprintf("PATAChannel: Requested to force PIO mode!\n"); - } + + 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"); + return; + } + + // Let's try to set up DMA transfers. + PCI::enable_bus_mastering(m_pci_address); + m_prdt.end_of_table = 0x8000; + m_bus_master_base = PCI::get_BAR4(m_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); } static void print_ide_status(u8 status) diff --git a/Kernel/Devices/PATAChannel.h b/Kernel/Devices/PATAChannel.h index af93cf18374..da1cb954218 100644 --- a/Kernel/Devices/PATAChannel.h +++ b/Kernel/Devices/PATAChannel.h @@ -69,7 +69,6 @@ private: RefPtr m_dma_buffer_page; u16 m_bus_master_base { 0 }; Lockable m_dma_enabled; - Lockable m_force_pio; RefPtr m_master; RefPtr m_slave; diff --git a/Kernel/Devices/PATADiskDevice.cpp b/Kernel/Devices/PATADiskDevice.cpp index eadbb1957d4..8c017e5d7a0 100644 --- a/Kernel/Devices/PATADiskDevice.cpp +++ b/Kernel/Devices/PATADiskDevice.cpp @@ -24,7 +24,7 @@ const char* PATADiskDevice::class_name() const bool PATADiskDevice::read_blocks(unsigned index, u16 count, u8* out) { - if (m_channel.m_bus_master_base && m_channel.m_dma_enabled.resource() && !m_channel.m_force_pio.resource()) + if (m_channel.m_bus_master_base && m_channel.m_dma_enabled.resource()) return read_sectors_with_dma(index, count, out); return read_sectors(index, count, out); }