18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright (C) 2012-2019 ARM Limited or its affiliates. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <linux/kernel.h> 58c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 68c2ecf20Sopenharmony_ci#include <linux/stringify.h> 78c2ecf20Sopenharmony_ci#include "cc_driver.h" 88c2ecf20Sopenharmony_ci#include "cc_crypto_ctx.h" 98c2ecf20Sopenharmony_ci#include "cc_debugfs.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define CC_DEBUG_REG(_X) { \ 128c2ecf20Sopenharmony_ci .name = __stringify(_X),\ 138c2ecf20Sopenharmony_ci .offset = CC_REG(_X) \ 148c2ecf20Sopenharmony_ci } 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* 178c2ecf20Sopenharmony_ci * This is a global var for the dentry of the 188c2ecf20Sopenharmony_ci * debugfs ccree/ dir. It is not tied down to 198c2ecf20Sopenharmony_ci * a specific instance of ccree, hence it is 208c2ecf20Sopenharmony_ci * global. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_cistatic struct dentry *cc_debugfs_dir; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic struct debugfs_reg32 ver_sig_regs[] = { 258c2ecf20Sopenharmony_ci { .name = "SIGNATURE" }, /* Must be 0th */ 268c2ecf20Sopenharmony_ci { .name = "VERSION" }, /* Must be 1st */ 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic const struct debugfs_reg32 pid_cid_regs[] = { 308c2ecf20Sopenharmony_ci CC_DEBUG_REG(PERIPHERAL_ID_0), 318c2ecf20Sopenharmony_ci CC_DEBUG_REG(PERIPHERAL_ID_1), 328c2ecf20Sopenharmony_ci CC_DEBUG_REG(PERIPHERAL_ID_2), 338c2ecf20Sopenharmony_ci CC_DEBUG_REG(PERIPHERAL_ID_3), 348c2ecf20Sopenharmony_ci CC_DEBUG_REG(PERIPHERAL_ID_4), 358c2ecf20Sopenharmony_ci CC_DEBUG_REG(COMPONENT_ID_0), 368c2ecf20Sopenharmony_ci CC_DEBUG_REG(COMPONENT_ID_1), 378c2ecf20Sopenharmony_ci CC_DEBUG_REG(COMPONENT_ID_2), 388c2ecf20Sopenharmony_ci CC_DEBUG_REG(COMPONENT_ID_3), 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic const struct debugfs_reg32 debug_regs[] = { 428c2ecf20Sopenharmony_ci CC_DEBUG_REG(HOST_IRR), 438c2ecf20Sopenharmony_ci CC_DEBUG_REG(HOST_POWER_DOWN_EN), 448c2ecf20Sopenharmony_ci CC_DEBUG_REG(AXIM_MON_ERR), 458c2ecf20Sopenharmony_ci CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT), 468c2ecf20Sopenharmony_ci CC_DEBUG_REG(HOST_IMR), 478c2ecf20Sopenharmony_ci CC_DEBUG_REG(AXIM_CFG), 488c2ecf20Sopenharmony_ci CC_DEBUG_REG(AXIM_CACHE_PARAMS), 498c2ecf20Sopenharmony_ci CC_DEBUG_REG(GPR_HOST), 508c2ecf20Sopenharmony_ci CC_DEBUG_REG(AXIM_MON_COMP), 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_civoid __init cc_debugfs_global_init(void) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci cc_debugfs_dir = debugfs_create_dir("ccree", NULL); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_civoid cc_debugfs_global_fini(void) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci debugfs_remove(cc_debugfs_dir); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciint cc_debugfs_init(struct cc_drvdata *drvdata) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci struct device *dev = drvdata_to_dev(drvdata); 668c2ecf20Sopenharmony_ci struct debugfs_regset32 *regset, *verset; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); 698c2ecf20Sopenharmony_ci if (!regset) 708c2ecf20Sopenharmony_ci return -ENOMEM; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci regset->regs = debug_regs; 738c2ecf20Sopenharmony_ci regset->nregs = ARRAY_SIZE(debug_regs); 748c2ecf20Sopenharmony_ci regset->base = drvdata->cc_base; 758c2ecf20Sopenharmony_ci regset->dev = dev; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci drvdata->dir = debugfs_create_dir(drvdata->plat_dev->name, 788c2ecf20Sopenharmony_ci cc_debugfs_dir); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci debugfs_create_regset32("regs", 0400, drvdata->dir, regset); 818c2ecf20Sopenharmony_ci debugfs_create_bool("coherent", 0400, drvdata->dir, &drvdata->coherent); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci verset = devm_kzalloc(dev, sizeof(*verset), GFP_KERNEL); 848c2ecf20Sopenharmony_ci /* Failing here is not important enough to fail the module load */ 858c2ecf20Sopenharmony_ci if (!verset) 868c2ecf20Sopenharmony_ci return 0; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci if (drvdata->hw_rev <= CC_HW_REV_712) { 898c2ecf20Sopenharmony_ci ver_sig_regs[0].offset = drvdata->sig_offset; 908c2ecf20Sopenharmony_ci ver_sig_regs[1].offset = drvdata->ver_offset; 918c2ecf20Sopenharmony_ci verset->regs = ver_sig_regs; 928c2ecf20Sopenharmony_ci verset->nregs = ARRAY_SIZE(ver_sig_regs); 938c2ecf20Sopenharmony_ci } else { 948c2ecf20Sopenharmony_ci verset->regs = pid_cid_regs; 958c2ecf20Sopenharmony_ci verset->nregs = ARRAY_SIZE(pid_cid_regs); 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci verset->base = drvdata->cc_base; 988c2ecf20Sopenharmony_ci verset->dev = dev; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci debugfs_create_regset32("version", 0400, drvdata->dir, verset); 1018c2ecf20Sopenharmony_ci return 0; 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_civoid cc_debugfs_fini(struct cc_drvdata *drvdata) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci debugfs_remove_recursive(drvdata->dir); 1078c2ecf20Sopenharmony_ci} 108