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 | |
Nathan Chancellor | f37ccf8 | 2021-06-22 18:38:01 -0700 | [diff] [blame] | 18 | #define BGRT_SHOW(_name, _member) \ |
| 19 | static ssize_t _name##_show(struct kobject *kobj, \ |
| 20 | struct kobj_attribute *attr, char *buf) \ |
| 21 | { \ |
Nathan Chancellor | 6554ca9 | 2021-06-22 18:38:02 -0700 | [diff] [blame] | 22 | return sysfs_emit(buf, "%d\n", bgrt_tab._member); \ |
Nathan Chancellor | f37ccf8 | 2021-06-22 18:38:01 -0700 | [diff] [blame] | 23 | } \ |
| 24 | struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name) |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 25 | |
Nathan Chancellor | f37ccf8 | 2021-06-22 18:38:01 -0700 | [diff] [blame] | 26 | BGRT_SHOW(version, version); |
| 27 | BGRT_SHOW(status, status); |
| 28 | BGRT_SHOW(type, image_type); |
| 29 | BGRT_SHOW(xoffset, image_offset_x); |
| 30 | BGRT_SHOW(yoffset, image_offset_y); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 31 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 32 | static ssize_t image_read(struct file *file, struct kobject *kobj, |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 33 | struct bin_attribute *attr, char *buf, loff_t off, size_t count) |
| 34 | { |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 35 | memcpy(buf, attr->private + off, count); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 36 | return count; |
| 37 | } |
| 38 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 39 | static BIN_ATTR_RO(image, 0); /* size gets filled in later */ |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 40 | |
| 41 | static struct attribute *bgrt_attributes[] = { |
Nathan Chancellor | f37ccf8 | 2021-06-22 18:38:01 -0700 | [diff] [blame] | 42 | &bgrt_attr_version.attr, |
| 43 | &bgrt_attr_status.attr, |
| 44 | &bgrt_attr_type.attr, |
| 45 | &bgrt_attr_xoffset.attr, |
| 46 | &bgrt_attr_yoffset.attr, |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 47 | NULL, |
| 48 | }; |
| 49 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 50 | static struct bin_attribute *bgrt_bin_attributes[] = { |
| 51 | &bin_attr_image, |
| 52 | NULL, |
| 53 | }; |
| 54 | |
Arvind Yadav | 7e53626 | 2017-06-30 18:06:34 +0530 | [diff] [blame] | 55 | static const struct attribute_group bgrt_attribute_group = { |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 56 | .attrs = bgrt_attributes, |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 57 | .bin_attrs = bgrt_bin_attributes, |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
Bhupesh Sharma | 6e7300c | 2017-04-04 17:02:41 +0100 | [diff] [blame] | 60 | int __init acpi_parse_bgrt(struct acpi_table_header *table) |
| 61 | { |
| 62 | efi_bgrt_init(table); |
| 63 | return 0; |
| 64 | } |
| 65 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 66 | static int __init bgrt_init(void) |
| 67 | { |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 68 | int ret; |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 69 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 70 | if (!bgrt_tab.image_address) |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 71 | return -ENODEV; |
| 72 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 73 | bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size, |
| 74 | MEMREMAP_WB); |
| 75 | if (!bgrt_image) { |
| 76 | pr_notice("Ignoring BGRT: failed to map image memory\n"); |
| 77 | return -ENOMEM; |
| 78 | } |
| 79 | |
Greg KH | 65f4467 | 2013-08-20 17:11:49 -0700 | [diff] [blame] | 80 | bin_attr_image.private = bgrt_image; |
| 81 | bin_attr_image.size = bgrt_image_size; |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 82 | |
| 83 | bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 84 | if (!bgrt_kobj) { |
| 85 | ret = -EINVAL; |
| 86 | goto out_memmap; |
| 87 | } |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 88 | |
| 89 | ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group); |
| 90 | if (ret) |
| 91 | goto out_kobject; |
| 92 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 93 | return 0; |
| 94 | |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 95 | out_kobject: |
| 96 | kobject_put(bgrt_kobj); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 97 | out_memmap: |
| 98 | memunmap(bgrt_image); |
Matthew Garrett | d1ff4b1 | 2012-01-31 13:19:20 -0500 | [diff] [blame] | 99 | return ret; |
| 100 | } |
Paul Gortmaker | cc079f8 | 2016-02-15 00:27:49 -0500 | [diff] [blame] | 101 | device_initcall(bgrt_init); |