diff options
-rw-r--r-- | Makefile.objs | 2 | ||||
-rw-r--r-- | backends/tpm.c | 38 | ||||
-rw-r--r-- | hw/Makefile.objs | 1 | ||||
-rw-r--r-- | hw/tpm/Makefile.objs (renamed from tpm/Makefile.objs) | 2 | ||||
-rw-r--r-- | hw/tpm/tpm_int.h (renamed from tpm/tpm_int.h) | 37 | ||||
-rw-r--r-- | hw/tpm/tpm_passthrough.c (renamed from tpm/tpm_passthrough.c) | 20 | ||||
-rw-r--r-- | hw/tpm/tpm_tis.c (renamed from tpm/tpm_tis.c) | 2 | ||||
-rw-r--r-- | hw/tpm/tpm_tis.h (renamed from tpm/tpm_tis.h) | 5 | ||||
-rw-r--r-- | include/backends/tpm.h | 41 | ||||
-rw-r--r-- | include/sysemu/tpm.h (renamed from include/tpm/tpm.h) | 2 | ||||
-rw-r--r-- | include/sysemu/tpm_backend_int.h (renamed from tpm/tpm_backend.h) | 0 | ||||
-rw-r--r-- | monitor.c | 2 | ||||
-rw-r--r-- | tpm.c (renamed from tpm/tpm.c) | 19 | ||||
-rw-r--r-- | tpm/tpm_backend.c | 58 | ||||
-rw-r--r-- | vl.c | 2 |
15 files changed, 103 insertions, 128 deletions
diff --git a/Makefile.objs b/Makefile.objs index e568c018b3..a473348dc2 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -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/ diff --git a/backends/tpm.c b/backends/tpm.c index 28148c23cf..0580108c5f 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -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, diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 1cb86fa323..b7a1613612 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -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/ diff --git a/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 366e4a7128..99f5983143 100644 --- a/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,4 +1,2 @@ -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 diff --git a/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 340bfd52f1..08f87cb9a8 100644 --- a/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -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 */ diff --git a/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 1fdd66d356..578127723f 100644 --- a/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -31,8 +31,8 @@ #include "tpm_int.h" #include "hw/hw.h" #include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" #include "tpm_tis.h" -#include "tpm_backend.h" /* #define DEBUG_TPM */ @@ -48,6 +48,8 @@ #define TPM_PASSTHROUGH(obj) \ OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) +static const TPMDriverOps tpm_passthrough_driver; + /* data structures */ typedef struct TPMPassthruThreadParams { TPMState *tpm_state; @@ -96,6 +98,20 @@ static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf) return be32_to_cpu(resp->len); } +/* + * Write an error message in the given output buffer. + */ +static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) +{ + if (out_len >= sizeof(struct tpm_resp_hdr)) { + struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; + + resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); + resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); + resp->errcode = cpu_to_be32(TPM_FAIL); + } +} + static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len) @@ -512,7 +528,7 @@ static void tpm_passthrough_destroy(TPMBackend *tb) g_free(tpm_pt->tpm_dev); } -const TPMDriverOps tpm_passthrough_driver = { +static const TPMDriverOps tpm_passthrough_driver = { .type = TPM_TYPE_PASSTHROUGH, .desc = tpm_passthrough_create_desc, .create = tpm_passthrough_create, diff --git a/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index f0a4584607..faa3cecafe 100644 --- a/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -26,7 +26,7 @@ #include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/pci/pci_ids.h" -#include "tpm/tpm_tis.h" +#include "tpm_tis.h" #include "qemu-common.h" /*#define DEBUG_TIS */ diff --git a/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h index 1be4ddc8a1..916152ae3e 100644 --- a/tpm/tpm_tis.h +++ b/hw/tpm/tpm_tis.h @@ -35,11 +35,6 @@ #define TYPE_TPM_TIS "tpm-tis" -struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -}; - typedef enum { TPM_TIS_STATE_IDLE = 0, TPM_TIS_STATE_READY, diff --git a/include/backends/tpm.h b/include/backends/tpm.h index 9e93cc5060..466787453d 100644 --- a/include/backends/tpm.h +++ b/include/backends/tpm.h @@ -18,7 +18,7 @@ #include "qapi/error.h" #include "qapi-types.h" #include "qemu/option.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #define TYPE_TPM_BACKEND "tpm-backend" #define TPM_BACKEND(obj) \ @@ -56,6 +56,39 @@ struct TPMBackend { QLIST_ENTRY(TPMBackend) list; }; +typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); + +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +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); +}; + /** * tpm_backend_get_type: @@ -167,4 +200,10 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s); */ void tpm_backend_open(TPMBackend *s, Error **errp); +TPMBackend *qemu_find_tpm(const char *id); + +const TPMDriverOps *tpm_get_backend_driver(const char *type); +int tpm_register_model(enum TpmModel model); +int tpm_register_driver(const TPMDriverOps *tdo); + #endif diff --git a/include/tpm/tpm.h b/include/sysemu/tpm.h index 2d457c4439..13febddbee 100644 --- a/include/tpm/tpm.h +++ b/include/sysemu/tpm.h @@ -15,8 +15,6 @@ #include "qemu/option.h" typedef struct TPMState TPMState; -typedef struct TPMSizedBuffer TPMSizedBuffer; -typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty); int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); int tpm_init(void); diff --git a/tpm/tpm_backend.h b/include/sysemu/tpm_backend_int.h index 05d94d0f5b..05d94d0f5b 100644 --- a/tpm/tpm_backend.h +++ b/include/sysemu/tpm_backend_int.h @@ -47,7 +47,7 @@ #include "migration/migration.h" #include "sysemu/kvm.h" #include "qemu/acl.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qfloat.h" #include "qapi/qmp/qlist.h" @@ -16,8 +16,7 @@ #include "monitor/monitor.h" #include "qapi/qmp/qerror.h" #include "backends/tpm.h" -#include "tpm_int.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #include "qemu/config-file.h" #include "qmp-commands.h" @@ -62,20 +61,6 @@ static bool tpm_model_is_registered(enum TpmModel model) return false; } -/* - * Write an error message in the given output buffer. - */ -void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) -{ - if (out_len >= sizeof(struct tpm_resp_hdr)) { - struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; - - resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); - resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); - resp->errcode = cpu_to_be32(TPM_FAIL); - } -} - const TPMDriverOps *tpm_get_backend_driver(const char *type) { int i; @@ -109,7 +94,7 @@ int tpm_register_driver(const TPMDriverOps *tdo) * Walk the list of available TPM backend drivers and display them on the * screen. */ -void tpm_display_backend_drivers(void) +static void tpm_display_backend_drivers(void) { int i; diff --git a/tpm/tpm_backend.c b/tpm/tpm_backend.c deleted file mode 100644 index 4144ef7d76..0000000000 --- a/tpm/tpm_backend.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * common TPM backend driver functions - * - * Copyright (c) 2012-2013 IBM Corporation - * Authors: - * Stefan Berger <stefanb@us.ibm.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/> - */ - -#include "tpm/tpm.h" -#include "qemu/thread.h" -#include "tpm_backend.h" - -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); - } -} @@ -139,7 +139,7 @@ int main(int argc, char **argv) #include "sysemu/blockdev.h" #include "hw/block/block.h" #include "migration/block.h" -#include "tpm/tpm.h" +#include "sysemu/tpm.h" #include "sysemu/dma.h" #include "audio/audio.h" #include "migration/migration.h" |