• Home
  • Raw
  • Download

Lines Matching +full:on +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
8 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
25 int tpm2_get_timeouts(struct tpm_chip *chip) in tpm2_get_timeouts() argument
28 chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); in tpm2_get_timeouts()
29 chip->timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); in tpm2_get_timeouts()
30 chip->timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); in tpm2_get_timeouts()
31 chip->timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); in tpm2_get_timeouts()
34 chip->duration[TPM_SHORT] = msecs_to_jiffies(TPM2_DURATION_SHORT); in tpm2_get_timeouts()
35 chip->duration[TPM_MEDIUM] = msecs_to_jiffies(TPM2_DURATION_MEDIUM); in tpm2_get_timeouts()
36 chip->duration[TPM_LONG] = msecs_to_jiffies(TPM2_DURATION_LONG); in tpm2_get_timeouts()
39 chip->duration[TPM_LONG_LONG] = in tpm2_get_timeouts()
42 chip->flags |= TPM_CHIP_FLAG_HAVE_TIMEOUTS; in tpm2_get_timeouts()
48 * tpm2_ordinal_duration_index() - returns an index to the chip duration table
51 * The function returns an index to the chip duration table
53 * time the chip could take to return the result for a particular ordinal.
59 * a longer time on some systems.
119 * tpm2_calc_ordinal_duration() - calculate the maximum command duration
120 * @chip: TPM chip to use.
123 * The function returns the maximum amount of time the chip could take
128 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) in tpm2_calc_ordinal_duration() argument
135 return chip->duration[index]; in tpm2_calc_ordinal_duration()
153 * tpm2_pcr_read() - read a PCR value
154 * @chip: TPM chip to use.
161 int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, in tpm2_pcr_read() argument
173 return -EINVAL; in tpm2_pcr_read()
176 for (i = 0; i < chip->nr_allocated_banks && in tpm2_pcr_read()
177 chip->allocated_banks[i].alg_id != digest->alg_id; i++) in tpm2_pcr_read()
180 if (i == chip->nr_allocated_banks) in tpm2_pcr_read()
181 return -EINVAL; in tpm2_pcr_read()
183 expected_digest_size = chip->allocated_banks[i].digest_size; in tpm2_pcr_read()
193 tpm_buf_append_u16(&buf, digest->alg_id); in tpm2_pcr_read()
198 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to read a pcr value"); in tpm2_pcr_read()
203 digest_size = be16_to_cpu(out->digest_size); in tpm2_pcr_read()
204 if (digest_size > sizeof(digest->digest) || in tpm2_pcr_read()
206 rc = -EINVAL; in tpm2_pcr_read()
213 memcpy(digest->digest, out->digest, digest_size); in tpm2_pcr_read()
227 * tpm2_pcr_extend() - extend a PCR value
229 * @chip: TPM chip to use.
235 int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, in tpm2_pcr_extend() argument
257 tpm_buf_append_u32(&buf, chip->nr_allocated_banks); in tpm2_pcr_extend()
259 for (i = 0; i < chip->nr_allocated_banks; i++) { in tpm2_pcr_extend()
262 chip->allocated_banks[i].digest_size); in tpm2_pcr_extend()
265 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting extend a PCR value"); in tpm2_pcr_extend()
278 * tpm2_get_random() - get random bytes from the TPM RNG
280 * @chip: a &tpm_chip instance
285 * size of the buffer on success,
286 * -errno otherwise (positive TPM return codes are masked to -EIO)
288 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) in tpm2_get_random() argument
300 return -EINVAL; in tpm2_get_random()
309 err = tpm_transmit_cmd(chip, &buf, in tpm2_get_random()
315 err = -EIO; in tpm2_get_random()
321 recd = min_t(u32, be16_to_cpu(out->size), num_bytes); in tpm2_get_random()
326 err = -EFAULT; in tpm2_get_random()
329 memcpy(dest_ptr, out->buffer, recd); in tpm2_get_random()
333 num_bytes -= recd; in tpm2_get_random()
334 } while (retries-- && total < max); in tpm2_get_random()
337 return total ? total : -EIO; in tpm2_get_random()
344 * tpm2_flush_context() - execute a TPM2_FlushContext command
345 * @chip: TPM chip to use
348 void tpm2_flush_context(struct tpm_chip *chip, u32 handle) in tpm2_flush_context() argument
355 dev_warn(&chip->dev, "0x%08x was not flushed, out of memory\n", in tpm2_flush_context()
362 tpm_transmit_cmd(chip, &buf, 0, "flushing context"); in tpm2_flush_context()
376 * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
377 * @chip: a &tpm_chip instance
383 * 0 on success,
384 * -errno or a TPM return code otherwise
386 ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value, in tpm2_get_tpm_pt() argument
399 rc = tpm_transmit_cmd(chip, &buf, 0, NULL); in tpm2_get_tpm_pt()
405 * returns SUCCESS on TPM2_Startup in field upgrade mode. Also in tpm2_get_tpm_pt()
409 if (be32_to_cpu(out->property_cnt) > 0) in tpm2_get_tpm_pt()
410 *value = be32_to_cpu(out->value); in tpm2_get_tpm_pt()
412 rc = -ENODATA; in tpm2_get_tpm_pt()
420 * tpm2_shutdown() - send a TPM shutdown command
426 * @chip: a &tpm_chip instance
429 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type) in tpm2_shutdown() argument
438 tpm_transmit_cmd(chip, &buf, 0, "stopping the TPM"); in tpm2_shutdown()
443 * tpm2_do_selftest() - ensure that all self tests have passed
445 * @chip: TPM chip to use
455 static int tpm2_do_selftest(struct tpm_chip *chip) in tpm2_do_selftest() argument
467 rc = tpm_transmit_cmd(chip, &buf, 0, in tpm2_do_selftest()
481 * tpm2_probe() - probe for the TPM 2.0 protocol
482 * @chip: a &tpm_chip instance
484 * Send an idempotent TPM 2.0 command and see whether there is TPM2 chip in the
485 * other end based on the response tag. The flag TPM_CHIP_FLAG_TPM2 is set by
489 * 0 on success,
490 * -errno otherwise
492 int tpm2_probe(struct tpm_chip *chip) in tpm2_probe() argument
504 rc = tpm_transmit_cmd(chip, &buf, 0, NULL); in tpm2_probe()
505 /* We ignore TPM return codes on purpose. */ in tpm2_probe()
508 if (be16_to_cpu(out->tag) == TPM2_ST_NO_SESSIONS) in tpm2_probe()
509 chip->flags |= TPM_CHIP_FLAG_TPM2; in tpm2_probe()
516 static int tpm2_init_bank_info(struct tpm_chip *chip, u32 bank_index) in tpm2_init_bank_info() argument
518 struct tpm_bank_info *bank = chip->allocated_banks + bank_index; in tpm2_init_bank_info()
519 struct tpm_digest digest = { .alg_id = bank->alg_id }; in tpm2_init_bank_info()
529 if (bank->alg_id != tpm2_hash_map[i].tpm_id) in tpm2_init_bank_info()
532 bank->digest_size = hash_digest_size[crypto_algo]; in tpm2_init_bank_info()
533 bank->crypto_id = crypto_algo; in tpm2_init_bank_info()
537 bank->crypto_id = HASH_ALGO__LAST; in tpm2_init_bank_info()
539 return tpm2_pcr_read(chip, 0, &digest, &bank->digest_size); in tpm2_init_bank_info()
548 ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) in tpm2_get_pcr_allocation() argument
571 rc = tpm_transmit_cmd(chip, &buf, 9, "get tpm pcr allocation"); in tpm2_get_pcr_allocation()
578 chip->allocated_banks = kcalloc(nr_possible_banks, in tpm2_get_pcr_allocation()
579 sizeof(*chip->allocated_banks), in tpm2_get_pcr_allocation()
581 if (!chip->allocated_banks) { in tpm2_get_pcr_allocation()
582 rc = -ENOMEM; in tpm2_get_pcr_allocation()
595 rc = -EFAULT; in tpm2_get_pcr_allocation()
605 chip->allocated_banks[nr_alloc_banks].alg_id = hash_alg; in tpm2_get_pcr_allocation()
607 rc = tpm2_init_bank_info(chip, nr_alloc_banks); in tpm2_get_pcr_allocation()
620 chip->nr_allocated_banks = nr_alloc_banks; in tpm2_get_pcr_allocation()
627 int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip) in tpm2_get_cc_attrs_tbl() argument
636 rc = tpm2_get_tpm_pt(chip, TPM_PT_TOTAL_COMMANDS, &nr_commands, NULL); in tpm2_get_cc_attrs_tbl()
641 rc = -EFAULT; in tpm2_get_cc_attrs_tbl()
645 chip->cc_attrs_tbl = devm_kcalloc(&chip->dev, 4, nr_commands, in tpm2_get_cc_attrs_tbl()
647 if (!chip->cc_attrs_tbl) { in tpm2_get_cc_attrs_tbl()
648 rc = -ENOMEM; in tpm2_get_cc_attrs_tbl()
660 rc = tpm_transmit_cmd(chip, &buf, 9 + 4 * nr_commands, NULL); in tpm2_get_cc_attrs_tbl()
668 rc = -EFAULT; in tpm2_get_cc_attrs_tbl()
673 chip->nr_commands = nr_commands; in tpm2_get_cc_attrs_tbl()
677 chip->cc_attrs_tbl[i] = be32_to_cpup(attrs); in tpm2_get_cc_attrs_tbl()
678 cc = chip->cc_attrs_tbl[i] & 0xFFFF; in tpm2_get_cc_attrs_tbl()
681 chip->cc_attrs_tbl[i] &= in tpm2_get_cc_attrs_tbl()
683 chip->cc_attrs_tbl[i] |= 1 << TPM2_CC_ATTR_CHANDLES; in tpm2_get_cc_attrs_tbl()
691 rc = -ENODEV; in tpm2_get_cc_attrs_tbl()
697 * tpm2_startup - turn on the TPM
698 * @chip: TPM chip to use
707 static int tpm2_startup(struct tpm_chip *chip) in tpm2_startup() argument
712 dev_info(&chip->dev, "starting up the TPM manually\n"); in tpm2_startup()
719 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to start the TPM"); in tpm2_startup()
726 * tpm2_auto_startup - Perform the standard automatic TPM initialization
728 * @chip: TPM chip to use
730 * Returns 0 on success, < 0 in case of fatal error.
732 int tpm2_auto_startup(struct tpm_chip *chip) in tpm2_auto_startup() argument
736 rc = tpm2_get_timeouts(chip); in tpm2_auto_startup()
740 rc = tpm2_do_selftest(chip); in tpm2_auto_startup()
745 rc = tpm2_startup(chip); in tpm2_auto_startup()
749 rc = tpm2_do_selftest(chip); in tpm2_auto_startup()
754 rc = tpm2_get_cc_attrs_tbl(chip); in tpm2_auto_startup()
758 rc = -ENODEV; in tpm2_auto_startup()
762 int tpm2_find_cc(struct tpm_chip *chip, u32 cc) in tpm2_find_cc() argument
766 for (i = 0; i < chip->nr_commands; i++) in tpm2_find_cc()
767 if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0))) in tpm2_find_cc()
770 return -1; in tpm2_find_cc()