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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <commproc.h> |
| 26 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_SYS_ALLOC_DPRAM |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 30 | |
| 31 | int dpram_init (void) |
| 32 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 33 | /* Reclaim the DP memory for our use. */ |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 34 | gd->arch.dp_alloc_base = CPM_DATAONLY_BASE; |
| 35 | gd->arch.dp_alloc_top = CPM_DATAONLY_BASE + CPM_DATAONLY_SIZE; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 36 | |
| 37 | return (0); |
| 38 | } |
| 39 | |
| 40 | /* Allocate some memory from the dual ported ram. We may want to |
| 41 | * enforce alignment restrictions, but right now everyone is a good |
| 42 | * citizen. |
| 43 | */ |
| 44 | uint dpram_alloc (uint size) |
| 45 | { |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 46 | uint addr = gd->arch.dp_alloc_base; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 47 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 48 | if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 49 | return (CPM_DP_NOSPACE); |
| 50 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 51 | gd->arch.dp_alloc_base += size; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 52 | |
| 53 | return addr; |
| 54 | } |
| 55 | |
| 56 | uint dpram_base (void) |
| 57 | { |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 58 | return gd->arch.dp_alloc_base; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Allocate some memory from the dual ported ram. We may want to |
| 62 | * enforce alignment restrictions, but right now everyone is a good |
| 63 | * citizen. |
| 64 | */ |
| 65 | uint dpram_alloc_align (uint size, uint align) |
| 66 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 67 | uint addr, mask = align - 1; |
| 68 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 69 | addr = (gd->arch.dp_alloc_base + mask) & ~mask; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 70 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 71 | if ((addr + size) >= gd->arch.dp_alloc_top) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 72 | return (CPM_DP_NOSPACE); |
| 73 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 74 | gd->arch.dp_alloc_base = addr + size; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 75 | |
| 76 | return addr; |
| 77 | } |
| 78 | |
| 79 | uint dpram_base_align (uint align) |
| 80 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 81 | uint mask = align - 1; |
| 82 | |
Simon Glass | 6bb9ba7 | 2012-12-13 20:48:58 +0000 | [diff] [blame] | 83 | return (gd->arch.dp_alloc_base + mask) & ~mask; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 84 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | #endif /* CONFIG_SYS_ALLOC_DPRAM */ |