Commit 899102bc authored by Tomas Winkler's avatar Tomas Winkler Committed by Jarkko Sakkinen

tpm2: add new tpm2 commands according to TCG 1.36

1. TPM2_CC_LAST has moved from 182 to 193
2. Convert tpm2_ordinal_duration from an array into a switch statement,
   as there are not so many commands that require special duration
   relative to a number of commands, the switch statement function
   is called tpm2_ordinal_duration_index().
3. Fix kdoc comments for tpm2_calc_ordinal_duration().
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 2ba5780c
...@@ -134,22 +134,31 @@ enum tpm2_algorithms { ...@@ -134,22 +134,31 @@ enum tpm2_algorithms {
}; };
enum tpm2_command_codes { enum tpm2_command_codes {
TPM2_CC_FIRST = 0x011F, TPM2_CC_FIRST = 0x011F,
TPM2_CC_CREATE_PRIMARY = 0x0131, TPM2_CC_HIERARCHY_CONTROL = 0x0121,
TPM2_CC_SELF_TEST = 0x0143, TPM2_CC_HIERARCHY_CHANGE_AUTH = 0x0129,
TPM2_CC_STARTUP = 0x0144, TPM2_CC_CREATE_PRIMARY = 0x0131,
TPM2_CC_SHUTDOWN = 0x0145, TPM2_CC_SEQUENCE_COMPLETE = 0x013E,
TPM2_CC_CREATE = 0x0153, TPM2_CC_SELF_TEST = 0x0143,
TPM2_CC_LOAD = 0x0157, TPM2_CC_STARTUP = 0x0144,
TPM2_CC_UNSEAL = 0x015E, TPM2_CC_SHUTDOWN = 0x0145,
TPM2_CC_CONTEXT_LOAD = 0x0161, TPM2_CC_NV_READ = 0x014E,
TPM2_CC_CONTEXT_SAVE = 0x0162, TPM2_CC_CREATE = 0x0153,
TPM2_CC_FLUSH_CONTEXT = 0x0165, TPM2_CC_LOAD = 0x0157,
TPM2_CC_GET_CAPABILITY = 0x017A, TPM2_CC_SEQUENCE_UPDATE = 0x015C,
TPM2_CC_GET_RANDOM = 0x017B, TPM2_CC_UNSEAL = 0x015E,
TPM2_CC_PCR_READ = 0x017E, TPM2_CC_CONTEXT_LOAD = 0x0161,
TPM2_CC_PCR_EXTEND = 0x0182, TPM2_CC_CONTEXT_SAVE = 0x0162,
TPM2_CC_LAST = 0x018F, TPM2_CC_FLUSH_CONTEXT = 0x0165,
TPM2_CC_VERIFY_SIGNATURE = 0x0177,
TPM2_CC_GET_CAPABILITY = 0x017A,
TPM2_CC_GET_RANDOM = 0x017B,
TPM2_CC_PCR_READ = 0x017E,
TPM2_CC_PCR_EXTEND = 0x0182,
TPM2_CC_EVENT_SEQUENCE_COMPLETE = 0x0185,
TPM2_CC_HASH_SEQUENCE_START = 0x0186,
TPM2_CC_CREATE_LOADED = 0x0191,
TPM2_CC_LAST = 0x0193, /* Spec 1.36 */
}; };
enum tpm2_permanent_handles { enum tpm2_permanent_handles {
......
...@@ -40,129 +40,100 @@ static struct tpm2_hash tpm2_hash_map[] = { ...@@ -40,129 +40,100 @@ static struct tpm2_hash tpm2_hash_map[] = {
{HASH_ALGO_SM3_256, TPM2_ALG_SM3_256}, {HASH_ALGO_SM3_256, TPM2_ALG_SM3_256},
}; };
/* /**
* Array with one entry per ordinal defining the maximum amount * tpm2_ordinal_duration_index() - returns an index to the chip duration table
* of time the chip could take to return the result. The values * @ordinal: TPM command ordinal.
* of the SHORT, MEDIUM, and LONG durations are taken from the *
* PC Client Profile (PTP) specification. * The function returns an index to the chip duration table
* LONG_LONG is for commands that generates keys which empirically * (enum tpm_duration), that describes the maximum amount of
* takes longer time on some systems. * time the chip could take to return the result for a particular ordinal.
*
* The values of the MEDIUM, and LONG durations are taken
* from the PC Client Profile (PTP) specification (750, 2000 msec)
*
* LONG_LONG is for commands that generates keys which empirically takes
* a longer time on some systems.
*
* Return:
* * TPM_MEDIUM
* * TPM_LONG
* * TPM_LONG_LONG
* * TPM_UNDEFINED
*/ */
static const u8 tpm2_ordinal_duration[TPM2_CC_LAST - TPM2_CC_FIRST + 1] = { static u8 tpm2_ordinal_duration_index(u32 ordinal)
TPM_UNDEFINED, /* 11F */ {
TPM_UNDEFINED, /* 120 */ switch (ordinal) {
TPM_LONG, /* 121 */ /* Startup */
TPM_UNDEFINED, /* 122 */ case TPM2_CC_STARTUP: /* 144 */
TPM_UNDEFINED, /* 123 */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 124 */
TPM_UNDEFINED, /* 125 */ case TPM2_CC_SELF_TEST: /* 143 */
TPM_UNDEFINED, /* 126 */ return TPM_LONG;
TPM_UNDEFINED, /* 127 */
TPM_UNDEFINED, /* 128 */ case TPM2_CC_GET_RANDOM: /* 17B */
TPM_LONG, /* 129 */ return TPM_LONG;
TPM_UNDEFINED, /* 12a */
TPM_UNDEFINED, /* 12b */ case TPM2_CC_SEQUENCE_UPDATE: /* 15C */
TPM_UNDEFINED, /* 12c */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 12d */ case TPM2_CC_SEQUENCE_COMPLETE: /* 13E */
TPM_UNDEFINED, /* 12e */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 12f */ case TPM2_CC_EVENT_SEQUENCE_COMPLETE: /* 185 */
TPM_UNDEFINED, /* 130 */ return TPM_MEDIUM;
TPM_LONG_LONG, /* 131 */ case TPM2_CC_HASH_SEQUENCE_START: /* 186 */
TPM_UNDEFINED, /* 132 */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 133 */
TPM_UNDEFINED, /* 134 */ case TPM2_CC_VERIFY_SIGNATURE: /* 177 */
TPM_UNDEFINED, /* 135 */ return TPM_LONG;
TPM_UNDEFINED, /* 136 */
TPM_UNDEFINED, /* 137 */ case TPM2_CC_PCR_EXTEND: /* 182 */
TPM_UNDEFINED, /* 138 */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 139 */
TPM_UNDEFINED, /* 13a */ case TPM2_CC_HIERARCHY_CONTROL: /* 121 */
TPM_UNDEFINED, /* 13b */ return TPM_LONG;
TPM_UNDEFINED, /* 13c */ case TPM2_CC_HIERARCHY_CHANGE_AUTH: /* 129 */
TPM_UNDEFINED, /* 13d */ return TPM_LONG;
TPM_MEDIUM, /* 13e */
TPM_UNDEFINED, /* 13f */ case TPM2_CC_GET_CAPABILITY: /* 17A */
TPM_UNDEFINED, /* 140 */ return TPM_MEDIUM;
TPM_UNDEFINED, /* 141 */
TPM_UNDEFINED, /* 142 */ case TPM2_CC_NV_READ: /* 14E */
TPM_LONG, /* 143 */ return TPM_LONG;
TPM_MEDIUM, /* 144 */
TPM_UNDEFINED, /* 145 */ case TPM2_CC_CREATE_PRIMARY: /* 131 */
TPM_UNDEFINED, /* 146 */ return TPM_LONG_LONG;
TPM_UNDEFINED, /* 147 */ case TPM2_CC_CREATE: /* 153 */
TPM_UNDEFINED, /* 148 */ return TPM_LONG_LONG;
TPM_UNDEFINED, /* 149 */ case TPM2_CC_CREATE_LOADED: /* 191 */
TPM_UNDEFINED, /* 14a */ return TPM_LONG_LONG;
TPM_UNDEFINED, /* 14b */
TPM_UNDEFINED, /* 14c */ default:
TPM_UNDEFINED, /* 14d */ return TPM_UNDEFINED;
TPM_LONG, /* 14e */ }
TPM_UNDEFINED, /* 14f */ }
TPM_UNDEFINED, /* 150 */
TPM_UNDEFINED, /* 151 */ /**
TPM_UNDEFINED, /* 152 */ * tpm2_calc_ordinal_duration() - calculate the maximum command duration
TPM_LONG_LONG, /* 153 */ * @chip: TPM chip to use.
TPM_UNDEFINED, /* 154 */ * @ordinal: TPM command ordinal.
TPM_UNDEFINED, /* 155 */ *
TPM_UNDEFINED, /* 156 */ * The function returns the maximum amount of time the chip could take
TPM_UNDEFINED, /* 157 */ * to return the result for a particular ordinal in jiffies.
TPM_UNDEFINED, /* 158 */ *
TPM_UNDEFINED, /* 159 */ * Return: A maximal duration time for an ordinal in jiffies.
TPM_UNDEFINED, /* 15a */ */
TPM_UNDEFINED, /* 15b */ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
TPM_MEDIUM, /* 15c */ {
TPM_UNDEFINED, /* 15d */ unsigned int index;
TPM_UNDEFINED, /* 15e */
TPM_UNDEFINED, /* 15f */ index = tpm2_ordinal_duration_index(ordinal);
TPM_UNDEFINED, /* 160 */
TPM_UNDEFINED, /* 161 */ if (index != TPM_UNDEFINED)
TPM_UNDEFINED, /* 162 */ return chip->duration[index];
TPM_UNDEFINED, /* 163 */ else
TPM_UNDEFINED, /* 164 */ return msecs_to_jiffies(TPM2_DURATION_DEFAULT);
TPM_UNDEFINED, /* 165 */ }
TPM_UNDEFINED, /* 166 */ EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration);
TPM_UNDEFINED, /* 167 */
TPM_UNDEFINED, /* 168 */
TPM_UNDEFINED, /* 169 */
TPM_UNDEFINED, /* 16a */
TPM_UNDEFINED, /* 16b */
TPM_UNDEFINED, /* 16c */
TPM_UNDEFINED, /* 16d */
TPM_UNDEFINED, /* 16e */
TPM_UNDEFINED, /* 16f */
TPM_UNDEFINED, /* 170 */
TPM_UNDEFINED, /* 171 */
TPM_UNDEFINED, /* 172 */
TPM_UNDEFINED, /* 173 */
TPM_UNDEFINED, /* 174 */
TPM_UNDEFINED, /* 175 */
TPM_UNDEFINED, /* 176 */
TPM_LONG, /* 177 */
TPM_UNDEFINED, /* 178 */
TPM_UNDEFINED, /* 179 */
TPM_MEDIUM, /* 17a */
TPM_LONG, /* 17b */
TPM_UNDEFINED, /* 17c */
TPM_UNDEFINED, /* 17d */
TPM_UNDEFINED, /* 17e */
TPM_UNDEFINED, /* 17f */
TPM_UNDEFINED, /* 180 */
TPM_UNDEFINED, /* 181 */
TPM_MEDIUM, /* 182 */
TPM_UNDEFINED, /* 183 */
TPM_UNDEFINED, /* 184 */
TPM_MEDIUM, /* 185 */
TPM_MEDIUM, /* 186 */
TPM_UNDEFINED, /* 187 */
TPM_UNDEFINED, /* 188 */
TPM_UNDEFINED, /* 189 */
TPM_UNDEFINED, /* 18a */
TPM_UNDEFINED, /* 18b */
TPM_UNDEFINED, /* 18c */
TPM_UNDEFINED, /* 18d */
TPM_UNDEFINED, /* 18e */
TPM_UNDEFINED /* 18f */
};
struct tpm2_pcr_read_out { struct tpm2_pcr_read_out {
__be32 update_cnt; __be32 update_cnt;
...@@ -748,32 +719,6 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type) ...@@ -748,32 +719,6 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
tpm_buf_destroy(&buf); tpm_buf_destroy(&buf);
} }
/*
* tpm2_calc_ordinal_duration() - maximum duration for a command
*
* @chip: TPM chip to use.
* @ordinal: command code number.
*
* Return: maximum duration for a command
*/
unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
{
int index = TPM_UNDEFINED;
int duration = 0;
if (ordinal >= TPM2_CC_FIRST && ordinal <= TPM2_CC_LAST)
index = tpm2_ordinal_duration[ordinal - TPM2_CC_FIRST];
if (index != TPM_UNDEFINED)
duration = chip->duration[index];
if (duration <= 0)
duration = msecs_to_jiffies(TPM2_DURATION_DEFAULT);
return duration;
}
EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration);
/** /**
* tpm2_do_selftest() - ensure that all self tests have passed * tpm2_do_selftest() - ensure that all self tests have passed
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment