Statistics
| Branch: | Revision:

root / hw / sh7750.c @ cd08ce8f

History | View | Annotate | Download (16.2 kB)

1 27c7ca7e bellard
/*
2 27c7ca7e bellard
 * SH7750 device
3 5fafdf24 ths
 *
4 80f515e6 balrog
 * Copyright (c) 2007 Magnus Damm
5 27c7ca7e bellard
 * Copyright (c) 2005 Samuel Tardieu
6 5fafdf24 ths
 *
7 27c7ca7e bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 27c7ca7e bellard
 * of this software and associated documentation files (the "Software"), to deal
9 27c7ca7e bellard
 * in the Software without restriction, including without limitation the rights
10 27c7ca7e bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 27c7ca7e bellard
 * copies of the Software, and to permit persons to whom the Software is
12 27c7ca7e bellard
 * furnished to do so, subject to the following conditions:
13 27c7ca7e bellard
 *
14 27c7ca7e bellard
 * The above copyright notice and this permission notice shall be included in
15 27c7ca7e bellard
 * all copies or substantial portions of the Software.
16 27c7ca7e bellard
 *
17 27c7ca7e bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 27c7ca7e bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 27c7ca7e bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 27c7ca7e bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 27c7ca7e bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 27c7ca7e bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 27c7ca7e bellard
 * THE SOFTWARE.
24 27c7ca7e bellard
 */
25 27c7ca7e bellard
#include <stdio.h>
26 27c7ca7e bellard
#include <assert.h>
27 27c7ca7e bellard
#include "vl.h"
28 27c7ca7e bellard
#include "sh7750_regs.h"
29 27c7ca7e bellard
#include "sh7750_regnames.h"
30 80f515e6 balrog
#include "sh_intc.h"
31 27c7ca7e bellard
32 27c7ca7e bellard
#define NB_DEVICES 4
33 27c7ca7e bellard
34 27c7ca7e bellard
typedef struct SH7750State {
35 27c7ca7e bellard
    /* CPU */
36 27c7ca7e bellard
    CPUSH4State *cpu;
37 27c7ca7e bellard
    /* Peripheral frequency in Hz */
38 27c7ca7e bellard
    uint32_t periph_freq;
39 27c7ca7e bellard
    /* SDRAM controller */
40 27c7ca7e bellard
    uint16_t rfcr;
41 27c7ca7e bellard
    /* IO ports */
42 27c7ca7e bellard
    uint16_t gpioic;
43 27c7ca7e bellard
    uint32_t pctra;
44 27c7ca7e bellard
    uint32_t pctrb;
45 27c7ca7e bellard
    uint16_t portdira;                /* Cached */
46 27c7ca7e bellard
    uint16_t portpullupa;        /* Cached */
47 27c7ca7e bellard
    uint16_t portdirb;                /* Cached */
48 27c7ca7e bellard
    uint16_t portpullupb;        /* Cached */
49 27c7ca7e bellard
    uint16_t pdtra;
50 27c7ca7e bellard
    uint16_t pdtrb;
51 27c7ca7e bellard
    uint16_t periph_pdtra;        /* Imposed by the peripherals */
52 27c7ca7e bellard
    uint16_t periph_portdira;        /* Direction seen from the peripherals */
53 27c7ca7e bellard
    uint16_t periph_pdtrb;        /* Imposed by the peripherals */
54 27c7ca7e bellard
    uint16_t periph_portdirb;        /* Direction seen from the peripherals */
55 27c7ca7e bellard
    sh7750_io_device *devices[NB_DEVICES];        /* External peripherals */
56 3464c589 ths
57 3464c589 ths
    uint16_t icr;
58 27c7ca7e bellard
    /* Cache */
59 27c7ca7e bellard
    uint32_t ccr;
60 27c7ca7e bellard
61 80f515e6 balrog
    struct intc_desc intc;
62 cd1a3f68 ths
} SH7750State;
63 27c7ca7e bellard
64 27c7ca7e bellard
65 27c7ca7e bellard
/**********************************************************************
66 27c7ca7e bellard
 I/O ports
67 27c7ca7e bellard
**********************************************************************/
68 27c7ca7e bellard
69 27c7ca7e bellard
int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)
70 27c7ca7e bellard
{
71 27c7ca7e bellard
    int i;
72 27c7ca7e bellard
73 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
74 27c7ca7e bellard
        if (s->devices[i] == NULL) {
75 27c7ca7e bellard
            s->devices[i] = device;
76 27c7ca7e bellard
            return 0;
77 27c7ca7e bellard
        }
78 27c7ca7e bellard
    }
