1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

Kernel+AudioServer: Use interrupts for Intel HDA audio buffer completion

We used to not care about stopping an audio output stream for Intel HDA
since AudioServer would continuously send new buffers to play. Since
707f5ac150ef858760eb9faa52b9ba80c50c4262 however, that has changed.

Intel HDA now uses interrupts to detect when each buffer was completed
by the device, and uses a simple heuristic to detect whether a buffer
underrun has occurred so it can stop the output stream.

This was tested on Qemu's Intel HDA (Linux x86_64) and a bare metal MSI
Starship/Matisse HD Audio Controller.
This commit is contained in:
Jelle Raaijmakers 2023-06-27 16:07:05 +02:00
parent 2e474e8c18
commit 5c64686666
5 changed files with 120 additions and 25 deletions

View file

@ -16,6 +16,7 @@
#include <Kernel/Devices/Audio/Controller.h>
#include <Kernel/Devices/Audio/IntelHDA/OutputPath.h>
#include <Kernel/Devices/Audio/IntelHDA/RingBuffer.h>
#include <Kernel/Interrupts/PCIIRQHandler.h>
#include <Kernel/Library/IOWindow.h>
namespace Kernel::Audio::IntelHDA {
@ -26,7 +27,8 @@ class Codec;
class Controller final
: public AudioController
, public PCI::Device {
, public PCI::Device
, public PCIIRQHandler {
public:
static ErrorOr<bool> probe(PCI::DeviceIdentifier const&);
static ErrorOr<NonnullRefPtr<AudioController>> create(PCI::DeviceIdentifier const&);
@ -35,6 +37,9 @@ public:
// ^PCI::Device
virtual StringView device_name() const override { return "IntelHDA"sv; }
// ^PCIIRQHandler
virtual StringView purpose() const override { return "IntelHDA IRQ Handler"sv; }
ErrorOr<u32> send_command(u8 codec_address, u8 node_id, CodecControlVerb verb, u16 payload);
private:
@ -47,6 +52,8 @@ private:
VersionMajor = 0x03,
GlobalControl = 0x08,
StateChangeStatus = 0x0e,
InterruptControl = 0x20,
InterruptStatus = 0x24,
CommandOutboundRingBufferOffset = 0x40,
ResponseInboundRingBufferOffset = 0x50,
StreamsOffset = 0x80,
@ -58,12 +65,25 @@ private:
AcceptUnsolicitedResponseEnable = 1u << 8,
};
// 3.3.14: INTCTL Interrupt Control
enum InterruptControlFlag : u32 {
GlobalInterruptEnable = 1u << 31,
};
// 3.3.15: INTSTS Interrupt Status
enum InterruptStatusFlag : u32 {
GlobalInterruptStatus = 1u << 31,
};
Controller(PCI::DeviceIdentifier const&, NonnullOwnPtr<IOWindow>);
ErrorOr<void> initialize_codec(u8 codec_address);
ErrorOr<void> configure_output_route();
ErrorOr<void> reset();
// ^PCIIRQHandler
virtual bool handle_irq(RegisterState const&) override;
// ^AudioController
virtual RefPtr<AudioChannel> audio_channel(u32 index) const override;
virtual ErrorOr<size_t> write(size_t channel_index, UserOrKernelBuffer const& data, size_t length) override;