1 // SPDX-License-Identifier: GPL-2.0-only
3 * BGRT boot graphic support
4 * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
5 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
6 * Copyright 2012 Intel Corporation
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/device.h>
12 #include <linux/sysfs.h>
13 #include <linux/efi-bgrt.h>
15 static void *bgrt_image;
16 static struct kobject *bgrt_kobj;
18 #define BGRT_SHOW(_name, _member) \
19 static ssize_t _name##_show(struct kobject *kobj, \
20 struct kobj_attribute *attr, char *buf) \
22 return sysfs_emit(buf, "%d\n", bgrt_tab._member); \
24 static struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name)
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);
32 static ssize_t image_read(struct file *file, struct kobject *kobj,
33 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
35 memcpy(buf, attr->private + off, count);
39 static BIN_ATTR_RO(image, 0); /* size gets filled in later */
41 static struct attribute *bgrt_attributes[] = {
42 &bgrt_attr_version.attr,
43 &bgrt_attr_status.attr,
45 &bgrt_attr_xoffset.attr,
46 &bgrt_attr_yoffset.attr,
50 static struct bin_attribute *bgrt_bin_attributes[] = {
55 static const struct attribute_group bgrt_attribute_group = {
56 .attrs = bgrt_attributes,
57 .bin_attrs = bgrt_bin_attributes,
60 int __init acpi_parse_bgrt(struct acpi_table_header *table)
66 static int __init bgrt_init(void)
70 if (!bgrt_tab.image_address)
73 bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
76 pr_notice("Ignoring BGRT: failed to map image memory\n");
80 bin_attr_image.private = bgrt_image;
81 bin_attr_image.size = bgrt_image_size;
83 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
89 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
96 kobject_put(bgrt_kobj);
101 device_initcall(bgrt_init);