x86/cache.c: Implement dcache_*

A new ChromeOS automated test will be introduced to check the cbmem log
of diagnostic boot mode. Because the diagnostic boot does not allow
booting into kernel, the test must perform AP reset and then check the
cbmem log afterwards. However, the memory content might not be written
back to memory (from CPU cache) during AP reset because of the cache
snooping mechanism on x86. Hence, some API to flush cache is needed.

Implement dcache_* to allow flushing cache proactively in x86. To avoid
unnecessary flush, check dma_coherent before calling dcache_* functions,
which will be always true in x86. Therefore, this change won't affect
the original functionality.

BUG=b:190026346
TEST=FW_NAME=primus emerge-brya libpayload

Cq-Depend: chromium:3841252
Signed-off-by: Hsin-Te Yuan <yuanhsinte@google.com>
Change-Id: I622d8b1cc652cbe477954a900885d12e6494d94d
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66578
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
This commit is contained in:
Hsin-Te Yuan
2022-08-09 15:00:55 +08:00
committed by Martin Roth
parent 412222ae75
commit cb28d649ea
5 changed files with 169 additions and 10 deletions

View File

@ -31,15 +31,21 @@
#ifndef __ARCH_CACHE_H__
#define __ARCH_CACHE_H__
#include <stddef.h>
#include <stdint.h>
/* returns number of bytes per cache line */
unsigned int dcache_line_bytes(void);
void dcache_invalidate_all(void);
void dcache_clean_invalidate_all(void);
void dcache_clean_all(void);
void dcache_clean_by_mva(void const *addr, size_t len);
void dcache_invalidate_by_mva(void const *addr, size_t len);
void dcache_clean_invalidate_by_mva(void const *addr, size_t len);
/* NOOPs mirroring ARM's cache API, since x86 devices usually cache snoop */
#define dmb()
#define dsb()
#define dcache_clean_all()
#define dcache_clean_by_mva(addr, len)
#define dcache_invalidate_all()
#define dcache_invalidate_by_mva(addr, len)
#define dcache_clean_invalidate_all()
#define dcache_clean_invalidate_by_mva(addr, len)
#define cache_sync_instructions()
#endif