]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/malloc_simple.c
ARM: dts: DRA7: use new dra7-specific compatible string
[people/ms/u-boot.git] / common / malloc_simple.c
CommitLineData
c9356be3
SG
1/*
2 * Simple malloc implementation
3 *
4 * Copyright (c) 2014 Google, Inc
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <malloc.h>
0eb25b61 11#include <mapmem.h>
c9356be3
SG
12#include <asm/io.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16void *malloc_simple(size_t bytes)
17{
18 ulong new_ptr;
19 void *ptr;
20
21 new_ptr = gd->malloc_ptr + bytes;
9a01cca7 22 debug("%s: size=%zx, ptr=%lx, limit=%lx: ", __func__, bytes, new_ptr,
836ac74c 23 gd->malloc_limit);
9a01cca7
SG
24 if (new_ptr > gd->malloc_limit) {
25 debug("space exhausted\n");
2c857170 26 return NULL;
9a01cca7 27 }
c9356be3
SG
28 ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
29 gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
9a01cca7 30 debug("%lx\n", (ulong)ptr);
836ac74c 31
c9356be3
SG
32 return ptr;
33}
34
b6bfb6ff
SG
35void *memalign_simple(size_t align, size_t bytes)
36{
37 ulong addr, new_ptr;
38 void *ptr;
39
972ea533 40 addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
596380db 41 new_ptr = addr + bytes - gd->malloc_base;
1923d54b
AD
42 if (new_ptr > gd->malloc_limit) {
43 debug("space exhausted\n");
b6bfb6ff 44 return NULL;
1923d54b
AD
45 }
46
b6bfb6ff
SG
47 ptr = map_sysmem(addr, bytes);
48 gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
1923d54b 49 debug("%lx\n", (ulong)ptr);
836ac74c 50
b6bfb6ff
SG
51 return ptr;
52}
53
1eb0c03c 54#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
c9356be3
SG
55void *calloc(size_t nmemb, size_t elem_size)
56{
57 size_t size = nmemb * elem_size;
58 void *ptr;
59
60 ptr = malloc(size);
61 memset(ptr, '\0', size);
62
63 return ptr;
64}
65#endif