2014-12-13 03:46:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 IBM Corporation
|
|
|
|
* Copyright (C) 2014 Intel Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
|
|
|
|
* Leendert van Doorn <leendert@watson.ibm.com>
|
|
|
|
* Dave Safford <safford@watson.ibm.com>
|
|
|
|
* Reiner Sailer <sailer@watson.ibm.com>
|
|
|
|
* Kylene Hall <kjhall@us.ibm.com>
|
|
|
|
*
|
|
|
|
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
|
|
|
|
*
|
|
|
|
* TPM chip management routines.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2 of the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/freezer.h>
|
2014-12-13 03:46:37 +08:00
|
|
|
#include <linux/major.h>
|
2014-12-13 03:46:34 +08:00
|
|
|
#include "tpm.h"
|
|
|
|
#include "tpm_eventlog.h"
|
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
DEFINE_IDR(dev_nums_idr);
|
|
|
|
static DEFINE_MUTEX(idr_lock);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2014-12-13 03:46:37 +08:00
|
|
|
struct class *tpm_class;
|
2017-01-04 01:07:32 +08:00
|
|
|
struct class *tpmrm_class;
|
2014-12-13 03:46:37 +08:00
|
|
|
dev_t tpm_devt;
|
|
|
|
|
2016-02-13 11:29:53 +08:00
|
|
|
/**
|
|
|
|
* tpm_try_get_ops() - Get a ref to the tpm_chip
|
|
|
|
* @chip: Chip to ref
|
|
|
|
*
|
|
|
|
* The caller must already have some kind of locking to ensure that chip is
|
|
|
|
* valid. This function will lock the chip so that the ops member can be
|
|
|
|
* accessed safely. The locking prevents tpm_chip_unregister from
|
|
|
|
* completing, so it should not be held for long periods.
|
|
|
|
*
|
|
|
|
* Returns -ERRNO if the chip could not be got.
|
2014-12-13 03:46:34 +08:00
|
|
|
*/
|
2016-02-13 11:29:53 +08:00
|
|
|
int tpm_try_get_ops(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
int rc = -EIO;
|
|
|
|
|
|
|
|
get_device(&chip->dev);
|
|
|
|
|
|
|
|
down_read(&chip->ops_sem);
|
|
|
|
if (!chip->ops)
|
|
|
|
goto out_lock;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_lock:
|
|
|
|
up_read(&chip->ops_sem);
|
|
|
|
put_device(&chip->dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_try_get_ops);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_put_ops() - Release a ref to the tpm_chip
|
|
|
|
* @chip: Chip to put
|
|
|
|
*
|
|
|
|
* This is the opposite pair to tpm_try_get_ops(). After this returns chip may
|
|
|
|
* be kfree'd.
|
|
|
|
*/
|
|
|
|
void tpm_put_ops(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
up_read(&chip->ops_sem);
|
|
|
|
put_device(&chip->dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_put_ops);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_chip_find_get() - return tpm_chip for a given chip number
|
|
|
|
* @chip_num: id to find
|
|
|
|
*
|
|
|
|
* The return'd chip has been tpm_try_get_ops'd and must be released via
|
|
|
|
* tpm_put_ops
|
2016-12-15 07:09:16 +08:00
|
|
|
*/
|
2014-12-13 03:46:34 +08:00
|
|
|
struct tpm_chip *tpm_chip_find_get(int chip_num)
|
|
|
|
{
|
2016-02-29 21:53:02 +08:00
|
|
|
struct tpm_chip *chip, *res = NULL;
|
|
|
|
int chip_prev;
|
|
|
|
|
|
|
|
mutex_lock(&idr_lock);
|
|
|
|
|
|
|
|
if (chip_num == TPM_ANY_NUM) {
|
|
|
|
chip_num = 0;
|
|
|
|
do {
|
|
|
|
chip_prev = chip_num;
|
|
|
|
chip = idr_get_next(&dev_nums_idr, &chip_num);
|
|
|
|
if (chip && !tpm_try_get_ops(chip)) {
|
|
|
|
res = chip;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (chip_prev != chip_num);
|
|
|
|
} else {
|
2016-12-15 07:09:16 +08:00
|
|
|
chip = idr_find(&dev_nums_idr, chip_num);
|
2016-02-29 21:53:02 +08:00
|
|
|
if (chip && !tpm_try_get_ops(chip))
|
|
|
|
res = chip;
|
|
|
|
}
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
mutex_unlock(&idr_lock);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
return res;
|
2014-12-13 03:46:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-13 03:46:37 +08:00
|
|
|
* tpm_dev_release() - free chip memory and the device number
|
|
|
|
* @dev: the character device for the TPM chip
|
2014-12-13 03:46:34 +08:00
|
|
|
*
|
2014-12-13 03:46:37 +08:00
|
|
|
* This is used as the release function for the character device.
|
2014-12-13 03:46:34 +08:00
|
|
|
*/
|
2014-12-13 03:46:37 +08:00
|
|
|
static void tpm_dev_release(struct device *dev)
|
2014-12-13 03:46:34 +08:00
|
|
|
{
|
2014-12-13 03:46:37 +08:00
|
|
|
struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
mutex_lock(&idr_lock);
|
|
|
|
idr_remove(&dev_nums_idr, chip->dev_num);
|
|
|
|
mutex_unlock(&idr_lock);
|
|
|
|
|
2016-11-14 18:00:52 +08:00
|
|
|
kfree(chip->log.bios_event_log);
|
2017-01-06 20:03:45 +08:00
|
|
|
kfree(chip->work_space.context_buf);
|
2017-02-01 07:47:31 +08:00
|
|
|
kfree(chip->work_space.session_buf);
|
2014-12-13 03:46:34 +08:00
|
|
|
kfree(chip);
|
|
|
|
}
|
|
|
|
|
2017-01-04 01:07:32 +08:00
|
|
|
static void tpm_devs_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = container_of(dev, struct tpm_chip, devs);
|
|
|
|
|
|
|
|
/* release the master device reference */
|
|
|
|
put_device(&chip->dev);
|
|
|
|
}
|
|
|
|
|
2017-06-26 05:53:24 +08:00
|
|
|
/**
|
|
|
|
* tpm_class_shutdown() - prepare the TPM device for loss of power.
|
|
|
|
* @dev: device to which the chip is associated.
|
|
|
|
*
|
|
|
|
* Issues a TPM2_Shutdown command prior to loss of power, as required by the
|
|
|
|
* TPM 2.0 spec.
|
|
|
|
* Then, calls bus- and device- specific shutdown code.
|
|
|
|
*
|
|
|
|
* XXX: This codepath relies on the fact that sysfs is not enabled for
|
|
|
|
* TPM2: sysfs uses an implicit lock on chip->ops, so this could race if TPM2
|
|
|
|
* has sysfs support enabled before TPM sysfs's implicit locking is fixed.
|
|
|
|
*/
|
|
|
|
static int tpm_class_shutdown(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
|
|
|
|
|
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
|
|
|
|
down_write(&chip->ops_sem);
|
|
|
|
tpm2_shutdown(chip, TPM2_SU_CLEAR);
|
|
|
|
chip->ops = NULL;
|
|
|
|
up_write(&chip->ops_sem);
|
|
|
|
}
|
|
|
|
/* Allow bus- and device-specific code to run. Note: since chip->ops
|
|
|
|
* is NULL, more-specific shutdown code will not be able to issue TPM
|
|
|
|
* commands.
|
|
|
|
*/
|
|
|
|
if (dev->bus && dev->bus->shutdown)
|
|
|
|
dev->bus->shutdown(dev);
|
|
|
|
else if (dev->driver && dev->driver->shutdown)
|
|
|
|
dev->driver->shutdown(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-13 03:46:34 +08:00
|
|
|
/**
|
2016-02-12 03:45:48 +08:00
|
|
|
* tpm_chip_alloc() - allocate a new struct tpm_chip instance
|
|
|
|
* @pdev: device to which the chip is associated
|
|
|
|
* At this point pdev mst be initialized, but does not have to
|
|
|
|
* be registered
|
2014-12-13 03:46:34 +08:00
|
|
|
* @ops: struct tpm_class_ops instance
|
|
|
|
*
|
|
|
|
* Allocates a new struct tpm_chip instance and assigns a free
|
2016-02-12 03:45:48 +08:00
|
|
|
* device number for it. Must be paired with put_device(&chip->dev).
|
2014-12-13 03:46:34 +08:00
|
|
|
*/
|
2016-11-23 18:04:13 +08:00
|
|
|
struct tpm_chip *tpm_chip_alloc(struct device *pdev,
|
2016-02-12 03:45:48 +08:00
|
|
|
const struct tpm_class_ops *ops)
|
2014-12-13 03:46:34 +08:00
|
|
|
{
|
|
|
|
struct tpm_chip *chip;
|
2016-02-13 17:58:16 +08:00
|
|
|
int rc;
|
2014-12-13 03:46:34 +08:00
|
|
|
|
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
|
|
|
if (chip == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
mutex_init(&chip->tpm_mutex);
|
2016-02-13 11:29:53 +08:00
|
|
|
init_rwsem(&chip->ops_sem);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
|
|
|
chip->ops = ops;
|
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
mutex_lock(&idr_lock);
|
|
|
|
rc = idr_alloc(&dev_nums_idr, NULL, 0, TPM_NUM_DEVICES, GFP_KERNEL);
|
|
|
|
mutex_unlock(&idr_lock);
|
|
|
|
if (rc < 0) {
|
2016-11-23 18:04:13 +08:00
|
|
|
dev_err(pdev, "No available tpm device numbers\n");
|
2014-12-13 03:46:34 +08:00
|
|
|
kfree(chip);
|
2016-02-29 21:53:02 +08:00
|
|
|
return ERR_PTR(rc);
|
2014-12-13 03:46:34 +08:00
|
|
|
}
|
2016-02-29 21:53:02 +08:00
|
|
|
chip->dev_num = rc;
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2016-03-01 01:29:48 +08:00
|
|
|
device_initialize(&chip->dev);
|
2017-01-04 01:07:32 +08:00
|
|
|
device_initialize(&chip->devs);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2014-12-13 03:46:37 +08:00
|
|
|
chip->dev.class = tpm_class;
|
2017-06-26 05:53:24 +08:00
|
|
|
chip->dev.class->shutdown = tpm_class_shutdown;
|
2014-12-13 03:46:37 +08:00
|
|
|
chip->dev.release = tpm_dev_release;
|
2016-11-23 18:04:13 +08:00
|
|
|
chip->dev.parent = pdev;
|
2015-04-14 22:56:48 +08:00
|
|
|
chip->dev.groups = chip->groups;
|
2014-12-13 03:46:37 +08:00
|
|
|
|
2017-01-04 01:07:32 +08:00
|
|
|
chip->devs.parent = pdev;
|
|
|
|
chip->devs.class = tpmrm_class;
|
|
|
|
chip->devs.release = tpm_devs_release;
|
|
|
|
/* get extra reference on main device to hold on
|
|
|
|
* behalf of devs. This holds the chip structure
|
|
|
|
* while cdevs is in use. The corresponding put
|
2017-04-18 09:58:26 +08:00
|
|
|
* is in the tpm_devs_release (TPM2 only)
|
2017-01-04 01:07:32 +08:00
|
|
|
*/
|
2017-04-18 09:58:26 +08:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
get_device(&chip->dev);
|
2017-01-04 01:07:32 +08:00
|
|
|
|
2014-12-13 03:46:37 +08:00
|
|
|
if (chip->dev_num == 0)
|
|
|
|
chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR);
|
|
|
|
else
|
|
|
|
chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num);
|
|
|
|
|
2017-01-04 01:07:32 +08:00
|
|
|
chip->devs.devt =
|
|
|
|
MKDEV(MAJOR(tpm_devt), chip->dev_num + TPM_NUM_DEVICES);
|
|
|
|
|
2016-03-01 01:29:48 +08:00
|
|
|
rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num);
|
2017-01-04 01:07:32 +08:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
rc = dev_set_name(&chip->devs, "tpmrm%d", chip->dev_num);
|
2016-03-01 01:29:48 +08:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
2014-12-13 03:46:37 +08:00
|
|
|
|
2016-11-23 18:04:13 +08:00
|
|
|
if (!pdev)
|
2016-04-19 01:26:14 +08:00
|
|
|
chip->flags |= TPM_CHIP_FLAG_VIRTUAL;
|
|
|
|
|
2014-12-13 03:46:37 +08:00
|
|
|
cdev_init(&chip->cdev, &tpm_fops);
|
2017-01-04 01:07:32 +08:00
|
|
|
cdev_init(&chip->cdevs, &tpmrm_fops);
|
2016-02-29 21:53:01 +08:00
|
|
|
chip->cdev.owner = THIS_MODULE;
|
2017-01-04 01:07:32 +08:00
|
|
|
chip->cdevs.owner = THIS_MODULE;
|
2014-12-13 03:46:37 +08:00
|
|
|
|
2017-01-06 20:03:45 +08:00
|
|
|
chip->work_space.context_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!chip->work_space.context_buf) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-02-01 07:47:31 +08:00
|
|
|
chip->work_space.session_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!chip->work_space.session_buf) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-01-06 20:03:45 +08:00
|
|
|
|
2017-03-24 17:45:49 +08:00
|
|
|
chip->locality = -1;
|
2016-02-12 03:45:48 +08:00
|
|
|
return chip;
|
|
|
|
|
|
|
|
out:
|
2017-01-04 01:07:32 +08:00
|
|
|
put_device(&chip->devs);
|
2016-02-12 03:45:48 +08:00
|
|
|
put_device(&chip->dev);
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_chip_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tpmm_chip_alloc() - allocate a new struct tpm_chip instance
|
|
|
|
* @pdev: parent device to which the chip is associated
|
|
|
|
* @ops: struct tpm_class_ops instance
|
|
|
|
*
|
|
|
|
* Same as tpm_chip_alloc except devm is used to do the put_device
|
|
|
|
*/
|
|
|
|
struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
|
|
|
|
const struct tpm_class_ops *ops)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
chip = tpm_chip_alloc(pdev, ops);
|
|
|
|
if (IS_ERR(chip))
|
|
|
|
return chip;
|
|
|
|
|
2016-06-12 22:05:29 +08:00
|
|
|
rc = devm_add_action_or_reset(pdev,
|
|
|
|
(void (*)(void *)) put_device,
|
|
|
|
&chip->dev);
|
|
|
|
if (rc)
|
2016-02-13 17:58:16 +08:00
|
|
|
return ERR_PTR(rc);
|
2016-02-09 04:31:08 +08:00
|
|
|
|
2016-02-12 03:45:48 +08:00
|
|
|
dev_set_drvdata(pdev, chip);
|
2016-03-01 01:29:48 +08:00
|
|
|
|
2016-02-12 03:45:48 +08:00
|
|
|
return chip;
|
2014-12-13 03:46:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
|
|
|
|
|
2016-01-30 01:47:22 +08:00
|
|
|
static int tpm_add_char_device(struct tpm_chip *chip)
|
2014-12-13 03:46:37 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2017-03-18 02:48:13 +08:00
|
|
|
rc = cdev_device_add(&chip->cdev, &chip->dev);
|
2014-12-13 03:46:37 +08:00
|
|
|
if (rc) {
|
|
|
|
dev_err(&chip->dev,
|
2017-03-18 02:48:13 +08:00
|
|
|
"unable to cdev_device_add() %s, major %d, minor %d, err=%d\n",
|
2016-03-01 01:29:48 +08:00
|
|
|
dev_name(&chip->dev), MAJOR(chip->dev.devt),
|
2014-12-13 03:46:37 +08:00
|
|
|
MINOR(chip->dev.devt), rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
char/misc patches for 4.12-rc1
Here is the big set of new char/misc driver drivers and features for
4.12-rc1.
There's lots of new drivers added this time around, new firmware drivers
from Google, more auxdisplay drivers, extcon drivers, fpga drivers, and
a bunch of other driver updates. Nothing major, except if you happen to
have the hardware for these drivers, and then you will be happy :)
All of these have been in linux-next for a while with no reported
issues.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-----BEGIN PGP SIGNATURE-----
iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWQvAgg8cZ3JlZ0Brcm9h
aC5jb20ACgkQMUfUDdst+yknsACgzkAeyz16Z97J3UTaeejbR7nKUCAAoKY4WEHY
8O9f9pr9gj8GMBwxeZQa
=OIfB
-----END PGP SIGNATURE-----
Merge tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver updates from Greg KH:
"Here is the big set of new char/misc driver drivers and features for
4.12-rc1.
There's lots of new drivers added this time around, new firmware
drivers from Google, more auxdisplay drivers, extcon drivers, fpga
drivers, and a bunch of other driver updates. Nothing major, except if
you happen to have the hardware for these drivers, and then you will
be happy :)
All of these have been in linux-next for a while with no reported
issues"
* tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (136 commits)
firmware: google memconsole: Fix return value check in platform_memconsole_init()
firmware: Google VPD: Fix return value check in vpd_platform_init()
goldfish_pipe: fix build warning about using too much stack.
goldfish_pipe: An implementation of more parallel pipe
fpga fr br: update supported version numbers
fpga: region: release FPGA region reference in error path
fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe()
mei: drop the TODO from samples
firmware: Google VPD sysfs driver
firmware: Google VPD: import lib_vpd source files
misc: lkdtm: Add volatile to intentional NULL pointer reference
eeprom: idt_89hpesx: Add OF device ID table
misc: ds1682: Add OF device ID table
misc: tsl2550: Add OF device ID table
w1: Remove unneeded use of assert() and remove w1_log.h
w1: Use kernel common min() implementation
uio_mf624: Align memory regions to page size and set correct offsets
uio_mf624: Refactor memory info initialization
uio: Allow handling of non page-aligned memory regions
hangcheck-timer: Fix typo in comment
...
2017-05-05 10:07:10 +08:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
|
|
|
|
rc = cdev_device_add(&chip->cdevs, &chip->devs);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(&chip->devs,
|
|
|
|
"unable to cdev_device_add() %s, major %d, minor %d, err=%d\n",
|
|
|
|
dev_name(&chip->devs), MAJOR(chip->devs.devt),
|
|
|
|
MINOR(chip->devs.devt), rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2017-01-04 01:07:32 +08:00
|
|
|
}
|
|
|
|
|
2016-02-29 21:53:02 +08:00
|
|
|
/* Make the chip available. */
|
|
|
|
mutex_lock(&idr_lock);
|
|
|
|
idr_replace(&dev_nums_idr, chip, chip->dev_num);
|
|
|
|
mutex_unlock(&idr_lock);
|
|
|
|
|
2014-12-13 03:46:37 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-01-30 01:47:22 +08:00
|
|
|
static void tpm_del_char_device(struct tpm_chip *chip)
|
2014-12-13 03:46:37 +08:00
|
|
|
{
|
2017-03-18 02:48:13 +08:00
|
|
|
cdev_device_del(&chip->cdev, &chip->dev);
|
2016-02-29 21:53:02 +08:00
|
|
|
|
|
|
|
/* Make the chip unavailable. */
|
|
|
|
mutex_lock(&idr_lock);
|
|
|
|
idr_replace(&dev_nums_idr, NULL, chip->dev_num);
|
|
|
|
mutex_unlock(&idr_lock);
|
2016-02-13 11:29:53 +08:00
|
|
|
|
|
|
|
/* Make the driver uncallable. */
|
|
|
|
down_write(&chip->ops_sem);
|
2016-04-25 17:20:07 +08:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
tpm2_shutdown(chip, TPM2_SU_CLEAR);
|
2016-02-13 11:29:53 +08:00
|
|
|
chip->ops = NULL;
|
|
|
|
up_write(&chip->ops_sem);
|
2014-12-13 03:46:37 +08:00
|
|
|
}
|
|
|
|
|
2016-04-19 01:26:13 +08:00
|
|
|
static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
struct attribute **i;
|
|
|
|
|
2016-04-19 01:26:14 +08:00
|
|
|
if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
|
2016-04-19 01:26:13 +08:00
|
|
|
return;
|
2015-03-18 14:17:14 +08:00
|
|
|
|
2016-04-19 01:26:13 +08:00
|
|
|
sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
|
|
|
|
|
|
|
|
for (i = chip->groups[0]->attrs; *i != NULL; ++i)
|
|
|
|
sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
|
2015-03-18 14:17:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-19 01:26:13 +08:00
|
|
|
/* For compatibility with legacy sysfs paths we provide symlinks from the
|
|
|
|
* parent dev directory to selected names within the tpm chip directory. Old
|
|
|
|
* kernel versions created these files directly under the parent.
|
|
|
|
*/
|
|
|
|
static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
struct attribute **i;
|
|
|
|
int rc;
|
|
|
|
|
2016-04-19 01:26:14 +08:00
|
|
|
if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
|
2016-04-19 01:26:13 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = __compat_only_sysfs_link_entry_to_kobj(
|
|
|
|
&chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
|
|
|
|
if (rc && rc != -ENOENT)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* All the names from tpm-sysfs */
|
|
|
|
for (i = chip->groups[0]->attrs; *i != NULL; ++i) {
|
|
|
|
rc = __compat_only_sysfs_link_entry_to_kobj(
|
|
|
|
&chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name);
|
|
|
|
if (rc) {
|
|
|
|
tpm_del_legacy_sysfs(chip);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-13 03:46:34 +08:00
|
|
|
/*
|
2014-12-13 03:46:37 +08:00
|
|
|
* tpm_chip_register() - create a character device for the TPM chip
|
2014-12-13 03:46:34 +08:00
|
|
|
* @chip: TPM chip to use.
|
|
|
|
*
|
2015-03-02 05:55:47 +08:00
|
|
|
* Creates a character device for the TPM chip and adds sysfs attributes for
|
|
|
|
* the device. As the last step this function adds the chip to the list of TPM
|
|
|
|
* chips available for in-kernel use.
|
2014-12-13 03:46:34 +08:00
|
|
|
*
|
2015-03-02 05:55:47 +08:00
|
|
|
* This function should be only called after the chip initialization is
|
|
|
|
* complete.
|
2014-12-13 03:46:34 +08:00
|
|
|
*/
|
|
|
|
int tpm_chip_register(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2016-07-13 01:41:49 +08:00
|
|
|
if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) {
|
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
rc = tpm2_auto_startup(chip);
|
|
|
|
else
|
|
|
|
rc = tpm1_auto_startup(chip);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-11-14 18:00:51 +08:00
|
|
|
tpm_sysfs_add_device(chip);
|
|
|
|
|
|
|
|
rc = tpm_bios_log_setup(chip);
|
2016-11-20 02:18:28 +08:00
|
|
|
if (rc != 0 && rc != -ENODEV)
|
2015-03-18 14:17:14 +08:00
|
|
|
return rc;
|
2014-12-13 03:46:34 +08:00
|
|
|
|
2015-04-14 22:56:48 +08:00
|
|
|
tpm_add_ppi(chip);
|
|
|
|
|
2016-01-30 01:47:22 +08:00
|
|
|
rc = tpm_add_char_device(chip);
|
2016-04-19 01:26:13 +08:00
|
|
|
if (rc) {
|
2016-11-14 18:00:51 +08:00
|
|
|
tpm_bios_log_teardown(chip);
|
2016-04-19 01:26:13 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2015-03-02 05:55:47 +08:00
|
|
|
|
2016-04-19 01:26:13 +08:00
|
|
|
rc = tpm_add_legacy_sysfs(chip);
|
|
|
|
if (rc) {
|
|
|
|
tpm_chip_unregister(chip);
|
|
|
|
return rc;
|
2015-11-07 19:33:25 +08:00
|
|
|
}
|
|
|
|
|
2014-12-13 03:46:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_chip_register);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tpm_chip_unregister() - release the TPM driver
|
|
|
|
* @chip: TPM chip to use.
|
|
|
|
*
|
|
|
|
* Takes the chip first away from the list of available TPM chips and then
|
|
|
|
* cleans up all the resources reserved by tpm_chip_register().
|
|
|
|
*
|
2016-02-13 11:29:53 +08:00
|
|
|
* Once this function returns the driver call backs in 'op's will not be
|
|
|
|
* running and will no longer start.
|
|
|
|
*
|
2014-12-13 03:46:34 +08:00
|
|
|
* NOTE: This function should be only called before deinitializing chip
|
|
|
|
* resources.
|
|
|
|
*/
|
|
|
|
void tpm_chip_unregister(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-19 01:26:13 +08:00
|
|
|
tpm_del_legacy_sysfs(chip);
|
2016-11-14 18:00:51 +08:00
|
|
|
tpm_bios_log_teardown(chip);
|
char/misc patches for 4.12-rc1
Here is the big set of new char/misc driver drivers and features for
4.12-rc1.
There's lots of new drivers added this time around, new firmware drivers
from Google, more auxdisplay drivers, extcon drivers, fpga drivers, and
a bunch of other driver updates. Nothing major, except if you happen to
have the hardware for these drivers, and then you will be happy :)
All of these have been in linux-next for a while with no reported
issues.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-----BEGIN PGP SIGNATURE-----
iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWQvAgg8cZ3JlZ0Brcm9h
aC5jb20ACgkQMUfUDdst+yknsACgzkAeyz16Z97J3UTaeejbR7nKUCAAoKY4WEHY
8O9f9pr9gj8GMBwxeZQa
=OIfB
-----END PGP SIGNATURE-----
Merge tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver updates from Greg KH:
"Here is the big set of new char/misc driver drivers and features for
4.12-rc1.
There's lots of new drivers added this time around, new firmware
drivers from Google, more auxdisplay drivers, extcon drivers, fpga
drivers, and a bunch of other driver updates. Nothing major, except if
you happen to have the hardware for these drivers, and then you will
be happy :)
All of these have been in linux-next for a while with no reported
issues"
* tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (136 commits)
firmware: google memconsole: Fix return value check in platform_memconsole_init()
firmware: Google VPD: Fix return value check in vpd_platform_init()
goldfish_pipe: fix build warning about using too much stack.
goldfish_pipe: An implementation of more parallel pipe
fpga fr br: update supported version numbers
fpga: region: release FPGA region reference in error path
fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe()
mei: drop the TODO from samples
firmware: Google VPD sysfs driver
firmware: Google VPD: import lib_vpd source files
misc: lkdtm: Add volatile to intentional NULL pointer reference
eeprom: idt_89hpesx: Add OF device ID table
misc: ds1682: Add OF device ID table
misc: tsl2550: Add OF device ID table
w1: Remove unneeded use of assert() and remove w1_log.h
w1: Use kernel common min() implementation
uio_mf624: Align memory regions to page size and set correct offsets
uio_mf624: Refactor memory info initialization
uio: Allow handling of non page-aligned memory regions
hangcheck-timer: Fix typo in comment
...
2017-05-05 10:07:10 +08:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
cdev_device_del(&chip->cdevs, &chip->devs);
|
2016-01-30 01:47:22 +08:00
|
|
|
tpm_del_char_device(chip);
|
2014-12-13 03:46:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_chip_unregister);
|