psp-dev.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. rsvd1 :4,
  29. security_reporting :1,
  30. fused_part :1,
  31. rsvd2 :1,
  32. debug_lock_on :1,
  33. rsvd3 :2,
  34. tsme_status :1,
  35. rsvd4 :1,
  36. anti_rollback_status :1,
  37. rpmc_production_enabled :1,
  38. rpmc_spirom_available :1,
  39. hsp_tpm_available :1,
  40. rom_armor_enforced :1,
  41. rsvd5 :12;
  42. };
  43. };
  44. struct psp_device {
  45. struct list_head entry;
  46. struct psp_vdata *vdata;
  47. char name[MAX_PSP_NAME_LEN];
  48. struct device *dev;
  49. struct sp_device *sp;
  50. void __iomem *io_regs;
  51. struct mutex mailbox_mutex;
  52. psp_irq_handler_t sev_irq_handler;
  53. void *sev_irq_data;
  54. void *sev_data;
  55. void *tee_data;
  56. void *platform_access_data;
  57. void *dbc_data;
  58. union psp_cap_register capability;
  59. };
  60. void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler,
  61. void *data);
  62. void psp_clear_sev_irq_handler(struct psp_device *psp);
  63. struct psp_device *psp_get_master_device(void);
  64. /**
  65. * enum psp_cmd - PSP mailbox commands
  66. * @PSP_CMD_TEE_RING_INIT: Initialize TEE ring buffer
  67. * @PSP_CMD_TEE_RING_DESTROY: Destroy TEE ring buffer
  68. * @PSP_CMD_TEE_EXTENDED_CMD: Extended command
  69. * @PSP_CMD_MAX: Maximum command id
  70. */
  71. enum psp_cmd {
  72. PSP_CMD_TEE_RING_INIT = 1,
  73. PSP_CMD_TEE_RING_DESTROY = 2,
  74. PSP_CMD_TEE_EXTENDED_CMD = 14,
  75. PSP_CMD_MAX = 15,
  76. };
  77. int psp_mailbox_command(struct psp_device *psp, enum psp_cmd cmd, void *cmdbuff,
  78. unsigned int timeout_msecs, unsigned int *cmdresp);
  79. /**
  80. * struct psp_ext_req_buffer_hdr - Structure of the extended command header
  81. * @payload_size: total payload size
  82. * @sub_cmd_id: extended command ID
  83. * @status: status of command execution (out)
  84. */
  85. struct psp_ext_req_buffer_hdr {
  86. u32 payload_size;
  87. u32 sub_cmd_id;
  88. u32 status;
  89. } __packed;
  90. struct psp_ext_request {
  91. struct psp_ext_req_buffer_hdr header;
  92. void *buf;
  93. } __packed;
  94. /**
  95. * enum psp_sub_cmd - PSP mailbox sub commands
  96. * @PSP_SUB_CMD_DBC_GET_NONCE: Get nonce from DBC
  97. * @PSP_SUB_CMD_DBC_SET_UID: Set UID for DBC
  98. * @PSP_SUB_CMD_DBC_GET_PARAMETER: Get parameter from DBC
  99. * @PSP_SUB_CMD_DBC_SET_PARAMETER: Set parameter for DBC
  100. */
  101. enum psp_sub_cmd {
  102. PSP_SUB_CMD_DBC_GET_NONCE = PSP_DYNAMIC_BOOST_GET_NONCE,
  103. PSP_SUB_CMD_DBC_SET_UID = PSP_DYNAMIC_BOOST_SET_UID,
  104. PSP_SUB_CMD_DBC_GET_PARAMETER = PSP_DYNAMIC_BOOST_GET_PARAMETER,
  105. PSP_SUB_CMD_DBC_SET_PARAMETER = PSP_DYNAMIC_BOOST_SET_PARAMETER,
  106. };
  107. int psp_extended_mailbox_cmd(struct psp_device *psp, unsigned int timeout_msecs,
  108. struct psp_ext_request *req);
  109. #endif /* __PSP_DEV_H */