memconsole.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
  23. static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
  24. struct bin_attribute *bin_attr, char *buf,
  25. loff_t pos, size_t count)
  26. {
  27. if (WARN_ON_ONCE(!memconsole_read_func))
  28. return -EIO;
  29. return memconsole_read_func(buf, pos, count);
  30. }
  31. static struct bin_attribute memconsole_bin_attr = {
  32. .attr = {.name = "log", .mode = 0444},
  33. .read = memconsole_read,
  34. };
  35. void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
  36. {
  37. memconsole_read_func = read_func;
  38. }
  39. EXPORT_SYMBOL(memconsole_setup);
  40. int memconsole_sysfs_init(void)
  41. {
  42. return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
  43. }
  44. EXPORT_SYMBOL(memconsole_sysfs_init);
  45. void memconsole_exit(void)
  46. {
  47. sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
  48. }
  49. EXPORT_SYMBOL(memconsole_exit);
  50. MODULE_AUTHOR("Google, Inc.");
  51. MODULE_LICENSE("GPL");