blob: fe134bfe14b93b1fb0adc979613047a9960ddddf [file] [log] [blame]
Mark Dykese7810b52020-06-03 15:46:55 -05001/*
mardyk017b51dbe2024-01-17 15:25:36 -06002 * Copyright (c) 2024, Arm Limited. All rights reserved.
Mark Dykese7810b52020-06-03 15:46:55 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef SMCMALLOC_H
8#define SMCMALLOC_H
9
10#include <stddef.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
Mark Dykese7810b52020-06-03 15:46:55 -050014
15#define TOTALMEMORYSIZE (0x10000)
16#define BLKSPACEDIV (4)
17#define TOPBITSIZE (20)
18#define MAX_NAME_CHARS 50
19
20struct memblk {
21 unsigned int address;
22 unsigned int size;
23 int valid;
24};
25
26struct memmod {
27 char memory[TOTALMEMORYSIZE];
28 unsigned int nmemblk;
29 unsigned int maxmemblk;
30 unsigned int checkadd;
31 struct memblk *memptr;
32 struct memblk *memptrend;
33 unsigned int mallocdeladd[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
34 struct memblk *precblock[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
35 struct memblk *trailblock[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
36 struct memblk *memblkqueue[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
37 unsigned int memallocsize[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
38 unsigned int mallocdeladd_valid[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
39 unsigned int mallocdeladd_queue[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
40 unsigned int checksa[4*((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
41 unsigned int checkea[4*((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))];
42 unsigned int cntdeladd;
43 unsigned int ptrmemblkqueue;
44 unsigned int mallocdeladd_queue_cnt;
45 unsigned int checknumentries;
46 unsigned int memerror;
47};
48
49struct peret {
50 unsigned int tbit;
51 unsigned int pow2;
52};
53
54void initmem(void);
55struct peret priorityencoder(unsigned int);
56void *smcmalloc(unsigned int, struct memmod*);
57int smcfree(void*, struct memmod *);
58#ifdef DEBUG_SMC_MALLOC
59void displayblocks(struct memmod *);
60void displaymalloctable(struct memmod *);
61#endif
62
63#endif /* SMCMALLOC_H */