79 27c7ca7e bellard
    return -1;
80 27c7ca7e bellard
}
81 27c7ca7e bellard
82 27c7ca7e bellard
static uint16_t portdir(uint32_t v)
83 27c7ca7e bellard
{
84 27c7ca7e bellard
#define EVENPORTMASK(n) ((v & (1<<((n)<<1))) >> (n))
85 27c7ca7e bellard
    return
86 27c7ca7e bellard
        EVENPORTMASK(15) | EVENPORTMASK(14) | EVENPORTMASK(13) |
87 27c7ca7e bellard
        EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) |
88 27c7ca7e bellard
        EVENPORTMASK(9) | EVENPORTMASK(8) | EVENPORTMASK(7) |
89 27c7ca7e bellard
        EVENPORTMASK(6) | EVENPORTMASK(5) | EVENPORTMASK(4) |
90 27c7ca7e bellard
        EVENPORTMASK(3) | EVENPORTMASK(2) | EVENPORTMASK(1) |
91 27c7ca7e bellard
        EVENPORTMASK(0);
92 27c7ca7e bellard
}
93 27c7ca7e bellard
94 27c7ca7e bellard
static uint16_t portpullup(uint32_t v)
95 27c7ca7e bellard
{
96 27c7ca7e bellard
#define ODDPORTMASK(n) ((v & (1<<(((n)<<1)+1))) >> (n))
97 27c7ca7e bellard
    return
98 27c7ca7e bellard
        ODDPORTMASK(15) | ODDPORTMASK(14) | ODDPORTMASK(13) |
99 27c7ca7e bellard
        ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) |
100 27c7ca7e bellard
        ODDPORTMASK(9) | ODDPORTMASK(8) | ODDPORTMASK(7) | ODDPORTMASK(6) |
101 27c7ca7e bellard
        ODDPORTMASK(5) | ODDPORTMASK(4) | ODDPORTMASK(3) | ODDPORTMASK(2) |
102 27c7ca7e bellard
        ODDPORTMASK(1) | ODDPORTMASK(0);
103 27c7ca7e bellard
}
104 27c7ca7e bellard
105 27c7ca7e bellard
static uint16_t porta_lines(SH7750State * s)
106 27c7ca7e bellard
{
107 27c7ca7e bellard
    return (s->portdira & s->pdtra) |        /* CPU */
108 27c7ca7e bellard
        (s->periph_portdira & s->periph_pdtra) |        /* Peripherals */
109 27c7ca7e bellard
        (~(s->portdira | s->periph_portdira) & s->portpullupa);        /* Pullups */
110 27c7ca7e bellard
}
111 27c7ca7e bellard
112 27c7ca7e bellard
static uint16_t portb_lines(SH7750State * s)
113 27c7ca7e bellard
{
114 27c7ca7e bellard
    return (s->portdirb & s->pdtrb) |        /* CPU */
115 27c7ca7e bellard
        (s->periph_portdirb & s->periph_pdtrb) |        /* Peripherals */
116 27c7ca7e bellard
        (~(s->portdirb | s->periph_portdirb) & s->portpullupb);        /* Pullups */
117 27c7ca7e bellard
}
118 27c7ca7e bellard
119 27c7ca7e bellard
static void gen_port_interrupts(SH7750State * s)
120 27c7ca7e bellard
{
121 27c7ca7e bellard
    /* XXXXX interrupts not generated */
122 27c7ca7e bellard
}
123 27c7ca7e bellard
124 27c7ca7e bellard
static void porta_changed(SH7750State * s, uint16_t prev)
125 27c7ca7e bellard
{
126 27c7ca7e bellard
    uint16_t currenta, changes;
127 27c7ca7e bellard
    int i, r = 0;
128 27c7ca7e bellard
129 27c7ca7e bellard
#if 0
130 27c7ca7e bellard
    fprintf(stderr, "porta changed from 0x%04x to 0x%04x\n",
131 27c7ca7e bellard
            prev, porta_lines(s));
132 27c7ca7e bellard
    fprintf(stderr, "pdtra=0x%04x, pctra=0x%08x\n", s->pdtra, s->pctra);
133 27c7ca7e bellard
#endif
134 27c7ca7e bellard
    currenta = porta_lines(s);
135 27c7ca7e bellard
    if (currenta == prev)
136 27c7ca7e bellard
        return;
137 27c7ca7e bellard
    changes = currenta ^ prev;
138 27c7ca7e bellard
139 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
140 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portamask_trigger & changes)) {
141 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(currenta, portb_lines(s),
142 27c7ca7e bellard
                                               &s->periph_pdtra,
143 27c7ca7e bellard
                                               &s->periph_portdira,
144 27c7ca7e bellard
                                               &s->periph_pdtrb,
145 27c7ca7e bellard
                                               &s->periph_portdirb);
146 27c7ca7e bellard
        }
