diff --git a/docs/development/npu-upscaler.md b/docs/development/npu-upscaler.md index 4936097483..63a8af1aaa 100644 --- a/docs/development/npu-upscaler.md +++ b/docs/development/npu-upscaler.md @@ -46,6 +46,29 @@ Wire format that worked (transaction codes are the AIDL order): `IDspService` 1 the compute DSP. The reply is `[status][1][size][int][int][NativeHandle: size, fd count, fds, int count]`. `tools/experiments/npu-fastrpc-probe` reproduces all of it; results go to logcat tag `NPUPROBE`. +### AYN Thor (QCS8550, Hexagon v73, Android 13, release-keys): closed + +- `/dev/adsprpc-smd` is `0664 system:system` and `open(O_RDWR)` from an app gives `EACCES`. There is no + `/dev/fastrpc-cdsp`. +- There is no `IDspService` here. `checkService` returns null, and SELinux logs a `find` denial for + `untrusted_app` on `default_android_service`. +- `dlopen("libcdsprpc.so")` fails with "not found" even with `` declared. +- So no route was found on this device without root. SELinux is enforcing here, which is the case the 8 Elite tests + could not cover. + +### How BananaNative's PR (moceure/BananaNative #703) gets in + +It declares ``, then +`dlopen("libcdsprpc.so")`, `remote_handle_control(4, {domain 3, enable 1})` to request an unsigned PD, and an +`ADSP_LIBRARY_PATH` that puts the app's own `adsp` directory first so the DSP can load the HTP skel from the app. +That only works on firmware that exposes the vendor library to apps; its logs are from a Xiaomi phone on a v81 SoC. +It does not work on the three Qualcomm-reference style builds tried here (Duo, FIT Elite, Thor), where the library is +invisible to app namespaces. Useful from it, if the NPU path goes ahead: a process-wide ref-counted QNN HTP runtime +shared by two users, zero-copy `AHardwareBuffer` DMA-BUF registration, a thermal power tier (turbo, balanced, low) +with hysteresis, and clamping the ADPF target duration to the frame-generated output period so the PowerHAL does not +halve a 2x frame-generated game. Its MIT-licensed GLSL for flow, splat and blend is a possible reference for DD-FG. +Its QNN graph binaries come from a companion repo; where they derive from is a licence question. + Caveats: - SELinux is permissive on both devices (dev-keys builds). On an enforcing production build, `untrusted_app` may not @@ -67,7 +90,7 @@ Caveats: be built as the app's own `libcdsprpc.so`, with the device open replaced by the binder call above. QNN stubs resolve `libcdsprpc.so` from the app's library directory, so they would pick it up unchanged. 2. Run a QNN HTP graph with the user's own QAIRT libraries (v79 skel for the 8 Elite) to prove an end-to-end NPU run. -3. Check the binder route on an enforcing build and on an 8 Elite Gen 5 device. +3. Check the binder route on an enforcing 8 Elite build and on an 8 Elite Gen 5 device. Thor (v73) has no route at all. 4. Decide the hook point. Guest-side (Winlator's approach) is the only one that can run FSR 4; compositor-side limits it to spatial super-resolution. 5. GPU-only FSR 4.1 Lite (DP4a) behind the hook, since it needs no NPU access and exercises the same plumbing. diff --git a/tools/experiments/npu-fastrpc-probe/AndroidManifest.xml b/tools/experiments/npu-fastrpc-probe/AndroidManifest.xml index dfe92368b6..c87568b568 100644 --- a/tools/experiments/npu-fastrpc-probe/AndroidManifest.xml +++ b/tools/experiments/npu-fastrpc-probe/AndroidManifest.xml @@ -1,6 +1,7 @@ + diff --git a/tools/experiments/npu-fastrpc-probe/probe.c b/tools/experiments/npu-fastrpc-probe/probe.c index f42a0c2b38..b746c82139 100644 --- a/tools/experiments/npu-fastrpc-probe/probe.c +++ b/tools/experiments/npu-fastrpc-probe/probe.c @@ -11,10 +11,27 @@ #include #include #include +#include +#include #include #define L(...) do { char b[600]; snprintf(b, sizeof b, __VA_ARGS__); __android_log_write(ANDROID_LOG_INFO, "NPUPROBE", b); } while (0) static void *oc(void *a){return a;} static void od(void *a){} static binder_status_t ot(AIBinder *b, transaction_code_t c, const AParcel *i, AParcel *o){return STATUS_UNKNOWN_TRANSACTION;} + +typedef uint32_t remote_handle; +/* Route A: what BananaNative does: dlopen the vendor libcdsprpc from the app namespace. */ +static void route_dlopen(void) { + void *h = dlopen("libcdsprpc.so", RTLD_NOW | RTLD_LOCAL); + L("A dlopen(libcdsprpc.so) = %s", h ? "ok" : dlerror()); + if (!h) return; + int (*ctl)(int, void *, uint32_t) = dlsym(h, "remote_handle_control"); + int (*cap)(int, uint32_t, uint32_t *) = dlsym(h, "fastrpc_get_cap"); + int (*opn)(int, const char *, remote_handle *) = dlsym(h, "remote_handle_open_domain"); + L("A syms control=%p get_cap=%p open_domain=%p", ctl, cap, opn); + if (ctl) { struct { uint32_t domain, enable; } req = {3, 1}; L("A unsigned-pd control r=%d", ctl(4, &req, sizeof req)); } + if (cap) for (uint32_t i = 0; i < 3; i++) { uint32_t v = 0xdead; int r = cap(3, i, &v); L("A get_cap(cdsp,%u) r=0x%x v=%u", i, r, v); } + if (opn) { remote_handle rh = 0; errno = 0; int r = opn(3, "file:///libhalide_hexagon_remote_skel.so?halide_hexagon_initialize_kernels&_modver=1.0", &rh); L("A open_domain r=0x%x errno=%d", r, errno); } +} static void dump_dev(AParcel *r) { int32_t v[16]; int n = 0; int32_t pos = AParcel_getDataPosition(r), size = AParcel_getDataSize(r); @@ -24,6 +41,9 @@ static void dump_dev(AParcel *r) { void ANativeActivity_onCreate(ANativeActivity *a, void *s, size_t n) { L("uid=%d", getuid()); + route_dlopen(); + { const char *nodes[] = {"/dev/fastrpc-cdsp", "/dev/adsprpc-smd"}; + for (int i = 0; i < 2; i++) { int f = open(nodes[i], O_RDWR | O_CLOEXEC); L("direct open(%s) fd=%d errno=%d", nodes[i], f, errno); if (f >= 0) close(f); } } const char *name = "vendor.qti.hardware.dsp.IDspService/default"; AIBinder *(*chk)(const char *) = dlsym(RTLD_DEFAULT, "AServiceManager_checkService"); L("dlsym checkService=%p", chk);