tpm: merge duplicate transmit_cmd() functions (v2)

Merged transmit_cmd() functions in tpm-interface.c and tpm-sysfs.c.
Added "tpm_" prefix for consistency sake. Changed cmd parameter as
opaque. This enables to use separate command structures for TPM1
and TPM2 command instead of putting everything to struct tpm_cmd_t.

Changes from v1:

- Changed tpm-dev.c to use tpm_transmit_cmd().
- Changed tpm_transmit() as static function.
- Changed cmd parameter as opaque.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: two-phase chip management functions

Added tpm_chip_alloc() and tpm_chip_register() where tpm_chip_alloc()
reserves memory resources and sets struct tpm_chip fields to their
default values and tpm_chip_register() initializes the device driver.

Removed broken release callback moving the responsibility for releasing
resources to the device drivers in their "detach" functions.

This change is done to better define life-cycle of a TPM device driver.
Before this change it has been unclear when and who should free the
resources.

tpm_register_hardware() is still available as a wrapper in order to
make this change less intrusive. However, device drivers should
eventually move to the tpm_chip_* functions.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM 2.0 commands

This patch contains the following internal helper functions for
tpm.ko:

- tpm2_get_random()
- tpm2_get_tpm_pt()
- tpm2_pcr_extend()
- tpm2_pcr_read()
- tpm2_startup()

And the following exported functions for implementing new device
drivers.

- tpm2_do_selftest()
- tpm2_calc_ordinal_durations()
- tpm2_gen_interrupt()

All the functions defined in include/linux/tpm.h have been added
a routing for TPM2 counter parts.

The code for tpm2_gen_interrupt(), tpm2_calc_ordinal_duration()
and tpm2_startup() is derived from the code originally made by
Will Arthur.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Will Arthur <will.c.arthur@intel.com>
tpm: TPM2 sysfs attributes

Implemented sysfs attributes for TPM2 devices.

Documentation/ABI/stable/sysfs-class/tpm2 contains descriptions
of these attributes.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM 2.0 FIFO Interface

Detect TPM 2.0 by using the extended STS (STS3) register. For TPM 2.0,
instead of calling tpm_get_timeouts(), assign duration and timeout
values defined in the TPM 2.0 PTP specification.

Signed-off-by: Will Arthur <will.c.arthur@intel.com>
tpm: TPM 2.0 CRB Interface

tpm_crb is a driver for TPM 2.0 Command Response Buffer (CRB) Interface
as defined in PC Client Platform TPM Profile (PTP) Specification.

Only polling and single locality is supported as these are the limitations
of the available hardware, Platform Trust Techonlogy (PTT) in Haswell
CPUs.

The driver always applies CRB with ACPI start because PTT reports using
only ACPI start as start method but as a result of my testing it requires
also CRB start.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>