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