memconsole.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * memconsole.c
  3. *
  4. * Architecture-independent parts of the memory based BIOS console.
  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/init.h>
  18. #include <linux/sysfs.h>
  19. #include <linux/kobject.h>
  20. #include <linux/module.h>
  21. #include "memconsole.h"
  22. static char *memconsole_baseaddr;
  23. static size_t memconsole_length;
  24. static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
  25. struct bin_attribute *bin_attr, char *buf,
  26. loff_t pos, size_t count)
  27. {
  28. return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr,
  29. memconsole_length);
  30. }
  31. static struct bin_attribute memconsole_bin_attr = {
  32. .attr = {.name = "log", .mode = 0444},
  33. .read = memconsole_read,
  34. };
  35. void memconsole_setup(void *baseaddr, size_t length)
  36. {
  37. memconsole_baseaddr = baseaddr;
  38. memconsole_length = length;
  39. }
  40. EXPORT_SYMBOL(memconsole_setup);
  41. int memconsole_sysfs_init(void)
  42. {
  43. memconsole_bin_attr.size = memconsole_length;
  44. return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
  45. }
  46. EXPORT_SYMBOL(memconsole_sysfs_init);
  47. void memconsole_exit(void)
  48. {
  49. sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
  50. }
  51. EXPORT_SYMBOL(memconsole_exit);
  52. MODULE_AUTHOR("Google, Inc.");
  53. MODULE_LICENSE("GPL");