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