mirror of
https://github.com/UniXNU/NativeAdreno.git
synced 2026-11-17 13:01:46 +03:00
9d99240ee4
The board registers free DRAM the kernel does not manage with native_adreno_pool_add. A write-combined system BO first asks the pool (NativeAdrenoPool.cpp: a bitmap a range, best single run, else the longest runs first, zero fill through the range's own write-combined kernel mapping before a grant is handed out); whatever the pool does not serve takes the descriptor path unchanged. A pool BO has a grant and no descriptor: its spans are the grant's runs, nothing of it is cleaned, audited or read through the cacheable aperture, its client view maps its physical runs write-combined and holds the grant until IOKit frees the view, and an import of pool pages is refused. Pages a client had a view of are retired unless gpu-pool=2; gpu-pool=0 turns the pool off. Counters: native_adreno_pool_state, native_adreno_pool_fallbacks, native_adreno_pool_zero. Host tests: test_pool (allocator against a page model) and test_pool_memory (BO paths); the existing 23 pass as before, test_client and test_gmuconfig fail as at the base. Every changed kernel source passes the kernel's compile recipe as a syntax check. Not built into an image and not run on hardware.
44 lines
2.3 KiB
C++
44 lines
2.3 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// Kernel services absent from the host model. Tests can replace these weak defaults.
|
|
#include "XnuMemoryFixture.h"
|
|
#include "NativeAdrenoMemory.h"
|
|
#include "NativeAdrenoPool.h"
|
|
extern "C" __attribute__((weak)) boolean_t PE_parse_boot_argn(const char *,void *,int) {return 0;}
|
|
__attribute__((weak)) void NativeAdrenoNotePhase(unsigned,size_t) {}
|
|
__attribute__((weak)) bool NativeAdrenoPagesUncached(const NativeAdrenoPhysicalSpan *,size_t) {return false;}
|
|
extern "C" __attribute__((weak)) unsigned native_pmap_user_mappings(ppnum_t,void **,uint64_t *,char *) {return 0;}
|
|
extern "C" {__attribute__((weak)) volatile uint32_t native_gpu_dcvs[15]{};}
|
|
extern "C" __attribute__((weak)) int proc_selfpid() {return 1;}
|
|
extern "C" __attribute__((weak)) uint64_t native_adreno_now_us() {return 0;}
|
|
|
|
extern "C" __attribute__((weak)) void native_gpu_trace_record(uint32_t,uint32_t,const uint64_t *,uint32_t) {}
|
|
|
|
// The pool's kernel services: a range's "kernel mapping" is host memory that stands for its pages, filled with a pattern no test
|
|
// writes, so a page handed out without its zero fill shows. The scrub is the kernel's: lines dropped (counted), then zeros.
|
|
extern "C" {__attribute__((weak)) unsigned native_adreno_host_pool_drops=0;}
|
|
__attribute__((weak)) void *NativeAdrenoPoolMapRange(uint64_t physical,size_t bytes,void **owner)
|
|
{
|
|
if(!owner || !physical || !bytes)return nullptr;
|
|
void *memory=nullptr;
|
|
if(posix_memalign(&memory,4096,bytes))return nullptr;
|
|
std::memset(memory,0xa5,bytes);
|
|
*owner=memory;
|
|
return memory;
|
|
}
|
|
__attribute__((weak)) IOReturn NativeAdrenoPoolScrub(void *mapping,size_t bytes,bool drop_lines)
|
|
{
|
|
if(!mapping || !bytes || (((uintptr_t)mapping|bytes)&4095))return kIOReturnBadArgument;
|
|
if(drop_lines)++native_adreno_host_pool_drops;
|
|
std::memset(mapping,0,bytes);
|
|
return kIOReturnSuccess;
|
|
}
|
|
// A host program built without NativeAdrenoPool.cpp has no pool: every system BO takes the descriptor path. NativeAdrenoPool.cpp's
|
|
// own definitions replace these wherever it is linked.
|
|
__attribute__((weak)) IOReturn NativeAdrenoPoolAllocate(size_t,uint64_t,bool,NativeAdrenoPoolGrant **out)
|
|
{
|
|
if(out)*out=nullptr;
|
|
return kIOReturnUnsupported;
|
|
}
|
|
__attribute__((weak)) void NativeAdrenoPoolRelease(NativeAdrenoPoolGrant *) {}
|
|
__attribute__((weak)) bool NativeAdrenoPoolContains(uint64_t,uint64_t) {return false;}
|