Blame view

drivers/acpi/bgrt.c 2.9 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
2
  /*
cc079f8cf   Paul Gortmaker   drivers/acpi: mak...
3
4
   * BGRT boot graphic support
   * Authors: Matthew Garrett, Josh Triplett <josh@joshtriplett.org>
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
5
   * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
2223af389   Josh Triplett   efi: Fix the ACPI...
6
   * Copyright 2012 Intel Corporation
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
7
8
9
   */
  
  #include <linux/kernel.h>
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
10
11
12
  #include <linux/init.h>
  #include <linux/device.h>
  #include <linux/sysfs.h>
2223af389   Josh Triplett   efi: Fix the ACPI...
13
  #include <linux/efi-bgrt.h>
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
14

7b0a91147   Dave Young   efi/x86: Move the...
15
  static void *bgrt_image;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
16
  static struct kobject *bgrt_kobj;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
17
18
19
  static ssize_t show_version(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
7b0a91147   Dave Young   efi/x86: Move the...
20
21
  	return snprintf(buf, PAGE_SIZE, "%d
  ", bgrt_tab.version);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
22
23
24
25
26
27
  }
  static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  
  static ssize_t show_status(struct device *dev,
  			   struct device_attribute *attr, char *buf)
  {
7b0a91147   Dave Young   efi/x86: Move the...
28
29
  	return snprintf(buf, PAGE_SIZE, "%d
  ", bgrt_tab.status);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
30
31
32
33
34
35
  }
  static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  
  static ssize_t show_type(struct device *dev,
  			 struct device_attribute *attr, char *buf)
  {
7b0a91147   Dave Young   efi/x86: Move the...
36
37
  	return snprintf(buf, PAGE_SIZE, "%d
  ", bgrt_tab.image_type);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
38
39
40
41
42
43
  }
  static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
  
  static ssize_t show_xoffset(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
7b0a91147   Dave Young   efi/x86: Move the...
44
45
  	return snprintf(buf, PAGE_SIZE, "%d
  ", bgrt_tab.image_offset_x);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
46
47
48
49
50
51
  }
  static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
  
  static ssize_t show_yoffset(struct device *dev,
  			    struct device_attribute *attr, char *buf)
  {
7b0a91147   Dave Young   efi/x86: Move the...
52
53
  	return snprintf(buf, PAGE_SIZE, "%d
  ", bgrt_tab.image_offset_y);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
54
55
  }
  static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
65f446795   Greg KH   ACPI: bgrt: take ...
56
  static ssize_t image_read(struct file *file, struct kobject *kobj,
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
57
58
  	       struct bin_attribute *attr, char *buf, loff_t off, size_t count)
  {
2223af389   Josh Triplett   efi: Fix the ACPI...
59
  	memcpy(buf, attr->private + off, count);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
60
61
  	return count;
  }
65f446795   Greg KH   ACPI: bgrt: take ...
62
  static BIN_ATTR_RO(image, 0);	/* size gets filled in later */
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
63
64
65
66
67
68
69
70
71
  
  static struct attribute *bgrt_attributes[] = {
  	&dev_attr_version.attr,
  	&dev_attr_status.attr,
  	&dev_attr_type.attr,
  	&dev_attr_xoffset.attr,
  	&dev_attr_yoffset.attr,
  	NULL,
  };
65f446795   Greg KH   ACPI: bgrt: take ...
72
73
74
75
  static struct bin_attribute *bgrt_bin_attributes[] = {
  	&bin_attr_image,
  	NULL,
  };
7e5362699   Arvind Yadav   ACPI: BGRT: const...
76
  static const struct attribute_group bgrt_attribute_group = {
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
77
  	.attrs = bgrt_attributes,
65f446795   Greg KH   ACPI: bgrt: take ...
78
  	.bin_attrs = bgrt_bin_attributes,
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
79
  };
6e7300cff   Bhupesh Sharma   efi/bgrt: Enable ...
80
81
82
83
84
  int __init acpi_parse_bgrt(struct acpi_table_header *table)
  {
  	efi_bgrt_init(table);
  	return 0;
  }
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
85
86
  static int __init bgrt_init(void)
  {
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
87
  	int ret;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
88

7b0a91147   Dave Young   efi/x86: Move the...
89
  	if (!bgrt_tab.image_address)
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
90
  		return -ENODEV;
7b0a91147   Dave Young   efi/x86: Move the...
91
92
93
94
95
96
97
  	bgrt_image = memremap(bgrt_tab.image_address, bgrt_image_size,
  			      MEMREMAP_WB);
  	if (!bgrt_image) {
  		pr_notice("Ignoring BGRT: failed to map image memory
  ");
  		return -ENOMEM;
  	}
65f446795   Greg KH   ACPI: bgrt: take ...
98
99
  	bin_attr_image.private = bgrt_image;
  	bin_attr_image.size = bgrt_image_size;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
100
101
  
  	bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
7b0a91147   Dave Young   efi/x86: Move the...
102
103
104
105
  	if (!bgrt_kobj) {
  		ret = -EINVAL;
  		goto out_memmap;
  	}
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
106
107
108
109
  
  	ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
  	if (ret)
  		goto out_kobject;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
110
  	return 0;
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
111
112
  out_kobject:
  	kobject_put(bgrt_kobj);
7b0a91147   Dave Young   efi/x86: Move the...
113
114
  out_memmap:
  	memunmap(bgrt_image);
d1ff4b1cd   Matthew Garrett   ACPI: Add support...
115
116
  	return ret;
  }
cc079f8cf   Paul Gortmaker   drivers/acpi: mak...
117
  device_initcall(bgrt_init);