Lines Matching +full:locality +full:- +full:specific

1 // SPDX-License-Identifier: GPL-2.0-only
13 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
39 if (!chip->ops->request_locality) in tpm_request_locality()
42 rc = chip->ops->request_locality(chip, 0); in tpm_request_locality()
46 chip->locality = rc; in tpm_request_locality()
54 if (!chip->ops->relinquish_locality) in tpm_relinquish_locality()
57 rc = chip->ops->relinquish_locality(chip, chip->locality); in tpm_relinquish_locality()
59 dev_err(&chip->dev, "%s: : error %d\n", __func__, rc); in tpm_relinquish_locality()
61 chip->locality = -1; in tpm_relinquish_locality()
66 if (!chip->ops->cmd_ready) in tpm_cmd_ready()
69 return chip->ops->cmd_ready(chip); in tpm_cmd_ready()
74 if (!chip->ops->go_idle) in tpm_go_idle()
77 return chip->ops->go_idle(chip); in tpm_go_idle()
82 if (chip->ops->clk_enable) in tpm_clk_enable()
83 chip->ops->clk_enable(chip, true); in tpm_clk_enable()
88 if (chip->ops->clk_enable) in tpm_clk_disable()
89 chip->ops->clk_enable(chip, false); in tpm_clk_disable()
93 * tpm_chip_start() - power on the TPM
97 * * The response length - OK
98 * * -errno - A system error
106 if (chip->locality == -1) { in tpm_chip_start()
126 * tpm_chip_stop() - power off the TPM
130 * * The response length - OK
131 * * -errno - A system error
142 * tpm_try_get_ops() - Get a ref to the tpm_chip
150 * Returns -ERRNO if the chip could not be got.
154 int rc = -EIO; in tpm_try_get_ops()
156 get_device(&chip->dev); in tpm_try_get_ops()
158 down_read(&chip->ops_sem); in tpm_try_get_ops()
159 if (!chip->ops) in tpm_try_get_ops()
162 mutex_lock(&chip->tpm_mutex); in tpm_try_get_ops()
169 mutex_unlock(&chip->tpm_mutex); in tpm_try_get_ops()
171 up_read(&chip->ops_sem); in tpm_try_get_ops()
172 put_device(&chip->dev); in tpm_try_get_ops()
178 * tpm_put_ops() - Release a ref to the tpm_chip
187 mutex_unlock(&chip->tpm_mutex); in tpm_put_ops()
188 up_read(&chip->ops_sem); in tpm_put_ops()
189 put_device(&chip->dev); in tpm_put_ops()
194 * tpm_default_chip() - find a TPM chip and get a reference to it
208 get_device(&chip->dev); in tpm_default_chip()
221 * tpm_find_get_ops() - find and reserve a TPM chip
250 put_device(&chip->dev); in tpm_find_get_ops()
257 * tpm_dev_release() - free chip memory and the device number
267 idr_remove(&dev_nums_idr, chip->dev_num); in tpm_dev_release()
270 kfree(chip->log.bios_event_log); in tpm_dev_release()
271 kfree(chip->work_space.context_buf); in tpm_dev_release()
272 kfree(chip->work_space.session_buf); in tpm_dev_release()
273 kfree(chip->allocated_banks); in tpm_dev_release()
282 put_device(&chip->dev); in tpm_devs_release()
286 * tpm_class_shutdown() - prepare the TPM device for loss of power.
290 * TPM 2.0 spec. Then, calls bus- and device- specific shutdown code.
298 down_write(&chip->ops_sem); in tpm_class_shutdown()
299 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_class_shutdown()
305 chip->ops = NULL; in tpm_class_shutdown()
306 up_write(&chip->ops_sem); in tpm_class_shutdown()
312 * tpm_chip_alloc() - allocate a new struct tpm_chip instance
319 * device number for it. Must be paired with put_device(&chip->dev).
329 return ERR_PTR(-ENOMEM); in tpm_chip_alloc()
331 mutex_init(&chip->tpm_mutex); in tpm_chip_alloc()
332 init_rwsem(&chip->ops_sem); in tpm_chip_alloc()
334 chip->ops = ops; in tpm_chip_alloc()
344 chip->dev_num = rc; in tpm_chip_alloc()
346 device_initialize(&chip->dev); in tpm_chip_alloc()
347 device_initialize(&chip->devs); in tpm_chip_alloc()
349 chip->dev.class = tpm_class; in tpm_chip_alloc()
350 chip->dev.class->shutdown_pre = tpm_class_shutdown; 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 chip->devs.parent = pdev; in tpm_chip_alloc()
356 chip->devs.class = tpmrm_class; in tpm_chip_alloc()
357 chip->devs.release = tpm_devs_release; in tpm_chip_alloc()
363 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_alloc()
364 get_device(&chip->dev); in tpm_chip_alloc()
366 if (chip->dev_num == 0) in tpm_chip_alloc()
367 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); in tpm_chip_alloc()
369 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); in tpm_chip_alloc()
371 chip->devs.devt = in tpm_chip_alloc()
372 MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES); in tpm_chip_alloc()
374 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); in tpm_chip_alloc()
377 rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num); in tpm_chip_alloc()
382 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; in tpm_chip_alloc()
384 cdev_init(&chip->cdev, &tpm_fops); in tpm_chip_alloc()
385 cdev_init(&chip->cdevs, &tpmrm_fops); in tpm_chip_alloc()
386 chip->cdev.owner = THIS_MODULE; in tpm_chip_alloc()
387 chip->cdevs.owner = THIS_MODULE; in tpm_chip_alloc()
389 rc = tpm2_init_space(&chip->work_space, TPM2_SPACE_BUFFER_SIZE); in tpm_chip_alloc()
391 rc = -ENOMEM; in tpm_chip_alloc()
395 chip->locality = -1; in tpm_chip_alloc()
399 put_device(&chip->devs); in tpm_chip_alloc()
400 put_device(&chip->dev); in tpm_chip_alloc()
406 * tpmm_chip_alloc() - allocate a new struct tpm_chip instance
424 &chip->dev); in tpmm_chip_alloc()
438 rc = cdev_device_add(&chip->cdev, &chip->dev); in tpm_add_char_device()
440 dev_err(&chip->dev, in tpm_add_char_device()
442 dev_name(&chip->dev), MAJOR(chip->dev.devt), in tpm_add_char_device()
443 MINOR(chip->dev.devt), rc); in tpm_add_char_device()
447 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_add_char_device()
448 rc = cdev_device_add(&chip->cdevs, &chip->devs); in tpm_add_char_device()
450 dev_err(&chip->devs, in tpm_add_char_device()
452 dev_name(&chip->devs), MAJOR(chip->devs.devt), in tpm_add_char_device()
453 MINOR(chip->devs.devt), rc); in tpm_add_char_device()
460 idr_replace(&dev_nums_idr, chip, chip->dev_num); in tpm_add_char_device()
468 cdev_device_del(&chip->cdev, &chip->dev); in tpm_del_char_device()
472 idr_replace(&dev_nums_idr, NULL, chip->dev_num); in tpm_del_char_device()
476 down_write(&chip->ops_sem); in tpm_del_char_device()
477 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_del_char_device()
483 chip->ops = NULL; in tpm_del_char_device()
484 up_write(&chip->ops_sem); in tpm_del_char_device()
491 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_del_legacy_sysfs()
494 sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); in tpm_del_legacy_sysfs()
496 for (i = chip->groups[0]->attrs; *i != NULL; ++i) in tpm_del_legacy_sysfs()
497 sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); in tpm_del_legacy_sysfs()
509 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_add_legacy_sysfs()
513 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi", NULL); in tpm_add_legacy_sysfs()
514 if (rc && rc != -ENOENT) in tpm_add_legacy_sysfs()
517 /* All the names from tpm-sysfs */ in tpm_add_legacy_sysfs()
518 for (i = chip->groups[0]->attrs; *i != NULL; ++i) { in tpm_add_legacy_sysfs()
520 &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name, NULL); in tpm_add_legacy_sysfs()
542 snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), in tpm_add_hwrng()
543 "tpm-rng-%d", chip->dev_num); in tpm_add_hwrng()
544 chip->hwrng.name = chip->hwrng_name; in tpm_add_hwrng()
545 chip->hwrng.read = tpm_hwrng_read; in tpm_add_hwrng()
546 return hwrng_register(&chip->hwrng); in tpm_add_hwrng()
553 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ? in tpm_get_pcr_allocation()
558 return -ENODEV; in tpm_get_pcr_allocation()
564 * tpm_chip_register() - create a character device for the TPM chip
569 * chips available for in-kernel use.
616 hwrng_unregister(&chip->hwrng); in tpm_chip_register()
625 * tpm_chip_unregister() - release the TPM driver
641 hwrng_unregister(&chip->hwrng); in tpm_chip_unregister()
643 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_unregister()
644 cdev_device_del(&chip->cdevs, &chip->devs); in tpm_chip_unregister()