bgrt.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * BGRT boot graphic support
  3. * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
  4. * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
  5. * Copyright 2012 Intel Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/sysfs.h>
  15. #include <linux/efi-bgrt.h>
  16. static void *bgrt_image;
  17. static struct kobject *bgrt_kobj;
  18. static ssize_t show_version(struct device *dev,
  19. struct device_attribute *attr, char *buf)
  20. {
  21. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
  22. }
  23. static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  24. static ssize_t show_status(struct device *dev,
  25. struct device_attribute *attr, char *buf)
  26. {
  27. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
  28. }
  29. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  30. static ssize_t show_type(struct device *dev,
  31. struct device_attribute *attr, char *buf)
  32. {
  33. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
  34. }
  35. static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
  36. static ssize_t show_xoffset(struct device *dev,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
  40. }
  41. static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
  42. static ssize_t show_yoffset(struct device *dev,
  43. struct device_attribute *attr, char *buf)
  44. {
  45. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
  46. }
  47. static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
  48. static ssize_t image_read(struct file *file, struct kobject *kobj,
  49. struct bin_attribute *attr, char *buf, loff_t off, size_t count)
  50. {
  51. memcpy(buf, attr->private + off, count);
  52. return count;
  53. }
  54. static BIN_ATTR_RO(image, 0); /* size gets filled in later */
  55. static struct attribute *bgrt_attributes[] = {
  56. &dev_attr_version.attr,
  57. &dev_attr_status.attr,
  58. &dev_attr_type.attr,
  59. &dev_attr_xoffset.attr,
  60. &dev_attr_yoffset.attr,
  61. NULL,
  62. };
  63. static struct bin_attribute *bgrt_bin_attributes[] = {
  64. &bin_attr_image,
  65. NULL,
  66. };
  67. static const struct attribute_group bgrt_attribute_group = {
  68. .attrs = bgrt_attributes,
  69. .bin_attrs = bgrt_bin_attributes,
  70. };
  71. int __init acpi_parse_bgrt(struct acpi_table_header *table)
  72. {
  73. efi_bgrt_init(table);
  74. return 0;
  75. }
  76. static int __init bgrt_init(void)
  77. {
  78. int ret;
  79. if (!bgrt_tab.image_address)
  80. return -ENODEV;
  81. bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
  82. MEMREMAP_WB);
  83. if (!bgrt_image) {
  84. pr_notice("Ignoring BGRT: failed to map image memory\n");
  85. return -ENOMEM;
  86. }
  87. bin_attr_image.private = bgrt_image;
  88. bin_attr_image.size = bgrt_image_size;
  89. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  90. if (!bgrt_kobj) {
  91. ret = -EINVAL;
  92. goto out_memmap;
  93. }
  94. ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  95. if (ret)
  96. goto out_kobject;
  97. return 0;
  98. out_kobject:
  99. kobject_put(bgrt_kobj);
  100. out_memmap:
  101. memunmap(bgrt_image);
  102. return ret;
  103. }
  104. device_initcall(bgrt_init);