From 7126a42d4d2ceabfb8af5f13e055351b5d0abb33 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 1 Dec 2019 12:53:19 +0100 Subject: [PATCH] Kernel: Use a WaitQueue in the SoundBlaster 16 driver Instead of waking up to check for IRQ's regularly, use a WaitQueue and wake it up in the IRQ handler. --- Kernel/Devices/SB16.cpp | 17 +++++++---------- Kernel/Devices/SB16.h | 4 +++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index 0ec3b382450..e51ed079df3 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -65,6 +65,8 @@ SB16& SB16::the() void SB16::initialize() { + disable_irq(); + IO::out8(0x226, 1); IO::delay(); IO::out8(0x226, 0); @@ -81,7 +83,6 @@ void SB16::initialize() auto vmin = dsp_read(); kprintf("SB16: found version %d.%d\n", m_major_version, vmin); - enable_irq(); } bool SB16::can_read(const FileDescription&) const @@ -134,16 +135,15 @@ void SB16::handle_irq() if (m_major_version >= 4) IO::in8(DSP_R_ACK); // 16 bit interrupt - m_interrupted = true; + m_irq_queue.wake_all(); } void SB16::wait_for_irq() { - // Well, we have no way of knowing how much got written. So just hope all of - // it did, even if we're interrupted. - (void)current->block_until("Interrupting", [this] { - return m_interrupted; - }); + cli(); + enable_irq(); + current->wait_on(m_irq_queue); + disable_irq(); } ssize_t SB16::write(FileDescription&, const u8* data, ssize_t length) @@ -162,7 +162,6 @@ ssize_t SB16::write(FileDescription&, const u8* data, ssize_t length) u8 mode = (u8)SampleFormat::Signed | (u8)SampleFormat::Stereo; - disable_irq(); const int sample_rate = 44100; set_sample_rate(sample_rate); memcpy(m_dma_buffer_page->paddr().as_ptr(), data, length); @@ -183,8 +182,6 @@ ssize_t SB16::write(FileDescription&, const u8* data, ssize_t length) dsp_write((u8)sample_count); dsp_write((u8)(sample_count >> 8)); - m_interrupted = false; - enable_irq(); wait_for_irq(); return length; } diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index 63d54569b86..43d70d595e8 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -5,6 +5,7 @@ #include #include #include +#include class SB16; @@ -37,6 +38,7 @@ private: u8 dsp_read(); RefPtr m_dma_buffer_page; - bool m_interrupted { false }; int m_major_version { 0 }; + + WaitQueue m_irq_queue; };