cc_debugfs.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. CC_DEBUG_REG(HOST_SIGNATURE),
  25. CC_DEBUG_REG(HOST_IRR),
  26. CC_DEBUG_REG(HOST_POWER_DOWN_EN),
  27. CC_DEBUG_REG(AXIM_MON_ERR),
  28. CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT),
  29. CC_DEBUG_REG(HOST_IMR),
  30. CC_DEBUG_REG(AXIM_CFG),
  31. CC_DEBUG_REG(AXIM_CACHE_PARAMS),
  32. CC_DEBUG_REG(HOST_VERSION),
  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. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  52. if (!ctx)
  53. return -ENOMEM;
  54. regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
  55. if (!regset)
  56. return -ENOMEM;
  57. regset->regs = debug_regs;
  58. regset->nregs = ARRAY_SIZE(debug_regs);
  59. regset->base = drvdata->cc_base;
  60. ctx->dir = debugfs_create_dir(drvdata->plat_dev->name, cc_debugfs_dir);
  61. if (!ctx->dir)
  62. return -ENFILE;
  63. file = debugfs_create_regset32("regs", 0400, ctx->dir, regset);
  64. if (!file) {
  65. debugfs_remove(ctx->dir);
  66. return -ENFILE;
  67. }
  68. file = debugfs_create_bool("coherent", 0400, ctx->dir,
  69. &drvdata->coherent);
  70. if (!file) {
  71. debugfs_remove_recursive(ctx->dir);
  72. return -ENFILE;
  73. }
  74. drvdata->debugfs = ctx;
  75. return 0;
  76. }
  77. void cc_debugfs_fini(struct cc_drvdata *drvdata)
  78. {
  79. struct cc_debugfs_ctx *ctx = (struct cc_debugfs_ctx *)drvdata->debugfs;
  80. debugfs_remove_recursive(ctx->dir);
  81. }