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