A Tour Beyond BIOS Memory Map in UEFI BIOS
A Tour Beyond BIOS Memory Map in UEFI BIOS
Jiewen Yao
Intel Corporation
Vincent J. Zimmer
Intel Corporation
February 2015
Executive Summary
This paper introduces the design of the memory map in a UEFI BIOS.
Prerequisite
This paper assumes that audience has basic EDKII/UEFI firmware development
experience.
ii
Table of Contents
Overview ..................................................................................................................................... 4
Introduction to memory map............................................................................................... 4
Memory Map Hardware Perspective .............................................................................. 5
System Memory ................................................................................................................... 5
Memory Mapped IO ............................................................................................................. 8
Memory Map Firmware Perspective ............................................................................ 10
Memory Map in PI specification (PEI Phase) ................................................................. 10
Memory Map in PI specification (DXE Phase) ............................................................... 13
Memory Map in UEFI specification .................................................................................. 14
Memory Map OS Perspective ......................................................................................... 16
Memory Map in UEFI specification .................................................................................. 16
Memory Map in ACPI specification ................................................................................. 18
Memory Map in S3 resume .............................................................................................. 19
Memory Map in S4 resume .............................................................................................. 19
Put it all together ................................................................................................................ 22
Conclusion ................................................................................................................................ 23
Glossary .................................................................................................................................... 24
References ................................................................................................................................ 25
iii
Overview
The main job of BIOS is to initialize the platform hardware and report information to generic
operating system. The memory map is one of most important information. Only if operating system
knows how the memory is allocated, it can load the kernel, driver and application to right place.
In this paper, we will discuss how memory map is reported in a UEFI BIOS, and how OS or OS
loader can leverage the memory type and attribute defined in UEFI specification to do protection.
System Memory
The system memory means the main dynamic random access memory (DRAM). It can be
classified as below:
1) Legacy region less-than 1MiB
2) Main memory between 1MiB and 4GiB
3) Main memory great-than 4GiB
Legacy Region is for legacy OS or device consideration. (See figure 1) It is divided into
following area:
0640KiB (0-0xA0000): DOS Area. The normal DRAM is for legacy OS (DOS) or boot
loader usage.
640768KiB (0xA0000-0xC0000): SMRAM/Legacy Video Buffer Area. This region can
be configured as SMM memory, or mapped IO for legacy video buffer.
768896KiB (0xC0000-0xE0000): Expansion Area for legacy option ROM. This region
is DRAM and could be locked to be read-only.
896KiB1MiB (0xE0000-0x100000): System BIOS Area. This region could be DRAM
or could be configured as memory IO to flash region.
Figure 1
The main memory between 1MiB and 4GiB is for traditional OS. (See figure 2) However,
memory region just below 4GiB is occupied by memory-mapped IO, like flash, CPU APIC,
TPM. There is a dedicated register Top of Low Usable DRAM (TOLUD) to indicate the bar.
Memory between 1MiB and TOLUD is divided into following area:
Normal DRAM: Used by OS.
ISA Hole (15MiB16MiB): Optional feature. If enabled, the normal DRAM is disabled
by opening the hole.
Protected Memory Range (PMR) below 4GiB: Programmable optional feature. If enabled,
this DRAM cannot be accessed by DMA.
DRAM Protected Range (DPR): Optional feature. If enabled, this DRAM cannot be
accessed by DMA.
Top memory for SMM: TSEG (Top Segment) SMRAM. If enabled, this DRAM can be
access if and only if CPU in SMM mode.
Top memory for SMM: TSEG (Top Segment) SMRAM. If enabled, this DRAM can be
access if and only if CPU in SMM mode.
Top memory for integrated graphic device (IGD): IGD stolen memory. If enabled, this
DRAM is served for IGD.
Top memory for Intel Manageability Engine (ME): ME stolen memory. If enabled, this
DRAM is served for ME. If the total memory is greater-than-4GiB, the ME stolen
memory will be greater-than-4Gib. So this region is always on top of physical memory
and it is not covered by TOLUD.
Figure 2
The main memory greater-than 4GiB is also for traditional OS. (See figure 3) If there is DRAM
between TOLUD and 4GiB, this memory can be reclaimed by chipset, to map to greater-than
4GiB. There is a set of dedicated register Reclaim BASE/SIZE to indicate the remap action. As a
result, the physical memory view (from DRAM controller) might be less-than-4GiB, while the
system memory view (from Host CPU) could be greater-than-4GiB. There is a dedicated register
Top of Upper Usable DRAM (TOUUD) to indicate the bar for highest system memory. Memory
greater-than-4GiB has below area:
Normal DRAM: Used by OS.
Protected Memory Range (PMR) above 4GiB: Programmable optional feature. If enabled,
this DRAM cannot be accessed by DMA.
Top memory for Intel Manageability Engine (ME): ME stolen memory. If enabled, this
DRAM is served for ME. This region is always on top of physical memory and it is not
covered by TOUUD.
Figure 3
7
Memory Mapped IO
The memory mapped IO provides methods of performing input/output between the CPU
and peripheral devices. (See figure 4) In a typical x86 platform, there are BIOS (flash area), MSI
interrupts, CPU local APIC, I/O APIC, PCI Express configuration space, TPM device space.
Figure 4
This paper will focus more on system memory. Since the memory-mapped IO is platform
specific, please refer to chipset document for detail.
A typical hardware memory map on an X86 platform is like below:
===============================================================================
PCI Express: 0xE0000000 - 0x10000000
IO APIC:
0xFEC00000 - 0x1000
HPET:
0xFED00000 - 0x400
MCH BAR:
0xFED10000 - 0x8000
DMI BAR:
0xFED18000 - 0x1000
EGP BAR:
0xFED19000 - 0x1000
RCBA:
0xFED1C000 - 0x4000
Intel TXT:
0xFED20000 - 0x20000
TPM:
0xFED40000 - 0x5000
Intel PTT:
0xFED70000 - 0x1000
Intel VTd:
0xFED90000 - 0x4000
Local APIC: 0xFEE00000 - 0x100000
Flash:
0xFF000000 - 0x1000000
===============================================================================
Summary
This section gives introduction on memory map from hardware perspective. We discussed how
system memory and memory mapped IO look like by using an Intel x86 platform as example.
10
does not describe how memory is used but instead describes the attributes of the physical
memory present.
The HOB consumer phase reads all resource descriptor HOBs when it established the initial
Global Coherency Domain (GCD) map. The minimum requirement for the HOB producer phase
is that executable content in the HOB producer phase report one of the following:
1) The resources that are necessary to start the HOB consumer phase
2) The fixed resources that are not captured by HOB consumer phase driver components
that were started prior to the dynamic system configuration performed by the platform
boot-policy phase.
For example, executable content in the HOB producer phase should report any physical memory
found during the HOB producer phase. Executable content in the HOB producer phase does not
need to report fixed system resources like IO or MMIO, because these fixed resources can be
allocated from the GCD by a platform-specific chipset driver loading in the HOB consumer
phase prior to the platform boot-policy phase, for example.
In most platforms, once memory initialization is done, the memory reference code (MRC)
wrapper will report all system memory. The platform initialization will report all fixed location
MMIO instead.
A typical resource description HOB on an X86 platform is like below:
===============================================================================
Resource Descriptor HOBs
BA=0000000077161000 L=000000000369E000 Attr=0000000000003C07 Tested Mem
BA=0000000000000000 L=00000000000A0000 Attr=0000000000003C07 Tested Mem
BA=00000000000A0000 L=0000000000020000 Attr=0000000000000000 Reserved Mem
BA=0000000000100000 L=0000000077061000 Attr=0000000000003C07 Tested Mem
BA=000000007C000000 L=0000000002800000 Attr=0000000000000000 Reserved Mem
BA=000000007B000000 L=0000000001000000 Attr=0000000000000000 Reserved Mem
BA=000000007A800000 L=0000000000800000 Attr=0000000000000000 Reserved Mem
BA=000000007A7FF000 L=0000000000001000 Attr=0000000000000000 Reserved Mem
BA=0000000100000000 L=0000000000800000 Attr=0000000000003C03 Init Mem
BA=00000000FED10000 L=0000000000008000 Attr=0000000000000403 MMIO
BA=00000000FED18000 L=0000000000001000 Attr=0000000000000403 MMIO
BA=00000000FED19000 L=0000000000001000 Attr=0000000000000403 MMIO
BA=00000000FED84000 L=0000000000001000 Attr=0000000000000403 MMIO
BA=00000000E0000000 L=0000000010000000 Attr=0000000000000403 MMIO
BA=00000000FEC00000 L=0000000000001000 Attr=0000000000000403 MMIO
BA=00000000FED00000 L=0000000000004000 Attr=0000000000000403 MMIO
BA=00000000FED1C000 L=0000000000004000 Attr=0000000000000403 MMIO
BA=00000000FEE00000 L=0000000000001000 Attr=0000000000000403 MMIO
BA=00000000FFA00000 L=0000000000600000 Attr=0000000000000403 MMIO
===============================================================================
Besides resource descriptor HOB, firmware volume HOB details the location of firmware
volumes that contain firmware files, and firmware volume2 HOB details the location of a
firmware volume which was extracted from a file within another firmware volume. By recording
the volume and file name, the HOB consumer phase can avoid processing the same file again.
A typical firmware volume HOB on an X86 platform is like below:
===============================================================================
FV HOBs
BA=00000000FFA00000 L=0000000000020000
BA=00000000FFA00000 L=0000000000600000
11
BA=000000007847A000 L=0000000000CF0000
FV2 HOBs
BA=000000007847A000 L=0000000000CF0000 Fv={00000000-0000-0000-0000-000000000000}
File={9E21FD93-9C72-4C15-8C4B-E77F1DB2D792}
===============================================================================
The resource descriptor HOB does not describe how memory is used. This work is done by
memory allocation HOB. It describes all memory ranges used during the HOB producer phase
that exist outside the HOB list. This HOB type describes how memory is used, not the physical
attributes of memory.
The HOB consumer phase does not make assumptions about the contents of the memory that is
allocated by the memory allocation HOB, and it will not move the data unless it has explicit
knowledge of the memory allocation HOBs Name (EFI_GUID). Memory may be allocated in
either the HOB producer phase memory area or other areas of present and initialized system
memory.
A HOB consumer phase driver that corresponds to the specific Name GUIDed memory
allocation HOB can parse the HOB list to find the specifically named memory allocation HOB
and then manipulate the memory space as defined by the usage model for that GUID. For
example:
1) BSP stack memory allocation HOB
2) BSP store memory allocation HOB
3) Memory allocation module HOB
A typical memory allocation HOB on an X86 platform is like below:
===============================================================================
Memory Allocation HOBs
BA=00000000783D0000 L=0000000000020000 Name={4ED4BF27-4092-42E9-807D-527B1D00C9BD}
BS Data (STACK)
BA=000000007A150000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
BS Code
BA=000000007A14F000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
BS Data
BA=000000007A139000 L=0000000000016000 Name={00000000-0000-0000-0000-000000000000}
BS Data
BA=00000000FED10000 L=0000000000008000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FED18000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FED19000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FED84000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000E0000000 L=0000000010000000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FEC00000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FED00000 L=0000000000004000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FED1C000 L=0000000000004000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FEE00000 L=0000000000001000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
BA=00000000FFA00000 L=0000000000600000 Name={00000000-0000-0000-0000-000000000000}
Loader Code
12
13
The GCD memory space map is initialized from the HOB list that is passed to the entry point of
the DXE Foundation. GCD memory space map must reflect the memory regions described in the
HOB list. A platform may have driver to add more memory regions which is not needed to be
reported in PEI phase. For example, PciHostBridge driver may add MMIO for PCI express
configuration space and add MMIO for PCI BAR.
A typical GCD memory map on an X86 platform is like below:
===============================================================================
U
RXRWCWWWU
Base Address
End Address
Type TPPPEBTCC Image
Device
================ ================ ==== ========= ================ ================
0000000000000000-000000000009FFFF SYS 0----1000 000000007A15EE18
00000000000A0000-00000000000BFFFF RSVD 0-------00000000000C0000-00000000000FFFFF NE
0000000000100000-000000007A7FEFFF SYS 0----1000 000000007A15EE18
000000007A7FF000-000000007E7FFFFF RSVD 0-------000000007E800000-000000007E80FFFF MMIO 0-------- 0000000076A31318
000000007E810000-000000007E81FFFF MMIO 0-------- 00000000769D6918
000000007E820000-000000007FFFFFFF MMIO 0-------0000000080000000-00000000911FFFFF MMIO 0-------- 0000000077697798
0000000091200000-00000000DFFFFFFF MMIO 0-------00000000E0000000-00000000E00F7FFF MMIO 0-------1 000000007A15EE18
00000000E00F8000-00000000E00F8FFF MMIO 1-------1 000000007A15EE18
00000000E00F9000-00000000EFFFFFFF MMIO 0-------1 000000007A15EE18
00000000F0000000-00000000FE100FFF NE
00000000FE101000-00000000FE112FFF RSVD 0-------- 0000000077240318
00000000FE113000-00000000FEBFFFFF NE
00000000FEC00000-00000000FEC00FFF MMIO 0-------1 000000007A15EE18
00000000FEC01000-00000000FECFFFFF NE
00000000FED00000-00000000FED03FFF MMIO 0-------1 000000007A15EE18
00000000FED04000-00000000FED0FFFF NE
00000000FED10000-00000000FED19FFF MMIO 0-------1 000000007A15EE18
00000000FED1A000-00000000FED1BFFF NE
00000000FED1C000-00000000FED1FFFF MMIO 1-------1 000000007A15EE18
00000000FED20000-00000000FED83FFF NE
00000000FED84000-00000000FED84FFF MMIO 0-------1 000000007A15EE18
00000000FED85000-00000000FEDFFFFF NE
00000000FEE00000-00000000FEE00FFF MMIO 0-------1 000000007A15EE18
00000000FEE01000-00000000FF9FFFFF NE
00000000FFA00000-00000000FFA1FFFF MMIO 1-------1 000000007A15EE18
00000000FFA20000-00000000FFFFFFFF MMIO 1-------1
0000000100000000-00000001007FFFFF SYS 0----1000 000000007A15EE18
0000000100800000-0000007FFFFFFFFF NE
===============================================================================
14
15
16
Memory mapping of PCI devices, ISA Option ROMs, and ISA Plug and Play cards.
Because the OS has mechanisms available to detect them. For example, PCI BAR MMIO
can be got by standard PCI bus enumeration. On-board device (e.g. TPM) MMIO could
be got by ACPI _CRS method.
Standard PC address ranges are not reported. For example, video memory at 0xA0000 to
0xBFFFF physical addresses are not described by this function.
17
Available
MMIO
MMIO
MMIO
0000000100000000-00000001007FFFFF
00000000E00F8000-00000000E00F8FFF
00000000FED1C000-00000000FED1FFFF
00000000FFA00000-00000000FFFFFFFF
0000000000000800
0000000000000001
0000000000000004
0000000000000600
000000000000000F
8000000000000001
8000000000000001
8000000000000001
Reserved :
LoaderCode:
LoaderData:
BS_Code
:
BS_Data
:
RT_Code
:
RT_Data
:
ACPI_Recl :
ACPI_NVS :
MMIO
:
MMIO_Port :
PalCode
:
Available :
18
E820[19]: 0x
FED10000 ---- 0x
FED18000, Type = 0x2
E820[20]: 0x
FED18000 ---- 0x
FED19000, Type = 0x2
E820[21]: 0x
FED19000 ---- 0x
FED1A000, Type = 0x2
E820[22]: 0x
FED1C000 ---- 0x
FED20000, Type = 0x2
E820[23]: 0x
FED84000 ---- 0x
FED85000, Type = 0x2
E820[24]: 0x
FEE00000 ---- 0x
FEE01000, Type = 0x2
E820[25]: 0x
FFA00000 ---- 0x
100000000, Type = 0x2
E820[26]: 0x
100000000 ---- 0x
100800000, Type = 0x1
===============================================================================
Besides E820 table, ACPI specification requires each device node to report current resource by
using _CRS method. _CRS can return any resource, including Memory, IO, IRQ, etc. If an
MMIO not assigned to standard PCI MMIO bar, it should be reported here.
Sample memory resource returned by ASL _CRS on an X86 platform is below:
===============================================================================
Device(PDRC): Memory32Fixed (ReadWrite, 0xE0000000, 0x10000000)// PCI Express
Device(HPET): Memory32Fixed (ReadWrite, 0xFED00000, 0x400)
// HPET
Device(PDRC): Memory32Fixed (ReadWrite, 0xFED10000, 0x8000)
// Intel MCH BAR
Device(PDRC): Memory32Fixed (ReadWrite, 0xFED18000, 0x1000)
// Intel DMI BAR
Device(PDRC): Memory32Fixed (ReadWrite, 0xFED19000, 0x1000)
// Intel EGP BAR
Device(PDRC): Memory32Fixed (ReadWrite, 0xFED1C000, 0x4000)
// Intel RCBA
Device(PDRC): Memory32Fixed (ReadWrite, 0xFED20000, 0x20000)
// Intel TXT
Device(TPM) : Memory32Fixed (ReadOnly, 0xFED40000, 0x5000)
// TPM
Device(PTT) : Memory32Fixed (ReadOnly, 0xFED70000, 0x1000)
// Intel PTT
Device(PDRC): Memory32Fixed (ReadOnly, 0xFED90000, 0x4000)
// Intel VTd
Device(PDRC): Memory32Fixed (ReadOnly, 0xFEE00000, 0x100000) // Local APIC
Device(FWHD): Memory32Fixed (ReadOnly, 0xFF000000, 0x1000000) // Flash
Device(PCI0): DWordMemory(ResourceProducer,PosDecode,MinFixed,MaxFixed,Cacheable,
ReadWrite,0x00,<TOLUD>,0xFEAFFFFF,0x00,<MMIO_LO_LEN>,,,PM01) // Low MMIO
Device(PCI0): QWordMemory(ResourceProducer,PosDecode,MinFixed,MaxFixed,Cacheable,
ReadWrite,0x00,<TOUUD>,<MMIO_HIGH>,0x00,<MMIO_HI_LEN>,,,PM02) // High MMIO
===============================================================================
19
Figure 5
The BIN data structure is stored in gMemoryTypeInformation at
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdeModulePkg/Core/Dxe/Mem/Page.c
During first boot, platform need report MemoryTypeInformation HOB to try to allocate BIN for
each of those types. MRC wrapper may get this information to reserve BIN range, and allocate
memory for PEI core below BIN. DXE core gets this HOB and pre-allocate BIN for each type.
Then if DXE core gets request to allocate memory for this type, DXE core will find the free
memory in BIN first. Only if there is no enough memory in BIN, DXE core will allocate free
memory outside BIN. DXE core also create UEFI configuration table for the
MemoryTypeInformation to record the memory usage in current boot.
Then in BDS after ReadyToBoot event, BdsSetMemoryTypeInformationVariable() will check if
BIN can hold the current allocated pages, by comparing the memory information in variable
(BIN usage) and in UEFI configuration table (current usage).
https://svn.code.sf.net/p/edk2/code/trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsL
ib/BdsMisc.c
If all BIN can hold current pages, that means there is no fragmentation in memory page. If some
BIN is smaller than current allocated pages, that means there is fragmentation.
BdsSetMemoryTypeInformationVariable() will set MemoryTypeInformation variable to save the
expected BIN size, then reset system. During next boot, platform can get
20
Figure 6
A sample Memory Type Information reporting (BIN not big enough and reset required) on an
X86 platform is below:
===============================================================================
Memory Previous Current
Next
Type
Pages
Pages
Pages
====== ======== ======== ========
09
00000048 00000045 00000048
0A
0000004D 00000052 00000066
00
00000500 00000307 00000500
06
00000020 0000001B 00000020
05
000000D0 0000009E 000000D0
===============================================================================
A sample Memory Type Information reporting (BIN big enough and reset not required) on an
X86 platform is below:
===============================================================================
Memory Previous Current
Next
Type
Pages
Pages
Pages
====== ======== ======== ========
09
00000048 00000045 00000048
0A
00000066 00000052 00000066
00
00000500 00000307 00000500
06
00000020 0000001B 00000020
05
000000D0 0000009E 000000D0
===============================================================================
21
22
Conclusion
Memory map is important information from firmware to OS. This paper describes how memory
map is constructed from firmware and how firmware conveys this message to OS.
23
Glossary
ACPI Advanced Configuration and Power Interface. The specification defines a new interface to
the system board that enables the operating system to implement operating system-directed power
management and system configuration.
24
References
[ACPI] ACPI specification, Version 5.1 www.uefi.org
[EDK2] UEFI Developer Kit www.tianocore.org
[IA32SDM] Intel 64 and IA-32 Architectures Software Developers Manual, www.intel.com
[UEFI] Unified Extensible Firmware Interface (UEFI) Specification, Version 2.4.b
www.uefi.org
[UEFI Book] Zimmer, et al, Beyond BIOS: Developing with the Unified Extensible Firmware
Interface, 2nd edition, Intel Press, January 2011
[UEFI Overview] Zimmer, Rothman, Hale, UEFI: From Reset Vector to Operating System,
Chapter 3 of Hardware-Dependent Software, Springer, February 2009
[UEFI PI Specification] UEFI Platform Initialization (PI) Specifications, volumes 1-5, Version
1.3 www.uefi.org
25
Authors
Jiewen Yao ([email protected]) is an EDKII BIOS architect, EDKII TPM2
module maintainer, ACPI/S3 module maintainer, and FSP package owner with
the Software and Services Group at Intel Corporation.
Vincent J. Zimmer ([email protected]) is a Senior Principal
Engineer and chairs the UEFI networking and security sub-team with the
Software and Services Group at Intel Corporation.
26
This paper is for informational purposes only. THIS DOCUMENT IS PROVIDED "AS IS" WITH NO
WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY,
NONINFRINGEMENT, FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANTY OTHERWISE
ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. Intel disclaims all liability, including
liability for infringement of any proprietary rights, relating to use of information in this specification.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted
herein.
Intel, the Intel logo, Intel. leap ahead. and Intel. Leap ahead. logo, and other Intel product name are
trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and
other countries.
*Other names and brands may be claimed as the property of others.
27