2 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
3 * Copyright 2012 Intel Corporation
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.
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>
15 #include <linux/efi-bgrt.h>
17 static struct kobject *bgrt_kobj;
19 static ssize_t show_version(struct device *dev,
20 struct device_attribute *attr, char *buf)
22 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
24 static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
26 static ssize_t show_status(struct device *dev,
27 struct device_attribute *attr, char *buf)
29 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
31 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
33 static ssize_t show_type(struct device *dev,
34 struct device_attribute *attr, char *buf)
36 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
38 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
40 static ssize_t show_xoffset(struct device *dev,
41 struct device_attribute *attr, char *buf)
43 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
45 static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
47 static ssize_t show_yoffset(struct device *dev,
48 struct device_attribute *attr, char *buf)
50 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
52 static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
54 static ssize_t show_image(struct file *file, struct kobject *kobj,
55 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
57 memcpy(buf, attr->private + off, count);
61 static struct bin_attribute image_attr = {
69 static struct attribute *bgrt_attributes[] = {
70 &dev_attr_version.attr,
71 &dev_attr_status.attr,
73 &dev_attr_xoffset.attr,
74 &dev_attr_yoffset.attr,
78 static struct attribute_group bgrt_attribute_group = {
79 .attrs = bgrt_attributes,
82 static int __init bgrt_init(void)
89 sysfs_bin_attr_init(&image_attr);
90 image_attr.private = bgrt_image;
91 image_attr.size = bgrt_image_size;
93 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
97 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
101 ret = sysfs_create_bin_file(bgrt_kobj, &image_attr);
108 sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group);
110 kobject_put(bgrt_kobj);
114 module_init(bgrt_init);
116 MODULE_AUTHOR("Matthew Garrett, Josh Triplett <josh@joshtriplett.org>");
117 MODULE_DESCRIPTION("BGRT boot graphic support");
118 MODULE_LICENSE("GPL");