2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #include <linux/kernel.h>
18 #include <linux/fips.h>
20 #include "ssi_config.h"
21 #include "ssi_driver.h"
25 static void fips_dsr(unsigned long devarg);
27 struct ssi_fips_handle {
28 struct tasklet_struct tasklet;
31 /* The function called once at driver entry point to check
32 * whether TEE FIPS error occurred.
34 static bool cc_get_tee_fips_status(struct ssi_drvdata *drvdata)
37 void __iomem *cc_base = drvdata->cc_base;
39 reg = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, GPR_HOST));
40 return (reg == (CC_FIPS_SYNC_TEE_STATUS | CC_FIPS_SYNC_MODULE_OK));
44 * This function should push the FIPS REE library status towards the TEE library
45 * by writing the error state to HOST_GPR0 register.
47 void cc_set_ree_fips_status(struct ssi_drvdata *drvdata, bool status)
49 void __iomem *cc_base = drvdata->cc_base;
50 int val = CC_FIPS_SYNC_REE_STATUS;
52 val |= (status ? CC_FIPS_SYNC_MODULE_OK : CC_FIPS_SYNC_MODULE_ERROR);
54 CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_GPR0), val);
57 void ssi_fips_fini(struct ssi_drvdata *drvdata)
59 struct ssi_fips_handle *fips_h = drvdata->fips_handle;
62 return; /* Not allocated */
65 tasklet_kill(&fips_h->tasklet);
68 drvdata->fips_handle = NULL;
71 void fips_handler(struct ssi_drvdata *drvdata)
73 struct ssi_fips_handle *fips_handle_ptr =
76 tasklet_schedule(&fips_handle_ptr->tasklet);
79 static inline void tee_fips_error(void)
82 panic("ccree: TEE reported cryptographic error in fips mode!\n");
84 SSI_LOG_ERR("TEE reported error!\n");
87 /* Deferred service handler, run as interrupt-fired tasklet */
88 static void fips_dsr(unsigned long devarg)
90 struct ssi_drvdata *drvdata = (struct ssi_drvdata *)devarg;
91 void __iomem *cc_base = drvdata->cc_base;
94 irq = (drvdata->irq & (SSI_GPR0_IRQ_MASK));
97 state = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, GPR_HOST));
99 if (state != (CC_FIPS_SYNC_TEE_STATUS | CC_FIPS_SYNC_MODULE_OK))
103 /* after verifing that there is nothing to do,
104 * unmask AXI completion interrupt.
106 val = (CC_REG_OFFSET(HOST_RGF, HOST_IMR) & ~irq);
107 CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR), val);
110 /* The function called once at driver entry point .*/
111 int ssi_fips_init(struct ssi_drvdata *p_drvdata)
113 struct ssi_fips_handle *fips_h;
115 fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL);
119 p_drvdata->fips_handle = fips_h;
121 SSI_LOG_DEBUG("Initializing fips tasklet\n");
122 tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata);
124 if (!cc_get_tee_fips_status(p_drvdata))