#!/usr/bin/env python3 """Qualify actual context programming code offline; never open a device.""" import hashlib,json,re,struct,subprocess,sys from pathlib import Path ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'kits/XnuPrelink')) from native_prelink import macho kit=ROOT/'kits/ArmSmmu4K';out=ROOT/'build/arm-smmu-4k-program';out.mkdir(exist_ok=True) pins=json.loads((ROOT/'scripts/data/adreno-inputs.json').read_text());cache=ROOT/'.cache/adreno-source' names=['drivers/iommu/arm/arm-smmu/arm-smmu.h','drivers/iommu/arm/arm-smmu/arm-smmu.c'] def sha(path):return hashlib.sha256(path.read_bytes()).hexdigest() for name in names: if sha(cache/name)!=pins['linux']['files'][name]['sha256']:raise SystemExit('Pinned source differs: '+name) header=(cache/names[0]).read_text();implementation=(cache/names[1]).read_text() definitions={} for text in [header,implementation]: for match in re.finditer(r'^#define\s+(\w+)(\([^\n]*?\))?\s+((?:[^\n]*\\\n)*[^\n]*)',text,re.M): definitions[match[1]]=match[0] registers=['ARM_SMMU_GR0_ID0','ARM_SMMU_GR0_ID1','ARM_SMMU_GR0_ID2','ARM_SMMU_CB_SCTLR', 'ARM_SMMU_CB_TCR2','ARM_SMMU_CB_TTBR0','ARM_SMMU_CB_TTBR1','ARM_SMMU_CB_TCR', 'ARM_SMMU_CB_S1_MAIR0','ARM_SMMU_CB_S1_MAIR1','ARM_SMMU_CB_FSR','ARM_SMMU_CB_S1_TLBIASID', 'ARM_SMMU_CB_TLBSYNC','ARM_SMMU_CB_TLBSTATUS','ARM_SMMU_CB_FSR_FAULT','ARM_SMMU_GR1_CBA2R(0)','QCOM_DUMMY_VAL'] selected={} def include(name): if name in selected:return if name not in definitions:raise SystemExit('Missing actual source definition '+name) selected[name]=definitions[name] for dependency in set(re.findall(r'ARM_SMMU_[A-Z0-9_]+',definitions[name]))-{name}:include(dependency) for expression in registers:include(expression.split('(')[0]) oracle=out/'source-registers.c' oracle.write_text('#include \n#define BIT(n) (UINT32_C(1)<<(n))\n#define GENMASK(h,l) ((UINT32_MAX>>(31-(h))) & (UINT32_MAX<<(l)))\n'+ '\n'.join(selected.values())+'\nuint32_t source_register(unsigned i){const uint32_t r[]={'+','.join(registers)+'};return r[i];}\n') # Check the pinned writer's required TCR-before-TTBR ordering, independently # of our event fixture. This is source evidence, not timing or MMIO evidence. writer=implementation[implementation.index('void arm_smmu_write_context_bank'):] writer=writer[:writer.index('\n}',writer.index('{'))+2] if not writer.index('ARM_SMMU_CB_TCR2')