Linux 4.19.133
[linux/fpc-iii.git] / drivers / crypto / ccree / cc_fips.c
blobbac278d274b0fde15e711c950f45e02e3c151c85
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
4 #include <linux/kernel.h>
5 #include <linux/fips.h>
7 #include "cc_driver.h"
8 #include "cc_fips.h"
10 static void fips_dsr(unsigned long devarg);
12 struct cc_fips_handle {
13 struct tasklet_struct tasklet;
16 /* The function called once at driver entry point to check
17 * whether TEE FIPS error occurred.
19 static bool cc_get_tee_fips_status(struct cc_drvdata *drvdata)
21 u32 reg;
23 reg = cc_ioread(drvdata, CC_REG(GPR_HOST));
24 /* Did the TEE report status? */
25 if (reg & CC_FIPS_SYNC_TEE_STATUS)
26 /* Yes. Is it OK? */
27 return (reg & CC_FIPS_SYNC_MODULE_OK);
29 /* No. It's either not in use or will be reported later */
30 return true;
34 * This function should push the FIPS REE library status towards the TEE library
35 * by writing the error state to HOST_GPR0 register.
37 void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool status)
39 int val = CC_FIPS_SYNC_REE_STATUS;
41 if (drvdata->hw_rev < CC_HW_REV_712)
42 return;
44 val |= (status ? CC_FIPS_SYNC_MODULE_OK : CC_FIPS_SYNC_MODULE_ERROR);
46 cc_iowrite(drvdata, CC_REG(HOST_GPR0), val);
49 void cc_fips_fini(struct cc_drvdata *drvdata)
51 struct cc_fips_handle *fips_h = drvdata->fips_handle;
53 if (drvdata->hw_rev < CC_HW_REV_712 || !fips_h)
54 return;
56 /* Kill tasklet */
57 tasklet_kill(&fips_h->tasklet);
59 kfree(fips_h);
60 drvdata->fips_handle = NULL;
63 void fips_handler(struct cc_drvdata *drvdata)
65 struct cc_fips_handle *fips_handle_ptr = drvdata->fips_handle;
67 if (drvdata->hw_rev < CC_HW_REV_712)
68 return;
70 tasklet_schedule(&fips_handle_ptr->tasklet);
73 static inline void tee_fips_error(struct device *dev)
75 if (fips_enabled)
76 panic("ccree: TEE reported cryptographic error in fips mode!\n");
77 else
78 dev_err(dev, "TEE reported error!\n");
82 * This function check if cryptocell tee fips error occurred
83 * and in such case triggers system error
85 void cc_tee_handle_fips_error(struct cc_drvdata *p_drvdata)
87 struct device *dev = drvdata_to_dev(p_drvdata);
89 if (!cc_get_tee_fips_status(p_drvdata))
90 tee_fips_error(dev);
93 /* Deferred service handler, run as interrupt-fired tasklet */
94 static void fips_dsr(unsigned long devarg)
96 struct cc_drvdata *drvdata = (struct cc_drvdata *)devarg;
97 u32 irq, val;
99 irq = (drvdata->irq & (CC_GPR0_IRQ_MASK));
101 if (irq) {
102 cc_tee_handle_fips_error(drvdata);
105 /* after verifing that there is nothing to do,
106 * unmask AXI completion interrupt.
108 val = (CC_REG(HOST_IMR) & ~irq);
109 cc_iowrite(drvdata, CC_REG(HOST_IMR), val);
112 /* The function called once at driver entry point .*/
113 int cc_fips_init(struct cc_drvdata *p_drvdata)
115 struct cc_fips_handle *fips_h;
116 struct device *dev = drvdata_to_dev(p_drvdata);
118 if (p_drvdata->hw_rev < CC_HW_REV_712)
119 return 0;
121 fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL);
122 if (!fips_h)
123 return -ENOMEM;
125 p_drvdata->fips_handle = fips_h;
127 dev_dbg(dev, "Initializing fips tasklet\n");
128 tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata);
130 cc_tee_handle_fips_error(p_drvdata);
132 return 0;