147 27c7ca7e bellard
    }
148 27c7ca7e bellard
149 27c7ca7e bellard
    if (r)
150 27c7ca7e bellard
        gen_port_interrupts(s);
151 27c7ca7e bellard
}
152 27c7ca7e bellard
153 27c7ca7e bellard
static void portb_changed(SH7750State * s, uint16_t prev)
154 27c7ca7e bellard
{
155 27c7ca7e bellard
    uint16_t currentb, changes;
156 27c7ca7e bellard
    int i, r = 0;
157 27c7ca7e bellard
158 27c7ca7e bellard
    currentb = portb_lines(s);
159 27c7ca7e bellard
    if (currentb == prev)
160 27c7ca7e bellard
        return;
161 27c7ca7e bellard
    changes = currentb ^ prev;
162 27c7ca7e bellard
163 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
164 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portbmask_trigger & changes)) {
165 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(portb_lines(s), currentb,
166 27c7ca7e bellard
                                               &s->periph_pdtra,
167 27c7ca7e bellard
                                               &s->periph_portdira,
168 27c7ca7e bellard
                                               &s->periph_pdtrb,
169 27c7ca7e bellard
                                               &s->periph_portdirb);
170 27c7ca7e bellard
        }
171 27c7ca7e bellard
    }
172 27c7ca7e bellard
173 27c7ca7e bellard
    if (r)
174 27c7ca7e bellard
        gen_port_interrupts(s);
