You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1_mm_introduction.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,9 @@
29
29
30
30
-->
31
31
32
-
# MM Introduction
32
+
# 1 MM Introduction
33
33
34
-
## SMM and MM Overview
34
+
## 1.1 SMM and MM Overview
35
35
36
36
This section describes the main differences between Traditional SMM and Standalone MM. A detailed comparison of the Traditional MM and Standalone MM load process is described in the PI Specification sections "Initializing Management Mode in MM Traditional Mode" and "Initializing Management Mode in Standalone Mode" respectively.
37
37
@@ -52,12 +52,12 @@ MM Driver:
52
52
- Module type is `MM_STANDALONE`. The entry point of an updatable MM driver follows the PI specification `MM_IMAGE_ENTRY_POINT`.
53
53
- A Standalone MM driver must only refer to MM servers.
54
54
- Launches early in the PEI phase.
55
-
- Two rounds of dispatch depend on the `gEventMmDispatchGuid` event. Refer to section **MM Driver Dispatch** for details.
56
-
- Cannot access any non-MMRAM memory unless the `MmUnblockMemoryRequest()` API is called for the non-MMRAM memory. Refer to section **Non-MMRAM Access** for details.
57
-
- Uses MM self-owned HOBs. Refer to section **MM HOBs** for details.
58
-
- Early memory protection in PEI: `StandaloneMmCore` installs the `EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE` once the second round of dispatch finishes. Refer to section **Memory Protection** for details.
55
+
- Two rounds of dispatch depend on the `gEventMmDispatchGuid` event. Refer to section **1.2 MM Driver Dispatch** for details.
56
+
- Cannot access any non-MMRAM memory unless the `MmUnblockMemoryRequest()` API is called for the non-MMRAM memory. Refer to section **1.4 Non-MMRAM Access** for details.
57
+
- Uses MM self-owned HOBs. Refer to section **1.5 MM HOBs** for details.
58
+
- Early memory protection in PEI: `StandaloneMmCore` installs the `EDKII_PI_SMM_MEMORY_ATTRIBUTES_TABLE` once the second round of dispatch finishes. Refer to section **1.7 Memory Protection** for details.
59
59
60
-
## MM Driver Dispatch
60
+
## 1.2 MM Driver Dispatch
61
61
62
62
For traditional SMM drivers, they are dispatched within multiple rounds: The dispatch is hooked on the `gEfiEventDxeDispatchGuid` event, which is signaled by DXE Core when DXE Core finishes one round of dispatch.
63
63
@@ -71,7 +71,7 @@ The following flow chart describes the MM driver dispatch flow:
71
71

