bgrt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 show_image(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 struct bin_attribute image_attr = {
  53. .attr = {
  54. .name = "image",
  55. .mode = S_IRUGO,
  56. },
  57. .read = show_image,
  58. };
  59. static struct attribute *bgrt_attributes[] = {
  60. &dev_attr_version.attr,
  61. &dev_attr_status.attr,
  62. &dev_attr_type.attr,
  63. &dev_attr_xoffset.attr,
  64. &dev_attr_yoffset.attr,
  65. NULL,
  66. };
  67. static struct attribute_group bgrt_attribute_group = {
  68. .attrs = bgrt_attributes,
  69. };
  70. static int __init bgrt_init(void)
  71. {
  72. int ret;
  73. if (!bgrt_image)
  74. return -ENODEV;
  75. sysfs_bin_attr_init(&image_attr);
  76. image_attr.private = bgrt_image;
  77. image_attr.size = bgrt_image_size;
  78. bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
  79. if (!bgrt_kobj)
  80. return -EINVAL;
  81. ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  82. if (ret)
  83. goto out_kobject;
  84. ret = sysfs_create_bin_file(bgrt_kobj, &image_attr);
  85. if (ret)
  86. goto out_group;
  87. return 0;
  88. out_group:
  89. sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group);
  90. out_kobject:
  91. kobject_put(bgrt_kobj);
  92. return ret;
  93. }
  94. module_init(bgrt_init);
  95. MODULE_AUTHOR("Matthew Garrett, Josh Triplett <josh@joshtriplett.org>");
  96. MODULE_DESCRIPTION("BGRT boot graphic support");
  97. MODULE_LICENSE("GPL");