SMBus qdev conversion
[qemu-kvm/fedora.git] / hw / sh7750.c
blobf079781b2442a2d06f6233c3a35c62adb358f75d
1 /*
2 * SH7750 device
4 * Copyright (c) 2007 Magnus Damm
5 * Copyright (c) 2005 Samuel Tardieu
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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.
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"
35 #define NB_DEVICES 4
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 */
66 /* Cache */
67 uint32_t ccr;
69 struct intc_desc intc;
70 } SH7750State;
72 static int inline has_bcr3_and_bcr4(SH7750State * s)
74 return (s->cpu->features & SH_FEATURE_BCR3_AND_BCR4);
76 /**********************************************************************
77 I/O ports
78 **********************************************************************/
80 int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)
82 int i;
84 for (i = 0; i < NB_DEVICES; i++) {
85 if (s->devices[i] == NULL) {
86 s->devices[i] = device;
87 return 0;
90 return -1;
93 static uint16_t portdir(uint32_t v)
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);
105 static uint16_t portpullup(uint32_t v)
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);
116 static uint16_t porta_lines(SH7750State * s)
118 return (s->portdira & s->pdtra) | /* CPU */
119 (s->periph_portdira & s->periph_pdtra) | /* Peripherals */
120 (~(s->portdira | s->periph_portdira) & s->portpullupa); /* Pullups */
123 static uint16_t portb_lines(SH7750State * s)
125 return (s->portdirb & s->pdtrb) | /* CPU */
126 (s->periph_portdirb & s->periph_pdtrb) | /* Peripherals */
127 (~(s->portdirb | s->periph_portdirb) & s->portpullupb); /* Pullups */
130 static void gen_port_interrupts(SH7750State * s)
132 /* XXXXX interrupts not generated */
135 static void porta_changed(SH7750State * s, uint16_t prev)
137 uint16_t currenta, changes;
138 int i, r = 0;
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;
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);
160 if (r)
161 gen_port_interrupts(s);
164 static void portb_changed(SH7750State * s, uint16_t prev)
166 uint16_t currentb, changes;
167 int i, r = 0;
169 currentb = portb_lines(s);
170 if (currentb == prev)
171 return;
172 changes = currentb ^ prev;
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);
184 if (r)
185 gen_port_interrupts(s);
188 /**********************************************************************
189 Memory
190 **********************************************************************/
192 static void error_access(const char *kind, target_phys_addr_t addr)
194 fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") not supported\n",
195 kind, regname(addr), addr);
198 static void ignore_access(const char *kind, target_phys_addr_t addr)
200 fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") ignored\n",
201 kind, regname(addr), addr);
204 static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr)
206 switch (addr) {
207 default:
208 error_access("byte read", addr);
209 assert(0);
213 static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr)
215 SH7750State *s = opaque;
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);
247 static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr)
249 SH7750State *s = opaque;
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);
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)
300 if (is_in_sdrmx(addr, 2) || is_in_sdrmx(addr, 3)) {
301 ignore_access("byte write", addr);
302 return;
305 error_access("byte write", addr);
306 assert(0);
309 static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
310 uint32_t mem_value)
312 SH7750State *s = opaque;
313 uint16_t temp;
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);
354 return;
355 default:
356 error_access("word write", addr);
357 assert(0);
361 static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,
362 uint32_t mem_value)
364 SH7750State *s = opaque;
365 uint16_t temp;
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);
437 static CPUReadMemoryFunc *sh7750_mem_read[] = {
438 sh7750_mem_readb,
439 sh7750_mem_readw,
440 sh7750_mem_readl
443 static CPUWriteMemoryFunc *sh7750_mem_write[] = {
444 sh7750_mem_writeb,
445 sh7750_mem_writew,
446 sh7750_mem_writel
449 /* sh775x interrupt controller tables for sh_intc.c
450 * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
453 enum {
454 UNUSED = 0,
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,
473 /* interrupt groups */
474 DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF,
475 /* irl bundle */
476 IRL,
478 NR_SOURCES,
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),
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),
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 } },
513 /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
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),
521 static struct intc_group groups_dma4[] = {
522 INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
523 DMAC_DMTE3, DMAC_DMAE),
526 /* SH7750R and SH7751R both have 8-channel DMA controllers */
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),
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),
542 /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
544 static struct intc_vect vectors_tmu34[] = {
545 INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
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 } },
557 /* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
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),
564 /* SH7751 and SH7751R both have PCI */
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),
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),
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),
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),
601 /**********************************************************************
602 Memory mapped cache and TLB
603 **********************************************************************/
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)
616 static uint32_t invalid_read(void *opaque, target_phys_addr_t addr)
618 assert(0);
620 return 0;
623 static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr)
625 uint32_t ret = 0;
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);
650 return ret;
653 static void invalid_write(void *opaque, target_phys_addr_t addr,
654 uint32_t mem_value)
656 assert(0);
659 static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr,
660 uint32_t mem_value)
662 SH7750State *s = opaque;
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;
691 static CPUReadMemoryFunc *sh7750_mmct_read[] = {
692 invalid_read,
693 invalid_read,
694 sh7750_mmct_readl
697 static CPUWriteMemoryFunc *sh7750_mmct_write[] = {
698 invalid_write,
699 invalid_write,
700 sh7750_mmct_writel
703 SH7750State *sh7750_init(CPUSH4State * cpu)
705 SH7750State *s;
706 int sh7750_io_memory;
707 int sh7750_mm_cache_and_tlb; /* memory mapped cache and tlb */
709 s = qemu_mallocz(sizeof(SH7750State));
710 s->cpu = cpu;
711 s->periph_freq = 60000000; /* 60MHz */
712 sh7750_io_memory = cpu_register_io_memory(0,
713 sh7750_mem_read,
714 sh7750_mem_write, s);
715 cpu_register_physical_memory_offset(0x1f000000, 0x1000,
716 sh7750_io_memory, 0x1f000000);
717 cpu_register_physical_memory_offset(0xff000000, 0x1000,
718 sh7750_io_memory, 0x1f000000);
719 cpu_register_physical_memory_offset(0x1f800000, 0x1000,
720 sh7750_io_memory, 0x1f800000);
721 cpu_register_physical_memory_offset(0xff800000, 0x1000,
722 sh7750_io_memory, 0x1f800000);
723 cpu_register_physical_memory_offset(0x1fc00000, 0x1000,
724 sh7750_io_memory, 0x1fc00000);
725 cpu_register_physical_memory_offset(0xffc00000, 0x1000,
726 sh7750_io_memory, 0x1fc00000);
728 sh7750_mm_cache_and_tlb = cpu_register_io_memory(0,
729 sh7750_mmct_read,
730 sh7750_mmct_write, s);
731 cpu_register_physical_memory(0xf0000000, 0x08000000,
732 sh7750_mm_cache_and_tlb);
734 sh_intc_init(&s->intc, NR_SOURCES,
735 _INTC_ARRAY(mask_registers),
736 _INTC_ARRAY(prio_registers));
738 sh_intc_register_sources(&s->intc,
739 _INTC_ARRAY(vectors),
740 _INTC_ARRAY(groups));
742 cpu->intc_handle = &s->intc;
744 sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0],
745 s->intc.irqs[SCI1_ERI],
746 s->intc.irqs[SCI1_RXI],
747 s->intc.irqs[SCI1_TXI],
748 s->intc.irqs[SCI1_TEI],
749 NULL);
750 sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF,
751 s->periph_freq, serial_hds[1],
752 s->intc.irqs[SCIF_ERI],
753 s->intc.irqs[SCIF_RXI],
754 s->intc.irqs[SCIF_TXI],
755 NULL,
756 s->intc.irqs[SCIF_BRI]);
758 tmu012_init(0x1fd80000,
759 TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK,
760 s->periph_freq,
761 s->intc.irqs[TMU0],
762 s->intc.irqs[TMU1],
763 s->intc.irqs[TMU2_TUNI],
764 s->intc.irqs[TMU2_TICPI]);
766 if (cpu->id & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
767 sh_intc_register_sources(&s->intc,
768 _INTC_ARRAY(vectors_dma4),
769 _INTC_ARRAY(groups_dma4));
772 if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
773 sh_intc_register_sources(&s->intc,
774 _INTC_ARRAY(vectors_dma8),
775 _INTC_ARRAY(groups_dma8));
778 if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751 | SH_CPU_SH7751R)) {
779 sh_intc_register_sources(&s->intc,
780 _INTC_ARRAY(vectors_tmu34),
781 NULL, 0);
782 tmu012_init(0x1e100000, 0, s->periph_freq,
783 s->intc.irqs[TMU3],
784 s->intc.irqs[TMU4],
785 NULL, NULL);
788 if (cpu->id & (SH_CPU_SH7751_ALL)) {
789 sh_intc_register_sources(&s->intc,
790 _INTC_ARRAY(vectors_pci),
791 _INTC_ARRAY(groups_pci));
794 if (cpu->id & (SH_CPU_SH7750S | SH_CPU_SH7750R | SH_CPU_SH7751_ALL)) {
795 sh_intc_register_sources(&s->intc,
796 _INTC_ARRAY(vectors_irlm),
797 NULL, 0);
800 sh_intc_register_sources(&s->intc,
801 _INTC_ARRAY(vectors_irl),
802 _INTC_ARRAY(groups_irl));
803 return s;
806 qemu_irq sh7750_irl(SH7750State *s)
808 sh_intc_toggle_source(sh_intc_source(&s->intc, IRL), 1, 0); /* enable */
809 return qemu_allocate_irqs(sh_intc_set_irl, sh_intc_source(&s->intc, IRL),
810 1)[0];