mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00

The serial driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_serial_init() first attempts to match the chosen stdout device, and upon failure matches the first available serial device in the DT. It is a fatal error if no such device is found. This matches the behavior of fdt_driver_init_one(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
|
*
|
|
* Authors:
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
*/
|
|
|
|
#include <libfdt.h>
|
|
#include <sbi/sbi_error.h>
|
|
#include <sbi_utils/fdt/fdt_helper.h>
|
|
#include <sbi_utils/serial/fdt_serial.h>
|
|
|
|
/* List of FDT serial drivers generated at compile time */
|
|
extern const struct fdt_driver *const fdt_serial_drivers[];
|
|
|
|
int fdt_serial_init(const void *fdt)
|
|
{
|
|
const void *prop;
|
|
int noff = -1, len, coff, rc;
|
|
|
|
/* Find offset of node pointed to by stdout-path */
|
|
coff = fdt_path_offset(fdt, "/chosen");
|
|
if (-1 < coff) {
|
|
prop = fdt_getprop(fdt, coff, "stdout-path", &len);
|
|
if (prop && len) {
|
|
const char *sep, *start = prop;
|
|
|
|
/* The device path may be followed by ':' */
|
|
sep = strchr(start, ':');
|
|
if (sep)
|
|
noff = fdt_path_offset_namelen(fdt, prop,
|
|
sep - start);
|
|
else
|
|
noff = fdt_path_offset(fdt, prop);
|
|
}
|
|
}
|
|
|
|
/* First check DT node pointed by stdout-path */
|
|
if (-1 < noff) {
|
|
rc = fdt_driver_init_by_offset(fdt, noff, fdt_serial_drivers);
|
|
if (rc != SBI_ENODEV)
|
|
return rc;
|
|
}
|
|
|
|
/* Lastly check all DT nodes */
|
|
return fdt_driver_init_one(fdt, fdt_serial_drivers);
|
|
}
|