175 27c7ca7e bellard
}
176 27c7ca7e bellard
177 27c7ca7e bellard
/**********************************************************************
178 27c7ca7e bellard
 Memory
179 27c7ca7e bellard
**********************************************************************/
180 27c7ca7e bellard
181 27c7ca7e bellard
static void error_access(const char *kind, target_phys_addr_t addr)
182 27c7ca7e bellard
{
183 27c7ca7e bellard
    fprintf(stderr, "%s to %s (0x%08x) not supported\n",
184 27c7ca7e bellard
            kind, regname(addr), addr);
185 27c7ca7e bellard
}
186 27c7ca7e bellard
187 27c7ca7e bellard
static void ignore_access(const char *kind, target_phys_addr_t addr)
188 27c7ca7e bellard
{
189 27c7ca7e bellard
    fprintf(stderr, "%s to %s (0x%08x) ignored\n",
190 27c7ca7e bellard
            kind, regname(addr), addr);
191 27c7ca7e bellard
}
192 27c7ca7e bellard
193 27c7ca7e bellard
static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr)
194 27c7ca7e bellard
{
195 27c7ca7e bellard
    switch (addr) {
196 27c7ca7e bellard
    default:
197 27c7ca7e bellard
        error_access("byte read", addr);
198 27c7ca7e bellard
        assert(0);
199 27c7ca7e bellard
    }
200 27c7ca7e bellard
}
201 27c7ca7e bellard
202 27c7ca7e bellard
static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr)
203 27c7ca7e bellard
{
204 27c7ca7e bellard
    SH7750State *s = opaque;
205 27c7ca7e bellard
206 27c7ca7e bellard
    switch (addr) {
207 ed8e0a4d ths
    case SH7750_FRQCR_A7:
208 ed8e0a4d ths
        return 0;
209 27c7ca7e bellard
    case SH7750_RFCR_A7:
210 27c7ca7e bellard
        fprintf(stderr,
211 27c7ca7e bellard
                "Read access to refresh count register, incrementing\n");
212 27c7ca7e bellard
        return s->rfcr++;
213 27c7ca7e bellard
    case SH7750_PDTRA_A7:
214 27c7ca7e bellard
        return porta_lines(s);
215 27c7ca7e bellard
    case SH7750_PDTRB_A7:
216 27c7ca7e bellard
        return portb_lines(s);
217 3464c589 ths
    case 0x1fd00000:
218 3464c589 ths
        return s->icr;
219 27c7ca7e bellard
    default:
220 27c7ca7e bellard
        error_access("word read", addr);
221 27c7ca7e bellard
        assert(0);
222 27c7ca7e bellard
    }
223 27c7ca7e bellard
}
224 27c7ca7e bellard
225 27c7ca7e bellard
static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr)
226 27c7ca7e bellard
{
227 27c7ca7e bellard
    SH7750State *s = opaque;
228 27c7ca7e bellard
229 27c7ca7e bellard
    switch (addr) {
230 27c7ca7e bellard
    case SH7750_MMUCR_A7:
231 27c7ca7e bellard
        return s->cpu->mmucr;
232 27c7ca7e bellard
    case SH7750_PTEH_A7:
233 27c7ca7e bellard
        return s->cpu->pteh;
234 27c7ca7e bellard
    case SH7750_PTEL_A7:
235 27c7ca7e bellard
        return s->cpu->ptel;
236 27c7ca7e bellard
    case SH7750_TTB_A7:
237 27c7ca7e bellard
        return s->cpu->ttb;
238 27c7ca7e bellard
    case SH7750_TEA_A7:
239 27c7ca7e bellard
        return s->cpu->tea;
240 27c7ca7e bellard
    case SH7750_TRA_A7:
241 27c7ca7e bellard
        return s->cpu->tra;
242 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
243 27c7ca7e bellard
        return s->cpu->expevt;
244 27c7ca7e bellard
    case SH7750_INTEVT_A7:
245 27c7ca7e bellard
        return s->cpu->intevt;
246 27c7ca7e bellard
    case SH7750_CCR_A7:
247 27c7ca7e bellard
        return s->ccr;
248 27c7ca7e bellard
    case 0x1f000030:                /* Processor version PVR */
249 27c7ca7e bellard
        return 0x00050000;        /* SH7750R */
250 27c7ca7e bellard
    case 0x1f000040:                /* Processor version CVR */
251 27c7ca7e bellard
        return 0x00110000;        /* Minimum caches */
252 27c7ca7e bellard
    case 0x1f000044:                /* Processor version PRR */
253 27c7ca7e bellard
        return 0x00000100;        /* SH7750R */
254 27c7ca7e bellard
    default:
255 27c7ca7e bellard
        error_access("long read", addr);
256 27c7ca7e bellard
        assert(0);
257 27c7ca7e bellard
    }
258 27c7ca7e bellard
}
259 27c7ca7e bellard
260 27c7ca7e bellard
static void sh7750_mem_writeb(void *opaque, target_phys_addr_t addr,
261 27c7ca7e bellard
                              uint32_t mem_value)
262 27c7ca7e bellard
{
263 27c7ca7e bellard
    switch (addr) {
264 27c7ca7e bellard
        /* PRECHARGE ? XXXXX */
265 27c7ca7e bellard
    case SH7750_PRECHARGE0_A7:
266 27c7ca7e bellard
    case SH7750_PRECHARGE1_A7:
267 27c7ca7e bellard
        ignore_access("byte write", addr);
268 27c7ca7e bellard
        return;
269 27c7ca7e bellard
    default:
270 27c7ca7e bellard
        error_access("byte write", addr);
271 27c7ca7e bellard
        assert(0);
272 27c7ca7e bellard
    }
273 27c7ca7e bellard
}
274 27c7ca7e bellard
275 27c7ca7e bellard
static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
276 27c7ca7e bellard
                              uint32_t mem_value)
