cbmem_console.c 1.6 KB

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