cc_debugfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
  3. #include <linux/kernel.h>
  4. #include <linux/debugfs.h>
  5. #include <linux/stringify.h>
  6. #include "cc_driver.h"
  7. #include "cc_crypto_ctx.h"
  8. #include "cc_debugfs.h"
  9. struct cc_debugfs_ctx {
  10. struct dentry *dir;
  11. };
  12. #define CC_DEBUG_REG(_X) { \
  13. .name = __stringify(_X),\
  14. .offset = CC_REG(_X) \
  15. }
  16. /*
  17. * This is a global var for the dentry of the
  18. * debugfs ccree/ dir. It is not tied down to
  19. * a specific instance of ccree, hence it is
  20. * global.
  21. */
  22. static struct dentry *cc_debugfs_dir;
  23. static struct debugfs_reg32 debug_regs[] = {
  24. { .name = "SIGNATURE" }, /* Must be 0th */
  25. { .name = "VERSION" }, /* Must be 1st */
  26. CC_DEBUG_REG(HOST_IRR),
  27. CC_DEBUG_REG(HOST_POWER_DOWN_EN),
  28. CC_DEBUG_REG(AXIM_MON_ERR),
  29. CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT),
  30. CC_DEBUG_REG(HOST_IMR),
  31. CC_DEBUG_REG(AXIM_CFG),
  32. CC_DEBUG_REG(AXIM_CACHE_PARAMS),
  33. CC_DEBUG_REG(GPR_HOST),
  34. CC_DEBUG_REG(AXIM_MON_COMP),
  35. };
  36. int __init cc_debugfs_global_init(void)
  37. {
  38. cc_debugfs_dir = debugfs_create_dir("ccree", NULL);
  39. return !cc_debugfs_dir;
  40. }
  41. void __exit cc_debugfs_global_fini(void)
  42. {
  43. debugfs_remove(cc_debugfs_dir);
  44. }
  45. int cc_debugfs_init(struct cc_drvdata *drvdata)
  46. {
  47. struct device *dev = drvdata_to_dev(drvdata);
  48. struct cc_debugfs_ctx *ctx;
  49. struct debugfs_regset32 *regset;
  50. struct dentry *file;
  51. debug_regs[0].offset = drvdata->sig_offset;
  52. debug_regs[1].offset = drvdata->ver_offset;
  53. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  54. if (!ctx)
  55. return -ENOMEM;
  56. regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
  57. if (!regset)
  58. return -ENOMEM;
  59. regset->regs = debug_regs;
  60. regset->nregs = ARRAY_SIZE(debug_regs);
  61. regset->base = drvdata->cc_base;
  62. ctx->dir = debugfs_create_dir(drvdata->plat_dev->name, cc_debugfs_dir);
  63. if (!ctx->dir)
  64. return -ENFILE;
  65. file = debugfs_create_regset32("regs", 0400, ctx->dir, regset);
  66. if (!file) {
  67. debugfs_remove(ctx->dir);
  68. return -ENFILE;
  69. }
  70. file = debugfs_create_bool("coherent", 0400, ctx->dir,
  71. &drvdata->coherent);
  72. if (!file) {
  73. debugfs_remove_recursive(ctx->dir);
  74. return -ENFILE;
  75. }
  76. drvdata->debugfs = ctx;
  77. return 0;
  78. }
  79. void cc_debugfs_fini(struct cc_drvdata *drvdata)
  80. {
  81. struct cc_debugfs_ctx *ctx = (struct cc_debugfs_ctx *)drvdata->debugfs;
  82. debugfs_remove_recursive(ctx->dir);
  83. }