277 27c7ca7e bellard
{
278 27c7ca7e bellard
    SH7750State *s = opaque;
279 27c7ca7e bellard
    uint16_t temp;
280 27c7ca7e bellard
281 27c7ca7e bellard
    switch (addr) {
282 27c7ca7e bellard
        /* SDRAM controller */
283 27c7ca7e bellard
    case SH7750_BCR2_A7:
284 27c7ca7e bellard
    case SH7750_BCR3_A7:
285 27c7ca7e bellard
    case SH7750_RTCOR_A7:
286 27c7ca7e bellard
    case SH7750_RTCNT_A7:
287 27c7ca7e bellard
    case SH7750_RTCSR_A7:
288 27c7ca7e bellard
        ignore_access("word write", addr);
289 27c7ca7e bellard
        return;
290 27c7ca7e bellard
        /* IO ports */
291 27c7ca7e bellard
    case SH7750_PDTRA_A7:
292 27c7ca7e bellard
        temp = porta_lines(s);
293 27c7ca7e bellard
        s->pdtra = mem_value;
294 27c7ca7e bellard
        porta_changed(s, temp);
295 27c7ca7e bellard
        return;
296 27c7ca7e bellard
    case SH7750_PDTRB_A7:
297 27c7ca7e bellard
        temp = portb_lines(s);
298 27c7ca7e bellard
        s->pdtrb = mem_value;
299 27c7ca7e bellard
        portb_changed(s, temp);
300 27c7ca7e bellard
        return;
301 27c7ca7e bellard
    case SH7750_RFCR_A7:
302 27c7ca7e bellard
        fprintf(stderr, "Write access to refresh count register\n");
303 27c7ca7e bellard
        s->rfcr = mem_value;
304 27c7ca7e bellard
        return;
305 27c7ca7e bellard
    case SH7750_GPIOIC_A7:
306 27c7ca7e bellard
        s->gpioic = mem_value;
307 27c7ca7e bellard
        if (mem_value != 0) {
308 27c7ca7e bellard
            fprintf(stderr, "I/O interrupts not implemented\n");
309 27c7ca7e bellard
            assert(0);
310 27c7ca7e bellard
        }
311 27c7ca7e bellard
        return;
312 3464c589 ths
    case 0x1fd00000:
313 3464c589 ths
        s->icr = mem_value;
314 3464c589 ths
        return;
315 27c7ca7e bellard
    default:
316 27c7ca7e bellard
        error_access("word write", addr);
317 27c7ca7e bellard
        assert(0);
318 27c7ca7e bellard
    }
319 27c7ca7e bellard
}
320 27c7ca7e bellard
321 27c7ca7e bellard
static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,
322 27c7ca7e bellard
                              uint32_t mem_value)
