Export platform features from ccp driver
Subsystems (11)
Mario Limonciello
maintainerv2 cover Export platform features from ccp driver
The i2c-designware-amdpsp driver communicates with a platform features mailbox provided by the PSP. The address used for communication is discovered via a non-architecturally guaranteed mechanism.
To better scale, export a feature for communication with platform features directly from the ccp driver.
v1->v2:
* Pick up tags
* Fix dependencies
* Add support for Skyrim (3 new patches in series)
Mario Limonciello (9):
crypto: ccp: Drop TEE support for IRQ handler
crypto: ccp: Add a header for multiple drivers to use __psp_pa
crypto: ccp: Move some PSP mailbox bit definitions into common header
crypto: ccp: Add support for an interface for platform features
crypto: ccp: Enable platform access interface on client PSP parts
i2c: designware: Use PCI PSP driver for communication
crypto: ccp: Add support for ringing a platform doorbell
i2c: designware: Add doorbell support for Skyrim
crypto: ccp: Add doorbell register offset
arch/x86/kvm/svm/sev.c | 1 + drivers/crypto/ccp/Makefile | 3 +- drivers/crypto/ccp/platform-access.c | 216 ++++++++++++++++++++ drivers/crypto/ccp/platform-access.h | 34 +++ drivers/crypto/ccp/psp-dev.c | 32 +-- drivers/crypto/ccp/psp-dev.h | 11 +- drivers/crypto/ccp/sev-dev.c | 16 +- drivers/crypto/ccp/sev-dev.h | 2 +- drivers/crypto/ccp/sp-dev.h | 8 + drivers/crypto/ccp/sp-pci.c | 8 + drivers/crypto/ccp/tee-dev.c | 17 +- drivers/i2c/busses/Kconfig | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 179 +++------------- drivers/i2c/busses/i2c-designware-core.h | 1 - drivers/i2c/busses/i2c-designware-platdrv.c | 2 +- drivers/tee/amdtee/call.c | 2 +- drivers/tee/amdtee/shm_pool.c | 2 +- include/linux/psp-platform-access.h | 65 ++++++ include/linux/psp-sev.h | 8 - include/linux/psp.h | 29 +++ 20 files changed, 432 insertions(+), 206 deletions(-) create mode 100644 drivers/crypto/ccp/platform-access.c create mode 100644 drivers/crypto/ccp/platform-access.h create mode 100644 include/linux/psp-platform-access.h create mode 100644 include/linux/psp.h
Signature · 1 line
2.34.1
Mario Limonciello
maintainerPATCH v2 1/9 crypto: ccp: Drop TEE support for IRQ handler
The only PSP mailbox that currently supports interrupt on completion is the SEV mailbox. Drop the dead code for the TEE subdriver to potentially call it.
--- drivers/crypto/ccp/psp-dev.c | 15 --------------- drivers/crypto/ccp/psp-dev.h | 7 ------- 2 files changed, 22 deletions(-)
drivers/crypto/ccp/psp-dev.c +0 -15
@@ -46,9 +46,6 @@ static irqreturn_t psp_irq_handler(int irq, void *data)if (status) {if (psp->sev_irq_handler) psp->sev_irq_handler (irq, psp->sev_irq_data, status); - -if (psp->tee_irq_handler) - psp->tee_irq_handler (irq, psp->tee_irq_data, status); }/* Clear the interrupt status by writing the same value we read. */
@@ -219,18 +216,6 @@ void psp_clear_sev_irq_handler(struct psp_device *psp)psp_set_sev_irq_handler (psp,NULL ,NULL ); } -void psp_set_tee_irq_handler (struct psp_device *psp,psp_irq_handler_t handler, -void *data) -{ - psp->tee_irq_data = data; - psp->tee_irq_handler = handler; -} - -void psp_clear_tee_irq_handler (struct psp_device *psp) -{ -psp_set_tee_irq_handler (psp,NULL ,NULL ); -} -struct psp_device *psp_get_master_device (void ) {struct sp_device *sp =sp_get_psp_master_device ();
drivers/crypto/ccp/psp-dev.h +0 -7
@@ -40,9 +40,6 @@ struct psp_device {psp_irq_handler_t sev_irq_handler;void *sev_irq_data; -psp_irq_handler_t tee_irq_handler; -void *tee_irq_data; -void *sev_data;void *tee_data;
@@ -53,10 +50,6 @@ void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler, void *data);void psp_clear_sev_irq_handler (struct psp_device *psp); -void psp_set_tee_irq_handler (struct psp_device *psp,psp_irq_handler_t handler, -void *data); -void psp_clear_tee_irq_handler (struct psp_device *psp); -struct psp_device *psp_get_master_device (void );#define PSP_CAPABILITY_SEV BIT(0)
Signature · 1 line
2.34.1
Re: [PATCH v2 1/9] crypto: ccp: Drop TEE support for IRQ handler
Quoted 5 lines · Mario Limonciello
The only PSP mailbox that currently supports interrupt on completion is the SEV mailbox. Drop the dead code for the TEE subdriver to potentially call it.
Signed-off-by Mario Limonciello <[email protected]>
Looks good.
Thanks,
Rijo
Quoted 63 lines
--- drivers/crypto/ccp/psp-dev.c | 15 --------------- drivers/crypto/ccp/psp-dev.h | 7 ------- 2 files changed, 22 deletions(-)drivers/crypto/ccp/psp-dev.c +0
-15@@ -46,9 +46,6 @@ static irqreturn_t psp_irq_handler(int irq, void *data)if (status) {if (psp->sev_irq_handler) psp->sev_irq_handler (irq, psp->sev_irq_data, status); - -if (psp->tee_irq_handler) - psp->tee_irq_handler (irq, psp->tee_irq_data, status); }/* Clear the interrupt status by writing the same value we read. */ @@ -219,18 +216,6 @@ void psp_clear_sev_irq_handler(struct psp_device *psp)psp_set_sev_irq_handler (psp,NULL ,NULL ); } -void psp_set_tee_irq_handler (struct psp_device *psp,psp_irq_handler_t handler, -void *data) -{ - psp->tee_irq_data = data; - psp->tee_irq_handler = handler; -} - -void psp_clear_tee_irq_handler (struct psp_device *psp) -{ -psp_set_tee_irq_handler (psp,NULL ,NULL ); -} -struct psp_device *psp_get_master_device (void ) {struct sp_device *sp =sp_get_psp_master_device ();drivers/crypto/ccp/psp-dev.h +0
-7@@ -40,9 +40,6 @@ struct psp_device {psp_irq_handler_t sev_irq_handler;void *sev_irq_data; -psp_irq_handler_t tee_irq_handler; -void *tee_irq_data; -void *sev_data;void *tee_data;@@ -53,10 +50,6 @@ void psp_set_sev_irq_handler(struct psp_device *psp, psp_irq_handler_t handler, void *data);void psp_clear_sev_irq_handler (struct psp_device *psp); -void psp_set_tee_irq_handler (struct psp_device *psp,psp_irq_handler_t handler, -void *data); -void psp_clear_tee_irq_handler (struct psp_device *psp); -struct psp_device *psp_get_master_device (void );#define PSP_CAPABILITY_SEV BIT(0)
Mario Limonciello
maintainerPATCH v2 2/9 crypto: ccp: Add a header for multiple drivers to use `__psp_pa`
In reply to Mario LimoncielloThe TEE subdriver for CCP, the amdtee driver and the i2c-designware-amdpsp drivers all include psp-sev.h even though they don't use SEV functionality.
Move the definition of __psp_pa into a common header to be included by all of these drivers.
---v1->v2:
* Add tags
--- arch/x86/kvm/svm/sev.c | 1 + drivers/crypto/ccp/sev-dev.c | 1 + drivers/crypto/ccp/tee-dev.c | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 2 +- drivers/tee/amdtee/call.c | 2 +- drivers/tee/amdtee/shm_pool.c | 2 +- include/linux/psp-sev.h | 8 -------- include/linux/psp.h | 14 ++++++++++++++ 8 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 include/linux/psp.h
arch/x86/kvm/svm/sev.c +1 -0
@@ -12,6 +12,7 @@#include <linux/kvm_host.h> #include <linux/kernel.h> #include <linux/highmem.h> +#include <linux/psp.h> #include <linux/psp-sev.h> #include <linux/pagemap.h> #include <linux/swap.h>
drivers/crypto/ccp/sev-dev.c +1 -0
@@ -24,6 +24,7 @@#include <linux/cpufeature.h> #include <linux/fs.h> #include <linux/fs_struct.h> +#include <linux/psp.h> #include <asm/smp.h> #include <asm/cacheflush.h>
drivers/crypto/ccp/tee-dev.c +1 -1
@@ -13,7 +13,7 @@#include <linux/delay.h> #include <linux/slab.h> #include <linux/gfp.h> -#include <linux/psp-sev.h> +#include <linux/psp.h> #include <linux/psp-tee.h> #include "psp-dev.h"
drivers/i2c/busses/i2c-designware-amdpsp.c +1 -1
@@ -4,7 +4,7 @@#include <linux/bits.h> #include <linux/i2c.h> #include <linux/io-64-nonatomic-lo-hi.h> -#include <linux/psp-sev.h> +#include <linux/psp.h> #include <linux/types.h> #include <linux/workqueue.h>
drivers/tee/amdtee/call.c +1 -1
@@ -8,7 +8,7 @@#include <linux/tee_drv.h> #include <linux/psp-tee.h> #include <linux/slab.h> -#include <linux/psp-sev.h> +#include <linux/psp.h> #include "amdtee_if.h" #include "amdtee_private.h"
drivers/tee/amdtee/shm_pool.c +1 -1
@@ -5,7 +5,7 @@#include <linux/slab.h> #include <linux/tee_drv.h> -#include <linux/psp-sev.h> +#include <linux/psp.h> #include "amdtee_private.h" static int pool_op_alloc(struct tee_shm_pool *pool, struct tee_shm *shm,
include/linux/psp-sev.h +0 -8
@@ -14,14 +14,6 @@#include <uapi/linux/psp-sev.h> -#ifdef CONFIG_X86 -#include <linux/mem_encrypt.h> - -#define __psp_pa (x) __sme_pa(x) -#else -#define __psp_pa (x) __pa(x) -#endif -#define SEV_FW_BLOB_MAX_SIZE 0x4000/* 16KB */ /**
include/linux/psp.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __PSP_H +#define __PSP_H + +#ifdef CONFIG_X86 +#include <linux/mem_encrypt.h> + +#define __psp_pa (x) __sme_pa(x) +#else +#define __psp_pa (x) __pa(x) +#endif + +#endif /* __PSP_H */
Signature · 1 line
2.34.1
Mario Limonciello
maintainerPATCH v2 3/9 crypto: ccp: Move some PSP mailbox bit definitions into common header
In reply to Mario LimoncielloSome of the bits and fields used for mailboxes communicating with the PSP are common across all mailbox implementations (SEV, TEE, etc).
Move these bits into the common linux/psp.h so they don't need to be re-defined for each implementation.
---v1->v2:
* Update comment to indicate it's PSP response not PSP ready
--- drivers/crypto/ccp/psp-dev.h | 3 --- drivers/crypto/ccp/sev-dev.c | 15 +++++++-------- drivers/crypto/ccp/sev-dev.h | 2 +- drivers/crypto/ccp/tee-dev.c | 15 ++++++++------- drivers/i2c/busses/i2c-designware-amdpsp.c | 16 +++++----------- include/linux/psp.h | 12 ++++++++++++ 6 files changed, 33 insertions(+), 30 deletions(-)
drivers/crypto/ccp/psp-dev.h +0 -3
@@ -17,9 +17,6 @@#include "sp-dev.h" -#define PSP_CMDRESP_RESP BIT(31) -#define PSP_CMDRESP_ERR_MASK 0xffff -#define MAX_PSP_NAME_LEN 16extern struct psp_device *psp_master;
drivers/crypto/ccp/sev-dev.c +7 -8
@@ -7,6 +7,7 @@* Author: Brijesh Singh <[email protected]> */ +#include <linux/bitfield.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/kthread.h>
@@ -103,7 +104,7 @@ static void sev_irq_handler(int irq, void *data, unsigned int status)/* Check if it is SEV command completion: */ reg =ioread32 (sev->io_regs + sev->vdata->cmdresp_reg); -if (reg &PSP_CMDRESP_RESP ) { +if (FIELD_GET (PSP_CMDRESP_RESP , reg)) { sev->int_rcvd =1 ;wake_up (&sev->int_queue); }
@@ -347,9 +348,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) sev->int_rcvd =0 ; - reg = cmd; - reg <<=SEV_CMDRESP_CMD_SHIFT ; - reg |=SEV_CMDRESP_IOC ; + reg =FIELD_PREP (SEV_CMDRESP_CMD , cmd) |SEV_CMDRESP_IOC ;iowrite32 (reg, sev->io_regs + sev->vdata->cmdresp_reg);/* wait for command completion */
@@ -367,11 +366,11 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) psp_timeout = psp_cmd_timeout;if (psp_ret) - *psp_ret = reg &PSP_CMDRESP_ERR_MASK ; + *psp_ret =FIELD_GET (PSP_CMDRESP_STS , reg); -if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_dbg (sev->dev,"sev command %#x failed (%#010x)\n" , - cmd, reg &PSP_CMDRESP_ERR_MASK ); +if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_dbg (sev->dev,"sev command %#x failed (%#010lx)\n" , + cmd,FIELD_GET (PSP_CMDRESP_STS , reg)); ret = -EIO ; }else { ret =sev_write_init_ex_file_if_required (cmd);
drivers/crypto/ccp/sev-dev.h +1 -1
@@ -25,8 +25,8 @@#include <linux/miscdevice.h> #include <linux/capability.h> +#define SEV_CMDRESP_CMD GENMASK(26, 16)#define SEV_CMD_COMPLETE BIT(1) -#define SEV_CMDRESP_CMD_SHIFT 16#define SEV_CMDRESP_IOC BIT(0)struct sev_misc_dev {
drivers/crypto/ccp/tee-dev.c +8 -7
@@ -8,6 +8,7 @@* Copyright (C) 2019,2021 Advanced Micro Devices, Inc. */ +#include <linux/bitfield.h> #include <linux/types.h> #include <linux/mutex.h> #include <linux/delay.h>
@@ -69,7 +70,7 @@ static int tee_wait_cmd_poll(struct psp_tee_device *tee, unsigned int timeout,while (--nloop) { *reg =ioread32 (tee->io_regs + tee->vdata->cmdresp_reg); -if (*reg &PSP_CMDRESP_RESP ) +if (FIELD_GET (PSP_CMDRESP_RESP , *reg))return 0 ;usleep_range (10000 ,10100 );
@@ -149,9 +150,9 @@ static int tee_init_ring(struct psp_tee_device *tee) goto free_buf; } -if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_err (tee->dev,"tee: ring init command failed (%#010x)\n" , - reg &PSP_CMDRESP_ERR_MASK ); +if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_err (tee->dev,"tee: ring init command failed (%#010lx)\n" , +FIELD_GET (PSP_CMDRESP_STS , reg));tee_free_ring (tee); ret = -EIO ; }
@@ -179,9 +180,9 @@ static void tee_destroy_ring(struct psp_tee_device *tee) ret =tee_wait_cmd_poll (tee,TEE_DEFAULT_TIMEOUT , ®);if (ret) {dev_err (tee->dev,"tee: ring destroy command timed out\n" ); - }else if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_err (tee->dev,"tee: ring destroy command failed (%#010x)\n" , - reg &PSP_CMDRESP_ERR_MASK ); + }else if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_err (tee->dev,"tee: ring destroy command failed (%#010lx)\n" , +FIELD_GET (PSP_CMDRESP_STS , reg)); } free_ring:
drivers/i2c/busses/i2c-designware-amdpsp.c +5 -11
@@ -25,12 +25,6 @@#define PSP_I2C_REQ_STS_BUS_BUSY 0x1#define PSP_I2C_REQ_STS_INV_PARAM 0x3 -#define PSP_MBOX_FIELDS_STS GENMASK(15, 0) -#define PSP_MBOX_FIELDS_CMD GENMASK(23, 16) -#define PSP_MBOX_FIELDS_RESERVED GENMASK(29, 24) -#define PSP_MBOX_FIELDS_RECOVERY BIT(30) -#define PSP_MBOX_FIELDS_READY BIT(31) -struct psp_req_buffer_hdr {u32 total_size;u32 status;
@@ -99,15 +93,15 @@ static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) tmp =readl (&mbox->cmd_fields); -return FIELD_GET (PSP_MBOX_FIELDS_RECOVERY , tmp); +return FIELD_GET (PSP_CMDRESP_RECOVERY , tmp); }static int psp_wait_cmd (struct psp_mbox __iomem *mbox) {u32 tmp, expected; -/* Expect mbox_cmd to be cleared and ready bit to be set by PSP */ - expected =FIELD_PREP (PSP_MBOX_FIELDS_READY ,1 ); +/* Expect mbox_cmd to be cleared and the response bit to be set by PSP */ + expected =FIELD_PREP (PSP_CMDRESP_RESP ,1 );/* * Check for readiness of PSP mailbox in a tight loop in order to
@@ -124,7 +118,7 @@ static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) cmd_reg =readl (&mbox->cmd_fields); -return FIELD_GET (PSP_MBOX_FIELDS_STS , cmd_reg); +return FIELD_GET (PSP_CMDRESP_STS , cmd_reg); }static int psp_send_cmd (struct psp_i2c_req *req)
@@ -148,7 +142,7 @@ static int psp_send_cmd(struct psp_i2c_req *req)writeq (req_addr, &mbox->i2c_req_addr);/* Write command register to trigger processing */ - cmd_reg =FIELD_PREP (PSP_MBOX_FIELDS_CMD ,PSP_I2C_REQ_BUS_CMD ); + cmd_reg =FIELD_PREP (PSP_CMDRESP_CMD ,PSP_I2C_REQ_BUS_CMD );writel (cmd_reg, &mbox->cmd_fields);if (psp_wait_cmd (mbox))
include/linux/psp.h +12 -0
@@ -11,4 +11,16 @@#define __psp_pa (x) __pa(x)#endif +/* +* Fields and bits used by most PSP mailboxes +* +* Note: Some mailboxes (such as SEV) have extra bits or different meanings +* and should include an appropriate local definition in their source file. +*/ +#define PSP_CMDRESP_STS GENMASK(15, 0) +#define PSP_CMDRESP_CMD GENMASK(23, 16) +#define PSP_CMDRESP_RESERVED GENMASK(29, 24) +#define PSP_CMDRESP_RECOVERY BIT(30) +#define PSP_CMDRESP_RESP BIT(31) +#endif /* __PSP_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 3/9] crypto: ccp: Move some PSP mailbox bit definitions into common header
Quoted 6 lines · Mario Limonciello
Some of the bits and fields used for mailboxes communicating with the PSP are common across all mailbox implementations (SEV, TEE, etc).
Move these bits into the common
linux/psp.hso they don't need to be re-defined for each implementation.
TEE related changes look fine.
Thanks,
Rijo
Quoted 211 lines
Signed-off-by Mario Limonciello <[email protected]>---
v1->v2:
* Update comment to indicate it's PSP response not PSP ready--- drivers/crypto/ccp/psp-dev.h | 3 --- drivers/crypto/ccp/sev-dev.c | 15 +++++++-------- drivers/crypto/ccp/sev-dev.h | 2 +- drivers/crypto/ccp/tee-dev.c | 15 ++++++++------- drivers/i2c/busses/i2c-designware-amdpsp.c | 16 +++++----------- include/linux/psp.h | 12 ++++++++++++ 6 files changed, 33 insertions(+), 30 deletions(-)drivers/crypto/ccp/psp-dev.h +0
-3@@ -17,9 +17,6 @@#include "sp-dev.h" -#define PSP_CMDRESP_RESP BIT(31) -#define PSP_CMDRESP_ERR_MASK 0xffff -#define MAX_PSP_NAME_LEN 16extern struct psp_device *psp_master;drivers/crypto/ccp/sev-dev.c +7
-8@@ -7,6 +7,7 @@* Author: Brijesh Singh <[email protected]> */ +#include <linux/bitfield.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/kthread.h> @@ -103,7 +104,7 @@ static void sev_irq_handler(int irq, void *data, unsigned int status)/* Check if it is SEV command completion: */ reg =ioread32 (sev->io_regs + sev->vdata->cmdresp_reg); -if (reg &PSP_CMDRESP_RESP ) { +if (FIELD_GET (PSP_CMDRESP_RESP , reg)) { sev->int_rcvd =1 ;wake_up (&sev->int_queue); }@@ -347,9 +348,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) sev->int_rcvd =0 ; - reg = cmd; - reg <<=SEV_CMDRESP_CMD_SHIFT ; - reg |=SEV_CMDRESP_IOC ; + reg =FIELD_PREP (SEV_CMDRESP_CMD , cmd) |SEV_CMDRESP_IOC ;iowrite32 (reg, sev->io_regs + sev->vdata->cmdresp_reg);/* wait for command completion */ @@ -367,11 +366,11 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) psp_timeout = psp_cmd_timeout;if (psp_ret) - *psp_ret = reg &PSP_CMDRESP_ERR_MASK ; + *psp_ret =FIELD_GET (PSP_CMDRESP_STS , reg); -if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_dbg (sev->dev,"sev command %#x failed (%#010x)\n" , - cmd, reg &PSP_CMDRESP_ERR_MASK ); +if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_dbg (sev->dev,"sev command %#x failed (%#010lx)\n" , + cmd,FIELD_GET (PSP_CMDRESP_STS , reg)); ret = -EIO ; }else { ret =sev_write_init_ex_file_if_required (cmd);drivers/crypto/ccp/sev-dev.h +1
-1@@ -25,8 +25,8 @@#include <linux/miscdevice.h> #include <linux/capability.h> +#define SEV_CMDRESP_CMD GENMASK(26, 16)#define SEV_CMD_COMPLETE BIT(1) -#define SEV_CMDRESP_CMD_SHIFT 16#define SEV_CMDRESP_IOC BIT(0)struct sev_misc_dev {drivers/crypto/ccp/tee-dev.c +8
-7@@ -8,6 +8,7 @@* Copyright (C) 2019,2021 Advanced Micro Devices, Inc. */ +#include <linux/bitfield.h> #include <linux/types.h> #include <linux/mutex.h> #include <linux/delay.h> @@ -69,7 +70,7 @@ static int tee_wait_cmd_poll(struct psp_tee_device *tee, unsigned int timeout,while (--nloop) { *reg =ioread32 (tee->io_regs + tee->vdata->cmdresp_reg); -if (*reg &PSP_CMDRESP_RESP ) +if (FIELD_GET (PSP_CMDRESP_RESP , *reg))return 0 ;usleep_range (10000 ,10100 );@@ -149,9 +150,9 @@ static int tee_init_ring(struct psp_tee_device *tee) goto free_buf; } -if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_err (tee->dev,"tee: ring init command failed (%#010x)\n" , - reg &PSP_CMDRESP_ERR_MASK ); +if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_err (tee->dev,"tee: ring init command failed (%#010lx)\n" , +FIELD_GET (PSP_CMDRESP_STS , reg));tee_free_ring (tee); ret = -EIO ; }@@ -179,9 +180,9 @@ static void tee_destroy_ring(struct psp_tee_device *tee) ret =tee_wait_cmd_poll (tee,TEE_DEFAULT_TIMEOUT , ®);if (ret) {dev_err (tee->dev,"tee: ring destroy command timed out\n" ); - }else if (reg &PSP_CMDRESP_ERR_MASK ) { -dev_err (tee->dev,"tee: ring destroy command failed (%#010x)\n" , - reg &PSP_CMDRESP_ERR_MASK ); + }else if (FIELD_GET (PSP_CMDRESP_STS , reg)) { +dev_err (tee->dev,"tee: ring destroy command failed (%#010lx)\n" , +FIELD_GET (PSP_CMDRESP_STS , reg)); } free_ring:drivers/i2c/busses/i2c-designware-amdpsp.c +5
-11@@ -25,12 +25,6 @@#define PSP_I2C_REQ_STS_BUS_BUSY 0x1#define PSP_I2C_REQ_STS_INV_PARAM 0x3 -#define PSP_MBOX_FIELDS_STS GENMASK(15, 0) -#define PSP_MBOX_FIELDS_CMD GENMASK(23, 16) -#define PSP_MBOX_FIELDS_RESERVED GENMASK(29, 24) -#define PSP_MBOX_FIELDS_RECOVERY BIT(30) -#define PSP_MBOX_FIELDS_READY BIT(31) -struct psp_req_buffer_hdr {u32 total_size;u32 status;@@ -99,15 +93,15 @@ static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) tmp =readl (&mbox->cmd_fields); -return FIELD_GET (PSP_MBOX_FIELDS_RECOVERY , tmp); +return FIELD_GET (PSP_CMDRESP_RECOVERY , tmp); }static int psp_wait_cmd (struct psp_mbox __iomem *mbox) {u32 tmp, expected; -/* Expect mbox_cmd to be cleared and ready bit to be set by PSP */ - expected =FIELD_PREP (PSP_MBOX_FIELDS_READY ,1 ); +/* Expect mbox_cmd to be cleared and the response bit to be set by PSP */ + expected =FIELD_PREP (PSP_CMDRESP_RESP ,1 );/* * Check for readiness of PSP mailbox in a tight loop in order to @@ -124,7 +118,7 @@ static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) cmd_reg =readl (&mbox->cmd_fields); -return FIELD_GET (PSP_MBOX_FIELDS_STS , cmd_reg); +return FIELD_GET (PSP_CMDRESP_STS , cmd_reg); }static int psp_send_cmd (struct psp_i2c_req *req)@@ -148,7 +142,7 @@ static int psp_send_cmd(struct psp_i2c_req *req)writeq (req_addr, &mbox->i2c_req_addr);/* Write command register to trigger processing */ - cmd_reg =FIELD_PREP (PSP_MBOX_FIELDS_CMD ,PSP_I2C_REQ_BUS_CMD ); + cmd_reg =FIELD_PREP (PSP_CMDRESP_CMD ,PSP_I2C_REQ_BUS_CMD );writel (cmd_reg, &mbox->cmd_fields);if (psp_wait_cmd (mbox))include/linux/psp.h +12
-0@@ -11,4 +11,16 @@#define __psp_pa (x) __pa(x)#endif +/* +* Fields and bits used by most PSP mailboxes +* +* Note: Some mailboxes (such as SEV) have extra bits or different meanings +* and should include an appropriate local definition in their source file. +*/ +#define PSP_CMDRESP_STS GENMASK(15, 0) +#define PSP_CMDRESP_CMD GENMASK(23, 16) +#define PSP_CMDRESP_RESERVED GENMASK(29, 24) +#define PSP_CMDRESP_RECOVERY BIT(30) +#define PSP_CMDRESP_RESP BIT(31) +#endif /* __PSP_H */
Mario Limonciello
maintainerPATCH v2 4/9 crypto: ccp: Add support for an interface for platform features
In reply to Mario LimoncielloSome platforms with a PSP support an interface for features that interact directly with the PSP instead of through a SEV or TEE environment.
Initialize this interface so that other drivers can consume it. These drivers may either be subdrivers for the ccp module or external modules. For external modules, export a symbol for them to utilize.
---v1->v2:
* Fix comment text
* Add safety check that register values were populated
--- drivers/crypto/ccp/Makefile | 3 +- drivers/crypto/ccp/platform-access.c | 169 +++++++++++++++++++++++++++ drivers/crypto/ccp/platform-access.h | 34 ++++++ drivers/crypto/ccp/psp-dev.c | 17 +++ drivers/crypto/ccp/psp-dev.h | 1 + drivers/crypto/ccp/sp-dev.h | 7 ++ include/linux/psp-platform-access.h | 49 ++++++++ 7 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/ccp/platform-access.c create mode 100644 drivers/crypto/ccp/platform-access.h create mode 100644 include/linux/psp-platform-access.h
drivers/crypto/ccp/Makefile +2 -1
@@ -10,7 +10,8 @@ ccp-$(CONFIG_CRYPTO_DEV_CCP_DEBUGFS) += ccp-debugfs.o ccp-$(CONFIG_PCI) += sp-pci.o ccp-$(CONFIG_CRYPTO_DEV_SP_PSP) += psp-dev.o \ sev-dev.o \ - tee-dev.o + tee-dev.o \ + platform-access.o obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o ccp-crypto-objs := ccp-crypto-main.o \
drivers/crypto/ccp/platform-access.c new file +169 -0
169 lines not on this page · raw message
drivers/crypto/ccp/platform-access.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* AMD Platform Security Processor (PSP) Platform Access interface +* +* Copyright (C) 2023 Advanced Micro Devices, Inc. +* +* Author: Mario Limonciello <[email protected]> +*/ + +#ifndef __PSP_PLATFORM_ACCESS_H__ +#define __PSP_PLATFORM_ACCESS_H__ + +#include <linux/device.h> +#include <linux/miscdevice.h> +#include <linux/mutex.h> +#include <linux/psp-platform-access.h> + +#include "psp-dev.h" + +struct psp_platform_access_device { +struct device *dev; +struct psp_device *psp; + +struct platform_access_vdata *vdata; + +struct mutex mutex; + +void *platform_access_data; +}; + +void platform_access_dev_destroy (struct psp_device *psp); +int platform_access_dev_init (struct psp_device *psp); + +#endif /* __PSP_PLATFORM_ACCESS_H__ */
drivers/crypto/ccp/psp-dev.c +17 -0
@@ -14,6 +14,7 @@#include "psp-dev.h" #include "sev-dev.h" #include "tee-dev.h" +#include "platform-access.h" struct psp_device *psp_master;
@@ -102,6 +103,17 @@ static int psp_check_tee_support(struct psp_device *psp)return 0 ; } +static void psp_init_platform_access (struct psp_device *psp) +{ +int ret; + + ret =platform_access_dev_init (psp); +if (ret) { +dev_warn (psp->dev,"platform access init failed: %d\n" , ret); +return ; + } +} +static int psp_init (struct psp_device *psp) {int ret;
@@ -118,6 +130,9 @@ static int psp_init(struct psp_device *psp)return ret; } +if (psp->vdata->platform_access) +psp_init_platform_access (psp); +return 0 ; }
@@ -198,6 +213,8 @@ void psp_dev_destroy(struct sp_device *sp)tee_dev_destroy (psp); +platform_access_dev_destroy (psp); +sp_free_psp_irq (sp, psp);if (sp->clear_psp_master_device)
drivers/crypto/ccp/psp-dev.h +1 -0
@@ -39,6 +39,7 @@ struct psp_device {void *sev_data;void *tee_data; +void *platform_access_data;unsigned int capability; };
drivers/crypto/ccp/sp-dev.h +7 -0
@@ -53,9 +53,16 @@ struct tee_vdata {const unsigned int ring_rptr_reg; }; +struct platform_access_vdata { +const unsigned int cmdresp_reg; +const unsigned int cmdbuff_addr_lo_reg; +const unsigned int cmdbuff_addr_hi_reg; +}; +struct psp_vdata {const struct sev_vdata *sev;const struct tee_vdata *tee; +const struct platform_access_vdata *platform_access;const unsigned int feature_reg;const unsigned int inten_reg;const unsigned int intsts_reg;
include/linux/psp-platform-access.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.34.1
Mario Limonciello
maintainerPATCH v2 5/9 crypto: ccp: Enable platform access interface on client PSP parts
In reply to Mario LimoncielloClient PSP parts support the platform access interface. Add the register offsets so that client parts will initialize this interface.
--- drivers/crypto/ccp/sp-pci.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/crypto/ccp/sp-pci.c +7 -0
@@ -361,6 +361,12 @@ static const struct tee_vdata teev1 = { .ring_rptr_reg = 0x10554, /* C2PMSG_21 */ }; +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 */ +}; +static const struct psp_vdata pspv1 = { .sev = &sevv1, .feature_reg =0x105fc ,/* C2PMSG_63 */
@@ -377,6 +383,7 @@ static const struct psp_vdata pspv2 = {static const struct psp_vdata pspv3 = { .tee = &teev1, + .platform_access = &pa_v1, .feature_reg =0x109fc ,/* C2PMSG_63 */ .inten_reg =0x10690 ,/* P2CMSG_INTEN */ .intsts_reg =0x10694 ,/* P2CMSG_INTSTS */
Signature · 1 line
2.34.1
Mario Limonciello
maintainerPATCH v2 6/9 i2c: designware: Use PCI PSP driver for communication
In reply to Mario LimoncielloCurrently the PSP semaphore communication base address is discovered by using an MSR that is not architecturally guaranteed for future platforms. Also the mailbox that is utilized for communication with the PSP may have other consumers in the kernel, so it's better to make all communication go through a single driver.
---v1->v2:
* Fix Kconfig to use imply
* Use IS_REACHABLE
--- drivers/i2c/busses/Kconfig | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 142 ++------------------ drivers/i2c/busses/i2c-designware-core.h | 1 - drivers/i2c/busses/i2c-designware-platdrv.c | 1 - include/linux/psp-platform-access.h | 1 + 5 files changed, 11 insertions(+), 136 deletions(-)
drivers/i2c/busses/Kconfig +1 -1
@@ -566,9 +566,9 @@ config I2C_DESIGNWARE_PLATFORM config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" - depends on X86_MSR depends on ACPI depends on I2C_DESIGNWARE_PLATFORM + imply CRYPTO_DEV_SP_PSP help This driver enables managed host access to the selected I2C bus shared between AMD CPU and AMD PSP.
drivers/i2c/busses/i2c-designware-amdpsp.c +9 -133
206 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-core.h +0 -1
@@ -383,7 +383,6 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev);#if IS_ENABLED (CONFIG_I2C_DESIGNWARE_AMDPSP )int i2c_dw_amdpsp_probe_lock_support (struct dw_i2c_dev *dev); -void i2c_dw_amdpsp_remove_lock_support (struct dw_i2c_dev *dev);#endif int i2c_dw_validate_speed (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-platdrv.c +0 -1
@@ -214,7 +214,6 @@ static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = { #ifdef CONFIG_I2C_DESIGNWARE_AMDPSP { .probe = i2c_dw_amdpsp_probe_lock_support, - .remove = i2c_dw_amdpsp_remove_lock_support, }, #endif {}
include/linux/psp-platform-access.h +1 -0
@@ -7,6 +7,7 @@enum psp_platform_access_msg {PSP_CMD_NONE =0x0 , +PSP_I2C_REQ_BUS_CMD =0x64 , };struct psp_req_buffer_hdr {
Signature · 1 line
2.34.1
Mario Limonciello
maintainerPATCH v2 7/9 crypto: ccp: Add support for ringing a platform doorbell
In reply to Mario LimoncielloSome platforms support using a doorbell to communicate. Export this feature for other drivers to utilize as well.
---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(+)
drivers/crypto/ccp/platform-access.c +47 -0
@@ -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;
drivers/crypto/ccp/sp-dev.h +1 -0
@@ -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;
include/linux/psp-platform-access.h +15 -0
@@ -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 *
include/linux/psp.h +3 -0
@@ -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 */
Signature · 1 line
2.34.1
Tom Lendacky
maintainerRe: [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform doorbell
Quoted 21 lines · Mario Limonciello
Some platforms support using a doorbell to communicate. Export this feature for other drivers to utilize as well.
Suggested-by Jan Dabros <[email protected]>Signed-off-by Mario Limonciello <[email protected]>---
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(+)drivers/crypto/ccp/platform-access.c +0
-0
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 143
Quoted 9 lines
drivers/crypto/ccp/platform-access.c +6
-0@@ -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;
Lets spell out doorbell for these two variable names.
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 153
Quoted 10 lines
drivers/crypto/ccp/platform-access.c +10
-0+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 ;
This will be non-zero because psp->io_regs will always be non-zero. Maybe you meant to check the actual pa_dev->vdata->doorbell_reg value?
I think you should squash this and patch #9 together so that patch #8 just works right away.
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 155
Quoted 2 lines
drivers/crypto/ccp/platform-access.c +2
-0+ +mutex_lock (&pa_dev->mutex);
Does the doorbell register operate independently from the other registers (C2PMSG_28 - C2PMSG_30)? If it does, you could probably just introduce a doorbell mutex.
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 158
Quoted 3 lines
drivers/crypto/ccp/platform-access.c +3
-0+ +if (check_recovery (drbl)) { +dev_dbg (psp->dev,"in recovery\n" );
Maybe a bit more info as to what is "in recovery" (that goes for patch #4, too) or just prefix it with "doorbell" (and "platform" in #4) since you now have duplicated messages.
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 164
Quoted 6 lines
drivers/crypto/ccp/platform-access.c +6
-0+ ret = -EBUSY ; + goto unlock; + } + +if (wait_cmd (drbl)) { +dev_dbg (psp->dev,"not done processing command\n" );
Ditto.
Thanks,
Tom
Quoted 73 lines
drivers/crypto/ccp/platform-access.c +20
-0+ 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;drivers/crypto/ccp/sp-dev.h +1
-0@@ -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;include/linux/psp-platform-access.h +15
-0@@ -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 * include/linux/psp.h +3
-0@@ -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 */
Limonciello, Mario
maintainerRE: [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform doorbell
[Public]
Quoted 41 lines
-----Original Message-----
From: Lendacky, Thomas <[email protected]>
Sent: Thursday, March 2, 2023 15:52
To: Limonciello, Mario <[email protected]>; Jan Dąbroś <[email protected]>; Grzegorz Bernacki <[email protected]>; Thomas, Rijo- john <[email protected]>; [email protected]; Allen, John <[email protected]>
Cc: David S. Miller <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform doorbellQuoted 4 lines · Mario Limonciello
Some platforms support using a doorbell to communicate. Export this feature for other drivers to utilize as well.
Quoted 7 lines
Suggested-by Jan Dabros <[email protected]>Signed-off-by Mario Limonciello <[email protected]>---
v1->v2:
* New patch--- drivers/crypto/ccp/platform-access.c | 47++++++++++++++++++++++++++++
Review
Quoted 6 lines
drivers/crypto/ccp/sp-dev.h | 1 + include/linux/psp-platform-access.h | 15 +++++++++ include/linux/psp.h | 3 ++ 4 files changed, 66 insertions(+)(quoted diff) +0
-0
b/drivers/crypto/ccp/platform-access.cdrivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum
Quoted 4 lines
index
af3a1e97abfe..0763389a2814100644drivers/crypto/ccp/platform-access.c +0
-0@@ -135,6 +135,53 @@ int psp_send_platform_access_msg(enum
psp_platform_access_msgmsg,Quoted 3 lines
drivers/crypto/ccp/platform-access.c +0
-0}EXPORT_SYMBOL_GPL (psp_send_platform_access_msg);
Quoted 8 lines
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 143
Quoted 6 lines
drivers/crypto/ccp/platform-access.c +6
-0+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;Lets spell out doorbell for these two variable names.
Ack. Given drbl_reg is only used one place, I might just drop it too.
Quoted 15 lines
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 153
Quoted 11 lines
drivers/crypto/ccp/platform-access.c +10
-0+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 ;This will be non-zero because
psp->io_regswill always be non-zero. Maybe you meant to check the actualpa_dev->vdata->doorbell_regvalue?
Quoted 2 lines
I think you should squash this and patch #9 together so that patch #8 just works right away.
Ack, I'll squash them together.
Quoted 7 lines
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum · line 155
Quoted 3 lines
drivers/crypto/ccp/platform-access.c +2
-0+ +mutex_lock (&pa_dev->mutex);Does the doorbell register operate independently from the other registers (
C2PMSG_28-C2PMSG_30)? If it does, you could probably just introduce a doorbell mutex.
It does work independently. I'll add a second mutex.
Quoted 8 lines
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 158
Quoted 4 lines
drivers/crypto/ccp/platform-access.c +3
-0+ +if (check_recovery (drbl)) { +dev_dbg (psp->dev,"in recovery\n" );Maybe a bit more info as to what is "in recovery" (that goes for patch #4, too) or just prefix it with "doorbell" (and "platform" in #4) since you now have duplicated messages.
Will add prefixes to make unique messages.
Quoted 10 lines
drivers/crypto/ccp/platform-access.c int psp_send_platform_access_msg(enum psp_platform_access_msg msg, · line 164
Quoted 7 lines
drivers/crypto/ccp/platform-access.c +6
-0+ ret = -EBUSY ; + goto unlock; + } + +if (wait_cmd (drbl)) { +dev_dbg (psp->dev,"not done processing command\n" );Ditto.
Quoted 2 lines
Thanks,
Tom
Thanks for the new comments.
I'll wait on Jan and Grzegorz to confirm whether the new doorbell stuff works on Skyrim or not to spin a v3.
Quoted 78 lines
include/linux/psp-
Quoted 38 lines
drivers/crypto/ccp/platform-access.c +20
-0+ 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;drivers/crypto/ccp/sp-dev.h +1
-0@@ -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;include/linux/psp- renamed from include/linux/psp-platform-access.h +0
-0
platform-access.hinclude/linux/psp-platform-access.h struct psp_request { · line 36
Quoted 6 lines
index
f5a03cd11f10..1e1d0e077cec100644include/linux/psp-platform-access.h +0
-0@@ -35,6 +35,21 @@ struct psp_request {*/ int psp_send_platform_access_msg(enum psp_platform_access_msg,struct
psp_request*req);Quoted 8 lines
include/linux/psp-platform-access.h +7
-0+/** +* 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: include/linux/psp-platform-access.h struct psp_request {
Quoted 10 lines
include/linux/psp-platform-access.h +8
-0+* 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
Quoted 13 lines
include/linux/psp-platform-access.h +0
-0* include/linux/psp.h +3
-0@@ -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 */
Mario Limonciello
maintainerPATCH v2 8/9 i2c: designware: Add doorbell support for Skyrim
In reply to Mario LimoncielloSkyrim doesn't use the platform feature mailbox for communication for I2C arbitration, it relies upon ringing a doorbell.
Add a new ACPI ID to use for Skyrim and when that ID is detected use the doorbell instead.
---v1->v2:
* New patch
Note: This ACPI ID hasn't currently been reserved, but as Skyrim runs coreboot it should be easy enough to modify the BIOS and test it out.
If this approach works and has general agreement it can be reserved.
--- drivers/i2c/busses/i2c-designware-amdpsp.c | 29 ++++++++++++++------- drivers/i2c/busses/i2c-designware-platdrv.c | 1 + 2 files changed, 20 insertions(+), 10 deletions(-)
drivers/i2c/busses/i2c-designware-amdpsp.c +19 -10
@@ -73,34 +73,44 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req)return check_i2c_req_sts (req); } -static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +static int psp_send_i2c_req_amdi0019 (enum psp_i2c_req_type i2c_req_type) {struct psp_i2c_req *req; -unsigned long start;int status, ret;/* Allocate command-response buffer */ req =kzalloc (sizeof (*req),GFP_KERNEL );if (!req)return -ENOMEM ; - req->hdr.payload_size =sizeof (*req); req->type = i2c_req_type; - - start = jiffies; ret =read_poll_timeout (psp_send_check_i2c_req, status, (status != -EBUSY ),PSP_I2C_REQ_RETRY_DELAY_US ,PSP_I2C_REQ_RETRY_CNT *PSP_I2C_REQ_RETRY_DELAY_US ,0 , req); -if (ret) { +kfree (req); + +if (ret)dev_err (psp_i2c_dev,"Timed out waiting for PSP to %s I2C bus\n" , (i2c_req_type ==PSP_I2C_REQ_ACQUIRE ) ?"release" :"acquire" ); - goto cleanup; - } - ret = status; +return ret ? ret : status; +} + +static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +{ +const char *hid =acpi_device_hid (ACPI_COMPANION (psp_i2c_dev)); +unsigned long start = jiffies; +int ret; + +/* Use doorbell for Skyrim and mailbox for Cezanne */ +if (!strcmp (hid,"AMDI0020" )) + ret =psp_ring_platform_doorbell (i2c_req_type); +else + ret =psp_send_i2c_req_amdi0019 (i2c_req_type); +if (ret) {dev_err (psp_i2c_dev,"PSP communication error\n" ); goto cleanup;
@@ -115,7 +125,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) psp_i2c_mbox_fail = true; } -kfree (req);return ret; }
drivers/i2c/busses/i2c-designware-platdrv.c +1 -0
@@ -51,6 +51,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = { { "AMD0010", ACCESS_INTR_MASK }, { "AMDI0010", ACCESS_INTR_MASK }, { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, + { "AMDI0020", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, { "AMDI0510", 0 }, { "APMC0D0F", 0 }, { "HISI02A1", 0 },
Signature · 1 line
2.34.1
Re: [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim
Hi Mario,
I am not sure if adding a new ACPI ID is a good idea. Actually we are talking about the same devices. The only difference is in the communication protocol between PSP and CPU. This could be easily detected at runtime by checking cpu id. There is no need to introduce a new id and create dependency on the FW version.
thanks,
greg
czw., 2 mar 2023 o 20:43 Mario Limonciello <[email protected]> napisał(a):
Quoted 101 lines
Skyrim doesn't use the platform feature mailbox for communication for I2C arbitration, it relies upon ringing a doorbell.
Add a new ACPI ID to use for Skyrim and when that ID is detected use the doorbell instead.
Signed-off-by Mario Limonciello <[email protected]>---
v1->v2:
* New patch
Note: This ACPI ID hasn't currently been reserved, but as Skyrim runs coreboot it should be easy enough to modify the BIOS and test it out.
If this approach works and has general agreement it can be reserved.--- drivers/i2c/busses/i2c-designware-amdpsp.c | 29 ++++++++++++++------- drivers/i2c/busses/i2c-designware-platdrv.c | 1 + 2 files changed, 20 insertions(+), 10 deletions(-)drivers/i2c/busses/i2c-designware-amdpsp.c +19
-10@@ -73,34 +73,44 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req)return check_i2c_req_sts (req); } -static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +static int psp_send_i2c_req_amdi0019 (enum psp_i2c_req_type i2c_req_type) {struct psp_i2c_req *req; -unsigned long start;int status, ret;/* Allocate command-response buffer */ req =kzalloc (sizeof (*req),GFP_KERNEL );if (!req)return -ENOMEM ; - req->hdr.payload_size =sizeof (*req); req->type = i2c_req_type; - - start = jiffies; ret =read_poll_timeout (psp_send_check_i2c_req, status, (status != -EBUSY ),PSP_I2C_REQ_RETRY_DELAY_US ,PSP_I2C_REQ_RETRY_CNT *PSP_I2C_REQ_RETRY_DELAY_US ,0 , req); -if (ret) { +kfree (req); + +if (ret)dev_err (psp_i2c_dev,"Timed out waiting for PSP to %s I2C bus\n" , (i2c_req_type ==PSP_I2C_REQ_ACQUIRE ) ?"release" :"acquire" ); - goto cleanup; - } - ret = status; +return ret ? ret : status; +} + +static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +{ +const char *hid =acpi_device_hid (ACPI_COMPANION (psp_i2c_dev)); +unsigned long start = jiffies; +int ret; + +/* Use doorbell for Skyrim and mailbox for Cezanne */ +if (!strcmp (hid,"AMDI0020" )) + ret =psp_ring_platform_doorbell (i2c_req_type); +else + ret =psp_send_i2c_req_amdi0019 (i2c_req_type); +if (ret) {dev_err (psp_i2c_dev,"PSP communication error\n" ); goto cleanup;@@ -115,7 +125,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) psp_i2c_mbox_fail = true; } -kfree (req);return ret; }drivers/i2c/busses/i2c-designware-platdrv.c +1
-1@@ -51,6 +51,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = { { "AMD0010", ACCESS_INTR_MASK }, { "AMDI0010", ACCESS_INTR_MASK }, { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, + { "AMDI0020", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, { "AMDI0510", 0 }, { "APMC0D0F", 0 }, { "HISI02A1", 0 }, --2.34.1
Limonciello, Mario
maintainerRE: [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim
[Public]
Quoted 13 lines
-----Original Message-----
From: Grzegorz Bernacki <[email protected]>
Sent: Friday, March 3, 2023 06:00
To: Limonciello, Mario <[email protected]>
Cc: Jan Dąbroś <[email protected]>; Thomas, Rijo-john <Rijo- [email protected]>; Lendacky, Thomas <[email protected]>; [email protected]; Jarkko Nikula <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim
Quoted 7 lines
Hi Mario,
I am not sure if adding a new ACPI ID is a good idea. Actually we are talking about the same devices. The only difference is in the communication protocol between PSP and CPU. This could be easily detected at runtime by checking cpu id. There is no need to introduce a new id and create dependency on the FW version.
An ACPI ID seems more scalable to me to represent the difference in protocol. Otherwise what happens when the follow on to Skyrim comes? Do you add a new ID/case to the code? If it was an ACPI ID then it's a one line change in the firmware to represent this.
What I'll do for v3 is do with a CPU ID in this patch, and then introduce an ACPI ID in a new patch. You can test it without the ACPI ID, and when it's working patch the BIOS with the new ID and see if that continues to work.
Quoted 116 lines
thanks,
gregczw., 2 mar 2023 o 20:43 Mario Limonciello <[email protected]> napisał(a):
Quoted 8 lines
Skyrim doesn't use the platform feature mailbox for communication for I2C arbitration, it relies upon ringing a doorbell.
Add a new ACPI ID to use for Skyrim and when that ID is detected use the doorbell instead.
Quoted 5 lines
Signed-off-by Mario Limonciello <[email protected]>---
v1->v2:
* New patch
Note: This ACPI ID hasn't currently been reserved, but as Skyrim runscoreboot
Review
Quoted 8 lines
it should be easy enough to modify the BIOS and test it out. If this approach works and has general agreement it can be reserved.
--- drivers/i2c/busses/i2c-designware-amdpsp.c | 29 ++++++++++++++------- drivers/i2c/busses/i2c-designware-platdrv.c | 1 + 2 files changed, 20 insertions(+), 10 deletions(-)(quoted diff) +0
-0
b/drivers/i2c/busses/i2c-designware-amdpsp.cdrivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_check_i2c_req(struct
Quoted 4 lines
index
105584abcf8f..e1a4d3002c80100644drivers/i2c/busses/i2c-designware-amdpsp.c +0
-0@@ -73,34 +73,44 @@ static int psp_send_check_i2c_req(struct
psp_i2c_req*req)drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_check_i2c_req(struct psp_i2c_req *req)
Quoted 5 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +1
-1return check_i2c_req_sts (req); } -static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +static int psp_send_i2c_req_amdi0019(enum psp_i2c_req_type
i2c_req_type)Quoted 8 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +0
-1{struct psp_i2c_req *req; -unsigned long start;int status, ret;/* Allocate command-response buffer */ req =kzalloc (sizeof (*req),GFP_KERNEL );if (!req)drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_check_i2c_req(struct psp_i2c_req *req)
Quoted 10 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +0
-3return -ENOMEM ; - req->hdr.payload_size =sizeof (*req); req->type = i2c_req_type; - - start = jiffies; ret = read_poll_timeout(psp_send_check_i2c_req, status, (status != -EBUSY), PSP_I2C_REQ_RETRY_DELAY_US, PSP_I2C_REQ_RETRY_CNT *
PSP_I2C_REQ_RETRY_DELAY_US,drivers/i2c/busses/i2c-designware-amdpsp.c static int psp_send_i2c_req(enum
Quoted 31 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +18
-40, req); -if (ret) { +kfree (req); + +if (ret)dev_err (psp_i2c_dev,"Timed out waiting for PSP to %s I2C bus\n" , (i2c_req_type ==PSP_I2C_REQ_ACQUIRE ) ?"release" :"acquire" ); - goto cleanup; - } - ret = status; +return ret ? ret : status; +} + +static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type) +{ +const char *hid =acpi_device_hid (ACPI_COMPANION (psp_i2c_dev)); +unsigned long start = jiffies; +int ret; + +/* Use doorbell for Skyrim and mailbox for Cezanne */ +if (!strcmp (hid,"AMDI0020" )) + ret =psp_ring_platform_doorbell (i2c_req_type); +else + ret =psp_send_i2c_req_amdi0019 (i2c_req_type); +if (ret) {dev_err (psp_i2c_dev,"PSP communication error\n" ); goto cleanup;@@ -115,7 +125,6 @@ static int psp_send_i2c_req(enum
psp_i2c_req_typei2c_req_type)Review
Quoted 8 lines
drivers/i2c/busses/i2c-designware-amdpsp.c +0
-1psp_i2c_mbox_fail = true; } -kfree (req);return ret; }(quoted diff) +0
-0
b/drivers/i2c/busses/i2c-designware-platdrv.cdrivers/i2c/busses/i2c-designware-platdrv.c static const struct acpi_device_id
Quoted 4 lines
index
89ad88c54754..5ca71bda9ac2100644drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -51,6 +51,7 @@ static const struct acpi_device_iddw_i2c_acpi_match[] = {
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1{ "AMD0010", ACCESS_INTR_MASK }, { "AMDI0010", ACCESS_INTR_MASK }, { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, + { "AMDI0020", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, { "AMDI0510", 0 }, { "APMC0D0F", 0 }, { "HISI02A1", 0 }, --2.34.1
Andy Shevchenko
reviewerRe: [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim
Quoted 10 lines · Mario
Quoted 9 lines
-----Original Message-----
From: Grzegorz Bernacki <[email protected]>
Sent: Friday, March 3, 2023 06:00I am not sure if adding a new ACPI ID is a good idea. Actually we are talking about the same devices. The only difference is in the communication protocol between PSP and CPU. This could be easily detected at runtime by checking cpu id. There is no need to introduce a new id and create dependency on the FW version.
Quoted 8 lines
An ACPI ID seems more scalable to me to represent the difference in protocol. Otherwise what happens when the follow on to Skyrim comes? Do you add a new ID/case to the code? If it was an ACPI ID then it's a one line change in the firmware to represent this.
What I'll do for v3 is do with a CPU ID in this patch, and then introduce an ACPI ID in a new patch. You can test it without the ACPI ID, and when it's working patch the BIOS with the new ID and see if that continues to work.
I don't think we need this complexity.
Please, use just an ACPI ID and that's it. For testing one may apply additional (HACK) patch(es).
As telling from my experience, to distinguish such things via CPU ID is a bad idea. Yes, we (used?) to have a PITA (find yourself what this stands for :) times with the (mixed) approach. So, no, please don't add CPU ID into the I²C platform driver (keyword: platform).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mario Limonciello
maintainerPATCH v2 9/9 crypto: ccp: Add doorbell register offset
In reply to Mario LimoncielloThe PSP in Skyrim uses i2c arbitration with a doorbell. Add this offset so that the communication can work.
---v1->v2:
* New patch
--- drivers/crypto/ccp/sp-pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/ccp/sp-pci.c +1 -0
@@ -365,6 +365,7 @@ 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_reg = 0x10a40, /* C2PMSG_80 */ };static const struct psp_vdata pspv1 = {
Signature · 1 line
2.34.1
Re: [PATCH v2 9/9] crypto: ccp: Add doorbell register offset
Hi Mario,
It won't work as expected since the Skyrim device has a different offset of cmdresp_reg, which is 0x10a40 and doorbell is actually 0x10a24. I apologize for giving you the wrong values. thanks,
greg
czw., 2 mar 2023 o 20:43 Mario Limonciello <[email protected]> napisał(a):
Quoted 28 lines
The PSP in Skyrim uses i2c arbitration with a doorbell. Add this offset so that the communication can work.
Signed-off-by Mario Limonciello <[email protected]>---
v1->v2:
* New patch--- drivers/crypto/ccp/sp-pci.c | 1 + 1 file changed, 1 insertion(+)drivers/crypto/ccp/sp-pci.c +1
-1@@ -365,6 +365,7 @@ 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_reg = 0x10a40, /* C2PMSG_80 */ };static const struct psp_vdata pspv1 = { --2.34.1