System Memory
- MEMORY SERVICES
- HOB TYPE
-
- RESOURCE HOB
-
- Type:
- Attributes:
- (System)MEMORY TYPE
- DXE/SMM: PAGE ALLOCATION TYPE
- PEI MEMORY LAYOUT
- DXE MEMORY LAYOUT
- MEMMAP
MEMORY SERVICES
- PEI on CAR and System Memory
- CreateHob
- AllocatePool: Light version. Don』t support memory type. No FreePool API. It bases on HOB.
- AllocatePages/FreePages: Don』t support memory allocate type.
- DXE on System Memory
- AllocatePool/FreePool
- AllocatePages/FreePages
- SMM on SMRAM
- AllocatePool/FreePool: support runtime data/code only
- AllocatePages/FreePages: support runtime data/code only
HOB TYPE
根據使用的不同需求,定義以下型別:
- EFI_HOB_TYPE_HANDOFF: Basic Hob information,描述Hob空間的起始結束地址以及那些空間可用
- EFI_HOB_TYPE_MEMORY_ALLOCATION:描述已被申請的memory的起始地址和結束地址
- Describe the allocated page memory base address, size and type
- EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:描述系統資源及屬性情況,包括系統空間屬性等
- Describe the system resource and attribute, include memory,SMRAM IO and MMIO
- EFI_HOB_TYPE_GUID_EXTENSION:為了在模組和內部的function之間共享資料
- Main usage is to share data between pre-memory and after-memory
- EFI_HOB_TYPE_FV:每個FV可以有一個HOB,Fv Hob是給DXE階段使用,
- FV reported to DXE phase
- EFI_HOB_TYPE_CPU
- EFI_HOB_TYPE_MEMORY_POOL
在開發過程中可能用到的,RESOURCE_DESCRIPTOR、GUID_EXTENSION、FV
RESOURCE HOB
Type:
? EFI_RESOURCE_SYSTEM_MEMORY:記憶體,可以執行程式碼儲存資料等操作
? EFI_RESOURCE_MEMORY_MAPPED_IO
? EFI_RESOURCE_IO
? EFI_RESOURCE_FIRMWARE_DEVICE:描述flash這一塊空間
? EFI_RESOURCE_MEMORY_MAPPED_IO_PORT
? EFI_RESOURCE_MEMORY_RESERVED
? EFI_RESOURCE_IO_RESERVED
Attributes:
? EFI_RESOURCE_ATTRIBUTE_PRESENT:是否存在
? EFI_RESOURCE_ATTRIBUTE_INITIALIZED:是否初始化
? EFI_RESOURCE_ATTRIBUTE_TESTED:是否已測試
? EFI_RESOURCE_ATTRIBUTE_PERSISTENT:是否一直存在(掉電不遺失)
(System)MEMORY TYPE
-
EfiConventionalMemory: Available memory space
-
EfiLoaderCode: UEFI Application code
-
EfiLoaderData: UEFI Application data
-
EfiBootServicesCode: UEFI/PEI/DXE driver
-
EfiBootServicesData: UEFI/PEI/DXE driver allocated memory
-
EfiPersistentMemory
-
EfiRuntimeServicesCode: Runtime driver. It can』t be used by OS.
-
EfiRuntimeServicesData: Runtime data. It can』t be used by OS.
-
EfiReservedMemoryType: Reserved memory in BIOS. It can』t be used by OS.
-
EfiACPIReclaimMemory: Used by ACPI.
-
EfiACPIMemoryNVS: Used by ACPI. It can』t be used by OS.
-
EfiMemoryMappedIO
-
EfiMemoryMappedIOPortSpace
DXE/SMM: PAGE ALLOCATION TYPE
? AllocateAnyPages: Allocate memory in the available memory space.
? AllocateMaxAddress: Allocate memory based on the specified max address.
? AllocateAddress: Allocate memory at the specified base address.
PEI MEMORY LAYOUT

上圖中:PHIT就是一個HOB,Handoff型別,包含基本的information,由下往上,PHIT作為第一個HOB,管理方式為不斷疊加,一旦某塊資料越界,整體的HOB會毀壞,但由於PEI階段的resource有限,尚不構成影響。某塊HOB失去作用時,也是沒有辦法取走的,只能不停新增。memory為從高往低進行分配,與HOB並不從衝突,當無空間可用則會報錯out of resource。Allocate申請的記憶體為Free space部分
DXE MEMORY LAYOUT

- Top reserved memory ranges are specified by EFI_MEMORY_TYPE_INFORMATION.
- Memory allocation is from top to bottom.
- Memory allocation is from its reserved memory type range. If no enough, it will be allocated from the remaining memory.
- Pool and Page are in the same memory range.
- PEI Memory is reported in PEI phase.
MEMMAP
memorymap 這個command會羅列出當前系統中所有的memory,包括其分配情況,剩餘量等。
| Type | Start | End # | Pages | Attributes |
|---|---|---|---|---|
| BS_Data | 00000000B5002000 | -00000000B53B9FFF | 00000000000003B8 | 000000000000000F |
| BS_Code | 00000000B53BA000 | -00000000B53E6FFF | 000000000000002D | 000000000000000F |
| … | ||||
| Reserved | 00000000BBE5F000 | -00000000BBE5FFFF | 0000000000000001 | 000000000000000F |
| ACPI_Recl | 00000000BBE60000 | -00000000BC02FFFF | 00000000000001D0 | 000000000000000F |
| ACPI_NVS | 00000000BC030000 | -00000000BC08FFFF | 0000000000000060 | 000000000000000F |
| RT_Data | 00000000BC090000 | -00000000BF67FFFF | 00000000000035F0 | 800000000000000F |
| RT_Code | 00000000BF7C0000 | -00000000BFC7FFFF | 00000000000004C0 | 800000000000000F |
| Available | 0000400100000000 | -00004007FFFFFFFF | 0000000000700000 | 000000000000000F |
| MMIO | 00001000026D0000 | -00001000026DFFFF | 0000000000000010 | 8000000000000000 |
| Reserved : | 869 Pages (3,559,424 Bytes) |
|---|---|
| LoaderCode: | 339 Pages (1,388,544 Bytes) |
| LoaderData: | 0 Pages (0 Bytes) |
| BS_Code : | 11,391 Pages (46,657,536 Bytes) |
| BS_Data : | 16,957 Pages (69,455,872 Bytes) |
| RT_Code : | 1,216 Pages (4,980,736 Bytes) |
| RT_Data : | 16,496 Pages (67,567,616 Bytes) |
| ACPI_Recl : | 479 Pages (1,961,984 Bytes) |
| ACPI_NVS : | 96 Pages (393,216 Bytes) |
| MMIO : | 32 Pages (131,072 Bytes) |
| MMIO_ | Port : 0 Pages (0 Bytes) |
| PalCode : | 0 Pages (0 Bytes) |
| Available : | 16,401,949 Pages (67,182,383,104 Bytes) |
| Persistent: | 0 Pages (0 Bytes) |
| Total Memory: | 64,253 MB (67,374,788,608 Bytes) |