blob: f8581d130d45bc82ffacbdb0cc9fb72a39d303d5 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenka042ac82002-09-12 22:36:57 +00006 */
7
8#include <common.h>
9#include <commproc.h>
10
Wolfgang Denk6405a152006-03-31 18:32:53 +020011DECLARE_GLOBAL_DATA_PTR;
12
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020013#ifdef CONFIG_SYS_ALLOC_DPRAM
wdenka042ac82002-09-12 22:36:57 +000014
15int dpram_init (void)
16{
wdenka042ac82002-09-12 22:36:57 +000017 /* Reclaim the DP memory for our use. */
Simon Glass93980082012-12-13 20:48:58 +000018 gd->arch.dp_alloc_base = CPM_DATAONLY_BASE;
19 gd->arch.dp_alloc_top = CPM_DATAONLY_BASE + CPM_DATAONLY_SIZE;
wdenka042ac82002-09-12 22:36:57 +000020
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 */
28uint dpram_alloc (uint size)
29{
Simon Glass93980082012-12-13 20:48:58 +000030 uint addr = gd->arch.dp_alloc_base;
wdenka042ac82002-09-12 22:36:57 +000031
Simon Glass93980082012-12-13 20:48:58 +000032 if ((gd->arch.dp_alloc_base + size) >= gd->arch.dp_alloc_top)
wdenka042ac82002-09-12 22:36:57 +000033 return (CPM_DP_NOSPACE);
34
Simon Glass93980082012-12-13 20:48:58 +000035 gd->arch.dp_alloc_base += size;
wdenka042ac82002-09-12 22:36:57 +000036
37 return addr;
38}
39
40uint dpram_base (void)
41{
Simon Glass93980082012-12-13 20:48:58 +000042 return gd->arch.dp_alloc_base;
wdenka042ac82002-09-12 22:36:57 +000043}
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 */
49uint dpram_alloc_align (uint size, uint align)
50{
wdenka042ac82002-09-12 22:36:57 +000051 uint addr, mask = align - 1;
52
Simon Glass93980082012-12-13 20:48:58 +000053 addr = (gd->arch.dp_alloc_base + mask) & ~mask;
wdenka042ac82002-09-12 22:36:57 +000054
Simon Glass93980082012-12-13 20:48:58 +000055 if ((addr + size) >= gd->arch.dp_alloc_top)
wdenka042ac82002-09-12 22:36:57 +000056 return (CPM_DP_NOSPACE);
57
Simon Glass93980082012-12-13 20:48:58 +000058 gd->arch.dp_alloc_base = addr + size;
wdenka042ac82002-09-12 22:36:57 +000059
60 return addr;
61}
62
63uint dpram_base_align (uint align)
64{
wdenka042ac82002-09-12 22:36:57 +000065 uint mask = align - 1;
66
Simon Glass93980082012-12-13 20:48:58 +000067 return (gd->arch.dp_alloc_base + mask) & ~mask;
wdenka042ac82002-09-12 22:36:57 +000068}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069#endif /* CONFIG_SYS_ALLOC_DPRAM */