• Home
  • Raw
  • Download

Lines Matching full:chip

14  * TPM chip management routines.
42 * @chip: Chip to ref
44 * The caller must already have some kind of locking to ensure that chip is
45 * valid. This function will lock the chip so that the ops member can be
49 * Returns -ERRNO if the chip could not be got.
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()
71 * @chip: Chip to put
73 * This is the opposite pair to tpm_try_get_ops(). After this returns chip may
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()
84 * tpm_default_chip() - find a TPM chip and get a reference to it
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()
111 * tpm_find_get_ops() - find and reserve a TPM chip
112 * @chip: a &struct tpm_chip instance, %NULL for the default chip
114 * Finds a TPM chip and reserves its class device and operations. The chip must
117 * by accepting NULL, but those callers should be converted to pass in a chip
122 * %NULL if a chip is not found.
123 * %NULL if the chip is not available.
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()
147 * tpm_dev_release() - free chip memory and the device number
148 * @dev: the character device for the TPM chip
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()
176 * @dev: device to which the chip is associated.
183 * TPM2: sysfs uses an implicit lock on chip->ops, so this could race if TPM2
188 struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); in tpm_class_shutdown() local
190 down_write(&chip->ops_sem); in tpm_class_shutdown()
191 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_class_shutdown()
192 tpm2_shutdown(chip, TPM2_SU_CLEAR); in tpm_class_shutdown()
193 chip->ops = NULL; in tpm_class_shutdown()
195 chip->ops = NULL; in tpm_class_shutdown()
196 up_write(&chip->ops_sem); in tpm_class_shutdown()
203 * @pdev: device to which the chip is associated
209 * device number for it. Must be paired with put_device(&chip->dev).
214 struct tpm_chip *chip; in tpm_chip_alloc() local
217 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in tpm_chip_alloc()
218 if (chip == NULL) in tpm_chip_alloc()
221 mutex_init(&chip->tpm_mutex); in tpm_chip_alloc()
222 init_rwsem(&chip->ops_sem); in tpm_chip_alloc()
224 chip->ops = ops; in tpm_chip_alloc()
231 kfree(chip); in tpm_chip_alloc()
234 chip->dev_num = rc; in tpm_chip_alloc()
236 device_initialize(&chip->dev); in tpm_chip_alloc()
237 device_initialize(&chip->devs); in tpm_chip_alloc()
239 chip->dev.class = tpm_class; in tpm_chip_alloc()
240 chip->dev.class->shutdown_pre = tpm_class_shutdown; in tpm_chip_alloc()
241 chip->dev.release = tpm_dev_release; in tpm_chip_alloc()
242 chip->dev.parent = pdev; in tpm_chip_alloc()
243 chip->dev.groups = chip->groups; in tpm_chip_alloc()
245 chip->devs.parent = pdev; in tpm_chip_alloc()
246 chip->devs.class = tpmrm_class; in tpm_chip_alloc()
247 chip->devs.release = tpm_devs_release; in tpm_chip_alloc()
249 * behalf of devs. This holds the chip structure in tpm_chip_alloc()
253 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_alloc()
254 get_device(&chip->dev); in tpm_chip_alloc()
256 if (chip->dev_num == 0) in tpm_chip_alloc()
257 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); in tpm_chip_alloc()
259 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); in tpm_chip_alloc()
261 chip->devs.devt = in tpm_chip_alloc()
262 MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES); in tpm_chip_alloc()
264 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); in tpm_chip_alloc()
267 rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num); in tpm_chip_alloc()
272 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; in tpm_chip_alloc()
274 cdev_init(&chip->cdev, &tpm_fops); in tpm_chip_alloc()
275 cdev_init(&chip->cdevs, &tpmrm_fops); in tpm_chip_alloc()
276 chip->cdev.owner = THIS_MODULE; in tpm_chip_alloc()
277 chip->cdevs.owner = THIS_MODULE; in tpm_chip_alloc()
279 rc = tpm2_init_space(&chip->work_space, TPM2_SPACE_BUFFER_SIZE); in tpm_chip_alloc()
285 chip->locality = -1; in tpm_chip_alloc()
286 return chip; in tpm_chip_alloc()
289 put_device(&chip->devs); in tpm_chip_alloc()
290 put_device(&chip->dev); in tpm_chip_alloc()
297 * @pdev: parent device to which the chip is associated
305 struct tpm_chip *chip; in tpmm_chip_alloc() local
308 chip = tpm_chip_alloc(pdev, ops); in tpmm_chip_alloc()
309 if (IS_ERR(chip)) in tpmm_chip_alloc()
310 return chip; in tpmm_chip_alloc()
314 &chip->dev); in tpmm_chip_alloc()
318 dev_set_drvdata(pdev, chip); in tpmm_chip_alloc()
320 return chip; in tpmm_chip_alloc()
324 static int tpm_add_char_device(struct tpm_chip *chip) in tpm_add_char_device() argument
328 rc = cdev_device_add(&chip->cdev, &chip->dev); in tpm_add_char_device()
330 dev_err(&chip->dev, in tpm_add_char_device()
332 dev_name(&chip->dev), MAJOR(chip->dev.devt), in tpm_add_char_device()
333 MINOR(chip->dev.devt), rc); in tpm_add_char_device()
337 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in tpm_add_char_device()
338 rc = cdev_device_add(&chip->cdevs, &chip->devs); in tpm_add_char_device()
340 dev_err(&chip->devs, in tpm_add_char_device()
342 dev_name(&chip->devs), MAJOR(chip->devs.devt), in tpm_add_char_device()
343 MINOR(chip->devs.devt), rc); in tpm_add_char_device()
348 /* Make the chip available. */ in tpm_add_char_device()
350 idr_replace(&dev_nums_idr, chip, chip->dev_num); in tpm_add_char_device()
356 static void tpm_del_char_device(struct tpm_chip *chip) in tpm_del_char_device() argument
358 cdev_device_del(&chip->cdev, &chip->dev); in tpm_del_char_device()
360 /* Make the chip unavailable. */ in tpm_del_char_device()
362 idr_replace(&dev_nums_idr, NULL, chip->dev_num); in tpm_del_char_device()
366 down_write(&chip->ops_sem); in tpm_del_char_device()
367 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_del_char_device()
368 tpm2_shutdown(chip, TPM2_SU_CLEAR); in tpm_del_char_device()
369 chip->ops = NULL; in tpm_del_char_device()
370 up_write(&chip->ops_sem); in tpm_del_char_device()
373 static void tpm_del_legacy_sysfs(struct tpm_chip *chip) in tpm_del_legacy_sysfs() argument
377 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_del_legacy_sysfs()
380 sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); in tpm_del_legacy_sysfs()
382 for (i = chip->groups[0]->attrs; *i != NULL; ++i) in tpm_del_legacy_sysfs()
383 sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); in tpm_del_legacy_sysfs()
387 * parent dev directory to selected names within the tpm chip directory. Old
390 static int tpm_add_legacy_sysfs(struct tpm_chip *chip) in tpm_add_legacy_sysfs() argument
395 if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) in tpm_add_legacy_sysfs()
399 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi"); in tpm_add_legacy_sysfs()
404 for (i = chip->groups[0]->attrs; *i != NULL; ++i) { in tpm_add_legacy_sysfs()
406 &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name); in tpm_add_legacy_sysfs()
408 tpm_del_legacy_sysfs(chip); in tpm_add_legacy_sysfs()
418 struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng); in tpm_hwrng_read() local
420 return tpm_get_random(chip, data, max); in tpm_hwrng_read()
423 static int tpm_add_hwrng(struct tpm_chip *chip) in tpm_add_hwrng() argument
428 snprintf(chip->hwrng_name, sizeof(chip->hwrng_name), in tpm_add_hwrng()
429 "tpm-rng-%d", chip->dev_num); in tpm_add_hwrng()
430 chip->hwrng.name = chip->hwrng_name; in tpm_add_hwrng()
431 chip->hwrng.read = tpm_hwrng_read; in tpm_add_hwrng()
432 return hwrng_register(&chip->hwrng); in tpm_add_hwrng()
436 * tpm_chip_register() - create a character device for the TPM chip
437 * @chip: TPM chip to use.
439 * Creates a character device for the TPM chip and adds sysfs attributes for
440 * the device. As the last step this function adds the chip to the list of TPM
443 * This function should be only called after the chip initialization is
446 int tpm_chip_register(struct tpm_chip *chip) in tpm_chip_register() argument
450 if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) { in tpm_chip_register()
451 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_register()
452 rc = tpm2_auto_startup(chip); in tpm_chip_register()
454 rc = tpm1_auto_startup(chip); in tpm_chip_register()
459 tpm_sysfs_add_device(chip); in tpm_chip_register()
461 tpm_bios_log_setup(chip); in tpm_chip_register()
463 tpm_add_ppi(chip); in tpm_chip_register()
465 rc = tpm_add_hwrng(chip); in tpm_chip_register()
469 rc = tpm_add_char_device(chip); in tpm_chip_register()
473 rc = tpm_add_legacy_sysfs(chip); in tpm_chip_register()
475 tpm_chip_unregister(chip); in tpm_chip_register()
483 hwrng_unregister(&chip->hwrng); in tpm_chip_register()
485 tpm_bios_log_teardown(chip); in tpm_chip_register()
493 * @chip: TPM chip to use.
495 * Takes the chip first away from the list of available TPM chips and then
501 * NOTE: This function should be only called before deinitializing chip
504 void tpm_chip_unregister(struct tpm_chip *chip) in tpm_chip_unregister() argument
506 tpm_del_legacy_sysfs(chip); in tpm_chip_unregister()
508 hwrng_unregister(&chip->hwrng); in tpm_chip_unregister()
509 tpm_bios_log_teardown(chip); in tpm_chip_unregister()
510 if (chip->flags & TPM_CHIP_FLAG_TPM2) in tpm_chip_unregister()
511 cdev_device_del(&chip->cdevs, &chip->devs); in tpm_chip_unregister()
512 tpm_del_char_device(chip); in tpm_chip_unregister()