1#
2# Copyright 2011, 2013 Red Hat, Inc.
3# Copyright 2013 IBM Corporation
4#
5# This work is licensed under the GNU GPLv2 or later.
6# See the COPYING file in the top-level directory.
7
8from .device import Device
9from ..xmlbuilder import XMLProperty
10
11
12class DeviceTpm(Device):
13    XML_NAME = "tpm"
14
15    VERSION_1_2 = "1.2"
16    VERSION_2_0 = "2.0"
17    VERSIONS = [VERSION_1_2, VERSION_2_0]
18
19    TYPE_PASSTHROUGH = "passthrough"
20    TYPE_EMULATOR = "emulator"
21    TYPES = [TYPE_PASSTHROUGH, TYPE_EMULATOR]
22
23    MODEL_TIS = "tpm-tis"
24    MODEL_CRB = "tpm-crb"
25    MODEL_SPAPR = "tpm-spapr"
26    MODELS = [MODEL_TIS, MODEL_CRB, MODEL_SPAPR]
27
28    type = XMLProperty("./backend/@type")
29    version = XMLProperty("./backend/@version")
30    model = XMLProperty("./@model")
31    device_path = XMLProperty("./backend/device/@path")
32    encryption_secret = XMLProperty("./backend/encryption/@secret")
33
34
35    ##################
36    # Default config #
37    ##################
38
39    def set_defaults(self, guest):
40        if not self.type:
41            self.type = self.TYPE_PASSTHROUGH
42        if not self.model:
43            self.model = self.MODEL_TIS
44
45            if guest.os.is_ppc64():
46                self.model = self.MODEL_SPAPR
47