mm/hmm.c: remove superfluous RCU protection around radix tree lookup
[linux/fpc-iii.git] / drivers / crypto / ccree / cc_fips.c
blobb4d0a6d983e0cfe0c35653d3f087c36fc8090cf8
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 return (reg == (CC_FIPS_SYNC_TEE_STATUS | CC_FIPS_SYNC_MODULE_OK));
28 * This function should push the FIPS REE library status towards the TEE library
29 * by writing the error state to HOST_GPR0 register.
31 void cc_set_ree_fips_status(struct cc_drvdata *drvdata, bool status)
33 int val = CC_FIPS_SYNC_REE_STATUS;
35 if (drvdata->hw_rev < CC_HW_REV_712)
36 return;
38 val |= (status ? CC_FIPS_SYNC_MODULE_OK : CC_FIPS_SYNC_MODULE_ERROR);
40 cc_iowrite(drvdata, CC_REG(HOST_GPR0), val);
43 void cc_fips_fini(struct cc_drvdata *drvdata)
45 struct cc_fips_handle *fips_h = drvdata->fips_handle;
47 if (drvdata->hw_rev < CC_HW_REV_712 || !fips_h)
48 return;
50 /* Kill tasklet */
51 tasklet_kill(&fips_h->tasklet);
53 kfree(fips_h);
54 drvdata->fips_handle = NULL;
57 void fips_handler(struct cc_drvdata *drvdata)
59 struct cc_fips_handle *fips_handle_ptr = drvdata->fips_handle;
61 if (drvdata->hw_rev < CC_HW_REV_712)
62 return;
64 tasklet_schedule(&fips_handle_ptr->tasklet);
67 static inline void tee_fips_error(struct device *dev)
69 if (fips_enabled)
70 panic("ccree: TEE reported cryptographic error in fips mode!\n");
71 else
72 dev_err(dev, "TEE reported error!\n");
75 /* Deferred service handler, run as interrupt-fired tasklet */
76 static void fips_dsr(unsigned long devarg)
78 struct cc_drvdata *drvdata = (struct cc_drvdata *)devarg;
79 struct device *dev = drvdata_to_dev(drvdata);
80 u32 irq, state, val;
82 irq = (drvdata->irq & (CC_GPR0_IRQ_MASK));
84 if (irq) {
85 state = cc_ioread(drvdata, CC_REG(GPR_HOST));
87 if (state != (CC_FIPS_SYNC_TEE_STATUS | CC_FIPS_SYNC_MODULE_OK))
88 tee_fips_error(dev);
91 /* after verifing that there is nothing to do,
92 * unmask AXI completion interrupt.
94 val = (CC_REG(HOST_IMR) & ~irq);
95 cc_iowrite(drvdata, CC_REG(HOST_IMR), val);
98 /* The function called once at driver entry point .*/
99 int cc_fips_init(struct cc_drvdata *p_drvdata)
101 struct cc_fips_handle *fips_h;
102 struct device *dev = drvdata_to_dev(p_drvdata);
104 if (p_drvdata->hw_rev < CC_HW_REV_712)
105 return 0;
107 fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL);
108 if (!fips_h)
109 return -ENOMEM;
111 p_drvdata->fips_handle = fips_h;
113 dev_dbg(dev, "Initializing fips tasklet\n");
114 tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata);
116 if (!cc_get_tee_fips_status(p_drvdata))
117 tee_fips_error(dev);
119 return 0;