blob: 2bcb5bf6dcf37d20c668ca0a773350342dd8e609 [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);
12void csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm,
13 u32 hi_pmm_size);
14void malloc_preinit(void);
15extern u32 LegacyRamSize;
16void malloc_init(void);
17void malloc_prepboot(void);
Kevin O'Connor743c1572013-12-14 13:14:02 -050018void *_malloc(struct zone_s *zone, u32 size, u32 align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040019int _free(void *data);
20u32 malloc_getspace(struct zone_s *zone);
Kevin O'Connor743c1572013-12-14 13:14:02 -050021void malloc_sethandle(void *data, u32 handle);
22void *malloc_findhandle(u32 handle);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040023
24#define MALLOC_DEFAULT_HANDLE 0xFFFFFFFF
25// Minimum alignment of malloc'd memory
26#define MALLOC_MIN_ALIGN 16
27// Helper functions for memory allocation.
28static inline void *malloc_low(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050029 return _malloc(&ZoneLow, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040030}
31static inline void *malloc_high(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050032 return _malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040033}
34static inline void *malloc_fseg(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050035 return _malloc(&ZoneFSeg, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040036}
37static inline void *malloc_tmplow(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050038 return _malloc(&ZoneTmpLow, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040039}
40static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050041 return _malloc(&ZoneTmpHigh, size, MALLOC_MIN_ALIGN);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040042}
43static inline void *malloc_tmp(u32 size) {
44 void *ret = malloc_tmphigh(size);
45 if (ret)
46 return ret;
47 return malloc_tmplow(size);
48}
49static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050050 return _malloc(&ZoneLow, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040051}
52static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050053 return _malloc(&ZoneHigh, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040054}
55static inline void *memalign_tmplow(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050056 return _malloc(&ZoneTmpLow, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040057}
58static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connor743c1572013-12-14 13:14:02 -050059 return _malloc(&ZoneTmpHigh, size, align);
Kevin O'Connor9dea5902013-09-14 20:23:54 -040060}
61static inline void *memalign_tmp(u32 align, u32 size) {
62 void *ret = memalign_tmphigh(align, size);
63 if (ret)
64 return ret;
65 return memalign_tmplow(align, size);
66}
67static inline void free(void *data) {
68 _free(data);
69}
70
71#endif // malloc.h