diff --git a/docs/SUBDEVICE_CONTROL_ABI.md b/docs/SUBDEVICE_CONTROL_ABI.md new file mode 100644 index 00000000..874454f4 --- /dev/null +++ b/docs/SUBDEVICE_CONTROL_ABI.md @@ -0,0 +1,99 @@ +# Subdevice control ABI: `0x20800110` / `0x20800111` / `0x20800170` + +This page is for anyone writing a client that issues RM controls against a GPU object and +wants the card's name strings and engine list back. It records where three commonly used +commands live in this driver's dispatch tables, what their reply buffers look like, and two +shapes of mistake that are easy to make and silent when they happen. + +Everything in [Facts](#facts) is read from this repository at base `d3c2897b6d0a5f367123043dda5603a73f926018` +(file:line citations inline). Everything in [Worked example](#worked-example-tu104) is output from our own +client on a TU104 and is illustrative only — it is not part of the ABI contract and not blob content. + +## Facts + +### 1. These three commands belong to the subdevice class + +The dispatch tables register all three under NVOC class **`0x4b01b3`** — the internal class of the +*subdevice* object (`class: 0x2080`, `internal_class: 0x4b01b3`, +`src/nvidia/src/resources.rs:513-515`): + +| Command | Registered row | Handler | +|---|---|---| +| `0x20800110` `GPU_GET_NAME_STRING` | `src/nvidia/src/rmapi/control_table.rs:565` | `src/nvidia/src/rmapi/gpu.rs:3008` (`gpu_name_string`) | +| `0x20800111` `GPU_GET_SHORT_NAME_STRING` | `src/nvidia/src/rmapi/control_table.rs:566` | `src/nvidia/src/rmapi/gpu.rs:3064` (`gpu_short_name_string`) | +| `0x20800170` `GPU_GET_ENGINES_V2` | `src/nvidia/src/rmapi/control_table.rs:623` | `src/nvidia/src/rmapi/providers/kernel_ce.rs:300` (`engines`) | + +Dispatch resolves a command against the addressed object's class and then its ancestors +(`src/nvidia/src/rmapi/server.rs:341-352`). If you send any of these three to the *device* +(`0x0080`) or to the binary-API root instead of the subdevice, the lookup misses and you get +status `0x56` (`NV_ERR_NOT_SUPPORTED`) before any handler runs. + +**This is a property of addressing, not of hardware.** Nothing about your GPU is missing or +unsupported; the command simply belongs to a different object than the one you named. +Re-address it at the subdevice handle. + +**Guidance, not measurement:** the subdevice handle is what clients normally receive per-GPU +from enumeration, so the practical rule is simply "issue `0x110/0x111/0x170` against the +subdevice you already hold". + +### 2. Reply buffers: two name commands, two different layouts + +`gpu_name_string` (handler cited above) writes a flags word first and the name starting at +offset 4 of the parameter buffer: + +- reads `u32` flags at offset 0 (`gpu.rs:3012`) +- writes the string at offset 4 for flag 0 (narrow) and as UTF-16LE at offset 4 for flag 1 + (`gpu.rs:3039-3058`; buffer length minus the leading word bounds the copy) + +`gpu_short_name_string` has no such preamble: the short name starts at offset **0** +(`gpu.rs:3081-3085`; the whole buffer is cleared first). + +A single `strcpy`-shaped routine pointed at offset 4 serves `0x110` but breaks `0x111`: its +first four bytes are left as the zeroes `clear` wrote, with the short name stranded at offset 4 — +a determinate wrong value, not garbage, and exactly the kind of corruption that passes a +casual "is there a string there" check. Handle the two layouts separately. + +### 3. `GPU_GET_ENGINES_V2` writes exactly `1 + count` words + +The `engines()` handler fills entries iteratively from a fixed engine table, stopping when the +table is exhausted or the buffer runs out, then writes the final count into the first word +(`kernel_ce.rs:308-315`): + +- word 0: number of engine words that follow (`count`) +- words 1..=count: engine type values, in table order +- everything after word `count` is left untouched — pre-filling the buffer with a sentinel is + safe and is how the handler's own offline test proves the boundary (`kernel_ce.rs:331-340`; + sentinel bytes remain beyond the written range) + +Reading past word `1 + count` yields whatever the client put there, not information about the +GPU. Size the buffer from the table bound (`param_size` 340 B per the registered row), not +from a guess about how many engines exist. + +## Worked example (TU104) + +The following comes from **our own test client's rendering of replies received through this +driver's dispatch path on a Quadro RTX 4000 (TU104GL-A)**. It shows the kind of payload these +commands produce; other parts return different names and lists, and nothing here is guaranteed +by the ABI: + +- `0x110` narrow-string reply (name at offset 4): `"Quadro RTX 4000"` +- `0x111` reply (short name at offset 0): `"TU104GL-A"` +- `0x170`: a multi-engine count followed by that many engine type words — on a Turing-class + part the plausible set spans GR0 plus copy engines plus decoder/encoder blocks, but see the + caveat below on what this example does and does not attest +- `0x800292` (`GPU_GET_CLASSLIST_V2`, registered for this same dispatch family): our client saw + 99 classes reported. Its count word is written as capacity **200** first and overwritten with + the real count only on success (handler doc `gpu.rs:3833-3835`, capacity at + `class_db.rs:44`); with more classes than fit, status is `0x3a` and the word keeps 200. + Unlike `0x170`, the handler does *not* promise to leave trailing buffer bytes untouched. + +These examples are **not** part of the contract: the class list grows across chip generations, +names differ per SKU, and count limits come from the registered buffer size, not from what one +card answered. + +## Traps recap + +1. Wrong object → `0x56`. Re-address at the subdevice; do not debug hardware. +2. One `strcpy` for both name commands → correct for `0x110`, silently wrong start offset for + `0x111`. +3. Pre-filling before `0x170` is safe; treating bytes after word `1 + count` as data is not.