Kernel: Refactor storage stack with u64 as number of blocks

This commit is contained in:
Jean-Baptiste Boric 2021-03-16 20:23:16 +01:00 committed by Andreas Kling
parent aeef14ae28
commit 9a3aa7eb0b
Notes: sideshowbarker 2024-07-18 21:16:07 +09:00
10 changed files with 26 additions and 38 deletions

View file

@ -243,7 +243,7 @@ bool AHCIPort::initialize()
size_t logical_sector_size = 512;
size_t physical_sector_size = 512;
size_t max_addressable_sector = 0;
u64 max_addressable_sector = 0;
if (identify_device()) {
auto identify_block = map_typed<ATAIdentifyBlock>(m_parent_handler->get_identify_metadata_physical_region(m_port_index));
// Check if word 106 is valid before using it!
@ -266,7 +266,7 @@ bool AHCIPort::initialize()
m_port_registers.cmd = m_port_registers.cmd | (1 << 24);
}
dmesgln("AHCI Port {}: max lba {:x}, L/P sector size - {}/{} ", representative_port_index(), max_addressable_sector, logical_sector_size, physical_sector_size);
dmesgln("AHCI Port {}: Device found, Capacity={}, Bytes per logical sector={}, Bytes per physical sector={}", representative_port_index(), max_addressable_sector * logical_sector_size, logical_sector_size, physical_sector_size);
// FIXME: We don't support ATAPI devices yet, so for now we don't "create" them
if (!is_atapi_attached()) {

View file

@ -388,12 +388,15 @@ UNMAP_AFTER_INIT void IDEChannel::detect_disks()
u16 capabilities = wbufbase[ATA_IDENT_CAPABILITIES / sizeof(u16)];
if (cyls == 0 || heads == 0 || spt == 0)
continue;
dbgln("IDEChannel: {} {} device found: Type={}, Name={}, C/H/Spt={}/{}/{}, Capabilities=0x{:04x}", channel_type_string(), channel_string(i), interface_type == PATADiskDevice::InterfaceType::ATA ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), cyls, heads, spt, capabilities);
u64 max_addressable_block = cyls * heads * spt;
if (capabilities & ATA_CAP_LBA)
max_addressable_block = (wbufbase[(ATA_IDENT_MAX_LBA + 2) / sizeof(u16)] << 16) | wbufbase[ATA_IDENT_MAX_LBA / sizeof(u16)];
dbgln("IDEChannel: {} {} {} device found: Name={}, Capacity={}, C/H/Spt={}/{}/{}, Capabilities=0x{:04x}", channel_type_string(), channel_string(i), interface_type == PATADiskDevice::InterfaceType::ATA ? "ATA" : "ATAPI", ((char*)bbuf.data() + 54), max_addressable_block * 512, cyls, heads, spt, capabilities);
if (i == 0) {
m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, interface_type, cyls, heads, spt, capabilities);
m_master = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Master, interface_type, capabilities, max_addressable_block);
} else {
m_slave = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Slave, interface_type, cyls, heads, spt, capabilities);
m_slave = PATADiskDevice::create(m_parent_controller, *this, PATADiskDevice::DriveType::Slave, interface_type, capabilities, max_addressable_block);
}
}
}

View file

@ -33,16 +33,13 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities)
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
{
return adopt(*new PATADiskDevice(controller, channel, type, interface_type, cylinders, heads, spt, capabilities));
return adopt(*new PATADiskDevice(controller, channel, type, interface_type, capabilities, max_addressable_block));
}
UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities)
: StorageDevice(controller, 512, 0)
, m_cylinders(cylinders)
, m_heads(heads)
, m_sectors_per_track(spt)
UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
: StorageDevice(controller, 512, max_addressable_block)
, m_capabilities(capabilities)
, m_channel(channel)
, m_drive_type(type)
@ -70,11 +67,6 @@ String PATADiskDevice::device_name() const
return String::formatted("hd{:c}", 'a' + minor());
}
size_t PATADiskDevice::max_addressable_block() const
{
return m_cylinders * m_heads * m_sectors_per_track;
}
bool PATADiskDevice::is_slave() const
{
return m_drive_type == DriveType::Slave;

View file

@ -57,19 +57,18 @@ public:
};
public:
static NonnullRefPtr<PATADiskDevice> create(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16);
static NonnullRefPtr<PATADiskDevice> create(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
virtual ~PATADiskDevice() override;
// ^StorageDevice
virtual Type type() const override { return StorageDevice::Type::IDE; }
virtual size_t max_addressable_block() const override;
// ^BlockDevice
virtual void start_request(AsyncBlockDeviceRequest&) override;
virtual String device_name() const override;
private:
PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u16, u16, u16);
PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
// ^DiskDevice
virtual const char* class_name() const override;

