Kernel: Export both interface type and command set of a StorageDevice

This commit is contained in:
Liav A 2022-04-22 16:15:41 +03:00 committed by Andreas Kling
parent 6ff1aeb64d
commit 7db6b77e75
Notes: sideshowbarker 2024-07-17 08:56:28 +09:00
6 changed files with 54 additions and 0 deletions

View file

@ -26,6 +26,7 @@ public:
virtual CommandSet command_set() const override { return CommandSet::ATA; } virtual CommandSet command_set() const override { return CommandSet::ATA; }
private: private:
virtual InterfaceType interface_type() const override { return InterfaceType::ATA; }
ATADiskDevice(ATAController const&, Address, MinorNumber, u16, u16, u64, NonnullOwnPtr<KString>); ATADiskDevice(ATAController const&, Address, MinorNumber, u16, u16, u64, NonnullOwnPtr<KString>);
// ^DiskDevice // ^DiskDevice

View file

@ -26,6 +26,7 @@ public:
virtual CommandSet command_set() const override { return CommandSet::SCSI; } virtual CommandSet command_set() const override { return CommandSet::SCSI; }
private: private:
virtual InterfaceType interface_type() const override { return InterfaceType::ATA; }
ATAPIDiscDevice(ATAController const&, Address, MinorNumber, u16, u64, NonnullOwnPtr<KString>); ATAPIDiscDevice(ATAController const&, Address, MinorNumber, u16, u64, NonnullOwnPtr<KString>);
// ^DiskDevice // ^DiskDevice

View file

@ -29,6 +29,7 @@ public:
void start_request(AsyncBlockDeviceRequest& request) override; void start_request(AsyncBlockDeviceRequest& request) override;
private: private:
virtual InterfaceType interface_type() const override { return InterfaceType::NVMe; }
u16 m_nsid; u16 m_nsid;
NonnullRefPtrVector<NVMeQueue> m_queues; NonnullRefPtrVector<NVMeQueue> m_queues;
}; };

View file

@ -32,6 +32,7 @@ private:
// ^StorageDevice // ^StorageDevice
virtual CommandSet command_set() const override { return CommandSet::PlainMemory; } virtual CommandSet command_set() const override { return CommandSet::PlainMemory; }
virtual InterfaceType interface_type() const override { return InterfaceType::PlainMemory; }
Mutex m_lock { "RamdiskDevice"sv }; Mutex m_lock { "RamdiskDevice"sv };

View file

@ -27,6 +27,40 @@ StringView StorageDevice::class_name() const
return "StorageDevice"sv; return "StorageDevice"sv;
} }
StringView StorageDevice::command_set_to_string_view() const
{
switch (command_set()) {
case CommandSet::PlainMemory:
return "memory"sv;
case CommandSet::SCSI:
return "scsi"sv;
case CommandSet::ATA:
return "ata"sv;
case CommandSet::NVMe:
return "nvme"sv;
default:
break;
}
VERIFY_NOT_REACHED();
}
StringView StorageDevice::interface_type_to_string_view() const
{
switch (interface_type()) {
case InterfaceType::PlainMemory:
return "memory"sv;
case InterfaceType::SCSI:
return "scsi"sv;
case InterfaceType::ATA:
return "ata"sv;
case InterfaceType::NVMe:
return "nvme"sv;
default:
break;
}
VERIFY_NOT_REACHED();
}
ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKernelBuffer& outbuf, size_t len) ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKernelBuffer& outbuf, size_t len)
{ {
u64 index = offset >> block_size_log(); u64 index = offset >> block_size_log();

View file

@ -33,6 +33,18 @@ public:
NVMe, NVMe,
}; };
// Note: this attribute describes the interface type of a Storage device.
// For example, an ordinary harddrive utilizes the ATA command set, while
// an ATAPI device (e.g. Optical drive) that is connected to the ATA bus,
// is actually using SCSI commands (packets) encapsulated inside an ATA command.
// Therefore, an ATAPI device is still using the ATA interface.
enum class InterfaceType {
PlainMemory,
SCSI,
ATA,
NVMe,
};
public: public:
virtual u64 max_addressable_block() const { return m_max_addressable_block; } virtual u64 max_addressable_block() const { return m_max_addressable_block; }
@ -52,6 +64,9 @@ public:
virtual CommandSet command_set() const = 0; virtual CommandSet command_set() const = 0;
StringView interface_type_to_string_view() const;
StringView command_set_to_string_view() const;
// ^File // ^File
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) final; virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) final;
@ -61,6 +76,7 @@ protected:
virtual StringView class_name() const override; virtual StringView class_name() const override;
private: private:
virtual InterfaceType interface_type() const = 0;
mutable IntrusiveListNode<StorageDevice, RefPtr<StorageDevice>> m_list_node; mutable IntrusiveListNode<StorageDevice, RefPtr<StorageDevice>> m_list_node;
NonnullRefPtrVector<DiskPartition> m_partitions; NonnullRefPtrVector<DiskPartition> m_partitions;