Statistics
| Branch: | Revision:

root / hw / mac_dbdma.c @ b42ec42d

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 ea026b2f blueswir1
#define DBDMA_DPRINTF(fmt, args...) \
48 ea026b2f blueswir1
do { printf("DBDMA: " fmt , ##args); } while (0)
49 ea026b2f blueswir1
#else
50 ea026b2f blueswir1
#define DBDMA_DPRINTF(fmt, args...)
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 28ce5ce6 aurel32
    dbdma_cmd current;
164 b42ec42d aurel32
    int processing;
165 28ce5ce6 aurel32
} DBDMA_channel;
166 28ce5ce6 aurel32
167 28ce5ce6 aurel32
#ifdef DEBUG_DBDMA
168 28ce5ce6 aurel32
static void dump_dbdma_cmd(dbdma_cmd *cmd)
169 28ce5ce6 aurel32
{
170 28ce5ce6 aurel32
    printf("dbdma_cmd %p\n", cmd);
171 28ce5ce6 aurel32
    printf("    req_count 0x%04x\n", le16_to_cpu(cmd->req_count));
172 28ce5ce6 aurel32
    printf("    command 0x%04x\n", le16_to_cpu(cmd->command));
173 28ce5ce6 aurel32
    printf("    phy_addr 0x%08x\n", le32_to_cpu(cmd->phy_addr));
174 28ce5ce6 aurel32
    printf("    cmd_dep 0x%08x\n", le32_to_cpu(cmd->cmd_dep));
175 28ce5ce6 aurel32
    printf("    res_count 0x%04x\n", le16_to_cpu(cmd->res_count));
176 28ce5ce6 aurel32
    printf("    xfer_status 0x%04x\n", le16_to_cpu(cmd->xfer_status));
177 28ce5ce6 aurel32
}
178 28ce5ce6 aurel32
#else
179 28ce5ce6 aurel32
static void dump_dbdma_cmd(dbdma_cmd *cmd)
180 3cbee15b j_mayer
{
181 28ce5ce6 aurel32
}
182 28ce5ce6 aurel32
#endif
183 28ce5ce6 aurel32
static void dbdma_cmdptr_load(DBDMA_channel *ch)
184 28ce5ce6 aurel32
{
185 28ce5ce6 aurel32
    DBDMA_DPRINTF("dbdma_cmdptr_load 0x%08x\n",
186 28ce5ce6 aurel32
                  be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]));
187 28ce5ce6 aurel32
    cpu_physical_memory_read(be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]),
188 28ce5ce6 aurel32
                             (uint8_t*)&ch->current, sizeof(dbdma_cmd));
189 3cbee15b j_mayer
}
190 3cbee15b j_mayer
191 28ce5ce6 aurel32
static void dbdma_cmdptr_save(DBDMA_channel *ch)
192 3cbee15b j_mayer
{
193 28ce5ce6 aurel32
    DBDMA_DPRINTF("dbdma_cmdptr_save 0x%08x\n",
194 28ce5ce6 aurel32
                  be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]));
195 28ce5ce6 aurel32
    DBDMA_DPRINTF("xfer_status 0x%08x res_count 0x%04x\n",
196 28ce5ce6 aurel32
                  le16_to_cpu(ch->current.xfer_status),
197 28ce5ce6 aurel32
                  le16_to_cpu(ch->current.res_count));
198 28ce5ce6 aurel32
    cpu_physical_memory_write(be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]),
199 28ce5ce6 aurel32
                              (uint8_t*)&ch->current, sizeof(dbdma_cmd));
200 3cbee15b j_mayer
}
201 3cbee15b j_mayer
202 28ce5ce6 aurel32
static void kill_channel(DBDMA_channel *ch)
203 3cbee15b j_mayer
{
204 28ce5ce6 aurel32
    DBDMA_DPRINTF("kill_channel\n");
205 28ce5ce6 aurel32
206 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] |= cpu_to_be32(DEAD);
207 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~ACTIVE);
208 28ce5ce6 aurel32
209 28ce5ce6 aurel32
    qemu_irq_raise(ch->irq);
210 28ce5ce6 aurel32
}
211 28ce5ce6 aurel32
212 28ce5ce6 aurel32
static void conditional_interrupt(DBDMA_channel *ch)
213 28ce5ce6 aurel32
{
214 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
215 28ce5ce6 aurel32
    uint16_t intr;
216 28ce5ce6 aurel32
    uint16_t sel_mask, sel_value;
217 28ce5ce6 aurel32
    uint32_t status;
218 28ce5ce6 aurel32
    int cond;
219 28ce5ce6 aurel32
220 28ce5ce6 aurel32
    DBDMA_DPRINTF("conditional_interrupt\n");
221 28ce5ce6 aurel32
222 b42ec42d aurel32
    intr = le16_to_cpu(current->command) & INTR_MASK;
223 28ce5ce6 aurel32
224 28ce5ce6 aurel32
    switch(intr) {
225 28ce5ce6 aurel32
    case INTR_NEVER:  /* don't interrupt */
226 28ce5ce6 aurel32
        return;
227 28ce5ce6 aurel32
    case INTR_ALWAYS: /* always interrupt */
228 28ce5ce6 aurel32
        qemu_irq_raise(ch->irq);
229 28ce5ce6 aurel32
        return;
230 28ce5ce6 aurel32
    }
231 28ce5ce6 aurel32
232 28ce5ce6 aurel32
    status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT;
233 28ce5ce6 aurel32
234 28ce5ce6 aurel32
    sel_mask = (be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) >> 16) & 0x0f;