View file

@ -38,10 +38,10 @@ NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& cont
}
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, OwnPtr<Region>&& region, int major, int minor)
: StorageDevice(controller, major, minor, 512, 0)
: StorageDevice(controller, major, minor, 512, m_region->size() / 512)
, m_region(move(region))
{
dmesgln("Ramdisk: Device #{} @ {}, length {}", minor, m_region->vaddr(), m_region->size());
dmesgln("Ramdisk: Device #{} @ {}, Capacity={}", minor, m_region->vaddr(), max_addressable_block() * 512);
}
RamdiskDevice::~RamdiskDevice()
@ -53,11 +53,6 @@ const char* RamdiskDevice::class_name() const
return "RamdiskDevice";
}
size_t RamdiskDevice::max_addressable_block() const
{
return m_region->size() / 512;
}
void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request)
{
LOCKER(m_lock);

View file

@ -43,7 +43,6 @@ public:
// ^StorageDevice
virtual Type type() const override { return StorageDevice::Type::Ramdisk; }
virtual size_t max_addressable_block() const override;
// ^BlockDevice
virtual void start_request(AsyncBlockDeviceRequest&) override;

View file

@ -33,12 +33,12 @@
namespace Kernel {
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, size_t max_addressable_block)
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
{
return adopt(*new SATADiskDevice(controller, port, sector_size, max_addressable_block));
}
SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, size_t max_addressable_block)
SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
: StorageDevice(controller, sector_size, max_addressable_block)
, m_port(port)
{

View file

@ -44,7 +44,7 @@ public:
};
public:
static NonnullRefPtr<SATADiskDevice> create(const AHCIController&, const AHCIPort&, size_t sector_size, size_t max_addressable_block);
static NonnullRefPtr<SATADiskDevice> create(const AHCIController&, const AHCIPort&, size_t sector_size, u64 max_addressable_block);
virtual ~SATADiskDevice() override;
// ^StorageDevice
@ -54,7 +54,7 @@ public:
virtual String device_name() const override;
private:
SATADiskDevice(const AHCIController&, const AHCIPort&, size_t sector_size, size_t max_addressable_block);
SATADiskDevice(const AHCIController&, const AHCIPort&, size_t sector_size, u64 max_addressable_block);
// ^DiskDevice
virtual const char* class_name() const override;

View file

@ -33,14 +33,14 @@
namespace Kernel {
StorageDevice::StorageDevice(const StorageController& controller, size_t sector_size, size_t max_addressable_block)
StorageDevice::StorageDevice(const StorageController& controller, size_t sector_size, u64 max_addressable_block)
: BlockDevice(StorageManagement::major_number(), StorageManagement::minor_number(), sector_size)
, m_storage_controller(controller)
, m_max_addressable_block(max_addressable_block)
{
}
StorageDevice::StorageDevice(const StorageController& controller, int major, int minor, size_t sector_size, size_t max_addressable_block)
StorageDevice::StorageDevice(const StorageController& controller, int major, int minor, size_t sector_size, u64 max_addressable_block)
: BlockDevice(major, minor, sector_size)
, m_storage_controller(controller)
, m_max_addressable_block(max_addressable_block)

View file

@ -47,7 +47,7 @@ public:
public:
virtual Type type() const = 0;
virtual size_t max_addressable_block() const { return m_max_addressable_block; }
virtual u64 max_addressable_block() const { return m_max_addressable_block; }
NonnullRefPtr<StorageController> controller() const;
@ -61,15 +61,15 @@ public:
virtual mode_t required_mode() const override { return 0600; }
protected:
StorageDevice(const StorageController&, size_t, size_t);
StorageDevice(const StorageController&, int, int, size_t, size_t);
StorageDevice(const StorageController&, size_t, u64);
StorageDevice(const StorageController&, int, int, size_t, u64);
// ^DiskDevice
virtual const char* class_name() const override;
private:
NonnullRefPtr<StorageController> m_storage_controller;
NonnullRefPtrVector<DiskPartition> m_partitions;
size_t m_max_addressable_block;
u64 m_max_addressable_block;
};
}