root / hw / sh7750.c @ 94a943ef
History | View | Annotate | Download (21.7 kB)
1 |
/*
|
---|---|
2 |
* SH7750 device
|
3 |
*
|
4 |
* Copyright (c) 2007 Magnus Damm
|
5 |
* Copyright (c) 2005 Samuel Tardieu
|
6 |
*
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
9 |
* in the Software without restriction, including without limitation the rights
|
10 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
* copies of the Software, and to permit persons to whom the Software is
|
12 |
* furnished to do so, subject to the following conditions:
|
13 |
*
|
14 |
* The above copyright notice and this permission notice shall be included in
|
15 |
* all copies or substantial portions of the Software.
|
16 |
*
|
17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 |
* THE SOFTWARE.
|
24 |
*/
|
25 |
#include <stdio.h> |
26 |
#include "hw.h" |
27 |
#include "sh.h" |
28 |
#include "sysemu.h" |
29 |
#include "sh7750_regs.h" |
30 |
#include "sh7750_regnames.h" |
31 |
#include "sh_intc.h" |
32 |
#include "exec-all.h" |
33 |
#include "cpu.h" |
34 |
|
35 |
#define NB_DEVICES 4 |
36 |
|
37 |
typedef struct SH7750State { |
38 |
/* CPU */
|
39 |
CPUSH4State *cpu; |
40 |
/* Peripheral frequency in Hz */
|
41 |
uint32_t periph_freq; |
42 |
/* SDRAM controller */
|
43 |
uint32_t bcr1; |
44 |
uint16_t bcr2; |
45 |
uint16_t bcr3; |
46 |
uint32_t bcr4; |
47 |
uint16_t rfcr; |
48 |
/* PCMCIA controller */
|
49 |
uint16_t pcr; |
50 |
/* IO ports */
|
51 |
uint16_t gpioic; |
52 |
uint32_t pctra; |
53 |
uint32_t pctrb; |
54 |
uint16_t portdira; /* Cached */
|
55 |
uint16_t portpullupa; /* Cached */
|
56 |
uint16_t portdirb; /* Cached */
|
57 |
uint16_t portpullupb; /* Cached */
|
58 |
uint16_t pdtra; |
59 |
uint16_t pdtrb; |
60 |
uint16_t periph_pdtra; /* Imposed by the peripherals */
|
61 |
uint16_t periph_portdira; /* Direction seen from the peripherals */
|
62 |
uint16_t periph_pdtrb; /* Imposed by the peripherals */
|
63 |
uint16_t periph_portdirb; /* Direction seen from the peripherals */
|
64 |
sh7750_io_device *devices[NB_DEVICES]; /* External peripherals */
|
65 |
|
66 |
/* Cache */
|
67 |
uint32_t ccr; |
68 |
|
69 |
struct intc_desc intc;
|
70 |
} SH7750State; |
71 |
|
72 |
static int inline has_bcr3_and_bcr4(SH7750State * s) |
73 |
{ |
74 |
return (s->cpu->features & SH_FEATURE_BCR3_AND_BCR4);
|
75 |
} |
76 |
/**********************************************************************
|
77 |
I/O ports
|
78 |
**********************************************************************/
|
79 |
|
80 |
int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)
|
81 |
{ |
82 |
int i;
|
83 |
|
84 |
for (i = 0; i < NB_DEVICES; i++) { |
85 |
if (s->devices[i] == NULL) { |
86 |
s->devices[i] = device; |
87 |
return 0; |
88 |
} |
89 |
} |
90 |
return -1; |
91 |
} |
92 |
|
93 |
static uint16_t portdir(uint32_t v)
|
94 |
{ |
95 |
#define EVENPORTMASK(n) ((v & (1<<((n)<<1))) >> (n)) |
96 |
return
|
97 |
EVENPORTMASK(15) | EVENPORTMASK(14) | EVENPORTMASK(13) | |
98 |
EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) | |
99 |
EVENPORTMASK(9) | EVENPORTMASK(8) | EVENPORTMASK(7) | |
100 |
EVENPORTMASK(6) | EVENPORTMASK(5) | EVENPORTMASK(4) | |
101 |
EVENPORTMASK(3) | EVENPORTMASK(2) | EVENPORTMASK(1) | |
102 |
EVENPORTMASK(0);
|
103 |
} |
104 |
|
105 |
static uint16_t portpullup(uint32_t v)
|
106 |
{ |
107 |
#define ODDPORTMASK(n) ((v & (1<<(((n)<<1)+1))) >> (n)) |
108 |
return
|
109 |
ODDPORTMASK(15) | ODDPORTMASK(14) | ODDPORTMASK(13) | |
110 |
ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) | |
111 |
ODDPORTMASK(9) | ODDPORTMASK(8) | ODDPORTMASK(7) | ODDPORTMASK(6) | |
112 |
ODDPORTMASK(5) | ODDPORTMASK(4) | ODDPORTMASK(3) | ODDPORTMASK(2) | |
113 |
ODDPORTMASK(1) | ODDPORTMASK(0); |
114 |
} |
115 |
|
116 |
static uint16_t porta_lines(SH7750State * s)
|
117 |
{ |
118 |
return (s->portdira & s->pdtra) | /* CPU */ |
119 |
(s->periph_portdira & s->periph_pdtra) | /* Peripherals */
|
120 |
(~(s->portdira | s->periph_portdira) & s->portpullupa); /* Pullups */
|
121 |
} |
122 |
|
123 |
static uint16_t portb_lines(SH7750State * s)
|
124 |
{ |
125 |
return (s->portdirb & s->pdtrb) | /* CPU */ |
126 |
(s->periph_portdirb & s->periph_pdtrb) | /* Peripherals */
|
127 |
(~(s->portdirb | s->periph_portdirb) & s->portpullupb); /* Pullups */
|
128 |
} |
129 |
|
130 |
static void gen_port_interrupts(SH7750State * s) |
131 |
{ |
132 |
/* XXXXX interrupts not generated */
|
133 |
} |
134 |
|
135 |
static void porta_changed(SH7750State * s, uint16_t prev) |
136 |
{ |
137 |
uint16_t currenta, changes; |
138 |
int i, r = 0; |
139 |
|
140 |
#if 0
|
141 |
fprintf(stderr, "porta changed from 0x%04x to 0x%04x\n",
|
142 |
prev, porta_lines(s));
|
143 |
fprintf(stderr, "pdtra=0x%04x, pctra=0x%08x\n", s->pdtra, s->pctra);
|
144 |
#endif
|
145 |
currenta = porta_lines(s); |
146 |
if (currenta == prev)
|
147 |
return;
|
148 |
changes = currenta ^ prev; |
149 |
|
150 |
for (i = 0; i < NB_DEVICES; i++) { |
151 |
if (s->devices[i] && (s->devices[i]->portamask_trigger & changes)) {
|
152 |
r |= s->devices[i]->port_change_cb(currenta, portb_lines(s), |
153 |
&s->periph_pdtra, |
154 |
&s->periph_portdira, |
155 |
&s->periph_pdtrb, |
156 |
&s->periph_portdirb); |
157 |
} |
158 |
} |
159 |
|
160 |
if (r)
|
161 |
gen_port_interrupts(s); |
162 |
} |
163 |
|
164 |
static void portb_changed(SH7750State * s, uint16_t prev) |
165 |
{ |
166 |
uint16_t currentb, changes; |
167 |
int i, r = 0; |
168 |
|
169 |
currentb = portb_lines(s); |
170 |
if (currentb == prev)
|
171 |
return;
|
172 |
changes = currentb ^ prev; |
173 |
|
174 |
for (i = 0; i < NB_DEVICES; i++) { |
175 |
if (s->devices[i] && (s->devices[i]->portbmask_trigger & changes)) {
|
176 |
r |= s->devices[i]->port_change_cb(portb_lines(s), currentb, |
177 |
&s->periph_pdtra, |
178 |
&s->periph_portdira, |
179 |
&s->periph_pdtrb, |
180 |
&s->periph_portdirb); |
181 |
} |
182 |
} |
183 |
|
184 |
if (r)
|
185 |
gen_port_interrupts(s); |
186 |
} |
187 |
|
188 |
/**********************************************************************
|
189 |
Memory
|
190 |
**********************************************************************/
|
191 |
|
192 |
static void error_access(const char *kind, target_phys_addr_t addr) |
193 |
{ |
194 |
fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") not supported\n", |
195 |
kind, regname(addr), addr); |
196 |
} |
197 |
|
198 |
static void ignore_access(const char *kind, target_phys_addr_t addr) |
199 |
{ |
200 |
fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") ignored\n", |
201 |
kind, regname(addr), addr); |
202 |
} |
203 |
|
204 |
static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr) |
205 |
{ |
206 |
switch (addr) {
|
207 |
default:
|
208 |
error_access("byte read", addr);
|
209 |
assert(0);
|
210 |
} |
211 |
} |
212 |
|
213 |
static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr) |
214 |
{ |
215 |
SH7750State *s = opaque; |
216 |
|
217 |
switch (addr) {
|
218 |
case SH7750_BCR2_A7:
|
219 |
return s->bcr2;
|
220 |
case SH7750_BCR3_A7:
|
221 |
if(!has_bcr3_and_bcr4(s))
|
222 |
error_access("word read", addr);
|
223 |
return s->bcr3;
|
224 |
case SH7750_FRQCR_A7:
|
225 |
return 0; |
226 |
case SH7750_PCR_A7:
|
227 |
return s->pcr;
|
228 |
case SH7750_RFCR_A7:
|
229 |
fprintf(stderr, |
230 |
"Read access to refresh count register, incrementing\n");
|
231 |
return s->rfcr++;
|
232 |
case SH7750_PDTRA_A7:
|
233 |
return porta_lines(s);
|
234 |
case SH7750_PDTRB_A7:
|
235 |
return portb_lines(s);
|
236 |
case SH7750_RTCOR_A7:
|
237 |
case SH7750_RTCNT_A7:
|
238 |
case SH7750_RTCSR_A7:
|
239 |
ignore_access("word read", addr);
|
240 |
return 0; |
241 |
default:
|
242 |
error_access("word read", addr);
|
243 |
assert(0);
|
244 |
} |
245 |
} |
246 |
|
247 |
static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr) |
248 |
{ |
249 |
SH7750State *s = opaque; |
250 |
|
251 |
switch (addr) {
|
252 |
case SH7750_BCR1_A7:
|
253 |
return s->bcr1;
|
254 |
case SH7750_BCR4_A7:
|
255 |
if(!has_bcr3_and_bcr4(s))
|
256 |
error_access("long read", addr);
|
257 |
return s->bcr4;
|
258 |
case SH7750_WCR1_A7:
|
259 |
case SH7750_WCR2_A7:
|
260 |
case SH7750_WCR3_A7:
|
261 |
case SH7750_MCR_A7:
|
262 |
ignore_access("long read", addr);
|
263 |
return 0; |
264 |
case SH7750_MMUCR_A7:
|
265 |
return s->cpu->mmucr;
|
266 |
case SH7750_PTEH_A7:
|
267 |
return s->cpu->pteh;
|
268 |
case SH7750_PTEL_A7:
|
269 |
return s->cpu->ptel;
|
270 |
case SH7750_TTB_A7:
|
271 |
return s->cpu->ttb;
|
272 |
case SH7750_TEA_A7:
|
273 |
return s->cpu->tea;
|
274 |
case SH7750_TRA_A7:
|
275 |
return s->cpu->tra;
|
276 |
case SH7750_EXPEVT_A7:
|
277 |
return s->cpu->expevt;
|
278 |
case SH7750_INTEVT_A7:
|
279 |
return s->cpu->intevt;
|
280 |
case SH7750_CCR_A7:
|
281 |
return s->ccr;
|
282 |
case 0x1f000030: /* Processor version */ |
283 |
return s->cpu->pvr;
|
284 |
case 0x1f000040: /* Cache version */ |
285 |
return s->cpu->cvr;
|
286 |
case 0x1f000044: /* Processor revision */ |
287 |
return s->cpu->prr;
|
288 |
default:
|
289 |
error_access("long read", addr);
|
290 |
assert(0);
|
291 |
} |
292 |
} |
293 |
|
294 |
#define is_in_sdrmx(a, x) (a >= SH7750_SDMR ## x ## _A7 \ |
295 |
&& a <= (SH7750_SDMR ## x ## _A7 + SH7750_SDMR ## x ## _REGNB)) |
296 |
static void sh7750_mem_writeb(void *opaque, target_phys_addr_t addr, |
297 |
uint32_t mem_value) |
298 |
{ |
299 |
|
300 |
if (is_in_sdrmx(addr, 2) || is_in_sdrmx(addr, 3)) { |
301 |
ignore_access("byte write", addr);
|
302 |
return;
|
303 |
} |
304 |
|
305 |
error_access("byte write", addr);
|
306 |
assert(0);
|
307 |
} |
308 |
|
309 |
static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr, |
310 |
uint32_t mem_value) |
311 |
{ |
312 |
SH7750State *s = opaque; |
313 |
uint16_t temp; |
314 |
|
315 |
switch (addr) {
|
316 |
/* SDRAM controller */
|
317 |
case SH7750_BCR2_A7:
|
318 |
s->bcr2 = mem_value; |
319 |
return;
|
320 |
case SH7750_BCR3_A7:
|
321 |
if(!has_bcr3_and_bcr4(s))
|
322 |
error_access("word write", addr);
|
323 |
s->bcr3 = mem_value; |
324 |
return;
|
325 |
case SH7750_PCR_A7:
|
326 |
s->pcr = mem_value; |
327 |
return;
|
328 |
case SH7750_RTCNT_A7:
|
329 |
case SH7750_RTCOR_A7:
|
330 |
case SH7750_RTCSR_A7:
|
331 |
ignore_access("word write", addr);
|
332 |
return;
|
333 |
/* IO ports */
|
334 |
case SH7750_PDTRA_A7:
|
335 |
temp = porta_lines(s); |
336 |
s->pdtra = mem_value; |
337 |
porta_changed(s, temp); |
338 |
return;
|
339 |
case SH7750_PDTRB_A7:
|
340 |
temp = portb_lines(s); |
341 |
s->pdtrb = mem_value; |
342 |
portb_changed(s, temp); |
343 |
return;
|
344 |
case SH7750_RFCR_A7:
|
345 |
fprintf(stderr, "Write access to refresh count register\n");
|
346 |
s->rfcr = mem_value; |
347 |
return;
|
348 |
case SH7750_GPIOIC_A7:
|
349 |
s->gpioic = mem_value; |
350 |
if (mem_value != 0) { |
351 |
fprintf(stderr, "I/O interrupts not implemented\n");
|
352 |
assert(0);
|
353 |
} |
354 |
return;
|
355 |
default:
|
356 |
error_access("word write", addr);
|
357 |
assert(0);
|
358 |
} |
359 |
} |
360 |
|
361 |
static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr, |
362 |
uint32_t mem_value) |
363 |
{ |
364 |
SH7750State *s = opaque; |
365 |
uint16_t temp; |
366 |
|
367 |
switch (addr) {
|
368 |
/* SDRAM controller */
|
369 |
case SH7750_BCR1_A7:
|
370 |
s->bcr1 = mem_value; |
371 |
return;
|
372 |
case SH7750_BCR4_A7:
|
373 |
if(!has_bcr3_and_bcr4(s))
|
374 |
error_access("long write", addr);
|
375 |
s->bcr4 = mem_value; |
376 |
return;
|
377 |
case SH7750_WCR1_A7:
|
378 |
case SH7750_WCR2_A7:
|
379 |
case SH7750_WCR3_A7:
|
380 |
case SH7750_MCR_A7:
|
381 |
ignore_access("long write", addr);
|
382 |
return;
|
383 |
/* IO ports */
|
384 |
case SH7750_PCTRA_A7:
|
385 |
temp = porta_lines(s); |
386 |
s->pctra = mem_value; |
387 |
s->portdira = portdir(mem_value); |
388 |
s->portpullupa = portpullup(mem_value); |
389 |
porta_changed(s, temp); |
390 |
return;
|
391 |
case SH7750_PCTRB_A7:
|
392 |
temp = portb_lines(s); |
393 |
s->pctrb = mem_value; |
394 |
s->portdirb = portdir(mem_value); |
395 |
s->portpullupb = portpullup(mem_value); |
396 |
portb_changed(s, temp); |
397 |
return;
|
398 |
case SH7750_MMUCR_A7:
|
399 |
s->cpu->mmucr = mem_value; |
400 |
return;
|
401 |
case SH7750_PTEH_A7:
|
402 |
/* If asid changes, clear all registered tlb entries. */
|
403 |
if ((s->cpu->pteh & 0xff) != (mem_value & 0xff)) |
404 |
tlb_flush(s->cpu, 1);
|
405 |
s->cpu->pteh = mem_value; |
406 |
return;
|
407 |
case SH7750_PTEL_A7:
|
408 |
s->cpu->ptel = mem_value; |
409 |
return;
|
410 |
case SH7750_PTEA_A7:
|
411 |
s->cpu->ptea = mem_value & 0x0000000f;
|
412 |
return;
|
413 |
case SH7750_TTB_A7:
|
414 |
s->cpu->ttb = mem_value; |
415 |
return;
|
416 |
case SH7750_TEA_A7:
|
417 |
s->cpu->tea = mem_value; |
418 |
return;
|
419 |
case SH7750_TRA_A7:
|
420 |
s->cpu->tra = mem_value & 0x000007ff;
|
421 |
return;
|
422 |
case SH7750_EXPEVT_A7:
|
423 |
s->cpu->expevt = mem_value & 0x000007ff;
|
424 |
return;
|
425 |
case SH7750_INTEVT_A7:
|
426 |
s->cpu->intevt = mem_value & 0x000007ff;
|
427 |
return;
|
428 |
case SH7750_CCR_A7:
|
429 |
s->ccr = mem_value; |
430 |
return;
|
431 |
default:
|
432 |
error_access("long write", addr);
|
433 |
assert(0);
|
434 |
} |
435 |
} |
436 |
|
437 |
static CPUReadMemoryFunc * const sh7750_mem_read[] = { |
438 |
sh7750_mem_readb, |
439 |
sh7750_mem_readw, |
440 |
sh7750_mem_readl |
441 |
}; |
442 |
|
443 |
static CPUWriteMemoryFunc * const sh7750_mem_write[] = { |
444 |
sh7750_mem_writeb, |
445 |
sh7750_mem_writew, |
446 |
sh7750_mem_writel |
447 |
}; |
448 |
|
449 |
/* sh775x interrupt controller tables for sh_intc.c
|
450 |
* stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
|
451 |
*/
|
452 |
|
453 |
enum {
|
454 |
UNUSED = 0,
|
455 |
|
456 |
/* interrupt sources */
|
457 |
IRL_0, IRL_1, IRL_2, IRL_3, IRL_4, IRL_5, IRL_6, IRL_7, |
458 |
IRL_8, IRL_9, IRL_A, IRL_B, IRL_C, IRL_D, IRL_E, |
459 |
IRL0, IRL1, IRL2, IRL3, |
460 |
HUDI, GPIOI, |
461 |
DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3, |
462 |
DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7, |
463 |
DMAC_DMAE, |
464 |
PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON, |
465 |
PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3, |
466 |
TMU3, TMU4, TMU0, TMU1, TMU2_TUNI, TMU2_TICPI, |
467 |
RTC_ATI, RTC_PRI, RTC_CUI, |
468 |
SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI, |
469 |
SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI, |
470 |
WDT, |
471 |
REF_RCMI, REF_ROVI, |
472 |
|
473 |
/* interrupt groups */
|
474 |
DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF, |
475 |
/* irl bundle */
|
476 |
IRL, |
477 |
|
478 |
NR_SOURCES, |
479 |
}; |
480 |
|
481 |
static struct intc_vect vectors[] = { |
482 |
INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620), |
483 |
INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), |
484 |
INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460), |
485 |
INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), |
486 |
INTC_VECT(RTC_CUI, 0x4c0),
|
487 |
INTC_VECT(SCI1_ERI, 0x4e0), INTC_VECT(SCI1_RXI, 0x500), |
488 |
INTC_VECT(SCI1_TXI, 0x520), INTC_VECT(SCI1_TEI, 0x540), |
489 |
INTC_VECT(SCIF_ERI, 0x700), INTC_VECT(SCIF_RXI, 0x720), |
490 |
INTC_VECT(SCIF_BRI, 0x740), INTC_VECT(SCIF_TXI, 0x760), |
491 |
INTC_VECT(WDT, 0x560),
|
492 |
INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0), |
493 |
}; |
494 |
|
495 |
static struct intc_group groups[] = { |
496 |
INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI), |
497 |
INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI), |
498 |
INTC_GROUP(SCI1, SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI), |
499 |
INTC_GROUP(SCIF, SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI), |
500 |
INTC_GROUP(REF, REF_RCMI, REF_ROVI), |
501 |
}; |
502 |
|
503 |
static struct intc_prio_reg prio_registers[] = { |
504 |
{ 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } }, |
505 |
{ 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } }, |
506 |
{ 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } }, |
507 |
{ 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } }, |
508 |
{ 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0, |
509 |
TMU4, TMU3, |
510 |
PCIC1, PCIC0_PCISERR } }, |
511 |
}; |
512 |
|
513 |
/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
|
514 |
|
515 |
static struct intc_vect vectors_dma4[] = { |
516 |
INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660), |
517 |
INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0), |
518 |
INTC_VECT(DMAC_DMAE, 0x6c0),
|
519 |
}; |
520 |
|
521 |
static struct intc_group groups_dma4[] = { |
522 |
INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, |
523 |
DMAC_DMTE3, DMAC_DMAE), |
524 |
}; |
525 |
|
526 |
/* SH7750R and SH7751R both have 8-channel DMA controllers */
|
527 |
|
528 |
static struct intc_vect vectors_dma8[] = { |
529 |
INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660), |
530 |
INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0), |
531 |
INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0), |
532 |
INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0), |
533 |
INTC_VECT(DMAC_DMAE, 0x6c0),
|
534 |
}; |
535 |
|
536 |
static struct intc_group groups_dma8[] = { |
537 |
INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, |
538 |
DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5, |
539 |
DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE), |
540 |
}; |
541 |
|
542 |
/* SH7750R, SH7751 and SH7751R all have two extra timer channels */
|
543 |
|
544 |
static struct intc_vect vectors_tmu34[] = { |
545 |
INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80), |
546 |
}; |
547 |
|
548 |
static struct intc_mask_reg mask_registers[] = { |
549 |
{ 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */ |
550 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
551 |
0, 0, 0, 0, 0, 0, TMU4, TMU3, |
552 |
PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON, |
553 |
PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, |
554 |
PCIC1_PCIDMA3, PCIC0_PCISERR } }, |
555 |
}; |
556 |
|
557 |
/* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
|
558 |
|
559 |
static struct intc_vect vectors_irlm[] = { |
560 |
INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0), |
561 |
INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360), |
562 |
}; |
563 |
|
564 |
/* SH7751 and SH7751R both have PCI */
|
565 |
|
566 |
static struct intc_vect vectors_pci[] = { |
567 |
INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0), |
568 |
INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0), |
569 |
INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60), |
570 |
INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20), |
571 |
}; |
572 |
|
573 |
static struct intc_group groups_pci[] = { |
574 |
INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON, |
575 |
PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3), |
576 |
}; |
577 |
|
578 |
static struct intc_vect vectors_irl[] = { |
579 |
INTC_VECT(IRL_0, 0x200),
|
580 |
INTC_VECT(IRL_1, 0x220),
|
581 |
INTC_VECT(IRL_2, 0x240),
|
582 |
INTC_VECT(IRL_3, 0x260),
|
583 |
INTC_VECT(IRL_4, 0x280),
|
584 |
INTC_VECT(IRL_5, 0x2a0),
|
585 |
INTC_VECT(IRL_6, 0x2c0),
|
586 |
INTC_VECT(IRL_7, 0x2e0),
|
587 |
INTC_VECT(IRL_8, 0x300),
|
588 |
INTC_VECT(IRL_9, 0x320),
|
589 |
INTC_VECT(IRL_A, 0x340),
|
590 |
INTC_VECT(IRL_B, 0x360),
|
591 |
INTC_VECT(IRL_C, 0x380),
|
592 |
INTC_VECT(IRL_D, 0x3a0),
|
593 |
INTC_VECT(IRL_E, 0x3c0),
|
594 |
}; |
595 |
|
596 |
static struct intc_group groups_irl[] = { |
597 |
INTC_GROUP(IRL, IRL_0, IRL_1, IRL_2, IRL_3, IRL_4, IRL_5, IRL_6, |
598 |
IRL_7, IRL_8, IRL_9, IRL_A, IRL_B, IRL_C, IRL_D, IRL_E), |
599 |
}; |
600 |
|
601 |
/**********************************************************************
|
602 |
Memory mapped cache and TLB
|
603 |
**********************************************************************/
|
604 |
|
605 |
#define MM_REGION_MASK 0x07000000 |
606 |
#define MM_ICACHE_ADDR (0) |
607 |
#define MM_ICACHE_DATA (1) |
608 |
#define MM_ITLB_ADDR (2) |
609 |
#define MM_ITLB_DATA (3) |
610 |
#define MM_OCACHE_ADDR (4) |
611 |
#define MM_OCACHE_DATA (5) |
612 |
#define MM_UTLB_ADDR (6) |
613 |
#define MM_UTLB_DATA (7) |
614 |
#define MM_REGION_TYPE(addr) ((addr & MM_REGION_MASK) >> 24) |
615 |
|
616 |
static uint32_t invalid_read(void *opaque, target_phys_addr_t addr) |
617 |
{ |
618 |
assert(0);
|
619 |
|
620 |
return 0; |
621 |
} |
622 |
|
623 |
static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr) |
624 |
{ |
625 |
uint32_t ret = 0;
|
626 |
|
627 |
switch (MM_REGION_TYPE(addr)) {
|
628 |
case MM_ICACHE_ADDR:
|
629 |
case MM_ICACHE_DATA:
|
630 |
/* do nothing */
|
631 |
break;
|
632 |
case MM_ITLB_ADDR:
|
633 |
case MM_ITLB_DATA:
|
634 |
/* XXXXX */
|
635 |
assert(0);
|
636 |
break;
|
637 |
case MM_OCACHE_ADDR:
|
638 |
case MM_OCACHE_DATA:
|
639 |
/* do nothing */
|
640 |
break;
|
641 |
case MM_UTLB_ADDR:
|
642 |
case MM_UTLB_DATA:
|
643 |
/* XXXXX */
|
644 |
assert(0);
|
645 |
break;
|
646 |
default:
|
647 |
assert(0);
|
648 |
} |
649 |
|
650 |
return ret;
|
651 |
} |
652 |
|
653 |
static void invalid_write(void *opaque, target_phys_addr_t addr, |
654 |
uint32_t mem_value) |
655 |
{ |
656 |
assert(0);
|
657 |
} |
658 |
|
659 |
static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr, |
660 |
uint32_t mem_value) |
661 |
{ |
662 |
SH7750State *s = opaque; |
663 |
|
664 |
switch (MM_REGION_TYPE(addr)) {
|
665 |
case MM_ICACHE_ADDR:
|
666 |
case MM_ICACHE_DATA:
|
667 |
/* do nothing */
|
668 |
break;
|
669 |
case MM_ITLB_ADDR:
|
670 |
case MM_ITLB_DATA:
|
671 |
/* XXXXX */
|
672 |
assert(0);
|
673 |
break;
|
674 |
case MM_OCACHE_ADDR:
|
675 |
case MM_OCACHE_DATA:
|
676 |
/* do nothing */
|
677 |
break;
|
678 |
case MM_UTLB_ADDR:
|
679 |
cpu_sh4_write_mmaped_utlb_addr(s->cpu, addr, mem_value); |
680 |
break;
|
681 |
case MM_UTLB_DATA:
|
682 |
/* XXXXX */
|
683 |
assert(0);
|
684 |
break;
|
685 |
default:
|
686 |
assert(0);
|
687 |
break;
|
688 |
} |
689 |
} |
690 |
|
691 |
static CPUReadMemoryFunc * const sh7750_mmct_read[] = { |
692 |
invalid_read, |
693 |
invalid_read, |
694 |
sh7750_mmct_readl |
695 |
}; |
696 |
|
697 |
static CPUWriteMemoryFunc * const sh7750_mmct_write[] = { |
698 |
invalid_write, |
699 |
invalid_write, |
700 |
sh7750_mmct_writel |
701 |
}; |
702 |
|
703 |
SH7750State *sh7750_init(CPUSH4State * cpu) |
704 |
{ |
705 |
SH7750State *s; |
706 |
int sh7750_io_memory;
|
707 |
int sh7750_mm_cache_and_tlb; /* memory mapped cache and tlb */ |
708 |
|
709 |
s = qemu_mallocz(sizeof(SH7750State));
|
710 |
s->cpu = cpu; |
711 |
s->periph_freq = 60000000; /* 60MHz */ |
712 |
sh7750_io_memory = cpu_register_io_memory(sh7750_mem_read, |
713 |
sh7750_mem_write, s); |
714 |
cpu_register_physical_memory_offset(0x1f000000, 0x1000, |
715 |
sh7750_io_memory, 0x1f000000);
|
716 |
cpu_register_physical_memory_offset(0xff000000, 0x1000, |
717 |
sh7750_io_memory, 0x1f000000);
|
718 |
cpu_register_physical_memory_offset(0x1f800000, 0x1000, |
719 |
sh7750_io_memory, 0x1f800000);
|
720 |
cpu_register_physical_memory_offset(0xff800000, 0x1000, |
721 |
sh7750_io_memory, 0x1f800000);
|
722 |
cpu_register_physical_memory_offset(0x1fc00000, 0x1000, |
723 |
sh7750_io_memory, 0x1fc00000);
|
724 |
cpu_register_physical_memory_offset(0xffc00000, 0x1000, |
725 |
sh7750_io_memory, 0x1fc00000);
|
726 |
|
727 |
sh7750_mm_cache_and_tlb = cpu_register_io_memory(sh7750_mmct_read, |
728 |
sh7750_mmct_write, s); |
729 |
cpu_register_physical_memory(0xf0000000, 0x08000000, |
730 |
sh7750_mm_cache_and_tlb); |
731 |
|
732 |
sh_intc_init(&s->intc, NR_SOURCES, |
733 |
_INTC_ARRAY(mask_registers), |
734 |
_INTC_ARRAY(prio_registers)); |
735 |
|
736 |
sh_intc_register_sources(&s->intc, |
737 |
_INTC_ARRAY(vectors), |
738 |
_INTC_ARRAY(groups)); |
739 |
|
740 |
cpu->intc_handle = &s->intc; |
741 |
|
742 |
sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0], |
743 |
s->intc.irqs[SCI1_ERI], |
744 |
s->intc.irqs[SCI1_RXI], |
745 |
s->intc.irqs[SCI1_TXI], |
746 |
s->intc.irqs[SCI1_TEI], |
747 |
NULL);
|
748 |
sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF,
|
749 |
s->periph_freq, serial_hds[1],
|
750 |
s->intc.irqs[SCIF_ERI], |
751 |
s->intc.irqs[SCIF_RXI], |
752 |
s->intc.irqs[SCIF_TXI], |
753 |
NULL,
|
754 |
s->intc.irqs[SCIF_BRI]); |
755 |
|
756 |
tmu012_init(0x1fd80000,
|
757 |
TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK, |
758 |
s->periph_freq, |
759 |
s->intc.irqs[TMU0], |
760 |
s->intc.irqs[TMU1], |
761 |
s->intc.irqs[TMU2_TUNI], |
762 |
s->intc.irqs[TMU2_TICPI]); |
763 |
|
764 |
if (cpu->id & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
|
765 |
sh_intc_register_sources(&s->intc, |
766 |
_INTC_ARRAY(vectors_dma4), |
767 |
_INTC_ARRAY(groups_dma4)); |
768 |
} |
769 |
|
770 |
if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
|
771 |
sh_intc_register_sources(&s->intc, |
772 |
_INTC_ARRAY(vectors_dma8), |
773 |
_INTC_ARRAY(groups_dma8)); |
774 |
} |
775 |
|
776 |
if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751 | SH_CPU_SH7751R)) {
|
777 |
sh_intc_register_sources(&s->intc, |
778 |
_INTC_ARRAY(vectors_tmu34), |
779 |
NULL, 0); |
780 |
tmu012_init(0x1e100000, 0, s->periph_freq, |
781 |
s->intc.irqs[TMU3], |
782 |
s->intc.irqs[TMU4], |
783 |
NULL, NULL); |
784 |
} |
785 |
|
786 |
if (cpu->id & (SH_CPU_SH7751_ALL)) {
|
787 |
sh_intc_register_sources(&s->intc, |
788 |
_INTC_ARRAY(vectors_pci), |
789 |
_INTC_ARRAY(groups_pci)); |
790 |
} |
791 |
|
792 |
if (cpu->id & (SH_CPU_SH7750S | SH_CPU_SH7750R | SH_CPU_SH7751_ALL)) {
|
793 |
sh_intc_register_sources(&s->intc, |
794 |
_INTC_ARRAY(vectors_irlm), |
795 |
NULL, 0); |
796 |
} |
797 |
|
798 |
sh_intc_register_sources(&s->intc, |
799 |
_INTC_ARRAY(vectors_irl), |
800 |
_INTC_ARRAY(groups_irl)); |
801 |
return s;
|
802 |
} |
803 |
|
804 |
qemu_irq sh7750_irl(SH7750State *s) |
805 |
{ |
806 |
sh_intc_toggle_source(sh_intc_source(&s->intc, IRL), 1, 0); /* enable */ |
807 |
return qemu_allocate_irqs(sh_intc_set_irl, sh_intc_source(&s->intc, IRL),
|
808 |
1)[0]; |
809 |
} |