coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
dma.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __NVIDIA_TEGRA124_DMA_H__
4 #define __NVIDIA_TEGRA124_DMA_H__
5 
6 #include <stdint.h>
7 #include <soc/addressmap.h>
8 
9 /*
10  * The DMA engine operates on 4 bytes at a time, so make sure any data
11  * passed via DMA is aligned to avoid underrun/overrun.
12  */
13 #define TEGRA_DMA_ALIGN_BYTES 4
14 
15 /*
16  * Note: Many APB DMA controller registers are laid out such that each
17  * bit controls or represents the status for the corresponding channel.
18  * So we will not bother to list each individual bit in this case.
19  */
20 #define APB_COMMAND_GEN (1 << 31)
21 
22 #define APB_CNTRL_REG_COUNT_VALUE_MASK 0xffff
23 #define APB_CNTRL_REG_COUNT_VALUE_SHIFT 0
24 
25 /*
26  * Note: Many APB DMA controller registers are laid out such that each
27  * bit controls or represents the status for the corresponding channel.
28  * So we will not bother to list each individual bit in this case.
29  */
30 #define APB_COMMAND_GEN (1 << 31)
31 
32 #define APB_CNTRL_REG_COUNT_VALUE_MASK 0xffff
33 #define APB_CNTRL_REG_COUNT_VALUE_SHIFT 0
34 struct apb_dma {
35  u32 command; /* 0x00 */
36  u32 status; /* 0x04 */
37  u32 rsvd1[2];
38  u32 cntrl_reg; /* 0x10 */
39  u32 irq_sta_cpu; /* 0x14 */
40  u32 irq_sta_cop; /* 0x18 */
41  u32 irq_mask; /* 0x1c */
42  u32 irq_mask_set; /* 0x20 */
43  u32 irq_mask_clr; /* 0x24 */
44  u32 trig_reg; /* 0x28 */
45  u32 channel_trig_reg; /* 0x2c */
46  u32 dma_status; /* 0x30 */
47  u32 channel_en_reg; /* 0x34 */
48  u32 security_reg; /* 0x38 */
49  u32 channel_swid; /* 0x3c */
50  u32 rsvd[1];
51  u32 chan_wt_reg0; /* 0x44 */
52  u32 chan_wt_reg1; /* 0x48 */
53  u32 chan_wt_reg2; /* 0x4c */
54  u32 chan_wr_reg3; /* 0x50 */
55  u32 channel_swid1; /* 0x54 */
57 check_member(apb_dma, channel_swid1, 0x54);
58 
59 /*
60  * Naming in the doc included a superfluous _CHANNEL_n_ for
61  * each entry and was left out for the sake of conciseness.
62  */
63 #define APB_CSR_ENB (1 << 31)
64 #define APB_CSR_IE_EOC (1 << 30)
65 #define APB_CSR_HOLD (1 << 29)
66 #define APB_CSR_DIR (1 << 28)
67 #define APB_CSR_ONCE (1 << 27)
68 #define APB_CSR_FLOW (1 << 21)
69 #define APB_CSR_REQ_SEL_MASK 0x1f
70 #define APB_CSR_REQ_SEL_SHIFT 16
71 
105 };
106 
107 #define APB_STA_BSY (1 << 31)
108 #define APB_STA_ISE_EOC (1 << 30)
109 #define APB_STA_HALT (1 << 29)
110 #define APB_STA_PING_PONG_STA (1 << 28)
111 #define APB_STA_DMA_ACTIVITY (1 << 27)
112 #define APB_STA_CHANNEL_PAUSE (1 << 26)
113 
114 #define APB_CSRE_CHANNEL_PAUSE (1 << 31)
115 #define APB_CSRE_TRIG_SEL_MASK 0x3f
116 #define APB_CSRE_TRIG_SEL_SHIFT 14
117 
118 #define AHB_PTR_MASK (0x3fffffff)
119 #define AHB_PTR_SHIFT 2
120 
121 #define AHB_SEQ_INTR_ENB (1 << 31)
122 #define AHB_BUS_WIDTH_MASK 0x7
123 #define AHB_BUS_WIDTH_SHIFT 28
124 #define AHB_DATA_SWAP (1 << 27)
125 #define AHB_BURST_MASK 0x7
126 #define AHB_BURST_SHIFT 24
127 #define AHB_SEQ_DBL_BUF (1 << 19)
128 #define AHB_SEQ_WRAP_MASK 0x7
129 #define AHB_SEQ_WRAP_SHIFT 16
130 
131 #define APB_PTR_MASK 0x3fffffff
132 #define APB_PTR_SHIFT 2
133 
134 #define APB_BUS_WIDTH_MASK 0x7
135 #define APB_BUS_WIDTH_SHIFT 28
136 #define APB_DATA_SWAP (1 << 27)
137 #define APB_ADDR_WRAP_MASK 0x7
138 #define APB_ADDR_WRAP_SHIFT 16
139 
140 #define APB_WORD_TRANSFER_MASK 0x0fffffff
141 #define APB_WORD_TRANSFER_SHIFT 2
142 
144  u32 csr; /* 0x00 */
145  u32 sta; /* 0x04 */
146  u32 dma_byte_sta; /* 0x08 */
147  u32 csre; /* 0x0c */
148  u32 ahb_ptr; /* 0x10 */
149  u32 ahb_seq; /* 0x14 */
150  u32 apb_ptr; /* 0x18 */
151  u32 apb_seq; /* 0x1c */
152  u32 wcount; /* 0x20 */
153  u32 word_transfer; /* 0x24 */
154 } __packed;
155 check_member(apb_dma_channel_regs, word_transfer, 0x24);
156 
158  const int num;
160 
161  /*
162  * Basic high-level semaphore that can be used to "claim"
163  * a DMA channel e.g. by SPI, I2C, or other peripheral driver.
164  */
165  int in_use;
166 };
167 
168 struct apb_dma_channel * const dma_claim(void);
169 void dma_release(struct apb_dma_channel * const channel);
170 int dma_start(struct apb_dma_channel * const channel);
171 int dma_stop(struct apb_dma_channel * const channel);
172 int dma_busy(struct apb_dma_channel * const channel);
173 
174 #endif /* __NVIDIA_TEGRA124_DMA_H__ */
uint32_t u32
Definition: stdint.h:51
const int num
Definition: dma.h:158
struct apb_dma_channel_regs * regs
Definition: dma.h:159
int in_use
Definition: dma.h:165
Definition: dma.h:34
u32 channel_swid1
Definition: dma.h:55
u32 cntrl_reg
Definition: dma.h:38
u32 rsvd[1]
Definition: dma.h:50
u32 irq_mask
Definition: dma.h:41
u32 chan_wt_reg1
Definition: dma.h:52
u32 irq_sta_cpu
Definition: dma.h:39
u32 trig_reg
Definition: dma.h:44
u32 channel_swid
Definition: dma.h:49
u32 channel_en_reg
Definition: dma.h:47
u32 chan_wt_reg2
Definition: dma.h:53
u32 chan_wr_reg3
Definition: dma.h:54
u32 irq_sta_cop
Definition: dma.h:40
u32 chan_wt_reg0
Definition: dma.h:51
u32 dma_status
Definition: dma.h:46
u32 security_reg
Definition: dma.h:48
u32 rsvd1[2]
Definition: dma.h:37
u32 irq_mask_clr
Definition: dma.h:43
u32 channel_trig_reg
Definition: dma.h:45
u32 command
Definition: dma.h:35
u32 irq_mask_set
Definition: dma.h:42
u32 status
Definition: dma.h:36
check_member(apb_dma, channel_swid1, 0x54)
int dma_start(struct apb_dma_channel *const channel)
Definition: dma.c:111
struct apb_dma __packed
int dma_stop(struct apb_dma_channel *const channel)
Definition: dma.c:121
void dma_release(struct apb_dma_channel *const channel)
Definition: dma.c:92
int dma_busy(struct apb_dma_channel *const channel)
Definition: dma.c:48
apbdmachan_req_sel
Definition: dma.h:72
@ APBDMA_SLAVE_DVC_I2C
Definition: dma.h:97
@ APBDMA_SLAVE_I2C4
Definition: dma.h:99
@ APBDMA_SLAVE_APBIF_CH5
Definition: dma.h:80
@ APBDMA_SLAVE_APBIF_CH8
Definition: dma.h:87
@ APBDMA_SLAVE_APBIF_CH7
Definition: dma.h:86
@ APBDMA_SLAVE_APBIF_CH9
Definition: dma.h:102
@ APBDMA_SLAVE_SL2B3
Definition: dma.h:90
@ APBDMA_SLAVE_UART_A
Definition: dma.h:81
@ APBDMA_SLAVE_SL2B6
Definition: dma.h:101
@ APBDMA_SLAVE_UART_C
Definition: dma.h:83
@ APBDMA_SLAVE_APBIF_CH6
Definition: dma.h:85
@ APBDMA_SLAVE_APBIF_CH2
Definition: dma.h:76
@ APBDMA_SLAVE_CNTR_REQ
Definition: dma.h:73
@ APBDMA_SLAVE_UART_E
Definition: dma.h:93
@ APBDMA_SLAVE_APBIF_CH0
Definition: dma.h:74
@ APBDMA_SLAVE_APBIF_CH1
Definition: dma.h:75
@ APBDMA_SLAVE_SL2B4
Definition: dma.h:91
@ APBDMA_SLAVE_HSI
Definition: dma.h:78
@ APBDMA_SLAVE_SL2B2
Definition: dma.h:89
@ APBDMA_SLAVE_UART_D
Definition: dma.h:92
@ APBDMA_SLAVE_I2C
Definition: dma.h:94
@ APBDMA_SLAVE_I2C6
Definition: dma.h:103
@ APBDMA_SLAVE_APBIF_CH3
Definition: dma.h:77
@ APBDMA_SLAVE_SL2B1
Definition: dma.h:88
@ APBDMA_SLAVE_UART_B
Definition: dma.h:82
@ APBDMA_SLAVE_APBIF_CH4
Definition: dma.h:79
@ APBDMA_SLAVE_SL2B5
Definition: dma.h:100
@ APBDMA_SLAVE_OWR
Definition: dma.h:98
@ APBDMA_SLAVE_DTV
Definition: dma.h:84
@ APBDMA_SLAVE_NA31
Definition: dma.h:104
@ APBDMA_SLAVE_I2C3
Definition: dma.h:96
@ APBDMA_SLAVE_I2C2
Definition: dma.h:95
struct apb_dma_channel *const dma_claim(void)
Definition: dma.c:59