/* SPDX-License-Identifier: MIT */ /* System BOs of pool pages over host doubles: a write-combined BO takes a grant and no descriptor, its spans are the grant's runs, * nothing of it is ever maintained, release and the release after the lock give the pages up, a quarantined BO keeps them, a viewed * grant is retired (gpu-pool=1), an import of pool pages is refused and whatever the pool cannot serve takes the descriptor path. */ #include "XnuMemoryFixture.h" #include "NativeAdrenoMemory.h" #include "NativeAdrenoPool.h" #include #define CHECK(x) do {if(!(x)){std::fprintf(stderr,"line %d: %s\n",__LINE__,#x);std::exit(1);}}while(0) extern "C" volatile uint32_t native_adreno_bo_memory[8]; extern "C" int proc_selfpid() {return 7;} static unsigned physical_calls,owned_calls; IOReturn NativeAdrenoQueryCpu4K(NativeAdrenoCpuState *out) {CHECK(out);*out={};return kIOReturnSuccess;} IOReturn NativeAdrenoMaintainOwnedPages(void *,size_t,NativeAdrenoCacheOperation) {++owned_calls;return kIOReturnSuccess;} IOReturn NativeAdrenoSetPagesCacheMode(const NativeAdrenoPhysicalSpan *,size_t,bool) {CHECK(false);return kIOReturnSuccess;} IOReturn NativeAdrenoReassertWriteCombined(const NativeAdrenoPhysicalSpan *,size_t,uint32_t *) {CHECK(false);return kIOReturnSuccess;} IOReturn NativeAdrenoMaintainPhysicalPages(uint64_t physical,size_t,NativeAdrenoCacheOperation) {CHECK(physical(2),0x10000,8192,40,8192)==kIOReturnNotPermitted && !imported.backed() && !fixture.imports_live); fixture.next_physical=saved; CHECK(!imported.importTask(reinterpret_cast(2),0x10000,8192,40,8192) && !imported.release()); /* A quarantined BO keeps its pages: nothing returns to the pool. */ NativeAdrenoMemory q; CHECK(!q.allocateSystem(65536,40,65536,true) && q.poolGrant()); const uint32_t held=native_adreno_pool_state[2]; q.quarantine(); CHECK(q.release()==kIOReturnBusy && q.releaseSystemInto(&freed)==kIOReturnBusy && !freed.held() && q.poolGrant()); CHECK(native_adreno_pool_state[2]==held && native_adreno_pool_state[4]==2); /* A client view holds the grant past the BO; with the default gpu-pool the viewed pages are then retired, not reused. */ NativeAdrenoPoolGrant *const view=a.poolGrant(); NativeAdrenoPoolRetain(view);NativeAdrenoPoolNoteView(view); CHECK(!a.release() && !a.backed() && native_adreno_pool_state[4]==2 && native_adreno_pool_state[2]==held); NativeAdrenoPoolRelease(view); CHECK(native_adreno_pool_state[4]==1 && native_adreno_pool_state[8]==1 && native_adreno_pool_state[9]==2048 && native_adreno_pool_state[2]==held); CHECK(fixture.live.empty() && !owned_calls); std::printf("pool memory: %u served, fallbacks kind %u exhausted %u\n",native_adreno_pool_state[6], native_adreno_pool_fallbacks[NativeAdrenoPoolKind],native_adreno_pool_fallbacks[NativeAdrenoPoolExhausted]); return 0; }