|
25 | 25 | #include <linux/platform_device.h>
|
26 | 26 | #include <linux/io.h>
|
27 | 27 | #include <linux/tpm.h>
|
28 |
| -#include <linux/highmem.h> |
29 | 28 | #include <linux/tpm_eventlog.h>
|
30 | 29 |
|
31 | 30 | #ifdef CONFIG_X86
|
@@ -58,124 +57,6 @@ enum tpm_addr {
|
58 | 57 | #define TPM_ERR_DISABLED 0x7
|
59 | 58 | #define TPM_ERR_INVALID_POSTINIT 38
|
60 | 59 |
|
61 |
| -#define TPM_HEADER_SIZE 10 |
62 |
| - |
63 |
| -enum tpm2_const { |
64 |
| - TPM2_PLATFORM_PCR = 24, |
65 |
| - TPM2_PCR_SELECT_MIN = ((TPM2_PLATFORM_PCR + 7) / 8), |
66 |
| -}; |
67 |
| - |
68 |
| -enum tpm2_timeouts { |
69 |
| - TPM2_TIMEOUT_A = 750, |
70 |
| - TPM2_TIMEOUT_B = 2000, |
71 |
| - TPM2_TIMEOUT_C = 200, |
72 |
| - TPM2_TIMEOUT_D = 30, |
73 |
| - TPM2_DURATION_SHORT = 20, |
74 |
| - TPM2_DURATION_MEDIUM = 750, |
75 |
| - TPM2_DURATION_LONG = 2000, |
76 |
| - TPM2_DURATION_LONG_LONG = 300000, |
77 |
| - TPM2_DURATION_DEFAULT = 120000, |
78 |
| -}; |
79 |
| - |
80 |
| -enum tpm2_structures { |
81 |
| - TPM2_ST_NO_SESSIONS = 0x8001, |
82 |
| - TPM2_ST_SESSIONS = 0x8002, |
83 |
| -}; |
84 |
| - |
85 |
| -/* Indicates from what layer of the software stack the error comes from */ |
86 |
| -#define TSS2_RC_LAYER_SHIFT 16 |
87 |
| -#define TSS2_RESMGR_TPM_RC_LAYER (11 << TSS2_RC_LAYER_SHIFT) |
88 |
| - |
89 |
| -enum tpm2_return_codes { |
90 |
| - TPM2_RC_SUCCESS = 0x0000, |
91 |
| - TPM2_RC_HASH = 0x0083, /* RC_FMT1 */ |
92 |
| - TPM2_RC_HANDLE = 0x008B, |
93 |
| - TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */ |
94 |
| - TPM2_RC_FAILURE = 0x0101, |
95 |
| - TPM2_RC_DISABLED = 0x0120, |
96 |
| - TPM2_RC_COMMAND_CODE = 0x0143, |
97 |
| - TPM2_RC_TESTING = 0x090A, /* RC_WARN */ |
98 |
| - TPM2_RC_REFERENCE_H0 = 0x0910, |
99 |
| - TPM2_RC_RETRY = 0x0922, |
100 |
| -}; |
101 |
| - |
102 |
| -enum tpm2_command_codes { |
103 |
| - TPM2_CC_FIRST = 0x011F, |
104 |
| - TPM2_CC_HIERARCHY_CONTROL = 0x0121, |
105 |
| - TPM2_CC_HIERARCHY_CHANGE_AUTH = 0x0129, |
106 |
| - TPM2_CC_CREATE_PRIMARY = 0x0131, |
107 |
| - TPM2_CC_SEQUENCE_COMPLETE = 0x013E, |
108 |
| - TPM2_CC_SELF_TEST = 0x0143, |
109 |
| - TPM2_CC_STARTUP = 0x0144, |
110 |
| - TPM2_CC_SHUTDOWN = 0x0145, |
111 |
| - TPM2_CC_NV_READ = 0x014E, |
112 |
| - TPM2_CC_CREATE = 0x0153, |
113 |
| - TPM2_CC_LOAD = 0x0157, |
114 |
| - TPM2_CC_SEQUENCE_UPDATE = 0x015C, |
115 |
| - TPM2_CC_UNSEAL = 0x015E, |
116 |
| - TPM2_CC_CONTEXT_LOAD = 0x0161, |
117 |
| - TPM2_CC_CONTEXT_SAVE = 0x0162, |
118 |
| - TPM2_CC_FLUSH_CONTEXT = 0x0165, |
119 |
| - TPM2_CC_VERIFY_SIGNATURE = 0x0177, |
120 |
| - TPM2_CC_GET_CAPABILITY = 0x017A, |
121 |
| - TPM2_CC_GET_RANDOM = 0x017B, |
122 |
| - TPM2_CC_PCR_READ = 0x017E, |
123 |
| - TPM2_CC_PCR_EXTEND = 0x0182, |
124 |
| - TPM2_CC_EVENT_SEQUENCE_COMPLETE = 0x0185, |
125 |
| - TPM2_CC_HASH_SEQUENCE_START = 0x0186, |
126 |
| - TPM2_CC_CREATE_LOADED = 0x0191, |
127 |
| - TPM2_CC_LAST = 0x0193, /* Spec 1.36 */ |
128 |
| -}; |
129 |
| - |
130 |
| -enum tpm2_permanent_handles { |
131 |
| - TPM2_RS_PW = 0x40000009, |
132 |
| -}; |
133 |
| - |
134 |
| -enum tpm2_capabilities { |
135 |
| - TPM2_CAP_HANDLES = 1, |
136 |
| - TPM2_CAP_COMMANDS = 2, |
137 |
| - TPM2_CAP_PCRS = 5, |
138 |
| - TPM2_CAP_TPM_PROPERTIES = 6, |
139 |
| -}; |
140 |
| - |
141 |
| -enum tpm2_properties { |
142 |
| - TPM_PT_TOTAL_COMMANDS = 0x0129, |
143 |
| -}; |
144 |
| - |
145 |
| -enum tpm2_startup_types { |
146 |
| - TPM2_SU_CLEAR = 0x0000, |
147 |
| - TPM2_SU_STATE = 0x0001, |
148 |
| -}; |
149 |
| - |
150 |
| -enum tpm2_cc_attrs { |
151 |
| - TPM2_CC_ATTR_CHANDLES = 25, |
152 |
| - TPM2_CC_ATTR_RHANDLE = 28, |
153 |
| -}; |
154 |
| - |
155 |
| -#define TPM_VID_INTEL 0x8086 |
156 |
| -#define TPM_VID_WINBOND 0x1050 |
157 |
| -#define TPM_VID_STM 0x104A |
158 |
| - |
159 |
| -enum tpm_chip_flags { |
160 |
| - TPM_CHIP_FLAG_TPM2 = BIT(1), |
161 |
| - TPM_CHIP_FLAG_IRQ = BIT(2), |
162 |
| - TPM_CHIP_FLAG_VIRTUAL = BIT(3), |
163 |
| - TPM_CHIP_FLAG_HAVE_TIMEOUTS = BIT(4), |
164 |
| - TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5), |
165 |
| - TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED = BIT(6), |
166 |
| -}; |
167 |
| - |
168 |
| -#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) |
169 |
| - |
170 |
| -struct tpm_header { |
171 |
| - __be16 tag; |
172 |
| - __be32 length; |
173 |
| - union { |
174 |
| - __be32 ordinal; |
175 |
| - __be32 return_code; |
176 |
| - }; |
177 |
| -} __packed; |
178 |
| - |
179 | 60 | #define TPM_TAG_RQU_COMMAND 193
|
180 | 61 |
|
181 | 62 | struct stclear_flags_t {
|
@@ -272,99 +153,6 @@ enum tpm_sub_capabilities {
|
272 | 153 | * compiler warnings about stack frame size. */
|
273 | 154 | #define TPM_MAX_RNG_DATA 128
|
274 | 155 |
|
275 |
| -/* A string buffer type for constructing TPM commands. This is based on the |
276 |
| - * ideas of string buffer code in security/keys/trusted.h but is heap based |
277 |
| - * in order to keep the stack usage minimal. |
278 |
| - */ |
279 |
| - |
280 |
| -enum tpm_buf_flags { |
281 |
| - TPM_BUF_OVERFLOW = BIT(0), |
282 |
| -}; |
283 |
| - |
284 |
| -struct tpm_buf { |
285 |
| - unsigned int flags; |
286 |
| - u8 *data; |
287 |
| -}; |
288 |
| - |
289 |
| -static inline void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal) |
290 |
| -{ |
291 |
| - struct tpm_header *head = (struct tpm_header *)buf->data; |
292 |
| - |
293 |
| - head->tag = cpu_to_be16(tag); |
294 |
| - head->length = cpu_to_be32(sizeof(*head)); |
295 |
| - head->ordinal = cpu_to_be32(ordinal); |
296 |
| -} |
297 |
| - |
298 |
| -static inline int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal) |
299 |
| -{ |
300 |
| - buf->data = (u8 *)__get_free_page(GFP_KERNEL); |
301 |
| - if (!buf->data) |
302 |
| - return -ENOMEM; |
303 |
| - |
304 |
| - buf->flags = 0; |
305 |
| - tpm_buf_reset(buf, tag, ordinal); |
306 |
| - return 0; |
307 |
| -} |
308 |
| - |
309 |
| -static inline void tpm_buf_destroy(struct tpm_buf *buf) |
310 |
| -{ |
311 |
| - free_page((unsigned long)buf->data); |
312 |
| -} |
313 |
| - |
314 |
| -static inline u32 tpm_buf_length(struct tpm_buf *buf) |
315 |
| -{ |
316 |
| - struct tpm_header *head = (struct tpm_header *)buf->data; |
317 |
| - |
318 |
| - return be32_to_cpu(head->length); |
319 |
| -} |
320 |
| - |
321 |
| -static inline u16 tpm_buf_tag(struct tpm_buf *buf) |
322 |
| -{ |
323 |
| - struct tpm_header *head = (struct tpm_header *)buf->data; |
324 |
| - |
325 |
| - return be16_to_cpu(head->tag); |
326 |
| -} |
327 |
| - |
328 |
| -static inline void tpm_buf_append(struct tpm_buf *buf, |
329 |
| - const unsigned char *new_data, |
330 |
| - unsigned int new_len) |
331 |
| -{ |
332 |
| - struct tpm_header *head = (struct tpm_header *)buf->data; |
333 |
| - u32 len = tpm_buf_length(buf); |
334 |
| - |
335 |
| - /* Return silently if overflow has already happened. */ |
336 |
| - if (buf->flags & TPM_BUF_OVERFLOW) |
337 |
| - return; |
338 |
| - |
339 |
| - if ((len + new_len) > PAGE_SIZE) { |
340 |
| - WARN(1, "tpm_buf: overflow\n"); |
341 |
| - buf->flags |= TPM_BUF_OVERFLOW; |
342 |
| - return; |
343 |
| - } |
344 |
| - |
345 |
| - memcpy(&buf->data[len], new_data, new_len); |
346 |
| - head->length = cpu_to_be32(len + new_len); |
347 |
| -} |
348 |
| - |
349 |
| -static inline void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value) |
350 |
| -{ |
351 |
| - tpm_buf_append(buf, &value, 1); |
352 |
| -} |
353 |
| - |
354 |
| -static inline void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value) |
355 |
| -{ |
356 |
| - __be16 value2 = cpu_to_be16(value); |
357 |
| - |
358 |
| - tpm_buf_append(buf, (u8 *) &value2, 2); |
359 |
| -} |
360 |
| - |
361 |
| -static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value) |
362 |
| -{ |
363 |
| - __be32 value2 = cpu_to_be32(value); |
364 |
| - |
365 |
| - tpm_buf_append(buf, (u8 *) &value2, 4); |
366 |
| -} |
367 |
| - |
368 | 156 | extern struct class *tpm_class;
|
369 | 157 | extern struct class *tpmrm_class;
|
370 | 158 | extern dev_t tpm_devt;
|
|
0 commit comments