summaryrefslogtreecommitdiffstats
path: root/src/usr/i2c/tpmdd.H
blob: be184e9211d03b6ea5db3858f4e501e997eb160d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/i2c/tpmdd.H $                                         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __TPMDD_H
#define __TPMDD_H

/**
 * @file tpmdd.H
 *
 * @brief Provides the interfaces for accessing TPMs within
 *      the system via the I2C device driver.
 */

// ----------------------------------------------
// Includes
// ----------------------------------------------
#include <i2c/tpmddif.H>
#include <errl/errlentry.H>

namespace TPMDD
{


/// TPM Timeouts listed in ms
/// Timeout names and durations are as described in the TCG specification
enum tpm_timeouts
{
    TPM_TIMEOUT_A = 750, ///< 750ms
    TPM_TIMEOUT_B = 2000, ///< 2000ms
    TPM_TIMEOUT_C = 750, ///< 750ms
    TPM_TIMEOUT_D = 750, ///< 750ms
};

/// TPM Driver values
enum
{
    MAX_STSVALID_POLLS = 5, ///< Max poll of 50ms (5*10ms)
};




#ifdef CONFIG_TPM_NUVOTON
/**
 * @brief Nuvoton 2.0 TPM definitions
 */
enum nuvo_20_defs_t
{
    I2C_REG_STS        = 0x0,
    I2C_REG_BURSTCOUNT = 0x1,
    I2C_REG_BURSTCOUNT_HIGH = 0x2,
    I2C_REG_FAMILYID   = 0x3,
    I2C_REG_TPM_HASH   = 0x4,
    I2C_REG_WR_FIFO    = 0x20,
    I2C_REG_RD_FIFO    = 0x40,
    I2C_REG_VENDOR     = 0x60,

    TPM_VENDORID       = 0x5010FE00,
    TPM_VENDORID_MASK  = 0xFFFFFF00,
    TPM_MAXBURSTSIZE   = 0xFFFF,
    TPM_FAMILYID       = 0x04,
    TPM_FAMILYID_MASK  = 0x0C,
    TPM_HASH_START     = 0x01,
    TPM_HASH_END       = 0x02,
};


#endif


/**
* @brief TPM STS register definition (PTP 2.0 Spec)
*/
union tpm_sts_reg_t
{
    uint8_t value;
    struct
    {
        uint8_t stsValid       : 1; // 00 // RO
        uint8_t isCommandReady : 1; // 01 // RW
        uint8_t tpmGo          : 1; // 02 // WO
        uint8_t dataAvail      : 1; // 03 // RO
        uint8_t expect         : 1; // 04 // RO
        uint8_t selfTestDone   : 1; // 05 // RO
        uint8_t responseRetry  : 1; // 06 // WO
        uint8_t rsvd2          : 1; // 07 // RO
    } PACKED;
};

/**
*
* @brief Perform a TPM access operation.
*
* @param[in] i_opType Operation Type - See DeviceFW::OperationType in
*       driververif.H
*
* @param[in] i_target target node.
*
* @param[in/out] io_buffer
*       INPUT: Pointer to the data that will be  written to the target
*           device.
*       OUTPUT: Pointer to the data that was read from the target device.
*
* @param[in/out] io_buflen
*       INPUT: Length of the buffer to be written to target device.
*       OUTPUT: Length of buffer that was written, or length of buffer
*           to be read from target device.
*
* @param [in] i_accessType Access Type - See DeviceFW::AccessType in
*       usrif.H
*
* @param [in] i_args This is an argument list for the device driver
*       framework.  This argument list consists of the chip number of
*       the TPM to access from the given I2C Master target and the
*       internal offset to use on the slave I2C device.
*
* @return errlHndl_t NULL if successful, otherwise a pointer to the
*       error log.
*
*/
errlHndl_t tpmPerformOp( DeviceFW::OperationType i_opType,
                         TARGETING::Target * i_target,
                         void * io_buffer,
                         size_t & io_buflen,
                         int64_t i_accessType,
                         va_list i_args );

/**
 * @brief This function peforms the sequencing to do a read of the
 *      TPM that is identified.
 *
 * @param[out] o_buffer The buffer that will return the data read
 *      from the TPM device.
 *
 * @param[in] i_buflen Number of bytes to read from the TPM device.
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] i_silent Don't log any error logs on failure
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmRead ( void * o_buffer,
                     size_t i_buflen,
                     const tpm_info_t & i_tpmInfo,
                     bool i_silent = false);

/**
 * @brief This function peforms the sequencing to do a write of the
 *      TPM that is identified.
 *
 * @param[out] i_buffer The buffer containing data to write
 *      to the TPM device.
 *
 * @param[in] i_buflen Number of bytes to write to the TPM device.
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWrite ( void * i_buffer,
                      size_t i_buflen,
                      const tpm_info_t & i_tpmInfo );

/**
 * @brief This function peforms the sequencing to do a transmit of the
 *      TPM that is identified.
 *
 * @param[in/out] io_buffer Data buffer
 *       INPUT: Command to be written to the TPM
 *       OUTPUT: Response from the TPM
 *
 * @param[in/out] io_buflen Buffer Length
 *       INPUT: Full length of io_buffer allocated.
 *       OUTPUT: Length of the response read from TPM.
 *
 * @param[in] i_commandlen Length of command to send in bytes
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmTransmit ( void * io_buffer,
                         size_t & io_buflen,
                         size_t i_commandlen,
                         const tpm_info_t & i_tpmInfo );

#ifdef CONFIG_DRTM
/**
 * @brief This function peforms the sequencing to do a reset of the
 *      dynamic PCRs 17-22
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t nullptr if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmDrtmReset (tpm_info_t i_tpmInfo);
#endif

/**
 * @brief This function prepares the I2C byte address for adding to the
 *      existing buffer (for Writes), or as a separate write operation
 *      (for Reads).
 *
 * @param[in/out] io_buffer The buffer to be written as a byte address to
 *      the TPM device.  Must be pre-allocated to MAX_BYTE_ADDR size.
 *
 * @param[out] o_bufSize The size of the buffer to be written.
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmPrepareAddress ( void * io_buffer,
                               size_t & o_bufSize,
                               const tpm_info_t & i_tpmInfo );

/**
 * @brief This function decides whether or not the target passed into the
 *      TPM device driver actually contains the I2C Master engines.  If
 *      not, it will then read the attribute of the target to get the path
 *      of the target which does contain the I2C Master engine.
 *
 * @param[in] i_target The current Target.
 *
 * @param[in/out] io_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 * *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmGetI2CMasterTarget ( TARGETING::Target * i_target,
                                   tpm_info_t & io_tpmInfo );



/**
 * @brief Write a Tpm Register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] i_offset TPM Register Offset
 *
 * @param[in] i_buflen Length of write
 *
 * @param[in] i_buffer Value to write into register
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWriteReg ( tpm_info_t i_tpmInfo,
                         size_t i_offset,
                         size_t i_buflen,
                         void * i_buffer);

/**
 * @brief Read a Tpm Register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] i_offset TPM Register Offset
 *
 * @param[in] i_buflen Length of read
 *
 * @param[in] o_buffer Value read from the register
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmReadReg ( tpm_info_t i_tpmInfo,
                        size_t i_offset,
                        size_t i_buflen,
                        void * o_buffer);

/**
 * @brief Read the Tpm STS Register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] o_stsReg Value read from the register
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmReadSTSReg ( tpm_info_t i_tpmInfo,
                           tpm_sts_reg_t & o_stsReg);

/**
 * @brief Read the Tpm STS Register polling for stsValid
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] o_stsReg Value read from the register
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmReadSTSRegValid ( tpm_info_t i_tpmInfo,
                                tpm_sts_reg_t & o_stsReg);

/**
 * @brief Check for command ready in STS reg
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[out] o_isReady True if TPM in command ready state.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmIsCommandReady( const tpm_info_t & i_tpmInfo,
                              bool & o_isReady);

/**
 * @brief Poll the Tpm waiting for it to enter command ready state
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmPollForCommandReady( const tpm_info_t & i_tpmInfo);

/**
 * @brief Check for expecting state in TPM STS Register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[out] o_isExpecting True if TPM is expecting data
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmIsExpecting( const tpm_info_t & i_tpmInfo,
                           bool & o_isExpecting);

/**
 * @brief Check for data available state in Tpm STS register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[out] o_isDataAvail True if TPM data is available
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmIsDataAvail( const tpm_info_t & i_tpmInfo,
                           bool & o_isDataAvail);

/**
 * @brief Poll the Tpm waiting for data available state
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmPollForDataAvail( const tpm_info_t & i_tpmInfo);

/**
 * @brief Read the current burst count value
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[out] o_burstCount Current TPM burst count
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmReadBurstCount( const tpm_info_t & i_tpmInfo,
                              uint16_t & o_burstCount);

/**
 * @brief Write the command ready bit in the Tpm STS register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWriteCommandReady( const tpm_info_t & i_tpmInfo);

/**
 * @brief Write the TpmGo bit in the STS register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWriteTpmGo( const tpm_info_t & i_tpmInfo);

/**
 * @brief Write the response retry bit in the Tpm STS register
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWriteResponseRetry( const tpm_info_t & i_tpmInfo);


/**
 * @brief Write the buffer into the TPM's input FIFO
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] i_buffer Input buffer to write to TPM
 *
 * @param[in] i_buflen Byte length of data to write
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmWriteFifo( const tpm_info_t & i_tpmInfo,
                         void * i_buffer,
                         size_t i_buflen);

/**
 * @brief Read from the TPM FIFO into the buffer
 *
 * @param[in] i_tpmInfo Structure of I2C parameters needed to execute
 *      the command to the I2C device driver.
 *
 * @param[in] o_buffer Output buffer
 *
 * @param[in] io_buflen Byte length of buffer
 *       INPUT: Full length of io_buffer allocated.
 *       OUTPUT: Length of the response read from TPM.
 *
 * @return errlHndl_t NULL if successful, otherwise a pointer to the
 *      error log.
 */
errlHndl_t tpmReadFifo( const tpm_info_t & i_tpmInfo,
                        void * o_buffer,
                        size_t & io_buflen);
/**
 * @brief Performs a presence detect operation on a TPM Chip.
 *  This is used for the discoverTargets path and called TPMDD::tpmPresence
 *
 * @param[in]   i_opType        Operation type, see DeviceFW::OperationType
 *                              in driverif.H
 * @param[in]   i_target        Presence detect target
 * @param[in/out] io_buffer     Read: Pointer to output data storage
 *                              Write: Pointer to input data storage
 * @param[in/out] io_buflen     Input: size of io_buffer (in bytes, always 1)
 *                              Output: Success = 1, Failure = 0
 * @param[in]   i_accessType    DeviceFW::AccessType enum (userif.H)
 * @param[in]   i_args          This is an argument list for DD framework.
 *                              In this function, there are no arguments.
 * @return  errlHndl_t
 */
errlHndl_t tpmPresenceDetect(DeviceFW::OperationType i_opType,
                             TARGETING::Target* i_target,
                             void* io_buffer,
                             size_t& io_buflen,
                             int64_t i_accessType,
                             va_list i_args);

}; // end TPMDD namespace

#endif  // __TPMDD_H
OpenPOWER on IntegriCloud