2013-03-28 12:26:21 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:12:57 +02:00
|
|
|
#ifndef TPM_BACKEND_H
|
|
|
|
#define TPM_BACKEND_H
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
#include "qom/object.h"
|
|
|
|
#include "qemu/option.h"
|
2013-04-02 18:28:41 +02:00
|
|
|
#include "sysemu/tpm.h"
|
2018-01-29 19:33:06 +01:00
|
|
|
#include "qapi/error.h"
|
2013-03-28 12:26:21 +01:00
|
|
|
|
2021-06-15 16:21:20 +02:00
|
|
|
#ifdef CONFIG_TPM
|
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
#define TYPE_TPM_BACKEND "tpm-backend"
|
2020-08-31 23:07:37 +02:00
|
|
|
OBJECT_DECLARE_TYPE(TPMBackend, TPMBackendClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 20:25:17 +02:00
|
|
|
TPM_BACKEND)
|
2013-03-28 12:26:21 +01:00
|
|
|
|
2017-10-10 00:55:49 +02:00
|
|
|
|
2017-10-10 00:55:55 +02:00
|
|
|
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;
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
struct TPMBackend {
|
|
|
|
Object parent;
|
|
|
|
|
|
|
|
/*< protected >*/
|
2017-11-06 19:39:00 +01:00
|
|
|
TPMIf *tpmif;
|
2013-03-28 12:26:21 +01:00
|
|
|
bool opened;
|
2017-09-29 13:10:16 +02:00
|
|
|
bool had_startup_error;
|
2018-01-29 19:33:05 +01:00
|
|
|
TPMBackendCmd *cmd;
|
2013-03-28 12:26:21 +01:00
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
/* <public> */
|
2013-03-28 12:26:21 +01:00
|
|
|
char *id;
|
|
|
|
|
|
|
|
QLIST_ENTRY(TPMBackend) list;
|
|
|
|
};
|
|
|
|
|
2017-09-29 13:10:14 +02:00
|
|
|
struct TPMBackendClass {
|
|
|
|
ObjectClass parent_class;
|
|
|
|
|
2013-04-02 18:28:41 +02:00
|
|
|
enum TpmType type;
|
2013-04-22 16:41:39 +02:00
|
|
|
const QemuOptDesc *opts;
|
2013-04-02 18:28:41 +02:00
|
|
|
/* get a descriptive text of the backend to display to the user */
|
2017-09-29 13:10:16 +02:00
|
|
|
const char *desc;
|
2013-04-02 18:28:41 +02:00
|
|
|
|
2017-11-06 19:39:09 +01:00
|
|
|
TPMBackend *(*create)(QemuOpts *opts);
|
2013-04-02 18:28:41 +02:00
|
|
|
|
2017-11-06 19:39:07 +01:00
|
|
|
/* start up the TPM on the backend - optional */
|
2017-11-05 00:57:15 +01:00
|
|
|
int (*startup_tpm)(TPMBackend *t, size_t buffersize);
|
2013-04-02 18:28:41 +02:00
|
|
|
|
2017-11-06 19:39:07 +01:00
|
|
|
/* optional */
|
2013-04-02 18:28:41 +02:00
|
|
|
void (*reset)(TPMBackend *t);
|
|
|
|
|
|
|
|
void (*cancel_cmd)(TPMBackend *t);
|
|
|
|
|
2017-11-06 19:39:07 +01:00
|
|
|
/* optional */
|
2013-04-02 18:28:41 +02:00
|
|
|
bool (*get_tpm_established_flag)(TPMBackend *t);
|
2015-05-26 22:51:05 +02:00
|
|
|
|
2017-11-06 19:39:07 +01:00
|
|
|
/* optional */
|
2015-05-26 22:51:05 +02:00
|
|
|
int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
|
|
|
|
|
|
|
|
TPMVersion (*get_tpm_version)(TPMBackend *t);
|
2017-09-29 13:10:17 +02:00
|
|
|
|
2017-11-03 23:10:01 +01:00
|
|
|
size_t (*get_buffer_size)(TPMBackend *t);
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
|
2013-04-02 18:28:41 +02:00
|
|
|
|
2018-01-29 19:33:06 +01:00
|
|
|
void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd, Error **errp);
|
2017-10-10 00:55:49 +02:00
|
|
|
};
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2017-11-06 19:39:00 +01:00
|
|
|
* @tpmif: TPM interface
|
2013-03-28 12:26:21 +01:00
|
|
|
* @datacb: callback for sending data to frontend
|
2017-11-06 19:39:03 +01:00
|
|
|
* @errp: a pointer to return the #Error object if an error occurs.
|
2013-03-28 12:26:21 +01:00
|
|
|
*
|
|
|
|
* Initialize the backend with the given variables.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2017-11-06 19:39:03 +01:00
|
|
|
int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp);
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_backend_startup_tpm:
|
|
|
|
* @s: the backend whose TPM support is to be started
|
2017-11-05 00:57:15 +01:00
|
|
|
* @buffersize: the buffer size the TPM is supposed to use,
|
|
|
|
* 0 to leave it as-is
|
2013-03-28 12:26:21 +01:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2017-11-05 00:57:15 +01:00
|
|
|
int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize);
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_backend_had_startup_error:
|
2023-07-14 13:33:02 +02:00
|
|
|
* @s: the backend to query for a startup error
|
2013-03-28 12:26:21 +01:00
|
|
|
*
|
|
|
|
* 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
|
2017-10-10 00:55:55 +02:00
|
|
|
* @cmd: the command to deliver
|
2013-03-28 12:26:21 +01:00
|
|
|
*
|
|
|
|
* Send a request to the backend. The backend will then send the request
|
|
|
|
* to the TPM implementation.
|
|
|
|
*/
|
2017-10-10 00:55:55 +02:00
|
|
|
void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2015-05-26 22:51:05 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-11-03 23:10:01 +01:00
|
|
|
/**
|
|
|
|
* tpm_backend_get_buffer_size:
|
|
|
|
* @s: the backend to call into
|
|
|
|
*
|
|
|
|
* Get the TPM's buffer size.
|
|
|
|
*
|
|
|
|
* Returns buffer size.
|
|
|
|
*/
|
|
|
|
size_t tpm_backend_get_buffer_size(TPMBackend *s);
|
|
|
|
|
2018-01-29 19:33:05 +01:00
|
|
|
/**
|
|
|
|
* tpm_backend_finish_sync:
|
|
|
|
* @s: the backend to call into
|
|
|
|
*
|
|
|
|
* Finish the pending command synchronously (this will call aio_poll()
|
|
|
|
* on qemu main AIOContext until it ends)
|
|
|
|
*/
|
|
|
|
void tpm_backend_finish_sync(TPMBackend *s);
|
|
|
|
|
2017-09-29 13:10:17 +02:00
|
|
|
/**
|
|
|
|
* tpm_backend_query_tpm:
|
|
|
|
* @s: the backend
|
|
|
|
*
|
|
|
|
* Query backend tpm info
|
|
|
|
*
|
|
|
|
* Returns newly allocated TPMInfo
|
|
|
|
*/
|
|
|
|
TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
|
|
|
|
|
2017-11-06 19:39:14 +01:00
|
|
|
TPMBackend *qemu_find_tpm_be(const char *id);
|
2013-04-02 18:28:41 +02:00
|
|
|
|
2021-06-15 16:21:20 +02:00
|
|
|
#endif /* CONFIG_TPM */
|
|
|
|
|
|
|
|
#endif /* TPM_BACKEND_H */
|