wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <commproc.h> |
| 10 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_SYS_ALLOC_DPRAM |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 14 | |
| 15 | int dpram_init (void) |
| 16 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 17 | /* Reclaim the DP memory for our use. */ |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 18 | gd->arch.dp_alloc_base = CPM_DATAONLY_BASE; |
| 19 | gd->arch.dp_alloc_top = CPM_DATAONLY_BASE + CPM_DATAONLY_SIZE; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 20 | |
| 21 | return (0); |
| 22 | } |
| 23 | |
| 24 | /* Allocate some memory from the dual ported ram. We may want to |
| 25 | * enforce alignment restrictions, but right now everyone is a good |
| 26 | * citizen. |
| 27 | */ |
| 28 | uint dpram_alloc (uint size) |
| 29 | { |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 30 | uint addr = gd->arch.dp_alloc_base; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 31 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 32 | if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 33 | return (CPM_DP_NOSPACE); |
| 34 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 35 | gd->arch.dp_alloc_base += size; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 36 | |
| 37 | return addr; |
| 38 | } |
| 39 | |
| 40 | uint dpram_base (void) |
| 41 | { |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 42 | return gd->arch.dp_alloc_base; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /* Allocate some memory from the dual ported ram. We may want to |
| 46 | * enforce alignment restrictions, but right now everyone is a good |
| 47 | * citizen. |
| 48 | */ |
| 49 | uint dpram_alloc_align (uint size, uint align) |
| 50 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 51 | uint addr, mask = align - 1; |
| 52 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 53 | addr = (gd->arch.dp_alloc_base + mask) & ~mask; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 54 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 55 | if ((addr + size) >= gd->arch.dp_alloc_top) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 56 | return (CPM_DP_NOSPACE); |
| 57 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 58 | gd->arch.dp_alloc_base = addr + size; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 59 | |
| 60 | return addr; |
| 61 | } |
| 62 | |
| 63 | uint dpram_base_align (uint align) |
| 64 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 65 | uint mask = align - 1; |
| 66 | |
Simon Glass | 9398008 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 67 | return (gd->arch.dp_alloc_base + mask) & ~mask; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 68 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | #endif /* CONFIG_SYS_ALLOC_DPRAM */ |