2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
#include <AK/ByteBuffer.h>
|
2020-08-24 19:35:19 -06:00
|
|
|
#include <AK/Singleton.h>
|
2020-03-23 13:45:10 +01:00
|
|
|
#include <AK/StringView.h>
|
2019-05-19 15:54:33 +02:00
|
|
|
#include <Kernel/FileSystem/ProcFS.h>
|
2020-06-24 14:07:28 -06:00
|
|
|
#include <Kernel/IO.h>
|
2019-06-07 11:43:58 +02:00
|
|
|
#include <Kernel/Process.h>
|
2020-12-19 12:50:57 +02:00
|
|
|
#include <Kernel/Storage/IDEChannel.h>
|
|
|
|
#include <Kernel/Storage/IDEController.h>
|
|
|
|
#include <Kernel/Storage/PATADiskDevice.h>
|
2019-06-07 11:43:58 +02:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
#define PATA_PRIMARY_IRQ 14
|
|
|
|
#define PATA_SECONDARY_IRQ 15
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
//#define PATA_DEBUG
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-06-07 11:43:58 +02:00
|
|
|
#define ATA_SR_BSY 0x80
|
|
|
|
#define ATA_SR_DRDY 0x40
|
|
|
|
#define ATA_SR_DF 0x20
|
|
|
|
#define ATA_SR_DSC 0x10
|
|
|
|
#define ATA_SR_DRQ 0x08
|
|
|
|
#define ATA_SR_CORR 0x04
|
|
|
|
#define ATA_SR_IDX 0x02
|
|
|
|
#define ATA_SR_ERR 0x01
|
|
|
|
|
|
|
|
#define ATA_ER_BBK 0x80
|
|
|
|
#define ATA_ER_UNC 0x40
|
|
|
|
#define ATA_ER_MC 0x20
|
|
|
|
#define ATA_ER_IDNF 0x10
|
|
|
|
#define ATA_ER_MCR 0x08
|
|
|
|
#define ATA_ER_ABRT 0x04
|
|
|
|
#define ATA_ER_TK0NF 0x02
|
|
|
|
#define ATA_ER_AMNF 0x01
|
|
|
|
|
|
|
|
#define ATA_CMD_READ_PIO 0x20
|
|
|
|
#define ATA_CMD_READ_PIO_EXT 0x24
|
|
|
|
#define ATA_CMD_READ_DMA 0xC8
|
|
|
|
#define ATA_CMD_READ_DMA_EXT 0x25
|
|
|
|
#define ATA_CMD_WRITE_PIO 0x30
|
|
|
|
#define ATA_CMD_WRITE_PIO_EXT 0x34
|
|
|
|
#define ATA_CMD_WRITE_DMA 0xCA
|
|
|
|
#define ATA_CMD_WRITE_DMA_EXT 0x35
|
|
|
|
#define ATA_CMD_CACHE_FLUSH 0xE7
|
|
|
|
#define ATA_CMD_CACHE_FLUSH_EXT 0xEA
|
|
|
|
#define ATA_CMD_PACKET 0xA0
|
|
|
|
#define ATA_CMD_IDENTIFY_PACKET 0xA1
|
|
|
|
#define ATA_CMD_IDENTIFY 0xEC
|
|
|
|
|
|
|
|
#define ATAPI_CMD_READ 0xA8
|
|
|
|
#define ATAPI_CMD_EJECT 0x1B
|
|
|
|
|
|
|
|
#define ATA_IDENT_DEVICETYPE 0
|
|
|
|
#define ATA_IDENT_CYLINDERS 2
|
|
|
|
#define ATA_IDENT_HEADS 6
|
|
|
|
#define ATA_IDENT_SECTORS 12
|
|
|
|
#define ATA_IDENT_SERIAL 20
|
|
|
|
#define ATA_IDENT_MODEL 54
|
2019-05-19 03:46:50 +02:00
|
|
|
#define ATA_IDENT_CAPABILITIES 98
|
2019-06-07 11:43:58 +02:00
|
|
|
#define ATA_IDENT_FIELDVALID 106
|
|
|
|
#define ATA_IDENT_MAX_LBA 120
|
|
|
|
#define ATA_IDENT_COMMANDSETS 164
|
|
|
|
#define ATA_IDENT_MAX_LBA_EXT 200
|
|
|
|
|
|
|
|
#define IDE_ATA 0x00
|
|
|
|
#define IDE_ATAPI 0x01
|
|
|
|
|
|
|
|
#define ATA_REG_DATA 0x00
|
|
|
|
#define ATA_REG_ERROR 0x01
|
|
|
|
#define ATA_REG_FEATURES 0x01
|
|
|
|
#define ATA_REG_SECCOUNT0 0x02
|
|
|
|
#define ATA_REG_LBA0 0x03
|
|
|
|
#define ATA_REG_LBA1 0x04
|
|
|
|
#define ATA_REG_LBA2 0x05
|
|
|
|
#define ATA_REG_HDDEVSEL 0x06
|
|
|
|
#define ATA_REG_COMMAND 0x07
|
|
|
|
#define ATA_REG_STATUS 0x07
|
2019-09-04 11:10:07 +02:00
|
|
|
#define ATA_CTL_CONTROL 0x00
|
|
|
|
#define ATA_CTL_ALTSTATUS 0x00
|
|
|
|
#define ATA_CTL_DEVADDRESS 0x01
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2019-11-13 19:29:16 +02:00
|
|
|
#define PCI_Mass_Storage_Class 0x1
|
|
|
|
#define PCI_IDE_Controller_Subclass 0x1
|
2020-08-24 19:35:19 -06:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
NonnullOwnPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IOAddressGroup io_group, ChannelType type, bool force_pio)
|
2018-10-16 14:17:43 +02:00
|
|
|
{
|
2020-12-19 12:50:57 +02:00
|
|
|
return make<IDEChannel>(controller, io_group, type, force_pio);
|
2018-10-16 14:17:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
RefPtr<StorageDevice> IDEChannel::master_device()
|
|
|
|
{
|
|
|
|
return m_master;
|
|
|
|
}
|
|
|
|
RefPtr<StorageDevice> IDEChannel::slave_device()
|
|
|
|
{
|
|
|
|
return m_slave;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDEChannel::IDEChannel(const IDEController& controller, IOAddressGroup io_group, ChannelType type, bool force_pio)
|
|
|
|
: IRQHandler(type == ChannelType::Primary ? PATA_PRIMARY_IRQ : PATA_SECONDARY_IRQ)
|
2019-07-28 23:44:01 +10:00
|
|
|
, m_channel_number((type == ChannelType::Primary ? 0 : 1))
|
2020-12-19 12:50:57 +02:00
|
|
|
, m_io_group(io_group)
|
|
|
|
, m_parent_controller(controller)
|
2018-10-16 14:17:43 +02:00
|
|
|
{
|
2020-01-22 22:23:50 +01:00
|
|
|
disable_irq();
|
2019-12-01 12:47:53 +01:00
|
|
|
|
2020-04-14 22:48:02 +03:00
|
|
|
m_dma_enabled.resource() = !force_pio;
|
2019-08-16 16:35:02 +03:00
|
|
|
ProcFS::add_sys_bool("ide_dma", m_dma_enabled);
|
2018-10-16 14:17:43 +02:00
|
|
|
|
2019-11-13 19:29:16 +02:00
|
|
|
initialize(force_pio);
|
2019-07-28 23:44:01 +10:00
|
|
|
detect_disks();
|
2020-11-02 11:16:01 -07:00
|
|
|
enable_irq();
|
2018-10-16 14:17:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
IDEChannel::~IDEChannel()
|
2019-05-19 04:40:30 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::start_request(AsyncBlockDeviceRequest& request, bool use_dma, bool is_slave)
|
2020-03-06 03:22:53 +02:00
|
|
|
{
|
2020-11-02 11:16:01 -07:00
|
|
|
ScopedSpinLock lock(m_request_lock);
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel::start_request";
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
m_current_request = &request;
|
|
|
|
m_current_request_block_index = 0;
|
|
|
|
m_current_request_uses_dma = use_dma;
|
|
|
|
m_current_request_flushing_cache = false;
|
|
|
|
|
|
|
|
if (request.request_type() == AsyncBlockDeviceRequest::Read) {
|
|
|
|
if (use_dma)
|
|
|
|
ata_read_sectors_with_dma(is_slave);
|
|
|
|
else
|
|
|
|
ata_read_sectors(is_slave);
|
|
|
|
} else {
|
|
|
|
if (use_dma)
|
|
|
|
ata_write_sectors_with_dma(is_slave);
|
|
|
|
else
|
|
|
|
ata_write_sectors(is_slave);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::complete_current_request(AsyncDeviceRequest::RequestResult result)
|
2020-11-02 11:16:01 -07:00
|
|
|
{
|
|
|
|
// NOTE: this may be called from the interrupt handler!
|
|
|
|
ASSERT(m_current_request);
|
|
|
|
ASSERT(m_request_lock.is_locked());
|
|
|
|
|
|
|
|
// Now schedule reading back the buffer as soon as we leave the irq handler.
|
|
|
|
// This is important so that we can safely write the buffer back,
|
|
|
|
// which could cause page faults. Note that this may be called immediately
|
|
|
|
// before Processor::deferred_call_queue returns!
|
|
|
|
Processor::deferred_call_queue([this, result]() {
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel::complete_current_request result: " << result;
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
ASSERT(m_current_request);
|
|
|
|
auto& request = *m_current_request;
|
|
|
|
m_current_request = nullptr;
|
|
|
|
|
|
|
|
if (m_current_request_uses_dma) {
|
|
|
|
if (result == AsyncDeviceRequest::Success) {
|
|
|
|
if (request.request_type() == AsyncBlockDeviceRequest::Read) {
|
|
|
|
if (!request.write_to_buffer(request.buffer(), m_dma_buffer_page->paddr().offset(0xc0000000).as_ptr(), 512 * request.block_count())) {
|
|
|
|
request.complete(AsyncDeviceRequest::MemoryFault);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// I read somewhere that this may trigger a cache flush so let's do it.
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().offset(2).out<u8>(m_io_group.bus_master_base().offset(2).in<u8>() | 0x6);
|
2020-11-02 11:16:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request.complete(result);
|
|
|
|
});
|
2020-03-06 03:22:53 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::initialize(bool force_pio)
|
2018-10-16 14:17:43 +02:00
|
|
|
{
|
2020-12-19 12:50:57 +02:00
|
|
|
m_parent_controller->enable_pin_based_interrupts();
|
2019-12-27 08:57:58 +11:00
|
|
|
if (force_pio) {
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: Requested to force PIO mode; not setting up DMA";
|
2019-12-27 08:57:58 +11:00
|
|
|
return;
|
|
|
|
}
|
2020-04-14 22:48:02 +03:00
|
|
|
|
2019-12-27 08:57:58 +11:00
|
|
|
// Let's try to set up DMA transfers.
|
2020-12-19 12:50:57 +02:00
|
|
|
PCI::enable_bus_mastering(m_parent_controller->pci_address());
|
2020-04-14 22:48:02 +03:00
|
|
|
m_prdt_page = MM.allocate_supervisor_physical_page();
|
2020-01-17 19:59:20 +01:00
|
|
|
prdt().end_of_table = 0x8000;
|
2019-12-27 08:57:58 +11:00
|
|
|
m_dma_buffer_page = MM.allocate_supervisor_physical_page();
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: Bus master IDE: " << m_io_group.bus_master_base();
|
2018-10-16 14:17:43 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static void print_ide_status(u8 status)
|
2018-11-10 15:15:31 +01:00
|
|
|
{
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: print_ide_status: DRQ=" << ((status & ATA_SR_DRQ) != 0) << " BSY=" << ((status & ATA_SR_BSY) != 0) << " DRDY=" << ((status & ATA_SR_DRDY) != 0) << " DSC=" << ((status & ATA_SR_DSC) != 0) << " DF=" << ((status & ATA_SR_DF) != 0) << " CORR=" << ((status & ATA_SR_CORR) != 0) << " IDX=" << ((status & ATA_SR_IDX) != 0) << " ERR=" << ((status & ATA_SR_ERR) != 0);
|
2018-11-10 15:15:31 +01:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::handle_irq(const RegisterState&)
|
2018-11-10 15:15:31 +01:00
|
|
|
{
|
2020-12-19 12:50:57 +02:00
|
|
|
u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
|
2020-06-24 14:07:28 -06:00
|
|
|
|
|
|
|
m_entropy_source.add_random_event(status);
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
u8 bstatus = m_io_group.bus_master_base().offset(2).in<u8>();
|
2020-06-29 17:15:29 -06:00
|
|
|
if (!(bstatus & 0x4)) {
|
|
|
|
// interrupt not from this device, ignore
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: ignore interrupt";
|
2020-06-29 17:15:29 -06:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
ScopedSpinLock lock(m_request_lock);
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: interrupt: DRQ=" << ((status & ATA_SR_DRQ) != 0) << " BSY=" << ((status & ATA_SR_BSY) != 0) << " DRDY=" << ((status & ATA_SR_DRDY) != 0);
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!m_current_request) {
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel: IRQ but no pending request!";
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool received_all_irqs = m_current_request_uses_dma || m_current_request_block_index + 1 >= m_current_request->block_count();
|
|
|
|
|
2019-05-24 04:17:15 +02:00
|
|
|
if (status & ATA_SR_ERR) {
|
2019-02-11 11:38:14 +01:00
|
|
|
print_ide_status(status);
|
2020-12-19 12:50:57 +02:00
|
|
|
m_device_error = m_io_group.io_base().offset(ATA_REG_ERROR).in<u8>();
|
|
|
|
klog() << "IDEChannel: Error " << String::format("%b", m_device_error) << "!";
|
2020-11-02 11:16:01 -07:00
|
|
|
complete_current_request(AsyncDeviceRequest::Failure);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_device_error = 0;
|
|
|
|
if (received_all_irqs) {
|
|
|
|
complete_current_request(AsyncDeviceRequest::Success);
|
2019-02-11 11:38:14 +01:00
|
|
|
} else {
|
2020-11-02 11:16:01 -07:00
|
|
|
ASSERT(!m_current_request_uses_dma);
|
|
|
|
|
|
|
|
// Now schedule reading/writing the buffer as soon as we leave the irq handler.
|
|
|
|
// This is important so that we can safely access the buffers, which could
|
|
|
|
// trigger page faults
|
|
|
|
Processor::deferred_call_queue([this]() {
|
|
|
|
if (m_current_request->request_type() == AsyncBlockDeviceRequest::Read) {
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel: Read block " << m_current_request_block_index << "/" << m_current_request->block_count();
|
2020-11-02 11:16:01 -07:00
|
|
|
if (ata_do_read_sector()) {
|
|
|
|
if (++m_current_request_block_index >= m_current_request->block_count()) {
|
|
|
|
complete_current_request(AsyncDeviceRequest::Success);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Wait for the next block
|
|
|
|
enable_irq();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!m_current_request_flushing_cache) {
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel: Wrote block " << m_current_request_block_index << "/" << m_current_request->block_count();
|
2020-11-02 11:16:01 -07:00
|
|
|
if (++m_current_request_block_index >= m_current_request->block_count()) {
|
|
|
|
// We read the last block, flush cache
|
|
|
|
ASSERT(!m_current_request_flushing_cache);
|
|
|
|
m_current_request_flushing_cache = true;
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_CACHE_FLUSH);
|
2020-11-02 11:16:01 -07:00
|
|
|
} else {
|
|
|
|
// Read next block
|
|
|
|
ata_do_write_sector();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
complete_current_request(AsyncDeviceRequest::Success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-02-11 11:38:14 +01:00
|
|
|
}
|
2018-11-10 15:15:31 +01:00
|
|
|
}
|
|
|
|
|
2019-09-04 11:10:07 +02:00
|
|
|
static void io_delay()
|
2018-11-10 15:15:31 +01:00
|
|
|
{
|
2019-07-28 23:44:01 +10:00
|
|
|
for (int i = 0; i < 4; ++i)
|
2019-09-04 11:10:07 +02:00
|
|
|
IO::in8(0x3f6);
|
2019-07-28 23:44:01 +10:00
|
|
|
}
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::detect_disks()
|
2019-07-28 23:44:01 +10:00
|
|
|
{
|
|
|
|
// There are only two possible disks connected to a channel
|
|
|
|
for (auto i = 0; i < 2; i++) {
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_HDDEVSEL).out<u8>(0xA0 | (i << 4)); // First, we need to select the drive itself
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
// Apparently these need to be 0 before sending IDENTIFY?!
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(0x00);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>(0x00);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>(0x00);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>(0x00);
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_IDENTIFY); // Send the ATA_IDENTIFY command
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
// Wait for the BSY flag to be reset
|
2020-12-19 12:50:57 +02:00
|
|
|
while (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY)
|
2019-07-28 23:44:01 +10:00
|
|
|
;
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
if (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() == 0x00) {
|
2019-07-28 23:44:01 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: No " << (i == 0 ? "master" : "slave") << " disk detected!";
|
2019-07-28 23:44:01 +10:00
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512);
|
|
|
|
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512);
|
2019-09-30 08:57:01 +02:00
|
|
|
u8* b = bbuf.data();
|
|
|
|
u16* w = (u16*)wbuf.data();
|
|
|
|
const u16* wbufbase = (u16*)wbuf.data();
|
2019-07-28 23:44:01 +10:00
|
|
|
|
|
|
|
for (u32 i = 0; i < 256; ++i) {
|
2020-12-19 12:50:57 +02:00
|
|
|
u16 data = m_io_group.io_base().offset(ATA_REG_DATA).in<u16>();
|
2019-07-28 23:44:01 +10:00
|
|
|
*(w++) = data;
|
|
|
|
*(b++) = MSB(data);
|
|
|
|
*(b++) = LSB(data);
|
|
|
|
}
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2019-07-28 23:44:01 +10:00
|
|
|
// "Unpad" the device name string.
|
|
|
|
for (u32 i = 93; i > 54 && bbuf[i] == ' '; --i)
|
|
|
|
bbuf[i] = 0;
|
|
|
|
|
|
|
|
u8 cyls = wbufbase[1];
|
|
|
|
u8 heads = wbufbase[3];
|
|
|
|
u8 spt = wbufbase[6];
|
2020-12-19 12:50:57 +02:00
|
|
|
if (cyls == 0 || heads == 0 || spt == 0)
|
|
|
|
continue;
|
|
|
|
klog() << "IDEChannel: Name=" << ((char*)bbuf.data() + 54) << ", C/H/Spt=" << cyls << "/" << heads << "/" << spt;
|
2019-07-28 23:44:01 +10:00
|
|
|
|
|
|
|
if (i == 0) {
|
2020-12-19 12:53:34 +02:00
|
|
|
m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, cyls, heads, spt, 3, (m_channel_number == 0) ? 0 : 2);
|
2019-07-28 23:44:01 +10:00
|
|
|
} else {
|
2020-12-19 12:53:34 +02:00
|
|
|
m_slave = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Slave, cyls, heads, spt, 3, (m_channel_number == 0) ? 1 : 3);
|
2019-07-28 23:44:01 +10:00
|
|
|
}
|
2019-05-19 03:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::ata_read_sectors_with_dma(bool slave_request)
|
2019-05-19 03:46:50 +02:00
|
|
|
{
|
2020-11-02 11:16:01 -07:00
|
|
|
auto& request = *m_current_request;
|
|
|
|
u32 lba = request.block_index();
|
2019-07-28 23:44:01 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel::ata_read_sectors_with_dma (" << lba << " x" << request.block_count() << ")";
|
2019-05-19 03:46:50 +02:00
|
|
|
#endif
|
|
|
|
|
2020-01-17 19:59:20 +01:00
|
|
|
prdt().offset = m_dma_buffer_page->paddr();
|
2020-11-02 11:16:01 -07:00
|
|
|
prdt().size = 512 * request.block_count();
|
2019-05-19 04:40:30 +02:00
|
|
|
|
2020-01-17 19:59:20 +01:00
|
|
|
ASSERT(prdt().size <= PAGE_SIZE);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
|
|
|
// Stop bus master
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().out<u8>(0);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
|
|
|
// Write the PRDT location
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().offset(4).out(m_prdt_page->paddr().get());
|
2019-05-19 03:46:50 +02:00
|
|
|
|
|
|
|
// Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware.
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().offset(2).out<u8>(m_io_group.bus_master_base().offset(2).in<u8>() | 0x6);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
|
|
|
// Set transfer direction
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().out<u8>(0x8);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
while (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY)
|
2019-06-07 11:43:58 +02:00
|
|
|
;
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.control_base().offset(ATA_CTL_CONTROL).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_HDDEVSEL).out<u8>(0x40 | (static_cast<u8>(slave_request) << 4));
|
2019-09-04 11:10:07 +02:00
|
|
|
io_delay();
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_FEATURES).out<u16>(0);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>(0);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(request.block_count());
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>((lba & 0x000000ff) >> 0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>((lba & 0x0000ff00) >> 8);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>((lba & 0x00ff0000) >> 16);
|
2019-05-19 03:46:50 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2020-12-19 12:50:57 +02:00
|
|
|
auto status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
|
2019-05-19 03:46:50 +02:00
|
|
|
if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_READ_DMA_EXT);
|
2019-09-04 11:10:07 +02:00
|
|
|
io_delay();
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
enable_irq();
|
2019-05-19 03:46:50 +02:00
|
|
|
// Start bus master
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().out<u8>(0x9);
|
2020-11-02 11:16:01 -07:00
|
|
|
}
|
2019-05-19 03:46:50 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
bool IDEChannel::ata_do_read_sector()
|
2020-11-02 11:16:01 -07:00
|
|
|
{
|
|
|
|
auto& request = *m_current_request;
|
|
|
|
auto out_buffer = request.buffer().offset(m_current_request_block_index * 512);
|
|
|
|
ssize_t nwritten = request.write_to_buffer_buffered<512>(out_buffer, 512, [&](u8* buffer, size_t buffer_bytes) {
|
|
|
|
for (size_t i = 0; i < buffer_bytes; i += sizeof(u16))
|
2020-12-19 12:50:57 +02:00
|
|
|
*(u16*)&buffer[i] = IO::in16(m_io_group.io_base().offset(ATA_REG_DATA).get());
|
2020-11-02 11:16:01 -07:00
|
|
|
return (ssize_t)buffer_bytes;
|
|
|
|
});
|
|
|
|
if (nwritten < 0) {
|
|
|
|
// TODO: Do we need to abort the PATA read if this wasn't the last block?
|
|
|
|
complete_current_request(AsyncDeviceRequest::MemoryFault);
|
2019-05-19 03:56:06 +02:00
|
|
|
return false;
|
2020-11-02 11:16:01 -07:00
|
|
|
}
|
2019-05-19 03:46:50 +02:00
|
|
|
return true;
|
2018-11-10 15:15:31 +01:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::ata_read_sectors(bool slave_request)
|
2018-11-10 15:15:31 +01:00
|
|
|
{
|
2020-11-02 11:16:01 -07:00
|
|
|
auto& request = *m_current_request;
|
|
|
|
ASSERT(request.block_count() <= 256);
|
2019-07-28 23:44:01 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel::ata_read_sectors";
|
2019-05-26 14:58:21 +02:00
|
|
|
#endif
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
while (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY)
|
2020-11-04 21:25:26 +01:00
|
|
|
;
|
2020-11-02 11:16:01 -07:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
auto lba = request.block_index();
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: Reading " << request.block_count() << " sector(s) @ LBA " << lba;
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
u8 devsel = 0xe0;
|
|
|
|
if (slave_request)
|
|
|
|
devsel |= 0x10;
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.control_base().offset(ATA_CTL_CONTROL).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_HDDEVSEL).out<u8>(devsel | (static_cast<u8>(slave_request) << 4) | 0x40);
|
2019-09-04 11:10:07 +02:00
|
|
|
io_delay();
|
2019-05-26 14:58:21 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_FEATURES).out<u8>(0);
|
2019-05-26 14:58:21 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>(0);
|
2019-05-26 14:58:21 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(request.block_count());
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>((lba & 0x000000ff) >> 0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>((lba & 0x0000ff00) >> 8);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>((lba & 0x00ff0000) >> 16);
|
2019-05-26 14:58:21 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2020-12-19 12:50:57 +02:00
|
|
|
auto status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
|
2019-05-26 14:58:21 +02:00
|
|
|
if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
enable_irq();
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_READ_PIO);
|
2019-05-26 14:58:21 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::ata_write_sectors_with_dma(bool slave_request)
|
2018-11-18 14:57:41 +01:00
|
|
|
{
|
2020-11-02 11:16:01 -07:00
|
|
|
auto& request = *m_current_request;
|
|
|
|
u32 lba = request.block_index();
|
2019-07-28 23:44:01 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel::ata_write_sectors_with_dma (" << lba << " x" << request.block_count() << ")";
|
2019-07-28 23:44:01 +10:00
|
|
|
#endif
|
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
prdt().offset = m_dma_buffer_page->paddr();
|
|
|
|
prdt().size = 512 * request.block_count();
|
2019-07-28 23:44:01 +10:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
if (!request.read_from_buffer(request.buffer(), m_dma_buffer_page->paddr().offset(0xc0000000).as_ptr(), 512 * request.block_count())) {
|
|
|
|
complete_current_request(AsyncDeviceRequest::MemoryFault);
|
|
|
|
return;
|
|
|
|
}
|
2020-11-04 21:25:26 +01:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
ASSERT(prdt().size <= PAGE_SIZE);
|
|
|
|
|
|
|
|
// Stop bus master
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().out<u8>(0);
|
2020-11-02 11:16:01 -07:00
|
|
|
|
|
|
|
// Write the PRDT location
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().offset(4).out<u32>(m_prdt_page->paddr().get());
|
2020-11-02 11:16:01 -07:00
|
|
|
|
|
|
|
// Turn on "Interrupt" and "Error" flag. The error flag should be cleared by hardware.
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().offset(2).out<u8>(m_io_group.bus_master_base().offset(2).in<u8>() | 0x6);
|
2020-11-02 11:16:01 -07:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
while (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY)
|
2020-11-02 11:16:01 -07:00
|
|
|
;
|
2020-11-04 21:25:26 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.control_base().offset(ATA_CTL_CONTROL).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_HDDEVSEL).out<u8>(0x40 | (static_cast<u8>(slave_request) << 4));
|
2020-04-14 22:48:02 +03:00
|
|
|
io_delay();
|
2019-07-28 23:44:01 +10:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_FEATURES).out<u16>(0);
|
2019-07-28 23:44:01 +10:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>(0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>(0);
|
2019-07-28 23:44:01 +10:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(request.block_count());
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>((lba & 0x000000ff) >> 0);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>((lba & 0x0000ff00) >> 8);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>((lba & 0x00ff0000) >> 16);
|
2020-04-14 22:48:02 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2020-12-19 12:50:57 +02:00
|
|
|
auto status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
|
2020-04-14 22:48:02 +03:00
|
|
|
if (!(status & ATA_SR_BSY) && (status & ATA_SR_DRDY))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_WRITE_DMA_EXT);
|
2020-11-02 11:16:01 -07:00
|
|
|
io_delay();
|
2019-08-11 14:55:53 +10:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
enable_irq();
|
|
|
|
// Start bus master
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.bus_master_base().out<u8>(0x1);
|
2020-11-02 11:16:01 -07:00
|
|
|
}
|
2020-04-15 15:46:36 +03:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::ata_do_write_sector()
|
2020-11-02 11:16:01 -07:00
|
|
|
{
|
|
|
|
auto& request = *m_current_request;
|
2020-04-15 15:46:36 +03:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
io_delay();
|
2020-12-19 12:50:57 +02:00
|
|
|
while ((m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY) || !(m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_DRQ))
|
2020-11-02 11:16:01 -07:00
|
|
|
;
|
2020-11-04 21:25:26 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
u8 status = m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>();
|
2020-11-02 11:16:01 -07:00
|
|
|
ASSERT(status & ATA_SR_DRQ);
|
2020-11-04 21:25:26 +01:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
auto in_buffer = request.buffer().offset(m_current_request_block_index * 512);
|
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
dbg() << "IDEChannel: Writing 512 bytes (part " << m_current_request_block_index << ") (status=" << String::format("%b", status) << ")...";
|
2020-11-02 11:16:01 -07:00
|
|
|
#endif
|
|
|
|
ssize_t nread = request.read_from_buffer_buffered<512>(in_buffer, 512, [&](const u8* buffer, size_t buffer_bytes) {
|
|
|
|
for (size_t i = 0; i < buffer_bytes; i += sizeof(u16))
|
2020-12-19 12:50:57 +02:00
|
|
|
IO::out16(m_io_group.io_base().offset(ATA_REG_DATA).get(), *(const u16*)&buffer[i]);
|
2020-11-02 11:16:01 -07:00
|
|
|
return (ssize_t)buffer_bytes;
|
|
|
|
});
|
|
|
|
if (nread < 0)
|
|
|
|
complete_current_request(AsyncDeviceRequest::MemoryFault);
|
2019-07-28 23:44:01 +10:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
void IDEChannel::ata_write_sectors(bool slave_request)
|
2019-07-28 23:44:01 +10:00
|
|
|
{
|
2020-11-02 11:16:01 -07:00
|
|
|
auto& request = *m_current_request;
|
|
|
|
|
|
|
|
ASSERT(request.block_count() <= 256);
|
|
|
|
u32 start_sector = request.block_index();
|
|
|
|
u32 count = request.block_count();
|
2019-07-28 23:44:01 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel::ata_write_sectors request (" << count << " sector(s) @ " << start_sector << ")";
|
2019-01-22 16:34:24 +01:00
|
|
|
#endif
|
2018-11-18 14:57:41 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
while (m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY)
|
2019-06-07 11:43:58 +02:00
|
|
|
;
|
2018-11-18 14:57:41 +01:00
|
|
|
|
2019-08-11 14:58:21 +10:00
|
|
|
#ifdef PATA_DEBUG
|
2020-12-19 12:50:57 +02:00
|
|
|
klog() << "IDEChannel: Writing " << count << " sector(s) @ LBA " << start_sector;
|
2019-08-11 14:58:21 +10:00
|
|
|
#endif
|
2018-11-18 14:57:41 +01:00
|
|
|
|
2019-07-08 06:16:52 +00:00
|
|
|
u8 devsel = 0xe0;
|
2019-07-28 23:44:01 +10:00
|
|
|
if (slave_request)
|
2019-07-08 06:16:52 +00:00
|
|
|
devsel |= 0x10;
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out<u8>(count == 256 ? 0 : LSB(count));
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA0).out<u8>(start_sector & 0xff);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA1).out<u8>((start_sector >> 8) & 0xff);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_LBA2).out<u8>((start_sector >> 16) & 0xff);
|
|
|
|
m_io_group.io_base().offset(ATA_REG_HDDEVSEL).out<u8>(devsel | ((start_sector >> 24) & 0xf));
|
2018-11-18 14:57:41 +01:00
|
|
|
|
|
|
|
IO::out8(0x3F6, 0x08);
|
2020-12-19 12:50:57 +02:00
|
|
|
while (!(m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_DRDY))
|
2019-08-12 21:05:14 +10:00
|
|
|
;
|
2018-11-18 14:57:41 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
m_io_group.io_base().offset(ATA_REG_COMMAND).out<u8>(ATA_CMD_WRITE_PIO);
|
2018-11-18 14:57:41 +01:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
io_delay();
|
2020-12-19 12:50:57 +02:00
|
|
|
while ((m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_BSY) || !(m_io_group.io_base().offset(ATA_REG_STATUS).in<u8>() & ATA_SR_DRQ))
|
2020-11-02 11:16:01 -07:00
|
|
|
;
|
2020-11-04 21:25:26 +01:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
enable_irq();
|
|
|
|
ata_do_write_sector();
|
2018-11-18 14:57:41 +01:00
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|