xref: /freebsd/sys/contrib/alpine-hal/al_hal_udma_debug.h (revision 2414e86439f4c53aff73d1afe0453fb48145d9e5)
1 /*-
2 *******************************************************************************
3 Copyright (C) 2015 Annapurna Labs Ltd.
4 
5 This file may be licensed under the terms of the Annapurna Labs Commercial
6 License Agreement.
7 
8 Alternatively, this file can be distributed under the terms of the GNU General
9 Public License V2 as published by the Free Software Foundation and can be
10 found at http://www.gnu.org/licenses/gpl-2.0.html
11 
12 Alternatively, redistribution and use in source and binary forms, with or
13 without modification, are permitted provided that the following conditions are
14 met:
15 
16     *     Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
18 
19     *     Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in
21 the documentation and/or other materials provided with the
22 distribution.
23 
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 *******************************************************************************/
36 
37 /**
38  * @defgroup group_udma_debug UDMA Debug
39  * @ingroup group_udma_api
40  *  UDMA Debug
41  *  @{
42  * @file   al_hal_udma_debug.h
43  *
44  * @brief C Header file for the Universal DMA HAL driver for debug APIs
45  *
46  */
47 
48 #ifndef __AL_HAL_UDMA_DEBUG_H__
49 #define __AL_HAL_UDMA_DEBUG_H__
50 
51 #include <al_hal_udma.h>
52 
53 /* *INDENT-OFF* */
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 /* *INDENT-ON* */
58 
59 /* UDMA register print helper macros */
60 #define AL_UDMA_PRINT_REG(UDMA, PREFIX, POSTFIX, TYPE, GROUP, REG) \
61 	al_dbg(PREFIX #REG " = 0x%08x" POSTFIX, al_reg_read32( \
62 		&(UDMA->udma_regs->TYPE.GROUP.REG)))
63 
64 #define AL_UDMA_PRINT_REG_FIELD( \
65 		UDMA, PREFIX, POSTFIX, FMT, TYPE, GROUP, REG, LBL, FIELD) \
66 	al_dbg(PREFIX #LBL " = " FMT POSTFIX, al_reg_read32( \
67 			&(UDMA->udma_regs->TYPE.GROUP.REG)) \
68 			& FIELD ## _MASK >> FIELD ## _SHIFT)
69 
70 #define AL_UDMA_PRINT_REG_BIT( \
71 		UDMA, PREFIX, POSTFIX, TYPE, GROUP, REG, LBL, FIELD) \
72 	al_dbg(PREFIX #LBL " = %d" POSTFIX, ((al_reg_read32( \
73 			&(UDMA->udma_regs->TYPE.GROUP.REG)) \
74 			& FIELD) != 0))
75 
76 /* UDMA register print mask definitions */
77 #define AL_UDMA_DEBUG_QUEUE(n)			AL_BIT(n)
78 #define AL_UDMA_DEBUG_AXI			AL_BIT(DMA_MAX_Q)
79 #define AL_UDMA_DEBUG_GENERAL			AL_BIT(DMA_MAX_Q + 1)
80 #define AL_UDMA_DEBUG_READ			AL_BIT(DMA_MAX_Q + 2)
81 #define AL_UDMA_DEBUG_WRITE			AL_BIT(DMA_MAX_Q + 3)
82 #define AL_UDMA_DEBUG_DWRR			AL_BIT(DMA_MAX_Q + 4)
83 #define AL_UDMA_DEBUG_RATE_LIMITER		AL_BIT(DMA_MAX_Q + 5)
84 #define AL_UDMA_DEBUG_STREAM_RATE_LIMITER	AL_BIT(DMA_MAX_Q + 6)
85 #define AL_UDMA_DEBUG_COMP			AL_BIT(DMA_MAX_Q + 7)
86 #define AL_UDMA_DEBUG_STAT			AL_BIT(DMA_MAX_Q + 8)
87 #define AL_UDMA_DEBUG_FEATURE			AL_BIT(DMA_MAX_Q + 9)
88 #define AL_UDMA_DEBUG_ALL			0xFFFFFFFF
89 
90 /* Debug functions */
91 
92 /**
93  * Print udma registers according to the provided mask
94  *
95  * @param udma udma data structure
96  * @param mask mask that specifies which registers groups to print
97  * e.g. AL_UDMA_DEBUG_AXI prints AXI registers, AL_UDMA_DEBUG_ALL prints all
98  * registers
99  */
100 void al_udma_regs_print(struct al_udma *udma, unsigned int mask);
101 
102 /**
103  * Print udma queue software structure
104  *
105  * @param udma udma data structure
106  * @param qid queue index
107  */
108 void al_udma_q_struct_print(struct al_udma *udma, uint32_t qid);
109 
110 /** UDMA ring type */
111 enum al_udma_ring_type {
112 	AL_RING_SUBMISSION,
113 	AL_RING_COMPLETION
114 };
115 
116 /**
117  * Print the ring entries for the specified queue index and ring type
118  * (submission/completion)
119  *
120  * @param udma udma data structure
121  * @param qid queue index
122  * @param rtype udma ring type
123  */
124 void al_udma_ring_print(struct al_udma *udma, uint32_t qid,
125 		enum al_udma_ring_type rtype);
126 
127 
128 /* *INDENT-OFF* */
129 #ifdef __cplusplus
130 }
131 #endif
132 /* *INDENT-ON* */
133 #endif /* __AL_HAL_UDMA_DEBUG_H__ */
134 /** @} end of UDMA debug group */
135