1 // SPDX-License-Identifier: GPL-2.0-only
4 * FPDT support for exporting boot and suspend/resume performance data
6 * Copyright (C) 2021 Intel Corporation. All rights reserved.
9 #define pr_fmt(fmt) "ACPI FPDT: " fmt
11 #include <linux/acpi.h>
14 * FPDT contains ACPI table header and a number of fpdt_subtable_entries.
15 * Each fpdt_subtable_entry points to a subtable: FBPT or S3PT.
16 * Each FPDT subtable (FBPT/S3PT) is composed of a fpdt_subtable_header
17 * and a number of fpdt performance records.
18 * Each FPDT performance record is composed of a fpdt_record_header and
19 * performance data fields, for boot or suspend or resume phase.
21 enum fpdt_subtable_type {
26 struct fpdt_subtable_entry {
27 u16 type; /* refer to enum fpdt_subtable_type */
31 u64 address; /* physical address of the S3PT/FBPT table */
34 struct fpdt_subtable_header {
39 enum fpdt_record_type {
45 struct fpdt_record_header {
46 u16 type; /* refer to enum fpdt_record_type */
51 struct resume_performance_record {
52 struct fpdt_record_header header;
56 } __attribute__((packed));
58 struct boot_performance_record {
59 struct fpdt_record_header header;
63 u64 bootloader_launch;
64 u64 exitbootservice_start;
65 u64 exitbootservice_end;
66 } __attribute__((packed));
68 struct suspend_performance_record {
69 struct fpdt_record_header header;
72 } __attribute__((packed));
75 static struct resume_performance_record *record_resume;
76 static struct suspend_performance_record *record_suspend;
77 static struct boot_performance_record *record_boot;
79 #define FPDT_ATTR(phase, name) \
80 static ssize_t name##_show(struct kobject *kobj, \
81 struct kobj_attribute *attr, char *buf) \
83 return sprintf(buf, "%llu\n", record_##phase->name); \
85 static struct kobj_attribute name##_attr = \
86 __ATTR(name##_ns, 0444, name##_show, NULL)
88 FPDT_ATTR(resume, resume_prev);
89 FPDT_ATTR(resume, resume_avg);
90 FPDT_ATTR(suspend, suspend_start);
91 FPDT_ATTR(suspend, suspend_end);
92 FPDT_ATTR(boot, firmware_start);
93 FPDT_ATTR(boot, bootloader_load);
94 FPDT_ATTR(boot, bootloader_launch);
95 FPDT_ATTR(boot, exitbootservice_start);
96 FPDT_ATTR(boot, exitbootservice_end);
98 static ssize_t resume_count_show(struct kobject *kobj,
99 struct kobj_attribute *attr, char *buf)
101 return sprintf(buf, "%u\n", record_resume->resume_count);
104 static struct kobj_attribute resume_count_attr =
105 __ATTR_RO(resume_count);
107 static struct attribute *resume_attrs[] = {
108 &resume_count_attr.attr,
109 &resume_prev_attr.attr,
110 &resume_avg_attr.attr,
114 static const struct attribute_group resume_attr_group = {
115 .attrs = resume_attrs,
119 static struct attribute *suspend_attrs[] = {
120 &suspend_start_attr.attr,
121 &suspend_end_attr.attr,
125 static const struct attribute_group suspend_attr_group = {
126 .attrs = suspend_attrs,
130 static struct attribute *boot_attrs[] = {
131 &firmware_start_attr.attr,
132 &bootloader_load_attr.attr,
133 &bootloader_launch_attr.attr,
134 &exitbootservice_start_attr.attr,
135 &exitbootservice_end_attr.attr,
139 static const struct attribute_group boot_attr_group = {
144 static struct kobject *fpdt_kobj;
146 static int fpdt_process_subtable(u64 address, u32 subtable_type)
148 struct fpdt_subtable_header *subtable_header;
149 struct fpdt_record_header *record_header;
150 char *signature = (subtable_type == SUBTABLE_FBPT ? "FBPT" : "S3PT");
154 subtable_header = acpi_os_map_memory(address, sizeof(*subtable_header));
155 if (!subtable_header)
158 if (strncmp((char *)&subtable_header->signature, signature, 4)) {
159 pr_info(FW_BUG "subtable signature and type mismatch!\n");
163 length = subtable_header->length;
164 acpi_os_unmap_memory(subtable_header, sizeof(*subtable_header));
166 subtable_header = acpi_os_map_memory(address, length);
167 if (!subtable_header)
170 offset = sizeof(*subtable_header);
171 while (offset < length) {
172 record_header = (void *)subtable_header + offset;
173 offset += record_header->length;
175 switch (record_header->type) {
176 case RECORD_S3_RESUME:
177 if (subtable_type != SUBTABLE_S3PT) {
178 pr_err(FW_BUG "Invalid record %d for subtable %s\n",
179 record_header->type, signature);
183 pr_err("Duplicate resume performance record found.\n");
186 record_resume = (struct resume_performance_record *)record_header;
187 result = sysfs_create_group(fpdt_kobj, &resume_attr_group);
191 case RECORD_S3_SUSPEND:
192 if (subtable_type != SUBTABLE_S3PT) {
193 pr_err(FW_BUG "Invalid %d for subtable %s\n",
194 record_header->type, signature);
197 if (record_suspend) {
198 pr_err("Duplicate suspend performance record found.\n");
201 record_suspend = (struct suspend_performance_record *)record_header;
202 result = sysfs_create_group(fpdt_kobj, &suspend_attr_group);
207 if (subtable_type != SUBTABLE_FBPT) {
208 pr_err(FW_BUG "Invalid %d for subtable %s\n",
209 record_header->type, signature);
213 pr_err("Duplicate boot performance record found.\n");
216 record_boot = (struct boot_performance_record *)record_header;
217 result = sysfs_create_group(fpdt_kobj, &boot_attr_group);
223 /* Other types are reserved in ACPI 6.4 spec. */
230 static int __init acpi_init_fpdt(void)
233 struct acpi_table_header *header;
234 struct fpdt_subtable_entry *subtable;
235 u32 offset = sizeof(*header);
237 status = acpi_get_table(ACPI_SIG_FPDT, 0, &header);
239 if (ACPI_FAILURE(status))
242 fpdt_kobj = kobject_create_and_add("fpdt", acpi_kobj);
244 acpi_put_table(header);
248 while (offset < header->length) {
249 subtable = (void *)header + offset;
250 switch (subtable->type) {
253 fpdt_process_subtable(subtable->address,
257 /* Other types are reserved in ACPI 6.4 spec. */
260 offset += sizeof(*subtable);
265 fs_initcall(acpi_init_fpdt);