soc/intel_adsp: Elevate cached/uncached mapping to a SoC API

The trace output layer was using this transformation already, make it
an official API.  There are other places doing similar logic that can
benefit.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2021-02-15 19:59:18 -08:00 committed by Anas Nashif
commit f596768427
3 changed files with 47 additions and 7 deletions

View file

@ -15,4 +15,48 @@
#define SOC_DCACHE_INVALIDATE(addr, size) \
xthal_dcache_region_invalidate((addr), (size))
/**
* @brief Return uncached pointer to a RAM address
*
* The Intel ADSP architecture maps all addressable RAM (of all types)
* twice, in two different 512MB segments regions whose L1 cache
* settings can be controlled independently. So for any given
* pointer, it is possible to convert it to and from a cached version.
*
* This function takes a pointer to any addressible object (either in
* cacheable memory or not) and returns a pointer that can be used to
* refer to the same memory while bypassing the L1 data cache. Data
* in the L1 cache will not be inspected nor modified by the access.
*
* @see z_soc_cached_ptr()
*
* @param p A pointer to a valid C object
* @return A pointer to the same object bypassing the L1 dcache
*/
static inline void *z_soc_uncached_ptr(void *p)
{
return ((void *)(((size_t)p) & ~0x20000000));
}
/**
* @brief Return cached pointer to a RAM address
*
* This function takes a pointer to any addressible object (either in
* cacheable memory or not) and returns a pointer that can be used to
* refer to the same memory through the L1 data cache. Data read
* through the resulting pointer will reflect locally cached values on
* the current CPU if they exist, and writes will go first into the
* cache and be written back later.
*
* @see z_soc_uncached_ptr()
*
* @param p A pointer to a valid C object
* @return A pointer to the same object via the L1 dcache
*/
static inline void *z_soc_cached_ptr(void *p)
{
return ((void *)(((size_t)p) | 0x20000000));
}
#endif

View file

@ -167,4 +167,5 @@ extern void z_soc_irq_enable(uint32_t irq);
extern void z_soc_irq_disable(uint32_t irq);
extern int z_soc_irq_is_enabled(unsigned int irq);
#endif /* __INC_SOC_H */

View file

@ -28,11 +28,6 @@
#define NSLOTS (SRAM_TRACE_SIZE / SLOT_SIZE)
#define MSGSZ (SLOT_SIZE - sizeof(struct slot_hdr))
/* Translates a SRAM pointer into an address of the same memory in the
* uncached region from 0x80000000-0x9fffffff
*/
#define UNCACHED_PTR(p) ((void *)(((int)p) & ~0x20000000))
struct slot_hdr {
uint16_t magic;
uint16_t id;
@ -56,11 +51,11 @@ static __aligned(64) union {
uint32_t cache_pad[16];
} data_rec;
#define data ((volatile struct metadata *)UNCACHED_PTR(&data_rec.meta))
#define data ((volatile struct metadata *)z_soc_uncached_ptr(&data_rec.meta))
static inline struct slot *slot(int i)
{
struct slot *slots = UNCACHED_PTR(SRAM_TRACE_BASE);
struct slot *slots = z_soc_uncached_ptr((void *)SRAM_TRACE_BASE);
return &slots[i];
}