OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:07 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 74 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Mar 08, 2021 4:30 pm 
Offline

Joined: Wed Feb 17, 2021 10:44 am
Posts: 1
Any update in 2021?


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Apr 26, 2021 1:09 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Hey guys, today I got first sound from my hda driver!

https://github.com/Klaykap/BleskOS/blob ... nd_hda.asm

Main feature is that I use immediate interface instead CORB/RIRB interface. So there is still a lot of work, but I am happy that I reached some point.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Sat Aug 14, 2021 8:20 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Well, I finally have it. I can send verb through CORB/RIRB interface.

Initalizing CORB:
  • Turn CORB off - outb(CORBCTL, 0x0);
  • Set CORB memory - outd(CORB_LBA, low_base_address_of_corb); outd(CORB_HBA, high_base_address_of_corb);
  • Set CORB size to 256 entries - outb(CORBSIZE, 0x2);
  • Set write pointer - outw(CORB_WP, 0);
  • Reset read pointer - outw(CORB_RP, 0x8000); here wait until bit 15 is set outw(CORB_RP, 0x0000); here wait until bit 15 is clear

Initalizing RIRB:
  • Turn RIRB off - outb(RIRBCTL, 0x0);
  • Set RIRB memory - outd(RIRB_LBA, low_base_address_of_rirb); outd(RIRB_HBA, high_base_address_of_rirb);
  • Set RIRB size to 256 entries - outb(RIRBSIZE, 0x2);
  • Reset write pointer - outw(RIRB_WP, 0x8000); here wait until bit 15 is set outw(RIRB_WP, 0x0000); here wait until bit 15 is clear
  • Set interrupt control - outw(RIRB_INTCTL, 0x0);

Here we can turn on CORB and RIRB by writing value 0x2 to their CONTROL registers.

And now you can send verb by this:
  • Write verb to CORB memory (important: you have to start writing verbs from entry 1, not entry 0 in your memory)
  • Update CORB write pointer - outw(CORB_WP, entry_number); So for first entry this will be 1
  • Wait until RIRB write pointer is the same value as CORB write pointer
  • Read response from RIRB memory

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Sat Aug 14, 2021 12:33 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
After CORB & RIRB you need to setup the codec so the sound flows on the correct path. This is a bit complicated. First you need to discover what is connected, and then you need to enable paths so sound flows to the enabled device. You probably also want to be able to change volume.


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Aug 30, 2021 1:03 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Here is my understanding of playing sound through nodes.

Stream -> Audio Output -> optional Mixer/Selector -> Out Pin -> Device

Stream:
Is controlled by Output Stream set of ports.

Audio Output:
Set format of stream by verb 0x2
Set stream and channel number by verb 0x706
Set volume by verb 0x3

Mixer/Selector:
Set volume by verb 0x3
In selector also select node by verb 0x701

Out Pin:
Enable pin by set bit 6 by verb 0x707
Enable external speaker by verb 0x70C
Set volume by verb 0x3

Now I can load sound data, describe it in Buffer Descriptor List, run stream and I will hear sound.

Please is this right? Or am I missing something? Thank you for responses.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Tue Aug 31, 2021 1:42 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
Klakap wrote:
Here is my understanding of playing sound through nodes.

Stream -> Audio Output -> optional Mixer/Selector -> Out Pin -> Device

Stream:
Is controlled by Output Stream set of ports.

Audio Output:
Set format of stream by verb 0x2
Set stream and channel number by verb 0x706
Set volume by verb 0x3

Mixer/Selector:
Set volume by verb 0x3
In selector also select node by verb 0x701

Out Pin:
Enable pin by set bit 6 by verb 0x707
Enable external speaker by verb 0x70C
Set volume by verb 0x3

Now I can load sound data, describe it in Buffer Descriptor List, run stream and I will hear sound.

Please is this right? Or am I missing something? Thank you for responses.


I think the above is a bit simplistic. First, you can have several output PINs, and you should check if they are connected or not before assuming you should enable them. Based on which connected output PINs you have, you then need to find a path from the source to the connected output PINs. You then need to send the correct commands to mixers and selectors so this path is properly enabled. You also might need to set volume controls on the path to reasonable values, and/or set the global volume control. The values set should depend on the volume the user has selected.


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Tue Aug 31, 2021 4:19 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
My driver is already able to find output pins nodes. So now I should check every pin if is some device connected to it. If yes, I can enable this pin and start going on his connection list. By connection lists I must find path to some audio output node. When I have this, I can enable all nodes I found. Am I understand it right?

And I also found that on real computer there are many speaker output pins. It is little confusing to me. Should I enable only one pin, if is some device connected to it, or should I enable all pins to whose are connected some devices?

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Tue Aug 31, 2021 5:33 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
Klakap wrote:
My driver is already able to find output pins nodes. So now I should check every pin if is some device connected to it. If yes, I can enable this pin and start going on his connection list. By connection lists I must find path to some audio output node. When I have this, I can enable all nodes I found. Am I understand it right?


I think so.

Klakap wrote:
And I also found that on real computer there are many speaker output pins. It is little confusing to me. Should I enable only one pin, if is some device connected to it, or should I enable all pins to whose are connected some devices?


It's a bit complicated. If I remember it correctly, there is also some output (speaker?) that doesn't have connection checking support. I think I prioritize if something is plugged into an output, and then I only enable that output & path. If nothing is connected, then I route to the "default speaker" which has no support for connection status. This should work on real computers.


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Sun Jun 19, 2022 8:46 pm 
Offline

Joined: Sun Jun 19, 2022 7:42 am
Posts: 1
Hi, I'm from 2022. I want to play audio with HD Audio on a small operating system (for teaching purposes), and I am just wondering, what should be done for the PCI configuration and Memory mapped configuration part? (or, what should I do with all the registers listed in Chapter 6?)


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Sat Mar 09, 2024 1:16 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Finally, now I can say that I have fully functioning driver. Last and very tricky part for me was figuring out how to properly update buffer. It was issue because sound card read buffer entries directly from RAM memory, but because it is such small part of data, many computers wrote it in fact only to processor cache. So then sound card was playing previous content of buffer what was of course extremely weird. But today I finally found that flushing processor cache fixes this. I tested that my actual driver works with 6 different codecs, and on multiple real computers. Feel free to check it out: https://github.com/VendelinSlezak/Blesk ... ound/hda.c

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Mar 11, 2024 4:15 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
Sounds like you are using the wrong page attributes on the sound buffer. You should set it to non-cachable or something to make sure the CPU writes it to physical memory.


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Mar 11, 2024 9:19 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Wait a minute, PCI DMA is supposed to be cache-coherent by default. You shouldn't need to flush the caches unless you've intentionally told the HDA controller to use non-snooped reads.


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Mar 11, 2024 12:45 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Thank you for pointing this out. I digged deeper and I found out that in there is PCI register 0x78 in which bit 11 enables non snoop. When I cleared it, problem is fixed even without flushing processor cache. However I really do not understand why it is even set as default. It makes no sense for me, because it is great way to mess things up with cache / RAM data. But anyway, it is nice solution for this problem.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: How to play sound Intel HD Audio?
PostPosted: Mon Mar 11, 2024 4:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Huh. I took a look at the HDA specification and it says HDA controllers are allowed to force non-snoop DMA. So, the correct fix is what rdos suggested: change the buffer memory type to prevent caching.

I also checked a random Windows PC, and the Intel HDA driver leaves the Enable No Snoop bit set.

Oh, and that bit is set by default because it's part of the PCI Express Capability Structure, and the PCIe specification says that bit should be set by default.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], cloudapio, DotBot [Bot] and 75 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