bgrt.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * BGRT boot graphic support
  4. * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
  5. * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
  6. * Copyright 2012 Intel Corporation
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/device.h>
  11. #include <linux/sysfs.h>
  12. #include <linux/efi-bgrt.h>
  13. static void *bgrt_image;
  14. static struct kobject *bgrt_kobj;
  15. #define BGRT_SHOW(_name, _member) \
  16. static ssize_t _name##_show(struct kobject *kobj, \
  17. struct kobj_attribute *attr, char *buf) \
  18. { \
  19. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab._member); \
  20. } \
  21. struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name)
  22. BGRT_SHOW(version, version);
  23. BGRT_SHOW(status, status);
  24. BGRT_SHOW(type, image_type);
  25. BGRT_SHOW(xoffset, image_offset_x);
  26. BGRT_SHOW(yoffset, image_offset_y);
  27. static ssize_t image_read(struct file *file, struct kobject *kobj,
  28. struct bin_attribute *attr, char *buf, loff_t off, size_t count)
  29. {
  30. memcpy(buf, attr->private + off, count);
  31. return count;
  32. }
  33. static BIN_ATTR_RO(image, 0); /* size gets filled in later */
  34. static struct attribute *bgrt_attributes[] = {
  35. &bgrt_attr_version.attr,
  36. &bgrt_attr_status.attr,
  37. &bgrt_attr_type.attr,
  38. &bgrt_attr_xoffset.attr,
  39. &bgrt_attr_yoffset.attr,
  40. NULL,
  41. };
  42. static struct bin_attribute *bgrt_bin_attributes[] = {
  43. &bin_attr_image,
  44. NULL,
  45. };
  46. static const struct attribute_group bgrt_attribute_group = {
  47. .attrs = bgrt_attributes,
  48. .bin_attrs = bgrt_bin_attributes,
  49. };
  50. int __init acpi_parse_bgrt(struct acpi_table_header *table)
  51. {
  52. efi_bgrt_init(table);
  53. return 0;
  54. }
  55. static int __init bgrt_init(void)
  56. {
  57. int ret;
  58. if (!bgrt_tab.image_address)
  59. return -ENODEV;
  60. bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
  61. MEMREMAP_WB);
  62. if (!bgrt_image) {
  63. pr_notice("Ignoring BGRT: failed to map image memory\n");
  64. return -ENOMEM;
  65. }
  66. bin_attr_image.private = bgrt_image;
  67. bin_attr_image.size = bgrt_image_size;
  68. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  69. if (!bgrt_kobj) {
  70. ret = -EINVAL;
  71. goto out_memmap;
  72. }
  73. ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  74. if (ret)
  75. goto out_kobject;
  76. return 0;
  77. out_kobject:
  78. kobject_put(bgrt_kobj);
  79. out_memmap:
  80. memunmap(bgrt_image);
  81. return ret;
  82. }
  83. device_initcall(bgrt_init);