]> git.proxmox.com Git - mirror_qemu.git/blob - hw/tpm/tpm_tis_isa.c
Use DECLARE_*CHECKER* macros
[mirror_qemu.git] / hw / tpm / tpm_tis_isa.c
1 /*
2 * tpm_tis_isa.c - QEMU's TPM TIS ISA Device
3 *
4 * Copyright (C) 2006,2010-2013 IBM Corporation
5 *
6 * Authors:
7 * Stefan Berger <stefanb@us.ibm.com>
8 * David Safford <safford@us.ibm.com>
9 *
10 * Xen 4 support: Andrease Niederl <andreas.niederl@iaik.tugraz.at>
11 *
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.
14 *
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
19 * specification.
20 *
21 * TPM TIS for TPM 2 implementation following TCG PC Client Platform
22 * TPM Profile (PTP) Specification, Familiy 2.0, Revision 00.43
23 */
24
25 #include "qemu/osdep.h"
26 #include "hw/isa/isa.h"
27 #include "hw/qdev-properties.h"
28 #include "migration/vmstate.h"
29 #include "hw/acpi/tpm.h"
30 #include "tpm_prop.h"
31 #include "tpm_tis.h"
32 #include "qom/object.h"
33
34 struct TPMStateISA {
35 /*< private >*/
36 ISADevice parent_obj;
37
38 /*< public >*/
39 TPMState state; /* not a QOM object */
40 };
41 typedef struct TPMStateISA TPMStateISA;
42
43 DECLARE_INSTANCE_CHECKER(TPMStateISA, TPM_TIS_ISA,
44 TYPE_TPM_TIS_ISA)
45
46 static int tpm_tis_pre_save_isa(void *opaque)
47 {
48 TPMStateISA *isadev = opaque;
49
50 return tpm_tis_pre_save(&isadev->state);
51 }
52
53 static const VMStateDescription vmstate_tpm_tis_isa = {
54 .name = "tpm-tis",
55 .version_id = 0,
56 .pre_save = tpm_tis_pre_save_isa,
57 .fields = (VMStateField[]) {
58 VMSTATE_BUFFER(state.buffer, TPMStateISA),
59 VMSTATE_UINT16(state.rw_offset, TPMStateISA),
60 VMSTATE_UINT8(state.active_locty, TPMStateISA),
61 VMSTATE_UINT8(state.aborting_locty, TPMStateISA),
62 VMSTATE_UINT8(state.next_locty, TPMStateISA),
63
64 VMSTATE_STRUCT_ARRAY(state.loc, TPMStateISA, TPM_TIS_NUM_LOCALITIES, 0,
65 vmstate_locty, TPMLocality),
66
67 VMSTATE_END_OF_LIST()
68 }
69 };
70
71 static void tpm_tis_isa_request_completed(TPMIf *ti, int ret)
72 {
73 TPMStateISA *isadev = TPM_TIS_ISA(ti);
74 TPMState *s = &isadev->state;
75
76 tpm_tis_request_completed(s, ret);
77 }
78
79 static enum TPMVersion tpm_tis_isa_get_tpm_version(TPMIf *ti)
80 {
81 TPMStateISA *isadev = TPM_TIS_ISA(ti);
82 TPMState *s = &isadev->state;
83
84 return tpm_tis_get_tpm_version(s);
85 }
86
87 static void tpm_tis_isa_reset(DeviceState *dev)
88 {
89 TPMStateISA *isadev = TPM_TIS_ISA(dev);
90 TPMState *s = &isadev->state;
91
92 return tpm_tis_reset(s);
93 }
94
95 static Property tpm_tis_isa_properties[] = {
96 DEFINE_PROP_UINT32("irq", TPMStateISA, state.irq_num, TPM_TIS_IRQ),
97 DEFINE_PROP_TPMBE("tpmdev", TPMStateISA, state.be_driver),
98 DEFINE_PROP_BOOL("ppi", TPMStateISA, state.ppi_enabled, true),
99 DEFINE_PROP_END_OF_LIST(),
100 };
101
102 static void tpm_tis_isa_initfn(Object *obj)
103 {
104 TPMStateISA *isadev = TPM_TIS_ISA(obj);
105 TPMState *s = &isadev->state;
106
107 memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops,
108 s, "tpm-tis-mmio",
109 TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT);
110 }
111
112 static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp)
113 {
114 TPMStateISA *isadev = TPM_TIS_ISA(dev);
115 TPMState *s = &isadev->state;
116
117 if (!tpm_find()) {
118 error_setg(errp, "at most one TPM device is permitted");
119 return;
120 }
121
122 if (!s->be_driver) {
123 error_setg(errp, "'tpmdev' property is required");
124 return;
125 }
126 if (s->irq_num > 15) {
127 error_setg(errp, "IRQ %d is outside valid range of 0 to 15",
128 s->irq_num);
129 return;
130 }
131
132 isa_init_irq(ISA_DEVICE(dev), &s->irq, s->irq_num);
133
134 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)),
135 TPM_TIS_ADDR_BASE, &s->mmio);
136
137 if (s->ppi_enabled) {
138 tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)),
139 TPM_PPI_ADDR_BASE, OBJECT(dev));
140 }
141 }
142
143 static void tpm_tis_isa_class_init(ObjectClass *klass, void *data)
144 {
145 DeviceClass *dc = DEVICE_CLASS(klass);
146 TPMIfClass *tc = TPM_IF_CLASS(klass);
147
148 device_class_set_props(dc, tpm_tis_isa_properties);
149 dc->vmsd = &vmstate_tpm_tis_isa;
150 tc->model = TPM_MODEL_TPM_TIS;
151 dc->realize = tpm_tis_isa_realizefn;
152 dc->reset = tpm_tis_isa_reset;
153 tc->request_completed = tpm_tis_isa_request_completed;
154 tc->get_version = tpm_tis_isa_get_tpm_version;
155 }
156
157 static const TypeInfo tpm_tis_isa_info = {
158 .name = TYPE_TPM_TIS_ISA,
159 .parent = TYPE_ISA_DEVICE,
160 .instance_size = sizeof(TPMStateISA),
161 .instance_init = tpm_tis_isa_initfn,
162 .class_init = tpm_tis_isa_class_init,
163 .interfaces = (InterfaceInfo[]) {
164 { TYPE_TPM_IF },
165 { }
166 }
167 };
168
169 static void tpm_tis_isa_register(void)
170 {
171 type_register_static(&tpm_tis_isa_info);
172 }
173
174 type_init(tpm_tis_isa_register)