1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2023 Cai Huoqing
4 * Synopsys DesignWare HDMA v0 debugfs
6 * Author: Cai Huoqing <cai.huoqing@linux.dev>
9 #include <linux/debugfs.h>
10 #include <linux/bitfield.h>
12 #include "dw-hdma-v0-debugfs.h"
13 #include "dw-hdma-v0-regs.h"
14 #include "dw-edma-core.h"
16 #define REGS_ADDR(dw, name) \
18 struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
20 (void __iomem *)&__regs->name; \
23 #define REGS_CH_ADDR(dw, name, _dir, _ch) \
25 struct dw_hdma_v0_ch_regs __iomem *__ch_regs; \
27 if (_dir == EDMA_DIR_READ) \
28 __ch_regs = REGS_ADDR(dw, ch[_ch].rd); \
30 __ch_regs = REGS_ADDR(dw, ch[_ch].wr); \
32 (void __iomem *)&__ch_regs->name; \
35 #define CTX_REGISTER(dw, name, dir, ch) \
36 {#name, REGS_CH_ADDR(dw, name, dir, ch)}
38 #define WRITE_STR "write"
39 #define READ_STR "read"
40 #define CHANNEL_STR "channel"
41 #define REGISTERS_STR "registers"
43 struct dw_hdma_debugfs_entry
{
48 static int dw_hdma_debugfs_u32_get(void *data
, u64
*val
)
50 struct dw_hdma_debugfs_entry
*entry
= data
;
51 void __iomem
*reg
= entry
->reg
;
57 DEFINE_DEBUGFS_ATTRIBUTE(fops_x32
, dw_hdma_debugfs_u32_get
, NULL
, "0x%08llx\n");
59 static void dw_hdma_debugfs_create_x32(struct dw_edma
*dw
,
60 const struct dw_hdma_debugfs_entry ini
[],
61 int nr_entries
, struct dentry
*dent
)
63 struct dw_hdma_debugfs_entry
*entries
;
66 entries
= devm_kcalloc(dw
->chip
->dev
, nr_entries
, sizeof(*entries
),
71 for (i
= 0; i
< nr_entries
; i
++) {
74 debugfs_create_file_unsafe(entries
[i
].name
, 0444, dent
,
75 &entries
[i
], &fops_x32
);
79 static void dw_hdma_debugfs_regs_ch(struct dw_edma
*dw
, enum dw_edma_dir dir
,
80 u16 ch
, struct dentry
*dent
)
82 const struct dw_hdma_debugfs_entry debugfs_regs
[] = {
83 CTX_REGISTER(dw
, ch_en
, dir
, ch
),
84 CTX_REGISTER(dw
, doorbell
, dir
, ch
),
85 CTX_REGISTER(dw
, prefetch
, dir
, ch
),
86 CTX_REGISTER(dw
, handshake
, dir
, ch
),
87 CTX_REGISTER(dw
, llp
.lsb
, dir
, ch
),
88 CTX_REGISTER(dw
, llp
.msb
, dir
, ch
),
89 CTX_REGISTER(dw
, cycle_sync
, dir
, ch
),
90 CTX_REGISTER(dw
, transfer_size
, dir
, ch
),
91 CTX_REGISTER(dw
, sar
.lsb
, dir
, ch
),
92 CTX_REGISTER(dw
, sar
.msb
, dir
, ch
),
93 CTX_REGISTER(dw
, dar
.lsb
, dir
, ch
),
94 CTX_REGISTER(dw
, dar
.msb
, dir
, ch
),
95 CTX_REGISTER(dw
, watermark_en
, dir
, ch
),
96 CTX_REGISTER(dw
, control1
, dir
, ch
),
97 CTX_REGISTER(dw
, func_num
, dir
, ch
),
98 CTX_REGISTER(dw
, qos
, dir
, ch
),
99 CTX_REGISTER(dw
, ch_stat
, dir
, ch
),
100 CTX_REGISTER(dw
, int_stat
, dir
, ch
),
101 CTX_REGISTER(dw
, int_setup
, dir
, ch
),
102 CTX_REGISTER(dw
, int_clear
, dir
, ch
),
103 CTX_REGISTER(dw
, msi_stop
.lsb
, dir
, ch
),
104 CTX_REGISTER(dw
, msi_stop
.msb
, dir
, ch
),
105 CTX_REGISTER(dw
, msi_watermark
.lsb
, dir
, ch
),
106 CTX_REGISTER(dw
, msi_watermark
.msb
, dir
, ch
),
107 CTX_REGISTER(dw
, msi_abort
.lsb
, dir
, ch
),
108 CTX_REGISTER(dw
, msi_abort
.msb
, dir
, ch
),
109 CTX_REGISTER(dw
, msi_msgdata
, dir
, ch
),
111 int nr_entries
= ARRAY_SIZE(debugfs_regs
);
113 dw_hdma_debugfs_create_x32(dw
, debugfs_regs
, nr_entries
, dent
);
116 static void dw_hdma_debugfs_regs_wr(struct dw_edma
*dw
, struct dentry
*dent
)
118 struct dentry
*regs_dent
, *ch_dent
;
122 regs_dent
= debugfs_create_dir(WRITE_STR
, dent
);
124 for (i
= 0; i
< dw
->wr_ch_cnt
; i
++) {
125 snprintf(name
, sizeof(name
), "%s:%d", CHANNEL_STR
, i
);
127 ch_dent
= debugfs_create_dir(name
, regs_dent
);
129 dw_hdma_debugfs_regs_ch(dw
, EDMA_DIR_WRITE
, i
, ch_dent
);
133 static void dw_hdma_debugfs_regs_rd(struct dw_edma
*dw
, struct dentry
*dent
)
135 struct dentry
*regs_dent
, *ch_dent
;
139 regs_dent
= debugfs_create_dir(READ_STR
, dent
);
141 for (i
= 0; i
< dw
->rd_ch_cnt
; i
++) {
142 snprintf(name
, sizeof(name
), "%s:%d", CHANNEL_STR
, i
);
144 ch_dent
= debugfs_create_dir(name
, regs_dent
);
146 dw_hdma_debugfs_regs_ch(dw
, EDMA_DIR_READ
, i
, ch_dent
);
150 static void dw_hdma_debugfs_regs(struct dw_edma
*dw
)
152 struct dentry
*regs_dent
;
154 regs_dent
= debugfs_create_dir(REGISTERS_STR
, dw
->dma
.dbg_dev_root
);
156 dw_hdma_debugfs_regs_wr(dw
, regs_dent
);
157 dw_hdma_debugfs_regs_rd(dw
, regs_dent
);
160 void dw_hdma_v0_debugfs_on(struct dw_edma
*dw
)
162 if (!debugfs_initialized())
165 debugfs_create_u32("mf", 0444, dw
->dma
.dbg_dev_root
, &dw
->chip
->mf
);
166 debugfs_create_u16("wr_ch_cnt", 0444, dw
->dma
.dbg_dev_root
, &dw
->wr_ch_cnt
);
167 debugfs_create_u16("rd_ch_cnt", 0444, dw
->dma
.dbg_dev_root
, &dw
->rd_ch_cnt
);
169 dw_hdma_debugfs_regs(dw
);