From 999c57ef2dffb36e15c51aa99d4921122caad6ee Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Boric Date: Tue, 16 Mar 2021 20:31:45 +0100 Subject: [PATCH] Kernel: Refactor storage stack with u64 as block index --- Kernel/Devices/BlockDevice.cpp | 6 +++--- Kernel/Devices/BlockDevice.h | 10 +++++----- Kernel/Storage/IDEChannel.cpp | 12 ++++++------ Kernel/Storage/IDEChannel.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Kernel/Devices/BlockDevice.cpp b/Kernel/Devices/BlockDevice.cpp index 17e679e5a2d..15f35301938 100644 --- a/Kernel/Devices/BlockDevice.cpp +++ b/Kernel/Devices/BlockDevice.cpp @@ -28,7 +28,7 @@ namespace Kernel { -AsyncBlockDeviceRequest::AsyncBlockDeviceRequest(Device& block_device, RequestType request_type, u32 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size) +AsyncBlockDeviceRequest::AsyncBlockDeviceRequest(Device& block_device, RequestType request_type, u64 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size) : AsyncDeviceRequest(block_device) , m_block_device(static_cast(block_device)) , m_request_type(request_type) @@ -48,7 +48,7 @@ BlockDevice::~BlockDevice() { } -bool BlockDevice::read_block(unsigned index, UserOrKernelBuffer& buffer) +bool BlockDevice::read_block(u64 index, UserOrKernelBuffer& buffer) { auto read_request = make_request(AsyncBlockDeviceRequest::Read, index, 1, buffer, 512); switch (read_request->wait().request_result()) { @@ -69,7 +69,7 @@ bool BlockDevice::read_block(unsigned index, UserOrKernelBuffer& buffer) return false; } -bool BlockDevice::write_block(unsigned index, const UserOrKernelBuffer& buffer) +bool BlockDevice::write_block(u64 index, const UserOrKernelBuffer& buffer) { auto write_request = make_request(AsyncBlockDeviceRequest::Write, index, 1, buffer, 512); switch (write_request->wait().request_result()) { diff --git a/Kernel/Devices/BlockDevice.h b/Kernel/Devices/BlockDevice.h index e2f3d771f4c..0e786d24319 100644 --- a/Kernel/Devices/BlockDevice.h +++ b/Kernel/Devices/BlockDevice.h @@ -39,10 +39,10 @@ public: Write }; AsyncBlockDeviceRequest(Device& block_device, RequestType request_type, - u32 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size); + u64 block_index, u32 block_count, const UserOrKernelBuffer& buffer, size_t buffer_size); RequestType request_type() const { return m_request_type; } - u32 block_index() const { return m_block_index; } + u64 block_index() const { return m_block_index; } u32 block_count() const { return m_block_count; } UserOrKernelBuffer& buffer() { return m_buffer; } const UserOrKernelBuffer& buffer() const { return m_buffer; } @@ -64,7 +64,7 @@ public: private: BlockDevice& m_block_device; const RequestType m_request_type; - const u32 m_block_index; + const u64 m_block_index; const u32 m_block_count; UserOrKernelBuffer m_buffer; const size_t m_buffer_size; @@ -77,8 +77,8 @@ public: size_t block_size() const { return m_block_size; } virtual bool is_seekable() const override { return true; } - bool read_block(unsigned index, UserOrKernelBuffer&); - bool write_block(unsigned index, const UserOrKernelBuffer&); + bool read_block(u64 index, UserOrKernelBuffer&); + bool write_block(u64 index, const UserOrKernelBuffer&); virtual void start_request(AsyncBlockDeviceRequest&) = 0; diff --git a/Kernel/Storage/IDEChannel.cpp b/Kernel/Storage/IDEChannel.cpp index 837e5347a31..1b1213fa69c 100644 --- a/Kernel/Storage/IDEChannel.cpp +++ b/Kernel/Storage/IDEChannel.cpp @@ -401,7 +401,7 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks() } } -void IDEChannel::ata_access(Direction direction, bool slave_request, u32 lba, u8 block_count, u16 capabilities, bool use_dma) +void IDEChannel::ata_access(Direction direction, bool slave_request, u64 lba, u8 block_count, u16 capabilities, bool use_dma) { LBAMode lba_mode; u8 head = 0; @@ -432,8 +432,8 @@ void IDEChannel::ata_access(Direction direction, bool slave_request, u32 lba, u8 if (lba_mode == LBAMode::FortyEightBit) { m_io_group.io_base().offset(ATA_REG_SECCOUNT1).out(0); m_io_group.io_base().offset(ATA_REG_LBA3).out((lba & 0xFF000000) >> 24); - m_io_group.io_base().offset(ATA_REG_LBA4).out(0); - m_io_group.io_base().offset(ATA_REG_LBA5).out(0); + m_io_group.io_base().offset(ATA_REG_LBA4).out((lba & 0xFF00000000ull) >> 32); + m_io_group.io_base().offset(ATA_REG_LBA5).out((lba & 0xFF0000000000ull) >> 40); } m_io_group.io_base().offset(ATA_REG_SECCOUNT0).out(block_count); @@ -470,7 +470,7 @@ void IDEChannel::ata_access(Direction direction, bool slave_request, u32 lba, u8 void IDEChannel::ata_read_sectors_with_dma(bool slave_request, u16 capabilities) { auto& request = *m_current_request; - u32 lba = request.block_index(); + auto lba = request.block_index(); dbgln_if(PATA_DEBUG, "IDEChannel::ata_read_sectors_with_dma ({} x {})", lba, request.block_count()); prdt().offset = m_dma_buffer_page->paddr(); @@ -530,7 +530,7 @@ void IDEChannel::ata_read_sectors(bool slave_request, u16 capabilities) void IDEChannel::ata_write_sectors_with_dma(bool slave_request, u16 capabilities) { auto& request = *m_current_request; - u32 lba = request.block_index(); + auto lba = request.block_index(); dbgln_if(PATA_DEBUG, "IDEChannel::ata_write_sectors_with_dma ({} x {})", lba, request.block_count()); prdt().offset = m_dma_buffer_page->paddr(); @@ -586,7 +586,7 @@ void IDEChannel::ata_write_sectors(bool slave_request, u16 capabilities) auto& request = *m_current_request; VERIFY(request.block_count() <= 256); - u32 start_sector = request.block_index(); + auto start_sector = request.block_index(); u32 count = request.block_count(); dbgln_if(PATA_DEBUG, "IDEChannel: Writing {} sector(s) @ LBA {}", count, start_sector); diff --git a/Kernel/Storage/IDEChannel.h b/Kernel/Storage/IDEChannel.h index 1380ca364ef..e48c7fd68cb 100644 --- a/Kernel/Storage/IDEChannel.h +++ b/Kernel/Storage/IDEChannel.h @@ -140,7 +140,7 @@ private: void clear_pending_interrupts() const; - void ata_access(Direction, bool, u32, u8, u16, bool); + void ata_access(Direction, bool, u64, u8, u16, bool); void ata_read_sectors_with_dma(bool, u16); void ata_read_sectors(bool, u16); bool ata_do_read_sector();