1 #ifndef __MALLOC_H
2 #define __MALLOC_H
3 
4 #include "autoconf.h" // CONFIG_*
5 #include "types.h" // u32
6 
7 // malloc.c
8 extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
9 u32 rom_get_max(void);
10 u32 rom_get_last(void);
11 struct rom_header *rom_reserve(u32 size);
12 int rom_confirm(u32 size);
13 void malloc_csm_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm,
14                         u32 hi_pmm_size);
15 void malloc_preinit(void);
16 extern u32 LegacyRamSize;
17 void malloc_init(void);
18 void malloc_prepboot(void);
19 unsigned long malloc_palloc(struct zone_s *zone, u32 size, u32 align);
20 void *parisc_malloc(u32 size, u32 align);
21 void *x86_malloc(struct zone_s *zone, u32 size, u32 align);
22 #define _malloc(zone, size, align) \
23     (CONFIG_X86 ? x86_malloc(zone, size, align) : parisc_malloc(size, align))
24 int malloc_pfree(u32 data);
25 void free(void *data);
26 u32 malloc_getspace(struct zone_s *zone);
27 void malloc_sethandle(u32 data, u32 handle);
28 u32 malloc_findhandle(u32 handle);
29 
30 #define MALLOC_DEFAULT_HANDLE 0xFFFFFFFF
31 // Minimum alignment of malloc'd memory
32 #define MALLOC_MIN_ALIGN 16
33 // Helper functions for memory allocation.
malloc_low(u32 size)34 static inline void *malloc_low(u32 size) {
35     return _malloc(&ZoneLow, size, MALLOC_MIN_ALIGN);
36 }
malloc_high(u32 size)37 static inline void *malloc_high(u32 size) {
38     return _malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN);
39 }
malloc_fseg(u32 size)40 static inline void *malloc_fseg(u32 size) {
41     return _malloc(&ZoneFSeg, size, MALLOC_MIN_ALIGN);
42 }
malloc_tmplow(u32 size)43 static inline void *malloc_tmplow(u32 size) {
44     return _malloc(&ZoneTmpLow, size, MALLOC_MIN_ALIGN);
45 }
malloc_tmphigh(u32 size)46 static inline void *malloc_tmphigh(u32 size) {
47     return _malloc(&ZoneTmpHigh, size, MALLOC_MIN_ALIGN);
48 }
malloc_tmp(u32 size)49 static inline void *malloc_tmp(u32 size) {
50     void *ret = malloc_tmphigh(size);
51     if (ret)
52         return ret;
53     return malloc_tmplow(size);
54 }
memalign_low(u32 align,u32 size)55 static inline void *memalign_low(u32 align, u32 size) {
56     return _malloc(&ZoneLow, size, align);
57 }
memalign_high(u32 align,u32 size)58 static inline void *memalign_high(u32 align, u32 size) {
59     return _malloc(&ZoneHigh, size, align);
60 }
memalign_tmplow(u32 align,u32 size)61 static inline void *memalign_tmplow(u32 align, u32 size) {
62     return _malloc(&ZoneTmpLow, size, align);
63 }
memalign_tmphigh(u32 align,u32 size)64 static inline void *memalign_tmphigh(u32 align, u32 size) {
65     return _malloc(&ZoneTmpHigh, size, align);
66 }
memalign_tmp(u32 align,u32 size)67 static inline void *memalign_tmp(u32 align, u32 size) {
68     void *ret = memalign_tmphigh(align, size);
69     if (ret)
70         return ret;
71     return memalign_tmplow(align, size);
72 }
73 
74 #endif // malloc.h
75