]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: tpm: Tidy up enums and return values
authorSimon Glass <sjg@chromium.org>
Mon, 1 Oct 2018 17:55:17 +0000 (11:55 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 9 Oct 2018 10:40:27 +0000 (04:40 -0600)
Use an enum for command values instead of open-coding them. This removes
the need for comments. Also make sure the driver returns proper error
numbers instead of -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/tpm/tpm_tis_sandbox.c
include/tpm-v1.h
include/tpm-v2.h

index 8816d55759fdf7bba66537bbf9efe2434afe6a49..c0b35a06c8a0f003fbc6105b3a20a2352ad88fd4 100644 (file)
@@ -151,10 +151,10 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
               *recv_len, code);
        print_buffer(0, sendbuf, 1, send_size, 0);
        switch (code) {
-       case 0x65: /* get flags */
+       case TPM_CMD_GET_CAPABILITY:
                type = get_unaligned_be32(sendbuf + 14);
                switch (type) {
-               case 4:
+               case TPM_CAP_FLAG:
                        index = get_unaligned_be32(sendbuf + 18);
                        printf("Get flags index %#02x\n", index);
                        *recv_len = 22;
@@ -173,7 +173,7 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
                                break;
                        }
                        break;
-               case 0x11: /* TPM_CAP_NV_INDEX */
+               case TPM_CAP_NV_INDEX:
                        index = get_unaligned_be32(sendbuf + 18);
                        printf("Get cap nv index %#02x\n", index);
                        put_unaligned_be32(22, recvbuf +
@@ -182,26 +182,26 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
                default:
                        printf("   ** Unknown 0x65 command type %#02x\n",
                               type);
-                       return -1;
+                       return -ENOSYS;
                }
                break;
-       case 0xcd: /* nvwrite */
+       case TPM_CMD_NV_WRITE_VALUE:
                index = get_unaligned_be32(sendbuf + 10);
                length = get_unaligned_be32(sendbuf + 18);
                seq = index_to_seq(index);
                if (seq < 0)
-                       return -1;
+                       return -EINVAL;
                printf("tpm: nvwrite index=%#02x, len=%#02x\n", index, length);
                memcpy(&tpm->nvdata[seq], sendbuf + 22, length);
                *recv_len = 12;
                memset(recvbuf, '\0', *recv_len);
                break;
-       case 0xcf: /* nvread */
+       case TPM_CMD_NV_READ_VALUE: /* nvread */
                index = get_unaligned_be32(sendbuf + 10);
                length = get_unaligned_be32(sendbuf + 18);
                seq = index_to_seq(index);
                if (seq < 0)
-                       return -1;
+                       return -EINVAL;
                printf("tpm: nvread index=%#02x, len=%#02x\n", index, length);
                *recv_len = TPM_RESPONSE_HEADER_LENGTH + sizeof(uint32_t) +
                                        length;
@@ -225,7 +225,7 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
                               sizeof(uint32_t), &tpm->nvdata[seq], length);
                }
                break;
-       case 0x14: /* tpm extend */
+       case TPM_CMD_EXTEND: /* tpm extend */
        case 0x15: /* pcr read */
        case 0x5d: /* force clear */
        case 0x6f: /* physical enable */
@@ -237,7 +237,7 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
                break;
        default:
                printf("Unknown tpm command %02x\n", code);
-               return -1;
+               return -ENOSYS;
        }
 
        return 0;
index 6b4941ef9a2f1969f6e59854e444b71d177517b7..29788b5390f7bde9f3f90d4bd6c56eb5f40eaf12 100644 (file)
@@ -81,6 +81,12 @@ enum tpm_capability_areas {
        TPM_CAP_VERSION_VAL     = 0x0000001A,
 };
 
+enum tmp_cap_flag {
+       TPM_CAP_FLAG_PERMANENT  = 0x108,
+};
+
+#define TPM_TAG_PERMANENT_FLAGS                0x001f
+
 #define TPM_NV_PER_GLOBALLOCK          BIT(15)
 #define TPM_NV_PER_PPREAD              BIT(16)
 #define TPM_NV_PER_PPWRITE             BIT(0)
@@ -93,6 +99,14 @@ enum {
        TPM_PUBEK_SIZE                  = 256,
 };
 
+enum {
+       TPM_CMD_EXTEND                  = 0x14,
+       TPM_CMD_GET_CAPABILITY          = 0x65,
+       TPM_CMD_NV_DEFINE_SPACE         = 0xcc,
+       TPM_CMD_NV_WRITE_VALUE          = 0xcd,
+       TPM_CMD_NV_READ_VALUE           = 0xcf,
+};
+
 /**
  * TPM return codes as defined in the TCG Main specification
  * (TPM Main Part 2 Structures; Specification version 1.2)
index 780e0619750cef4c6c8ea6c2144b2de9196b1e3b..c77b416182ed78ff4ac4c45d1d22381d0e28ed50 100644 (file)
@@ -83,6 +83,7 @@ enum tpm2_command_codes {
        TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
        TPM2_CC_DAM_RESET       = 0x0139,
        TPM2_CC_DAM_PARAMETERS  = 0x013A,
+       TPM2_CC_NV_READ         = 0x014E,
        TPM2_CC_GET_CAPABILITY  = 0x017A,
        TPM2_CC_PCR_READ        = 0x017E,
        TPM2_CC_PCR_EXTEND      = 0x0182,