Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Red Hat, Inc <mjg@redhat.com> |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 3 | * Copyright 2012 Intel Corporation |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 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 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/sysfs.h> |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 15 | #include <linux/efi-bgrt.h> |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 16 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 17 | static struct kobject *bgrt_kobj; |
| 18 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 19 | static ssize_t show_version(struct device *dev, |
| 20 | struct device_attribute *attr, char *buf) |
| 21 | { |
| 22 | return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version); |
| 23 | } |
| 24 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); |
| 25 | |
| 26 | static ssize_t show_status(struct device *dev, |
| 27 | struct device_attribute *attr, char *buf) |
| 28 | { |
| 29 | return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status); |
| 30 | } |
| 31 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 32 | |
| 33 | static ssize_t show_type(struct device *dev, |
| 34 | struct device_attribute *attr, char *buf) |
| 35 | { |
| 36 | return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type); |
| 37 | } |
| 38 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); |
| 39 | |
| 40 | static ssize_t show_xoffset(struct device *dev, |
| 41 | struct device_attribute *attr, char *buf) |
| 42 | { |
| 43 | return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x); |
| 44 | } |
| 45 | static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL); |
| 46 | |
| 47 | static ssize_t show_yoffset(struct device *dev, |
| 48 | struct device_attribute *attr, char *buf) |
| 49 | { |
| 50 | return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y); |
| 51 | } |
| 52 | static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL); |
| 53 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 54 | static ssize_t image_read(struct file *file, struct kobject *kobj, |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 55 | struct bin_attribute *attr, char *buf, loff_t off, size_t count) |
| 56 | { |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 57 | memcpy(buf, attr->private + off, count); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 58 | return count; |
| 59 | } |
| 60 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 61 | static BIN_ATTR_RO(image, 0); /* size gets filled in later */ |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 62 | |
| 63 | static struct attribute *bgrt_attributes[] = { |
| 64 | &dev_attr_version.attr, |
| 65 | &dev_attr_status.attr, |
| 66 | &dev_attr_type.attr, |
| 67 | &dev_attr_xoffset.attr, |
| 68 | &dev_attr_yoffset.attr, |
| 69 | NULL, |
| 70 | }; |
| 71 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 72 | static struct bin_attribute *bgrt_bin_attributes[] = { |
| 73 | &bin_attr_image, |
| 74 | NULL, |
| 75 | }; |
| 76 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 77 | static struct attribute_group bgrt_attribute_group = { |
| 78 | .attrs = bgrt_attributes, |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 79 | .bin_attrs = bgrt_bin_attributes, |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static int __init bgrt_init(void) |
| 83 | { |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 84 | int ret; |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 85 | |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 86 | if (!bgrt_image) |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 87 | return -ENODEV; |
| 88 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 89 | bin_attr_image.private = bgrt_image; |
| 90 | bin_attr_image.size = bgrt_image_size; |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 91 | |
| 92 | bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 93 | if (!bgrt_kobj) |
| 94 | return -EINVAL; |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 95 | |
| 96 | ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group); |
| 97 | if (ret) |
| 98 | goto out_kobject; |
| 99 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 100 | return 0; |
| 101 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 102 | out_kobject: |
| 103 | kobject_put(bgrt_kobj); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 104 | return ret; |
| 105 | } |
| 106 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 107 | module_init(bgrt_init); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 108 | |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 109 | MODULE_AUTHOR("Matthew Garrett, Josh Triplett <josh@joshtriplett.org>"); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 110 | MODULE_DESCRIPTION("BGRT boot graphic support"); |
| 111 | MODULE_LICENSE("GPL"); |