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