2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-10-13 02:48:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2015-11-09 14:47:45 +08:00
|
|
|
#include <console.h>
|
2024-05-21 03:35:03 +08:00
|
|
|
#include <linux/string.h>
|
2021-03-15 13:00:18 +08:00
|
|
|
#include <asm/cb_sysinfo.h>
|
2012-10-13 02:48:48 +08:00
|
|
|
|
2014-07-23 20:54:59 +08:00
|
|
|
void cbmemc_putc(struct stdio_dev *dev, char data)
|
2012-10-13 02:48:48 +08:00
|
|
|
{
|
2023-09-11 03:13:02 +08:00
|
|
|
const struct sysinfo_t *sysinfo = cb_get_sysinfo();
|
|
|
|
struct cbmem_console *cons;
|
|
|
|
uint pos, flags;
|
|
|
|
|
|
|
|
if (!sysinfo)
|
|
|
|
return;
|
|
|
|
cons = sysinfo->cbmem_cons;
|
|
|
|
if (!cons)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pos = cons->cursor & CBMC_CURSOR_MASK;
|
|
|
|
|
|
|
|
/* preserve the overflow flag if present */
|
|
|
|
flags = cons->cursor & ~CBMC_CURSOR_MASK;
|
|
|
|
|
|
|
|
cons->body[pos++] = data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with overflow - the flag may be cleared by another program which
|
|
|
|
* reads the buffer out later, e.g. Linux
|
|
|
|
*/
|
|
|
|
if (pos >= cons->size) {
|
|
|
|
pos = 0;
|
|
|
|
flags |= CBMC_OVERFLOW;
|
|
|
|
}
|
2012-10-13 02:48:48 +08:00
|
|
|
|
2023-09-11 03:13:02 +08:00
|
|
|
cons->cursor = flags | pos;
|
2012-10-13 02:48:48 +08:00
|
|
|
}
|
|
|
|
|
2014-07-23 20:54:59 +08:00
|
|
|
void cbmemc_puts(struct stdio_dev *dev, const char *str)
|
2012-10-13 02:48:48 +08:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while ((c = *str++) != 0)
|
2014-07-23 20:54:59 +08:00
|
|
|
cbmemc_putc(dev, c);
|
2012-10-13 02:48:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int cbmemc_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct stdio_dev cons_dev;
|
|
|
|
|
|
|
|
memset(&cons_dev, 0, sizeof(cons_dev));
|
|
|
|
|
|
|
|
strcpy(cons_dev.name, "cbmem");
|
|
|
|
cons_dev.flags = DEV_FLAGS_OUTPUT; /* Output only */
|
|
|
|
cons_dev.putc = cbmemc_putc;
|
|
|
|
cons_dev.puts = cbmemc_puts;
|
|
|
|
|
|
|
|
rc = stdio_register(&cons_dev);
|
|
|
|
|
|
|
|
return (rc == 0) ? 1 : rc;
|
|
|
|
}
|