Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 2 | /* Copyright (C) 2012-2019 ARM Limited or its affiliates. */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | static struct debugfs_reg32 ver_sig_regs[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | { .name = "SIGNATURE" }, /* Must be 0th */ |
| 30 | { .name = "VERSION" }, /* Must be 1st */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 31 | }; |
| 32 | |
| 33 | static struct debugfs_reg32 pid_cid_regs[] = { |
| 34 | CC_DEBUG_REG(PERIPHERAL_ID_0), |
| 35 | CC_DEBUG_REG(PERIPHERAL_ID_1), |
| 36 | CC_DEBUG_REG(PERIPHERAL_ID_2), |
| 37 | CC_DEBUG_REG(PERIPHERAL_ID_3), |
| 38 | CC_DEBUG_REG(PERIPHERAL_ID_4), |
| 39 | CC_DEBUG_REG(COMPONENT_ID_0), |
| 40 | CC_DEBUG_REG(COMPONENT_ID_1), |
| 41 | CC_DEBUG_REG(COMPONENT_ID_2), |
| 42 | CC_DEBUG_REG(COMPONENT_ID_3), |
| 43 | }; |
| 44 | |
| 45 | static struct debugfs_reg32 debug_regs[] = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | CC_DEBUG_REG(HOST_IRR), |
| 47 | CC_DEBUG_REG(HOST_POWER_DOWN_EN), |
| 48 | CC_DEBUG_REG(AXIM_MON_ERR), |
| 49 | CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT), |
| 50 | CC_DEBUG_REG(HOST_IMR), |
| 51 | CC_DEBUG_REG(AXIM_CFG), |
| 52 | CC_DEBUG_REG(AXIM_CACHE_PARAMS), |
| 53 | CC_DEBUG_REG(GPR_HOST), |
| 54 | CC_DEBUG_REG(AXIM_MON_COMP), |
| 55 | }; |
| 56 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 57 | void __init cc_debugfs_global_init(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | { |
| 59 | cc_debugfs_dir = debugfs_create_dir("ccree", NULL); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void __exit cc_debugfs_global_fini(void) |
| 63 | { |
| 64 | debugfs_remove(cc_debugfs_dir); |
| 65 | } |
| 66 | |
| 67 | int cc_debugfs_init(struct cc_drvdata *drvdata) |
| 68 | { |
| 69 | struct device *dev = drvdata_to_dev(drvdata); |
| 70 | struct cc_debugfs_ctx *ctx; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 71 | struct debugfs_regset32 *regset, *verset; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 72 | |
| 73 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 74 | if (!ctx) |
| 75 | return -ENOMEM; |
| 76 | |
| 77 | regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); |
| 78 | if (!regset) |
| 79 | return -ENOMEM; |
| 80 | |
| 81 | regset->regs = debug_regs; |
| 82 | regset->nregs = ARRAY_SIZE(debug_regs); |
| 83 | regset->base = drvdata->cc_base; |
| 84 | |
| 85 | ctx->dir = debugfs_create_dir(drvdata->plat_dev->name, cc_debugfs_dir); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 86 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 87 | debugfs_create_regset32("regs", 0400, ctx->dir, regset); |
| 88 | debugfs_create_bool("coherent", 0400, ctx->dir, &drvdata->coherent); |
| 89 | |
| 90 | verset = devm_kzalloc(dev, sizeof(*verset), GFP_KERNEL); |
| 91 | /* Failing here is not important enough to fail the module load */ |
| 92 | if (!verset) |
| 93 | goto out; |
| 94 | |
| 95 | if (drvdata->hw_rev <= CC_HW_REV_712) { |
| 96 | ver_sig_regs[0].offset = drvdata->sig_offset; |
| 97 | ver_sig_regs[1].offset = drvdata->ver_offset; |
| 98 | verset->regs = ver_sig_regs; |
| 99 | verset->nregs = ARRAY_SIZE(ver_sig_regs); |
| 100 | } else { |
| 101 | verset->regs = pid_cid_regs; |
| 102 | verset->nregs = ARRAY_SIZE(pid_cid_regs); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 103 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 104 | verset->base = drvdata->cc_base; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 105 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 106 | debugfs_create_regset32("version", 0400, ctx->dir, verset); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 107 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 108 | out: |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 109 | drvdata->debugfs = ctx; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | void cc_debugfs_fini(struct cc_drvdata *drvdata) |
| 114 | { |
| 115 | struct cc_debugfs_ctx *ctx = (struct cc_debugfs_ctx *)drvdata->debugfs; |
| 116 | |
| 117 | debugfs_remove_recursive(ctx->dir); |
| 118 | } |