Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2004 IBM Corporation
0004  * Copyright (C) 2015 Intel Corporation
0005  *
0006  * Authors:
0007  * Leendert van Doorn <leendert@watson.ibm.com>
0008  * Dave Safford <safford@watson.ibm.com>
0009  * Reiner Sailer <sailer@watson.ibm.com>
0010  * Kylene Hall <kjhall@us.ibm.com>
0011  *
0012  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
0013  *
0014  * Device driver for TCG/TCPA TPM (trusted platform module).
0015  * Specifications at www.trustedcomputinggroup.org
0016  */
0017 
0018 #ifndef __TPM_H__
0019 #define __TPM_H__
0020 
0021 #include <linux/module.h>
0022 #include <linux/delay.h>
0023 #include <linux/mutex.h>
0024 #include <linux/sched.h>
0025 #include <linux/platform_device.h>
0026 #include <linux/io.h>
0027 #include <linux/tpm.h>
0028 #include <linux/tpm_eventlog.h>
0029 
0030 #ifdef CONFIG_X86
0031 #include <asm/intel-family.h>
0032 #endif
0033 
0034 #define TPM_MINOR       224 /* officially assigned */
0035 #define TPM_BUFSIZE     4096
0036 #define TPM_NUM_DEVICES     65536
0037 #define TPM_RETRY       50
0038 
0039 enum tpm_timeout {
0040     TPM_TIMEOUT = 5,    /* msecs */
0041     TPM_TIMEOUT_RETRY = 100, /* msecs */
0042     TPM_TIMEOUT_RANGE_US = 300, /* usecs */
0043     TPM_TIMEOUT_POLL = 1,   /* msecs */
0044     TPM_TIMEOUT_USECS_MIN = 100,      /* usecs */
0045     TPM_TIMEOUT_USECS_MAX = 500      /* usecs */
0046 };
0047 
0048 /* TPM addresses */
0049 enum tpm_addr {
0050     TPM_SUPERIO_ADDR = 0x2E,
0051     TPM_ADDR = 0x4E,
0052 };
0053 
0054 #define TPM_WARN_RETRY          0x800
0055 #define TPM_WARN_DOING_SELFTEST 0x802
0056 #define TPM_ERR_DEACTIVATED     0x6
0057 #define TPM_ERR_DISABLED        0x7
0058 #define TPM_ERR_FAILEDSELFTEST  0x1C
0059 #define TPM_ERR_INVALID_POSTINIT 38
0060 
0061 #define TPM_TAG_RQU_COMMAND 193
0062 
0063 /* TPM2 specific constants. */
0064 #define TPM2_SPACE_BUFFER_SIZE      16384 /* 16 kB */
0065 
0066 struct  stclear_flags_t {
0067     __be16  tag;
0068     u8  deactivated;
0069     u8  disableForceClear;
0070     u8  physicalPresence;
0071     u8  physicalPresenceLock;
0072     u8  bGlobalLock;
0073 } __packed;
0074 
0075 struct tpm1_version {
0076     u8 major;
0077     u8 minor;
0078     u8 rev_major;
0079     u8 rev_minor;
0080 } __packed;
0081 
0082 struct tpm1_version2 {
0083     __be16 tag;
0084     struct tpm1_version version;
0085 } __packed;
0086 
0087 struct  timeout_t {
0088     __be32  a;
0089     __be32  b;
0090     __be32  c;
0091     __be32  d;
0092 } __packed;
0093 
0094 struct duration_t {
0095     __be32  tpm_short;
0096     __be32  tpm_medium;
0097     __be32  tpm_long;
0098 } __packed;
0099 
0100 struct permanent_flags_t {
0101     __be16  tag;
0102     u8  disable;
0103     u8  ownership;
0104     u8  deactivated;
0105     u8  readPubek;
0106     u8  disableOwnerClear;
0107     u8  allowMaintenance;
0108     u8  physicalPresenceLifetimeLock;
0109     u8  physicalPresenceHWEnable;
0110     u8  physicalPresenceCMDEnable;
0111     u8  CEKPUsed;
0112     u8  TPMpost;
0113     u8  TPMpostLock;
0114     u8  FIPS;
0115     u8  operator;
0116     u8  enableRevokeEK;
0117     u8  nvLocked;
0118     u8  readSRKPub;
0119     u8  tpmEstablished;
0120     u8  maintenanceDone;
0121     u8  disableFullDALogicInfo;
0122 } __packed;
0123 
0124 typedef union {
0125     struct  permanent_flags_t perm_flags;
0126     struct  stclear_flags_t stclear_flags;
0127     __u8    owned;
0128     __be32  num_pcrs;
0129     struct tpm1_version version1;
0130     struct tpm1_version2 version2;
0131     __be32  manufacturer_id;
0132     struct timeout_t  timeout;
0133     struct duration_t duration;
0134 } cap_t;
0135 
0136 enum tpm_capabilities {
0137     TPM_CAP_FLAG = 4,
0138     TPM_CAP_PROP = 5,
0139     TPM_CAP_VERSION_1_1 = 0x06,
0140     TPM_CAP_VERSION_1_2 = 0x1A,
0141 };
0142 
0143 enum tpm_sub_capabilities {
0144     TPM_CAP_PROP_PCR = 0x101,
0145     TPM_CAP_PROP_MANUFACTURER = 0x103,
0146     TPM_CAP_FLAG_PERM = 0x108,
0147     TPM_CAP_FLAG_VOL = 0x109,
0148     TPM_CAP_PROP_OWNER = 0x111,
0149     TPM_CAP_PROP_TIS_TIMEOUT = 0x115,
0150     TPM_CAP_PROP_TIS_DURATION = 0x120,
0151 };
0152 
0153 
0154 /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
0155  * bytes, but 128 is still a relatively large number of random bytes and
0156  * anything much bigger causes users of struct tpm_cmd_t to start getting
0157  * compiler warnings about stack frame size. */
0158 #define TPM_MAX_RNG_DATA    128
0159 
0160 extern struct class *tpm_class;
0161 extern struct class *tpmrm_class;
0162 extern dev_t tpm_devt;
0163 extern const struct file_operations tpm_fops;
0164 extern const struct file_operations tpmrm_fops;
0165 extern struct idr dev_nums_idr;
0166 
0167 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
0168 int tpm_get_timeouts(struct tpm_chip *);
0169 int tpm_auto_startup(struct tpm_chip *chip);
0170 
0171 int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
0172 int tpm1_auto_startup(struct tpm_chip *chip);
0173 int tpm1_do_selftest(struct tpm_chip *chip);
0174 int tpm1_get_timeouts(struct tpm_chip *chip);
0175 unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
0176 int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
0177             const char *log_msg);
0178 int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
0179 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
0180             const char *desc, size_t min_cap_length);
0181 int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
0182 int tpm1_get_pcr_allocation(struct tpm_chip *chip);
0183 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
0184 int tpm_pm_suspend(struct device *dev);
0185 int tpm_pm_resume(struct device *dev);
0186 
0187 static inline void tpm_msleep(unsigned int delay_msec)
0188 {
0189     usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
0190              delay_msec * 1000);
0191 };
0192 
0193 int tpm_chip_start(struct tpm_chip *chip);
0194 void tpm_chip_stop(struct tpm_chip *chip);
0195 struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
0196 
0197 struct tpm_chip *tpm_chip_alloc(struct device *dev,
0198                 const struct tpm_class_ops *ops);
0199 struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
0200                  const struct tpm_class_ops *ops);
0201 int tpm_chip_register(struct tpm_chip *chip);
0202 void tpm_chip_unregister(struct tpm_chip *chip);
0203 
0204 void tpm_sysfs_add_device(struct tpm_chip *chip);
0205 
0206 
0207 #ifdef CONFIG_ACPI
0208 extern void tpm_add_ppi(struct tpm_chip *chip);
0209 #else
0210 static inline void tpm_add_ppi(struct tpm_chip *chip)
0211 {
0212 }
0213 #endif
0214 
0215 int tpm2_get_timeouts(struct tpm_chip *chip);
0216 int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
0217           struct tpm_digest *digest, u16 *digest_size_ptr);
0218 int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
0219             struct tpm_digest *digests);
0220 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
0221 ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
0222             u32 *value, const char *desc);
0223 
0224 ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
0225 int tpm2_auto_startup(struct tpm_chip *chip);
0226 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
0227 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
0228 int tpm2_probe(struct tpm_chip *chip);
0229 int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip);
0230 int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
0231 int tpm2_init_space(struct tpm_space *space, unsigned int buf_size);
0232 void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
0233 void tpm2_flush_space(struct tpm_chip *chip);
0234 int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
0235                size_t cmdsiz);
0236 int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
0237               size_t *bufsiz);
0238 int tpm_devs_add(struct tpm_chip *chip);
0239 void tpm_devs_remove(struct tpm_chip *chip);
0240 
0241 void tpm_bios_log_setup(struct tpm_chip *chip);
0242 void tpm_bios_log_teardown(struct tpm_chip *chip);
0243 int tpm_dev_common_init(void);
0244 void tpm_dev_common_exit(void);
0245 #endif