blob: 40018a73b3cb7e93aa206b012d0afca8a72ce176 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001// SPDX-License-Identifier: GPL-2.0-only
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -08002/*
3 * Copyright (C) 2012-2014 Intel Corporation
4 *
5 * Authors:
6 * Xiaoyan Zhang <xiaoyan.zhang@intel.com>
7 * Jiang Liu <jiang.liu@linux.intel.com>
8 * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
9 *
10 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
11 *
12 * This file contains implementation of the sysfs interface for PPI.
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -080013 */
14
15
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080016#include <linux/acpi.h>
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080017#include "tpm.h"
18
Stefan Berger09fe1b42019-01-17 12:41:32 -050019#define TPM_PPI_REVISION_ID_1 1
Stefan Berger8b60c792019-01-17 12:41:34 -050020#define TPM_PPI_REVISION_ID_2 2
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080021#define TPM_PPI_FN_VERSION 1
22#define TPM_PPI_FN_SUBREQ 2
23#define TPM_PPI_FN_GETREQ 3
24#define TPM_PPI_FN_GETACT 4
25#define TPM_PPI_FN_GETRSP 5
26#define TPM_PPI_FN_SUBREQ2 7
27#define TPM_PPI_FN_GETOPR 8
Stefan Berger9d4023e2019-01-17 12:41:33 -050028#define PPI_TPM_REQ_MAX 101 /* PPI 1.3 for TPM 2 */
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080029#define PPI_VS_REQ_START 128
30#define PPI_VS_REQ_END 255
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080031
Andy Shevchenko94116f82017-06-05 19:40:46 +030032static const guid_t tpm_ppi_guid =
33 GUID_INIT(0x3DDDFAA6, 0x361B, 0x4EB4,
34 0xA4, 0x24, 0x8D, 0x10, 0x08, 0x9D, 0x16, 0x53);
Jiang Liu84b16672013-12-19 20:38:17 +080035
Stefan Berger8b60c792019-01-17 12:41:34 -050036static bool tpm_ppi_req_has_parameter(u64 req)
37{
38 return req == 23;
39}
40
Jiang Liu84b16672013-12-19 20:38:17 +080041static inline union acpi_object *
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -080042tpm_eval_dsm(acpi_handle ppi_handle, int func, acpi_object_type type,
Stefan Berger587bad72019-01-17 12:41:31 -050043 union acpi_object *argv4, u64 rev)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080044{
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -080045 BUG_ON(!ppi_handle);
Andy Shevchenko94116f82017-06-05 19:40:46 +030046 return acpi_evaluate_dsm_typed(ppi_handle, &tpm_ppi_guid,
Stefan Berger587bad72019-01-17 12:41:31 -050047 rev, func, argv4, type);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080048}
49
Xiaoyan Zhang81198072013-08-29 20:39:11 +080050static ssize_t tpm_show_ppi_version(struct device *dev,
51 struct device_attribute *attr, char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080052{
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +030053 struct tpm_chip *chip = to_tpm_chip(dev);
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -080054
55 return scnprintf(buf, PAGE_SIZE, "%s\n", chip->ppi_version);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080056}
57
Xiaoyan Zhang81198072013-08-29 20:39:11 +080058static ssize_t tpm_show_ppi_request(struct device *dev,
59 struct device_attribute *attr, char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080060{
Jiang Liu84b16672013-12-19 20:38:17 +080061 ssize_t size = -EINVAL;
62 union acpi_object *obj;
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +030063 struct tpm_chip *chip = to_tpm_chip(dev);
Stefan Berger8b60c792019-01-17 12:41:34 -050064 u64 rev = TPM_PPI_REVISION_ID_2;
65 u64 req;
66
67 if (strcmp(chip->ppi_version, "1.2") < 0)
68 rev = TPM_PPI_REVISION_ID_1;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080069
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -080070 obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETREQ,
Stefan Berger8b60c792019-01-17 12:41:34 -050071 ACPI_TYPE_PACKAGE, NULL, rev);
Jiang Liu84b16672013-12-19 20:38:17 +080072 if (!obj)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080073 return -ENXIO;
74
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +080075 /*
76 * output.pointer should be of package type, including two integers.
77 * The first is function return code, 0 means success and 1 means
78 * error. The second is pending TPM operation requested by the OS, 0
79 * means none and >0 means operation value.
80 */
Stefan Berger8b60c792019-01-17 12:41:34 -050081 if (obj->package.count == 3 &&
82 obj->package.elements[0].type == ACPI_TYPE_INTEGER &&
83 obj->package.elements[1].type == ACPI_TYPE_INTEGER &&
84 obj->package.elements[2].type == ACPI_TYPE_INTEGER) {
85 if (obj->package.elements[0].integer.value)
86 size = -EFAULT;
87 else {
88 req = obj->package.elements[1].integer.value;
89 if (tpm_ppi_req_has_parameter(req))
90 size = scnprintf(buf, PAGE_SIZE,
91 "%llu %llu\n", req,
92 obj->package.elements[2].integer.value);
93 else
94 size = scnprintf(buf, PAGE_SIZE,
95 "%llu\n", req);
96 }
97 } else if (obj->package.count == 2 &&
Jiang Liu84b16672013-12-19 20:38:17 +080098 obj->package.elements[0].type == ACPI_TYPE_INTEGER &&
99 obj->package.elements[1].type == ACPI_TYPE_INTEGER) {
100 if (obj->package.elements[0].integer.value)
101 size = -EFAULT;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800102 else
Jiang Liu84b16672013-12-19 20:38:17 +0800103 size = scnprintf(buf, PAGE_SIZE, "%llu\n",
104 obj->package.elements[1].integer.value);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800105 }
Jiang Liu84b16672013-12-19 20:38:17 +0800106
107 ACPI_FREE(obj);
108
109 return size;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800110}
111
Xiaoyan Zhang81198072013-08-29 20:39:11 +0800112static ssize_t tpm_store_ppi_request(struct device *dev,
113 struct device_attribute *attr,
114 const char *buf, size_t count)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800115{
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800116 u32 req;
117 u64 ret;
Jiang Liu84b16672013-12-19 20:38:17 +0800118 int func = TPM_PPI_FN_SUBREQ;
Stefan Berger50a81b62019-01-17 12:41:35 -0500119 union acpi_object *obj, tmp[2];
120 union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(2, tmp);
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300121 struct tpm_chip *chip = to_tpm_chip(dev);
Stefan Berger50a81b62019-01-17 12:41:35 -0500122 u64 rev = TPM_PPI_REVISION_ID_1;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800123
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800124 /*
125 * the function to submit TPM operation request to pre-os environment
126 * is updated with function index from SUBREQ to SUBREQ2 since PPI
127 * version 1.1
128 */
Andy Shevchenko94116f82017-06-05 19:40:46 +0300129 if (acpi_check_dsm(chip->acpi_dev_handle, &tpm_ppi_guid,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500130 TPM_PPI_REVISION_ID_1, 1 << TPM_PPI_FN_SUBREQ2))
Jiang Liu84b16672013-12-19 20:38:17 +0800131 func = TPM_PPI_FN_SUBREQ2;
132
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800133 /*
134 * PPI spec defines params[3].type as ACPI_TYPE_PACKAGE. Some BIOS
135 * accept buffer/string/integer type, but some BIOS accept buffer/
136 * string/package type. For PPI version 1.0 and 1.1, use buffer type
137 * for compatibility, and use package type since 1.2 according to spec.
138 */
Stefan Berger50a81b62019-01-17 12:41:35 -0500139 if (strcmp(chip->ppi_version, "1.3") == 0) {
140 if (sscanf(buf, "%llu %llu", &tmp[0].integer.value,
141 &tmp[1].integer.value) != 2)
142 goto ppi12;
143 rev = TPM_PPI_REVISION_ID_2;
144 tmp[0].type = ACPI_TYPE_INTEGER;
145 tmp[1].type = ACPI_TYPE_INTEGER;
146 } else if (strcmp(chip->ppi_version, "1.2") < 0) {
Jiang Liu84b16672013-12-19 20:38:17 +0800147 if (sscanf(buf, "%d", &req) != 1)
148 return -EINVAL;
149 argv4.type = ACPI_TYPE_BUFFER;
150 argv4.buffer.length = sizeof(req);
151 argv4.buffer.pointer = (u8 *)&req;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800152 } else {
Stefan Berger50a81b62019-01-17 12:41:35 -0500153ppi12:
154 argv4.package.count = 1;
155 tmp[0].type = ACPI_TYPE_INTEGER;
156 if (sscanf(buf, "%llu", &tmp[0].integer.value) != 1)
Jiang Liu84b16672013-12-19 20:38:17 +0800157 return -EINVAL;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800158 }
159
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800160 obj = tpm_eval_dsm(chip->acpi_dev_handle, func, ACPI_TYPE_INTEGER,
Stefan Berger50a81b62019-01-17 12:41:35 -0500161 &argv4, rev);
Jiang Liu84b16672013-12-19 20:38:17 +0800162 if (!obj) {
163 return -ENXIO;
164 } else {
165 ret = obj->integer.value;
166 ACPI_FREE(obj);
167 }
168
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800169 if (ret == 0)
Jiang Liu84b16672013-12-19 20:38:17 +0800170 return (acpi_status)count;
171
172 return (ret == 1) ? -EPERM : -EFAULT;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800173}
174
Xiaoyan Zhang81198072013-08-29 20:39:11 +0800175static ssize_t tpm_show_ppi_transition_action(struct device *dev,
176 struct device_attribute *attr,
177 char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800178{
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800179 u32 ret;
Jiang Liu84b16672013-12-19 20:38:17 +0800180 acpi_status status;
181 union acpi_object *obj = NULL;
182 union acpi_object tmp = {
183 .buffer.type = ACPI_TYPE_BUFFER,
184 .buffer.length = 0,
185 .buffer.pointer = NULL
186 };
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300187 struct tpm_chip *chip = to_tpm_chip(dev);
Jiang Liu84b16672013-12-19 20:38:17 +0800188
189 static char *info[] = {
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800190 "None",
191 "Shutdown",
192 "Reboot",
193 "OS Vendor-specific",
194 "Error",
195 };
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800196
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800197 /*
198 * PPI spec defines params[3].type as empty package, but some platforms
199 * (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for
200 * compatibility, define params[3].type as buffer, if PPI version < 1.2
201 */
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800202 if (strcmp(chip->ppi_version, "1.2") < 0)
Jiang Liu84b16672013-12-19 20:38:17 +0800203 obj = &tmp;
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800204 obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETACT,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500205 ACPI_TYPE_INTEGER, obj, TPM_PPI_REVISION_ID_1);
Jiang Liu84b16672013-12-19 20:38:17 +0800206 if (!obj) {
207 return -ENXIO;
208 } else {
209 ret = obj->integer.value;
210 ACPI_FREE(obj);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800211 }
Jiang Liu84b16672013-12-19 20:38:17 +0800212
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800213 if (ret < ARRAY_SIZE(info) - 1)
214 status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, info[ret]);
215 else
216 status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret,
217 info[ARRAY_SIZE(info)-1]);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800218 return status;
219}
220
Xiaoyan Zhang81198072013-08-29 20:39:11 +0800221static ssize_t tpm_show_ppi_response(struct device *dev,
222 struct device_attribute *attr,
223 char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800224{
Jiang Liu84b16672013-12-19 20:38:17 +0800225 acpi_status status = -EINVAL;
226 union acpi_object *obj, *ret_obj;
227 u64 req, res;
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300228 struct tpm_chip *chip = to_tpm_chip(dev);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800229
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800230 obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETRSP,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500231 ACPI_TYPE_PACKAGE, NULL, TPM_PPI_REVISION_ID_1);
Jiang Liu84b16672013-12-19 20:38:17 +0800232 if (!obj)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800233 return -ENXIO;
234
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800235 /*
236 * parameter output.pointer should be of package type, including
237 * 3 integers. The first means function return code, the second means
238 * most recent TPM operation request, and the last means response to
239 * the most recent TPM operation request. Only if the first is 0, and
240 * the second integer is not 0, the response makes sense.
241 */
Jiang Liu84b16672013-12-19 20:38:17 +0800242 ret_obj = obj->package.elements;
243 if (obj->package.count < 3 ||
244 ret_obj[0].type != ACPI_TYPE_INTEGER ||
245 ret_obj[1].type != ACPI_TYPE_INTEGER ||
246 ret_obj[2].type != ACPI_TYPE_INTEGER)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800247 goto cleanup;
Jiang Liu84b16672013-12-19 20:38:17 +0800248
249 if (ret_obj[0].integer.value) {
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800250 status = -EFAULT;
251 goto cleanup;
252 }
Jiang Liu84b16672013-12-19 20:38:17 +0800253
254 req = ret_obj[1].integer.value;
255 res = ret_obj[2].integer.value;
256 if (req) {
257 if (res == 0)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800258 status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
259 "0: Success");
Jiang Liu84b16672013-12-19 20:38:17 +0800260 else if (res == 0xFFFFFFF0)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800261 status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
262 "0xFFFFFFF0: User Abort");
Jiang Liu84b16672013-12-19 20:38:17 +0800263 else if (res == 0xFFFFFFF1)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800264 status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
265 "0xFFFFFFF1: BIOS Failure");
Jiang Liu84b16672013-12-19 20:38:17 +0800266 else if (res >= 1 && res <= 0x00000FFF)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800267 status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n",
Jiang Liu84b16672013-12-19 20:38:17 +0800268 req, res, "Corresponding TPM error");
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800269 else
270 status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n",
Jiang Liu84b16672013-12-19 20:38:17 +0800271 req, res, "Error");
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800272 } else {
273 status = scnprintf(buf, PAGE_SIZE, "%llu: %s\n",
Jiang Liu84b16672013-12-19 20:38:17 +0800274 req, "No Recent Request");
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800275 }
Jiang Liu84b16672013-12-19 20:38:17 +0800276
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800277cleanup:
Jiang Liu84b16672013-12-19 20:38:17 +0800278 ACPI_FREE(obj);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800279 return status;
280}
281
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800282static ssize_t show_ppi_operations(acpi_handle dev_handle, char *buf, u32 start,
283 u32 end)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800284{
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800285 int i;
286 u32 ret;
Jiang Liu84b16672013-12-19 20:38:17 +0800287 char *str = buf;
288 union acpi_object *obj, tmp;
289 union acpi_object argv = ACPI_INIT_DSM_ARGV4(1, &tmp);
290
291 static char *info[] = {
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800292 "Not implemented",
293 "BIOS only",
294 "Blocked for OS by BIOS",
295 "User required",
296 "User not required",
297 };
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800298
Stefan Berger09fe1b42019-01-17 12:41:32 -0500299 if (!acpi_check_dsm(dev_handle, &tpm_ppi_guid, TPM_PPI_REVISION_ID_1,
Jiang Liu1569a4c2013-12-19 20:38:18 +0800300 1 << TPM_PPI_FN_GETOPR))
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800301 return -EPERM;
302
Jiang Liu84b16672013-12-19 20:38:17 +0800303 tmp.integer.type = ACPI_TYPE_INTEGER;
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800304 for (i = start; i <= end; i++) {
Jiang Liu84b16672013-12-19 20:38:17 +0800305 tmp.integer.value = i;
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800306 obj = tpm_eval_dsm(dev_handle, TPM_PPI_FN_GETOPR,
Stefan Berger587bad72019-01-17 12:41:31 -0500307 ACPI_TYPE_INTEGER, &argv,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500308 TPM_PPI_REVISION_ID_1);
Jiang Liu84b16672013-12-19 20:38:17 +0800309 if (!obj) {
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800310 return -ENOMEM;
Jiang Liu84b16672013-12-19 20:38:17 +0800311 } else {
312 ret = obj->integer.value;
313 ACPI_FREE(obj);
314 }
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800315
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800316 if (ret > 0 && ret < ARRAY_SIZE(info))
317 str += scnprintf(str, PAGE_SIZE, "%d %d: %s\n",
318 i, ret, info[ret]);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800319 }
Jiang Liu84b16672013-12-19 20:38:17 +0800320
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800321 return str - buf;
322}
323
Xiaoyan Zhang81198072013-08-29 20:39:11 +0800324static ssize_t tpm_show_ppi_tcg_operations(struct device *dev,
325 struct device_attribute *attr,
326 char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800327{
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300328 struct tpm_chip *chip = to_tpm_chip(dev);
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800329
330 return show_ppi_operations(chip->acpi_dev_handle, buf, 0,
331 PPI_TPM_REQ_MAX);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800332}
333
Xiaoyan Zhang81198072013-08-29 20:39:11 +0800334static ssize_t tpm_show_ppi_vs_operations(struct device *dev,
335 struct device_attribute *attr,
336 char *buf)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800337{
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300338 struct tpm_chip *chip = to_tpm_chip(dev);
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800339
340 return show_ppi_operations(chip->acpi_dev_handle, buf, PPI_VS_REQ_START,
341 PPI_VS_REQ_END);
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800342}
343
344static DEVICE_ATTR(version, S_IRUGO, tpm_show_ppi_version, NULL);
345static DEVICE_ATTR(request, S_IRUGO | S_IWUSR | S_IWGRP,
346 tpm_show_ppi_request, tpm_store_ppi_request);
347static DEVICE_ATTR(transition_action, S_IRUGO,
348 tpm_show_ppi_transition_action, NULL);
349static DEVICE_ATTR(response, S_IRUGO, tpm_show_ppi_response, NULL);
350static DEVICE_ATTR(tcg_operations, S_IRUGO, tpm_show_ppi_tcg_operations, NULL);
351static DEVICE_ATTR(vs_operations, S_IRUGO, tpm_show_ppi_vs_operations, NULL);
352
353static struct attribute *ppi_attrs[] = {
354 &dev_attr_version.attr,
355 &dev_attr_request.attr,
356 &dev_attr_transition_action.attr,
357 &dev_attr_response.attr,
358 &dev_attr_tcg_operations.attr,
359 &dev_attr_vs_operations.attr, NULL,
360};
Rikard Falkeborn90cba8d2021-02-04 22:54:27 +0100361static const struct attribute_group ppi_attr_grp = {
Gang Wei1631cfb2012-10-09 17:35:22 +0800362 .name = "ppi",
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800363 .attrs = ppi_attrs
364};
365
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300366void tpm_add_ppi(struct tpm_chip *chip)
Xiaoyan Zhangf84fdff2012-08-22 18:47:22 +0800367{
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800368 union acpi_object *obj;
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800369
370 if (!chip->acpi_dev_handle)
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300371 return;
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800372
Andy Shevchenko94116f82017-06-05 19:40:46 +0300373 if (!acpi_check_dsm(chip->acpi_dev_handle, &tpm_ppi_guid,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500374 TPM_PPI_REVISION_ID_1, 1 << TPM_PPI_FN_VERSION))
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300375 return;
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800376
377 /* Cache PPI version string. */
Andy Shevchenko94116f82017-06-05 19:40:46 +0300378 obj = acpi_evaluate_dsm_typed(chip->acpi_dev_handle, &tpm_ppi_guid,
Stefan Berger09fe1b42019-01-17 12:41:32 -0500379 TPM_PPI_REVISION_ID_1,
380 TPM_PPI_FN_VERSION,
Jarkko Sakkinen0dc55362014-12-12 11:46:35 -0800381 NULL, ACPI_TYPE_STRING);
382 if (obj) {
383 strlcpy(chip->ppi_version, obj->string.pointer,
384 sizeof(chip->ppi_version));
385 ACPI_FREE(obj);
386 }
387
Jarkko Sakkinen9b774d52015-04-14 17:56:48 +0300388 chip->groups[chip->groups_cnt++] = &ppi_attr_grp;
Gang Wei1631cfb2012-10-09 17:35:22 +0800389}