Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATA Driver supports multiple drives #365

Merged
merged 1 commit into from
Jul 28, 2019

Conversation

Quaker762
Copy link
Member

@Quaker762 Quaker762 commented Jul 26, 2019

The previous implementation of the PIIX3/4 PATA/IDE channel driver
only supported a single drive, as the object model was wrong (the channel
inherits the IRQ, not the disk drive itself). This fixes
it by 'attaching' two PATADiskDevices to a PATAChannel, which
makes more sense.

The reading/writing code is presented as is, which (somewhat) violates the
spec outlined by Seagate in the linked datasheet. That spec
is rather old, so it might not be 100% up to date, though may cause
issues on real hardware, so until we can actually test it, this will
suffice.

RefPtr<PhysicalPage> m_dma_buffer_page;
u16 m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled;
PATAChannel& m_ptr_channel;
Copy link
Member Author

@Quaker762 Quaker762 Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awesomekling I'm not too sure if this is okay. I was struggling a bit with some of the smart pointers inAK so I felt it was best to just use a normal reference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct.
A PATADiskDevice object is always owned by a PATAChannel object, and so we know that the PATAChannel will always exist as long as the PATADiskDevice does.
When we know that something is guaranteed to exist, and we're not responsible for keeping it alive, a plain reference is the most appropriate. :)
I'd suggest dropping ptr from the name though, since it's not a pointer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh good, I wasn't 100% sure but I assumed as much because the disk exists as long as it's actually connected to the channel.

I'll change the name now :)

Kernel/Devices/PATAChannel.h Outdated Show resolved Hide resolved
Lockable<bool> m_dma_enabled;


RefPtr<PATADiskDevice> m_hd0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we call these m_master and m_slave respectively?

And what do you think about this general object model description:

  • There should be two PATAChannel objects, with type() either Primary or Secondary.
  • Each PATAChannel object should in turn have two PATADiskDevice objects, master() and slave().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds about right. Would I have them as static members inside the class, or would they just be instantiated somewhere??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PATADiskDevice objects should be non-static members of PATAChannel, since they logically belong to the channel.

RefPtr<PhysicalPage> m_dma_buffer_page;
u16 m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled;
PATAChannel& m_ptr_channel;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct.
A PATADiskDevice object is always owned by a PATAChannel object, and so we know that the PATAChannel will always exist as long as the PATADiskDevice does.
When we know that something is guaranteed to exist, and we're not responsible for keeping it alive, a plain reference is the most appropriate. :)
I'd suggest dropping ptr from the name though, since it's not a pointer.

Copy link
Collaborator

@awesomekling awesomekling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please conform to the project coding style, you can use clang-format (version 8) or newer to auto-format the whitespace, braces etc.


//#define DISK_DEBUG
#define PATA_MASTER_IRQ 14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PATA_PRIMARY_IRQ and PATA_SECONDARY_IRQ, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops

Kernel/init.cpp Outdated
@@ -68,9 +69,10 @@ VFS* vfs;
hang();
}

auto dev_hd0 = IDEDiskDevice::create(IDEDiskDevice::DriveType::MASTER);
auto pata0 = PATAChannel::create(PATAChannel::ChannelType::Primary);
//auto dev_hd0 = IDEDiskDevice::create(*pata0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just delete this. Let's not leave commented-out code around. If something is worth keeping for debugging, we can put it behind an #ifdef FOO_DEBUG

volatile bool m_interrupted { false };

Lock m_lock { "PATAChannel" };
PCI::Address m_pci_address;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so both channels will find the same PCI address here.
What do we need to do to ensure that using both disks at the same time doesn't cause problems?

Copy link
Member Author

@Quaker762 Quaker762 Jul 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a static global lock so only one disk can access at any one time? I think the controller itself can handle multiple channel requests without issues, but I'd have to test it/re-read the PIIX spec a bit.

Also I'm not too familiar with the PCI spec/code. What's the side effects of them having the same address??

@Quaker762
Copy link
Member Author

Please conform to the project coding style, you can use clang-format (version 8) or newer to auto-format the whitespace, braces etc.

Hmmm woops, I thought I ran this... I must've forgotten again....

The previous implementation of the PIIX3/4 PATA/IDE channel driver
only supported a single drive, as the object model was wrong (the channel
inherits the IRQ, not the disk drive itself). This fixes
it by 'attaching' two `PATADiskDevices` to a `PATAChannel`, which
makes more sense.

The reading/writing code is presented as is, which violates the
spec outlined by Seagate in the linked datasheet. That spec
is rather old, so it might not be 100% up to date, though may cause
issues on real hardware, so until we can actually test it, this will
suffice.
@awesomekling awesomekling merged commit 59e122f into SerenityOS:master Jul 28, 2019
RyanGrieb pushed a commit to RyanGrieb/serenity that referenced this pull request Jul 28, 2019
…S#365)

The previous implementation of the PIIX3/4 PATA/IDE channel driver only
supported a single drive, as the object model was wrong (the channel
inherits the IRQ, not the disk drive itself). This fixes it by 'attaching'
two `PATADiskDevices` to a `PATAChannel`, which makes more sense.

The reading/writing code is presented as is, which violates the spec
outlined by Seagate in the linked datasheet. That spec is rather old,
so it might not be 100% up to date, though may cause issues on real
hardware, so until we can actually test it, this will suffice.
@Quaker762 Quaker762 deleted the ata_channel branch November 3, 2019 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants