git: a2a0ded3cdc1 - stable/15 - tpm: crb: Support the ACPI start method
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Nov 2026 01:20:19 UTC
The branch stable/15 has been updated by kbowling:
URL: https://cgit.FreeBSD.org/src/commit/?id=a2a0ded3cdc1f11aafcbb0efcf9eabf982da0c08
commit a2a0ded3cdc1f11aafcbb0efcf9eabf982da0c08
Author: Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-11 09:33:56 +0000
Commit: Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-11-13 01:20:07 +0000
tpm: crb: Support the ACPI start method
Some AMD firmware TPMs report StartMethod 2 and had no driver. They never
acknowledge CTRL_REQ, so skip the idle and ready requests.
Do not harvest entropy from these TPMs on AMD: on a Ryzen 7 7735HS each
periodic TPM2_GetRandom froze every CPU, for up to 1.2 s (AMD PA-410).
Reviewed by: kbowling
Approved by: kbowling
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/103
(cherry picked from commit 6af18560a124b84549713a5f2b667a1df0990929)
---
sys/dev/tpm/tpm20.c | 17 +++++----
sys/dev/tpm/tpm20.h | 1 +
sys/dev/tpm/tpm_crb.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 104 insertions(+), 9 deletions(-)
diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c
index b5d40eeac7d7..aced216c352d 100644
--- a/sys/dev/tpm/tpm20.c
+++ b/sys/dev/tpm/tpm20.c
@@ -277,10 +277,13 @@ tpm20_init(struct tpm_sc *sc)
return (result);
#if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM
- random_source_register(&random_tpm);
TIMEOUT_TASK_INIT(taskqueue_thread, &sc->harvest_task, 0,
tpm20_harvest, sc);
- taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0);
+ if (!sc->no_harvest) {
+ random_source_register(&random_tpm);
+ taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task,
+ 0);
+ }
#endif
sc->common_initialized = true;
@@ -306,7 +309,8 @@ tpm20_release(struct tpm_sc *sc)
goto out;
#if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM
taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task);
- random_source_deregister(&random_tpm);
+ if (!sc->no_harvest)
+ random_source_deregister(&random_tpm);
#endif
sc->common_initialized = false;
out:
@@ -338,8 +342,9 @@ out:
return (error);
#if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM
- taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task,
- hz * TPM_HARVEST_INTERVAL);
+ if (!sc->no_harvest)
+ taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task,
+ hz * TPM_HARVEST_INTERVAL);
#endif
return (0);
}
@@ -369,7 +374,7 @@ tpm20_suspend(device_t dev)
out:
sx_xunlock(&sc->dev_lock);
#if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM
- if (error != 0)
+ if (error != 0 && !sc->no_harvest)
taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task,
hz * TPM_HARVEST_INTERVAL);
#endif
diff --git a/sys/dev/tpm/tpm20.h b/sys/dev/tpm/tpm20.h
index f4dcb2fe4e9a..2ff195264ba8 100644
--- a/sys/dev/tpm/tpm20.h
+++ b/sys/dev/tpm/tpm20.h
@@ -150,6 +150,7 @@ struct tpm_sc {
bool common_initialized;
bool dying;
bool suspended;
+ bool no_harvest; /* Set by the transport before tpm20_init() */
struct tpm_priv *internal_priv;
diff --git a/sys/dev/tpm/tpm_crb.c b/sys/dev/tpm/tpm_crb.c
index e191699e4e4c..bf0ff1bae9d4 100644
--- a/sys/dev/tpm/tpm_crb.c
+++ b/sys/dev/tpm/tpm_crb.c
@@ -28,6 +28,10 @@
#include <sys/cdefs.h>
#include "tpm20.h"
+#if defined(__amd64__) || defined(__i386__)
+#include <x86/cputypes.h>
+#endif
+
/*
* PTP locality registers, relative to the start of the ACPI memory resource.
* TCG PC Client PTP 1.03, section 5.5.3.1, Table 23.
@@ -89,8 +93,12 @@ struct tpmcrb_sm_cfg {
sm_detach_t *sm_detach;
sm_statechange_t *sm_statechange;
sm_statechange_t *sm_cmdready;
+ sm_statechange_t *sm_cancel;
+ bool no_idle_states; /* CTRL_REQ is not acknowledged */
};
+static sm_attach_t acpi_start_attach;
+static sm_statechange_t acpi_start_invoke;
static sm_attach_t pluton_attach;
static sm_detach_t pluton_detach;
static sm_statechange_t pluton_doorbell;
@@ -106,6 +114,16 @@ static const struct tpmcrb_sm_cfg_map {
.desc = "Trusted Platform Module 2.0, CRB mode",
.sm_cfg = { NULL }, /* No notifications required */
},
+ {
+ .acpi_sm = TPM2_START_METHOD_ACPI,
+ .desc = "Trusted Platform Module 2.0, CRB mode (ACPI start)",
+ .sm_cfg = {
+ .sm_attach = &acpi_start_attach,
+ .sm_cmdready = &acpi_start_invoke,
+ .sm_cancel = &acpi_start_invoke,
+ .no_idle_states = true,
+ },
+ },
{
.acpi_sm = ACPI_TPM2_COMMAND_BUFFER_WITH_PLUTON,
.desc = "Trusted Platform Module 2.0, CRB mode (Pluton)",
@@ -138,6 +156,7 @@ struct tpmcrb_sc {
bus_space_handle_t start_bsh;
bus_space_handle_t reply_bsh;
} pluton;
+ ACPI_HANDLE acpi_start_handle;
};
bus_space_tag_t bst;
struct tpmcrb_mapping ctrl;
@@ -593,6 +612,8 @@ tpmcrb_cancel_cmd(struct tpmcrb_sc *crb_sc)
uint32_t mask = ~0;
tpmcrb_ctrl_write_4(crb_sc, TPM_CRB_CTRL_CANCEL, TPM_CRB_CTRL_CANCEL_CMD);
+ if (crb_sc->sm_cfg->sm_cancel != NULL)
+ (void)(*crb_sc->sm_cfg->sm_cancel)(crb_sc, 0);
if (!tpmcrb_ctrl_wait(crb_sc, TPM_CRB_CTRL_START,
mask, ~mask, TPM_TIMEOUT_B)) {
device_printf(crb_sc->base.dev,
@@ -633,6 +654,8 @@ tpmcrb_state_idle(struct tpmcrb_sc *crb_sc, bool wait)
{
int mask, timeout;
+ if (crb_sc->sm_cfg->no_idle_states)
+ return (true);
timeout = wait ? TPM_TIMEOUT_C : 0;
tpmcrb_ctrl_write_4(crb_sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_IDLE);
@@ -656,6 +679,8 @@ tpmcrb_state_ready(struct tpmcrb_sc *crb_sc, bool wait)
{
int mask, timeout;
+ if (crb_sc->sm_cfg->no_idle_states)
+ return (true);
timeout = wait ? TPM_TIMEOUT_C : 0;
tpmcrb_ctrl_write_4(crb_sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_READY);
@@ -753,9 +778,7 @@ tpmcrb_transmit(device_t dev, struct tpm_priv *priv, size_t length)
command_started = true;
if (!tpmcrb_notify_cmdready(crb_sc, timeout)) {
- device_printf(dev,
- "Timeout while waiting for device to ready (cmd=%#x)\n",
- curr_cmd);
+ device_printf(dev, "Start method failed (cmd=%#x)\n", curr_cmd);
if (!tpmcrb_cancel_cmd(crb_sc)) {
error = EIO;
goto out;
@@ -828,6 +851,72 @@ out:
/* StartMethod Implementation Details */
+/*
+ * ACPI start method: TCG ACPI Specification 1.4, section 4.1. After setting
+ * CTRL_START or CTRL_CANCEL, the driver evaluates _DSM function 1 to ask the
+ * firmware to act on the control area. Some firmware using this method
+ * never acknowledges CTRL_REQ, so the idle and ready states are skipped.
+ */
+#define TPM_ACPI_START_REV 0
+#define TPM_ACPI_START_FUNC_START 1
+
+/* 6BBF6CAB-5463-4714-B7CD-F0203C0368D4 */
+static const uint8_t tpm_acpi_start_uuid[ACPI_UUID_LENGTH] = {
+ 0xab, 0x6c, 0xbf, 0x6b, 0x63, 0x54, 0x14, 0x47,
+ 0xb7, 0xcd, 0xf0, 0x20, 0x3c, 0x03, 0x68, 0xd4
+};
+
+static bool
+acpi_start_attach(struct tpmcrb_sc *crb_sc, void *smdataregion __unused,
+ size_t datasz __unused)
+{
+ ACPI_HANDLE handle;
+
+ handle = acpi_get_handle(crb_sc->base.dev);
+ if (handle == NULL || (acpi_DSMQuery(handle, tpm_acpi_start_uuid,
+ TPM_ACPI_START_REV) & (1 << TPM_ACPI_START_FUNC_START)) == 0) {
+ device_printf(crb_sc->base.dev, "No ACPI start method in _DSM\n");
+ return (false);
+ }
+ crb_sc->acpi_start_handle = handle;
+#if defined(__amd64__) || defined(__i386__)
+ /* AMD advisory PA-410: fTPM commands can stall every CPU. */
+ if (cpu_vendor_id == CPU_VENDOR_AMD) {
+ device_printf(crb_sc->base.dev,
+ "Not used as an entropy source (AMD PA-410)\n");
+ crb_sc->base.no_harvest = true;
+ }
+#endif
+ return (true);
+}
+
+static bool
+acpi_start_invoke(struct tpmcrb_sc *crb_sc, int timeout __unused)
+{
+ ACPI_BUFFER buf;
+ ACPI_OBJECT *obj;
+ ACPI_STATUS status;
+ bool ret;
+
+ status = acpi_EvaluateDSMTyped(crb_sc->acpi_start_handle,
+ tpm_acpi_start_uuid, TPM_ACPI_START_REV, TPM_ACPI_START_FUNC_START,
+ NULL, &buf, ACPI_TYPE_INTEGER);
+ if (ACPI_FAILURE(status)) {
+ device_printf(crb_sc->base.dev,
+ "ACPI start method failed: %s\n",
+ AcpiFormatException(status));
+ return (false);
+ }
+ obj = buf.Pointer;
+ ret = obj->Integer.Value == 0;
+ if (!ret)
+ device_printf(crb_sc->base.dev,
+ "ACPI start method returned %ju\n",
+ (uintmax_t)obj->Integer.Value);
+ AcpiOsFree(buf.Pointer);
+ return (ret);
+}
+
/** Pluton **/
struct tpmcrb_startmethod_pluton {
uint64_t sm_startaddr;