| | 1 | = Physical Memory Allocators == |
| | 2 | |
| | 3 | The [source:soft/giet_vm/giet_common/pmem.c pmem.c] and [source:soft/giet_vm/giet_common/pmem.h pmem.h] files define the data structures and functions used by the boot-loader to allocate physical memory. |
| | 4 | |
| | 5 | The physical memory allocation is statically done by the boot-loader, and the functions defined here |
| | 6 | should not be used by the kernel. |
| | 7 | |
| | 8 | The physical address format is 40 bits, structured in five fields: |
| | 9 | | 4 | 4 | 11 | 9 | 12 | |
| | 10 | | X | Y | BPPI | SPPI | OFFSET | |
| | 11 | * The (X,Y) fields define the cluster coordinates in the 2D mesh. |
| | 12 | * The BPPI field is the Big Physical Page Index |
| | 13 | * The SPPI field is the Small Physical Page Index |
| | 14 | * The |X|Y|BPPI|SPPI| concatenation is the PPN (Physical Page Number) |
| | 15 | |
| | 16 | As the physical memory can be distributed in all clusters, there is one physical memory allocator in each cluster, and the allocation state is defined by the boot_pmem_alloc[x][y] array (defined in the |
| | 17 | boot.c file). As the allocated physical memory is never released, the allocator structure is very simple, and is defined in the pmem_alloc_t structure. |
| | 18 | |
| | 19 | As the boot-loader is executed by one single processor, this structure does not contain any lock protecting exclusive access. |
| | 20 | |
| | 21 | Both small pages allocator and big pages allocators allocate a variable number of CONTIGUOUS pages in the physical space. The first big page in cluster[0][0] is reserved for identity mapping vsegs, and is not allocated by the physical memory allocators. |
| | 22 | |
| | 23 | |
| | 24 | === void _pmem_alloc_init( unsigned int x, unsigned int y, unsigned int base, unsigned int size ) === |
| | 25 | |
| | 26 | This function initialises the physical memory allocator in cluster (x,y). |
| | 27 | The pseg base address and the pseg size must be multiple of 2 Mbytes (one big page). |
| | 28 | * base is the pseg local base address (no cluster extension) |
| | 29 | * size is the pseg length (bytes) |
| | 30 | The first page in cluster[0][0] is reserved for the boot code identity mapping vsegs. |
| | 31 | |
| | 32 | === unsigned int _get_small_ppn( pmem_alloc_t* p, unsigned int n ) === |
| | 33 | |
| | 34 | This function allocates n contiguous small pages (4 Kbytes), |
| | 35 | from the physical memory allocator defined by the p pointer. |
| | 36 | It returns the PPN (28 bits) of the first physical small page. |
| | 37 | Exit if not enough free space. |
| | 38 | |
| | 39 | === unsigned int _get_big_ppn( pmem_alloc_t* p, unsigned int n ) === |
| | 40 | |
| | 41 | This function allocates n contiguous big pages (2 Mbytes), |
| | 42 | from the physical memory allocator defined by the p pointer. |
| | 43 | It returns the PPN (28 bits) of the first physical big page (the SPPI field of the ppn is always 0). |
| | 44 | Exit if not enough free space. |
| | 45 | |
| | 46 | |