mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Use IOAddress instead of direct IO calls in SerialDevice
This commit is contained in:
parent
a5699a141d
commit
62f69cc50f
Notes:
sideshowbarker
2024-07-18 17:57:05 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/62f69cc50fd Pull-request: https://github.com/SerenityOS/serenity/pull/7116 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/supercomputer7
3 changed files with 21 additions and 20 deletions
|
@ -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>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -157,10 +157,10 @@ extern "C" UNMAP_AFTER_INIT [[noreturn]] void init()
|
|||
|
||||
NullDevice::initialize();
|
||||
if (!get_serial_debug())
|
||||
new SerialDevice(SERIAL_COM1_ADDR, 64);
|
||||
new SerialDevice(SERIAL_COM2_ADDR, 65);
|
||||
new SerialDevice(SERIAL_COM3_ADDR, 66);
|
||||
new SerialDevice(SERIAL_COM4_ADDR, 67);
|
||||
new SerialDevice(IOAddress(SERIAL_COM1_ADDR), 64);
|
||||
new SerialDevice(IOAddress(SERIAL_COM2_ADDR), 65);
|
||||
new SerialDevice(IOAddress(SERIAL_COM3_ADDR), 66);
|
||||
new SerialDevice(IOAddress(SERIAL_COM4_ADDR), 67);
|
||||
|
||||
VMWareBackdoor::the(); // don't wait until first mouse packet
|
||||
HIDManagement::initialize();
|
||||
|
|
Loading…
Reference in a new issue