Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152966905
D53682.id166489.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D53682.id166489.diff
View Options
diff --git a/sys/dev/tpm/tpm_crb.c b/sys/dev/tpm/tpm_crb.c
--- a/sys/dev/tpm/tpm_crb.c
+++ b/sys/dev/tpm/tpm_crb.c
@@ -301,6 +301,48 @@
return (true);
}
+static bool
+tpmcrb_state_idle(struct tpmcrb_sc *crb_sc, bool wait)
+{
+ struct tpm_sc *sc;
+ int mask, timeout;
+
+ timeout = wait ? TPM_TIMEOUT_C : 0;
+
+ sc = &crb_sc->base;
+ OR4(sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_IDLE);
+
+ if (timeout > 0) {
+ mask = TPM_CRB_CTRL_STS_IDLE_BIT;
+ if (!tpm_wait_for_u32(sc, TPM_CRB_CTRL_STS, mask, mask,
+ timeout))
+ return (false);
+ }
+
+ return (true);
+}
+
+static bool
+tpmcrb_state_ready(struct tpmcrb_sc *crb_sc, bool wait)
+{
+ struct tpm_sc *sc;
+ int mask, timeout;
+
+ timeout = wait ? TPM_TIMEOUT_C : 0;
+
+ sc = &crb_sc->base;
+ OR4(sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_READY);
+
+ if (timeout > 0) {
+ mask = TPM_CRB_CTRL_REQ_GO_READY;
+ if (!tpm_wait_for_u32(sc, TPM_CRB_CTRL_STS, mask, !mask,
+ timeout))
+ return (false);
+ }
+
+ return (true);
+}
+
int
tpmcrb_transmit(device_t dev, size_t length)
{
@@ -335,22 +377,15 @@
/* Switch device to idle state if necessary */
if (!(TPM_READ_4(dev, TPM_CRB_CTRL_STS) & TPM_CRB_CTRL_STS_IDLE_BIT)) {
- OR4(sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_IDLE);
-
- mask = TPM_CRB_CTRL_STS_IDLE_BIT;
- if (!tpm_wait_for_u32(sc, TPM_CRB_CTRL_STS,
- mask, mask, TPM_TIMEOUT_C)) {
+ if (!tpmcrb_state_idle(crb_sc, true)) {
device_printf(dev,
"Failed to transition to idle state\n");
return (EIO);
}
}
- /* Switch to ready state */
- OR4(sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_READY);
- mask = TPM_CRB_CTRL_REQ_GO_READY;
- if (!tpm_wait_for_u32(sc, TPM_CRB_CTRL_STS,
- mask, !mask, TPM_TIMEOUT_C)) {
+ /* Switch to ready state */
+ if (!tpmcrb_state_ready(crb_sc, true)) {
device_printf(dev,
"Failed to transition to ready state\n");
return (EIO);
@@ -394,7 +429,11 @@
bus_read_region_stream_1(sc->mem_res, crb_sc->rsp_off + TPM_HEADER_SIZE,
&sc->buf[TPM_HEADER_SIZE], bytes_available - TPM_HEADER_SIZE);
- OR4(sc, TPM_CRB_CTRL_REQ, TPM_CRB_CTRL_REQ_GO_IDLE);
+ if (!tpmcrb_state_idle(crb_sc, false)) {
+ device_printf(dev,
+ "Failed to transition to idle state post-send\n");
+ return (EIO);
+ }
tpmcrb_relinquish_locality(sc);
sc->pending_data_length = bytes_available;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 19, 9:27 AM (7 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31710102
Default Alt Text
D53682.id166489.diff (2 KB)
Attached To
Mode
D53682: tpm: crb: factor out idle/ready state transitions
Attached
Detach File
Event Timeline
Log In to Comment