Lines Matching +full:locality +full:- +full:specific
1 // SPDX-License-Identifier: GPL-2.0-only
13 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
44 if (!chip->ops->request_locality) in tpm_request_locality()
47 rc = chip->ops->request_locality(chip, 0); in tpm_request_locality()
51 chip->locality = rc; in tpm_request_locality()
59 if (!chip->ops->relinquish_locality) in tpm_relinquish_locality()
62 rc = chip->ops->relinquish_locality(chip, chip->locality); in tpm_relinquish_locality()
64 dev_err(&chip->dev, "%s: : error %d\n", __func__, rc); in tpm_relinquish_locality()
66 chip->locality = -1; in tpm_relinquish_locality()
71 if (!chip->ops->cmd_ready) in tpm_cmd_ready()
74 return chip->ops->cmd_ready(chip); in tpm_cmd_ready()
79 if (!chip->ops->go_idle) in tpm_go_idle()
82 return chip->ops->go_idle(chip); in tpm_go_idle()
87 if (chip->ops->clk_enable) in tpm_clk_enable()
88 chip->ops->clk_enable(chip, true); in tpm_clk_enable()
93 if (chip->ops->clk_enable) in tpm_clk_disable()
94 chip->ops->clk_enable(chip, false); in tpm_clk_disable()
98 * tpm_chip_start() - power on the TPM
102 * * The response length - OK
103 * * -errno - A system error
111 if (chip->locality == -1) { in tpm_chip_start()
131 * tpm_chip_stop() - power off the TPM
135 * * The response length - OK
136 * * -errno - A system error
147 * tpm_try_get_ops() - Get a ref to the tpm_chip
155 * Returns -ERRNO if the chip could not be got.
159 int rc = -EIO; in tpm_try_get_ops()
161 get_device(&chip->dev); in tpm_try_get_ops()
163 down_read(&chip->ops_sem); in tpm_try_get_ops()
164 if (!chip->ops) in tpm_try_get_ops()
167 mutex_lock(&chip->tpm_mutex); in tpm_try_get_ops()
174 mutex_unlock(&chip->tpm_mutex); in tpm_try_get_ops()
176 up_read(&chip->ops_sem); in tpm_try_get_ops()
177 put_device(&chip->dev); in tpm_try_get_ops()
183 * tpm_put_ops() - Release a ref to the tpm_chip
192 mutex_unlock(&chip->tpm_mutex); in tpm_put_ops()
193 up_read(&chip->ops_sem); in tpm_put_ops()
194 put_device(&chip->dev); in tpm_put_ops()
199 * tpm_default_chip() - find a TPM chip and get a reference to it
213 get_device(&chip->dev); in tpm_default_chip()
226 * tpm_find_get_ops() - find and reserve a TPM chip
255 put_device(&chip->dev); in tpm_find_get_ops()
262 * tpm_dev_release() - free chip memory and the device number
272 idr_remove(&dev_nums_idr, chip->dev_num); in tpm_dev_release()
275 kfree(chip->work_space.context_buf); in tpm_dev_release()
276 kfree(chip->work_space.session_buf); in tpm_dev_release()
277 kfree(chip->allocated_banks); in tpm_dev_release()
282 * tpm_class_shutdown() - prepare the TPM device for loss of power.
286 * TPM 2.0 spec. Then, calls bus- and device- specific shutdown code.
294 down_write(&chip->ops_sem); in tpm_class_shutdown()
295 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_class_shutdown()
301 chip->ops = NULL; in tpm_class_shutdown()
302 up_write(&chip->ops_sem); in tpm_class_shutdown()
308 * tpm_chip_alloc() - allocate a new struct tpm_chip instance
315 * device number for it. Must be paired with put_device(&chip->dev).
325 return ERR_PTR(-ENOMEM); in tpm_chip_alloc()
327 mutex_init(&chip->tpm_mutex); in tpm_chip_alloc()
328 init_rwsem(&chip->ops_sem); in tpm_chip_alloc()
330 chip->ops = ops; in tpm_chip_alloc()
340 chip->dev_num = rc; in tpm_chip_alloc()
342 device_initialize(&chip->dev); in tpm_chip_alloc()
344 chip->dev.class = &tpm_class; in tpm_chip_alloc()
345 chip->dev.release = tpm_dev_release; in tpm_chip_alloc()
346 chip->dev.parent = pdev; in tpm_chip_alloc()
347 chip->dev.groups = chip->groups; in tpm_chip_alloc()
349 if (chip->dev_num == 0) in tpm_chip_alloc()
350 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); in tpm_chip_alloc()
352 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); in tpm_chip_alloc()
354 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); in tpm_chip_alloc()
359 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; in tpm_chip_alloc()
361 cdev_init(&chip->cdev, &tpm_fops); in tpm_chip_alloc()
362 chip->cdev.owner = THIS_MODULE; in tpm_chip_alloc()
364 rc = tpm2_init_space(&chip->work_space, TPM2_SPACE_BUFFER_SIZE); in tpm_chip_alloc()
366 rc = -ENOMEM; in tpm_chip_alloc()
370 chip->locality = -1; in tpm_chip_alloc()
374 put_device(&chip->dev); in tpm_chip_alloc()
385 * tpmm_chip_alloc() - allocate a new struct tpm_chip instance
403 &chip->dev); in tpmm_chip_alloc()
417 rc = cdev_device_add(&chip->cdev, &chip->dev); in tpm_add_char_device()
419 dev_err(&chip->dev, in tpm_add_char_device()
421 dev_name(&chip->dev), MAJOR(chip->dev.devt), in tpm_add_char_device()
422 MINOR(chip->dev.devt), rc); in tpm_add_char_device()
426 if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip)) { in tpm_add_char_device()
434 idr_replace(&dev_nums_idr, chip, chip->dev_num); in tpm_add_char_device()
440 cdev_device_del(&chip->cdev, &chip->dev); in tpm_add_char_device()
446 cdev_device_del(&chip->cdev, &chip->dev); in tpm_del_char_device()
450 idr_replace(&dev_nums_idr, NULL, chip->dev_num); in tpm_del_char_device()
454 down_write(&chip->ops_sem); in tpm_del_char_device()
457 * Check if chip->ops is still valid: In case that the controller in tpm_del_char_device()
459 * shutdown handler we are called twice and chip->ops to NULL. in tpm_del_char_device()
461 if (chip->ops) { in tpm_del_char_device()
462 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_del_char_device()
468 chip->ops = NULL; in tpm_del_char_device()
470 up_write(&chip->ops_sem); in tpm_del_char_device()
477 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL) || in tpm_del_legacy_sysfs()
481 sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); in tpm_del_legacy_sysfs()
483 for (i = chip->groups[0]->attrs; *i != NULL; ++i) in tpm_del_legacy_sysfs()
484 sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); in tpm_del_legacy_sysfs()
496 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL) || in tpm_add_legacy_sysfs()
501 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi", NULL); in tpm_add_legacy_sysfs()
502 if (rc && rc != -ENOENT) in tpm_add_legacy_sysfs()
505 /* All the names from tpm-sysfs */ in tpm_add_legacy_sysfs()
506 for (i = chip->groups[0]->attrs; *i != NULL; ++i) { in tpm_add_legacy_sysfs()
508 &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name, NULL); in tpm_add_legacy_sysfs()
523 if (chip->flags & TPM_CHIP_FLAG_SUSPENDED) in tpm_hwrng_read()
535 if (chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED) in tpm_is_hwrng_enabled()
545 snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), in tpm_add_hwrng()
546 "tpm-rng-%d", chip->dev_num); in tpm_add_hwrng()
547 chip->hwrng.name = chip->hwrng_name; in tpm_add_hwrng()
548 chip->hwrng.read = tpm_hwrng_read; in tpm_add_hwrng()
549 return hwrng_register(&chip->hwrng); in tpm_add_hwrng()
559 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ? in tpm_get_pcr_allocation()
564 return -ENODEV; in tpm_get_pcr_allocation()
570 * tpm_chip_bootstrap() - Boostrap TPM chip after power on
573 * Initialize TPM chip after power on. This a one-shot function: subsequent
580 if (chip->flags & TPM_CHIP_FLAG_BOOTSTRAPPED) in tpm_chip_bootstrap()
599 chip->flags |= TPM_CHIP_FLAG_BOOTSTRAPPED; in tpm_chip_bootstrap()
606 * tpm_chip_register() - create a character device for the TPM chip
611 * chips available for in-kernel use.
648 hwrng_unregister(&chip->hwrng); in tpm_chip_register()
657 * tpm_chip_unregister() - release the TPM driver
673 hwrng_unregister(&chip->hwrng); in tpm_chip_unregister()
675 if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip)) in tpm_chip_unregister()