1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +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

@ -30,14 +30,16 @@ UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<AudioController>> Controller::create(PCI:
UNMAP_AFTER_INIT Controller::Controller(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<IOWindow> controller_io_window)
: PCI::Device(const_cast<PCI::DeviceIdentifier&>(pci_device_identifier))
, PCIIRQHandler(*this, device_identifier().interrupt_line().value())
, m_controller_io_window(move(controller_io_window))
{
}
UNMAP_AFTER_INIT ErrorOr<void> Controller::initialize(Badge<AudioManagement>)
{
// Enable DMA
// Enable DMA and interrupts
PCI::enable_bus_mastering(device_identifier());
enable_irq();
// 3.3.3, 3.3.4: Controller version
auto version_minor = m_controller_io_window->read8(ControllerRegister::VersionMinor);
@ -163,6 +165,13 @@ UNMAP_AFTER_INIT ErrorOr<void> Controller::configure_output_route()
// Create output path
auto output_path = TRY(OutputPath::create(move(path), move(output_stream)));
TRY(output_path->activate());
// Enable controller and stream interrupts for this output stream
auto interrupt_control = m_controller_io_window->read32(ControllerRegister::InterruptControl);
interrupt_control |= InterruptControlFlag::GlobalInterruptEnable;
interrupt_control |= 1u << (m_number_of_input_streams + output_stream_index);
m_controller_io_window->write32(ControllerRegister::InterruptControl, interrupt_control);
return output_path;
};
@ -290,6 +299,24 @@ ErrorOr<void> Controller::reset()
return {};
}
bool Controller::handle_irq(Kernel::RegisterState const&)
{
// Check if any interrupt status bit is set
auto interrupt_status = m_controller_io_window->read32(ControllerRegister::InterruptStatus);
if ((interrupt_status & InterruptStatusFlag::GlobalInterruptStatus) == 0)
return false;
// FIXME: Actually look at interrupt_status and iterate over streams as soon as
// we support multiple streams.
if (m_output_path) {
auto maybe_error = m_output_path->output_stream().handle_interrupt({});
if (maybe_error.is_error())
dbgln("IntelHDA: Error during interrupt handling: {}", maybe_error.error());
}
return true;
}
RefPtr<AudioChannel> Controller::audio_channel(u32 index) const
{
if (index != fixed_audio_channel_index)