-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
Kernel/Devices/PATADiskDevice.h
Outdated
RefPtr<PhysicalPage> m_dma_buffer_page; | ||
u16 m_bus_master_base { 0 }; | ||
Lockable<bool> m_dma_enabled; | ||
PATAChannel& m_ptr_channel; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Lockable<bool> m_dma_enabled; | ||
|
||
|
||
RefPtr<PATADiskDevice> m_hd0; |
There was a problem hiding this comment.
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, withtype()
eitherPrimary
orSecondary
. - Each
PATAChannel
object should in turn have twoPATADiskDevice
objects,master()
andslave()
.
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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.
Kernel/Devices/PATADiskDevice.h
Outdated
RefPtr<PhysicalPage> m_dma_buffer_page; | ||
u16 m_bus_master_base { 0 }; | ||
Lockable<bool> m_dma_enabled; | ||
PATAChannel& m_ptr_channel; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Kernel/Devices/PATAChannel.cpp
Outdated
|
||
//#define DISK_DEBUG | ||
#define PATA_MASTER_IRQ 14 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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??
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.
…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.
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 aPATAChannel
, whichmakes 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.