72
72
###### Figure 1: MM Driver Dispatch Flow
73
73
74
-
## MM Communication Buffer
74
+
## 1.3 MM Communication Buffer
75
75
76
76
MM communication buffer is specific memory regions used for communication between the Non-MM and MM environment.
77
77
@@ -89,7 +89,7 @@ Every communication flow is as follows where steps #2, #3, and #4 run inside MM:
89
89
90
90
By following the above, the `CommBuffer` used by the Communication PPI/Protocol is referred to as the **Primary Buffer**. Additionally, other non-MMRAM memory for specific MM driver usage are termed **Non-Primary Buffer**. Those buffer can be pointed from the MM HOBs, or pointed from the `CommBuffer`. Both the Primary Buffer and Non-Primary Buffer used by MM drivers should be validated for accessibility before use.
91
91
92
-
## Non-MMRAM Access
92
+
## 1.4 Non-MMRAM Access
93
93
94
94
Any memory outside of the MMRAM (non-MMRAM) that needs to be accessed by MMI handlers must be explicitly declared as "Unblock Mem" through `MmUnblockMemoryRequest()` (`MdePkg/Include/Library/MmUnblockMemoryLib.h`).
95
95
@@ -100,13 +100,13 @@ Requirements for marking the non-MMRAM as "Unblocked":
100
100
101
101
`StandaloneMmIpl` builds the corresponding `EFI_HOB_RESOURCE_DESCRIPTOR` in the MM HOB list for all unblocked non-MMRAM memory access. Any non-MMRAM memory region that is not described by `EFI_HOB_RESOURCE_DESCRIPTOR` in the MM HOB list is not accessible from SMM mode.
102
102
103
-
## MM HOBs
103
+
## 1.5 MM HOBs
104
104
105
105
PEI HOBs are used by the traditional SMM. The lifecycle of traditional SMM HOBs is limited to the boot phase, and once entering the runtime phase, HOBs can no longer be accessed or used in the SMM. In contrast, Standalone MM is designed to maintain the validity of its self-owned HOBs throughout the entire lifecycle, including the runtime phase.
106
106
107
107
`StandaloneMmIpl` is not required to pass the entire PEI HOB list to the SMM foundation. Instead, it must create and pass a specific subset of HOBs that are essential for the operation of the Standalone MM environment. Overall, MM self-owned HOBs can be divided into two categories: **MM Foundation HOBs** and **MM Platform HOBs**.
108
108
109
-
### MM Foundation HOBs
109
+
### 1.5.1 MM Foundation HOBs
110
110
111
111
The MM Foundation HOBs are a set of HOBs that are created by the common logic within the `StandaloneMmIpl`. These HOBs provide the necessary information about the firmware environment and memory regions that the MM Core and drivers will interact with. The following HOBs are created by `StandaloneMmIpl` common logic; hence, they should **NOT** be created by the platform part:
112
112
@@ -123,33 +123,33 @@ The MM Foundation HOBs are a set of HOBs that are created by the common logic wi
123
123
- Single GUIDed (`gEfiAcpiVariableGuid`) HOB to identify the S3 data root region in x86.
124
124
- Single GUIDed (`gMmStatusCodeUseSerialHobGuid`) HOB to describe whether the status code uses the serial port or not.
125
125
126
-
### MM Platform HOBs
126
+
### 1.5.2 MM Platform HOBs
127
127
128
128
In addition to the MM Foundation HOBs, the `StandaloneMmIpl` will consume the `MmPlatformHobProducerLib/CreateMmPlatformHob()` to create platform-specific HOBs that are necessary for the Standalone MM environment. These HOBs provide information and configuration details that are unique to the platform on which the system is running. The creation of these HOBs ensures that the MM environment is properly configured to interact with the platform's hardware and firmware features.
129
129
130
-
## Communication between SMM/Non-SMM
130
+
## 1.6 Communication between SMM/Non-SMM
131
131
The following mechanisms are provided for communication between SMM and Non-SMM:
132
132
133
133
1. Using `CommBuffer` with Protocol `EFI_MM_COMMUNICATION_PROTOCOL` or PPI `EFI_PEI_MM_COMMUNICATION_PPI`:
134
134
- Requires dependency on the `EFI_MM_COMMUNICATION_PROTOCOL` or `EFI_PEI_MM_COMMUNICATION_PPI`.
135
135
- Triggers an SMI when sharing data between SMM and Non-SMM code.
136
136
137
137
2. Using "Unblock Mem":
138
-
- Must meet the usage requirements. Refer to the**Non-MMRAM Access** section for details.
138
+
- Must meet the usage requirements. Refer to section**1.4 Non-MMRAM Access** for details.
139
139
140
140
3. Using MM Guided HOBs:
141
141
- For data sizes < 64KB: Embed the data directly into the HOB.
142
142
143
143
Option #1 is suitable when the data cannot be finalized before launching MM or when the data flow is bidirectional between SMM and Non-SMM code. Option #2 is necessary for ASL code to pass data to the SW SMI handler. It is also an alternative solution to avoid triggering an SMI for latency considerations. Option #3 is ideal when the data size is small than 64K and it can be finalized before launching MM and the data flow is unidirectional between SMM and Non-SMM code.
144
144
145
-
But in cases where silicon initialization code does not want to rely on the communication PPI, the data size to be passed to MM exceeds 64KB, and the memory cannot be runtime-accessible due to the requirement for Runtime Non-SMM invisibility, then options #1 and #2 are not applicable. Option #3 requires splitting the data into multiple Guided HOBs, which increases code complexity due to the need to reassemble the data in MM. To simplify this, a fourth solution was introduced:
145
+
But in cases where silicon initialization code does not want to rely on the communication PPI, the data size to be passed to MM exceeds 64KB, and the memory cannot be runtime-accessible due to the requirement for Runtime Non-SMM invisibility, then options #1 and #2 are not applicable. Option #3 requires splitting the data into multiple Guided HOBs, which increases code complexity due to the need to reassemble the data in MM. To simplify this, a fourth method was introduced as below:
146
146
147
147
4. Using MM Memory Allocation HOBs with BSData and Non-Zero GUID:
148
148
- Memory Producer (PEIM): Create a Memory Allocation HOB pointing to a BSData memory region and assign a Non-Zero GUID to the corresponding HOB.
149
149
- MM Core: Migrate the Memory Allocation HOB into MMRAM by copying the data from Non-MMRAM to MMRAM. Refer to `MigrateMemoryAllocationHobs()` in `Edk2/StandaloneMmPkg/Core/StandaloneMmCore.c`.
150
150
- Memory Consumer (MM Drivers): Retrieve the memory from the Memory Allocation HOB using its assigned Non-Zero GUID.
151
151
152
-
## Memory Protection
152
+
## 1.7 Memory Protection
153
153
154
154
The `PiSmmCpuStandaloneMm` driver creates a page table used in MM mode according to the `EFI_HOB_RESOURCE_DESCRIPTOR` in the MM HOB list. The newly created page table controls memory accessibility in MM.
Copy file name to clipboardExpand all lines: 2_smm_to_mm_porting_guide.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,9 @@
29
29
30
30
-->
31
31
32
-
# SMM to MM Porting Guide
32
+
# 2 SMM to MM Porting Guide
33
33
34
-
## Porting Design Overview
34
+
## 2.1 Porting Design Overview
35
35
36
36
This section provides instructions on how to convert traditional SMM drivers to MM drivers. A traditional SMM driver may need to be split into one or more drivers when transitioning to a Standalone MM driver:
37
37
@@ -46,7 +46,7 @@ The figure below illustrates how to convert a traditional SMM driver to an MM dr
46
46

