Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 7 | #include <console.h> |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 8 | #ifndef CONFIG_SYS_COREBOOT |
| 9 | #error This driver requires coreboot |
| 10 | #endif |
| 11 | |
| 12 | #include <asm/arch/sysinfo.h> |
| 13 | |
| 14 | struct cbmem_console { |
| 15 | u32 buffer_size; |
| 16 | u32 buffer_cursor; |
| 17 | u8 buffer_body[0]; |
| 18 | } __attribute__ ((__packed__)); |
| 19 | |
| 20 | static struct cbmem_console *cbmem_console_p; |
| 21 | |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 22 | void cbmemc_putc(struct stdio_dev *dev, char data) |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 23 | { |
| 24 | int cursor; |
| 25 | |
| 26 | cursor = cbmem_console_p->buffer_cursor++; |
| 27 | if (cursor < cbmem_console_p->buffer_size) |
| 28 | cbmem_console_p->buffer_body[cursor] = data; |
| 29 | } |
| 30 | |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 31 | void cbmemc_puts(struct stdio_dev *dev, const char *str) |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 32 | { |
| 33 | char c; |
| 34 | |
| 35 | while ((c = *str++) != 0) |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 36 | cbmemc_putc(dev, c); |
Vadim Bendebury | e53e53b | 2012-10-12 18:48:48 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | int cbmemc_init(void) |
| 40 | { |
| 41 | int rc; |
| 42 | struct stdio_dev cons_dev; |
| 43 | cbmem_console_p = lib_sysinfo.cbmem_cons; |
| 44 | |
| 45 | memset(&cons_dev, 0, sizeof(cons_dev)); |
| 46 | |
| 47 | strcpy(cons_dev.name, "cbmem"); |
| 48 | cons_dev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 49 | cons_dev.putc = cbmemc_putc; |
| 50 | cons_dev.puts = cbmemc_puts; |
| 51 | |
| 52 | rc = stdio_register(&cons_dev); |
| 53 | |
| 54 | return (rc == 0) ? 1 : rc; |
| 55 | } |