diff options
author | bunnei <bunneidev@gmail.com> | 2022-11-18 22:18:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 22:18:36 +0100 |
commit | 1fb33bd1e19fe0855072b08a91353a3b457fa85d (patch) | |
tree | 3687b2c5e394843e4554b0e0ca733d840aca8720 /src/common/cache_management.cpp | |
parent | Merge pull request #9244 from liamwhite/lost-wakeup (diff) | |
parent | kernel: implement FlushProcessDataCache (diff) | |
download | yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar.gz yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar.bz2 yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar.lz yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar.xz yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.tar.zst yuzu-1fb33bd1e19fe0855072b08a91353a3b457fa85d.zip |
Diffstat (limited to 'src/common/cache_management.cpp')
-rw-r--r-- | src/common/cache_management.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/common/cache_management.cpp b/src/common/cache_management.cpp new file mode 100644 index 000000000..57810b76a --- /dev/null +++ b/src/common/cache_management.cpp @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <cstring> + +#include "alignment.h" +#include "cache_management.h" +#include "common_types.h" + +namespace Common { + +#if defined(ARCHITECTURE_x86_64) + +// Most cache operations are no-ops on x86 + +void DataCacheLineCleanByVAToPoU(void* start, size_t size) {} +void DataCacheLineCleanAndInvalidateByVAToPoC(void* start, size_t size) {} +void DataCacheLineCleanByVAToPoC(void* start, size_t size) {} +void DataCacheZeroByVA(void* start, size_t size) { + std::memset(start, 0, size); +} + +#elif defined(ARCHITECTURE_arm64) + +// BS/DminLine is log2(cache size in words), we want size in bytes +#define EXTRACT_DMINLINE(ctr_el0) (1 << ((((ctr_el0) >> 16) & 0xf) + 2)) +#define EXTRACT_BS(dczid_el0) (1 << (((dczid_el0)&0xf) + 2)) + +#define DEFINE_DC_OP(op_name, function_name) \ + void function_name(void* start, size_t size) { \ + size_t ctr_el0; \ + asm volatile("mrs %[ctr_el0], ctr_el0\n\t" : [ctr_el0] "=r"(ctr_el0)); \ + size_t cacheline_size = EXTRACT_DMINLINE(ctr_el0); \ + uintptr_t va_start = reinterpret_cast<uintptr_t>(start); \ + uintptr_t va_end = va_start + size; \ + for (uintptr_t va = va_start; va < va_end; va += cacheline_size) { \ + asm volatile("dc " #op_name ", %[va]\n\t" : : [va] "r"(va) : "memory"); \ + } \ + } + +#define DEFINE_DC_OP_DCZID(op_name, function_name) \ + void function_name(void* start, size_t size) { \ + size_t dczid_el0; \ + asm volatile("mrs %[dczid_el0], dczid_el0\n\t" : [dczid_el0] "=r"(dczid_el0)); \ + size_t cacheline_size = EXTRACT_BS(dczid_el0); \ + uintptr_t va_start = reinterpret_cast<uintptr_t>(start); \ + uintptr_t va_end = va_start + size; \ + for (uintptr_t va = va_start; va < va_end; va += cacheline_size) { \ + asm volatile("dc " #op_name ", %[va]\n\t" : : [va] "r"(va) : "memory"); \ + } \ + } + +DEFINE_DC_OP(cvau, DataCacheLineCleanByVAToPoU); +DEFINE_DC_OP(civac, DataCacheLineCleanAndInvalidateByVAToPoC); +DEFINE_DC_OP(cvac, DataCacheLineCleanByVAToPoC); +DEFINE_DC_OP_DCZID(zva, DataCacheZeroByVA); + +#endif + +} // namespace Common |