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