• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <types.h>
4 #include <acpi/acpigen.h>
5 #include <acpi/acpi_device.h>
6 
7 #include "tpm_ppi.h"
8 
tpm_ppi_func0_cb(void * arg)9 static void tpm_ppi_func0_cb(void *arg)
10 {
11 	/* Functions 1-8. */
12 	u8 buf[] = {0xff, 0x01};
13 	acpigen_write_return_byte_buffer(buf, sizeof(buf));
14 }
15 
tpm_ppi_func1_cb(void * arg)16 static void tpm_ppi_func1_cb(void *arg)
17 {
18 	if (CONFIG(TPM2))
19 		/* Interface version: 1.3 */
20 		acpigen_write_return_string("1.3");
21 	else
22 		/* Interface version: 1.2 */
23 		acpigen_write_return_string("1.2");
24 }
25 
tpm_ppi_func2_cb(void * arg)26 static void tpm_ppi_func2_cb(void *arg)
27 {
28 	/* Submit operations: drop on the floor and return success. */
29 	acpigen_write_return_byte(PPI2_RET_SUCCESS);
30 }
31 
tpm_ppi_func3_cb(void * arg)32 static void tpm_ppi_func3_cb(void *arg)
33 {
34 	/* Pending operation: none. */
35 	acpigen_emit_byte(RETURN_OP);
36 	acpigen_write_package(2);
37 	acpigen_write_byte(0);
38 	acpigen_write_byte(0);
39 	acpigen_pop_len();
40 }
41 
tpm_ppi_func4_cb(void * arg)42 static void tpm_ppi_func4_cb(void *arg)
43 {
44 	/* Pre-OS transition method: reboot. */
45 	acpigen_write_return_byte(2);
46 }
47 
tpm_ppi_func5_cb(void * arg)48 static void tpm_ppi_func5_cb(void *arg)
49 {
50 	/* Operation response: no operation executed. */
51 	acpigen_emit_byte(RETURN_OP);
52 	acpigen_write_package(3);
53 	acpigen_write_byte(0);
54 	acpigen_write_byte(0);
55 	acpigen_write_byte(0);
56 	acpigen_pop_len();
57 }
58 
tpm_ppi_func6_cb(void * arg)59 static void tpm_ppi_func6_cb(void *arg)
60 {
61 	/*
62 	 * Set preferred user language: deprecated and must return 3 AKA
63 	 * "not implemented".
64 	 */
65 	acpigen_write_return_byte(PPI6_RET_NOT_IMPLEMENTED);
66 }
67 
tpm_ppi_func7_cb(void * arg)68 static void tpm_ppi_func7_cb(void *arg)
69 {
70 	/* Submit operations: deny. */
71 	acpigen_write_return_byte(PPI7_RET_BLOCKED_BY_FIRMWARE);
72 }
73 
tpm_ppi_func8_cb(void * arg)74 static void tpm_ppi_func8_cb(void *arg)
75 {
76 	/* All actions are forbidden. */
77 	acpigen_write_return_byte(PPI8_RET_FIRMWARE_ONLY);
78 }
79 
80 static void (*tpm_ppi_callbacks[])(void *) = {
81 	tpm_ppi_func0_cb,
82 	tpm_ppi_func1_cb,
83 	tpm_ppi_func2_cb,
84 	tpm_ppi_func3_cb,
85 	tpm_ppi_func4_cb,
86 	tpm_ppi_func5_cb,
87 	tpm_ppi_func6_cb,
88 	tpm_ppi_func7_cb,
89 	tpm_ppi_func8_cb,
90 };
91 
tpm_mci_func0_cb(void * arg)92 static void tpm_mci_func0_cb(void *arg)
93 {
94 	/* Function 1. */
95 	acpigen_write_return_singleton_buffer(0x3);
96 }
tpm_mci_func1_cb(void * arg)97 static void tpm_mci_func1_cb(void *arg)
98 {
99 	/* Just return success. */
100 	acpigen_write_return_byte(0);
101 }
102 
103 static void (*tpm_mci_callbacks[])(void *) = {
104 	tpm_mci_func0_cb,
105 	tpm_mci_func1_cb,
106 };
107 
tpm_ppi_acpi_fill_ssdt(const struct device * dev)108 void tpm_ppi_acpi_fill_ssdt(const struct device *dev)
109 {
110 	/*
111 	 * _DSM method
112 	 */
113 	struct dsm_uuid ids[] = {
114 		/* Physical presence interface.
115 		 * This is used to submit commands like "Clear TPM" to
116 		 * be run at next reboot provided that user confirms
117 		 * them. Spec allows user to cancel all commands and/or
118 		 * configure BIOS to reject commands. So we pretend that
119 		 * user did just this: cancelled everything. If user
120 		 * really wants to clear TPM the only option now is to
121 		 * do it manually in payload.
122 		 */
123 		DSM_UUID(TPM_PPI_UUID, tpm_ppi_callbacks,
124 			ARRAY_SIZE(tpm_ppi_callbacks), NULL),
125 		/* Memory clearing on boot: just a dummy. */
126 		DSM_UUID(TPM_MCI_UUID, tpm_mci_callbacks,
127 			ARRAY_SIZE(tpm_mci_callbacks), NULL),
128 	};
129 
130 	acpigen_write_dsm_uuid_arr(ids, ARRAY_SIZE(ids));
131 }
132