Patchwork [V21,1/7] Support for TPM command line options

login
register
mail settings
Submitter Stefan Berger
Date Feb. 8, 2013, 9:42 p.m.
Message ID <1360359741-18151-2-git-send-email-stefanb@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/219315/
State New
Headers show

Comments

Stefan Berger - Feb. 8, 2013, 9:42 p.m.
This patch adds support for TPM command line options.
The command line options supported here are

./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
           -device tpm-tis,tpmdev=<id>

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 <stefanb@linux.vnet.ibm.com>
---
 Makefile.objs     |   1 +
 hmp-commands.hx   |   2 +
 hmp.c             |  31 ++++++++
 hmp.h             |   1 +
 include/tpm/tpm.h |  21 ++++++
 monitor.c         |   8 ++
 qapi-schema.json  |  56 ++++++++++++++
 qemu-options.hx   |  33 +++++++++
 qmp-commands.hx   |   6 ++
 tpm/Makefile.objs |   1 +
 tpm/tpm.c         | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tpm/tpm_int.h     |  79 ++++++++++++++++++++
 tpm/tpm_tis.h     |  78 +++++++++++++++++++
 vl.c              |  37 +++++++++
 14 files changed, 572 insertions(+)
 create mode 100644 include/tpm/tpm.h
 create mode 100644 tpm/Makefile.objs
 create mode 100644 tpm/tpm.c
 create mode 100644 tpm/tpm_int.h
 create mode 100644 tpm/tpm_tis.h
Eric Blake - Feb. 8, 2013, 10:01 p.m.
On 02/08/2013 02:42 PM, Stefan Berger wrote:
> This patch adds support for TPM command line options.
> The command line options supported here are
> 
> ./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
>            -device tpm-tis,tpmdev=<id>
> 
> and
> 
> ./qemu-... -tpmdev ?

I though we preferred '-tpmdev help' instead of '-tpmdev ?' these days,
as that doesn't need shell quoting.

> 
> where the latter works similar to -soundhw ? and shows a list of
> available TPM backends (for example 'passthrough').

What is the QMP counterpart command for listing all possible TPM
backends?  Libvirt refuses to use command-line probing since qemu 1.3,
so we need some way for libvirt to get at the same list from QMP without
having to use '-tpmdev ?'.


> +++ b/qapi-schema.json
> @@ -3184,3 +3184,59 @@
>  # Since: 1.4
>  ##
>  { 'command': 'chardev-remove', 'data': {'id': 'str'} }
> +
> +##
> +# @TpmModel
> +#
> +# An enumeration of TPM models.
> +#
> +# @tpm-tis: TPM TIS model
> +#
> +# Since: 1.5
> +##
> +{ 'enum': 'TpmModel',
> +  'data': [ 'tpm-tis' ] }
> +
> +##
> +# @TpmType
> +#
> +# An enumeration of TPM types.
> +#
> +# @passthrough: TPM passthrough
> +#
> +# Since: 1.5
> +##
> +{ 'enum': 'TpmType',
> +  'data': [ 'passthrough' ] }
> +
> +##
> +# @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
> +#
> +# @path: #optional Path to the TPM backend device
> +#
> +# @cancel_path: #optional Path to TPM backend device's cancel sysfs entry

Prefer '-' over '_' in QMP; this should be cancel-path.

> +#
> +# Since: 1.5
> +##
> +{ 'type': 'TPMInfo',
> +  'data': {'model': 'TpmModel', 'id': 'str', 'type': 'TpmType', '*path': 'str',
> +           '*cancel_path': 'str' } }

Is this a case where the choice of which optional parameters are present
depends on which model was in use?  That is, if we add a new model that
uses a new field, would it be better to have a union type, something like:

{ 'type': 'TPMTis', 'data': {'path':'str', '*cancel-path':'str'} }
{ 'union': 'TPMBackend',
  'data': { 'tpm-tis' : 'TPMTis',
            'tpm-future': 'TPMFUture' } }
{ 'type': 'TPMInfo',
  'data': { 'id': 'str', 'type': 'TpmType', 'model': 'TPMBackend' } }

so that the user sees:
{ 'id': 'tpm0', 'type':'passthrough',
  'model': { 'type':'tpm-tis', 'data':{'path':'/dev/tpm'} } }

not necessarily better, just food for thought.

> +Options to each backend are described below.
> +
> +Use ? to print all available TPM backend types.
> +@example
> +qemu -tpmdev ?

Again, new code should prefer 'help' rather than '?' from the command line.
Stefan Berger - Feb. 9, 2013, 2:55 a.m.
On 02/08/2013 05:01 PM, Eric Blake wrote:
> On 02/08/2013 02:42 PM, Stefan Berger wrote:
>> This patch adds support for TPM command line options.
>> The command line options supported here are
>>
>> ./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
>>             -device tpm-tis,tpmdev=<id>
>>
>> and
>>
>> ./qemu-... -tpmdev ?
> I though we preferred '-tpmdev help' instead of '-tpmdev ?' these days,
> as that doesn't need shell quoting.

