Page 1 of 1

How to initialize AHCI? (step 2)

Posted: Sat Jan 09, 2016 6:46 am
by ashishkumar4
I know I sound Silly and Stupid (which I am) but I cant do much for it.
I know how to detect AHCI controllers and SATA Drives and get ALL their info by enumerating PCI buses. no prob in that. Its also not a big issue handling the FISs or making them. I know that ahci is a HBA and that it moves data from system mem to SATA. making these handling parts of driver isn't a problem.
But I just don't know HOW TO ISSUE an FIS or simply, HOW O INITIALIZE AHCI so that it can MAP some system mem for use? means there isn't some magic going to happen and I just would have to make fis, rest ahci would handle. That's surely not the case and cant be one. I need to tell AHCI from where to take the info or command etc whatever. The prob is How? I was reading the Intel Specs for it but after reading 50-60 pages, I concluded that I don't have enough time to read it as My exams are near :/ so PLEASE I BEG U TO EXPLAIN THIS TO ME AND CORRECT MY CONCEPTS IF THEY ARE WRONG. Don't get angry on me, Because I am stupid, making mistakes is my habit :3 :p

Re: How to initialize AHCI? (step 2)

Posted: Sat Jan 09, 2016 8:36 am
by cmpxchg64
Using basic AHCI is pretty simple. Over time you're just going to grow a folder full of additionall specs (like ATA-ACS, ATAPI -> SCSI CDB, ...).

The basic operation is also lined out in the AHCI spec in section 10.2-10.3.
Basically it works the following way:
1. For each port you first have to set up the received FIS memory structure and then start the corresponding DMA engine.
2. Do the same setup for the port command lists with the physical memory address etc.
3. Check the prerequisites for enabling the command list dma engine (DET=3h, etc.)
4. Switch on the command list by setting the ST bit
5. Build a command table for your first command somewhere in aligned memory where you know the physical address of. (A simple command table for reading is contained in the AHCI-wiki entry)
6. Also have physical memory for the received data to be specified in the PRDs ready
and last step:
7. Get a command slot, update the command header and set the corresponding command-issue (CI) bit.
8. Wait for completion et voila the data will be in the memory pointed to by the PRDTs.

BUT: For issuing commands etc. you have to know the ATA or ATAPI/SCSI command codes and the layout/sizes of each command (which you have to place at the base(or for ATAPI at a certain offset) of each command table). Additionally you should know the meaning of each field in these commands. The AHCI-wiki code is a starting point, the ATA8-ACS with all the codes is then the next step.

Re: How to initialize AHCI? (step 2)

Posted: Sat Jan 09, 2016 10:04 am
by ashishkumar4
ok, let me try :/ Thanks by the way :p
It would be great if someone gives me a TUtorial link because It would make me understand it faster :/ please suggest some tutorials please

Re: How to initialize AHCI? (step 2)

Posted: Sat Jan 09, 2016 11:25 am
by cmpxchg64
I have thrown some code there: http://pastebin.com/WRpJbjhS

Just work your way up from module_init().

Additionally this code uses a worker_thread for issuing pending commands. In your case you just should do ahci_device_init, then issue a command by the procedure outlined in ahci_process_command and then wait for completion.

Re: How to initialize AHCI? (step 2)

Posted: Sat Jan 09, 2016 11:49 am
by ashishkumar4
Thanks :D this word is not enough to describe ur help but I don't have any other words, just Thanks a lot :D :)