mbox series

[v2,0/9] Export platform features from ccp driver

Message ID 20230302194235.1724-1-mario.limonciello@amd.com
Headers show
Series Export platform features from ccp driver | expand

Message

Mario Limonciello March 2, 2023, 7:42 p.m. UTC
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

Comments

Tom Lendacky March 2, 2023, 9:51 p.m. UTC | #1
On 3/2/23 13:42, Mario Limonciello wrote:
> 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(+)
> 
> diff --git a/drivers/crypto/ccp/platform-access.c b/drivers/crypto/ccp/platform-access.c
> index af3a1e97abfe..0763389a2814 100644
> --- a/drivers/crypto/ccp/platform-access.c
> +++ b/drivers/crypto/ccp/platform-access.c
> @@ -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.

> +	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.

> +
> +	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.

> +
> +	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.

> +		ret = -EBUSY;
> +		goto unlock;
> +	}
> +
> +	if (wait_cmd(drbl)) {
> +		dev_dbg(psp->dev, "not done processing command\n");

Ditto.

Thanks,
Tom

> +		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;
> diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h
> index 5ec6c219a731..87c0b9350bc2 100644
> --- a/drivers/crypto/ccp/sp-dev.h
> +++ b/drivers/crypto/ccp/sp-dev.h
> @@ -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;
> 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 */
Mario Limonciello March 2, 2023, 9:55 p.m. UTC | #2
[Public]



> -----Original Message-----
> From: Lendacky, Thomas <Thomas.Lendacky@amd.com>
> Sent: Thursday, March 2, 2023 15:52
> To: Limonciello, Mario <Mario.Limonciello@amd.com>; Jan Dąbroś
> <jsd@semihalf.com>; Grzegorz Bernacki <gjb@semihalf.com>; Thomas, Rijo-
> john <Rijo-john.Thomas@amd.com>; herbert@gondor.apana.org.au; Allen,
> John <John.Allen@amd.com>
> Cc: David S. Miller <davem@davemloft.net>; linux-crypto@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2 7/9] crypto: ccp: Add support for ringing a platform
> doorbell
> 
> On 3/2/23 13:42, Mario Limonciello wrote:
> > 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(+)
> >
> > diff --git a/drivers/crypto/ccp/platform-access.c
> b/drivers/crypto/ccp/platform-access.c
> > index af3a1e97abfe..0763389a2814 100644
> > --- a/drivers/crypto/ccp/platform-access.c
> > +++ b/drivers/crypto/ccp/platform-access.c
> > @@ -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.

Ack.  Given drbl_reg is only used one place, I might just drop it too.

> 
> > +	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.

Ack, I'll squash them together.

> 
> > +
> > +	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.

> 
> > +
> > +	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.

> 
> > +		ret = -EBUSY;
> > +		goto unlock;
> > +	}
> > +
> > +	if (wait_cmd(drbl)) {
> > +		dev_dbg(psp->dev, "not done processing command\n");
> 
> Ditto.
> 
> 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.

> 
> > +		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;
> > diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h
> > index 5ec6c219a731..87c0b9350bc2 100644
> > --- a/drivers/crypto/ccp/sp-dev.h
> > +++ b/drivers/crypto/ccp/sp-dev.h
> > @@ -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;
> > 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 */
Rijo Thomas March 3, 2023, 10:31 a.m. UTC | #3
On 3/3/2023 1:12 AM, Mario Limonciello wrote:
> 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 <mario.limonciello@amd.com>

Looks good.

Acked-by: Rijo Thomas <Rijo-john.Thomas@amd.com>

Thanks,
Rijo

> ---
>  drivers/crypto/ccp/psp-dev.c | 15 ---------------
>  drivers/crypto/ccp/psp-dev.h |  7 -------
>  2 files changed, 22 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
> index c9c741ac8442..cd8d1974726a 100644
> --- a/drivers/crypto/ccp/psp-dev.c
> +++ b/drivers/crypto/ccp/psp-dev.c
> @@ -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();
> diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h
> index d528eb04c3ef..06e1f317216d 100644
> --- a/drivers/crypto/ccp/psp-dev.h
> +++ b/drivers/crypto/ccp/psp-dev.h
> @@ -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)