Confusion regarding hard drives, PCI, IDE, SATA etc.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kalia247
Posts: 2
Joined: Sun Sep 07, 2014 4:21 am

Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by kalia247 »

I have been reading about hard drives for 3 days now. What my understanding of it is that there 2 kinds of hard drives in the world: (P)ATA and SATA.

These devices can then be attached to both IDE controller as well as AHCI controller. The IDE controller is an old one with primary/secondary, master/slave devices. It has been around for a long time. AHCI is a new controller specified by Intel and its sole purpose is to create interface between system and SATA device. All such controllers are ultimately connected to PCI bus.

Thus:

PCI -> IDE -> ATA/ATAPI devices
PCI -> AHCI -> SATA devices

All such devices work in polling (PIO) as well as DMA mode.

Now I could be horribly wrong about my concepts, but when I go on to enumerate all the devices on my PCI bus in Virtualbox machine, I cannot for the life of me find any IDE controller. I know it is there because virtual machine's settings say IDE controller exists and also has a CD/DVD drive (my .iso file) as well as another empty virtual hard drive connected. Every forum on earth about IDE starts with a BAR#4 address to reach its registers. But I cannot enumerate my IDE controller at all!

I cannot find another person on internet who seems to have my problem therefore I am quite sure I am horribly wrong somewhere but I don't know where. It would be a kind gesture to help this flailing man!

Can it be buggy function
In which case I'll post it here;
Or is it misconception
Of the parts I can't test bare.
Hey lady or gentleman,
Would you help this flailing man?
Point me in a direction
Where work and read more I can.

:)
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by SpyderTL »

When I run into an issue like this, I usually stop and do a "sanity check", and load up, say, Arch Linux in the exact same virtual machine, and run a "lspci" command and see if your IDE device shows up there. If so, the bug is in your PCI enumeration code. If not, the problem is in VirtualBox.

Although rare, I have seen VirtualBox act strange until I deleted the Virtual Machine, and recreated it.

Let us know if this helps.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by FallenAvatar »

Are you checking for, and properly handling (and enumerating the children of) PCI-PCI Bridges?

- Monk
kalia247
Posts: 2
Joined: Sun Sep 07, 2014 4:21 am

Re: Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by kalia247 »

When I run into an issue like this, I usually stop and do a "sanity check", and load up, say, Arch Linux in the exact same virtual machine, and run a "lspci" command and see if your IDE device shows up there.
Thanks for this piece of information. I am very new to hardware level programming so I have very less reason to put blame on VirtualBox. If everything else fails, I'll try this one. Thanks for introducing me to Arch Linux though (downloading it as we speak)!
Are you checking for, and properly handling (and enumerating the children of) PCI-PCI Bridges?
No, I am not. In fact, I am actively ignoring existence of such bridges. All I do is iterate through all 256 buses of PCI and go through all the 32 devices on each bus (8192 in total) and see whether a device exists there or not.

Is it wrong? The method #1 on OSDev says it is clunky but works (link: http://wiki.osdev.org/PCI under "Enumerating PCI Buses: Brute Scan"). They mentioned PCI-to-PCI configuration in the third method but refrained from recommending it without "deep understanding of PCI specifications".


Refinement Of Question Due To New Findings
---------------------------------------------------
I found new perspective on IDE/ATA. It turns out that primary/secondary IDE controllers have their own set of I/O ports. Could it be that IDE controller is there in the machine but not connected to PCI bus at all? In general, is it possible for a device to be connected to multiple buses on the same machine?
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by SpyderTL »

Is it possible your IDE controller isn't connected to your PCI bus? Yes.

Is it likely? No.

Is it remotely possible in VirtualBox? No.

I'm also looping through every possible PCI slot/function number, and it is still, for all intents and purposes, instant.

You probably already know this, but your BAR0-5 values will be zero in VirtualBox. For some reason that I can't quite comprehend, the IDE/PCI standard states that a BAR address of zero means that the device is located at the "default" address. As far as I know, the IDE controller is the only PCI device on the planet that doesn't have to explicitly report it's address to the PCI bus.

Seriously.... WTF?!?
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Confusion regarding hard drives, PCI, IDE, SATA etc.

Post by Combuster »

As far as I know, the IDE controller is the only PCI device on the planet that doesn't have to explicitly report it's address to the PCI bus.
Nope. The video card is the other one every computer has and neglects to inform you about memory 0xA0000-0xBFFFF and ports 3B0-3DF. In fact it's likely that any ISA device addresses are not reported on the PCI bus, even if it's a PCI device providing them, so any onboard PCI soundblaster clones might also go on this list.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply