From f9ab02429b4d51d882111c990d26add1243fbe27 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Tue, 25 Oct 2022 18:42:57 +0200 Subject: [PATCH] Kernel: Use generic functions to change interrupt state of Processor This allows these files to be built for aarch64. --- Kernel/Devices/Audio/AC97.cpp | 49 ++++++++++++------------ Kernel/Net/Intel/E1000NetworkAdapter.cpp | 4 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Kernel/Devices/Audio/AC97.cpp b/Kernel/Devices/Audio/AC97.cpp index 5ba2a33bba..9a0bcd02be 100644 --- a/Kernel/Devices/Audio/AC97.cpp +++ b/Kernel/Devices/Audio/AC97.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace Kernel { @@ -226,34 +227,34 @@ ErrorOr AC97::write_single_buffer(UserOrKernelBuffer const& data, size_t o { VERIFY(length <= PAGE_SIZE); - // Block until we can write into an unused buffer - cli(); - do { - auto pcm_out_status = m_pcm_out_channel->io_window().read16(AC97Channel::Register::Status); - auto current_index = m_pcm_out_channel->io_window().read8(AC97Channel::Register::CurrentIndexValue); - int last_valid_index = m_pcm_out_channel->io_window().read8(AC97Channel::Register::LastValidIndex); + { + // Block until we can write into an unused buffer + InterruptDisabler disabler; + do { + auto pcm_out_status = m_pcm_out_channel->io_window().read16(AC97Channel::Register::Status); + auto current_index = m_pcm_out_channel->io_window().read8(AC97Channel::Register::CurrentIndexValue); + int last_valid_index = m_pcm_out_channel->io_window().read8(AC97Channel::Register::LastValidIndex); - auto head_distance = last_valid_index - current_index; - if (head_distance < 0) - head_distance += buffer_descriptor_list_max_entries; - if (m_pcm_out_channel->dma_running()) - ++head_distance; + auto head_distance = last_valid_index - current_index; + if (head_distance < 0) + head_distance += buffer_descriptor_list_max_entries; + if (m_pcm_out_channel->dma_running()) + ++head_distance; - // Current index has _passed_ last valid index - move our list index up - if (head_distance > m_output_buffer_page_count) { - m_buffer_descriptor_list_index = current_index + 1; - break; - } + // Current index has _passed_ last valid index - move our list index up + if (head_distance > m_output_buffer_page_count) { + m_buffer_descriptor_list_index = current_index + 1; + break; + } - // There is room for our data - if (head_distance < m_output_buffer_page_count) - break; - - dbgln_if(AC97_DEBUG, "AC97 @ {}: waiting on interrupt - status: {:#05b} CI: {} LVI: {}", pci_address(), pcm_out_status, current_index, last_valid_index); - m_irq_queue.wait_forever("AC97"sv); - } while (m_pcm_out_channel->dma_running()); - sti(); + // There is room for our data + if (head_distance < m_output_buffer_page_count) + break; + dbgln_if(AC97_DEBUG, "AC97 @ {}: waiting on interrupt - status: {:#05b} CI: {} LVI: {}", pci_address(), pcm_out_status, current_index, last_valid_index); + m_irq_queue.wait_forever("AC97"sv); + } while (m_pcm_out_channel->dma_running()); + } // Copy data from userspace into one of our buffers TRY(data.read(m_output_buffer->vaddr_from_page_index(m_output_buffer_page_index).as_ptr(), offset, length)); diff --git a/Kernel/Net/Intel/E1000NetworkAdapter.cpp b/Kernel/Net/Intel/E1000NetworkAdapter.cpp index 18fd59ac8e..d7e5239b9b 100644 --- a/Kernel/Net/Intel/E1000NetworkAdapter.cpp +++ b/Kernel/Net/Intel/E1000NetworkAdapter.cpp @@ -408,12 +408,12 @@ void E1000NetworkAdapter::send_raw(ReadonlyBytes payload) descriptor.cmd = CMD_EOP | CMD_IFCS | CMD_RS; dbgln_if(E1000_DEBUG, "E1000: Using tx descriptor {} (head is at {})", tx_current, in32(REG_TXDESCHEAD)); tx_current = (tx_current + 1) % number_of_tx_descriptors; - cli(); + Processor::disable_interrupts(); enable_irq(); out32(REG_TXDESCTAIL, tx_current); for (;;) { if (descriptor.status) { - sti(); + Processor::enable_interrupts(); break; } m_wait_queue.wait_forever("E1000NetworkAdapter"sv);