summaryrefslogtreecommitdiff
path: root/Kernel/Devices
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-05-15 13:51:13 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-17 18:15:25 +0200
commit62f69cc50fd5174c4202ad7f57138c27422b2b65 (patch)
treed3ab2f18626d59da0430c400c57c9de1904bda3e /Kernel/Devices
parenta5699a141dcfaa3c1c605d70316ce5b08dfcf0c2 (diff)
downloadserenity-62f69cc50fd5174c4202ad7f57138c27422b2b65.zip
Kernel: Use IOAddress instead of direct IO calls in SerialDevice
Diffstat (limited to 'Kernel/Devices')
-rw-r--r--Kernel/Devices/SerialDevice.cpp28
-rw-r--r--Kernel/Devices/SerialDevice.h5
2 files changed, 17 insertions, 16 deletions
diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp
index 7daec69cd7..d3bb36e166 100644
--- a/Kernel/Devices/SerialDevice.cpp
+++ b/Kernel/Devices/SerialDevice.cpp
@@ -10,7 +10,7 @@
namespace Kernel {
-UNMAP_AFTER_INIT SerialDevice::SerialDevice(u32 base_addr, unsigned minor)
+UNMAP_AFTER_INIT SerialDevice::SerialDevice(IOAddress base_addr, unsigned minor)
: CharacterDevice(4, minor)
, m_base_addr(base_addr)
{
@@ -36,7 +36,7 @@ KResultOr<size_t> SerialDevice::read(FileDescription&, u64, UserOrKernelBuffer&
return buffer.write_buffered<128>(size, [&](u8* data, size_t data_size) {
for (size_t i = 0; i < data_size; i++)
- data[i] = IO::in8(m_base_addr);
+ data[i] = m_base_addr.in<u8>();
return data_size;
});
}
@@ -67,9 +67,9 @@ void SerialDevice::put_char(char ch)
;
if (ch == '\n' && !m_last_put_char_was_carriage_return)
- IO::out8(m_base_addr, '\r');
+ m_base_addr.out<u8>('\r');
- IO::out8(m_base_addr, ch);
+ m_base_addr.out<u8>(ch);
m_last_put_char_was_carriage_return = (ch == '\r');
}
@@ -92,24 +92,24 @@ UNMAP_AFTER_INIT void SerialDevice::set_interrupts(bool interrupt_enable)
{
m_interrupt_enable = interrupt_enable;
- IO::out8(m_base_addr + 1, interrupt_enable);
+ m_base_addr.offset(1).out<u8>(interrupt_enable);
}
void SerialDevice::set_baud(Baud baud)
{
m_baud = baud;
- IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) | 0x80); // turn on DLAB
- IO::out8(m_base_addr + 0, ((u8)(baud)) & 0xff); // lower half of divisor
- IO::out8(m_base_addr + 1, ((u8)(baud)) >> 2); // upper half of divisor
- IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & 0x7f); // turn off DLAB
+ m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() | 0x80); // turn on DLAB
+ m_base_addr.out<u8>(((u8)(baud)) & 0xff); // lower half of divisor
+ m_base_addr.offset(1).out<u8>(((u8)(baud)) >> 2); // upper half of divisor
+ m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() & 0x7f); // turn off DLAB
}
void SerialDevice::set_fifo_control(u8 fifo_control)
{
m_fifo_control = fifo_control;
- IO::out8(m_base_addr + 2, fifo_control);
+ m_base_addr.offset(2).out<u8>(fifo_control);
}
void SerialDevice::set_line_control(ParitySelect parity_select, StopBits stop_bits, WordLength word_length)
@@ -118,26 +118,26 @@ void SerialDevice::set_line_control(ParitySelect parity_select, StopBits stop_bi
m_stop_bits = stop_bits;
m_word_length = word_length;
- IO::out8(m_base_addr + 3, (IO::in8(m_base_addr + 3) & ~0x3f) | parity_select | stop_bits | word_length);
+ m_base_addr.offset(3).out<u8>((m_base_addr.offset(3).in<u8>() & ~0x3f) | parity_select | stop_bits | word_length);
}
void SerialDevice::set_break_enable(bool break_enable)
{
m_break_enable = break_enable;
- IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & (break_enable ? 0xff : 0xbf));
+ m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() & (break_enable ? 0xff : 0xbf));
}
void SerialDevice::set_modem_control(u8 modem_control)
{
m_modem_control = modem_control;
- IO::out8(m_base_addr + 4, modem_control);
+ m_base_addr.offset(4).out<u8>(modem_control);
}
u8 SerialDevice::get_line_status() const
{
- return IO::in8(m_base_addr + 5);
+ return m_base_addr.offset(5).in<u8>();
}
}
diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h
index 1bd05c944b..5a7182d972 100644
--- a/Kernel/Devices/SerialDevice.h
+++ b/Kernel/Devices/SerialDevice.h
@@ -7,6 +7,7 @@
#pragma once
#include <Kernel/Devices/CharacterDevice.h>
+#include <Kernel/IO.h>
namespace Kernel {
@@ -18,7 +19,7 @@ namespace Kernel {
class SerialDevice final : public CharacterDevice {
AK_MAKE_ETERNAL
public:
- SerialDevice(u32 base_addr, unsigned minor);
+ SerialDevice(IOAddress base_addr, unsigned minor);
virtual ~SerialDevice() override;
// ^CharacterDevice
@@ -122,7 +123,7 @@ private:
void set_modem_control(u8 modem_control);
u8 get_line_status() const;
- u32 m_base_addr { 0 };
+ IOAddress m_base_addr;
bool m_interrupt_enable { false };
u8 m_fifo_control { 0 };
Baud m_baud { Baud38400 };