[OpenBIOS] [PATCH 3/5] ofmem: helper to find first virtual address map entry
Igor V. Kovalenko
igor.v.kovalenko at gmail.com
Sun Dec 27 12:44:13 CET 2009
From: Igor V. Kovalenko <igor.v.kovalenko at gmail.com>
A few places in sparc64 code may need to know where
specific physical address range is mapped to access
memory locations. Create helper to find first suitable
mapping and return virtual address.
- ofmem_find_virtual: new method; use it to find
where physical memory address is mapped
Signed-off-by: Igor V. Kovalenko <igor.v.kovalenko at gmail.com>
---
include/ofmem.h | 1 +
modules/ofmem_common.c | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/include/ofmem.h b/include/ofmem.h
index 37f9e3b..eaa5082 100644
--- a/include/ofmem.h
+++ b/include/ofmem.h
@@ -92,6 +92,7 @@ extern int ofmem_unmap( ucell virt, ucell size );
extern void ofmem_release_phys( ucell phys, ucell size );
extern void ofmem_release_virt( ucell virt, ucell size );
extern ucell ofmem_translate( ucell virt, ucell *ret_mode );
+extern ucell ofmem_find_virtual( ucell phys );
#ifdef CONFIG_PPC
#define PAGE_SHIFT 12
diff --git a/modules/ofmem_common.c b/modules/ofmem_common.c
index 760823d..fedcaa1 100644
--- a/modules/ofmem_common.c
+++ b/modules/ofmem_common.c
@@ -694,6 +694,31 @@ ucell ofmem_translate( ucell virt, ucell *mode )
return -1;
}
+/* physical -> virtual.
+ return first found translation
+ */
+ucell ofmem_find_virtual( ucell phys )
+{
+ ofmem_t *ofmem = ofmem_arch_get_private();
+ translation_t *t;
+
+ OFMEM_TRACE("ofmem_find_virtual: searching virtual address of "
+ FMT_ucellx "\n", phys);
+
+ for( t=ofmem->trans; t ; t=t->next ) {
+ ucell offs;
+ if( t->phys <= phys && t->phys + t->size - 1 >= phys ) {
+ offs = phys - t->phys;
+ return t->virt + offs;
+ }
+ }
+
+ OFMEM_TRACE("ofmem_find_virtual: no translation defined (" FMT_ucellx ")\n",
+ phys);
+
+ return -1;
+}
+
/* release memory allocated by ofmem_claim_phys */
void ofmem_release_phys( ucell phys, ucell size )
{
More information about the OpenBIOS
mailing list