1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

Kernel: Use IOAddress instead of direct IO calls in SerialDevice

This commit is contained in:
Idan Horowitz 2021-05-15 13:51:13 +03:00 committed by Andreas Kling
parent a5699a141d
commit 62f69cc50f
3 changed files with 21 additions and 20 deletions

View file

@ -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>();
}
}