blob: 251f961c28cc4c3cbe5883d987977edd84676a98 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05002/*
Paul Gortmakercc079f82016-02-15 00:27:49 -05003 * BGRT boot graphic support
4 * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05005 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
Josh Triplett2223af32012-09-28 17:57:05 -07006 * Copyright 2012 Intel Corporation
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05007 */
8
9#include <linux/kernel.h>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050010#include <linux/init.h>
11#include <linux/device.h>
12#include <linux/sysfs.h>
Josh Triplett2223af32012-09-28 17:57:05 -070013#include <linux/efi-bgrt.h>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050014
Dave Young7b0a9112017-01-31 13:21:40 +000015static void *bgrt_image;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050016static struct kobject *bgrt_kobj;
17
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050018static ssize_t show_version(struct device *dev,
19 struct device_attribute *attr, char *buf)
20{
Dave Young7b0a9112017-01-31 13:21:40 +000021 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050022}
23static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
24
25static ssize_t show_status(struct device *dev,
26 struct device_attribute *attr, char *buf)
27{
Dave Young7b0a9112017-01-31 13:21:40 +000028 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050029}
30static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
31
32static ssize_t show_type(struct device *dev,
33 struct device_attribute *attr, char *buf)
34{
Dave Young7b0a9112017-01-31 13:21:40 +000035 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050036}
37static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
38
39static ssize_t show_xoffset(struct device *dev,
40 struct device_attribute *attr, char *buf)
41{
Dave Young7b0a9112017-01-31 13:21:40 +000042 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050043}
44static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
45
46static ssize_t show_yoffset(struct device *dev,
47 struct device_attribute *attr, char *buf)
48{
Dave Young7b0a9112017-01-31 13:21:40 +000049 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050050}
51static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
52
Greg KH65f44672013-08-20 17:11:49 -070053static ssize_t image_read(struct file *file, struct kobject *kobj,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050054 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
55{
Josh Triplett2223af32012-09-28 17:57:05 -070056 memcpy(buf, attr->private + off, count);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050057 return count;
58}
59
Greg KH65f44672013-08-20 17:11:49 -070060static BIN_ATTR_RO(image, 0); /* size gets filled in later */
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050061
62static 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 KH65f44672013-08-20 17:11:49 -070071static struct bin_attribute *bgrt_bin_attributes[] = {
72 &bin_attr_image,
73 NULL,
74};
75
Arvind Yadav7e536262017-06-30 18:06:34 +053076static const struct attribute_group bgrt_attribute_group = {
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050077 .attrs = bgrt_attributes,
Greg KH65f44672013-08-20 17:11:49 -070078 .bin_attrs = bgrt_bin_attributes,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050079};
80
Bhupesh Sharma6e7300c2017-04-04 17:02:41 +010081int __init acpi_parse_bgrt(struct acpi_table_header *table)
82{
83 efi_bgrt_init(table);
84 return 0;
85}
86
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050087static int __init bgrt_init(void)
88{
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050089 int ret;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050090
Dave Young7b0a9112017-01-31 13:21:40 +000091 if (!bgrt_tab.image_address)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050092 return -ENODEV;
93
Dave Young7b0a9112017-01-31 13:21:40 +000094 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 KH65f44672013-08-20 17:11:49 -0700101 bin_attr_image.private = bgrt_image;
102 bin_attr_image.size = bgrt_image_size;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500103
104 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +0000105 if (!bgrt_kobj) {
106 ret = -EINVAL;
107 goto out_memmap;
108 }
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500109
110 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
111 if (ret)
112 goto out_kobject;
113
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500114 return 0;
115
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500116out_kobject:
117 kobject_put(bgrt_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +0000118out_memmap:
119 memunmap(bgrt_image);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500120 return ret;
121}
Paul Gortmakercc079f82016-02-15 00:27:49 -0500122device_initcall(bgrt_init);