@@ -135,6 +135,53 @@ int psp_send_platform_access_msg(enum psp_platform_access_msg msg,
}
EXPORT_SYMBOL_GPL(psp_send_platform_access_msg);
+int psp_ring_platform_doorbell(enum psp_platform_access_msg msg)
+{
+ struct psp_device *psp = psp_get_master_device();
+ struct psp_platform_access_device *pa_dev;
+ u32 __iomem *drbl;
+ u32 drbl_reg;
+ int ret;
+
+ if (!psp || !psp->platform_access_data)
+ return -ENODEV;
+
+ pa_dev = psp->platform_access_data;
+ drbl = psp->io_regs + pa_dev->vdata->doorbell_reg;
+
+ if (!drbl)
+ return -ENODEV;
+
+ mutex_lock(&pa_dev->mutex);
+
+ if (check_recovery(drbl)) {
+ dev_dbg(psp->dev, "in recovery\n");
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ if (wait_cmd(drbl)) {
+ dev_dbg(psp->dev, "not done processing command\n");
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ drbl_reg = FIELD_PREP(PSP_DRBL_MSG, msg) | PSP_DRBL_RING;
+ iowrite32(drbl_reg, drbl);
+
+ if (wait_cmd(drbl)) {
+ ret = -ETIMEDOUT;
+ goto unlock;
+ }
+
+ ret = 0;
+unlock:
+ mutex_unlock(&pa_dev->mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(psp_ring_platform_doorbell);
+
void platform_access_dev_destroy(struct psp_device *psp)
{
struct psp_platform_access_device *pa_dev = psp->platform_access_data;
@@ -54,6 +54,7 @@ struct tee_vdata {
};
struct platform_access_vdata {
+ const unsigned int doorbell_reg;
const unsigned int cmdresp_reg;
const unsigned int cmdbuff_addr_lo_reg;
const unsigned int cmdbuff_addr_hi_reg;
@@ -35,6 +35,21 @@ struct psp_request {
*/
int psp_send_platform_access_msg(enum psp_platform_access_msg, struct psp_request *req);
+/**
+ * psp_ring_platform_doorbell() - Ring platform doorbell
+ *
+ * This function is intended to be used by drivers outside of ccp to ring the
+ * platform doorbell with a message.
+ *
+ * Returns:
+ * 0: success
+ * -%EBUSY: mailbox in recovery or in use
+ * -%ENODEV: driver not bound with PSP device
+ * -%ETIMEDOUT: request timed out
+ * -%EIO: unknown error (see kernel log)
+ */
+int psp_ring_platform_doorbell(enum psp_platform_access_msg);
+
/**
* psp_check_platform_access_status() - Checks whether platform features is ready
*
@@ -23,4 +23,7 @@
#define PSP_CMDRESP_RECOVERY BIT(30)
#define PSP_CMDRESP_RESP BIT(31)
+#define PSP_DRBL_MSG PSP_CMDRESP_CMD
+#define PSP_DRBL_RING BIT(0)
+
#endif /* __PSP_H */
Some platforms support using a doorbell to communicate. Export this feature for other drivers to utilize as well. Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/ Suggested-by: Jan Dabros <jsd@semihalf.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v1->v2: * New patch --- drivers/crypto/ccp/platform-access.c | 47 ++++++++++++++++++++++++++++ drivers/crypto/ccp/sp-dev.h | 1 + include/linux/psp-platform-access.h | 15 +++++++++ include/linux/psp.h | 3 ++ 4 files changed, 66 insertions(+)