mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/9] memtest: move request/release regions to common/
Date: Tue, 27 Oct 2015 09:29:54 +0100	[thread overview]
Message-ID: <1445934602-25903-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1445934602-25903-1-git-send-email-s.hauer@pengutronix.de>

Normally code providing a feature should be implemented in common/ which
is then called from the command code. Follow this rule and move some more
of the memtest code to common/.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/memtest.c | 107 +-------------------------------------------------
 common/memtest.c   | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memtest.h  |   3 ++
 3 files changed, 117 insertions(+), 105 deletions(-)

diff --git a/commands/memtest.c b/commands/memtest.c
index 7561230..531b8e0 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -26,102 +26,8 @@
 #include <malloc.h>
 #include <common.h>
 #include <errno.h>
-
 #include <memtest.h>
 
-static int alloc_memtest_region(struct list_head *list,
-		resource_size_t start, resource_size_t size)
-{
-	struct resource *r_new;
-	struct mem_test_resource *r;
-
-	r = xzalloc(sizeof(struct mem_test_resource));
-	r_new = request_sdram_region("memtest", start, size);
-	if (!r_new)
-		return -EINVAL;
-
-	r->r = r_new;
-	list_add_tail(&r->list, list);
-
-	return 0;
-}
-
-static int request_memtest_regions(struct list_head *list)
-{
-	int ret;
-	struct memory_bank *bank;
-	struct resource *r, *r_prev = NULL;
-	resource_size_t start, end, size;
-
-	for_each_memory_bank(bank) {
-		/*
-		 * If we don't have any allocated region on bank,
-		 * we use the whole bank boundary
-		 */
-		if (list_empty(&bank->res->children)) {
-			start = PAGE_ALIGN(bank->res->start);
-			size = PAGE_ALIGN_DOWN(bank->res->end - start + 1);
-
-			if (size) {
-				ret = alloc_memtest_region(list, start, size);
-				if (ret < 0)
-					return ret;
-			}
-
-			continue;
-		}
-
-		r = list_first_entry(&bank->res->children,
-				     struct resource, sibling);
-		start = PAGE_ALIGN(bank->res->start);
-		end = PAGE_ALIGN_DOWN(r->start);
-		r_prev = r;
-		if (start != end) {
-			size = end - start;
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-		/*
-		 * We assume that the regions are sorted in this list
-		 * So the first element has start boundary on bank->res->start
-		 * and the last element hast end boundary on bank->res->end.
-		 *
-		 * Between used regions. Start from second entry.
-		 */
-		list_for_each_entry_from(r, &bank->res->children, sibling) {
-			start = PAGE_ALIGN(r_prev->end + 1);
-			end = r->start - 1;
-			r_prev = r;
-			if (start >= end)
-				continue;
-
-			size = PAGE_ALIGN_DOWN(end - start + 1);
-			if (size == 0)
-				continue;
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-
-		/*
-		 * Do on head element for bank boundary.
-		 */
-		r = list_last_entry(&bank->res->children,
-				     struct resource, sibling);
-		start = PAGE_ALIGN(r->end);
-		end = bank->res->end;
-		size = PAGE_ALIGN_DOWN(end - start + 1);
-		if (size && start < end && start > r->end) {
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-	}
-
-	return 0;
-}
-
 static int __do_memtest(struct list_head *memtest_regions,
 		int bus_only, uint32_t cache_flag)
 {
@@ -148,7 +54,6 @@ static int do_memtest(int argc, char *argv[])
 {
 	int bus_only = 0, ret, opt;
 	uint32_t i, max_i = 1, pte_flags_cached, pte_flags_uncached;
-	struct mem_test_resource *r, *r_tmp;
 	struct list_head memtest_used_regions;
 
 	while ((opt = getopt(argc, argv, "i:b")) > 0) {
@@ -175,7 +80,7 @@ static int do_memtest(int argc, char *argv[])
 
 	INIT_LIST_HEAD(&memtest_used_regions);
 
-	ret = request_memtest_regions(&memtest_used_regions);
+	ret = mem_test_request_regions(&memtest_used_regions);
 	if (ret < 0)
 		goto out;
 
@@ -203,15 +108,7 @@ static int do_memtest(int argc, char *argv[])
 	}
 
 out:
-	list_for_each_entry_safe(r, r_tmp, &memtest_used_regions, list) {
-		/*
-		 * Ensure to leave with a cached on non used sdram regions.
-		 */
-		remap_range((void *)r->r->start, r->r->end -
-				r->r->start + 1, pte_flags_cached);
-		release_sdram_region(r->r);
-		free(r);
-	}
+	mem_test_release_regions(&memtest_used_regions);
 
 	if (ret < 0) {
 		/*
diff --git a/common/memtest.c b/common/memtest.c
index d8d1154..fc71e91 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -27,6 +27,118 @@
 #include <linux/sizes.h>
 #include <errno.h>
 #include <memtest.h>
+#include <malloc.h>
+#include <asm/mmu.h>
+
+static int alloc_memtest_region(struct list_head *list,
+		resource_size_t start, resource_size_t size)
+{
+	struct resource *r_new;
+	struct mem_test_resource *r;
+
+	r = xzalloc(sizeof(struct mem_test_resource));
+	r_new = request_sdram_region("memtest", start, size);
+	if (!r_new)
+		return -EINVAL;
+
+	r->r = r_new;
+	list_add_tail(&r->list, list);
+
+	return 0;
+}
+
+int mem_test_request_regions(struct list_head *list)
+{
+	int ret;
+	struct memory_bank *bank;
+	struct resource *r, *r_prev = NULL;
+	resource_size_t start, end, size;
+
+	for_each_memory_bank(bank) {
+		/*
+		 * If we don't have any allocated region on bank,
+		 * we use the whole bank boundary
+		 */
+		if (list_empty(&bank->res->children)) {
+			start = PAGE_ALIGN(bank->res->start);
+			size = PAGE_ALIGN_DOWN(bank->res->end - start + 1);
+
+			if (size) {
+				ret = alloc_memtest_region(list, start, size);
+				if (ret < 0)
+					return ret;
+			}
+
+			continue;
+		}
+
+		r = list_first_entry(&bank->res->children,
+				     struct resource, sibling);
+		start = PAGE_ALIGN(bank->res->start);
+		end = PAGE_ALIGN_DOWN(r->start);
+		r_prev = r;
+		if (start != end) {
+			size = end - start;
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+		/*
+		 * We assume that the regions are sorted in this list
+		 * So the first element has start boundary on bank->res->start
+		 * and the last element hast end boundary on bank->res->end.
+		 *
+		 * Between used regions. Start from second entry.
+		 */
+		list_for_each_entry_from(r, &bank->res->children, sibling) {
+			start = PAGE_ALIGN(r_prev->end + 1);
+			end = r->start - 1;
+			r_prev = r;
+			if (start >= end)
+				continue;
+
+			size = PAGE_ALIGN_DOWN(end - start + 1);
+			if (size == 0)
+				continue;
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+
+		/*
+		 * Do on head element for bank boundary.
+		 */
+		r = list_last_entry(&bank->res->children,
+				     struct resource, sibling);
+		start = PAGE_ALIGN(r->end);
+		end = bank->res->end;
+		size = PAGE_ALIGN_DOWN(end - start + 1);
+		if (size && start < end && start > r->end) {
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+void mem_test_release_regions(struct list_head *list)
+{
+	struct mem_test_resource *r, *r_tmp;
+	uint32_t pte_flags_cached = mmu_get_pte_cached_flags();
+
+	list_for_each_entry_safe(r, r_tmp, list, list) {
+		/*
+		 * Ensure to leave with a cached on non used sdram regions.
+		 */
+		remap_range((void *)r->r->start, r->r->end -
+				r->r->start + 1, pte_flags_cached);
+
+		release_sdram_region(r->r);
+		free(r);
+	}
+}
 
 static void mem_test_report_failure(const char *failure_description,
 				    resource_size_t expected_value,
diff --git a/include/memtest.h b/include/memtest.h
index a337be8..1c67a73 100644
--- a/include/memtest.h
+++ b/include/memtest.h
@@ -8,6 +8,9 @@ struct mem_test_resource {
 	struct list_head list;
 };
 
+int mem_test_request_regions(struct list_head *list);
+void mem_test_release_regions(struct list_head *list);
+
 int mem_test(resource_size_t _start,
 		resource_size_t _end, int bus_only);
 
-- 
2.6.1


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

  reply	other threads:[~2015-10-27  8:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27  8:29 memtest updates Sascha Hauer
2015-10-27  8:29 ` Sascha Hauer [this message]
2015-10-27  8:29 ` [PATCH 2/9] rework remap_range Sascha Hauer
2015-10-27  8:29 ` [PATCH 3/9] memtest: split tests in separate functions Sascha Hauer
2015-10-27  8:29 ` [PATCH 4/9] memtest: Make output more compact Sascha Hauer
2015-10-27  8:29 ` [PATCH 5/9] memtest: Make comments single line when appropriate Sascha Hauer
2015-10-27  8:29 ` [PATCH 6/9] memtest: move ctrlc check / progress showing into separate function Sascha Hauer
2015-10-27  8:30 ` [PATCH 7/9] memtest: move error handling to end of function Sascha Hauer
2015-10-27  8:30 ` [PATCH 8/9] memtest: By default only test biggest region Sascha Hauer
2015-10-27  8:30 ` [PATCH 9/9] memtest: Make cached/uncached test configurable Sascha Hauer
2015-10-27 16:55 ` memtest updates Alexander Aring
2015-10-27 17:27   ` Alexander Aring
2015-10-27 17:35     ` Alexander Aring
2015-10-28  6:17   ` Sascha Hauer
2015-10-28  9:11     ` Alexander Aring

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=1445934602-25903-2-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