blob: 960a7f8000f886c3aee64302f81e0b45df9e7448 [file] [log] [blame]
Kevin O'Connor9dea5902013-09-14 20:23:54 -04001#ifndef __MALLOC_H
2#define __MALLOC_H
3
4#include "types.h" // u32
5
6// malloc.c
7extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
8u32 rom_get_max(void);
9u32 rom_get_last(void);
10struct rom_header *rom_reserve(u32 size);
11int rom_confirm(u32 size);
Kevin O'Connor7d0393d2015-10-15 13:53:04 -040012void malloc_csm_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm,
Kevin O'Connor9dea5902013-09-14 20:23:54 -040013 u32 hi_pmm_size);
14void malloc_preinit(void);
15extern u32 LegacyRamSize;
16void malloc_init(void);
17void malloc_prepboot(void);
Kevin O'Connorfe6682d2015-09-22 14:45:25 -040018u32 malloc_palloc(struct zone_s *zone, u32 size, u32 align);
Kevin O'Connor743c1572013-12-14 13:14:02 -050019void *_malloc(struct zone_s *zone, u32 size, u32 align);
Kevin O'Connorfe6682d2015-09-22 14:45:25 -040020int malloc_pfree(u32 data);
Kevin O'Connor3c6ae7c2015-10-06 15:37:53 -040021void free(void *data);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040022u32 malloc_getspace(struct zone_s *zone);
Kevin O'Connorfe6682d2015-09-22 14:45:25 -040023void malloc_sethandle(u32 data, u32 handle);
24u32 malloc_findhandle(u32 handle);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040025
26#define MALLOC_DEFAULT_HANDLE 0xFFFFFFFF
27// Minimum alignment of malloc'd memory
28#define MALLOC_MIN_ALIGN 16
29// Helper functions for memory allocation.
30static inline void *malloc_low(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050031 return _malloc(&ZoneLow, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040032}
33static inline void *malloc_high(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050034 return _malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040035}
36static inline void *malloc_fseg(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050037 return _malloc(&ZoneFSeg, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040038}
39static inline void *malloc_tmplow(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050040 return _malloc(&ZoneTmpLow, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040041}
42static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050043 return _malloc(&ZoneTmpHigh, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040044}
45static inline void *malloc_tmp(u32 size) {
46 void *ret = malloc_tmphigh(size);
47 if (ret)
48 return ret;
49 return malloc_tmplow(size);
50}
51static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050052 return _malloc(&ZoneLow, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040053}
54static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050055 return _malloc(&ZoneHigh, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040056}
57static inline void *memalign_tmplow(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050058 return _malloc(&ZoneTmpLow, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040059}
60static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050061 return _malloc(&ZoneTmpHigh, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040062}
63static inline void *memalign_tmp(u32 align, u32 size) {
64 void *ret = memalign_tmphigh(align, size);
65 if (ret)
66 return ret;
67 return memalign_tmplow(align, size);
68}
Kevin O'Connor9dea5902013-09-14 20:23:54 -040069
70#endif // malloc.h