235 28ce5ce6 aurel32
    sel_value = be32_to_cpu(ch->regs[DBDMA_INTR_SEL]) & 0x0f;
236 28ce5ce6 aurel32
237 28ce5ce6 aurel32
    cond = (status & sel_mask) == (sel_value & sel_mask);
238 28ce5ce6 aurel32
239 28ce5ce6 aurel32
    switch(intr) {
240 28ce5ce6 aurel32
    case INTR_IFSET:  /* intr if condition bit is 1 */
241 28ce5ce6 aurel32
        if (cond)
242 28ce5ce6 aurel32
            qemu_irq_raise(ch->irq);
243 28ce5ce6 aurel32
        return;
244 28ce5ce6 aurel32
    case INTR_IFCLR:  /* intr if condition bit is 0 */
245 28ce5ce6 aurel32
        if (!cond)
246 28ce5ce6 aurel32
            qemu_irq_raise(ch->irq);
247 28ce5ce6 aurel32
        return;
248 28ce5ce6 aurel32
    }
249 28ce5ce6 aurel32
}
250 28ce5ce6 aurel32
251 28ce5ce6 aurel32
static int conditional_wait(DBDMA_channel *ch)
252 28ce5ce6 aurel32
{
253 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
254 28ce5ce6 aurel32
    uint16_t wait;
255 28ce5ce6 aurel32
    uint16_t sel_mask, sel_value;
256 28ce5ce6 aurel32
    uint32_t status;
257 28ce5ce6 aurel32
    int cond;
258 28ce5ce6 aurel32
259 28ce5ce6 aurel32
    DBDMA_DPRINTF("conditional_wait\n");
260 28ce5ce6 aurel32
261 b42ec42d aurel32
    wait = le16_to_cpu(current->command) & WAIT_MASK;
262 28ce5ce6 aurel32
263 28ce5ce6 aurel32
    switch(wait) {
264 28ce5ce6 aurel32
    case WAIT_NEVER:  /* don't wait */
265 28ce5ce6 aurel32
        return 0;
266 28ce5ce6 aurel32
    case WAIT_ALWAYS: /* always wait */
267 28ce5ce6 aurel32
        return 1;
268 28ce5ce6 aurel32
    }
269 28ce5ce6 aurel32
270 28ce5ce6 aurel32
    status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT;
271 28ce5ce6 aurel32
272 28ce5ce6 aurel32
    sel_mask = (be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) >> 16) & 0x0f;
273 28ce5ce6 aurel32
    sel_value = be32_to_cpu(ch->regs[DBDMA_WAIT_SEL]) & 0x0f;
274 28ce5ce6 aurel32
275 28ce5ce6 aurel32
    cond = (status & sel_mask) == (sel_value & sel_mask);
276 28ce5ce6 aurel32
277 28ce5ce6 aurel32
    switch(wait) {
278 28ce5ce6 aurel32
    case WAIT_IFSET:  /* wait if condition bit is 1 */
279 28ce5ce6 aurel32
        if (cond)
280 28ce5ce6 aurel32
            return 1;
281 28ce5ce6 aurel32
        return 0;
282 28ce5ce6 aurel32
    case WAIT_IFCLR:  /* wait if condition bit is 0 */
283 28ce5ce6 aurel32
        if (!cond)
284 28ce5ce6 aurel32
            return 1;
285 28ce5ce6 aurel32
        return 0;
286 28ce5ce6 aurel32
    }
287 28ce5ce6 aurel32
    return 0;
288 28ce5ce6 aurel32
}
289 28ce5ce6 aurel32
290 28ce5ce6 aurel32
static void next(DBDMA_channel *ch)
291 28ce5ce6 aurel32
{
292 28ce5ce6 aurel32
    uint32_t cp;
293 28ce5ce6 aurel32
294 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~BT);
295 28ce5ce6 aurel32
296 28ce5ce6 aurel32
    cp = be32_to_cpu(ch->regs[DBDMA_CMDPTR_LO]);
297 28ce5ce6 aurel32
    ch->regs[DBDMA_CMDPTR_LO] = cpu_to_be32(cp + sizeof(dbdma_cmd));
298 28ce5ce6 aurel32
    dbdma_cmdptr_load(ch);
299 28ce5ce6 aurel32
}
300 28ce5ce6 aurel32
301 28ce5ce6 aurel32
static void branch(DBDMA_channel *ch)
302 28ce5ce6 aurel32
{
303 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
304 28ce5ce6 aurel32
305 28ce5ce6 aurel32
    ch->regs[DBDMA_CMDPTR_LO] = current->cmd_dep;
306 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] |= cpu_to_be32(BT);
307 28ce5ce6 aurel32
    dbdma_cmdptr_load(ch);
308 28ce5ce6 aurel32
}
309 28ce5ce6 aurel32
310 28ce5ce6 aurel32
static void conditional_branch(DBDMA_channel *ch)
311 28ce5ce6 aurel32
{
312 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
313 28ce5ce6 aurel32
    uint16_t br;
314 28ce5ce6 aurel32
    uint16_t sel_mask, sel_value;
315 28ce5ce6 aurel32
    uint32_t status;
316 28ce5ce6 aurel32
    int cond;
317 28ce5ce6 aurel32
318 28ce5ce6 aurel32
    DBDMA_DPRINTF("conditional_branch\n");
319 28ce5ce6 aurel32
320 28ce5ce6 aurel32
    /* check if we must branch */
321 28ce5ce6 aurel32
322 b42ec42d aurel32
    br = le16_to_cpu(current->command) & BR_MASK;
323 28ce5ce6 aurel32
324 28ce5ce6 aurel32
    switch(br) {
325 28ce5ce6 aurel32
    case BR_NEVER:  /* don't branch */
326 28ce5ce6 aurel32
        next(ch);
327 28ce5ce6 aurel32
        return;
328 28ce5ce6 aurel32
    case BR_ALWAYS: /* always branch */
329 28ce5ce6 aurel32
        branch(ch);
330 28ce5ce6 aurel32
        return;
331 28ce5ce6 aurel32
    }
332 28ce5ce6 aurel32
333 28ce5ce6 aurel32
    status = be32_to_cpu(ch->regs[DBDMA_STATUS]) & DEVSTAT;
334 28ce5ce6 aurel32
335 28ce5ce6 aurel32
    sel_mask = (be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) >> 16) & 0x0f;
336 28ce5ce6 aurel32
    sel_value = be32_to_cpu(ch->regs[DBDMA_BRANCH_SEL]) & 0x0f;
337 28ce5ce6 aurel32
338 28ce5ce6 aurel32
    cond = (status & sel_mask) == (sel_value & sel_mask);
339 28ce5ce6 aurel32
340 28ce5ce6 aurel32
    switch(br) {
341 28ce5ce6 aurel32
    case BR_IFSET:  /* branch if condition bit is 1 */
342 28ce5ce6 aurel32
        if (cond)
343 28ce5ce6 aurel32
            branch(ch);
344 28ce5ce6 aurel32
        else
345 28ce5ce6 aurel32
            next(ch);
346 28ce5ce6 aurel32
        return;
347 28ce5ce6 aurel32
    case BR_IFCLR:  /* branch if condition bit is 0 */
348 28ce5ce6 aurel32
        if (!cond)
349 28ce5ce6 aurel32
            branch(ch);
350 28ce5ce6 aurel32
        else
351 28ce5ce6 aurel32
            next(ch);
352 28ce5ce6 aurel32
        return;
353 28ce5ce6 aurel32
    }
354 28ce5ce6 aurel32
}
355 28ce5ce6 aurel32
356 b42ec42d aurel32
static QEMUBH *dbdma_bh;
357 b42ec42d aurel32
static void channel_run(DBDMA_channel *ch);
358 28ce5ce6 aurel32
359 b42ec42d aurel32
static void dbdma_end(DBDMA_io *io)
360 28ce5ce6 aurel32
{
361 28ce5ce6 aurel32
    DBDMA_channel *ch = io->channel;
362 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
363 28ce5ce6 aurel32
364 b42ec42d aurel32
    if (conditional_wait(ch))
365 b42ec42d aurel32
        goto wait;
366 28ce5ce6 aurel32
367 b42ec42d aurel32
    current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS]));
368 b42ec42d aurel32
    current->res_count = cpu_to_le16(be32_to_cpu(io->len));
369 b42ec42d aurel32
    dbdma_cmdptr_save(ch);
370 b42ec42d aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH);
371 b42ec42d aurel32
372 b42ec42d aurel32
    conditional_interrupt(ch);
373 b42ec42d aurel32
    conditional_branch(ch);
374 28ce5ce6 aurel32
375 b42ec42d aurel32
wait:
376 b42ec42d aurel32
    ch->processing = 0;
377 b42ec42d aurel32
    if ((ch->regs[DBDMA_STATUS] & cpu_to_be32(RUN)) &&
378 b42ec42d aurel32
        (ch->regs[DBDMA_STATUS] & cpu_to_be32(ACTIVE)))
379 b42ec42d aurel32
        channel_run(ch);
380 28ce5ce6 aurel32
}
381 28ce5ce6 aurel32
382 b42ec42d aurel32
static void start_output(DBDMA_channel *ch, int key, uint32_t addr,
383 28ce5ce6 aurel32
                        uint16_t req_count, int is_last)
384 28ce5ce6 aurel32
{
385 28ce5ce6 aurel32
    DBDMA_DPRINTF("start_output\n");
386 28ce5ce6 aurel32
387 28ce5ce6 aurel32
    /* KEY_REGS, KEY_DEVICE and KEY_STREAM
388 28ce5ce6 aurel32
     * are not implemented in the mac-io chip
389 28ce5ce6 aurel32
     */
390 28ce5ce6 aurel32
391 28ce5ce6 aurel32
    DBDMA_DPRINTF("addr 0x%x key 0x%x\n", addr, key);
392 28ce5ce6 aurel32
    if (!addr || key > KEY_STREAM3) {
393 28ce5ce6 aurel32
        kill_channel(ch);
394 b42ec42d aurel32
        return;
395 28ce5ce6 aurel32
    }
396 28ce5ce6 aurel32
397 b42ec42d aurel32
    ch->io.addr = addr;
398 28ce5ce6 aurel32
    ch->io.len = req_count;
399 28ce5ce6 aurel32
    ch->io.is_last = is_last;
400 b42ec42d aurel32
    ch->io.dma_end = dbdma_end;
401 b42ec42d aurel32
    ch->io.is_dma_out = 1;
402 b42ec42d aurel32
    ch->processing = 1;
403 b42ec42d aurel32
    ch->rw(&ch->io);
404 28ce5ce6 aurel32
}
405 28ce5ce6 aurel32
406 b42ec42d aurel32
static void start_input(DBDMA_channel *ch, int key, uint32_t addr,
407 28ce5ce6 aurel32
                       uint16_t req_count, int is_last)
