mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 4/5] Add address translation
@ 2005-08-24 18:44 Zachary Amsden
  0 siblings, 0 replies; only message in thread
From: Zachary Amsden @ 2005-08-24 18:44 UTC (permalink / raw)
  To: Andrew Morton, Linux Kernel Mailing List,
	Virtualization Mailing List, H. Peter Anvin, Zwane Mwaikambo,
	Chris Wright, Martin Bligh, Pratap Subrahmanyam, Christopher Li,
	Zachary Amsden

Add a helper function to convert an arbitrary mapped virtual address to a
physical frame number.  Adapted from code by Chris Wright, added support
for large pages.

Because of the placement, this needs to be a macro; pgd_offset_k requires
init_mm to be defined, and getting the include files right seemed more
complicated than a macroized implementation.

A more proper location would be in asm/page.h, but that gets confounded
by the use of pgd_offset_k() again.

Signed-off-by: Zachary Amsden <zach@vmware.com>
Index: linux-2.6.13/include/asm-i386/pgtable.h
===================================================================
--- linux-2.6.13.orig/include/asm-i386/pgtable.h	2005-08-24 09:43:27.000000000 -0700
+++ linux-2.6.13/include/asm-i386/pgtable.h	2005-08-24 09:47:38.000000000 -0700
@@ -388,6 +388,28 @@ static inline pte_t pte_modify(pte_t pte
 extern pte_t *lookup_address(unsigned long address);
 
 /*
+ * Helper function that returns physical page for virtual address.
+ * This assumes the mapping is valid.
+ */
+#define virt_to_pfn(_address) 					\
+({ 								\
+	unsigned long long __paddr;				\
+	pgd_t *pgd = pgd_offset_k(_address);			\
+	pud_t *pud = pud_offset(pgd, (_address));		\
+	pmd_t *pmd = pmd_offset(pud, (_address));		\
+	if (pmd_large(*pmd))					\
+		__paddr = (pmd_val(*pmd) & LARGE_PAGE_MASK) |	\
+			((_address) & ~LARGE_PAGE_MASK);	\
+	else {							\
+		pte_t *pte = pte_offset_kernel(pmd, (_address));\
+		__paddr = (pte_val(*pte) & PAGE_MASK) |		\
+			((_address) & ~PAGE_MASK);		\
+	}							\
+	__paddr >>= PAGE_SHIFT;					\
+	__paddr;						\
+}) 
+
+/*
  * Make a given kernel text page executable/non-executable.
  * Returns the previous executability setting of that page (which
  * is used to restore the previous state). Used by the SMP bootup code.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-24 18:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-24 18:44 [PATCH 4/5] Add address translation Zachary Amsden

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®