// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2004 IBM Corporation * Copyright (C) 2014 Intel Corporation * * Authors: * Leendert van Doorn <[email protected]> * Dave Safford <[email protected]> * Reiner Sailer <[email protected]> * Kylene Hall <[email protected]> * * Maintained by: <[email protected]> * * Device driver for TCG/TCPA TPM (trusted platform module). * Specifications at www.trustedcomputinggroup.org * * Note, the TPM chip is not interrupt driven (only polling) * and can have very long timeouts (minutes!). Hence the unusual * calls to msleep. */ #include <linux/poll.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/suspend.h> #include <linux/freezer.h> #include <linux/tpm_eventlog.h> #include "tpm.h" /* * Bug workaround - some TPM's don't flush the most * recently changed pcr on suspend, so force the flush * with an extend to the selected _unused_ non-volatile pcr. */ static u32 tpm_suspend_pcr; module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644); MODULE_PARM_DESC(…) …; /** * tpm_calc_ordinal_duration() - calculate the maximum command duration * @chip: TPM chip to use. * @ordinal: TPM command ordinal. * * The function returns the maximum amount of time the chip could take * to return the result for a particular ordinal in jiffies. * * Return: A maximal duration time for an ordinal in jiffies. */ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) { … } EXPORT_SYMBOL_GPL(…); static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) { … } /** * tpm_transmit - Internal kernel interface to transmit TPM commands. * @chip: a TPM chip to use * @buf: a TPM command buffer * @bufsiz: length of the TPM command buffer * * A wrapper around tpm_try_transmit() that handles TPM2_RC_RETRY returns from * the TPM and retransmits the command after a delay up to a maximum wait of * TPM2_DURATION_LONG. * * Note that TPM 1.x never returns TPM2_RC_RETRY so the retry logic is TPM 2.0 * only. * * Return: * * The response length - OK * * -errno - A system error */ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) { … } /** * tpm_transmit_cmd - send a tpm command to the device * @chip: a TPM chip to use * @buf: a TPM command buffer * @min_rsp_body_length: minimum expected length of response body * @desc: command description used in the error message * * Return: * * 0 - OK * * -errno - A system error * * TPM_RC - A TPM error */ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, size_t min_rsp_body_length, const char *desc) { … } EXPORT_SYMBOL_GPL(…); int tpm_get_timeouts(struct tpm_chip *chip) { … } EXPORT_SYMBOL_GPL(…); /** * tpm_is_tpm2 - do we a have a TPM2 chip? * @chip: a &struct tpm_chip instance, %NULL for the default chip * * Return: * 1 if we have a TPM2 chip. * 0 if we don't have a TPM2 chip. * A negative number for system errors (errno). */ int tpm_is_tpm2(struct tpm_chip *chip) { … } EXPORT_SYMBOL_GPL(…); /** * tpm_pcr_read - read a PCR value from SHA1 bank * @chip: a &struct tpm_chip instance, %NULL for the default chip * @pcr_idx: the PCR to be retrieved * @digest: the PCR bank and buffer current PCR value is written to * * Return: same as with tpm_transmit_cmd() */ int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digest) { … } EXPORT_SYMBOL_GPL(…); /** * tpm_pcr_extend - extend a PCR value in SHA1 bank. * @chip: a &struct tpm_chip instance, %NULL for the default chip * @pcr_idx: the PCR to be retrieved * @digests: array of tpm_digest structures used to extend PCRs * * Note: callers must pass a digest for every allocated PCR bank, in the same * order of the banks in chip->allocated_banks. * * Return: same as with tpm_transmit_cmd() */ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, struct tpm_digest *digests) { … } EXPORT_SYMBOL_GPL(…); int tpm_auto_startup(struct tpm_chip *chip) { … } /* * We are about to suspend. Save the TPM state * so that it can be restored. */ int tpm_pm_suspend(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /* * Resume from a power safe. The BIOS already restored * the TPM state. */ int tpm_pm_resume(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * tpm_get_random() - get random bytes from the TPM's RNG * @chip: a &struct tpm_chip instance, %NULL for the default chip * @out: destination buffer for the random bytes * @max: the max number of bytes to write to @out * * Return: number of random bytes read or a negative error value. */ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) { … } EXPORT_SYMBOL_GPL(…); static int __init tpm_init(void) { … } static void __exit tpm_exit(void) { … } subsys_initcall(tpm_init); module_exit(tpm_exit); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_VERSION(…) …; MODULE_LICENSE(…) …;