Skip to content

Commit 0489929

Browse files
horiagherbertx
authored andcommitted
crypto: caam - OP-TEE firmware support
caam driver needs to be aware of OP-TEE f/w presence, since some things are done differently: 1. there is no access to controller's register page (note however that some registers are aliased in job rings' register pages) 2 Due to this, MCFGR[PS] cannot be read and driver assumes MCFGR[PS] = b'0 - engine using 32-bit address pointers. This is in sync with the fact that: -all i.MX SoCs currently use MCFGR[PS] = b'0 -only i.MX OP-TEE use cases don't allow access to controller register page Signed-off-by: Horia GeantA <[email protected]> Signed-off-by: Meenakshi Aggarwal <[email protected]> Reviewed-by: Gaurav Jain <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ae1dd17 commit 0489929

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

drivers/crypto/caam/ctrl.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ static int caam_probe(struct platform_device *pdev)
635635
int pg_size;
636636
int BLOCK_OFFSET = 0;
637637
bool pr_support = false;
638+
bool reg_access = true;
638639

639640
ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
640641
if (!ctrlpriv)
@@ -648,6 +649,17 @@ static int caam_probe(struct platform_device *pdev)
648649
caam_imx = (bool)imx_soc_match;
649650

650651
if (imx_soc_match) {
652+
/*
653+
* Until Layerscape and i.MX OP-TEE get in sync,
654+
* only i.MX OP-TEE use cases disallow access to
655+
* caam page 0 (controller) registers.
656+
*/
657+
np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz");
658+
ctrlpriv->optee_en = !!np;
659+
of_node_put(np);
660+
661+
reg_access = !ctrlpriv->optee_en;
662+
651663
if (!imx_soc_match->data) {
652664
dev_err(dev, "No clock data provided for i.MX SoC");
653665
return -EINVAL;
@@ -698,7 +710,8 @@ static int caam_probe(struct platform_device *pdev)
698710
caam_little_end = !(bool)(rd_reg32(&perfmon->status) &
699711
(CSTA_PLEND | CSTA_ALT_PLEND));
700712
comp_params = rd_reg32(&perfmon->comp_parms_ms);
701-
if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
713+
if (reg_access && comp_params & CTPR_MS_PS &&
714+
rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
702715
caam_ptr_sz = sizeof(u64);
703716
else
704717
caam_ptr_sz = sizeof(u32);
@@ -763,6 +776,9 @@ static int caam_probe(struct platform_device *pdev)
763776
}
764777
#endif
765778

779+
if (!reg_access)
780+
goto set_dma_mask;
781+
766782
/*
767783
* Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
768784
* long pointers in master configuration register.
@@ -802,6 +818,7 @@ static int caam_probe(struct platform_device *pdev)
802818
JRSTART_JR1_START | JRSTART_JR2_START |
803819
JRSTART_JR3_START);
804820

821+
set_dma_mask:
805822
ret = dma_set_mask_and_coherent(dev, caam_get_dma_mask(dev));
806823
if (ret) {
807824
dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
@@ -844,6 +861,9 @@ static int caam_probe(struct platform_device *pdev)
844861
return -ENOMEM;
845862
}
846863

864+
if (!reg_access)
865+
goto report_live;
866+
847867
comp_params = rd_reg32(&perfmon->comp_parms_ls);
848868
ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB);
849869

@@ -946,6 +966,7 @@ static int caam_probe(struct platform_device *pdev)
946966
clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE);
947967
}
948968

969+
report_live:
949970
/* NOTE: RTIC detection ought to go here, around Si time */
950971

951972
caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 |

drivers/crypto/caam/debugfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void caam_debugfs_init(struct caam_drv_private *ctrlpriv,
7777
debugfs_create_file("fault_status", 0444, ctrlpriv->ctl,
7878
&perfmon->status, &caam_fops_u32_ro);
7979

80+
if (ctrlpriv->optee_en)
81+
return;
82+
8083
/* Internal covering keys (useful in non-secure mode only) */
8184
ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0];
8285
ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);

drivers/crypto/caam/intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct caam_drv_private {
9494
u8 qi_present; /* Nonzero if QI present in device */
9595
u8 blob_present; /* Nonzero if BLOB support present in device */
9696
u8 mc_en; /* Nonzero if MC f/w is active */
97+
u8 optee_en; /* Nonzero if OP-TEE f/w is active */
9798
int secvio_irq; /* Security violation interrupt number */
9899
int virt_en; /* Virtualization enabled in CAAM */
99100
int era; /* CAAM Era (internal HW revision) */

0 commit comments

Comments
 (0)