Skip to content

Commit

Permalink
lib: xlnx: Avoid mapping in MPU for region mapped by bsp
Browse files Browse the repository at this point in the history
Avoiding memory mapping in MPU config table for region that are already
mapped by bsp and no change in attribute property.

Signed-off-by: Rajiv Mohan <rajiv.mohan@amd.com>
Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
  • Loading branch information
tnmysh committed Jan 15, 2024
1 parent 224cdea commit d0600ce
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion lib/system/generic/xlnx/sys.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022, Xilinx Inc. and Contributors. All rights reserved.
* Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All Rights Reserved.
* Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All Rights Reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -72,12 +72,63 @@ 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) 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 ReqEndAddr = pa + size;
XMpu_Config MpuConfig;
u32 ReqAddr = pa;
u32 mmap_req = 1;
u32 BaseEndAddr;
u32 Cnt;

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

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

BaseEndAddr = MpuConfig[Cnt].Size + MpuConfig[Cnt].BaseAddress;

if ( MpuConfig[Cnt].BaseAddress <= ReqAddr && BaseEndAddr >= ReqEndAddr) {

Check failure on line 99 in lib/system/generic/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

lib/system/generic/xlnx/sys.c:99 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
*/
if (MpuConfig[Cnt].Attribute == flags) {
mmap_req=0;

Check failure on line 106 in lib/system/generic/xlnx/sys.c

View workflow job for this annotation

GitHub Actions / compliance review

SPACING

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

/* if mapping is required we call Xil_MemMap to get the mapping done */
if (mmap_req == 1) {
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)
{
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 d0600ce

Please sign in to comment.