Mark Dykes | e7810b5 | 2020-06-03 15:46:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | * |
| 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> |
| 14 | #include "fifo3d.h" |
| 15 | |
| 16 | #define TOTALMEMORYSIZE (0x10000) |
| 17 | #define BLKSPACEDIV (4) |
| 18 | #define TOPBITSIZE (20) |
| 19 | #define MAX_NAME_CHARS 50 |
| 20 | |
| 21 | struct memblk { |
| 22 | unsigned int address; |
| 23 | unsigned int size; |
| 24 | int valid; |
| 25 | }; |
| 26 | |
| 27 | struct memmod { |
| 28 | char memory[TOTALMEMORYSIZE]; |
| 29 | unsigned int nmemblk; |
| 30 | unsigned int maxmemblk; |
| 31 | unsigned int checkadd; |
| 32 | struct memblk *memptr; |
| 33 | struct memblk *memptrend; |
| 34 | unsigned int mallocdeladd[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 35 | struct memblk *precblock[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 36 | struct memblk *trailblock[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 37 | struct memblk *memblkqueue[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 38 | unsigned int memallocsize[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 39 | unsigned int mallocdeladd_valid[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 40 | unsigned int mallocdeladd_queue[((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 41 | unsigned int checksa[4*((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 42 | unsigned int checkea[4*((TOTALMEMORYSIZE/BLKSPACEDIV)/sizeof(struct memblk))]; |
| 43 | unsigned int cntdeladd; |
| 44 | unsigned int ptrmemblkqueue; |
| 45 | unsigned int mallocdeladd_queue_cnt; |
| 46 | unsigned int checknumentries; |
| 47 | unsigned int memerror; |
| 48 | }; |
| 49 | |
| 50 | struct peret { |
| 51 | unsigned int tbit; |
| 52 | unsigned int pow2; |
| 53 | }; |
| 54 | |
| 55 | void initmem(void); |
| 56 | struct peret priorityencoder(unsigned int); |
| 57 | void *smcmalloc(unsigned int, struct memmod*); |
| 58 | int smcfree(void*, struct memmod *); |
| 59 | #ifdef DEBUG_SMC_MALLOC |
| 60 | void displayblocks(struct memmod *); |
| 61 | void displaymalloctable(struct memmod *); |
| 62 | #endif |
| 63 | |
| 64 | #endif /* SMCMALLOC_H */ |