2 * tpm_tis_isa.c - QEMU's TPM TIS ISA Device
4 * Copyright (C) 2006,2010-2013 IBM Corporation
7 * Stefan Berger <stefanb@us.ibm.com>
8 * David Safford <safford@us.ibm.com>
10 * Xen 4 support: Andrease Niederl <andreas.niederl@iaik.tugraz.at>
12 * This work is licensed under the terms of the GNU GPL, version 2 or later.
13 * See the COPYING file in the top-level directory.
15 * Implementation of the TIS interface according to specs found at
16 * http://www.trustedcomputinggroup.org. This implementation currently
17 * supports version 1.3, 21 March 2013
18 * In the developers menu choose the PC Client section then find the TIS
21 * TPM TIS for TPM 2 implementation following TCG PC Client Platform
22 * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43
25 #include "qemu/osdep.h"
26 #include "hw/isa/isa.h"
27 #include "hw/qdev-properties.h"
28 #include "migration/vmstate.h"
32 typedef struct TPMStateISA
{
37 TPMState state
; /* not a QOM object */
40 #define TPM_TIS_ISA(obj) OBJECT_CHECK(TPMStateISA, (obj), TYPE_TPM_TIS_ISA)
42 static int tpm_tis_pre_save_isa(void *opaque
)
44 TPMStateISA
*isadev
= opaque
;
46 return tpm_tis_pre_save(&isadev
->state
);
49 static const VMStateDescription vmstate_tpm_tis_isa
= {
52 .pre_save
= tpm_tis_pre_save_isa
,
53 .fields
= (VMStateField
[]) {
54 VMSTATE_BUFFER(state
.buffer
, TPMStateISA
),
55 VMSTATE_UINT16(state
.rw_offset
, TPMStateISA
),
56 VMSTATE_UINT8(state
.active_locty
, TPMStateISA
),
57 VMSTATE_UINT8(state
.aborting_locty
, TPMStateISA
),
58 VMSTATE_UINT8(state
.next_locty
, TPMStateISA
),
60 VMSTATE_STRUCT_ARRAY(state
.loc
, TPMStateISA
, TPM_TIS_NUM_LOCALITIES
, 0,
61 vmstate_locty
, TPMLocality
),
67 static void tpm_tis_isa_request_completed(TPMIf
*ti
, int ret
)
69 TPMStateISA
*isadev
= TPM_TIS_ISA(ti
);
70 TPMState
*s
= &isadev
->state
;
72 tpm_tis_request_completed(s
, ret
);
75 static enum TPMVersion
tpm_tis_isa_get_tpm_version(TPMIf
*ti
)
77 TPMStateISA
*isadev
= TPM_TIS_ISA(ti
);
78 TPMState
*s
= &isadev
->state
;
80 return tpm_tis_get_tpm_version(s
);
83 static void tpm_tis_isa_reset(DeviceState
*dev
)
85 TPMStateISA
*isadev
= TPM_TIS_ISA(dev
);
86 TPMState
*s
= &isadev
->state
;
88 return tpm_tis_reset(s
);
91 static Property tpm_tis_isa_properties
[] = {
92 DEFINE_PROP_UINT32("irq", TPMStateISA
, state
.irq_num
, TPM_TIS_IRQ
),
93 DEFINE_PROP_TPMBE("tpmdev", TPMStateISA
, state
.be_driver
),
94 DEFINE_PROP_BOOL("ppi", TPMStateISA
, state
.ppi_enabled
, true),
95 DEFINE_PROP_END_OF_LIST(),
98 static void tpm_tis_isa_initfn(Object
*obj
)
100 TPMStateISA
*isadev
= TPM_TIS_ISA(obj
);
101 TPMState
*s
= &isadev
->state
;
103 memory_region_init_io(&s
->mmio
, obj
, &tpm_tis_memory_ops
,
105 TPM_TIS_NUM_LOCALITIES
<< TPM_TIS_LOCALITY_SHIFT
);
108 static void tpm_tis_isa_realizefn(DeviceState
*dev
, Error
**errp
)
110 TPMStateISA
*isadev
= TPM_TIS_ISA(dev
);
111 TPMState
*s
= &isadev
->state
;
114 error_setg(errp
, "at most one TPM device is permitted");
119 error_setg(errp
, "'tpmdev' property is required");
122 if (s
->irq_num
> 15) {
123 error_setg(errp
, "IRQ %d is outside valid range of 0 to 15",
128 isa_init_irq(ISA_DEVICE(dev
), &s
->irq
, s
->irq_num
);
130 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev
)),
131 TPM_TIS_ADDR_BASE
, &s
->mmio
);
133 if (s
->ppi_enabled
) {
134 tpm_ppi_init(&s
->ppi
, isa_address_space(ISA_DEVICE(dev
)),
135 TPM_PPI_ADDR_BASE
, OBJECT(dev
));
139 static void tpm_tis_isa_class_init(ObjectClass
*klass
, void *data
)
141 DeviceClass
*dc
= DEVICE_CLASS(klass
);
142 TPMIfClass
*tc
= TPM_IF_CLASS(klass
);
144 device_class_set_props(dc
, tpm_tis_isa_properties
);
145 dc
->vmsd
= &vmstate_tpm_tis_isa
;
146 tc
->model
= TPM_MODEL_TPM_TIS
;
147 dc
->realize
= tpm_tis_isa_realizefn
;
148 dc
->reset
= tpm_tis_isa_reset
;
149 tc
->request_completed
= tpm_tis_isa_request_completed
;
150 tc
->get_version
= tpm_tis_isa_get_tpm_version
;
153 static const TypeInfo tpm_tis_isa_info
= {
154 .name
= TYPE_TPM_TIS_ISA
,
155 .parent
= TYPE_ISA_DEVICE
,
156 .instance_size
= sizeof(TPMStateISA
),
157 .instance_init
= tpm_tis_isa_initfn
,
158 .class_init
= tpm_tis_isa_class_init
,
159 .interfaces
= (InterfaceInfo
[]) {
165 static void tpm_tis_isa_register(void)
167 type_register_static(&tpm_tis_isa_info
);
170 type_init(tpm_tis_isa_register
)