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: prepare TPM driver for adding TPM2 support

* Separated allocation and registeration into two functions:
  * tpm_chip_alloc()
  * tpm_chip_register()
* Modified tpm_register_hardware() to call tpm_chip_alloc/register().
* Added tpm2 boolean flag to struct tpm_chip.
* If a chip has tpm2 flag set TCPA log is not initialized in
  tpm_chip_register().

The rationale is to introduce TPM2 support without existing drivers
getting harmed.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_calc_ordinal_durations()

Implemented TPM2 support for tpm_calc_ordinal_duration(). TPM2 version
is encapsulated into tpm2_calc_ordinal_duration() that is called by
tpm_calc_ordinal_duration() for TPM2 chips.

[jarkko.sakkinen: implemented tpm2_calc_ordinal_duration() based on
 the Wills original patch. Updated durations table to use worst case
 estimates.]

Signed-off-by: Will Arthur <will.c.arthur@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_pcr_read()

Implemented TPM2 support for tpm_pcr_read() by adding a new function
tpm2_pcr_read_dev() that is called for TPM2 chipsets.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_do_selftest()

Implemented tpm2_do_selftest() that runs the full (all commands)
self-test for the TPM chip. During the self-test TPM2 commands return
with the TPM error code RC_TESTING. Waiting is done by issuing PCR
read until it executes succesfully or some other error condition
than RC_TESTING happens.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: added tpm2_get_tpm_pt()

Added the function tpm2_get_tpm_pt() for acquiring TPM properties
(properties under under TPM_CAP_TPM_PROPERTIES capability).

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_pcr_extend()

Implemented TPM2 protocol support for tpm_pcr_extend().

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_get_random().

Implemented TPM2 support for tpm_get_random().

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: TPM2 support for tpm_startup()

This patch implements TPM2 support for tpm_startup().

[jarkko.sakkinen: implemented tpm2_startup() based on the Wills
 original patch.]

Signed-off-by: Will Arthur <will.c.arthur@intel.com>
tpm: TPM2 support for tpm_gen_interrupt().

This patch adds TPM2 support for tpm_gen_interrupt().

[jarkko.sakkinen: implemented tpm2_gen_interrupt() based on Wills
 original patch that is called from tpm_gen_interrupt() for TPM2
 chipsets.]

Signed-off-by: Will Arthur <will.c.arthur@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>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
tpm: Driver for 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>
tpm: TPM2 sysfs attributes

Added tpm2-sysfs.c that defines sysfs attributes for a TPM2
device driver. Documentation/ABI/stable/sysfs-class/tpm2 contains
descriptions of these attributes.

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