Will fix it. I only used this syntax because the existing  '-soundhw ?'.

>> where the latter works similar to -soundhw ? and shows a list of
>> available TPM backends (for example 'passthrough').
> What is the QMP counterpart command for listing all possible TPM
> backends?  Libvirt refuses to use command-line probing since qemu 1.3,
> so we need some way for libvirt to get at the same list from QMP without
> having to use '-tpmdev ?'.

Now added query-tpm-models and query-tpm-types listing the below shown 
enumerations.

>
>> +++ b/qapi-schema.json
>> @@ -3184,3 +3184,59 @@
>>   # Since: 1.4
>>   ##
>>   { 'command': 'chardev-remove', 'data': {'id': 'str'} }
>> +
>> +##
>> +# @TpmModel
>> +#
>> +# An enumeration of TPM models.
>> +#
>> +# @tpm-tis: TPM TIS model
>> +#
>> +# Since: 1.5
>> +##
>> +{ 'enum': 'TpmModel',
>> +  'data': [ 'tpm-tis' ] }
>> +
>> +##
>> +# @TpmType
>> +#
>> +# An enumeration of TPM types.
>> +#
>> +# @passthrough: TPM passthrough
>> +#
>> +# Since: 1.5
>> +##
>> +{ 'enum': 'TpmType',
>> +  'data': [ 'passthrough' ] }
>> +
>> +##
>> +# @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
>> +#
>> +# @path: #optional Path to the TPM backend device
>> +#
>> +# @cancel_path: #optional Path to TPM backend device's cancel sysfs entry
> Prefer '-' over '_' in QMP; this should be cancel-path.
>

Fine, I changed it and also changed it for the command line (6/7). I 
looked around in this file and searched for '_' versus '-' and found 
both, rolled the dice afterwards...

>> +#
>> +# Since: 1.5
>> +##
>> +{ 'type': 'TPMInfo',
>> +  'data': {'model': 'TpmModel', 'id': 'str', 'type': 'TpmType', '*path': 'str',
>> +           '*cancel_path': 'str' } }
> Is this a case where the choice of which optional parameters are present
> depends on which model was in use?  That is, if we add a new model that
> uses a new field, would it be better to have a union type, something like:
>
> { 'type': 'TPMTis', 'data': {'path':'str', '*cancel-path':'str'} }
> { 'union': 'TPMBackend',
>    'data': { 'tpm-tis' : 'TPMTis',
>              'tpm-future': 'TPMFUture' } }
> { 'type': 'TPMInfo',
>    'data': { 'id': 'str', 'type': 'TpmType', 'model': 'TPMBackend' } }
>
> so that the user sees:
> { 'id': 'tpm0', 'type':'passthrough',
>    'model': { 'type':'tpm-tis', 'data':{'path':'/dev/tpm'} } }
>
> not necessarily better, just food for thought.
>

Above is not entirely reflecting the real world. What about the following?

The backend:

{ 'type': 'TPMPassthrough', 'data': { 'type' : 'TpmType', 'path':'str', '*cancel-path':'str'} }

{ 'union': 'TPMBE',
   'data': { 'tpm-passthrough'   : 'TPMPassthrough',
             'tpm-future-backend': 'TPMFutureBackend' } }


The hardware device 'model' (frontend):


