xref: /openbmc/linux/drivers/char/tpm/tpm_ppi.c (revision 50a81b60bfe075a0023670ff86558abd02536799)
10dc55365SJarkko Sakkinen /*
20dc55365SJarkko Sakkinen  * Copyright (C) 2012-2014 Intel Corporation
30dc55365SJarkko Sakkinen  *
40dc55365SJarkko Sakkinen  * Authors:
50dc55365SJarkko Sakkinen  * Xiaoyan Zhang <xiaoyan.zhang@intel.com>
60dc55365SJarkko Sakkinen  * Jiang Liu <jiang.liu@linux.intel.com>
70dc55365SJarkko Sakkinen  * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
80dc55365SJarkko Sakkinen  *
90dc55365SJarkko Sakkinen  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
100dc55365SJarkko Sakkinen  *
110dc55365SJarkko Sakkinen  * This file contains implementation of the sysfs interface for PPI.
120dc55365SJarkko Sakkinen  *
130dc55365SJarkko Sakkinen  * This program is free software; you can redistribute it and/or
140dc55365SJarkko Sakkinen  * modify it under the terms of the GNU General Public License
150dc55365SJarkko Sakkinen  * as published by the Free Software Foundation; version 2
160dc55365SJarkko Sakkinen  * of the License.
170dc55365SJarkko Sakkinen  */
180dc55365SJarkko Sakkinen 
190dc55365SJarkko Sakkinen 
20f84fdff0SXiaoyan Zhang #include <linux/acpi.h>
21f84fdff0SXiaoyan Zhang #include "tpm.h"
22f84fdff0SXiaoyan Zhang 
2309fe1b42SStefan Berger #define TPM_PPI_REVISION_ID_1	1
248b60c79bSStefan Berger #define TPM_PPI_REVISION_ID_2	2
25f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_VERSION	1
26f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_SUBREQ	2
27f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_GETREQ	3
28f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_GETACT	4
29f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_GETRSP	5
30f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_SUBREQ2	7
31f84fdff0SXiaoyan Zhang #define TPM_PPI_FN_GETOPR	8
329d4023edSStefan Berger #define PPI_TPM_REQ_MAX		101 /* PPI 1.3 for TPM 2 */
33f84fdff0SXiaoyan Zhang #define PPI_VS_REQ_START	128
34f84fdff0SXiaoyan Zhang #define PPI_VS_REQ_END		255
35f84fdff0SXiaoyan Zhang 
3694116f81SAndy Shevchenko static const guid_t tpm_ppi_guid =
3794116f81SAndy Shevchenko 	GUID_INIT(0x3DDDFAA6, 0x361B, 0x4EB4,
3894116f81SAndy Shevchenko 		  0xA4, 0x24, 0x8D, 0x10, 0x08, 0x9D, 0x16, 0x53);
3984b1667dSJiang Liu 
408b60c79bSStefan Berger static bool tpm_ppi_req_has_parameter(u64 req)
418b60c79bSStefan Berger {
428b60c79bSStefan Berger 	return req == 23;
438b60c79bSStefan Berger }
448b60c79bSStefan Berger 
4584b1667dSJiang Liu static inline union acpi_object *
460dc55365SJarkko Sakkinen tpm_eval_dsm(acpi_handle ppi_handle, int func, acpi_object_type type,
47587bad77SStefan Berger 	     union acpi_object *argv4, u64 rev)
48f84fdff0SXiaoyan Zhang {
490dc55365SJarkko Sakkinen 	BUG_ON(!ppi_handle);
5094116f81SAndy Shevchenko 	return acpi_evaluate_dsm_typed(ppi_handle, &tpm_ppi_guid,
51587bad77SStefan Berger 				       rev, func, argv4, type);
52f84fdff0SXiaoyan Zhang }
53f84fdff0SXiaoyan Zhang 
5481198078SXiaoyan Zhang static ssize_t tpm_show_ppi_version(struct device *dev,
5581198078SXiaoyan Zhang 				    struct device_attribute *attr, char *buf)
56f84fdff0SXiaoyan Zhang {
579b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
580dc55365SJarkko Sakkinen 
590dc55365SJarkko Sakkinen 	return scnprintf(buf, PAGE_SIZE, "%s\n", chip->ppi_version);
60f84fdff0SXiaoyan Zhang }
61f84fdff0SXiaoyan Zhang 
6281198078SXiaoyan Zhang static ssize_t tpm_show_ppi_request(struct device *dev,
6381198078SXiaoyan Zhang 				    struct device_attribute *attr, char *buf)
64f84fdff0SXiaoyan Zhang {
6584b1667dSJiang Liu 	ssize_t size = -EINVAL;
6684b1667dSJiang Liu 	union acpi_object *obj;
679b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
688b60c79bSStefan Berger 	u64 rev = TPM_PPI_REVISION_ID_2;
698b60c79bSStefan Berger 	u64 req;
708b60c79bSStefan Berger 
718b60c79bSStefan Berger 	if (strcmp(chip->ppi_version, "1.2") < 0)
728b60c79bSStefan Berger 		rev = TPM_PPI_REVISION_ID_1;
73f84fdff0SXiaoyan Zhang 
740dc55365SJarkko Sakkinen 	obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETREQ,
758b60c79bSStefan Berger 			   ACPI_TYPE_PACKAGE, NULL, rev);
7684b1667dSJiang Liu 	if (!obj)
77f84fdff0SXiaoyan Zhang 		return -ENXIO;
78f84fdff0SXiaoyan Zhang 
79f84fdff0SXiaoyan Zhang 	/*
80f84fdff0SXiaoyan Zhang 	 * output.pointer should be of package type, including two integers.
81f84fdff0SXiaoyan Zhang 	 * The first is function return code, 0 means success and 1 means
82f84fdff0SXiaoyan Zhang 	 * error. The second is pending TPM operation requested by the OS, 0
83f84fdff0SXiaoyan Zhang 	 * means none and >0 means operation value.
84f84fdff0SXiaoyan Zhang 	 */
858b60c79bSStefan Berger 	if (obj->package.count == 3 &&
868b60c79bSStefan Berger 	    obj->package.elements[0].type == ACPI_TYPE_INTEGER &&
878b60c79bSStefan Berger 	    obj->package.elements[1].type == ACPI_TYPE_INTEGER &&
888b60c79bSStefan Berger 	    obj->package.elements[2].type == ACPI_TYPE_INTEGER) {
898b60c79bSStefan Berger 		if (obj->package.elements[0].integer.value)
908b60c79bSStefan Berger 			size = -EFAULT;
918b60c79bSStefan Berger 		else {
928b60c79bSStefan Berger 			req = obj->package.elements[1].integer.value;
938b60c79bSStefan Berger 			if (tpm_ppi_req_has_parameter(req))
948b60c79bSStefan Berger 				size = scnprintf(buf, PAGE_SIZE,
958b60c79bSStefan Berger 				    "%llu %llu\n", req,
968b60c79bSStefan Berger 				    obj->package.elements[2].integer.value);
978b60c79bSStefan Berger 			else
988b60c79bSStefan Berger 				size = scnprintf(buf, PAGE_SIZE,
998b60c79bSStefan Berger 						"%llu\n", req);
1008b60c79bSStefan Berger 		}
1018b60c79bSStefan Berger 	} else if (obj->package.count == 2 &&
10284b1667dSJiang Liu 	    obj->package.elements[0].type == ACPI_TYPE_INTEGER &&
10384b1667dSJiang Liu 	    obj->package.elements[1].type == ACPI_TYPE_INTEGER) {
10484b1667dSJiang Liu 		if (obj->package.elements[0].integer.value)
10584b1667dSJiang Liu 			size = -EFAULT;
106f84fdff0SXiaoyan Zhang 		else
10784b1667dSJiang Liu 			size = scnprintf(buf, PAGE_SIZE, "%llu\n",
10884b1667dSJiang Liu 				 obj->package.elements[1].integer.value);
109f84fdff0SXiaoyan Zhang 	}
11084b1667dSJiang Liu 
11184b1667dSJiang Liu 	ACPI_FREE(obj);
11284b1667dSJiang Liu 
11384b1667dSJiang Liu 	return size;
114f84fdff0SXiaoyan Zhang }
115f84fdff0SXiaoyan Zhang 
11681198078SXiaoyan Zhang static ssize_t tpm_store_ppi_request(struct device *dev,
117f84fdff0SXiaoyan Zhang 				     struct device_attribute *attr,
118f84fdff0SXiaoyan Zhang 				     const char *buf, size_t count)
119f84fdff0SXiaoyan Zhang {
120f84fdff0SXiaoyan Zhang 	u32 req;
121f84fdff0SXiaoyan Zhang 	u64 ret;
12284b1667dSJiang Liu 	int func = TPM_PPI_FN_SUBREQ;
123*50a81b60SStefan Berger 	union acpi_object *obj, tmp[2];
124*50a81b60SStefan Berger 	union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(2, tmp);
1259b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
126*50a81b60SStefan Berger 	u64 rev = TPM_PPI_REVISION_ID_1;
127f84fdff0SXiaoyan Zhang 
128f84fdff0SXiaoyan Zhang 	/*
129f84fdff0SXiaoyan Zhang 	 * the function to submit TPM operation request to pre-os environment
130f84fdff0SXiaoyan Zhang 	 * is updated with function index from SUBREQ to SUBREQ2 since PPI
131f84fdff0SXiaoyan Zhang 	 * version 1.1
132f84fdff0SXiaoyan Zhang 	 */
13394116f81SAndy Shevchenko 	if (acpi_check_dsm(chip->acpi_dev_handle, &tpm_ppi_guid,
13409fe1b42SStefan Berger 			   TPM_PPI_REVISION_ID_1, 1 << TPM_PPI_FN_SUBREQ2))
13584b1667dSJiang Liu 		func = TPM_PPI_FN_SUBREQ2;
13684b1667dSJiang Liu 
137f84fdff0SXiaoyan Zhang 	/*
138f84fdff0SXiaoyan Zhang 	 * PPI spec defines params[3].type as ACPI_TYPE_PACKAGE. Some BIOS
139f84fdff0SXiaoyan Zhang 	 * accept buffer/string/integer type, but some BIOS accept buffer/
140f84fdff0SXiaoyan Zhang 	 * string/package type. For PPI version 1.0 and 1.1, use buffer type
141f84fdff0SXiaoyan Zhang 	 * for compatibility, and use package type since 1.2 according to spec.
142f84fdff0SXiaoyan Zhang 	 */
143*50a81b60SStefan Berger 	if (strcmp(chip->ppi_version, "1.3") == 0) {
144*50a81b60SStefan Berger 		if (sscanf(buf, "%llu %llu", &tmp[0].integer.value,
145*50a81b60SStefan Berger 			   &tmp[1].integer.value) != 2)
146*50a81b60SStefan Berger 			goto ppi12;
147*50a81b60SStefan Berger 		rev = TPM_PPI_REVISION_ID_2;
148*50a81b60SStefan Berger 		tmp[0].type = ACPI_TYPE_INTEGER;
149*50a81b60SStefan Berger 		tmp[1].type = ACPI_TYPE_INTEGER;
150*50a81b60SStefan Berger 	} else if (strcmp(chip->ppi_version, "1.2") < 0) {
15184b1667dSJiang Liu 		if (sscanf(buf, "%d", &req) != 1)
15284b1667dSJiang Liu 			return -EINVAL;
15384b1667dSJiang Liu 		argv4.type = ACPI_TYPE_BUFFER;
15484b1667dSJiang Liu 		argv4.buffer.length = sizeof(req);
15584b1667dSJiang Liu 		argv4.buffer.pointer = (u8 *)&req;
156f84fdff0SXiaoyan Zhang 	} else {
157*50a81b60SStefan Berger ppi12:
158*50a81b60SStefan Berger 		argv4.package.count = 1;
159*50a81b60SStefan Berger 		tmp[0].type = ACPI_TYPE_INTEGER;
160*50a81b60SStefan Berger 		if (sscanf(buf, "%llu", &tmp[0].integer.value) != 1)
16184b1667dSJiang Liu 			return -EINVAL;
162f84fdff0SXiaoyan Zhang 	}
163f84fdff0SXiaoyan Zhang 
1640dc55365SJarkko Sakkinen 	obj = tpm_eval_dsm(chip->acpi_dev_handle, func, ACPI_TYPE_INTEGER,
165*50a81b60SStefan Berger 			   &argv4, rev);
16684b1667dSJiang Liu 	if (!obj) {
16784b1667dSJiang Liu 		return -ENXIO;
16884b1667dSJiang Liu 	} else {
16984b1667dSJiang Liu 		ret = obj->integer.value;
17084b1667dSJiang Liu 		ACPI_FREE(obj);
17184b1667dSJiang Liu 	}
17284b1667dSJiang Liu 
173f84fdff0SXiaoyan Zhang 	if (ret == 0)
17484b1667dSJiang Liu 		return (acpi_status)count;
17584b1667dSJiang Liu 
17684b1667dSJiang Liu 	return (ret == 1) ? -EPERM : -EFAULT;
177f84fdff0SXiaoyan Zhang }
178f84fdff0SXiaoyan Zhang 
17981198078SXiaoyan Zhang static ssize_t tpm_show_ppi_transition_action(struct device *dev,
180f84fdff0SXiaoyan Zhang 					      struct device_attribute *attr,
181f84fdff0SXiaoyan Zhang 					      char *buf)
182f84fdff0SXiaoyan Zhang {
183f84fdff0SXiaoyan Zhang 	u32 ret;
18484b1667dSJiang Liu 	acpi_status status;
18584b1667dSJiang Liu 	union acpi_object *obj = NULL;
18684b1667dSJiang Liu 	union acpi_object tmp = {
18784b1667dSJiang Liu 		.buffer.type = ACPI_TYPE_BUFFER,
18884b1667dSJiang Liu 		.buffer.length = 0,
18984b1667dSJiang Liu 		.buffer.pointer = NULL
19084b1667dSJiang Liu 	};
1919b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
19284b1667dSJiang Liu 
19384b1667dSJiang Liu 	static char *info[] = {
194f84fdff0SXiaoyan Zhang 		"None",
195f84fdff0SXiaoyan Zhang 		"Shutdown",
196f84fdff0SXiaoyan Zhang 		"Reboot",
197f84fdff0SXiaoyan Zhang 		"OS Vendor-specific",
198f84fdff0SXiaoyan Zhang 		"Error",
199f84fdff0SXiaoyan Zhang 	};
200f84fdff0SXiaoyan Zhang 
201f84fdff0SXiaoyan Zhang 	/*
202f84fdff0SXiaoyan Zhang 	 * PPI spec defines params[3].type as empty package, but some platforms
203f84fdff0SXiaoyan Zhang 	 * (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for
204f84fdff0SXiaoyan Zhang 	 * compatibility, define params[3].type as buffer, if PPI version < 1.2
205f84fdff0SXiaoyan Zhang 	 */
2060dc55365SJarkko Sakkinen 	if (strcmp(chip->ppi_version, "1.2") < 0)
20784b1667dSJiang Liu 		obj = &tmp;
2080dc55365SJarkko Sakkinen 	obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETACT,
20909fe1b42SStefan Berger 			   ACPI_TYPE_INTEGER, obj, TPM_PPI_REVISION_ID_1);
21084b1667dSJiang Liu 	if (!obj) {
21184b1667dSJiang Liu 		return -ENXIO;
21284b1667dSJiang Liu 	} else {
21384b1667dSJiang Liu 		ret = obj->integer.value;
21484b1667dSJiang Liu 		ACPI_FREE(obj);
215f84fdff0SXiaoyan Zhang 	}
21684b1667dSJiang Liu 
217f84fdff0SXiaoyan Zhang 	if (ret < ARRAY_SIZE(info) - 1)
218f84fdff0SXiaoyan Zhang 		status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, info[ret]);
219f84fdff0SXiaoyan Zhang 	else
220f84fdff0SXiaoyan Zhang 		status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret,
221f84fdff0SXiaoyan Zhang 				   info[ARRAY_SIZE(info)-1]);
222f84fdff0SXiaoyan Zhang 	return status;
223f84fdff0SXiaoyan Zhang }
224f84fdff0SXiaoyan Zhang 
22581198078SXiaoyan Zhang static ssize_t tpm_show_ppi_response(struct device *dev,
226f84fdff0SXiaoyan Zhang 				     struct device_attribute *attr,
227f84fdff0SXiaoyan Zhang 				     char *buf)
228f84fdff0SXiaoyan Zhang {
22984b1667dSJiang Liu 	acpi_status status = -EINVAL;
23084b1667dSJiang Liu 	union acpi_object *obj, *ret_obj;
23184b1667dSJiang Liu 	u64 req, res;
2329b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
233f84fdff0SXiaoyan Zhang 
2340dc55365SJarkko Sakkinen 	obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETRSP,
23509fe1b42SStefan Berger 			   ACPI_TYPE_PACKAGE, NULL, TPM_PPI_REVISION_ID_1);
23684b1667dSJiang Liu 	if (!obj)
237f84fdff0SXiaoyan Zhang 		return -ENXIO;
238f84fdff0SXiaoyan Zhang 
239f84fdff0SXiaoyan Zhang 	/*
240f84fdff0SXiaoyan Zhang 	 * parameter output.pointer should be of package type, including
241f84fdff0SXiaoyan Zhang 	 * 3 integers. The first means function return code, the second means
242f84fdff0SXiaoyan Zhang 	 * most recent TPM operation request, and the last means response to
243f84fdff0SXiaoyan Zhang 	 * the most recent TPM operation request. Only if the first is 0, and
244f84fdff0SXiaoyan Zhang 	 * the second integer is not 0, the response makes sense.
245f84fdff0SXiaoyan Zhang 	 */
24684b1667dSJiang Liu 	ret_obj = obj->package.elements;
24784b1667dSJiang Liu 	if (obj->package.count < 3 ||
24884b1667dSJiang Liu 	    ret_obj[0].type != ACPI_TYPE_INTEGER ||
24984b1667dSJiang Liu 	    ret_obj[1].type != ACPI_TYPE_INTEGER ||
25084b1667dSJiang Liu 	    ret_obj[2].type != ACPI_TYPE_INTEGER)
251f84fdff0SXiaoyan Zhang 		goto cleanup;
25284b1667dSJiang Liu 
25384b1667dSJiang Liu 	if (ret_obj[0].integer.value) {
254f84fdff0SXiaoyan Zhang 		status = -EFAULT;
255f84fdff0SXiaoyan Zhang 		goto cleanup;
256f84fdff0SXiaoyan Zhang 	}
25784b1667dSJiang Liu 
25884b1667dSJiang Liu 	req = ret_obj[1].integer.value;
25984b1667dSJiang Liu 	res = ret_obj[2].integer.value;
26084b1667dSJiang Liu 	if (req) {
26184b1667dSJiang Liu 		if (res == 0)
262f84fdff0SXiaoyan Zhang 			status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
263f84fdff0SXiaoyan Zhang 					   "0: Success");
26484b1667dSJiang Liu 		else if (res == 0xFFFFFFF0)
265f84fdff0SXiaoyan Zhang 			status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
266f84fdff0SXiaoyan Zhang 					   "0xFFFFFFF0: User Abort");
26784b1667dSJiang Liu 		else if (res == 0xFFFFFFF1)
268f84fdff0SXiaoyan Zhang 			status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req,
269f84fdff0SXiaoyan Zhang 					   "0xFFFFFFF1: BIOS Failure");
27084b1667dSJiang Liu 		else if (res >= 1 && res <= 0x00000FFF)
271f84fdff0SXiaoyan Zhang 			status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n",
27284b1667dSJiang Liu 					   req, res, "Corresponding TPM error");
273f84fdff0SXiaoyan Zhang 		else
274f84fdff0SXiaoyan Zhang 			status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n",
27584b1667dSJiang Liu 					   req, res, "Error");
276f84fdff0SXiaoyan Zhang 	} else {
277f84fdff0SXiaoyan Zhang 		status = scnprintf(buf, PAGE_SIZE, "%llu: %s\n",
27884b1667dSJiang Liu 				   req, "No Recent Request");
279f84fdff0SXiaoyan Zhang 	}
28084b1667dSJiang Liu 
281f84fdff0SXiaoyan Zhang cleanup:
28284b1667dSJiang Liu 	ACPI_FREE(obj);
283f84fdff0SXiaoyan Zhang 	return status;
284f84fdff0SXiaoyan Zhang }
285f84fdff0SXiaoyan Zhang 
2860dc55365SJarkko Sakkinen static ssize_t show_ppi_operations(acpi_handle dev_handle, char *buf, u32 start,
2870dc55365SJarkko Sakkinen 				   u32 end)
288f84fdff0SXiaoyan Zhang {
289f84fdff0SXiaoyan Zhang 	int i;
290f84fdff0SXiaoyan Zhang 	u32 ret;
29184b1667dSJiang Liu 	char *str = buf;
29284b1667dSJiang Liu 	union acpi_object *obj, tmp;
29384b1667dSJiang Liu 	union acpi_object argv = ACPI_INIT_DSM_ARGV4(1, &tmp);
29484b1667dSJiang Liu 
29584b1667dSJiang Liu 	static char *info[] = {
296f84fdff0SXiaoyan Zhang 		"Not implemented",
297f84fdff0SXiaoyan Zhang 		"BIOS only",
298f84fdff0SXiaoyan Zhang 		"Blocked for OS by BIOS",
299f84fdff0SXiaoyan Zhang 		"User required",
300f84fdff0SXiaoyan Zhang 		"User not required",
301f84fdff0SXiaoyan Zhang 	};
302f84fdff0SXiaoyan Zhang 
30309fe1b42SStefan Berger 	if (!acpi_check_dsm(dev_handle, &tpm_ppi_guid, TPM_PPI_REVISION_ID_1,
3041569a4c4SJiang Liu 			    1 << TPM_PPI_FN_GETOPR))
305f84fdff0SXiaoyan Zhang 		return -EPERM;
306f84fdff0SXiaoyan Zhang 
30784b1667dSJiang Liu 	tmp.integer.type = ACPI_TYPE_INTEGER;
308f84fdff0SXiaoyan Zhang 	for (i = start; i <= end; i++) {
30984b1667dSJiang Liu 		tmp.integer.value = i;
3100dc55365SJarkko Sakkinen 		obj = tpm_eval_dsm(dev_handle, TPM_PPI_FN_GETOPR,
311587bad77SStefan Berger 				   ACPI_TYPE_INTEGER, &argv,
31209fe1b42SStefan Berger 				   TPM_PPI_REVISION_ID_1);
31384b1667dSJiang Liu 		if (!obj) {
314f84fdff0SXiaoyan Zhang 			return -ENOMEM;
31584b1667dSJiang Liu 		} else {
31684b1667dSJiang Liu 			ret = obj->integer.value;
31784b1667dSJiang Liu 			ACPI_FREE(obj);
31884b1667dSJiang Liu 		}
319f84fdff0SXiaoyan Zhang 
320f84fdff0SXiaoyan Zhang 		if (ret > 0 && ret < ARRAY_SIZE(info))
321f84fdff0SXiaoyan Zhang 			str += scnprintf(str, PAGE_SIZE, "%d %d: %s\n",
322f84fdff0SXiaoyan Zhang 					 i, ret, info[ret]);
323f84fdff0SXiaoyan Zhang 	}
32484b1667dSJiang Liu 
325f84fdff0SXiaoyan Zhang 	return str - buf;
326f84fdff0SXiaoyan Zhang }
327f84fdff0SXiaoyan Zhang 
32881198078SXiaoyan Zhang static ssize_t tpm_show_ppi_tcg_operations(struct device *dev,
32981198078SXiaoyan Zhang 					   struct device_attribute *attr,
33081198078SXiaoyan Zhang 					   char *buf)
331f84fdff0SXiaoyan Zhang {
3329b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
3330dc55365SJarkko Sakkinen 
3340dc55365SJarkko Sakkinen 	return show_ppi_operations(chip->acpi_dev_handle, buf, 0,
3350dc55365SJarkko Sakkinen 				   PPI_TPM_REQ_MAX);
336f84fdff0SXiaoyan Zhang }
337f84fdff0SXiaoyan Zhang 
33881198078SXiaoyan Zhang static ssize_t tpm_show_ppi_vs_operations(struct device *dev,
33981198078SXiaoyan Zhang 					  struct device_attribute *attr,
34081198078SXiaoyan Zhang 					  char *buf)
341f84fdff0SXiaoyan Zhang {
3429b774d5cSJarkko Sakkinen 	struct tpm_chip *chip = to_tpm_chip(dev);
3430dc55365SJarkko Sakkinen 
3440dc55365SJarkko Sakkinen 	return show_ppi_operations(chip->acpi_dev_handle, buf, PPI_VS_REQ_START,
3450dc55365SJarkko Sakkinen 				   PPI_VS_REQ_END);
346f84fdff0SXiaoyan Zhang }
347f84fdff0SXiaoyan Zhang 
348f84fdff0SXiaoyan Zhang static DEVICE_ATTR(version, S_IRUGO, tpm_show_ppi_version, NULL);
349f84fdff0SXiaoyan Zhang static DEVICE_ATTR(request, S_IRUGO | S_IWUSR | S_IWGRP,
350f84fdff0SXiaoyan Zhang 		   tpm_show_ppi_request, tpm_store_ppi_request);
351f84fdff0SXiaoyan Zhang static DEVICE_ATTR(transition_action, S_IRUGO,
352f84fdff0SXiaoyan Zhang 		   tpm_show_ppi_transition_action, NULL);
353f84fdff0SXiaoyan Zhang static DEVICE_ATTR(response, S_IRUGO, tpm_show_ppi_response, NULL);
354f84fdff0SXiaoyan Zhang static DEVICE_ATTR(tcg_operations, S_IRUGO, tpm_show_ppi_tcg_operations, NULL);
355f84fdff0SXiaoyan Zhang static DEVICE_ATTR(vs_operations, S_IRUGO, tpm_show_ppi_vs_operations, NULL);
356f84fdff0SXiaoyan Zhang 
357f84fdff0SXiaoyan Zhang static struct attribute *ppi_attrs[] = {
358f84fdff0SXiaoyan Zhang 	&dev_attr_version.attr,
359f84fdff0SXiaoyan Zhang 	&dev_attr_request.attr,
360f84fdff0SXiaoyan Zhang 	&dev_attr_transition_action.attr,
361f84fdff0SXiaoyan Zhang 	&dev_attr_response.attr,
362f84fdff0SXiaoyan Zhang 	&dev_attr_tcg_operations.attr,
363f84fdff0SXiaoyan Zhang 	&dev_attr_vs_operations.attr, NULL,
364f84fdff0SXiaoyan Zhang };
365f84fdff0SXiaoyan Zhang static struct attribute_group ppi_attr_grp = {
3661631cfb7SGang Wei 	.name = "ppi",
367f84fdff0SXiaoyan Zhang 	.attrs = ppi_attrs
368f84fdff0SXiaoyan Zhang };
369f84fdff0SXiaoyan Zhang 
3709b774d5cSJarkko Sakkinen void tpm_add_ppi(struct tpm_chip *chip)
371f84fdff0SXiaoyan Zhang {
3720dc55365SJarkko Sakkinen 	union acpi_object *obj;
3730dc55365SJarkko Sakkinen 
3740dc55365SJarkko Sakkinen 	if (!chip->acpi_dev_handle)
3759b774d5cSJarkko Sakkinen 		return;
3760dc55365SJarkko Sakkinen 
37794116f81SAndy Shevchenko 	if (!acpi_check_dsm(chip->acpi_dev_handle, &tpm_ppi_guid,
37809fe1b42SStefan Berger 			    TPM_PPI_REVISION_ID_1, 1 << TPM_PPI_FN_VERSION))
3799b774d5cSJarkko Sakkinen 		return;
3800dc55365SJarkko Sakkinen 
3810dc55365SJarkko Sakkinen 	/* Cache PPI version string. */
38294116f81SAndy Shevchenko 	obj = acpi_evaluate_dsm_typed(chip->acpi_dev_handle, &tpm_ppi_guid,
38309fe1b42SStefan Berger 				      TPM_PPI_REVISION_ID_1,
38409fe1b42SStefan Berger 				      TPM_PPI_FN_VERSION,
3850dc55365SJarkko Sakkinen 				      NULL, ACPI_TYPE_STRING);
3860dc55365SJarkko Sakkinen 	if (obj) {
3870dc55365SJarkko Sakkinen 		strlcpy(chip->ppi_version, obj->string.pointer,
3880dc55365SJarkko Sakkinen 			sizeof(chip->ppi_version));
3890dc55365SJarkko Sakkinen 		ACPI_FREE(obj);
390f84fdff0SXiaoyan Zhang 	}
3911631cfb7SGang Wei 
3929b774d5cSJarkko Sakkinen 	chip->groups[chip->groups_cnt++] = &ppi_attr_grp;
3931631cfb7SGang Wei }
394