blob: be60399585456a76b973208c8674833c766fa824 [file] [log] [blame]
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05001/*
2 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
Josh Triplett2223af32012-09-28 17:57:05 -07003 * Copyright 2012 Intel Corporation
Matthew Garrettd1ff4b12012-01-31 13:19:20 -05004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/device.h>
14#include <linux/sysfs.h>
Josh Triplett2223af32012-09-28 17:57:05 -070015#include <linux/efi-bgrt.h>
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050016
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050017static struct kobject *bgrt_kobj;
18
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050019static ssize_t show_version(struct device *dev,
20 struct device_attribute *attr, char *buf)
21{
22 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
23}
24static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
25
26static ssize_t show_status(struct device *dev,
27 struct device_attribute *attr, char *buf)
28{
29 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
30}
31static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
32
33static ssize_t show_type(struct device *dev,
34 struct device_attribute *attr, char *buf)
35{
36 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
37}
38static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
39
40static ssize_t show_xoffset(struct device *dev,
41 struct device_attribute *attr, char *buf)
42{
43 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
44}
45static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
46
47static ssize_t show_yoffset(struct device *dev,
48 struct device_attribute *attr, char *buf)
49{
50 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
51}
52static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
53
54static ssize_t show_image(struct file *file, struct kobject *kobj,
55 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
56{
Josh Triplett2223af32012-09-28 17:57:05 -070057 memcpy(buf, attr->private + off, count);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050058 return count;
59}
60
61static struct bin_attribute image_attr = {
62 .attr = {
63 .name = "image",
64 .mode = S_IRUGO,
65 },
66 .read = show_image,
67};
68
69static struct attribute *bgrt_attributes[] = {
70 &dev_attr_version.attr,
71 &dev_attr_status.attr,
72 &dev_attr_type.attr,
73 &dev_attr_xoffset.attr,
74 &dev_attr_yoffset.attr,
75 NULL,
76};
77
78static struct attribute_group bgrt_attribute_group = {
79 .attrs = bgrt_attributes,
80};
81
82static int __init bgrt_init(void)
83{
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050084 int ret;
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050085
Josh Triplett2223af32012-09-28 17:57:05 -070086 if (!bgrt_image)
Matthew Garrettd1ff4b12012-01-31 13:19:20 -050087 return -ENODEV;
88
89 sysfs_bin_attr_init(&image_attr);
Josh Triplett2223af32012-09-28 17:57:05 -070090 image_attr.private = bgrt_image;
91 image_attr.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
101 ret = sysfs_create_bin_file(bgrt_kobj, &image_attr);
102 if (ret)
103 goto out_group;
104
105 return 0;
106
107out_group:
108 sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group);
109out_kobject:
110 kobject_put(bgrt_kobj);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500111 return ret;
112}
113
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500114module_init(bgrt_init);
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500115
Josh Triplett2223af32012-09-28 17:57:05 -0700116MODULE_AUTHOR("Matthew Garrett, Josh Triplett <josh@joshtriplett.org>");
Matthew Garrettd1ff4b12012-01-31 13:19:20 -0500117MODULE_DESCRIPTION("BGRT boot graphic support");
118MODULE_LICENSE("GPL");