2 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/sysfs.h>
14 #include <acpi/acpi.h>
15 #include <acpi/acpi_bus.h>
17 static struct acpi_table_bgrt
*bgrt_tab
;
18 static struct kobject
*bgrt_kobj
;
23 } __attribute ((packed
));
25 static struct bmp_header bmp_header
;
27 static ssize_t
show_version(struct device
*dev
,
28 struct device_attribute
*attr
, char *buf
)
30 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
->version
);
32 static DEVICE_ATTR(version
, S_IRUGO
, show_version
, NULL
);
34 static ssize_t
show_status(struct device
*dev
,
35 struct device_attribute
*attr
, char *buf
)
37 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
->status
);
39 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
41 static ssize_t
show_type(struct device
*dev
,
42 struct device_attribute
*attr
, char *buf
)
44 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
->image_type
);
46 static DEVICE_ATTR(type
, S_IRUGO
, show_type
, NULL
);
48 static ssize_t
show_xoffset(struct device
*dev
,
49 struct device_attribute
*attr
, char *buf
)
51 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
->image_offset_x
);
53 static DEVICE_ATTR(xoffset
, S_IRUGO
, show_xoffset
, NULL
);
55 static ssize_t
show_yoffset(struct device
*dev
,
56 struct device_attribute
*attr
, char *buf
)
58 return snprintf(buf
, PAGE_SIZE
, "%d\n", bgrt_tab
->image_offset_y
);
60 static DEVICE_ATTR(yoffset
, S_IRUGO
, show_yoffset
, NULL
);
62 static ssize_t
show_image(struct file
*file
, struct kobject
*kobj
,
63 struct bin_attribute
*attr
, char *buf
, loff_t off
, size_t count
)
65 int size
= attr
->size
;
66 void __iomem
*image
= attr
->private;
71 if (off
+ count
> size
)
74 memcpy_fromio(buf
, image
+off
, count
);
80 static struct bin_attribute image_attr
= {
88 static struct attribute
*bgrt_attributes
[] = {
89 &dev_attr_version
.attr
,
90 &dev_attr_status
.attr
,
92 &dev_attr_xoffset
.attr
,
93 &dev_attr_yoffset
.attr
,
97 static struct attribute_group bgrt_attribute_group
= {
98 .attrs
= bgrt_attributes
,
101 static int __init
bgrt_init(void)
110 status
= acpi_get_table("BGRT", 0,
111 (struct acpi_table_header
**)&bgrt_tab
);
113 if (ACPI_FAILURE(status
))
116 sysfs_bin_attr_init(&image_attr
);
118 bgrt
= ioremap(bgrt_tab
->image_address
, sizeof(struct bmp_header
));
125 memcpy_fromio(&bmp_header
, bgrt
, sizeof(bmp_header
));
126 image_attr
.size
= bmp_header
.size
;
129 image_attr
.private = ioremap(bgrt_tab
->image_address
, image_attr
.size
);
131 if (!image_attr
.private) {
137 bgrt_kobj
= kobject_create_and_add("bgrt", acpi_kobj
);
143 ret
= sysfs_create_group(bgrt_kobj
, &bgrt_attribute_group
);
147 ret
= sysfs_create_bin_file(bgrt_kobj
, &image_attr
);
154 sysfs_remove_group(bgrt_kobj
, &bgrt_attribute_group
);
156 kobject_put(bgrt_kobj
);
158 iounmap(image_attr
.private);
163 static void __exit
bgrt_exit(void)
165 iounmap(image_attr
.private);
166 sysfs_remove_group(bgrt_kobj
, &bgrt_attribute_group
);
167 sysfs_remove_bin_file(bgrt_kobj
, &image_attr
);
170 module_init(bgrt_init
);
171 module_exit(bgrt_exit
);
173 MODULE_AUTHOR("Matthew Garrett");
174 MODULE_DESCRIPTION("BGRT boot graphic support");
175 MODULE_LICENSE("GPL");