mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/5] register sdram as resources
Date: Mon,  5 Dec 2011 09:56:00 +0100	[thread overview]
Message-ID: <1323075361-27455-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1323075361-27455-1-git-send-email-s.hauer@pengutronix.de>

Also, request the sdram regions used by the barebox binary,
bss, malloc space and stack.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memory.c  |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory.h |    5 ++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 0ba9a18..7d0f4ca 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -25,6 +25,9 @@
 #include <of.h>
 #include <init.h>
 #include <libfdt.h>
+#include <linux/ioport.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/sections.h>
 
 /*
  * Begin and End of memory area for malloc(), and current "brk"
@@ -50,6 +53,33 @@ void mem_malloc_init(void *start, void *end)
 	malloc_brk = malloc_start;
 }
 
+static int mem_malloc_resource(void)
+{
+	/*
+	 * Normally it's a bug when one of these fails,
+	 * but we have some setups where some of these
+	 * regions are outside of sdram in which case
+	 * the following fails.
+	 */
+	request_sdram_region("malloc space",
+			malloc_start,
+			malloc_end - malloc_start + 1);
+	request_sdram_region("barebox",
+			(unsigned long)&_stext,
+			(unsigned long)&_etext -
+			(unsigned long)&_stext + 1);
+	request_sdram_region("bss",
+			(unsigned long)&__bss_start,
+			(unsigned long)&__bss_stop -
+			(unsigned long)&__bss_start + 1);
+#ifdef STACK_BASE
+	request_sdram_region("stack", STACK_BASE, STACK_SIZE);
+#endif
+
+	return 0;
+}
+coredevice_initcall(mem_malloc_resource);
+
 static void *sbrk_no_zero(ptrdiff_t increment)
 {
 	unsigned long old = malloc_brk;
@@ -82,6 +112,10 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
 	struct memory_bank *bank = xzalloc(sizeof(*bank));
 	struct device_d *dev;
 
+	bank->res = request_iomem_region(name, start, size);
+
+	BUG_ON(!bank->res);
+
 	dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
 
 	bank->dev = dev;
@@ -91,6 +125,30 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
 	list_add_tail(&bank->list, &memory_banks);
 }
 
+/*
+ * Request a region from the registered sdram
+ */
+struct resource *request_sdram_region(const char *name, resource_size_t start,
+		resource_size_t size)
+{
+	struct memory_bank *bank;
+
+	for_each_memory_bank(bank) {
+		struct resource *res;
+
+		res = request_region(bank->res, name, start, size);
+		if (res)
+			return res;
+	}
+
+	return NULL;
+}
+
+int release_sdram_region(struct resource *res)
+{
+	return release_region(res);
+}
+
 #ifdef CONFIG_OFTREE
 
 /*
diff --git a/include/memory.h b/include/memory.h
index cb185af..4be4340 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -13,6 +13,7 @@ struct memory_bank {
 	struct device_d *dev;
 	unsigned long start;
 	unsigned long size;
+	struct resource *res;
 };
 
 extern struct list_head memory_banks;
@@ -22,4 +23,8 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
 
 #define for_each_memory_bank(mem)	list_for_each_entry(mem, &memory_banks, list)
 
+struct resource *request_sdram_region(const char *name, resource_size_t start,
+		resource_size_t size);
+int release_sdram_region(struct resource *res);
+
 #endif
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-12-05  8:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05  8:55 [PATCH] resources Sascha Hauer
2011-12-05  8:55 ` [PATCH 1/5] fix malloc space sizes Sascha Hauer
2011-12-05  8:55 ` [PATCH 2/5] add resource management functions Sascha Hauer
2011-12-05  8:55 ` [PATCH 3/5] add iomem command to show iomem usage Sascha Hauer
2011-12-05  8:56 ` Sascha Hauer [this message]
2011-12-05  8:56 ` [PATCH 5/5] implement resource management for platform devices Sascha Hauer

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=1323075361-27455-5-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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