fix: audio stack bug fixes
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <Hal/Apic/IoApic.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <CppLib/Stream.hpp>
|
||||
#include <CppLib/Spinlock.hpp>
|
||||
#include <Libraries/Memory.hpp>
|
||||
|
||||
namespace Drivers::Audio::IntelHda {
|
||||
@@ -24,6 +25,7 @@ namespace Drivers::Audio::IntelHda {
|
||||
// =========================================================================
|
||||
|
||||
static bool g_initialized = false;
|
||||
static kcp::Spinlock g_codecLock;
|
||||
|
||||
static volatile uint8_t* g_mmioBase = nullptr;
|
||||
static uint8_t g_bus, g_dev, g_func;
|
||||
@@ -199,16 +201,20 @@ namespace Drivers::Audio::IntelHda {
|
||||
|
||||
// Send a verb and wait for the response
|
||||
static uint32_t CodecCommand(uint8_t codec, uint8_t nid, uint32_t verb) {
|
||||
g_codecLock.Acquire();
|
||||
|
||||
uint32_t fullVerb = ((uint32_t)codec << 28) | ((uint32_t)nid << 20) | verb;
|
||||
SendVerb(fullVerb);
|
||||
|
||||
uint32_t response = 0;
|
||||
if (!ReadResponse(&response, nullptr)) {
|
||||
g_codecLock.Release();
|
||||
KernelLogStream(WARNING, "HDA") << "Verb timeout: codec=" << base::dec
|
||||
<< (uint64_t)codec << " nid=" << (uint64_t)nid
|
||||
<< " verb=" << base::hex << (uint64_t)verb;
|
||||
return 0;
|
||||
}
|
||||
g_codecLock.Release();
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -652,6 +658,7 @@ namespace Drivers::Audio::IntelHda {
|
||||
// never runs and unsolicited responses (jack events) pile up unread.
|
||||
// This consumes them and sets g_jackEventPending if any are found.
|
||||
static void DrainUnsolicitedResponses() {
|
||||
g_codecLock.Acquire();
|
||||
for (;;) {
|
||||
uint16_t wp = Read16(REG_RIRBWP) & 0xFF;
|
||||
if (g_rirbReadPtr == wp)
|
||||
@@ -666,6 +673,7 @@ namespace Drivers::Audio::IntelHda {
|
||||
g_rirbReadPtr = next;
|
||||
g_jackEventPending = true;
|
||||
}
|
||||
g_codecLock.Release();
|
||||
}
|
||||
|
||||
// Poll jack state; call when an unsolicited response fires.
|
||||
|
||||
Reference in New Issue
Block a user