root / hw / mac_dbdma.c @ c6df7102
History | View | Annotate | Download (21.4 kB)
1 | 3cbee15b | j_mayer | /*
|
---|---|---|---|
2 | 3cbee15b | j_mayer | * PowerMac descriptor-based DMA emulation
|
3 | 3cbee15b | j_mayer | *
|
4 | 3cbee15b | j_mayer | * Copyright (c) 2005-2007 Fabrice Bellard
|
5 | 3cbee15b | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
6 | 28ce5ce6 | aurel32 | * Copyright (c) 2009 Laurent Vivier
|
7 | 28ce5ce6 | aurel32 | *
|
8 | 28ce5ce6 | aurel32 | * some parts from linux-2.6.28, arch/powerpc/include/asm/dbdma.h
|
9 | 28ce5ce6 | aurel32 | *
|
10 | 28ce5ce6 | aurel32 | * Definitions for using the Apple Descriptor-Based DMA controller
|
11 | 28ce5ce6 | aurel32 | * in Power Macintosh computers.
|
12 | 28ce5ce6 | aurel32 | *
|
13 | 28ce5ce6 | aurel32 | * Copyright (C) 1996 Paul Mackerras.
|
14 | 28ce5ce6 | aurel32 | *
|
15 | 28ce5ce6 | aurel32 | * some parts from mol 0.9.71
|
16 | 28ce5ce6 | aurel32 | *
|
17 | 28ce5ce6 | aurel32 | * Descriptor based DMA emulation
|
18 | 28ce5ce6 | aurel32 | *
|
19 | 28ce5ce6 | aurel32 | * Copyright (C) 1998-2004 Samuel Rydh (samuel@ibrium.se)
|
20 | 3cbee15b | j_mayer | *
|
21 | 3cbee15b | j_mayer | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
22 | 3cbee15b | j_mayer | * of this software and associated documentation files (the "Software"), to deal
|
23 | 3cbee15b | j_mayer | * in the Software without restriction, including without limitation the rights
|
24 | 3cbee15b | j_mayer | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
25 | 3cbee15b | j_mayer | * copies of the Software, and to permit persons to whom the Software is
|
26 | 3cbee15b | j_mayer | * furnished to do so, subject to the following conditions:
|
27 | 3cbee15b | j_mayer | *
|
28 | 3cbee15b | j_mayer | * The above copyright notice and this permission notice shall be included in
|
29 | 3cbee15b | j_mayer | * all copies or substantial portions of the Software.
|
30 | 3cbee15b | j_mayer | *
|
31 | 3cbee15b | j_mayer | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32 | 3cbee15b | j_mayer | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
33 | 3cbee15b | j_mayer | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
34 | 3cbee15b | j_mayer | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
35 | 3cbee15b | j_mayer | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
36 | 3cbee15b | j_mayer | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
37 | 3cbee15b | j_mayer | * THE SOFTWARE.
|
38 | 3cbee15b | j_mayer | */
|
39 | 87ecb68b | pbrook | #include "hw.h" |
40 | 28ce5ce6 | aurel32 | #include "isa.h" |
41 | 28ce5ce6 | aurel32 | #include "mac_dbdma.h" |
42 | 3cbee15b | j_mayer | |
43 | ea026b2f | blueswir1 | /* debug DBDMA */
|
44 | ea026b2f | blueswir1 | //#define DEBUG_DBDMA
|
45 | ea026b2f | blueswir1 | |
46 | ea026b2f | blueswir1 | #ifdef DEBUG_DBDMA
|
47 | 001faf32 | Blue Swirl | #define DBDMA_DPRINTF(fmt, ...) \
|
48 | 001faf32 | Blue Swirl | do { printf("DBDMA: " fmt , ## __VA_ARGS__); } while (0) |
49 | ea026b2f | blueswir1 | #else
|
50 | 001faf32 | Blue Swirl | #define DBDMA_DPRINTF(fmt, ...)
|
51 | ea026b2f | blueswir1 | #endif
|
52 | ea026b2f | blueswir1 | |
53 | 28ce5ce6 | aurel32 | /*
|
54 | 28ce5ce6 | aurel32 | */
|
55 | 28ce5ce6 | aurel32 | |
56 | 28ce5ce6 | aurel32 | /*
|
57 | 28ce5ce6 | aurel32 | * DBDMA control/status registers. All little-endian.
|
58 | 28ce5ce6 | aurel32 | */
|
59 | 3cbee15b | j_mayer | |
60 | 28ce5ce6 | aurel32 | #define DBDMA_CONTROL 0x00 |
61 | 28ce5ce6 | aurel32 | #define DBDMA_STATUS 0x01 |
62 | 28ce5ce6 | aurel32 | #define DBDMA_CMDPTR_HI 0x02 |
63 | 28ce5ce6 | aurel32 | #define DBDMA_CMDPTR_LO 0x03 |
64 | 28ce5ce6 | aurel32 | #define DBDMA_INTR_SEL 0x04 |
65 | 28ce5ce6 | aurel32 | #define DBDMA_BRANCH_SEL 0x05 |
66 | 28ce5ce6 | aurel32 | #define DBDMA_WAIT_SEL 0x06 |
67 | 28ce5ce6 | aurel32 | #define DBDMA_XFER_MODE 0x07 |
68 | 28ce5ce6 | aurel32 | #define DBDMA_DATA2PTR_HI 0x08 |
69 | 28ce5ce6 | aurel32 | #define DBDMA_DATA2PTR_LO 0x09 |
70 | 28ce5ce6 | aurel32 | #define DBDMA_RES1 0x0A |
71 | 28ce5ce6 | aurel32 | #define DBDMA_ADDRESS_HI 0x0B |
72 | 28ce5ce6 | aurel32 | #define DBDMA_BRANCH_ADDR_HI 0x0C |
73 | 28ce5ce6 | aurel32 | #define DBDMA_RES2 0x0D |
74 | 28ce5ce6 | aurel32 | #define DBDMA_RES3 0x0E |
75 | 28ce5ce6 | aurel32 | #define DBDMA_RES4 0x0F |
76 | 28ce5ce6 | aurel32 | |
77 | 28ce5ce6 | aurel32 | #define DBDMA_REGS 16 |
78 | 28ce5ce6 | aurel32 | #define DBDMA_SIZE (DBDMA_REGS * sizeof(uint32_t)) |
79 | 28ce5ce6 | aurel32 | |
80 | 28ce5ce6 | aurel32 | #define DBDMA_CHANNEL_SHIFT 7 |
81 | 28ce5ce6 | aurel32 | #define DBDMA_CHANNEL_SIZE (1 << DBDMA_CHANNEL_SHIFT) |
82 | 28ce5ce6 | aurel32 | |
83 | 28ce5ce6 | aurel32 | #define DBDMA_CHANNELS (0x1000 >> DBDMA_CHANNEL_SHIFT) |
84 | 28ce5ce6 | aurel32 | |
85 | 28ce5ce6 | aurel32 | /* Bits in control and status registers */
|
86 | 28ce5ce6 | aurel32 | |
87 | 28ce5ce6 | aurel32 | #define RUN 0x8000 |
88 | 28ce5ce6 | aurel32 | #define PAUSE 0x4000 |
89 | 28ce5ce6 | aurel32 | #define FLUSH 0x2000 |
90 | 28ce5ce6 | aurel32 | #define WAKE 0x1000 |
91 | 28ce5ce6 | aurel32 | #define DEAD 0x0800 |
92 | 28ce5ce6 | aurel32 | #define ACTIVE 0x0400 |
93 | 28ce5ce6 | aurel32 | #define BT 0x0100 |
94 | 28ce5ce6 | aurel32 | #define DEVSTAT 0x00ff |
95 | 28ce5ce6 | aurel32 | |
96 | 28ce5ce6 | aurel32 | /*
|
97 | 28ce5ce6 | aurel32 | * DBDMA command structure. These fields are all little-endian!
|
98 | 28ce5ce6 | aurel32 | */
|
99 | 28ce5ce6 | aurel32 | |
100 | 28ce5ce6 | aurel32 | typedef struct dbdma_cmd { |
101 | 28ce5ce6 | aurel32 | uint16_t req_count; /* requested byte transfer count */
|
102 | 28ce5ce6 | aurel32 | uint16_t command; /* command word (has bit-fields) */
|
103 | 28ce5ce6 | aurel32 | uint32_t phy_addr; /* physical data address */
|
104 | 28ce5ce6 | aurel32 | uint32_t cmd_dep; /* command-dependent field */
|
105 | 28ce5ce6 | aurel32 | uint16_t res_count; /* residual count after completion */
|
106 | 28ce5ce6 | aurel32 | uint16_t xfer_status; /* transfer status */
|
107 | 28ce5ce6 | aurel32 | } dbdma_cmd; |
108 | 28ce5ce6 | aurel32 | |
109 | 28ce5ce6 | aurel32 | /* DBDMA command values in command field */
|
110 | 28ce5ce6 | aurel32 | |
111 | 28ce5ce6 | aurel32 | #define COMMAND_MASK 0xf000 |
112 | 28ce5ce6 | aurel32 | #define OUTPUT_MORE 0x0000 /* transfer memory data to stream */ |
113 | 28ce5ce6 | aurel32 | #define OUTPUT_LAST 0x1000 /* ditto followed by end marker */ |
114 | 28ce5ce6 | aurel32 | #define INPUT_MORE 0x2000 /* transfer stream data to memory */ |
115 | 28ce5ce6 | aurel32 | #define INPUT_LAST 0x3000 /* ditto, expect end marker */ |
116 | 28ce5ce6 | aurel32 | #define STORE_WORD 0x4000 /* write word (4 bytes) to device reg */ |
117 | 28ce5ce6 | aurel32 | #define LOAD_WORD 0x5000 /* read word (4 bytes) from device reg */ |
118 | 28ce5ce6 | aurel32 | #define DBDMA_NOP 0x6000 /* do nothing */ |
119 | 28ce5ce6 | aurel32 | #define DBDMA_STOP 0x7000 /* suspend processing */ |
120 | 28ce5ce6 | aurel32 | |
121 | 28ce5ce6 | aurel32 | /* Key values in command field */
|
122 | 28ce5ce6 | aurel32 | |
123 | 28ce5ce6 | aurel32 | #define KEY_MASK 0x0700 |
124 | 28ce5ce6 | aurel32 | #define KEY_STREAM0 0x0000 /* usual data stream */ |
125 | 28ce5ce6 | aurel32 | #define KEY_STREAM1 0x0100 /* control/status stream */ |
126 | 28ce5ce6 | aurel32 | #define KEY_STREAM2 0x0200 /* device-dependent stream */ |
127 | 28ce5ce6 | aurel32 | #define KEY_STREAM3 0x0300 /* device-dependent stream */ |
128 | 28ce5ce6 | aurel32 | #define KEY_STREAM4 0x0400 /* reserved */ |
129 | 28ce5ce6 | aurel32 | #define KEY_REGS 0x0500 /* device register space */ |
130 | 28ce5ce6 | aurel32 | #define KEY_SYSTEM 0x0600 /* system memory-mapped space */ |
131 | 28ce5ce6 | aurel32 | #define KEY_DEVICE 0x0700 /* device memory-mapped space */ |
132 | 28ce5ce6 | aurel32 | |
133 | 28ce5ce6 | aurel32 | /* Interrupt control values in command field */
|
134 | 28ce5ce6 | aurel32 | |
135 | 28ce5ce6 | aurel32 | #define INTR_MASK 0x0030 |
136 | 28ce5ce6 | aurel32 | #define INTR_NEVER 0x0000 /* don't interrupt */ |
137 | 28ce5ce6 | aurel32 | #define INTR_IFSET 0x0010 /* intr if condition bit is 1 */ |
138 | 28ce5ce6 | aurel32 | #define INTR_IFCLR 0x0020 /* intr if condition bit is 0 */ |
139 | 28ce5ce6 | aurel32 | #define INTR_ALWAYS 0x0030 /* always interrupt */ |
140 | 28ce5ce6 | aurel32 | |
141 | 28ce5ce6 | aurel32 | /* Branch control values in command field */
|
142 | 28ce5ce6 | aurel32 | |
143 | 28ce5ce6 | aurel32 | #define BR_MASK 0x000c |
144 | 28ce5ce6 | aurel32 | #define BR_NEVER 0x0000 /* don't branch */ |
145 | 28ce5ce6 | aurel32 | #define BR_IFSET 0x0004 /* branch if condition bit is 1 */ |
146 | 28ce5ce6 | aurel32 | #define BR_IFCLR 0x0008 /* branch if condition bit is 0 */ |
147 | 28ce5ce6 | aurel32 | #define BR_ALWAYS 0x000c /* always branch */ |
148 | 28ce5ce6 | aurel32 | |
149 | 28ce5ce6 | aurel32 | /* Wait control values in command field */
|
150 | 28ce5ce6 | aurel32 | |
151 | 28ce5ce6 | aurel32 | #define WAIT_MASK 0x0003 |
152 | 28ce5ce6 | aurel32 | #define WAIT_NEVER 0x0000 /* don't wait */ |
153 | 28ce5ce6 | aurel32 | #define WAIT_IFSET 0x0001 /* wait if condition bit is 1 */ |
154 | 28ce5ce6 | aurel32 | #define WAIT_IFCLR 0x0002 /* wait if condition bit is 0 */ |
155 | 28ce5ce6 | aurel32 | #define WAIT_ALWAYS 0x0003 /* always wait */ |
156 | 28ce5ce6 | aurel32 | |
157 | 28ce5ce6 | aurel32 | typedef struct DBDMA_channel { |
158 | 28ce5ce6 | aurel32 | int channel;
|
159 | 28ce5ce6 | aurel32 | uint32_t regs[DBDMA_REGS]; |
160 | 28ce5ce6 | aurel32 | qemu_irq irq; |
161 | b42ec42d | aurel32 | DBDMA_io io; |
162 | b42ec42d | aurel32 | DBDMA_rw rw; |
163 | 862c9280 | aurel32 | DBDMA_flush flush; |
164 | 28ce5ce6 | aurel32 | dbdma_cmd current; |
165 | b42ec42d | aurel32 | int processing;
|
166 | 28ce5ce6 | aurel32 | } DBDMA_channel; |
167 | 28ce5ce6 | aurel32 | |
168 | c20df14b | Juan Quintela | typedef struct { |
169 | c20df14b | Juan Quintela | DBDMA_channel channels[DBDMA_CHANNELS]; |
170 | c20df14b | Juan Quintela | } DBDMAState; |
171 | c20df14b | Juan Quintela | |
172 | 28ce5ce6 | aurel32 | #ifdef DEBUG_DBDMA
|
173 | 28ce5ce6 | aurel32 | static void dump_dbdma_cmd(dbdma_cmd *cmd) |
174 | 28ce5ce6 | aurel32 | { |
175 | 28ce5ce6 | aurel32 | printf("dbdma_cmd %p\n", cmd);
|
176 | 28ce5ce6 | aurel32 | printf(" req_count 0x%04x\n", le16_to_cpu(cmd->req_count));
|
177 | 28ce5ce6 | aurel32 | printf(" command 0x%04x\n", le16_to_cpu(cmd->command));
|
178 | 28ce5ce6 | aurel32 | printf(" phy_addr 0x%08x\n", le32_to_cpu(cmd->phy_addr));
|
179 | 28ce5ce6 | aurel32 | printf(" cmd_dep 0x%08x\n", le32_to_cpu(cmd->cmd_dep));
|
180 | 28ce5ce6 | aurel32 | printf(" res_count 0x%04x\n", le16_to_cpu(cmd->res_count));
|
181 | 28ce5ce6 | aurel32 | printf(" xfer_status 0x%04x\n", le16_to_cpu(cmd->xfer_status));
|
182 | 28ce5ce6 | aurel32 | } |
183 | 28ce5ce6 | aurel32 | #else
|
184 | 28ce5ce6 | aurel32 | static void dump_dbdma_cmd(dbdma_cmd *cmd) |
185 | 3cbee15b | j_mayer | { |
186 | 28ce5ce6 | aurel32 | } |
187 | 28ce5ce6 | aurel32 | #endif
|
188 | 28ce5ce6 | aurel32 | static void dbdma_cmdptr_load(DBDMA_channel *ch) |
189 | 28ce5ce6 | aurel32 | { |
190 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("dbdma_cmdptr_load 0x%08x\n",
|
191 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_CMDPTR_LO]); |
192 | ad674e53 | Aurelien Jarno | cpu_physical_memory_read(ch->regs[DBDMA_CMDPTR_LO], |
193 | 28ce5ce6 | aurel32 | (uint8_t*)&ch->current, sizeof(dbdma_cmd));
|
194 | 3cbee15b | j_mayer | } |
195 | 3cbee15b | j_mayer | |
196 | 28ce5ce6 | aurel32 | static void dbdma_cmdptr_save(DBDMA_channel *ch) |
197 | 3cbee15b | j_mayer | { |
198 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("dbdma_cmdptr_save 0x%08x\n",
|
199 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_CMDPTR_LO]); |
200 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("xfer_status 0x%08x res_count 0x%04x\n",
|
201 | 28ce5ce6 | aurel32 | le16_to_cpu(ch->current.xfer_status), |
202 | 28ce5ce6 | aurel32 | le16_to_cpu(ch->current.res_count)); |
203 | ad674e53 | Aurelien Jarno | cpu_physical_memory_write(ch->regs[DBDMA_CMDPTR_LO], |
204 | 28ce5ce6 | aurel32 | (uint8_t*)&ch->current, sizeof(dbdma_cmd));
|
205 | 3cbee15b | j_mayer | } |
206 | 3cbee15b | j_mayer | |
207 | 28ce5ce6 | aurel32 | static void kill_channel(DBDMA_channel *ch) |
208 | 3cbee15b | j_mayer | { |
209 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("kill_channel\n");
|
210 | 28ce5ce6 | aurel32 | |
211 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] |= DEAD; |
212 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~ACTIVE; |
213 | 28ce5ce6 | aurel32 | |
214 | 28ce5ce6 | aurel32 | qemu_irq_raise(ch->irq); |
215 | 28ce5ce6 | aurel32 | } |
216 | 28ce5ce6 | aurel32 | |
217 | 28ce5ce6 | aurel32 | static void conditional_interrupt(DBDMA_channel *ch) |
218 | 28ce5ce6 | aurel32 | { |
219 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
220 | 28ce5ce6 | aurel32 | uint16_t intr; |
221 | 28ce5ce6 | aurel32 | uint16_t sel_mask, sel_value; |
222 | 28ce5ce6 | aurel32 | uint32_t status; |
223 | 28ce5ce6 | aurel32 | int cond;
|
224 | 28ce5ce6 | aurel32 | |
225 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("conditional_interrupt\n");
|
226 | 28ce5ce6 | aurel32 | |
227 | b42ec42d | aurel32 | intr = le16_to_cpu(current->command) & INTR_MASK; |
228 | 28ce5ce6 | aurel32 | |
229 | 28ce5ce6 | aurel32 | switch(intr) {
|
230 | 28ce5ce6 | aurel32 | case INTR_NEVER: /* don't interrupt */ |
231 | 28ce5ce6 | aurel32 | return;
|
232 | 28ce5ce6 | aurel32 | case INTR_ALWAYS: /* always interrupt */ |
233 | 28ce5ce6 | aurel32 | qemu_irq_raise(ch->irq); |
234 | 28ce5ce6 | aurel32 | return;
|
235 | 28ce5ce6 | aurel32 | } |
236 | 28ce5ce6 | aurel32 | |
237 | ad674e53 | Aurelien Jarno | status = ch->regs[DBDMA_STATUS] & DEVSTAT; |
238 | 28ce5ce6 | aurel32 | |
239 | ad674e53 | Aurelien Jarno | sel_mask = (ch->regs[DBDMA_INTR_SEL] >> 16) & 0x0f; |
240 | ad674e53 | Aurelien Jarno | sel_value = ch->regs[DBDMA_INTR_SEL] & 0x0f;
|
241 | 28ce5ce6 | aurel32 | |
242 | 28ce5ce6 | aurel32 | cond = (status & sel_mask) == (sel_value & sel_mask); |
243 | 28ce5ce6 | aurel32 | |
244 | 28ce5ce6 | aurel32 | switch(intr) {
|
245 | 28ce5ce6 | aurel32 | case INTR_IFSET: /* intr if condition bit is 1 */ |
246 | 28ce5ce6 | aurel32 | if (cond)
|
247 | 28ce5ce6 | aurel32 | qemu_irq_raise(ch->irq); |
248 | 28ce5ce6 | aurel32 | return;
|
249 | 28ce5ce6 | aurel32 | case INTR_IFCLR: /* intr if condition bit is 0 */ |
250 | 28ce5ce6 | aurel32 | if (!cond)
|
251 | 28ce5ce6 | aurel32 | qemu_irq_raise(ch->irq); |
252 | 28ce5ce6 | aurel32 | return;
|
253 | 28ce5ce6 | aurel32 | } |
254 | 28ce5ce6 | aurel32 | } |
255 | 28ce5ce6 | aurel32 | |
256 | 28ce5ce6 | aurel32 | static int conditional_wait(DBDMA_channel *ch) |
257 | 28ce5ce6 | aurel32 | { |
258 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
259 | 28ce5ce6 | aurel32 | uint16_t wait; |
260 | 28ce5ce6 | aurel32 | uint16_t sel_mask, sel_value; |
261 | 28ce5ce6 | aurel32 | uint32_t status; |
262 | 28ce5ce6 | aurel32 | int cond;
|
263 | 28ce5ce6 | aurel32 | |
264 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("conditional_wait\n");
|
265 | 28ce5ce6 | aurel32 | |
266 | b42ec42d | aurel32 | wait = le16_to_cpu(current->command) & WAIT_MASK; |
267 | 28ce5ce6 | aurel32 | |
268 | 28ce5ce6 | aurel32 | switch(wait) {
|
269 | 28ce5ce6 | aurel32 | case WAIT_NEVER: /* don't wait */ |
270 | 28ce5ce6 | aurel32 | return 0; |
271 | 28ce5ce6 | aurel32 | case WAIT_ALWAYS: /* always wait */ |
272 | 28ce5ce6 | aurel32 | return 1; |
273 | 28ce5ce6 | aurel32 | } |
274 | 28ce5ce6 | aurel32 | |
275 | ad674e53 | Aurelien Jarno | status = ch->regs[DBDMA_STATUS] & DEVSTAT; |
276 | 28ce5ce6 | aurel32 | |
277 | ad674e53 | Aurelien Jarno | sel_mask = (ch->regs[DBDMA_WAIT_SEL] >> 16) & 0x0f; |
278 | ad674e53 | Aurelien Jarno | sel_value = ch->regs[DBDMA_WAIT_SEL] & 0x0f;
|
279 | 28ce5ce6 | aurel32 | |
280 | 28ce5ce6 | aurel32 | cond = (status & sel_mask) == (sel_value & sel_mask); |
281 | 28ce5ce6 | aurel32 | |
282 | 28ce5ce6 | aurel32 | switch(wait) {
|
283 | 28ce5ce6 | aurel32 | case WAIT_IFSET: /* wait if condition bit is 1 */ |
284 | 28ce5ce6 | aurel32 | if (cond)
|
285 | 28ce5ce6 | aurel32 | return 1; |
286 | 28ce5ce6 | aurel32 | return 0; |
287 | 28ce5ce6 | aurel32 | case WAIT_IFCLR: /* wait if condition bit is 0 */ |
288 | 28ce5ce6 | aurel32 | if (!cond)
|
289 | 28ce5ce6 | aurel32 | return 1; |
290 | 28ce5ce6 | aurel32 | return 0; |
291 | 28ce5ce6 | aurel32 | } |
292 | 28ce5ce6 | aurel32 | return 0; |
293 | 28ce5ce6 | aurel32 | } |
294 | 28ce5ce6 | aurel32 | |
295 | 28ce5ce6 | aurel32 | static void next(DBDMA_channel *ch) |
296 | 28ce5ce6 | aurel32 | { |
297 | 28ce5ce6 | aurel32 | uint32_t cp; |
298 | 28ce5ce6 | aurel32 | |
299 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~BT; |
300 | 28ce5ce6 | aurel32 | |
301 | ad674e53 | Aurelien Jarno | cp = ch->regs[DBDMA_CMDPTR_LO]; |
302 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_CMDPTR_LO] = cp + sizeof(dbdma_cmd);
|
303 | 28ce5ce6 | aurel32 | dbdma_cmdptr_load(ch); |
304 | 28ce5ce6 | aurel32 | } |
305 | 28ce5ce6 | aurel32 | |
306 | 28ce5ce6 | aurel32 | static void branch(DBDMA_channel *ch) |
307 | 28ce5ce6 | aurel32 | { |
308 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
309 | 28ce5ce6 | aurel32 | |
310 | 28ce5ce6 | aurel32 | ch->regs[DBDMA_CMDPTR_LO] = current->cmd_dep; |
311 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] |= BT; |
312 | 28ce5ce6 | aurel32 | dbdma_cmdptr_load(ch); |
313 | 28ce5ce6 | aurel32 | } |
314 | 28ce5ce6 | aurel32 | |
315 | 28ce5ce6 | aurel32 | static void conditional_branch(DBDMA_channel *ch) |
316 | 28ce5ce6 | aurel32 | { |
317 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
318 | 28ce5ce6 | aurel32 | uint16_t br; |
319 | 28ce5ce6 | aurel32 | uint16_t sel_mask, sel_value; |
320 | 28ce5ce6 | aurel32 | uint32_t status; |
321 | 28ce5ce6 | aurel32 | int cond;
|
322 | 28ce5ce6 | aurel32 | |
323 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("conditional_branch\n");
|
324 | 28ce5ce6 | aurel32 | |
325 | 28ce5ce6 | aurel32 | /* check if we must branch */
|
326 | 28ce5ce6 | aurel32 | |
327 | b42ec42d | aurel32 | br = le16_to_cpu(current->command) & BR_MASK; |
328 | 28ce5ce6 | aurel32 | |
329 | 28ce5ce6 | aurel32 | switch(br) {
|
330 | 28ce5ce6 | aurel32 | case BR_NEVER: /* don't branch */ |
331 | 28ce5ce6 | aurel32 | next(ch); |
332 | 28ce5ce6 | aurel32 | return;
|
333 | 28ce5ce6 | aurel32 | case BR_ALWAYS: /* always branch */ |
334 | 28ce5ce6 | aurel32 | branch(ch); |
335 | 28ce5ce6 | aurel32 | return;
|
336 | 28ce5ce6 | aurel32 | } |
337 | 28ce5ce6 | aurel32 | |
338 | ad674e53 | Aurelien Jarno | status = ch->regs[DBDMA_STATUS] & DEVSTAT; |
339 | 28ce5ce6 | aurel32 | |
340 | ad674e53 | Aurelien Jarno | sel_mask = (ch->regs[DBDMA_BRANCH_SEL] >> 16) & 0x0f; |
341 | ad674e53 | Aurelien Jarno | sel_value = ch->regs[DBDMA_BRANCH_SEL] & 0x0f;
|
342 | 28ce5ce6 | aurel32 | |
343 | 28ce5ce6 | aurel32 | cond = (status & sel_mask) == (sel_value & sel_mask); |
344 | 28ce5ce6 | aurel32 | |
345 | 28ce5ce6 | aurel32 | switch(br) {
|
346 | 28ce5ce6 | aurel32 | case BR_IFSET: /* branch if condition bit is 1 */ |
347 | 28ce5ce6 | aurel32 | if (cond)
|
348 | 28ce5ce6 | aurel32 | branch(ch); |
349 | 28ce5ce6 | aurel32 | else
|
350 | 28ce5ce6 | aurel32 | next(ch); |
351 | 28ce5ce6 | aurel32 | return;
|
352 | 28ce5ce6 | aurel32 | case BR_IFCLR: /* branch if condition bit is 0 */ |
353 | 28ce5ce6 | aurel32 | if (!cond)
|
354 | 28ce5ce6 | aurel32 | branch(ch); |
355 | 28ce5ce6 | aurel32 | else
|
356 | 28ce5ce6 | aurel32 | next(ch); |
357 | 28ce5ce6 | aurel32 | return;
|
358 | 28ce5ce6 | aurel32 | } |
359 | 28ce5ce6 | aurel32 | } |
360 | 28ce5ce6 | aurel32 | |
361 | b42ec42d | aurel32 | static QEMUBH *dbdma_bh;
|
362 | b42ec42d | aurel32 | static void channel_run(DBDMA_channel *ch); |
363 | 28ce5ce6 | aurel32 | |
364 | b42ec42d | aurel32 | static void dbdma_end(DBDMA_io *io) |
365 | 28ce5ce6 | aurel32 | { |
366 | 28ce5ce6 | aurel32 | DBDMA_channel *ch = io->channel; |
367 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
368 | 28ce5ce6 | aurel32 | |
369 | b42ec42d | aurel32 | if (conditional_wait(ch))
|
370 | b42ec42d | aurel32 | goto wait;
|
371 | 28ce5ce6 | aurel32 | |
372 | ad674e53 | Aurelien Jarno | current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]); |
373 | ad674e53 | Aurelien Jarno | current->res_count = cpu_to_le16(io->len); |
374 | b42ec42d | aurel32 | dbdma_cmdptr_save(ch); |
375 | 862c9280 | aurel32 | if (io->is_last)
|
376 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~FLUSH; |
377 | b42ec42d | aurel32 | |
378 | b42ec42d | aurel32 | conditional_interrupt(ch); |
379 | b42ec42d | aurel32 | conditional_branch(ch); |
380 | 28ce5ce6 | aurel32 | |
381 | b42ec42d | aurel32 | wait:
|
382 | b42ec42d | aurel32 | ch->processing = 0;
|
383 | ad674e53 | Aurelien Jarno | if ((ch->regs[DBDMA_STATUS] & RUN) &&
|
384 | ad674e53 | Aurelien Jarno | (ch->regs[DBDMA_STATUS] & ACTIVE)) |
385 | b42ec42d | aurel32 | channel_run(ch); |
386 | 28ce5ce6 | aurel32 | } |
387 | 28ce5ce6 | aurel32 | |
388 | b42ec42d | aurel32 | static void start_output(DBDMA_channel *ch, int key, uint32_t addr, |
389 | 28ce5ce6 | aurel32 | uint16_t req_count, int is_last)
|
390 | 28ce5ce6 | aurel32 | { |
391 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("start_output\n");
|
392 | 28ce5ce6 | aurel32 | |
393 | 28ce5ce6 | aurel32 | /* KEY_REGS, KEY_DEVICE and KEY_STREAM
|
394 | 28ce5ce6 | aurel32 | * are not implemented in the mac-io chip
|
395 | 28ce5ce6 | aurel32 | */
|
396 | 28ce5ce6 | aurel32 | |
397 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("addr 0x%x key 0x%x\n", addr, key);
|
398 | 28ce5ce6 | aurel32 | if (!addr || key > KEY_STREAM3) {
|
399 | 28ce5ce6 | aurel32 | kill_channel(ch); |
400 | b42ec42d | aurel32 | return;
|
401 | 28ce5ce6 | aurel32 | } |
402 | 28ce5ce6 | aurel32 | |
403 | b42ec42d | aurel32 | ch->io.addr = addr; |
404 | 28ce5ce6 | aurel32 | ch->io.len = req_count; |
405 | 28ce5ce6 | aurel32 | ch->io.is_last = is_last; |
406 | b42ec42d | aurel32 | ch->io.dma_end = dbdma_end; |
407 | b42ec42d | aurel32 | ch->io.is_dma_out = 1;
|
408 | b42ec42d | aurel32 | ch->processing = 1;
|
409 | a9ceb76d | Alexander Graf | if (ch->rw) {
|
410 | a9ceb76d | Alexander Graf | ch->rw(&ch->io); |
411 | a9ceb76d | Alexander Graf | } |
412 | 28ce5ce6 | aurel32 | } |
413 | 28ce5ce6 | aurel32 | |
414 | b42ec42d | aurel32 | static void start_input(DBDMA_channel *ch, int key, uint32_t addr, |
415 | 28ce5ce6 | aurel32 | uint16_t req_count, int is_last)
|
416 | 28ce5ce6 | aurel32 | { |
417 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("start_input\n");
|
418 | 28ce5ce6 | aurel32 | |
419 | 28ce5ce6 | aurel32 | /* KEY_REGS, KEY_DEVICE and KEY_STREAM
|
420 | 28ce5ce6 | aurel32 | * are not implemented in the mac-io chip
|
421 | 28ce5ce6 | aurel32 | */
|
422 | 28ce5ce6 | aurel32 | |
423 | 28ce5ce6 | aurel32 | if (!addr || key > KEY_STREAM3) {
|
424 | 28ce5ce6 | aurel32 | kill_channel(ch); |
425 | b42ec42d | aurel32 | return;
|
426 | 28ce5ce6 | aurel32 | } |
427 | 28ce5ce6 | aurel32 | |
428 | b42ec42d | aurel32 | ch->io.addr = addr; |
429 | 28ce5ce6 | aurel32 | ch->io.len = req_count; |
430 | 28ce5ce6 | aurel32 | ch->io.is_last = is_last; |
431 | b42ec42d | aurel32 | ch->io.dma_end = dbdma_end; |
432 | b42ec42d | aurel32 | ch->io.is_dma_out = 0;
|
433 | b42ec42d | aurel32 | ch->processing = 1;
|
434 | a9ceb76d | Alexander Graf | if (ch->rw) {
|
435 | a9ceb76d | Alexander Graf | ch->rw(&ch->io); |
436 | a9ceb76d | Alexander Graf | } |
437 | 28ce5ce6 | aurel32 | } |
438 | 28ce5ce6 | aurel32 | |
439 | b42ec42d | aurel32 | static void load_word(DBDMA_channel *ch, int key, uint32_t addr, |
440 | 28ce5ce6 | aurel32 | uint16_t len) |
441 | 28ce5ce6 | aurel32 | { |
442 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
443 | 28ce5ce6 | aurel32 | uint32_t val; |
444 | 28ce5ce6 | aurel32 | |
445 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("load_word\n");
|
446 | 28ce5ce6 | aurel32 | |
447 | 28ce5ce6 | aurel32 | /* only implements KEY_SYSTEM */
|
448 | 28ce5ce6 | aurel32 | |
449 | 28ce5ce6 | aurel32 | if (key != KEY_SYSTEM) {
|
450 | 28ce5ce6 | aurel32 | printf("DBDMA: LOAD_WORD, unimplemented key %x\n", key);
|
451 | 28ce5ce6 | aurel32 | kill_channel(ch); |
452 | b42ec42d | aurel32 | return;
|
453 | 28ce5ce6 | aurel32 | } |
454 | 28ce5ce6 | aurel32 | |
455 | 28ce5ce6 | aurel32 | cpu_physical_memory_read(addr, (uint8_t*)&val, len); |
456 | 28ce5ce6 | aurel32 | |
457 | 28ce5ce6 | aurel32 | if (len == 2) |
458 | 28ce5ce6 | aurel32 | val = (val << 16) | (current->cmd_dep & 0x0000ffff); |
459 | 28ce5ce6 | aurel32 | else if (len == 1) |
460 | 28ce5ce6 | aurel32 | val = (val << 24) | (current->cmd_dep & 0x00ffffff); |
461 | 28ce5ce6 | aurel32 | |
462 | 28ce5ce6 | aurel32 | current->cmd_dep = val; |
463 | 28ce5ce6 | aurel32 | |
464 | 28ce5ce6 | aurel32 | if (conditional_wait(ch))
|
465 | b42ec42d | aurel32 | goto wait;
|
466 | 28ce5ce6 | aurel32 | |
467 | ad674e53 | Aurelien Jarno | current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]); |
468 | 28ce5ce6 | aurel32 | dbdma_cmdptr_save(ch); |
469 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~FLUSH; |
470 | 28ce5ce6 | aurel32 | |
471 | 28ce5ce6 | aurel32 | conditional_interrupt(ch); |
472 | 28ce5ce6 | aurel32 | next(ch); |
473 | 28ce5ce6 | aurel32 | |
474 | b42ec42d | aurel32 | wait:
|
475 | b42ec42d | aurel32 | qemu_bh_schedule(dbdma_bh); |
476 | 28ce5ce6 | aurel32 | } |
477 | 28ce5ce6 | aurel32 | |
478 | b42ec42d | aurel32 | static void store_word(DBDMA_channel *ch, int key, uint32_t addr, |
479 | 28ce5ce6 | aurel32 | uint16_t len) |
480 | 28ce5ce6 | aurel32 | { |
481 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
482 | 28ce5ce6 | aurel32 | uint32_t val; |
483 | 28ce5ce6 | aurel32 | |
484 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("store_word\n");
|
485 | 28ce5ce6 | aurel32 | |
486 | 28ce5ce6 | aurel32 | /* only implements KEY_SYSTEM */
|
487 | 28ce5ce6 | aurel32 | |
488 | 28ce5ce6 | aurel32 | if (key != KEY_SYSTEM) {
|
489 | 28ce5ce6 | aurel32 | printf("DBDMA: STORE_WORD, unimplemented key %x\n", key);
|
490 | 28ce5ce6 | aurel32 | kill_channel(ch); |
491 | b42ec42d | aurel32 | return;
|
492 | 28ce5ce6 | aurel32 | } |
493 | 28ce5ce6 | aurel32 | |
494 | 28ce5ce6 | aurel32 | val = current->cmd_dep; |
495 | 28ce5ce6 | aurel32 | if (len == 2) |
496 | 28ce5ce6 | aurel32 | val >>= 16;
|
497 | 28ce5ce6 | aurel32 | else if (len == 1) |
498 | 28ce5ce6 | aurel32 | val >>= 24;
|
499 | 28ce5ce6 | aurel32 | |
500 | 28ce5ce6 | aurel32 | cpu_physical_memory_write(addr, (uint8_t*)&val, len); |
501 | 28ce5ce6 | aurel32 | |
502 | 28ce5ce6 | aurel32 | if (conditional_wait(ch))
|
503 | b42ec42d | aurel32 | goto wait;
|
504 | 28ce5ce6 | aurel32 | |
505 | ad674e53 | Aurelien Jarno | current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]); |
506 | 28ce5ce6 | aurel32 | dbdma_cmdptr_save(ch); |
507 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~FLUSH; |
508 | 28ce5ce6 | aurel32 | |
509 | 28ce5ce6 | aurel32 | conditional_interrupt(ch); |
510 | 28ce5ce6 | aurel32 | next(ch); |
511 | 28ce5ce6 | aurel32 | |
512 | b42ec42d | aurel32 | wait:
|
513 | b42ec42d | aurel32 | qemu_bh_schedule(dbdma_bh); |
514 | 28ce5ce6 | aurel32 | } |
515 | 28ce5ce6 | aurel32 | |
516 | b42ec42d | aurel32 | static void nop(DBDMA_channel *ch) |
517 | 28ce5ce6 | aurel32 | { |
518 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
519 | 28ce5ce6 | aurel32 | |
520 | 28ce5ce6 | aurel32 | if (conditional_wait(ch))
|
521 | b42ec42d | aurel32 | goto wait;
|
522 | 28ce5ce6 | aurel32 | |
523 | ad674e53 | Aurelien Jarno | current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]); |
524 | 28ce5ce6 | aurel32 | dbdma_cmdptr_save(ch); |
525 | 28ce5ce6 | aurel32 | |
526 | 28ce5ce6 | aurel32 | conditional_interrupt(ch); |
527 | 28ce5ce6 | aurel32 | conditional_branch(ch); |
528 | 28ce5ce6 | aurel32 | |
529 | b42ec42d | aurel32 | wait:
|
530 | b42ec42d | aurel32 | qemu_bh_schedule(dbdma_bh); |
531 | 3cbee15b | j_mayer | } |
532 | 3cbee15b | j_mayer | |
533 | b42ec42d | aurel32 | static void stop(DBDMA_channel *ch) |
534 | 3cbee15b | j_mayer | { |
535 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~(ACTIVE|DEAD|FLUSH); |
536 | 28ce5ce6 | aurel32 | |
537 | 28ce5ce6 | aurel32 | /* the stop command does not increment command pointer */
|
538 | 3cbee15b | j_mayer | } |
539 | 3cbee15b | j_mayer | |
540 | b42ec42d | aurel32 | static void channel_run(DBDMA_channel *ch) |
541 | 3cbee15b | j_mayer | { |
542 | 28ce5ce6 | aurel32 | dbdma_cmd *current = &ch->current; |
543 | 28ce5ce6 | aurel32 | uint16_t cmd, key; |
544 | 28ce5ce6 | aurel32 | uint16_t req_count; |
545 | 28ce5ce6 | aurel32 | uint32_t phy_addr; |
546 | 28ce5ce6 | aurel32 | |
547 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("channel_run\n");
|
548 | 28ce5ce6 | aurel32 | dump_dbdma_cmd(current); |
549 | 28ce5ce6 | aurel32 | |
550 | 28ce5ce6 | aurel32 | /* clear WAKE flag at command fetch */
|
551 | 28ce5ce6 | aurel32 | |
552 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] &= ~WAKE; |
553 | 28ce5ce6 | aurel32 | |
554 | 28ce5ce6 | aurel32 | cmd = le16_to_cpu(current->command) & COMMAND_MASK; |
555 | 28ce5ce6 | aurel32 | |
556 | 28ce5ce6 | aurel32 | switch (cmd) {
|
557 | 28ce5ce6 | aurel32 | case DBDMA_NOP:
|
558 | b42ec42d | aurel32 | nop(ch); |
559 | b42ec42d | aurel32 | return;
|
560 | 28ce5ce6 | aurel32 | |
561 | 28ce5ce6 | aurel32 | case DBDMA_STOP:
|
562 | b42ec42d | aurel32 | stop(ch); |
563 | b42ec42d | aurel32 | return;
|
564 | 28ce5ce6 | aurel32 | } |
565 | 28ce5ce6 | aurel32 | |
566 | 28ce5ce6 | aurel32 | key = le16_to_cpu(current->command) & 0x0700;
|
567 | 28ce5ce6 | aurel32 | req_count = le16_to_cpu(current->req_count); |
568 | 28ce5ce6 | aurel32 | phy_addr = le32_to_cpu(current->phy_addr); |
569 | 28ce5ce6 | aurel32 | |
570 | 28ce5ce6 | aurel32 | if (key == KEY_STREAM4) {
|
571 | 28ce5ce6 | aurel32 | printf("command %x, invalid key 4\n", cmd);
|
572 | 28ce5ce6 | aurel32 | kill_channel(ch); |
573 | b42ec42d | aurel32 | return;
|
574 | 28ce5ce6 | aurel32 | } |
575 | 28ce5ce6 | aurel32 | |
576 | 28ce5ce6 | aurel32 | switch (cmd) {
|
577 | 28ce5ce6 | aurel32 | case OUTPUT_MORE:
|
578 | b42ec42d | aurel32 | start_output(ch, key, phy_addr, req_count, 0);
|
579 | b42ec42d | aurel32 | return;
|
580 | 28ce5ce6 | aurel32 | |
581 | 28ce5ce6 | aurel32 | case OUTPUT_LAST:
|
582 | b42ec42d | aurel32 | start_output(ch, key, phy_addr, req_count, 1);
|
583 | b42ec42d | aurel32 | return;
|
584 | 28ce5ce6 | aurel32 | |
585 | 28ce5ce6 | aurel32 | case INPUT_MORE:
|
586 | b42ec42d | aurel32 | start_input(ch, key, phy_addr, req_count, 0);
|
587 | b42ec42d | aurel32 | return;
|
588 | 28ce5ce6 | aurel32 | |
589 | 28ce5ce6 | aurel32 | case INPUT_LAST:
|
590 | b42ec42d | aurel32 | start_input(ch, key, phy_addr, req_count, 1);
|
591 | b42ec42d | aurel32 | return;
|
592 | 28ce5ce6 | aurel32 | } |
593 | 28ce5ce6 | aurel32 | |
594 | 28ce5ce6 | aurel32 | if (key < KEY_REGS) {
|
595 | 28ce5ce6 | aurel32 | printf("command %x, invalid key %x\n", cmd, key);
|
596 | 28ce5ce6 | aurel32 | key = KEY_SYSTEM; |
597 | 28ce5ce6 | aurel32 | } |
598 | 28ce5ce6 | aurel32 | |
599 | 28ce5ce6 | aurel32 | /* for LOAD_WORD and STORE_WORD, req_count is on 3 bits
|
600 | 28ce5ce6 | aurel32 | * and BRANCH is invalid
|
601 | 28ce5ce6 | aurel32 | */
|
602 | 28ce5ce6 | aurel32 | |
603 | 28ce5ce6 | aurel32 | req_count = req_count & 0x0007;
|
604 | 28ce5ce6 | aurel32 | if (req_count & 0x4) { |
605 | 28ce5ce6 | aurel32 | req_count = 4;
|
606 | 28ce5ce6 | aurel32 | phy_addr &= ~3;
|
607 | 28ce5ce6 | aurel32 | } else if (req_count & 0x2) { |
608 | 28ce5ce6 | aurel32 | req_count = 2;
|
609 | 28ce5ce6 | aurel32 | phy_addr &= ~1;
|
610 | 28ce5ce6 | aurel32 | } else
|
611 | 28ce5ce6 | aurel32 | req_count = 1;
|
612 | 28ce5ce6 | aurel32 | |
613 | 28ce5ce6 | aurel32 | switch (cmd) {
|
614 | 28ce5ce6 | aurel32 | case LOAD_WORD:
|
615 | b42ec42d | aurel32 | load_word(ch, key, phy_addr, req_count); |
616 | b42ec42d | aurel32 | return;
|
617 | 28ce5ce6 | aurel32 | |
618 | 28ce5ce6 | aurel32 | case STORE_WORD:
|
619 | b42ec42d | aurel32 | store_word(ch, key, phy_addr, req_count); |
620 | b42ec42d | aurel32 | return;
|
621 | 28ce5ce6 | aurel32 | } |
622 | 3cbee15b | j_mayer | } |
623 | 3cbee15b | j_mayer | |
624 | c20df14b | Juan Quintela | static void DBDMA_run(DBDMAState *s) |
625 | 28ce5ce6 | aurel32 | { |
626 | 28ce5ce6 | aurel32 | int channel;
|
627 | 28ce5ce6 | aurel32 | |
628 | c20df14b | Juan Quintela | for (channel = 0; channel < DBDMA_CHANNELS; channel++) { |
629 | c20df14b | Juan Quintela | DBDMA_channel *ch = &s->channels[channel]; |
630 | c20df14b | Juan Quintela | uint32_t status = ch->regs[DBDMA_STATUS]; |
631 | c20df14b | Juan Quintela | if (!ch->processing && (status & RUN) && (status & ACTIVE)) {
|
632 | c20df14b | Juan Quintela | channel_run(ch); |
633 | c20df14b | Juan Quintela | } |
634 | 28ce5ce6 | aurel32 | } |
635 | 28ce5ce6 | aurel32 | } |
636 | 28ce5ce6 | aurel32 | |
637 | 28ce5ce6 | aurel32 | static void DBDMA_run_bh(void *opaque) |
638 | 28ce5ce6 | aurel32 | { |
639 | c20df14b | Juan Quintela | DBDMAState *s = opaque; |
640 | 28ce5ce6 | aurel32 | |
641 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("DBDMA_run_bh\n");
|
642 | 28ce5ce6 | aurel32 | |
643 | c20df14b | Juan Quintela | DBDMA_run(s); |
644 | 28ce5ce6 | aurel32 | } |
645 | 28ce5ce6 | aurel32 | |
646 | 28ce5ce6 | aurel32 | void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq, |
647 | 862c9280 | aurel32 | DBDMA_rw rw, DBDMA_flush flush, |
648 | 28ce5ce6 | aurel32 | void *opaque)
|
649 | 28ce5ce6 | aurel32 | { |
650 | c20df14b | Juan Quintela | DBDMAState *s = dbdma; |
651 | c20df14b | Juan Quintela | DBDMA_channel *ch = &s->channels[nchan]; |
652 | 28ce5ce6 | aurel32 | |
653 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("DBDMA_register_channel 0x%x\n", nchan);
|
654 | 28ce5ce6 | aurel32 | |
655 | 28ce5ce6 | aurel32 | ch->irq = irq; |
656 | 28ce5ce6 | aurel32 | ch->channel = nchan; |
657 | b42ec42d | aurel32 | ch->rw = rw; |
658 | 862c9280 | aurel32 | ch->flush = flush; |
659 | 28ce5ce6 | aurel32 | ch->io.opaque = opaque; |
660 | 28ce5ce6 | aurel32 | ch->io.channel = ch; |
661 | 28ce5ce6 | aurel32 | } |
662 | 28ce5ce6 | aurel32 | |
663 | 28ce5ce6 | aurel32 | void DBDMA_schedule(void) |
664 | 28ce5ce6 | aurel32 | { |
665 | d9f75a4e | aliguori | qemu_notify_event(); |
666 | 28ce5ce6 | aurel32 | } |
667 | 28ce5ce6 | aurel32 | |
668 | 28ce5ce6 | aurel32 | static void |
669 | 28ce5ce6 | aurel32 | dbdma_control_write(DBDMA_channel *ch) |
670 | 28ce5ce6 | aurel32 | { |
671 | 28ce5ce6 | aurel32 | uint16_t mask, value; |
672 | 28ce5ce6 | aurel32 | uint32_t status; |
673 | 28ce5ce6 | aurel32 | |
674 | ad674e53 | Aurelien Jarno | mask = (ch->regs[DBDMA_CONTROL] >> 16) & 0xffff; |
675 | ad674e53 | Aurelien Jarno | value = ch->regs[DBDMA_CONTROL] & 0xffff;
|
676 | 28ce5ce6 | aurel32 | |
677 | 28ce5ce6 | aurel32 | value &= (RUN | PAUSE | FLUSH | WAKE | DEVSTAT); |
678 | 28ce5ce6 | aurel32 | |
679 | ad674e53 | Aurelien Jarno | status = ch->regs[DBDMA_STATUS]; |
680 | 28ce5ce6 | aurel32 | |
681 | 28ce5ce6 | aurel32 | status = (value & mask) | (status & ~mask); |
682 | 28ce5ce6 | aurel32 | |
683 | 28ce5ce6 | aurel32 | if (status & WAKE)
|
684 | 28ce5ce6 | aurel32 | status |= ACTIVE; |
685 | 28ce5ce6 | aurel32 | if (status & RUN) {
|
686 | 28ce5ce6 | aurel32 | status |= ACTIVE; |
687 | 28ce5ce6 | aurel32 | status &= ~DEAD; |
688 | 28ce5ce6 | aurel32 | } |
689 | 28ce5ce6 | aurel32 | if (status & PAUSE)
|
690 | 28ce5ce6 | aurel32 | status &= ~ACTIVE; |
691 | ad674e53 | Aurelien Jarno | if ((ch->regs[DBDMA_STATUS] & RUN) && !(status & RUN)) {
|
692 | 28ce5ce6 | aurel32 | /* RUN is cleared */
|
693 | 28ce5ce6 | aurel32 | status &= ~(ACTIVE|DEAD); |
694 | 28ce5ce6 | aurel32 | } |
695 | 28ce5ce6 | aurel32 | |
696 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF(" status 0x%08x\n", status);
|
697 | 28ce5ce6 | aurel32 | |
698 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_STATUS] = status; |
699 | 28ce5ce6 | aurel32 | |
700 | b42ec42d | aurel32 | if (status & ACTIVE)
|
701 | b42ec42d | aurel32 | qemu_bh_schedule(dbdma_bh); |
702 | a9ceb76d | Alexander Graf | if ((status & FLUSH) && ch->flush)
|
703 | 862c9280 | aurel32 | ch->flush(&ch->io); |
704 | 28ce5ce6 | aurel32 | } |
705 | 28ce5ce6 | aurel32 | |
706 | 28ce5ce6 | aurel32 | static void dbdma_writel (void *opaque, |
707 | c227f099 | Anthony Liguori | target_phys_addr_t addr, uint32_t value) |
708 | 28ce5ce6 | aurel32 | { |
709 | 28ce5ce6 | aurel32 | int channel = addr >> DBDMA_CHANNEL_SHIFT;
|
710 | c20df14b | Juan Quintela | DBDMAState *s = opaque; |
711 | c20df14b | Juan Quintela | DBDMA_channel *ch = &s->channels[channel]; |
712 | 28ce5ce6 | aurel32 | int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2; |
713 | 28ce5ce6 | aurel32 | |
714 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("writel 0x" TARGET_FMT_plx " <= 0x%08x\n", addr, value); |
715 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
|
716 | 28ce5ce6 | aurel32 | (uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg); |
717 | 28ce5ce6 | aurel32 | |
718 | 28ce5ce6 | aurel32 | /* cmdptr cannot be modified if channel is RUN or ACTIVE */
|
719 | 28ce5ce6 | aurel32 | |
720 | 28ce5ce6 | aurel32 | if (reg == DBDMA_CMDPTR_LO &&
|
721 | ad674e53 | Aurelien Jarno | (ch->regs[DBDMA_STATUS] & (RUN | ACTIVE))) |
722 | 28ce5ce6 | aurel32 | return;
|
723 | 28ce5ce6 | aurel32 | |
724 | 28ce5ce6 | aurel32 | ch->regs[reg] = value; |
725 | 28ce5ce6 | aurel32 | |
726 | 28ce5ce6 | aurel32 | switch(reg) {
|
727 | 28ce5ce6 | aurel32 | case DBDMA_CONTROL:
|
728 | 28ce5ce6 | aurel32 | dbdma_control_write(ch); |
729 | 28ce5ce6 | aurel32 | break;
|
730 | 28ce5ce6 | aurel32 | case DBDMA_CMDPTR_LO:
|
731 | 28ce5ce6 | aurel32 | /* 16-byte aligned */
|
732 | ad674e53 | Aurelien Jarno | ch->regs[DBDMA_CMDPTR_LO] &= ~0xf;
|
733 | 28ce5ce6 | aurel32 | dbdma_cmdptr_load(ch); |
734 | 28ce5ce6 | aurel32 | break;
|
735 | 28ce5ce6 | aurel32 | case DBDMA_STATUS:
|
736 | 28ce5ce6 | aurel32 | case DBDMA_INTR_SEL:
|
737 | 28ce5ce6 | aurel32 | case DBDMA_BRANCH_SEL:
|
738 | 28ce5ce6 | aurel32 | case DBDMA_WAIT_SEL:
|
739 | 28ce5ce6 | aurel32 | /* nothing to do */
|
740 | 28ce5ce6 | aurel32 | break;
|
741 | 28ce5ce6 | aurel32 | case DBDMA_XFER_MODE:
|
742 | 28ce5ce6 | aurel32 | case DBDMA_CMDPTR_HI:
|
743 | 28ce5ce6 | aurel32 | case DBDMA_DATA2PTR_HI:
|
744 | 28ce5ce6 | aurel32 | case DBDMA_DATA2PTR_LO:
|
745 | 28ce5ce6 | aurel32 | case DBDMA_ADDRESS_HI:
|
746 | 28ce5ce6 | aurel32 | case DBDMA_BRANCH_ADDR_HI:
|
747 | 28ce5ce6 | aurel32 | case DBDMA_RES1:
|
748 | 28ce5ce6 | aurel32 | case DBDMA_RES2:
|
749 | 28ce5ce6 | aurel32 | case DBDMA_RES3:
|
750 | 28ce5ce6 | aurel32 | case DBDMA_RES4:
|
751 | 28ce5ce6 | aurel32 | /* unused */
|
752 | 28ce5ce6 | aurel32 | break;
|
753 | 28ce5ce6 | aurel32 | } |
754 | 28ce5ce6 | aurel32 | } |
755 | 28ce5ce6 | aurel32 | |
756 | c227f099 | Anthony Liguori | static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr) |
757 | 3cbee15b | j_mayer | { |
758 | 28ce5ce6 | aurel32 | uint32_t value; |
759 | 28ce5ce6 | aurel32 | int channel = addr >> DBDMA_CHANNEL_SHIFT;
|
760 | c20df14b | Juan Quintela | DBDMAState *s = opaque; |
761 | c20df14b | Juan Quintela | DBDMA_channel *ch = &s->channels[channel]; |
762 | 28ce5ce6 | aurel32 | int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2; |
763 | ea026b2f | blueswir1 | |
764 | 28ce5ce6 | aurel32 | value = ch->regs[reg]; |
765 | 28ce5ce6 | aurel32 | |
766 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("readl 0x" TARGET_FMT_plx " => 0x%08x\n", addr, value); |
767 | 28ce5ce6 | aurel32 | DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
|
768 | 28ce5ce6 | aurel32 | (uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg); |
769 | 28ce5ce6 | aurel32 | |
770 | 28ce5ce6 | aurel32 | switch(reg) {
|
771 | 28ce5ce6 | aurel32 | case DBDMA_CONTROL:
|
772 | 28ce5ce6 | aurel32 | value = 0;
|
773 | 28ce5ce6 | aurel32 | break;
|
774 | 28ce5ce6 | aurel32 | case DBDMA_STATUS:
|
775 | 28ce5ce6 | aurel32 | case DBDMA_CMDPTR_LO:
|
776 | 28ce5ce6 | aurel32 | case DBDMA_INTR_SEL:
|
777 | 28ce5ce6 | aurel32 | case DBDMA_BRANCH_SEL:
|
778 | 28ce5ce6 | aurel32 | case DBDMA_WAIT_SEL:
|
779 | 28ce5ce6 | aurel32 | /* nothing to do */
|
780 | 28ce5ce6 | aurel32 | break;
|
781 | 28ce5ce6 | aurel32 | case DBDMA_XFER_MODE:
|
782 | 28ce5ce6 | aurel32 | case DBDMA_CMDPTR_HI:
|
783 | 28ce5ce6 | aurel32 | case DBDMA_DATA2PTR_HI:
|
784 | 28ce5ce6 | aurel32 | case DBDMA_DATA2PTR_LO:
|
785 | 28ce5ce6 | aurel32 | case DBDMA_ADDRESS_HI:
|
786 | 28ce5ce6 | aurel32 | case DBDMA_BRANCH_ADDR_HI:
|
787 | 28ce5ce6 | aurel32 | /* unused */
|
788 | 28ce5ce6 | aurel32 | value = 0;
|
789 | 28ce5ce6 | aurel32 | break;
|
790 | 28ce5ce6 | aurel32 | case DBDMA_RES1:
|
791 | 28ce5ce6 | aurel32 | case DBDMA_RES2:
|
792 | 28ce5ce6 | aurel32 | case DBDMA_RES3:
|
793 | 28ce5ce6 | aurel32 | case DBDMA_RES4:
|
794 | 28ce5ce6 | aurel32 | /* reserved */
|
795 | 28ce5ce6 | aurel32 | break;
|
796 | 28ce5ce6 | aurel32 | } |
797 | 28ce5ce6 | aurel32 | |
798 | 28ce5ce6 | aurel32 | return value;
|
799 | 3cbee15b | j_mayer | } |
800 | 3cbee15b | j_mayer | |
801 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const dbdma_write[] = { |
802 | 28ce5ce6 | aurel32 | NULL,
|
803 | 28ce5ce6 | aurel32 | NULL,
|
804 | 28ce5ce6 | aurel32 | dbdma_writel, |
805 | 3cbee15b | j_mayer | }; |
806 | 3cbee15b | j_mayer | |
807 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const dbdma_read[] = { |
808 | 28ce5ce6 | aurel32 | NULL,
|
809 | 28ce5ce6 | aurel32 | NULL,
|
810 | 28ce5ce6 | aurel32 | dbdma_readl, |
811 | 3cbee15b | j_mayer | }; |
812 | 3cbee15b | j_mayer | |
813 | da26fdc3 | Juan Quintela | static const VMStateDescription vmstate_dbdma_channel = { |
814 | da26fdc3 | Juan Quintela | .name = "dbdma_channel",
|
815 | da26fdc3 | Juan Quintela | .version_id = 0,
|
816 | da26fdc3 | Juan Quintela | .minimum_version_id = 0,
|
817 | da26fdc3 | Juan Quintela | .minimum_version_id_old = 0,
|
818 | da26fdc3 | Juan Quintela | .fields = (VMStateField[]) { |
819 | da26fdc3 | Juan Quintela | VMSTATE_UINT32_ARRAY(regs, struct DBDMA_channel, DBDMA_REGS),
|
820 | da26fdc3 | Juan Quintela | VMSTATE_END_OF_LIST() |
821 | da26fdc3 | Juan Quintela | } |
822 | da26fdc3 | Juan Quintela | }; |
823 | 28ce5ce6 | aurel32 | |
824 | da26fdc3 | Juan Quintela | static const VMStateDescription vmstate_dbdma = { |
825 | da26fdc3 | Juan Quintela | .name = "dbdma",
|
826 | da26fdc3 | Juan Quintela | .version_id = 2,
|
827 | da26fdc3 | Juan Quintela | .minimum_version_id = 2,
|
828 | da26fdc3 | Juan Quintela | .minimum_version_id_old = 2,
|
829 | da26fdc3 | Juan Quintela | .fields = (VMStateField[]) { |
830 | da26fdc3 | Juan Quintela | VMSTATE_STRUCT_ARRAY(channels, DBDMAState, DBDMA_CHANNELS, 1,
|
831 | da26fdc3 | Juan Quintela | vmstate_dbdma_channel, DBDMA_channel), |
832 | da26fdc3 | Juan Quintela | VMSTATE_END_OF_LIST() |
833 | da26fdc3 | Juan Quintela | } |
834 | da26fdc3 | Juan Quintela | }; |
835 | 9b64997f | blueswir1 | |
836 | 6e6b7363 | blueswir1 | static void dbdma_reset(void *opaque) |
837 | 6e6b7363 | blueswir1 | { |
838 | c20df14b | Juan Quintela | DBDMAState *s = opaque; |
839 | 28ce5ce6 | aurel32 | int i;
|
840 | 28ce5ce6 | aurel32 | |
841 | 28ce5ce6 | aurel32 | for (i = 0; i < DBDMA_CHANNELS; i++) |
842 | c20df14b | Juan Quintela | memset(s->channels[i].regs, 0, DBDMA_SIZE);
|
843 | 6e6b7363 | blueswir1 | } |
844 | 6e6b7363 | blueswir1 | |
845 | 28ce5ce6 | aurel32 | void* DBDMA_init (int *dbdma_mem_index) |
846 | 3cbee15b | j_mayer | { |
847 | c20df14b | Juan Quintela | DBDMAState *s; |
848 | 28ce5ce6 | aurel32 | |
849 | c20df14b | Juan Quintela | s = qemu_mallocz(sizeof(DBDMAState));
|
850 | 28ce5ce6 | aurel32 | |
851 | 2507c12a | Alexander Graf | *dbdma_mem_index = cpu_register_io_memory(dbdma_read, dbdma_write, s, |
852 | 0f4f039b | Alexander Graf | DEVICE_LITTLE_ENDIAN); |
853 | da26fdc3 | Juan Quintela | vmstate_register(NULL, -1, &vmstate_dbdma, s); |
854 | a08d4367 | Jan Kiszka | qemu_register_reset(dbdma_reset, s); |
855 | 28ce5ce6 | aurel32 | |
856 | 28ce5ce6 | aurel32 | dbdma_bh = qemu_bh_new(DBDMA_run_bh, s); |
857 | 28ce5ce6 | aurel32 | |
858 | 28ce5ce6 | aurel32 | return s;
|
859 | 3cbee15b | j_mayer | } |