memconsole-coreboot.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * memconsole-coreboot.c
  3. *
  4. * Memory based BIOS console accessed through coreboot table.
  5. *
  6. * Copyright 2017 Google Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License v2.0 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include "memconsole.h"
  21. #include "coreboot_table.h"
  22. #define CB_TAG_CBMEM_CONSOLE 0x17
  23. /* CBMEM firmware console log descriptor. */
  24. struct cbmem_cons {
  25. u32 buffer_size;
  26. u32 buffer_cursor;
  27. u8 buffer_body[0];
  28. } __packed;
  29. static struct cbmem_cons __iomem *cbmem_console;
  30. static int memconsole_coreboot_init(phys_addr_t physaddr)
  31. {
  32. struct cbmem_cons __iomem *tmp_cbmc;
  33. tmp_cbmc = memremap(physaddr, sizeof(*tmp_cbmc), MEMREMAP_WB);
  34. if (!tmp_cbmc)
  35. return -ENOMEM;
  36. cbmem_console = memremap(physaddr,
  37. tmp_cbmc->buffer_size + sizeof(*cbmem_console),
  38. MEMREMAP_WB);
  39. memunmap(tmp_cbmc);
  40. if (!cbmem_console)
  41. return -ENOMEM;
  42. memconsole_setup(cbmem_console->buffer_body,
  43. min(cbmem_console->buffer_cursor, cbmem_console->buffer_size));
  44. return 0;
  45. }
  46. static int memconsole_probe(struct platform_device *pdev)
  47. {
  48. int ret;
  49. struct lb_cbmem_ref entry;
  50. ret = coreboot_table_find(CB_TAG_CBMEM_CONSOLE, &entry, sizeof(entry));
  51. if (ret)
  52. return ret;
  53. ret = memconsole_coreboot_init(entry.cbmem_addr);
  54. if (ret)
  55. return ret;
  56. return memconsole_sysfs_init();
  57. }
  58. static int memconsole_remove(struct platform_device *pdev)
  59. {
  60. memconsole_exit();
  61. if (cbmem_console)
  62. memunmap(cbmem_console);
  63. return 0;
  64. }
  65. static struct platform_driver memconsole_driver = {
  66. .probe = memconsole_probe,
  67. .remove = memconsole_remove,
  68. .driver = {
  69. .name = "memconsole",
  70. },
  71. };
  72. static int __init platform_memconsole_init(void)
  73. {
  74. struct platform_device *pdev;
  75. pdev = platform_device_register_simple("memconsole", -1, NULL, 0);
  76. if (IS_ERR(pdev))
  77. return PTR_ERR(pdev);
  78. platform_driver_register(&memconsole_driver);
  79. return 0;
  80. }
  81. module_init(platform_memconsole_init);
  82. MODULE_AUTHOR("Google, Inc.");
  83. MODULE_LICENSE("GPL");