blob: 02d208732f9a3e0b8cbdb09ea30783bdbc9417e4 [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
Nathan Chancellorf37ccf82021-06-22 18:38:01 -070018#define BGRT_SHOW(_name, _member) \
19 static ssize_t _name##_show(struct kobject *kobj, \
20 struct kobj_attribute *attr, char *buf) \
21 { \
Nathan Chancellor6554ca92021-06-22 18:38:02 -070022 return sysfs_emit(buf, "%d\n", bgrt_tab._member); \
Nathan Chancellorf37ccf82021-06-22 18:38:01 -070023 } \
24 struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050025
Nathan Chancellorf37ccf82021-06-22 18:38:01 -070026BGRT_SHOW(version, version);
27BGRT_SHOW(status, status);
28BGRT_SHOW(type, image_type);
29BGRT_SHOW(xoffset, image_offset_x);
30BGRT_SHOW(yoffset, image_offset_y);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050031
Greg KH65f44672013-08-20 17:11:49 -070032static ssize_t image_read(struct file *file, struct kobject *kobj,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050033 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
34{
Josh Triplett2223af32012-09-28 17:57:05 -070035 memcpy(buf, attr->private + off, count);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050036 return count;
37}
38
Greg KH65f44672013-08-20 17:11:49 -070039static BIN_ATTR_RO(image, 0); /* size gets filled in later */
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050040
41static struct attribute *bgrt_attributes[] = {
Nathan Chancellorf37ccf82021-06-22 18:38:01 -070042 &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 Garrettd1ff4b12012-01-31 13:19:20 -050047 NULL,
48};
49
Greg KH65f44672013-08-20 17:11:49 -070050static struct bin_attribute *bgrt_bin_attributes[] = {
51 &bin_attr_image,
52 NULL,
53};
54
Arvind Yadav7e536262017-06-30 18:06:34 +053055static const struct attribute_group bgrt_attribute_group = {
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050056 .attrs = bgrt_attributes,
Greg KH65f44672013-08-20 17:11:49 -070057 .bin_attrs = bgrt_bin_attributes,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050058};
59
Bhupesh Sharma6e7300c2017-04-04 17:02:41 +010060int __init acpi_parse_bgrt(struct acpi_table_header *table)
61{
62 efi_bgrt_init(table);
63 return 0;
64}
65
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050066static int __init bgrt_init(void)
67{
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050068 int ret;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050069
Dave Young7b0a9112017-01-31 13:21:40 +000070 if (!bgrt_tab.image_address)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050071 return -ENODEV;
72
Dave Young7b0a9112017-01-31 13:21:40 +000073 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 KH65f44672013-08-20 17:11:49 -070080 bin_attr_image.private = bgrt_image;
81 bin_attr_image.size = bgrt_image_size;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050082
83 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +000084 if (!bgrt_kobj) {
85 ret = -EINVAL;
86 goto out_memmap;
87 }
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050088
89 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
90 if (ret)
91 goto out_kobject;
92
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050093 return 0;
94
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050095out_kobject:
96 kobject_put(bgrt_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +000097out_memmap:
98 memunmap(bgrt_image);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050099 return ret;
100}
Paul Gortmakercc079f82016-02-15 00:27:49 -0500101device_initcall(bgrt_init);