Page 1 of 1

hardisk program in ahci mode

Posted: Tue Jun 02, 2015 7:07 am
by royaldsouza1
i am writing a low level hardisk access program in c using linux. It is user space program.
I already have written a program for hard disk in ide simulation mode using osdev has reference. I had used inb(), outb() etc.

However what i am trying to achive now is a c program to work in ahci mode. My hardisk abar register value is 0xc1617000. When i am trying to read this paticalular regiter or PI at offset 0x0c. My program crashes as this are memory mapped I/O. How can i contnue with this program. Any help would be helpfull.

Re: hardisk program in ahci mode

Posted: Tue Jun 02, 2015 8:37 am
by Combuster
google wrote:Linux provides the pcimem utility to allow reading from and writing to MMIO addresses

Re: hardisk program in ahci mode

Posted: Tue Jun 02, 2015 8:59 am
by iansjack
If you are writing this as a user-mode program in Linux why do you just not access the device (/dev/sda for example)?

Re: hardisk program in ahci mode

Posted: Wed Jun 03, 2015 12:44 am
by royaldsouza1
i need the ability to read status register has well has error registers. I need to read sectors in different directions. Send ata comands to the drive. has welll has learn few things on the way.

My program is running with sudo privileges and i am using iopl for accessing ports. However ACHI uses memory mapped I/O how can i go with it. pcimem dint work.

Re: hardisk program in ahci mode

Posted: Wed Jun 03, 2015 4:19 am
by iansjack
My gut feeling is that allowing a user program to access the controller registers, let alone send commands to the controller, is going to have unpredictable results. For example, if you read an error register how do you know what commands led up to any error code you see? And if you send a command in the middle of a stream of commands from the device driver, how can you predict the outcome?

Re: hardisk program in ahci mode

Posted: Wed Jun 03, 2015 10:12 am
by jnc100
If you wish to do this under linux, I'd imagine your best bet would be to write a custom version of the ahci driver, that dumps the registers you want to view to userspace somehow, rather than trying to access the controller whilst the standard driver thinks it has sole control of it.

Regards,
John.

Re: hardisk program in ahci mode

Posted: Fri Jun 05, 2015 10:00 pm
by royaldsouza1
jnc100 i do like your idea. Please could you point me out some links. How to map the ahci memory location to user process memory.

Re: hardisk program in ahci mode

Posted: Sat Jun 06, 2015 2:06 am
by iansjack
royaldsouza1 wrote:How to map the ahci memory location to user process memory.
Just create the appropriate Page Table entries. Be sure to set the VM_IO and VM_RESERVED flags when doing this.

Re: hardisk program in ahci mode

Posted: Sat Jun 06, 2015 6:40 am
by jnc100
I meant modify the existing driver (drivers/ata/ahci.c and drivers/ata/libachi.c) to suit your needs. In this case the appropriate memory ranges are already mapped for you. For example, to answer your original question, to read the ports implemented register you could add something like

Code: Select all

u32 pi = readl(mmio + HOST_PORTS_IMPL);
to ahci_init_controller() in libahci.c and then dump it somehow (I don't know the specifics of the linux kernel logging process to give you an accurate example here).

Regards,
John.