Lines Matching +full:chip +full:- +full:to +full:- +full:chip
10 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
20 * Note, the TPM chip is not interrupt driven (only polling)
22 * calls to msleep.
52 * Bug workaround - some TPM's don't flush the most
54 * with an extend to the selected _unused_ non-volatile pcr.
59 "PCR to use for dummy writes to faciltate flush on suspend.");
67 * of time the chip could take to return the result. The ordinal
71 * from the chip during initialization with a call to tpm_get_timeouts.
336 struct tpm_chip *chip = (struct tpm_chip *) ptr; in user_reader_timeout() local
338 schedule_work(&chip->work); in user_reader_timeout()
343 struct tpm_chip *chip = container_of(work, struct tpm_chip, work); in timeout_work() local
345 mutex_lock(&chip->buffer_mutex); in timeout_work()
346 atomic_set(&chip->data_pending, 0); in timeout_work()
347 memset(chip->data_buffer, 0, TPM_BUFSIZE); in timeout_work()
348 mutex_unlock(&chip->buffer_mutex); in timeout_work()
352 * Returns max number of jiffies to wait
354 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, in tpm_calc_ordinal_duration() argument
369 duration = chip->vendor.duration[duration_idx]; in tpm_calc_ordinal_duration()
378 * Internal kernel interface to transmit TPM commands
380 static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, in tpm_transmit() argument
393 return -ENODATA; in tpm_transmit()
395 dev_err(chip->dev, in tpm_transmit()
397 return -E2BIG; in tpm_transmit()
400 mutex_lock(&chip->tpm_mutex); in tpm_transmit()
402 if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) { in tpm_transmit()
403 dev_err(chip->dev, in tpm_transmit()
408 if (chip->vendor.irq) in tpm_transmit()
411 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); in tpm_transmit()
413 u8 status = chip->vendor.status(chip); in tpm_transmit()
414 if ((status & chip->vendor.req_complete_mask) == in tpm_transmit()
415 chip->vendor.req_complete_val) in tpm_transmit()
418 if ((status == chip->vendor.req_canceled)) { in tpm_transmit()
419 dev_err(chip->dev, "Operation Canceled\n"); in tpm_transmit()
420 rc = -ECANCELED; in tpm_transmit()
428 chip->vendor.cancel(chip); in tpm_transmit()
429 dev_err(chip->dev, "Operation Timed out\n"); in tpm_transmit()
430 rc = -ETIME; in tpm_transmit()
434 rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz); in tpm_transmit()
436 dev_err(chip->dev, in tpm_transmit()
439 mutex_unlock(&chip->tpm_mutex); in tpm_transmit()
464 static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd, in transmit_cmd() argument
469 len = tpm_transmit(chip,(u8 *) cmd, len); in transmit_cmd()
473 return -EFAULT; in transmit_cmd()
475 err = be32_to_cpu(cmd->header.out.return_code); in transmit_cmd()
477 dev_err(chip->dev, "A TPM error (%d) occurred %s\n", err, desc); in transmit_cmd()
497 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_getcap() local
504 tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32)); in tpm_getcap()
514 rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc); in tpm_getcap()
520 void tpm_gen_interrupt(struct tpm_chip *chip) in tpm_gen_interrupt() argument
530 rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_gen_interrupt()
531 "attempting to determine the timeouts"); in tpm_gen_interrupt()
535 int tpm_get_timeouts(struct tpm_chip *chip) in tpm_get_timeouts() argument
549 rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_get_timeouts()
550 "attempting to determine the timeouts"); in tpm_get_timeouts()
557 return -EINVAL; in tpm_get_timeouts()
561 timeout = be32_to_cpu(timeout_cap->a); in tpm_get_timeouts()
565 chip->vendor.timeout_adjusted = true; in tpm_get_timeouts()
568 chip->vendor.timeout_a = usecs_to_jiffies(timeout * scale); in tpm_get_timeouts()
569 timeout = be32_to_cpu(timeout_cap->b); in tpm_get_timeouts()
571 chip->vendor.timeout_b = usecs_to_jiffies(timeout * scale); in tpm_get_timeouts()
572 timeout = be32_to_cpu(timeout_cap->c); in tpm_get_timeouts()
574 chip->vendor.timeout_c = usecs_to_jiffies(timeout * scale); in tpm_get_timeouts()
575 timeout = be32_to_cpu(timeout_cap->d); in tpm_get_timeouts()
577 chip->vendor.timeout_d = usecs_to_jiffies(timeout * scale); in tpm_get_timeouts()
585 rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, in tpm_get_timeouts()
586 "attempting to determine the durations"); in tpm_get_timeouts()
593 return -EINVAL; in tpm_get_timeouts()
596 chip->vendor.duration[TPM_SHORT] = in tpm_get_timeouts()
597 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); in tpm_get_timeouts()
598 chip->vendor.duration[TPM_MEDIUM] = in tpm_get_timeouts()
599 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_medium)); in tpm_get_timeouts()
600 chip->vendor.duration[TPM_LONG] = in tpm_get_timeouts()
601 usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_long)); in tpm_get_timeouts()
605 * fix up the resulting too-small TPM_SHORT value to make things work. in tpm_get_timeouts()
606 * We also scale the TPM_MEDIUM and -_LONG values by 1000. in tpm_get_timeouts()
608 if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) { in tpm_get_timeouts()
609 chip->vendor.duration[TPM_SHORT] = HZ; in tpm_get_timeouts()
610 chip->vendor.duration[TPM_MEDIUM] *= 1000; in tpm_get_timeouts()
611 chip->vendor.duration[TPM_LONG] *= 1000; in tpm_get_timeouts()
612 chip->vendor.duration_adjusted = true; in tpm_get_timeouts()
613 dev_info(chip->dev, "Adjusting TPM timeout parameters."); in tpm_get_timeouts()
629 * tpm_continue_selftest -- run TPM's selftest
630 * @chip: TPM chip to use
635 static int tpm_continue_selftest(struct tpm_chip *chip) in tpm_continue_selftest() argument
641 rc = transmit_cmd(chip, &cmd, CONTINUE_SELFTEST_RESULT_SIZE, in tpm_continue_selftest()
653 "attempting to determine the permanent enabled state"); in tpm_show_enabled()
669 "attempting to determine the permanent active state"); in tpm_show_active()
685 "attempting to determine the owner state"); in tpm_show_owned()
701 "attempting to determine the temporary state"); in tpm_show_temp_deactivated()
711 * tpm_chip_find_get - return tpm_chip for given chip number
715 struct tpm_chip *pos, *chip = NULL; in tpm_chip_find_get() local
719 if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num) in tpm_chip_find_get()
722 if (try_module_get(pos->dev->driver->owner)) { in tpm_chip_find_get()
723 chip = pos; in tpm_chip_find_get()
728 return chip; in tpm_chip_find_get()
739 static int __tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) in __tpm_pcr_read() argument
746 rc = transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE, in __tpm_pcr_read()
747 "attempting to read a pcr value"); in __tpm_pcr_read()
756 * tpm_pcr_read - read a pcr value
758 * @pcr_idx: pcr idx to retrieve
762 * The TPM driver should be built-in, but for whatever reason it
763 * isn't, protect against the chip disappearing, by incrementing
768 struct tpm_chip *chip; in tpm_pcr_read() local
771 chip = tpm_chip_find_get(chip_num); in tpm_pcr_read()
772 if (chip == NULL) in tpm_pcr_read()
773 return -ENODEV; in tpm_pcr_read()
774 rc = __tpm_pcr_read(chip, pcr_idx, res_buf); in tpm_pcr_read()
775 tpm_chip_put(chip); in tpm_pcr_read()
781 * tpm_pcr_extend - extend pcr value with hash
783 * @pcr_idx: pcr idx to extend
784 * @hash: hash value used to extend pcr value
786 * The TPM driver should be built-in, but for whatever reason it
787 * isn't, protect against the chip disappearing, by incrementing
802 struct tpm_chip *chip; in tpm_pcr_extend() local
804 chip = tpm_chip_find_get(chip_num); in tpm_pcr_extend()
805 if (chip == NULL) in tpm_pcr_extend()
806 return -ENODEV; in tpm_pcr_extend()
811 rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, in tpm_pcr_extend()
814 tpm_chip_put(chip); in tpm_pcr_extend()
820 * tpm_do_selftest - have the TPM continue its selftest and wait until it
822 * @chip: TPM chip to use
827 int tpm_do_selftest(struct tpm_chip *chip) in tpm_do_selftest() argument
835 duration = tpm_calc_ordinal_duration(chip, in tpm_do_selftest()
840 rc = tpm_continue_selftest(chip); in tpm_do_selftest()
848 rc = __tpm_pcr_read(chip, 0, digest); in tpm_do_selftest()
850 dev_info(chip->dev, in tpm_do_selftest()
861 } while (--loops > 0); in tpm_do_selftest()
869 struct tpm_chip *chip; in tpm_send() local
872 chip = tpm_chip_find_get(chip_num); in tpm_send()
873 if (chip == NULL) in tpm_send()
874 return -ENODEV; in tpm_send()
876 rc = transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd"); in tpm_send()
878 tpm_chip_put(chip); in tpm_send()
891 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_show_pcrs() local
894 "attempting to determine the number of PCRS"); in tpm_show_pcrs()
900 rc = __tpm_pcr_read(chip, i, digest); in tpm_show_pcrs()
903 str += sprintf(str, "PCR-%02d: ", i); in tpm_show_pcrs()
908 return str - buf; in tpm_show_pcrs()
929 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_show_pubek() local
932 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE, in tpm_show_pubek()
933 "attempting to read the PUBEK"); in tpm_show_pubek()
942 parameters (RSA 12->bytes: keybit, #primes, expbit) in tpm_show_pubek()
972 rc = str - buf; in tpm_show_pubek()
986 "attempting to determine the manufacturer"); in tpm_show_caps()
993 "attempting to determine the 1.1 version"); in tpm_show_caps()
1000 return str - buf; in tpm_show_caps()
1012 "attempting to determine the manufacturer"); in tpm_show_caps_1_2()
1018 "attempting to determine the 1.2 version"); in tpm_show_caps_1_2()
1026 return str - buf; in tpm_show_caps_1_2()
1033 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_show_durations() local
1035 if (chip->vendor.duration[TPM_LONG] == 0) in tpm_show_durations()
1039 jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]), in tpm_show_durations()
1040 jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]), in tpm_show_durations()
1041 jiffies_to_usecs(chip->vendor.duration[TPM_LONG]), in tpm_show_durations()
1042 chip->vendor.duration_adjusted in tpm_show_durations()
1050 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_show_timeouts() local
1053 jiffies_to_usecs(chip->vendor.timeout_a), in tpm_show_timeouts()
1054 jiffies_to_usecs(chip->vendor.timeout_b), in tpm_show_timeouts()
1055 jiffies_to_usecs(chip->vendor.timeout_c), in tpm_show_timeouts()
1056 jiffies_to_usecs(chip->vendor.timeout_d), in tpm_show_timeouts()
1057 chip->vendor.timeout_adjusted in tpm_show_timeouts()
1065 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_store_cancel() local
1066 if (chip == NULL) in tpm_store_cancel()
1069 chip->vendor.cancel(chip); in tpm_store_cancel()
1074 int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, in wait_for_tpm_stat() argument
1082 status = chip->vendor.status(chip); in wait_for_tpm_stat()
1088 if (chip->vendor.irq) { in wait_for_tpm_stat()
1090 timeout = stop - jiffies; in wait_for_tpm_stat()
1092 return -ETIME; in wait_for_tpm_stat()
1094 ((chip->vendor.status(chip) in wait_for_tpm_stat()
1099 if (rc == -ERESTARTSYS && freezing(current)) { in wait_for_tpm_stat()
1106 status = chip->vendor.status(chip); in wait_for_tpm_stat()
1111 return -ETIME; in wait_for_tpm_stat()
1115 * Device file system interface to the TPM
1117 * It's assured that the chip will be opened just once,
1124 struct tpm_chip *chip = NULL, *pos; in tpm_open() local
1128 if (pos->vendor.miscdev.minor == minor) { in tpm_open()
1129 chip = pos; in tpm_open()
1130 get_device(chip->dev); in tpm_open()
1136 if (!chip) in tpm_open()
1137 return -ENODEV; in tpm_open()
1139 if (test_and_set_bit(0, &chip->is_open)) { in tpm_open()
1140 dev_dbg(chip->dev, "Another process owns this TPM\n"); in tpm_open()
1141 put_device(chip->dev); in tpm_open()
1142 return -EBUSY; in tpm_open()
1145 chip->data_buffer = kzalloc(TPM_BUFSIZE, GFP_KERNEL); in tpm_open()
1146 if (chip->data_buffer == NULL) { in tpm_open()
1147 clear_bit(0, &chip->is_open); in tpm_open()
1148 put_device(chip->dev); in tpm_open()
1149 return -ENOMEM; in tpm_open()
1152 atomic_set(&chip->data_pending, 0); in tpm_open()
1154 file->private_data = chip; in tpm_open()
1164 struct tpm_chip *chip = file->private_data; in tpm_release() local
1166 del_singleshot_timer_sync(&chip->user_read_timer); in tpm_release()
1167 flush_work_sync(&chip->work); in tpm_release()
1168 file->private_data = NULL; in tpm_release()
1169 atomic_set(&chip->data_pending, 0); in tpm_release()
1170 kfree(chip->data_buffer); in tpm_release()
1171 clear_bit(0, &chip->is_open); in tpm_release()
1172 put_device(chip->dev); in tpm_release()
1180 struct tpm_chip *chip = file->private_data; in tpm_write() local
1185 while (atomic_read(&chip->data_pending) != 0) in tpm_write()
1188 mutex_lock(&chip->buffer_mutex); in tpm_write()
1194 (chip->data_buffer, (void __user *) buf, in_size)) { in tpm_write()
1195 mutex_unlock(&chip->buffer_mutex); in tpm_write()
1196 return -EFAULT; in tpm_write()
1200 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); in tpm_write()
1202 atomic_set(&chip->data_pending, out_size); in tpm_write()
1203 mutex_unlock(&chip->buffer_mutex); in tpm_write()
1206 mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); in tpm_write()
1215 struct tpm_chip *chip = file->private_data; in tpm_read() local
1219 del_singleshot_timer_sync(&chip->user_read_timer); in tpm_read()
1220 flush_work_sync(&chip->work); in tpm_read()
1221 ret_size = atomic_read(&chip->data_pending); in tpm_read()
1222 atomic_set(&chip->data_pending, 0); in tpm_read()
1227 mutex_lock(&chip->buffer_mutex); in tpm_read()
1228 rc = copy_to_user(buf, chip->data_buffer, ret_size); in tpm_read()
1229 memset(chip->data_buffer, 0, ret_size); in tpm_read()
1231 ret_size = -EFAULT; in tpm_read()
1233 mutex_unlock(&chip->buffer_mutex); in tpm_read()
1242 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_remove_hardware() local
1244 if (chip == NULL) { in tpm_remove_hardware()
1250 list_del_rcu(&chip->list); in tpm_remove_hardware()
1254 misc_deregister(&chip->vendor.miscdev); in tpm_remove_hardware()
1255 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group); in tpm_remove_hardware()
1256 tpm_bios_log_teardown(chip->bios_dir); in tpm_remove_hardware()
1258 /* write it this way to be explicit (chip->dev == dev) */ in tpm_remove_hardware()
1259 put_device(chip->dev); in tpm_remove_hardware()
1273 * We are about to suspend. Save the TPM state
1278 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_suspend() local
1284 if (chip == NULL) in tpm_pm_suspend()
1285 return -ENODEV; in tpm_pm_suspend()
1287 /* for buggy tpm, flush pcrs with extend to selected dummy */ in tpm_pm_suspend()
1293 rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE, in tpm_pm_suspend()
1299 rc = transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE, in tpm_pm_suspend()
1311 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_pm_resume() local
1313 if (chip == NULL) in tpm_pm_resume()
1314 return -ENODEV; in tpm_pm_resume()
1322 void tpm_dev_vendor_release(struct tpm_chip *chip) in tpm_dev_vendor_release() argument
1324 if (chip->vendor.release) in tpm_dev_vendor_release()
1325 chip->vendor.release(chip->dev); in tpm_dev_vendor_release()
1327 clear_bit(chip->dev_num, dev_mask); in tpm_dev_vendor_release()
1328 kfree(chip->vendor.miscdev.name); in tpm_dev_vendor_release()
1334 * Once all references to platform device are down to 0,
1339 struct tpm_chip *chip = dev_get_drvdata(dev); in tpm_dev_release() local
1341 tpm_dev_vendor_release(chip); in tpm_dev_release()
1343 chip->release(dev); in tpm_dev_release()
1344 kfree(chip); in tpm_dev_release()
1350 * the driver has determined it should claim. Prior to calling
1361 struct tpm_chip *chip; in tpm_register_hardware() local
1363 /* Driver specific per-device data */ in tpm_register_hardware()
1364 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in tpm_register_hardware()
1367 if (chip == NULL || devname == NULL) in tpm_register_hardware()
1370 mutex_init(&chip->buffer_mutex); in tpm_register_hardware()
1371 mutex_init(&chip->tpm_mutex); in tpm_register_hardware()
1372 INIT_LIST_HEAD(&chip->list); in tpm_register_hardware()
1374 INIT_WORK(&chip->work, timeout_work); in tpm_register_hardware()
1376 setup_timer(&chip->user_read_timer, user_reader_timeout, in tpm_register_hardware()
1377 (unsigned long)chip); in tpm_register_hardware()
1379 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); in tpm_register_hardware()
1381 chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES); in tpm_register_hardware()
1383 if (chip->dev_num >= TPM_NUM_DEVICES) { in tpm_register_hardware()
1386 } else if (chip->dev_num == 0) in tpm_register_hardware()
1387 chip->vendor.miscdev.minor = TPM_MINOR; in tpm_register_hardware()
1389 chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR; in tpm_register_hardware()
1391 set_bit(chip->dev_num, dev_mask); in tpm_register_hardware()
1393 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); in tpm_register_hardware()
1394 chip->vendor.miscdev.name = devname; in tpm_register_hardware()
1396 chip->vendor.miscdev.parent = dev; in tpm_register_hardware()
1397 chip->dev = get_device(dev); in tpm_register_hardware()
1398 chip->release = dev->release; in tpm_register_hardware()
1399 dev->release = tpm_dev_release; in tpm_register_hardware()
1400 dev_set_drvdata(dev, chip); in tpm_register_hardware()
1402 if (misc_register(&chip->vendor.miscdev)) { in tpm_register_hardware()
1403 dev_err(chip->dev, in tpm_register_hardware()
1404 "unable to misc_register %s, minor %d\n", in tpm_register_hardware()
1405 chip->vendor.miscdev.name, in tpm_register_hardware()
1406 chip->vendor.miscdev.minor); in tpm_register_hardware()
1407 put_device(chip->dev); in tpm_register_hardware()
1411 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { in tpm_register_hardware()
1412 misc_deregister(&chip->vendor.miscdev); in tpm_register_hardware()
1413 put_device(chip->dev); in tpm_register_hardware()
1418 chip->bios_dir = tpm_bios_log_setup(devname); in tpm_register_hardware()
1420 /* Make chip available */ in tpm_register_hardware()
1422 list_add_rcu(&chip->list, &tpm_chip_list); in tpm_register_hardware()
1425 return chip; in tpm_register_hardware()
1428 kfree(chip); in tpm_register_hardware()