• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2005, 2006 IBM Corporation
4  * Copyright (C) 2014, 2015 Intel Corporation
5  *
6  * Authors:
7  * Leendert van Doorn <leendert@watson.ibm.com>
8  * Kylene Hall <kjhall@us.ibm.com>
9  *
10  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
11  *
12  * Device driver for TCG/TCPA TPM (trusted platform module).
13  * Specifications at www.trustedcomputinggroup.org
14  *
15  * This device driver implements the TPM interface as defined in
16  * the TCG TPM Interface Spec version 1.2, revision 1.0.
17  */
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/pnp.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/wait.h>
25 #include <linux/acpi.h>
26 #include <linux/freezer.h>
27 #include "tpm.h"
28 #include "tpm_tis_core.h"
29 
30 static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value);
31 
wait_for_tpm_stat_cond(struct tpm_chip * chip,u8 mask,bool check_cancel,bool * canceled)32 static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
33 					bool check_cancel, bool *canceled)
34 {
35 	u8 status = chip->ops->status(chip);
36 
37 	*canceled = false;
38 	if ((status & mask) == mask)
39 		return true;
40 	if (check_cancel && chip->ops->req_canceled(chip, status)) {
41 		*canceled = true;
42 		return true;
43 	}
44 	return false;
45 }
46 
wait_for_tpm_stat(struct tpm_chip * chip,u8 mask,unsigned long timeout,wait_queue_head_t * queue,bool check_cancel)47 static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,
48 		unsigned long timeout, wait_queue_head_t *queue,
49 		bool check_cancel)
50 {
51 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
52 	unsigned long stop;
53 	long rc;
54 	u8 status;
55 	bool canceled = false;
56 
57 	/* check current status */
58 	status = chip->ops->status(chip);
59 	if ((status & mask) == mask)
60 		return 0;
61 
62 	stop = jiffies + timeout;
63 
64 	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
65 again:
66 		timeout = stop - jiffies;
67 		if ((long)timeout <= 0)
68 			return -ETIME;
69 		rc = wait_event_interruptible_timeout(*queue,
70 			wait_for_tpm_stat_cond(chip, mask, check_cancel,
71 					       &canceled),
72 			timeout);
73 		if (rc > 0) {
74 			if (canceled)
75 				return -ECANCELED;
76 			return 0;
77 		}
78 		if (rc == -ERESTARTSYS && freezing(current)) {
79 			clear_thread_flag(TIF_SIGPENDING);
80 			goto again;
81 		}
82 	} else {
83 		do {
84 			usleep_range(priv->timeout_min,
85 				     priv->timeout_max);
86 			status = chip->ops->status(chip);
87 			if ((status & mask) == mask)
88 				return 0;
89 		} while (time_before(jiffies, stop));
90 	}
91 	return -ETIME;
92 }
93 
94 /* Before we attempt to access the TPM we must see that the valid bit is set.
95  * The specification says that this bit is 0 at reset and remains 0 until the
96  * 'TPM has gone through its self test and initialization and has established
97  * correct values in the other bits.'
98  */
wait_startup(struct tpm_chip * chip,int l)99 static int wait_startup(struct tpm_chip *chip, int l)
100 {
101 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
102 	unsigned long stop = jiffies + chip->timeout_a;
103 
104 	do {
105 		int rc;
106 		u8 access;
107 
108 		rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
109 		if (rc < 0)
110 			return rc;
111 
112 		if (access & TPM_ACCESS_VALID)
113 			return 0;
114 		tpm_msleep(TPM_TIMEOUT);
115 	} while (time_before(jiffies, stop));
116 	return -1;
117 }
118 
check_locality(struct tpm_chip * chip,int l)119 static bool check_locality(struct tpm_chip *chip, int l)
120 {
121 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
122 	int rc;
123 	u8 access;
124 
125 	rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
126 	if (rc < 0)
127 		return false;
128 
129 	if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID
130 		       | TPM_ACCESS_REQUEST_USE)) ==
131 	    (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
132 		priv->locality = l;
133 		return true;
134 	}
135 
136 	return false;
137 }
138 
__tpm_tis_relinquish_locality(struct tpm_tis_data * priv,int l)139 static int __tpm_tis_relinquish_locality(struct tpm_tis_data *priv, int l)
140 {
141 	tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
142 
143 	return 0;
144 }
145 
tpm_tis_relinquish_locality(struct tpm_chip * chip,int l)146 static int tpm_tis_relinquish_locality(struct tpm_chip *chip, int l)
147 {
148 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
149 
150 	mutex_lock(&priv->locality_count_mutex);
151 	priv->locality_count--;
152 	if (priv->locality_count == 0)
153 		__tpm_tis_relinquish_locality(priv, l);
154 	mutex_unlock(&priv->locality_count_mutex);
155 
156 	return 0;
157 }
158 
__tpm_tis_request_locality(struct tpm_chip * chip,int l)159 static int __tpm_tis_request_locality(struct tpm_chip *chip, int l)
160 {
161 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
162 	unsigned long stop, timeout;
163 	long rc;
164 
165 	if (check_locality(chip, l))
166 		return l;
167 
168 	rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE);
169 	if (rc < 0)
170 		return rc;
171 
172 	stop = jiffies + chip->timeout_a;
173 
174 	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
175 again:
176 		timeout = stop - jiffies;
177 		if ((long)timeout <= 0)
178 			return -1;
179 		rc = wait_event_interruptible_timeout(priv->int_queue,
180 						      (check_locality
181 						       (chip, l)),
182 						      timeout);
183 		if (rc > 0)
184 			return l;
185 		if (rc == -ERESTARTSYS && freezing(current)) {
186 			clear_thread_flag(TIF_SIGPENDING);
187 			goto again;
188 		}
189 	} else {
190 		/* wait for burstcount */
191 		do {
192 			if (check_locality(chip, l))
193 				return l;
194 			tpm_msleep(TPM_TIMEOUT);
195 		} while (time_before(jiffies, stop));
196 	}
197 	return -1;
198 }
199 
tpm_tis_request_locality(struct tpm_chip * chip,int l)200 static int tpm_tis_request_locality(struct tpm_chip *chip, int l)
201 {
202 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
203 	int ret = 0;
204 
205 	mutex_lock(&priv->locality_count_mutex);
206 	if (priv->locality_count == 0)
207 		ret = __tpm_tis_request_locality(chip, l);
208 	if (!ret)
209 		priv->locality_count++;
210 	mutex_unlock(&priv->locality_count_mutex);
211 	return ret;
212 }
213 
tpm_tis_status(struct tpm_chip * chip)214 static u8 tpm_tis_status(struct tpm_chip *chip)
215 {
216 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
217 	int rc;
218 	u8 status;
219 
220 	rc = tpm_tis_read8(priv, TPM_STS(priv->locality), &status);
221 	if (rc < 0)
222 		return 0;
223 
224 	if (unlikely((status & TPM_STS_READ_ZERO) != 0)) {
225 		if  (!test_and_set_bit(TPM_TIS_INVALID_STATUS, &priv->flags)) {
226 			/*
227 			 * If this trips, the chances are the read is
228 			 * returning 0xff because the locality hasn't been
229 			 * acquired.  Usually because tpm_try_get_ops() hasn't
230 			 * been called before doing a TPM operation.
231 			 */
232 			dev_err(&chip->dev, "invalid TPM_STS.x 0x%02x, dumping stack for forensics\n",
233 				status);
234 
235 			/*
236 			 * Dump stack for forensics, as invalid TPM_STS.x could be
237 			 * potentially triggered by impaired tpm_try_get_ops() or
238 			 * tpm_find_get_ops().
239 			 */
240 			dump_stack();
241 		}
242 
243 		return 0;
244 	}
245 
246 	return status;
247 }
248 
tpm_tis_ready(struct tpm_chip * chip)249 static void tpm_tis_ready(struct tpm_chip *chip)
250 {
251 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
252 
253 	/* this causes the current command to be aborted */
254 	tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_COMMAND_READY);
255 }
256 
get_burstcount(struct tpm_chip * chip)257 static int get_burstcount(struct tpm_chip *chip)
258 {
259 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
260 	unsigned long stop;
261 	int burstcnt, rc;
262 	u32 value;
263 
264 	/* wait for burstcount */
265 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
266 		stop = jiffies + chip->timeout_a;
267 	else
268 		stop = jiffies + chip->timeout_d;
269 	do {
270 		rc = tpm_tis_read32(priv, TPM_STS(priv->locality), &value);
271 		if (rc < 0)
272 			return rc;
273 
274 		burstcnt = (value >> 8) & 0xFFFF;
275 		if (burstcnt)
276 			return burstcnt;
277 		usleep_range(TPM_TIMEOUT_USECS_MIN, TPM_TIMEOUT_USECS_MAX);
278 	} while (time_before(jiffies, stop));
279 	return -EBUSY;
280 }
281 
recv_data(struct tpm_chip * chip,u8 * buf,size_t count)282 static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
283 {
284 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
285 	int size = 0, burstcnt, rc;
286 
287 	while (size < count) {
288 		rc = wait_for_tpm_stat(chip,
289 				 TPM_STS_DATA_AVAIL | TPM_STS_VALID,
290 				 chip->timeout_c,
291 				 &priv->read_queue, true);
292 		if (rc < 0)
293 			return rc;
294 		burstcnt = get_burstcount(chip);
295 		if (burstcnt < 0) {
296 			dev_err(&chip->dev, "Unable to read burstcount\n");
297 			return burstcnt;
298 		}
299 		burstcnt = min_t(int, burstcnt, count - size);
300 
301 		rc = tpm_tis_read_bytes(priv, TPM_DATA_FIFO(priv->locality),
302 					burstcnt, buf + size);
303 		if (rc < 0)
304 			return rc;
305 
306 		size += burstcnt;
307 	}
308 	return size;
309 }
310 
tpm_tis_recv(struct tpm_chip * chip,u8 * buf,size_t count)311 static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
312 {
313 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
314 	int size = 0;
315 	int status;
316 	u32 expected;
317 	int rc;
318 
319 	if (count < TPM_HEADER_SIZE) {
320 		size = -EIO;
321 		goto out;
322 	}
323 
324 	size = recv_data(chip, buf, TPM_HEADER_SIZE);
325 	/* read first 10 bytes, including tag, paramsize, and result */
326 	if (size < TPM_HEADER_SIZE) {
327 		dev_err(&chip->dev, "Unable to read header\n");
328 		goto out;
329 	}
330 
331 	expected = be32_to_cpu(*(__be32 *) (buf + 2));
332 	if (expected > count || expected < TPM_HEADER_SIZE) {
333 		size = -EIO;
334 		goto out;
335 	}
336 
337 	rc = recv_data(chip, &buf[TPM_HEADER_SIZE],
338 		       expected - TPM_HEADER_SIZE);
339 	if (rc < 0) {
340 		size = rc;
341 		goto out;
342 	}
343 	size += rc;
344 	if (size < expected) {
345 		dev_err(&chip->dev, "Unable to read remainder of result\n");
346 		size = -ETIME;
347 		goto out;
348 	}
349 
350 	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
351 				&priv->int_queue, false) < 0) {
352 		size = -ETIME;
353 		goto out;
354 	}
355 	status = tpm_tis_status(chip);
356 	if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
357 		dev_err(&chip->dev, "Error left over data\n");
358 		size = -EIO;
359 		goto out;
360 	}
361 
362 out:
363 	tpm_tis_ready(chip);
364 	return size;
365 }
366 
367 /*
368  * If interrupts are used (signaled by an irq set in the vendor structure)
369  * tpm.c can skip polling for the data to be available as the interrupt is
370  * waited for here
371  */
tpm_tis_send_data(struct tpm_chip * chip,const u8 * buf,size_t len)372 static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
373 {
374 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
375 	int rc, status, burstcnt;
376 	size_t count = 0;
377 	bool itpm = priv->flags & TPM_TIS_ITPM_WORKAROUND;
378 
379 	status = tpm_tis_status(chip);
380 	if ((status & TPM_STS_COMMAND_READY) == 0) {
381 		tpm_tis_ready(chip);
382 		if (wait_for_tpm_stat
383 		    (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
384 		     &priv->int_queue, false) < 0) {
385 			rc = -ETIME;
386 			goto out_err;
387 		}
388 	}
389 
390 	while (count < len - 1) {
391 		burstcnt = get_burstcount(chip);
392 		if (burstcnt < 0) {
393 			dev_err(&chip->dev, "Unable to read burstcount\n");
394 			rc = burstcnt;
395 			goto out_err;
396 		}
397 		burstcnt = min_t(int, burstcnt, len - count - 1);
398 		rc = tpm_tis_write_bytes(priv, TPM_DATA_FIFO(priv->locality),
399 					 burstcnt, buf + count);
400 		if (rc < 0)
401 			goto out_err;
402 
403 		count += burstcnt;
404 
405 		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
406 					&priv->int_queue, false) < 0) {
407 			rc = -ETIME;
408 			goto out_err;
409 		}
410 		status = tpm_tis_status(chip);
411 		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
412 			rc = -EIO;
413 			goto out_err;
414 		}
415 	}
416 
417 	/* write last byte */
418 	rc = tpm_tis_write8(priv, TPM_DATA_FIFO(priv->locality), buf[count]);
419 	if (rc < 0)
420 		goto out_err;
421 
422 	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
423 				&priv->int_queue, false) < 0) {
424 		rc = -ETIME;
425 		goto out_err;
426 	}
427 	status = tpm_tis_status(chip);
428 	if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
429 		rc = -EIO;
430 		goto out_err;
431 	}
432 
433 	return 0;
434 
435 out_err:
436 	tpm_tis_ready(chip);
437 	return rc;
438 }
439 
disable_interrupts(struct tpm_chip * chip)440 static void disable_interrupts(struct tpm_chip *chip)
441 {
442 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
443 	u32 intmask;
444 	int rc;
445 
446 	if (priv->irq == 0)
447 		return;
448 
449 	rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
450 	if (rc < 0)
451 		intmask = 0;
452 
453 	intmask &= ~TPM_GLOBAL_INT_ENABLE;
454 	rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
455 
456 	devm_free_irq(chip->dev.parent, priv->irq, chip);
457 	priv->irq = 0;
458 	chip->flags &= ~TPM_CHIP_FLAG_IRQ;
459 }
460 
461 /*
462  * If interrupts are used (signaled by an irq set in the vendor structure)
463  * tpm.c can skip polling for the data to be available as the interrupt is
464  * waited for here
465  */
tpm_tis_send_main(struct tpm_chip * chip,const u8 * buf,size_t len)466 static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
467 {
468 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
469 	int rc;
470 	u32 ordinal;
471 	unsigned long dur;
472 
473 	rc = tpm_tis_send_data(chip, buf, len);
474 	if (rc < 0)
475 		return rc;
476 
477 	/* go and do it */
478 	rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
479 	if (rc < 0)
480 		goto out_err;
481 
482 	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
483 		ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
484 
485 		dur = tpm_calc_ordinal_duration(chip, ordinal);
486 		if (wait_for_tpm_stat
487 		    (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur,
488 		     &priv->read_queue, false) < 0) {
489 			rc = -ETIME;
490 			goto out_err;
491 		}
492 	}
493 	return 0;
494 out_err:
495 	tpm_tis_ready(chip);
496 	return rc;
497 }
498 
tpm_tis_send(struct tpm_chip * chip,u8 * buf,size_t len)499 static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
500 {
501 	int rc, irq;
502 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
503 
504 	if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested)
505 		return tpm_tis_send_main(chip, buf, len);
506 
507 	/* Verify receipt of the expected IRQ */
508 	irq = priv->irq;
509 	priv->irq = 0;
510 	chip->flags &= ~TPM_CHIP_FLAG_IRQ;
511 	rc = tpm_tis_send_main(chip, buf, len);
512 	priv->irq = irq;
513 	chip->flags |= TPM_CHIP_FLAG_IRQ;
514 	if (!priv->irq_tested)
515 		tpm_msleep(1);
516 	if (!priv->irq_tested)
517 		disable_interrupts(chip);
518 	priv->irq_tested = true;
519 	return rc;
520 }
521 
522 struct tis_vendor_durations_override {
523 	u32 did_vid;
524 	struct tpm1_version version;
525 	unsigned long durations[3];
526 };
527 
528 static const struct  tis_vendor_durations_override vendor_dur_overrides[] = {
529 	/* STMicroelectronics 0x104a */
530 	{ 0x0000104a,
531 	  { 1, 2, 8, 28 },
532 	  { (2 * 60 * HZ), (2 * 60 * HZ), (2 * 60 * HZ) } },
533 };
534 
tpm_tis_update_durations(struct tpm_chip * chip,unsigned long * duration_cap)535 static void tpm_tis_update_durations(struct tpm_chip *chip,
536 				     unsigned long *duration_cap)
537 {
538 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
539 	struct tpm1_version *version;
540 	u32 did_vid;
541 	int i, rc;
542 	cap_t cap;
543 
544 	chip->duration_adjusted = false;
545 
546 	if (chip->ops->clk_enable != NULL)
547 		chip->ops->clk_enable(chip, true);
548 
549 	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
550 	if (rc < 0) {
551 		dev_warn(&chip->dev, "%s: failed to read did_vid. %d\n",
552 			 __func__, rc);
553 		goto out;
554 	}
555 
556 	/* Try to get a TPM version 1.2 or 1.1 TPM_CAP_VERSION_INFO */
557 	rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap,
558 			 "attempting to determine the 1.2 version",
559 			 sizeof(cap.version2));
560 	if (!rc) {
561 		version = &cap.version2.version;
562 	} else {
563 		rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap,
564 				 "attempting to determine the 1.1 version",
565 				 sizeof(cap.version1));
566 
567 		if (rc)
568 			goto out;
569 
570 		version = &cap.version1;
571 	}
572 
573 	for (i = 0; i != ARRAY_SIZE(vendor_dur_overrides); i++) {
574 		if (vendor_dur_overrides[i].did_vid != did_vid)
575 			continue;
576 
577 		if ((version->major ==
578 		     vendor_dur_overrides[i].version.major) &&
579 		    (version->minor ==
580 		     vendor_dur_overrides[i].version.minor) &&
581 		    (version->rev_major ==
582 		     vendor_dur_overrides[i].version.rev_major) &&
583 		    (version->rev_minor ==
584 		     vendor_dur_overrides[i].version.rev_minor)) {
585 
586 			memcpy(duration_cap,
587 			       vendor_dur_overrides[i].durations,
588 			       sizeof(vendor_dur_overrides[i].durations));
589 
590 			chip->duration_adjusted = true;
591 			goto out;
592 		}
593 	}
594 
595 out:
596 	if (chip->ops->clk_enable != NULL)
597 		chip->ops->clk_enable(chip, false);
598 }
599 
600 struct tis_vendor_timeout_override {
601 	u32 did_vid;
602 	unsigned long timeout_us[4];
603 };
604 
605 static const struct tis_vendor_timeout_override vendor_timeout_overrides[] = {
606 	/* Atmel 3204 */
607 	{ 0x32041114, { (TIS_SHORT_TIMEOUT*1000), (TIS_LONG_TIMEOUT*1000),
608 			(TIS_SHORT_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000) } },
609 };
610 
tpm_tis_update_timeouts(struct tpm_chip * chip,unsigned long * timeout_cap)611 static void tpm_tis_update_timeouts(struct tpm_chip *chip,
612 				    unsigned long *timeout_cap)
613 {
614 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
615 	int i, rc;
616 	u32 did_vid;
617 
618 	chip->timeout_adjusted = false;
619 
620 	if (chip->ops->clk_enable != NULL)
621 		chip->ops->clk_enable(chip, true);
622 
623 	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
624 	if (rc < 0) {
625 		dev_warn(&chip->dev, "%s: failed to read did_vid: %d\n",
626 			 __func__, rc);
627 		goto out;
628 	}
629 
630 	for (i = 0; i != ARRAY_SIZE(vendor_timeout_overrides); i++) {
631 		if (vendor_timeout_overrides[i].did_vid != did_vid)
632 			continue;
633 		memcpy(timeout_cap, vendor_timeout_overrides[i].timeout_us,
634 		       sizeof(vendor_timeout_overrides[i].timeout_us));
635 		chip->timeout_adjusted = true;
636 	}
637 
638 out:
639 	if (chip->ops->clk_enable != NULL)
640 		chip->ops->clk_enable(chip, false);
641 
642 	return;
643 }
644 
645 /*
646  * Early probing for iTPM with STS_DATA_EXPECT flaw.
647  * Try sending command without itpm flag set and if that
648  * fails, repeat with itpm flag set.
649  */
probe_itpm(struct tpm_chip * chip)650 static int probe_itpm(struct tpm_chip *chip)
651 {
652 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
653 	int rc = 0;
654 	static const u8 cmd_getticks[] = {
655 		0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
656 		0x00, 0x00, 0x00, 0xf1
657 	};
658 	size_t len = sizeof(cmd_getticks);
659 	u16 vendor;
660 
661 	if (priv->flags & TPM_TIS_ITPM_WORKAROUND)
662 		return 0;
663 
664 	rc = tpm_tis_read16(priv, TPM_DID_VID(0), &vendor);
665 	if (rc < 0)
666 		return rc;
667 
668 	/* probe only iTPMS */
669 	if (vendor != TPM_VID_INTEL)
670 		return 0;
671 
672 	if (tpm_tis_request_locality(chip, 0) != 0)
673 		return -EBUSY;
674 
675 	rc = tpm_tis_send_data(chip, cmd_getticks, len);
676 	if (rc == 0)
677 		goto out;
678 
679 	tpm_tis_ready(chip);
680 
681 	priv->flags |= TPM_TIS_ITPM_WORKAROUND;
682 
683 	rc = tpm_tis_send_data(chip, cmd_getticks, len);
684 	if (rc == 0)
685 		dev_info(&chip->dev, "Detected an iTPM.\n");
686 	else {
687 		priv->flags &= ~TPM_TIS_ITPM_WORKAROUND;
688 		rc = -EFAULT;
689 	}
690 
691 out:
692 	tpm_tis_ready(chip);
693 	tpm_tis_relinquish_locality(chip, priv->locality);
694 
695 	return rc;
696 }
697 
tpm_tis_req_canceled(struct tpm_chip * chip,u8 status)698 static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
699 {
700 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
701 
702 	switch (priv->manufacturer_id) {
703 	case TPM_VID_WINBOND:
704 		return ((status == TPM_STS_VALID) ||
705 			(status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
706 	case TPM_VID_STM:
707 		return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
708 	default:
709 		return (status == TPM_STS_COMMAND_READY);
710 	}
711 }
712 
tis_int_handler(int dummy,void * dev_id)713 static irqreturn_t tis_int_handler(int dummy, void *dev_id)
714 {
715 	struct tpm_chip *chip = dev_id;
716 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
717 	u32 interrupt;
718 	int i, rc;
719 
720 	rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
721 	if (rc < 0)
722 		return IRQ_NONE;
723 
724 	if (interrupt == 0)
725 		return IRQ_NONE;
726 
727 	priv->irq_tested = true;
728 	if (interrupt & TPM_INTF_DATA_AVAIL_INT)
729 		wake_up_interruptible(&priv->read_queue);
730 	if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
731 		for (i = 0; i < 5; i++)
732 			if (check_locality(chip, i))
733 				break;
734 	if (interrupt &
735 	    (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
736 	     TPM_INTF_CMD_READY_INT))
737 		wake_up_interruptible(&priv->int_queue);
738 
739 	/* Clear interrupts handled with TPM_EOI */
740 	tpm_tis_request_locality(chip, 0);
741 	rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), interrupt);
742 	tpm_tis_relinquish_locality(chip, 0);
743 	if (rc < 0)
744 		return IRQ_NONE;
745 
746 	tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &interrupt);
747 	return IRQ_HANDLED;
748 }
749 
tpm_tis_gen_interrupt(struct tpm_chip * chip)750 static void tpm_tis_gen_interrupt(struct tpm_chip *chip)
751 {
752 	const char *desc = "attempting to generate an interrupt";
753 	u32 cap2;
754 	cap_t cap;
755 	int ret;
756 
757 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
758 		ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
759 	else
760 		ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0);
761 }
762 
763 /* Register the IRQ and issue a command that will cause an interrupt. If an
764  * irq is seen then leave the chip setup for IRQ operation, otherwise reverse
765  * everything and leave in polling mode. Returns 0 on success.
766  */
tpm_tis_probe_irq_single(struct tpm_chip * chip,u32 intmask,int flags,int irq)767 static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
768 				    int flags, int irq)
769 {
770 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
771 	u8 original_int_vec;
772 	int rc;
773 	u32 int_status;
774 
775 
776 	rc = devm_request_threaded_irq(chip->dev.parent, irq, NULL,
777 				       tis_int_handler, IRQF_ONESHOT | flags,
778 				       dev_name(&chip->dev), chip);
779 	if (rc) {
780 		dev_info(&chip->dev, "Unable to request irq: %d for probe\n",
781 			 irq);
782 		return -1;
783 	}
784 	priv->irq = irq;
785 
786 	rc = tpm_tis_request_locality(chip, 0);
787 	if (rc < 0)
788 		return rc;
789 
790 	rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality),
791 			   &original_int_vec);
792 	if (rc < 0) {
793 		tpm_tis_relinquish_locality(chip, priv->locality);
794 		return rc;
795 	}
796 
797 	rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq);
798 	if (rc < 0)
799 		goto restore_irqs;
800 
801 	rc = tpm_tis_read32(priv, TPM_INT_STATUS(priv->locality), &int_status);
802 	if (rc < 0)
803 		goto restore_irqs;
804 
805 	/* Clear all existing */
806 	rc = tpm_tis_write32(priv, TPM_INT_STATUS(priv->locality), int_status);
807 	if (rc < 0)
808 		goto restore_irqs;
809 	/* Turn on */
810 	rc = tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality),
811 			     intmask | TPM_GLOBAL_INT_ENABLE);
812 	if (rc < 0)
813 		goto restore_irqs;
814 
815 	priv->irq_tested = false;
816 
817 	/* Generate an interrupt by having the core call through to
818 	 * tpm_tis_send
819 	 */
820 	tpm_tis_gen_interrupt(chip);
821 
822 restore_irqs:
823 	/* tpm_tis_send will either confirm the interrupt is working or it
824 	 * will call disable_irq which undoes all of the above.
825 	 */
826 	if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
827 		tpm_tis_write8(priv, original_int_vec,
828 			       TPM_INT_VECTOR(priv->locality));
829 		rc = -1;
830 	}
831 
832 	tpm_tis_relinquish_locality(chip, priv->locality);
833 
834 	return rc;
835 }
836 
837 /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that
838  * do not have ACPI/etc. We typically expect the interrupt to be declared if
839  * present.
840  */
tpm_tis_probe_irq(struct tpm_chip * chip,u32 intmask)841 static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask)
842 {
843 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
844 	u8 original_int_vec;
845 	int i, rc;
846 
847 	rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality),
848 			   &original_int_vec);
849 	if (rc < 0)
850 		return;
851 
852 	if (!original_int_vec) {
853 		if (IS_ENABLED(CONFIG_X86))
854 			for (i = 3; i <= 15; i++)
855 				if (!tpm_tis_probe_irq_single(chip, intmask, 0,
856 							      i))
857 					return;
858 	} else if (!tpm_tis_probe_irq_single(chip, intmask, 0,
859 					     original_int_vec))
860 		return;
861 }
862 
tpm_tis_remove(struct tpm_chip * chip)863 void tpm_tis_remove(struct tpm_chip *chip)
864 {
865 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
866 	u32 reg = TPM_INT_ENABLE(priv->locality);
867 	u32 interrupt;
868 	int rc;
869 
870 	tpm_tis_clkrun_enable(chip, true);
871 
872 	rc = tpm_tis_read32(priv, reg, &interrupt);
873 	if (rc < 0)
874 		interrupt = 0;
875 
876 	tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt);
877 
878 	tpm_tis_clkrun_enable(chip, false);
879 
880 	if (priv->ilb_base_addr)
881 		iounmap(priv->ilb_base_addr);
882 }
883 EXPORT_SYMBOL_GPL(tpm_tis_remove);
884 
885 /**
886  * tpm_tis_clkrun_enable() - Keep clkrun protocol disabled for entire duration
887  *                           of a single TPM command
888  * @chip:	TPM chip to use
889  * @value:	1 - Disable CLKRUN protocol, so that clocks are free running
890  *		0 - Enable CLKRUN protocol
891  * Call this function directly in tpm_tis_remove() in error or driver removal
892  * path, since the chip->ops is set to NULL in tpm_chip_unregister().
893  */
tpm_tis_clkrun_enable(struct tpm_chip * chip,bool value)894 static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
895 {
896 	struct tpm_tis_data *data = dev_get_drvdata(&chip->dev);
897 	u32 clkrun_val;
898 
899 	if (!IS_ENABLED(CONFIG_X86) || !is_bsw() ||
900 	    !data->ilb_base_addr)
901 		return;
902 
903 	if (value) {
904 		data->clkrun_enabled++;
905 		if (data->clkrun_enabled > 1)
906 			return;
907 		clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
908 
909 		/* Disable LPC CLKRUN# */
910 		clkrun_val &= ~LPC_CLKRUN_EN;
911 		iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
912 
913 		/*
914 		 * Write any random value on port 0x80 which is on LPC, to make
915 		 * sure LPC clock is running before sending any TPM command.
916 		 */
917 		outb(0xCC, 0x80);
918 	} else {
919 		data->clkrun_enabled--;
920 		if (data->clkrun_enabled)
921 			return;
922 
923 		clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
924 
925 		/* Enable LPC CLKRUN# */
926 		clkrun_val |= LPC_CLKRUN_EN;
927 		iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
928 
929 		/*
930 		 * Write any random value on port 0x80 which is on LPC, to make
931 		 * sure LPC clock is running before sending any TPM command.
932 		 */
933 		outb(0xCC, 0x80);
934 	}
935 }
936 
937 static const struct tpm_class_ops tpm_tis = {
938 	.flags = TPM_OPS_AUTO_STARTUP,
939 	.status = tpm_tis_status,
940 	.recv = tpm_tis_recv,
941 	.send = tpm_tis_send,
942 	.cancel = tpm_tis_ready,
943 	.update_timeouts = tpm_tis_update_timeouts,
944 	.update_durations = tpm_tis_update_durations,
945 	.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
946 	.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
947 	.req_canceled = tpm_tis_req_canceled,
948 	.request_locality = tpm_tis_request_locality,
949 	.relinquish_locality = tpm_tis_relinquish_locality,
950 	.clk_enable = tpm_tis_clkrun_enable,
951 };
952 
tpm_tis_core_init(struct device * dev,struct tpm_tis_data * priv,int irq,const struct tpm_tis_phy_ops * phy_ops,acpi_handle acpi_dev_handle)953 int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
954 		      const struct tpm_tis_phy_ops *phy_ops,
955 		      acpi_handle acpi_dev_handle)
956 {
957 	u32 vendor;
958 	u32 intfcaps;
959 	u32 intmask;
960 	u32 clkrun_val;
961 	u8 rid;
962 	int rc, probe;
963 	struct tpm_chip *chip;
964 
965 	chip = tpmm_chip_alloc(dev, &tpm_tis);
966 	if (IS_ERR(chip))
967 		return PTR_ERR(chip);
968 
969 #ifdef CONFIG_ACPI
970 	chip->acpi_dev_handle = acpi_dev_handle;
971 #endif
972 
973 	chip->hwrng.quality = priv->rng_quality;
974 
975 	/* Maximum timeouts */
976 	chip->timeout_a = msecs_to_jiffies(TIS_TIMEOUT_A_MAX);
977 	chip->timeout_b = msecs_to_jiffies(TIS_TIMEOUT_B_MAX);
978 	chip->timeout_c = msecs_to_jiffies(TIS_TIMEOUT_C_MAX);
979 	chip->timeout_d = msecs_to_jiffies(TIS_TIMEOUT_D_MAX);
980 	priv->timeout_min = TPM_TIMEOUT_USECS_MIN;
981 	priv->timeout_max = TPM_TIMEOUT_USECS_MAX;
982 	priv->phy_ops = phy_ops;
983 	priv->locality_count = 0;
984 	mutex_init(&priv->locality_count_mutex);
985 
986 	dev_set_drvdata(&chip->dev, priv);
987 
988 	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor);
989 	if (rc < 0)
990 		return rc;
991 
992 	priv->manufacturer_id = vendor;
993 
994 	if (priv->manufacturer_id == TPM_VID_ATML &&
995 		!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
996 		priv->timeout_min = TIS_TIMEOUT_MIN_ATML;
997 		priv->timeout_max = TIS_TIMEOUT_MAX_ATML;
998 	}
999 
1000 	if (is_bsw()) {
1001 		priv->ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR,
1002 					ILB_REMAP_SIZE);
1003 		if (!priv->ilb_base_addr)
1004 			return -ENOMEM;
1005 
1006 		clkrun_val = ioread32(priv->ilb_base_addr + LPC_CNTRL_OFFSET);
1007 		/* Check if CLKRUN# is already not enabled in the LPC bus */
1008 		if (!(clkrun_val & LPC_CLKRUN_EN)) {
1009 			iounmap(priv->ilb_base_addr);
1010 			priv->ilb_base_addr = NULL;
1011 		}
1012 	}
1013 
1014 	if (chip->ops->clk_enable != NULL)
1015 		chip->ops->clk_enable(chip, true);
1016 
1017 	if (wait_startup(chip, 0) != 0) {
1018 		rc = -ENODEV;
1019 		goto out_err;
1020 	}
1021 
1022 	/* Take control of the TPM's interrupt hardware and shut it off */
1023 	rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
1024 	if (rc < 0)
1025 		goto out_err;
1026 
1027 	intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT |
1028 		   TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
1029 	intmask &= ~TPM_GLOBAL_INT_ENABLE;
1030 
1031 	rc = tpm_tis_request_locality(chip, 0);
1032 	if (rc < 0) {
1033 		rc = -ENODEV;
1034 		goto out_err;
1035 	}
1036 
1037 	tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
1038 	tpm_tis_relinquish_locality(chip, 0);
1039 
1040 	rc = tpm_chip_start(chip);
1041 	if (rc)
1042 		goto out_err;
1043 	rc = tpm2_probe(chip);
1044 	tpm_chip_stop(chip);
1045 	if (rc)
1046 		goto out_err;
1047 
1048 	rc = tpm_tis_read8(priv, TPM_RID(0), &rid);
1049 	if (rc < 0)
1050 		goto out_err;
1051 
1052 	dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n",
1053 		 (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
1054 		 vendor >> 16, rid);
1055 
1056 	probe = probe_itpm(chip);
1057 	if (probe < 0) {
1058 		rc = -ENODEV;
1059 		goto out_err;
1060 	}
1061 
1062 	/* Figure out the capabilities */
1063 	rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps);
1064 	if (rc < 0)
1065 		goto out_err;
1066 
1067 	dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
1068 		intfcaps);
1069 	if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
1070 		dev_dbg(dev, "\tBurst Count Static\n");
1071 	if (intfcaps & TPM_INTF_CMD_READY_INT)
1072 		dev_dbg(dev, "\tCommand Ready Int Support\n");
1073 	if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
1074 		dev_dbg(dev, "\tInterrupt Edge Falling\n");
1075 	if (intfcaps & TPM_INTF_INT_EDGE_RISING)
1076 		dev_dbg(dev, "\tInterrupt Edge Rising\n");
1077 	if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
1078 		dev_dbg(dev, "\tInterrupt Level Low\n");
1079 	if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
1080 		dev_dbg(dev, "\tInterrupt Level High\n");
1081 	if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
1082 		dev_dbg(dev, "\tLocality Change Int Support\n");
1083 	if (intfcaps & TPM_INTF_STS_VALID_INT)
1084 		dev_dbg(dev, "\tSts Valid Int Support\n");
1085 	if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
1086 		dev_dbg(dev, "\tData Avail Int Support\n");
1087 
1088 	/* INTERRUPT Setup */
1089 	init_waitqueue_head(&priv->read_queue);
1090 	init_waitqueue_head(&priv->int_queue);
1091 	if (irq != -1) {
1092 		/*
1093 		 * Before doing irq testing issue a command to the TPM in polling mode
1094 		 * to make sure it works. May as well use that command to set the
1095 		 * proper timeouts for the driver.
1096 		 */
1097 
1098 		rc = tpm_tis_request_locality(chip, 0);
1099 		if (rc < 0)
1100 			goto out_err;
1101 
1102 		rc = tpm_get_timeouts(chip);
1103 
1104 		tpm_tis_relinquish_locality(chip, 0);
1105 
1106 		if (rc) {
1107 			dev_err(dev, "Could not get TPM timeouts and durations\n");
1108 			rc = -ENODEV;
1109 			goto out_err;
1110 		}
1111 
1112 		if (irq)
1113 			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
1114 						 irq);
1115 		else
1116 			tpm_tis_probe_irq(chip, intmask);
1117 
1118 		if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
1119 			dev_err(&chip->dev, FW_BUG
1120 					"TPM interrupt not working, polling instead\n");
1121 
1122 			rc = tpm_tis_request_locality(chip, 0);
1123 			if (rc < 0)
1124 				goto out_err;
1125 			disable_interrupts(chip);
1126 			tpm_tis_relinquish_locality(chip, 0);
1127 		}
1128 	}
1129 
1130 	rc = tpm_chip_register(chip);
1131 	if (rc)
1132 		goto out_err;
1133 
1134 	if (chip->ops->clk_enable != NULL)
1135 		chip->ops->clk_enable(chip, false);
1136 
1137 	return 0;
1138 out_err:
1139 	if (chip->ops->clk_enable != NULL)
1140 		chip->ops->clk_enable(chip, false);
1141 
1142 	tpm_tis_remove(chip);
1143 
1144 	return rc;
1145 }
1146 EXPORT_SYMBOL_GPL(tpm_tis_core_init);
1147 
1148 #ifdef CONFIG_PM_SLEEP
tpm_tis_reenable_interrupts(struct tpm_chip * chip)1149 static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
1150 {
1151 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
1152 	u32 intmask;
1153 	int rc;
1154 
1155 	if (chip->ops->clk_enable != NULL)
1156 		chip->ops->clk_enable(chip, true);
1157 
1158 	/* reenable interrupts that device may have lost or
1159 	 * BIOS/firmware may have disabled
1160 	 */
1161 	rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), priv->irq);
1162 	if (rc < 0)
1163 		goto out;
1164 
1165 	rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
1166 	if (rc < 0)
1167 		goto out;
1168 
1169 	intmask |= TPM_INTF_CMD_READY_INT
1170 	    | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
1171 	    | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE;
1172 
1173 	tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
1174 
1175 out:
1176 	if (chip->ops->clk_enable != NULL)
1177 		chip->ops->clk_enable(chip, false);
1178 
1179 	return;
1180 }
1181 
tpm_tis_resume(struct device * dev)1182 int tpm_tis_resume(struct device *dev)
1183 {
1184 	struct tpm_chip *chip = dev_get_drvdata(dev);
1185 	int ret;
1186 
1187 	ret = tpm_tis_request_locality(chip, 0);
1188 	if (ret < 0)
1189 		return ret;
1190 
1191 	if (chip->flags & TPM_CHIP_FLAG_IRQ)
1192 		tpm_tis_reenable_interrupts(chip);
1193 
1194 	ret = tpm_pm_resume(dev);
1195 	if (ret)
1196 		goto out;
1197 
1198 	/*
1199 	 * TPM 1.2 requires self-test on resume. This function actually returns
1200 	 * an error code but for unknown reason it isn't handled.
1201 	 */
1202 	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
1203 		tpm1_do_selftest(chip);
1204 out:
1205 	tpm_tis_relinquish_locality(chip, 0);
1206 
1207 	return ret;
1208 }
1209 EXPORT_SYMBOL_GPL(tpm_tis_resume);
1210 #endif
1211 
1212 MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
1213 MODULE_DESCRIPTION("TPM Driver");
1214 MODULE_VERSION("2.0");
1215 MODULE_LICENSE("GPL");
1216