2
0

tpm-hmp-cmds.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "qemu/osdep.h"
  8. #include "qapi/qapi-commands-tpm.h"
  9. #include "monitor/monitor.h"
  10. #include "monitor/hmp.h"
  11. #include "qapi/error.h"
  12. void hmp_info_tpm(Monitor *mon, const QDict *qdict)
  13. {
  14. #ifdef CONFIG_TPM
  15. TPMInfoList *info_list, *info;
  16. Error *err = NULL;
  17. unsigned int c = 0;
  18. TPMPassthroughOptions *tpo;
  19. TPMEmulatorOptions *teo;
  20. info_list = qmp_query_tpm(&err);
  21. if (err) {
  22. monitor_printf(mon, "TPM device not supported\n");
  23. error_free(err);
  24. return;
  25. }
  26. if (info_list) {
  27. monitor_printf(mon, "TPM device:\n");
  28. }
  29. for (info = info_list; info; info = info->next) {
  30. TPMInfo *ti = info->value;
  31. monitor_printf(mon, " tpm%d: model=%s\n",
  32. c, TpmModel_str(ti->model));
  33. monitor_printf(mon, " \\ %s: type=%s",
  34. ti->id, TpmType_str(ti->options->type));
  35. switch (ti->options->type) {
  36. case TPM_TYPE_PASSTHROUGH:
  37. tpo = ti->options->u.passthrough.data;
  38. monitor_printf(mon, "%s%s%s%s",
  39. tpo->path ? ",path=" : "",
  40. tpo->path ?: "",
  41. tpo->cancel_path ? ",cancel-path=" : "",
  42. tpo->cancel_path ?: "");
  43. break;
  44. case TPM_TYPE_EMULATOR:
  45. teo = ti->options->u.emulator.data;
  46. monitor_printf(mon, ",chardev=%s", teo->chardev);
  47. break;
  48. case TPM_TYPE__MAX:
  49. break;
  50. }
  51. monitor_printf(mon, "\n");
  52. c++;
  53. }
  54. qapi_free_TPMInfoList(info_list);
  55. #else
  56. monitor_printf(mon, "TPM device not supported\n");
  57. #endif /* CONFIG_TPM */
  58. }