OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 9:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Thu Jan 25, 2024 4:07 am 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Octocontrabass wrote:
Are the virtual addresses aligned too?

Yes, I aligned the virtual addresses too, but nothing changed


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Thu Jan 25, 2024 10:09 am 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
So, i rewrite the driver again, because i noticed some problems in allocation in my posted code, and i can't use aligned virtual memory propertly, now using the code from wiki, i allocate the address space for AHCI at kernel boot, align it to 1KiB, the CI is clears, but i don't see the DMA transfer from the controller, did my aligment is incorrect again?

EDIT: Fixed some structure issues and i got error 0x7f from PxTFD register before issusing new command


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Thu Jan 25, 2024 8:19 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
WinExperements wrote:
i got error 0x7f from PxTFD register before issusing new command

Do you mean the error field contains the value 0x7F, or the entire register contains 0x7F? If it's the entire register, the drive hasn't sent a status update since the controller was reset.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Fri Jan 26, 2024 9:14 am 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
i fixed the issue about the 0x7f value. I tested the reading from AHCI. Also after enabling the interrupts i got continuislly the interrupt from IRQ 0x2b, but the PCI device interrupt line reports that the IRQ is 0x10b, i read the interrupt line using PciRead32, can the interrupts caused by non handled previously interrupts from the controller? Also runned on real hardware, got port hung error and some wierd(for me) values of port registers: serr - 0x4050000, tfd - 0x80


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Fri Jan 26, 2024 8:01 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
WinExperements wrote:
Also after enabling the interrupts i got continuislly the interrupt from IRQ 0x2b, but the PCI device interrupt line reports that the IRQ is 0x10b,

You're receiving IRQ11. You've configured the PICs to map IRQ11 to interrupt vector 0x2B.

WinExperements wrote:
can the interrupts caused by non handled previously interrupts from the controller?

PCI IRQs are level-triggered. If you send an EOI without acknowledging the IRQ in the AHCI HBA, you will immediately receive another interrupt.

WinExperements wrote:
Also runned on real hardware, got port hung error and some wierd(for me) values of port registers: serr - 0x4050000, tfd - 0x80

PxTFD indicates you sent a FIS to the drive and the HBA is waiting for the drive to respond. PxSERR doesn't show any errors, but it does say the SATA link state changed since the last time it was cleared.

It sounds like the drive doesn't think it needs to respond to the FIS you're sending.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Fri Jan 26, 2024 8:26 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Octocontrabass wrote:
If you send an EOI without acknowledging the IRQ in the AHCI HBA, you will immediately receive another interrupt.

Understood, thanks

Octocontrabass wrote:
the drive doesn't think it needs to respond to the FIS you're sending.


can it be caused by non handled interruptions from HBA and what I should do in this situation?

EDIT: I added interrupt handler, and noticed that on real HW the 0x80 of TFD register is set after some ms after controller reset and stay remain, i reset it using this code:
Code:
info->abar->ghc = (uint32_t ) (1 << 31);
    info->abar->ghc = (uint32_t ) (1 << 0);
    info->abar->ghc = (uint32_t) (1 << 31);
    info->abar->ghc = (uint32_t) (1 << 1);


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Sun Jan 28, 2024 12:20 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Okay, it’s looks like the reset busy stuff is likely controller specific. Okay, I still have few questions about hard drives, a specially: I currently also writing PCI IDE driver and tests it on my notebook and virtual machines. So on VM the driver perfectly works, but on my notebook that use SATA controller IDE mode I got the IRQ10 interrupt and if I read the first successfully detected drive status register I got 0x7f. The read/write code works fine. So did anyone know why I got there interrupts and how correctly process there interrupts? Also i got there interrupts continuosly


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 11:47 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
WinExperements wrote:
can it be caused by non handled interruptions from HBA and what I should do in this situation?

AHCI is supposed to process commands completely automatically, so an unhandled interrupt shouldn't get in the way of command processing. There's probably still something wrong somewhere, but I've looked through your code a few times and haven't found the problem.

You don't need to enable all of the different AHCI interrupts if you're not sure how to handle them. Also, PCI allows interrupt sharing, so you need to check whether the interrupt is coming from your AHCI HBA when you handle it.

WinExperements wrote:
on my notebook that use SATA controller IDE mode I got the IRQ10 interrupt and if I read the first successfully detected drive status register I got 0x7f.

Usually that status means no drive is connected, but you may also see strange values if you're using DMA and not reading the status registers in the correct order. The PCI IDE specifications explain how your driver is expected to work with the hardware, although the explanations assume you're already familiar with legacy ISA IDE.

WinExperements wrote:
So did anyone know why I got there interrupts and how correctly process there interrupts?

Without more information, it's impossible to say where the interrupts are coming from.

WinExperements wrote:
Also i got there interrupts continuosly

If you send an EOI to the interrupt controller before you acknowledge the PCI device, you will receive another interrupt. If you never acknowledge the PCI device, you will receive interrupts from it continuously.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 2:50 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Thanks for this information. About ATA, I think to post here about that to not create new topic, so after some verbose loging I can say that the interrupts fired from the SATA controller itself(or IDE controller because it’s in IDE mode) after sending IDENTIFY command. Also after reading the wiki about PCI IDE and IDE PIO I don’t fully understand how my driver must reply to there device IRQ. So can I do something based on this information? On QEMU the IRQ (0x2e) fired on IDENTIFY command too, but only one time


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 4:19 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
WinExperements wrote:
the interrupts fired from the SATA controller itself(or IDE controller because it’s in IDE mode) after sending IDENTIFY command.

The interrupt is to tell you the drive is done processing the command. Read the drive's status register to acknowledge the interrupt and see what you need to do next.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 4:25 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Octocontrabass wrote:
Read the drive's status register to acknowledge the interrupt and see what you need to do next.


Okay, my interrupt handler reads the status register, and this register is 0x58, and error register is zero, what I should do with this(because I really don’t get it). Writing back the status register doesn’t help, I still get the interrupt


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 4:39 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
WinExperements wrote:
Okay, my interrupt handler reads the status register, and this register is 0x58

There are no errors and the drive is ready for you to transfer data. Since you used the IDENTIFY DEVICE command, the drive is expecting you to read 512 bytes.

WinExperements wrote:
I still get the interrupt

Did you read the status register before or after the EOI? You must read the status register before the EOI.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 4:57 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
I rewrite the IRQ handler, so the EOI will sent after the IRQ handler exited, and still the same


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 4:59 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
Is another PCI device using the same IRQ? PCI IRQs can be shared.


Top
 Profile  
 
 Post subject: Re: Cannot read blocks using AHCI
PostPosted: Mon Jan 29, 2024 5:18 pm 
Offline
Member
Member

Joined: Thu Jul 14, 2022 9:45 am
Posts: 94
Octocontrabass wrote:
Is another PCI device using the same IRQ?

After checking each PCI device IRQ line, the first IDE PCI device IRQ line used also by Signal Processing Unit and second PCI IDE device. So how I can correctly add the interrupt handler or what I must do in this situation?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group