From: tip-bot for Josh Triplett <josh@joshtriplett.org>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
josh@joshtriplett.org, tglx@linutronix.de, hpa@linux.intel.com
Subject: [tip:x86/efi] efi: Add a function to look up existing IO memory mappings
Date: Sat, 29 Sep 2012 16:14:17 -0700 [thread overview]
Message-ID: <tip-7bc90e01c3f66c137e7e761f574bbf883087d590@git.kernel.org> (raw)
In-Reply-To: <0eb48ae012797912874919110660ad420b90268b.1348876882.git.josh@joshtriplett.org>
Commit-ID: 7bc90e01c3f66c137e7e761f574bbf883087d590
Gitweb: http://git.kernel.org/tip/7bc90e01c3f66c137e7e761f574bbf883087d590
Author: Josh Triplett <josh@joshtriplett.org>
AuthorDate: Fri, 28 Sep 2012 17:56:08 -0700
Committer: H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Sat, 29 Sep 2012 12:21:02 -0700
efi: Add a function to look up existing IO memory mappings
The EFI initialization creates virtual mappings for EFI boot services
memory, so if a driver wants to access EFI boot services memory, it
cannot call ioremap itself; doing so will trip the WARN about mapping
RAM twice. Thus, a driver accessing EFI boot services memory must do so
via the existing mapping already created during EFI intiialization.
Since the EFI code already maintains a memory map for that memory, add a
function efi_lookup_mapped_addr to look up mappings in that memory map.
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Link: http://lkml.kernel.org/r/0eb48ae012797912874919110660ad420b90268b.1348876882.git.josh@joshtriplett.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
arch/x86/platform/efi/efi.c | 28 ++++++++++++++++++++++++++++
include/linux/efi.h | 1 +
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index b3dbbdb..f7f928c 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -777,6 +777,34 @@ static void __init runtime_code_page_mkexec(void)
}
/*
+ * We can't ioremap data in EFI boot services RAM, because we've already mapped
+ * it as RAM. So, look it up in the existing EFI memory map instead. Only
+ * callable after efi_enter_virtual_mode and before efi_free_boot_services.
+ */
+void __iomem *efi_lookup_mapped_addr(u64 phys_addr)
+{
+ void *p;
+ if (WARN_ON(!memmap.map))
+ return NULL;
+ for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
+ efi_memory_desc_t *md = p;
+ u64 size = md->num_pages << EFI_PAGE_SHIFT;
+ u64 end = md->phys_addr + size;
+ if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
+ md->type != EFI_BOOT_SERVICES_CODE &&
+ md->type != EFI_BOOT_SERVICES_DATA)
+ continue;
+ if (!md->virt_addr)
+ continue;
+ if (phys_addr >= md->phys_addr && phys_addr < end) {
+ phys_addr += md->virt_addr - md->phys_addr;
+ return (__force void __iomem *)(unsigned long)phys_addr;
+ }
+ }
+ return NULL;
+}
+
+/*
* This function will switch the EFI runtime services to virtual mode.
* Essentially, look through the EFI memmap and map every region that
* has the runtime attribute bit set in its memory descriptor and update
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 5782114..fff135d 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -501,6 +501,7 @@ extern void efi_free_boot_services(void);
#else
static inline void efi_free_boot_services(void) {}
#endif
+extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
extern u64 efi_get_iobase (void);
extern u32 efi_mem_type (unsigned long phys_addr);
extern u64 efi_mem_attributes (unsigned long phys_addr);
next prev parent reply other threads:[~2012-09-29 23:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-29 0:55 [PATCHv4 0/3] Fix ACPI BGRT support for images located in EFI boot services memory Josh Triplett
2012-09-29 0:55 ` [PATCHv4 1/3] efi: Defer freeing boot services memory until after ACPI init Josh Triplett
2012-09-29 23:13 ` [tip:x86/efi] " tip-bot for Josh Triplett
2012-09-29 0:56 ` [PATCHv4 2/3] efi: Add a function to look up existing IO memory mappings Josh Triplett
2012-09-29 23:14 ` tip-bot for Josh Triplett [this message]
2012-09-29 0:57 ` [PATCHv4 3/3] efi: Fix the ACPI BGRT driver for images located in EFI boot services memory Josh Triplett
2012-09-29 23:15 ` [tip:x86/efi] " tip-bot for Josh Triplett
-- strict thread matches above, loose matches on Subject: below --
2012-09-08 22:09 [PATCHv3 3/4] efi: Add a function to look up existing IO memory mappings Josh Triplett
2012-09-27 21:57 ` [tip:x86/efi] " tip-bot for Josh Triplett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-7bc90e01c3f66c137e7e761f574bbf883087d590@git.kernel.org \
--to=josh@joshtriplett.org \
--cc=hpa@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome