Skip to content

Commit 17eb313

Browse files
lyakhcarlescufi
authored andcommitted
sparse: add an address space and a __sparse_force annotation
We want to use a sparse address space to identify invalid conversions between cached and uncached address aliases. This patch adds a __sparse_cache sparse annotation for that. Where those conversions must be done that has to be supported by using the __sparse_force sparse attribute. To avoid compiler complains about unknown attributes we add a -Wno-attributes flag when building with sparse support. Signed-off-by: Guennadi Liakhovetski <[email protected]>
1 parent 41a77be commit 17eb313

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ endif()
269269

270270
if("${SPARSE}" STREQUAL "y")
271271
list(APPEND TOOLCHAIN_C_FLAGS -D__CHECKER__)
272+
# Avoid compiler "attribute directive ignored" warnings
273+
list(APPEND TOOLCHAIN_C_FLAGS -Wno-attributes)
272274
endif()
273275

274276
zephyr_compile_options(

include/zephyr/arch/xtensa/cache.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <xtensa/config/core-isa.h>
99
#include <toolchain.h>
1010
#include <sys/util.h>
11+
#include <debug/sparse.h>
1112

1213
#ifdef __cplusplus
1314
extern "C" {
@@ -127,11 +128,11 @@ static ALWAYS_INLINE uint32_t z_xtrpoflip(uint32_t addr, uint32_t rto, uint32_t
127128
* @param ptr A pointer to a valid C object
128129
* @return A pointer to the same object via the L1 dcache
129130
*/
130-
static inline void *arch_xtensa_cached_ptr(void *ptr)
131+
static inline void __sparse_cache *arch_xtensa_cached_ptr(void *ptr)
131132
{
132-
return (void *)z_xtrpoflip((uint32_t) ptr,
133-
CONFIG_XTENSA_CACHED_REGION,
134-
CONFIG_XTENSA_UNCACHED_REGION);
133+
return (__sparse_force void __sparse_cache *)z_xtrpoflip((uint32_t) ptr,
134+
CONFIG_XTENSA_CACHED_REGION,
135+
CONFIG_XTENSA_UNCACHED_REGION);
135136
}
136137

137138
/**
@@ -152,7 +153,7 @@ static inline void *arch_xtensa_cached_ptr(void *ptr)
152153
* @param ptr A pointer to a valid C object
153154
* @return A pointer to the same object bypassing the L1 dcache
154155
*/
155-
static inline void *arch_xtensa_uncached_ptr(void *ptr)
156+
static inline void *arch_xtensa_uncached_ptr(void __sparse_cache *ptr)
156157
{
157158
return (void *)z_xtrpoflip((uint32_t) ptr,
158159
CONFIG_XTENSA_UNCACHED_REGION,

include/zephyr/debug/sparse.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DEBUG_SPARSE_H
8+
#define ZEPHYR_INCLUDE_DEBUG_SPARSE_H
9+
10+
#if defined(__CHECKER__)
11+
#define __sparse_cache __attribute__((address_space(__cache)))
12+
#define __sparse_force __attribute__((force))
13+
#else
14+
#define __sparse_cache
15+
#define __sparse_force
16+
#endif
17+
18+
#endif

0 commit comments

Comments
 (0)