Move CMA DOE discovery out of pci_tsm_pf0_constructor(). An external Endpoint requires a mailbox, while an RcIEP can use device assignment without DOE. Let each TSM driver enforce its own requirement. Keep SEV-TIO requiring a CMA mailbox and reject devices without one. A later patch adds the CCA host driver's mailbox checks, allowing RcIEPs to operate without DOE. Signed-off-by: Aneesh Kumar K.V (Arm) --- drivers/crypto/ccp/sev-dev-tsm.c | 7 ++++++ drivers/pci/tsm.c | 39 ++++++++++++++++---------------- include/linux/pci-tsm.h | 4 ++-- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev-tsm.c b/drivers/crypto/ccp/sev-dev-tsm.c index 5c61ce74ee0f..af22f36a2318 100644 --- a/drivers/crypto/ccp/sev-dev-tsm.c +++ b/drivers/crypto/ccp/sev-dev-tsm.c @@ -213,6 +213,13 @@ static struct pci_tsm *tio_pf0_probe(struct pci_dev *pdev, struct sev_device *se if (!dsm) return NULL; + dsm->tsm.doe_mb = pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG, + PCI_DOE_FEATURE_CMA); + if (!dsm->tsm.doe_mb) { + pci_warn(pdev, "TSM init failure, no CMA mailbox\n"); + return NULL; + } + rc = pci_tsm_pf0_constructor(pdev, &dsm->tsm, sev->tsmdev); if (rc) return NULL; diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c index 5ff1265714aa..2be92bde8780 100644 --- a/drivers/pci/tsm.c +++ b/drivers/pci/tsm.c @@ -714,30 +714,31 @@ EXPORT_SYMBOL_GPL(pci_tsm_link_constructor); /** * pci_tsm_pf0_constructor() - common 'struct pci_tsm_pf0' (DSM) initialization * @pdev: Physical Function 0 PCI device (as indicated by is_pci_tsm_pf0()) - * @tsm: context to initialize + * @pf0: PF0 state to initialize * @tsm_dev: Platform TEE Security Manager, initiator of security operations */ -int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *tsm, +int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0, struct tsm_dev *tsm_dev) { - mutex_init(&tsm->lock); - init_completion(&tsm->dsm_context_drain_complete); - tsm->dsm_context_users = 0; - tsm->removing = false; - tsm->doe_mb = pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG, - PCI_DOE_FEATURE_CMA); - if (!tsm->doe_mb) { - pci_warn(pdev, "TSM init failure, no CMA mailbox\n"); - return -ENODEV; - } + mutex_init(&pf0->lock); + init_completion(&pf0->dsm_context_drain_complete); + pf0->dsm_context_users = 0; + pf0->removing = false; + /* + * Note, low-level TSM driver responsible for determining if it wants to + * proceed with a device that has no DOE mailbox. TSM may have an + * alternate method for coordinating TDISP. + */ + if (!pf0->doe_mb) + pci_dbg(pdev, "No DOE mailbox for Component Measurement and Authentication\n"); - return pci_tsm_link_constructor(pdev, &tsm->base_tsm, tsm_dev); + return pci_tsm_link_constructor(pdev, &pf0->base_tsm, tsm_dev); } EXPORT_SYMBOL_GPL(pci_tsm_pf0_constructor); -void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0_tsm) +void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0) { - mutex_destroy(&pf0_tsm->lock); + mutex_destroy(&pf0->lock); } EXPORT_SYMBOL_GPL(pci_tsm_pf0_destructor); @@ -954,16 +955,16 @@ void pci_tsm_unregister(struct tsm_dev *tsm_dev) int pci_tsm_doe_transfer(struct pci_dev *pdev, u8 type, const void *req, size_t req_sz, void *resp, size_t resp_sz) { - struct pci_tsm_pf0 *tsm; + struct pci_tsm_pf0 *pf0; if (!pdev->tsm || !is_pci_tsm_pf0(pdev)) return -ENXIO; - tsm = to_pci_tsm_pf0(pdev->tsm); - if (!tsm->doe_mb) + pf0 = to_pci_tsm_pf0(pdev->tsm); + if (!pf0->doe_mb) return -ENXIO; - return pci_doe(tsm->doe_mb, PCI_VENDOR_ID_PCI_SIG, type, req, req_sz, + return pci_doe(pf0->doe_mb, PCI_VENDOR_ID_PCI_SIG, type, req, req_sz, resp, resp_sz); } EXPORT_SYMBOL_GPL(pci_tsm_doe_transfer); diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h index 68ebe774121b..7e91c15ffe3b 100644 --- a/include/linux/pci-tsm.h +++ b/include/linux/pci-tsm.h @@ -160,9 +160,9 @@ int pci_tsm_register(struct tsm_dev *tsm_dev); void pci_tsm_unregister(struct tsm_dev *tsm_dev); int pci_tsm_link_constructor(struct pci_dev *pdev, struct pci_tsm *tsm, struct tsm_dev *tsm_dev); -int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *tsm, +int pci_tsm_pf0_constructor(struct pci_dev *pdev, struct pci_tsm_pf0 *pf0, struct tsm_dev *tsm_dev); -void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *tsm); +void pci_tsm_pf0_destructor(struct pci_tsm_pf0 *pf0); int pci_tsm_doe_transfer(struct pci_dev *pdev, u8 type, const void *req, size_t req_sz, void *resp, size_t resp_sz); bool pci_tsm_is_configured(struct pci_dev *pdev); -- 2.43.0