System Memory
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部分。对于HOB表的详细描述指路https://blog.csdn.net/CeliaQianhj/article/details/6799799。
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) |