Skip to content

Commit

Permalink
FreeRTOS Avoid mem mapping in MPU for region mapped
Browse files Browse the repository at this point in the history
FreeRTOS patch for Avoiding memory mapping in MPU config table for region that are already mapped by bsp and no change in attribute property
Note: this is a temp fix, need a more robust solution to avoid issues coming up later

Signed-off-by: Rajiv Mohan <[email protected]>
  • Loading branch information
rajimoha committed Feb 1, 2024
1 parent 224cdea commit 18f7d5b
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions lib/system/freertos/xlnx/sys.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, Advanced Micro Devices, Inc.
* Copyright (C) 2024, Advanced Micro Devices, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -75,12 +75,64 @@ void metal_weak metal_generic_default_poll(void)
metal_asm volatile("wfi");
}

/*
* VERSAL_NET is used since XMpu_Config structure is
* different for r52(versal net) and r5(zynqmp), done to avoid
* build failure
*/

#ifdef VERSAL_NET
void *metal_machine_io_mem_map_versal_net(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
void *__attribute__((unused)) physaddr;
u32 req_end_addr = pa + size;
XMpu_Config mpu_config;
u32 req_addr = pa;
u32 mmap_req = 1;
u32 base_end_addr;
u32 cnt;

/* Get the MPU Config enties */
Xil_GetMPUConfig(mpu_config);

for (cnt = 0; (cnt < MAX_POSSIBLE_MPU_REGS) &&
(mpu_config[cnt].flags & XMPU_VALID_REGION); cnt++){

Check failure on line 100 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/freertos/xlnx/sys.c:100 space required before the open brace '{'

base_end_addr = mpu_config[cnt].Size + mpu_config[cnt].BaseAddress;

if ( mpu_config[cnt].BaseAddress <= req_addr && base_end_addr >= req_end_addr){

Check failure on line 104 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/freertos/xlnx/sys.c:104 space required before the open brace '{'

Check failure on line 104 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/freertos/xlnx/sys.c:104 space prohibited after that open parenthesis '('
/*
* Mapping available for requested region in MPU table
* If no change in Attribute for region then additional mapping in MPU table is not required

Check warning on line 107 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

LONG_LINE_COMMENT

lib/system/freertos/xlnx/sys.c:107 line over 100 characters
*/
if (mpu_config[cnt].Attribute == flags) {
mmap_req=0;

Check failure on line 110 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/freertos/xlnx/sys.c:110 spaces required around that '=' (ctx:VxV)
break;
}
}
}

/* if mapping is required we call Xil_MemMap to get the mapping done */
if (mmap_req == 1){

Check failure on line 117 in lib/system/freertos/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/freertos/xlnx/sys.c:117 space required before the open brace '{'
physaddr = Xil_MemMap(pa, size, flags);
metal_assert(physaddr == (void *)pa);
}

return va;
}
#endif

void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
size_t size, unsigned int flags)
{
void *__attribute__((unused)) physaddr;
#ifdef VERSAL_NET
va = metal_machine_io_mem_map_versal_net(va, pa, size, flags);

#else
physaddr = Xil_MemMap(pa, size, flags);
metal_assert(physaddr == (void *)pa);
#endif
return va;
}

0 comments on commit 18f7d5b

Please sign in to comment.