tpm: A fix and a cleanup
PATCH 2/2 tpm: wrap stX_be_p in tpm_cmd_set_XYZ functions
In reply to Stefan BergerWrap the calls to stl_be_p and stw_be_p in tpm_cmd_set_XYZ functions that are similar to existing getters.
--- hw/tpm/tpm_util.c | 6 +++--- hw/tpm/tpm_util.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-)
hw/tpm/tpm_util.c +3 -3
@@ -106,9 +106,9 @@ const PropertyInfo qdev_prop_tpm = {void tpm_util_write_fatal_error_response (uint8_t *out,uint32_t out_len) {if (out_len >=sizeof (struct tpm_resp_hdr )) { -stw_be_p (out,TPM_TAG_RSP_COMMAND ); -stl_be_p (out +2 ,sizeof (struct tpm_resp_hdr )); -stl_be_p (out +6 ,TPM_FAIL ); +tpm_cmd_set_tag (out,TPM_TAG_RSP_COMMAND ); +tpm_cmd_set_size (out,sizeof (struct tpm_resp_hdr )); +tpm_cmd_set_error (out,TPM_FAIL ); } }
hw/tpm/tpm_util.h +15 -0
@@ -36,11 +36,21 @@ static inline uint16_t tpm_cmd_get_tag(const void *b)return lduw_be_p (b); } +static inline void tpm_cmd_set_tag (void *b,uint16_t tag) +{ +stw_be_p (b, tag); +} +static inline uint32_t tpm_cmd_get_size (const void *b) {return ldl_be_p (b +2 ); } +static inline void tpm_cmd_set_size (void *b,uint32_t size) +{ +stl_be_p (b +2 , size); +} +static inline uint32_t tpm_cmd_get_ordinal (const void *b) {return ldl_be_p (b +6 );
@@ -51,6 +61,11 @@ static inline uint32_t tpm_cmd_get_errcode(const void *b)return ldl_be_p (b +6 ); } +static inline void tpm_cmd_set_error (void *b,uint32_t error) +{ +stl_be_p (b +6 , error); +} +int tpm_util_get_buffer_size (int tpm_fd,TPMVersion tpm_version,size_t *buffersize);
Signature · 1 line
2.5.5
cover tpm: A fix and a cleanup
The following two patches fix the resetting of the CRB interface and wrap calls to st{w,l}_be_p in tpm_cmd_set_XYZ functions.
Stefan
Stefan Berger (2):
tpm: Split off tpm_crb_reset function
tpm: wrap stX_be_p in tpm_cmd_set_XYZ functions
hw/tpm/tpm_crb.c | 6 ++++++ hw/tpm/tpm_util.c | 6 +++--- hw/tpm/tpm_util.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/2 tpm: Split off tpm_crb_reset function
Split off the tpm_crb_reset function part from tpm_crb_realize that we need to run every time the machine resets.
--- hw/tpm/tpm_crb.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/tpm/tpm_crb.c +6 -0
@@ -232,6 +232,11 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp) TPM_CRB_ADDR_BASE, &s->mmio);memory_region_add_subregion (get_system_memory (),TPM_CRB_ADDR_BASE +sizeof (s->regs), &s->cmdmem); +} + +static void tpm_crb_reset (DeviceState *dev) +{ +CRBState *s =CRB (dev);tpm_backend_reset (s->tpmbe);
@@ -274,6 +279,7 @@ static void tpm_crb_class_init(ObjectClass *klass, void *data) dc->realize = tpm_crb_realize; dc->props = tpm_crb_properties; + dc->reset = tpm_crb_reset; dc->vmsd = &vmstate_tpm_crb; dc->user_creatable = true; tc->model =TPM_MODEL_TPM_CRB ;
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH 1/2] tpm: Split off tpm_crb_reset function
Quoted 25 lines · Stefan Berger
Split off the
tpm_crb_resetfunction part fromtpm_crb_realizethat we need to run every time the machine resets.Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_crb.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/tpm/tpm_crb.c +5
-0@@ -232,6 +232,11 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp) TPM_CRB_ADDR_BASE, &s->mmio);memory_region_add_subregion (get_system_memory (),TPM_CRB_ADDR_BASE +sizeof (s->regs), &s->cmdmem); +} + +static void tpm_crb_reset (DeviceState *dev) +{ +CRBState *s =CRB (dev);tpm_backend_reset (s->tpmbe);
hw/tpm/tpm_crb.c static void tpm_crb_class_init(ObjectClass *klass, void *data) · line 285
Quoted 7 lines
hw/tpm/tpm_crb.c +1
-0@@ -274,6 +279,7 @@ static void tpm_crb_class_init(ObjectClass *klass, void *data) dc->realize = tpm_crb_realize; dc->props = tpm_crb_properties; + dc->reset = tpm_crb_reset; dc->vmsd = &vmstate_tpm_crb; dc->user_creatable = true; tc->model =TPM_MODEL_TPM_CRB ;
So this splt-off unfortunately causes the tpm-crb-test to fail since the reset function is not called. I wonder how to trigger that? Do we need to call tpm_crb_reset now from tpm_crb_realize just to make the tests work ? Or is there a function we can call in the test case to trigger the device reset ?
Re: [Qemu-devel] [PATCH 2/2] tpm: wrap stX_be_p in tpm_cmd_set_XYZ functions
In reply to Stefan BergerHi
Quoted 2 lines · Stefan Berger
Wrap the calls to
stl_be_pandstw_be_pintpm_cmd_set_XYZfunctions that are similar to existing getters.
why not,
Quoted 65 lines
Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_util.c | 6 +++--- hw/tpm/tpm_util.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-)hw/tpm/tpm_util.c +3
-3@@ -106,9 +106,9 @@ const PropertyInfo qdev_prop_tpm = {void tpm_util_write_fatal_error_response (uint8_t *out,uint32_t out_len) {if (out_len >=sizeof (struct tpm_resp_hdr )) { -stw_be_p (out,TPM_TAG_RSP_COMMAND ); -stl_be_p (out +2 ,sizeof (struct tpm_resp_hdr )); -stl_be_p (out +6 ,TPM_FAIL ); +tpm_cmd_set_tag (out,TPM_TAG_RSP_COMMAND ); +tpm_cmd_set_size (out,sizeof (struct tpm_resp_hdr )); +tpm_cmd_set_error (out,TPM_FAIL ); } }hw/tpm/tpm_util.h +15
-1@@ -36,11 +36,21 @@ static inline uint16_t tpm_cmd_get_tag(const void *b)return lduw_be_p (b); } +static inline void tpm_cmd_set_tag (void *b,uint16_t tag) +{ +stw_be_p (b, tag); +} +static inline uint32_t tpm_cmd_get_size (const void *b) {return ldl_be_p (b +2 ); } +static inline void tpm_cmd_set_size (void *b,uint32_t size) +{ +stl_be_p (b +2 , size); +} +static inline uint32_t tpm_cmd_get_ordinal (const void *b) {return ldl_be_p (b +6 );@@ -51,6 +61,11 @@ static inline uint32_t tpm_cmd_get_errcode(const void *b)return ldl_be_p (b +6 ); } +static inline void tpm_cmd_set_error (void *b,uint32_t error) +{ +stl_be_p (b +6 , error); +} +int tpm_util_get_buffer_size (int tpm_fd,TPMVersion tpm_version,size_t *buffersize); --2.5.5