Kernel: Move SCSI device rdev allocation out of ATA code
This commit is contained in:
parent
31d2a39540
commit
8bf14d542e
|
@ -89,6 +89,7 @@ set(KERNEL_SOURCES
|
|||
kernel/Storage/NVMe/Namespace.cpp
|
||||
kernel/Storage/NVMe/Queue.cpp
|
||||
kernel/Storage/Partition.cpp
|
||||
kernel/Storage/SCSI.cpp
|
||||
kernel/Storage/StorageDevice.cpp
|
||||
kernel/Syscall.cpp
|
||||
kernel/Terminal/FramebufferTerminal.cpp
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Kernel
|
|||
};
|
||||
|
||||
public:
|
||||
virtual ~ATABaseDevice() {};
|
||||
virtual ~ATABaseDevice();
|
||||
|
||||
virtual uint32_t sector_size() const override { return m_sector_words * 2; }
|
||||
virtual uint64_t total_size() const override { return m_lba_count * sector_size(); }
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
dev_t scsi_get_rdev();
|
||||
void scsi_free_rdev(dev_t);
|
||||
|
||||
}
|
|
@ -4,25 +4,25 @@
|
|||
#include <kernel/Storage/ATA/ATABus.h>
|
||||
#include <kernel/Storage/ATA/ATADefinitions.h>
|
||||
#include <kernel/Storage/ATA/ATADevice.h>
|
||||
#include <kernel/Storage/SCSI.h>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
static dev_t get_ata_dev_minor()
|
||||
{
|
||||
static dev_t minor = 0;
|
||||
return minor++;
|
||||
}
|
||||
|
||||
detail::ATABaseDevice::ATABaseDevice()
|
||||
: m_rdev(makedev(DeviceNumber::SCSI, get_ata_dev_minor()))
|
||||
: m_rdev(scsi_get_rdev())
|
||||
{
|
||||
strcpy(m_name, "sda");
|
||||
m_name[2] += minor(m_rdev);
|
||||
}
|
||||
|
||||
detail::ATABaseDevice::~ATABaseDevice()
|
||||
{
|
||||
scsi_free_rdev(m_rdev);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> detail::ATABaseDevice::initialize(BAN::Span<const uint16_t> identify_data)
|
||||
{
|
||||
ASSERT(identify_data.size() >= 256);
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#include <kernel/Device/DeviceNumbers.h>
|
||||
#include <kernel/Lock/SpinLock.h>
|
||||
#include <kernel/Storage/SCSI.h>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
static uint64_t s_scsi_bitmap { 0 };
|
||||
static SpinLock s_scsi_spinlock;
|
||||
|
||||
static constexpr size_t s_scsi_bitmap_bits = sizeof(s_scsi_bitmap) * 8;
|
||||
|
||||
dev_t scsi_get_rdev()
|
||||
{
|
||||
SpinLockGuard _(s_scsi_spinlock);
|
||||
|
||||
uint64_t mask = 1;
|
||||
for (uint8_t minor = 0; minor < s_scsi_bitmap_bits; minor++, mask <<= 1)
|
||||
{
|
||||
if (s_scsi_bitmap & mask)
|
||||
continue;
|
||||
s_scsi_bitmap |= mask;
|
||||
|
||||
return makedev(DeviceNumber::SCSI, minor);
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void scsi_free_rdev(dev_t rdev)
|
||||
{
|
||||
ASSERT(major(rdev) == static_cast<dev_t>(DeviceNumber::SCSI));
|
||||
|
||||
SpinLockGuard _(s_scsi_spinlock);
|
||||
|
||||
const uint64_t mask = static_cast<uint64_t>(1) << minor(rdev);
|
||||
ASSERT(s_scsi_bitmap & mask);
|
||||
|
||||
s_scsi_bitmap &= ~mask;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue