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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
|
/*++
Copyright (c) 2005 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
TpmDxe.h
Abstract:
DXE driver for TPM devices
--*/
//*************************************************************************
// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TpmDxe.c 2 4/21/14 3:17p Fredericko $
//
// $Revision: 2 $
//
// $Date: 4/21/14 3:17p $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TpmDxe.c $
//
// 2 4/21/14 3:17p Fredericko
//
// 1 4/21/14 2:16p Fredericko
//
// 2 3/11/14 6:35p Fredericko
// [TAG] EIP151925
// [Category] New Feature
// [Description] Changes for TcgGeneric Regression Testing
//
// 1 10/08/13 12:03p Fredericko
// Initial Check-In for Tpm-Next module
//
// 2 10/03/13 2:00p Fredericko
//
// 1 7/10/13 5:51p Fredericko
// [TAG] EIP120969
// [Category] New Feature
// [Description] TCG (TPM20)
//
// 13 11/14/11 1:27p Fredericko
// Changes for Tcgprotocol interface. Function is currently not used.
//
// 12 3/31/11 4:57p Fredericko
// Changes for TCG_LEGACY support
//
// 11 3/29/11 1:12p Fredericko
//
// 10 3/28/11 2:19p Fredericko
// [TAG] EIP 54642
// [Category] Improvement
// [Description] 1. Checkin Files related to TCG function override
// 2. Include TCM and TPM auto detection
// [Files] Affects all TCG files
//
// 9 5/19/10 5:31p Fredericko
// Included File Header
// Included File Revision History
// Code Beautification
// EIP 37653
//
//*************************************************************************
//*************************************************************************
//<AMI_FHDR_START>
//
// Name: TpmDxe.c
//
// Description:
// Abstracted functions for Tpm protocol are defined here
//
//<AMI_FHDR_END>
//*************************************************************************
#include <Efi.h>
#include "TcgTpm12.h"
#include <TpmLib.h>
#include <Protocol\TpmDevice\TpmDevice.h>
#include <AmiDxeLib.h>
#include <token.h>
#include "Tpm20CRBLib.h"
#define _CR( Record, TYPE,\
Field )((TYPE*) ((CHAR8*) (Record) - (CHAR8*) &(((TYPE*) 0)->Field)))
EFI_GUID TcgGuid = AMI_TCG_RESETVAR_HOB_GUID;
VOID* LocateATcgHob (
UINTN NoTableEntries,
EFI_CONFIGURATION_TABLE *ConfigTable,
EFI_GUID *HOB_guid );
#define TPM_DXE_PRIVATE_DATA_FROM_THIS( this ) \
_CR( this, TPM_DXE_PRIVATE_DATA, TpmInterface )
typedef struct _TPM_DXE_PRIVATE_DATA
{
EFI_TPM_DEVICE_PROTOCOL TpmInterface;
EFI_PHYSICAL_ADDRESS BaseAddr;
} TPM_DXE_PRIVATE_DATA;
FixedDelay(UINT32 dCount);
static UINTN TpmFuncID;
static TPMTransmitEntryStruct TpmEmptyBuf;
static UINT32 TpmRet;
static UINTN ReadytoBootVar = 0;
#if TCG_LEGACY == 0
EFI_STATUS
EFIAPI TpmDxeInit(
IN EFI_TPM_DEVICE_PROTOCOL *This )
{
EFI_STATUS Status;
volatile TPM_1_2_REGISTERS_PTR TpmReg;
TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
Status = TisRequestLocality(TpmReg);
return Status;
}
EFI_STATUS
EFIAPI TpmDxeClose(
IN EFI_TPM_DEVICE_PROTOCOL *This )
{
EFI_STATUS Status;
volatile TPM_1_2_REGISTERS_PTR TpmReg;
TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
Status = TisReleaseLocality(TpmReg);
return Status;
}
EFI_STATUS
EFIAPI TpmDxeGetStatusInfo(
IN EFI_TPM_DEVICE_PROTOCOL *This )
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI TpmDxeTransmit(
IN EFI_TPM_DEVICE_PROTOCOL *This,
IN UINTN NoInBuffers,
IN TPM_TRANSMIT_BUFFER *InBuffers,
IN UINTN NoOutBuffers,
IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
{
volatile TPM_1_2_REGISTERS_PTR TpmReg;
TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
TRACE(( TRACE_ALWAYS,"TpmReg.Access = %x \n", TpmReg->Access));
return TpmLibPassThrough(
TpmReg,
NoInBuffers,
InBuffers,
NoOutBuffers,
OutBuffers
);
}
#else
//**********************************************************************
//<AMI_PHDR_START>
//
// Name: TpmDxeInit
//
// Description: Call to OEM driver to initialize TPM.
//
// Input: IN EFI_TPM_DEVICE_PROTOCOL *This
//
// Returns: EFI_STATUS
//
// Output:
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI TpmDxeInit(
IN EFI_TPM_DEVICE_PROTOCOL *This )
{
return EFI_SUCCESS; //init command is only sent once and done in PEI
}
//**********************************************************************
//<AMI_PHDR_START>
//
// Name: TpmDxeClose
//
// Description: Close TPM connection for locality 0
//
// Input: IN PEI_TPM_PPI *This,
// IN EFI_PEI_SERVICES **PeiServices
//
// Output: EFI STATUS
///
// Output:
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI TpmDxeClose(
IN EFI_TPM_DEVICE_PROTOCOL *This )
{
return EFI_SUCCESS;
}
//**********************************************************************
//<AMI_PHDR_START>
//
//
// Name: TpmDxeGetStatusInfo
//
// Description: GetStatus Info from MP driver
//
// Input: IN PEI_TPM_PPI *This,
// IN EFI_PEI_SERVICES **PeiServices
//
// Output: EFI STATUS
//
// Output:
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI TpmDxeGetStatusInfo(
IN EFI_TPM_DEVICE_PROTOCOL * This
)
{
return EFI_UNSUPPORTED;
}
//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: SetEfiOSTransitions
//
// Description: SetEfiOSTransitions
//
// Input: IN EFI_EVENT efiev
// IN VOID *ctx
//
// Output: EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
void SetEfiOSTransitions(
IN EFI_EVENT efiev,
IN VOID *ctx )
{
ReadytoBootVar = 1;
}
//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: EfiOSReadyToBoot
//
// Description: Sets ready to boot callback on ready to boot
//
// Input: NONE
//
// Output: EFI_STATUS
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI EfiOSReadyToBoot()
{
EFI_EVENT ReadToBootEvent;
EFI_STATUS Status;
#if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT)\
&& EFI_SPECIFICATION_VERSION < 0x20000
Status = pBS->CreateEvent( EFI_EVENT_SIGNAL_READY_TO_BOOT,
EFI_TPL_CALLBACK,
SetEfiOSTransitions, NULL, &ReadToBootEvent );
#else
Status = CreateReadyToBootEvent( EFI_TPL_CALLBACK-1,
SetEfiOSTransitions,
NULL,
&ReadToBootEvent );
#endif
return Status;
}
EFI_STATUS
EFIAPI EfiPreOSTransition(
IN EFI_TPM_DEVICE_PROTOCOL *This,
IN UINTN NoInBuffers,
IN TPM_TRANSMIT_BUFFER *InBuffers,
IN UINTN NoOutBuffers,
IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
{
TPM_DXE_PRIVATE_DATA *Private;
TPM_1_2_REGISTERS_PTR TpmReg;
EFI_STATUS Status;
Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
TisRequestLocality(
(TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
TpmReg = (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr;
Status = TpmLibPassThrough(
TpmReg,
NoInBuffers,
InBuffers,
NoOutBuffers,
OutBuffers
);
TisReleaseLocality(
(TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
return Status;
}
//**********************************************************************
//<AMI_PHDR_START>
//
//
// Name: TpmDxeTransmit
//
// Description: Dxe Transmit Tcg Data
//
// Input: IN EFI_TPM_DEVICE_PROTOCOL *This,
// IN UINTN NoInBuffers,
// IN TPM_TRANSMIT_BUFFER *InBuffers,
// IN UINTN NoOutBuffers,
// IN OUT TPM_TRANSMIT_BUFFER *OutBuffers
//
// Output: EFI STATUS
//
// Output:
//
// Modified:
//
// Referrals:
//
// Notes:
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS
EFIAPI TpmDxeTransmit(
IN EFI_TPM_DEVICE_PROTOCOL *This,
IN UINTN NoInBuffers,
IN TPM_TRANSMIT_BUFFER *InBuffers,
IN UINTN NoOutBuffers,
IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
{
TPM_DXE_PRIVATE_DATA *Private;
TPMTransmitEntryStruct FillESI;
UINTN FuncID = (UINTN)MP_FUNCTION_TRANSMIT;
UINT32 Ret;
UINT8 *SHA_ARRAY_OUT = NULL;
BOOLEAN FillBuff = FALSE;
BOOLEAN Other = FALSE;
UINTN i = 0, loc = 0;
UINT8 *Tpm_SHA_ARRAY= NULL;
EFI_STATUS Status;
if(NoInBuffers == 0 || InBuffers == NULL || NoOutBuffers == 0 || OutBuffers == NULL)
return EFI_INVALID_PARAMETER;
if(ReadytoBootVar == 1)
{
return EfiPreOSTransition(This, NoInBuffers, InBuffers, NoOutBuffers, OutBuffers);
}
FillESI.dwInLen = 0;
FillESI.dwOutLen = 0;
for (; i < NoInBuffers; i++ )
{
FillESI.dwInLen += (UINT32)InBuffers[i].Size;
}
Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwInLen, &Tpm_SHA_ARRAY);
if(EFI_ERROR(Status))return Status;
for (i = 0; i < NoOutBuffers; i++ )
{
FillESI.dwOutLen += (UINT32)OutBuffers[i].Size;
}
Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwOutLen, &SHA_ARRAY_OUT );
if(EFI_ERROR(Status))return Status;
for (i = 0; i < NoInBuffers; i++ )
{
pBS->CopyMem(Tpm_SHA_ARRAY + loc,
InBuffers[i].Buffer,
InBuffers[i].Size );
loc += InBuffers[i].Size;
}
FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) Tpm_SHA_ARRAY;
FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) SHA_ARRAY_OUT;
Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
TpmDxeCallMPDriver( FuncID, &FillESI, &Ret );
if ( Tpm_SHA_ARRAY != NULL )
{
pBS->FreePool( Tpm_SHA_ARRAY );
}
loc = 0;
for (i=0; i < NoOutBuffers; i++ )
{
pBS->CopyMem( OutBuffers[i].Buffer,
&SHA_ARRAY_OUT[loc],
OutBuffers[i].Size );
loc += (UINTN)OutBuffers[i].Size;
}
if ( SHA_ARRAY_OUT != NULL )
{
pBS->FreePool( SHA_ARRAY_OUT );
}
return EFI_SUCCESS;
}
#endif
static TPM_DXE_PRIVATE_DATA mTpmPrivate = {
{
TpmDxeInit,
TpmDxeClose,
TpmDxeGetStatusInfo,
TpmDxeTransmit
},
TPM_BASE_ADDRESS
};
EFI_STATUS
EFIAPI TpmDxeEntry(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable )
{
EFI_STATUS Status;
#if TCG_LEGACY == 1
EFI_GUID gMpDriverHobGuid = EFI_TCG_MPDriver_HOB_GUID;
FAR32LOCALS *TempLoc = NULL;
#endif
#if TCG_LEGACY == 0
Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)( UINTN ) mTpmPrivate.BaseAddr );
if ( EFI_ERROR( Status ))
{
if(isTpm20CrbPresent())return EFI_SUCCESS;
return EFI_UNLOAD_IMAGE;
}
#else
TempLoc = (FAR32LOCALS*)LocateATcgHob( pST->NumberOfTableEntries,
pST->ConfigurationTable,
&gMpDriverHobGuid );
if(TempLoc == NULL || TempLoc->Offset == NULL ) return EFI_NOT_FOUND;
Prepare2Thunkproc( TempLoc->Offset, TempLoc->Selector );
Status = EfiOSReadyToBoot();
#endif
Status = pBS->InstallMultipleProtocolInterfaces(
&ImageHandle,
&gEfiTpmDeviceProtocolGuid,
&mTpmPrivate.TpmInterface,
NULL
);
return Status;
}
EFI_GUID gEfiTpmDeviceProtocolGuid = EFI_TPM_DEVICE_PROTOCOL_GUID;
|