Files
NativeAdreno/tests/test_gmumem.cpp
bluseliu50 d834731657 feat(adreno): on-demand GPU page tables and a 2^ias address space
Each GPU address space takes its table pages one at a time from the
system (NativeAdrenoTablePages) instead of a 1027-page pool, so the
aperture is the bank's whole input size: ias from ID2.UBS as Linux
arm_smmu_id_size_to_bits reads it. Every process maps from
ADRENO_VM_START (4 GiB) to 2^ias, as msm's adreno_private_vm_size.
The GMU keeps its 0..2 GiB space. The alias scratch belongs to each
VM and grows with its range table. A map that cannot get a table page
is undone and returns kIOReturnNoMemory without poisoning the VM.
Host tests cover a sparse 48-bit space and the refusal.
2026-11-01 05:20:57 +08:00

70 lines
3.7 KiB
C++

/* SPDX-License-Identifier: MIT */
/* Real allocator/layout over host IOKit doubles. No mapping or GMU access. */
#include "XnuMemoryFixture.h"
#include "NativeAdrenoGmuMemory.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define CHECK(x) do {if(!(x)){std::fprintf(stderr,"line %d: %s\n",__LINE__,#x);std::exit(1);}}while(0)
IOReturn NativeAdrenoQueryCpu4K(NativeAdrenoCpuState *state)
{CHECK(state);*state={};return kIOReturnSuccess;}
IOReturn NativeAdrenoMaintainOwnedPages(void *mapping,size_t bytes,NativeAdrenoCacheOperation op)
{
CHECK(mapping && bytes && op<=NativeAdrenoInvalidate);
return kIOReturnSuccess;
}
int main()
{
{
NativeAdrenoGmuAllocator allocator;
CHECK(allocator.allocate(NativeAdrenoGmuDefaultSizes())==kIOReturnSuccess && allocator.ready());
const NativeAdrenoGmuMemoryLayout &layout=allocator.layout();
/* a6xx_gmu.c at the pinned tree: icache 0x4000, dummy 0x60000000, debug 0x60400000; log and hfi
* take the lowest free pages after the 16 KiB dummy. */
CHECK(layout.icache_iova==0x4000);
CHECK(layout.dummy_iova==0x60000000);
CHECK(layout.debug_iova==0x60400000);
CHECK(layout.log_iova==0x60004000);
CHECK(layout.hfi_iova==0x60008000);
CHECK(layout.end_iova==0x60407000);
CHECK(allocator.icache().bytes()==0xffc000 && allocator.icache().spanCount()==1);
CHECK(allocator.hfi().bytes()==0x4000 && !allocator.tables().pageCount());
CHECK(allocator.allocate(NativeAdrenoGmuDefaultSizes())==kIOReturnBusy);
CHECK(allocator.release()==kIOReturnSuccess && !allocator.ready());
CHECK(fixture.live.empty());
}
/* Bad sizes, payloads that leave their fixed range, and allocation failure leave nothing behind. */
{
NativeAdrenoGmuAllocator allocator;
NativeAdrenoGmuSizes big=NativeAdrenoGmuDefaultSizes();
big.icache=0x60000000; /* would run into the uncached range */
CHECK(allocator.allocate(big)==kIOReturnBadArgument);
big=NativeAdrenoGmuDefaultSizes();
big.hfi=0x400000; /* dummy+log+hfi past 0x60400000 */
CHECK(allocator.allocate(big)==kIOReturnBadArgument);
big=NativeAdrenoGmuDefaultSizes();
big.debug=0x20000000; /* past the 2 GiB GMU space */
CHECK(allocator.allocate(big)==kIOReturnBadArgument);
CHECK(!allocator.ready() && fixture.live.empty());
}
{
fixture=MemoryFixture{};
fixture.allocation_fail=true;
NativeAdrenoGmuAllocator allocator;
CHECK(allocator.allocate(NativeAdrenoGmuDefaultSizes())==kIOReturnNoMemory);
CHECK(!allocator.ready() && fixture.live.empty());
fixture.allocation_fail=false;
}
std::printf("PASS: 1 fixed a6xx GMU layout allocation and release, 3 size/range refusals, 1 allocation failure and 1 repeat-allocation refusal over host doubles\n");
}
/* Physical-page maintenance (imported BOs): record it; no host page is touched. */
/* Host double: the page attribute change of user BOs has no host equivalent (no host page is touched). */
IOReturn NativeAdrenoSetPagesCacheMode(const NativeAdrenoPhysicalSpan *spans,size_t count,bool){return spans && count?kIOReturnSuccess:kIOReturnBadArgument;}
IOReturn NativeAdrenoReassertWriteCombined(const NativeAdrenoPhysicalSpan *spans,size_t count,uint32_t *reset)
{return spans && count && reset?kIOReturnSuccess:kIOReturnBadArgument;}
IOReturn NativeAdrenoMaintainPhysicalPages(uint64_t physical,size_t bytes,NativeAdrenoCacheOperation op)
{
if(!physical || !bytes || ((physical|bytes)&4095) || op>NativeAdrenoInvalidate)std::abort();
++fixture.physical_calls;fixture.physical_bytes+=bytes;return kIOReturnSuccess;
}