mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Kernel: Remove hardcoded values for block size in IDEChannel
This commit is contained in:
parent
6d3a7fabeb
commit
e40d4b2677
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/Panky-codes Commit: https://github.com/SerenityOS/serenity/commit/e40d4b2677 Pull-request: https://github.com/SerenityOS/serenity/pull/13282 Reviewed-by: https://github.com/bgianfo ✅
2 changed files with 13 additions and 11 deletions
|
@ -378,8 +378,8 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks()
|
|||
}
|
||||
|
||||
// FIXME: Handle possible OOM situation here.
|
||||
ByteBuffer wbuf = ByteBuffer::create_uninitialized(512).release_value_but_fixme_should_propagate_errors();
|
||||
ByteBuffer bbuf = ByteBuffer::create_uninitialized(512).release_value_but_fixme_should_propagate_errors();
|
||||
ByteBuffer wbuf = ByteBuffer::create_uninitialized(m_logical_sector_size).release_value_but_fixme_should_propagate_errors();
|
||||
ByteBuffer bbuf = ByteBuffer::create_uninitialized(m_logical_sector_size).release_value_but_fixme_should_propagate_errors();
|
||||
u8* b = bbuf.data();
|
||||
u16* w = (u16*)wbuf.data();
|
||||
|
||||
|
@ -407,13 +407,12 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks()
|
|||
if (identify_block.commands_and_feature_sets_supported[1] & (1 << 10))
|
||||
max_addressable_block = identify_block.user_addressable_logical_sectors_count;
|
||||
|
||||
dbgln("IDEChannel: {} {} {} device found: Name={}, Capacity={}, Capabilities={:#04x}", channel_type_string(), channel_string(i), !command_set_is_atapi ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), max_addressable_block * 512, capabilities);
|
||||
// FIXME: Don't assume all drives will have logical sector size of 512 bytes.
|
||||
dbgln("IDEChannel: {} {} {} device found: Name={}, Capacity={}, Capabilities={:#04x}", channel_type_string(), channel_string(i), !command_set_is_atapi ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), max_addressable_block * m_logical_sector_size, capabilities);
|
||||
ATADevice::Address address = { m_channel_type == ChannelType::Primary ? static_cast<u8>(0) : static_cast<u8>(1), static_cast<u8>(i) };
|
||||
if (i == 0) {
|
||||
m_master = ATADiskDevice::create(m_parent_controller, address, capabilities, 512, max_addressable_block);
|
||||
m_master = ATADiskDevice::create(m_parent_controller, address, capabilities, m_logical_sector_size, max_addressable_block);
|
||||
} else {
|
||||
m_slave = ATADiskDevice::create(m_parent_controller, address, capabilities, 512, max_addressable_block);
|
||||
m_slave = ATADiskDevice::create(m_parent_controller, address, capabilities, m_logical_sector_size, max_addressable_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -478,8 +477,9 @@ bool IDEChannel::ata_do_read_sector()
|
|||
VERIFY(!m_current_request.is_null());
|
||||
dbgln_if(PATA_DEBUG, "IDEChannel::ata_do_read_sector");
|
||||
auto& request = *m_current_request;
|
||||
auto out_buffer = request.buffer().offset(m_current_request_block_index * 512);
|
||||
auto result = request.write_to_buffer_buffered<512>(out_buffer, 512, [&](Bytes bytes) {
|
||||
auto block_size = m_current_request->block_size();
|
||||
auto out_buffer = request.buffer().offset(m_current_request_block_index * block_size);
|
||||
auto result = request.write_to_buffer_buffered<m_logical_sector_size>(out_buffer, block_size, [&](Bytes bytes) {
|
||||
for (size_t i = 0; i < bytes.size(); i += sizeof(u16))
|
||||
*(u16*)bytes.offset_pointer(i) = IO::in16(m_io_group.io_base().offset(ATA_REG_DATA).get());
|
||||
return bytes.size();
|
||||
|
@ -519,9 +519,10 @@ void IDEChannel::ata_do_write_sector()
|
|||
u8 status = m_io_group.control_base().in<u8>();
|
||||
VERIFY(status & ATA_SR_DRQ);
|
||||
|
||||
auto in_buffer = request.buffer().offset(m_current_request_block_index * 512);
|
||||
dbgln_if(PATA_DEBUG, "IDEChannel: Writing 512 bytes (part {}) (status={:#02x})...", m_current_request_block_index, status);
|
||||
auto result = request.read_from_buffer_buffered<512>(in_buffer, 512, [&](ReadonlyBytes readonly_bytes) {
|
||||
auto block_size = m_current_request->block_size();
|
||||
auto in_buffer = request.buffer().offset(m_current_request_block_index * block_size);
|
||||
dbgln_if(PATA_DEBUG, "IDEChannel: Writing {} bytes (part {}) (status={:#02x})...", block_size, m_current_request_block_index, status);
|
||||
auto result = request.read_from_buffer_buffered<m_logical_sector_size>(in_buffer, block_size, [&](ReadonlyBytes readonly_bytes) {
|
||||
for (size_t i = 0; i < readonly_bytes.size(); i += sizeof(u16))
|
||||
IO::out16(m_io_group.io_base().offset(ATA_REG_DATA).get(), *(const u16*)readonly_bytes.offset(i));
|
||||
return readonly_bytes.size();
|
||||
|
|
|
@ -105,6 +105,7 @@ public:
|
|||
private:
|
||||
void complete_current_request(AsyncDeviceRequest::RequestResult);
|
||||
void initialize();
|
||||
static constexpr size_t m_logical_sector_size = 512;
|
||||
|
||||
protected:
|
||||
enum class LBAMode : u8 {
|
||||
|
|
Loading…
Reference in a new issue