^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * BGRT boot graphic support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2012 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/efi-bgrt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static void *bgrt_image;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static struct kobject *bgrt_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define BGRT_SHOW(_name, _member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static ssize_t _name##_show(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct kobj_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab._member); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct kobj_attribute bgrt_attr_##_name = __ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) BGRT_SHOW(version, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) BGRT_SHOW(status, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) BGRT_SHOW(type, image_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) BGRT_SHOW(xoffset, image_offset_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) BGRT_SHOW(yoffset, image_offset_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static ssize_t image_read(struct file *file, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct bin_attribute *attr, char *buf, loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) memcpy(buf, attr->private + off, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static BIN_ATTR_RO(image, 0); /* size gets filled in later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static struct attribute *bgrt_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) &bgrt_attr_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) &bgrt_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) &bgrt_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) &bgrt_attr_xoffset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) &bgrt_attr_yoffset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static struct bin_attribute *bgrt_bin_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) &bin_attr_image,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static const struct attribute_group bgrt_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .attrs = bgrt_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .bin_attrs = bgrt_bin_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int __init acpi_parse_bgrt(struct acpi_table_header *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) efi_bgrt_init(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int __init bgrt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!bgrt_tab.image_address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) MEMREMAP_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!bgrt_image) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) pr_notice("Ignoring BGRT: failed to map image memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) bin_attr_image.private = bgrt_image;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bin_attr_image.size = bgrt_image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (!bgrt_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) goto out_memmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) goto out_kobject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) out_kobject:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) kobject_put(bgrt_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) out_memmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) memunmap(bgrt_image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) device_initcall(bgrt_init);