1 /** @file
2   Common header file.
3 
4 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef _CAPSULE_COMMON_HEADER_
16 #define _CAPSULE_COMMON_HEADER_
17 
18 //
19 // 8 extra pages for PF handler.
20 //
21 #define EXTRA_PAGE_TABLE_PAGES      8
22 
23 //
24 // This capsule PEIM puts its private data at the start of the
25 // coalesced capsule. Here's the structure definition.
26 //
27 #define EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'a', 'p', 'P')
28 
29 #pragma pack(1)
30 typedef struct {
31   UINT64  Signature;
32   UINT64  CapsuleAllImageSize;
33   UINT64  CapsuleNumber;
34   UINT64  CapsuleOffset[1];
35 } EFI_CAPSULE_PEIM_PRIVATE_DATA;
36 #pragma pack()
37 
38 typedef struct {
39   ///
40   /// The physical start address of the resource region.
41   ///
42   EFI_PHYSICAL_ADDRESS        PhysicalStart;
43   ///
44   /// The number of bytes of the resource region.
45   ///
46   UINT64                      ResourceLength;
47 } MEMORY_RESOURCE_DESCRIPTOR;
48 
49 #define CAPSULE_TEST_SIGNATURE SIGNATURE_32('T', 'E', 'S', 'T')
50 
51 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
52 #pragma pack(1)
53 typedef struct {
54   EFI_PHYSICAL_ADDRESS  EntryPoint;
55   EFI_PHYSICAL_ADDRESS  StackBufferBase;
56   UINT64                StackBufferLength;
57   EFI_PHYSICAL_ADDRESS  JumpBuffer;
58   EFI_PHYSICAL_ADDRESS  BlockListAddr;
59   EFI_PHYSICAL_ADDRESS  MemoryResource;
60   EFI_PHYSICAL_ADDRESS  MemoryBase64Ptr;
61   EFI_PHYSICAL_ADDRESS  MemorySize64Ptr;
62   BOOLEAN               Page1GSupport;
63 } SWITCH_32_TO_64_CONTEXT;
64 
65 typedef struct {
66   UINT16                ReturnCs;
67   EFI_PHYSICAL_ADDRESS  ReturnEntryPoint;
68   UINT64                ReturnStatus;
69   //
70   // NOTICE:
71   // Be careful about the Base field of IA32_DESCRIPTOR
72   // that is UINTN type.
73   // To extend new field for this structure, add it to
74   // right before this Gdtr field.
75   //
76   IA32_DESCRIPTOR       Gdtr;
77 } SWITCH_64_TO_32_CONTEXT;
78 #pragma pack()
79 #endif
80 
81 /**
82   The function to coalesce a fragmented capsule in memory.
83 
84   @param PeiServices        General purpose services available to every PEIM.
85   @param BlockListBuffer    Point to the buffer of Capsule Descriptor Variables.
86   @param MemoryResource     Pointer to the buffer of memory resource descriptor.
87   @param MemoryBase         Pointer to the base of a block of memory that we can walk
88                             all over while trying to coalesce our buffers.
89                             On output, this variable will hold the base address of
90                             a coalesced capsule.
91   @param MemorySize         Size of the memory region pointed to by MemoryBase.
92                             On output, this variable will contain the size of the
93                             coalesced capsule.
94 
95   @retval EFI_NOT_FOUND     if we can't determine the boot mode
96                             if the boot mode is not flash-update
97                             if we could not find the capsule descriptors
98 
99   @retval EFI_BUFFER_TOO_SMALL
100                             if we could not coalesce the capsule in the memory
101                             region provided to us
102 
103   @retval EFI_SUCCESS       if there's no capsule, or if we processed the
104                             capsule successfully.
105 **/
106 EFI_STATUS
107 EFIAPI
108 CapsuleDataCoalesce (
109   IN EFI_PEI_SERVICES                **PeiServices,
110   IN EFI_PHYSICAL_ADDRESS            *BlockListBuffer,
111   IN MEMORY_RESOURCE_DESCRIPTOR      *MemoryResource,
112   IN OUT VOID                        **MemoryBase,
113   IN OUT UINTN                       *MemorySize
114   );
115 
116 #endif
117