diff --git a/core/libs/prx/libSceAgcDriver/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/CMakeLists.txt index 86645f54d..3490c5852 100644 --- a/core/libs/prx/libSceAgcDriver/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/CMakeLists.txt @@ -403,6 +403,7 @@ target_include_directories(agc_driver_pm4_tests PRIVATE target_link_libraries(agc_driver_pm4_tests PRIVATE libSceAgcDriver libc + libkernel ) set_target_properties(agc_driver_pm4_tests PROPERTIES CXX_EXTENSIONS OFF) diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp index 1e319192e..4292b133f 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp @@ -10,15 +10,16 @@ #include #include -extern "C" int APS5_VABI sceKernelMapFlexibleMemory(void** addr_in_out, size_t len, int prot, int flags); +extern "C" void* APS5_VABI mmap_nid_postfix(void* address, std::size_t length, int protection, int flags, int descriptor, std::int64_t offset) noexcept; namespace AgcDriver::Pm4 { std::uint64_t GdsAddress() { static const std::uint64_t address = [] { - constexpr int CpuGpuReadWrite = 0x33; - void* mapped = nullptr; - if (sceKernelMapFlexibleMemory(&mapped, GdsBytes, CpuGpuReadWrite, 0) != 0 || mapped == nullptr) throw std::runtime_error("cannot allocate the global data share"); + constexpr int ReadWrite = 0x3; + constexpr int PrivateAnonymous = 0x1002; + void* mapped = mmap_nid_postfix(nullptr, GdsBytes, ReadWrite, PrivateAnonymous, -1, 0); + if (mapped == nullptr || mapped == reinterpret_cast(static_cast(-1))) throw std::runtime_error("cannot allocate the global data share"); return reinterpret_cast(mapped); }(); return address; diff --git a/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp b/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp index 661d07a16..86640969c 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Pm4.cpp @@ -22,6 +22,8 @@ #include #endif +extern "C" int APS5_VABI sceKernelAvailableFlexibleMemorySize(size_t* size); + namespace { void check(bool condition, const char* reason) { @@ -320,9 +322,13 @@ void testCopies() { execute(state, makePacket(0x50, {0x40000000, 0x44332211, 0, low(destination.data()), high(destination.data()), 6})); check(destination[0] == 0x44332211 && destination[1] == 0x00002211, "DMA_DATA byte fill failed"); constexpr std::uint32_t cachePolicies = (1u << 13u) | (2u << 25u); + std::size_t flexibleBefore = 0; + check(sceKernelAvailableFlexibleMemorySize(&flexibleBefore) == 0, "cannot query flexible memory"); const auto toGds = makePacket(0x50, {0x60100000 | cachePolicies, low(source.data()), high(source.data()), 0x100, 0, 16}); check(!AgcDriver::Pm4::ResolveStore(toGds, state, 64).has_value(), "DMA_DATA to GDS resolved as a memory store"); execute(state, toGds); + std::size_t flexibleAfter = 0; + check(sceKernelAvailableFlexibleMemorySize(&flexibleAfter) == 0 && flexibleAfter == flexibleBefore, "the GDS was charged to the flexible memory budget"); execute(state, makePacket(0x50, {0x20100000, 0x104, 0, 0xfff8, 0, 8})); destination = {}; execute(state, makePacket(0x50, {0x20000000 | cachePolicies, 0xfff8, 0, low(destination.data()), high(destination.data()), 8}));