ctrl.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * CAAM control-plane driver backend
  3. * Controller-level driver, kernel property detection, initialization
  4. *
  5. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  6. */
  7. #include "compat.h"
  8. #include "regs.h"
  9. #include "intern.h"
  10. #include "jr.h"
  11. static int caam_remove(struct platform_device *pdev)
  12. {
  13. struct device *ctrldev;
  14. struct caam_drv_private *ctrlpriv;
  15. struct caam_drv_private_jr *jrpriv;
  16. struct caam_full __iomem *topregs;
  17. int ring, ret = 0;
  18. ctrldev = &pdev->dev;
  19. ctrlpriv = dev_get_drvdata(ctrldev);
  20. topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
  21. /* shut down JobRs */
  22. for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
  23. ret |= caam_jr_shutdown(ctrlpriv->jrdev[ring]);
  24. jrpriv = dev_get_drvdata(ctrlpriv->jrdev[ring]);
  25. irq_dispose_mapping(jrpriv->irq);
  26. }
  27. /* Shut down debug views */
  28. #ifdef CONFIG_DEBUG_FS
  29. debugfs_remove_recursive(ctrlpriv->dfs_root);
  30. #endif
  31. /* Unmap controller region */
  32. iounmap(&topregs->ctrl);
  33. kfree(ctrlpriv->jrdev);
  34. kfree(ctrlpriv);
  35. return ret;
  36. }
  37. /* Probe routine for CAAM top (controller) level */
  38. static int caam_probe(struct platform_device *pdev,
  39. const struct of_device_id *devmatch)
  40. {
  41. int d, ring, rspec;
  42. struct device *dev;
  43. struct device_node *nprop, *np;
  44. struct caam_ctrl __iomem *ctrl;
  45. struct caam_full __iomem *topregs;
  46. struct caam_drv_private *ctrlpriv;
  47. struct caam_perfmon *perfmon;
  48. struct caam_deco **deco;
  49. u32 deconum;
  50. ctrlpriv = kzalloc(sizeof(struct caam_drv_private), GFP_KERNEL);
  51. if (!ctrlpriv)
  52. return -ENOMEM;
  53. dev = &pdev->dev;
  54. dev_set_drvdata(dev, ctrlpriv);
  55. ctrlpriv->pdev = pdev;
  56. nprop = pdev->dev.of_node;
  57. /* Get configuration properties from device tree */
  58. /* First, get register page */
  59. ctrl = of_iomap(nprop, 0);
  60. if (ctrl == NULL) {
  61. dev_err(dev, "caam: of_iomap() failed\n");
  62. return -ENOMEM;
  63. }
  64. ctrlpriv->ctrl = (struct caam_ctrl __force *)ctrl;
  65. /* topregs used to derive pointers to CAAM sub-blocks only */
  66. topregs = (struct caam_full __iomem *)ctrl;
  67. /* Get the IRQ of the controller (for security violations only) */
  68. ctrlpriv->secvio_irq = of_irq_to_resource(nprop, 0, NULL);
  69. /*
  70. * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
  71. * 36-bit pointers in master configuration register
  72. */
  73. setbits32(&topregs->ctrl.mcr, MCFGR_WDENABLE |
  74. (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
  75. if (sizeof(dma_addr_t) == sizeof(u64))
  76. dma_set_mask(dev, DMA_BIT_MASK(36));
  77. /* Find out how many DECOs are present */
  78. deconum = (rd_reg64(&topregs->ctrl.perfmon.cha_num) &
  79. CHA_NUM_DECONUM_MASK) >> CHA_NUM_DECONUM_SHIFT;
  80. ctrlpriv->deco = kmalloc(deconum * sizeof(struct caam_deco *),
  81. GFP_KERNEL);
  82. deco = (struct caam_deco __force **)&topregs->deco;
  83. for (d = 0; d < deconum; d++)
  84. ctrlpriv->deco[d] = deco[d];
  85. /*
  86. * Detect and enable JobRs
  87. * First, find out how many ring spec'ed, allocate references
  88. * for all, then go probe each one.
  89. */
  90. rspec = 0;
  91. for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring")
  92. rspec++;
  93. ctrlpriv->jrdev = kzalloc(sizeof(struct device *) * rspec, GFP_KERNEL);
  94. if (ctrlpriv->jrdev == NULL) {
  95. iounmap(&topregs->ctrl);
  96. return -ENOMEM;
  97. }
  98. ring = 0;
  99. ctrlpriv->total_jobrs = 0;
  100. for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring") {
  101. caam_jr_probe(pdev, np, ring);
  102. ctrlpriv->total_jobrs++;
  103. ring++;
  104. }
  105. /* Check to see if QI present. If so, enable */
  106. ctrlpriv->qi_present = !!(rd_reg64(&topregs->ctrl.perfmon.comp_parms) &
  107. CTPR_QI_MASK);
  108. if (ctrlpriv->qi_present) {
  109. ctrlpriv->qi = (struct caam_queue_if __force *)&topregs->qi;
  110. /* This is all that's required to physically enable QI */
  111. wr_reg32(&topregs->qi.qi_control_lo, QICTL_DQEN);
  112. }
  113. /* If no QI and no rings specified, quit and go home */
  114. if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
  115. dev_err(dev, "no queues configured, terminating\n");
  116. caam_remove(pdev);
  117. return -ENOMEM;
  118. }
  119. /* NOTE: RTIC detection ought to go here, around Si time */
  120. /* Initialize queue allocator lock */
  121. spin_lock_init(&ctrlpriv->jr_alloc_lock);
  122. /* Report "alive" for developer to see */
  123. dev_info(dev, "device ID = 0x%016llx\n",
  124. rd_reg64(&topregs->ctrl.perfmon.caam_id));
  125. dev_info(dev, "job rings = %d, qi = %d\n",
  126. ctrlpriv->total_jobrs, ctrlpriv->qi_present);
  127. #ifdef CONFIG_DEBUG_FS
  128. /*
  129. * FIXME: needs better naming distinction, as some amalgamation of
  130. * "caam" and nprop->full_name. The OF name isn't distinctive,
  131. * but does separate instances
  132. */
  133. perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
  134. ctrlpriv->dfs_root = debugfs_create_dir("caam", NULL);
  135. ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root);
  136. /* Controller-level - performance monitor counters */
  137. ctrlpriv->ctl_rq_dequeued =
  138. debugfs_create_u64("rq_dequeued",
  139. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  140. ctrlpriv->ctl, &perfmon->req_dequeued);
  141. ctrlpriv->ctl_ob_enc_req =
  142. debugfs_create_u64("ob_rq_encrypted",
  143. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  144. ctrlpriv->ctl, &perfmon->ob_enc_req);
  145. ctrlpriv->ctl_ib_dec_req =
  146. debugfs_create_u64("ib_rq_decrypted",
  147. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  148. ctrlpriv->ctl, &perfmon->ib_dec_req);
  149. ctrlpriv->ctl_ob_enc_bytes =
  150. debugfs_create_u64("ob_bytes_encrypted",
  151. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  152. ctrlpriv->ctl, &perfmon->ob_enc_bytes);
  153. ctrlpriv->ctl_ob_prot_bytes =
  154. debugfs_create_u64("ob_bytes_protected",
  155. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  156. ctrlpriv->ctl, &perfmon->ob_prot_bytes);
  157. ctrlpriv->ctl_ib_dec_bytes =
  158. debugfs_create_u64("ib_bytes_decrypted",
  159. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  160. ctrlpriv->ctl, &perfmon->ib_dec_bytes);
  161. ctrlpriv->ctl_ib_valid_bytes =
  162. debugfs_create_u64("ib_bytes_validated",
  163. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  164. ctrlpriv->ctl, &perfmon->ib_valid_bytes);
  165. /* Controller level - global status values */
  166. ctrlpriv->ctl_faultaddr =
  167. debugfs_create_u64("fault_addr",
  168. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  169. ctrlpriv->ctl, &perfmon->faultaddr);
  170. ctrlpriv->ctl_faultdetail =
  171. debugfs_create_u32("fault_detail",
  172. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  173. ctrlpriv->ctl, &perfmon->faultdetail);
  174. ctrlpriv->ctl_faultstatus =
  175. debugfs_create_u32("fault_status",
  176. S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH,
  177. ctrlpriv->ctl, &perfmon->status);
  178. /* Internal covering keys (useful in non-secure mode only) */
  179. ctrlpriv->ctl_kek_wrap.data = &ctrlpriv->ctrl->kek[0];
  180. ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  181. ctrlpriv->ctl_kek = debugfs_create_blob("kek",
  182. S_IFCHR | S_IRUSR |
  183. S_IRGRP | S_IROTH,
  184. ctrlpriv->ctl,
  185. &ctrlpriv->ctl_kek_wrap);
  186. ctrlpriv->ctl_tkek_wrap.data = &ctrlpriv->ctrl->tkek[0];
  187. ctrlpriv->ctl_tkek_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  188. ctrlpriv->ctl_tkek = debugfs_create_blob("tkek",
  189. S_IFCHR | S_IRUSR |
  190. S_IRGRP | S_IROTH,
  191. ctrlpriv->ctl,
  192. &ctrlpriv->ctl_tkek_wrap);
  193. ctrlpriv->ctl_tdsk_wrap.data = &ctrlpriv->ctrl->tdsk[0];
  194. ctrlpriv->ctl_tdsk_wrap.size = KEK_KEY_SIZE * sizeof(u32);
  195. ctrlpriv->ctl_tdsk = debugfs_create_blob("tdsk",
  196. S_IFCHR | S_IRUSR |
  197. S_IRGRP | S_IROTH,
  198. ctrlpriv->ctl,
  199. &ctrlpriv->ctl_tdsk_wrap);
  200. #endif
  201. return 0;
  202. }
  203. static struct of_device_id caam_match[] = {
  204. {
  205. .compatible = "fsl,sec4.0",
  206. },
  207. {},
  208. };
  209. MODULE_DEVICE_TABLE(of, caam_match);
  210. static struct of_platform_driver caam_driver = {
  211. .driver = {
  212. .name = "caam",
  213. .owner = THIS_MODULE,
  214. .of_match_table = caam_match,
  215. },
  216. .probe = caam_probe,
  217. .remove = __devexit_p(caam_remove),
  218. };
  219. static int __init caam_base_init(void)
  220. {
  221. return of_register_platform_driver(&caam_driver);
  222. }
  223. static void __exit caam_base_exit(void)
  224. {
  225. return of_unregister_platform_driver(&caam_driver);
  226. }
  227. module_init(caam_base_init);
  228. module_exit(caam_base_exit);
  229. MODULE_LICENSE("GPL");
  230. MODULE_DESCRIPTION("FSL CAAM request backend");
  231. MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");