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 void tpm_chip_cancel(struct tpm_chip *chip) in tpm_chip_cancel() argument
63 if (!chip->ops->cancel) in tpm_chip_cancel()
66 chip->ops->cancel(chip); in tpm_chip_cancel()
69 static u8 tpm_chip_status(struct tpm_chip *chip) in tpm_chip_status() argument
71 if (!chip->ops->status) in tpm_chip_status()
74 return chip->ops->status(chip); in tpm_chip_status()
77 static bool tpm_chip_req_canceled(struct tpm_chip *chip, u8 status) in tpm_chip_req_canceled() argument
79 if (!chip->ops->req_canceled) in tpm_chip_req_canceled()
82 return chip->ops->req_canceled(chip, status); in tpm_chip_req_canceled()
85 static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) in tpm_try_transmit() argument
94 return -EINVAL; in tpm_try_transmit()
99 count = be32_to_cpu(header->length); in tpm_try_transmit()
100 ordinal = be32_to_cpu(header->ordinal); in tpm_try_transmit()
102 return -ENODATA; in tpm_try_transmit()
104 dev_err(&chip->dev, in tpm_try_transmit()
106 return -E2BIG; in tpm_try_transmit()
109 rc = chip->ops->send(chip, buf, count); in tpm_try_transmit()
111 if (rc != -EPIPE) in tpm_try_transmit()
112 dev_err(&chip->dev, in tpm_try_transmit()
121 dev_warn(&chip->dev, in tpm_try_transmit()
126 if (chip->flags & TPM_CHIP_FLAG_IRQ) in tpm_try_transmit()
129 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); in tpm_try_transmit()
131 u8 status = tpm_chip_status(chip); in tpm_try_transmit()
132 if ((status & chip->ops->req_complete_mask) == in tpm_try_transmit()
133 chip->ops->req_complete_val) in tpm_try_transmit()
136 if (tpm_chip_req_canceled(chip, status)) { in tpm_try_transmit()
137 dev_err(&chip->dev, "Operation Canceled\n"); in tpm_try_transmit()
138 return -ECANCELED; in tpm_try_transmit()
145 tpm_chip_cancel(chip); in tpm_try_transmit()
146 dev_err(&chip->dev, "Operation Timed out\n"); in tpm_try_transmit()
147 return -ETIME; in tpm_try_transmit()
150 len = chip->ops->recv(chip, buf, bufsiz); in tpm_try_transmit()
153 dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); in tpm_try_transmit()
154 } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) in tpm_try_transmit()
155 rc = -EFAULT; in tpm_try_transmit()
161 * tpm_transmit - Internal kernel interface to transmit TPM commands.
162 * @chip: a TPM chip to use
167 * the TPM and retransmits the command after a delay up to a maximum wait of
174 * * The response length - OK
175 * * -errno - A system error
177 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) in tpm_transmit() argument
187 u32 cc = be32_to_cpu(header->return_code); in tpm_transmit()
191 * transformed, so when we restore the header we also have to in tpm_transmit()
197 ret = tpm_try_transmit(chip, buf, bufsiz); in tpm_transmit()
200 rc = be32_to_cpu(header->return_code); in tpm_transmit()
205 * still running to shorten boot time. in tpm_transmit()
212 dev_err(&chip->dev, "in retry loop\n"); in tpm_transmit()
214 dev_err(&chip->dev, in tpm_transmit()
226 * tpm_transmit_cmd - send a tpm command to the device
227 * @chip: a TPM chip to use
233 * * 0 - OK
234 * * -errno - A system error
235 * * TPM_RC - A TPM error
237 ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, in tpm_transmit_cmd() argument
240 const struct tpm_header *header = (struct tpm_header *)buf->data; in tpm_transmit_cmd()
244 len = tpm_transmit(chip, buf->data, PAGE_SIZE); in tpm_transmit_cmd()
248 err = be32_to_cpu(header->return_code); in tpm_transmit_cmd()
251 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err, in tpm_transmit_cmd()
257 return -EFAULT; in tpm_transmit_cmd()
259 buf->length = len; in tpm_transmit_cmd()
264 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
266 if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) in tpm_get_timeouts()
269 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_timeouts()
270 return tpm2_get_timeouts(chip); in tpm_get_timeouts()
272 return tpm1_get_timeouts(chip); in tpm_get_timeouts()
277 * tpm_is_tpm2 - do we a have a TPM2 chip?
278 * @chip: a &struct tpm_chip instance, %NULL for the default chip
281 * 1 if we have a TPM2 chip.
282 * 0 if we don't have a TPM2 chip.
285 int tpm_is_tpm2(struct tpm_chip *chip) in tpm_is_tpm2() argument
289 chip = tpm_find_get_ops(chip); in tpm_is_tpm2()
290 if (!chip) in tpm_is_tpm2()
291 return -ENODEV; in tpm_is_tpm2()
293 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; in tpm_is_tpm2()
295 tpm_put_ops(chip); in tpm_is_tpm2()
302 * tpm_pcr_read - read a PCR value from SHA1 bank
303 * @chip: a &struct tpm_chip instance, %NULL for the default chip
304 * @pcr_idx: the PCR to be retrieved
305 * @digest: the PCR bank and buffer current PCR value is written to
309 int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_read() argument
314 chip = tpm_find_get_ops(chip); in tpm_pcr_read()
315 if (!chip) in tpm_pcr_read()
316 return -ENODEV; in tpm_pcr_read()
318 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
319 rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL); in tpm_pcr_read()
321 rc = tpm1_pcr_read(chip, pcr_idx, digest->digest); in tpm_pcr_read()
323 tpm_put_ops(chip); in tpm_pcr_read()
329 * tpm_pcr_extend - extend a PCR value in SHA1 bank.
330 * @chip: a &struct tpm_chip instance, %NULL for the default chip
331 * @pcr_idx: the PCR to be retrieved
332 * @digests: array of tpm_digest structures used to extend PCRs
335 * order of the banks in chip->allocated_banks.
339 int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_extend() argument
345 chip = tpm_find_get_ops(chip); in tpm_pcr_extend()
346 if (!chip) in tpm_pcr_extend()
347 return -ENODEV; in tpm_pcr_extend()
349 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm_pcr_extend()
350 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) { in tpm_pcr_extend()
351 rc = -EINVAL; in tpm_pcr_extend()
356 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
357 rc = tpm2_pcr_extend(chip, pcr_idx, digests); in tpm_pcr_extend()
361 rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest, in tpm_pcr_extend()
365 tpm_put_ops(chip); in tpm_pcr_extend()
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 rc = tpm_try_get_ops(chip); in tpm_pm_suspend()
400 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
404 if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED) in tpm_pm_suspend()
407 if ((chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED) && in tpm_pm_suspend()
411 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pm_suspend()
412 tpm2_end_auth_session(chip); in tpm_pm_suspend()
413 tpm2_shutdown(chip, TPM2_SU_STATE); in tpm_pm_suspend()
417 rc = tpm1_pm_suspend(chip, tpm_suspend_pcr); in tpm_pm_suspend()
420 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
421 tpm_put_ops(chip); in tpm_pm_suspend()
436 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
438 if (chip == NULL) in tpm_pm_resume()
439 return -ENODEV; in tpm_pm_resume()
441 chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_resume()
445 * activate before the chip has been fully resumed. in tpm_pm_resume()
454 * tpm_get_random() - get random bytes from the TPM's RNG
455 * @chip: a &struct tpm_chip instance, %NULL for the default chip
457 * @max: the max number of bytes to write to @out
461 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) in tpm_get_random() argument
466 return -EINVAL; in tpm_get_random()
468 chip = tpm_find_get_ops(chip); in tpm_get_random()
469 if (!chip) in tpm_get_random()
470 return -ENODEV; in tpm_get_random()
472 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_random()
473 rc = tpm2_get_random(chip, out, max); in tpm_get_random()
475 rc = tpm1_get_random(chip, out, max); in tpm_get_random()
477 tpm_put_ops(chip); in tpm_get_random()
500 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()
506 pr_err("tpm: failed to allocate char dev region\n"); in tpm_init()