blob: 75f128e766a979e38a3a91ca00ec8fbde5b686dc [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
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050018static struct kobject *bgrt_kobj;
19
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050020static ssize_t show_version(struct device *dev,
21 struct device_attribute *attr, char *buf)
22{
23 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
24}
25static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
26
27static ssize_t show_status(struct device *dev,
28 struct device_attribute *attr, char *buf)
29{
30 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
31}
32static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
33
34static ssize_t show_type(struct device *dev,
35 struct device_attribute *attr, char *buf)
36{
37 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
38}
39static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
40
41static ssize_t show_xoffset(struct device *dev,
42 struct device_attribute *attr, char *buf)
43{
44 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
45}
46static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
47
48static ssize_t show_yoffset(struct device *dev,
49 struct device_attribute *attr, char *buf)
50{
51 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
52}
53static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
54
Greg KH65f44672013-08-20 17:11:49 -070055static ssize_t image_read(struct file *file, struct kobject *kobj,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050056 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
57{
Josh Triplett2223af32012-09-28 17:57:05 -070058 memcpy(buf, attr->private + off, count);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050059 return count;
60}
61
Greg KH65f44672013-08-20 17:11:49 -070062static BIN_ATTR_RO(image, 0); /* size gets filled in later */
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050063
64static struct attribute *bgrt_attributes[] = {
65 &dev_attr_version.attr,
66 &dev_attr_status.attr,
67 &dev_attr_type.attr,
68 &dev_attr_xoffset.attr,
69 &dev_attr_yoffset.attr,
70 NULL,
71};
72
Greg KH65f44672013-08-20 17:11:49 -070073static struct bin_attribute *bgrt_bin_attributes[] = {
74 &bin_attr_image,
75 NULL,
76};
77
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050078static struct attribute_group bgrt_attribute_group = {
79 .attrs = bgrt_attributes,
Greg KH65f44672013-08-20 17:11:49 -070080 .bin_attrs = bgrt_bin_attributes,
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050081};
82
83static int __init bgrt_init(void)
84{
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050085 int ret;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050086
Josh Triplett2223af32012-09-28 17:57:05 -070087 if (!bgrt_image)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050088 return -ENODEV;
89
Greg KH65f44672013-08-20 17:11:49 -070090 bin_attr_image.private = bgrt_image;
91 bin_attr_image.size = bgrt_image_size;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050092
93 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
Josh Triplett2223af32012-09-28 17:57:05 -070094 if (!bgrt_kobj)
95 return -EINVAL;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050096
97 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
98 if (ret)
99 goto out_kobject;
100
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500101 return 0;
102
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500103out_kobject:
104 kobject_put(bgrt_kobj);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500105 return ret;
106}
Paul Gortmakercc079f82016-02-15 00:27:49 -0500107device_initcall(bgrt_init);