[if !mso]> [if !mso]>

RE: [EDK DEV] Mapping memory in runtime driver

Subject: RE: [EDK DEV] Mapping memory in runtime driver

From: "Tian, Hot" <hot.tian@intel.com>

To: <dev@edk.tianocore.org>

Date: 2008-07-24 06:28:53

MMIO range can be accessed directly by the known memory mapping address. (gBS->AllocatePages() is used to allocate unallocated system memory). If you want to make it runtime, you should make sure the MMIO range is added to GCD by gDS->AddMemorySpace() and gDS->AllocateMemorySpace() (Refer to PI1.0 V2 6.2.4 Global Coherency Domain Services for details). Usually this is already done by platform drivers. And then you can set the range attribute to EFI_MEMORY_RUNTIME by gDS->SetMemorySpaceAttributes(). There is such sample in Edk\Sample\Universal\Variable\RuntimeDxe\Variable.c to mark the variable storage region of the FLASH as RUNTIME:

Status = gDS->SetMemorySpaceAttributes (



                  GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME



By setting GCD MMIO range to EFI_MEMORY_RUNTIME, gBS->GetMemoryMap() will return these MMIO runtime ranges to EFI OS loader. And then the EFI OS loader can create virtual memory mapping info for SetVirtualAddressMap().





The content of this message is my personal opinion only and although I am an employee of Intel, the statements I make here in no way represent Intel's position on the issue, nor am I authorized to speak on behalf of Intel on this matter.


From: Martin Mocko [mailto:vid512@gmail.com]
Sent: 2008
723 6:05
To: dev@edk.tianocore.org
Subject: Re: [EDK DEV] Mapping memory in runtime driver



On 7/22/08, Mark_A_Young@dell.com <Mark_A_Young@dell.com> wrote:

All you need to to do to an address in hardware (or memory) that is
known to exist is dereference it.
There is no need to map it, EFI is in flat real mode.

UINT64 test(void)
  #define MSR_IA32_APIC_BASE 0xFEEF0000
  UINT64 gApicIoBase = MSR_IA32_APIC_BASE;
  UINT64 data = *(UINT64 *)gApicIoBase;
  return (data);

I run 64bit UEFI implementation. That can't run in flat real mode, and also doesn't according to specs:
(UEFI 2.1 specs, 2.3.4)

During boot services time the processor is in the following execution mode:
• Uniprocessor
• Long mode, in 64-bit mode
• Paging mode is enabled and any memory space defined by the UEFI memory map is identity
mapped (virtual address equals physical address). The mappings to other regions are undefined
and may vary form implementation to implementation.

However, I just realized that UEFI implementation probably already has identity mapped APIC region,
since EFI shell uses keyboard.  I will try touching that memory now.

My concern is whether this mapping is marked as runtime data, and so it would remain valid
even after ExitBootServices() and especially after SetVirtualAddressMap(), when my runtime
driver will still need it.


Reading the base is not really want you want, but it does work.
Of course, the safest way is to use Mem.Read. I think this is what you
want, or similiar


I haven't heard of that Mem.Read function. Can you point me to some more information about
it? Thanks.