WIP FPC-III support
[linux/fpc-iii.git] / drivers / acpi / bgrt.c
blob251f961c28cc4c3cbe5883d987977edd84676a98
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 */
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);
57 return 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,
65 &dev_attr_type.attr,
66 &dev_attr_xoffset.attr,
67 &dev_attr_yoffset.attr,
68 NULL,
71 static struct bin_attribute *bgrt_bin_attributes[] = {
72 &bin_attr_image,
73 NULL,
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)
83 efi_bgrt_init(table);
84 return 0;
87 static int __init bgrt_init(void)
89 int ret;
91 if (!bgrt_tab.image_address)
92 return -ENODEV;
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;
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);
105 if (!bgrt_kobj) {
106 ret = -EINVAL;
107 goto out_memmap;
110 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
111 if (ret)
112 goto out_kobject;
114 return 0;
116 out_kobject:
117 kobject_put(bgrt_kobj);
118 out_memmap:
119 memunmap(bgrt_image);
120 return ret;
122 device_initcall(bgrt_init);