1b012bc94SVadim Bendebury /* 2b012bc94SVadim Bendebury * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. 3b012bc94SVadim Bendebury * 4b012bc94SVadim Bendebury * This program is free software; you can redistribute it and/or modify 5b012bc94SVadim Bendebury * it under the terms of the GNU General Public License as published by 6b012bc94SVadim Bendebury * the Free Software Foundation; version 2 of the License. 7b012bc94SVadim Bendebury * 8b012bc94SVadim Bendebury * This program is distributed in the hope that it will be useful, 9b012bc94SVadim Bendebury * but WITHOUT ANY WARRANTY; without even the implied warranty of 10b012bc94SVadim Bendebury * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11b012bc94SVadim Bendebury * GNU General Public License for more details. 12b012bc94SVadim Bendebury * 13b012bc94SVadim Bendebury * You should have received a copy of the GNU General Public License 14b012bc94SVadim Bendebury * along with this program; if not, write to the Free Software 15b012bc94SVadim Bendebury * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA 16b012bc94SVadim Bendebury */ 17b012bc94SVadim Bendebury 18b012bc94SVadim Bendebury #include <common.h> 19b012bc94SVadim Bendebury 20b012bc94SVadim Bendebury #ifndef CONFIG_SYS_COREBOOT 21b012bc94SVadim Bendebury #error This driver requires coreboot 22b012bc94SVadim Bendebury #endif 23b012bc94SVadim Bendebury 24b012bc94SVadim Bendebury #include <asm/arch/sysinfo.h> 25b012bc94SVadim Bendebury 26b012bc94SVadim Bendebury struct cbmem_console { 27b012bc94SVadim Bendebury u32 buffer_size; 28b012bc94SVadim Bendebury u32 buffer_cursor; 29b012bc94SVadim Bendebury u8 buffer_body[0]; 30b012bc94SVadim Bendebury } __attribute__ ((__packed__)); 31b012bc94SVadim Bendebury 32b012bc94SVadim Bendebury static struct cbmem_console *cbmem_console_p; 33b012bc94SVadim Bendebury 34*709ea543SSimon Glass void cbmemc_putc(struct stdio_dev *dev, char data) 35b012bc94SVadim Bendebury { 36b012bc94SVadim Bendebury int cursor; 37b012bc94SVadim Bendebury 38b012bc94SVadim Bendebury cursor = cbmem_console_p->buffer_cursor++; 39b012bc94SVadim Bendebury if (cursor < cbmem_console_p->buffer_size) 40b012bc94SVadim Bendebury cbmem_console_p->buffer_body[cursor] = data; 41b012bc94SVadim Bendebury } 42b012bc94SVadim Bendebury 43*709ea543SSimon Glass void cbmemc_puts(struct stdio_dev *dev, const char *str) 44b012bc94SVadim Bendebury { 45b012bc94SVadim Bendebury char c; 46b012bc94SVadim Bendebury 47b012bc94SVadim Bendebury while ((c = *str++) != 0) 48*709ea543SSimon Glass cbmemc_putc(dev, c); 49b012bc94SVadim Bendebury } 50b012bc94SVadim Bendebury 51b012bc94SVadim Bendebury int cbmemc_init(void) 52b012bc94SVadim Bendebury { 53b012bc94SVadim Bendebury int rc; 54b012bc94SVadim Bendebury struct stdio_dev cons_dev; 55b012bc94SVadim Bendebury cbmem_console_p = lib_sysinfo.cbmem_cons; 56b012bc94SVadim Bendebury 57b012bc94SVadim Bendebury memset(&cons_dev, 0, sizeof(cons_dev)); 58b012bc94SVadim Bendebury 59b012bc94SVadim Bendebury strcpy(cons_dev.name, "cbmem"); 60b012bc94SVadim Bendebury cons_dev.flags = DEV_FLAGS_OUTPUT; /* Output only */ 61b012bc94SVadim Bendebury cons_dev.putc = cbmemc_putc; 62b012bc94SVadim Bendebury cons_dev.puts = cbmemc_puts; 63b012bc94SVadim Bendebury 64b012bc94SVadim Bendebury rc = stdio_register(&cons_dev); 65b012bc94SVadim Bendebury 66b012bc94SVadim Bendebury return (rc == 0) ? 1 : rc; 67b012bc94SVadim Bendebury } 68