408 28ce5ce6 aurel32
{
409 28ce5ce6 aurel32
    DBDMA_DPRINTF("start_input\n");
410 28ce5ce6 aurel32
411 28ce5ce6 aurel32
    /* KEY_REGS, KEY_DEVICE and KEY_STREAM
412 28ce5ce6 aurel32
     * are not implemented in the mac-io chip
413 28ce5ce6 aurel32
     */
414 28ce5ce6 aurel32
415 28ce5ce6 aurel32
    if (!addr || key > KEY_STREAM3) {
416 28ce5ce6 aurel32
        kill_channel(ch);
417 b42ec42d aurel32
        return;
418 28ce5ce6 aurel32
    }
419 28ce5ce6 aurel32
420 b42ec42d aurel32
    ch->io.addr = addr;
421 28ce5ce6 aurel32
    ch->io.len = req_count;
422 28ce5ce6 aurel32
    ch->io.is_last = is_last;
423 b42ec42d aurel32
    ch->io.dma_end = dbdma_end;
424 b42ec42d aurel32
    ch->io.is_dma_out = 0;
425 b42ec42d aurel32
    ch->processing = 1;
426 b42ec42d aurel32
    ch->rw(&ch->io);
427 28ce5ce6 aurel32
}
428 28ce5ce6 aurel32
429 b42ec42d aurel32
static void load_word(DBDMA_channel *ch, int key, uint32_t addr,
430 28ce5ce6 aurel32
                     uint16_t len)
431 28ce5ce6 aurel32
{
432 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
433 28ce5ce6 aurel32
    uint32_t val;
434 28ce5ce6 aurel32
435 28ce5ce6 aurel32
    DBDMA_DPRINTF("load_word\n");
436 28ce5ce6 aurel32
437 28ce5ce6 aurel32
    /* only implements KEY_SYSTEM */
438 28ce5ce6 aurel32
439 28ce5ce6 aurel32
    if (key != KEY_SYSTEM) {
440 28ce5ce6 aurel32
        printf("DBDMA: LOAD_WORD, unimplemented key %x\n", key);
441 28ce5ce6 aurel32
        kill_channel(ch);
442 b42ec42d aurel32
        return;
443 28ce5ce6 aurel32
    }
444 28ce5ce6 aurel32
445 28ce5ce6 aurel32
    cpu_physical_memory_read(addr, (uint8_t*)&val, len);
446 28ce5ce6 aurel32
447 28ce5ce6 aurel32
    if (len == 2)
448 28ce5ce6 aurel32
        val = (val << 16) | (current->cmd_dep & 0x0000ffff);
449 28ce5ce6 aurel32
    else if (len == 1)
450 28ce5ce6 aurel32
        val = (val << 24) | (current->cmd_dep & 0x00ffffff);
451 28ce5ce6 aurel32
452 28ce5ce6 aurel32
    current->cmd_dep = val;
453 28ce5ce6 aurel32
454 28ce5ce6 aurel32
    if (conditional_wait(ch))
455 b42ec42d aurel32
        goto wait;
456 28ce5ce6 aurel32
457 28ce5ce6 aurel32
    current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS]));
458 28ce5ce6 aurel32
    dbdma_cmdptr_save(ch);
459 b42ec42d aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH);
460 28ce5ce6 aurel32
461 28ce5ce6 aurel32
    conditional_interrupt(ch);
462 28ce5ce6 aurel32
    next(ch);
463 28ce5ce6 aurel32
464 b42ec42d aurel32
wait:
465 b42ec42d aurel32
    qemu_bh_schedule(dbdma_bh);
466 28ce5ce6 aurel32
}
467 28ce5ce6 aurel32
468 b42ec42d aurel32
static void store_word(DBDMA_channel *ch, int key, uint32_t addr,
469 28ce5ce6 aurel32
                      uint16_t len)
470 28ce5ce6 aurel32
{
471 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
472 28ce5ce6 aurel32
    uint32_t val;
473 28ce5ce6 aurel32
474 28ce5ce6 aurel32
    DBDMA_DPRINTF("store_word\n");
475 28ce5ce6 aurel32
476 28ce5ce6 aurel32
    /* only implements KEY_SYSTEM */
477 28ce5ce6 aurel32
478 28ce5ce6 aurel32
    if (key != KEY_SYSTEM) {
479 28ce5ce6 aurel32
        printf("DBDMA: STORE_WORD, unimplemented key %x\n", key);
480 28ce5ce6 aurel32
        kill_channel(ch);
481 b42ec42d aurel32
        return;
482 28ce5ce6 aurel32
    }
483 28ce5ce6 aurel32
484 28ce5ce6 aurel32
    val = current->cmd_dep;
485 28ce5ce6 aurel32
    if (len == 2)
486 28ce5ce6 aurel32
        val >>= 16;
487 28ce5ce6 aurel32
    else if (len == 1)
488 28ce5ce6 aurel32
        val >>= 24;
489 28ce5ce6 aurel32
490 28ce5ce6 aurel32
    cpu_physical_memory_write(addr, (uint8_t*)&val, len);
491 28ce5ce6 aurel32
492 28ce5ce6 aurel32
    if (conditional_wait(ch))
493 b42ec42d aurel32
        goto wait;
494 28ce5ce6 aurel32
495 28ce5ce6 aurel32
    current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS]));
496 28ce5ce6 aurel32
    dbdma_cmdptr_save(ch);
497 b42ec42d aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~FLUSH);
498 28ce5ce6 aurel32
499 28ce5ce6 aurel32
    conditional_interrupt(ch);
500 28ce5ce6 aurel32
    next(ch);
501 28ce5ce6 aurel32
502 b42ec42d aurel32
wait:
503 b42ec42d aurel32
    qemu_bh_schedule(dbdma_bh);
