tpm: Store devname in the tpm_chip

Just put the memory directly in the chip structure, rather than
a 2nd dedicated kalloc.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Use container_of to locate the tpm_chip in tpm_open

misc_open sets the file->private_date to the misc_dev when calling
open. We can use container_of to go from the misc_dev back to the
tpm_chip.

Future clean ups will move tpm_open into a new file and this change
means we do not have to export the tpm_chip list.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Pull everything related to /dev/tpmX into tpm-dev.c

CLASS-dev.c is a common idiom for Linux subsystems

This pulls all the code related to the miscdev into tpm-dev.c and makes it
static. The identical file_operation structs in the drivers are purged and the
tpm common code unconditionally creates the miscdev.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Remove tpm_show_caps_1_2

The version of the TPM should not depend on the bus it is connected
through. 1.1, 1.2 and soon 2.0 TPMS will be all be able to use the
same bus interfaces.

Make tpm_show_caps try the 1.2 capability first. If that fails then
fall back to the 1.1 capability. This effectively auto-detects what
interface the TPM supports at run-time.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Pull everything related to sysfs into tpm-sysfs.c

CLASS-sysfs.c is a common idiom for linux subsystems.

This pulls all the sysfs attribute functions and related code
into tpm-sysfs.c. To support this change some constants are moved
from tpm.c to tpm.h and __tpm_pcr_read is made non-static and is
called tpm_pcr_read_dev.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Create a tpm_class_ops structure and use it in the drivers

This replaces the static initialization of a tpm_vendor_specific
structure in the drivers with the standard Linux idiom of providing
a const structure of function pointers.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
JUNK: Provide a vio.h good enough to compile tpm_ibmvtpm.c on x86

This way I can easily compile test all TPM drivers
tpm: Use the ops structure instead of a copy in tpm_vendor_specific

This builds on the last commit to use the ops structure in the core
and reduce the size of tpm_vendor_specific.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: Make device driver private data managed by the core layer

This is similar to how netdev_priv() works. The driver tells the core
how much memory it needs and it is allocated and managed for it.

The memory must be accessed through tpm_priv()

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: xen-tpmfront: Remove redundant dev_set_drvdata

TPM drivers should not call dev_set_drvdata, only the core code
is allowed to call dev_set_drvdata.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: i2c-infineon: Remvoe dev_set_drvdata

TPM drivers should not call dev_set_drvdata, only the core code
is allowed to call dev_set_drvdata.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
fixup! tpm: Make device driver private data managed by the core layer
tpm: Fix the TPM lifetime model

This is unfortunately currently a confusing mess and the drivers are
all doing something a little different/wrong.

Here are the rules we are aiming for after this commit:
 - Failure of the probe function calls tpm_remove_hardware
   on the cleanup path
 - On device remove the driver calls tpm_remove_hardware
 - ops.release is used by drivers to free any resources allocated
   inside the tpm_priv()
 - ops.release is called automatically on probe failure
 - Drivers should use devm functions

tpm_remove_hardware will take care of all the race conditions,
ensuring the device is not used, and will not be used, then

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
tpm: tpm_tis: Use devm_ for all resources

This lays the ground work for fixing the lifetime issues in the TPM
core.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
fixup! tpm: Fix the TPM lifetime model
fixup! tpm: Fix the TPM lifetime model