323 27c7ca7e bellard
{
324 27c7ca7e bellard
    SH7750State *s = opaque;
325 27c7ca7e bellard
    uint16_t temp;
326 27c7ca7e bellard
327 27c7ca7e bellard
    switch (addr) {
328 27c7ca7e bellard
        /* SDRAM controller */
329 27c7ca7e bellard
    case SH7750_BCR1_A7:
330 27c7ca7e bellard
    case SH7750_BCR4_A7:
331 27c7ca7e bellard
    case SH7750_WCR1_A7:
332 27c7ca7e bellard
    case SH7750_WCR2_A7:
333 27c7ca7e bellard
    case SH7750_WCR3_A7:
334 27c7ca7e bellard
    case SH7750_MCR_A7:
335 27c7ca7e bellard
        ignore_access("long write", addr);
336 27c7ca7e bellard
        return;
337 27c7ca7e bellard
        /* IO ports */
338 27c7ca7e bellard
    case SH7750_PCTRA_A7:
339 27c7ca7e bellard
        temp = porta_lines(s);
340 27c7ca7e bellard
        s->pctra = mem_value;
341 27c7ca7e bellard
        s->portdira = portdir(mem_value);
342 27c7ca7e bellard
        s->portpullupa = portpullup(mem_value);
343 27c7ca7e bellard
        porta_changed(s, temp);
344 27c7ca7e bellard
        return;
345 27c7ca7e bellard
    case SH7750_PCTRB_A7:
346 27c7ca7e bellard
        temp = portb_lines(s);
347 27c7ca7e bellard
        s->pctrb = mem_value;
348 27c7ca7e bellard
        s->portdirb = portdir(mem_value);
349 27c7ca7e bellard
        s->portpullupb = portpullup(mem_value);
350 27c7ca7e bellard
        portb_changed(s, temp);
351 27c7ca7e bellard
        return;
352 27c7ca7e bellard
    case SH7750_MMUCR_A7:
353 27c7ca7e bellard
        s->cpu->mmucr = mem_value;
354 27c7ca7e bellard
        return;
355 27c7ca7e bellard
    case SH7750_PTEH_A7:
356 27c7ca7e bellard
        s->cpu->pteh = mem_value;
357 27c7ca7e bellard
        return;
358 27c7ca7e bellard
    case SH7750_PTEL_A7:
359 27c7ca7e bellard
        s->cpu->ptel = mem_value;
360 27c7ca7e bellard
        return;
361 27c7ca7e bellard
    case SH7750_TTB_A7:
362 27c7ca7e bellard
        s->cpu->ttb = mem_value;
363 27c7ca7e bellard
        return;
364 27c7ca7e bellard
    case SH7750_TEA_A7:
365 27c7ca7e bellard
        s->cpu->tea = mem_value;
366 27c7ca7e bellard
        return;
367 27c7ca7e bellard
    case SH7750_TRA_A7:
368 27c7ca7e bellard
        s->cpu->tra = mem_value & 0x000007ff;
369 27c7ca7e bellard
        return;
370 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
371 27c7ca7e bellard
        s->cpu->expevt = mem_value & 0x000007ff;
372 27c7ca7e bellard
        return;
373 27c7ca7e bellard
    case SH7750_INTEVT_A7:
374 27c7ca7e bellard
        s->cpu->intevt = mem_value & 0x000007ff;
375 27c7ca7e bellard
        return;
376 27c7ca7e bellard
    case SH7750_CCR_A7:
377 27c7ca7e bellard
        s->ccr = mem_value;
378 27c7ca7e bellard
        return;
379 27c7ca7e bellard
    default:
380 27c7ca7e bellard
        error_access("long write", addr);
381 27c7ca7e bellard
        assert(0);
382 27c7ca7e bellard
    }
383 27c7ca7e bellard
}
384 27c7ca7e bellard
385 27c7ca7e bellard
static CPUReadMemoryFunc *sh7750_mem_read[] = {
386 27c7ca7e bellard
    sh7750_mem_readb,
387 27c7ca7e bellard
    sh7750_mem_readw,
388 27c7ca7e bellard
    sh7750_mem_readl
389 27c7ca7e bellard
};
390 27c7ca7e bellard
391 27c7ca7e bellard
static CPUWriteMemoryFunc *sh7750_mem_write[] = {
392 27c7ca7e bellard
    sh7750_mem_writeb,
393 27c7ca7e bellard
    sh7750_mem_writew,
394 27c7ca7e bellard
    sh7750_mem_writel
395 27c7ca7e bellard
};
396 27c7ca7e bellard
397 80f515e6 balrog
/* sh775x interrupt controller tables for sh_intc.c
398 80f515e6 balrog
 * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
399 80f515e6 balrog
 */
400 80f515e6 balrog
401 80f515e6 balrog
enum {
402 80f515e6 balrog
        UNUSED = 0,
403 80f515e6 balrog
404 80f515e6 balrog
        /* interrupt sources */
405 80f515e6 balrog
        IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
406 80f515e6 balrog
        HUDI, GPIOI,
407 80f515e6 balrog
        DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3,
408 80f515e6 balrog
        DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7,
409 80f515e6 balrog
        DMAC_DMAE,
410 80f515e6 balrog
        PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
411 80f515e6 balrog
        PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
412 80f515e6 balrog
        TMU3, TMU4, TMU0, TMU1, TMU2_TUNI, TMU2_TICPI,
413 80f515e6 balrog
        RTC_ATI, RTC_PRI, RTC_CUI,
414 80f515e6 balrog
        SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI,
415 80f515e6 balrog
        SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI,
416 80f515e6 balrog
        WDT,
417 80f515e6 balrog
        REF_RCMI, REF_ROVI,
418 80f515e6 balrog
419 80f515e6 balrog
        /* interrupt groups */
420 80f515e6 balrog
        DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF,
421 80f515e6 balrog
422 80f515e6 balrog
        NR_SOURCES,
423 80f515e6 balrog
};
424 80f515e6 balrog
425 80f515e6 balrog
static struct intc_vect vectors[] = {
426 80f515e6 balrog
        INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
427 80f515e6 balrog
        INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
428 80f515e6 balrog
        INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460),
429 80f515e6 balrog
        INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0),
