// SPDX-License-Identifier: GPL-2.0 /* * 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]> * * Device driver for TCG/TCPA TPM (trusted platform module). * Specifications at www.trustedcomputinggroup.org */ #include <linux/poll.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/freezer.h> #include <linux/tpm_eventlog.h> #include "tpm.h" #define TPM_MAX_ORDINAL … /* * Array with one entry per ordinal defining the maximum amount * of time the chip could take to return the result. The ordinal * designation of short, medium or long is defined in a table in * TCG Specification TPM Main Part 2 TPM Structures Section 17. The * values of the SHORT, MEDIUM, and LONG durations are retrieved * from the chip during initialization with a call to tpm_get_timeouts. */ static const u8 tpm1_ordinal_duration[TPM_MAX_ORDINAL] = …; /** * tpm1_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 tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) { … } #define TPM_ORD_STARTUP … #define TPM_ST_CLEAR … /** * tpm1_startup() - turn on the TPM * @chip: TPM chip to use * * Normally the firmware should start the TPM. This function is provided as a * workaround if this does not happen. A legal case for this could be for * example when a TPM emulator is used. * * Return: same as tpm_transmit_cmd() */ static int tpm1_startup(struct tpm_chip *chip) { … } int tpm1_get_timeouts(struct tpm_chip *chip) { … } #define TPM_ORD_PCR_EXTEND … int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash, const char *log_msg) { … } #define TPM_ORD_GET_CAP … ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, const char *desc, size_t min_cap_length) { … } EXPORT_SYMBOL_GPL(…); #define TPM_ORD_GET_RANDOM … struct tpm1_get_random_out { … } __packed; /** * tpm1_get_random() - get random bytes from the TPM's RNG * @chip: a &struct tpm_chip instance * @dest: destination buffer for the random bytes * @max: the maximum number of bytes to write to @dest * * Return: * * number of bytes read * * -errno (positive TPM return codes are masked to -EIO) */ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max) { … } #define TPM_ORD_PCRREAD … int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf) { … } #define TPM_ORD_CONTINUE_SELFTEST … /** * tpm1_continue_selftest() - run TPM's selftest * @chip: TPM chip to use * * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing * a TPM error code. */ static int tpm1_continue_selftest(struct tpm_chip *chip) { … } /** * tpm1_do_selftest - have the TPM continue its selftest and wait until it * can receive further commands * @chip: TPM chip to use * * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing * a TPM error code. */ int tpm1_do_selftest(struct tpm_chip *chip) { … } EXPORT_SYMBOL_GPL(…); /** * tpm1_auto_startup - Perform the standard automatic TPM initialization * sequence * @chip: TPM chip to use * * Returns 0 on success, < 0 in case of fatal error. */ int tpm1_auto_startup(struct tpm_chip *chip) { … } #define TPM_ORD_SAVESTATE … /** * tpm1_pm_suspend() - pm suspend handler * @chip: TPM chip to use. * @tpm_suspend_pcr: flush pcr for buggy TPM chips. * * The functions saves the TPM state to be restored on resume. * * Return: * * 0 on success, * * < 0 on error. */ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr) { … } /** * tpm1_get_pcr_allocation() - initialize the allocated bank * @chip: TPM chip to use. * * The function initializes the SHA1 allocated bank to extend PCR * * Return: * * 0 on success, * * < 0 on error. */ int tpm1_get_pcr_allocation(struct tpm_chip *chip) { … }