public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kumar Gala <galak@kernel.crashing.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 2/4] Introduce addr_map library
Date: Sat, 13 Dec 2008 17:20:28 -0600	[thread overview]
Message-ID: <1229210430-4522-2-git-send-email-galak@kernel.crashing.org> (raw)
In-Reply-To: <1229210430-4522-1-git-send-email-galak@kernel.crashing.org>

Add a library that helps in translating between virtual and physical
addresses.  This library can be useful as a simple means to implement
map_physmem() and virt_to_phys() for platforms that need functionality
beyond the simple 1:1 mapping.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
* Folded in Becky's phys_size_t changes

 include/addr_map.h     |   29 +++++++++++++++++
 lib_generic/Makefile   |    1 +
 lib_generic/addr_map.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 include/addr_map.h
 create mode 100644 lib_generic/addr_map.c

diff --git a/include/addr_map.h b/include/addr_map.h
new file mode 100644
index 0000000..d55f5f6
--- /dev/null
+++ b/include/addr_map.h
@@ -0,0 +1,29 @@
+#ifndef __ADDR_MAP_H
+#define __ADDR_MAP_H
+
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <asm/types.h>
+
+extern phys_addr_t addrmap_virt_to_phys(void *vaddr);
+extern unsigned long addrmap_phys_to_virt(phys_addr_t paddr);
+extern void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
+				phys_size_t size, int idx);
+
+#endif
diff --git a/lib_generic/Makefile b/lib_generic/Makefile
index d62c39b..3f04022 100644
--- a/lib_generic/Makefile
+++ b/lib_generic/Makefile
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)libgeneric.a
 
+COBJS-$(CONFIG_ADDR_MAP) += addr_map.o
 COBJS-y += bzlib.o
 COBJS-y += bzlib_crctable.o
 COBJS-y += bzlib_decompress.o
diff --git a/lib_generic/addr_map.c b/lib_generic/addr_map.c
new file mode 100644
index 0000000..ff8532c
--- /dev/null
+++ b/lib_generic/addr_map.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <addr_map.h>
+
+static struct {
+	phys_addr_t paddr;
+	phys_size_t size;
+	unsigned long vaddr;
+} address_map[CONFIG_SYS_NUM_ADDR_MAP];
+
+phys_addr_t addrmap_virt_to_phys(void * vaddr)
+{
+	int i;
+
+	for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
+		u64 base, upper, addr;
+
+		if (address_map[i].size == 0)
+			continue;
+
+		addr = (u64)((u32)vaddr);
+		base = (u64)(address_map[i].vaddr);
+		upper = (u64)(address_map[i].size) + base - 1;
+
+		if (addr >= base && addr <= upper) {
+			return addr - address_map[i].vaddr + address_map[i].paddr;
+		}
+	}
+
+	return (phys_addr_t)(~0);
+}
+
+unsigned long addrmap_phys_to_virt(phys_addr_t paddr)
+{
+	int i;
+
+	for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
+		u64 base, upper, addr;
+
+		if (address_map[i].size == 0)
+			continue;
+
+		addr = (u64)paddr;
+		base = (u64)(address_map[i].paddr);
+		upper = (u64)(address_map[i].size) + base - 1;
+
+		if (addr >= base && addr <= upper) {
+			return paddr - address_map[i].paddr + address_map[i].vaddr;
+		}
+	}
+
+	return (unsigned long)(~0);
+}
+
+void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
+			phys_size_t size, int idx)
+{
+	if (idx > CONFIG_SYS_NUM_ADDR_MAP)
+		return;
+
+	address_map[idx].vaddr = vaddr;
+	address_map[idx].paddr = paddr;
+	address_map[idx].size  = size;
+}
-- 
1.5.6.5

  reply	other threads:[~2008-12-13 23:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-13 23:20 [U-Boot] [PATCH v4 1/4] Introduce virt_to_phys() Kumar Gala
2008-12-13 23:20 ` Kumar Gala [this message]
2008-12-13 23:20   ` [U-Boot] [PATCH v4 3/4] 85xx: Add support to populate addr map based on TLB settings Kumar Gala
2008-12-13 23:20     ` [U-Boot] [PATCH v4 4/4] ppc: Use addrmap in virt_to_phys and map_physmem Kumar Gala
2008-12-15 21:07   ` [U-Boot] [PATCH v4 2/4] Introduce addr_map library Wolfgang Denk
2008-12-15 21:12     ` Kumar Gala
2008-12-16  0:46       ` Wolfgang Denk
2008-12-16  3:33         ` Becky Bruce
2008-12-16 15:55           ` Wolfgang Denk
2008-12-15 21:04 ` [U-Boot] [PATCH v4 1/4] Introduce virt_to_phys() Wolfgang Denk
2008-12-17 15:47 ` Haavard Skinnemoen
2008-12-17 15:55   ` Kumar Gala
2008-12-17 16:00     ` Haavard Skinnemoen
2008-12-17 16:04       ` Kumar Gala
2008-12-17 16:22         ` Haavard Skinnemoen

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=1229210430-4522-2-git-send-email-galak@kernel.crashing.org \
    --to=galak@kernel.crashing.org \
    --cc=u-boot@lists.denx.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