]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/char/tpm/tpm.h
Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[mirror_ubuntu-jammy-kernel.git] / drivers / char / tpm / tpm.h
CommitLineData
b886d83c 1/* SPDX-License-Identifier: GPL-2.0-only */
1da177e4
LT
2/*
3 * Copyright (C) 2004 IBM Corporation
a74f8b36 4 * Copyright (C) 2015 Intel Corporation
1da177e4
LT
5 *
6 * Authors:
7 * Leendert van Doorn <leendert@watson.ibm.com>
8 * Dave Safford <safford@watson.ibm.com>
9 * Reiner Sailer <sailer@watson.ibm.com>
10 * Kylene Hall <kjhall@us.ibm.com>
11 *
8e81cc13 12 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
1da177e4
LT
13 *
14 * Device driver for TCG/TCPA TPM (trusted platform module).
3b09825d 15 * Specifications at www.trustedcomputinggroup.org
1da177e4 16 */
d2efee6e
CR
17
18#ifndef __TPM_H__
19#define __TPM_H__
20
1da177e4 21#include <linux/module.h>
1da177e4 22#include <linux/delay.h>
d081d470 23#include <linux/mutex.h>
914e2637 24#include <linux/sched.h>
bbc5b212 25#include <linux/platform_device.h>
276ad0c1 26#include <linux/io.h>
659aaf2b 27#include <linux/tpm.h>
fd3ec366 28#include <linux/tpm_eventlog.h>
1da177e4 29
5e572cab
AS
30#ifdef CONFIG_X86
31#include <asm/intel-family.h>
32#endif
33
901615cb
RS
34#define TPM_MINOR 224 /* officially assigned */
35#define TPM_BUFSIZE 4096
36#define TPM_NUM_DEVICES 65536
37#define TPM_RETRY 50
41ab999c 38
3122a88a
KH
39enum tpm_timeout {
40 TPM_TIMEOUT = 5, /* msecs */
9f3fc7bc 41 TPM_TIMEOUT_RETRY = 100, /* msecs */
59f5a6b0 42 TPM_TIMEOUT_RANGE_US = 300, /* usecs */
424eaf91
NJ
43 TPM_TIMEOUT_POLL = 1, /* msecs */
44 TPM_TIMEOUT_USECS_MIN = 100, /* usecs */
45 TPM_TIMEOUT_USECS_MAX = 500 /* usecs */
3122a88a 46};
1da177e4
LT
47
48/* TPM addresses */
3122a88a 49enum tpm_addr {
daacdfa6 50 TPM_SUPERIO_ADDR = 0x2E,
3122a88a 51 TPM_ADDR = 0x4E,
3122a88a
KH
52};
53
32d33b29 54#define TPM_WARN_RETRY 0x800
68d6e671 55#define TPM_WARN_DOING_SELFTEST 0x802
be405411
SB
56#define TPM_ERR_DEACTIVATED 0x6
57#define TPM_ERR_DISABLED 0x7
c584af19 58#define TPM_ERR_INVALID_POSTINIT 38
be405411 59
06e93279 60#define TPM_TAG_RQU_COMMAND 193
000a07b0 61
08837438
RA
62struct stclear_flags_t {
63 __be16 tag;
64 u8 deactivated;
65 u8 disableForceClear;
66 u8 physicalPresence;
67 u8 physicalPresenceLock;
68 u8 bGlobalLock;
348df8db 69} __packed;
08837438 70
f2f5820e
JS
71struct tpm1_version {
72 u8 major;
73 u8 minor;
74 u8 rev_major;
75 u8 rev_minor;
348df8db 76} __packed;
08837438 77
f2f5820e
JS
78struct tpm1_version2 {
79 __be16 tag;
80 struct tpm1_version version;
348df8db 81} __packed;
08837438
RA
82
83struct timeout_t {
84 __be32 a;
85 __be32 b;
86 __be32 c;
87 __be32 d;
348df8db 88} __packed;
08837438
RA
89
90struct duration_t {
91 __be32 tpm_short;
92 __be32 tpm_medium;
93 __be32 tpm_long;
348df8db 94} __packed;
08837438
RA
95
96struct permanent_flags_t {
97 __be16 tag;
98 u8 disable;
99 u8 ownership;
100 u8 deactivated;
101 u8 readPubek;
102 u8 disableOwnerClear;
103 u8 allowMaintenance;
104 u8 physicalPresenceLifetimeLock;
105 u8 physicalPresenceHWEnable;
106 u8 physicalPresenceCMDEnable;
107 u8 CEKPUsed;
108 u8 TPMpost;
109 u8 TPMpostLock;
110 u8 FIPS;
111 u8 operator;
112 u8 enableRevokeEK;
113 u8 nvLocked;
114 u8 readSRKPub;
115 u8 tpmEstablished;
116 u8 maintenanceDone;
117 u8 disableFullDALogicInfo;
348df8db 118} __packed;
08837438
RA
119
120typedef union {
121 struct permanent_flags_t perm_flags;
122 struct stclear_flags_t stclear_flags;
a118cf2a 123 __u8 owned;
08837438 124 __be32 num_pcrs;
f2f5820e
JS
125 struct tpm1_version version1;
126 struct tpm1_version2 version2;
08837438
RA
127 __be32 manufacturer_id;
128 struct timeout_t timeout;
129 struct duration_t duration;
130} cap_t;
131
000a07b0 132enum tpm_capabilities {
84fda152
JS
133 TPM_CAP_FLAG = 4,
134 TPM_CAP_PROP = 5,
135 TPM_CAP_VERSION_1_1 = 0x06,
136 TPM_CAP_VERSION_1_2 = 0x1A,
000a07b0
JG
137};
138
139enum tpm_sub_capabilities {
84fda152
JS
140 TPM_CAP_PROP_PCR = 0x101,
141 TPM_CAP_PROP_MANUFACTURER = 0x103,
142 TPM_CAP_FLAG_PERM = 0x108,
143 TPM_CAP_FLAG_VOL = 0x109,
144 TPM_CAP_PROP_OWNER = 0x111,
145 TPM_CAP_PROP_TIS_TIMEOUT = 0x115,
146 TPM_CAP_PROP_TIS_DURATION = 0x120,
000a07b0
JG
147};
148
659aaf2b 149
41ab999c
KY
150/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
151 * bytes, but 128 is still a relatively large number of random bytes and
152 * anything much bigger causes users of struct tpm_cmd_t to start getting
153 * compiler warnings about stack frame size. */
154#define TPM_MAX_RNG_DATA 128
155
313d21ee 156extern struct class *tpm_class;
fdc915f7 157extern struct class *tpmrm_class;
313d21ee
JS
158extern dev_t tpm_devt;
159extern const struct file_operations tpm_fops;
fdc915f7 160extern const struct file_operations tpmrm_fops;
15516788 161extern struct idr dev_nums_idr;
313d21ee 162
47a6c28b 163ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
5faafbab 164ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
47a6c28b 165 size_t min_rsp_body_length, const char *desc);
d4abd956 166int tpm_get_timeouts(struct tpm_chip *);
b03c4370 167int tpm_auto_startup(struct tpm_chip *chip);
c82a330c 168
95adc6b4 169int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
cae8b441 170int tpm1_auto_startup(struct tpm_chip *chip);
d4a31756 171int tpm1_do_selftest(struct tpm_chip *chip);
70a3199a 172int tpm1_get_timeouts(struct tpm_chip *chip);
b2d6e6de 173unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
95adc6b4 174int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
1ad6640c 175 const char *log_msg);
95adc6b4 176int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
f4d916b7
TW
177ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
178 const char *desc, size_t min_cap_length);
433d390f 179int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
fa4f99c0 180int tpm1_get_pcr_allocation(struct tpm_chip *chip);
d856c00f 181unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
d4abd956
JS
182int tpm_pm_suspend(struct device *dev);
183int tpm_pm_resume(struct device *dev);
f84fdff0 184
9f3fc7bc
HA
185static inline void tpm_msleep(unsigned int delay_msec)
186{
5ef924d9
NJ
187 usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
188 delay_msec * 1000);
9f3fc7bc
HA
189};
190
47a6c28b
JS
191int tpm_chip_start(struct tpm_chip *chip);
192void tpm_chip_stop(struct tpm_chip *chip);
fc1d52b7 193struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
4e26195f
JG
194__must_check int tpm_try_get_ops(struct tpm_chip *chip);
195void tpm_put_ops(struct tpm_chip *chip);
196
d4abd956
JS
197struct tpm_chip *tpm_chip_alloc(struct device *dev,
198 const struct tpm_class_ops *ops);
199struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
200 const struct tpm_class_ops *ops);
201int tpm_chip_register(struct tpm_chip *chip);
202void tpm_chip_unregister(struct tpm_chip *chip);
afb5abc2 203
062807f2 204void tpm_sysfs_add_device(struct tpm_chip *chip);
afdba32e 205
000a07b0 206
f84fdff0 207#ifdef CONFIG_ACPI
9b774d5c 208extern void tpm_add_ppi(struct tpm_chip *chip);
f84fdff0 209#else
9b774d5c 210static inline void tpm_add_ppi(struct tpm_chip *chip)
1631cfb7
GW
211{
212}
f84fdff0 213#endif
7a1d7e6d 214
70a3199a 215int tpm2_get_timeouts(struct tpm_chip *chip);
879b5892
RS
216int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
217 struct tpm_digest *digest, u16 *digest_size_ptr);
0b6cf6b9 218int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
aa042475 219 struct tpm_digest *digests);
ce63c05b 220int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
47a6c28b 221void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
7a1d7e6d
JS
222ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
223 u32 *value, const char *desc);
224
fa4f99c0 225ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
cae8b441 226int tpm2_auto_startup(struct tpm_chip *chip);
d4abd956
JS
227void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
228unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
d4abd956 229int tpm2_probe(struct tpm_chip *chip);
58472f5c 230int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
745b361e 231int tpm2_init_space(struct tpm_space *space);
4d57856a 232void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
304ff672 233void tpm2_flush_space(struct tpm_chip *chip);
c3465a37
JS
234int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
235 size_t cmdsiz);
236int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
237 size_t *bufsiz);
fd3ec366 238
fd3ec366
TW
239int tpm_bios_log_setup(struct tpm_chip *chip);
240void tpm_bios_log_teardown(struct tpm_chip *chip);
9e1b74a6
TS
241int tpm_dev_common_init(void);
242void tpm_dev_common_exit(void);
d2efee6e 243#endif