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 if (chip->flags & TPM_CHIP_FLAG_DISABLE) in tpm_try_get_ops()
164 get_device(&chip->dev); in tpm_try_get_ops()
166 down_read(&chip->ops_sem); in tpm_try_get_ops()
167 if (!chip->ops) in tpm_try_get_ops()
170 mutex_lock(&chip->tpm_mutex); in tpm_try_get_ops()
177 mutex_unlock(&chip->tpm_mutex); in tpm_try_get_ops()
179 up_read(&chip->ops_sem); in tpm_try_get_ops()
180 put_device(&chip->dev); in tpm_try_get_ops()
186 * tpm_put_ops() - Release a ref to the tpm_chip
195 mutex_unlock(&chip->tpm_mutex); in tpm_put_ops()
196 up_read(&chip->ops_sem); in tpm_put_ops()
197 put_device(&chip->dev); in tpm_put_ops()
202 * tpm_default_chip() - find a TPM chip and get a reference to it
216 get_device(&chip->dev); in tpm_default_chip()
229 * tpm_find_get_ops() - find and reserve a TPM chip
258 put_device(&chip->dev); in tpm_find_get_ops()
265 * tpm_dev_release() - free chip memory and the device number
275 idr_remove(&dev_nums_idr, chip->dev_num); in tpm_dev_release()
278 kfree(chip->work_space.context_buf); in tpm_dev_release()
279 kfree(chip->work_space.session_buf); in tpm_dev_release()
280 kfree(chip->allocated_banks); in tpm_dev_release()
282 kfree(chip->auth); in tpm_dev_release()
288 * tpm_class_shutdown() - prepare the TPM device for loss of power.
292 * TPM 2.0 spec. Then, calls bus- and device- specific shutdown code.
300 down_write(&chip->ops_sem); in tpm_class_shutdown()
301 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_class_shutdown()
307 chip->ops = NULL; in tpm_class_shutdown()
308 up_write(&chip->ops_sem); in tpm_class_shutdown()
314 * tpm_chip_alloc() - allocate a new struct tpm_chip instance
321 * device number for it. Must be paired with put_device(&chip->dev).
331 return ERR_PTR(-ENOMEM); in tpm_chip_alloc()
333 mutex_init(&chip->tpm_mutex); in tpm_chip_alloc()
334 init_rwsem(&chip->ops_sem); in tpm_chip_alloc()
336 chip->ops = ops; in tpm_chip_alloc()
346 chip->dev_num = rc; in tpm_chip_alloc()
348 device_initialize(&chip->dev); in tpm_chip_alloc()
350 chip->dev.class = &tpm_class; in tpm_chip_alloc()
351 chip->dev.release = tpm_dev_release; in tpm_chip_alloc()
352 chip->dev.parent = pdev; in tpm_chip_alloc()
353 chip->dev.groups = chip->groups; in tpm_chip_alloc()
355 if (chip->dev_num == 0) in tpm_chip_alloc()
356 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); in tpm_chip_alloc()
358 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); in tpm_chip_alloc()
360 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); in tpm_chip_alloc()
365 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; in tpm_chip_alloc()
367 cdev_init(&chip->cdev, &tpm_fops); in tpm_chip_alloc()
368 chip->cdev.owner = THIS_MODULE; in tpm_chip_alloc()
370 rc = tpm2_init_space(&chip->work_space, TPM2_SPACE_BUFFER_SIZE); in tpm_chip_alloc()
372 rc = -ENOMEM; in tpm_chip_alloc()
376 chip->locality = -1; in tpm_chip_alloc()
380 put_device(&chip->dev); in tpm_chip_alloc()
391 * tpmm_chip_alloc() - allocate a new struct tpm_chip instance
409 &chip->dev); in tpmm_chip_alloc()
423 rc = cdev_device_add(&chip->cdev, &chip->dev); in tpm_add_char_device()
425 dev_err(&chip->dev, in tpm_add_char_device()
427 dev_name(&chip->dev), MAJOR(chip->dev.devt), in tpm_add_char_device()
428 MINOR(chip->dev.devt), rc); in tpm_add_char_device()
432 if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip)) { in tpm_add_char_device()
440 idr_replace(&dev_nums_idr, chip, chip->dev_num); in tpm_add_char_device()
446 cdev_device_del(&chip->cdev, &chip->dev); in tpm_add_char_device()
452 cdev_device_del(&chip->cdev, &chip->dev); in tpm_del_char_device()
456 idr_replace(&dev_nums_idr, NULL, chip->dev_num); in tpm_del_char_device()
460 down_write(&chip->ops_sem); in tpm_del_char_device()
463 * Check if chip->ops is still valid: In case that the controller in tpm_del_char_device()
465 * shutdown handler we are called twice and chip->ops to NULL. in tpm_del_char_device()
467 if (chip->ops) { in tpm_del_char_device()
468 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_del_char_device()
474 chip->ops = NULL; in tpm_del_char_device()
476 up_write(&chip->ops_sem); in tpm_del_char_device()
483 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL) || in tpm_del_legacy_sysfs()
487 sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); in tpm_del_legacy_sysfs()
489 for (i = chip->groups[0]->attrs; *i != NULL; ++i) in tpm_del_legacy_sysfs()
490 sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); in tpm_del_legacy_sysfs()
502 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL) || in tpm_add_legacy_sysfs()
507 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi", NULL); in tpm_add_legacy_sysfs()
508 if (rc && rc != -ENOENT) in tpm_add_legacy_sysfs()
511 /* All the names from tpm-sysfs */ in tpm_add_legacy_sysfs()
512 for (i = chip->groups[0]->attrs; *i != NULL; ++i) { in tpm_add_legacy_sysfs()
514 &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name, NULL); in tpm_add_legacy_sysfs()
537 if (chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED) in tpm_is_hwrng_enabled()
547 snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), in tpm_add_hwrng()
548 "tpm-rng-%d", chip->dev_num); in tpm_add_hwrng()
549 chip->hwrng.name = chip->hwrng_name; in tpm_add_hwrng()
550 chip->hwrng.read = tpm_hwrng_read; in tpm_add_hwrng()
551 return hwrng_register(&chip->hwrng); in tpm_add_hwrng()
561 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ? in tpm_get_pcr_allocation()
566 return -ENODEV; in tpm_get_pcr_allocation()
572 * tpm_chip_bootstrap() - Boostrap TPM chip after power on
575 * Initialize TPM chip after power on. This a one-shot function: subsequent
582 if (chip->flags & TPM_CHIP_FLAG_BOOTSTRAPPED) in tpm_chip_bootstrap()
601 chip->flags |= TPM_CHIP_FLAG_BOOTSTRAPPED; in tpm_chip_bootstrap()
608 * tpm_chip_register() - create a character device for the TPM chip
613 * chips available for in-kernel use.
650 hwrng_unregister(&chip->hwrng); in tpm_chip_register()
659 * tpm_chip_unregister() - release the TPM driver
685 hwrng_unregister(&chip->hwrng); in tpm_chip_unregister()
687 if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip)) in tpm_chip_unregister()