blob: 75af78361ce5bd72a1305b2318aa7f3b728c367c [file] [log] [blame]
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05001/*
Paul Gortmakercc079f82016-02-15 00:27:49 -05002 * BGRT boot graphic support
3 * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05004 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
Josh Triplett2223af32012-09-28 17:57:05 -07005 * Copyright 2012 Intel Corporation
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05006 *
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>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050013#include <linux/init.h>
14#include <linux/device.h>
15#include <linux/sysfs.h>
Josh Triplett2223af32012-09-28 17:57:05 -070016#include <linux/efi-bgrt.h>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050017
Dave Young7b0a9112017-01-31 13:21:40 +000018static void *bgrt_image;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050019static struct kobject *bgrt_kobj;
20
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050021static ssize_t show_version(struct device *dev,
22 struct device_attribute *attr, char *buf)
23{
Dave Young7b0a9112017-01-31 13:21:40 +000024 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.version);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050025}
26static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
27
28static ssize_t show_status(struct device *dev,
29 struct device_attribute *attr, char *buf)
30{
Dave Young7b0a9112017-01-31 13:21:40 +000031 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.status);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050032}
33static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
34
35static ssize_t show_type(struct device *dev,
36 struct device_attribute *attr, char *buf)
37{
Dave Young7b0a9112017-01-31 13:21:40 +000038 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_type);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050039}
40static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
41
42static ssize_t show_xoffset(struct device *dev,
43 struct device_attribute *attr, char *buf)
44{
Dave Young7b0a9112017-01-31 13:21:40 +000045 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_x);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050046}
47static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
48
49static ssize_t show_yoffset(struct device *dev,
50 struct device_attribute *attr, char *buf)
51{
Dave Young7b0a9112017-01-31 13:21:40 +000052 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab.image_offset_y);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050053}
54static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
55
Greg KH65f44672013-08-20 17:11:49 -070056static ssize_t image_read(struct file *file, struct kobject *kobj,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050057 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
58{
Josh Triplett2223af32012-09-28 17:57:05 -070059 memcpy(buf, attr->private + off, count);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050060 return count;
61}
62
Greg KH65f44672013-08-20 17:11:49 -070063static BIN_ATTR_RO(image, 0); /* size gets filled in later */
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050064
65static struct attribute *bgrt_attributes[] = {
66 &dev_attr_version.attr,
67 &dev_attr_status.attr,
68 &dev_attr_type.attr,
69 &dev_attr_xoffset.attr,
70 &dev_attr_yoffset.attr,
71 NULL,
72};
73
Greg KH65f44672013-08-20 17:11:49 -070074static struct bin_attribute *bgrt_bin_attributes[] = {
75 &bin_attr_image,
76 NULL,
77};
78
Arvind Yadav7e536262017-06-30 18:06:34 +053079static const struct attribute_group bgrt_attribute_group = {
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050080 .attrs = bgrt_attributes,
Greg KH65f44672013-08-20 17:11:49 -070081 .bin_attrs = bgrt_bin_attributes,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050082};
83
Bhupesh Sharma6e7300c2017-04-04 17:02:41 +010084int __init acpi_parse_bgrt(struct acpi_table_header *table)
85{
86 efi_bgrt_init(table);
87 return 0;
88}
89
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050090static int __init bgrt_init(void)
91{
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050092 int ret;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050093
Dave Young7b0a9112017-01-31 13:21:40 +000094 if (!bgrt_tab.image_address)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050095 return -ENODEV;
96
Dave Young7b0a9112017-01-31 13:21:40 +000097 bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
98 MEMREMAP_WB);
99 if (!bgrt_image) {
100 pr_notice("Ignoring BGRT: failed to map image memory\n");
101 return -ENOMEM;
102 }
103
Greg KH65f44672013-08-20 17:11:49 -0700104 bin_attr_image.private = bgrt_image;
105 bin_attr_image.size = bgrt_image_size;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500106
107 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +0000108 if (!bgrt_kobj) {
109 ret = -EINVAL;
110 goto out_memmap;
111 }
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500112
113 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
114 if (ret)
115 goto out_kobject;
116
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500117 return 0;
118
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500119out_kobject:
120 kobject_put(bgrt_kobj);
Dave Young7b0a9112017-01-31 13:21:40 +0000121out_memmap:
122 memunmap(bgrt_image);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500123 return ret;
124}
Paul Gortmakercc079f82016-02-15 00:27:49 -0500125device_initcall(bgrt_init);