Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/backend/hw/tpm.om # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / backend / hw / tpm.om` 200 lines · 5047 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note tpm.om: hwman unit 3, the TPM 2.0 DIRECT_DEVICE runner (runner hwman-tpm). It writes complete 3 note TPM 2.0 command frames to the kernel resource-manager node named in the row (/dev/tpmrm0) and reads 4 note the response frame back; there is no TSS library. Frame layout and constants, TCG TPM 2.0 Library 5 note Part 2/3, as transcribed in tpm2-tss 4.0.1 include/tss2/tss2_tpm2_types.h and Linux 6 note include/linux/tpm.h: 7 note header tag UINT16 | commandSize UINT32 | commandCode UINT32 (big-endian, 10 bytes) 8 note tag TPM2_ST_NO_SESSIONS 0x8001 9 note GetCapability 0x0000017a: capability UINT32, property UINT32, propertyCount UINT32 10 note response: moreData BYTE, capability UINT32, count UINT32, count x (property UINT32, value UINT32) 11 note TPM2_CAP_TPM_PROPERTIES 6; TPM2_PT_FIXED 0x100; TPM2_PT_REVISION 0x102; 12 note TPM2_PT_MANUFACTURER 0x105; TPM2_PT_FIRMWARE_VERSION_1 0x10b, _2 0x10c 13 note GetRandom 0x0000017b: bytesRequested UINT16; response TPM2B_DIGEST (size UINT16, bytes) 14 note TPM2_RC_SUCCESS 0; TPM2_RC_COMMAND_CODE 0x143; TPM2_RC_COMMAND_SIZE 0x142 15 note TSS2_RESMGR_TPM_RC_LAYER 11 << 16: Linux tpm-dev-common.c synthesizes TPM2_RC_COMMAND_CODE | 16 note TSS2_RESMGR_TPM_RC_LAYER = 0x000b0143 for a command code the chip does not list 17 note (tpm2_prepare_space -EOPNOTSUPP); that frame never reaches the chip 18 note Every response is checked: responseSize equals the bytes read, tag 0x8001, then per command the 19 note exact parameter layout. The response read waits at most the row's timeout_ms (waitio). 20 note Operations: props (identity and firmware), getrandom N (1..32 bytes). Fault frames (fault command): 21 note badsize a GetRandom frame whose commandSize says 13 but 12 bytes are written 22 note badcc a 10-byte frame with commandCode 0x11e, below TPM2_CC_FIRST 0x11f (no such command); 23 note /dev/tpmrm0 answers it in the kernel resource manager with rc 0x000b0143 24 25 text TPMPROPS "props" 26 text TPMRAND "getrandom" 27 text TPMBSZ "badsize" 28 text TPMBADCC "badcc" 29 const TPMMAXR ulong 32 30 note responses that are not TPM frames, and a response that did not arrive in time 31 const TPMEFRM long -1000 32 const TPMETIME long -1001 33 34 global gcmd uchar 64 35 global gresp uchar 4096 36 37 fn tpmp16 o ulong v ulong to void 38 put gcmd o uchar and shr v 8 255 39 put gcmd add o 1 uchar and v 255 40 end 41 42 fn tpmp32 o ulong v ulong to void 43 tpmp16 o shr v 16 44 tpmp16 add o 2 and v 65535 45 end 46 47 fn tpmg16 o ulong to ulong 48 ret or shl ulong get gresp o 8 ulong get gresp add o 1 49 end 50 51 fn tpmg32 o ulong to ulong 52 ret or shl tpmg16 o 16 tpmg16 add o 2 53 end 54 55 fn tpmhdr size ulong cc ulong to void 56 tpmp16 0 0x8001 57 tpmp32 2 size 58 tpmp32 6 cc 59 end 60 61 note open the row's device node read-write: descriptor or -errno 62 fn tpmopen to long 63 pclear 64 pfield CNODE 65 ret fopen gpath 0 get gst 5 2 0 66 end 67 68 note write n command bytes, wait up to tmo nanoseconds, read and frame-check the response. 69 note Returns the response length; -errno when the kernel refused the write or read; TPMETIME; TPMEFRM. 70 fn tpmxfer fd int n ulong tmo long to long 71 w = write fd gcmd 0 n 72 if lt w 0 73 ret w 74 end 75 if ne w long n 76 ret TPMEFRM 77 end 78 p = waitio fd 1 tmo 79 if lt p 0 80 ret p 81 end 82 if eq p 0 83 ret TPMETIME 84 end 85 r = read fd gresp 0 len gresp 86 if lt r 0 87 ret r 88 end 89 if lt r 10 90 ret TPMEFRM 91 end 92 if ne tpmg32 2 ulong r 93 ret TPMEFRM 94 end 95 if ne tpmg16 0 0x8001 96 ret TPMEFRM 97 end 98 put gst 14 tpmg32 6 99 ret r 100 end 101 102 note TPM2_GetCapability(TPM_PROPERTIES, PT_FIXED, 64): manufacturer gst 10, firmware gst 11/12, 103 note revision gst 13. Returns 0, a negative transfer result, or the TPM response code (> 0). 104 fn tpmprops fd int tmo long to long 105 tpmhdr 22 0x17a 106 tpmp32 10 6 107 tpmp32 14 0x100 108 tpmp32 18 64 109 r = tpmxfer fd 22 tmo 110 if lt r 0 111 ret r 112 end 113 rc = get gst 14 114 if ne rc 0 115 ret long rc 116 end 117 n = ulong r 118 if lt n 19 119 ret TPMEFRM 120 end 121 if ne tpmg32 11 6 122 ret TPMEFRM 123 end 124 c = tpmg32 15 125 if ne add 19 mul c 8 n 126 ret TPMEFRM 127 end 128 seen = ulong 0 129 for i ulong c 130 p = tpmg32 add 19 mul i 8 131 v = tpmg32 add 23 mul i 8 132 if eq p 0x105 133 put gst 10 v 134 seen = or seen 1 135 end 136 if eq p 0x10b 137 put gst 11 v 138 seen = or seen 2 139 end 140 if eq p 0x10c 141 put gst 12 v 142 seen = or seen 4 143 end 144 if eq p 0x102 145 put gst 13 v 146 seen = or seen 8 147 end 148 end 149 if ne seen 15 150 ret TPMEFRM 151 end 152 ret 0 153 end 154 155 note TPM2_GetRandom(n): the n bytes are left at gresp[12..12+n). Returns 0, a negative transfer 156 note result, or the TPM response code. 157 fn tpmrand fd int n ulong tmo long to long 158 tpmhdr 12 0x17b 159 tpmp16 10 n 160 r = tpmxfer fd 12 tmo 161 if lt r 0 162 ret r 163 end 164 rc = get gst 14 165 if ne rc 0 166 ret long rc 167 end 168 if ne ulong r add 12 n 169 ret TPMEFRM 170 end 171 if ne tpmg16 10 n 172 ret TPMEFRM 173 end 174 ret 0 175 end 176 177 note fault frame argument a: returns the transfer result (negative) or the TPM response code; 178 note gst 9 is 1 when a names no fault frame 179 fn tpmfault fd int a ulong tmo long to long 180 put gst 9 0 181 if argeq a TPMBSZ 182 tpmhdr 13 0x17b 183 tpmp16 10 16 184 r = tpmxfer fd 12 tmo 185 if lt r 0 186 ret r 187 end 188 ret long get gst 14 189 end 190 if argeq a TPMBADCC 191 tpmhdr 10 0x11e 192 r = tpmxfer fd 10 tmo 193 if lt r 0 194 ret r 195 end 196 ret long get gst 14 197 end 198 put gst 9 1 199 ret 0 200 end