drivers/tty/serial/earlycon-riscv-sbi.c
Source file repositories/reference/linux-study-clean/drivers/tty/serial/earlycon-riscv-sbi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/serial/earlycon-riscv-sbi.c- Extension
.c- Size
- 1095 bytes
- Lines
- 53
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/console.hlinux/init.hlinux/serial_core.hasm/sbi.h
Detected Declarations
function Copyrightfunction sbi_0_1_console_writefunction sbi_dbcn_console_writefunction early_sbi_setup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* RISC-V SBI based earlycon
*
* Copyright (C) 2018 Anup Patel <anup@brainfault.org>
*/
#include <linux/kernel.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/serial_core.h>
#include <asm/sbi.h>
static void sbi_putc(struct uart_port *port, unsigned char c)
{
sbi_console_putchar(c);
}
static void sbi_0_1_console_write(struct console *con,
const char *s, unsigned int n)
{
struct earlycon_device *dev = con->data;
uart_console_write(&dev->port, s, n, sbi_putc);
}
static void sbi_dbcn_console_write(struct console *con,
const char *s, unsigned int n)
{
int ret;
while (n) {
ret = sbi_debug_console_write(s, n);
if (ret < 0)
break;
s += ret;
n -= ret;
}
}
static int __init early_sbi_setup(struct earlycon_device *device,
const char *opt)
{
if (sbi_debug_console_available)
device->con->write = sbi_dbcn_console_write;
else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
device->con->write = sbi_0_1_console_write;
else
return -ENODEV;
return 0;
}
EARLYCON_DECLARE(sbi, early_sbi_setup);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/console.h`, `linux/init.h`, `linux/serial_core.h`, `asm/sbi.h`.
- Detected declarations: `function Copyright`, `function sbi_0_1_console_write`, `function sbi_dbcn_console_write`, `function early_sbi_setup`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.