Linux Audio

Check our new training course

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