TPM: Add new TPMs to the tail of the list to prevent inadvertent change of dev

Add newly registered TPMs to the tail of the list, not the beginning, so that
things that are specifying TPM_ANY_NUM don't find that the device they're
using has inadvertently changed.  Adding a second device would break IMA, for
instance.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
tpm_tis: verify interrupt during init

Some machines, such as the Acer C720 and Toshiba CB35, have TPMs that do
not send IRQs while also having an ACPI TPM entry indicating that they
will be sent. These machines freeze on resume while the tpm_tis module
waits for an IRQ, eventually timing out.

When in interrupt mode, the tpm_tis module should receive an IRQ during
module init. Fall back to polling mode if none is received when expected.

Signed-off-by: Scot Doyle <lkml14@scotdoyle.com>
Tested-by: Michael Mullin <masmullin@gmail.com>
Reviewed-By: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
TPM: Provide a kernel facility for a userspace TPM emulator [ver #2]

TPM: Provide a facility for a userspace TPM emulator

Provide a misc device file (/dev/tpm_emul) by which a userspace TPM emulator
can set up a virtual TPM device under the control of the TPM frontend.  The
way this works is:

 (1) The emulator opens /dev/tpm_emul which is provided by the tpm_user
     driver.

 (2) tpm_user registers a TPM device and the tpm driver creates a /dev/tpmN
     misc device for the trousers package and suchlike to access.

 (3) The emulator sits in read() on the emulator device waiting for a command
     to come through.

 (4) tpm_user passes requests from /dev/tpmN to the emulator's read() call.

 (5) The emulator processes the request.

 (6) The emulator either write()'s the reply or calls ioctl(fd,0,0) to cancel
     the command.

 (7) The emulator goes back to read() to wait for the next command.

 (8) tpm_user passes the reply back to the tpm driver which passes it back to
     /dev/tpmN.

When the emulator closes /dev/tpm_emul, the TPM driver is unregistered and the
/dev/tpmN misc device is then removed.  Any outstanding requests are aborted
and -EIO will be returned from then on.  Multiple TPMs can be registered.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>