This source file includes following definitions.
- show_version
- show_status
- show_type
- show_xoffset
- show_yoffset
- image_read
- acpi_parse_bgrt
- bgrt_init
1
2
3
4
5
6
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
15 static void *bgrt_image;
16 static struct kobject *bgrt_kobj;
17
18 static 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 }
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 {
28 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
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 {
35 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
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 {
42 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
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 {
49 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
50 }
51 static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
52
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)
55 {
56 memcpy(buf, attr->private + off, count);
57 return count;
58 }
59
60 static BIN_ATTR_RO(image, 0);
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
71 static struct bin_attribute *bgrt_bin_attributes[] = {
72 &bin_attr_image,
73 NULL,
74 };
75
76 static const struct attribute_group bgrt_attribute_group = {
77 .attrs = bgrt_attributes,
78 .bin_attrs = bgrt_bin_attributes,
79 };
80
81 int __init acpi_parse_bgrt(struct acpi_table_header *table)
82 {
83 efi_bgrt_init(table);
84 return 0;
85 }
86
87 static 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
116 out_kobject:
117 kobject_put(bgrt_kobj);
118 out_memmap:
119 memunmap(bgrt_image);
120 return ret;
121 }
122 device_initcall(bgrt_init);