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.
hardisk program in ahci mode
- Combuster
- 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
google wrote:Linux provides the pcimem utility to allow reading from and writing to MMIO addresses
Re: hardisk program in ahci mode
If you are writing this as a user-mode program in Linux why do you just not access the device (/dev/sda for example)?
-
- Posts: 3
- Joined: Tue Jun 02, 2015 6:41 am
Re: hardisk program in ahci mode
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.
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
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
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.
Regards,
John.
-
- Posts: 3
- Joined: Tue Jun 02, 2015 6:41 am
Re: hardisk program in ahci mode
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
Just create the appropriate Page Table entries. Be sure to set the VM_IO and VM_RESERVED flags when doing this.royaldsouza1 wrote:How to map the ahci memory location to user process memory.
Re: hardisk program in ahci mode
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 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.
Code: Select all
u32 pi = readl(mmio + HOST_PORTS_IMPL);
Regards,
John.