tpm.h 6.7 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-only */
L
Linus Torvalds 已提交
2 3
/*
 * Copyright (C) 2004 IBM Corporation
J
Jarkko Sakkinen 已提交
4
 * Copyright (C) 2015 Intel Corporation
L
Linus Torvalds 已提交
5 6 7 8 9 10 11
 *
 * Authors:
 * Leendert van Doorn <leendert@watson.ibm.com>
 * Dave Safford <safford@watson.ibm.com>
 * Reiner Sailer <sailer@watson.ibm.com>
 * Kylene Hall <kjhall@us.ibm.com>
 *
K
Kent Yoder 已提交
12
 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
L
Linus Torvalds 已提交
13 14
 *
 * Device driver for TCG/TCPA TPM (trusted platform module).
15
 * Specifications at www.trustedcomputinggroup.org
L
Linus Torvalds 已提交
16
 */
17 18 19 20

#ifndef __TPM_H__
#define __TPM_H__

L
Linus Torvalds 已提交
21 22
#include <linux/module.h>
#include <linux/delay.h>
23
#include <linux/mutex.h>
24
#include <linux/sched.h>
25
#include <linux/platform_device.h>
A
Andrew Morton 已提交
26
#include <linux/io.h>
R
Rajiv Andrade 已提交
27
#include <linux/tpm.h>
28
#include <linux/tpm_eventlog.h>
L
Linus Torvalds 已提交
29

30 31 32 33
#ifdef CONFIG_X86
#include <asm/intel-family.h>
#endif

34 35 36 37
#define TPM_MINOR		224	/* officially assigned */
#define TPM_BUFSIZE		4096
#define TPM_NUM_DEVICES		65536
#define TPM_RETRY		50
38

39 40
enum tpm_timeout {
	TPM_TIMEOUT = 5,	/* msecs */
41
	TPM_TIMEOUT_RETRY = 100, /* msecs */
42
	TPM_TIMEOUT_RANGE_US = 300,	/* usecs */
43 44 45
	TPM_TIMEOUT_POLL = 1,	/* msecs */
	TPM_TIMEOUT_USECS_MIN = 100,      /* usecs */
	TPM_TIMEOUT_USECS_MAX = 500      /* usecs */
46
};
L
Linus Torvalds 已提交
47 48

/* TPM addresses */
49
enum tpm_addr {
50
	TPM_SUPERIO_ADDR = 0x2E,
51 52 53
	TPM_ADDR = 0x4E,
};

54
#define TPM_WARN_RETRY          0x800
55
#define TPM_WARN_DOING_SELFTEST 0x802
56 57
#define TPM_ERR_DEACTIVATED     0x6
#define TPM_ERR_DISABLED        0x7
58
#define TPM_ERR_INVALID_POSTINIT 38
59

60
#define TPM_TAG_RQU_COMMAND 193
61

62 63 64
/* TPM2 specific constants. */
#define TPM2_SPACE_BUFFER_SIZE		16384 /* 16 kB */

65 66 67 68 69 70 71
struct	stclear_flags_t {
	__be16	tag;
	u8	deactivated;
	u8	disableForceClear;
	u8	physicalPresence;
	u8	physicalPresenceLock;
	u8	bGlobalLock;
72
} __packed;
73

74 75 76 77 78
struct tpm1_version {
	u8 major;
	u8 minor;
	u8 rev_major;
	u8 rev_minor;
79
} __packed;
80

81 82 83
struct tpm1_version2 {
	__be16 tag;
	struct tpm1_version version;
84
} __packed;
85 86 87 88 89 90

struct	timeout_t {
	__be32	a;
	__be32	b;
	__be32	c;
	__be32	d;
91
} __packed;
92 93 94 95 96

struct duration_t {
	__be32	tpm_short;
	__be32	tpm_medium;
	__be32	tpm_long;
97
} __packed;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

struct permanent_flags_t {
	__be16	tag;
	u8	disable;
	u8	ownership;
	u8	deactivated;
	u8	readPubek;
	u8	disableOwnerClear;
	u8	allowMaintenance;
	u8	physicalPresenceLifetimeLock;
	u8	physicalPresenceHWEnable;
	u8	physicalPresenceCMDEnable;
	u8	CEKPUsed;
	u8	TPMpost;
	u8	TPMpostLock;
	u8	FIPS;
	u8	operator;
	u8	enableRevokeEK;
	u8	nvLocked;
	u8	readSRKPub;
	u8	tpmEstablished;
	u8	maintenanceDone;
	u8	disableFullDALogicInfo;
121
} __packed;
122 123 124 125

typedef union {
	struct	permanent_flags_t perm_flags;
	struct	stclear_flags_t	stclear_flags;
126
	__u8	owned;
127
	__be32	num_pcrs;
128 129
	struct tpm1_version version1;
	struct tpm1_version2 version2;
130 131 132 133 134
	__be32	manufacturer_id;
	struct timeout_t  timeout;
	struct duration_t duration;
} cap_t;

