summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-07-19 09:58:32 +0200
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2011-07-18 20:32:45 +0800
commitf928efa818adfe56a08350569a9b0f3c2fb791d2 (patch)
tree4fc754655afbd235d466a5c9d7a63ce89faed24b /common
parent88618eb5f12c27be7bb4400eb13768e4c2822ae7 (diff)
downloadbarebox-f928efa818adfe56a08350569a9b0f3c2fb791d2.tar.gz
barebox-f928efa818adfe56a08350569a9b0f3c2fb791d2.tar.xz
add a add_mem_device function
Add a helper function for boards to register their memory devices. This makes the board code smaller and also helps getting rid of map_base and struct memory_platform_data. And switch all of the memory to it Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'common')
-rw-r--r--common/Makefile1
-rw-r--r--common/mem.c46
-rw-r--r--common/startup.c16
3 files changed, 50 insertions, 13 deletions
diff --git a/common/Makefile b/common/Makefile
index 9fed2ae521..27aebae24d 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_POLLER) += poller.o
obj-$(CONFIG_BLOCK) += block.o
obj-y += memory.o
+obj-y += mem.o
obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
obj-y += clock.o
diff --git a/common/mem.c b/common/mem.c
new file mode 100644
index 0000000000..7b0020bb69
--- /dev/null
+++ b/common/mem.c
@@ -0,0 +1,46 @@
+/*
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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 <driver.h>
+#include <xfuncs.h>
+
+struct device_d *add_mem_device(const char *name, resource_size_t start,
+ resource_size_t size, unsigned int flags)
+{
+ struct device_d *dev;
+
+ dev = xzalloc(sizeof(*dev));
+ strcpy(dev->name, "mem");
+ dev->id = -1;
+ dev->resource = xzalloc(sizeof(struct resource));
+ dev->num_resources = 1;
+ dev->resource[0].name = xstrdup(name);
+ dev->resource[0].start = start;
+ dev->resource[0].size = size;
+ dev->resource[0].flags = IORESOURCE_MEM | flags;
+
+ register_device(dev);
+
+ return dev;
+}
diff --git a/common/startup.c b/common/startup.c
index 2e28cb2264..bf67aef152 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -82,21 +82,11 @@ void early_init (void)
#ifdef CONFIG_DEFAULT_ENVIRONMENT
#include <generated/barebox_default_env.h>
-static struct memory_platform_data default_env_platform_data = {
- .name = "defaultenv",
-};
-
-static struct device_d default_env_dev = {
- .id = -1,
- .name = "mem",
- .platform_data = &default_env_platform_data,
-};
-
static int register_default_env(void)
{
- default_env_dev.map_base = (unsigned long)default_environment;
- default_env_dev.size = sizeof(default_environment);
- register_device(&default_env_dev);
+ add_mem_device("defaultenv", (unsigned long)default_environment,
+ sizeof(default_environment),
+ IORESOURCE_MEM_WRITEABLE);
return 0;
}