Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
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
7 */
8
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>
14
15static void *bgrt_image;
16static struct kobject *bgrt_kobj;
17
18static ssize_t show_version(struct device *dev,
19 struct device_attribute *attr, char *buf)
20{
21 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
22}
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{
28 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
29}
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{
35 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
36}
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{
42 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
43}
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{
49 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
50}
51static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
52
53static ssize_t image_read(struct file *file, struct kobject *kobj,
54 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
55{
56 memcpy(buf, attr->private + off, count);
57 return count;
58}
59
60static BIN_ATTR_RO(image, 0); /* size gets filled in later */
61
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
71static struct bin_attribute *bgrt_bin_attributes[] = {
72 &bin_attr_image,
73 NULL,
74};
75
76static const struct attribute_group bgrt_attribute_group = {
77 .attrs = bgrt_attributes,
78 .bin_attrs = bgrt_bin_attributes,
79};
80
81int __init acpi_parse_bgrt(struct acpi_table_header *table)
82{
83 efi_bgrt_init(table);
84 return 0;
85}
86
87static int __init bgrt_init(void)
88{
89 int ret;
90
91 if (!bgrt_tab.image_address)
92 return -ENODEV;
93
94 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
101 bin_attr_image.private = bgrt_image;
102 bin_attr_image.size = bgrt_image_size;
103
104 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
105 if (!bgrt_kobj) {
106 ret = -EINVAL;
107 goto out_memmap;
108 }
109
110 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
111 if (ret)
112 goto out_kobject;
113
114 return 0;
115
116out_kobject:
117 kobject_put(bgrt_kobj);
118out_memmap:
119 memunmap(bgrt_image);
120 return ret;
121}
122device_initcall(bgrt_init);
1/*
2 * BGRT boot graphic support
3 * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
4 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
5 * Copyright 2012 Intel Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/device.h>
15#include <linux/sysfs.h>
16#include <linux/efi-bgrt.h>
17
18static struct kobject *bgrt_kobj;
19
20static ssize_t show_version(struct device *dev,
21 struct device_attribute *attr, char *buf)
22{
23 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
24}
25static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
26
27static ssize_t show_status(struct device *dev,
28 struct device_attribute *attr, char *buf)
29{
30 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
31}
32static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
33
34static ssize_t show_type(struct device *dev,
35 struct device_attribute *attr, char *buf)
36{
37 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
38}
39static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
40
41static ssize_t show_xoffset(struct device *dev,
42 struct device_attribute *attr, char *buf)
43{
44 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
45}
46static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
47
48static ssize_t show_yoffset(struct device *dev,
49 struct device_attribute *attr, char *buf)
50{
51 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
52}
53static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
54
55static ssize_t image_read(struct file *file, struct kobject *kobj,
56 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
57{
58 memcpy(buf, attr->private + off, count);
59 return count;
60}
61
62static BIN_ATTR_RO(image, 0); /* size gets filled in later */
63
64static struct attribute *bgrt_attributes[] = {
65 &dev_attr_version.attr,
66 &dev_attr_status.attr,
67 &dev_attr_type.attr,
68 &dev_attr_xoffset.attr,
69 &dev_attr_yoffset.attr,
70 NULL,
71};
72
73static struct bin_attribute *bgrt_bin_attributes[] = {
74 &bin_attr_image,
75 NULL,
76};
77
78static struct attribute_group bgrt_attribute_group = {
79 .attrs = bgrt_attributes,
80 .bin_attrs = bgrt_bin_attributes,
81};
82
83static int __init bgrt_init(void)
84{
85 int ret;
86
87 if (!bgrt_image)
88 return -ENODEV;
89
90 bin_attr_image.private = bgrt_image;
91 bin_attr_image.size = bgrt_image_size;
92
93 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
94 if (!bgrt_kobj)
95 return -EINVAL;
96
97 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
98 if (ret)
99 goto out_kobject;
100
101 return 0;
102
103out_kobject:
104 kobject_put(bgrt_kobj);
105 return ret;
106}
107device_initcall(bgrt_init);