Add memory that's usable for GX2 usage

This commit is contained in:
Maschell 2020-06-27 11:17:38 +02:00
parent 360a87977a
commit 36ba62e669
3 changed files with 45 additions and 9 deletions

View File

@ -76,8 +76,15 @@ void *MemoryMappingAllocEx(uint32_t size, uint32_t align) {
return res; return res;
} }
void *MemoryMappingAllocForGX2Ex(uint32_t size, uint32_t align) {
void *res = MemoryMapping_allocVideoMemory(size, align);
//DEBUG_FUNCTION_LINE("[res %08X] allocEX %d %d ", res, size, align);
return res;
}
uint32_t MEMAllocFromMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAlloc; uint32_t MEMAllocFromMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAlloc;
uint32_t MEMAllocFromMappedMemoryEx __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAllocEx; uint32_t MEMAllocFromMappedMemoryEx __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAllocEx;
uint32_t MEMAllocFromMappedMemoryForGX2Ex __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAllocForGX2Ex;
uint32_t MEMFreeToMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingFree; uint32_t MEMFreeToMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingFree;
WUMS_EXPORT_FUNCTION(MemoryMappingEffectiveToPhysical); WUMS_EXPORT_FUNCTION(MemoryMappingEffectiveToPhysical);
@ -85,4 +92,5 @@ WUMS_EXPORT_FUNCTION(MemoryMappingPhysicalToEffective);
WUMS_EXPORT_DATA(MEMAllocFromMappedMemory); WUMS_EXPORT_DATA(MEMAllocFromMappedMemory);
WUMS_EXPORT_DATA(MEMAllocFromMappedMemoryEx); WUMS_EXPORT_DATA(MEMAllocFromMappedMemoryEx);
WUMS_EXPORT_DATA(MEMAllocFromMappedMemoryForGX2Ex);
WUMS_EXPORT_DATA(MEMFreeToMappedMemory); WUMS_EXPORT_DATA(MEMFreeToMappedMemory);

View File

@ -396,6 +396,27 @@ void *MemoryMapping_alloc(uint32_t size, uint32_t align) {
return res; return res;
} }
void *MemoryMapping_allocVideoMemory(uint32_t size, uint32_t align) {
void *res = NULL;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
break;
}
uint32_t effectiveAddress = mem_mapping[i].effective_start_address;
// Skip non-video memory
if(effectiveAddress < MEMORY_START_VIDEO || effectiveAddress > MEMORY_END_VIDEO){
continue;
}
res = MEMAllocFromExpHeapEx((MEMHeapHandle) mem_mapping[i].effective_start_address, size, align);
if (res != NULL) {
break;
}
}
return res;
}
void MemoryMapping_free(void *ptr) { void MemoryMapping_free(void *ptr) {
if (ptr == NULL) { if (ptr == NULL) {
return; return;

View File

@ -36,6 +36,7 @@ typedef struct _memory_mapping_t {
#define PAGE_INDEX_MASK ((1 << (28 - PAGE_INDEX_SHIFT)) - 1) #define PAGE_INDEX_MASK ((1 << (28 - PAGE_INDEX_SHIFT)) - 1)
#define MEMORY_START_BASE 0x80000000 #define MEMORY_START_BASE 0x80000000
#define MEMORY_START_VIDEO_BASE (MEMORY_START_BASE + 0x08000000)
const memory_values_t mem_vals_heap_1[] = { const memory_values_t mem_vals_heap_1[] = {
{0x28000000 + 0x06620000, 0x28000000 + 0x07F80000}, // size: 25984 kB {0x28000000 + 0x06620000, 0x28000000 + 0x07F80000}, // size: 25984 kB
@ -71,15 +72,6 @@ const memory_values_t mem_vals_heap_4[] = {
#define MEMORY_HEAP4 MEMORY_HEAP3 + MEMORY_HEAP3_SIZE #define MEMORY_HEAP4 MEMORY_HEAP3 + MEMORY_HEAP3_SIZE
const memory_mapping_t mem_mapping[] = {
{MEMORY_HEAP0, MEMORY_HEAP1, mem_vals_heap_1},
{MEMORY_HEAP1, MEMORY_HEAP2, mem_vals_heap_2},
{MEMORY_HEAP2, MEMORY_HEAP3, mem_vals_heap_3},
{MEMORY_HEAP3, MEMORY_HEAP4, mem_vals_heap_4},
{0, 0, NULL}
};
const memory_values_t mem_vals_video[] = { const memory_values_t mem_vals_video[] = {
// The GPU doesn't have access to the 0x28000000 - 0x32000000 area, so we need memory from somewhere else. // The GPU doesn't have access to the 0x28000000 - 0x32000000 area, so we need memory from somewhere else.
// From the SharedReadHeap of the loader. // From the SharedReadHeap of the loader.
@ -114,6 +106,19 @@ const memory_values_t mem_vals_video[] = {
{0, 0} {0, 0}
}; };
#define MEMORY_START_VIDEO MEMORY_START_VIDEO_BASE
#define MEMORY_END_VIDEO MEMORY_START_VIDEO + 0xE60000
const memory_mapping_t mem_mapping[] = {
{MEMORY_HEAP0, MEMORY_HEAP1, mem_vals_heap_1},
{MEMORY_HEAP1, MEMORY_HEAP2, mem_vals_heap_2},
{MEMORY_HEAP2, MEMORY_HEAP3, mem_vals_heap_3},
{MEMORY_HEAP3, MEMORY_HEAP4, mem_vals_heap_4},
{MEMORY_START_VIDEO, MEMORY_END_VIDEO, mem_vals_video},
{0, 0, NULL}
};
// Values needs to be aligned to 0x20000 and size needs to be a multiple of 0x20000 // Values needs to be aligned to 0x20000 and size needs to be a multiple of 0x20000
const memory_values_t mem_vals_heap[] = { const memory_values_t mem_vals_heap[] = {
// 5.5.2 EUR // 5.5.2 EUR
@ -179,6 +184,8 @@ void MemoryMapping_searchEmptyMemoryRegions();
void *MemoryMapping_alloc(uint32_t size, uint32_t align); void *MemoryMapping_alloc(uint32_t size, uint32_t align);
void *MemoryMapping_allocVideoMemory(uint32_t size, uint32_t align);
void MemoryMapping_free(void *ptr); void MemoryMapping_free(void *ptr);
uint32_t MemoryMapping_getAreaSizeFromPageTable(uint32_t start, uint32_t maxSize); uint32_t MemoryMapping_getAreaSizeFromPageTable(uint32_t start, uint32_t maxSize);