Skip to content

Commit 422250d

Browse files
dcpleungnashif
authored andcommitted
mm: intel_adsp_mtl_tlb: suppress sparse address space warnings
There are various call to z_soc_cached_ptr() which returns values in the cached address space and are stored in temporary variables that are not marked as in the cached address space. This results in sparse complaining about discarding the cached address space attribute. These temporary variables are then passed to other internal memory management related functions which do not have the concept of cached address space (as it is currently Xtensa specific). Because of this, we cannot change the signature of these functions. Instead, we force a change of address space when those temporary variables are being assigned to suppress sparse warnings. Signed-off-by: Daniel Leung <[email protected]>
1 parent 618a478 commit 422250d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/mm/mm_drv_intel_adsp_mtl_tlb.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mm_drv_intel_adsp.h"
2424

2525
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>
26+
#include <zephyr/debug/sparse.h>
2627

2728
static struct k_spinlock tlb_lock;
2829
extern struct k_spinlock sys_mm_drv_common_lock;
@@ -290,7 +291,7 @@ int sys_mm_drv_map_region(void *virt, uintptr_t phys,
290291
goto out;
291292
}
292293

293-
va = (uint8_t *)z_soc_cached_ptr(virt);
294+
va = (__sparse_force uint8_t *)z_soc_cached_ptr(virt);
294295
pa = phys;
295296

296297
key = k_spin_lock(&sys_mm_drv_common_lock);
@@ -318,7 +319,7 @@ int sys_mm_drv_map_region(void *virt, uintptr_t phys,
318319
int sys_mm_drv_map_array(void *virt, uintptr_t *phys,
319320
size_t cnt, uint32_t flags)
320321
{
321-
void *va = z_soc_cached_ptr(virt);
322+
void *va = (__sparse_force void *)z_soc_cached_ptr(virt);
322323

323324
return sys_mm_drv_simple_map_array(va, phys, cnt, flags);
324325
}
@@ -387,7 +388,7 @@ int sys_mm_drv_unmap_page(void *virt)
387388

388389
int sys_mm_drv_unmap_region(void *virt, size_t size)
389390
{
390-
void *va = z_soc_cached_ptr(virt);
391+
void *va = (__sparse_force void *)z_soc_cached_ptr(virt);
391392

392393
return sys_mm_drv_simple_unmap_region(va, size);
393394
}
@@ -478,8 +479,8 @@ int sys_mm_drv_page_flag_get(void *virt, uint32_t *flags)
478479
int sys_mm_drv_remap_region(void *virt_old, size_t size,
479480
void *virt_new)
480481
{
481-
void *va_new = z_soc_cached_ptr(virt_new);
482-
void *va_old = z_soc_cached_ptr(virt_old);
482+
void *va_new = (__sparse_force void *)z_soc_cached_ptr(virt_new);
483+
void *va_old = (__sparse_force void *)z_soc_cached_ptr(virt_old);
483484

484485
return sys_mm_drv_simple_remap_region(va_old, size, va_new);
485486
}
@@ -491,8 +492,8 @@ int sys_mm_drv_move_region(void *virt_old, size_t size, void *virt_new,
491492
size_t offset;
492493
int ret = 0;
493494

494-
virt_new = z_soc_cached_ptr(virt_new);
495-
virt_old = z_soc_cached_ptr(virt_old);
495+
virt_new = (__sparse_force void *)z_soc_cached_ptr(virt_new);
496+
virt_old = (__sparse_force void *)z_soc_cached_ptr(virt_old);
496497

497498
CHECKIF(!sys_mm_drv_is_virt_addr_aligned(virt_old) ||
498499
!sys_mm_drv_is_virt_addr_aligned(virt_new) ||
@@ -589,8 +590,8 @@ int sys_mm_drv_move_array(void *virt_old, size_t size, void *virt_new,
589590
{
590591
int ret;
591592

592-
void *va_new = z_soc_cached_ptr(virt_new);
593-
void *va_old = z_soc_cached_ptr(virt_old);
593+
void *va_new = (__sparse_force void *)z_soc_cached_ptr(virt_new);
594+
void *va_old = (__sparse_force void *)z_soc_cached_ptr(virt_old);
594595

595596
ret = sys_mm_drv_simple_move_array(va_old, size, va_new,
596597
phys_new, phys_cnt);
@@ -766,7 +767,8 @@ __imr void adsp_mm_restore_context(void *storage_buffer)
766767

767768
while (phys_addr != 0) {
768769
uint32_t phys_addr_uncached =
769-
POINTER_TO_UINT(z_soc_uncached_ptr(UINT_TO_POINTER(phys_addr)));
770+
POINTER_TO_UINT(z_soc_uncached_ptr(
771+
(void __sparse_cache *)UINT_TO_POINTER(phys_addr)));
770772
uint32_t phys_offset = phys_addr - L2_SRAM_BASE;
771773
uint32_t bank_idx = (phys_offset / SRAM_BANK_SIZE);
772774

0 commit comments

Comments
 (0)