xref: /openbmc/qemu/system/tpm-hmp-cmds.c (revision 4921d0a7)
1 /*
2  * HMP commands related to TPM
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or
5  * (at your option) any later version.
6  */
7 
8 #include "qemu/osdep.h"
9 #include "qapi/qapi-commands-tpm.h"
10 #include "monitor/monitor.h"
11 #include "monitor/hmp.h"
12 #include "qapi/error.h"
13 
14 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
15 {
16 #ifdef CONFIG_TPM
17     TPMInfoList *info_list, *info;
18     Error *err = NULL;
19     unsigned int c = 0;
20     TPMPassthroughOptions *tpo;
21     TPMEmulatorOptions *teo;
22 
23     info_list = qmp_query_tpm(&err);
24     if (err) {
25         monitor_printf(mon, "TPM device not supported\n");
26         error_free(err);
27         return;
28     }
29 
30     if (info_list) {
31         monitor_printf(mon, "TPM device:\n");
32     }
33 
34     for (info = info_list; info; info = info->next) {
35         TPMInfo *ti = info->value;
36         monitor_printf(mon, " tpm%d: model=%s\n",
37                        c, TpmModel_str(ti->model));
38 
39         monitor_printf(mon, "  \\ %s: type=%s",
40                        ti->id, TpmType_str(ti->options->type));
41 
42         switch (ti->options->type) {
43         case TPM_TYPE_PASSTHROUGH:
44             tpo = ti->options->u.passthrough.data;
45             monitor_printf(mon, "%s%s%s%s",
46                            tpo->path ? ",path=" : "",
47                            tpo->path ?: "",
48                            tpo->cancel_path ? ",cancel-path=" : "",
49                            tpo->cancel_path ?: "");
50             break;
51         case TPM_TYPE_EMULATOR:
52             teo = ti->options->u.emulator.data;
53             monitor_printf(mon, ",chardev=%s", teo->chardev);
54             break;
55         case TPM_TYPE__MAX:
56             break;
57         }
58         monitor_printf(mon, "\n");
59         c++;
60     }
61     qapi_free_TPMInfoList(info_list);
62 #else
63     monitor_printf(mon, "TPM device not supported\n");
64 #endif /* CONFIG_TPM */
65 }
66