Skip to content

Commit 654f2b9

Browse files
Fabio Estevamherbertx
authored andcommitted
crypto: caam - allow retrieving 'era' from register
The 'era' information can be retrieved from CAAM registers, so introduce a caam_get_era_from_hw() function that gets it via register reads in case the 'fsl,sec-era' property is not passed in the device tree. This function is based on the U-Boot implementation from drivers/crypto/fsl/sec.c Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Tested-by: Breno Lima <breno.lima@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent b0039c0 commit 654f2b9

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

drivers/crypto/caam/ctrl.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,56 @@ static void kick_trng(struct platform_device *pdev, int ent_delay)
396396
clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
397397
}
398398

399+
static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
400+
{
401+
static const struct {
402+
u16 ip_id;
403+
u8 maj_rev;
404+
u8 era;
405+
} id[] = {
406+
{0x0A10, 1, 1},
407+
{0x0A10, 2, 2},
408+
{0x0A12, 1, 3},
409+
{0x0A14, 1, 3},
410+
{0x0A14, 2, 4},
411+
{0x0A16, 1, 4},
412+
{0x0A10, 3, 4},
413+
{0x0A11, 1, 4},
414+
{0x0A18, 1, 4},
415+
{0x0A11, 2, 5},
416+
{0x0A12, 2, 5},
417+
{0x0A13, 1, 5},
418+
{0x0A1C, 1, 5}
419+
};
420+
u32 ccbvid, id_ms;
421+
u8 maj_rev, era;
422+
u16 ip_id;
423+
int i;
424+
425+
ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
426+
era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
427+
if (era) /* This is '0' prior to CAAM ERA-6 */
428+
return era;
429+
430+
id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
431+
ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
432+
maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
433+
434+
for (i = 0; i < ARRAY_SIZE(id); i++)
435+
if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
436+
return id[i].era;
437+
438+
return -ENOTSUPP;
439+
}
440+
399441
/**
400442
* caam_get_era() - Return the ERA of the SEC on SoC, based
401-
* on "sec-era" propery in the DTS. This property is updated by u-boot.
443+
* on "sec-era" optional property in the DTS. This property is updated
444+
* by u-boot.
445+
* In case this property is not passed an attempt to retrieve the CAAM
446+
* era via register reads will be made.
402447
**/
403-
static int caam_get_era(void)
448+
static int caam_get_era(struct caam_ctrl __iomem *ctrl)
404449
{
405450
struct device_node *caam_node;
406451
int ret;
@@ -410,7 +455,10 @@ static int caam_get_era(void)
410455
ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
411456
of_node_put(caam_node);
412457

413-
return ret ? -ENOTSUPP : prop;
458+
if (!ret)
459+
return prop;
460+
else
461+
return caam_get_era_from_hw(ctrl);
414462
}
415463

416464
static const struct of_device_id caam_match[] = {
@@ -622,7 +670,7 @@ static int caam_probe(struct platform_device *pdev)
622670
goto iounmap_ctrl;
623671
}
624672

625-
ctrlpriv->era = caam_get_era();
673+
ctrlpriv->era = caam_get_era(ctrl);
626674

627675
ret = of_platform_populate(nprop, caam_match, NULL, dev);
628676
if (ret) {

drivers/crypto/caam/regs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,17 @@ struct caam_perfmon {
312312

313313
/* Component Instantiation Parameters fe0-fff */
314314
u32 rtic_id; /* RVID - RTIC Version ID */
315+
#define CCBVID_ERA_MASK 0xff000000
316+
#define CCBVID_ERA_SHIFT 24
315317
u32 ccb_id; /* CCBVID - CCB Version ID */
316318
u32 cha_id_ms; /* CHAVID - CHA Version ID Most Significant*/
317319
u32 cha_id_ls; /* CHAVID - CHA Version ID Least Significant*/
318320
u32 cha_num_ms; /* CHANUM - CHA Number Most Significant */
319321
u32 cha_num_ls; /* CHANUM - CHA Number Least Significant*/
322+
#define SECVID_MS_IPID_MASK 0xffff0000
323+
#define SECVID_MS_IPID_SHIFT 16
324+
#define SECVID_MS_MAJ_REV_MASK 0x0000ff00
325+
#define SECVID_MS_MAJ_REV_SHIFT 8
320326
u32 caam_id_ms; /* CAAMVID - CAAM Version ID MS */
321327
u32 caam_id_ls; /* CAAMVID - CAAM Version ID LS */
322328
};

0 commit comments

Comments
 (0)