root / hw / rc4030.c @ cc9f28bc
History | View | Annotate | Download (21 kB)
1 | 4ce7ff6e | aurel32 | /*
|
---|---|---|---|
2 | 4ce7ff6e | aurel32 | * QEMU JAZZ RC4030 chipset
|
3 | 4ce7ff6e | aurel32 | *
|
4 | 9ea0b7a1 | aurel32 | * Copyright (c) 2007-2009 Herve Poussineau
|
5 | 4ce7ff6e | aurel32 | *
|
6 | 4ce7ff6e | aurel32 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 4ce7ff6e | aurel32 | * of this software and associated documentation files (the "Software"), to deal
|
8 | 4ce7ff6e | aurel32 | * in the Software without restriction, including without limitation the rights
|
9 | 4ce7ff6e | aurel32 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 4ce7ff6e | aurel32 | * copies of the Software, and to permit persons to whom the Software is
|
11 | 4ce7ff6e | aurel32 | * furnished to do so, subject to the following conditions:
|
12 | 4ce7ff6e | aurel32 | *
|
13 | 4ce7ff6e | aurel32 | * The above copyright notice and this permission notice shall be included in
|
14 | 4ce7ff6e | aurel32 | * all copies or substantial portions of the Software.
|
15 | 4ce7ff6e | aurel32 | *
|
16 | 4ce7ff6e | aurel32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 4ce7ff6e | aurel32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 4ce7ff6e | aurel32 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 4ce7ff6e | aurel32 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 4ce7ff6e | aurel32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 4ce7ff6e | aurel32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 4ce7ff6e | aurel32 | * THE SOFTWARE.
|
23 | 4ce7ff6e | aurel32 | */
|
24 | 4ce7ff6e | aurel32 | |
25 | 4ce7ff6e | aurel32 | #include "hw.h" |
26 | cd5158ea | aurel32 | #include "mips.h" |
27 | 4ce7ff6e | aurel32 | #include "qemu-timer.h" |
28 | 4ce7ff6e | aurel32 | |
29 | c6945b15 | aurel32 | /********************************************************/
|
30 | c6945b15 | aurel32 | /* debug rc4030 */
|
31 | c6945b15 | aurel32 | |
32 | 4ce7ff6e | aurel32 | //#define DEBUG_RC4030
|
33 | c6945b15 | aurel32 | //#define DEBUG_RC4030_DMA
|
34 | 4ce7ff6e | aurel32 | |
35 | 4ce7ff6e | aurel32 | #ifdef DEBUG_RC4030
|
36 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
37 | 001faf32 | Blue Swirl | do { printf("rc4030: " fmt , ## __VA_ARGS__); } while (0) |
38 | 4ce7ff6e | aurel32 | static const char* irq_names[] = { "parallel", "floppy", "sound", "video", |
39 | 4ce7ff6e | aurel32 | "network", "scsi", "keyboard", "mouse", "serial0", "serial1" }; |
40 | c6945b15 | aurel32 | #else
|
41 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...)
|
42 | 4ce7ff6e | aurel32 | #endif
|
43 | 4ce7ff6e | aurel32 | |
44 | 001faf32 | Blue Swirl | #define RC4030_ERROR(fmt, ...) \
|
45 | 001faf32 | Blue Swirl | do { fprintf(stderr, "rc4030 ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0) |
46 | c6945b15 | aurel32 | |
47 | c6945b15 | aurel32 | /********************************************************/
|
48 | c6945b15 | aurel32 | /* rc4030 emulation */
|
49 | c6945b15 | aurel32 | |
50 | c6945b15 | aurel32 | typedef struct dma_pagetable_entry { |
51 | c6945b15 | aurel32 | int32_t frame; |
52 | c6945b15 | aurel32 | int32_t owner; |
53 | c6945b15 | aurel32 | } __attribute__((packed)) dma_pagetable_entry; |
54 | c6945b15 | aurel32 | |
55 | c6945b15 | aurel32 | #define DMA_PAGESIZE 4096 |
56 | c6945b15 | aurel32 | #define DMA_REG_ENABLE 1 |
57 | c6945b15 | aurel32 | #define DMA_REG_COUNT 2 |
58 | c6945b15 | aurel32 | #define DMA_REG_ADDRESS 3 |
59 | c6945b15 | aurel32 | |
60 | c6945b15 | aurel32 | #define DMA_FLAG_ENABLE 0x0001 |
61 | c6945b15 | aurel32 | #define DMA_FLAG_MEM_TO_DEV 0x0002 |
62 | c6945b15 | aurel32 | #define DMA_FLAG_TC_INTR 0x0100 |
63 | c6945b15 | aurel32 | #define DMA_FLAG_MEM_INTR 0x0200 |
64 | c6945b15 | aurel32 | #define DMA_FLAG_ADDR_INTR 0x0400 |
65 | c6945b15 | aurel32 | |
66 | 4ce7ff6e | aurel32 | typedef struct rc4030State |
67 | 4ce7ff6e | aurel32 | { |
68 | 4ce7ff6e | aurel32 | uint32_t config; /* 0x0000: RC4030 config register */
|
69 | 9ea0b7a1 | aurel32 | uint32_t revision; /* 0x0008: RC4030 Revision register */
|
70 | 4ce7ff6e | aurel32 | uint32_t invalid_address_register; /* 0x0010: Invalid Address register */
|
71 | 4ce7ff6e | aurel32 | |
72 | 4ce7ff6e | aurel32 | /* DMA */
|
73 | 4ce7ff6e | aurel32 | uint32_t dma_regs[8][4]; |
74 | 4ce7ff6e | aurel32 | uint32_t dma_tl_base; /* 0x0018: DMA transl. table base */
|
75 | 4ce7ff6e | aurel32 | uint32_t dma_tl_limit; /* 0x0020: DMA transl. table limit */
|
76 | 4ce7ff6e | aurel32 | |
77 | 4ce7ff6e | aurel32 | /* cache */
|
78 | 9ea0b7a1 | aurel32 | uint32_t cache_maint; /* 0x0030: Cache Maintenance */
|
79 | 4ce7ff6e | aurel32 | uint32_t remote_failed_address; /* 0x0038: Remote Failed Address */
|
80 | 4ce7ff6e | aurel32 | uint32_t memory_failed_address; /* 0x0040: Memory Failed Address */
|
81 | 4ce7ff6e | aurel32 | uint32_t cache_ptag; /* 0x0048: I/O Cache Physical Tag */
|
82 | 4ce7ff6e | aurel32 | uint32_t cache_ltag; /* 0x0050: I/O Cache Logical Tag */
|
83 | 4ce7ff6e | aurel32 | uint32_t cache_bmask; /* 0x0058: I/O Cache Byte Mask */
|
84 | 4ce7ff6e | aurel32 | |
85 | 9ea0b7a1 | aurel32 | uint32_t nmi_interrupt; /* 0x0200: interrupt source */
|
86 | 4ce7ff6e | aurel32 | uint32_t offset210; |
87 | 4ce7ff6e | aurel32 | uint32_t nvram_protect; /* 0x0220: NV ram protect register */
|
88 | 9ea0b7a1 | aurel32 | uint32_t rem_speed[16];
|
89 | 4ce7ff6e | aurel32 | uint32_t imr_jazz; /* Local bus int enable mask */
|
90 | 4ce7ff6e | aurel32 | uint32_t isr_jazz; /* Local bus int source */
|
91 | 4ce7ff6e | aurel32 | |
92 | 4ce7ff6e | aurel32 | /* timer */
|
93 | 4ce7ff6e | aurel32 | QEMUTimer *periodic_timer; |
94 | 4ce7ff6e | aurel32 | uint32_t itr; /* Interval timer reload */
|
95 | 4ce7ff6e | aurel32 | |
96 | 4ce7ff6e | aurel32 | qemu_irq timer_irq; |
97 | 4ce7ff6e | aurel32 | qemu_irq jazz_bus_irq; |
98 | 4ce7ff6e | aurel32 | } rc4030State; |
99 | 4ce7ff6e | aurel32 | |
100 | 4ce7ff6e | aurel32 | static void set_next_tick(rc4030State *s) |
101 | 4ce7ff6e | aurel32 | { |
102 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->timer_irq); |
103 | b0f74c87 | balrog | uint32_t tm_hz; |
104 | 4ce7ff6e | aurel32 | |
105 | b0f74c87 | balrog | tm_hz = 1000 / (s->itr + 1); |
106 | 4ce7ff6e | aurel32 | |
107 | 6ee093c9 | Juan Quintela | qemu_mod_timer(s->periodic_timer, qemu_get_clock(vm_clock) + |
108 | 6ee093c9 | Juan Quintela | get_ticks_per_sec() / tm_hz); |
109 | 4ce7ff6e | aurel32 | } |
110 | 4ce7ff6e | aurel32 | |
111 | 4ce7ff6e | aurel32 | /* called for accesses to rc4030 */
|
112 | c227f099 | Anthony Liguori | static uint32_t rc4030_readl(void *opaque, target_phys_addr_t addr) |
113 | 4ce7ff6e | aurel32 | { |
114 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
115 | 4ce7ff6e | aurel32 | uint32_t val; |
116 | 4ce7ff6e | aurel32 | |
117 | 4ce7ff6e | aurel32 | addr &= 0x3fff;
|
118 | 4ce7ff6e | aurel32 | switch (addr & ~0x3) { |
119 | 4ce7ff6e | aurel32 | /* Global config register */
|
120 | 4ce7ff6e | aurel32 | case 0x0000: |
121 | 4ce7ff6e | aurel32 | val = s->config; |
122 | 4ce7ff6e | aurel32 | break;
|
123 | 9ea0b7a1 | aurel32 | /* Revision register */
|
124 | 9ea0b7a1 | aurel32 | case 0x0008: |
125 | 9ea0b7a1 | aurel32 | val = s->revision; |
126 | 9ea0b7a1 | aurel32 | break;
|
127 | 4ce7ff6e | aurel32 | /* Invalid Address register */
|
128 | 4ce7ff6e | aurel32 | case 0x0010: |
129 | 4ce7ff6e | aurel32 | val = s->invalid_address_register; |
130 | 4ce7ff6e | aurel32 | break;
|
131 | 4ce7ff6e | aurel32 | /* DMA transl. table base */
|
132 | 4ce7ff6e | aurel32 | case 0x0018: |
133 | 4ce7ff6e | aurel32 | val = s->dma_tl_base; |
134 | 4ce7ff6e | aurel32 | break;
|
135 | 4ce7ff6e | aurel32 | /* DMA transl. table limit */
|
136 | 4ce7ff6e | aurel32 | case 0x0020: |
137 | 4ce7ff6e | aurel32 | val = s->dma_tl_limit; |
138 | 4ce7ff6e | aurel32 | break;
|
139 | 4ce7ff6e | aurel32 | /* Remote Failed Address */
|
140 | 4ce7ff6e | aurel32 | case 0x0038: |
141 | 4ce7ff6e | aurel32 | val = s->remote_failed_address; |
142 | 4ce7ff6e | aurel32 | break;
|
143 | 4ce7ff6e | aurel32 | /* Memory Failed Address */
|
144 | 4ce7ff6e | aurel32 | case 0x0040: |
145 | 4ce7ff6e | aurel32 | val = s->memory_failed_address; |
146 | 4ce7ff6e | aurel32 | break;
|
147 | 4ce7ff6e | aurel32 | /* I/O Cache Byte Mask */
|
148 | 4ce7ff6e | aurel32 | case 0x0058: |
149 | 4ce7ff6e | aurel32 | val = s->cache_bmask; |
150 | 4ce7ff6e | aurel32 | /* HACK */
|
151 | 4ce7ff6e | aurel32 | if (s->cache_bmask == (uint32_t)-1) |
152 | 4ce7ff6e | aurel32 | s->cache_bmask = 0;
|
153 | 4ce7ff6e | aurel32 | break;
|
154 | 4ce7ff6e | aurel32 | /* Remote Speed Registers */
|
155 | 4ce7ff6e | aurel32 | case 0x0070: |
156 | 4ce7ff6e | aurel32 | case 0x0078: |
157 | 4ce7ff6e | aurel32 | case 0x0080: |
158 | 4ce7ff6e | aurel32 | case 0x0088: |
159 | 4ce7ff6e | aurel32 | case 0x0090: |
160 | 4ce7ff6e | aurel32 | case 0x0098: |
161 | 4ce7ff6e | aurel32 | case 0x00a0: |
162 | 4ce7ff6e | aurel32 | case 0x00a8: |
163 | 4ce7ff6e | aurel32 | case 0x00b0: |
164 | 4ce7ff6e | aurel32 | case 0x00b8: |
165 | 4ce7ff6e | aurel32 | case 0x00c0: |
166 | 4ce7ff6e | aurel32 | case 0x00c8: |
167 | 4ce7ff6e | aurel32 | case 0x00d0: |
168 | 4ce7ff6e | aurel32 | case 0x00d8: |
169 | 4ce7ff6e | aurel32 | case 0x00e0: |
170 | 9ea0b7a1 | aurel32 | case 0x00e8: |
171 | 4ce7ff6e | aurel32 | val = s->rem_speed[(addr - 0x0070) >> 3]; |
172 | 4ce7ff6e | aurel32 | break;
|
173 | 4ce7ff6e | aurel32 | /* DMA channel base address */
|
174 | 4ce7ff6e | aurel32 | case 0x0100: |
175 | 4ce7ff6e | aurel32 | case 0x0108: |
176 | 4ce7ff6e | aurel32 | case 0x0110: |
177 | 4ce7ff6e | aurel32 | case 0x0118: |
178 | 4ce7ff6e | aurel32 | case 0x0120: |
179 | 4ce7ff6e | aurel32 | case 0x0128: |
180 | 4ce7ff6e | aurel32 | case 0x0130: |
181 | 4ce7ff6e | aurel32 | case 0x0138: |
182 | 4ce7ff6e | aurel32 | case 0x0140: |
183 | 4ce7ff6e | aurel32 | case 0x0148: |
184 | 4ce7ff6e | aurel32 | case 0x0150: |
185 | 4ce7ff6e | aurel32 | case 0x0158: |
186 | 4ce7ff6e | aurel32 | case 0x0160: |
187 | 4ce7ff6e | aurel32 | case 0x0168: |
188 | 4ce7ff6e | aurel32 | case 0x0170: |
189 | 4ce7ff6e | aurel32 | case 0x0178: |
190 | 4ce7ff6e | aurel32 | case 0x0180: |
191 | 4ce7ff6e | aurel32 | case 0x0188: |
192 | 4ce7ff6e | aurel32 | case 0x0190: |
193 | 4ce7ff6e | aurel32 | case 0x0198: |
194 | 4ce7ff6e | aurel32 | case 0x01a0: |
195 | 4ce7ff6e | aurel32 | case 0x01a8: |
196 | 4ce7ff6e | aurel32 | case 0x01b0: |
197 | 4ce7ff6e | aurel32 | case 0x01b8: |
198 | 4ce7ff6e | aurel32 | case 0x01c0: |
199 | 4ce7ff6e | aurel32 | case 0x01c8: |
200 | 4ce7ff6e | aurel32 | case 0x01d0: |
201 | 4ce7ff6e | aurel32 | case 0x01d8: |
202 | 4ce7ff6e | aurel32 | case 0x01e0: |
203 | c6945b15 | aurel32 | case 0x01e8: |
204 | 4ce7ff6e | aurel32 | case 0x01f0: |
205 | 4ce7ff6e | aurel32 | case 0x01f8: |
206 | 4ce7ff6e | aurel32 | { |
207 | 4ce7ff6e | aurel32 | int entry = (addr - 0x0100) >> 5; |
208 | 4ce7ff6e | aurel32 | int idx = (addr & 0x1f) >> 3; |
209 | 4ce7ff6e | aurel32 | val = s->dma_regs[entry][idx]; |
210 | 4ce7ff6e | aurel32 | } |
211 | 4ce7ff6e | aurel32 | break;
|
212 | 9ea0b7a1 | aurel32 | /* Interrupt source */
|
213 | 9ea0b7a1 | aurel32 | case 0x0200: |
214 | 9ea0b7a1 | aurel32 | val = s->nmi_interrupt; |
215 | 9ea0b7a1 | aurel32 | break;
|
216 | 9ea0b7a1 | aurel32 | /* Error type */
|
217 | 4ce7ff6e | aurel32 | case 0x0208: |
218 | c6945b15 | aurel32 | val = 0;
|
219 | 4ce7ff6e | aurel32 | break;
|
220 | 4ce7ff6e | aurel32 | /* Offset 0x0210 */
|
221 | 4ce7ff6e | aurel32 | case 0x0210: |
222 | 4ce7ff6e | aurel32 | val = s->offset210; |
223 | 4ce7ff6e | aurel32 | break;
|
224 | 4ce7ff6e | aurel32 | /* NV ram protect register */
|
225 | 4ce7ff6e | aurel32 | case 0x0220: |
226 | 4ce7ff6e | aurel32 | val = s->nvram_protect; |
227 | 4ce7ff6e | aurel32 | break;
|
228 | 4ce7ff6e | aurel32 | /* Interval timer count */
|
229 | 4ce7ff6e | aurel32 | case 0x0230: |
230 | c6945b15 | aurel32 | val = 0;
|
231 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->timer_irq); |
232 | 4ce7ff6e | aurel32 | break;
|
233 | 9ea0b7a1 | aurel32 | /* EISA interrupt */
|
234 | 4ce7ff6e | aurel32 | case 0x0238: |
235 | 9ea0b7a1 | aurel32 | val = 7; /* FIXME: should be read from EISA controller */ |
236 | 4ce7ff6e | aurel32 | break;
|
237 | 4ce7ff6e | aurel32 | default:
|
238 | c6945b15 | aurel32 | RC4030_ERROR("invalid read [" TARGET_FMT_plx "]\n", addr); |
239 | 4ce7ff6e | aurel32 | val = 0;
|
240 | 4ce7ff6e | aurel32 | break;
|
241 | 4ce7ff6e | aurel32 | } |
242 | 4ce7ff6e | aurel32 | |
243 | 4ce7ff6e | aurel32 | if ((addr & ~3) != 0x230) |
244 | c6945b15 | aurel32 | DPRINTF("read 0x%02x at " TARGET_FMT_plx "\n", val, addr); |
245 | 4ce7ff6e | aurel32 | |
246 | 4ce7ff6e | aurel32 | return val;
|
247 | 4ce7ff6e | aurel32 | } |
248 | 4ce7ff6e | aurel32 | |
249 | c227f099 | Anthony Liguori | static uint32_t rc4030_readw(void *opaque, target_phys_addr_t addr) |
250 | 4ce7ff6e | aurel32 | { |
251 | 4ce7ff6e | aurel32 | uint32_t v = rc4030_readl(opaque, addr & ~0x3);
|
252 | 4ce7ff6e | aurel32 | if (addr & 0x2) |
253 | 4ce7ff6e | aurel32 | return v >> 16; |
254 | 4ce7ff6e | aurel32 | else
|
255 | 4ce7ff6e | aurel32 | return v & 0xffff; |
256 | 4ce7ff6e | aurel32 | } |
257 | 4ce7ff6e | aurel32 | |
258 | c227f099 | Anthony Liguori | static uint32_t rc4030_readb(void *opaque, target_phys_addr_t addr) |
259 | 4ce7ff6e | aurel32 | { |
260 | 4ce7ff6e | aurel32 | uint32_t v = rc4030_readl(opaque, addr & ~0x3);
|
261 | 4ce7ff6e | aurel32 | return (v >> (8 * (addr & 0x3))) & 0xff; |
262 | 4ce7ff6e | aurel32 | } |
263 | 4ce7ff6e | aurel32 | |
264 | c227f099 | Anthony Liguori | static void rc4030_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
265 | 4ce7ff6e | aurel32 | { |
266 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
267 | 4ce7ff6e | aurel32 | addr &= 0x3fff;
|
268 | 4ce7ff6e | aurel32 | |
269 | c6945b15 | aurel32 | DPRINTF("write 0x%02x at " TARGET_FMT_plx "\n", val, addr); |
270 | 4ce7ff6e | aurel32 | |
271 | 4ce7ff6e | aurel32 | switch (addr & ~0x3) { |
272 | 4ce7ff6e | aurel32 | /* Global config register */
|
273 | 4ce7ff6e | aurel32 | case 0x0000: |
274 | 4ce7ff6e | aurel32 | s->config = val; |
275 | 4ce7ff6e | aurel32 | break;
|
276 | 4ce7ff6e | aurel32 | /* DMA transl. table base */
|
277 | 4ce7ff6e | aurel32 | case 0x0018: |
278 | 4ce7ff6e | aurel32 | s->dma_tl_base = val; |
279 | 4ce7ff6e | aurel32 | break;
|
280 | 4ce7ff6e | aurel32 | /* DMA transl. table limit */
|
281 | 4ce7ff6e | aurel32 | case 0x0020: |
282 | 4ce7ff6e | aurel32 | s->dma_tl_limit = val; |
283 | 4ce7ff6e | aurel32 | break;
|
284 | c6945b15 | aurel32 | /* DMA transl. table invalidated */
|
285 | c6945b15 | aurel32 | case 0x0028: |
286 | c6945b15 | aurel32 | break;
|
287 | c6945b15 | aurel32 | /* Cache Maintenance */
|
288 | c6945b15 | aurel32 | case 0x0030: |
289 | 9ea0b7a1 | aurel32 | s->cache_maint = val; |
290 | c6945b15 | aurel32 | break;
|
291 | 4ce7ff6e | aurel32 | /* I/O Cache Physical Tag */
|
292 | 4ce7ff6e | aurel32 | case 0x0048: |
293 | 4ce7ff6e | aurel32 | s->cache_ptag = val; |
294 | 4ce7ff6e | aurel32 | break;
|
295 | 4ce7ff6e | aurel32 | /* I/O Cache Logical Tag */
|
296 | 4ce7ff6e | aurel32 | case 0x0050: |
297 | 4ce7ff6e | aurel32 | s->cache_ltag = val; |
298 | 4ce7ff6e | aurel32 | break;
|
299 | 4ce7ff6e | aurel32 | /* I/O Cache Byte Mask */
|
300 | 4ce7ff6e | aurel32 | case 0x0058: |
301 | 4ce7ff6e | aurel32 | s->cache_bmask |= val; /* HACK */
|
302 | 4ce7ff6e | aurel32 | break;
|
303 | 4ce7ff6e | aurel32 | /* I/O Cache Buffer Window */
|
304 | 4ce7ff6e | aurel32 | case 0x0060: |
305 | 4ce7ff6e | aurel32 | /* HACK */
|
306 | 4ce7ff6e | aurel32 | if (s->cache_ltag == 0x80000001 && s->cache_bmask == 0xf0f0f0f) { |
307 | c227f099 | Anthony Liguori | target_phys_addr_t dest = s->cache_ptag & ~0x1;
|
308 | 9ea0b7a1 | aurel32 | dest += (s->cache_maint & 0x3) << 3; |
309 | 9ea0b7a1 | aurel32 | cpu_physical_memory_rw(dest, (uint8_t*)&val, 4, 1); |
310 | 4ce7ff6e | aurel32 | } |
311 | 4ce7ff6e | aurel32 | break;
|
312 | 4ce7ff6e | aurel32 | /* Remote Speed Registers */
|
313 | 4ce7ff6e | aurel32 | case 0x0070: |
314 | 4ce7ff6e | aurel32 | case 0x0078: |
315 | 4ce7ff6e | aurel32 | case 0x0080: |
316 | 4ce7ff6e | aurel32 | case 0x0088: |
317 | 4ce7ff6e | aurel32 | case 0x0090: |
318 | 4ce7ff6e | aurel32 | case 0x0098: |
319 | 4ce7ff6e | aurel32 | case 0x00a0: |
320 | 4ce7ff6e | aurel32 | case 0x00a8: |
321 | 4ce7ff6e | aurel32 | case 0x00b0: |
322 | 4ce7ff6e | aurel32 | case 0x00b8: |
323 | 4ce7ff6e | aurel32 | case 0x00c0: |
324 | 4ce7ff6e | aurel32 | case 0x00c8: |
325 | 4ce7ff6e | aurel32 | case 0x00d0: |
326 | 4ce7ff6e | aurel32 | case 0x00d8: |
327 | 4ce7ff6e | aurel32 | case 0x00e0: |
328 | 9ea0b7a1 | aurel32 | case 0x00e8: |
329 | 4ce7ff6e | aurel32 | s->rem_speed[(addr - 0x0070) >> 3] = val; |
330 | 4ce7ff6e | aurel32 | break;
|
331 | 4ce7ff6e | aurel32 | /* DMA channel base address */
|
332 | 4ce7ff6e | aurel32 | case 0x0100: |
333 | 4ce7ff6e | aurel32 | case 0x0108: |
334 | 4ce7ff6e | aurel32 | case 0x0110: |
335 | 4ce7ff6e | aurel32 | case 0x0118: |
336 | 4ce7ff6e | aurel32 | case 0x0120: |
337 | 4ce7ff6e | aurel32 | case 0x0128: |
338 | 4ce7ff6e | aurel32 | case 0x0130: |
339 | 4ce7ff6e | aurel32 | case 0x0138: |
340 | 4ce7ff6e | aurel32 | case 0x0140: |
341 | 4ce7ff6e | aurel32 | case 0x0148: |
342 | 4ce7ff6e | aurel32 | case 0x0150: |
343 | 4ce7ff6e | aurel32 | case 0x0158: |
344 | 4ce7ff6e | aurel32 | case 0x0160: |
345 | 4ce7ff6e | aurel32 | case 0x0168: |
346 | 4ce7ff6e | aurel32 | case 0x0170: |
347 | 4ce7ff6e | aurel32 | case 0x0178: |
348 | 4ce7ff6e | aurel32 | case 0x0180: |
349 | 4ce7ff6e | aurel32 | case 0x0188: |
350 | 4ce7ff6e | aurel32 | case 0x0190: |
351 | 4ce7ff6e | aurel32 | case 0x0198: |
352 | 4ce7ff6e | aurel32 | case 0x01a0: |
353 | 4ce7ff6e | aurel32 | case 0x01a8: |
354 | 4ce7ff6e | aurel32 | case 0x01b0: |
355 | 4ce7ff6e | aurel32 | case 0x01b8: |
356 | 4ce7ff6e | aurel32 | case 0x01c0: |
357 | 4ce7ff6e | aurel32 | case 0x01c8: |
358 | 4ce7ff6e | aurel32 | case 0x01d0: |
359 | 4ce7ff6e | aurel32 | case 0x01d8: |
360 | 4ce7ff6e | aurel32 | case 0x01e0: |
361 | c6945b15 | aurel32 | case 0x01e8: |
362 | 4ce7ff6e | aurel32 | case 0x01f0: |
363 | 4ce7ff6e | aurel32 | case 0x01f8: |
364 | 4ce7ff6e | aurel32 | { |
365 | 4ce7ff6e | aurel32 | int entry = (addr - 0x0100) >> 5; |
366 | 4ce7ff6e | aurel32 | int idx = (addr & 0x1f) >> 3; |
367 | 4ce7ff6e | aurel32 | s->dma_regs[entry][idx] = val; |
368 | 4ce7ff6e | aurel32 | } |
369 | 4ce7ff6e | aurel32 | break;
|
370 | 4ce7ff6e | aurel32 | /* Offset 0x0210 */
|
371 | 4ce7ff6e | aurel32 | case 0x0210: |
372 | 4ce7ff6e | aurel32 | s->offset210 = val; |
373 | 4ce7ff6e | aurel32 | break;
|
374 | 4ce7ff6e | aurel32 | /* Interval timer reload */
|
375 | 4ce7ff6e | aurel32 | case 0x0228: |
376 | 4ce7ff6e | aurel32 | s->itr = val; |
377 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->timer_irq); |
378 | 4ce7ff6e | aurel32 | set_next_tick(s); |
379 | 4ce7ff6e | aurel32 | break;
|
380 | 9ea0b7a1 | aurel32 | /* EISA interrupt */
|
381 | 9ea0b7a1 | aurel32 | case 0x0238: |
382 | 9ea0b7a1 | aurel32 | break;
|
383 | 4ce7ff6e | aurel32 | default:
|
384 | c6945b15 | aurel32 | RC4030_ERROR("invalid write of 0x%02x at [" TARGET_FMT_plx "]\n", val, addr); |
385 | 4ce7ff6e | aurel32 | break;
|
386 | 4ce7ff6e | aurel32 | } |
387 | 4ce7ff6e | aurel32 | } |
388 | 4ce7ff6e | aurel32 | |
389 | c227f099 | Anthony Liguori | static void rc4030_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
390 | 4ce7ff6e | aurel32 | { |
391 | 4ce7ff6e | aurel32 | uint32_t old_val = rc4030_readl(opaque, addr & ~0x3);
|
392 | 4ce7ff6e | aurel32 | |
393 | 4ce7ff6e | aurel32 | if (addr & 0x2) |
394 | 4ce7ff6e | aurel32 | val = (val << 16) | (old_val & 0x0000ffff); |
395 | 4ce7ff6e | aurel32 | else
|
396 | 4ce7ff6e | aurel32 | val = val | (old_val & 0xffff0000);
|
397 | 4ce7ff6e | aurel32 | rc4030_writel(opaque, addr & ~0x3, val);
|
398 | 4ce7ff6e | aurel32 | } |
399 | 4ce7ff6e | aurel32 | |
400 | c227f099 | Anthony Liguori | static void rc4030_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
401 | 4ce7ff6e | aurel32 | { |
402 | 4ce7ff6e | aurel32 | uint32_t old_val = rc4030_readl(opaque, addr & ~0x3);
|
403 | 4ce7ff6e | aurel32 | |
404 | 4ce7ff6e | aurel32 | switch (addr & 3) { |
405 | 4ce7ff6e | aurel32 | case 0: |
406 | 4ce7ff6e | aurel32 | val = val | (old_val & 0xffffff00);
|
407 | 4ce7ff6e | aurel32 | break;
|
408 | 4ce7ff6e | aurel32 | case 1: |
409 | 4ce7ff6e | aurel32 | val = (val << 8) | (old_val & 0xffff00ff); |
410 | 4ce7ff6e | aurel32 | break;
|
411 | 4ce7ff6e | aurel32 | case 2: |
412 | 4ce7ff6e | aurel32 | val = (val << 16) | (old_val & 0xff00ffff); |
413 | 4ce7ff6e | aurel32 | break;
|
414 | 4ce7ff6e | aurel32 | case 3: |
415 | 4ce7ff6e | aurel32 | val = (val << 24) | (old_val & 0x00ffffff); |
416 | 4ce7ff6e | aurel32 | break;
|
417 | 4ce7ff6e | aurel32 | } |
418 | 4ce7ff6e | aurel32 | rc4030_writel(opaque, addr & ~0x3, val);
|
419 | 4ce7ff6e | aurel32 | } |
420 | 4ce7ff6e | aurel32 | |
421 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const rc4030_read[3] = { |
422 | 4ce7ff6e | aurel32 | rc4030_readb, |
423 | 4ce7ff6e | aurel32 | rc4030_readw, |
424 | 4ce7ff6e | aurel32 | rc4030_readl, |
425 | 4ce7ff6e | aurel32 | }; |
426 | 4ce7ff6e | aurel32 | |
427 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const rc4030_write[3] = { |
428 | 4ce7ff6e | aurel32 | rc4030_writeb, |
429 | 4ce7ff6e | aurel32 | rc4030_writew, |
430 | 4ce7ff6e | aurel32 | rc4030_writel, |
431 | 4ce7ff6e | aurel32 | }; |
432 | 4ce7ff6e | aurel32 | |
433 | 4ce7ff6e | aurel32 | static void update_jazz_irq(rc4030State *s) |
434 | 4ce7ff6e | aurel32 | { |
435 | 4ce7ff6e | aurel32 | uint16_t pending; |
436 | 4ce7ff6e | aurel32 | |
437 | 4ce7ff6e | aurel32 | pending = s->isr_jazz & s->imr_jazz; |
438 | 4ce7ff6e | aurel32 | |
439 | 4ce7ff6e | aurel32 | #ifdef DEBUG_RC4030
|
440 | 4ce7ff6e | aurel32 | if (s->isr_jazz != 0) { |
441 | 4ce7ff6e | aurel32 | uint32_t irq = 0;
|
442 | c6945b15 | aurel32 | DPRINTF("pending irqs:");
|
443 | b1503cda | malc | for (irq = 0; irq < ARRAY_SIZE(irq_names); irq++) { |
444 | 4ce7ff6e | aurel32 | if (s->isr_jazz & (1 << irq)) { |
445 | 4ce7ff6e | aurel32 | printf(" %s", irq_names[irq]);
|
446 | 4ce7ff6e | aurel32 | if (!(s->imr_jazz & (1 << irq))) { |
447 | 4ce7ff6e | aurel32 | printf("(ignored)");
|
448 | 4ce7ff6e | aurel32 | } |
449 | 4ce7ff6e | aurel32 | } |
450 | 4ce7ff6e | aurel32 | } |
451 | 4ce7ff6e | aurel32 | printf("\n");
|
452 | 4ce7ff6e | aurel32 | } |
453 | 4ce7ff6e | aurel32 | #endif
|
454 | 4ce7ff6e | aurel32 | |
455 | 4ce7ff6e | aurel32 | if (pending != 0) |
456 | 4ce7ff6e | aurel32 | qemu_irq_raise(s->jazz_bus_irq); |
457 | 4ce7ff6e | aurel32 | else
|
458 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->jazz_bus_irq); |
459 | 4ce7ff6e | aurel32 | } |
460 | 4ce7ff6e | aurel32 | |
461 | 4ce7ff6e | aurel32 | static void rc4030_irq_jazz_request(void *opaque, int irq, int level) |
462 | 4ce7ff6e | aurel32 | { |
463 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
464 | 4ce7ff6e | aurel32 | |
465 | 4ce7ff6e | aurel32 | if (level) {
|
466 | 4ce7ff6e | aurel32 | s->isr_jazz |= 1 << irq;
|
467 | 4ce7ff6e | aurel32 | } else {
|
468 | 4ce7ff6e | aurel32 | s->isr_jazz &= ~(1 << irq);
|
469 | 4ce7ff6e | aurel32 | } |
470 | 4ce7ff6e | aurel32 | |
471 | 4ce7ff6e | aurel32 | update_jazz_irq(s); |
472 | 4ce7ff6e | aurel32 | } |
473 | 4ce7ff6e | aurel32 | |
474 | 4ce7ff6e | aurel32 | static void rc4030_periodic_timer(void *opaque) |
475 | 4ce7ff6e | aurel32 | { |
476 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
477 | 4ce7ff6e | aurel32 | |
478 | 4ce7ff6e | aurel32 | set_next_tick(s); |
479 | 4ce7ff6e | aurel32 | qemu_irq_raise(s->timer_irq); |
480 | 4ce7ff6e | aurel32 | } |
481 | 4ce7ff6e | aurel32 | |
482 | c227f099 | Anthony Liguori | static uint32_t jazzio_readw(void *opaque, target_phys_addr_t addr) |
483 | 4ce7ff6e | aurel32 | { |
484 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
485 | 4ce7ff6e | aurel32 | uint32_t val; |
486 | 4ce7ff6e | aurel32 | uint32_t irq; |
487 | 4ce7ff6e | aurel32 | addr &= 0xfff;
|
488 | 4ce7ff6e | aurel32 | |
489 | 4ce7ff6e | aurel32 | switch (addr) {
|
490 | c6945b15 | aurel32 | /* Local bus int source */
|
491 | 4ce7ff6e | aurel32 | case 0x00: { |
492 | 4ce7ff6e | aurel32 | uint32_t pending = s->isr_jazz & s->imr_jazz; |
493 | 4ce7ff6e | aurel32 | val = 0;
|
494 | 4ce7ff6e | aurel32 | irq = 0;
|
495 | 4ce7ff6e | aurel32 | while (pending) {
|
496 | 4ce7ff6e | aurel32 | if (pending & 1) { |
497 | c6945b15 | aurel32 | DPRINTF("returning irq %s\n", irq_names[irq]);
|
498 | 4ce7ff6e | aurel32 | val = (irq + 1) << 2; |
499 | 4ce7ff6e | aurel32 | break;
|
500 | 4ce7ff6e | aurel32 | } |
501 | 4ce7ff6e | aurel32 | irq++; |
502 | 4ce7ff6e | aurel32 | pending >>= 1;
|
503 | 4ce7ff6e | aurel32 | } |
504 | 4ce7ff6e | aurel32 | break;
|
505 | 4ce7ff6e | aurel32 | } |
506 | c6945b15 | aurel32 | /* Local bus int enable mask */
|
507 | c6945b15 | aurel32 | case 0x02: |
508 | c6945b15 | aurel32 | val = s->imr_jazz; |
509 | c6945b15 | aurel32 | break;
|
510 | 4ce7ff6e | aurel32 | default:
|
511 | c6945b15 | aurel32 | RC4030_ERROR("(jazz io controller) invalid read [" TARGET_FMT_plx "]\n", addr); |
512 | c6945b15 | aurel32 | val = 0;
|
513 | 4ce7ff6e | aurel32 | } |
514 | 4ce7ff6e | aurel32 | |
515 | c6945b15 | aurel32 | DPRINTF("(jazz io controller) read 0x%04x at " TARGET_FMT_plx "\n", val, addr); |
516 | 4ce7ff6e | aurel32 | |
517 | 4ce7ff6e | aurel32 | return val;
|
518 | 4ce7ff6e | aurel32 | } |
519 | 4ce7ff6e | aurel32 | |
520 | c227f099 | Anthony Liguori | static uint32_t jazzio_readb(void *opaque, target_phys_addr_t addr) |
521 | 4ce7ff6e | aurel32 | { |
522 | 4ce7ff6e | aurel32 | uint32_t v; |
523 | c6945b15 | aurel32 | v = jazzio_readw(opaque, addr & ~0x1);
|
524 | c6945b15 | aurel32 | return (v >> (8 * (addr & 0x1))) & 0xff; |
525 | 4ce7ff6e | aurel32 | } |
526 | 4ce7ff6e | aurel32 | |
527 | c227f099 | Anthony Liguori | static uint32_t jazzio_readl(void *opaque, target_phys_addr_t addr) |
528 | 4ce7ff6e | aurel32 | { |
529 | 4ce7ff6e | aurel32 | uint32_t v; |
530 | c6945b15 | aurel32 | v = jazzio_readw(opaque, addr); |
531 | c6945b15 | aurel32 | v |= jazzio_readw(opaque, addr + 2) << 16; |
532 | 4ce7ff6e | aurel32 | return v;
|
533 | 4ce7ff6e | aurel32 | } |
534 | 4ce7ff6e | aurel32 | |
535 | c227f099 | Anthony Liguori | static void jazzio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
536 | 4ce7ff6e | aurel32 | { |
537 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
538 | 4ce7ff6e | aurel32 | addr &= 0xfff;
|
539 | 4ce7ff6e | aurel32 | |
540 | c6945b15 | aurel32 | DPRINTF("(jazz io controller) write 0x%04x at " TARGET_FMT_plx "\n", val, addr); |
541 | 4ce7ff6e | aurel32 | |
542 | 4ce7ff6e | aurel32 | switch (addr) {
|
543 | 4ce7ff6e | aurel32 | /* Local bus int enable mask */
|
544 | 4ce7ff6e | aurel32 | case 0x02: |
545 | c6945b15 | aurel32 | s->imr_jazz = val; |
546 | c6945b15 | aurel32 | update_jazz_irq(s); |
547 | 4ce7ff6e | aurel32 | break;
|
548 | 4ce7ff6e | aurel32 | default:
|
549 | c6945b15 | aurel32 | RC4030_ERROR("(jazz io controller) invalid write of 0x%04x at [" TARGET_FMT_plx "]\n", val, addr); |
550 | 4ce7ff6e | aurel32 | break;
|
551 | 4ce7ff6e | aurel32 | } |
552 | 4ce7ff6e | aurel32 | } |
553 | 4ce7ff6e | aurel32 | |
554 | c227f099 | Anthony Liguori | static void jazzio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
555 | 4ce7ff6e | aurel32 | { |
556 | c6945b15 | aurel32 | uint32_t old_val = jazzio_readw(opaque, addr & ~0x1);
|
557 | c6945b15 | aurel32 | |
558 | c6945b15 | aurel32 | switch (addr & 1) { |
559 | c6945b15 | aurel32 | case 0: |
560 | c6945b15 | aurel32 | val = val | (old_val & 0xff00);
|
561 | c6945b15 | aurel32 | break;
|
562 | c6945b15 | aurel32 | case 1: |
563 | c6945b15 | aurel32 | val = (val << 8) | (old_val & 0x00ff); |
564 | c6945b15 | aurel32 | break;
|
565 | c6945b15 | aurel32 | } |
566 | c6945b15 | aurel32 | jazzio_writew(opaque, addr & ~0x1, val);
|
567 | 4ce7ff6e | aurel32 | } |
568 | 4ce7ff6e | aurel32 | |
569 | c227f099 | Anthony Liguori | static void jazzio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
570 | 4ce7ff6e | aurel32 | { |
571 | c6945b15 | aurel32 | jazzio_writew(opaque, addr, val & 0xffff);
|
572 | c6945b15 | aurel32 | jazzio_writew(opaque, addr + 2, (val >> 16) & 0xffff); |
573 | 4ce7ff6e | aurel32 | } |
574 | 4ce7ff6e | aurel32 | |
575 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const jazzio_read[3] = { |
576 | c6945b15 | aurel32 | jazzio_readb, |
577 | c6945b15 | aurel32 | jazzio_readw, |
578 | c6945b15 | aurel32 | jazzio_readl, |
579 | 4ce7ff6e | aurel32 | }; |
580 | 4ce7ff6e | aurel32 | |
581 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const jazzio_write[3] = { |
582 | c6945b15 | aurel32 | jazzio_writeb, |
583 | c6945b15 | aurel32 | jazzio_writew, |
584 | c6945b15 | aurel32 | jazzio_writel, |
585 | 4ce7ff6e | aurel32 | }; |
586 | 4ce7ff6e | aurel32 | |
587 | 4ce7ff6e | aurel32 | static void rc4030_reset(void *opaque) |
588 | 4ce7ff6e | aurel32 | { |
589 | 4ce7ff6e | aurel32 | rc4030State *s = opaque; |
590 | 4ce7ff6e | aurel32 | int i;
|
591 | 4ce7ff6e | aurel32 | |
592 | c6945b15 | aurel32 | s->config = 0x410; /* some boards seem to accept 0x104 too */ |
593 | 9ea0b7a1 | aurel32 | s->revision = 1;
|
594 | 4ce7ff6e | aurel32 | s->invalid_address_register = 0;
|
595 | 4ce7ff6e | aurel32 | |
596 | 4ce7ff6e | aurel32 | memset(s->dma_regs, 0, sizeof(s->dma_regs)); |
597 | 4ce7ff6e | aurel32 | s->dma_tl_base = s->dma_tl_limit = 0;
|
598 | 4ce7ff6e | aurel32 | |
599 | 4ce7ff6e | aurel32 | s->remote_failed_address = s->memory_failed_address = 0;
|
600 | 9ea0b7a1 | aurel32 | s->cache_maint = 0;
|
601 | 4ce7ff6e | aurel32 | s->cache_ptag = s->cache_ltag = 0;
|
602 | 9ea0b7a1 | aurel32 | s->cache_bmask = 0;
|
603 | 4ce7ff6e | aurel32 | |
604 | 4ce7ff6e | aurel32 | s->offset210 = 0x18186;
|
605 | 4ce7ff6e | aurel32 | s->nvram_protect = 7;
|
606 | 4ce7ff6e | aurel32 | for (i = 0; i < 15; i++) |
607 | 4ce7ff6e | aurel32 | s->rem_speed[i] = 7;
|
608 | 9ea0b7a1 | aurel32 | s->imr_jazz = 0x10; /* XXX: required by firmware, but why? */ |
609 | 9ea0b7a1 | aurel32 | s->isr_jazz = 0;
|
610 | 4ce7ff6e | aurel32 | |
611 | 4ce7ff6e | aurel32 | s->itr = 0;
|
612 | 4ce7ff6e | aurel32 | |
613 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->timer_irq); |
614 | 4ce7ff6e | aurel32 | qemu_irq_lower(s->jazz_bus_irq); |
615 | 4ce7ff6e | aurel32 | } |
616 | 4ce7ff6e | aurel32 | |
617 | d5853c20 | aurel32 | static int rc4030_load(QEMUFile *f, void *opaque, int version_id) |
618 | d5853c20 | aurel32 | { |
619 | d5853c20 | aurel32 | rc4030State* s = opaque; |
620 | d5853c20 | aurel32 | int i, j;
|
621 | d5853c20 | aurel32 | |
622 | 9ea0b7a1 | aurel32 | if (version_id != 2) |
623 | d5853c20 | aurel32 | return -EINVAL;
|
624 | d5853c20 | aurel32 | |
625 | d5853c20 | aurel32 | s->config = qemu_get_be32(f); |
626 | d5853c20 | aurel32 | s->invalid_address_register = qemu_get_be32(f); |
627 | d5853c20 | aurel32 | for (i = 0; i < 8; i++) |
628 | d5853c20 | aurel32 | for (j = 0; j < 4; j++) |
629 | d5853c20 | aurel32 | s->dma_regs[i][j] = qemu_get_be32(f); |
630 | d5853c20 | aurel32 | s->dma_tl_base = qemu_get_be32(f); |
631 | d5853c20 | aurel32 | s->dma_tl_limit = qemu_get_be32(f); |
632 | 9ea0b7a1 | aurel32 | s->cache_maint = qemu_get_be32(f); |
633 | d5853c20 | aurel32 | s->remote_failed_address = qemu_get_be32(f); |
634 | d5853c20 | aurel32 | s->memory_failed_address = qemu_get_be32(f); |
635 | d5853c20 | aurel32 | s->cache_ptag = qemu_get_be32(f); |
636 | d5853c20 | aurel32 | s->cache_ltag = qemu_get_be32(f); |
637 | d5853c20 | aurel32 | s->cache_bmask = qemu_get_be32(f); |
638 | d5853c20 | aurel32 | s->offset210 = qemu_get_be32(f); |
639 | d5853c20 | aurel32 | s->nvram_protect = qemu_get_be32(f); |
640 | d5853c20 | aurel32 | for (i = 0; i < 15; i++) |
641 | d5853c20 | aurel32 | s->rem_speed[i] = qemu_get_be32(f); |
642 | d5853c20 | aurel32 | s->imr_jazz = qemu_get_be32(f); |
643 | d5853c20 | aurel32 | s->isr_jazz = qemu_get_be32(f); |
644 | d5853c20 | aurel32 | s->itr = qemu_get_be32(f); |
645 | d5853c20 | aurel32 | |
646 | d5853c20 | aurel32 | set_next_tick(s); |
647 | d5853c20 | aurel32 | update_jazz_irq(s); |
648 | d5853c20 | aurel32 | |
649 | d5853c20 | aurel32 | return 0; |
650 | d5853c20 | aurel32 | } |
651 | d5853c20 | aurel32 | |
652 | d5853c20 | aurel32 | static void rc4030_save(QEMUFile *f, void *opaque) |
653 | d5853c20 | aurel32 | { |
654 | d5853c20 | aurel32 | rc4030State* s = opaque; |
655 | d5853c20 | aurel32 | int i, j;
|
656 | d5853c20 | aurel32 | |
657 | d5853c20 | aurel32 | qemu_put_be32(f, s->config); |
658 | d5853c20 | aurel32 | qemu_put_be32(f, s->invalid_address_register); |
659 | d5853c20 | aurel32 | for (i = 0; i < 8; i++) |
660 | d5853c20 | aurel32 | for (j = 0; j < 4; j++) |
661 | d5853c20 | aurel32 | qemu_put_be32(f, s->dma_regs[i][j]); |
662 | d5853c20 | aurel32 | qemu_put_be32(f, s->dma_tl_base); |
663 | d5853c20 | aurel32 | qemu_put_be32(f, s->dma_tl_limit); |
664 | 9ea0b7a1 | aurel32 | qemu_put_be32(f, s->cache_maint); |
665 | d5853c20 | aurel32 | qemu_put_be32(f, s->remote_failed_address); |
666 | d5853c20 | aurel32 | qemu_put_be32(f, s->memory_failed_address); |
667 | d5853c20 | aurel32 | qemu_put_be32(f, s->cache_ptag); |
668 | d5853c20 | aurel32 | qemu_put_be32(f, s->cache_ltag); |
669 | d5853c20 | aurel32 | qemu_put_be32(f, s->cache_bmask); |
670 | d5853c20 | aurel32 | qemu_put_be32(f, s->offset210); |
671 | d5853c20 | aurel32 | qemu_put_be32(f, s->nvram_protect); |
672 | d5853c20 | aurel32 | for (i = 0; i < 15; i++) |
673 | d5853c20 | aurel32 | qemu_put_be32(f, s->rem_speed[i]); |
674 | d5853c20 | aurel32 | qemu_put_be32(f, s->imr_jazz); |
675 | d5853c20 | aurel32 | qemu_put_be32(f, s->isr_jazz); |
676 | d5853c20 | aurel32 | qemu_put_be32(f, s->itr); |
677 | d5853c20 | aurel32 | } |
678 | d5853c20 | aurel32 | |
679 | c227f099 | Anthony Liguori | void rc4030_dma_memory_rw(void *opaque, target_phys_addr_t addr, uint8_t *buf, int len, int is_write) |
680 | c6945b15 | aurel32 | { |
681 | c6945b15 | aurel32 | rc4030State *s = opaque; |
682 | c227f099 | Anthony Liguori | target_phys_addr_t entry_addr; |
683 | c227f099 | Anthony Liguori | target_phys_addr_t phys_addr; |
684 | c6945b15 | aurel32 | dma_pagetable_entry entry; |
685 | 9ea0b7a1 | aurel32 | int index;
|
686 | c6945b15 | aurel32 | int ncpy, i;
|
687 | c6945b15 | aurel32 | |
688 | c6945b15 | aurel32 | i = 0;
|
689 | c6945b15 | aurel32 | for (;;) {
|
690 | c6945b15 | aurel32 | if (i == len) {
|
691 | c6945b15 | aurel32 | break;
|
692 | c6945b15 | aurel32 | } |
693 | c6945b15 | aurel32 | |
694 | 9ea0b7a1 | aurel32 | ncpy = DMA_PAGESIZE - (addr & (DMA_PAGESIZE - 1));
|
695 | c6945b15 | aurel32 | if (ncpy > len - i)
|
696 | c6945b15 | aurel32 | ncpy = len - i; |
697 | c6945b15 | aurel32 | |
698 | c6945b15 | aurel32 | /* Get DMA translation table entry */
|
699 | 9ea0b7a1 | aurel32 | index = addr / DMA_PAGESIZE; |
700 | c6945b15 | aurel32 | if (index >= s->dma_tl_limit / sizeof(dma_pagetable_entry)) { |
701 | c6945b15 | aurel32 | break;
|
702 | c6945b15 | aurel32 | } |
703 | c6945b15 | aurel32 | entry_addr = s->dma_tl_base + index * sizeof(dma_pagetable_entry);
|
704 | c6945b15 | aurel32 | /* XXX: not sure. should we really use only lowest bits? */
|
705 | c6945b15 | aurel32 | entry_addr &= 0x7fffffff;
|
706 | c6945b15 | aurel32 | cpu_physical_memory_rw(entry_addr, (uint8_t *)&entry, sizeof(entry), 0); |
707 | c6945b15 | aurel32 | |
708 | c6945b15 | aurel32 | /* Read/write data at right place */
|
709 | 9ea0b7a1 | aurel32 | phys_addr = entry.frame + (addr & (DMA_PAGESIZE - 1));
|
710 | c6945b15 | aurel32 | cpu_physical_memory_rw(phys_addr, &buf[i], ncpy, is_write); |
711 | c6945b15 | aurel32 | |
712 | c6945b15 | aurel32 | i += ncpy; |
713 | 9ea0b7a1 | aurel32 | addr += ncpy; |
714 | 9ea0b7a1 | aurel32 | } |
715 | 9ea0b7a1 | aurel32 | } |
716 | 9ea0b7a1 | aurel32 | |
717 | 9ea0b7a1 | aurel32 | static void rc4030_do_dma(void *opaque, int n, uint8_t *buf, int len, int is_write) |
718 | 9ea0b7a1 | aurel32 | { |
719 | 9ea0b7a1 | aurel32 | rc4030State *s = opaque; |
720 | c227f099 | Anthony Liguori | target_phys_addr_t dma_addr; |
721 | 9ea0b7a1 | aurel32 | int dev_to_mem;
|
722 | 9ea0b7a1 | aurel32 | |
723 | 9ea0b7a1 | aurel32 | s->dma_regs[n][DMA_REG_ENABLE] &= ~(DMA_FLAG_TC_INTR | DMA_FLAG_MEM_INTR | DMA_FLAG_ADDR_INTR); |
724 | 9ea0b7a1 | aurel32 | |
725 | 9ea0b7a1 | aurel32 | /* Check DMA channel consistency */
|
726 | 9ea0b7a1 | aurel32 | dev_to_mem = (s->dma_regs[n][DMA_REG_ENABLE] & DMA_FLAG_MEM_TO_DEV) ? 0 : 1; |
727 | 9ea0b7a1 | aurel32 | if (!(s->dma_regs[n][DMA_REG_ENABLE] & DMA_FLAG_ENABLE) ||
|
728 | 9ea0b7a1 | aurel32 | (is_write != dev_to_mem)) { |
729 | 9ea0b7a1 | aurel32 | s->dma_regs[n][DMA_REG_ENABLE] |= DMA_FLAG_MEM_INTR; |
730 | 9ea0b7a1 | aurel32 | s->nmi_interrupt |= 1 << n;
|
731 | 9ea0b7a1 | aurel32 | return;
|
732 | c6945b15 | aurel32 | } |
733 | c6945b15 | aurel32 | |
734 | 9ea0b7a1 | aurel32 | /* Get start address and len */
|
735 | 9ea0b7a1 | aurel32 | if (len > s->dma_regs[n][DMA_REG_COUNT])
|
736 | 9ea0b7a1 | aurel32 | len = s->dma_regs[n][DMA_REG_COUNT]; |
737 | 9ea0b7a1 | aurel32 | dma_addr = s->dma_regs[n][DMA_REG_ADDRESS]; |
738 | 9ea0b7a1 | aurel32 | |
739 | 9ea0b7a1 | aurel32 | /* Read/write data at right place */
|
740 | 9ea0b7a1 | aurel32 | rc4030_dma_memory_rw(opaque, dma_addr, buf, len, is_write); |
741 | 9ea0b7a1 | aurel32 | |
742 | 9ea0b7a1 | aurel32 | s->dma_regs[n][DMA_REG_ENABLE] |= DMA_FLAG_TC_INTR; |
743 | 9ea0b7a1 | aurel32 | s->dma_regs[n][DMA_REG_COUNT] -= len; |
744 | 9ea0b7a1 | aurel32 | |
745 | c6945b15 | aurel32 | #ifdef DEBUG_RC4030_DMA
|
746 | c6945b15 | aurel32 | { |
747 | c6945b15 | aurel32 | int i, j;
|
748 | c6945b15 | aurel32 | printf("rc4030 dma: Copying %d bytes %s host %p\n",
|
749 | c6945b15 | aurel32 | len, is_write ? "from" : "to", buf); |
750 | c6945b15 | aurel32 | for (i = 0; i < len; i += 16) { |
751 | c6945b15 | aurel32 | int n = min(16, len - i); |
752 | c6945b15 | aurel32 | for (j = 0; j < n; j++) |
753 | c6945b15 | aurel32 | printf("%02x ", buf[i + j]);
|
754 | c6945b15 | aurel32 | while (j++ < 16) |
755 | c6945b15 | aurel32 | printf(" ");
|
756 | c6945b15 | aurel32 | printf("| ");
|
757 | c6945b15 | aurel32 | for (j = 0; j < n; j++) |
758 | c6945b15 | aurel32 | printf("%c", isprint(buf[i + j]) ? buf[i + j] : '.'); |
759 | c6945b15 | aurel32 | printf("\n");
|
760 | c6945b15 | aurel32 | } |
761 | c6945b15 | aurel32 | } |
762 | c6945b15 | aurel32 | #endif
|
763 | c6945b15 | aurel32 | } |
764 | c6945b15 | aurel32 | |
765 | c6945b15 | aurel32 | struct rc4030DMAState {
|
766 | c6945b15 | aurel32 | void *opaque;
|
767 | c6945b15 | aurel32 | int n;
|
768 | c6945b15 | aurel32 | }; |
769 | c6945b15 | aurel32 | |
770 | 68238a9e | aurel32 | void rc4030_dma_read(void *dma, uint8_t *buf, int len) |
771 | c6945b15 | aurel32 | { |
772 | c6945b15 | aurel32 | rc4030_dma s = dma; |
773 | c6945b15 | aurel32 | rc4030_do_dma(s->opaque, s->n, buf, len, 0);
|
774 | c6945b15 | aurel32 | } |
775 | c6945b15 | aurel32 | |
776 | 68238a9e | aurel32 | void rc4030_dma_write(void *dma, uint8_t *buf, int len) |
777 | c6945b15 | aurel32 | { |
778 | c6945b15 | aurel32 | rc4030_dma s = dma; |
779 | c6945b15 | aurel32 | rc4030_do_dma(s->opaque, s->n, buf, len, 1);
|
780 | c6945b15 | aurel32 | } |
781 | c6945b15 | aurel32 | |
782 | c6945b15 | aurel32 | static rc4030_dma *rc4030_allocate_dmas(void *opaque, int n) |
783 | c6945b15 | aurel32 | { |
784 | c6945b15 | aurel32 | rc4030_dma *s; |
785 | c6945b15 | aurel32 | struct rc4030DMAState *p;
|
786 | c6945b15 | aurel32 | int i;
|
787 | c6945b15 | aurel32 | |
788 | c6945b15 | aurel32 | s = (rc4030_dma *)qemu_mallocz(sizeof(rc4030_dma) * n);
|
789 | c6945b15 | aurel32 | p = (struct rc4030DMAState *)qemu_mallocz(sizeof(struct rc4030DMAState) * n); |
790 | c6945b15 | aurel32 | for (i = 0; i < n; i++) { |
791 | c6945b15 | aurel32 | p->opaque = opaque; |
792 | c6945b15 | aurel32 | p->n = i; |
793 | c6945b15 | aurel32 | s[i] = p; |
794 | c6945b15 | aurel32 | p++; |
795 | c6945b15 | aurel32 | } |
796 | c6945b15 | aurel32 | return s;
|
797 | c6945b15 | aurel32 | } |
798 | c6945b15 | aurel32 | |
799 | 68238a9e | aurel32 | void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus,
|
800 | 68238a9e | aurel32 | qemu_irq **irqs, rc4030_dma **dmas) |
801 | 4ce7ff6e | aurel32 | { |
802 | 4ce7ff6e | aurel32 | rc4030State *s; |
803 | c6945b15 | aurel32 | int s_chipset, s_jazzio;
|
804 | 4ce7ff6e | aurel32 | |
805 | 4ce7ff6e | aurel32 | s = qemu_mallocz(sizeof(rc4030State));
|
806 | 4ce7ff6e | aurel32 | |
807 | 68238a9e | aurel32 | *irqs = qemu_allocate_irqs(rc4030_irq_jazz_request, s, 16);
|
808 | c6945b15 | aurel32 | *dmas = rc4030_allocate_dmas(s, 4);
|
809 | c6945b15 | aurel32 | |
810 | 4ce7ff6e | aurel32 | s->periodic_timer = qemu_new_timer(vm_clock, rc4030_periodic_timer, s); |
811 | 4ce7ff6e | aurel32 | s->timer_irq = timer; |
812 | 4ce7ff6e | aurel32 | s->jazz_bus_irq = jazz_bus; |
813 | 4ce7ff6e | aurel32 | |
814 | a08d4367 | Jan Kiszka | qemu_register_reset(rc4030_reset, s); |
815 | 9ea0b7a1 | aurel32 | register_savevm("rc4030", 0, 2, rc4030_save, rc4030_load, s); |
816 | 4ce7ff6e | aurel32 | rc4030_reset(s); |
817 | 4ce7ff6e | aurel32 | |
818 | 1eed09cb | Avi Kivity | s_chipset = cpu_register_io_memory(rc4030_read, rc4030_write, s); |
819 | 4ce7ff6e | aurel32 | cpu_register_physical_memory(0x80000000, 0x300, s_chipset); |
820 | 1eed09cb | Avi Kivity | s_jazzio = cpu_register_io_memory(jazzio_read, jazzio_write, s); |
821 | c6945b15 | aurel32 | cpu_register_physical_memory(0xf0000000, 0x00001000, s_jazzio); |
822 | 4ce7ff6e | aurel32 | |
823 | 68238a9e | aurel32 | return s;
|
824 | 4ce7ff6e | aurel32 | } |