Commit bdee56f5 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

tpm: reorganize headers and split hardware part



The TPM subsystem does not have a full front-end/back-end separation.
The sole available backend, tpm_passthrough, depends on the data
structures of the sole available frontend, tpm_tis.

However, we can at least try to split the user interface (tpm.c) from the
implementation (hw/tpm).  The patches makes tpm.c not include tpm_int.h,
which is shared between tpm_tis.c and tpm_passthrough.c; instead it
moves more stuff to tpm_backend.h.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 3b8acc11
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ common-obj-y += bt-host.o bt-vhci.o

common-obj-y += dma-helpers.o
common-obj-y += vl.o
common-obj-y += tpm/
common-obj-y += tpm.o

common-obj-$(CONFIG_SLIRP) += slirp/

+37 −1
Original line number Diff line number Diff line
@@ -13,8 +13,10 @@
 */

#include "backends/tpm.h"
#include "tpm/tpm_int.h"
#include "qapi/qmp/qerror.h"
#include "sysemu/tpm.h"
#include "qemu/thread.h"
#include "sysemu/tpm_backend_int.h"

enum TpmType tpm_backend_get_type(TPMBackend *s)
{
@@ -137,6 +139,40 @@ static void tpm_backend_instance_init(Object *obj)
                             NULL);
}

void tpm_backend_thread_deliver_request(TPMBackendThread *tbt)
{
   g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL);
}

void tpm_backend_thread_create(TPMBackendThread *tbt,
                               GFunc func, gpointer user_data)
{
    if (!tbt->pool) {
        tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL);
        g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);
    }
}

void tpm_backend_thread_end(TPMBackendThread *tbt)
{
    if (tbt->pool) {
        g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL);
        g_thread_pool_free(tbt->pool, FALSE, TRUE);
        tbt->pool = NULL;
    }
}

void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt,
                                  GFunc func, gpointer user_data)
{
    if (!tbt->pool) {
        tpm_backend_thread_create(tbt, func, user_data);
    } else {
        g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_TPM_RESET,
                           NULL);
    }
}

static const TypeInfo tpm_backend_info = {
    .name = TYPE_TPM_BACKEND,
    .parent = TYPE_OBJECT,
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += scsi/
devices-dirs-$(CONFIG_SOFTMMU) += sd/
devices-dirs-$(CONFIG_SOFTMMU) += ssi/
devices-dirs-$(CONFIG_SOFTMMU) += timer/
devices-dirs-$(CONFIG_TPM) += tpm/
devices-dirs-$(CONFIG_SOFTMMU) += usb/
devices-dirs-$(CONFIG_SOFTMMU) += virtio/
devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
+0 −2
Original line number Diff line number Diff line
common-obj-y = tpm.o
common-obj-$(CONFIG_TPM) += tpm_backend.o
common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o
common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
+1 −36
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#define TPM_TPM_INT_H

#include "exec/memory.h"
#include "tpm/tpm_tis.h"
#include "tpm_tis.h"

/* overall state of the TPM interface */
struct TPMState {
@@ -33,32 +33,6 @@ struct TPMState {

#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)

struct TPMDriverOps {
    enum TpmType type;
    /* get a descriptive text of the backend to display to the user */
    const char *(*desc)(void);

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

    /* initialize the backend */
    int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
    /* start up the TPM on the backend */
    int (*startup_tpm)(TPMBackend *t);
    /* returns true if nothing will ever answer TPM requests */
    bool (*had_startup_error)(TPMBackend *t);

    size_t (*realloc_buffer)(TPMSizedBuffer *sb);

    void (*deliver_request)(TPMBackend *t);

    void (*reset)(TPMBackend *t);

    void (*cancel_cmd)(TPMBackend *t);

    bool (*get_tpm_established_flag)(TPMBackend *t);
};

struct tpm_req_hdr {
    uint16_t tag;
    uint32_t len;
@@ -83,13 +57,4 @@ struct tpm_resp_hdr {

#define TPM_ORD_GetTicks          0xf1

TPMBackend *qemu_find_tpm(const char *id);
int tpm_register_model(enum TpmModel model);
int tpm_register_driver(const TPMDriverOps *tdo);
void tpm_display_backend_drivers(void);
const TPMDriverOps *tpm_get_backend_driver(const char *type);
void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len);

extern const TPMDriverOps tpm_passthrough_driver;

#endif /* TPM_TPM_INT_H */
Loading