Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 2 | /* Copyright (C) 2012-2019 ARM Limited or its affiliates. */ |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 3 | |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/module.h> |
| 6 | |
| 7 | #include <linux/crypto.h> |
| 8 | #include <linux/moduleparam.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/of_address.h> |
Geert Uytterhoeven | 1b940e3 | 2020-02-11 19:19:09 +0100 | [diff] [blame^] | 17 | #include <linux/of_device.h> |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 18 | #include <linux/pm_runtime.h> |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 19 | |
| 20 | #include "cc_driver.h" |
| 21 | #include "cc_request_mgr.h" |
| 22 | #include "cc_buffer_mgr.h" |
| 23 | #include "cc_debugfs.h" |
Gilad Ben-Yossef | 63ee04c | 2018-01-22 09:27:01 +0000 | [diff] [blame] | 24 | #include "cc_cipher.h" |
Gilad Ben-Yossef | ff27e85 | 2018-01-22 09:27:03 +0000 | [diff] [blame] | 25 | #include "cc_aead.h" |
Gilad Ben-Yossef | 6389381 | 2018-01-22 09:27:02 +0000 | [diff] [blame] | 26 | #include "cc_hash.h" |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 27 | #include "cc_sram_mgr.h" |
| 28 | #include "cc_pm.h" |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 29 | #include "cc_fips.h" |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 30 | |
| 31 | bool cc_dump_desc; |
| 32 | module_param_named(dump_desc, cc_dump_desc, bool, 0600); |
| 33 | MODULE_PARM_DESC(cc_dump_desc, "Dump descriptors to kernel log as debugging aid"); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 34 | bool cc_dump_bytes; |
| 35 | module_param_named(dump_bytes, cc_dump_bytes, bool, 0600); |
| 36 | MODULE_PARM_DESC(cc_dump_bytes, "Dump buffers to kernel log as debugging aid"); |
| 37 | |
YueHaibing | 181a909 | 2019-04-27 00:43:13 +0800 | [diff] [blame] | 38 | static bool cc_sec_disable; |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 39 | module_param_named(sec_disable, cc_sec_disable, bool, 0600); |
| 40 | MODULE_PARM_DESC(cc_sec_disable, "Disable security functions"); |
| 41 | |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 42 | struct cc_hw_data { |
| 43 | char *name; |
| 44 | enum cc_hw_rev rev; |
| 45 | u32 sig; |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 46 | u32 cidr_0123; |
| 47 | u32 pidr_0124; |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 48 | int std_bodies; |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 51 | #define CC_NUM_IDRS 4 |
Ofir Drang | d84f626 | 2019-06-17 11:46:28 +0300 | [diff] [blame] | 52 | #define CC_HW_RESET_LOOP_COUNT 10 |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 53 | |
| 54 | /* Note: PIDR3 holds CMOD/Rev so ignored for HW identification purposes */ |
| 55 | static const u32 pidr_0124_offsets[CC_NUM_IDRS] = { |
| 56 | CC_REG(PERIPHERAL_ID_0), CC_REG(PERIPHERAL_ID_1), |
| 57 | CC_REG(PERIPHERAL_ID_2), CC_REG(PERIPHERAL_ID_4) |
| 58 | }; |
| 59 | |
| 60 | static const u32 cidr_0123_offsets[CC_NUM_IDRS] = { |
| 61 | CC_REG(COMPONENT_ID_0), CC_REG(COMPONENT_ID_1), |
| 62 | CC_REG(COMPONENT_ID_2), CC_REG(COMPONENT_ID_3) |
| 63 | }; |
| 64 | |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 65 | /* Hardware revisions defs. */ |
| 66 | |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 67 | /* The 703 is a OSCCA only variant of the 713 */ |
| 68 | static const struct cc_hw_data cc703_hw = { |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 69 | .name = "703", .rev = CC_HW_REV_713, .cidr_0123 = 0xB105F00DU, |
| 70 | .pidr_0124 = 0x040BB0D0U, .std_bodies = CC_STD_OSCCA |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 73 | static const struct cc_hw_data cc713_hw = { |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 74 | .name = "713", .rev = CC_HW_REV_713, .cidr_0123 = 0xB105F00DU, |
| 75 | .pidr_0124 = 0x040BB0D0U, .std_bodies = CC_STD_ALL |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 78 | static const struct cc_hw_data cc712_hw = { |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 79 | .name = "712", .rev = CC_HW_REV_712, .sig = 0xDCC71200U, |
| 80 | .std_bodies = CC_STD_ALL |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static const struct cc_hw_data cc710_hw = { |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 84 | .name = "710", .rev = CC_HW_REV_710, .sig = 0xDCC63200U, |
| 85 | .std_bodies = CC_STD_ALL |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | static const struct cc_hw_data cc630p_hw = { |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 89 | .name = "630P", .rev = CC_HW_REV_630, .sig = 0xDCC63000U, |
| 90 | .std_bodies = CC_STD_ALL |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | static const struct of_device_id arm_ccree_dev_of_match[] = { |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 94 | { .compatible = "arm,cryptocell-703-ree", .data = &cc703_hw }, |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 95 | { .compatible = "arm,cryptocell-713-ree", .data = &cc713_hw }, |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 96 | { .compatible = "arm,cryptocell-712-ree", .data = &cc712_hw }, |
| 97 | { .compatible = "arm,cryptocell-710-ree", .data = &cc710_hw }, |
| 98 | { .compatible = "arm,cryptocell-630p-ree", .data = &cc630p_hw }, |
| 99 | {} |
| 100 | }; |
| 101 | MODULE_DEVICE_TABLE(of, arm_ccree_dev_of_match); |
| 102 | |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 103 | static u32 cc_read_idr(struct cc_drvdata *drvdata, const u32 *idr_offsets) |
| 104 | { |
| 105 | int i; |
| 106 | union { |
| 107 | u8 regs[CC_NUM_IDRS]; |
Gilad Ben-Yossef | e59f755 | 2019-04-28 11:33:22 +0300 | [diff] [blame] | 108 | __le32 val; |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 109 | } idr; |
| 110 | |
| 111 | for (i = 0; i < CC_NUM_IDRS; ++i) |
| 112 | idr.regs[i] = cc_ioread(drvdata, idr_offsets[i]); |
| 113 | |
| 114 | return le32_to_cpu(idr.val); |
| 115 | } |
| 116 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 117 | void __dump_byte_array(const char *name, const u8 *buf, size_t len) |
| 118 | { |
| 119 | char prefix[64]; |
| 120 | |
| 121 | if (!buf) |
| 122 | return; |
| 123 | |
| 124 | snprintf(prefix, sizeof(prefix), "%s[%zu]: ", name, len); |
| 125 | |
| 126 | print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_ADDRESS, 16, 1, buf, |
| 127 | len, false); |
| 128 | } |
| 129 | |
| 130 | static irqreturn_t cc_isr(int irq, void *dev_id) |
| 131 | { |
| 132 | struct cc_drvdata *drvdata = (struct cc_drvdata *)dev_id; |
| 133 | struct device *dev = drvdata_to_dev(drvdata); |
| 134 | u32 irr; |
| 135 | u32 imr; |
| 136 | |
| 137 | /* STAT_OP_TYPE_GENERIC STAT_PHASE_0: Interrupt */ |
Hadar Gat | e86eca4 | 2019-11-27 10:49:06 +0200 | [diff] [blame] | 138 | /* if driver suspended return, probably shared interrupt */ |
Ofir Drang | 3db617e | 2019-06-17 11:46:29 +0300 | [diff] [blame] | 139 | if (cc_pm_is_dev_suspended(dev)) |
| 140 | return IRQ_NONE; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 141 | |
| 142 | /* read the interrupt status */ |
| 143 | irr = cc_ioread(drvdata, CC_REG(HOST_IRR)); |
| 144 | dev_dbg(dev, "Got IRR=0x%08X\n", irr); |
Gilad Ben-Yossef | 27649c3 | 2019-01-15 15:43:16 +0200 | [diff] [blame] | 145 | |
| 146 | if (irr == 0) /* Probably shared interrupt line */ |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 147 | return IRQ_NONE; |
Gilad Ben-Yossef | 27649c3 | 2019-01-15 15:43:16 +0200 | [diff] [blame] | 148 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 149 | imr = cc_ioread(drvdata, CC_REG(HOST_IMR)); |
| 150 | |
| 151 | /* clear interrupt - must be before processing events */ |
| 152 | cc_iowrite(drvdata, CC_REG(HOST_ICR), irr); |
| 153 | |
| 154 | drvdata->irq = irr; |
| 155 | /* Completion interrupt - most probable */ |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 156 | if (irr & drvdata->comp_mask) { |
| 157 | /* Mask all completion interrupts - will be unmasked in |
| 158 | * deferred service handler |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 159 | */ |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 160 | cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | drvdata->comp_mask); |
| 161 | irr &= ~drvdata->comp_mask; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 162 | complete_request(drvdata); |
| 163 | } |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 164 | #ifdef CONFIG_CRYPTO_FIPS |
| 165 | /* TEE FIPS interrupt */ |
| 166 | if (irr & CC_GPR0_IRQ_MASK) { |
| 167 | /* Mask interrupt - will be unmasked in Deferred service |
| 168 | * handler |
| 169 | */ |
| 170 | cc_iowrite(drvdata, CC_REG(HOST_IMR), imr | CC_GPR0_IRQ_MASK); |
| 171 | irr &= ~CC_GPR0_IRQ_MASK; |
| 172 | fips_handler(drvdata); |
| 173 | } |
| 174 | #endif |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 175 | /* AXI error interrupt */ |
| 176 | if (irr & CC_AXI_ERR_IRQ_MASK) { |
| 177 | u32 axi_err; |
| 178 | |
| 179 | /* Read the AXI error ID */ |
| 180 | axi_err = cc_ioread(drvdata, CC_REG(AXIM_MON_ERR)); |
| 181 | dev_dbg(dev, "AXI completion error: axim_mon_err=0x%08X\n", |
| 182 | axi_err); |
| 183 | |
| 184 | irr &= ~CC_AXI_ERR_IRQ_MASK; |
| 185 | } |
| 186 | |
| 187 | if (irr) { |
Gilad Ben-Yossef | 5c324a2 | 2018-07-01 08:02:39 +0100 | [diff] [blame] | 188 | dev_dbg_ratelimited(dev, "IRR includes unknown cause bits (0x%08X)\n", |
| 189 | irr); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 190 | /* Just warning */ |
| 191 | } |
| 192 | |
| 193 | return IRQ_HANDLED; |
| 194 | } |
| 195 | |
Ofir Drang | d84f626 | 2019-06-17 11:46:28 +0300 | [diff] [blame] | 196 | bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata) |
| 197 | { |
| 198 | unsigned int val; |
| 199 | unsigned int i; |
| 200 | |
| 201 | /* 712/710/63 has no reset completion indication, always return true */ |
| 202 | if (drvdata->hw_rev <= CC_HW_REV_712) |
| 203 | return true; |
| 204 | |
| 205 | for (i = 0; i < CC_HW_RESET_LOOP_COUNT; i++) { |
| 206 | /* in cc7x3 NVM_IS_IDLE indicates that CC reset is |
| 207 | * completed and device is fully functional |
| 208 | */ |
| 209 | val = cc_ioread(drvdata, CC_REG(NVM_IS_IDLE)); |
| 210 | if (val & CC_NVM_IS_IDLE_MASK) { |
| 211 | /* hw indicate reset completed */ |
| 212 | return true; |
| 213 | } |
| 214 | /* allow scheduling other process on the processor */ |
| 215 | schedule(); |
| 216 | } |
| 217 | /* reset not completed */ |
| 218 | return false; |
| 219 | } |
| 220 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 221 | int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe) |
| 222 | { |
| 223 | unsigned int val, cache_params; |
| 224 | struct device *dev = drvdata_to_dev(drvdata); |
| 225 | |
Ofir Drang | 1fc16572 | 2019-04-18 16:39:07 +0300 | [diff] [blame] | 226 | /* Unmask all AXI interrupt sources AXI_CFG1 register */ |
| 227 | /* AXI interrupt config are obsoleted startign at cc7x3 */ |
| 228 | if (drvdata->hw_rev <= CC_HW_REV_712) { |
| 229 | val = cc_ioread(drvdata, CC_REG(AXIM_CFG)); |
| 230 | cc_iowrite(drvdata, CC_REG(AXIM_CFG), val & ~CC_AXI_IRQ_MASK); |
| 231 | dev_dbg(dev, "AXIM_CFG=0x%08X\n", |
| 232 | cc_ioread(drvdata, CC_REG(AXIM_CFG))); |
| 233 | } |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 234 | |
| 235 | /* Clear all pending interrupts */ |
| 236 | val = cc_ioread(drvdata, CC_REG(HOST_IRR)); |
| 237 | dev_dbg(dev, "IRR=0x%08X\n", val); |
| 238 | cc_iowrite(drvdata, CC_REG(HOST_ICR), val); |
| 239 | |
| 240 | /* Unmask relevant interrupt cause */ |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 241 | val = drvdata->comp_mask | CC_AXI_ERR_IRQ_MASK; |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 242 | |
| 243 | if (drvdata->hw_rev >= CC_HW_REV_712) |
| 244 | val |= CC_GPR0_IRQ_MASK; |
| 245 | |
| 246 | cc_iowrite(drvdata, CC_REG(HOST_IMR), ~val); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 247 | |
| 248 | cache_params = (drvdata->coherent ? CC_COHERENT_CACHE_PARAMS : 0x0); |
| 249 | |
| 250 | val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); |
| 251 | |
| 252 | if (is_probe) |
Gilad Ben-Yossef | 565018b | 2018-05-24 15:19:08 +0100 | [diff] [blame] | 253 | dev_dbg(dev, "Cache params previous: 0x%08X\n", val); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 254 | |
| 255 | cc_iowrite(drvdata, CC_REG(AXIM_CACHE_PARAMS), cache_params); |
| 256 | val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS)); |
| 257 | |
| 258 | if (is_probe) |
Gilad Ben-Yossef | 565018b | 2018-05-24 15:19:08 +0100 | [diff] [blame] | 259 | dev_dbg(dev, "Cache params current: 0x%08X (expect: 0x%08X)\n", |
| 260 | val, cache_params); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static int init_cc_resources(struct platform_device *plat_dev) |
| 266 | { |
| 267 | struct resource *req_mem_cc_regs = NULL; |
| 268 | struct cc_drvdata *new_drvdata; |
| 269 | struct device *dev = &plat_dev->dev; |
| 270 | struct device_node *np = dev->of_node; |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 271 | u32 val, hw_rev_pidr, sig_cidr; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 272 | u64 dma_mask; |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 273 | const struct cc_hw_data *hw_rev; |
Gilad Ben-Yossef | 35f859f | 2018-05-24 15:19:07 +0100 | [diff] [blame] | 274 | struct clk *clk; |
Gilad Ben-Yossef | 33c4b31 | 2020-01-16 12:14:44 +0200 | [diff] [blame] | 275 | int irq; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 276 | int rc = 0; |
| 277 | |
| 278 | new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL); |
| 279 | if (!new_drvdata) |
| 280 | return -ENOMEM; |
| 281 | |
Geert Uytterhoeven | 1b940e3 | 2020-02-11 19:19:09 +0100 | [diff] [blame^] | 282 | hw_rev = of_device_get_match_data(dev); |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 283 | new_drvdata->hw_rev_name = hw_rev->name; |
| 284 | new_drvdata->hw_rev = hw_rev->rev; |
Gilad Ben-Yossef | 1c876a9 | 2018-11-13 09:40:35 +0000 | [diff] [blame] | 285 | new_drvdata->std_bodies = hw_rev->std_bodies; |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 286 | |
| 287 | if (hw_rev->rev >= CC_HW_REV_712) { |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 288 | new_drvdata->axim_mon_offset = CC_REG(AXIM_MON_COMP); |
Gilad Ben-Yossef | 281a58c | 2018-05-24 15:19:06 +0100 | [diff] [blame] | 289 | new_drvdata->sig_offset = CC_REG(HOST_SIGNATURE_712); |
| 290 | new_drvdata->ver_offset = CC_REG(HOST_VERSION_712); |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 291 | } else { |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 292 | new_drvdata->axim_mon_offset = CC_REG(AXIM_MON_COMP8); |
Gilad Ben-Yossef | 281a58c | 2018-05-24 15:19:06 +0100 | [diff] [blame] | 293 | new_drvdata->sig_offset = CC_REG(HOST_SIGNATURE_630); |
| 294 | new_drvdata->ver_offset = CC_REG(HOST_VERSION_630); |
Gilad Ben-Yossef | 27b3b22 | 2018-02-19 14:51:23 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 297 | new_drvdata->comp_mask = CC_COMP_IRQ_MASK; |
| 298 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 299 | platform_set_drvdata(plat_dev, new_drvdata); |
| 300 | new_drvdata->plat_dev = plat_dev; |
| 301 | |
Geert Uytterhoeven | 2f272ef | 2020-02-11 19:19:02 +0100 | [diff] [blame] | 302 | clk = devm_clk_get_optional(dev, NULL); |
| 303 | if (IS_ERR(clk)) { |
| 304 | if (PTR_ERR(clk) != -EPROBE_DEFER) |
| 305 | dev_err(dev, "Error getting clock: %pe\n", clk); |
| 306 | return PTR_ERR(clk); |
| 307 | } |
Gilad Ben-Yossef | 35f859f | 2018-05-24 15:19:07 +0100 | [diff] [blame] | 308 | new_drvdata->clk = clk; |
| 309 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 310 | new_drvdata->coherent = of_dma_is_coherent(np); |
| 311 | |
| 312 | /* Get device resources */ |
| 313 | /* First CC registers space */ |
| 314 | req_mem_cc_regs = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); |
| 315 | /* Map registers space */ |
| 316 | new_drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs); |
| 317 | if (IS_ERR(new_drvdata->cc_base)) { |
| 318 | dev_err(dev, "Failed to ioremap registers"); |
| 319 | return PTR_ERR(new_drvdata->cc_base); |
| 320 | } |
| 321 | |
| 322 | dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name, |
| 323 | req_mem_cc_regs); |
| 324 | dev_dbg(dev, "CC registers mapped from %pa to 0x%p\n", |
| 325 | &req_mem_cc_regs->start, new_drvdata->cc_base); |
| 326 | |
| 327 | /* Then IRQ */ |
Gilad Ben-Yossef | 33c4b31 | 2020-01-16 12:14:44 +0200 | [diff] [blame] | 328 | irq = platform_get_irq(plat_dev, 0); |
| 329 | if (irq < 0) |
| 330 | return irq; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 331 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 332 | init_completion(&new_drvdata->hw_queue_avail); |
| 333 | |
| 334 | if (!plat_dev->dev.dma_mask) |
| 335 | plat_dev->dev.dma_mask = &plat_dev->dev.coherent_dma_mask; |
| 336 | |
| 337 | dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN); |
| 338 | while (dma_mask > 0x7fffffffUL) { |
| 339 | if (dma_supported(&plat_dev->dev, dma_mask)) { |
| 340 | rc = dma_set_coherent_mask(&plat_dev->dev, dma_mask); |
| 341 | if (!rc) |
| 342 | break; |
| 343 | } |
| 344 | dma_mask >>= 1; |
| 345 | } |
| 346 | |
| 347 | if (rc) { |
Gilad Ben-Yossef | 5e7b516 | 2018-04-23 08:25:15 +0100 | [diff] [blame] | 348 | dev_err(dev, "Failed in dma_set_mask, mask=%llx\n", dma_mask); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 349 | return rc; |
| 350 | } |
| 351 | |
Geert Uytterhoeven | 2f272ef | 2020-02-11 19:19:02 +0100 | [diff] [blame] | 352 | rc = clk_prepare_enable(new_drvdata->clk); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 353 | if (rc) { |
| 354 | dev_err(dev, "Failed to enable clock"); |
| 355 | return rc; |
| 356 | } |
| 357 | |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 358 | new_drvdata->sec_disabled = cc_sec_disable; |
| 359 | |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 360 | pm_runtime_set_autosuspend_delay(dev, CC_SUSPEND_TIMEOUT); |
| 361 | pm_runtime_use_autosuspend(dev); |
| 362 | pm_runtime_set_active(dev); |
| 363 | pm_runtime_enable(dev); |
| 364 | rc = pm_runtime_get_sync(dev); |
| 365 | if (rc < 0) { |
| 366 | dev_err(dev, "pm_runtime_get_sync() failed: %d\n", rc); |
| 367 | goto post_pm_err; |
| 368 | } |
| 369 | |
Ofir Drang | d84f626 | 2019-06-17 11:46:28 +0300 | [diff] [blame] | 370 | /* wait for Crytpcell reset completion */ |
| 371 | if (!cc_wait_for_reset_completion(new_drvdata)) { |
| 372 | dev_err(dev, "Cryptocell reset not completed"); |
| 373 | } |
| 374 | |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 375 | if (hw_rev->rev <= CC_HW_REV_712) { |
| 376 | /* Verify correct mapping */ |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 377 | val = cc_ioread(new_drvdata, new_drvdata->sig_offset); |
| 378 | if (val != hw_rev->sig) { |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 379 | dev_err(dev, "Invalid CC signature: SIGNATURE=0x%08X != expected=0x%08X\n", |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 380 | val, hw_rev->sig); |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 381 | rc = -EINVAL; |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 382 | goto post_pm_err; |
Gilad Ben-Yossef | e40fdb50 | 2018-10-29 09:50:12 +0000 | [diff] [blame] | 383 | } |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 384 | sig_cidr = val; |
| 385 | hw_rev_pidr = cc_ioread(new_drvdata, new_drvdata->ver_offset); |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 386 | } else { |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 387 | /* Verify correct mapping */ |
| 388 | val = cc_read_idr(new_drvdata, pidr_0124_offsets); |
| 389 | if (val != hw_rev->pidr_0124) { |
| 390 | dev_err(dev, "Invalid CC PIDR: PIDR0124=0x%08X != expected=0x%08X\n", |
| 391 | val, hw_rev->pidr_0124); |
| 392 | rc = -EINVAL; |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 393 | goto post_pm_err; |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 394 | } |
| 395 | hw_rev_pidr = val; |
| 396 | |
| 397 | val = cc_read_idr(new_drvdata, cidr_0123_offsets); |
| 398 | if (val != hw_rev->cidr_0123) { |
| 399 | dev_err(dev, "Invalid CC CIDR: CIDR0123=0x%08X != expected=0x%08X\n", |
| 400 | val, hw_rev->cidr_0123); |
| 401 | rc = -EINVAL; |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 402 | goto post_pm_err; |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 403 | } |
| 404 | sig_cidr = val; |
| 405 | |
Gilad Ben-Yossef | 303f99a | 2019-06-17 11:46:30 +0300 | [diff] [blame] | 406 | /* Check HW engine configuration */ |
| 407 | val = cc_ioread(new_drvdata, CC_REG(HOST_REMOVE_INPUT_PINS)); |
| 408 | switch (val) { |
| 409 | case CC_PINS_FULL: |
| 410 | /* This is fine */ |
| 411 | break; |
| 412 | case CC_PINS_SLIM: |
| 413 | if (new_drvdata->std_bodies & CC_STD_NIST) { |
| 414 | dev_warn(dev, "703 mode forced due to HW configuration.\n"); |
| 415 | new_drvdata->std_bodies = CC_STD_OSCCA; |
| 416 | } |
| 417 | break; |
| 418 | default: |
Colin Ian King | aca24d4 | 2019-07-01 14:08:14 +0100 | [diff] [blame] | 419 | dev_err(dev, "Unsupported engines configuration.\n"); |
Gilad Ben-Yossef | 303f99a | 2019-06-17 11:46:30 +0300 | [diff] [blame] | 420 | rc = -EINVAL; |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 421 | goto post_pm_err; |
Gilad Ben-Yossef | 303f99a | 2019-06-17 11:46:30 +0300 | [diff] [blame] | 422 | } |
| 423 | |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 424 | /* Check security disable state */ |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 425 | val = cc_ioread(new_drvdata, CC_REG(SECURITY_DISABLED)); |
| 426 | val &= CC_SECURITY_DISABLED_MASK; |
Gilad Ben-Yossef | cadfd89 | 2019-04-18 16:38:40 +0300 | [diff] [blame] | 427 | new_drvdata->sec_disabled |= !!val; |
| 428 | |
| 429 | if (!new_drvdata->sec_disabled) { |
| 430 | new_drvdata->comp_mask |= CC_CPP_SM4_ABORT_MASK; |
| 431 | if (new_drvdata->std_bodies & CC_STD_NIST) |
| 432 | new_drvdata->comp_mask |= CC_CPP_AES_ABORT_MASK; |
| 433 | } |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 434 | } |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 435 | |
Gilad Ben-Yossef | f98f6e2 | 2019-04-18 16:38:39 +0300 | [diff] [blame] | 436 | if (new_drvdata->sec_disabled) |
| 437 | dev_info(dev, "Security Disabled mode is in effect. Security functions disabled.\n"); |
| 438 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 439 | /* Display HW versions */ |
Gilad Ben-Yossef | dcf6285 | 2019-04-18 16:38:45 +0300 | [diff] [blame] | 440 | dev_info(dev, "ARM CryptoCell %s Driver: HW version 0x%08X/0x%8X, Driver version %s\n", |
| 441 | hw_rev->name, hw_rev_pidr, sig_cidr, DRV_MODULE_VERSION); |
ofir.drang@arm.com | 0b970d5 | 2019-06-17 11:46:27 +0300 | [diff] [blame] | 442 | /* register the driver isr function */ |
Gilad Ben-Yossef | 33c4b31 | 2020-01-16 12:14:44 +0200 | [diff] [blame] | 443 | rc = devm_request_irq(dev, irq, cc_isr, IRQF_SHARED, "ccree", |
| 444 | new_drvdata); |
ofir.drang@arm.com | 0b970d5 | 2019-06-17 11:46:27 +0300 | [diff] [blame] | 445 | if (rc) { |
Gilad Ben-Yossef | 33c4b31 | 2020-01-16 12:14:44 +0200 | [diff] [blame] | 446 | dev_err(dev, "Could not register to interrupt %d\n", irq); |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 447 | goto post_pm_err; |
ofir.drang@arm.com | 0b970d5 | 2019-06-17 11:46:27 +0300 | [diff] [blame] | 448 | } |
Gilad Ben-Yossef | 33c4b31 | 2020-01-16 12:14:44 +0200 | [diff] [blame] | 449 | dev_dbg(dev, "Registered to IRQ: %d\n", irq); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 450 | |
| 451 | rc = init_cc_regs(new_drvdata, true); |
| 452 | if (rc) { |
| 453 | dev_err(dev, "init_cc_regs failed\n"); |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 454 | goto post_pm_err; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | rc = cc_debugfs_init(new_drvdata); |
| 458 | if (rc) { |
| 459 | dev_err(dev, "Failed registering debugfs interface\n"); |
| 460 | goto post_regs_err; |
| 461 | } |
| 462 | |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 463 | rc = cc_fips_init(new_drvdata); |
| 464 | if (rc) { |
Hadar Gat | 7c06603 | 2019-11-27 10:49:07 +0200 | [diff] [blame] | 465 | dev_err(dev, "cc_fips_init failed 0x%x\n", rc); |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 466 | goto post_debugfs_err; |
| 467 | } |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 468 | rc = cc_sram_mgr_init(new_drvdata); |
| 469 | if (rc) { |
| 470 | dev_err(dev, "cc_sram_mgr_init failed\n"); |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 471 | goto post_fips_init_err; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | new_drvdata->mlli_sram_addr = |
| 475 | cc_sram_alloc(new_drvdata, MAX_MLLI_BUFF_SIZE); |
| 476 | if (new_drvdata->mlli_sram_addr == NULL_SRAM_ADDR) { |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 477 | rc = -ENOMEM; |
Geert Uytterhoeven | fc3b8c1 | 2020-02-11 19:19:01 +0100 | [diff] [blame] | 478 | goto post_fips_init_err; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | rc = cc_req_mgr_init(new_drvdata); |
| 482 | if (rc) { |
| 483 | dev_err(dev, "cc_req_mgr_init failed\n"); |
Geert Uytterhoeven | fc3b8c1 | 2020-02-11 19:19:01 +0100 | [diff] [blame] | 484 | goto post_fips_init_err; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | rc = cc_buffer_mgr_init(new_drvdata); |
| 488 | if (rc) { |
Hadar Gat | 7c06603 | 2019-11-27 10:49:07 +0200 | [diff] [blame] | 489 | dev_err(dev, "cc_buffer_mgr_init failed\n"); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 490 | goto post_req_mgr_err; |
| 491 | } |
| 492 | |
Gilad Ben-Yossef | 63ee04c | 2018-01-22 09:27:01 +0000 | [diff] [blame] | 493 | /* Allocate crypto algs */ |
| 494 | rc = cc_cipher_alloc(new_drvdata); |
| 495 | if (rc) { |
| 496 | dev_err(dev, "cc_cipher_alloc failed\n"); |
Gilad Ben-Yossef | e6e6600 | 2019-07-02 14:39:18 +0300 | [diff] [blame] | 497 | goto post_buf_mgr_err; |
Gilad Ben-Yossef | 63ee04c | 2018-01-22 09:27:01 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Gilad Ben-Yossef | 6389381 | 2018-01-22 09:27:02 +0000 | [diff] [blame] | 500 | /* hash must be allocated before aead since hash exports APIs */ |
| 501 | rc = cc_hash_alloc(new_drvdata); |
| 502 | if (rc) { |
| 503 | dev_err(dev, "cc_hash_alloc failed\n"); |
| 504 | goto post_cipher_err; |
| 505 | } |
| 506 | |
Gilad Ben-Yossef | ff27e85 | 2018-01-22 09:27:03 +0000 | [diff] [blame] | 507 | rc = cc_aead_alloc(new_drvdata); |
| 508 | if (rc) { |
| 509 | dev_err(dev, "cc_aead_alloc failed\n"); |
| 510 | goto post_hash_err; |
| 511 | } |
| 512 | |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 513 | /* If we got here and FIPS mode is enabled |
| 514 | * it means all FIPS test passed, so let TEE |
| 515 | * know we're good. |
| 516 | */ |
| 517 | cc_set_ree_fips_status(new_drvdata, true); |
| 518 | |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 519 | pm_runtime_put(dev); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 520 | return 0; |
| 521 | |
Gilad Ben-Yossef | ff27e85 | 2018-01-22 09:27:03 +0000 | [diff] [blame] | 522 | post_hash_err: |
| 523 | cc_hash_free(new_drvdata); |
Gilad Ben-Yossef | 6389381 | 2018-01-22 09:27:02 +0000 | [diff] [blame] | 524 | post_cipher_err: |
| 525 | cc_cipher_free(new_drvdata); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 526 | post_buf_mgr_err: |
| 527 | cc_buffer_mgr_fini(new_drvdata); |
| 528 | post_req_mgr_err: |
| 529 | cc_req_mgr_fini(new_drvdata); |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 530 | post_fips_init_err: |
| 531 | cc_fips_fini(new_drvdata); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 532 | post_debugfs_err: |
| 533 | cc_debugfs_fini(new_drvdata); |
| 534 | post_regs_err: |
| 535 | fini_cc_regs(new_drvdata); |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 536 | post_pm_err: |
| 537 | pm_runtime_put_noidle(dev); |
| 538 | pm_runtime_disable(dev); |
| 539 | pm_runtime_set_suspended(dev); |
Geert Uytterhoeven | 2f272ef | 2020-02-11 19:19:02 +0100 | [diff] [blame] | 540 | clk_disable_unprepare(new_drvdata->clk); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 541 | return rc; |
| 542 | } |
| 543 | |
| 544 | void fini_cc_regs(struct cc_drvdata *drvdata) |
| 545 | { |
| 546 | /* Mask all interrupts */ |
| 547 | cc_iowrite(drvdata, CC_REG(HOST_IMR), 0xFFFFFFFF); |
| 548 | } |
| 549 | |
| 550 | static void cleanup_cc_resources(struct platform_device *plat_dev) |
| 551 | { |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 552 | struct device *dev = &plat_dev->dev; |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 553 | struct cc_drvdata *drvdata = |
| 554 | (struct cc_drvdata *)platform_get_drvdata(plat_dev); |
| 555 | |
Gilad Ben-Yossef | ff27e85 | 2018-01-22 09:27:03 +0000 | [diff] [blame] | 556 | cc_aead_free(drvdata); |
Gilad Ben-Yossef | 6389381 | 2018-01-22 09:27:02 +0000 | [diff] [blame] | 557 | cc_hash_free(drvdata); |
Gilad Ben-Yossef | 63ee04c | 2018-01-22 09:27:01 +0000 | [diff] [blame] | 558 | cc_cipher_free(drvdata); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 559 | cc_buffer_mgr_fini(drvdata); |
| 560 | cc_req_mgr_fini(drvdata); |
Gilad Ben-Yossef | ab8ec96 | 2018-01-22 09:27:04 +0000 | [diff] [blame] | 561 | cc_fips_fini(drvdata); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 562 | cc_debugfs_fini(drvdata); |
| 563 | fini_cc_regs(drvdata); |
Geert Uytterhoeven | 8c7849a | 2020-02-11 19:19:08 +0100 | [diff] [blame] | 564 | pm_runtime_put_noidle(dev); |
| 565 | pm_runtime_disable(dev); |
| 566 | pm_runtime_set_suspended(dev); |
Geert Uytterhoeven | 2f272ef | 2020-02-11 19:19:02 +0100 | [diff] [blame] | 567 | clk_disable_unprepare(drvdata->clk); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Yael Chemla | f1e52fd | 2018-10-18 13:59:57 +0100 | [diff] [blame] | 570 | unsigned int cc_get_default_hash_len(struct cc_drvdata *drvdata) |
| 571 | { |
| 572 | if (drvdata->hw_rev >= CC_HW_REV_712) |
| 573 | return HASH_LEN_SIZE_712; |
| 574 | else |
| 575 | return HASH_LEN_SIZE_630; |
| 576 | } |
| 577 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 578 | static int ccree_probe(struct platform_device *plat_dev) |
| 579 | { |
| 580 | int rc; |
| 581 | struct device *dev = &plat_dev->dev; |
| 582 | |
| 583 | /* Map registers space */ |
| 584 | rc = init_cc_resources(plat_dev); |
| 585 | if (rc) |
| 586 | return rc; |
| 587 | |
| 588 | dev_info(dev, "ARM ccree device initialized\n"); |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int ccree_remove(struct platform_device *plat_dev) |
| 594 | { |
| 595 | struct device *dev = &plat_dev->dev; |
| 596 | |
| 597 | dev_dbg(dev, "Releasing ccree resources...\n"); |
| 598 | |
| 599 | cleanup_cc_resources(plat_dev); |
| 600 | |
| 601 | dev_info(dev, "ARM ccree device terminated\n"); |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 606 | static struct platform_driver ccree_driver = { |
| 607 | .driver = { |
| 608 | .name = "ccree", |
| 609 | .of_match_table = arm_ccree_dev_of_match, |
| 610 | #ifdef CONFIG_PM |
| 611 | .pm = &ccree_pm, |
| 612 | #endif |
| 613 | }, |
| 614 | .probe = ccree_probe, |
| 615 | .remove = ccree_remove, |
| 616 | }; |
| 617 | |
| 618 | static int __init ccree_init(void) |
| 619 | { |
Greg Kroah-Hartman | 54eedf0 | 2019-01-22 16:14:17 +0100 | [diff] [blame] | 620 | cc_debugfs_global_init(); |
Gilad Ben-Yossef | 4c3f972 | 2018-01-22 09:27:00 +0000 | [diff] [blame] | 621 | |
| 622 | return platform_driver_register(&ccree_driver); |
| 623 | } |
| 624 | module_init(ccree_init); |
| 625 | |
| 626 | static void __exit ccree_exit(void) |
| 627 | { |
| 628 | platform_driver_unregister(&ccree_driver); |
| 629 | cc_debugfs_global_fini(); |
| 630 | } |
| 631 | module_exit(ccree_exit); |
| 632 | |
| 633 | /* Module description */ |
| 634 | MODULE_DESCRIPTION("ARM TrustZone CryptoCell REE Driver"); |
| 635 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 636 | MODULE_AUTHOR("ARM"); |
| 637 | MODULE_LICENSE("GPL v2"); |