Commit b34b77a9 authored by Jarkko Sakkinen's avatar Jarkko Sakkinen

tpm: declare struct tpm_header

Declare struct tpm_header that replaces struct tpm_input_header and
struct tpm_output_header.
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
Tested-by: default avatarAlexander Steffen <Alexander.Steffen@infineon.com>
parent aff0c20b
...@@ -62,12 +62,10 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) ...@@ -62,12 +62,10 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
} }
EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration); EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
static int tpm_validate_command(struct tpm_chip *chip, static int tpm_validate_command(struct tpm_chip *chip, struct tpm_space *space,
struct tpm_space *space, const void *cmd, size_t len)
const u8 *cmd,
size_t len)
{ {
const struct tpm_input_header *header = (const void *)cmd; const struct tpm_header *header = cmd;
int i; int i;
u32 cc; u32 cc;
u32 attrs; u32 attrs;
...@@ -161,12 +159,10 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags) ...@@ -161,12 +159,10 @@ static int tpm_go_idle(struct tpm_chip *chip, unsigned int flags)
return chip->ops->go_idle(chip); return chip->ops->go_idle(chip);
} }
static ssize_t tpm_try_transmit(struct tpm_chip *chip, static ssize_t tpm_try_transmit(struct tpm_chip *chip, struct tpm_space *space,
struct tpm_space *space, void *buf, size_t bufsiz, unsigned int flags)
u8 *buf, size_t bufsiz,
unsigned int flags)
{ {
struct tpm_output_header *header = (void *)buf; struct tpm_header *header = buf;
int rc; int rc;
ssize_t len = 0; ssize_t len = 0;
u32 count, ordinal; u32 count, ordinal;
...@@ -325,7 +321,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, ...@@ -325,7 +321,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
u8 *buf, size_t bufsiz, unsigned int flags) u8 *buf, size_t bufsiz, unsigned int flags)
{ {
struct tpm_output_header *header = (struct tpm_output_header *)buf; struct tpm_header *header = (struct tpm_header *)buf;
/* space for header and handles */ /* space for header and handles */
u8 save[TPM_HEADER_SIZE + 3*sizeof(u32)]; u8 save[TPM_HEADER_SIZE + 3*sizeof(u32)];
unsigned int delay_msec = TPM2_DURATION_SHORT; unsigned int delay_msec = TPM2_DURATION_SHORT;
...@@ -390,8 +386,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, ...@@ -390,8 +386,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
struct tpm_buf *buf, size_t min_rsp_body_length, struct tpm_buf *buf, size_t min_rsp_body_length,
unsigned int flags, const char *desc) unsigned int flags, const char *desc)
{ {
const struct tpm_output_header *header = const struct tpm_header *header = (struct tpm_header *)buf->data;
(struct tpm_output_header *)buf->data;
int err; int err;
ssize_t len; ssize_t len;
......
...@@ -273,16 +273,13 @@ struct tpm_chip { ...@@ -273,16 +273,13 @@ struct tpm_chip {
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)
struct tpm_input_header { struct tpm_header {
__be16 tag; __be16 tag;
__be32 length; __be32 length;
__be32 ordinal; union {
} __packed; __be32 ordinal;
__be32 return_code;
struct tpm_output_header { };
__be16 tag;
__be32 length;
__be32 return_code;
} __packed; } __packed;
#define TPM_TAG_RQU_COMMAND 193 #define TPM_TAG_RQU_COMMAND 193
...@@ -401,8 +398,8 @@ struct tpm_buf { ...@@ -401,8 +398,8 @@ struct tpm_buf {
static inline void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal) static inline void tpm_buf_reset(struct tpm_buf *buf, u16 tag, u32 ordinal)
{ {
struct tpm_input_header *head; struct tpm_header *head = (struct tpm_header *)buf->data;
head = (struct tpm_input_header *)buf->data;
head->tag = cpu_to_be16(tag); head->tag = cpu_to_be16(tag);
head->length = cpu_to_be32(sizeof(*head)); head->length = cpu_to_be32(sizeof(*head));
head->ordinal = cpu_to_be32(ordinal); head->ordinal = cpu_to_be32(ordinal);
...@@ -428,14 +425,14 @@ static inline void tpm_buf_destroy(struct tpm_buf *buf) ...@@ -428,14 +425,14 @@ static inline void tpm_buf_destroy(struct tpm_buf *buf)
static inline u32 tpm_buf_length(struct tpm_buf *buf) static inline u32 tpm_buf_length(struct tpm_buf *buf)
{ {
struct tpm_input_header *head = (struct tpm_input_header *) buf->data; struct tpm_header *head = (struct tpm_header *)buf->data;
return be32_to_cpu(head->length); return be32_to_cpu(head->length);
} }
static inline u16 tpm_buf_tag(struct tpm_buf *buf) static inline u16 tpm_buf_tag(struct tpm_buf *buf)
{ {
struct tpm_input_header *head = (struct tpm_input_header *) buf->data; struct tpm_header *head = (struct tpm_header *)buf->data;
return be16_to_cpu(head->tag); return be16_to_cpu(head->tag);
} }
...@@ -444,7 +441,7 @@ static inline void tpm_buf_append(struct tpm_buf *buf, ...@@ -444,7 +441,7 @@ static inline void tpm_buf_append(struct tpm_buf *buf,
const unsigned char *new_data, const unsigned char *new_data,
unsigned int new_len) unsigned int new_len)
{ {
struct tpm_input_header *head = (struct tpm_input_header *) buf->data; struct tpm_header *head = (struct tpm_header *)buf->data;
u32 len = tpm_buf_length(buf); u32 len = tpm_buf_length(buf);
/* Return silently if overflow has already happened. */ /* Return silently if overflow has already happened. */
...@@ -582,7 +579,7 @@ void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space); ...@@ -582,7 +579,7 @@ void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc, int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc,
u8 *cmd); u8 *cmd);
int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
u32 cc, u8 *buf, size_t *bufsiz); u32 cc, void *buf, size_t *bufsiz);
int tpm_bios_log_setup(struct tpm_chip *chip); int tpm_bios_log_setup(struct tpm_chip *chip);
void tpm_bios_log_teardown(struct tpm_chip *chip); void tpm_bios_log_teardown(struct tpm_chip *chip);
......
...@@ -784,7 +784,7 @@ static int tpm2_do_selftest(struct tpm_chip *chip) ...@@ -784,7 +784,7 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
*/ */
int tpm2_probe(struct tpm_chip *chip) int tpm2_probe(struct tpm_chip *chip)
{ {
struct tpm_output_header *out; struct tpm_header *out;
struct tpm_buf buf; struct tpm_buf buf;
int rc; int rc;
...@@ -797,7 +797,7 @@ int tpm2_probe(struct tpm_chip *chip) ...@@ -797,7 +797,7 @@ int tpm2_probe(struct tpm_chip *chip)
rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL); rc = tpm_transmit_cmd(chip, NULL, &buf, 0, 0, NULL);
/* We ignore TPM return codes on purpose. */ /* We ignore TPM return codes on purpose. */
if (rc >= 0) { if (rc >= 0) {
out = (struct tpm_output_header *)buf.data; out = (struct tpm_header *)buf.data;
if (be16_to_cpu(out->tag) == TPM2_ST_NO_SESSIONS) if (be16_to_cpu(out->tag) == TPM2_ST_NO_SESSIONS)
chip->flags |= TPM_CHIP_FLAG_TPM2; chip->flags |= TPM_CHIP_FLAG_TPM2;
} }
......
...@@ -334,7 +334,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp, ...@@ -334,7 +334,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
size_t len) size_t len)
{ {
struct tpm_space *space = &chip->work_space; struct tpm_space *space = &chip->work_space;
struct tpm_output_header *header = (void *)rsp; struct tpm_header *header = (struct tpm_header *)rsp;
u32 phandle; u32 phandle;
u32 phandle_type; u32 phandle_type;
u32 vhandle; u32 vhandle;
...@@ -394,7 +394,7 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp, ...@@ -394,7 +394,7 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
size_t len) size_t len)
{ {
struct tpm_space *space = &chip->work_space; struct tpm_space *space = &chip->work_space;
struct tpm_output_header *header = (void *)rsp; struct tpm_header *header = (struct tpm_header *)rsp;
struct tpm2_cap_handles *data; struct tpm2_cap_handles *data;
u32 phandle; u32 phandle;
u32 phandle_type; u32 phandle_type;
...@@ -490,9 +490,9 @@ static int tpm2_save_space(struct tpm_chip *chip) ...@@ -490,9 +490,9 @@ static int tpm2_save_space(struct tpm_chip *chip)
} }
int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space,
u32 cc, u8 *buf, size_t *bufsiz) u32 cc, void *buf, size_t *bufsiz)
{ {
struct tpm_output_header *header = (void *)buf; struct tpm_header *header = buf;
int rc; int rc;
if (!space) if (!space)
......
...@@ -46,7 +46,7 @@ struct priv_data { ...@@ -46,7 +46,7 @@ struct priv_data {
/* This is the amount we read on the first try. 25 was chosen to fit a /* This is the amount we read on the first try. 25 was chosen to fit a
* fair number of read responses in the buffer so a 2nd retry can be * fair number of read responses in the buffer so a 2nd retry can be
* avoided in small message cases. */ * avoided in small message cases. */
u8 buffer[sizeof(struct tpm_output_header) + 25]; u8 buffer[sizeof(struct tpm_header) + 25];
}; };
static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len) static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
...@@ -80,8 +80,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -80,8 +80,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
{ {
struct priv_data *priv = dev_get_drvdata(&chip->dev); struct priv_data *priv = dev_get_drvdata(&chip->dev);
struct i2c_client *client = to_i2c_client(chip->dev.parent); struct i2c_client *client = to_i2c_client(chip->dev.parent);
struct tpm_output_header *hdr = struct tpm_header *hdr = (struct tpm_header *)priv->buffer;
(struct tpm_output_header *)priv->buffer;
u32 expected_len; u32 expected_len;
int rc; int rc;
......
...@@ -303,9 +303,9 @@ static int vtpm_proxy_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -303,9 +303,9 @@ static int vtpm_proxy_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
static int vtpm_proxy_is_driver_command(struct tpm_chip *chip, static int vtpm_proxy_is_driver_command(struct tpm_chip *chip,
u8 *buf, size_t count) u8 *buf, size_t count)
{ {
struct tpm_input_header *hdr = (struct tpm_input_header *)buf; struct tpm_header *hdr = (struct tpm_header *)buf;
if (count < sizeof(struct tpm_input_header)) if (count < sizeof(struct tpm_header))
return 0; return 0;
if (chip->flags & TPM_CHIP_FLAG_TPM2) { if (chip->flags & TPM_CHIP_FLAG_TPM2) {
...@@ -401,7 +401,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) ...@@ -401,7 +401,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
{ {
struct tpm_buf buf; struct tpm_buf buf;
int rc; int rc;
const struct tpm_output_header *header; const struct tpm_header *header;
struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
if (chip->flags & TPM_CHIP_FLAG_TPM2) if (chip->flags & TPM_CHIP_FLAG_TPM2)
...@@ -426,7 +426,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) ...@@ -426,7 +426,7 @@ static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
goto out; goto out;
} }
header = (const struct tpm_output_header *)buf.data; header = (const struct tpm_header *)buf.data;
rc = be32_to_cpu(header->return_code); rc = be32_to_cpu(header->return_code);
if (rc) if (rc)
locality = -1; locality = -1;
......
...@@ -163,7 +163,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) ...@@ -163,7 +163,7 @@ static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
wmb(); wmb();
notify_remote_via_evtchn(priv->evtchn); notify_remote_via_evtchn(priv->evtchn);
ordinal = be32_to_cpu(((struct tpm_input_header*)buf)->ordinal); ordinal = be32_to_cpu(((struct tpm_header *)buf)->ordinal);
duration = tpm_calc_ordinal_duration(chip, ordinal); duration = tpm_calc_ordinal_duration(chip, ordinal);
if (wait_for_tpm_stat(chip, VTPM_STATUS_IDLE, duration, if (wait_for_tpm_stat(chip, VTPM_STATUS_IDLE, duration,
......
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