]> git.proxmox.com Git - qemu.git/blob - tpm/tpm_int.h
Add a TPM Passthrough backend driver implementation
[qemu.git] / tpm / tpm_int.h
1 /*
2 * TPM configuration
3 *
4 * Copyright (C) 2011-2013 IBM Corporation
5 *
6 * Authors:
7 * Stefan Berger <stefanb@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12 #ifndef TPM_TPM_INT_H
13 #define TPM_TPM_INT_H
14
15 #include "exec/memory.h"
16 #include "tpm/tpm_tis.h"
17
18 struct TPMDriverOps;
19 typedef struct TPMDriverOps TPMDriverOps;
20
21 typedef struct TPMPassthruState TPMPassthruState;
22
23 typedef struct TPMBackend {
24 char *id;
25 enum TpmModel fe_model;
26 char *path;
27 char *cancel_path;
28 const TPMDriverOps *ops;
29
30 union {
31 TPMPassthruState *tpm_pt;
32 } s;
33
34 QLIST_ENTRY(TPMBackend) list;
35 } TPMBackend;
36
37 /* overall state of the TPM interface */
38 typedef struct TPMState {
39 ISADevice busdev;
40 MemoryRegion mmio;
41
42 union {
43 TPMTISEmuState tis;
44 } s;
45
46 uint8_t locty_number;
47 TPMLocality *locty_data;
48
49 char *backend;
50 TPMBackend *be_driver;
51 } TPMState;
52
53 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
54
55 typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty);
56
57 struct TPMDriverOps {
58 enum TpmType type;
59 /* get a descriptive text of the backend to display to the user */
60 const char *(*desc)(void);
61
62 TPMBackend *(*create)(QemuOpts *opts, const char *id);
63 void (*destroy)(TPMBackend *t);
64
65 /* initialize the backend */
66 int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
67 /* start up the TPM on the backend */
68 int (*startup_tpm)(TPMBackend *t);
69 /* returns true if nothing will ever answer TPM requests */
70 bool (*had_startup_error)(TPMBackend *t);
71
72 size_t (*realloc_buffer)(TPMSizedBuffer *sb);
73
74 void (*deliver_request)(TPMBackend *t);
75
76 void (*reset)(TPMBackend *t);
77
78 void (*cancel_cmd)(TPMBackend *t);
79
80 bool (*get_tpm_established_flag)(TPMBackend *t);
81 };
82
83 struct tpm_req_hdr {
84 uint16_t tag;
85 uint32_t len;
86 uint32_t ordinal;
87 } QEMU_PACKED;
88
89 struct tpm_resp_hdr {
90 uint16_t tag;
91 uint32_t len;
92 uint32_t errcode;
93 } QEMU_PACKED;
94
95 #define TPM_TAG_RQU_COMMAND 0xc1
96 #define TPM_TAG_RQU_AUTH1_COMMAND 0xc2
97 #define TPM_TAG_RQU_AUTH2_COMMAND 0xc3
98
99 #define TPM_TAG_RSP_COMMAND 0xc4
100 #define TPM_TAG_RSP_AUTH1_COMMAND 0xc5
101 #define TPM_TAG_RSP_AUTH2_COMMAND 0xc6
102
103 #define TPM_FAIL 9
104
105 #define TPM_ORD_GetTicks 0xf1
106
107 TPMBackend *qemu_find_tpm(const char *id);
108 int tpm_register_model(enum TpmModel model);
109 int tpm_register_driver(const TPMDriverOps *tdo);
110 void tpm_display_backend_drivers(void);
111 const TPMDriverOps *tpm_get_backend_driver(const char *type);
112 void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len);
113
114 extern const TPMDriverOps tpm_passthrough_driver;
115
116 #endif /* TPM_TPM_INT_H */