1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved
7 #include <linux/cpufeature.h>
8 #include <linux/debugfs.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/device.h>
13 #include <linux/interrupt.h>
14 #include <linux/ioport.h>
15 #include <soc/tegra/fuse.h>
16 #include <soc/tegra/tegra-cbb.h>
18 void tegra_cbb_print_err(struct seq_file
*file
, const char *fmt
, ...)
26 seq_vprintf(file
, fmt
, args
);
36 void tegra_cbb_print_cache(struct seq_file
*file
, u32 cache
)
38 const char *buff_str
, *mod_str
, *rd_str
, *wr_str
;
40 buff_str
= (cache
& BIT(0)) ? "Bufferable " : "";
41 mod_str
= (cache
& BIT(1)) ? "Modifiable " : "";
42 rd_str
= (cache
& BIT(2)) ? "Read-Allocate " : "";
43 wr_str
= (cache
& BIT(3)) ? "Write-Allocate" : "";
46 buff_str
= "Device Non-Bufferable";
48 tegra_cbb_print_err(file
, "\t Cache\t\t\t: 0x%x -- %s%s%s%s\n",
49 cache
, buff_str
, mod_str
, rd_str
, wr_str
);
52 void tegra_cbb_print_prot(struct seq_file
*file
, u32 prot
)
54 const char *data_str
, *secure_str
, *priv_str
;
56 data_str
= (prot
& 0x4) ? "Instruction" : "Data";
57 secure_str
= (prot
& 0x2) ? "Non-Secure" : "Secure";
58 priv_str
= (prot
& 0x1) ? "Privileged" : "Unprivileged";
60 tegra_cbb_print_err(file
, "\t Protection\t\t: 0x%x -- %s, %s, %s Access\n",
61 prot
, priv_str
, secure_str
, data_str
);
64 static int tegra_cbb_err_show(struct seq_file
*file
, void *data
)
66 struct tegra_cbb
*cbb
= file
->private;
68 return cbb
->ops
->debugfs_show(cbb
, file
, data
);
70 DEFINE_SHOW_ATTRIBUTE(tegra_cbb_err
);
72 static int tegra_cbb_err_debugfs_init(struct tegra_cbb
*cbb
)
74 static struct dentry
*root
;
77 root
= debugfs_create_file("tegra_cbb_err", 0444, NULL
, cbb
, &tegra_cbb_err_fops
);
78 if (IS_ERR_OR_NULL(root
)) {
79 pr_err("%s(): could not create debugfs node\n", __func__
);
87 void tegra_cbb_stall_enable(struct tegra_cbb
*cbb
)
89 if (cbb
->ops
->stall_enable
)
90 cbb
->ops
->stall_enable(cbb
);
93 void tegra_cbb_fault_enable(struct tegra_cbb
*cbb
)
95 if (cbb
->ops
->fault_enable
)
96 cbb
->ops
->fault_enable(cbb
);
99 void tegra_cbb_error_clear(struct tegra_cbb
*cbb
)
101 if (cbb
->ops
->error_clear
)
102 cbb
->ops
->error_clear(cbb
);
105 u32
tegra_cbb_get_status(struct tegra_cbb
*cbb
)
107 if (cbb
->ops
->get_status
)
108 return cbb
->ops
->get_status(cbb
);
113 int tegra_cbb_get_irq(struct platform_device
*pdev
, unsigned int *nonsec_irq
,
114 unsigned int *sec_irq
)
116 unsigned int index
= 0;
117 int num_intr
= 0, irq
;
119 num_intr
= platform_irq_count(pdev
);
124 irq
= platform_get_irq(pdev
, index
);
132 irq
= platform_get_irq(pdev
, index
);
139 dev_dbg(&pdev
->dev
, "secure IRQ: %u\n", *sec_irq
);
142 dev_dbg(&pdev
->dev
, "secure IRQ: %u, non-secure IRQ: %u\n", *sec_irq
, *nonsec_irq
);
147 int tegra_cbb_register(struct tegra_cbb
*cbb
)
151 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
152 ret
= tegra_cbb_err_debugfs_init(cbb
);
154 dev_err(cbb
->dev
, "failed to create debugfs\n");
159 /* register interrupt handler for errors due to different initiators */
160 ret
= cbb
->ops
->interrupt_enable(cbb
);
162 dev_err(cbb
->dev
, "Failed to register CBB Interrupt ISR");
166 cbb
->ops
->error_enable(cbb
);