blob: e18f9aff0ec03386068ca7faac9da2538d4025fa [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer3008bbad2011-10-11 14:46:25 -07002
3/*
4 * The code in this file has been heavily based on the article "Writing a TPM
5 * Device Driver" published on http://ptgmedia.pearsoncmg.com and the
6 * submission by Stefan Berger on Qemu-devel mailing list.
7 *
8 * One principal difference is that in the simplest config the other than 0
9 * TPM localities do not get mapped by some devices (for instance, by
10 * Infineon slb9635), so this driver provides access to locality 0 only.
11 */
12
Elyes HAOUAS361a9352019-12-18 21:26:33 +010013#include <commonlib/helpers.h>
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070014#include <string.h>
15#include <delay.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070017#include <acpi/acpi.h>
18#include <acpi/acpigen.h>
19#include <acpi/acpi_device.h>
Naresh G Solanki80ff0382016-11-15 11:01:33 +053020#include <device/device.h>
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070021#include <console/console.h>
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +020022#include <security/tpm/tis.h>
Duncan Lauriedd281ed2014-10-30 15:20:19 -070023#include <device/pnp.h>
24#include "chip.h"
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070025
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070026#define PREFIX "lpc_tpm: "
Naresh G Solanki80ff0382016-11-15 11:01:33 +053027/* TCG Physical Presence Interface */
28#define TPM_PPI_UUID "3dddfaa6-361b-4eb4-a424-8d10089d1653"
29/* TCG Memory Clear Interface */
30#define TPM_MCI_UUID "376054ed-cc13-4675-901c-4756d7f2d45d"
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070031/* coreboot wrapper for TPM driver (start) */
32#define TPM_DEBUG(fmt, args...) \
Julius Wernercd49cce2019-03-05 16:53:33 -080033 if (CONFIG(DEBUG_TPM)) { \
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070034 printk(BIOS_DEBUG, PREFIX); \
Elyes HAOUASa342f392018-10-17 10:56:26 +020035 printk(BIOS_DEBUG, fmt, ##args); \
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070036 }
Aaron Durbinc4220022013-07-24 16:02:14 -050037#define TPM_DEBUG_IO_READ(reg_, val_) \
38 TPM_DEBUG("Read reg 0x%x returns 0x%x\n", (reg_), (val_))
39#define TPM_DEBUG_IO_WRITE(reg_, val_) \
40 TPM_DEBUG("Write reg 0x%x with 0x%x\n", (reg_), (val_))
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070041#define printf(x...) printk(BIOS_ERR, x)
42
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070043/* coreboot wrapper for TPM driver (end) */
44
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070045/* the macro accepts the locality value, but only locality 0 is operational */
46#define TIS_REG(LOCALITY, REG) \
Martin Rothb9810a42017-07-23 20:00:04 -060047 (void *)(CONFIG_TPM_TIS_BASE_ADDRESS + (LOCALITY << 12) + REG)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070048
49/* hardware registers' offsets */
50#define TIS_REG_ACCESS 0x0
51#define TIS_REG_INT_ENABLE 0x8
52#define TIS_REG_INT_VECTOR 0xc
53#define TIS_REG_INT_STATUS 0x10
54#define TIS_REG_INTF_CAPABILITY 0x14
55#define TIS_REG_STS 0x18
Aaron Durbinc4220022013-07-24 16:02:14 -050056#define TIS_REG_BURST_COUNT 0x19
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070057#define TIS_REG_DATA_FIFO 0x24
58#define TIS_REG_DID_VID 0xf00
59#define TIS_REG_RID 0xf04
60
61/* Some registers' bit field definitions */
62#define TIS_STS_VALID (1 << 7) /* 0x80 */
63#define TIS_STS_COMMAND_READY (1 << 6) /* 0x40 */
64#define TIS_STS_TPM_GO (1 << 5) /* 0x20 */
65#define TIS_STS_DATA_AVAILABLE (1 << 4) /* 0x10 */
66#define TIS_STS_EXPECT (1 << 3) /* 0x08 */
67#define TIS_STS_RESPONSE_RETRY (1 << 1) /* 0x02 */
68
69#define TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) /* 0x80 */
70#define TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) /* 0x20 */
71#define TIS_ACCESS_BEEN_SEIZED (1 << 4) /* 0x10 */
72#define TIS_ACCESS_SEIZE (1 << 3) /* 0x08 */
73#define TIS_ACCESS_PENDING_REQUEST (1 << 2) /* 0x04 */
74#define TIS_ACCESS_REQUEST_USE (1 << 1) /* 0x02 */
75#define TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) /* 0x01 */
76
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070077/*
78 * Error value returned if a tpm register does not enter the expected state
79 * after continuous polling. No actual TPM register reading ever returns ~0,
80 * so this value is a safe error indication to be mixed with possible status
81 * register values.
82 */
83#define TPM_TIMEOUT_ERR (~0)
84
85/* Error value returned on various TPM driver errors */
86#define TPM_DRIVER_ERR (~0)
87
88 /* 1 second is plenty for anything TPM does.*/
89#define MAX_DELAY_US (1000 * 1000)
90
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070091/*
92 * Structures defined below allow creating descriptions of TPM vendor/device
93 * ID information for run time discovery. The only device the system knows
94 * about at this time is Infineon slb9635
95 */
96struct device_name {
97 u16 dev_id;
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +020098 const char *const dev_name;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -070099};
100
101struct vendor_name {
102 u16 vendor_id;
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +0200103 const char *vendor_name;
104 const struct device_name *dev_names;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700105};
106
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700107static const struct device_name atmel_devices[] = {
108 {0x3204, "AT97SC3204"},
109 {0xffff}
110};
111
Stefan Reinauerc668af72011-10-27 21:28:25 +0000112static const struct device_name infineon_devices[] = {
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700113 {0x000b, "SLB9635 TT 1.2"},
Julius Wernercd49cce2019-03-05 16:53:33 -0800114#if CONFIG(TPM2)
Kamil Wcislobf5ccfd2017-10-12 13:12:11 +0200115 {0x001a, "SLB9665 TT 2.0"},
Subrata Banik5b8c4a72016-11-11 09:28:45 +0530116 {0x001b, "SLB9670 TT 2.0"},
117#else
Kamil Wcislobf5ccfd2017-10-12 13:12:11 +0200118 {0x001a, "SLB9660 TT 1.2"},
Wenkai Du641529b2015-05-29 10:54:27 -0700119 {0x001b, "SLB9670 TT 1.2"},
Subrata Banik5b8c4a72016-11-11 09:28:45 +0530120#endif
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700121 {0xffff}
122};
123
124static const struct device_name nuvoton_devices[] = {
125 {0x00fe, "NPCT420AA V2"},
126 {0xffff}
127};
128
129static const struct device_name stmicro_devices[] = {
130 {0x0000, "ST33ZP24" },
131 {0xffff}
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700132};
133
Tsung Ho Wu804a0432019-06-07 15:03:49 -0700134static const struct device_name swtpm_devices[] = {
135#if CONFIG(TPM2)
136 {0x0001, "SwTPM 2.0" },
137#endif
138 {0xffff}
139};
140
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700141static const struct vendor_name vendor_names[] = {
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700142 {0x1114, "Atmel", atmel_devices},
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700143 {0x15d1, "Infineon", infineon_devices},
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700144 {0x1050, "Nuvoton", nuvoton_devices},
Tsung Ho Wu804a0432019-06-07 15:03:49 -0700145 {0x1014, "TPM Emulator", swtpm_devices},
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700146 {0x104a, "ST Microelectronics", stmicro_devices},
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700147};
148
149/*
150 * Cached vendor/device ID pair to indicate that the device has been already
151 * discovered
152 */
Arthur Heymans0ca944b2019-11-20 19:51:06 +0100153static u32 vendor_dev_id;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700154
Aaron Durbinc4220022013-07-24 16:02:14 -0500155static inline u8 tpm_read_status(int locality)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700156{
Julius Werner2f37bd62015-02-19 14:51:15 -0800157 u8 value = read8(TIS_REG(locality, TIS_REG_STS));
Aaron Durbinc4220022013-07-24 16:02:14 -0500158 TPM_DEBUG_IO_READ(TIS_REG_STS, value);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700159 return value;
160}
161
Aaron Durbinc4220022013-07-24 16:02:14 -0500162static inline void tpm_write_status(u8 sts, int locality)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700163{
Aaron Durbinc4220022013-07-24 16:02:14 -0500164 TPM_DEBUG_IO_WRITE(TIS_REG_STS, sts);
Julius Werner2f37bd62015-02-19 14:51:15 -0800165 write8(TIS_REG(locality, TIS_REG_STS), sts);
Aaron Durbinc4220022013-07-24 16:02:14 -0500166}
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700167
Aaron Durbinc4220022013-07-24 16:02:14 -0500168static inline u8 tpm_read_data(int locality)
169{
Julius Werner2f37bd62015-02-19 14:51:15 -0800170 u8 value = read8(TIS_REG(locality, TIS_REG_DATA_FIFO));
Aaron Durbinc4220022013-07-24 16:02:14 -0500171 TPM_DEBUG_IO_READ(TIS_REG_DATA_FIFO, value);
172 return value;
173}
174
175static inline void tpm_write_data(u8 data, int locality)
176{
177 TPM_DEBUG_IO_WRITE(TIS_REG_STS, data);
Julius Werner2f37bd62015-02-19 14:51:15 -0800178 write8(TIS_REG(locality, TIS_REG_DATA_FIFO), data);
Aaron Durbinc4220022013-07-24 16:02:14 -0500179}
180
181static inline u16 tpm_read_burst_count(int locality)
182{
183 u16 count;
Julius Werner2f37bd62015-02-19 14:51:15 -0800184 count = read8(TIS_REG(locality, TIS_REG_BURST_COUNT));
185 count |= read8(TIS_REG(locality, TIS_REG_BURST_COUNT + 1)) << 8;
Aaron Durbinc4220022013-07-24 16:02:14 -0500186 TPM_DEBUG_IO_READ(TIS_REG_BURST_COUNT, count);
187 return count;
188}
189
190static inline u8 tpm_read_access(int locality)
191{
Julius Werner2f37bd62015-02-19 14:51:15 -0800192 u8 value = read8(TIS_REG(locality, TIS_REG_ACCESS));
Aaron Durbinc4220022013-07-24 16:02:14 -0500193 TPM_DEBUG_IO_READ(TIS_REG_ACCESS, value);
194 return value;
195}
196
197static inline void tpm_write_access(u8 data, int locality)
198{
199 TPM_DEBUG_IO_WRITE(TIS_REG_ACCESS, data);
Julius Werner2f37bd62015-02-19 14:51:15 -0800200 write8(TIS_REG(locality, TIS_REG_ACCESS), data);
Aaron Durbinc4220022013-07-24 16:02:14 -0500201}
202
203static inline u32 tpm_read_did_vid(int locality)
204{
Julius Werner2f37bd62015-02-19 14:51:15 -0800205 u32 value = read32(TIS_REG(locality, TIS_REG_DID_VID));
Aaron Durbinc4220022013-07-24 16:02:14 -0500206 TPM_DEBUG_IO_READ(TIS_REG_DID_VID, value);
207 return value;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700208}
209
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700210static inline void tpm_write_int_vector(int vector, int locality)
211{
212 TPM_DEBUG_IO_WRITE(TIS_REG_INT_VECTOR, vector);
Julius Werner2f37bd62015-02-19 14:51:15 -0800213 write8(TIS_REG(locality, TIS_REG_INT_VECTOR), vector & 0xf);
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700214}
215
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530216static inline u8 tpm_read_int_vector(int locality)
217{
218 u8 value = read8(TIS_REG(locality, TIS_REG_INT_VECTOR));
219 TPM_DEBUG_IO_READ(TIS_REG_INT_VECTOR, value);
220 return value;
221}
222
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700223static inline void tpm_write_int_polarity(int polarity, int locality)
224{
225 /* Set polarity and leave all other bits at 0 */
226 u32 value = (polarity & 0x3) << 3;
227 TPM_DEBUG_IO_WRITE(TIS_REG_INT_ENABLE, value);
Julius Werner2f37bd62015-02-19 14:51:15 -0800228 write32(TIS_REG(locality, TIS_REG_INT_ENABLE), value);
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700229}
230
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530231static inline u32 tpm_read_int_polarity(int locality)
232{
233 /* Get polarity and leave all other bits */
234 u32 value = read8(TIS_REG(locality, TIS_REG_INT_ENABLE));
235 value = (value >> 3) & 0x3;
236 TPM_DEBUG_IO_READ(TIS_REG_INT_ENABLE, value);
237 return value;
238}
239
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700240/*
Aaron Durbinc4220022013-07-24 16:02:14 -0500241 * tis_wait_sts()
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700242 *
Aaron Durbinc4220022013-07-24 16:02:14 -0500243 * Wait for at least a second for a status to change its state to match the
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700244 * expected state. Normally the transition happens within microseconds.
245 *
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700246 * @locality - locality
247 * @mask - bitmask for the bitfield(s) to watch
248 * @expected - value the field(s) are supposed to be set to
249 *
Aaron Durbinc4220022013-07-24 16:02:14 -0500250 * Returns 0 on success or TPM_TIMEOUT_ERR on timeout.
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700251 */
Aaron Durbinc4220022013-07-24 16:02:14 -0500252static int tis_wait_sts(int locality, u8 mask, u8 expected)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700253{
254 u32 time_us = MAX_DELAY_US;
255 while (time_us > 0) {
Aaron Durbinc4220022013-07-24 16:02:14 -0500256 u8 value = tpm_read_status(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700257 if ((value & mask) == expected)
Aaron Durbinc4220022013-07-24 16:02:14 -0500258 return 0;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700259 udelay(1); /* 1 us */
260 time_us--;
261 }
262 return TPM_TIMEOUT_ERR;
263}
264
Aaron Durbinc4220022013-07-24 16:02:14 -0500265static inline int tis_wait_ready(int locality)
266{
267 return tis_wait_sts(locality, TIS_STS_COMMAND_READY,
268 TIS_STS_COMMAND_READY);
269}
270
271static inline int tis_wait_valid(int locality)
272{
273 return tis_wait_sts(locality, TIS_STS_VALID, TIS_STS_VALID);
274}
275
276static inline int tis_wait_valid_data(int locality)
277{
278 const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID;
279 return tis_wait_sts(locality, has_data, has_data);
280}
281
282static inline int tis_has_valid_data(int locality)
283{
284 const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID;
285 return (tpm_read_status(locality) & has_data) == has_data;
286}
287
288static inline int tis_expect_data(int locality)
289{
290 return !!(tpm_read_status(locality) & TIS_STS_EXPECT);
291}
292
293/*
294 * tis_wait_access()
295 *
296 * Wait for at least a second for a access to change its state to match the
297 * expected state. Normally the transition happens within microseconds.
298 *
299 * @locality - locality
300 * @mask - bitmask for the bitfield(s) to watch
301 * @expected - value the field(s) are supposed to be set to
302 *
303 * Returns 0 on success or TPM_TIMEOUT_ERR on timeout.
304 */
305static int tis_wait_access(int locality, u8 mask, u8 expected)
306{
307 u32 time_us = MAX_DELAY_US;
308 while (time_us > 0) {
309 u8 value = tpm_read_access(locality);
310 if ((value & mask) == expected)
311 return 0;
312 udelay(1); /* 1 us */
313 time_us--;
314 }
315 return TPM_TIMEOUT_ERR;
316}
317
318static inline int tis_wait_dropped_access(int locality)
319{
320 return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY, 0);
321}
322
323static inline int tis_wait_received_access(int locality)
324{
325 return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY,
326 TIS_ACCESS_ACTIVE_LOCALITY);
327}
328
329static inline int tis_has_access(int locality)
330{
331 return !!(tpm_read_access(locality) & TIS_ACCESS_ACTIVE_LOCALITY);
332}
333
334static inline void tis_request_access(int locality)
335{
336 tpm_write_access(TIS_ACCESS_REQUEST_USE, locality);
337}
338
339static inline void tis_drop_access(int locality)
340{
341 tpm_write_access(TIS_ACCESS_ACTIVE_LOCALITY, locality);
342}
343
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700344/*
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700345 * PC Client Specific TPM Interface Specification section 11.2.12:
346 *
347 * Software must be prepared to send two writes of a "1" to command ready
348 * field: the first to indicate successful read of all the data, thus
349 * clearing the data from the ReadFIFO and freeing the TPM's resources,
350 * and the second to indicate to the TPM it is about to send a new command.
351 *
352 * In practice not all TPMs behave the same so it is necessary to be
353 * flexible when trying to set command ready.
354 *
355 * Returns 0 on success if the TPM is ready for transactions.
356 * Returns TPM_TIMEOUT_ERR if the command ready bit does not get set.
357 */
358static int tis_command_ready(u8 locality)
359{
360 u32 status;
361
362 /* 1st attempt to set command ready */
Aaron Durbinc4220022013-07-24 16:02:14 -0500363 tpm_write_status(TIS_STS_COMMAND_READY, locality);
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700364
365 /* Wait for response */
Aaron Durbinc4220022013-07-24 16:02:14 -0500366 status = tpm_read_status(locality);
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700367
368 /* Check if command ready is set yet */
369 if (status & TIS_STS_COMMAND_READY)
370 return 0;
371
372 /* 2nd attempt to set command ready */
Aaron Durbinc4220022013-07-24 16:02:14 -0500373 tpm_write_status(TIS_STS_COMMAND_READY, locality);
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700374
Aaron Durbinc4220022013-07-24 16:02:14 -0500375 return tis_wait_ready(locality);
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700376}
377
378/*
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700379 * Probe the TPM device and try determining its manufacturer/device name.
380 *
381 * Returns 0 on success (the device is found or was found during an earlier
382 * invocation) or TPM_DRIVER_ERR if the device is not found.
383 */
384static u32 tis_probe(void)
385{
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700386 const char *device_name = "unknown";
387 const char *vendor_name = device_name;
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700388 const struct device_name *dev;
389 u32 didvid;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700390 u16 vid, did;
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700391 int i;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700392
Arthur Heymans0ca944b2019-11-20 19:51:06 +0100393 if (vendor_dev_id)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700394 return 0; /* Already probed. */
395
Aaron Durbinc4220022013-07-24 16:02:14 -0500396 didvid = tpm_read_did_vid(0);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700397 if (!didvid || (didvid == 0xffffffff)) {
Angel Pons08e8cab2020-06-18 15:20:37 +0200398 printf("%s: No TPM device found\n", __func__);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700399 return TPM_DRIVER_ERR;
400 }
401
Arthur Heymans0ca944b2019-11-20 19:51:06 +0100402 vendor_dev_id = didvid;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700403
404 vid = didvid & 0xffff;
405 did = (didvid >> 16) & 0xffff;
406 for (i = 0; i < ARRAY_SIZE(vendor_names); i++) {
407 int j = 0;
408 u16 known_did;
409 if (vid == vendor_names[i].vendor_id) {
410 vendor_name = vendor_names[i].vendor_name;
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700411 } else {
412 continue;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700413 }
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700414 dev = &vendor_names[i].dev_names[j];
415 while ((known_did = dev->dev_id) != 0xffff) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700416 if (known_did == did) {
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700417 device_name = dev->dev_name;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700418 break;
419 }
420 j++;
Subrata41b08d92015-05-14 14:38:07 +0530421 dev = &vendor_names[i].dev_names[j];
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700422 }
423 break;
424 }
425 /* this will have to be converted into debug printout */
Duncan Laurie17ba9442015-09-03 16:00:49 -0700426 printk(BIOS_INFO, "Found TPM %s by %s\n", device_name, vendor_name);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700427 return 0;
428}
429
430/*
431 * tis_senddata()
432 *
433 * send the passed in data to the TPM device.
434 *
435 * @data - address of the data to send, byte by byte
436 * @len - length of the data to send
437 *
438 * Returns 0 on success, TPM_DRIVER_ERR on error (in case the device does
439 * not accept the entire command).
440 */
Elyes HAOUASb0b0c8c2018-07-08 12:33:47 +0200441static u32 tis_senddata(const u8 *const data, u32 len)
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700442{
443 u32 offset = 0;
444 u16 burst = 0;
445 u32 max_cycles = 0;
446 u8 locality = 0;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700447
Aaron Durbinc4220022013-07-24 16:02:14 -0500448 if (tis_wait_ready(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700449 printf("%s:%d - failed to get 'command_ready' status\n",
450 __FILE__, __LINE__);
451 return TPM_DRIVER_ERR;
452 }
Aaron Durbinc4220022013-07-24 16:02:14 -0500453 burst = tpm_read_burst_count(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700454
455 while (1) {
Martin Roth38ddbfb2019-10-23 21:41:00 -0600456 unsigned int count;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700457
458 /* Wait till the device is ready to accept more data. */
459 while (!burst) {
460 if (max_cycles++ == MAX_DELAY_US) {
461 printf("%s:%d failed to feed %d bytes of %d\n",
462 __FILE__, __LINE__, len - offset, len);
463 return TPM_DRIVER_ERR;
464 }
465 udelay(1);
Aaron Durbinc4220022013-07-24 16:02:14 -0500466 burst = tpm_read_burst_count(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700467 }
468
469 max_cycles = 0;
470
471 /*
472 * Calculate number of bytes the TPM is ready to accept in one
473 * shot.
474 *
475 * We want to send the last byte outside of the loop (hence
476 * the -1 below) to make sure that the 'expected' status bit
477 * changes to zero exactly after the last byte is fed into the
478 * FIFO.
479 */
Elyes HAOUAS361a9352019-12-18 21:26:33 +0100480 count = MIN(burst, len - offset - 1);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700481 while (count--)
Aaron Durbinc4220022013-07-24 16:02:14 -0500482 tpm_write_data(data[offset++], locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700483
Aaron Durbinc4220022013-07-24 16:02:14 -0500484 if (tis_wait_valid(locality) || !tis_expect_data(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700485 printf("%s:%d TPM command feed overflow\n",
486 __FILE__, __LINE__);
487 return TPM_DRIVER_ERR;
488 }
489
Aaron Durbinc4220022013-07-24 16:02:14 -0500490 burst = tpm_read_burst_count(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700491 if ((offset == (len - 1)) && burst)
492 /*
493 * We need to be able to send the last byte to the
494 * device, so burst size must be nonzero before we
495 * break out.
496 */
497 break;
498 }
499
500 /* Send the last byte. */
Aaron Durbinc4220022013-07-24 16:02:14 -0500501 tpm_write_data(data[offset++], locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700502
503 /*
504 * Verify that TPM does not expect any more data as part of this
505 * command.
506 */
Aaron Durbinc4220022013-07-24 16:02:14 -0500507 if (tis_wait_valid(locality) || tis_expect_data(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700508 printf("%s:%d unexpected TPM status 0x%x\n",
Aaron Durbinc4220022013-07-24 16:02:14 -0500509 __FILE__, __LINE__, tpm_read_status(locality));
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700510 return TPM_DRIVER_ERR;
511 }
512
513 /* OK, sitting pretty, let's start the command execution. */
Aaron Durbinc4220022013-07-24 16:02:14 -0500514 tpm_write_status(TIS_STS_TPM_GO, locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700515
516 return 0;
517}
518
519/*
520 * tis_readresponse()
521 *
522 * read the TPM device response after a command was issued.
523 *
524 * @buffer - address where to read the response, byte by byte.
525 * @len - pointer to the size of buffer
526 *
527 * On success stores the number of received bytes to len and returns 0. On
528 * errors (misformatted TPM data or synchronization problems) returns
529 * TPM_DRIVER_ERR.
530 */
531static u32 tis_readresponse(u8 *buffer, size_t *len)
532{
533 u16 burst_count;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700534 u32 offset = 0;
535 u8 locality = 0;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700536 u32 expected_count = *len;
537 int max_cycles = 0;
538
539 /* Wait for the TPM to process the command */
Aaron Durbinc4220022013-07-24 16:02:14 -0500540 if (tis_wait_valid_data(locality)) {
541 printf("%s:%d failed processing command\n", __FILE__, __LINE__);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700542 return TPM_DRIVER_ERR;
543 }
544
545 do {
Aaron Durbinc4220022013-07-24 16:02:14 -0500546 while ((burst_count = tpm_read_burst_count(locality)) == 0) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700547 if (max_cycles++ == MAX_DELAY_US) {
548 printf("%s:%d TPM stuck on read\n",
549 __FILE__, __LINE__);
550 return TPM_DRIVER_ERR;
551 }
552 udelay(1);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700553 }
554
555 max_cycles = 0;
556
557 while (burst_count-- && (offset < expected_count)) {
Aaron Durbinc4220022013-07-24 16:02:14 -0500558 buffer[offset++] = tpm_read_data(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700559 if (offset == 6) {
560 /*
561 * We got the first six bytes of the reply,
562 * let's figure out how many bytes to expect
563 * total - it is stored as a 4 byte number in
564 * network order, starting with offset 2 into
565 * the body of the reply.
566 */
567 u32 real_length;
568 memcpy(&real_length,
569 buffer + 2,
570 sizeof(real_length));
571 expected_count = be32_to_cpu(real_length);
572
573 if ((expected_count < offset) ||
574 (expected_count > *len)) {
575 printf("%s:%d bad response size %d\n",
576 __FILE__, __LINE__,
577 expected_count);
578 return TPM_DRIVER_ERR;
579 }
580 }
581 }
582
583 /* Wait for the next portion */
Aaron Durbinc4220022013-07-24 16:02:14 -0500584 if (tis_wait_valid(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700585 printf("%s:%d failed to read response\n",
586 __FILE__, __LINE__);
587 return TPM_DRIVER_ERR;
588 }
589
590 if (offset == expected_count)
591 break; /* We got all we need */
592
Bill XIEa4bf0b72018-03-22 17:07:43 +0800593 /*
594 * Certain TPMs seem to need some delay between tis_wait_valid()
595 * and tis_has_valid_data(), or some race-condition-related
596 * issue will occur.
597 */
Julius Wernercd49cce2019-03-05 16:53:33 -0800598 if (CONFIG(TPM_RDRESP_NEED_DELAY))
Bill XIEa4bf0b72018-03-22 17:07:43 +0800599 udelay(10);
600
Aaron Durbinc4220022013-07-24 16:02:14 -0500601 } while (tis_has_valid_data(locality));
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700602
Aaron Durbinc4220022013-07-24 16:02:14 -0500603 /* * Make sure we indeed read all there was. */
604 if (tis_has_valid_data(locality)) {
605 printf("%s:%d wrong receive status: %x %d bytes left\n",
606 __FILE__, __LINE__, tpm_read_status(locality),
607 tpm_read_burst_count(locality));
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700608 return TPM_DRIVER_ERR;
609 }
610
611 /* Tell the TPM that we are done. */
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700612 if (tis_command_ready(locality) == TPM_TIMEOUT_ERR)
613 return TPM_DRIVER_ERR;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700614
615 *len = offset;
616 return 0;
617}
618
619/*
620 * tis_init()
621 *
622 * Initialize the TPM device. Returns 0 on success or TPM_DRIVER_ERR on
623 * failure (in case device probing did not succeed).
624 */
625int tis_init(void)
626{
627 if (tis_probe())
628 return TPM_DRIVER_ERR;
629 return 0;
630}
631
632/*
633 * tis_open()
634 *
635 * Requests access to locality 0 for the caller. After all commands have been
636 * completed the caller is supposed to call tis_close().
637 *
638 * Returns 0 on success, TPM_DRIVER_ERR on failure.
639 */
640int tis_open(void)
641{
642 u8 locality = 0; /* we use locality zero for everything */
643
644 if (tis_close())
645 return TPM_DRIVER_ERR;
646
647 /* now request access to locality */
Aaron Durbinc4220022013-07-24 16:02:14 -0500648 tis_request_access(locality);
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700649
650 /* did we get a lock? */
Aaron Durbinc4220022013-07-24 16:02:14 -0500651 if (tis_wait_received_access(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700652 printf("%s:%d - failed to lock locality %d\n",
653 __FILE__, __LINE__, locality);
654 return TPM_DRIVER_ERR;
655 }
656
Stefan Reinauerc908fc72012-04-30 16:33:44 -0700657 /* Certain TPMs seem to need some delay here or they hang... */
658 udelay(10);
659
660 if (tis_command_ready(locality) == TPM_TIMEOUT_ERR)
661 return TPM_DRIVER_ERR;
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700662
663 return 0;
664}
665
666/*
667 * tis_close()
668 *
Martin Roth56889792013-07-09 21:39:46 -0600669 * terminate the current session with the TPM by releasing the locked
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700670 * locality. Returns 0 on success of TPM_DRIVER_ERR on failure (in case lock
671 * removal did not succeed).
672 */
673int tis_close(void)
674{
675 u8 locality = 0;
Aaron Durbinc4220022013-07-24 16:02:14 -0500676 if (tis_has_access(locality)) {
677 tis_drop_access(locality);
678 if (tis_wait_dropped_access(locality)) {
Stefan Reinauer3008bbad2011-10-11 14:46:25 -0700679 printf("%s:%d - failed to release locality %d\n",
680 __FILE__, __LINE__, locality);
681 return TPM_DRIVER_ERR;
682 }
683 }
684 return 0;
685}
686
687/*
688 * tis_sendrecv()
689 *
690 * Send the requested data to the TPM and then try to get its response
691 *
692 * @sendbuf - buffer of the data to send
693 * @send_size size of the data to send
694 * @recvbuf - memory to save the response to
695 * @recv_len - pointer to the size of the response buffer
696 *
697 * Returns 0 on success (and places the number of response bytes at recv_len)
698 * or TPM_DRIVER_ERR on failure.
699 */
700int tis_sendrecv(const uint8_t *sendbuf, size_t send_size,
701 uint8_t *recvbuf, size_t *recv_len)
702{
703 if (tis_senddata(sendbuf, send_size)) {
704 printf("%s:%d failed sending data to TPM\n",
705 __FILE__, __LINE__);
706 return TPM_DRIVER_ERR;
707 }
708
709 return tis_readresponse(recvbuf, recv_len);
710}
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700711
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700712/*
713 * tis_setup_interrupt()
714 *
715 * Set up the interrupt vector and polarity for locality 0 and
716 * disable all interrupts so they are unused in firmware but can
717 * be enabled by the OS.
718 *
719 * The values used here must match what is passed in the TPM ACPI
720 * device if ACPI is used on the platform.
721 *
722 * @vector - TPM interrupt vector
723 * @polarity - TPM interrupt polarity
724 *
725 * Returns 0 on success, TPM_DRIVER_ERR on failure.
726 */
727static int tis_setup_interrupt(int vector, int polarity)
728{
729 u8 locality = 0;
730 int has_access = tis_has_access(locality);
731
732 /* Open connection and request access if not already granted */
733 if (!has_access && tis_open() < 0)
734 return TPM_DRIVER_ERR;
735
736 /* Set TPM interrupt vector */
737 tpm_write_int_vector(vector, locality);
738
Elyes HAOUAS18958382018-08-07 12:23:16 +0200739 /* Set TPM interrupt polarity and disable interrupts */
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700740 tpm_write_int_polarity(polarity, locality);
741
742 /* Close connection if it was opened */
743 if (!has_access && tis_close() < 0)
744 return TPM_DRIVER_ERR;
745
746 return 0;
747}
748
749static void lpc_tpm_read_resources(struct device *dev)
750{
751 /* Static 5K memory region specified in Kconfig */
752 mmio_resource(dev, 0, CONFIG_TPM_TIS_BASE_ADDRESS >> 10, 0x5000 >> 10);
753}
754
755static void lpc_tpm_set_resources(struct device *dev)
756{
757 tpm_config_t *config = (tpm_config_t *)dev->chip_info;
Kyösti Mälkkibaa16e92019-11-05 18:38:00 +0200758 DEVTREE_CONST struct resource *res;
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700759
760 for (res = dev->resource_list; res; res = res->next) {
761 if (!(res->flags & IORESOURCE_ASSIGNED))
762 continue;
763
764 if (res->flags & IORESOURCE_IRQ) {
765 /* Set interrupt vector */
766 tis_setup_interrupt((int)res->base,
767 config->irq_polarity);
768 } else {
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700769 continue;
770 }
771
Kyösti Mälkkibaa16e92019-11-05 18:38:00 +0200772#if !DEVTREE_EARLY
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700773 res->flags |= IORESOURCE_STORED;
774 report_resource_stored(dev, res, " <tpm>");
Kyösti Mälkkibaa16e92019-11-05 18:38:00 +0200775#endif
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700776 }
777}
778
Julius Wernercd49cce2019-03-05 16:53:33 -0800779#if CONFIG(HAVE_ACPI_TABLES)
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530780
781static void tpm_ppi_func0_cb(void *arg)
782{
783 /* Functions 1-8. */
784 u8 buf[] = {0xff, 0x01};
785 acpigen_write_return_byte_buffer(buf, 2);
786}
787
788static void tpm_ppi_func1_cb(void *arg)
789{
Julius Wernercd49cce2019-03-05 16:53:33 -0800790 if (CONFIG(TPM2))
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530791 /* Interface version: 2.0 */
792 acpigen_write_return_string("2.0");
793 else
794 /* Interface version: 1.2 */
795 acpigen_write_return_string("1.2");
796}
797
798static void tpm_ppi_func2_cb(void *arg)
799{
800 /* Submit operations: drop on the floor and return success. */
801 acpigen_write_return_byte(0);
802}
803
804static void tpm_ppi_func3_cb(void *arg)
805{
806 /* Pending operation: none. */
807 acpigen_emit_byte(RETURN_OP);
808 acpigen_write_package(2);
809 acpigen_write_byte(0);
810 acpigen_write_byte(0);
811 acpigen_pop_len();
812}
813static void tpm_ppi_func4_cb(void *arg)
814{
815 /* Pre-OS transition method: reboot. */
816 acpigen_write_return_byte(2);
817}
818static void tpm_ppi_func5_cb(void *arg)
819{
820 /* Operation response: no operation executed. */
821 acpigen_emit_byte(RETURN_OP);
822 acpigen_write_package(3);
823 acpigen_write_byte(0);
824 acpigen_write_byte(0);
825 acpigen_write_byte(0);
826 acpigen_pop_len();
827}
828static void tpm_ppi_func6_cb(void *arg)
829{
830 /*
831 * Set preferred user language: deprecated and must return 3 aka
832 * "not implemented".
833 */
834 acpigen_write_return_byte(3);
835}
836static void tpm_ppi_func7_cb(void *arg)
837{
838 /* Submit operations: deny. */
839 acpigen_write_return_byte(3);
840}
841static void tpm_ppi_func8_cb(void *arg)
842{
843 /* All actions are forbidden. */
844 acpigen_write_return_byte(1);
845}
846static void (*tpm_ppi_callbacks[])(void *) = {
847 tpm_ppi_func0_cb,
848 tpm_ppi_func1_cb,
849 tpm_ppi_func2_cb,
850 tpm_ppi_func3_cb,
851 tpm_ppi_func4_cb,
852 tpm_ppi_func5_cb,
853 tpm_ppi_func6_cb,
854 tpm_ppi_func7_cb,
855 tpm_ppi_func8_cb,
856};
857
858static void tpm_mci_func0_cb(void *arg)
859{
860 /* Function 1. */
861 acpigen_write_return_singleton_buffer(0x3);
862}
863static void tpm_mci_func1_cb(void *arg)
864{
865 /* Just return success. */
866 acpigen_write_return_byte(0);
867}
868
869static void (*tpm_mci_callbacks[])(void *) = {
870 tpm_mci_func0_cb,
871 tpm_mci_func1_cb,
872};
873
Furquan Shaikh7536a392020-04-24 21:59:21 -0700874static void lpc_tpm_fill_ssdt(const struct device *dev)
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530875{
876 const char *path = acpi_device_path(dev->bus->dev);
877 u32 arg;
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530878
Philipp Deppenwiese3a1fbea2016-12-14 01:06:55 +0100879 if (!path) {
Tobias Diedrich36537f12017-02-10 00:28:45 +0100880 path = "\\_SB_.PCI0.LPCB";
Philipp Deppenwiese3a1fbea2016-12-14 01:06:55 +0100881 printk(BIOS_DEBUG, "Using default TPM ACPI path: '%s'\n", path);
882 }
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530883
884 /* Device */
885 acpigen_write_scope(path);
886 acpigen_write_device(acpi_device_name(dev));
887
Michał Żygowski7b288012020-03-20 15:41:44 +0100888 if (CONFIG(TPM2)) {
889 acpigen_write_name_string("_HID", "MSFT0101");
890 acpigen_write_name_string("_CID", "MSFT0101");
891 } else {
892 acpigen_write_name("_HID");
893 acpigen_emit_eisaid("PNP0C31");
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530894
Michał Żygowski7b288012020-03-20 15:41:44 +0100895 acpigen_write_name("_CID");
896 acpigen_emit_eisaid("PNP0C31");
897 }
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530898
Patrick Rudolphc83bab62019-12-13 12:16:06 +0100899 acpi_device_write_uid(dev);
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530900
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530901 u32 did_vid = tpm_read_did_vid(0);
902 if (did_vid > 0 && did_vid < 0xffffffff)
903 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
904 else
905 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_OFF);
906
Kevin Cody-Littlec97b5af2018-05-09 14:14:59 -0400907 u16 port = dev->path.pnp.port;
908
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530909 /* Resources */
910 acpigen_write_name("_CRS");
911 acpigen_write_resourcetemplate_header();
912 acpigen_write_mem32fixed(1, CONFIG_TPM_TIS_BASE_ADDRESS, 0x5000);
Frans Hendriks6cc937e2018-10-29 14:30:58 +0100913 if (port)
914 acpigen_write_io16(port, port, 1, 2, 1);
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530915
916 if (CONFIG_TPM_PIRQ) {
917 /*
918 * PIRQ: Update interrupt vector with configured PIRQ
919 * Active-Low Level-Triggered Shared
920 */
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800921 struct acpi_irq tpm_irq_a = ACPI_IRQ_LEVEL_LOW(CONFIG_TPM_PIRQ);
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530922 acpi_device_write_interrupt(&tpm_irq_a);
923 } else if (tpm_read_int_vector(0) > 0) {
924 u8 int_vec = tpm_read_int_vector(0);
925 u8 int_pol = tpm_read_int_polarity(0);
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800926 struct acpi_irq tpm_irq = ACPI_IRQ_LEVEL_LOW(int_vec);
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530927
928 if (int_pol & 1)
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800929 tpm_irq.polarity = ACPI_IRQ_ACTIVE_LOW;
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530930 else
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800931 tpm_irq.polarity = ACPI_IRQ_ACTIVE_HIGH;
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530932
933 if (int_pol & 2)
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800934 tpm_irq.mode = ACPI_IRQ_EDGE_TRIGGERED;
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530935 else
Furquan Shaikh5b9b5932017-02-21 13:16:30 -0800936 tpm_irq.mode = ACPI_IRQ_LEVEL_TRIGGERED;
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530937
938 acpi_device_write_interrupt(&tpm_irq);
939 }
940
941 acpigen_write_resourcetemplate_footer();
942
Julius Wernercd49cce2019-03-05 16:53:33 -0800943 if (!CONFIG(CHROMEOS)) {
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530944 /*
945 * _DSM method
946 */
947 struct dsm_uuid ids[] = {
948 /* Physical presence interface.
949 * This is used to submit commands like "Clear TPM" to
950 * be run at next reboot provided that user confirms
951 * them. Spec allows user to cancel all commands and/or
952 * configure BIOS to reject commands. So we pretend that
953 * user did just this: cancelled everything. If user
954 * really wants to clear TPM the only option now is to
955 * do it manually in payload.
956 */
957 DSM_UUID(TPM_PPI_UUID, &tpm_ppi_callbacks[0],
958 ARRAY_SIZE(tpm_ppi_callbacks), (void *) &arg),
959 /* Memory clearing on boot: just a dummy. */
960 DSM_UUID(TPM_MCI_UUID, &tpm_mci_callbacks[0],
961 ARRAY_SIZE(tpm_mci_callbacks), (void *) &arg),
962 };
963
964 acpigen_write_dsm_uuid_arr(ids, ARRAY_SIZE(ids));
965 }
966 acpigen_pop_len(); /* Device */
967 acpigen_pop_len(); /* Scope */
968
Kyösti Mälkkibaa16e92019-11-05 18:38:00 +0200969#if !DEVTREE_EARLY
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530970 printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
971 dev->chip_ops->name, dev_path(dev));
Kyösti Mälkkibaa16e92019-11-05 18:38:00 +0200972#endif
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530973}
974
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600975static const char *lpc_tpm_acpi_name(const struct device *dev)
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530976{
977 return "TPM";
978}
979#endif
980
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700981static struct device_operations lpc_tpm_ops = {
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100982 .read_resources = lpc_tpm_read_resources,
983 .set_resources = lpc_tpm_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800984#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200985 .acpi_name = lpc_tpm_acpi_name,
986 .acpi_fill_ssdt = lpc_tpm_fill_ssdt,
Naresh G Solanki80ff0382016-11-15 11:01:33 +0530987#endif
Duncan Lauriedd281ed2014-10-30 15:20:19 -0700988};
989
990static struct pnp_info pnp_dev_info[] = {
991 { .flags = PNP_IRQ0 }
992};
993
994static void enable_dev(struct device *dev)
995{
996 pnp_enable_devices(dev, &lpc_tpm_ops,
997 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
998}
999
1000struct chip_operations drivers_pc80_tpm_ops = {
1001 CHIP_NAME("LPC TPM")
1002 .enable_dev = enable_dev
1003};