summaryrefslogtreecommitdiffstats
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2022-11-20 16:31:20 +0100
committerGitHub <noreply@github.com>2022-11-20 16:31:20 +0100
commitdb7bcd51ae09c4ef25e08096de563903f61e2380 (patch)
tree5ae9977b48e1aff118fae3ebffb215b0b4afa887 /src/core/memory.cpp
parentservice: nfc: Implement nfc user (diff)
parentMerge pull request #9238 from german77/cabinet_applet (diff)
downloadyuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar.gz
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar.bz2
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar.lz
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar.xz
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.tar.zst
yuzu-db7bcd51ae09c4ef25e08096de563903f61e2380.zip
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r--src/core/memory.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 3ca80c8ff..3141122f1 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -6,6 +6,7 @@
#include "common/assert.h"
#include "common/atomic_ops.h"
+#include "common/cache_management.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/page_table.h"
@@ -329,6 +330,55 @@ struct Memory::Impl {
});
}
+ template <typename Callback>
+ Result PerformCacheOperation(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size,
+ Callback&& cb) {
+ class InvalidMemoryException : public std::exception {};
+
+ try {
+ WalkBlock(
+ process, dest_addr, size,
+ [&](const std::size_t block_size, const VAddr current_vaddr) {
+ LOG_ERROR(HW_Memory, "Unmapped cache maintenance @ {:#018X}", current_vaddr);
+ throw InvalidMemoryException();
+ },
+ [&](const std::size_t block_size, u8* const host_ptr) { cb(block_size, host_ptr); },
+ [&](const VAddr current_vaddr, const std::size_t block_size, u8* const host_ptr) {
+ system.GPU().FlushRegion(current_vaddr, block_size);
+ cb(block_size, host_ptr);
+ },
+ [](const std::size_t block_size) {});
+ } catch (InvalidMemoryException&) {
+ return Kernel::ResultInvalidCurrentMemory;
+ }
+
+ return ResultSuccess;
+ }
+
+ Result InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // Do nothing; this operation (dc ivac) cannot be supported
+ // from EL0
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
+ Result StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // dc cvac: Store to point of coherency
+ Common::DataCacheLineCleanByVAToPoC(host_ptr, block_size);
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
+ Result FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
+ auto perform = [&](const std::size_t block_size, u8* const host_ptr) {
+ // dc civac: Store to point of coherency, and invalidate from cache
+ Common::DataCacheLineCleanAndInvalidateByVAToPoC(host_ptr, block_size);
+ };
+ return PerformCacheOperation(process, dest_addr, size, perform);
+ }
+
void MarkRegionDebug(VAddr vaddr, u64 size, bool debug) {
if (vaddr == 0) {
return;
@@ -786,6 +836,21 @@ void Memory::ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, const s
impl->ZeroBlock(process, dest_addr, size);
}
+Result Memory::InvalidateDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->InvalidateDataCache(process, dest_addr, size);
+}
+
+Result Memory::StoreDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->StoreDataCache(process, dest_addr, size);
+}
+
+Result Memory::FlushDataCache(const Kernel::KProcess& process, VAddr dest_addr,
+ const std::size_t size) {
+ return impl->FlushDataCache(process, dest_addr, size);
+}
+
void Memory::RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
impl->RasterizerMarkRegionCached(vaddr, size, cached);
}