[SeaBIOS] [RFC PATCH 2/2] tcgbios: extend physical presence interface with more functions

Stefan Berger stefanb at linux.vnet.ibm.com
Thu Jan 11 15:57:02 CET 2018


Implement more functions of the physical presence interface.
Some of the added functions will automatically reboot the machine.
Thus we need to save the next step after the reboot in an additional
variable.

Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
 src/std/tcg.h |  7 +++++++
 src/tcgbios.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/src/std/tcg.h b/src/std/tcg.h
index 0aeafe8..459cbd4 100644
--- a/src/std/tcg.h
+++ b/src/std/tcg.h
@@ -548,8 +548,15 @@ struct pcctes_romex
 #define TPM_PPI_OP_ACTIVATE 3
 #define TPM_PPI_OP_DEACTIVATE 4
 #define TPM_PPI_OP_CLEAR 5
+#define TPM_PPI_OP_ENABLE_ACTIVATE 6
+#define TPM_PPI_OP_DEACTIVATE_DISABLE 7
 #define TPM_PPI_OP_SET_OWNERINSTALL_TRUE 8
 #define TPM_PPI_OP_SET_OWNERINSTALL_FALSE 9
+#define TPM_PPI_OP_ENABLE_ACTIVATE_SET_OWNERINSTALL_TRUE 10
+#define TPM_PPI_OP_SET_OWNERINSTALL_FALSE_DEACTIVATE_DISABLE 11
+#define TPM_PPI_OP_CLEAR_ENABLE_ACTIVATE 14
+#define TPM_PPI_OP_ENABLE_ACTIVATE_CLEAR 21
+#define TPM_PPI_OP_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE 22
 
 #define TPM_PPI_ADDR_BASE  0xffff0000
 
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 2adca71..d45716a 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -1646,7 +1646,7 @@ tpm12_set_owner_install(int allow, int verbose)
 }
 
 static int
-tpm12_process_cfg(tpm_ppi_code msgCode, int verbose)
+tpm12_process_cfg(tpm_ppi_code msgCode, int verbose, u8 *next_step)
 {
     int ret = 0;
 
@@ -1674,6 +1674,18 @@ tpm12_process_cfg(tpm_ppi_code msgCode, int verbose)
             ret = tpm12_force_clear(1, 0, verbose);
             break;
 
+        case TPM_PPI_OP_ENABLE_ACTIVATE:
+            ret = tpm12_enable_tpm(1, verbose);
+            if (!ret)
+                ret = tpm12_activate_tpm(1, 1, verbose);
+            break;
+
+        case TPM_PPI_OP_DEACTIVATE_DISABLE:
+            ret = tpm12_activate_tpm(0, 1, verbose);
+            if (!ret)
+                ret = tpm12_enable_tpm(0, verbose);
+            break;
+
         case TPM_PPI_OP_SET_OWNERINSTALL_TRUE:
             ret = tpm12_set_owner_install(1, verbose);
             break;
@@ -1682,6 +1694,43 @@ tpm12_process_cfg(tpm_ppi_code msgCode, int verbose)
             ret = tpm12_set_owner_install(0, verbose);
             break;
 
+        case TPM_PPI_OP_ENABLE_ACTIVATE_SET_OWNERINSTALL_TRUE:
+            *next_step = TPM_PPI_OP_SET_OWNERINSTALL_TRUE;
+            ret = tpm12_enable_activate(1, verbose);
+            if (!ret)
+                ret = tpm12_set_owner_install(1, verbose);
+            break;
+
+        case TPM_PPI_OP_SET_OWNERINSTALL_FALSE_DEACTIVATE_DISABLE:
+            ret = tpm12_set_owner_install(0, verbose);
+            if (!ret)
+                ret = tpm12_activate_tpm(0, 0, verbose);
+            if (!ret)
+                ret = tpm12_enable_tpm(0, verbose);
+            break;
+
+        case TPM_PPI_OP_CLEAR_ENABLE_ACTIVATE:
+            ret = tpm12_force_clear(0, 1, verbose);
+            break;
+
+        case TPM_PPI_OP_ENABLE_ACTIVATE_CLEAR:
+            *next_step = TPM_PPI_OP_CLEAR;
+            ret = tpm12_enable_activate(1, verbose);
+            /* no reboot happened */
+            if (!ret)
+                ret = tpm12_force_clear(0, 0, verbose);
+            break;
+
+        case TPM_PPI_OP_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
+            *next_step = TPM_PPI_OP_CLEAR_ENABLE_ACTIVATE;
+            ret = tpm12_enable_activate(1, verbose);
+            /* no reboot happened */
+            if (!ret) {
+                 *next_step = TPM_PPI_OP_NONE;
+                ret = tpm12_force_clear(0, 1, verbose);
+            }
+            break;
+
         default:
             break;
     }
@@ -1774,11 +1823,11 @@ tpm20_process_cfg(tpm_ppi_code msgCode, int verbose)
 }
 
 static int
-tpm_process_cfg(tpm_ppi_code msgCode, int verbose)
+tpm_process_cfg(tpm_ppi_code msgCode, int verbose, u8 *next_step)
 {
     switch (TPM_version) {
     case TPM_VERSION_1_2:
-        return tpm12_process_cfg(msgCode, verbose);
+        return tpm12_process_cfg(msgCode, verbose, next_step);
     case TPM_VERSION_2:
         return tpm20_process_cfg(msgCode, verbose);
     }
@@ -1950,7 +1999,8 @@ tpm12_menu(void)
                     break;
 
                 if (next_scancodes[i] == scancode) {
-                    tpm12_process_cfg(msgCode, 1);
+                    u8 ignore;
+                    tpm12_process_cfg(msgCode, 1, &ignore);
                     waitkey = 0;
                     break;
                 }
@@ -2026,7 +2076,7 @@ tpm_can_show_menu(void)
 }
 
 static struct tpm_ppi *tp;
-static u8 next_step; /* next opcode to execute after reboot */
+static u8 next_step = TPM_PPI_OP_NONE; /* opcode to execute after reboot */
 
 void
 tpm_ppi_init(void)
@@ -2065,7 +2115,7 @@ tpm_ppi_process(void)
             tp->pprq = 0;
 
             printf("Processing TPM PPI opcode %d\n", op);
-            tp->fail = (tpm_process_cfg(op, 0) != 0);
+            tp->fail = (tpm_process_cfg(op, 0, &next_step) != 0);
             if (tp->fail)
                 tp->pprp = 0x0badc0de;
             else
-- 
2.5.5




More information about the SeaBIOS mailing list