]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/tpm_util.h
hvf: Split out common code on vcpu init and destroy
[mirror_qemu.git] / include / sysemu / tpm_util.h
CommitLineData
56a3c24f
SB
1/*
2 * TPM utility functions
3 *
4 * Copyright (c) 2010 - 2015 IBM Corporation
5 * Authors:
6 * Stefan Berger <stefanb@us.ibm.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
eac2fce9 11 * version 2.1 of the License, or (at your option) any later version.
56a3c24f
SB
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>
20 */
121d0712 21
0f7d2148
PMD
22#ifndef SYSEMU_TPM_UTIL_H
23#define SYSEMU_TPM_UTIL_H
56a3c24f 24
5cf954d0
MAL
25#include "sysemu/tpm.h"
26#include "qemu/bswap.h"
56a3c24f 27
4a3d8098
AV
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
56a3c24f
SB
32int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);
33
cc1b6c55
MAL
34static inline uint16_t tpm_cmd_get_tag(const void *b)
35{
36 return lduw_be_p(b);
37}
38
a35e15dc
SB
39static inline void tpm_cmd_set_tag(void *b, uint16_t tag)
40{
41 stw_be_p(b, tag);
42}
43
5cf954d0
MAL
44static inline uint32_t tpm_cmd_get_size(const void *b)
45{
cc1b6c55
MAL
46 return ldl_be_p(b + 2);
47}
48
a35e15dc
SB
49static inline void tpm_cmd_set_size(void *b, uint32_t size)
50{
51 stl_be_p(b + 2, size);
52}
53
cc1b6c55
MAL
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);
5cf954d0
MAL
62}
63
a35e15dc
SB
64static inline void tpm_cmd_set_error(void *b, uint32_t error)
65{
66 stl_be_p(b + 6, error);
67}
68
3688d73b
SB
69void tpm_util_show_buffer(const unsigned char *buffer,
70 size_t buffer_size, const char *string);
71
0f7d2148 72#endif /* SYSEMU_TPM_UTIL_H */