bgrt.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 sysfs_emit(buf, "%d\n", bgrt_tab._member); \
  20. } \
  21. static 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 BIN_ATTR_SIMPLE_RO(image);
  28. static struct attribute *bgrt_attributes[] = {
  29. &bgrt_attr_version.attr,
  30. &bgrt_attr_status.attr,
  31. &bgrt_attr_type.attr,
  32. &bgrt_attr_xoffset.attr,
  33. &bgrt_attr_yoffset.attr,
  34. NULL,
  35. };
  36. static struct bin_attribute *bgrt_bin_attributes[] = {
  37. &bin_attr_image,
  38. NULL,
  39. };
  40. static const struct attribute_group bgrt_attribute_group = {
  41. .attrs = bgrt_attributes,
  42. .bin_attrs = bgrt_bin_attributes,
  43. };
  44. int __init acpi_parse_bgrt(struct acpi_table_header *table)
  45. {
  46. efi_bgrt_init(table);
  47. return 0;
  48. }
  49. static int __init bgrt_init(void)
  50. {
  51. int ret;
  52. if (!bgrt_tab.image_address)
  53. return -ENODEV;
  54. bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
  55. MEMREMAP_WB);
  56. if (!bgrt_image) {
  57. pr_notice("Ignoring BGRT: failed to map image memory\n");
  58. return -ENOMEM;
  59. }
  60. bin_attr_image.private = bgrt_image;
  61. bin_attr_image.size = bgrt_image_size;
  62. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  63. if (!bgrt_kobj) {
  64. ret = -EINVAL;
  65. goto out_memmap;
  66. }
  67. ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  68. if (ret)
  69. goto out_kobject;
  70. return 0;
  71. out_kobject:
  72. kobject_put(bgrt_kobj);
  73. out_memmap:
  74. memunmap(bgrt_image);
  75. return ret;
  76. }
  77. device_initcall(bgrt_init);