430 80f515e6 balrog
        INTC_VECT(RTC_CUI, 0x4c0),
431 80f515e6 balrog
        INTC_VECT(SCI1_ERI, 0x4e0), INTC_VECT(SCI1_RXI, 0x500),
432 80f515e6 balrog
        INTC_VECT(SCI1_TXI, 0x520), INTC_VECT(SCI1_TEI, 0x540),
433 80f515e6 balrog
        INTC_VECT(SCIF_ERI, 0x700), INTC_VECT(SCIF_RXI, 0x720),
434 80f515e6 balrog
        INTC_VECT(SCIF_BRI, 0x740), INTC_VECT(SCIF_TXI, 0x760),
435 80f515e6 balrog
        INTC_VECT(WDT, 0x560),
436 80f515e6 balrog
        INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0),
437 80f515e6 balrog
};
438 80f515e6 balrog
439 80f515e6 balrog
static struct intc_group groups[] = {
440 80f515e6 balrog
        INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
441 80f515e6 balrog
        INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
442 80f515e6 balrog
        INTC_GROUP(SCI1, SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI),
443 80f515e6 balrog
        INTC_GROUP(SCIF, SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI),
444 80f515e6 balrog
        INTC_GROUP(REF, REF_RCMI, REF_ROVI),
445 80f515e6 balrog
};
446 80f515e6 balrog
447 80f515e6 balrog
static struct intc_prio_reg prio_registers[] = {
448 80f515e6 balrog
        { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
449 80f515e6 balrog
        { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
450 80f515e6 balrog
        { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
451 80f515e6 balrog
        { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
452 80f515e6 balrog
        { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
453 80f515e6 balrog
                                                 TMU4, TMU3,
454 80f515e6 balrog
                                                 PCIC1, PCIC0_PCISERR } },
455 80f515e6 balrog
};
456 80f515e6 balrog
457 80f515e6 balrog
/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
458 80f515e6 balrog
459 80f515e6 balrog
static struct intc_vect vectors_dma4[] = {
460 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
461 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
462 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
463 80f515e6 balrog
};
464 80f515e6 balrog
465 80f515e6 balrog
static struct intc_group groups_dma4[] = {
466 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
467 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMAE),
468 80f515e6 balrog
};
469 80f515e6 balrog
470 80f515e6 balrog
/* SH7750R and SH7751R both have 8-channel DMA controllers */
471 80f515e6 balrog
472 80f515e6 balrog
static struct intc_vect vectors_dma8[] = {
473 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
474 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
475 80f515e6 balrog
        INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0),
476 80f515e6 balrog
        INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0),
477 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
478 80f515e6 balrog
};
479 80f515e6 balrog
480 80f515e6 balrog
static struct intc_group groups_dma8[] = {
481 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
482 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5,
483 80f515e6 balrog
                   DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE),