47
47
###### Figure 2: SMM to MM Conversion
48
48
49
-
## Checkpoints in Converted MM Driver
49
+
## 2.2 Checkpoints in Converted MM Driver
50
50
51
51
To ensure the converted Standalone MM driver is functional, the following checkpoints should be verified:
52
52
@@ -58,14 +58,14 @@ To ensure the converted Standalone MM driver is functional, the following checkp
58
58
59
59
2.**Checkpoint 2: Confirm Necessary HOBs Have Been Migrated to MM HOB Database**
60
60
61
-
Refer to section **MM HOBs** for details.
61
+
Refer to section **1.5 MM HOBs** for details.
62
62
**Note**: HOB creation cannot depend on the end of the PEI notify event if the HOB needs to be accessed in MM. This is because the `StandaloneMmIpl` PEIM is dispatched before the end of PEI, leaving no opportunity for the IPL to migrate newly created HOBs to the MM HOB database.
63
63
64
64
3.**Checkpoint 3: Check Dependencies on `gBS`, `gDS`, `gRT`, or ACPI-Related Services**
65
65
66
66
If the original SMM driver depends on DXE protocols (e.g., `gBS` or `gDS`), it can only be used during the DXE phase. And ACPI tables must be installed during the DXE phase.
67
67
68
-
1.**Checkpoint 4: Check Access to Non-MMRAM**
68
+
4.**Checkpoint 4: Check Access to Non-MMRAM**
69
69
70
70
Non-MMRAM access typically falls into the following cases:
71
71
-**Case 1**: Accessing a HOB that contains a pointer or address pointing to non-MMRAM.
@@ -75,13 +75,13 @@ To ensure the converted Standalone MM driver is functional, the following checkp
75
75
-**Case 3**: The registered SMI handler uses `gMmst->MmiHandlerRegister(SmiHandler, NULL, ...)` or MM Child Dispatch protocols (e.g., `SwDispatch->Register`).
76
76
If it accesses any non-MMRAM buffer, use `MmUnblockMemoryRequest()` in the PEI phase before the `StandaloneMmIpl` entry point.
Refer to section **Non-MMRAM Access** for definitions of Primary and Non-Primary Buffers. Both types of buffers used by MM drivers should be validated for accessibility before use:
80
+
Refer to section **1.3 MM Communication Buffer** for definitions of Primary and Non-Primary Buffers. Both types of buffers used by MM drivers should be validated for accessibility before use:
81
81
- Use `XXXIsPrimaryBufferValid()` to validate the `CommBuffer`.
82
82
- Use `XXXIsNonPrimaryBufferValid()` to validate non-MMRAM memory pointed from the `CommBuffer` or MM HOB.
83
83
84
-
## Sample: SMM to MM Conversion
84
+
## 2.3 Sample: SMM to MM Conversion
85
85
86
86
The Tcg2 SMM and MM modules will be used as a sample to highlight the key points to consider when converting a traditional SMM module to an MM module:
87
87
@@ -127,7 +127,7 @@ The Tcg2 SMM and MM modules will be used as a sample to highlight the key points
127
127
128
128
The `mTcgNvs` global variable in the Tcg2 SMM module plays a crucial role in TPM operations, especially when updating the ACPI table and handling SMI callback functions.
129
129
`mTcgNvs` is the operation region in the TCG ACPI table and must be a non-MMRAM memory buffer pointed from the `CommBuffer`.
130
-
According to Section **Non-MMRAM Access**, it must be unblocked using `MmUnblockMemoryRequest()`.
130
+
According to Section **1.4 Non-MMRAM Access**, it must be unblocked using `MmUnblockMemoryRequest()`.
131
131
The related operation can be found in the `BuildTcg2AcpiCommunicateBufferHob()` function in `Edk2\SecurityPkg\Tcg\Tcg2Config\Tcg2ConfigPei.inf`.
0 commit comments