42 #define EM_MAX_ADDRESS 0xffffffffUL 45 #define EM_ALIGN ( 4 * 1024 ) 48 #define UNOWHERE ( ~UNULL ) 88 for ( i = 0 ; i < memmap.
count ; i++ ) {
90 DBG (
"Considering [%llx,%llx)\n", region->
start, region->
end );
94 DBG (
"...starts after maximum address %lx\n",
max );
97 region_start = region->
start;
99 DBG (
"...end truncated to maximum address %lx\n",
max);
102 region_end = region->
end;
104 region_len = ( region_end - region_start );
107 if ( region_len >
len ) {
108 DBG (
"...new best block found\n" );
126 DBG (
"External heap grows downwards from %lx (size %zx)\n",
146 len = ( extmem.
size +
sizeof ( extmem ) );
179 DBG (
"EXTMEM out of space\n" );
184 DBG (
"EXTMEM allocating [%lx,%lx)\n",
188 extmem.
used = ( new_size > 0 );
198 DBG (
"EXTMEM out of space\n" );
201 DBG (
"EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n",
207 extmem.
size : new_size ) );
210 extmem.
size = new_size;
213 if ( new_size > extmem.
size ) {
215 DBG (
"EXTMEM cannot expand [%lx,%lx)\n",
229 0 : -
sizeof ( extmem ) ) ),
232 return ( new_size ?
new :
UNOWHERE );
static void init_eheap(void)
Initialise external heap.
static __always_inline void struct dma_mapping size_t size_t align
void get_memmap(struct memory_map *memmap)
Get memory map.
unsigned int count
Number of used regions.
void hide_umalloc(physaddr_t start, physaddr_t end)
Hide umalloc() region.
size_t size
Size of this memory block (excluding this header)
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
PROVIDE_UMALLOC(memtop, urealloc, memtop_urealloc)
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
static size_t heap_size
Remaining space on heap.
static userptr_t bottom
Bottom of heap (current lowest allocated block)
Access to external ("user") memory.
uint32_t start
Starting offset.
struct memory_region regions[MAX_MEMORY_REGIONS]
Memory regions.
userptr_t userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
uint32_t userptr_t
A pointer to a user buffer.
An external memory block.
static userptr_t memtop_urealloc(userptr_t ptr, size_t new_size)
Reallocate external memory.
userptr_t urealloc(userptr_t userptr, size_t new_size)
Reallocate external memory.
#define EM_MAX_ADDRESS
Maximum usable address for external allocated memory.
static userptr_t top
Top of heap.
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
#define EM_ALIGN
Alignment of external allocated memory.
#define UNOWHERE
Equivalent of NOWHERE for user pointers.
#define UNULL
Equivalent of NULL for user pointers.
uint64_t start
Physical start address.
int used
Block is currently in use.
size_t largest_memblock(userptr_t *start)
Find largest usable memory region.
void memmove_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers, allowing for overlap.
static void ecollect_free(void)
Collect free blocks.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define DBG(...)
Print a debugging message.
uint64_t end
Physical end address.