Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * BGRT boot graphic support
0004  * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
0005  * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
0006  * Copyright 2012 Intel Corporation
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/init.h>
0011 #include <linux/device.h>
0012 #include <linux/sysfs.h>
0013 #include <linux/efi-bgrt.h>
0014 
0015 static void *bgrt_image;
0016 static struct kobject *bgrt_kobj;
0017 
0018 #define BGRT_SHOW(_name, _member) \
0019     static ssize_t _name##_show(struct kobject *kobj,           \
0020                     struct kobj_attribute *attr, char *buf) \
0021     {                                   \
0022         return sysfs_emit(buf, "%d\n", bgrt_tab._member);       \
0023     }                                   \
0024     static struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name)
0025 
0026 BGRT_SHOW(version, version);
0027 BGRT_SHOW(status, status);
0028 BGRT_SHOW(type, image_type);
0029 BGRT_SHOW(xoffset, image_offset_x);
0030 BGRT_SHOW(yoffset, image_offset_y);
0031 
0032 static ssize_t image_read(struct file *file, struct kobject *kobj,
0033            struct bin_attribute *attr, char *buf, loff_t off, size_t count)
0034 {
0035     memcpy(buf, attr->private + off, count);
0036     return count;
0037 }
0038 
0039 static BIN_ATTR_RO(image, 0);   /* size gets filled in later */
0040 
0041 static struct attribute *bgrt_attributes[] = {
0042     &bgrt_attr_version.attr,
0043     &bgrt_attr_status.attr,
0044     &bgrt_attr_type.attr,
0045     &bgrt_attr_xoffset.attr,
0046     &bgrt_attr_yoffset.attr,
0047     NULL,
0048 };
0049 
0050 static struct bin_attribute *bgrt_bin_attributes[] = {
0051     &bin_attr_image,
0052     NULL,
0053 };
0054 
0055 static const struct attribute_group bgrt_attribute_group = {
0056     .attrs = bgrt_attributes,
0057     .bin_attrs = bgrt_bin_attributes,
0058 };
0059 
0060 int __init acpi_parse_bgrt(struct acpi_table_header *table)
0061 {
0062     efi_bgrt_init(table);
0063     return 0;
0064 }
0065 
0066 static int __init bgrt_init(void)
0067 {
0068     int ret;
0069 
0070     if (!bgrt_tab.image_address)
0071         return -ENODEV;
0072 
0073     bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
0074                   MEMREMAP_WB);
0075     if (!bgrt_image) {
0076         pr_notice("Ignoring BGRT: failed to map image memory\n");
0077         return -ENOMEM;
0078     }
0079 
0080     bin_attr_image.private = bgrt_image;
0081     bin_attr_image.size = bgrt_image_size;
0082 
0083     bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
0084     if (!bgrt_kobj) {
0085         ret = -EINVAL;
0086         goto out_memmap;
0087     }
0088 
0089     ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
0090     if (ret)
0091         goto out_kobject;
0092 
0093     return 0;
0094 
0095 out_kobject:
0096     kobject_put(bgrt_kobj);
0097 out_memmap:
0098     memunmap(bgrt_image);
0099     return ret;
0100 }
0101 device_initcall(bgrt_init);