summaryrefslogtreecommitdiff
path: root/sys/dev/ic/tpmreg.h
diff options
context:
space:
mode:
authormartin <martin@NetBSD.org>2022-08-03 16:00:47 +0000
committermartin <martin@NetBSD.org>2022-08-03 16:00:47 +0000
commit041f0bae70183514e3e452cbce4a36c3f0137745 (patch)
treed3d4530185ca053a255c05af90602419f17524e9 /sys/dev/ic/tpmreg.h
parent351d30dbc7897502cf6d653004326befb43c5d6f (diff)
Pull up following revision(s) (requested by riastradh in ticket #1495):
share/man/man4/tpm.4: revision 1.7 sys/dev/ic/tpm.c: revision 1.17 sys/dev/ic/tpmvar.h: revision 1.10 sys/dev/ic/tpm.c: revision 1.18 sys/dev/ic/tpm.c: revision 1.19 sys/dev/acpi/tpm_acpi.c: revision 1.14 sys/dev/ic/tpmreg.h: revision 1.10 sys/dev/ic/tpmreg.h: revision 1.11 sys/dev/ic/tpm.c: revision 1.21 sys/dev/ic/tpm.c: revision 1.22 sys/dev/ic/tpm.c: revision 1.23 sys/dev/ic/tpm.c: revision 1.24 sys/dev/ic/tpm.c: revision 1.25 sys/dev/ic/tpmreg.h: revision 1.7 sys/dev/ic/tpmreg.h: revision 1.8 sys/dev/ic/tpmreg.h: revision 1.9 sys/dev/ic/tpmvar.h: revision 1.8 sys/dev/ic/tpmvar.h: revision 1.9 dev/ic/tpm: Tidy up headers. - Add include guards. - Add necessary includes. - Sort includes. - Use _BYTE_ORDER, not BYTE_ORDER, for public header. dev/ic/tpm: Add missing line break in attach output. dev/ic/tpm: Take advantage of entropy source if available. If the tpm is deactivated, though, detach the entropy source so we don't continue to try polling it -- it can't be activated without a reboot anyway. Add note about enabling TPM and rnd(4) source. tpm(4): Handle TPM 2.0 random source too, and loop on short reads. Tested on ThinkPad T480. tpm(4): Preserve error if any on ending commands. This way we don't spuriously suppress an error, such as TPM_DEACTIVATED, in a loop where we rely on it. tpm@acpi: Require only one locality's worth of register space. We don't actually use the registers for the other localities, and some older TPMs only have the first locality exposed via ACPI. tpm(4): Fix disabling of rnd source if tpm is deactivated. Nothing prevents a second worker from being queued when the first one is about to do rnd_detach_source. Instead, just set a flag so future requests don't bother running a new thread; if there's a concurrent one that's already been scheduled on another CPU, well, too bad, we get a couple extra log messages but that's fine. A better way to do this would probably be to detect whether the tpm is deactivated at attach time, but that requires reading more of the tpm spec than I care to do when there are alternative ways to procrastinate like scrubbing the toilet. tpm(4): Fix suspend and rework I/O transaction lock. Use sc->sc_lock over individual I/O transactions, not open/close of the whole device. This way there is a bounded time before the tpm is unbusied even if userland is getting at it, so userland can't hold up suspend indefinitely. Of course, the tpm might be suspended and resumed in the middle of the user's session this way -- tough. This limits the response buffer to 1024 bytes -- which is already a bit hefty to have on the stack (but it's probably not very deep on the stack from userland so maybe not a big deal). If it turns out we need more, we can use kmem to allocate a buffer on the heap, with the caveat that it might fail. This is necessary so that suspend doesn't block indefinitely on uiomove in tpmread. tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
Diffstat (limited to 'sys/dev/ic/tpmreg.h')
-rw-r--r--sys/dev/ic/tpmreg.h77
1 files changed, 67 insertions, 10 deletions
diff --git a/sys/dev/ic/tpmreg.h b/sys/dev/ic/tpmreg.h
index 0cc988c195b..218c9c1dc1c 100644
--- a/sys/dev/ic/tpmreg.h
+++ b/sys/dev/ic/tpmreg.h
@@ -1,4 +1,4 @@
-/* $NetBSD: tpmreg.h,v 1.4.2.1 2019/10/16 09:52:38 martin Exp $ */
+/* $NetBSD: tpmreg.h,v 1.4.2.2 2022/08/03 16:00:47 martin Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,13 +29,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-#define TPM_BE16(a) bswap16(a)
-#define TPM_BE32(a) bswap32(a)
-#else
-#define TPM_BE16(a) (a)
-#define TPM_BE32(a) (a)
-#endif
+#ifndef DEV_IC_TPMREG_H
+#define DEV_IC_TPMREG_H
+
+#include <sys/types.h>
+
+#include <sys/cdefs.h>
+#include <sys/endian.h>
struct tpm_header {
uint16_t tag;
@@ -102,6 +102,63 @@ struct tpm_header {
#define TPM_REV 0x0f04 /* 8bit register */
/*
- * Five localities, 4K per locality.
+ * Five localities, 4K per locality. But we only use the registers for
+ * the first locality, so this is 0x1000 rather than 0x5000.
+ */
+#define TPM_SPACE_SIZE 0x1000
+
+#define TPM_TAG_RQU_COMMAND 0x00c1
+#define TPM_TAG_RSP_COMMAND 0x00c4
+
+#define TPM_ORD_GetRandom 0x00000046
+
+/* TPM_RESULT return codes */
+#define TPM_AUTHFAIL 1
+#define TPM_BADINDEX 2
+#define TPM_BAD_PARAMETER 3
+#define TPM_AUDITFAILURE 4
+#define TPM_CLEAR_DISABLED 5
+#define TPM_DEACTIVATED 6
+#define TPM_DISABLED 7
+#define TPM_DISABLED_CMD 8
+#define TPM_FAIL 9
+#define TPM_BAD_ORDINAL 10
+/* ... */
+
+#define TPM_NON_FATAL 0x800
+
+/* -------------------------------------------------------------------------- */
+
+/*
+ * Trusted Platform Module Library Specification, Family "2.0",
+ * Level 00, Revision 01.59 -- November 2019
+ *
+ * https://trustedcomputinggroup.org/resource/tpm-library-specification/
+ *
+ * Where this spec names things TPM_* that don't obviously coincide
+ * with the 1.2 things, we name them TPM2_*.
*/
-#define TPM_SPACE_SIZE 0x5000
+
+/* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-4-Supporting-Routines-01.38-code.pdf#page=172 */
+#define TPM2_ST_RSP_COMMAND 0x00c4
+#define TPM2_ST_NULL 0x8000
+#define TPM2_ST_NO_SESSIONS 0x8001
+#define TPM2_ST_SESSIONS 0x8002
+/* ... */
+
+/* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf#page=45 */
+#define TPM2_CC_GetRandom 0x0000017b
+
+/* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf#page=53 */
+#define TPM2_RC_SUCCESS 0x000
+#define TPM2_RC_BAD_TAG 0x01e
+
+#define TPM2_RC_VER1 0x100
+
+#define TPM2_RC_FMT1 0x080
+
+#define TPM2_RC_WARN 0x900
+#define TPM2_RC_TESTING (TPM2_RC_WARN + 0x00a)
+#define TPM2_RC_RETRY (TPM2_RC_WARN + 0x022)
+
+#endif /* DEV_IC_TPMREG_H */