{ 'type' : 'TPMTis', 'data' : { model : 'TpmModel' }

{ 'union': 'TPMFE',
   'data': { 'tpm-tis'         : 'TPMTis',
             'tpm-future-model': 'TPMFutureModel' } }

{ 'type' : 'TPMInfo'
   'data' : { 'id' : 'str', 'model' : 'TPMFE', 'type' : 'TPMBE' }

The user should then see:

{ 'id': 'tpm0',
   'model' : { 'model' : 'tpm-tis'},
   'type'  : { 'type'  : 'passthrough', 'path' : '/dev/tpm0' , 'cancel-path' = '/dev/fdset/2' } }


Stefan
Corey Bryant - Feb. 11, 2013, 3:20 p.m.
On 02/08/2013 09:55 PM, Stefan Berger wrote:
> On 02/08/2013 05:01 PM, Eric Blake wrote:
>> On 02/08/2013 02:42 PM, Stefan Berger wrote:
>>> This patch adds support for TPM command line options.
>>> The command line options supported here are
>>>
>>> ./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
>>>             -device tpm-tis,tpmdev=<id>
>>>
>>> and
>>>
>>> ./qemu-... -tpmdev ?
>> I though we preferred '-tpmdev help' instead of '-tpmdev ?' these days,
>> as that doesn't need shell quoting.
> 
> Will fix it. I only used this syntax because the existing  '-soundhw ?'.
> 
>>> where the latter works similar to -soundhw ? and shows a list of
>>> available TPM backends (for example 'passthrough').
>> What is the QMP counterpart command for listing all possible TPM
>> backends?  Libvirt refuses to use command-line probing since qemu 1.3,
>> so we need some way for libvirt to get at the same list from QMP without
>> having to use '-tpmdev ?'.
> 
> Now added query-tpm-models and query-tpm-types listing the below shown 
> enumerations.
> 
>>
>>> +++ b/qapi-schema.json
>>> @@ -3184,3 +3184,59 @@
>>>   # Since: 1.4
>>>   ##
>>>   { 'command': 'chardev-remove', 'data': {'id': 'str'} }
>>> +
>>> +##
>>> +# @TpmModel
>>> +#
>>> +# An enumeration of TPM models.
>>> +#
>>> +# @tpm-tis: TPM TIS model
>>> +#
>>> +# Since: 1.5
>>> +##
>>> +{ 'enum': 'TpmModel',
>>> +  'data': [ 'tpm-tis' ] }
>>> +
>>> +##
>>> +# @TpmType
>>> +#
>>> +# An enumeration of TPM types.
>>> +#
>>> +# @passthrough: TPM passthrough
>>> +#
>>> +# Since: 1.5
>>> +##
>>> +{ 'enum': 'TpmType',
>>> +  'data': [ 'passthrough' ] }
>>> +
>>> +##
>>> +# @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
>>> +#
>>> +# @path: #optional Path to the TPM backend device
>>> +#
>>> +# @cancel_path: #optional Path to TPM backend device's cancel sysfs entry
>> Prefer '-' over '_' in QMP; this should be cancel-path.
>>
> 
> Fine, I changed it and also changed it for the command line (6/7). I 
> looked around in this file and searched for '_' versus '-' and found 
> both, rolled the dice afterwards...
> 
>>> +#
>>> +# Since: 1.5
>>> +##
>>> +{ 'type': 'TPMInfo',
>>> +  'data': {'model': 'TpmModel', 'id': 'str', 'type': 'TpmType', '*path': 'str',
>>> +           '*cancel_path': 'str' } }
>> Is this a case where the choice of which optional parameters are present
>> depends on which model was in use?  That is, if we add a new model that
>> uses a new field, would it be better to have a union type, something like:
>>
>> { 'type': 'TPMTis', 'data': {'path':'str', '*cancel-path':'str'} }
>> { 'union': 'TPMBackend',
>>    'data': { 'tpm-tis' : 'TPMTis',
>>              'tpm-future': 'TPMFUture' } }
>> { 'type': 'TPMInfo',
>>    'data': { 'id': 'str', 'type': 'TpmType', 'model': 'TPMBackend' } }
>>
>> so that the user sees:
>> { 'id': 'tpm0', 'type':'passthrough',
>>    'model': { 'type':'tpm-tis', 'data':{'path':'/dev/tpm'} } }
>>
>> not necessarily better, just food for thought.
>>
> 
> Above is not entirely reflecting the real world. What about the following?
> 
> The backend:
> 
> { 'type': 'TPMPassthrough', 'data': { 'type' : 'TpmType', 'path':'str', '*cancel-path':'str'} }
> 
> { 'union': 'TPMBE',
>    'data': { 'tpm-passthrough'   : 'TPMPassthrough',
>              'tpm-future-backend': 'TPMFutureBackend' } }
> 
> 
> The hardware device 'model' (frontend):
> 
> 
> { 'type' : 'TPMTis', 'data' : { model : 'TpmModel' }
> 
> { 'union': 'TPMFE',
>    'data': { 'tpm-tis'         : 'TPMTis',
>              'tpm-future-model': 'TPMFutureModel' } }
> 
> { 'type' : 'TPMInfo'
>    'data' : { 'id' : 'str', 'model' : 'TPMFE', 'type' : 'TPMBE' }
> 
> The user should then see:
> 
> { 'id': 'tpm0',
>    'model' : { 'model' : 'tpm-tis'},
>    'type'  : { 'type'  : 'passthrough', 'path' : '/dev/tpm0' , 'cancel-path' = '/dev/fdset/2' } }
> 
> 
> Stefan
> 

It might be cleaner if you use a hybrid of what you have here and what you already had before (plus you might be able to re-use some of these for query-tpm-models and query-tpm-types).  Maybe something like this?

{ 'enum': 'TpmModel',
  'data': [ 'tpm-tis' ] }

{ 'enum': 'TpmType',
  'data': [ 'passthrough' ] }

{ 'type': 'TPMPassthroughOptions', 'data': { '*path':'str', '*cancel-path':'str'} }

{ 'union': 'TpmTypeOptions',
   'data': { 'tpm-passthrough-options'   : 'TPMPassthroughOptions',
             'tpm-future-backend-options': 'TPMFutureBackendOptions' } }

{ 'type': 'TPMInfo',
  'data': {'id': 'str', 'model': 'TpmModel', 'type': 'TpmType', 'type-options' 'TpmTypeOptions' } }
Stefan Berger - Feb. 11, 2013, 4:19 p.m.
On 02/11/2013 10:20 AM, Corey Bryant wrote:
>
> On 02/08/2013 09:55 PM, Stefan Berger wrote:
>> On 02/08/2013 05:01 PM, Eric Blake wrote:
>>> On 02/08/2013 02:42 PM, Stefan Berger wrote:
>>>> This patch adds support for TPM command line options.
>>>> The command line options supported here are
>>>>
>>>> ./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
>>>>              -device tpm-tis,tpmdev=<id>
>>>>
>>>> and
>>>>
>>>> ./qemu-... -tpmdev ?
>>> I though we preferred '-tpmdev help' instead of '-tpmdev ?' these days,
>>> as that doesn't need shell quoting.
>> Will fix it. I only used this syntax because the existing  '-soundhw ?'.
>>
>>>> where the latter works similar to -soundhw ? and shows a list of
>>>> available TPM backends (for example 'passthrough').
>>> What is the QMP counterpart command for listing all possible TPM
>>> backends?  Libvirt refuses to use command-line probing since qemu 1.3,
>>> so we need some way for libvirt to get at the same list from QMP without
>>> having to use '-tpmdev ?'.
>> Now added query-tpm-models and query-tpm-types listing the below shown
>> enumerations.
>>
>>>> +++ b/qapi-schema.json
>>>> @@ -3184,3 +3184,59 @@
>>>>    # Since: 1.4
>>>>    ##
>>>>    { 'command': 'chardev-remove', 'data': {'id': 'str'} }
>>>> +
>>>> +##
>>>> +# @TpmModel
>>>> +#
>>>> +# An enumeration of TPM models.
>>>> +#
>>>> +# @tpm-tis: TPM TIS model
>>>> +#
>>>> +# Since: 1.5
>>>> +##
>>>> +{ 'enum': 'TpmModel',
>>>> +  'data': [ 'tpm-tis' ] }
>>>> +
>>>> +##
>>>> +# @TpmType
>>>> +#
>>>> +# An enumeration of TPM types.
>>>> +#
>>>> +# @passthrough: TPM passthrough
>>>> +#
>>>> +# Since: 1.5
>>>> +##
>>>> +{ 'enum': 'TpmType',
>>>> +  'data': [ 'passthrough' ] }
>>>> +
>>>> +##
>>>> +# @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
>>>> +#
>>>> +# @path: #optional Path to the TPM backend device
>>>> +#
>>>> +# @cancel_path: #optional Path to TPM backend device's cancel sysfs entry
>>> Prefer '-' over '_' in QMP; this should be cancel-path.
>>>
>> Fine, I changed it and also changed it for the command line (6/7). I
>> looked around in this file and searched for '_' versus '-' and found
>> both, rolled the dice afterwards...
>>
>>>> +#
>>>> +# Since: 1.5
>>>> +##
>>>> +{ 'type': 'TPMInfo',
>>>> +  'data': {'model': 'TpmModel', 'id': 'str', 'type': 'TpmType', '*path': 'str',
>>>> +           '*cancel_path': 'str' } }
>>> Is this a case where the choice of which optional parameters are present
>>> depends on which model was in use?  That is, if we add a new model that
>>> uses a new field, would it be better to have a union type, something like:
>>>
>>> { 'type': 'TPMTis', 'data': {'path':'str', '*cancel-path':'str'} }
>>> { 'union': 'TPMBackend',
>>>     'data': { 'tpm-tis' : 'TPMTis',
>>>               'tpm-future': 'TPMFUture' } }
>>> { 'type': 'TPMInfo',
>>>     'data': { 'id': 'str', 'type': 'TpmType', 'model': 'TPMBackend' } }
>>>
>>> so that the user sees:
>>> { 'id': 'tpm0', 'type':'passthrough',
>>>     'model': { 'type':'tpm-tis', 'data':{'path':'/dev/tpm'} } }
>>>
>>> not necessarily better, just food for thought.
>>>
>> Above is not entirely reflecting the real world. What about the following?
>>
>> The backend:
>>
>> { 'type': 'TPMPassthrough', 'data': { 'type' : 'TpmType', 'path':'str', '*cancel-path':'str'} }
>>
>> { 'union': 'TPMBE',
>>     'data': { 'tpm-passthrough'   : 'TPMPassthrough',
>>               'tpm-future-backend': 'TPMFutureBackend' } }
>>
>>
>> The hardware device 'model' (frontend):
>>
>>
>> { 'type' : 'TPMTis', 'data' : { model : 'TpmModel' }
>>
>> { 'union': 'TPMFE',
>>     'data': { 'tpm-tis'         : 'TPMTis',
>>               'tpm-future-model': 'TPMFutureModel' } }
>>
>> { 'type' : 'TPMInfo'
>>     'data' : { 'id' : 'str', 'model' : 'TPMFE', 'type' : 'TPMBE' }
>>
>> The user should then see:
>>
>> { 'id': 'tpm0',
>>     'model' : { 'model' : 'tpm-tis'},
>>     'type'  : { 'type'  : 'passthrough', 'path' : '/dev/tpm0' , 'cancel-path' = '/dev/fdset/2' } }
>>
>>
>> Stefan
>>
> It might be cleaner if you use a hybrid of what you have here and what you already had before (plus you might be able to re-use some of these for query-tpm-models and query-tpm-types).  Maybe something like this?
>
> { 'enum': 'TpmModel',
>    'data': [ 'tpm-tis' ] }
>
> { 'enum': 'TpmType',
>    'data': [ 'passthrough' ] }
>
> { 'type': 'TPMPassthroughOptions', 'data': { '*path':'str', '*cancel-path':'str'} }
>
> { 'union': 'TpmTypeOptions',
>     'data': { 'tpm-passthrough-options'   : 'TPMPassthroughOptions',
>               'tpm-future-backend-options': 'TPMFutureBackendOptions' } }
>
> { 'type': 'TPMInfo',
>    'data': {'id': 'str', 'model': 'TpmModel', 'type': 'TpmType', 'type-options' 'TpmTypeOptions' } }
>

Yes, maybe that's better.

I tried it with the following:

{ 'type' : 'TPMPassthrough',
   'data' : { 'path' : 'str', '*cancel-path' : 'str' } }

{ 'union' : 'TpmType',
   'data' : { 'passthrough' : 'TPMPassthrough' } }

{ 'type' : 'TPMTis',
   'data' : { } }

{ 'union' : 'TpmModel',
   'data' : { 'tpm-tis' : 'TPMTis' } }

This is what I get now.

{ "execute" : "query-tpm"}
{"return": [{"model": {"type": "tpm-tis", "data": {}}, "type": {"type": 
"passthrough", "data": {"cancel-path": "/dev/fdset/2", "path": 
"/dev/fdset/1"}}, "id": "tpm0"}]}

There's not much to report on tpm-tis, so it shows 'data' : {}. Not 
necessarily nice, but I guess it would be ok and data could show 
something for other models.

{ "execute" : "query-tpm-types" }
{"return": [{"type": "passthrough", "data": {}}]}

Here I would not expect the "data" : {}, but this obviously comes from 
the 'union'.

Similarly here:

{ "execute" : "query-tpm-models" }
{"return": [{"type": "tpm-tis", "data": {}}]}


So I'll try your suggestion...

      Stefan
Corey Bryant - Feb. 11, 2013, 5:19 p.m.
On 02/08/2013 04:42 PM, Stefan Berger wrote:
> + * Implementation of the TIS interface according to specs found at
> + *http://www.trustedcomputiggroup.org

Were you going to make a comment somewhere that this front end is based 
on the v1.21 rev 1.0 TIS spec?
Stefan Berger - Feb. 11, 2013, 5:28 p.m.
On 02/11/2013 12:19 PM, Corey Bryant wrote:
>
>
> On 02/08/2013 04:42 PM, Stefan Berger wrote:
>> + * Implementation of the TIS interface according to specs found at
>> + *http://www.trustedcomputiggroup.org
>
> Were you going to make a comment somewhere that this front end is 
> based on the v1.21 rev 1.0 TIS spec?
>
Yes, it's in tpm_tis.c's header.

    Stefan
Corey Bryant - Feb. 11, 2013, 5:30 p.m.
On 02/11/2013 12:28 PM, Stefan Berger wrote:
> On 02/11/2013 12:19 PM, Corey Bryant wrote:
>>
>>
>> On 02/08/2013 04:42 PM, Stefan Berger wrote:
>>> + * Implementation of the TIS interface according to specs found at
>>> + *http://www.trustedcomputiggroup.org
>>
>> Were you going to make a comment somewhere that this front end is
>> based on the v1.21 rev 1.0 TIS spec?
>>
> Yes, it's in tpm_tis.c's header.
>
>     Stefan
>

Ah, my mistake.  I see it's in patch 2.

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 21e9c91..d52ea49 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -74,6 +74,7 @@  common-obj-y += bt-host.o bt-vhci.o
 common-obj-y += dma-helpers.o
 common-obj-y += qtest.o
 common-obj-y += vl.o
+common-obj-y += tpm/
 
 common-obj-$(CONFIG_SLIRP) += slirp/
 
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 64008a9..a952fd1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1642,6 +1642,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 420d48b..84fe6a4 100644
--- a/hmp.c
+++ b/hmp.c
@@ -607,6 +607,37 @@  void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
     }
 }
 
+void hmp_info_tpm(Monitor *mon, const QDict *qdict)
+{
+    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;
+    }
+
+    if (info_list)
+        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, TpmModel_lookup[ti->model]);
+        monitor_printf(mon, "  \\ %s: type=%s%s%s%s%s\n",
+                       ti->id, TpmType_lookup[ti->type],
+                       ti->has_path ? ",path=" : "",
+                       ti->has_path ? ti->path : "",
+                       ti->has_cancel_path ? ",cancel_path=" : "",
+                       ti->has_cancel_path ? ti->cancel_path : "");
+        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 30b3c20..95fe76e 100644
--- a/hmp.h
+++ b/hmp.h
@@ -36,6 +36,7 @@  void hmp_info_spice(Monitor *mon, const QDict *qdict);
 void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
+void hmp_info_tpm(Monitor *mon, const QDict *qdict);
 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/include/tpm/tpm.h b/include/tpm/tpm.h
new file mode 100644
index 0000000..cc8f20e
--- /dev/null
+++ b/include/tpm/tpm.h
@@ -0,0 +1,21 @@ 
+/*
+ * Public TPM functions
+ *
+ * Copyright (C) 2011-2013 IBM Corporation
+ *
+ * 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.
+ */
+#ifndef QEMU_TPM_H
+#define QEMU_TPM_H
+
+#include "qemu/option.h"
+
+int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
+int tpm_init(void);
+void tpm_cleanup(void);
+
+#endif /* QEMU_TPM_H */
diff --git a/monitor.c b/monitor.c
index 20bd19b..71fbdda 100644
--- a/monitor.c
+++ b/monitor.c
@@ -47,6 +47,7 @@ 
 #include "migration/migration.h"
 #include "sysemu/kvm.h"
 #include "qemu/acl.h"
+#include "tpm/tpm.h"
 #include "qapi/qmp/qint.h"
 #include "qapi/qmp/qfloat.h"
 #include "qapi/qmp/qlist.h"
@@ -2722,6 +2723,13 @@  static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = do_trace_print_events,
     },
     {
+        .name       = "tpm",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the TPM device",
+        .mhandler.cmd = hmp_info_tpm,
+    },
+    {
         .name       = NULL,
     },
 };
diff --git a/qapi-schema.json b/qapi-schema.json
index 736f881..b1a5d96 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3184,3 +3184,59 @@ 
 # Since: 1.4
 ##
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
+
+##
+# @TpmModel
+#
+# An enumeration of TPM models.
+#
+# @tpm-tis: TPM TIS model
+#
+# Since: 1.5
+##
+{ 'enum': 'TpmModel',
+  'data': [ 'tpm-tis' ] }
+
+##
+# @TpmType
+#
+# An enumeration of TPM types.
+#
+# @passthrough: TPM passthrough
+#
+# Since: 1.5
+##
+{ 'enum': 'TpmType',
+  'data': [ 'passthrough' ] }
+
+##
+# @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
+#
+# @path: #optional Path to the TPM backend device
+#
+# @cancel_path: #optional Path to TPM backend device's cancel sysfs entry
+#
+# Since: 1.5
+##
+{ 'type': 'TPMInfo',
+  'data': {'model': 'TpmModel', 'id': 'str', 'type': 'TpmType', '*path': 'str',
+           '*cancel_path': 'str' } }
+
+##
+# @query-tpm
+#
+# Return information about the TPM device.
+#
+# Returns: @TPMInfo on success
+#
+# Since: 1.5
+##
+{ 'command': 'query-tpm', 'returns': ['TPMInfo'] }
diff --git a/qemu-options.hx b/qemu-options.hx
index 046bdc0..a5cb56a 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2188,6 +2188,39 @@  ETEXI
 
 DEFHEADING()
 
+#ifdef CONFIG_TPM
+DEFHEADING(TPM device options:)
+
+DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \
+    "-tpmdev [<type>],id=str[,option][,option][,...]\n",
+    QEMU_ARCH_ALL)
+STEXI
+
+The general form of a TPM device option is:
+@table @option
+
+@item -tpmdev @var{backend} ,id=@var{id} [,@var{options}]
+@findex -tpmdev
+Backend type must be:
+
+The specific backend type will determine the applicable options.
+The @code{-tpmdev} options requires a @code{-device} option.
+
+Options to each backend are described below.
+
+Use ? to print all available TPM backend types.
+@example
+qemu -tpmdev ?
+@end example
+
+@end table
+
+ETEXI
+
+DEFHEADING()
+
+#endif
+
 DEFHEADING(Linux/Multiboot boot specific:)
 STEXI
 
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 799adea..e2e3e2b 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2716,6 +2716,12 @@  EQMP
     },
 
     {
+        .name       = "query-tpm",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_tpm,
+    },
+
+    {
         .name       = "chardev-add",
         .args_type  = "id:s,backend:q",
         .mhandler.cmd_new = qmp_marshal_input_chardev_add,
diff --git a/tpm/Makefile.objs b/tpm/Makefile.objs
new file mode 100644
index 0000000..dffb567
--- /dev/null
+++ b/tpm/Makefile.objs
@@ -0,0 +1 @@ 
+common-obj-y = tpm.o
diff --git a/tpm/tpm.c b/tpm/tpm.c
new file mode 100644
index 0000000..5ca2104
--- /dev/null
+++ b/tpm/tpm.c
@@ -0,0 +1,218 @@ 
+/*
+ * TPM configuration
+ *
+ * Copyright (C) 2011-2013 IBM Corporation
+ *
+ * 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.
+ *
+ * Based on net.c
+ */
+#include "config-host.h"
+
+#include "monitor/monitor.h"
+#include "qapi/qmp/qerror.h"
+#include "tpm_int.h"
+#include "tpm/tpm.h"
+#include "qemu/config-file.h"
+#include "qmp-commands.h"
+
+static QLIST_HEAD(, TPMBackend) tpm_backends =
+    QLIST_HEAD_INITIALIZER(tpm_backends);
+
+#ifdef CONFIG_TPM
+
+static const TPMDriverOps *be_drivers[] = {
+    NULL,
+};
+
+const TPMDriverOps *tpm_get_backend_driver(const char *type)
+{
+    int i;
+
+    for (i = 0; be_drivers[i] != NULL; i++) {
+        if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) {
+            break;
+        }
+    }
+
+    return be_drivers[i];
+}
+
+/*
+ * Walk the list of available TPM backend drivers and display them on the
+ * screen.
+ */
+void tpm_display_backend_drivers(void)
+{
+    int i;
+
+    fprintf(stderr, "Supported TPM types (choose only one):\n");
+
+    for (i = 0; be_drivers[i] != NULL; i++) {
+        fprintf(stderr, "%12s   %s\n",
+                TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc());
+    }
+    fprintf(stderr, "\n");
+}
+
+/*
+ * Find the TPM with the given Id
+ */
+TPMBackend *qemu_find_tpm(const char *id)
+{
+    TPMBackend *drv;
+
+    QLIST_FOREACH(drv, &tpm_backends, list) {
+        if (!strcmp(drv->id, id)) {
+            return drv;
+        }
+    }
+
+    return NULL;
+}
+
+static int configure_tpm(QemuOpts *opts)
+{
+    const char *value;
+    const char *id;
+    const TPMDriverOps *be;
+    TPMBackend *drv;
+
+    if (!QLIST_EMPTY(&tpm_backends)) {
+        error_report("Only one TPM is allowed.\n");
+        return 1;
+    }
+
+    id = qemu_opts_id(opts);
+    if (id == NULL) {
+        qerror_report(QERR_MISSING_PARAMETER, "id");
+        return 1;
+    }
+
+    value = qemu_opt_get(opts, "type");
+    if (!value) {
+        qerror_report(QERR_MISSING_PARAMETER, "type");
+        tpm_display_backend_drivers();
+        return 1;
+    }
+
+    be = tpm_get_backend_driver(value);
+    if (be == NULL) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
+                      "a TPM backend type");
+        tpm_display_backend_drivers();
+        return 1;
+    }
+
+    drv = be->create(opts, id);
+    if (!drv) {
+        return 1;
+    }
+
+    QLIST_INSERT_HEAD(&tpm_backends, drv, list);
+
+    return 0;
+}
+
+static int tpm_init_tpmdev(QemuOpts *opts, void *dummy)
+{
+    return configure_tpm(opts);
+}
+
+/*
+ * Walk the list of TPM backend drivers that are in use and call their
+ * destroy function to have them cleaned up.
+ */
+void tpm_cleanup(void)
+{
+    TPMBackend *drv, *next;
+
+    QLIST_FOREACH_SAFE(drv, &tpm_backends, list, next) {
+        QLIST_REMOVE(drv, list);
+        drv->ops->destroy(drv);
+    }
+}
+
+/*
+ * Initialize the TPM. Process the tpmdev command line options describing the
+ * TPM backend.
+ */
+int tpm_init(void)
+{
+    if (qemu_opts_foreach(qemu_find_opts("tpmdev"),
+                          tpm_init_tpmdev, NULL, 1) != 0) {
+        return -1;
+    }
+
+    atexit(tpm_cleanup);
+
+    return 0;
+}
+
+/*
+ * Parse the TPM configuration options.
+ * To display all available TPM backends the user may use '-tpmdev ?'
+ */
+int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
+{
+    QemuOpts *opts;
+
+    if (*optarg == '?') {
+        tpm_display_backend_drivers();
+        return -1;
+    }
+    opts = qemu_opts_parse(opts_list, optarg, 1);
+    if (!opts) {
+        return -1;
+    }
+    return 0;
+}
+
+#endif /* CONFIG_TPM */
+
+static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)
+{
+    TPMInfo *res = g_new0(TPMInfo, 1);
+
+    res->model = drv->fe_model;
+    res->id = g_strdup(drv->id);
+    if (drv->path) {
+        res->path = g_strdup(drv->path);
+        res->has_path = true;
+    }
+    if (drv->cancel_path) {
+        res->cancel_path = g_strdup(drv->cancel_path);
+        res->has_cancel_path = true;
+    }
+    res->type = drv->ops->type;
+
+    return res;
+}
+
+/*
+ * Walk the list of active TPM backends and collect information about them
+ * following the schema description in qapi-schema.json.
+ */
+TPMInfoList *qmp_query_tpm(Error **errp)
+{
+    TPMBackend *drv;
+    TPMInfoList *info, *head = NULL, *cur_item = NULL;
+
+    QLIST_FOREACH(drv, &tpm_backends, list) {
+        info = g_new0(TPMInfoList, 1);
+        info->value = qmp_query_tpm_inst(drv);
+
+        if (!cur_item) {
+            head = cur_item = info;
+        } else {
+            cur_item->next = info;
+            cur_item = info;
+        }
+    }
+
+    return head;
+}
diff --git a/tpm/tpm_int.h b/tpm/tpm_int.h
new file mode 100644
index 0000000..6781a97
--- /dev/null
+++ b/tpm/tpm_int.h
@@ -0,0 +1,79 @@ 
+/*
+ * TPM configuration
+ *
+ * Copyright (C) 2011-2013 IBM Corporation
+ *
+ * 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.
+ */
+#ifndef TPM_TPM_INT_H
+#define TPM_TPM_INT_H
+
+#include "exec/memory.h"
+#include "tpm/tpm_tis.h"
+
+struct TPMDriverOps;
+typedef struct TPMDriverOps TPMDriverOps;
+
+typedef struct TPMBackend {
+    char *id;
+    enum TpmModel fe_model;
+    char *path;
+    char *cancel_path;
+    const TPMDriverOps *ops;
+
+    QLIST_ENTRY(TPMBackend) list;
+} TPMBackend;
+
+/* overall state of the TPM interface */
+typedef struct TPMState {
+    ISADevice busdev;
+    MemoryRegion mmio;
+
+    union {
+        TPMTISEmuState tis;
+    } s;
+
+    uint8_t     locty_number;
+    TPMLocality *locty_data;
+
+    char *backend;
+    TPMBackend *be_driver;
+} TPMState;
+
+typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty);
+
+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);
+};
+
+TPMBackend *qemu_find_tpm(const char *id);
+void tpm_display_backend_drivers(void);
+const TPMDriverOps *tpm_get_backend_driver(const char *type);
+
+#endif /* TPM_TPM_INT_H */
diff --git a/tpm/tpm_tis.h b/tpm/tpm_tis.h
new file mode 100644
index 0000000..6cf18bc
--- /dev/null
+++ b/tpm/tpm_tis.h
@@ -0,0 +1,78 @@ 
+/*
+ * tpm_tis.h - QEMU's TPM TIS interface emulator
+ *
+ * Copyright (C) 2006, 2010-2013 IBM Corporation
+ *
+ * Authors:
+ *  Stefan Berger <stefanb@us.ibm.com>
+ *  David Safford <safford@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.
+ *
+ * Implementation of the TIS interface according to specs found at
+ * http://www.trustedcomputiggroup.org
+ *
+ */
+#ifndef TPM_TPM_TIS_H
+#define TPM_TPM_TIS_H
+
+#include "hw/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_STATE_IDLE = 0,
+    TPM_TIS_STATE_READY,
+    TPM_TIS_STATE_COMPLETION,
+    TPM_TIS_STATE_EXECUTION,
+    TPM_TIS_STATE_RECEPTION,
+} TPMTISState;
+
+/* locality data  -- all fields are persisted */
+typedef struct TPMLocality {
+    TPMTISState state;
+    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 TPMTISEmuState {
+    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;
+} TPMTISEmuState;
+
+#endif /* TPM_TPM_TIS_H */
diff --git a/vl.c b/vl.c
index a8dc73d..b4e5239 100644
--- a/vl.c
+++ b/vl.c
@@ -139,6 +139,7 @@  int main(int argc, char **argv)
 #include "sysemu/blockdev.h"
 #include "hw/block-common.h"
 #include "migration/block.h"
+#include "tpm/tpm.h"
 #include "sysemu/dma.h"
 #include "audio/audio.h"
 #include "migration/migration.h"
@@ -491,6 +492,25 @@  static QemuOptsList qemu_object_opts = {
     },
 };
 