504 28ce5ce6 aurel32
}
505 28ce5ce6 aurel32
506 b42ec42d aurel32
static void nop(DBDMA_channel *ch)
507 28ce5ce6 aurel32
{
508 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
509 28ce5ce6 aurel32
510 28ce5ce6 aurel32
    if (conditional_wait(ch))
511 b42ec42d aurel32
        goto wait;
512 28ce5ce6 aurel32
513 28ce5ce6 aurel32
    current->xfer_status = cpu_to_le16(be32_to_cpu(ch->regs[DBDMA_STATUS]));
514 28ce5ce6 aurel32
    dbdma_cmdptr_save(ch);
515 28ce5ce6 aurel32
516 28ce5ce6 aurel32
    conditional_interrupt(ch);
517 28ce5ce6 aurel32
    conditional_branch(ch);
518 28ce5ce6 aurel32
519 b42ec42d aurel32
wait:
520 b42ec42d aurel32
    qemu_bh_schedule(dbdma_bh);
521 3cbee15b j_mayer
}
522 3cbee15b j_mayer
523 b42ec42d aurel32
static void stop(DBDMA_channel *ch)
524 3cbee15b j_mayer
{
525 b42ec42d aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~(ACTIVE|DEAD|FLUSH));
526 28ce5ce6 aurel32
527 28ce5ce6 aurel32
    /* the stop command does not increment command pointer */
528 3cbee15b j_mayer
}
529 3cbee15b j_mayer
530 b42ec42d aurel32
static void channel_run(DBDMA_channel *ch)
531 3cbee15b j_mayer
{
532 28ce5ce6 aurel32
    dbdma_cmd *current = &ch->current;
533 28ce5ce6 aurel32
    uint16_t cmd, key;
534 28ce5ce6 aurel32
    uint16_t req_count;
535 28ce5ce6 aurel32
    uint32_t phy_addr;
536 28ce5ce6 aurel32
537 28ce5ce6 aurel32
    DBDMA_DPRINTF("channel_run\n");
538 28ce5ce6 aurel32
    dump_dbdma_cmd(current);
539 28ce5ce6 aurel32
540 28ce5ce6 aurel32
    /* clear WAKE flag at command fetch */
541 28ce5ce6 aurel32
542 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] &= cpu_to_be32(~WAKE);
543 28ce5ce6 aurel32
544 28ce5ce6 aurel32
    cmd = le16_to_cpu(current->command) & COMMAND_MASK;
545 28ce5ce6 aurel32
546 28ce5ce6 aurel32
    switch (cmd) {
547 28ce5ce6 aurel32
    case DBDMA_NOP:
548 b42ec42d aurel32
        nop(ch);
549 b42ec42d aurel32
        return;
550 28ce5ce6 aurel32
551 28ce5ce6 aurel32
    case DBDMA_STOP:
552 b42ec42d aurel32
        stop(ch);
553 b42ec42d aurel32
        return;
554 28ce5ce6 aurel32
    }
555 28ce5ce6 aurel32
556 28ce5ce6 aurel32
    key = le16_to_cpu(current->command) & 0x0700;
557 28ce5ce6 aurel32
    req_count = le16_to_cpu(current->req_count);
558 28ce5ce6 aurel32
    phy_addr = le32_to_cpu(current->phy_addr);
559 28ce5ce6 aurel32
560 28ce5ce6 aurel32
    if (key == KEY_STREAM4) {
561 28ce5ce6 aurel32
        printf("command %x, invalid key 4\n", cmd);
562 28ce5ce6 aurel32
        kill_channel(ch);
563 b42ec42d aurel32
        return;
564 28ce5ce6 aurel32
    }
565 28ce5ce6 aurel32
566 28ce5ce6 aurel32
    switch (cmd) {
567 28ce5ce6 aurel32
    case OUTPUT_MORE:
568 b42ec42d aurel32
        start_output(ch, key, phy_addr, req_count, 0);
569 b42ec42d aurel32
        return;
570 28ce5ce6 aurel32
571 28ce5ce6 aurel32
    case OUTPUT_LAST:
572 b42ec42d aurel32
        start_output(ch, key, phy_addr, req_count, 1);
573 b42ec42d aurel32
        return;
574 28ce5ce6 aurel32
575 28ce5ce6 aurel32
    case INPUT_MORE:
576 b42ec42d aurel32
        start_input(ch, key, phy_addr, req_count, 0);
577 b42ec42d aurel32
        return;
578 28ce5ce6 aurel32
579 28ce5ce6 aurel32
    case INPUT_LAST:
580 b42ec42d aurel32
        start_input(ch, key, phy_addr, req_count, 1);
581 b42ec42d aurel32
        return;
582 28ce5ce6 aurel32
    }
583 28ce5ce6 aurel32
584 28ce5ce6 aurel32
    if (key < KEY_REGS) {
585 28ce5ce6 aurel32
        printf("command %x, invalid key %x\n", cmd, key);
586 28ce5ce6 aurel32
        key = KEY_SYSTEM;
587 28ce5ce6 aurel32
    }
588 28ce5ce6 aurel32
589 28ce5ce6 aurel32
    /* for LOAD_WORD and STORE_WORD, req_count is on 3 bits
590 28ce5ce6 aurel32
     * and BRANCH is invalid
591 28ce5ce6 aurel32
     */
592 28ce5ce6 aurel32
593 28ce5ce6 aurel32
    req_count = req_count & 0x0007;
