mirror of
https://github.com/RGBCube/serenity
synced 2025-07-29 01:27:44 +00:00
Kernel: Add character device driver for the RPi "mini UART" (UART1)
While the PL011-based UART0 is currently reserved for the kernel console, UART1 is free to be exposed to the userspace as `/dev/ttyS0`. This will be used as the stdout of `run-tests-and-shutdown.sh` when testing the AArch64 kernel.
This commit is contained in:
parent
3beb488887
commit
c460b84ebe
4 changed files with 186 additions and 0 deletions
47
Kernel/Arch/aarch64/RPi/MiniUART.h
Normal file
47
Kernel/Arch/aarch64/RPi/MiniUART.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Daniel Bertalan <dani@danielbertalan.dev>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Devices/CharacterDevice.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/Locking/Spinlock.h>
|
||||
|
||||
namespace Kernel::RPi {
|
||||
|
||||
struct MiniUARTRegisters;
|
||||
|
||||
// Makes the secondary "mini UART" (UART1) available to the userspace.
|
||||
// See bcm2711-peripherals.pdf chapter "2.2. Mini UART".
|
||||
class MiniUART final : public CharacterDevice {
|
||||
friend class Kernel::DeviceManagement;
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<MiniUART>> create();
|
||||
|
||||
virtual ~MiniUART() override;
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
||||
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
||||
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
||||
|
||||
void put_char(u8);
|
||||
|
||||
private:
|
||||
MiniUART();
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual StringView class_name() const override { return "MiniUART"sv; }
|
||||
|
||||
void set_baud_rate(u32);
|
||||
|
||||
bool m_last_put_char_was_carriage_return { false };
|
||||
Spinlock<LockRank::None> m_serial_lock {};
|
||||
MiniUARTRegisters volatile* m_registers;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue