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()
239 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
241 if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) in tpm_get_timeouts()
244 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_timeouts()
245 return tpm2_get_timeouts(chip); in tpm_get_timeouts()
247 return tpm1_get_timeouts(chip); in tpm_get_timeouts()
252 * tpm_is_tpm2 - do we a have a TPM2 chip?
253 * @chip: a &struct tpm_chip instance, %NULL for the default chip
256 * 1 if we have a TPM2 chip.
257 * 0 if we don't have a TPM2 chip.
260 int tpm_is_tpm2(struct tpm_chip *chip) in tpm_is_tpm2() argument
264 chip = tpm_find_get_ops(chip); in tpm_is_tpm2()
265 if (!chip) in tpm_is_tpm2()
266 return -ENODEV; in tpm_is_tpm2()
268 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; in tpm_is_tpm2()
270 tpm_put_ops(chip); in tpm_is_tpm2()
277 * tpm_pcr_read - read a PCR value from SHA1 bank
278 * @chip: a &struct tpm_chip instance, %NULL for the default chip
279 * @pcr_idx: the PCR to be retrieved
280 * @digest: the PCR bank and buffer current PCR value is written to
284 int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_read() argument
289 chip = tpm_find_get_ops(chip); in tpm_pcr_read()
290 if (!chip) in tpm_pcr_read()
291 return -ENODEV; in tpm_pcr_read()
293 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
294 rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL); in tpm_pcr_read()
296 rc = tpm1_pcr_read(chip, pcr_idx, digest->digest); in tpm_pcr_read()
298 tpm_put_ops(chip); in tpm_pcr_read()
304 * tpm_pcr_extend - extend a PCR value in SHA1 bank.
305 * @chip: a &struct tpm_chip instance, %NULL for the default chip
306 * @pcr_idx: the PCR to be retrieved
307 * @digests: array of tpm_digest structures used to extend PCRs
310 * order of the banks in chip->allocated_banks.
314 int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_extend() argument
320 chip = tpm_find_get_ops(chip); in tpm_pcr_extend()
321 if (!chip) in tpm_pcr_extend()
322 return -ENODEV; in tpm_pcr_extend()
324 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm_pcr_extend()
325 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) { in tpm_pcr_extend()
326 rc = -EINVAL; in tpm_pcr_extend()
331 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
332 rc = tpm2_pcr_extend(chip, pcr_idx, digests); in tpm_pcr_extend()
336 rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest, in tpm_pcr_extend()
340 tpm_put_ops(chip); in tpm_pcr_extend()
346 * tpm_send - send a TPM command
347 * @chip: a &struct tpm_chip instance, %NULL for the default chip
353 int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) in tpm_send() argument
358 chip = tpm_find_get_ops(chip); in tpm_send()
359 if (!chip) in tpm_send()
360 return -ENODEV; in tpm_send()
363 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to a send a command"); in tpm_send()
365 tpm_put_ops(chip); in tpm_send()
370 int tpm_auto_startup(struct tpm_chip *chip) in tpm_auto_startup() argument
374 if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) in tpm_auto_startup()
377 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_auto_startup()
378 rc = tpm2_auto_startup(chip); in tpm_auto_startup()
380 rc = tpm1_auto_startup(chip); in tpm_auto_startup()
386 * We are about to suspend. Save the TPM state
391 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_suspend() local
394 if (!chip) in tpm_pm_suspend()
395 return -ENODEV; in tpm_pm_suspend()
397 if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED) in tpm_pm_suspend()
400 if ((chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED) && in tpm_pm_suspend()
404 rc = tpm_try_get_ops(chip); in tpm_pm_suspend()
406 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pm_suspend()
407 tpm2_shutdown(chip, TPM2_SU_STATE); in tpm_pm_suspend()
409 rc = tpm1_pm_suspend(chip, tpm_suspend_pcr); in tpm_pm_suspend()
411 tpm_put_ops(chip); in tpm_pm_suspend()
415 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
429 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
431 if (chip == NULL) in tpm_pm_resume()
432 return -ENODEV; in tpm_pm_resume()
434 chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_resume()
438 * activate before the chip has been fully resumed. in tpm_pm_resume()
447 * tpm_get_random() - get random bytes from the TPM's RNG
448 * @chip: a &struct tpm_chip instance, %NULL for the default chip
450 * @max: the max number of bytes to write to @out
454 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) in tpm_get_random() argument
459 return -EINVAL; in tpm_get_random()
461 chip = tpm_find_get_ops(chip); in tpm_get_random()
462 if (!chip) in tpm_get_random()
463 return -ENODEV; in tpm_get_random()
465 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_random()
466 rc = tpm2_get_random(chip, out, max); in tpm_get_random()
468 rc = tpm1_get_random(chip, out, max); in tpm_get_random()
470 tpm_put_ops(chip); in tpm_get_random()
493 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()
499 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()