bgrt.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * BGRT boot graphic support
  3. * Authors: Matthew Garrett, Josh Triplett <[email protected]>
  4. * Copyright 2012 Red Hat, Inc <[email protected]>
  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 struct kobject *bgrt_kobj;
  17. static ssize_t show_version(struct device *dev,
  18. struct device_attribute *attr, char *buf)
  19. {
  20. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
  21. }
  22. static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  23. static ssize_t show_status(struct device *dev,
  24. struct device_attribute *attr, char *buf)
  25. {
  26. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
  27. }
  28. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  29. static ssize_t show_type(struct device *dev,
  30. struct device_attribute *attr, char *buf)
  31. {
  32. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
  33. }
  34. static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
  35. static ssize_t show_xoffset(struct device *dev,
  36. struct device_attribute *attr, char *buf)
  37. {
  38. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
  39. }
  40. static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
  41. static ssize_t show_yoffset(struct device *dev,
  42. struct device_attribute *attr, char *buf)
  43. {
  44. return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
  45. }
  46. static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
  47. static ssize_t image_read(struct file *file, struct kobject *kobj,
  48. struct bin_attribute *attr, char *buf, loff_t off, size_t count)
  49. {
  50. memcpy(buf, attr->private + off, count);
  51. return count;
  52. }
  53. static BIN_ATTR_RO(image, 0); /* size gets filled in later */
  54. static struct attribute *bgrt_attributes[] = {
  55. &dev_attr_version.attr,
  56. &dev_attr_status.attr,
  57. &dev_attr_type.attr,
  58. &dev_attr_xoffset.attr,
  59. &dev_attr_yoffset.attr,
  60. NULL,
  61. };
  62. static struct bin_attribute *bgrt_bin_attributes[] = {
  63. &bin_attr_image,
  64. NULL,
  65. };
  66. static struct attribute_group bgrt_attribute_group = {
  67. .attrs = bgrt_attributes,
  68. .bin_attrs = bgrt_bin_attributes,
  69. };
  70. static int __init bgrt_init(void)
  71. {
  72. int ret;
  73. if (!bgrt_image)
  74. return -ENODEV;
  75. bin_attr_image.private = bgrt_image;
  76. bin_attr_image.size = bgrt_image_size;
  77. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  78. if (!bgrt_kobj)
  79. return -EINVAL;
  80. ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  81. if (ret)
  82. goto out_kobject;
  83. return 0;
  84. out_kobject:
  85. kobject_put(bgrt_kobj);
  86. return ret;
  87. }
  88. device_initcall(bgrt_init);