hardisk program in ahci mode

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
royaldsouza1
Posts: 3
Joined: Tue Jun 02, 2015 6:41 am

hardisk program in ahci mode

Post 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.
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: hardisk program in ahci mode

Post by Combuster »

google wrote:Linux provides the pcimem utility to allow reading from and writing to MMIO addresses
"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 ]
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: hardisk program in ahci mode

Post 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)?
royaldsouza1
Posts: 3
Joined: Tue Jun 02, 2015 6:41 am

Re: hardisk program in ahci mode

Post 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.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: hardisk program in ahci mode

Post 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?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: hardisk program in ahci mode

Post 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.
royaldsouza1
Posts: 3
Joined: Tue Jun 02, 2015 6:41 am

Re: hardisk program in ahci mode

Post 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.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: hardisk program in ahci mode

Post 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.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: hardisk program in ahci mode

Post 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.
Post Reply