[SOLVED] HD Audio Stream DMA engine not working

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
SK317
Posts: 4
Joined: Thu Oct 26, 2017 7:25 pm

[SOLVED] HD Audio Stream DMA engine not working

Post by SK317 »

Hello!

I am currently implementing HD Audio driver in my Thinkpad X220i. I have managed to make CORB and RIRB working well. However, I have been stuck in making stream DMA engine work for about two weeks. The problem is that DMA position is 0 and no interrupt has been fired, whereas Link Position in Buffer (LPIB) is changing.

Here is what I did:

1. enumerate PCI devices and find hda controller, Memory space and bus master bits are set in PCI Command register.
2. enable MSI support
3. reset controller
4. setup CORB and RIRB
5. enable interrupt
6. use verbs to find the correct DAC and pin widgets nodes.
7. reset output stream
8. initialize BDLE

*(PULONG64)(bdle+i*16) = 0x1000000+i*0x1000; //data buffer
*(PULONG)(bdle+i*16+8) = 0x800; // length
*(PULONG)(bdle+i*16+0xc) = 1; //IOC

9. set stream id 1 in sd control
10. set stream format 0x4011
11. set CBL 0x800*0x70
12. set LVI 0x6f
13. set BDL Pointer
14. set DMA Position

15. set afg, DAC and pin widgets powerstate
16. set format, stream id and channel for the DAC
17. unmute each widgets
18. turn on HP node

19. enable Interrupt On Completion and start stream

I have dumped some of the registers value in my timer isr. SDLPIB is changing and SDSTS is always 0x20.

GCAP:4401 SSYNC:00000000

SDCTL:0014001E SDSTS:20 SDLPIB:(0000DD34,00015734,00001138...) SDCBL:00038000 SDLVI:006F SDFIFOS:00C0 SDFMT:4011 SDBDPL:03000000 SDBDPU:00000000

Did I set things up correctly or maybe I forget something?

Thank You!
Last edited by SK317 on Sun Oct 29, 2017 12:56 am, edited 1 time in total.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: HD Audio Stream DMA engine not working

Post by DavidCooper »

Your best bet would be to look at other people's code to see what they might be setting that you aren't - you only have to get one thing wrong for the DMA engine not to run. You might find something in this thread: http://forum.osdev.org/viewtopic.php?f=1&t=28944 where someone had a similar problem as a result of not setting some obscure register. If you've gone through all the steps listed there and still can't get it working I'll take a closer look at what you're doing - I haven't worked with HDA for a while and have forgotten a lot of the details, so I'd need to do a bit of revision.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
SK317
Posts: 4
Joined: Thu Oct 26, 2017 7:25 pm

Re: HD Audio Stream DMA engine not working

Post by SK317 »

Hi,David, Thanks for your reply. I have gone through HD audio related posts in this forum. For my laptop, I found out that CORB and RIRB are working well in both cases where I reset and did not reset the controller. I also did a test where I chose not to reset stream, but still no luck.
The nodes I used in my test are DAC and HP nodes or DAC and built-in speaker nodes. I really have no idea what could possibly cause this problem.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: HD Audio Stream DMA engine not working

Post by DavidCooper »

Have you tried running KolibriOS on your machine to see if its HDA code works on it?
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
SK317
Posts: 4
Joined: Thu Oct 26, 2017 7:25 pm

Re: HD Audio Stream DMA engine not working

Post by SK317 »

Problem finally solved! David, Thank you for pointing me to the right direction. After I skim through the code of this OS. I clear the bit 0-2 of TCSEL and enable HDA snoop and the sound comes out of the built-in speaker instantly. For my laptop, it doesn't matter whether or not I reset host controller or stream. But it is crucial to set up PCI registers correctly.
Post Reply