+static QemuOptsList qemu_tpmdev_opts = {
+    .name = "tpmdev",
+    .implied_opt_name = "type",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
+    .desc = {
+        {
+            .name = "type",
+            .type = QEMU_OPT_STRING,
+            .help = "Type of TPM backend",
+        },
+        {
+            .name = "path",
+            .type = QEMU_OPT_STRING,
+            .help = "Path to TPM device on the host",
+        },
+        { /* end of list */ }
+    },
+};
+
 const char *qemu_get_vm_name(void)
 {
     return qemu_name;
@@ -2860,6 +2880,7 @@  int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_sandbox_opts);
     qemu_add_opts(&qemu_add_fd_opts);
     qemu_add_opts(&qemu_object_opts);
+    qemu_add_opts(&qemu_tpmdev_opts);
 
     runstate_init();
 
@@ -3221,6 +3242,13 @@  int main(int argc, char **argv, char **envp)
                 }
                 break;
             }
+#ifdef CONFIG_TPM
+            case QEMU_OPTION_tpmdev:
+                if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
+                    exit(1);
+                }
+                break;
+#endif
             case QEMU_OPTION_mempath:
                 mem_path = optarg;
                 break;
@@ -4069,6 +4097,12 @@  int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+#ifdef CONFIG_TPM
+    if (tpm_init() < 0) {
+        exit(1);
+    }
+#endif
+
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -4323,6 +4357,9 @@  int main(int argc, char **argv, char **envp)
     bdrv_close_all();
     pause_all_vcpus();
     res_free();
+#ifdef CONFIG_TPM
+    tpm_cleanup();
+#endif
 
     return 0;
 }