2013-02-27 18:47:53 +01:00
|
|
|
/*
|
|
|
|
* passthrough TPM driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 - 2013 IBM Corporation
|
|
|
|
* Authors:
|
|
|
|
* Stefan Berger <stefanb@us.ibm.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 IAIK, Graz University of Technology
|
|
|
|
* Author: Andreas Niederl
|
|
|
|
*
|
|
|
|
* 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
|
2020-10-23 14:35:16 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-02-27 18:47:53 +01:00
|
|
|
*
|
|
|
|
* 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/>
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2015-03-17 18:29:20 +01:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2013-02-27 18:47:53 +01:00
|
|
|
#include "qemu/sockets.h"
|
2013-04-08 16:55:25 +02:00
|
|
|
#include "sysemu/tpm_backend.h"
|
2020-06-12 10:54:43 +02:00
|
|
|
#include "sysemu/tpm_util.h"
|
2013-02-27 18:47:53 +01:00
|
|
|
#include "tpm_int.h"
|
2017-09-29 13:10:17 +02:00
|
|
|
#include "qapi/clone-visitor.h"
|
2018-02-11 10:36:01 +01:00
|
|
|
#include "qapi/qapi-visit-tpm.h"
|
2018-03-03 02:28:30 +01:00
|
|
|
#include "trace.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
#define TYPE_TPM_PASSTHROUGH "tpm-passthrough"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(TPMPassthruState, TPM_PASSTHROUGH)
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
/* data structures */
|
2013-02-27 18:47:53 +01:00
|
|
|
struct TPMPassthruState {
|
2013-03-28 12:26:21 +01:00
|
|
|
TPMBackend parent;
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
TPMPassthroughOptions *options;
|
|
|
|
const char *tpm_dev;
|
2013-02-27 18:47:53 +01:00
|
|
|
int tpm_fd;
|
2013-02-27 18:47:54 +01:00
|
|
|
bool tpm_executing;
|
|
|
|
bool tpm_op_canceled;
|
|
|
|
int cancel_fd;
|
2015-05-26 22:51:06 +02:00
|
|
|
|
|
|
|
TPMVersion tpm_version;
|
2017-11-04 03:49:23 +01:00
|
|
|
size_t tpm_buffersize;
|
2013-02-27 18:47:53 +01:00
|
|
|
};
|
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
#define TPM_PASSTHROUGH_DEFAULT_DEVICE "/dev/tpm0"
|
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
/* functions */
|
|
|
|
|
|
|
|
static void tpm_passthrough_cancel_cmd(TPMBackend *tb);
|
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len)
|
|
|
|
{
|
2015-12-23 14:59:04 +01:00
|
|
|
int ret;
|
|
|
|
reread:
|
|
|
|
ret = read(fd, buf, len);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (errno != EINTR && errno != EAGAIN) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
goto reread;
|
|
|
|
}
|
|
|
|
return ret;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
2018-01-29 19:33:06 +01:00
|
|
|
|
|
|
|
static void tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
|
|
|
|
const uint8_t *in, uint32_t in_len,
|
|
|
|
uint8_t *out, uint32_t out_len,
|
|
|
|
bool *selftest_done, Error **errp)
|
2013-02-27 18:47:53 +01:00
|
|
|
{
|
2017-09-29 13:10:19 +02:00
|
|
|
ssize_t ret;
|
2015-02-23 15:27:19 +01:00
|
|
|
bool is_selftest;
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2017-11-06 19:39:12 +01:00
|
|
|
/* FIXME: protect shared variables or use other sync mechanism */
|
2013-02-27 18:47:54 +01:00
|
|
|
tpm_pt->tpm_op_canceled = false;
|
|
|
|
tpm_pt->tpm_executing = true;
|
2015-02-23 15:27:19 +01:00
|
|
|
*selftest_done = false;
|
|
|
|
|
2017-09-29 13:10:19 +02:00
|
|
|
is_selftest = tpm_util_is_selftest(in, in_len);
|
2013-02-27 18:47:54 +01:00
|
|
|
|
2017-10-10 00:55:53 +02:00
|
|
|
ret = qemu_write_full(tpm_pt->tpm_fd, in, in_len);
|
2013-02-27 18:47:53 +01:00
|
|
|
if (ret != in_len) {
|
2016-10-12 17:33:44 +02:00
|
|
|
if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) {
|
2018-01-29 19:33:06 +01:00
|
|
|
error_setg_errno(errp, errno, "tpm_passthrough: error while "
|
|
|
|
"transmitting data to TPM");
|
2013-02-27 18:47:54 +01:00
|
|
|
}
|
2013-02-27 18:47:53 +01:00
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
tpm_pt->tpm_executing = false;
|
|
|
|
|
|
|
|
ret = tpm_passthrough_unix_read(tpm_pt->tpm_fd, out, out_len);
|
2013-02-27 18:47:53 +01:00
|
|
|
if (ret < 0) {
|
2016-10-12 17:33:44 +02:00
|
|
|
if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) {
|
2018-01-29 19:33:06 +01:00
|
|
|
error_setg_errno(errp, errno, "tpm_passthrough: error while "
|
|
|
|
"reading data from TPM");
|
2013-02-27 18:47:54 +01:00
|
|
|
}
|
2013-02-27 18:47:53 +01:00
|
|
|
} else if (ret < sizeof(struct tpm_resp_hdr) ||
|
2018-01-29 19:33:03 +01:00
|
|
|
tpm_cmd_get_size(out) != ret) {
|
2013-02-27 18:47:53 +01:00
|
|
|
ret = -1;
|
2018-01-29 19:33:06 +01:00
|
|
|
error_setg_errno(errp, errno, "tpm_passthrough: received invalid "
|
|
|
|
"response packet from TPM");
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2015-02-23 15:27:19 +01:00
|
|
|
if (is_selftest && (ret >= sizeof(struct tpm_resp_hdr))) {
|
2018-01-29 19:33:03 +01:00
|
|
|
*selftest_done = tpm_cmd_get_errcode(out) == 0;
|
2015-02-23 15:27:19 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
err_exit:
|
|
|
|
if (ret < 0) {
|
2017-09-29 13:10:19 +02:00
|
|
|
tpm_util_write_fatal_error_response(out, out_len);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
tpm_pt->tpm_executing = false;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-29 19:33:06 +01:00
|
|
|
static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd,
|
|
|
|
Error **errp)
|
2013-02-27 18:47:53 +01:00
|
|
|
{
|
2017-09-29 13:10:14 +02:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2018-03-03 02:28:30 +01:00
|
|
|
trace_tpm_passthrough_handle_request(cmd);
|
2017-10-10 00:55:52 +02:00
|
|
|
|
2017-10-10 00:55:55 +02:00
|
|
|
tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len,
|
2018-01-29 19:33:06 +01:00
|
|
|
cmd->out, cmd->out_len, &cmd->selftest_done,
|
|
|
|
errp);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_passthrough_reset(TPMBackend *tb)
|
|
|
|
{
|
2018-03-03 02:28:30 +01:00
|
|
|
trace_tpm_passthrough_reset();
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
tpm_passthrough_cancel_cmd(tb);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-26 22:51:05 +02:00
|
|
|
static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb,
|
|
|
|
uint8_t locty)
|
|
|
|
{
|
|
|
|
/* only a TPM 2.0 will support this */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
static void tpm_passthrough_cancel_cmd(TPMBackend *tb)
|
|
|
|
{
|
2013-03-28 12:26:21 +01:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
2013-02-27 18:47:54 +01:00
|
|
|
int n;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As of Linux 3.7 the tpm_tis driver does not properly cancel
|
|
|
|
* commands on all TPM manufacturers' TPMs.
|
|
|
|
* Only cancel if we're busy so we don't cancel someone else's
|
|
|
|
* command, e.g., a command executed on the host.
|
|
|
|
*/
|
|
|
|
if (tpm_pt->tpm_executing) {
|
|
|
|
if (tpm_pt->cancel_fd >= 0) {
|
2017-11-06 19:39:12 +01:00
|
|
|
tpm_pt->tpm_op_canceled = true;
|
2013-02-27 18:47:54 +01:00
|
|
|
n = write(tpm_pt->cancel_fd, "-", 1);
|
|
|
|
if (n != 1) {
|
2015-02-25 05:22:35 +01:00
|
|
|
error_report("Canceling TPM command failed: %s",
|
2013-02-27 18:47:54 +01:00
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_report("Cannot cancel TPM command due to missing "
|
|
|
|
"TPM sysfs cancel entry");
|
|
|
|
}
|
|
|
|
}
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-26 22:51:05 +02:00
|
|
|
static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb)
|
|
|
|
{
|
2015-05-26 22:51:06 +02:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2015-05-26 22:51:06 +02:00
|
|
|
return tpm_pt->tpm_version;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-03 23:10:01 +01:00
|
|
|
static size_t tpm_passthrough_get_buffer_size(TPMBackend *tb)
|
|
|
|
{
|
2017-11-04 03:49:23 +01:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = tpm_util_get_buffer_size(tpm_pt->tpm_fd, tpm_pt->tpm_version,
|
|
|
|
&tpm_pt->tpm_buffersize);
|
|
|
|
if (ret < 0) {
|
|
|
|
tpm_pt->tpm_buffersize = 4096;
|
|
|
|
}
|
|
|
|
return tpm_pt->tpm_buffersize;
|
2017-11-03 23:10:01 +01:00
|
|
|
}
|
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
/*
|
|
|
|
* Unless path or file descriptor set has been provided by user,
|
|
|
|
* determine the sysfs cancel file following kernel documentation
|
|
|
|
* in Documentation/ABI/stable/sysfs-class-tpm.
|
2018-01-29 19:33:04 +01:00
|
|
|
* From /dev/tpm0 create /sys/class/tpm/tpm0/device/cancel
|
|
|
|
* before 4.0: /sys/class/misc/tpm0/device/cancel
|
2013-02-27 18:47:54 +01:00
|
|
|
*/
|
2017-09-29 13:10:17 +02:00
|
|
|
static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)
|
2013-02-27 18:47:54 +01:00
|
|
|
{
|
|
|
|
int fd = -1;
|
2013-04-16 23:08:36 +02:00
|
|
|
char *dev;
|
2013-02-27 18:47:54 +01:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
if (tpm_pt->options->cancel_path) {
|
2020-07-21 14:25:21 +02:00
|
|
|
fd = qemu_open_old(tpm_pt->options->cancel_path, O_WRONLY);
|
2013-02-27 18:47:54 +01:00
|
|
|
if (fd < 0) {
|
2018-01-29 19:33:04 +01:00
|
|
|
error_report("tpm_passthrough: Could not open TPM cancel path: %s",
|
2013-02-27 18:47:54 +01:00
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:08:36 +02:00
|
|
|
dev = strrchr(tpm_pt->tpm_dev, '/');
|
2018-01-29 19:33:04 +01:00
|
|
|
if (!dev) {
|
|
|
|
error_report("tpm_passthrough: Bad TPM device path %s",
|
|
|
|
tpm_pt->tpm_dev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev++;
|
|
|
|
if (snprintf(path, sizeof(path), "/sys/class/tpm/%s/device/cancel",
|
|
|
|
dev) < sizeof(path)) {
|
2020-07-21 14:25:21 +02:00
|
|
|
fd = qemu_open_old(path, O_WRONLY);
|
2018-01-29 19:33:04 +01:00
|
|
|
if (fd < 0) {
|
|
|
|
if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",
|
|
|
|
dev) < sizeof(path)) {
|
2020-07-21 14:25:21 +02:00
|
|
|
fd = qemu_open_old(path, O_WRONLY);
|
2013-04-16 23:08:36 +02:00
|
|
|
}
|
2013-02-27 18:47:54 +01:00
|
|
|
}
|
2018-01-29 19:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
error_report("tpm_passthrough: Could not guess TPM cancel path");
|
2013-04-16 23:08:36 +02:00
|
|
|
} else {
|
2018-01-29 19:33:04 +01:00
|
|
|
tpm_pt->options->cancel_path = g_strdup(path);
|
2013-02-27 18:47:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2017-11-06 19:39:08 +01:00
|
|
|
static int
|
|
|
|
tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opts)
|
2013-02-27 18:47:53 +01:00
|
|
|
{
|
|
|
|
const char *value;
|
|
|
|
|
2013-02-27 18:47:54 +01:00
|
|
|
value = qemu_opt_get(opts, "cancel-path");
|
2017-09-29 13:10:17 +02:00
|
|
|
if (value) {
|
|
|
|
tpm_pt->options->cancel_path = g_strdup(value);
|
|
|
|
}
|
2013-02-27 18:47:54 +01:00
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
value = qemu_opt_get(opts, "path");
|
2017-09-29 13:10:17 +02:00
|
|
|
if (value) {
|
|
|
|
tpm_pt->options->path = g_strdup(value);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
tpm_pt->tpm_dev = value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE;
|
2020-07-21 14:25:21 +02:00
|
|
|
tpm_pt->tpm_fd = qemu_open_old(tpm_pt->tpm_dev, O_RDWR);
|
2013-03-28 12:26:21 +01:00
|
|
|
if (tpm_pt->tpm_fd < 0) {
|
2015-02-25 05:22:35 +01:00
|
|
|
error_report("Cannot access TPM device using '%s': %s",
|
2013-03-28 12:26:21 +01:00
|
|
|
tpm_pt->tpm_dev, strerror(errno));
|
2017-11-06 19:39:11 +01:00
|
|
|
return -1;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2015-05-26 22:51:06 +02:00
|
|
|
if (tpm_util_test_tpmdev(tpm_pt->tpm_fd, &tpm_pt->tpm_version)) {
|
2015-02-25 05:22:35 +01:00
|
|
|
error_report("'%s' is not a TPM device.",
|
2013-03-28 12:26:21 +01:00
|
|
|
tpm_pt->tpm_dev);
|
2017-11-06 19:39:11 +01:00
|
|
|
return -1;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-06 19:39:11 +01:00
|
|
|
tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tpm_pt);
|
|
|
|
if (tpm_pt->cancel_fd < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2017-11-06 19:39:11 +01:00
|
|
|
return 0;
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-06 19:39:09 +01:00
|
|
|
static TPMBackend *tpm_passthrough_create(QemuOpts *opts)
|
2013-02-27 18:47:53 +01:00
|
|
|
{
|
2013-03-28 12:26:21 +01:00
|
|
|
Object *obj = object_new(TYPE_TPM_PASSTHROUGH);
|
2013-02-27 18:47:53 +01:00
|
|
|
|
2017-11-06 19:39:11 +01:00
|
|
|
if (tpm_passthrough_handle_device_opts(TPM_PASSTHROUGH(obj), opts)) {
|
|
|
|
object_unref(obj);
|
|
|
|
return NULL;
|
2013-02-27 18:47:54 +01:00
|
|
|
}
|
|
|
|
|
2017-11-06 19:39:09 +01:00
|
|
|
return TPM_BACKEND(obj);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-06 01:31:43 +01:00
|
|
|
static int tpm_passthrough_startup_tpm(TPMBackend *tb, size_t buffersize)
|
|
|
|
{
|
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
|
|
|
|
|
|
|
if (buffersize && buffersize < tpm_pt->tpm_buffersize) {
|
|
|
|
error_report("Requested buffer size of %zu is smaller than host TPM's "
|
|
|
|
"fixed buffer size of %zu",
|
|
|
|
buffersize, tpm_pt->tpm_buffersize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
static TpmTypeOptions *tpm_passthrough_get_tpm_options(TPMBackend *tb)
|
|
|
|
{
|
|
|
|
TpmTypeOptions *options = g_new0(TpmTypeOptions, 1);
|
|
|
|
|
2021-09-17 16:31:16 +02:00
|
|
|
options->type = TPM_TYPE_PASSTHROUGH;
|
2017-09-29 13:10:17 +02:00
|
|
|
options->u.passthrough.data = QAPI_CLONE(TPMPassthroughOptions,
|
|
|
|
TPM_PASSTHROUGH(tb)->options);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2013-04-22 16:41:39 +02:00
|
|
|
static const QemuOptDesc tpm_passthrough_cmdline_opts[] = {
|
|
|
|
TPM_STANDARD_CMDLINE_OPTS,
|
|
|
|
{
|
|
|
|
.name = "cancel-path",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Sysfs file entry for canceling TPM commands",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "path",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Path to TPM device on the host",
|
|
|
|
},
|
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
static void tpm_passthrough_inst_init(Object *obj)
|
|
|
|
{
|
2017-09-29 13:10:15 +02:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
tpm_pt->options = g_new0(TPMPassthroughOptions, 1);
|
2017-09-29 13:10:15 +02:00
|
|
|
tpm_pt->tpm_fd = -1;
|
|
|
|
tpm_pt->cancel_fd = -1;
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_passthrough_inst_finalize(Object *obj)
|
|
|
|
{
|
2017-09-29 13:10:15 +02:00
|
|
|
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
|
|
|
|
|
|
|
|
tpm_passthrough_cancel_cmd(TPM_BACKEND(obj));
|
|
|
|
|
2017-11-06 19:39:10 +01:00
|
|
|
if (tpm_pt->tpm_fd >= 0) {
|
|
|
|
qemu_close(tpm_pt->tpm_fd);
|
|
|
|
}
|
|
|
|
if (tpm_pt->cancel_fd >= 0) {
|
|
|
|
qemu_close(tpm_pt->cancel_fd);
|
|
|
|
}
|
2017-09-29 13:10:17 +02:00
|
|
|
qapi_free_TPMPassthroughOptions(tpm_pt->options);
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_passthrough_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass);
|
|
|
|
|
2017-10-10 00:55:49 +02:00
|
|
|
tbc->type = TPM_TYPE_PASSTHROUGH;
|
|
|
|
tbc->opts = tpm_passthrough_cmdline_opts;
|
|
|
|
tbc->desc = "Passthrough TPM backend driver";
|
|
|
|
tbc->create = tpm_passthrough_create;
|
2017-11-06 01:31:43 +01:00
|
|
|
tbc->startup_tpm = tpm_passthrough_startup_tpm;
|
2017-10-10 00:55:49 +02:00
|
|
|
tbc->reset = tpm_passthrough_reset;
|
|
|
|
tbc->cancel_cmd = tpm_passthrough_cancel_cmd;
|
|
|
|
tbc->get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag;
|
|
|
|
tbc->reset_tpm_established_flag =
|
|
|
|
tpm_passthrough_reset_tpm_established_flag;
|
|
|
|
tbc->get_tpm_version = tpm_passthrough_get_tpm_version;
|
2017-11-03 23:10:01 +01:00
|
|
|
tbc->get_buffer_size = tpm_passthrough_get_buffer_size;
|
2017-10-10 00:55:49 +02:00
|
|
|
tbc->get_tpm_options = tpm_passthrough_get_tpm_options;
|
2017-09-29 13:10:14 +02:00
|
|
|
tbc->handle_request = tpm_passthrough_handle_request;
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo tpm_passthrough_info = {
|
|
|
|
.name = TYPE_TPM_PASSTHROUGH,
|
|
|
|
.parent = TYPE_TPM_BACKEND,
|
|
|
|
.instance_size = sizeof(TPMPassthruState),
|
|
|
|
.class_init = tpm_passthrough_class_init,
|
|
|
|
.instance_init = tpm_passthrough_inst_init,
|
|
|
|
.instance_finalize = tpm_passthrough_inst_finalize,
|
|
|
|
};
|
|
|
|
|
2013-02-27 18:47:53 +01:00
|
|
|
static void tpm_passthrough_register(void)
|
|
|
|
{
|
2013-03-28 12:26:21 +01:00
|
|
|
type_register_static(&tpm_passthrough_info);
|
2013-02-27 18:47:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(tpm_passthrough_register)
|