Hard Drive Driver

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.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

You're welcome? :roll:
Free energy is indeed evil for it absorbs the light.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

JamesM: I know you haven't wrote a SATA driver yet, but you seem to know what to do, so I just want to ask a few more questions:

Once I locate my RAID Mass Storage Device: (Bus 1, Device 11, Function 0), how would I send commands to the device? Do I send it through the PCI controller? If possible, can you explain this a bit, like how to set up its BARs? Thanks
Free energy is indeed evil for it absorbs the light.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Hard Drive Driver

Post by JamesM »

One of it's BARs will lead to an area of IO or memory space where its registers reside. You'd configure that BAR then treat it as any other memory-mapped (or IO-mapped) device.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

Duh, also explained in the wiki, sorry and thank you.
Free energy is indeed evil for it absorbs the light.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Hard Drive Driver

Post by Revelation »

The SATA drive on my system gets reported as IDE in the PCI bus enumeration, so you should keep that in mind. Once you have read in the BARs for the SATA (IDE), you should check if the BARs are zero. If they are, you can't use native PCI reading and you have to use standard ports (I guess this also means that that drive is not the SATA drive).

Once you find a drive that has non-zero BARs and a 1 in the lowest bit, that means you can use the BAR as I/O port (I've added this too the wiki last week). If I am not mistaking, the BARs translate to this:

Code: Select all

                        ide[idecount].com_prim = ((unsigned short)pci_read(bus, dev, func, 0x10)) ^ 0x1;
                        ide[idecount].com_sec = (unsigned short)pci_read(bus, dev, func, 0x18) ^ 0x1;
                        ide[idecount].con_prim = (unsigned short)pci_read(bus, dev, func, 0x14) ^ 0x1;
                        ide[idecount].con_sec = ((unsigned short)pci_read(bus, dev, func, 0x1C)) ^ 0x1;
com means command port. con means control port. So to read from the first drive, you should use com_prim.

I hope this information is valid. It took me quite some time to write the whole code, and it worked for me.
Now is the winter of my disk content.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

Hey Revelation. Where do you got that posted?

EDIT: Please someone correct me if I am wrong, but this is what I gathered from my research thus far. Mine returns as RAID on bus 1 device 11 function 0 the class is 1 (mass storage) :subclass 1 (it thinks it is an IDE Controller), because the nvidia nforce2 emulates that I suppose. My nvidia nforce2 returns as IDE class 1 (mass storage) subclass 11 (unknown to me) which I think is just an emulation device for my SATA SCSI HD. So, it may not be abnormal for it to be that as SATA is not what describes the device as it is simply a description of the standard in which your device transfers data via the way it is wired to the MB. Your PCI Controller locates the RAID Controller at Bus ?? Device ?? Function ?? and then you use the PCI_READ function to read the RAID Controllers registers to locate the BARs where Mapped-IO can take place and then... (still researching this). Your last post got me this far, so thank you.
Free energy is indeed evil for it absorbs the light.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Hard Drive Driver

Post by bubach »

OT: I've mirrored the "geezer" files on http://www.asmhackers.net/geezer/ and it will be there for at least a couple of years.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

I wrote my IsIDE function to test for IDE disk drives, so can someone look at it and tell me if it is OK?

Code: Select all

#define HDC_DRV_SELECT 0x1F6
#define HDC_IDENTIFY 0xEC
#define HDC_COMMAND_PORT 0x1F7 

unsigned int IsIDE(unsigned char drive)
{
	/*To use the IDENTIFY command, select a target drive by sending 0xA0 for the master drive, or 0xB0 for the slave, to the "drive select" IO port (0x1F6).
	A 400ns delay is a good idea. 
	Then send the IDENTIFY command (0xEC) to the Command IO port (0x1F7). 
	Then read the Status port (0x1F7) again. If the value read is 0, the drive does not exist. */
	outl(drive,HDC_DRV_SELECT);
	delay(1);
	outl(HDC_IDENTIFY,HDC_COMMAND_PORT);
	return inl(HDC_COMMAND_PORT);
}
It doesn't seem to be working, because it is returning really larger integers on real hardware and 80 in MS V-PC. In MS V-PC you cannot emulate SATA, so all you get is IDE, so in MS V-PC it should return something other than 0, and on my real hardware is should return 0 but it does not. Thanks
Free energy is indeed evil for it absorbs the light.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

Any PCI guys in the house that can help me here? Thanks
Free energy is indeed evil for it absorbs the light.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Hard Drive Driver

Post by Revelation »

I got the IDE specification from his document.

I used the read method described here to read my drive. The only difference is that you use the base port read from the BARs.
Now is the winter of my disk content.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Hard Drive Driver

Post by bewing »

What size is the data for outl and inl? They should be bytes. The IO Port bus is an 8 bit bus.
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Hard Drive Driver

Post by Omega »

Thank you for responding, I thought I wasn't going to get any attention with this. OK:

outl and inl is a long value, I tried using bytes, but the compiler (GCC) complained that there was a conversion from a large integer to something smaller. So, I used outl instead of outb and it compiled but I get nothing in return. Just some crazy integers.

I have been looking into this in major detail, and I have to say that the PCI controller needs very much a driver on its own. Then if I am to use the ISA bridge then that takes some substantial coding too, then I may need to code different drivers for each possible device, or I could try using default values and PnP. And I mean that in the Plug 'n' Pray way. I might just put this RAID driver on hold and just setup my test PC to use IDE since I have a working IDE driver already. I don't know, but I just want to get a solid grasp before I start swimming in water too deep, and it gets pretty deep in PCI land.

Anyway, I guess I am trying to say that I am no longer seeking help with this issue, but thanks anyway. :)
Free energy is indeed evil for it absorbs the light.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Hard Drive Driver

Post by jal »

So is there any more recent info than that at ata-atapi.com? That stuff seems a bit outdated.
ata-atapi.com wrote:SATA devices that are shipping today (mid-year 2003)
In five years, a lot can happen.


JAL
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Hard Drive Driver

Post by bewing »

I agree. It does seem like it would be outdated. But the basic situation seems not to have changed much. SATA-IO seems to have established firm control of the standard -- but to get the standard, you still need to pony up $25.

Wikipedia seems to have a fairly well updated article "SATA 2". But, of course, it gives no programming details.
Post Reply