From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPMVG-0004OP-Bm for qemu-devel@nongnu.org; Tue, 01 May 2012 19:29:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPMVD-000191-Oh for qemu-devel@nongnu.org; Tue, 01 May 2012 19:29:05 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:57390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPMVD-00016p-Hd for qemu-devel@nongnu.org; Tue, 01 May 2012 19:29:03 -0400 Received: by obbwd20 with SMTP id wd20so118241obb.4 for ; Tue, 01 May 2012 16:29:01 -0700 (PDT) Message-ID: <4FA06B18.9040507@codemonkey.ws> Date: Tue, 01 May 2012 18:00:40 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1335788196-315-1-git-send-email-stefanb@linux.vnet.ibm.com> <1335788196-315-2-git-send-email-stefanb@linux.vnet.ibm.com> In-Reply-To: <1335788196-315-2-git-send-email-stefanb@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V16 1/7] Support for TPM command line options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Berger Cc: mst@redhat.com, qemu-devel@nongnu.org, andreas.niederl@iaik.tugraz.at On 04/30/2012 07:16 AM, Stefan Berger wrote: > This patch adds support for TPM command line options. > The command line options supported here are > > ./qemu-... -tpmdev passthrough,path=,id= > -device tpm-tis,tpmdev= > > and > > ./qemu-... -tpmdev ? > > where the latter works similar to -soundhw ? and shows a list of > available TPM backends (for example 'passthrough'). > > Using the type parameter, the backend is chosen, i.e., 'passthrough' for the > passthrough driver. The interpretation of the other parameters along > with determining whether enough parameters were provided is pushed into > the backend driver, which needs to implement the interface function > 'create' and return a TPMDriver structure if the VM can be started or 'NULL' > if not enough or bad parameters were provided. > > Monitor support for 'info tpm' has been added. It for example prints the > following: > > (qemu) info tpm > TPM devices: > tpm0: model=tpm-tis > \ tpm0: type=passthrough,path=/dev/tpm0 > > Signed-off-by: Stefan Berger > --- > hmp-commands.hx | 2 + > hmp.c | 28 +++++++ > hmp.h | 1 + > hw/tpm_tis.h | 78 ++++++++++++++++++++ > monitor.c | 8 ++ > qapi-schema.json | 29 ++++++++ > qemu-config.c | 20 +++++ > qemu-options.hx | 33 +++++++++ > tpm.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > tpm.h | 81 +++++++++++++++++++++ > vl.c | 17 +++++ > 11 files changed, 510 insertions(+), 0 deletions(-) > create mode 100644 hw/tpm_tis.h > create mode 100644 tpm.c > create mode 100644 tpm.h > > diff --git a/hmp-commands.hx b/hmp-commands.hx > index 18cb415..08f6942 100644 > --- a/hmp-commands.hx > +++ b/hmp-commands.hx > @@ -1401,6 +1401,8 @@ show device tree > show qdev device model list > @item info roms > show roms > +@item info tpm > +show the TPM device > @end table > ETEXI > > diff --git a/hmp.c b/hmp.c > index eb96618..7e130c5 100644 > --- a/hmp.c > +++ b/hmp.c > @@ -546,6 +546,34 @@ void hmp_info_block_jobs(Monitor *mon) > } > } > > +void hmp_info_tpm(Monitor *mon) > +{ > + TPMInfoList *info_list, *info; > + Error *err = NULL; > + unsigned int c = 0; > + > + info_list = qmp_query_tpm(&err); > + if (err) { > + monitor_printf(mon, "TPM device not supported\n"); > + error_free(err); > + return; > + } > + > + monitor_printf(mon, "TPM device:\n"); > + > + for (info = info_list; info; info = info->next) { > + TPMInfo *ti = info->value; > + monitor_printf(mon, " tpm%d: model=%s\n", > + c, ti->model); > + monitor_printf(mon, " \\ %s: type=%s%s%s\n", > + ti->id, ti->type, > + ti->parameters ? "," : "", > + ti->parameters ? ti->parameters : ""); > + c++; > + } > + qapi_free_TPMInfoList(info_list); > +} > + > void hmp_quit(Monitor *mon, const QDict *qdict) > { > monitor_suspend(mon); > diff --git a/hmp.h b/hmp.h > index 443b812..8e2a858 100644 > --- a/hmp.h > +++ b/hmp.h > @@ -33,6 +33,7 @@ void hmp_info_spice(Monitor *mon); > void hmp_info_balloon(Monitor *mon); > void hmp_info_pci(Monitor *mon); > void hmp_info_block_jobs(Monitor *mon); > +void hmp_info_tpm(Monitor *mon); > void hmp_quit(Monitor *mon, const QDict *qdict); > void hmp_stop(Monitor *mon, const QDict *qdict); > void hmp_system_reset(Monitor *mon, const QDict *qdict); > diff --git a/hw/tpm_tis.h b/hw/tpm_tis.h > new file mode 100644 > index 0000000..5e1f731 > --- /dev/null > +++ b/hw/tpm_tis.h > @@ -0,0 +1,78 @@ > +/* > + * tpm_tis.c - QEMU's TPM TIS interface emulator > + * > + * Copyright (C) 2006,2010,2011 IBM Corporation > + * > + * Authors: > + * Stefan Berger > + * David Safford > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + * > + * Implementation of the TIS interface according to specs found at > + * http://www.trustedcomputiggroup.org > + * > + */ > +#ifndef HW_TPM_TIS_H > +#define HW_TPM_TIS_H > + > +#include "isa.h" > +#include "qemu-common.h" > + > +#define TPM_TIS_ADDR_BASE 0xFED40000 > + > +#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ > +#define TPM_TIS_LOCALITY_SHIFT 12 > +#define TPM_TIS_NO_LOCALITY 0xff > + > +#define TPM_TIS_IS_VALID_LOCTY(x) ((x)< TPM_TIS_NUM_LOCALITIES) > + > +#define TPM_TIS_IRQ 5 > + > +#define TPM_TIS_BUFFER_MAX 4096 > + > + > +typedef struct TPMSizedBuffer { > + uint32_t size; > + uint8_t *buffer; > +} TPMSizedBuffer; > + > +typedef enum { > + TPM_TIS_STATUS_IDLE = 0, > + TPM_TIS_STATUS_READY, > + TPM_TIS_STATUS_COMPLETION, > + TPM_TIS_STATUS_EXECUTION, > + TPM_TIS_STATUS_RECEPTION, > +} TPMTISStatus; > + > +/* locality data -- all fields are persisted */ > +typedef struct TPMLocality { > + TPMTISStatus status; > + uint8_t access; > + uint8_t sts; > + uint32_t inte; > + uint32_t ints; > + > + uint16_t w_offset; > + uint16_t r_offset; > + TPMSizedBuffer w_buffer; > + TPMSizedBuffer r_buffer; > +} TPMLocality; > + > +typedef struct TPMTISState { > + QEMUBH *bh; > + uint32_t offset; > + uint8_t buf[TPM_TIS_BUFFER_MAX]; > + > + uint8_t active_locty; > + uint8_t aborting_locty; > + uint8_t next_locty; > + > + TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; > + > + qemu_irq irq; > + uint32_t irq_num; > +} TPMTISState; > + > +#endif /* HW_TPM_TIS_H */ > diff --git a/monitor.c b/monitor.c > index 8946a10..18bb195 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -47,6 +47,7 @@ > #include "migration.h" > #include "kvm.h" > #include "acl.h" > +#include "tpm.h" > #include "qint.h" > #include "qfloat.h" > #include "qlist.h" > @@ -2602,6 +2603,13 @@ static mon_cmd_t info_cmds[] = { > .mhandler.info = do_trace_print_events, > }, > { > + .name = "tpm", > + .args_type = "", > + .params = "", > + .help = "show the TPM device", > + .mhandler.info = hmp_info_tpm, > + }, > + { > .name = NULL, > }, > }; > diff --git a/qapi-schema.json b/qapi-schema.json > index 9193fb9..aa4cf10 100644 > --- a/qapi-schema.json > +++ b/qapi-schema.json > @@ -1728,3 +1728,32 @@ > # Since: 0.14.0 > ## > { 'command': 'device_del', 'data': {'id': 'str'} } > + > +## > +# @TPMInfo: > +# > +# Information about the TPM > +# > +# @model: The TPM frontend model, i.e., tpm-tis > +# > +# @id: The ID of the TPM > +# > +# @type: The type of TPM backend, i.e., passthrough > +# > +# @parameters: #optional Additional parameters of the TPM backend device > +# > +# Since: 1.1 > +## > +{ 'type': 'TPMInfo', > + 'data': {'model': 'str', 'id': 'str', 'type': 'str', '*parameters': 'str' } } As I mentioned in my previous review, parameters needs to be broken up into the supported parameters. So: '*fd': 'int', '*path': 'str', etc. Regards, Anthony Liguori