Lines Matching full:chip

17  * Note, the TPM chip is not interrupt driven (only polling)
44 * @chip: TPM chip to use.
47 * The function returns the maximum amount of time the chip could take
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()
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 bool tpm_transmit_completed(u8 status, struct tpm_chip *chip) in tpm_transmit_completed() argument
87 u8 status_masked = status & chip->ops->req_complete_mask; in tpm_transmit_completed()
89 return status_masked == chip->ops->req_complete_val; in tpm_transmit_completed()
92 static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) in tpm_try_transmit() argument
111 dev_err(&chip->dev, in tpm_try_transmit()
116 rc = chip->ops->send(chip, buf, bufsiz, count); in tpm_try_transmit()
119 dev_err(&chip->dev, in tpm_try_transmit()
128 if (chip->flags & TPM_CHIP_FLAG_SYNC) { in tpm_try_transmit()
139 dev_warn(&chip->dev, in tpm_try_transmit()
144 if (chip->flags & TPM_CHIP_FLAG_IRQ) in tpm_try_transmit()
147 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); in tpm_try_transmit()
149 u8 status = tpm_chip_status(chip); in tpm_try_transmit()
150 if (tpm_transmit_completed(status, chip)) in tpm_try_transmit()
153 if (tpm_chip_req_canceled(chip, status)) { in tpm_try_transmit()
154 dev_err(&chip->dev, "Operation Canceled\n"); in tpm_try_transmit()
166 if (tpm_transmit_completed(tpm_chip_status(chip), chip)) in tpm_try_transmit()
169 tpm_chip_cancel(chip); in tpm_try_transmit()
170 dev_err(&chip->dev, "Operation Timed out\n"); in tpm_try_transmit()
174 len = chip->ops->recv(chip, buf, bufsiz); in tpm_try_transmit()
177 dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); in tpm_try_transmit()
189 * @chip: a TPM chip to use
204 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) in tpm_transmit() argument
224 ret = tpm_try_transmit(chip, buf, bufsiz); in tpm_transmit()
239 dev_err(&chip->dev, "in retry loop\n"); in tpm_transmit()
241 dev_err(&chip->dev, in tpm_transmit()
254 * @chip: a TPM chip to use
264 ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, in tpm_transmit_cmd() argument
271 len = tpm_transmit(chip, buf->data, PAGE_SIZE); in tpm_transmit_cmd()
278 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err, in tpm_transmit_cmd()
291 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
293 if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS) in tpm_get_timeouts()
296 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_timeouts()
297 return tpm2_get_timeouts(chip); in tpm_get_timeouts()
299 return tpm1_get_timeouts(chip); in tpm_get_timeouts()
304 * tpm_is_tpm2 - do we a have a TPM2 chip?
305 * @chip: a &struct tpm_chip instance, %NULL for the default chip
308 * 1 if we have a TPM2 chip.
309 * 0 if we don't have a TPM2 chip.
312 int tpm_is_tpm2(struct tpm_chip *chip) in tpm_is_tpm2() argument
316 if (!chip) in tpm_is_tpm2()
319 rc = tpm_try_get_ops(chip); in tpm_is_tpm2()
323 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0; in tpm_is_tpm2()
325 tpm_put_ops(chip); in tpm_is_tpm2()
333 * @chip: a &struct tpm_chip instance, %NULL for the default chip
339 int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_read() argument
344 if (!chip) in tpm_pcr_read()
347 rc = tpm_try_get_ops(chip); in tpm_pcr_read()
351 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_pcr_read()
352 rc = tpm2_pcr_read(chip, pcr_idx, digest, NULL); in tpm_pcr_read()
354 rc = tpm1_pcr_read(chip, pcr_idx, digest->digest); in tpm_pcr_read()
356 tpm_put_ops(chip); in tpm_pcr_read()
363 * @chip: a &struct tpm_chip instance, %NULL for the default chip
368 * order of the banks in chip->allocated_banks.
372 int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, in tpm_pcr_extend() argument
378 if (!chip) in tpm_pcr_extend()
381 rc = tpm_try_get_ops(chip); in tpm_pcr_extend()
385 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm_pcr_extend()
386 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) { in tpm_pcr_extend()
392 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pcr_extend()
393 rc = tpm2_pcr_extend(chip, pcr_idx, digests); in tpm_pcr_extend()
397 rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest, in tpm_pcr_extend()
401 tpm_put_ops(chip); in tpm_pcr_extend()
406 int tpm_auto_startup(struct tpm_chip *chip) in tpm_auto_startup() argument
410 if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP)) in tpm_auto_startup()
413 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_auto_startup()
414 rc = tpm2_auto_startup(chip); in tpm_auto_startup()
416 rc = tpm1_auto_startup(chip); in tpm_auto_startup()
427 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_suspend() local
430 if (!chip) in tpm_pm_suspend()
433 rc = tpm_try_get_ops(chip); in tpm_pm_suspend()
436 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
440 if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED) in tpm_pm_suspend()
443 if ((chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED) && in tpm_pm_suspend()
447 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_pm_suspend()
448 tpm2_end_auth_session(chip); in tpm_pm_suspend()
449 tpm2_shutdown(chip, TPM2_SU_STATE); in tpm_pm_suspend()
453 rc = tpm1_pm_suspend(chip, tpm_suspend_pcr); in tpm_pm_suspend()
456 chip->flags |= TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_suspend()
457 tpm_put_ops(chip); in tpm_pm_suspend()
472 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
474 if (chip == NULL) in tpm_pm_resume()
477 chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED; in tpm_pm_resume()
481 * activate before the chip has been fully resumed. in tpm_pm_resume()
491 * @chip: a &struct tpm_chip instance, %NULL for the default chip
497 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) in tpm_get_random() argument
504 if (!chip) in tpm_get_random()
507 rc = tpm_try_get_ops(chip); in tpm_get_random()
511 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_get_random()
512 rc = tpm2_get_random(chip, out, max); in tpm_get_random()
514 rc = tpm1_get_random(chip, out, max); in tpm_get_random()
516 tpm_put_ops(chip); in tpm_get_random()