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