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.
This commit is contained in:
Liav A 2020-02-22 20:11:18 +02:00 committed by Andreas Kling
parent 83aa868c17
commit b3c132ffb7
Notes: sideshowbarker 2024-07-19 09:06:27 +09:00

View File

@ -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) {