Lines Matching refs:chip
51 int tpm_try_get_ops(struct tpm_chip *chip) in tpm_try_get_ops() argument
55 get_device(&chip->dev); in tpm_try_get_ops()
57 down_read(&chip->ops_sem); in tpm_try_get_ops()
58 if (!chip->ops) in tpm_try_get_ops()
63 up_read(&chip->ops_sem); in tpm_try_get_ops()
64 put_device(&chip->dev); in tpm_try_get_ops()
76 void tpm_put_ops(struct tpm_chip *chip) in tpm_put_ops() argument
78 up_read(&chip->ops_sem); in tpm_put_ops()
79 put_device(&chip->dev); in tpm_put_ops()
88 struct tpm_chip *chip, *res = NULL; in tpm_default_chip() local
96 chip = idr_get_next(&dev_nums_idr, &chip_num); in tpm_default_chip()
97 if (chip) { in tpm_default_chip()
98 get_device(&chip->dev); in tpm_default_chip()
99 res = chip; in tpm_default_chip()
125 struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip) in tpm_find_get_ops() argument
129 if (chip) { in tpm_find_get_ops()
130 if (!tpm_try_get_ops(chip)) in tpm_find_get_ops()
131 return chip; in tpm_find_get_ops()
135 chip = tpm_default_chip(); in tpm_find_get_ops()
136 if (!chip) in tpm_find_get_ops()
138 rc = tpm_try_get_ops(chip); in tpm_find_get_ops()
140 put_device(&chip->dev); in tpm_find_get_ops()
143 return chip; in tpm_find_get_ops()
154 struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); in tpm_dev_release() local
157 idr_remove(&dev_nums_idr, chip->dev_num); in tpm_dev_release()
160 kfree(chip->log.bios_event_log); in tpm_dev_release()
161 kfree(chip->work_space.context_buf); in tpm_dev_release()
162 kfree(chip->work_space.session_buf); in tpm_dev_release()
163 kfree(chip); in tpm_dev_release()
168 struct tpm_chip *chip = container_of(dev, struct tpm_chip, devs); in tpm_devs_release() local
171 put_device(&chip->dev); in tpm_devs_release()
188 struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); in tpm_class_shutdown() local
190 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_class_shutdown()
191 down_write(&chip->ops_sem); in tpm_class_shutdown()
192 tpm2_shutdown(chip, TPM2_SU_CLEAR); in tpm_class_shutdown()
193 chip->ops = NULL; in tpm_class_shutdown()
194 up_write(&chip->ops_sem); in tpm_class_shutdown()
213 struct tpm_chip *chip; in tpm_chip_alloc() local
216 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in tpm_chip_alloc()
217 if (chip == NULL) in tpm_chip_alloc()
220 mutex_init(&chip->tpm_mutex); in tpm_chip_alloc()
221 init_rwsem(&chip->ops_sem); in tpm_chip_alloc()
223 chip->ops = ops; in tpm_chip_alloc()
230 kfree(chip); in tpm_chip_alloc()
233 chip->dev_num = rc; in tpm_chip_alloc()
235 device_initialize(&chip->dev); in tpm_chip_alloc()
236 device_initialize(&chip->devs); in tpm_chip_alloc()
238 chip->dev.class = tpm_class; in tpm_chip_alloc()
239 chip->dev.class->shutdown_pre = tpm_class_shutdown; in tpm_chip_alloc()
240 chip->dev.release = tpm_dev_release; in tpm_chip_alloc()
241 chip->dev.parent = pdev; in tpm_chip_alloc()
242 chip->dev.groups = chip->groups; in tpm_chip_alloc()
244 chip->devs.parent = pdev; in tpm_chip_alloc()
245 chip->devs.class = tpmrm_class; in tpm_chip_alloc()
246 chip->devs.release = tpm_devs_release; in tpm_chip_alloc()
252 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_alloc()
253 get_device(&chip->dev); in tpm_chip_alloc()
255 if (chip->dev_num == 0) in tpm_chip_alloc()
256 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); in tpm_chip_alloc()
258 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); in tpm_chip_alloc()
260 chip->devs.devt = in tpm_chip_alloc()
261 MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES); in tpm_chip_alloc()
263 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); in tpm_chip_alloc()
266 rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num); in tpm_chip_alloc()
271 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; in tpm_chip_alloc()
273 cdev_init(&chip->cdev, &tpm_fops); in tpm_chip_alloc()
274 cdev_init(&chip->cdevs, &tpmrm_fops); in tpm_chip_alloc()
275 chip->cdev.owner = THIS_MODULE; in tpm_chip_alloc()
276 chip->cdevs.owner = THIS_MODULE; in tpm_chip_alloc()
278 chip->work_space.context_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); in tpm_chip_alloc()
279 if (!chip->work_space.context_buf) { in tpm_chip_alloc()
283 chip->work_space.session_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); in tpm_chip_alloc()
284 if (!chip->work_space.session_buf) { in tpm_chip_alloc()
289 chip->locality = -1; in tpm_chip_alloc()
290 return chip; in tpm_chip_alloc()
293 put_device(&chip->devs); in tpm_chip_alloc()
294 put_device(&chip->dev); in tpm_chip_alloc()
309 struct tpm_chip *chip; in tpmm_chip_alloc() local
312 chip = tpm_chip_alloc(pdev, ops); in tpmm_chip_alloc()
313 if (IS_ERR(chip)) in tpmm_chip_alloc()
314 return chip; in tpmm_chip_alloc()
318 &chip->dev); in tpmm_chip_alloc()
322 dev_set_drvdata(pdev, chip); in tpmm_chip_alloc()
324 return chip; in tpmm_chip_alloc()
328 static int tpm_add_char_device(struct tpm_chip *chip) in tpm_add_char_device() argument
332 rc = cdev_device_add(&chip->cdev, &chip->dev); in tpm_add_char_device()
334 dev_err(&chip->dev, in tpm_add_char_device()
336 dev_name(&chip->dev), MAJOR(chip->dev.devt), in tpm_add_char_device()
337 MINOR(chip->dev.devt), rc); in tpm_add_char_device()
341 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_add_char_device()
342 rc = cdev_device_add(&chip->cdevs, &chip->devs); in tpm_add_char_device()
344 dev_err(&chip->devs, in tpm_add_char_device()
346 dev_name(&chip->devs), MAJOR(chip->devs.devt), in tpm_add_char_device()
347 MINOR(chip->devs.devt), rc); in tpm_add_char_device()
354 idr_replace(&dev_nums_idr, chip, chip->dev_num); in tpm_add_char_device()
360 static void tpm_del_char_device(struct tpm_chip *chip) in tpm_del_char_device() argument
362 cdev_device_del(&chip->cdev, &chip->dev); in tpm_del_char_device()
366 idr_replace(&dev_nums_idr, NULL, chip->dev_num); in tpm_del_char_device()
370 down_write(&chip->ops_sem); in tpm_del_char_device()
371 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_del_char_device()
372 tpm2_shutdown(chip, TPM2_SU_CLEAR); in tpm_del_char_device()
373 chip->ops = NULL; in tpm_del_char_device()
374 up_write(&chip->ops_sem); in tpm_del_char_device()
377 static void tpm_del_legacy_sysfs(struct tpm_chip *chip) in tpm_del_legacy_sysfs() argument
381 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_del_legacy_sysfs()
384 sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); in tpm_del_legacy_sysfs()
386 for (i = chip->groups[0]->attrs; *i != NULL; ++i) in tpm_del_legacy_sysfs()
387 sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); in tpm_del_legacy_sysfs()
394 static int tpm_add_legacy_sysfs(struct tpm_chip *chip) in tpm_add_legacy_sysfs() argument
399 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_add_legacy_sysfs()
403 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi"); in tpm_add_legacy_sysfs()
408 for (i = chip->groups[0]->attrs; *i != NULL; ++i) { in tpm_add_legacy_sysfs()
410 &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name); in tpm_add_legacy_sysfs()
412 tpm_del_legacy_sysfs(chip); in tpm_add_legacy_sysfs()
422 struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); in tpm_hwrng_read() local
424 return tpm_get_random(chip, data, max); in tpm_hwrng_read()
427 static int tpm_add_hwrng(struct tpm_chip *chip) in tpm_add_hwrng() argument
432 snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), in tpm_add_hwrng()
433 "tpm-rng-%d", chip->dev_num); in tpm_add_hwrng()
434 chip->hwrng.name = chip->hwrng_name; in tpm_add_hwrng()
435 chip->hwrng.read = tpm_hwrng_read; in tpm_add_hwrng()
436 return hwrng_register(&chip->hwrng); in tpm_add_hwrng()
450 int tpm_chip_register(struct tpm_chip *chip) in tpm_chip_register() argument
454 if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) { in tpm_chip_register()
455 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_register()
456 rc = tpm2_auto_startup(chip); in tpm_chip_register()
458 rc = tpm1_auto_startup(chip); in tpm_chip_register()
463 tpm_sysfs_add_device(chip); in tpm_chip_register()
465 rc = tpm_bios_log_setup(chip); in tpm_chip_register()
469 tpm_add_ppi(chip); in tpm_chip_register()
471 rc = tpm_add_hwrng(chip); in tpm_chip_register()
475 rc = tpm_add_char_device(chip); in tpm_chip_register()
479 rc = tpm_add_legacy_sysfs(chip); in tpm_chip_register()
481 tpm_chip_unregister(chip); in tpm_chip_register()
489 hwrng_unregister(&chip->hwrng); in tpm_chip_register()
491 tpm_bios_log_teardown(chip); in tpm_chip_register()
510 void tpm_chip_unregister(struct tpm_chip *chip) in tpm_chip_unregister() argument
512 tpm_del_legacy_sysfs(chip); in tpm_chip_unregister()
514 hwrng_unregister(&chip->hwrng); in tpm_chip_unregister()
515 tpm_bios_log_teardown(chip); in tpm_chip_unregister()
516 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_unregister()
517 cdev_device_del(&chip->cdevs, &chip->devs); in tpm_chip_unregister()
518 tpm_del_char_device(chip); in tpm_chip_unregister()