1 #ifndef TCGBIOS_H
2 #define TCGBIOS_H
3 
4 /* TCPA ACPI definitions */
5 #define TCPA_ACPI_CLASS_CLIENT          0
6 #define TCPA_ACPI_CLASS_SERVER          1
7 
8 /* Define for section 12.3 */
9 #define TCG_PC_OK                       0x0
10 #define TCG_PC_TPMERROR                 0x1
11 #define TCG_PC_LOGOVERFLOW              0x2
12 #define TCG_PC_UNSUPPORTED              0x3
13 
14 #define TPM_ALG_SHA                     0x4
15 
16 #define TCG_MAGIC                       0x41504354L
17 #define TCG_VERSION_MAJOR               1
18 #define TCG_VERSION_MINOR               2
19 
20 #define TPM_OK                          0x0
21 #define TPM_RET_BASE                    0x1
22 #define TCG_GENERAL_ERROR               (TPM_RET_BASE + 0x0)
23 #define TCG_TPM_IS_LOCKED               (TPM_RET_BASE + 0x1)
24 #define TCG_NO_RESPONSE                 (TPM_RET_BASE + 0x2)
25 #define TCG_INVALID_RESPONSE            (TPM_RET_BASE + 0x3)
26 #define TCG_INVALID_ACCESS_REQUEST      (TPM_RET_BASE + 0x4)
27 #define TCG_FIRMWARE_ERROR              (TPM_RET_BASE + 0x5)
28 #define TCG_INTEGRITY_CHECK_FAILED      (TPM_RET_BASE + 0x6)
29 #define TCG_INVALID_DEVICE_ID           (TPM_RET_BASE + 0x7)
30 #define TCG_INVALID_VENDOR_ID           (TPM_RET_BASE + 0x8)
31 #define TCG_UNABLE_TO_OPEN              (TPM_RET_BASE + 0x9)
32 #define TCG_UNABLE_TO_CLOSE             (TPM_RET_BASE + 0xa)
33 #define TCG_RESPONSE_TIMEOUT            (TPM_RET_BASE + 0xb)
34 #define TCG_INVALID_COM_REQUEST         (TPM_RET_BASE + 0xc)
35 #define TCG_INVALID_ADR_REQUEST         (TPM_RET_BASE + 0xd)
36 #define TCG_WRITE_BYTE_ERROR            (TPM_RET_BASE + 0xe)
37 #define TCG_READ_BYTE_ERROR             (TPM_RET_BASE + 0xf)
38 #define TCG_BLOCK_WRITE_TIMEOUT         (TPM_RET_BASE + 0x10)
39 #define TCG_CHAR_WRITE_TIMEOUT          (TPM_RET_BASE + 0x11)
40 #define TCG_CHAR_READ_TIMEOUT           (TPM_RET_BASE + 0x12)
41 #define TCG_BLOCK_READ_TIMEOUT          (TPM_RET_BASE + 0x13)
42 #define TCG_TRANSFER_ABORT              (TPM_RET_BASE + 0x14)
43 #define TCG_INVALID_DRV_FUNCTION        (TPM_RET_BASE + 0x15)
44 #define TCG_OUTPUT_BUFFER_TOO_SHORT     (TPM_RET_BASE + 0x16)
45 #define TCG_FATAL_COM_ERROR             (TPM_RET_BASE + 0x17)
46 #define TCG_INVALID_INPUT_PARA          (TPM_RET_BASE + 0x18)
47 #define TCG_TCG_COMMAND_ERROR           (TPM_RET_BASE + 0x19)
48 #define TCG_INTERFACE_SHUTDOWN          (TPM_RET_BASE + 0x20)
49 //define TCG_PC_UNSUPPORTED             (TPM_RET_BASE + 0x21)
50 #define TCG_PC_TPM_NOT_PRESENT          (TPM_RET_BASE + 0x22)
51 #define TCG_PC_TPM_DEACTIVATED          (TPM_RET_BASE + 0x23)
52 
53 
54 #define TPM_INVALID_ADR_REQUEST          TCG_INVALID_ADR_REQUEST
55 #define TPM_IS_LOCKED                    TCG_TPM_IS_LOCKED
56 #define TPM_INVALID_DEVICE_ID            TCG_INVALID_DEVICE_ID
57 #define TPM_INVALID_VENDOR_ID            TCG_INVALID_VENDOR_ID
58 //define TPM_RESERVED_REG_INVALID
59 #define TPM_FIRMWARE_ERROR               TCG_FIRMWARE_ERROR
60 #define TPM_UNABLE_TO_OPEN               TCG_UNABLE_TO_OPEN
61 #define TPM_UNABLE_TO_CLOSE              TCG_UNABLE_TO_CLOSE
62 #define TPM_INVALID_RESPONSE             TCG_INVALID_RESPONSE
63 #define TPM_RESPONSE_TIMEOUT             TCG_RESPONSE_TIMEOUT
64 #define TPM_INVALID_ACCESS_REQUEST       TCG_INVALID_ACCESS_REQUEST
65 #define TPM_TRANSFER_ABORT               TCG_TRANSFER_ABORT
66 #define TPM_GENERAL_ERROR                TCG_GENERAL_ERROR
67 
68 #define TPM_ST_CLEAR                      0x0
69 #define TPM_ST_STATE                      0x1
70 #define TPM_ST_DEACTIVATED                0x2
71 
72 /* event types: 10.4.1 / table 11 */
73 #define EV_POST_CODE             1
74 #define EV_SEPARATOR             4
75 #define EV_ACTION                5
76 #define EV_EVENT_TAG             6
77 #define EV_COMPACT_HASH         12
78 #define EV_IPL                  13
79 #define EV_IPL_PARTITION_DATA   14
80 
81 
82 // MA Driver defines
83 #define CODE_MAInitTPM                    0x01
84 #define CODE_MAHashAllExtendTPM           0x02
85 #define CODE_MAPhysicalPresenceTPM        0x03
86 /* vendor specific ones */
87 #define CODE_MAIsTPMPresent               0x80
88 #define CODE_MAHashAll                    0x81
89 #define CODE_MATransmit                   0x82
90 
91 /*
92   indices for commands to be sent via proprietary
93    _TCG_SendCommand function
94  */
95 #define IDX_CMD_TPM_Startup_0x01                0
96 #define IDX_CMD_TSC_PhysicalPresence_0x20       1
97 #define IDX_CMD_TSC_PhysicalPresence_0x08       2
98 #define IDX_CMD_TSC_PhysicalPresence_0x100      3
99 #define IDX_CMD_TSC_PhysicalPresence_0x10       4
100 #define IDX_CMD_TPM_PhysicalEnable              5
101 #define IDX_CMD_TPM_PhysicalSetDeactivated_0x00 6
102 #define IDX_CMD_TPM_SHA1Start                   7
103 
104 
105 /* hardware registers for TPM TIS */
106 #define TPM_ACCESS                 0x0
107 #define TPM_INT_ENABLE             0x8
108 #define TPM_INT_VECTOR             0xc
109 #define TPM_INT_STATUS             0x10
110 #define TPM_INTF_CAPABILITY        0x14
111 #define TPM_STS                    0x18
112 #define TPM_DATA_FIFO              0x24
113 #define TPM_DID_VID                0xf00
114 #define TPM_RID                    0xf04
115 
116 /* address of locality 0 (TIS) */
117 #define TPM_TIS_BASE_ADDRESS        0xfed40000
118 
119 #define STATUS_FLAG_SHUTDOWN                (1 << 0)
120 
121 /* Input and Output blocks for the TCG BIOS commands */
122 
123 struct hleei_short
124 {
125 	uint16_t   ipblength;
126 	uint16_t   reserved;
127 	uint32_t   hashdataptr;
128 	uint32_t   hashdatalen;
129 	uint32_t   pcrindex;
130 	uint32_t   logdataptr;
131 	uint32_t   logdatalen;
132 } __attribute__((packed));
133 
134 struct hleei_long
135 {
136 	uint16_t   ipblength;
137 	uint16_t   reserved;
138 	uint32_t   hashdataptr;
139 	uint32_t   hashdatalen;
140 	uint32_t   pcrindex;
141 	uint32_t   reserved2;
142 	uint32_t   logdataptr;
143 	uint32_t   logdatalen;
144 } __attribute__((packed));
145 
146 struct hleeo
147 {
148 	uint16_t    opblength;
149 	uint16_t    reserved;
150 	uint32_t    eventnumber;
151 	uint8_t     hashvalue[20];
152 } __attribute__((packed));
153 
154 
155 
156 struct pttti
157 {
158 	uint16_t    ipblength;
159 	uint16_t    reserved;
160 	uint16_t    opblength;
161 	uint16_t    reserved2;
162 	uint8_t     tpmoperandin[0];
163 } __attribute__((packed));
164 
165 struct pttto
166 {
167 	uint16_t    opblength;
168 	uint16_t    reserved;
169 	uint8_t     tpmoperandout[0];
170 };
171 
172 
173 struct hlei
174 {
175 	uint16_t    ipblength;
176 	uint16_t    reserved;
177 	uint32_t    hashdataptr;
178 	uint32_t    hashdatalen;
179 	uint32_t    pcrindex;
180 	uint32_t    logeventtype;
181 	uint32_t    logdataptr;
182 	uint32_t    logdatalen;
183 } __attribute__((packed));
184 
185 struct hleo
186 {
187 	uint16_t    opblength;
188 	uint16_t    reserved;
189 	uint32_t    eventnumber;
190 } __attribute__((packed));
191 
192 struct hai
193 {
194 	uint16_t    ipblength;
195 	uint16_t    reserved;
196 	uint32_t    hashdataptr;
197 	uint32_t    hashdatalen;
198 	uint32_t    algorithmid;
199 } __attribute__((packed));
200 
201 struct ti
202 {
203 	uint16_t    ipblength;
204 	uint16_t    reserved;
205         uint16_t    opblength;
206         uint16_t    reserved2;
207         uint8_t     tssoperandin[0];
208 } __attribute__((packed));
209 
210 struct to
211 {
212 	uint16_t    opblength;
213 	uint16_t    reserved;
214 	uint8_t     tssoperandout[0];
215 } __attribute__((packed));
216 
217 
218 struct pcpes
219 {
220 	uint32_t    pcrindex;
221 	uint32_t    eventtype;
222 	uint8_t     digest[20];
223 	uint32_t    eventdatasize;
224 	uint32_t    event;
225 } __attribute__((packed));
226 
227 struct acpi_20_tcpa_client {
228 	uint32_t laml;
229 	uint64_t lasa;
230 } __attribute__((packed));
231 
232 struct acpi_20_tcpa_server {
233 	uint16_t reserved;
234 	uint32_t laml;
235 	uint64_t lasa;
236 	/* more here */
237 } __attribute__((packed));
238 
239 struct acpi_20_tcpa_clisrv {
240 	struct acpi_header header;
241 	uint16_t platform_class;
242 	union {
243 		struct acpi_20_tcpa_client client;
244 		struct acpi_20_tcpa_server server;
245 	} u;
246 } __attribute__((packed));
247 
248 
249 #endif
250