The RAM Allocator interface is used to allocate and free RAM. During
ChorusOS boot and initialization, the RAM occupation is described by a RamDesc
object. The ramAllocator field in
the BootConf structure points to the RamDesc
object. The ramAllocator field is initialized
by the mkimage tool as described in "RAM Occupation".
RAM occupation is described by a particular tag value associated with each address of the physical address space. The tag can have one of the following values:
RAM_ALLOCATED, indicating that the physical address belongs to an occupied portion of RAM
RAM_FREE, indicating that the physical address belongs to a portion of RAM available for allocation
RAM_NONEXISTENT, indicating that the physical address does not belong to RAM (or is not available for allocation as RAM)
Three routines are provided for managing RamDesc
. These
routines can be used by the bootstrap program to update RamDesc
according to
the target BKI.
ram_tag()
void ram_tag (RamDesc* ram, PhAddr paddr, Phsize size, int tag);
The ram_tag() function attempts to change the tag values of all addresses from the address range of size size starting from paddr to the value specified by tag. The ram_tag() function only changes a tag if the initial value is RAM_FREE or RAM_NONEXISTENT. It does not change a tag if the initial value is RAM_ALLOCATED.
ram_alloc()
int ram_alloc (RamDesc* ram, PhAddr*, paddr, PhSize size, int align);
The ram_alloc() function allocates a portion of available RAM, tags the corresponding address range as RAM_ALLOCATED, and returns the physical address of the allocated RAM in the variable that paddr points to. align specifies the RAM alignment constraints (in bytes), or is 0 if there are no constraints. ram_alloc() returns 1 if successful, and 0 if the allocation failed.
ram_free()
void ram_free (RamDesc* ram, PhAddr paddr, PhSize size);
The ram_free() function changes the tag values for the specified range of physical addresses to RAM_FREE.