psp-dev.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AMD Platform Security Processor (PSP) interface driver
  4. *
  5. * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
  6. *
  7. * Author: Brijesh Singh <brijesh.singh@amd.com>
  8. */
  9. #ifndef __PSP_DEV_H__
  10. #define __PSP_DEV_H__
  11. #include <linux/device.h>
  12. #include <linux/list.h>
  13. #include <linux/bits.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/mutex.h>
  16. #include <linux/psp.h>
  17. #include <linux/psp-platform-access.h>
  18. #include "sp-dev.h"
  19. #define MAX_PSP_NAME_LEN 16
  20. extern struct psp_device *psp_master;
  21. typedef void (*psp_irq_handler_t)(int, void *, unsigned int);
  22. union psp_cap_register {
  23. unsigned int raw;
  24. struct {
  25. unsigned int sev :1,
  26. tee :1,
  27. dbc_thru_ext :1,
  28. sfs :1,
  29. rsvd1 :3,
  30. security_reporting :1,
  31. fused_part :1,
  32. boot_integrity :1,
  33. debug_lock_on :1,
  34. rsvd3 :2,
  35. tsme_status :1,
  36. rsvd4 :1,
  37. anti_rollback_status :1,
  38. rpmc_production_enabled :1,
  39. rpmc_spirom_available :1,
  40. hsp_tpm_available :1,
  41. rom_armor_enforced :1,
  42. rsvd5 :12;
  43. };
  44. };
  45. struct psp_device {
  46. struct list_head entry;
  47. struct psp_vdata *vdata;
  48. char name[MAX_PSP_NAME_LEN];
  49. struct device *dev;
  50. struct sp_device *sp;
  51. void __iomem *io_regs;
  52. struct mutex mailbox_mutex;
  53. psp_irq_handler_t sev_irq_handler;
  54. void *sev_irq_data;
  55. void *sev_data;
  56. void *tee_data;
  57. void *platform_access_data;
  58. void *dbc_data;
  59. void *sfs_data;
  60. union psp_cap_register capability;
  61. };
  62. void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
  63. void *data);
  64. void psp_clear_sev_irq_handler(struct psp_device *psp);
  65. struct psp_device *psp_get_master_device(void);
  66. /**
  67. * enum psp_cmd - PSP mailbox commands
  68. * @PSP_CMD_TEE_RING_INIT: Initialize TEE ring buffer
  69. * @PSP_CMD_TEE_RING_DESTROY: Destroy TEE ring buffer
  70. * @PSP_CMD_TEE_EXTENDED_CMD: Extended command
  71. * @PSP_CMD_MAX: Maximum command id
  72. */
  73. enum psp_cmd {
  74. PSP_CMD_TEE_RING_INIT = 1,
  75. PSP_CMD_TEE_RING_DESTROY = 2,
  76. PSP_CMD_TEE_EXTENDED_CMD = 14,
  77. PSP_CMD_MAX = 15,
  78. };
  79. int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff,
  80. unsigned int timeout_msecs, unsigned int *cmdresp);
  81. /**
  82. * struct psp_ext_req_buffer_hdr - Structure of the extended command header
  83. * @payload_size: total payload size
  84. * @sub_cmd_id: extended command ID
  85. * @status: status of command execution (out)
  86. */
  87. struct psp_ext_req_buffer_hdr {
  88. u32 payload_size;
  89. u32 sub_cmd_id;
  90. u32 status;
  91. } __packed;
  92. struct psp_ext_request {
  93. struct psp_ext_req_buffer_hdr header;
  94. void *buf;
  95. } __packed;
  96. /**
  97. * enum psp_sub_cmd - PSP mailbox sub commands
  98. * @PSP_SUB_CMD_DBC_GET_NONCE: Get nonce from DBC
  99. * @PSP_SUB_CMD_DBC_SET_UID: Set UID for DBC
  100. * @PSP_SUB_CMD_DBC_GET_PARAMETER: Get parameter from DBC
  101. * @PSP_SUB_CMD_DBC_SET_PARAMETER: Set parameter for DBC
  102. * @PSP_SUB_CMD_SFS_GET_FW_VERS: Get firmware versions for ASP and other MP
  103. * @PSP_SUB_CMD_SFS_UPDATE: Command to load, verify and execute SFS package
  104. */
  105. enum psp_sub_cmd {
  106. PSP_SUB_CMD_DBC_GET_NONCE = PSP_DYNAMIC_BOOST_GET_NONCE,
  107. PSP_SUB_CMD_DBC_SET_UID = PSP_DYNAMIC_BOOST_SET_UID,
  108. PSP_SUB_CMD_DBC_GET_PARAMETER = PSP_DYNAMIC_BOOST_GET_PARAMETER,
  109. PSP_SUB_CMD_DBC_SET_PARAMETER = PSP_DYNAMIC_BOOST_SET_PARAMETER,
  110. PSP_SUB_CMD_SFS_GET_FW_VERS = PSP_SFS_GET_FW_VERSIONS,
  111. PSP_SUB_CMD_SFS_UPDATE = PSP_SFS_UPDATE,
  112. };
  113. int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs,
  114. struct psp_ext_request *req);
  115. #endif /* __PSP_DEV_H */