.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | | -/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */ |
---|
| 2 | +/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */ |
---|
3 | 3 | |
---|
4 | 4 | #include <linux/kernel.h> |
---|
5 | 5 | #include <linux/fips.h> |
---|
| 6 | +#include <linux/notifier.h> |
---|
6 | 7 | |
---|
7 | 8 | #include "cc_driver.h" |
---|
8 | 9 | #include "cc_fips.h" |
---|
.. | .. |
---|
11 | 12 | |
---|
12 | 13 | struct cc_fips_handle { |
---|
13 | 14 | struct tasklet_struct tasklet; |
---|
| 15 | + struct notifier_block nb; |
---|
| 16 | + struct cc_drvdata *drvdata; |
---|
14 | 17 | }; |
---|
15 | 18 | |
---|
16 | 19 | /* The function called once at driver entry point to check |
---|
.. | .. |
---|
46 | 49 | cc_iowrite(drvdata, CC_REG(HOST_GPR0), val); |
---|
47 | 50 | } |
---|
48 | 51 | |
---|
| 52 | +/* Push REE side FIPS test failure to TEE side */ |
---|
| 53 | +static int cc_ree_fips_failure(struct notifier_block *nb, unsigned long unused1, |
---|
| 54 | + void *unused2) |
---|
| 55 | +{ |
---|
| 56 | + struct cc_fips_handle *fips_h = |
---|
| 57 | + container_of(nb, struct cc_fips_handle, nb); |
---|
| 58 | + struct cc_drvdata *drvdata = fips_h->drvdata; |
---|
| 59 | + struct device *dev = drvdata_to_dev(drvdata); |
---|
| 60 | + |
---|
| 61 | + cc_set_ree_fips_status(drvdata, false); |
---|
| 62 | + dev_info(dev, "Notifying TEE of FIPS test failure...\n"); |
---|
| 63 | + |
---|
| 64 | + return NOTIFY_OK; |
---|
| 65 | +} |
---|
| 66 | + |
---|
49 | 67 | void cc_fips_fini(struct cc_drvdata *drvdata) |
---|
50 | 68 | { |
---|
51 | 69 | struct cc_fips_handle *fips_h = drvdata->fips_handle; |
---|
.. | .. |
---|
53 | 71 | if (drvdata->hw_rev < CC_HW_REV_712 || !fips_h) |
---|
54 | 72 | return; |
---|
55 | 73 | |
---|
| 74 | + atomic_notifier_chain_unregister(&fips_fail_notif_chain, &fips_h->nb); |
---|
| 75 | + |
---|
56 | 76 | /* Kill tasklet */ |
---|
57 | 77 | tasklet_kill(&fips_h->tasklet); |
---|
58 | | - |
---|
59 | | - kfree(fips_h); |
---|
60 | 78 | drvdata->fips_handle = NULL; |
---|
61 | 79 | } |
---|
62 | 80 | |
---|
.. | .. |
---|
102 | 120 | cc_tee_handle_fips_error(drvdata); |
---|
103 | 121 | } |
---|
104 | 122 | |
---|
105 | | - /* after verifing that there is nothing to do, |
---|
| 123 | + /* after verifying that there is nothing to do, |
---|
106 | 124 | * unmask AXI completion interrupt. |
---|
107 | 125 | */ |
---|
108 | 126 | val = (CC_REG(HOST_IMR) & ~irq); |
---|
.. | .. |
---|
118 | 136 | if (p_drvdata->hw_rev < CC_HW_REV_712) |
---|
119 | 137 | return 0; |
---|
120 | 138 | |
---|
121 | | - fips_h = kzalloc(sizeof(*fips_h), GFP_KERNEL); |
---|
| 139 | + fips_h = devm_kzalloc(dev, sizeof(*fips_h), GFP_KERNEL); |
---|
122 | 140 | if (!fips_h) |
---|
123 | 141 | return -ENOMEM; |
---|
124 | 142 | |
---|
.. | .. |
---|
126 | 144 | |
---|
127 | 145 | dev_dbg(dev, "Initializing fips tasklet\n"); |
---|
128 | 146 | tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata); |
---|
| 147 | + fips_h->drvdata = p_drvdata; |
---|
| 148 | + fips_h->nb.notifier_call = cc_ree_fips_failure; |
---|
| 149 | + atomic_notifier_chain_register(&fips_fail_notif_chain, &fips_h->nb); |
---|
129 | 150 | |
---|
130 | 151 | cc_tee_handle_fips_error(p_drvdata); |
---|
131 | 152 | |
---|