tpm_backend.h 4.8 KB
Newer Older
S
Stefan Berger 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * QEMU TPM Backend
 *
 * Copyright IBM, Corp. 2013
 *
 * Authors:
 *  Stefan Berger  <stefanb@us.ibm.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 */

13 14
#ifndef TPM_BACKEND_H
#define TPM_BACKEND_H
S
Stefan Berger 已提交
15 16 17 18 19

#include "qom/object.h"
#include "qemu-common.h"
#include "qapi-types.h"
#include "qemu/option.h"
20
#include "sysemu/tpm.h"
S
Stefan Berger 已提交
21 22 23 24 25 26 27 28 29 30 31

#define TYPE_TPM_BACKEND "tpm-backend"
#define TPM_BACKEND(obj) \
    OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
#define TPM_BACKEND_GET_CLASS(obj) \
    OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
#define TPM_BACKEND_CLASS(klass) \
    OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)

typedef struct TPMBackendClass TPMBackendClass;
typedef struct TPMBackend TPMBackend;
M
Marc-André Lureau 已提交
32

33 34 35 36 37 38 39 40
typedef struct TPMBackendCmd {
    uint8_t locty;
    const uint8_t *in;
    uint32_t in_len;
    uint8_t *out;
    uint32_t out_len;
    bool selftest_done;
} TPMBackendCmd;
S
Stefan Berger 已提交
41 42 43 44 45 46

struct TPMBackend {
    Object parent;

    /*< protected >*/
    bool opened;
47 48
    TPMState *tpm_state;
    GThreadPool *thread_pool;
49
    bool had_startup_error;
S
Stefan Berger 已提交
50

51
    /* <public> */
S
Stefan Berger 已提交
52 53 54 55 56 57
    char *id;
    enum TpmModel fe_model;

    QLIST_ENTRY(TPMBackend) list;
};

58 59 60
struct TPMBackendClass {
    ObjectClass parent_class;

61
    enum TpmType type;
62
    const QemuOptDesc *opts;
63
    /* get a descriptive text of the backend to display to the user */
64
    const char *desc;
65 66 67 68 69 70 71 72 73 74 75

    TPMBackend *(*create)(QemuOpts *opts, const char *id);

    /* start up the TPM on the backend */
    int (*startup_tpm)(TPMBackend *t);

    void (*reset)(TPMBackend *t);

    void (*cancel_cmd)(TPMBackend *t);

    bool (*get_tpm_established_flag)(TPMBackend *t);
76 77 78 79

    int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);

    TPMVersion (*get_tpm_version)(TPMBackend *t);
80 81

    TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
82

M
Marc-André Lureau 已提交
83 84
    void (*opened)(TPMBackend *s, Error **errp);

85
    void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd);
M
Marc-André Lureau 已提交
86
};
S
Stefan Berger 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

/**
 * tpm_backend_get_type:
 * @s: the backend
 *
 * Returns the TpmType of the backend.
 */
enum TpmType tpm_backend_get_type(TPMBackend *s);

/**
 * tpm_backend_init:
 * @s: the backend to initialized
 * @state: TPMState
 * @datacb: callback for sending data to frontend
 *
 * Initialize the backend with the given variables.
 *
 * Returns 0 on success.
 */
106
int tpm_backend_init(TPMBackend *s, TPMState *state);
S
Stefan Berger 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

/**
 * tpm_backend_startup_tpm:
 * @s: the backend whose TPM support is to be started
 *
 * Returns 0 on success.
 */
int tpm_backend_startup_tpm(TPMBackend *s);

/**
 * tpm_backend_had_startup_error:
 * @s: the backend to query for a statup error
 *
 * Check whether the backend had an error during startup. Returns
 * false if no error occurred and the backend can be used, true
 * otherwise.
 */
bool tpm_backend_had_startup_error(TPMBackend *s);

/**
 * tpm_backend_deliver_request:
 * @s: the backend to send the request to
129
 * @cmd: the command to deliver
S
Stefan Berger 已提交
130 131 132 133
 *
 * Send a request to the backend. The backend will then send the request
 * to the TPM implementation.
 */
134
void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
S
Stefan Berger 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

/**
 * tpm_backend_reset:
 * @s: the backend to reset
 *
 * Reset the backend into a well defined state with all previous errors
 * reset.
 */
void tpm_backend_reset(TPMBackend *s);

/**
 * tpm_backend_cancel_cmd:
 * @s: the backend
 *
 * Cancel any ongoing command being processed by the TPM implementation
 * on behalf of the QEMU guest.
 */
void tpm_backend_cancel_cmd(TPMBackend *s);

/**
 * tpm_backend_get_tpm_established_flag:
 * @s: the backend
 *
 * Get the TPM establishment flag. This function may be called very
 * frequently by the frontend since for example in the TIS implementation
 * this flag is part of a register.
 */
bool tpm_backend_get_tpm_established_flag(TPMBackend *s);

164 165 166 167 168 169 170 171 172
/**
 * tpm_backend_reset_tpm_established_flag:
 * @s: the backend
 * @locty: the locality number
 *
 * Reset the TPM establishment flag.
 */
int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);

S
Stefan Berger 已提交
173 174 175 176 177 178 179 180 181 182
/**
 * tpm_backend_open:
 * @s: the backend to open
 * @errp: a pointer to return the #Error object if an error occurs.
 *
 * This function will open the backend if it is not already open.  Calling this
 * function on an already opened backend will not result in an error.
 */
void tpm_backend_open(TPMBackend *s, Error **errp);

183 184 185 186 187 188 189 190 191 192
/**
 * tpm_backend_get_tpm_version:
 * @s: the backend to call into
 *
 * Get the TPM Version that is emulated at the backend.
 *
 * Returns TPMVersion.
 */
TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);

193 194 195 196 197 198 199 200 201 202
/**
 * tpm_backend_query_tpm:
 * @s: the backend
 *
 * Query backend tpm info
 *
 * Returns newly allocated TPMInfo
 */
TPMInfo *tpm_backend_query_tpm(TPMBackend *s);

203 204
TPMBackend *qemu_find_tpm(const char *id);

205
void tpm_register_model(enum TpmModel model);
206

S
Stefan Berger 已提交
207
#endif