Message ID | 20191219140605.3243321-2-stefanb@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add vTPM emulator support for ppc64 platform | expand |
On 12/19/19 3:06 PM, Stefan Berger wrote: > Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> > --- > hw/tpm/tpm_tis.c | 32 ++++---------------------------- > hw/tpm/tpm_util.c | 25 +++++++++++++++++++++++++ > hw/tpm/tpm_util.h | 3 +++ > hw/tpm/trace-events | 2 +- > 4 files changed, 33 insertions(+), 29 deletions(-) > > diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c > index 7aaf9b946d..5b17c88a7d 100644 > --- a/hw/tpm/tpm_tis.c > +++ b/hw/tpm/tpm_tis.c > @@ -107,30 +107,6 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) > return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); > } > > -static void tpm_tis_show_buffer(const unsigned char *buffer, > - size_t buffer_size, const char *string) > -{ > - size_t len, i; > - char *line_buffer, *p; > - > - len = MIN(tpm_cmd_get_size(buffer), buffer_size); > - > - /* > - * allocate enough room for 3 chars per buffer entry plus a > - * newline after every 16 chars and a final null terminator. > - */ > - line_buffer = g_malloc(len * 3 + (len / 16) + 1); > - > - for (i = 0, p = line_buffer; i < len; i++) { > - if (i && !(i % 16)) { > - p += sprintf(p, "\n"); > - } > - p += sprintf(p, "%.2X ", buffer[i]); > - } > - trace_tpm_tis_show_buffer(string, len, line_buffer); > - > - g_free(line_buffer); > -} > > /* > * Set the given flags in the STS register by clearing the register but > @@ -156,8 +132,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags) > */ > static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) > { > - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { > - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); > + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { > + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); > } > > /* > @@ -325,8 +301,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) > s->loc[locty].state = TPM_TIS_STATE_COMPLETION; > s->rw_offset = 0; > > - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { > - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); > + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { > + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); > } > > if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { > diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c > index 62b091f0c0..c0a0f3d71f 100644 > --- a/hw/tpm/tpm_util.c > +++ b/hw/tpm/tpm_util.c > @@ -350,3 +350,28 @@ void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) > tsb->buffer = NULL; > tsb->size = 0; > } > + > +void tpm_util_show_buffer(const unsigned char *buffer, > + size_t buffer_size, const char *string) > +{ > + size_t len, i; > + char *line_buffer, *p; > + > + len = MIN(tpm_cmd_get_size(buffer), buffer_size); > + > + /* > + * allocate enough room for 3 chars per buffer entry plus a > + * newline after every 16 chars and a final null terminator. > + */ > + line_buffer = g_malloc(len * 3 + (len / 16) + 1); > + > + for (i = 0, p = line_buffer; i < len; i++) { > + if (i && !(i % 16)) { > + p += sprintf(p, "\n"); > + } > + p += sprintf(p, "%.2X ", buffer[i]); > + } > + trace_tpm_util_show_buffer(string, len, line_buffer); > + > + g_free(line_buffer); > +} > diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h > index f397ac21b8..7889081fba 100644 > --- a/hw/tpm/tpm_util.h > +++ b/hw/tpm/tpm_util.h > @@ -79,4 +79,7 @@ typedef struct TPMSizedBuffer { > > void tpm_sized_buffer_reset(TPMSizedBuffer *tsb); > > +void tpm_util_show_buffer(const unsigned char *buffer, > + size_t buffer_size, const char *string); > + > #endif /* TPM_TPM_UTIL_H */ > diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events > index 89804bcd64..357c9e9a84 100644 > --- a/hw/tpm/trace-events > +++ b/hw/tpm/trace-events > @@ -14,6 +14,7 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, > tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" > tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" > tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" > +tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" Please avoid multi-line trace formats if possible. Since this is a pre-existing issue: Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > > # tpm_emulator.c > tpm_emulator_set_locality(uint8_t locty) "setting locality to %d" > @@ -36,7 +37,6 @@ tpm_emulator_pre_save(void) "" > tpm_emulator_inst_init(void) "" > > # tpm_tis.c > -tpm_tis_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\nbuf: %s" > tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" > tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d" > tpm_tis_abort(uint8_t locty) "New active locality is %d" >
On Thu, Dec 19, 2019 at 09:06:00AM -0500, Stefan Berger wrote: > Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Do you want me to queue this in my ppc tree? > --- > hw/tpm/tpm_tis.c | 32 ++++---------------------------- > hw/tpm/tpm_util.c | 25 +++++++++++++++++++++++++ > hw/tpm/tpm_util.h | 3 +++ > hw/tpm/trace-events | 2 +- > 4 files changed, 33 insertions(+), 29 deletions(-) > > diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c > index 7aaf9b946d..5b17c88a7d 100644 > --- a/hw/tpm/tpm_tis.c > +++ b/hw/tpm/tpm_tis.c > @@ -107,30 +107,6 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) > return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); > } > > -static void tpm_tis_show_buffer(const unsigned char *buffer, > - size_t buffer_size, const char *string) > -{ > - size_t len, i; > - char *line_buffer, *p; > - > - len = MIN(tpm_cmd_get_size(buffer), buffer_size); > - > - /* > - * allocate enough room for 3 chars per buffer entry plus a > - * newline after every 16 chars and a final null terminator. > - */ > - line_buffer = g_malloc(len * 3 + (len / 16) + 1); > - > - for (i = 0, p = line_buffer; i < len; i++) { > - if (i && !(i % 16)) { > - p += sprintf(p, "\n"); > - } > - p += sprintf(p, "%.2X ", buffer[i]); > - } > - trace_tpm_tis_show_buffer(string, len, line_buffer); > - > - g_free(line_buffer); > -} > > /* > * Set the given flags in the STS register by clearing the register but > @@ -156,8 +132,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags) > */ > static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) > { > - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { > - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); > + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { > + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); > } > > /* > @@ -325,8 +301,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) > s->loc[locty].state = TPM_TIS_STATE_COMPLETION; > s->rw_offset = 0; > > - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { > - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); > + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { > + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); > } > > if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { > diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c > index 62b091f0c0..c0a0f3d71f 100644 > --- a/hw/tpm/tpm_util.c > +++ b/hw/tpm/tpm_util.c > @@ -350,3 +350,28 @@ void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) > tsb->buffer = NULL; > tsb->size = 0; > } > + > +void tpm_util_show_buffer(const unsigned char *buffer, > + size_t buffer_size, const char *string) > +{ > + size_t len, i; > + char *line_buffer, *p; > + > + len = MIN(tpm_cmd_get_size(buffer), buffer_size); > + > + /* > + * allocate enough room for 3 chars per buffer entry plus a > + * newline after every 16 chars and a final null terminator. > + */ > + line_buffer = g_malloc(len * 3 + (len / 16) + 1); > + > + for (i = 0, p = line_buffer; i < len; i++) { > + if (i && !(i % 16)) { > + p += sprintf(p, "\n"); > + } > + p += sprintf(p, "%.2X ", buffer[i]); > + } > + trace_tpm_util_show_buffer(string, len, line_buffer); > + > + g_free(line_buffer); > +} > diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h > index f397ac21b8..7889081fba 100644 > --- a/hw/tpm/tpm_util.h > +++ b/hw/tpm/tpm_util.h > @@ -79,4 +79,7 @@ typedef struct TPMSizedBuffer { > > void tpm_sized_buffer_reset(TPMSizedBuffer *tsb); > > +void tpm_util_show_buffer(const unsigned char *buffer, > + size_t buffer_size, const char *string); > + > #endif /* TPM_TPM_UTIL_H */ > diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events > index 89804bcd64..357c9e9a84 100644 > --- a/hw/tpm/trace-events > +++ b/hw/tpm/trace-events > @@ -14,6 +14,7 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, > tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" > tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" > tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" > +tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" > > # tpm_emulator.c > tpm_emulator_set_locality(uint8_t locty) "setting locality to %d" > @@ -36,7 +37,6 @@ tpm_emulator_pre_save(void) "" > tpm_emulator_inst_init(void) "" > > # tpm_tis.c > -tpm_tis_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\nbuf: %s" > tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" > tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d" > tpm_tis_abort(uint8_t locty) "New active locality is %d"
On 12/20/19 3:23 AM, David Gibson wrote: > On Thu, Dec 19, 2019 at 09:06:00AM -0500, Stefan Berger wrote: >> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> > Reviewed-by: David Gibson <david@gibson.dropbear.id.au> > > Do you want me to queue this in my ppc tree? Either you or me. It's fine if you queue it. Thanks. Stefan
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 7aaf9b946d..5b17c88a7d 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -107,30 +107,6 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); } -static void tpm_tis_show_buffer(const unsigned char *buffer, - size_t buffer_size, const char *string) -{ - size_t len, i; - char *line_buffer, *p; - - len = MIN(tpm_cmd_get_size(buffer), buffer_size); - - /* - * allocate enough room for 3 chars per buffer entry plus a - * newline after every 16 chars and a final null terminator. - */ - line_buffer = g_malloc(len * 3 + (len / 16) + 1); - - for (i = 0, p = line_buffer; i < len; i++) { - if (i && !(i % 16)) { - p += sprintf(p, "\n"); - } - p += sprintf(p, "%.2X ", buffer[i]); - } - trace_tpm_tis_show_buffer(string, len, line_buffer); - - g_free(line_buffer); -} /* * Set the given flags in the STS register by clearing the register but @@ -156,8 +132,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); } /* @@ -325,8 +301,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) s->loc[locty].state = TPM_TIS_STATE_COMPLETION; s->rw_offset = 0; - if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); + if (trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) { + tpm_util_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); } if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index 62b091f0c0..c0a0f3d71f 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -350,3 +350,28 @@ void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) tsb->buffer = NULL; tsb->size = 0; } + +void tpm_util_show_buffer(const unsigned char *buffer, + size_t buffer_size, const char *string) +{ + size_t len, i; + char *line_buffer, *p; + + len = MIN(tpm_cmd_get_size(buffer), buffer_size); + + /* + * allocate enough room for 3 chars per buffer entry plus a + * newline after every 16 chars and a final null terminator. + */ + line_buffer = g_malloc(len * 3 + (len / 16) + 1); + + for (i = 0, p = line_buffer; i < len; i++) { + if (i && !(i % 16)) { + p += sprintf(p, "\n"); + } + p += sprintf(p, "%.2X ", buffer[i]); + } + trace_tpm_util_show_buffer(string, len, line_buffer); + + g_free(line_buffer); +} diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index f397ac21b8..7889081fba 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -79,4 +79,7 @@ typedef struct TPMSizedBuffer { void tpm_sized_buffer_reset(TPMSizedBuffer *tsb); +void tpm_util_show_buffer(const unsigned char *buffer, + size_t buffer_size, const char *string); + #endif /* TPM_TPM_UTIL_H */ diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events index 89804bcd64..357c9e9a84 100644 --- a/hw/tpm/trace-events +++ b/hw/tpm/trace-events @@ -14,6 +14,7 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" +tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" # tpm_emulator.c tpm_emulator_set_locality(uint8_t locty) "setting locality to %d" @@ -36,7 +37,6 @@ tpm_emulator_pre_save(void) "" tpm_emulator_inst_init(void) "" # tpm_tis.c -tpm_tis_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\nbuf: %s" tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d" tpm_tis_abort(uint8_t locty) "New active locality is %d"
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> --- hw/tpm/tpm_tis.c | 32 ++++---------------------------- hw/tpm/tpm_util.c | 25 +++++++++++++++++++++++++ hw/tpm/tpm_util.h | 3 +++ hw/tpm/trace-events | 2 +- 4 files changed, 33 insertions(+), 29 deletions(-)