135
enum tpm_capabilities {
136 137 138 139
	TPM_CAP_FLAG = 4,
	TPM_CAP_PROP = 5,
	TPM_CAP_VERSION_1_1 = 0x06,
	TPM_CAP_VERSION_1_2 = 0x1A,
140 141 142
};

enum tpm_sub_capabilities {
143 144 145 146 147 148 149
	TPM_CAP_PROP_PCR = 0x101,
	TPM_CAP_PROP_MANUFACTURER = 0x103,
	TPM_CAP_FLAG_PERM = 0x108,
	TPM_CAP_FLAG_VOL = 0x109,
	TPM_CAP_PROP_OWNER = 0x111,
	TPM_CAP_PROP_TIS_TIMEOUT = 0x115,
	TPM_CAP_PROP_TIS_DURATION = 0x120,
150 151
};

R
Rajiv Andrade 已提交
152

153 154 155 156 157 158
/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
 * bytes, but 128 is still a relatively large number of random bytes and
 * anything much bigger causes users of struct tpm_cmd_t to start getting
 * compiler warnings about stack frame size. */
#define TPM_MAX_RNG_DATA	128

J
Jarkko Sakkinen 已提交
159
extern struct class *tpm_class;
160
extern struct class *tpmrm_class;
J
Jarkko Sakkinen 已提交
161 162
extern dev_t tpm_devt;
extern const struct file_operations tpm_fops;
163
extern const struct file_operations tpmrm_fops;
164
extern struct idr dev_nums_idr;
J
Jarkko Sakkinen 已提交
165

166
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
167
int tpm_get_timeouts(struct tpm_chip *);
168
int tpm_auto_startup(struct tpm_chip *chip);
169

170
int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
171
int tpm1_auto_startup(struct tpm_chip *chip);
172
int tpm1_do_selftest(struct tpm_chip *chip);
T
Tomas Winkler 已提交
173
int tpm1_get_timeouts(struct tpm_chip *chip);
174
unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
175
int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
176
		    const char *log_msg);
177
int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
T
Tomas Winkler 已提交
178 179
ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
		    const char *desc, size_t min_cap_length);
180
int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
181
int tpm1_get_pcr_allocation(struct tpm_chip *chip);
182
unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
183 184
int tpm_pm_suspend(struct device *dev);
int tpm_pm_resume(struct device *dev);
185

186 187
static inline void tpm_msleep(unsigned int delay_msec)
{
188 189
	usleep_range((delay_msec * 1000) - TPM_TIMEOUT_RANGE_US,
		     delay_msec * 1000);
190 191
};

192 193
int tpm_chip_start(struct tpm_chip *chip);
void tpm_chip_stop(struct tpm_chip *chip);
194
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
195

196 197 198 199 200 201
struct tpm_chip *tpm_chip_alloc(struct device *dev,
				const struct tpm_class_ops *ops);
struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
				 const struct tpm_class_ops *ops);
int tpm_chip_register(struct tpm_chip *chip);
void tpm_chip_unregister(struct tpm_chip *chip);
202

203
void tpm_sysfs_add_device(struct tpm_chip *chip);
204

205

206
#ifdef CONFIG_ACPI
207
extern void tpm_add_ppi(struct tpm_chip *chip);
208
#else
209
static inline void tpm_add_ppi(struct tpm_chip *chip)
210 211
{
}
212
#endif
J
Jarkko Sakkinen 已提交
213

T
Tomas Winkler 已提交
214
int tpm2_get_timeouts(struct tpm_chip *chip);
215 216
int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
		  struct tpm_digest *digest, u16 *digest_size_ptr);
217
int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
218
		    struct tpm_digest *digests);
219
int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
J
Jarkko Sakkinen 已提交
220 221 222
ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
			u32 *value, const char *desc);

223
ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
224
int tpm2_auto_startup(struct tpm_chip *chip);
225 226 227
void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
int tpm2_probe(struct tpm_chip *chip);
228
int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip);
J
Jarkko Sakkinen 已提交
229
int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
230
int tpm2_init_space(struct tpm_space *space, unsigned int buf_size);
231
void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
232
void tpm2_flush_space(struct tpm_chip *chip);
233 234 235 236
int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
		       size_t cmdsiz);
int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
		      size_t *bufsiz);
237 238
int tpm_devs_add(struct tpm_chip *chip);
void tpm_devs_remove(struct tpm_chip *chip);
239

240
void tpm_bios_log_setup(struct tpm_chip *chip);
241
void tpm_bios_log_teardown(struct tpm_chip *chip);
242 243
int tpm_dev_common_init(void);
void tpm_dev_common_exit(void);
244
#endif