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
25 #include "qemu/osdep.h"
27 #include "hw/sh4/sh.h"
28 #include "sysemu/sysemu.h"
29 #include "sh7750_regs.h"
30 #include "sh7750_regnames.h"
31 #include "hw/sh4/sh_intc.h"
33 #include "exec/exec-all.h"
34 #include "exec/address-spaces.h"
38 typedef struct SH7750State
{
40 MemoryRegion iomem_1f0
;
41 MemoryRegion iomem_ff0
;
42 MemoryRegion iomem_1f8
;
43 MemoryRegion iomem_ff8
;
44 MemoryRegion iomem_1fc
;
45 MemoryRegion iomem_ffc
;
46 MemoryRegion mmct_iomem
;
49 /* Peripheral frequency in Hz */
51 /* SDRAM controller */
57 /* PCMCIA controller */
63 uint16_t portdira
; /* Cached */
64 uint16_t portpullupa
; /* Cached */
65 uint16_t portdirb
; /* Cached */
66 uint16_t portpullupb
; /* Cached */
69 uint16_t periph_pdtra
; /* Imposed by the peripherals */
70 uint16_t periph_portdira
; /* Direction seen from the peripherals */
71 uint16_t periph_pdtrb
; /* Imposed by the peripherals */
72 uint16_t periph_portdirb
; /* Direction seen from the peripherals */
73 sh7750_io_device
*devices
[NB_DEVICES
]; /* External peripherals */
78 struct intc_desc intc
;
81 static inline int has_bcr3_and_bcr4(SH7750State
* s
)
83 return s
->cpu
->env
.features
& SH_FEATURE_BCR3_AND_BCR4
;
85 /**********************************************************************
87 **********************************************************************/
89 int sh7750_register_io_device(SH7750State
* s
, sh7750_io_device
* device
)
93 for (i
= 0; i
< NB_DEVICES
; i
++) {
94 if (s
->devices
[i
] == NULL
) {
95 s
->devices
[i
] = device
;
102 static uint16_t portdir(uint32_t v
)
104 #define EVENPORTMASK(n) ((v & (1<<((n)<<1))) >> (n))
106 EVENPORTMASK(15) | EVENPORTMASK(14) | EVENPORTMASK(13) |
107 EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) |
108 EVENPORTMASK(9) | EVENPORTMASK(8) | EVENPORTMASK(7) |
109 EVENPORTMASK(6) | EVENPORTMASK(5) | EVENPORTMASK(4) |
110 EVENPORTMASK(3) | EVENPORTMASK(2) | EVENPORTMASK(1) |
114 static uint16_t portpullup(uint32_t v
)
116 #define ODDPORTMASK(n) ((v & (1<<(((n)<<1)+1))) >> (n))
118 ODDPORTMASK(15) | ODDPORTMASK(14) | ODDPORTMASK(13) |
119 ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) |
120 ODDPORTMASK(9) | ODDPORTMASK(8) | ODDPORTMASK(7) | ODDPORTMASK(6) |
121 ODDPORTMASK(5) | ODDPORTMASK(4) | ODDPORTMASK(3) | ODDPORTMASK(2) |
122 ODDPORTMASK(1) | ODDPORTMASK(0);
125 static uint16_t porta_lines(SH7750State
* s
)
127 return (s
->portdira
& s
->pdtra
) | /* CPU */
128 (s
->periph_portdira
& s
->periph_pdtra
) | /* Peripherals */
129 (~(s
->portdira
| s
->periph_portdira
) & s
->portpullupa
); /* Pullups */
132 static uint16_t portb_lines(SH7750State
* s
)
134 return (s
->portdirb
& s
->pdtrb
) | /* CPU */
135 (s
->periph_portdirb
& s
->periph_pdtrb
) | /* Peripherals */
136 (~(s
->portdirb
| s
->periph_portdirb
) & s
->portpullupb
); /* Pullups */
139 static void gen_port_interrupts(SH7750State
* s
)
141 /* XXXXX interrupts not generated */
144 static void porta_changed(SH7750State
* s
, uint16_t prev
)
146 uint16_t currenta
, changes
;
150 fprintf(stderr
, "porta changed from 0x%04x to 0x%04x\n",
151 prev
, porta_lines(s
));
152 fprintf(stderr
, "pdtra=0x%04x, pctra=0x%08x\n", s
->pdtra
, s
->pctra
);
154 currenta
= porta_lines(s
);
155 if (currenta
== prev
)
157 changes
= currenta
^ prev
;
159 for (i
= 0; i
< NB_DEVICES
; i
++) {
160 if (s
->devices
[i
] && (s
->devices
[i
]->portamask_trigger
& changes
)) {
161 r
|= s
->devices
[i
]->port_change_cb(currenta
, portb_lines(s
),
165 &s
->periph_portdirb
);
170 gen_port_interrupts(s
);
173 static void portb_changed(SH7750State
* s
, uint16_t prev
)
175 uint16_t currentb
, changes
;
178 currentb
= portb_lines(s
);
179 if (currentb
== prev
)
181 changes
= currentb
^ prev
;
183 for (i
= 0; i
< NB_DEVICES
; i
++) {
184 if (s
->devices
[i
] && (s
->devices
[i
]->portbmask_trigger
& changes
)) {
185 r
|= s
->devices
[i
]->port_change_cb(portb_lines(s
), currentb
,
189 &s
->periph_portdirb
);
194 gen_port_interrupts(s
);
197 /**********************************************************************
199 **********************************************************************/
201 static void error_access(const char *kind
, hwaddr addr
)
203 fprintf(stderr
, "%s to %s (0x" TARGET_FMT_plx
") not supported\n",
204 kind
, regname(addr
), addr
);
207 static void ignore_access(const char *kind
, hwaddr addr
)
209 fprintf(stderr
, "%s to %s (0x" TARGET_FMT_plx
") ignored\n",
210 kind
, regname(addr
), addr
);
213 static uint32_t sh7750_mem_readb(void *opaque
, hwaddr addr
)
217 error_access("byte read", addr
);
222 static uint32_t sh7750_mem_readw(void *opaque
, hwaddr addr
)
224 SH7750State
*s
= opaque
;
230 if(!has_bcr3_and_bcr4(s
))
231 error_access("word read", addr
);
233 case SH7750_FRQCR_A7
:
239 "Read access to refresh count register, incrementing\n");
241 case SH7750_PDTRA_A7
:
242 return porta_lines(s
);
243 case SH7750_PDTRB_A7
:
244 return portb_lines(s
);
245 case SH7750_RTCOR_A7
:
246 case SH7750_RTCNT_A7
:
247 case SH7750_RTCSR_A7
:
248 ignore_access("word read", addr
);
251 error_access("word read", addr
);
256 static uint32_t sh7750_mem_readl(void *opaque
, hwaddr addr
)
258 SH7750State
*s
= opaque
;
265 if(!has_bcr3_and_bcr4(s
))
266 error_access("long read", addr
);
272 ignore_access("long read", addr
);
274 case SH7750_MMUCR_A7
:
275 return s
->cpu
->env
.mmucr
;
277 return s
->cpu
->env
.pteh
;
279 return s
->cpu
->env
.ptel
;
281 return s
->cpu
->env
.ttb
;
283 return s
->cpu
->env
.tea
;
285 return s
->cpu
->env
.tra
;
286 case SH7750_EXPEVT_A7
:
287 return s
->cpu
->env
.expevt
;
288 case SH7750_INTEVT_A7
:
289 return s
->cpu
->env
.intevt
;
292 case 0x1f000030: /* Processor version */
293 scc
= SUPERH_CPU_GET_CLASS(s
->cpu
);
295 case 0x1f000040: /* Cache version */
296 scc
= SUPERH_CPU_GET_CLASS(s
->cpu
);
298 case 0x1f000044: /* Processor revision */
299 scc
= SUPERH_CPU_GET_CLASS(s
->cpu
);
302 error_access("long read", addr
);
307 #define is_in_sdrmx(a, x) (a >= SH7750_SDMR ## x ## _A7 \
308 && a <= (SH7750_SDMR ## x ## _A7 + SH7750_SDMR ## x ## _REGNB))
309 static void sh7750_mem_writeb(void *opaque
, hwaddr addr
,
313 if (is_in_sdrmx(addr
, 2) || is_in_sdrmx(addr
, 3)) {
314 ignore_access("byte write", addr
);
318 error_access("byte write", addr
);
322 static void sh7750_mem_writew(void *opaque
, hwaddr addr
,
325 SH7750State
*s
= opaque
;
329 /* SDRAM controller */
334 if(!has_bcr3_and_bcr4(s
))
335 error_access("word write", addr
);
341 case SH7750_RTCNT_A7
:
342 case SH7750_RTCOR_A7
:
343 case SH7750_RTCSR_A7
:
344 ignore_access("word write", addr
);
347 case SH7750_PDTRA_A7
:
348 temp
= porta_lines(s
);
349 s
->pdtra
= mem_value
;
350 porta_changed(s
, temp
);
352 case SH7750_PDTRB_A7
:
353 temp
= portb_lines(s
);
354 s
->pdtrb
= mem_value
;
355 portb_changed(s
, temp
);
358 fprintf(stderr
, "Write access to refresh count register\n");
361 case SH7750_GPIOIC_A7
:
362 s
->gpioic
= mem_value
;
363 if (mem_value
!= 0) {
364 fprintf(stderr
, "I/O interrupts not implemented\n");
369 error_access("word write", addr
);
374 static void sh7750_mem_writel(void *opaque
, hwaddr addr
,
377 SH7750State
*s
= opaque
;
381 /* SDRAM controller */
386 if(!has_bcr3_and_bcr4(s
))
387 error_access("long write", addr
);
394 ignore_access("long write", addr
);
397 case SH7750_PCTRA_A7
:
398 temp
= porta_lines(s
);
399 s
->pctra
= mem_value
;
400 s
->portdira
= portdir(mem_value
);
401 s
->portpullupa
= portpullup(mem_value
);
402 porta_changed(s
, temp
);
404 case SH7750_PCTRB_A7
:
405 temp
= portb_lines(s
);
406 s
->pctrb
= mem_value
;
407 s
->portdirb
= portdir(mem_value
);
408 s
->portpullupb
= portpullup(mem_value
);
409 portb_changed(s
, temp
);
411 case SH7750_MMUCR_A7
:
412 if (mem_value
& MMUCR_TI
) {
413 cpu_sh4_invalidate_tlb(&s
->cpu
->env
);
415 s
->cpu
->env
.mmucr
= mem_value
& ~MMUCR_TI
;
418 /* If asid changes, clear all registered tlb entries. */
419 if ((s
->cpu
->env
.pteh
& 0xff) != (mem_value
& 0xff)) {
420 tlb_flush(CPU(s
->cpu
), 1);
422 s
->cpu
->env
.pteh
= mem_value
;
425 s
->cpu
->env
.ptel
= mem_value
;
428 s
->cpu
->env
.ptea
= mem_value
& 0x0000000f;
431 s
->cpu
->env
.ttb
= mem_value
;
434 s
->cpu
->env
.tea
= mem_value
;
437 s
->cpu
->env
.tra
= mem_value
& 0x000007ff;
439 case SH7750_EXPEVT_A7
:
440 s
->cpu
->env
.expevt
= mem_value
& 0x000007ff;
442 case SH7750_INTEVT_A7
:
443 s
->cpu
->env
.intevt
= mem_value
& 0x000007ff;
449 error_access("long write", addr
);
454 static const MemoryRegionOps sh7750_mem_ops
= {
456 .read
= {sh7750_mem_readb
,
459 .write
= {sh7750_mem_writeb
,
463 .endianness
= DEVICE_NATIVE_ENDIAN
,
466 /* sh775x interrupt controller tables for sh_intc.c
467 * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
473 /* interrupt sources */
474 IRL_0
, IRL_1
, IRL_2
, IRL_3
, IRL_4
, IRL_5
, IRL_6
, IRL_7
,
475 IRL_8
, IRL_9
, IRL_A
, IRL_B
, IRL_C
, IRL_D
, IRL_E
,
476 IRL0
, IRL1
, IRL2
, IRL3
,
478 DMAC_DMTE0
, DMAC_DMTE1
, DMAC_DMTE2
, DMAC_DMTE3
,
479 DMAC_DMTE4
, DMAC_DMTE5
, DMAC_DMTE6
, DMAC_DMTE7
,
481 PCIC0_PCISERR
, PCIC1_PCIERR
, PCIC1_PCIPWDWN
, PCIC1_PCIPWON
,
482 PCIC1_PCIDMA0
, PCIC1_PCIDMA1
, PCIC1_PCIDMA2
, PCIC1_PCIDMA3
,
483 TMU3
, TMU4
, TMU0
, TMU1
, TMU2_TUNI
, TMU2_TICPI
,
484 RTC_ATI
, RTC_PRI
, RTC_CUI
,
485 SCI1_ERI
, SCI1_RXI
, SCI1_TXI
, SCI1_TEI
,
486 SCIF_ERI
, SCIF_RXI
, SCIF_BRI
, SCIF_TXI
,
490 /* interrupt groups */
491 DMAC
, PCIC1
, TMU2
, RTC
, SCI1
, SCIF
, REF
,
498 static struct intc_vect vectors
[] = {
499 INTC_VECT(HUDI
, 0x600), INTC_VECT(GPIOI
, 0x620),
500 INTC_VECT(TMU0
, 0x400), INTC_VECT(TMU1
, 0x420),
501 INTC_VECT(TMU2_TUNI
, 0x440), INTC_VECT(TMU2_TICPI
, 0x460),
502 INTC_VECT(RTC_ATI
, 0x480), INTC_VECT(RTC_PRI
, 0x4a0),
503 INTC_VECT(RTC_CUI
, 0x4c0),
504 INTC_VECT(SCI1_ERI
, 0x4e0), INTC_VECT(SCI1_RXI
, 0x500),
505 INTC_VECT(SCI1_TXI
, 0x520), INTC_VECT(SCI1_TEI
, 0x540),
506 INTC_VECT(SCIF_ERI
, 0x700), INTC_VECT(SCIF_RXI
, 0x720),
507 INTC_VECT(SCIF_BRI
, 0x740), INTC_VECT(SCIF_TXI
, 0x760),
508 INTC_VECT(WDT
, 0x560),
509 INTC_VECT(REF_RCMI
, 0x580), INTC_VECT(REF_ROVI
, 0x5a0),
512 static struct intc_group groups
[] = {
513 INTC_GROUP(TMU2
, TMU2_TUNI
, TMU2_TICPI
),
514 INTC_GROUP(RTC
, RTC_ATI
, RTC_PRI
, RTC_CUI
),
515 INTC_GROUP(SCI1
, SCI1_ERI
, SCI1_RXI
, SCI1_TXI
, SCI1_TEI
),
516 INTC_GROUP(SCIF
, SCIF_ERI
, SCIF_RXI
, SCIF_BRI
, SCIF_TXI
),
517 INTC_GROUP(REF
, REF_RCMI
, REF_ROVI
),
520 static struct intc_prio_reg prio_registers
[] = {
521 { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0
, TMU1
, TMU2
, RTC
} },
522 { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT
, REF
, SCI1
, 0 } },
523 { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI
, DMAC
, SCIF
, HUDI
} },
524 { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0
, IRL1
, IRL2
, IRL3
} },
525 { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
527 PCIC1
, PCIC0_PCISERR
} },
530 /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
532 static struct intc_vect vectors_dma4
[] = {
533 INTC_VECT(DMAC_DMTE0
, 0x640), INTC_VECT(DMAC_DMTE1
, 0x660),
534 INTC_VECT(DMAC_DMTE2
, 0x680), INTC_VECT(DMAC_DMTE3
, 0x6a0),
535 INTC_VECT(DMAC_DMAE
, 0x6c0),
538 static struct intc_group groups_dma4
[] = {
539 INTC_GROUP(DMAC
, DMAC_DMTE0
, DMAC_DMTE1
, DMAC_DMTE2
,
540 DMAC_DMTE3
, DMAC_DMAE
),
543 /* SH7750R and SH7751R both have 8-channel DMA controllers */
545 static struct intc_vect vectors_dma8
[] = {
546 INTC_VECT(DMAC_DMTE0
, 0x640), INTC_VECT(DMAC_DMTE1
, 0x660),
547 INTC_VECT(DMAC_DMTE2
, 0x680), INTC_VECT(DMAC_DMTE3
, 0x6a0),
548 INTC_VECT(DMAC_DMTE4
, 0x780), INTC_VECT(DMAC_DMTE5
, 0x7a0),
549 INTC_VECT(DMAC_DMTE6
, 0x7c0), INTC_VECT(DMAC_DMTE7
, 0x7e0),
550 INTC_VECT(DMAC_DMAE
, 0x6c0),
553 static struct intc_group groups_dma8
[] = {
554 INTC_GROUP(DMAC
, DMAC_DMTE0
, DMAC_DMTE1
, DMAC_DMTE2
,
555 DMAC_DMTE3
, DMAC_DMTE4
, DMAC_DMTE5
,
556 DMAC_DMTE6
, DMAC_DMTE7
, DMAC_DMAE
),
559 /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
561 static struct intc_vect vectors_tmu34
[] = {
562 INTC_VECT(TMU3
, 0xb00), INTC_VECT(TMU4
, 0xb80),
565 static struct intc_mask_reg mask_registers
[] = {
566 { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
567 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
568 0, 0, 0, 0, 0, 0, TMU4
, TMU3
,
569 PCIC1_PCIERR
, PCIC1_PCIPWDWN
, PCIC1_PCIPWON
,
570 PCIC1_PCIDMA0
, PCIC1_PCIDMA1
, PCIC1_PCIDMA2
,
571 PCIC1_PCIDMA3
, PCIC0_PCISERR
} },
574 /* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
576 static struct intc_vect vectors_irlm
[] = {
577 INTC_VECT(IRL0
, 0x240), INTC_VECT(IRL1
, 0x2a0),
578 INTC_VECT(IRL2
, 0x300), INTC_VECT(IRL3
, 0x360),
581 /* SH7751 and SH7751R both have PCI */
583 static struct intc_vect vectors_pci
[] = {
584 INTC_VECT(PCIC0_PCISERR
, 0xa00), INTC_VECT(PCIC1_PCIERR
, 0xae0),
585 INTC_VECT(PCIC1_PCIPWDWN
, 0xac0), INTC_VECT(PCIC1_PCIPWON
, 0xaa0),
586 INTC_VECT(PCIC1_PCIDMA0
, 0xa80), INTC_VECT(PCIC1_PCIDMA1
, 0xa60),
587 INTC_VECT(PCIC1_PCIDMA2
, 0xa40), INTC_VECT(PCIC1_PCIDMA3
, 0xa20),
590 static struct intc_group groups_pci
[] = {
591 INTC_GROUP(PCIC1
, PCIC1_PCIERR
, PCIC1_PCIPWDWN
, PCIC1_PCIPWON
,
592 PCIC1_PCIDMA0
, PCIC1_PCIDMA1
, PCIC1_PCIDMA2
, PCIC1_PCIDMA3
),
595 static struct intc_vect vectors_irl
[] = {
596 INTC_VECT(IRL_0
, 0x200),
597 INTC_VECT(IRL_1
, 0x220),
598 INTC_VECT(IRL_2
, 0x240),
599 INTC_VECT(IRL_3
, 0x260),
600 INTC_VECT(IRL_4
, 0x280),
601 INTC_VECT(IRL_5
, 0x2a0),
602 INTC_VECT(IRL_6
, 0x2c0),
603 INTC_VECT(IRL_7
, 0x2e0),
604 INTC_VECT(IRL_8
, 0x300),
605 INTC_VECT(IRL_9
, 0x320),
606 INTC_VECT(IRL_A
, 0x340),
607 INTC_VECT(IRL_B
, 0x360),
608 INTC_VECT(IRL_C
, 0x380),
609 INTC_VECT(IRL_D
, 0x3a0),
610 INTC_VECT(IRL_E
, 0x3c0),
613 static struct intc_group groups_irl
[] = {
614 INTC_GROUP(IRL
, IRL_0
, IRL_1
, IRL_2
, IRL_3
, IRL_4
, IRL_5
, IRL_6
,
615 IRL_7
, IRL_8
, IRL_9
, IRL_A
, IRL_B
, IRL_C
, IRL_D
, IRL_E
),
618 /**********************************************************************
619 Memory mapped cache and TLB
620 **********************************************************************/
622 #define MM_REGION_MASK 0x07000000
623 #define MM_ICACHE_ADDR (0)
624 #define MM_ICACHE_DATA (1)
625 #define MM_ITLB_ADDR (2)
626 #define MM_ITLB_DATA (3)
627 #define MM_OCACHE_ADDR (4)
628 #define MM_OCACHE_DATA (5)
629 #define MM_UTLB_ADDR (6)
630 #define MM_UTLB_DATA (7)
631 #define MM_REGION_TYPE(addr) ((addr & MM_REGION_MASK) >> 24)
633 static uint64_t invalid_read(void *opaque
, hwaddr addr
)
640 static uint64_t sh7750_mmct_read(void *opaque
, hwaddr addr
,
643 SH7750State
*s
= opaque
;
647 return invalid_read(opaque
, addr
);
650 switch (MM_REGION_TYPE(addr
)) {
656 ret
= cpu_sh4_read_mmaped_itlb_addr(&s
->cpu
->env
, addr
);
659 ret
= cpu_sh4_read_mmaped_itlb_data(&s
->cpu
->env
, addr
);
666 ret
= cpu_sh4_read_mmaped_utlb_addr(&s
->cpu
->env
, addr
);
669 ret
= cpu_sh4_read_mmaped_utlb_data(&s
->cpu
->env
, addr
);
678 static void invalid_write(void *opaque
, hwaddr addr
,
684 static void sh7750_mmct_write(void *opaque
, hwaddr addr
,
685 uint64_t mem_value
, unsigned size
)
687 SH7750State
*s
= opaque
;
690 invalid_write(opaque
, addr
, mem_value
);
693 switch (MM_REGION_TYPE(addr
)) {
699 cpu_sh4_write_mmaped_itlb_addr(&s
->cpu
->env
, addr
, mem_value
);
702 cpu_sh4_write_mmaped_itlb_data(&s
->cpu
->env
, addr
, mem_value
);
710 cpu_sh4_write_mmaped_utlb_addr(&s
->cpu
->env
, addr
, mem_value
);
713 cpu_sh4_write_mmaped_utlb_data(&s
->cpu
->env
, addr
, mem_value
);
721 static const MemoryRegionOps sh7750_mmct_ops
= {
722 .read
= sh7750_mmct_read
,
723 .write
= sh7750_mmct_write
,
724 .endianness
= DEVICE_NATIVE_ENDIAN
,
727 SH7750State
*sh7750_init(SuperHCPU
*cpu
, MemoryRegion
*sysmem
)
731 s
= g_malloc0(sizeof(SH7750State
));
733 s
->periph_freq
= 60000000; /* 60MHz */
734 memory_region_init_io(&s
->iomem
, NULL
, &sh7750_mem_ops
, s
,
735 "memory", 0x1fc01000);
737 memory_region_init_alias(&s
->iomem_1f0
, NULL
, "memory-1f0",
738 &s
->iomem
, 0x1f000000, 0x1000);
739 memory_region_add_subregion(sysmem
, 0x1f000000, &s
->iomem_1f0
);
741 memory_region_init_alias(&s
->iomem_ff0
, NULL
, "memory-ff0",
742 &s
->iomem
, 0x1f000000, 0x1000);
743 memory_region_add_subregion(sysmem
, 0xff000000, &s
->iomem_ff0
);
745 memory_region_init_alias(&s
->iomem_1f8
, NULL
, "memory-1f8",
746 &s
->iomem
, 0x1f800000, 0x1000);
747 memory_region_add_subregion(sysmem
, 0x1f800000, &s
->iomem_1f8
);
749 memory_region_init_alias(&s
->iomem_ff8
, NULL
, "memory-ff8",
750 &s
->iomem
, 0x1f800000, 0x1000);
751 memory_region_add_subregion(sysmem
, 0xff800000, &s
->iomem_ff8
);
753 memory_region_init_alias(&s
->iomem_1fc
, NULL
, "memory-1fc",
754 &s
->iomem
, 0x1fc00000, 0x1000);
755 memory_region_add_subregion(sysmem
, 0x1fc00000, &s
->iomem_1fc
);
757 memory_region_init_alias(&s
->iomem_ffc
, NULL
, "memory-ffc",
758 &s
->iomem
, 0x1fc00000, 0x1000);
759 memory_region_add_subregion(sysmem
, 0xffc00000, &s
->iomem_ffc
);
761 memory_region_init_io(&s
->mmct_iomem
, NULL
, &sh7750_mmct_ops
, s
,
762 "cache-and-tlb", 0x08000000);
763 memory_region_add_subregion(sysmem
, 0xf0000000, &s
->mmct_iomem
);
765 sh_intc_init(sysmem
, &s
->intc
, NR_SOURCES
,
766 _INTC_ARRAY(mask_registers
),
767 _INTC_ARRAY(prio_registers
));
769 sh_intc_register_sources(&s
->intc
,
770 _INTC_ARRAY(vectors
),
771 _INTC_ARRAY(groups
));
773 cpu
->env
.intc_handle
= &s
->intc
;
775 sh_serial_init(sysmem
, 0x1fe00000,
776 0, s
->periph_freq
, serial_hds
[0],
777 s
->intc
.irqs
[SCI1_ERI
],
778 s
->intc
.irqs
[SCI1_RXI
],
779 s
->intc
.irqs
[SCI1_TXI
],
780 s
->intc
.irqs
[SCI1_TEI
],
782 sh_serial_init(sysmem
, 0x1fe80000,
784 s
->periph_freq
, serial_hds
[1],
785 s
->intc
.irqs
[SCIF_ERI
],
786 s
->intc
.irqs
[SCIF_RXI
],
787 s
->intc
.irqs
[SCIF_TXI
],
789 s
->intc
.irqs
[SCIF_BRI
]);
791 tmu012_init(sysmem
, 0x1fd80000,
792 TMU012_FEAT_TOCR
| TMU012_FEAT_3CHAN
| TMU012_FEAT_EXTCLK
,
796 s
->intc
.irqs
[TMU2_TUNI
],
797 s
->intc
.irqs
[TMU2_TICPI
]);
799 if (cpu
->env
.id
& (SH_CPU_SH7750
| SH_CPU_SH7750S
| SH_CPU_SH7751
)) {
800 sh_intc_register_sources(&s
->intc
,
801 _INTC_ARRAY(vectors_dma4
),
802 _INTC_ARRAY(groups_dma4
));
805 if (cpu
->env
.id
& (SH_CPU_SH7750R
| SH_CPU_SH7751R
)) {
806 sh_intc_register_sources(&s
->intc
,
807 _INTC_ARRAY(vectors_dma8
),
808 _INTC_ARRAY(groups_dma8
));
811 if (cpu
->env
.id
& (SH_CPU_SH7750R
| SH_CPU_SH7751
| SH_CPU_SH7751R
)) {
812 sh_intc_register_sources(&s
->intc
,
813 _INTC_ARRAY(vectors_tmu34
),
815 tmu012_init(sysmem
, 0x1e100000, 0, s
->periph_freq
,
821 if (cpu
->env
.id
& (SH_CPU_SH7751_ALL
)) {
822 sh_intc_register_sources(&s
->intc
,
823 _INTC_ARRAY(vectors_pci
),
824 _INTC_ARRAY(groups_pci
));
827 if (cpu
->env
.id
& (SH_CPU_SH7750S
| SH_CPU_SH7750R
| SH_CPU_SH7751_ALL
)) {
828 sh_intc_register_sources(&s
->intc
,
829 _INTC_ARRAY(vectors_irlm
),
833 sh_intc_register_sources(&s
->intc
,
834 _INTC_ARRAY(vectors_irl
),
835 _INTC_ARRAY(groups_irl
));
839 qemu_irq
sh7750_irl(SH7750State
*s
)
841 sh_intc_toggle_source(sh_intc_source(&s
->intc
, IRL
), 1, 0); /* enable */
842 return qemu_allocate_irq(sh_intc_set_irl
, sh_intc_source(&s
->intc
, IRL
), 0);