blob: a87a0dce88cbd3119baa617b79916be819229214 [file] [log] [blame]
wdenka042ac82002-09-12 22:36:57 +00001/*
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 Denkd87080b2006-03-31 18:32:53 +020027DECLARE_GLOBAL_DATA_PTR;
28
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020029#ifdef CONFIG_SYS_ALLOC_DPRAM
wdenka042ac82002-09-12 22:36:57 +000030
31int dpram_init (void)
32{
wdenka042ac82002-09-12 22:36:57 +000033 /* Reclaim the DP memory for our use. */
34 gd->dp_alloc_base = CPM_DATAONLY_BASE;
35 gd->dp_alloc_top = CPM_DATAONLY_BASE + CPM_DATAONLY_SIZE;
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 */
44uint dpram_alloc (uint size)
45{
wdenka042ac82002-09-12 22:36:57 +000046 uint addr = gd->dp_alloc_base;
47
48 if ((gd->dp_alloc_base + size) >= gd->dp_alloc_top)
49 return (CPM_DP_NOSPACE);
50
51 gd->dp_alloc_base += size;
52
53 return addr;
54}
55
56uint dpram_base (void)
57{
wdenka042ac82002-09-12 22:36:57 +000058 return gd->dp_alloc_base;
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 */
65uint dpram_alloc_align (uint size, uint align)
66{
wdenka042ac82002-09-12 22:36:57 +000067 uint addr, mask = align - 1;
68
69 addr = (gd->dp_alloc_base + mask) & ~mask;
70
71 if ((addr + size) >= gd->dp_alloc_top)
72 return (CPM_DP_NOSPACE);
73
74 gd->dp_alloc_base = addr + size;
75
76 return addr;
77}
78
79uint dpram_base_align (uint align)
80{
wdenka042ac82002-09-12 22:36:57 +000081 uint mask = align - 1;
82
83 return (gd->dp_alloc_base + mask) & ~mask;
84}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085#endif /* CONFIG_SYS_ALLOC_DPRAM */
wdenka042ac82002-09-12 22:36:57 +000086
wdenkd1cbe852003-06-28 17:24:46 +000087#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
wdenka042ac82002-09-12 22:36:57 +000088
89void post_word_store (ulong a)
90{
91 volatile void *save_addr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092 ((immap_t *) CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + CPM_POST_WORD_ADDR;
wdenka042ac82002-09-12 22:36:57 +000093
94 *(volatile ulong *) save_addr = a;
95}
96
97ulong post_word_load (void)
98{
99 volatile void *save_addr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100 ((immap_t *) CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + CPM_POST_WORD_ADDR;
wdenka042ac82002-09-12 22:36:57 +0000101
102 return *(volatile ulong *) save_addr;
103}
104
wdenkd1cbe852003-06-28 17:24:46 +0000105#endif /* CONFIG_POST || CONFIG_LOGBUFFER*/
wdenkbdccc4f2003-08-05 17:43:17 +0000106
107#ifdef CONFIG_BOOTCOUNT_LIMIT
108
109void bootcount_store (ulong a)
110{
111 volatile ulong *save_addr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112 (volatile ulong *)( ((immap_t *) CONFIG_SYS_IMMR)->im_cpm.cp_dpmem +
wdenkbdccc4f2003-08-05 17:43:17 +0000113 CPM_BOOTCOUNT_ADDR );
114
115 save_addr[0] = a;
116 save_addr[1] = BOOTCOUNT_MAGIC;
117}
118
119ulong bootcount_load (void)
120{
121 volatile ulong *save_addr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200122 (volatile ulong *)( ((immap_t *) CONFIG_SYS_IMMR)->im_cpm.cp_dpmem +
wdenkbdccc4f2003-08-05 17:43:17 +0000123 CPM_BOOTCOUNT_ADDR );
124
125 if (save_addr[1] != BOOTCOUNT_MAGIC)
126 return 0;
127 else
128 return save_addr[0];
129}
130
131#endif /* CONFIG_BOOTCOUNT_LIMIT */