484 80f515e6 balrog
};
485 80f515e6 balrog
486 80f515e6 balrog
/* SH7750R, SH7751 and SH7751R all have two extra timer channels */
487 80f515e6 balrog
488 80f515e6 balrog
static struct intc_vect vectors_tmu34[] = {
489 80f515e6 balrog
        INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
490 80f515e6 balrog
};
491 80f515e6 balrog
492 80f515e6 balrog
static struct intc_mask_reg mask_registers[] = {
493 80f515e6 balrog
        { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
494 80f515e6 balrog
          { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
495 80f515e6 balrog
            0, 0, 0, 0, 0, 0, TMU4, TMU3,
496 80f515e6 balrog
            PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
497 80f515e6 balrog
            PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
498 80f515e6 balrog
            PCIC1_PCIDMA3, PCIC0_PCISERR } },
499 80f515e6 balrog
};
500 80f515e6 balrog
501 80f515e6 balrog
/* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
502 80f515e6 balrog
503 80f515e6 balrog
static struct intc_vect vectors_irlm[] = {
504 80f515e6 balrog
        INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
505 80f515e6 balrog
        INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
506 80f515e6 balrog
};
507 80f515e6 balrog
508 80f515e6 balrog
/* SH7751 and SH7751R both have PCI */
509 80f515e6 balrog
510 80f515e6 balrog
static struct intc_vect vectors_pci[] = {
511 80f515e6 balrog
        INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
512 80f515e6 balrog
        INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
513 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
514 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
515 80f515e6 balrog
};
516 80f515e6 balrog
517 80f515e6 balrog
static struct intc_group groups_pci[] = {
518 80f515e6 balrog
        INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
519 80f515e6 balrog
                   PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
520 80f515e6 balrog
};
521 80f515e6 balrog
522 80f515e6 balrog
#define SH_CPU_SH7750  (1 << 0)
523 80f515e6 balrog
#define SH_CPU_SH7750S (1 << 1)
524 80f515e6 balrog
#define SH_CPU_SH7750R (1 << 2)
525 80f515e6 balrog
#define SH_CPU_SH7751  (1 << 3)
526 80f515e6 balrog
#define SH_CPU_SH7751R (1 << 4)
527 80f515e6 balrog
#define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R)
528 80f515e6 balrog
#define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R)
529 80f515e6 balrog
530 27c7ca7e bellard
SH7750State *sh7750_init(CPUSH4State * cpu)
531 27c7ca7e bellard
{
532 27c7ca7e bellard
    SH7750State *s;
533 27c7ca7e bellard
    int sh7750_io_memory;
534 80f515e6 balrog
    int cpu_model = SH_CPU_SH7751R; /* for now */
535 27c7ca7e bellard
536 27c7ca7e bellard
    s = qemu_mallocz(sizeof(SH7750State));
537 27c7ca7e bellard
    s->cpu = cpu;
538 27c7ca7e bellard
    s->periph_freq = 60000000;        /* 60MHz */
539 27c7ca7e bellard
    sh7750_io_memory = cpu_register_io_memory(0,
540 27c7ca7e bellard
                                              sh7750_mem_read,
541 27c7ca7e bellard
                                              sh7750_mem_write, s);
542 27c7ca7e bellard
    cpu_register_physical_memory(0x1c000000, 0x04000000, sh7750_io_memory);
543 2f062c72 ths
544 80f515e6 balrog
    sh_intc_init(&s->intc, NR_SOURCES,
545 80f515e6 balrog
                 _INTC_ARRAY(mask_registers),
546 80f515e6 balrog
                 _INTC_ARRAY(prio_registers));
547 80f515e6 balrog
548 80f515e6 balrog
    sh_intc_register_sources(&s->intc, 
549 80f515e6 balrog
                             _INTC_ARRAY(vectors),
550 80f515e6 balrog
                             _INTC_ARRAY(groups));
551 80f515e6 balrog
552 2f062c72 ths
    sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0]);
553 2f062c72 ths
    sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF,
554 2f062c72 ths
                   s->periph_freq, serial_hds[1]);
555 cd1a3f68 ths
556 cd1a3f68 ths
    tmu012_init(0x1fd80000,
557 cd1a3f68 ths
                TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK,
558 cd1a3f68 ths
                s->periph_freq);
559 80f515e6 balrog
560 80f515e6 balrog
561 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
562 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
563 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma4),
564 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma4));
565 80f515e6 balrog
    }
566 80f515e6 balrog
567 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
568 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
569 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma8),
570 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma8));
571 80f515e6 balrog
    }
572 80f515e6 balrog
573 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750R | SH_CPU_SH7751 | SH_CPU_SH7751R)) {
574 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
575 80f515e6 balrog
                                 _INTC_ARRAY(vectors_tmu34),
576 80f515e6 balrog
                                 _INTC_ARRAY(NULL));
577 80f515e6 balrog
        tmu012_init(0x1e100000, 0, s->periph_freq);
578 80f515e6 balrog
    }
579 80f515e6 balrog
580 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7751_ALL)) {
581 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
582 80f515e6 balrog
                                 _INTC_ARRAY(vectors_pci),
583 80f515e6 balrog
                                 _INTC_ARRAY(groups_pci));
584 80f515e6 balrog
    }
585 80f515e6 balrog
586 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750S | SH_CPU_SH7750R | SH_CPU_SH7751_ALL)) {
587 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
588 80f515e6 balrog
                                 _INTC_ARRAY(vectors_irlm),
589 80f515e6 balrog
                                 _INTC_ARRAY(NULL));
590 80f515e6 balrog
    }
591 80f515e6 balrog
592 27c7ca7e bellard
    return s;
593 27c7ca7e bellard
}