594 28ce5ce6 aurel32
    if (req_count & 0x4) {
595 28ce5ce6 aurel32
        req_count = 4;
596 28ce5ce6 aurel32
        phy_addr &= ~3;
597 28ce5ce6 aurel32
    } else if (req_count & 0x2) {
598 28ce5ce6 aurel32
        req_count = 2;
599 28ce5ce6 aurel32
        phy_addr &= ~1;
600 28ce5ce6 aurel32
    } else
601 28ce5ce6 aurel32
        req_count = 1;
602 28ce5ce6 aurel32
603 28ce5ce6 aurel32
    switch (cmd) {
604 28ce5ce6 aurel32
    case LOAD_WORD:
605 b42ec42d aurel32
        load_word(ch, key, phy_addr, req_count);
606 b42ec42d aurel32
        return;
607 28ce5ce6 aurel32
608 28ce5ce6 aurel32
    case STORE_WORD:
609 b42ec42d aurel32
        store_word(ch, key, phy_addr, req_count);
610 b42ec42d aurel32
        return;
611 28ce5ce6 aurel32
    }
612 3cbee15b j_mayer
}
613 3cbee15b j_mayer
614 28ce5ce6 aurel32
static void DBDMA_run (DBDMA_channel *ch)
615 28ce5ce6 aurel32
{
616 28ce5ce6 aurel32
    int channel;
617 28ce5ce6 aurel32
618 28ce5ce6 aurel32
    for (channel = 0; channel < DBDMA_CHANNELS; channel++, ch++) {
619 28ce5ce6 aurel32
            uint32_t status = be32_to_cpu(ch->regs[DBDMA_STATUS]);
620 b42ec42d aurel32
            if (!ch->processing && (status & RUN) && (status & ACTIVE))
621 b42ec42d aurel32
                channel_run(ch);
622 28ce5ce6 aurel32
    }
623 28ce5ce6 aurel32
}
624 28ce5ce6 aurel32
625 28ce5ce6 aurel32
static void DBDMA_run_bh(void *opaque)
626 28ce5ce6 aurel32
{
627 28ce5ce6 aurel32
    DBDMA_channel *ch = opaque;
628 28ce5ce6 aurel32
629 28ce5ce6 aurel32
    DBDMA_DPRINTF("DBDMA_run_bh\n");
630 28ce5ce6 aurel32
631 28ce5ce6 aurel32
    DBDMA_run(ch);
632 28ce5ce6 aurel32
}
633 28ce5ce6 aurel32
634 28ce5ce6 aurel32
void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq,
635 b42ec42d aurel32
                            DBDMA_rw rw,
636 28ce5ce6 aurel32
                            void *opaque)
637 28ce5ce6 aurel32
{
638 28ce5ce6 aurel32
    DBDMA_channel *ch = ( DBDMA_channel *)dbdma + nchan;
639 28ce5ce6 aurel32
640 28ce5ce6 aurel32
    DBDMA_DPRINTF("DBDMA_register_channel 0x%x\n", nchan);
641 28ce5ce6 aurel32
642 28ce5ce6 aurel32
    ch->irq = irq;
643 28ce5ce6 aurel32
    ch->channel = nchan;
644 b42ec42d aurel32
    ch->rw = rw;
645 28ce5ce6 aurel32
    ch->io.opaque = opaque;
646 28ce5ce6 aurel32
    ch->io.channel = ch;
647 28ce5ce6 aurel32
}
648 28ce5ce6 aurel32
649 28ce5ce6 aurel32
void DBDMA_schedule(void)
650 28ce5ce6 aurel32
{
651 28ce5ce6 aurel32
    CPUState *env = cpu_single_env;
652 28ce5ce6 aurel32
    if (env)
653 28ce5ce6 aurel32
        cpu_interrupt(env, CPU_INTERRUPT_EXIT);
654 28ce5ce6 aurel32
}
655 28ce5ce6 aurel32
656 28ce5ce6 aurel32
static void
657 28ce5ce6 aurel32
dbdma_control_write(DBDMA_channel *ch)
658 28ce5ce6 aurel32
{
659 28ce5ce6 aurel32
    uint16_t mask, value;
660 28ce5ce6 aurel32
    uint32_t status;
661 28ce5ce6 aurel32
662 28ce5ce6 aurel32
    mask = (be32_to_cpu(ch->regs[DBDMA_CONTROL]) >> 16) & 0xffff;
663 28ce5ce6 aurel32
    value = be32_to_cpu(ch->regs[DBDMA_CONTROL]) & 0xffff;
664 28ce5ce6 aurel32
665 28ce5ce6 aurel32
    value &= (RUN | PAUSE | FLUSH | WAKE | DEVSTAT);
666 28ce5ce6 aurel32
667 28ce5ce6 aurel32
    status = be32_to_cpu(ch->regs[DBDMA_STATUS]);
668 28ce5ce6 aurel32
669 28ce5ce6 aurel32
    status = (value & mask) | (status & ~mask);
670 28ce5ce6 aurel32
671 28ce5ce6 aurel32
    if (status & WAKE)
672 28ce5ce6 aurel32
        status |= ACTIVE;
673 28ce5ce6 aurel32
    if (status & RUN) {
674 28ce5ce6 aurel32
        status |= ACTIVE;
675 28ce5ce6 aurel32
        status &= ~DEAD;
676 28ce5ce6 aurel32
    }
677 28ce5ce6 aurel32
    if (status & PAUSE)
678 28ce5ce6 aurel32
        status &= ~ACTIVE;
679 28ce5ce6 aurel32
    if ((be32_to_cpu(ch->regs[DBDMA_STATUS]) & RUN) && !(status & RUN)) {
680 28ce5ce6 aurel32
        /* RUN is cleared */
681 28ce5ce6 aurel32
        status &= ~(ACTIVE|DEAD);
682 28ce5ce6 aurel32
    }
683 28ce5ce6 aurel32
684 28ce5ce6 aurel32
    DBDMA_DPRINTF("    status 0x%08x\n", status);
685 28ce5ce6 aurel32
686 28ce5ce6 aurel32
    ch->regs[DBDMA_STATUS] = cpu_to_be32(status);
687 28ce5ce6 aurel32
688 b42ec42d aurel32
    if (status & ACTIVE)
689 b42ec42d aurel32
        qemu_bh_schedule(dbdma_bh);
690 28ce5ce6 aurel32
}
691 28ce5ce6 aurel32
692 28ce5ce6 aurel32
static void dbdma_writel (void *opaque,
693 28ce5ce6 aurel32
                          target_phys_addr_t addr, uint32_t value)
