From: Mario Limonciello <mario.limonciello@amd.com>
To: "Jan Dąbroś" <jsd@semihalf.com>,
"Grzegorz Bernacki" <gjb@semihalf.com>,
Rijo-john.Thomas@amd.com, Thomas.Lendacky@amd.com,
herbert@gondor.apana.org.au,
"Tom Lendacky" <thomas.lendacky@amd.com>,
"John Allen" <john.allen@amd.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
"David S. Miller" <davem@davemloft.net>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 7/9] crypto: ccp: Add support for ringing a platform doorbell
Date: Fri, 3 Mar 2023 10:50:45 -0600 [thread overview]
Message-ID: <20230303165050.2918-8-mario.limonciello@amd.com> (raw)
In-Reply-To: <20230303165050.2918-1-mario.limonciello@amd.com>
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>
---
v2->v3:
* Squash register values in
* Use command and button registers
* Correct register values for incorrect ones previously shared
* Use a unique mutex
v1->v2:
* New patch
---
drivers/crypto/ccp/platform-access.c | 52 ++++++++++++++++++++++++++++
drivers/crypto/ccp/platform-access.h | 1 +
drivers/crypto/ccp/sp-dev.h | 3 ++
drivers/crypto/ccp/sp-pci.c | 2 ++
include/linux/psp-platform-access.h | 15 ++++++++
include/linux/psp.h | 3 ++
6 files changed, 76 insertions(+)
diff --git a/drivers/crypto/ccp/platform-access.c b/drivers/crypto/ccp/platform-access.c
index d7669a44dcfe..332e12637d48 100644
--- a/drivers/crypto/ccp/platform-access.c
+++ b/drivers/crypto/ccp/platform-access.c
@@ -132,6 +132,56 @@ 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 *button, __iomem *cmd;
+ int ret, val;
+
+ if (!psp || !psp->platform_access_data)
+ return -ENODEV;
+
+ pa_dev = psp->platform_access_data;
+ button = psp->io_regs + pa_dev->vdata->doorbell_button_reg;
+ cmd = psp->io_regs + pa_dev->vdata->doorbell_cmd_reg;
+
+ mutex_lock(&pa_dev->doorbell_mutex);
+
+ if (check_recovery(cmd)) {
+ dev_dbg(psp->dev, "doorbell in recovery\n");
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ if (wait_cmd(cmd)) {
+ dev_dbg(psp->dev, "doorbell not done processing command\n");
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ iowrite32(FIELD_PREP(PSP_DRBL_MSG, msg), cmd);
+ iowrite32(PSP_DRBL_RING, button);
+
+ if (wait_cmd(cmd)) {
+ ret = -ETIMEDOUT;
+ goto unlock;
+ }
+
+ val = FIELD_GET(PSP_CMDRESP_STS, ioread32(cmd));
+ if (val) {
+ ret = -EIO;
+ goto unlock;
+ }
+
+ ret = 0;
+unlock:
+ mutex_unlock(&pa_dev->doorbell_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;
@@ -140,6 +190,7 @@ void platform_access_dev_destroy(struct psp_device *psp)
return;
mutex_destroy(&pa_dev->mailbox_mutex);
+ mutex_destroy(&pa_dev->doorbell_mutex);
psp->platform_access_data = NULL;
}
@@ -159,6 +210,7 @@ int platform_access_dev_init(struct psp_device *psp)
pa_dev->vdata = (struct platform_access_vdata *)psp->vdata->platform_access;
mutex_init(&pa_dev->mailbox_mutex);
+ mutex_init(&pa_dev->doorbell_mutex);
dev_dbg(dev, "platform access enabled\n");
diff --git a/drivers/crypto/ccp/platform-access.h b/drivers/crypto/ccp/platform-access.h
index c3a97893320d..a83f03beb869 100644
--- a/drivers/crypto/ccp/platform-access.h
+++ b/drivers/crypto/ccp/platform-access.h
@@ -24,6 +24,7 @@ struct psp_platform_access_device {
struct platform_access_vdata *vdata;
struct mutex mailbox_mutex;
+ struct mutex doorbell_mutex;
void *platform_access_data;
};
diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h
index 5ec6c219a731..1253a0217985 100644
--- a/drivers/crypto/ccp/sp-dev.h
+++ b/drivers/crypto/ccp/sp-dev.h
@@ -57,6 +57,9 @@ struct platform_access_vdata {
const unsigned int cmdresp_reg;
const unsigned int cmdbuff_addr_lo_reg;
const unsigned int cmdbuff_addr_hi_reg;
+ const unsigned int doorbell_button_reg;
+ const unsigned int doorbell_cmd_reg;
+
};
struct psp_vdata {
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index 18aa902eb5ce..b5896f7af7ab 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -365,6 +365,8 @@ static const struct platform_access_vdata pa_v1 = {
.cmdresp_reg = 0x10570, /* C2PMSG_28 */
.cmdbuff_addr_lo_reg = 0x10574, /* C2PMSG_29 */
.cmdbuff_addr_hi_reg = 0x10578, /* C2PMSG_30 */
+ .doorbell_button_reg = 0x10a24, /* C2PMSG_73 */
+ .doorbell_cmd_reg = 0x10a40, /* C2PMSG_80 */
};
static const struct psp_vdata pspv1 = {
diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h
index f5a03cd11f10..1e1d0e077cec 100644
--- a/include/linux/psp-platform-access.h
+++ b/include/linux/psp-platform-access.h
@@ -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
*
diff --git a/include/linux/psp.h b/include/linux/psp.h
index d3424790a70e..92e60aeef21e 100644
--- a/include/linux/psp.h
+++ b/include/linux/psp.h
@@ -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 */
--
2.34.1
next prev parent reply other threads:[~2023-03-03 16:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 16:50 [PATCH v3 0/9] Export platform features from ccp driver Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 1/9] crypto: ccp: Drop TEE support for IRQ handler Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 2/9] crypto: ccp: Add a header for multiple drivers to use `__psp_pa` Mario Limonciello
2023-03-07 23:42 ` Sean Christopherson
2023-03-03 16:50 ` [PATCH v3 3/9] crypto: ccp: Move some PSP mailbox bit definitions into common header Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 4/9] crypto: ccp: Add support for an interface for platform features Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 5/9] crypto: ccp: Enable platform access interface on client PSP parts Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 6/9] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
2023-03-03 16:50 ` Mario Limonciello [this message]
2023-03-10 11:19 ` [PATCH v3 7/9] crypto: ccp: Add support for ringing a platform doorbell Herbert Xu
2023-03-03 16:50 ` [PATCH v3 8/9] i2c: designware: Add doorbell support for Skyrim Mario Limonciello
2023-03-03 16:50 ` [PATCH v3 9/9] i2c: designware: Add support for AMDI0020 ACPI ID Mario Limonciello
2023-03-06 12:04 ` Andy Shevchenko
2023-03-06 12:28 ` Jarkko Nikula
2023-03-06 12:55 ` Andy Shevchenko
2023-03-06 13:11 ` Mario Limonciello
2023-03-07 21:22 ` Limonciello, Mario
2023-03-03 20:58 ` [PATCH v3 0/9] Export platform features from ccp driver Tom Lendacky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230303165050.2918-8-mario.limonciello@amd.com \
--to=mario.limonciello@amd.com \
--cc=Rijo-john.Thomas@amd.com \
--cc=Thomas.Lendacky@amd.com \
--cc=davem@davemloft.net \
--cc=gjb@semihalf.com \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=jsd@semihalf.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®