Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
12 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
17 * Note, the TPM chip is not interrupt driven (only polling)
19 * calls to msleep.
33 * Bug workaround - some TPM's don't flush the most
35 * with an extend to the selected _unused_ non-volatile pcr.
40 "PCR to use for dummy writes to facilitate flush on suspend.");
43 * tpm_calc_ordinal_duration() - calculate the maximum command duration
44 * @chip: TPM chip to use.
47 * The function returns the maximum amount of time the chip could take
48 * to return the result for a particular ordinal in jiffies.
52 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) in tpm_calc_ordinal_duration() argument
54 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_calc_ordinal_duration()
55 return tpm2_calc_ordinal_duration(chip, ordinal); in tpm_calc_ordinal_duration()
57 return tpm1_calc_ordinal_duration(chip, ordinal); in tpm_calc_ordinal_duration()
61 static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) in tpm_try_transmit() argument
70 return -EINVAL; in tpm_try_transmit()
75 count = be32_to_cpu(header->length); in tpm_try_transmit()
76 ordinal = be32_to_cpu(header->ordinal); in tpm_try_transmit()
78 return -ENODATA; in tpm_try_transmit()
80 dev_err(&chip->dev, in tpm_try_transmit()
82 return -E2BIG; in tpm_try_transmit()
85 rc = chip->ops->send(chip, buf, count); in tpm_try_transmit()
87 if (rc != -EPIPE) in tpm_try_transmit()
88 dev_err(&chip->dev, in tpm_try_transmit()
97 dev_warn(&chip->dev, in tpm_try_transmit()
102 if (chip->flags & TPM_CHIP_FLAG_IRQ) in tpm_try_transmit()
105 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); in tpm_try_transmit()
107 u8 status = chip->ops->status(chip); in tpm_try_transmit()
108 if ((status & chip->ops->req_complete_mask) == in tpm_try_transmit()
109 chip->ops->req_complete_val) in tpm_try_transmit()
112 if (chip->ops->req_canceled(chip, status)) { in tpm_try_transmit()
113 dev_err(&chip->dev, "Operation Canceled\n"); in tpm_try_transmit()
114 return -ECANCELED; in tpm_try_transmit()
121 chip->ops->cancel(chip); in tpm_try_transmit()
122 dev_err(&chip->dev, "Operation Timed out\n"); in tpm_try_transmit()
123 return -ETIME; in tpm_try_transmit()
126 len = chip->ops->recv(chip, buf, bufsiz); in tpm_try_transmit()
129 dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); in tpm_try_transmit()
130 } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) in tpm_try_transmit()
131 rc = -EFAULT; in tpm_try_transmit()
137 * tpm_transmit - Internal kernel interface to transmit TPM commands.
138 * @chip: a TPM chip to use
143 * the TPM and retransmits the command after a delay up to a maximum wait of
150 * * The response length - OK
151 * * -errno - A system error
153 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) in tpm_transmit() argument
163 u32 cc = be32_to_cpu(header->return_code); in tpm_transmit()
167 * transformed, so when we restore the header we also have to in tpm_transmit()
173 ret = tpm_try_transmit(chip, buf, bufsiz); in tpm_transmit()
176 rc = be32_to_cpu(header->return_code); in tpm_transmit()
181 * still running to shorten boot time. in tpm_transmit()
188 dev_err(&chip->dev, "in retry loop\n"); in tpm_transmit()
190 dev_err(&chip->dev, in tpm_transmit()
202 * tpm_transmit_cmd - send a tpm command to the device
203 * @chip: a TPM chip to use
209 * * 0 - OK
210 * * -errno - A system error
211 * * TPM_RC - A TPM error
213 ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, in tpm_transmit_cmd() argument
216 const struct tpm_header *header = (struct tpm_header *)buf->data; in tpm_transmit_cmd()
220 len = tpm_transmit(chip, buf->data, PAGE_SIZE); in tpm_transmit_cmd()
224 err = be32_to_cpu(header->return_code); in tpm_transmit_cmd()
227 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err, in tpm_transmit_cmd()
233 return -EFAULT; in tpm_transmit_cmd()
235 buf->length = len; in tpm_transmit_cmd()
240 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
242 if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) in tpm_get_timeouts()
245 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_timeouts()
246 return tpm2_get_timeouts(chip); in tpm_get_timeouts()
248 return tpm1_get_timeouts(chip); in tpm_get_timeouts()
253 * tpm_is_tpm2 - do we a have a TPM2 chip?
254 * @chip: a &struct tpm_chip instance, %NULL for the default chip
257 * 1 if we have a TPM2 chip.
258 * 0 if we don't have a TPM2 chip.
261 int tpm_is_tpm2(struct tpm_chip *chip) in tpm_is_tpm2() argument
265 chip = tpm_find_get_ops(chip); in tpm_is_tpm2()
266 if (!chip) in tpm_is_tpm2()
267 return -ENODEV; in tpm_is_tpm2()
269 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; in tpm_is_tpm2()
271 tpm_put_ops(chip); in tpm_is_tpm2()
278 * tpm_pcr_read - read a PCR value from SHA1 bank
279 * @chip: a &struct tpm_chip instance, %NULL for the default chip
280 * @pcr_idx: the PCR to be retrieved
281 * @digest: the PCR bank and buffer current PCR value is written to
285 int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_read() argument
290 chip = tpm_find_get_ops(chip); in tpm_pcr_read()
291 if (!chip) in tpm_pcr_read()
292 return -ENODEV; in tpm_pcr_read()
294 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
295 rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL); in tpm_pcr_read()
297 rc = tpm1_pcr_read(chip, pcr_idx, digest->digest); in tpm_pcr_read()
299 tpm_put_ops(chip); in tpm_pcr_read()
305 * tpm_pcr_extend - extend a PCR value in SHA1 bank.
306 * @chip: a &struct tpm_chip instance, %NULL for the default chip
307 * @pcr_idx: the PCR to be retrieved
308 * @digests: array of tpm_digest structures used to extend PCRs
311 * order of the banks in chip->allocated_banks.
315 int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_extend() argument
321 chip = tpm_find_get_ops(chip); in tpm_pcr_extend()
322 if (!chip) in tpm_pcr_extend()
323 return -ENODEV; in tpm_pcr_extend()
325 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm_pcr_extend()
326 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) { in tpm_pcr_extend()
327 rc = -EINVAL; in tpm_pcr_extend()
332 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
333 rc = tpm2_pcr_extend(chip, pcr_idx, digests); in tpm_pcr_extend()
337 rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest, in tpm_pcr_extend()
341 tpm_put_ops(chip); in tpm_pcr_extend()
346 int tpm_auto_startup(struct tpm_chip *chip) in tpm_auto_startup() argument
350 if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) in tpm_auto_startup()
353 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_auto_startup()
354 rc = tpm2_auto_startup(chip); in tpm_auto_startup()
356 rc = tpm1_auto_startup(chip); in tpm_auto_startup()
362 * We are about to suspend. Save the TPM state
367 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_suspend() local
370 if (!chip) in tpm_pm_suspend()
371 return -ENODEV; in tpm_pm_suspend()
373 rc = tpm_try_get_ops(chip); in tpm_pm_suspend()
376 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
380 if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED) in tpm_pm_suspend()
383 if ((chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED) && in tpm_pm_suspend()
387 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pm_suspend()
388 tpm2_end_auth_session(chip); in tpm_pm_suspend()
389 tpm2_shutdown(chip, TPM2_SU_STATE); in tpm_pm_suspend()
393 rc = tpm1_pm_suspend(chip, tpm_suspend_pcr); in tpm_pm_suspend()
396 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
397 tpm_put_ops(chip); in tpm_pm_suspend()
412 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
414 if (chip == NULL) in tpm_pm_resume()
415 return -ENODEV; in tpm_pm_resume()
417 chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_resume()
421 * activate before the chip has been fully resumed. in tpm_pm_resume()
430 * tpm_get_random() - get random bytes from the TPM's RNG
431 * @chip: a &struct tpm_chip instance, %NULL for the default chip
433 * @max: the max number of bytes to write to @out
437 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) in tpm_get_random() argument
442 return -EINVAL; in tpm_get_random()
444 chip = tpm_find_get_ops(chip); in tpm_get_random()
445 if (!chip) in tpm_get_random()
446 return -ENODEV; in tpm_get_random()
448 /* Give back zero bytes, as TPM chip has not yet fully resumed: */ in tpm_get_random()
449 if (chip->flags & TPM_CHIP_FLAG_SUSPENDED) { in tpm_get_random()
454 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_random()
455 rc = tpm2_get_random(chip, out, max); in tpm_get_random()
457 rc = tpm1_get_random(chip, out, max); in tpm_get_random()
460 tpm_put_ops(chip); in tpm_get_random()
483 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()
489 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()