694 28ce5ce6 aurel32
{
695 28ce5ce6 aurel32
    int channel = addr >> DBDMA_CHANNEL_SHIFT;
696 28ce5ce6 aurel32
    DBDMA_channel *ch = (DBDMA_channel *)opaque + channel;
697 28ce5ce6 aurel32
    int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2;
698 28ce5ce6 aurel32
699 28ce5ce6 aurel32
    DBDMA_DPRINTF("writel 0x" TARGET_FMT_plx " <= 0x%08x\n", addr, value);
700 28ce5ce6 aurel32
    DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
701 28ce5ce6 aurel32
                  (uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg);
702 28ce5ce6 aurel32
703 28ce5ce6 aurel32
    /* cmdptr cannot be modified if channel is RUN or ACTIVE */
704 28ce5ce6 aurel32
705 28ce5ce6 aurel32
    if (reg == DBDMA_CMDPTR_LO &&
706 28ce5ce6 aurel32
        (ch->regs[DBDMA_STATUS] & cpu_to_be32(RUN | ACTIVE)))
707 28ce5ce6 aurel32
        return;
708 28ce5ce6 aurel32
709 28ce5ce6 aurel32
    ch->regs[reg] = value;
710 28ce5ce6 aurel32
711 28ce5ce6 aurel32
    switch(reg) {
712 28ce5ce6 aurel32
    case DBDMA_CONTROL:
713 28ce5ce6 aurel32
        dbdma_control_write(ch);
714 28ce5ce6 aurel32
        break;
715 28ce5ce6 aurel32
    case DBDMA_CMDPTR_LO:
716 28ce5ce6 aurel32
        /* 16-byte aligned */
717 28ce5ce6 aurel32
        ch->regs[DBDMA_CMDPTR_LO] &= cpu_to_be32(~0xf);
718 28ce5ce6 aurel32
        dbdma_cmdptr_load(ch);
719 28ce5ce6 aurel32
        break;
720 28ce5ce6 aurel32
    case DBDMA_STATUS:
721 28ce5ce6 aurel32
    case DBDMA_INTR_SEL:
722 28ce5ce6 aurel32
    case DBDMA_BRANCH_SEL:
723 28ce5ce6 aurel32
    case DBDMA_WAIT_SEL:
724 28ce5ce6 aurel32
        /* nothing to do */
725 28ce5ce6 aurel32
        break;
726 28ce5ce6 aurel32
    case DBDMA_XFER_MODE:
727 28ce5ce6 aurel32
    case DBDMA_CMDPTR_HI:
728 28ce5ce6 aurel32
    case DBDMA_DATA2PTR_HI:
729 28ce5ce6 aurel32
    case DBDMA_DATA2PTR_LO:
730 28ce5ce6 aurel32
    case DBDMA_ADDRESS_HI:
731 28ce5ce6 aurel32
    case DBDMA_BRANCH_ADDR_HI:
732 28ce5ce6 aurel32
    case DBDMA_RES1:
733 28ce5ce6 aurel32
    case DBDMA_RES2:
734 28ce5ce6 aurel32
    case DBDMA_RES3:
735 28ce5ce6 aurel32
    case DBDMA_RES4:
736 28ce5ce6 aurel32
        /* unused */
737 28ce5ce6 aurel32
        break;
738 28ce5ce6 aurel32
    }
739 28ce5ce6 aurel32
}
740 28ce5ce6 aurel32
741 3cbee15b j_mayer
static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr)
742 3cbee15b j_mayer
{
743 28ce5ce6 aurel32
    uint32_t value;
744 28ce5ce6 aurel32
    int channel = addr >> DBDMA_CHANNEL_SHIFT;
745 28ce5ce6 aurel32
    DBDMA_channel *ch = (DBDMA_channel *)opaque + channel;
746 28ce5ce6 aurel32
    int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2;
747 ea026b2f blueswir1
748 28ce5ce6 aurel32
    value = ch->regs[reg];
749 28ce5ce6 aurel32
750 28ce5ce6 aurel32
    DBDMA_DPRINTF("readl 0x" TARGET_FMT_plx " => 0x%08x\n", addr, value);
751 28ce5ce6 aurel32
    DBDMA_DPRINTF("channel 0x%x reg 0x%x\n",
752 28ce5ce6 aurel32
                  (uint32_t)addr >> DBDMA_CHANNEL_SHIFT, reg);
753 28ce5ce6 aurel32
754 28ce5ce6 aurel32
    switch(reg) {
755 28ce5ce6 aurel32
    case DBDMA_CONTROL:
756 28ce5ce6 aurel32
        value = 0;
757 28ce5ce6 aurel32
        break;
758 28ce5ce6 aurel32
    case DBDMA_STATUS:
759 28ce5ce6 aurel32
    case DBDMA_CMDPTR_LO:
760 28ce5ce6 aurel32
    case DBDMA_INTR_SEL:
761 28ce5ce6 aurel32
    case DBDMA_BRANCH_SEL:
762 28ce5ce6 aurel32
    case DBDMA_WAIT_SEL:
763 28ce5ce6 aurel32
        /* nothing to do */
764 28ce5ce6 aurel32
        break;
765 28ce5ce6 aurel32
    case DBDMA_XFER_MODE:
766 28ce5ce6 aurel32
    case DBDMA_CMDPTR_HI:
767 28ce5ce6 aurel32
    case DBDMA_DATA2PTR_HI:
768 28ce5ce6 aurel32
    case DBDMA_DATA2PTR_LO:
769 28ce5ce6 aurel32
    case DBDMA_ADDRESS_HI:
770 28ce5ce6 aurel32
    case DBDMA_BRANCH_ADDR_HI:
771 28ce5ce6 aurel32
        /* unused */
772 28ce5ce6 aurel32
        value = 0;
773 28ce5ce6 aurel32
        break;
774 28ce5ce6 aurel32
    case DBDMA_RES1:
775 28ce5ce6 aurel32
    case DBDMA_RES2:
776 28ce5ce6 aurel32
    case DBDMA_RES3:
777 28ce5ce6 aurel32
    case DBDMA_RES4:
778 28ce5ce6 aurel32
        /* reserved */
779 28ce5ce6 aurel32
        break;
780 28ce5ce6 aurel32
    }
781 28ce5ce6 aurel32
782 28ce5ce6 aurel32
    return value;
783 3cbee15b j_mayer
}
784 3cbee15b j_mayer
785 3cbee15b j_mayer
static CPUWriteMemoryFunc *dbdma_write[] = {
786 28ce5ce6 aurel32
    NULL,
787 28ce5ce6 aurel32
    NULL,
788 28ce5ce6 aurel32
    dbdma_writel,
789 3cbee15b j_mayer
};
790 3cbee15b j_mayer
791 3cbee15b j_mayer
static CPUReadMemoryFunc *dbdma_read[] = {
792 28ce5ce6 aurel32
    NULL,
793 28ce5ce6 aurel32
    NULL,
794 28ce5ce6 aurel32
    dbdma_readl,
795 3cbee15b j_mayer
};
796 3cbee15b j_mayer
797 9b64997f blueswir1
static void dbdma_save(QEMUFile *f, void *opaque)
798 9b64997f blueswir1
{
799 28ce5ce6 aurel32
    DBDMA_channel *s = opaque;
800 28ce5ce6 aurel32
    unsigned int i, j;
801 28ce5ce6 aurel32
802 28ce5ce6 aurel32
    for (i = 0; i < DBDMA_CHANNELS; i++)
803 28ce5ce6 aurel32
        for (j = 0; j < DBDMA_REGS; j++)
804 28ce5ce6 aurel32
            qemu_put_be32s(f, &s[i].regs[j]);
805 9b64997f blueswir1
}
806 9b64997f blueswir1
807 9b64997f blueswir1
static int dbdma_load(QEMUFile *f, void *opaque, int version_id)
808 9b64997f blueswir1
{
809 28ce5ce6 aurel32
    DBDMA_channel *s = opaque;
810 28ce5ce6 aurel32
    unsigned int i, j;
811 28ce5ce6 aurel32
812 28ce5ce6 aurel32
    if (version_id != 2)
813 9b64997f blueswir1
        return -EINVAL;
814 9b64997f blueswir1
815 28ce5ce6 aurel32
    for (i = 0; i < DBDMA_CHANNELS; i++)
816 28ce5ce6 aurel32
        for (j = 0; j < DBDMA_REGS; j++)
817 28ce5ce6 aurel32
            qemu_get_be32s(f, &s[i].regs[j]);
818 28ce5ce6 aurel32
819 9b64997f blueswir1
    return 0;
820 9b64997f blueswir1
}
821 9b64997f blueswir1
822 6e6b7363 blueswir1
static void dbdma_reset(void *opaque)
823 6e6b7363 blueswir1
{
824 28ce5ce6 aurel32
    DBDMA_channel *s = opaque;
825 28ce5ce6 aurel32
    int i;
826 28ce5ce6 aurel32
827 28ce5ce6 aurel32
    for (i = 0; i < DBDMA_CHANNELS; i++)
828 28ce5ce6 aurel32
        memset(s[i].regs, 0, DBDMA_SIZE);
829 6e6b7363 blueswir1
}
830 6e6b7363 blueswir1
831 28ce5ce6 aurel32
void* DBDMA_init (int *dbdma_mem_index)
832 3cbee15b j_mayer
{
833 28ce5ce6 aurel32
    DBDMA_channel *s;
834 28ce5ce6 aurel32
835 28ce5ce6 aurel32
    s = qemu_mallocz(sizeof(DBDMA_channel) * DBDMA_CHANNELS);
836 28ce5ce6 aurel32
837 28ce5ce6 aurel32
    *dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, s);
838 28ce5ce6 aurel32
    register_savevm("dbdma", -1, 1, dbdma_save, dbdma_load, s);
839 28ce5ce6 aurel32
    qemu_register_reset(dbdma_reset, s);
840 28ce5ce6 aurel32
    dbdma_reset(s);
841 28ce5ce6 aurel32
842 28ce5ce6 aurel32
    dbdma_bh = qemu_bh_new(DBDMA_run_bh, s);
843 28ce5ce6 aurel32
844 28ce5ce6 aurel32
    return s;
845 3cbee15b j_mayer
}