kernel/ATA: Stop storing ATA::Drive in a separate shared pointer
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bc20e1a31b
commit
f45734c61d
@ -161,7 +161,7 @@ namespace ATA
|
|||||||
{
|
{
|
||||||
if (!(read_bm(BusmasterRegister::Status) & BMS_IRQPending)) return;
|
if (!(read_bm(BusmasterRegister::Status) & BMS_IRQPending)) return;
|
||||||
|
|
||||||
if (m_current_drive < 2 && m_drives[m_current_drive]) m_drives[m_current_drive]->irq_handler();
|
if (m_current_drive < 2 && m_drives[m_current_drive].has_value()) m_drives[m_current_drive]->irq_handler();
|
||||||
|
|
||||||
m_irq_called = true;
|
m_irq_called = true;
|
||||||
|
|
||||||
@ -307,14 +307,7 @@ namespace ATA
|
|||||||
|
|
||||||
kinfoln("ata: Channel %d has a drive on slot %d!", m_channel_index, drive);
|
kinfoln("ata: Channel %d has a drive on slot %d!", m_channel_index, drive);
|
||||||
|
|
||||||
auto rc = adopt_shared_if_nonnull(new (std::nothrow) Drive(this, drive, {}));
|
m_drives[drive] = Drive { this, drive, {} };
|
||||||
if (rc.has_error())
|
|
||||||
{
|
|
||||||
kinfoln("ata: Failed to create drive object: %s", rc.error_string());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_drives[drive] = rc.release_value();
|
|
||||||
|
|
||||||
if (!m_drives[drive]->initialize())
|
if (!m_drives[drive]->initialize())
|
||||||
{
|
{
|
||||||
@ -327,7 +320,7 @@ namespace ATA
|
|||||||
|
|
||||||
for (u8 drive = 0; drive < 2; drive++)
|
for (u8 drive = 0; drive < 2; drive++)
|
||||||
{
|
{
|
||||||
if (m_drives[drive])
|
if (m_drives[drive].has_value())
|
||||||
{
|
{
|
||||||
if (!m_drives[drive]->post_initialize())
|
if (!m_drives[drive]->post_initialize())
|
||||||
{
|
{
|
||||||
@ -335,7 +328,7 @@ namespace ATA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rc = ATADevice::create(m_drives[drive]);
|
auto rc = ATADevice::create(m_drives[drive].value_ptr());
|
||||||
|
|
||||||
if (rc.has_error())
|
if (rc.has_error())
|
||||||
{
|
{
|
||||||
@ -723,7 +716,7 @@ namespace ATA
|
|||||||
|
|
||||||
static u32 next_minor = 0;
|
static u32 next_minor = 0;
|
||||||
|
|
||||||
Result<String> ATA::Drive::create_drive_name(SharedPtr<ATA::Drive> drive)
|
Result<String> ATA::Drive::create_drive_name(ATA::Drive* drive)
|
||||||
{
|
{
|
||||||
static u32 cd_index = 0;
|
static u32 cd_index = 0;
|
||||||
static u32 sd_index = 0;
|
static u32 sd_index = 0;
|
||||||
@ -731,7 +724,7 @@ Result<String> ATA::Drive::create_drive_name(SharedPtr<ATA::Drive> drive)
|
|||||||
return String::format("%s%d"_sv, drive->m_is_atapi ? "cd" : "sd", drive->m_is_atapi ? cd_index++ : sd_index++);
|
return String::format("%s%d"_sv, drive->m_is_atapi ? "cd" : "sd", drive->m_is_atapi ? cd_index++ : sd_index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<SharedPtr<Device>> ATADevice::create(SharedPtr<ATA::Drive> drive)
|
Result<SharedPtr<Device>> ATADevice::create(ATA::Drive* drive)
|
||||||
{
|
{
|
||||||
auto device = TRY(adopt_shared_if_nonnull(new (std::nothrow) ATADevice()));
|
auto device = TRY(adopt_shared_if_nonnull(new (std::nothrow) ATADevice()));
|
||||||
device->m_drive = drive;
|
device->m_drive = drive;
|
||||||
|
@ -131,7 +131,7 @@ namespace ATA
|
|||||||
|
|
||||||
static constexpr u16 END_OF_PRDT = (1 << 15);
|
static constexpr u16 END_OF_PRDT = (1 << 15);
|
||||||
|
|
||||||
class Drive : public Shareable
|
class Drive
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Drive(Channel* channel, u8 drive_index, Badge<Channel>);
|
Drive(Channel* channel, u8 drive_index, Badge<Channel>);
|
||||||
@ -164,7 +164,7 @@ namespace ATA
|
|||||||
|
|
||||||
Result<void> read_lba(u64 lba, void* out, usize nblocks);
|
Result<void> read_lba(u64 lba, void* out, usize nblocks);
|
||||||
|
|
||||||
static Result<String> create_drive_name(SharedPtr<ATA::Drive> drive);
|
static Result<String> create_drive_name(ATA::Drive* drive);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool identify_ata();
|
bool identify_ata();
|
||||||
@ -271,7 +271,7 @@ namespace ATA
|
|||||||
|
|
||||||
u8 m_current_drive = (u8)-1;
|
u8 m_current_drive = (u8)-1;
|
||||||
|
|
||||||
SharedPtr<Drive> m_drives[2];
|
Option<Drive> m_drives[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
class Controller : public Shareable
|
class Controller : public Shareable
|
||||||
@ -301,7 +301,7 @@ class ATADevice : public Device
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Initializer for DeviceRegistry.
|
// Initializer for DeviceRegistry.
|
||||||
static Result<SharedPtr<Device>> create(SharedPtr<ATA::Drive> drive);
|
static Result<SharedPtr<Device>> create(ATA::Drive* drive);
|
||||||
|
|
||||||
Result<usize> read(u8*, usize, usize) const override;
|
Result<usize> read(u8*, usize, usize) const override;
|
||||||
|
|
||||||
@ -339,6 +339,6 @@ class ATADevice : public Device
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ATADevice() = default;
|
ATADevice() = default;
|
||||||
SharedPtr<ATA::Drive> m_drive;
|
ATA::Drive* m_drive;
|
||||||
String m_device_path;
|
String m_device_path;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user