bgrt.c 2.7 KB

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