1 /*++
2 
3 Copyright (c) 1999 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 
13 Module Name:
14 
15   SmmBase.h
16 
17 Abstract:
18 
19   This file defines SMM Base abstraction protocol defined by the SMM Architecture
20   Specification.  This is the base level of compatiblity for SMM drivers.
21 
22 --*/
23 
24 #ifndef _SMM_BASE_H_
25 #define _SMM_BASE_H_
26 
27 #include EFI_PROTOCOL_DEFINITION (DevicePath)
28 
29 #define EFI_SMM_BASE_PROTOCOL_GUID \
30   { \
31     0x1390954D, 0xda95, 0x4227, {0x93, 0x28, 0x72, 0x82, 0xc2, 0x17, 0xda, 0xa8} \
32   }
33 
34 #define EFI_SMM_CPU_IO_GUID \
35   { \
36     0x5f439a0b, 0x45d8, 0x4682, {0xa4, 0xf4, 0xf0, 0x57, 0x6b, 0x51, 0x34, 0x41} \
37   }
38 
39 #define SMM_COMMUNICATE_HEADER_GUID \
40   { \
41     0xF328E36C, 0x23B6, 0x4a95, {0x85, 0x4B, 0x32, 0xE1, 0x95, 0x34, 0xCD, 0x75} \
42   }
43 
44 //
45 // SMM Base specification constant and types
46 //
47 #define SMM_SMST_SIGNATURE            EFI_SIGNATURE_32 ('S', 'M', 'S', 'T')
48 #define EFI_SMM_SYSTEM_TABLE_REVISION (0 << 16) | (0x09)
49 
50 EFI_FORWARD_DECLARATION (EFI_SMM_BASE_PROTOCOL);
51 EFI_FORWARD_DECLARATION (EFI_SMM_CPU_IO_INTERFACE);
52 EFI_FORWARD_DECLARATION (EFI_SMM_CPU_SAVE_STATE);
53 EFI_FORWARD_DECLARATION (EFI_SMM_OPTIONAL_FP_SAVE_STATE);
54 EFI_FORWARD_DECLARATION (EFI_SMM_SYSTEM_TABLE);
55 
56 //
57 // *******************************************************
58 // EFI_SMM_IO_WIDTH
59 // *******************************************************
60 //
61 typedef enum {
62   SMM_IO_UINT8  = 0,
63   SMM_IO_UINT16 = 1,
64   SMM_IO_UINT32 = 2,
65   SMM_IO_UINT64 = 3
66 } EFI_SMM_IO_WIDTH;
67 
68 //
69 // *******************************************************
70 // EFI_SMM_IO_ACCESS
71 // *******************************************************
72 //
73 typedef
74 EFI_STATUS
75 (EFIAPI *EFI_SMM_CPU_IO) (
76   IN EFI_SMM_CPU_IO_INTERFACE         * This,
77   IN EFI_SMM_IO_WIDTH                 Width,
78   IN UINT64                           Address,
79   IN UINTN                            Count,
80   IN OUT VOID                         *Buffer
81   );
82 
83 typedef struct {
84   EFI_SMM_CPU_IO  Read;
85   EFI_SMM_CPU_IO  Write;
86 } EFI_SMM_IO_ACCESS;
87 
88 struct _EFI_SMM_CPU_IO_INTERFACE {
89   EFI_SMM_IO_ACCESS Mem;
90   EFI_SMM_IO_ACCESS Io;
91 };
92 
93 typedef
94 EFI_STATUS
95 (EFIAPI *EFI_SMMCORE_ALLOCATE_POOL) (
96   IN EFI_MEMORY_TYPE                PoolType,
97   IN UINTN                          Size,
98   OUT VOID                          **Buffer
99   );
100 
101 typedef
102 EFI_STATUS
103 (EFIAPI *EFI_SMMCORE_FREE_POOL) (
104   IN VOID                   *Buffer
105   );
106 
107 typedef
108 EFI_STATUS
109 (EFIAPI *EFI_SMMCORE_ALLOCATE_PAGES) (
110   IN EFI_ALLOCATE_TYPE      Type,
111   IN EFI_MEMORY_TYPE        MemoryType,
112   IN UINTN                  NumberOfPages,
113   OUT EFI_PHYSICAL_ADDRESS  * Memory
114   );
115 
116 typedef
117 EFI_STATUS
118 (EFIAPI *EFI_SMMCORE_FREE_PAGES) (
119   IN EFI_PHYSICAL_ADDRESS   Memory,
120   IN UINTN                  NumberOfPages
121   );
122 
123 typedef
124 VOID
125 (EFIAPI *EFI_AP_PROCEDURE) (
126   IN  VOID                              *Buffer
127   );
128 
129 typedef
130 EFI_STATUS
131 (EFIAPI *EFI_SMM_STARTUP_THIS_AP) (
132   IN  EFI_AP_PROCEDURE                    Procedure,
133   IN  UINTN                               CpuNumber,
134   IN  OUT VOID                            *ProcArguments OPTIONAL
135   );
136 
137 struct _EFI_SMM_CPU_SAVE_STATE {
138   UINT8   Reserved1[248];
139   UINT32  SMBASE;
140   UINT32  SMMRevId;
141   UINT16  IORestart;
142   UINT16  AutoHALTRestart;
143   UINT8   Reserved2[164];
144   UINT32  ES;
145   UINT32  CS;
146   UINT32  SS;
147   UINT32  DS;
148   UINT32  FS;
149   UINT32  GS;
150   UINT32  LDTBase;
151   UINT32  TR;
152   UINT32  DR7;
153   UINT32  DR6;
154   UINT32  EAX;
155   UINT32  ECX;
156   UINT32  EDX;
157   UINT32  EBX;
158   UINT32  ESP;
159   UINT32  EBP;
160   UINT32  ESI;
161   UINT32  EDI;
162   UINT32  EIP;
163   UINT32  EFLAGS;
164   UINT32  CR3;
165   UINT32  CR0;
166 };
167 
168 typedef struct {
169   UINT8   Reserved19[760];    // FC00
170   UINT32  SMBASE;             // FEF8
171   UINT32  REVID;              // FEFC
172   UINT16  HALT_RESTART;       // FF00
173   UINT16  IO_RESTART;         // FF02
174   UINT32  Reserved17[22];     // FF58, 54, 50, 4c, 48, 44, 40, 3c, 38, 34, 30, 2c, 28, 24, 20, 1c, 18, 14, 10, 0c, 08, 04
175   UINT32  EAX;                // FF5C
176   UINT32  Reserved16;         // FF60
177   UINT32  ECX;                // FF64
178   UINT32  Reserved15;         // FF68
179   UINT32  EDX;                // FF6C
180   UINT32  Reserved14;         // FF70
181   UINT32  EBX;                // FF74
182   UINT32  Reserved13;         // FF78
183   UINT32  ESP;                // FF7C
184   UINT32  Reserved12;         // FF80
185   UINT32  EBP;                // FF84
186   UINT32  Reserved11;         // FF88
187   UINT32  ESI;                // FF8C
188   UINT32  Reserved9;          // FF90
189   UINT32  EDI;                // FF94
190   UINT32  Reserved8;          // FF98
191   UINT32  IO_MEM_ADDR;        // FF9C
192   UINT32  Reserved7;          // FFA0
193   UINT32  IO_MISC;            // FFA4
194   UINT32  ES_SEL;             // FFA8
195   UINT32  CS_SEL;             // FFAC
196   UINT32  SS_SEL;             // FFB0
197   UINT32  DS_SEL;             // FFB4
198   UINT32  FS_SEL;             // FFB8
199   UINT32  GS_SEL;             // FFBC
200   UINT32  LDTR_SEL;           // FFC0
201   UINT32  TR_SEL;             // FFC4
202   UINT32  DR7;                // FFC8
203   UINT32  Reserved6;          // FFCC
204   UINT32  DR6;                // FFD0
205   UINT32  Reserved5;          // FFD4
206   UINT32  EIP;                // FFD8
207   UINT32  Reserved4;          // FFDC
208   UINT32  EFER;               // FFE0
209   UINT32  Reserved3;          // FFE4
210   UINT32  EFLAGS;             // FFE8
211   UINT32  Reserved2;          // FFEC
212   UINT32  CR3;                // FFF0
213   UINT32  Reserved1;          // FFF4
214   UINT32  CR0;                // FFF8
215   UINT32  Reserved0;          // FFFC
216 } EFI_SMM_CPU_CT_SAVE_STATE;
217 
218 typedef struct {
219   UINT8   Reserved26[464];        // FC00 - FDCF
220   UINT32  GdtrUpperBase;          // FDD0
221   UINT32  LdtrUpperBase;          // FDD4
222   UINT32  IdtrUpperBase;          // FDD8
223   UINT32  Reserved25;             // FDDC - FDDF
224   UINT64  IoRdi;                  // FDE0
225   UINT64  IoRip;                  // FDE8
226   UINT64  IoRcx;                  // FDF0
227   UINT64  IoRsi;                  // FDF8
228   UINT8   Reserved24[64];         // FE00 - FE3F
229   UINT64  Cr4;                    // FE40
230   UINT8   Reserved23[68];         // FE48 - FE8B
231   UINT32  GdtrBase;               // FE8C
232   UINT32  Reserved22;             // FE90
233   UINT32  IdtrBase;               // FE94
234   UINT32  Reserved21;             // FE98
235   UINT32  LdtrBase;               // FE9C
236   UINT32  Reserved20;             // FEA0
237   UINT8   Reserved19[84];         // FEA4 - FEF7
238   UINT32  Smbase;                 // FEF8
239   UINT32  RevId;                  // FEFC
240   UINT16  IoRestart;              // FF00
241   UINT16  HaltRestart;            // FF02
242   UINT8   Reserved18[24];         // FF04 - FF1B
243   UINT32  R15;                    // FF1C
244   UINT32  Reserved17;             // FE20
245   UINT32  R14;                    // FF24
246   UINT32  Reserved16;             // FE28
247   UINT32  R13;                    // FF2C
248   UINT32  Reserved15;             // FE30
249   UINT32  R12;                    // FF34
250   UINT32  Reserved14;             // FE38
251   UINT32  R11;                    // FF3C
252   UINT32  Reserved13;             // FE40
253   UINT32  R10;                    // FF44
254   UINT32  Reserved12;             // FE48
255   UINT32  R9;                     // FF4C
256   UINT32  Reserved11;             // FE50
257   UINT32  R8;                     // FF54
258   UINT32  Reserved10;             // FE58
259   UINT32  Rax;                    // FF5C
260   UINT32  Reserved9;              // FE60
261   UINT32  Rcx;                    // FF64
262   UINT32  Reserved8;              // FE68
263   UINT32  Rdx;                    // FF6C
264   UINT32  Reserved7;              // FE70
265   UINT32  Rbx;                    // FF74
266   UINT32  Reserved6;              // FE78
267   UINT32  Rsp;                    // FF7C
268   UINT32  Reserved5;              // FE80
269   UINT32  Rbp;                    // FF84
270   UINT32  Reserved4;              // FE88
271   UINT32  Rsi;                    // FF8C
272   UINT32  Reserved3;              // FE90
273   UINT32  Rdi;                    // FF94
274   UINT32  Reserved2;              // FE98
275   UINT32  IoMemAddr;              // FF9C
276   UINT32  Reserved1;              // FEA0
277   UINT32  IoMiscInfo;             // FFA4
278   UINT32  EsSel;                  // FFA8
279   UINT32  CsSel;                  // FFAC
280   UINT32  SsSel;                  // FFB0
281   UINT32  DsSel;                  // FFB4
282   UINT32  FsSel;                  // FFB8
283   UINT32  GsSel;                  // FFBC
284   UINT32  LdtrSel;                // FFC0
285   UINT32  TrSel;                  // FFC4
286   UINT64  Dr7;                    // FFC8
287   UINT64  Dr6;                    // FFD0
288   UINT32  Rip;                    // FFD8
289   UINT32  Reserved0;              // FFDC
290   UINT64  Efr;                    // FFE0
291   UINT64  RFlags;                 // FFE8
292   UINT64  Cr3;                    // FFF0
293   UINT64  Cr0;                    // FFF8
294 } EFI_SMM_CPU_MEROM_SAVE_STATE;
295 
296 
297 typedef struct {
298   UINT8   Reserved14[0x228];  // FC00-FE28
299   UINT32  IO_EIP;             // FE28
300   UINT8   Reserved13[0x14];   // FE2C-FE40
301   UINT32  CR4;                // FE40
302   UINT8   Reserved12[0x48];   // FE44-FE8C
303   UINT32  GDT_BASE;           // FE8C
304   UINT8   Reserved11[0xC];    // FE90-FE9C
305   UINT32  LDT_BASE;           // FE9C
306   UINT8   Reserved10[0x58];   // FEA0-FEF8
307   UINT32  SMBASE;
308   UINT32  REVID;
309   UINT16  IO_RESTART;
310   UINT16  HALT_RESTART;
311   UINT8   Reserved9[0xA4];
312 
313   UINT16  ES;
314   UINT16  Reserved8;
315   UINT16  CS;
316   UINT16  Reserved7;
317   UINT16  SS;
318   UINT16  Reserved6;
319   UINT16  DS;
320   UINT16  Reserved5;
321   UINT16  FS;
322   UINT16  Reserved4;
323   UINT16  GS;
324   UINT16  Reserved3;
325   UINT32  Reserved2;
326   UINT16  TR;
327   UINT16  Reserved1;
328   UINT32  DR7;
329   UINT32  DR6;
330   UINT32  EAX;
331   UINT32  ECX;
332   UINT32  EDX;
333   UINT32  EBX;
334   UINT32  ESP;
335   UINT32  EBP;
336   UINT32  ESI;
337   UINT32  EDI;
338   UINT32  EIP;
339   UINT32  EFLAGS;
340   UINT32  CR3;
341   UINT32  CR0;
342 } EFI_SMM_CPU_CT_NOT_ENABLED_SAVE_STATE;
343 
344 struct _EFI_SMM_OPTIONAL_FP_SAVE_STATE {
345   UINT16  Fcw;
346   UINT16  Fsw;
347   UINT16  Ftw;
348   UINT16  Opcode;
349   UINT32  Eip;
350   UINT16  Cs;
351   UINT16  Rsvd1;
352   UINT32  DataOffset;
353   UINT16  Ds;
354   UINT8   Rsvd2[10];
355   UINT8   St0Mm0[10], Rsvd3[6];
356   UINT8   St0Mm1[10], Rsvd4[6];
357   UINT8   St0Mm2[10], Rsvd5[6];
358   UINT8   St0Mm3[10], Rsvd6[6];
359   UINT8   St0Mm4[10], Rsvd7[6];
360   UINT8   St0Mm5[10], Rsvd8[6];
361   UINT8   St0Mm6[10], Rsvd9[6];
362   UINT8   St0Mm7[10], Rsvd10[6];
363   UINT8   Rsvd11[22 * 16];
364 };
365 
366 typedef struct _EFI_SMM_OPTIONAL_FP_SAVE_STATE32 {
367   UINT16  Fcw;
368   UINT16  Fsw;
369   UINT16  Ftw;
370   UINT16  Opcode;
371   UINT32  Eip;
372   UINT16  Cs;
373   UINT16  Rsvd1;
374   UINT32  DataOffset;
375   UINT16  Ds;
376   UINT8   Reserved2[10];
377   UINT8   St0Mm0[10], Rsvd3[6];
378   UINT8   St1Mm1[10], Rsvd4[6];
379   UINT8   St2Mm2[10], Rsvd5[6];
380   UINT8   St3Mm3[10], Rsvd6[6];
381   UINT8   St4Mm4[10], Rsvd7[6];
382   UINT8   St5Mm5[10], Rsvd8[6];
383   UINT8   St6Mm6[10], Rsvd9[6];
384   UINT8   St7Mm7[10], Rsvd10[6];
385   UINT8   Xmm0[16];
386   UINT8   Xmm1[16];
387   UINT8   Xmm2[16];
388   UINT8   Xmm3[16];
389   UINT8   Xmm4[16];
390   UINT8   Xmm5[16];
391   UINT8   Xmm6[16];
392   UINT8   Xmm7[16];
393   UINT8   Rsvd11[14 * 16];
394 } EFI_SMM_OPTIONAL_FP_SAVE_STATE32;
395 
396 typedef struct _EFI_SMM_OPTIONAL_FP_SAVE_STATE64 {
397   UINT16  Fcw;
398   UINT16  Fsw;
399   UINT16  Ftw;
400   UINT16  Opcode;
401   UINT64  Rip;
402   UINT64  DataOffset;
403   UINT8   Rsvd1[8];
404   UINT8   St0Mm0[10], Rsvd2[6];
405   UINT8   St1Mm1[10], Rsvd3[6];
406   UINT8   St2Mm2[10], Rsvd4[6];
407   UINT8   St3Mm3[10], Rsvd5[6];
408   UINT8   St4Mm4[10], Rsvd6[6];
409   UINT8   St5Mm5[10], Rsvd7[6];
410   UINT8   St6Mm6[10], Rsvd8[6];
411   UINT8   St7Mm7[10], Rsvd9[6];
412   UINT8   Xmm0[16];
413   UINT8   Xmm1[16];
414   UINT8   Xmm2[16];
415   UINT8   Xmm3[16];
416   UINT8   Xmm4[16];
417   UINT8   Xmm5[16];
418   UINT8   Xmm6[16];
419   UINT8   Xmm7[16];
420   UINT8   Xmm8[16];
421   UINT8   Xmm9[16];
422   UINT8   Xmm10[16];
423   UINT8   Xmm11[16];
424   UINT8   Xmm12[16];
425   UINT8   Xmm13[16];
426   UINT8   Xmm14[16];
427   UINT8   Xmm15[16];
428   UINT8   Rsvd10[6 * 16];
429 } EFI_SMM_OPTIONAL_FP_SAVE_STATE64;
430 
431 struct _EFI_SMM_SYSTEM_TABLE;
432 
433 typedef
434 EFI_STATUS
435 (EFIAPI *EFI_SMM_INSTALL_CONFIGURATION_TABLE) (
436   IN EFI_SMM_SYSTEM_TABLE         * SystemTable,
437   IN EFI_GUID                     * Guid,
438   IN VOID                         *Table,
439   IN UINTN                        TableSize
440   )
441 /*++
442 
443   Routine Description:
444     The SmmInstallConfigurationTable() function is used to maintain the list
445     of configuration tables that are stored in the System Management System
446     Table.  The list is stored as an array of (GUID, Pointer) pairs.  The list
447     must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
448 
449   Arguments:
450     SystemTable - A pointer to the SMM System Table.
451     Guid        - A pointer to the GUID for the entry to add, update, or remove.
452     Table       - A pointer to the buffer of the table to add.
453     TableSize   - The size of the table to install.
454 
455   Returns:
456     EFI_SUCCESS             - The (Guid, Table) pair was added, updated, or removed.
457     EFI_INVALID_PARAMETER   - Guid is not valid.
458     EFI_NOT_FOUND           - An attempt was made to delete a non-existent entry.
459     EFI_OUT_OF_RESOURCES    - There is not enough memory available to complete the operation.
460 
461 --*/
462 ;
463 
464 //
465 // System Management System Table (SMST)
466 //
467 struct _EFI_SMM_SYSTEM_TABLE {
468   EFI_TABLE_HEADER                    Hdr;
469 
470   CHAR16                              *SmmFirmwareVendor;
471   UINT32                              SmmFirmwareRevision;
472 
473   EFI_SMM_INSTALL_CONFIGURATION_TABLE SmmInstallConfigurationTable;
474 
475   //
476   // I/O Services
477   //
478   EFI_GUID                            EfiSmmCpuIoGuid;
479   EFI_SMM_CPU_IO_INTERFACE            SmmIo;
480 
481   //
482   // Runtime memory service
483   //
484   EFI_SMMCORE_ALLOCATE_POOL           SmmAllocatePool;
485   EFI_SMMCORE_FREE_POOL               SmmFreePool;
486   EFI_SMMCORE_ALLOCATE_PAGES          SmmAllocatePages;
487   EFI_SMMCORE_FREE_PAGES              SmmFreePages;
488 
489   //
490   // MP service
491   //
492   EFI_SMM_STARTUP_THIS_AP             SmmStartupThisAp;
493 
494   //
495   // CPU information records
496   //
497   UINTN                               CurrentlyExecutingCpu;
498   UINTN                               NumberOfCpus;
499   EFI_SMM_CPU_SAVE_STATE              *CpuSaveState;
500   EFI_SMM_OPTIONAL_FP_SAVE_STATE      *CpuOptionalFloatingPointState;
501 
502   //
503   // Extensibility table
504   //
505   UINTN                               NumberOfTableEntries;
506   EFI_CONFIGURATION_TABLE             *SmmConfigurationTable;
507 
508 };
509 
510 //
511 // SMM Handler Definition
512 //
513 #define EFI_HANDLER_SUCCESS         0x0000
514 #define EFI_HANDLER_CRITICAL_EXIT   0x0001
515 #define EFI_HANDLER_SOURCE_QUIESCED 0x0002
516 #define EFI_HANDLER_SOURCE_PENDING  0x0003
517 
518 //
519 // Structure of Communicate Buffer
520 //
521 typedef struct {
522   EFI_GUID              HeaderGuid;
523   UINTN                 MessageLength;
524   UINT8                 Data[1];
525 } EFI_SMM_COMMUNICATE_HEADER;
526 
527 typedef
528 EFI_STATUS
529 (EFIAPI *EFI_SMM_HANDLER_ENTRY_POINT) (
530   IN EFI_HANDLE             SmmImageHandle,
531   IN OUT VOID               *CommunicationBuffer OPTIONAL,
532   IN OUT UINTN              *SourceSize OPTIONAL
533   );
534 
535 typedef
536 EFI_STATUS
537 (EFIAPI *EFI_SMM_CALLBACK_ENTRY_POINT) (
538   IN EFI_HANDLE             SmmImageHandle,
539   IN OUT VOID               *CommunicationBuffer OPTIONAL,
540   IN OUT UINTN              *SourceSize OPTIONAL
541   );
542 
543 typedef struct {
544   EFI_HANDLE                SmmHandler;
545   EFI_DEVICE_PATH_PROTOCOL  *HandlerDevicePath;
546 } EFI_HANDLER_DESCRIPTOR;
547 
548 //
549 // SMM Base Protocol Definition
550 //
551 typedef
552 EFI_STATUS
553 (EFIAPI *EFI_SMM_REGISTER_HANDLER) (
554   IN EFI_SMM_BASE_PROTOCOL                           * This,
555   IN  EFI_DEVICE_PATH_PROTOCOL                       * FilePath,
556   IN  VOID                                           *SourceBuffer OPTIONAL,
557   IN  UINTN                                          SourceSize,
558   OUT EFI_HANDLE                                     * ImageHandle,
559   IN  BOOLEAN                                        LegacyIA32Binary OPTIONAL
560   )
561 /*++
562 
563   Routine Description:
564     Register a given driver into SMRAM.  This is the equivalent of performing
565     the LoadImage/StartImage into System Management Mode.
566 
567   Arguments:
568     This                  - Protocol instance pointer.
569     SourceBuffer          - Optional source buffer in case of the image file
570                             being in memory.
571     SourceSize            - Size of the source image file, if in memory.
572     ImageHandle           - Pointer to the handle that reflects the driver
573                             loaded into SMM.
574     LegacyIA32Binary      - The binary image to load is legacy 16 bit code.
575 
576   Returns:
577     EFI_SUCCESS           - The operation was successful.
578     EFI_OUT_OF_RESOURCES  - There were no additional SMRAM resources to load the handler
579     EFI_UNSUPPORTED       - This platform does not support 16-bit handlers.
580     EFI_UNSUPPORTED       - In runtime.
581     EFI_INVALID_PARAMETER - The handlers was not the correct image type
582 
583 --*/
584 ;
585 
586 typedef
587 EFI_STATUS
588 (EFIAPI *EFI_SMM_UNREGISTER_HANDLER) (
589   IN EFI_SMM_BASE_PROTOCOL          * This,
590   IN EFI_HANDLE                     ImageHandle
591   )
592 /*++
593 
594   Routine Description:
595     Remove a given driver SMRAM.  This is the equivalent of performing
596     the UnloadImage System Management Mode.
597 
598   Arguments:
599     This                  - Protocol instance pointer.
600     ImageHandle           - Pointer to the handle that reflects the driver
601                             loaded into SMM.
602 
603   Returns:
604     EFI_SUCCESS           - The operation was successful
605     EFI_INVALID_PARAMETER - The handler did not exist
606     EFI_UNSUPPORTED       - In runtime.
607 
608 --*/
609 ;
610 
611 typedef
612 EFI_STATUS
613 (EFIAPI *EFI_SMM_COMMUNICATE) (
614   IN EFI_SMM_BASE_PROTOCOL          * This,
615   IN EFI_HANDLE                     ImageHandle,
616   IN OUT VOID                       *CommunicationBuffer,
617   IN OUT UINTN                      *SourceSize
618   )
619 /*++
620 
621   Routine Description:
622     The SMM Inter-module Communicate Service Communicate() function
623     provides a services to send/received messages from a registered
624     EFI service.  The BASE protocol driver is responsible for doing
625     any of the copies such that the data lives in boot-service accessible RAM.
626 
627   Arguments:
628     This                  - Protocol instance pointer.
629     ImageHandle           - Pointer to the handle that reflects the driver
630                             loaded into SMM.
631     CommunicationBuffer   - Pointer to the buffer to convey into SMRAM.
632     SourceSize            - Size of the contents of buffer..
633 
634   Returns:
635     EFI_SUCCESS           - The message was successfully posted
636     EFI_INVALID_PARAMETER - The buffer was NULL
637 
638 --*/
639 ;
640 
641 typedef
642 EFI_STATUS
643 (EFIAPI *EFI_SMM_CALLBACK_SERVICE) (
644   IN EFI_SMM_BASE_PROTOCOL                            * This,
645   IN EFI_HANDLE                                       SmmImageHandle,
646   IN EFI_SMM_CALLBACK_ENTRY_POINT                     CallbackAddress,
647   IN BOOLEAN                                          MakeLast OPTIONAL,
648   IN BOOLEAN                                          FloatingPointSave OPTIONAL
649   )
650 /*++
651 
652   Routine Description:
653     Register a callback to execute within SMM.
654     This allows receipt of messages created with the Boot Service COMMUNICATE.
655 
656   Arguments:
657     This                  - Protocol instance pointer.
658     CallbackAddress       - Address of the callback service
659     MakeFirst             - If present, will stipulate that the handler is posted
660                             to be the first module executed in the dispatch table.
661     MakeLast              - If present, will stipulate that the handler is posted
662                             to be last executed in the dispatch table.
663     FloatingPointSave     - This is an optional parameter which informs the
664                             EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save
665                             the floating point register state.  If any of the handlers
666                             require this, then the state will be saved for all of the handlers.
667 
668   Returns:
669     EFI_SUCCESS           - The operation was successful
670     EFI_OUT_OF_RESOURCES  - Not enough space in the dispatch queue
671     EFI_UNSUPPORTED       - In runtime.
672     EFI_UNSUPPORTED       - Not in SMM.
673 
674 --*/
675 ;
676 
677 typedef
678 EFI_STATUS
679 (EFIAPI *EFI_SMM_ALLOCATE_POOL) (
680   IN EFI_SMM_BASE_PROTOCOL          * This,
681   IN EFI_MEMORY_TYPE                PoolType,
682   IN UINTN                          Size,
683   OUT VOID                          **Buffer
684   )
685 /*++
686 
687   Routine Description:
688     The SmmAllocatePool() function allocates a memory region of Size bytes from memory of
689     type PoolType and returns the address of the allocated memory in the location referenced
690     by Buffer.  This function allocates pages from EFI SMRAM Memory as needed to grow the
691     requested pool type.  All allocations are eight-byte aligned.
692 
693   Arguments:
694     This                  - Protocol instance pointer.
695     PoolType              - The type of pool to allocate.
696                             The only supported type is EfiRuntimeServicesData;
697                             the interface will internally map this runtime request to SMRAM.
698     Size                  - The number of bytes to allocate from the pool.
699     Buffer                - A pointer to a pointer to the allocated buffer if the call
700                             succeeds; undefined otherwise.
701 
702   Returns:
703     EFI_SUCCESS           - The requested number of bytes was allocated.
704     EFI_OUT_OF_RESOURCES  - The pool requested could not be allocated.
705     EFI_INVALID_PARAMETER - PoolType was invalid.
706     EFI_UNSUPPORTED       - In runtime.
707 
708 --*/
709 ;
710 
711 typedef
712 EFI_STATUS
713 (EFIAPI *EFI_SMM_FREE_POOL) (
714   IN EFI_SMM_BASE_PROTOCOL          * This,
715   IN VOID                           *Buffer
716   )
717 /*++
718 
719   Routine Description:
720     The SmmFreePool() function returns the memory specified by Buffer to the system.
721     On return, the memory's type is EFI SMRAM Memory.  The Buffer that is freed must
722     have been allocated by SmmAllocatePool().
723 
724   Arguments:
725     This                  - Protocol instance pointer.
726     Buffer                - Pointer to the buffer allocation.
727 
728   Returns:
729     EFI_SUCCESS           - The memory was returned to the system.
730     EFI_INVALID_PARAMETER - Buffer was invalid.
731     EFI_UNSUPPORTED       - In runtime.
732 
733 --*/
734 ;
735 
736 typedef
737 EFI_STATUS
738 (EFIAPI *EFI_SMM_INSIDE_OUT) (
739   IN EFI_SMM_BASE_PROTOCOL          * This,
740   OUT BOOLEAN                       *InSmm
741   )
742 /*++
743 
744   Routine Description:
745     This routine tells caller if execution context is SMM or not.
746 
747   Arguments:
748     This                  - Protocol instance pointer.
749 
750   Returns:
751     EFI_SUCCESS           - The operation was successful
752 
753 --*/
754 ;
755 
756 typedef
757 EFI_STATUS
758 (EFIAPI *EFI_SMM_GET_SMST_LOCATION) (
759   IN EFI_SMM_BASE_PROTOCOL          * This,
760   IN OUT EFI_SMM_SYSTEM_TABLE       **Smst
761   )
762 /*++
763 
764   Routine Description:
765     The GetSmstLocation() function returns the locatin of the System Management
766     Service Table.  The use of the API is such that a driver can discover the
767     location of the SMST in its entry point and then cache it in some driver
768     global variable so that the SMST can be invoked in subsequent callbacks.
769 
770   Arguments:
771     This                  - Protocol instance pointer.
772     Smst                  - Pointer to the SMST.
773 
774   Returns:
775     EFI_SUCCESS           - The operation was successful
776     EFI_INVALID_PARAMETER - Smst was invalid.
777     EFI_UNSUPPORTED       - Not in SMM.
778 
779 --*/
780 ;
781 
782 struct _EFI_SMM_BASE_PROTOCOL {
783   EFI_SMM_REGISTER_HANDLER    Register;
784   EFI_SMM_UNREGISTER_HANDLER  UnRegister;
785   EFI_SMM_COMMUNICATE         Communicate;
786   EFI_SMM_CALLBACK_SERVICE    RegisterCallback;
787   EFI_SMM_INSIDE_OUT          InSmm;
788   EFI_SMM_ALLOCATE_POOL       SmmAllocatePool;
789   EFI_SMM_FREE_POOL           SmmFreePool;
790   EFI_SMM_GET_SMST_LOCATION   GetSmstLocation;
791 };
792 
793 extern EFI_GUID gEfiSmmBaseProtocolGuid;
794 extern EFI_GUID gEfiSmmCpuIoGuid;
795 extern EFI_GUID gEfiSmmCommunicateHeaderGuid;
796 
797 #endif
798