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