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 static ssize_t
show_version(struct device
*dev
,
19 struct device_attribute
*attr
, char *buf
)
21 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
.version
);
23 static DEVICE_ATTR(version
, S_IRUGO
, show_version
, NULL
);
25 static ssize_t
show_status(struct device
*dev
,
26 struct device_attribute
*attr
, char *buf
)
28 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
.status
);
30 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
32 static ssize_t
show_type(struct device
*dev
,
33 struct device_attribute
*attr
, char *buf
)
35 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
.image_type
);
37 static DEVICE_ATTR(type
, S_IRUGO
, show_type
, NULL
);
39 static ssize_t
show_xoffset(struct device
*dev
,
40 struct device_attribute
*attr
, char *buf
)
42 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
.image_offset_x
);
44 static DEVICE_ATTR(xoffset
, S_IRUGO
, show_xoffset
, NULL
);
46 static ssize_t
show_yoffset(struct device
*dev
,
47 struct device_attribute
*attr
, char *buf
)
49 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
.image_offset_y
);
51 static DEVICE_ATTR(yoffset
, S_IRUGO
, show_yoffset
, NULL
);
53 static ssize_t
image_read(struct file
*file
, struct kobject
*kobj
,
54 struct bin_attribute
*attr
, char *buf
, loff_t off
, size_t count
)
56 memcpy(buf
, attr
->private + off
, count
);
60 static BIN_ATTR_RO(image
, 0); /* size gets filled in later */
62 static struct attribute
*bgrt_attributes
[] = {
63 &dev_attr_version
.attr
,
64 &dev_attr_status
.attr
,
66 &dev_attr_xoffset
.attr
,
67 &dev_attr_yoffset
.attr
,
71 static struct bin_attribute
*bgrt_bin_attributes
[] = {
76 static const struct attribute_group bgrt_attribute_group
= {
77 .attrs
= bgrt_attributes
,
78 .bin_attrs
= bgrt_bin_attributes
,
81 int __init
acpi_parse_bgrt(struct acpi_table_header
*table
)
87 static int __init
bgrt_init(void)
91 if (!bgrt_tab
.image_address
)
94 bgrt_image
= memremap(bgrt_tab
.image_address
, bgrt_image_size
,
97 pr_notice("Ignoring BGRT: failed to map image memory\n");
101 bin_attr_image
.private = bgrt_image
;
102 bin_attr_image
.size
= bgrt_image_size
;
104 bgrt_kobj
= kobject_create_and_add("bgrt", acpi_kobj
);
110 ret
= sysfs_create_group(bgrt_kobj
, &bgrt_attribute_group
);
117 kobject_put(bgrt_kobj
);
119 memunmap(bgrt_image
);
122 device_initcall(bgrt_init
);