diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-10-23 09:39:15 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-10-27 08:22:45 +0100 |
commit | 6b127d4f189c03f4417f6185de1aeb55b1706f94 (patch) | |
tree | 2d793225196ac86ef567ccbe4fc3e800727a6fa7 /commands/memtest.c | |
parent | 1678dcf7ca52b8028e6dd311fba1402eb49d3565 (diff) | |
download | barebox-6b127d4f189c03f4417f6185de1aeb55b1706f94.tar.gz barebox-6b127d4f189c03f4417f6185de1aeb55b1706f94.tar.xz |
memtest: move request/release regions to common/
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>
Diffstat (limited to 'commands/memtest.c')
-rw-r--r-- | commands/memtest.c | 107 |
1 files changed, 2 insertions, 105 deletions
diff --git a/commands/memtest.c b/commands/memtest.c index 756123001a..531b8e0ea7 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) { /* |