1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef TPM_TPM_UTIL_H
23#define TPM_TPM_UTIL_H
24
25#include "sysemu/tpm.h"
26#include "qemu/bswap.h"
27
28void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len);
29
30bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len);
31
32int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);
33
34static inline uint16_t tpm_cmd_get_tag(const void *b)
35{
36 return lduw_be_p(b);
37}
38
39static inline void tpm_cmd_set_tag(void *b, uint16_t tag)
40{
41 stw_be_p(b, tag);
42}
43
44static inline uint32_t tpm_cmd_get_size(const void *b)
45{
46 return ldl_be_p(b + 2);
47}
48
49static inline void tpm_cmd_set_size(void *b, uint32_t size)
50{
51 stl_be_p(b + 2, size);
52}
53
54static inline uint32_t tpm_cmd_get_ordinal(const void *b)
55{
56 return ldl_be_p(b + 6);
57}
58
59static inline uint32_t tpm_cmd_get_errcode(const void *b)
60{
61 return ldl_be_p(b + 6);
62}
63
64static inline void tpm_cmd_set_error(void *b, uint32_t error)
65{
66 stl_be_p(b + 6, error);
67}
68
69int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_version,
70 size_t *buffersize);
71
72#define DEFINE_PROP_TPMBE(_n, _s, _f) \
73 DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *)
74
75typedef struct TPMSizedBuffer {
76 uint32_t size;
77 uint8_t *buffer;
78} TPMSizedBuffer;
79
80void tpm_sized_buffer_reset(TPMSizedBuffer *tsb);
81
82#endif
83