~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to hw/ppc405_uc.c

  • Committer: blueswir1
  • Date: 2007-09-25 17:28:42 UTC
  • Revision ID: git-v1:c2efc95d45fd4c76d4650a34a2a2676b87a93ac4
 Fix monitor expressions


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3238 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
 * THE SOFTWARE.
23
23
 */
24
 
#include "hw.h"
25
 
#include "ppc.h"
 
24
#include "vl.h"
26
25
#include "ppc405.h"
27
 
#include "pc.h"
28
 
#include "qemu-timer.h"
29
 
#include "sysemu.h"
30
 
#include "qemu-log.h"
31
 
 
 
26
 
 
27
extern int loglevel;
 
28
extern FILE *logfile;
 
29
 
 
30
//#define DEBUG_MMIO
32
31
#define DEBUG_OPBA
33
32
#define DEBUG_SDRAM
34
33
#define DEBUG_GPIO
37
36
//#define DEBUG_I2C
38
37
#define DEBUG_GPT
39
38
#define DEBUG_MAL
 
39
#define DEBUG_UIC
40
40
#define DEBUG_CLOCKS
41
 
//#define DEBUG_CLOCKS_LL
42
 
 
43
 
ram_addr_t ppc405_set_bootinfo (CPUState *env, ppc4xx_bd_info_t *bd,
44
 
                                uint32_t flags)
 
41
//#define DEBUG_UNASSIGNED
 
42
 
 
43
/*****************************************************************************/
 
44
/* Generic PowerPC 405 processor instanciation */
 
45
CPUState *ppc405_init (const unsigned char *cpu_model,
 
46
                       clk_setup_t *cpu_clk, clk_setup_t *tb_clk,
 
47
                       uint32_t sysclk)
 
48
{
 
49
    CPUState *env;
 
50
    ppc_def_t *def;
 
51
 
 
52
    /* init CPUs */
 
53
    env = cpu_init();
 
54
    qemu_register_reset(&cpu_ppc_reset, env);
 
55
    register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
 
56
    ppc_find_by_name(cpu_model, &def);
 
57
    if (def == NULL) {
 
58
        cpu_abort(env, "Unable to find PowerPC %s CPU definition\n",
 
59
                  cpu_model);
 
60
    }
 
61
    cpu_ppc_register(env, def);
 
62
    cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */
 
63
    cpu_clk->opaque = env;
 
64
    /* Set time-base frequency to sysclk */
 
65
    tb_clk->cb = ppc_emb_timers_init(env, sysclk);
 
66
    tb_clk->opaque = env;
 
67
    ppc_dcr_init(env, NULL, NULL);
 
68
 
 
69
    return env;
 
70
}
 
71
 
 
72
ram_addr_t ppc405_set_bootinfo (CPUState *env, ppc4xx_bd_info_t *bd)
45
73
{
46
74
    ram_addr_t bdloc;
47
75
    int i, n;
75
103
    for (i = 0; i < 6; i++)
76
104
        stb_raw(phys_ram_base + bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]);
77
105
    n = 0x6A;
78
 
    if (flags & 0x00000001) {
 
106
    if (env->spr[SPR_PVR] == CPU_PPC_405EP) {
79
107
        for (i = 0; i < 6; i++)
80
108
            stb_raw(phys_ram_base + bdloc + n++, bd->bi_pci_enetaddr2[i]);
81
109
    }
93
121
/* Shared peripherals */
94
122
 
95
123
/*****************************************************************************/
 
124
/* Fake device used to map multiple devices in a single memory page */
 
125
#define MMIO_AREA_BITS 8
 
126
#define MMIO_AREA_LEN (1 << MMIO_AREA_BITS)
 
127
#define MMIO_AREA_NB (1 << (TARGET_PAGE_BITS - MMIO_AREA_BITS))
 
128
#define MMIO_IDX(addr) (((addr) >> MMIO_AREA_BITS) & (MMIO_AREA_NB - 1))
 
129
struct ppc4xx_mmio_t {
 
130
    target_phys_addr_t base;
 
131
    CPUReadMemoryFunc **mem_read[MMIO_AREA_NB];
 
132
    CPUWriteMemoryFunc **mem_write[MMIO_AREA_NB];
 
133
    void *opaque[MMIO_AREA_NB];
 
134
};
 
135
 
 
136
static uint32_t unassigned_mmio_readb (void *opaque, target_phys_addr_t addr)
 
137
{
 
138
#ifdef DEBUG_UNASSIGNED
 
139
    ppc4xx_mmio_t *mmio;
 
140
 
 
141
    mmio = opaque;
 
142
    printf("Unassigned mmio read 0x" PADDRX " base " PADDRX "\n",
 
143
           addr, mmio->base);
 
144
#endif
 
145
 
 
146
    return 0;
 
147
}
 
148
 
 
149
static void unassigned_mmio_writeb (void *opaque,
 
150
                                   target_phys_addr_t addr, uint32_t val)
 
151
{
 
152
#ifdef DEBUG_UNASSIGNED
 
153
    ppc4xx_mmio_t *mmio;
 
154
 
 
155
    mmio = opaque;
 
156
    printf("Unassigned mmio write 0x" PADDRX " = 0x%x base " PADDRX "\n",
 
157
           addr, val, mmio->base);
 
158
#endif
 
159
}
 
160
 
 
161
static CPUReadMemoryFunc *unassigned_mmio_read[3] = {
 
162
    unassigned_mmio_readb,
 
163
    unassigned_mmio_readb,
 
164
    unassigned_mmio_readb,
 
165
};
 
166
 
 
167
static CPUWriteMemoryFunc *unassigned_mmio_write[3] = {
 
168
    unassigned_mmio_writeb,
 
169
    unassigned_mmio_writeb,
 
170
    unassigned_mmio_writeb,
 
171
};
 
172
 
 
173
static uint32_t mmio_readlen (ppc4xx_mmio_t *mmio,
 
174
                              target_phys_addr_t addr, int len)
 
175
{
 
176
    CPUReadMemoryFunc **mem_read;
 
177
    uint32_t ret;
 
178
    int idx;
 
179
 
 
180
    idx = MMIO_IDX(addr - mmio->base);
 
181
#if defined(DEBUG_MMIO)
 
182
    printf("%s: mmio %p len %d addr " PADDRX " idx %d\n", __func__,
 
183
           mmio, len, addr, idx);
 
184
#endif
 
185
    mem_read = mmio->mem_read[idx];
 
186
    ret = (*mem_read[len])(mmio->opaque[idx], addr - mmio->base);
 
187
 
 
188
    return ret;
 
189
}
 
190
 
 
191
static void mmio_writelen (ppc4xx_mmio_t *mmio,
 
192
                           target_phys_addr_t addr, uint32_t value, int len)
 
193
{
 
194
    CPUWriteMemoryFunc **mem_write;
 
195
    int idx;
 
196
 
 
197
    idx = MMIO_IDX(addr - mmio->base);
 
198
#if defined(DEBUG_MMIO)
 
199
    printf("%s: mmio %p len %d addr " PADDRX " idx %d value %08x\n", __func__,
 
200
           mmio, len, addr, idx, value);
 
201
#endif
 
202
    mem_write = mmio->mem_write[idx];
 
203
    (*mem_write[len])(mmio->opaque[idx], addr - mmio->base, value);
 
204
}
 
205
 
 
206
static uint32_t mmio_readb (void *opaque, target_phys_addr_t addr)
 
207
{
 
208
#if defined(DEBUG_MMIO)
 
209
    printf("%s: addr " PADDRX "\n", __func__, addr);
 
210
#endif
 
211
 
 
212
    return mmio_readlen(opaque, addr, 0);
 
213
}
 
214
 
 
215
static void mmio_writeb (void *opaque,
 
216
                         target_phys_addr_t addr, uint32_t value)
 
217
{
 
218
#if defined(DEBUG_MMIO)
 
219
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
 
220
#endif
 
221
    mmio_writelen(opaque, addr, value, 0);
 
222
}
 
223
 
 
224
static uint32_t mmio_readw (void *opaque, target_phys_addr_t addr)
 
225
{
 
226
#if defined(DEBUG_MMIO)
 
227
    printf("%s: addr " PADDRX "\n", __func__, addr);
 
228
#endif
 
229
 
 
230
    return mmio_readlen(opaque, addr, 1);
 
231
}
 
232
 
 
233
static void mmio_writew (void *opaque,
 
234
                         target_phys_addr_t addr, uint32_t value)
 
235
{
 
236
#if defined(DEBUG_MMIO)
 
237
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
 
238
#endif
 
239
    mmio_writelen(opaque, addr, value, 1);
 
240
}
 
241
 
 
242
static uint32_t mmio_readl (void *opaque, target_phys_addr_t addr)
 
243
{
 
244
#if defined(DEBUG_MMIO)
 
245
    printf("%s: addr " PADDRX "\n", __func__, addr);
 
246
#endif
 
247
 
 
248
    return mmio_readlen(opaque, addr, 2);
 
249
}
 
250
 
 
251
static void mmio_writel (void *opaque,
 
252
                         target_phys_addr_t addr, uint32_t value)
 
253
{
 
254
#if defined(DEBUG_MMIO)
 
255
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
 
256
#endif
 
257
    mmio_writelen(opaque, addr, value, 2);
 
258
}
 
259
 
 
260
static CPUReadMemoryFunc *mmio_read[] = {
 
261
    &mmio_readb,
 
262
    &mmio_readw,
 
263
    &mmio_readl,
 
264
};
 
265
 
 
266
static CPUWriteMemoryFunc *mmio_write[] = {
 
267
    &mmio_writeb,
 
268
    &mmio_writew,
 
269
    &mmio_writel,
 
270
};
 
271
 
 
272
int ppc4xx_mmio_register (CPUState *env, ppc4xx_mmio_t *mmio,
 
273
                          target_phys_addr_t offset, uint32_t len,
 
274
                          CPUReadMemoryFunc **mem_read,
 
275
                          CPUWriteMemoryFunc **mem_write, void *opaque)
 
276
{
 
277
    uint32_t end;
 
278
    int idx, eidx;
 
279
 
 
280
    if ((offset + len) > TARGET_PAGE_SIZE)
 
281
        return -1;
 
282
    idx = MMIO_IDX(offset);
 
283
    end = offset + len - 1;
 
284
    eidx = MMIO_IDX(end);
 
285
#if defined(DEBUG_MMIO)
 
286
    printf("%s: offset %08x len %08x %08x %d %d\n", __func__, offset, len,
 
287
           end, idx, eidx);
 
288
#endif
 
289
    for (; idx <= eidx; idx++) {
 
290
        mmio->mem_read[idx] = mem_read;
 
291
        mmio->mem_write[idx] = mem_write;
 
292
        mmio->opaque[idx] = opaque;
 
293
    }
 
294
 
 
295
    return 0;
 
296
}
 
297
 
 
298
ppc4xx_mmio_t *ppc4xx_mmio_init (CPUState *env, target_phys_addr_t base)
 
299
{
 
300
    ppc4xx_mmio_t *mmio;
 
301
    int mmio_memory;
 
302
 
 
303
    mmio = qemu_mallocz(sizeof(ppc4xx_mmio_t));
 
304
    if (mmio != NULL) {
 
305
        mmio->base = base;
 
306
        mmio_memory = cpu_register_io_memory(0, mmio_read, mmio_write, mmio);
 
307
#if defined(DEBUG_MMIO)
 
308
        printf("%s: %p base %08x len %08x %d\n", __func__,
 
309
               mmio, base, TARGET_PAGE_SIZE, mmio_memory);
 
310
#endif
 
311
        cpu_register_physical_memory(base, TARGET_PAGE_SIZE, mmio_memory);
 
312
        ppc4xx_mmio_register(env, mmio, 0, TARGET_PAGE_SIZE,
 
313
                             unassigned_mmio_read, unassigned_mmio_write,
 
314
                             mmio);
 
315
    }
 
316
 
 
317
    return mmio;
 
318
}
 
319
 
 
320
/*****************************************************************************/
96
321
/* Peripheral local bus arbitrer */
97
322
enum {
98
323
    PLB0_BESR = 0x084,
296
521
    ppc4xx_opba_t *opba;
297
522
 
298
523
#ifdef DEBUG_OPBA
299
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
524
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
300
525
#endif
301
526
    opba = opaque;
302
527
    switch (addr - opba->base) {
328
553
                         target_phys_addr_t addr, uint32_t value)
329
554
{
330
555
#ifdef DEBUG_OPBA
331
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
556
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
332
557
#endif
333
558
    opba_writeb(opaque, addr, value >> 8);
334
559
    opba_writeb(opaque, addr + 1, value);
351
576
                         target_phys_addr_t addr, uint32_t value)
352
577
{
353
578
#ifdef DEBUG_OPBA
354
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
579
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
355
580
#endif
356
581
    opba_writeb(opaque, addr, value >> 24);
357
582
    opba_writeb(opaque, addr + 1, value >> 16);
387
612
    if (opba != NULL) {
388
613
        opba->base = offset;
389
614
#ifdef DEBUG_OPBA
390
 
        printf("%s: offset " PADDRX "\n", __func__, offset);
 
615
        printf("%s: offset=" PADDRX "\n", __func__, offset);
391
616
#endif
392
617
        ppc4xx_mmio_register(env, mmio, offset, 0x002,
393
618
                             opba_read, opba_write, opba);
397
622
}
398
623
 
399
624
/*****************************************************************************/
 
625
/* "Universal" Interrupt controller */
 
626
enum {
 
627
    DCR_UICSR  = 0x000,
 
628
    DCR_UICSRS = 0x001,
 
629
    DCR_UICER  = 0x002,
 
630
    DCR_UICCR  = 0x003,
 
631
    DCR_UICPR  = 0x004,
 
632
    DCR_UICTR  = 0x005,
 
633
    DCR_UICMSR = 0x006,
 
634
    DCR_UICVR  = 0x007,
 
635
    DCR_UICVCR = 0x008,
 
636
    DCR_UICMAX = 0x009,
 
637
};
 
638
 
 
639
#define UIC_MAX_IRQ 32
 
640
typedef struct ppcuic_t ppcuic_t;
 
641
struct ppcuic_t {
 
642
    uint32_t dcr_base;
 
643
    int use_vectors;
 
644
    uint32_t uicsr;  /* Status register */
 
645
    uint32_t uicer;  /* Enable register */
 
646
    uint32_t uiccr;  /* Critical register */
 
647
    uint32_t uicpr;  /* Polarity register */
 
648
    uint32_t uictr;  /* Triggering register */
 
649
    uint32_t uicvcr; /* Vector configuration register */
 
650
    uint32_t uicvr;
 
651
    qemu_irq *irqs;
 
652
};
 
653
 
 
654
static void ppcuic_trigger_irq (ppcuic_t *uic)
 
655
{
 
656
    uint32_t ir, cr;
 
657
    int start, end, inc, i;
 
658
 
 
659
    /* Trigger interrupt if any is pending */
 
660
    ir = uic->uicsr & uic->uicer & (~uic->uiccr);
 
661
    cr = uic->uicsr & uic->uicer & uic->uiccr;
 
662
#ifdef DEBUG_UIC
 
663
    if (loglevel & CPU_LOG_INT) {
 
664
        fprintf(logfile, "%s: uicsr %08x uicer %08x uiccr %08x\n"
 
665
                "   %08x ir %08x cr %08x\n", __func__,
 
666
                uic->uicsr, uic->uicer, uic->uiccr,
 
667
                uic->uicsr & uic->uicer, ir, cr);
 
668
    }
 
669
#endif
 
670
    if (ir != 0x0000000) {
 
671
#ifdef DEBUG_UIC
 
672
        if (loglevel & CPU_LOG_INT) {
 
673
            fprintf(logfile, "Raise UIC interrupt\n");
 
674
        }
 
675
#endif
 
676
        qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_INT]);
 
677
    } else {
 
678
#ifdef DEBUG_UIC
 
679
        if (loglevel & CPU_LOG_INT) {
 
680
            fprintf(logfile, "Lower UIC interrupt\n");
 
681
        }
 
682
#endif
 
683
        qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_INT]);
 
684
    }
 
685
    /* Trigger critical interrupt if any is pending and update vector */
 
686
    if (cr != 0x0000000) {
 
687
        qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_CINT]);
 
688
        if (uic->use_vectors) {
 
689
            /* Compute critical IRQ vector */
 
690
            if (uic->uicvcr & 1) {
 
691
                start = 31;
 
692
                end = 0;
 
693
                inc = -1;
 
694
            } else {
 
695
                start = 0;
 
696
                end = 31;
 
697
                inc = 1;
 
698
            }
 
699
            uic->uicvr = uic->uicvcr & 0xFFFFFFFC;
 
700
            for (i = start; i <= end; i += inc) {
 
701
                if (cr & (1 << i)) {
 
702
                    uic->uicvr += (i - start) * 512 * inc;
 
703
                    break;
 
704
                }
 
705
            }
 
706
        }
 
707
#ifdef DEBUG_UIC
 
708
        if (loglevel & CPU_LOG_INT) {
 
709
            fprintf(logfile, "Raise UIC critical interrupt - vector %08x\n",
 
710
                    uic->uicvr);
 
711
        }
 
712
#endif
 
713
    } else {
 
714
#ifdef DEBUG_UIC
 
715
        if (loglevel & CPU_LOG_INT) {
 
716
            fprintf(logfile, "Lower UIC critical interrupt\n");
 
717
        }
 
718
#endif
 
719
        qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_CINT]);
 
720
        uic->uicvr = 0x00000000;
 
721
    }
 
722
}
 
723
 
 
724
static void ppcuic_set_irq (void *opaque, int irq_num, int level)
 
725
{
 
726
    ppcuic_t *uic;
 
727
    uint32_t mask, sr;
 
728
 
 
729
    uic = opaque;
 
730
    mask = 1 << irq_num;
 
731
#ifdef DEBUG_UIC
 
732
    if (loglevel & CPU_LOG_INT) {
 
733
        fprintf(logfile, "%s: irq %d level %d uicsr %08x mask %08x => %08x "
 
734
                "%08x\n", __func__, irq_num, level,
 
735
                uic->uicsr, mask, uic->uicsr & mask, level << irq_num);
 
736
    }
 
737
#endif
 
738
    if (irq_num < 0 || irq_num > 31)
 
739
        return;
 
740
    sr = uic->uicsr;
 
741
    if (!(uic->uicpr & mask)) {
 
742
        /* Negatively asserted IRQ */
 
743
        level = level == 0 ? 1 : 0;
 
744
    }
 
745
    /* Update status register */
 
746
    if (uic->uictr & mask) {
 
747
        /* Edge sensitive interrupt */
 
748
        if (level == 1)
 
749
            uic->uicsr |= mask;
 
750
    } else {
 
751
        /* Level sensitive interrupt */
 
752
        if (level == 1)
 
753
            uic->uicsr |= mask;
 
754
        else
 
755
            uic->uicsr &= ~mask;
 
756
    }
 
757
#ifdef DEBUG_UIC
 
758
    if (loglevel & CPU_LOG_INT) {
 
759
        fprintf(logfile, "%s: irq %d level %d sr %08x => %08x\n", __func__,
 
760
                irq_num, level, uic->uicsr, sr);
 
761
    }
 
762
#endif
 
763
    if (sr != uic->uicsr)
 
764
        ppcuic_trigger_irq(uic);
 
765
}
 
766
 
 
767
static target_ulong dcr_read_uic (void *opaque, int dcrn)
 
768
{
 
769
    ppcuic_t *uic;
 
770
    target_ulong ret;
 
771
 
 
772
    uic = opaque;
 
773
    dcrn -= uic->dcr_base;
 
774
    switch (dcrn) {
 
775
    case DCR_UICSR:
 
776
    case DCR_UICSRS:
 
777
        ret = uic->uicsr;
 
778
        break;
 
779
    case DCR_UICER:
 
780
        ret = uic->uicer;
 
781
        break;
 
782
    case DCR_UICCR:
 
783
        ret = uic->uiccr;
 
784
        break;
 
785
    case DCR_UICPR:
 
786
        ret = uic->uicpr;
 
787
        break;
 
788
    case DCR_UICTR:
 
789
        ret = uic->uictr;
 
790
        break;
 
791
    case DCR_UICMSR:
 
792
        ret = uic->uicsr & uic->uicer;
 
793
        break;
 
794
    case DCR_UICVR:
 
795
        if (!uic->use_vectors)
 
796
            goto no_read;
 
797
        ret = uic->uicvr;
 
798
        break;
 
799
    case DCR_UICVCR:
 
800
        if (!uic->use_vectors)
 
801
            goto no_read;
 
802
        ret = uic->uicvcr;
 
803
        break;
 
804
    default:
 
805
    no_read:
 
806
        ret = 0x00000000;
 
807
        break;
 
808
    }
 
809
 
 
810
    return ret;
 
811
}
 
812
 
 
813
static void dcr_write_uic (void *opaque, int dcrn, target_ulong val)
 
814
{
 
815
    ppcuic_t *uic;
 
816
 
 
817
    uic = opaque;
 
818
    dcrn -= uic->dcr_base;
 
819
#ifdef DEBUG_UIC
 
820
    if (loglevel & CPU_LOG_INT) {
 
821
        fprintf(logfile, "%s: dcr %d val " ADDRX "\n", __func__, dcrn, val);
 
822
    }
 
823
#endif
 
824
    switch (dcrn) {
 
825
    case DCR_UICSR:
 
826
        uic->uicsr &= ~val;
 
827
        ppcuic_trigger_irq(uic);
 
828
        break;
 
829
    case DCR_UICSRS:
 
830
        uic->uicsr |= val;
 
831
        ppcuic_trigger_irq(uic);
 
832
        break;
 
833
    case DCR_UICER:
 
834
        uic->uicer = val;
 
835
        ppcuic_trigger_irq(uic);
 
836
        break;
 
837
    case DCR_UICCR:
 
838
        uic->uiccr = val;
 
839
        ppcuic_trigger_irq(uic);
 
840
        break;
 
841
    case DCR_UICPR:
 
842
        uic->uicpr = val;
 
843
        ppcuic_trigger_irq(uic);
 
844
        break;
 
845
    case DCR_UICTR:
 
846
        uic->uictr = val;
 
847
        ppcuic_trigger_irq(uic);
 
848
        break;
 
849
    case DCR_UICMSR:
 
850
        break;
 
851
    case DCR_UICVR:
 
852
        break;
 
853
    case DCR_UICVCR:
 
854
        uic->uicvcr = val & 0xFFFFFFFD;
 
855
        ppcuic_trigger_irq(uic);
 
856
        break;
 
857
    }
 
858
}
 
859
 
 
860
static void ppcuic_reset (void *opaque)
 
861
{
 
862
    ppcuic_t *uic;
 
863
 
 
864
    uic = opaque;
 
865
    uic->uiccr = 0x00000000;
 
866
    uic->uicer = 0x00000000;
 
867
    uic->uicpr = 0x00000000;
 
868
    uic->uicsr = 0x00000000;
 
869
    uic->uictr = 0x00000000;
 
870
    if (uic->use_vectors) {
 
871
        uic->uicvcr = 0x00000000;
 
872
        uic->uicvr = 0x0000000;
 
873
    }
 
874
}
 
875
 
 
876
qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs,
 
877
                       uint32_t dcr_base, int has_ssr, int has_vr)
 
878
{
 
879
    ppcuic_t *uic;
 
880
    int i;
 
881
 
 
882
    uic = qemu_mallocz(sizeof(ppcuic_t));
 
883
    if (uic != NULL) {
 
884
        uic->dcr_base = dcr_base;
 
885
        uic->irqs = irqs;
 
886
        if (has_vr)
 
887
            uic->use_vectors = 1;
 
888
        for (i = 0; i < DCR_UICMAX; i++) {
 
889
            ppc_dcr_register(env, dcr_base + i, uic,
 
890
                             &dcr_read_uic, &dcr_write_uic);
 
891
        }
 
892
        qemu_register_reset(ppcuic_reset, uic);
 
893
        ppcuic_reset(uic);
 
894
    }
 
895
 
 
896
    return qemu_allocate_irqs(&ppcuic_set_irq, uic, UIC_MAX_IRQ);
 
897
}
 
898
 
 
899
/*****************************************************************************/
400
900
/* Code decompression controller */
401
901
/* XXX: TODO */
402
902
 
427
927
    SDRAM0_CFGDATA = 0x011,
428
928
};
429
929
 
430
 
/* XXX: TOFIX: some patches have made this code become inconsistent:
431
 
 *      there are type inconsistencies, mixing target_phys_addr_t, target_ulong
432
 
 *      and uint32_t
433
 
 */
434
930
static uint32_t sdram_bcr (target_phys_addr_t ram_base,
435
931
                           target_phys_addr_t ram_size)
436
932
{
459
955
        bcr = 0x000C0000;
460
956
        break;
461
957
    default:
462
 
        printf("%s: invalid RAM size " PADDRX "\n", __func__, ram_size);
 
958
        printf("%s: invalid RAM size " TARGET_FMT_plx "\n",
 
959
               __func__, ram_size);
463
960
        return 0x00000000;
464
961
    }
465
962
    bcr |= ram_base & 0xFF800000;
468
965
    return bcr;
469
966
}
470
967
 
471
 
static always_inline target_phys_addr_t sdram_base (uint32_t bcr)
 
968
static inline target_phys_addr_t sdram_base (uint32_t bcr)
472
969
{
473
970
    return bcr & 0xFF800000;
474
971
}
492
989
    if (*bcrp & 0x00000001) {
493
990
        /* Unmap RAM */
494
991
#ifdef DEBUG_SDRAM
495
 
        printf("%s: unmap RAM area " PADDRX " " ADDRX "\n",
 
992
        printf("%s: unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
496
993
               __func__, sdram_base(*bcrp), sdram_size(*bcrp));
497
994
#endif
498
995
        cpu_register_physical_memory(sdram_base(*bcrp), sdram_size(*bcrp),
501
998
    *bcrp = bcr & 0xFFDEE001;
502
999
    if (enabled && (bcr & 0x00000001)) {
503
1000
#ifdef DEBUG_SDRAM
504
 
        printf("%s: Map RAM area " PADDRX " " ADDRX "\n",
 
1001
        printf("%s: Map RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
505
1002
               __func__, sdram_base(bcr), sdram_size(bcr));
506
1003
#endif
507
1004
        cpu_register_physical_memory(sdram_base(bcr), sdram_size(bcr),
530
1027
 
531
1028
    for (i = 0; i < sdram->nbanks; i++) {
532
1029
#ifdef DEBUG_SDRAM
533
 
        printf("%s: Unmap RAM area " PADDRX " " ADDRX "\n",
 
1030
        printf("%s: Unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
534
1031
               __func__, sdram_base(sdram->bcr[i]), sdram_size(sdram->bcr[i]));
535
1032
#endif
536
1033
        cpu_register_physical_memory(sdram_base(sdram->bcr[i]),
1111
1608
 
1112
1609
    gpio = opaque;
1113
1610
#ifdef DEBUG_GPIO
1114
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
1611
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1115
1612
#endif
1116
1613
}
1117
1614
 
1134
1631
 
1135
1632
    gpio = opaque;
1136
1633
#ifdef DEBUG_GPIO
1137
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
1634
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1138
1635
#endif
1139
1636
}
1140
1637
 
1157
1654
 
1158
1655
    gpio = opaque;
1159
1656
#ifdef DEBUG_GPIO
1160
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
1657
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1161
1658
#endif
1162
1659
}
1163
1660
 
1191
1688
        ppc405_gpio_reset(gpio);
1192
1689
        qemu_register_reset(&ppc405_gpio_reset, gpio);
1193
1690
#ifdef DEBUG_GPIO
1194
 
        printf("%s: offset " PADDRX "\n", __func__, offset);
 
1691
        printf("%s: offset=" PADDRX "\n", __func__, offset);
1195
1692
#endif
1196
1693
        ppc4xx_mmio_register(env, mmio, offset, 0x038,
1197
1694
                             ppc405_gpio_read, ppc405_gpio_write, gpio);
1219
1716
    void *serial;
1220
1717
 
1221
1718
#ifdef DEBUG_SERIAL
1222
 
    printf("%s: offset " PADDRX "\n", __func__, offset);
 
1719
    printf("%s: offset=" PADDRX "\n", __func__, offset);
1223
1720
#endif
1224
 
    serial = serial_mm_init(offset, 0, irq, 399193, chr, 0);
 
1721
    serial = serial_mm_init(offset, 0, irq, chr, 0);
1225
1722
    ppc4xx_mmio_register(env, mmio, offset, 0x008,
1226
1723
                         serial_mm_read, serial_mm_write, serial);
1227
1724
}
1249
1746
                                 uint32_t dsarc, uint32_t dsacntl)
1250
1747
{
1251
1748
#ifdef DEBUG_OCM
1252
 
    printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32
1253
 
           " %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32
1254
 
           " (%08" PRIx32 " %08" PRIx32 ")\n",
 
1749
    printf("OCM update ISA %08x %08x (%08x %08x) DSA %08x %08x (%08x %08x)\n",
1255
1750
           isarc, isacntl, dsarc, dsacntl,
1256
1751
           ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl);
1257
1752
#endif
1259
1754
        (ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) {
1260
1755
        if (ocm->isacntl & 0x80000000) {
1261
1756
            /* Unmap previously assigned memory region */
1262
 
            printf("OCM unmap ISA %08" PRIx32 "\n", ocm->isarc);
 
1757
            printf("OCM unmap ISA %08x\n", ocm->isarc);
1263
1758
            cpu_register_physical_memory(ocm->isarc, 0x04000000,
1264
1759
                                         IO_MEM_UNASSIGNED);
1265
1760
        }
1266
1761
        if (isacntl & 0x80000000) {
1267
1762
            /* Map new instruction memory region */
1268
1763
#ifdef DEBUG_OCM
1269
 
            printf("OCM map ISA %08" PRIx32 "\n", isarc);
 
1764
            printf("OCM map ISA %08x\n", isarc);
1270
1765
#endif
1271
1766
            cpu_register_physical_memory(isarc, 0x04000000,
1272
1767
                                         ocm->offset | IO_MEM_RAM);
1279
1774
            if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) {
1280
1775
                /* Unmap previously assigned memory region */
1281
1776
#ifdef DEBUG_OCM
1282
 
                printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc);
 
1777
                printf("OCM unmap DSA %08x\n", ocm->dsarc);
1283
1778
#endif
1284
1779
                cpu_register_physical_memory(ocm->dsarc, 0x04000000,
1285
1780
                                             IO_MEM_UNASSIGNED);
1290
1785
            if (!(isacntl & 0x80000000) || dsarc != isarc) {
1291
1786
                /* Map new data memory region */
1292
1787
#ifdef DEBUG_OCM
1293
 
                printf("OCM map DSA %08" PRIx32 "\n", dsarc);
 
1788
                printf("OCM map DSA %08x\n", dsarc);
1294
1789
#endif
1295
1790
                cpu_register_physical_memory(dsarc, 0x04000000,
1296
1791
                                             ocm->offset | IO_MEM_RAM);
1478
1973
        break;
1479
1974
    }
1480
1975
#ifdef DEBUG_I2C
1481
 
    printf("%s: addr " PADDRX " %02" PRIx32 "\n", __func__, addr, ret);
 
1976
    printf("%s: addr " PADDRX " %02x\n", __func__, addr, ret);
1482
1977
#endif
1483
1978
 
1484
1979
    return ret;
1490
1985
    ppc4xx_i2c_t *i2c;
1491
1986
 
1492
1987
#ifdef DEBUG_I2C
1493
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
1988
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1494
1989
#endif
1495
1990
    i2c = opaque;
1496
1991
    switch (addr - i2c->base) {
1560
2055
                               target_phys_addr_t addr, uint32_t value)
1561
2056
{
1562
2057
#ifdef DEBUG_I2C
1563
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
2058
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1564
2059
#endif
1565
2060
    ppc4xx_i2c_writeb(opaque, addr, value >> 8);
1566
2061
    ppc4xx_i2c_writeb(opaque, addr + 1, value);
1585
2080
                               target_phys_addr_t addr, uint32_t value)
1586
2081
{
1587
2082
#ifdef DEBUG_I2C
1588
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
2083
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1589
2084
#endif
1590
2085
    ppc4xx_i2c_writeb(opaque, addr, value >> 24);
1591
2086
    ppc4xx_i2c_writeb(opaque, addr + 1, value >> 16);
1632
2127
        i2c->irq = irq;
1633
2128
        ppc4xx_i2c_reset(i2c);
1634
2129
#ifdef DEBUG_I2C
1635
 
        printf("%s: offset " PADDRX "\n", __func__, offset);
 
2130
        printf("%s: offset=" PADDRX "\n", __func__, offset);
1636
2131
#endif
1637
2132
        ppc4xx_mmio_register(env, mmio, offset, 0x011,
1638
2133
                             i2c_read, i2c_write, i2c);
1671
2166
                               target_phys_addr_t addr, uint32_t value)
1672
2167
{
1673
2168
#ifdef DEBUG_I2C
1674
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
2169
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1675
2170
#endif
1676
2171
    /* XXX: generate a bus fault */
1677
2172
}
1689
2184
                               target_phys_addr_t addr, uint32_t value)
1690
2185
{
1691
2186
#ifdef DEBUG_I2C
1692
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
2187
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1693
2188
#endif
1694
2189
    /* XXX: generate a bus fault */
1695
2190
}
1808
2303
    int idx;
1809
2304
 
1810
2305
#ifdef DEBUG_I2C
1811
 
    printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value);
 
2306
    printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value);
1812
2307
#endif
1813
2308
    gpt = opaque;
1814
2309
    switch (addr - gpt->base) {
1916
2411
        gpt->timer = qemu_new_timer(vm_clock, &ppc4xx_gpt_cb, gpt);
1917
2412
        ppc4xx_gpt_reset(gpt);
1918
2413
#ifdef DEBUG_GPT
1919
 
        printf("%s: offset " PADDRX "\n", __func__, offset);
 
2414
        printf("%s: offset=" PADDRX "\n", __func__, offset);
1920
2415
#endif
1921
2416
        ppc4xx_mmio_register(env, mmio, offset, 0x0D4,
1922
2417
                             gpt_read, gpt_write, gpt);
2196
2691
    target_ulong dbsr;
2197
2692
 
2198
2693
    printf("Reset PowerPC core\n");
2199
 
    env->interrupt_request |= CPU_INTERRUPT_EXITTB;
2200
 
    /* XXX: TOFIX */
2201
 
#if 0
2202
2694
    cpu_ppc_reset(env);
2203
 
#else
2204
 
    qemu_system_reset_request();
2205
 
#endif
2206
2695
    dbsr = env->spr[SPR_40x_DBSR];
2207
2696
    dbsr &= ~0x00000300;
2208
2697
    dbsr |= 0x00000100;
2209
2698
    env->spr[SPR_40x_DBSR] = dbsr;
 
2699
    cpu_loop_exit();
2210
2700
}
2211
2701
 
2212
2702
void ppc40x_chip_reset (CPUState *env)
2214
2704
    target_ulong dbsr;
2215
2705
 
2216
2706
    printf("Reset PowerPC chip\n");
2217
 
    env->interrupt_request |= CPU_INTERRUPT_EXITTB;
2218
 
    /* XXX: TOFIX */
2219
 
#if 0
2220
2707
    cpu_ppc_reset(env);
2221
 
#else
2222
 
    qemu_system_reset_request();
2223
 
#endif
2224
2708
    /* XXX: TODO reset all internal peripherals */
2225
2709
    dbsr = env->spr[SPR_40x_DBSR];
2226
2710
    dbsr &= ~0x00000300;
2227
2711
    dbsr |= 0x00000200;
2228
2712
    env->spr[SPR_40x_DBSR] = dbsr;
 
2713
    cpu_loop_exit();
2229
2714
}
2230
2715
 
2231
2716
void ppc40x_system_reset (CPUState *env)
2552
3037
    int i;
2553
3038
 
2554
3039
    memset(clk_setup, 0, sizeof(clk_setup));
2555
 
    env = ppc4xx_init("405cr", &clk_setup[PPC405CR_CPU_CLK],
 
3040
    env = ppc405_init("405cr", &clk_setup[PPC405CR_CPU_CLK],
2556
3041
                      &clk_setup[PPC405CR_TMR_CLK], sysclk);
2557
3042
    /* Memory mapped devices registers */
2558
3043
    mmio = ppc4xx_mmio_init(env, 0xEF600000);
2565
3050
    /* Universal interrupt controller */
2566
3051
    irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
2567
3052
    irqs[PPCUIC_OUTPUT_INT] =
2568
 
        ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
 
3053
        ((qemu_irq *)env->irq_inputs)[PPC405_INPUT_INT];
2569
3054
    irqs[PPCUIC_OUTPUT_CINT] =
2570
 
        ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
 
3055
        ((qemu_irq *)env->irq_inputs)[PPC405_INPUT_CINT];
2571
3056
    pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
2572
3057
    *picp = pic;
2573
3058
    /* SDRAM controller */
2585
3070
    ppc405_dma_init(env, dma_irqs);
2586
3071
    /* Serial ports */
2587
3072
    if (serial_hds[0] != NULL) {
2588
 
        ppc405_serial_init(env, mmio, 0x300, pic[0], serial_hds[0]);
 
3073
        ppc405_serial_init(env, mmio, 0x300, pic[31], serial_hds[0]);
2589
3074
    }
2590
3075
    if (serial_hds[1] != NULL) {
2591
 
        ppc405_serial_init(env, mmio, 0x400, pic[1], serial_hds[1]);
 
3076
        ppc405_serial_init(env, mmio, 0x400, pic[30], serial_hds[1]);
2592
3077
    }
2593
3078
    /* IIC controller */
2594
 
    ppc405_i2c_init(env, mmio, 0x500, pic[2]);
 
3079
    ppc405_i2c_init(env, mmio, 0x500, pic[29]);
2595
3080
    /* GPIO */
2596
3081
    ppc405_gpio_init(env, mmio, 0x700);
2597
3082
    /* CPU control */
2659
3144
    VCO_out = 0;
2660
3145
    if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) {
2661
3146
        M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2662
 
#ifdef DEBUG_CLOCKS_LL
2663
 
        printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M);
2664
 
#endif
 
3147
        //        printf("FBMUL %01x %d\n", (cpc->pllmr[1] >> 20) & 0xF, M);
2665
3148
        D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */
2666
 
#ifdef DEBUG_CLOCKS_LL
2667
 
        printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D);
2668
 
#endif
 
3149
        //        printf("FWDA %01x %d\n", (cpc->pllmr[1] >> 16) & 0x7, D);
2669
3150
        VCO_out = cpc->sysclk * M * D;
2670
3151
        if (VCO_out < 500000000UL || VCO_out > 1000000000UL) {
2671
3152
            /* Error - unlock the PLL */
2690
3171
    }
2691
3172
    /* Now, compute all other clocks */
2692
3173
    D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */
2693
 
#ifdef DEBUG_CLOCKS_LL
2694
 
    printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D);
 
3174
#ifdef DEBUG_CLOCKS
 
3175
    //    printf("CCDV %01x %d\n", (cpc->pllmr[0] >> 20) & 0x3, D);
2695
3176
#endif
2696
3177
    CPU_clk = PLL_out / D;
2697
3178
    D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */
2698
 
#ifdef DEBUG_CLOCKS_LL
2699
 
    printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D);
 
3179
#ifdef DEBUG_CLOCKS
 
3180
    //    printf("CBDV %01x %d\n", (cpc->pllmr[0] >> 16) & 0x3, D);
2700
3181
#endif
2701
3182
    PLB_clk = CPU_clk / D;
2702
3183
    D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */
2703
 
#ifdef DEBUG_CLOCKS_LL
2704
 
    printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D);
 
3184
#ifdef DEBUG_CLOCKS
 
3185
    //    printf("OPDV %01x %d\n", (cpc->pllmr[0] >> 12) & 0x3, D);
2705
3186
#endif
2706
3187
    OPB_clk = PLB_clk / D;
2707
3188
    D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */
2708
 
#ifdef DEBUG_CLOCKS_LL
2709
 
    printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D);
 
3189
#ifdef DEBUG_CLOCKS
 
3190
    //    printf("EPDV %01x %d\n", (cpc->pllmr[0] >> 8) & 0x3, D);
2710
3191
#endif
2711
3192
    EBC_clk = PLB_clk / D;
2712
3193
    D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */
2713
 
#ifdef DEBUG_CLOCKS_LL
2714
 
    printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D);
 
3194
#ifdef DEBUG_CLOCKS
 
3195
    //    printf("MPDV %01x %d\n", (cpc->pllmr[0] >> 4) & 0x3, D);
2715
3196
#endif
2716
3197
    MAL_clk = PLB_clk / D;
2717
3198
    D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */
2718
 
#ifdef DEBUG_CLOCKS_LL
2719
 
    printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D);
 
3199
#ifdef DEBUG_CLOCKS
 
3200
    //    printf("PPDV %01x %d\n", cpc->pllmr[0] & 0x3, D);
2720
3201
#endif
2721
3202
    PCI_clk = PLB_clk / D;
2722
3203
    D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */
2723
 
#ifdef DEBUG_CLOCKS_LL
2724
 
    printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D);
 
3204
#ifdef DEBUG_CLOCKS
 
3205
    //    printf("U0DIV %01x %d\n", cpc->ucr & 0x7F, D);
2725
3206
#endif
2726
3207
    UART0_clk = PLL_out / D;
2727
3208
    D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */
2728
 
#ifdef DEBUG_CLOCKS_LL
2729
 
    printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D);
 
3209
#ifdef DEBUG_CLOCKS
 
3210
    //    printf("U1DIV %01x %d\n", (cpc->ucr >> 8) & 0x7F, D);
2730
3211
#endif
2731
3212
    UART1_clk = PLL_out / D;
2732
3213
#ifdef DEBUG_CLOCKS
2733
 
    printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64
 
3214
    printf("Setup PPC405EP clocks - sysclk %d VCO %" PRIu64
2734
3215
           " PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out);
2735
 
    printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32
2736
 
           " MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32
2737
 
           " UART1 %" PRIu32 "\n",
 
3216
    printf("CPU %d PLB %d OPB %d EBC %d MAL %d PCI %d UART0 %d UART1 %d\n",
2738
3217
           CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk,
2739
3218
           UART0_clk, UART1_clk);
 
3219
    printf("CB %p opaque %p\n", cpc->clk_setup[PPC405EP_CPU_CLK].cb,
 
3220
           cpc->clk_setup[PPC405EP_CPU_CLK].opaque);
2740
3221
#endif
2741
3222
    /* Setup CPU clocks */
2742
3223
    clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk);
2906
3387
 
2907
3388
    memset(clk_setup, 0, sizeof(clk_setup));
2908
3389
    /* init CPUs */
2909
 
    env = ppc4xx_init("405ep", &clk_setup[PPC405EP_CPU_CLK],
 
3390
    env = ppc405_init("405ep", &clk_setup[PPC405EP_CPU_CLK],
2910
3391
                      &tlb_clk_setup, sysclk);
2911
3392
    clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb;
2912
3393
    clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque;
2922
3403
    /* Universal interrupt controller */
2923
3404
    irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
2924
3405
    irqs[PPCUIC_OUTPUT_INT] =
2925
 
        ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
 
3406
        ((qemu_irq *)env->irq_inputs)[PPC405_INPUT_INT];
2926
3407
    irqs[PPCUIC_OUTPUT_CINT] =
2927
 
        ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
 
3408
        ((qemu_irq *)env->irq_inputs)[PPC405_INPUT_CINT];
2928
3409
    pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
2929
3410
    *picp = pic;
2930
3411
    /* SDRAM controller */
2931
 
        /* XXX 405EP has no ECC interrupt */
2932
 
    ppc405_sdram_init(env, pic[17], 2, ram_bases, ram_sizes, do_init);
 
3412
    ppc405_sdram_init(env, pic[14], 2, ram_bases, ram_sizes, do_init);
2933
3413
    offset = 0;
2934
3414
    for (i = 0; i < 2; i++)
2935
3415
        offset += ram_sizes[i];
2936
3416
    /* External bus controller */
2937
3417
    ppc405_ebc_init(env);
2938
3418
    /* DMA controller */
2939
 
    dma_irqs[0] = pic[5];
2940
 
    dma_irqs[1] = pic[6];
2941
 
    dma_irqs[2] = pic[7];
2942
 
    dma_irqs[3] = pic[8];
 
3419
    dma_irqs[0] = pic[26];
 
3420
    dma_irqs[1] = pic[25];
 
3421
    dma_irqs[2] = pic[24];
 
3422
    dma_irqs[3] = pic[23];
2943
3423
    ppc405_dma_init(env, dma_irqs);
2944
3424
    /* IIC controller */
2945
 
    ppc405_i2c_init(env, mmio, 0x500, pic[2]);
 
3425
    ppc405_i2c_init(env, mmio, 0x500, pic[29]);
2946
3426
    /* GPIO */
2947
3427
    ppc405_gpio_init(env, mmio, 0x700);
2948
3428
    /* Serial ports */
2949
3429
    if (serial_hds[0] != NULL) {
2950
 
        ppc405_serial_init(env, mmio, 0x300, pic[0], serial_hds[0]);
 
3430
        ppc405_serial_init(env, mmio, 0x300, pic[31], serial_hds[0]);
2951
3431
    }
2952
3432
    if (serial_hds[1] != NULL) {
2953
 
        ppc405_serial_init(env, mmio, 0x400, pic[1], serial_hds[1]);
 
3433
        ppc405_serial_init(env, mmio, 0x400, pic[30], serial_hds[1]);
2954
3434
    }
2955
3435
    /* OCM */
2956
3436
    ppc405_ocm_init(env, ram_sizes[0] + ram_sizes[1]);
2957
3437
    offset += 4096;
2958
3438
    /* GPT */
2959
 
    gpt_irqs[0] = pic[19];
2960
 
    gpt_irqs[1] = pic[20];
2961
 
    gpt_irqs[2] = pic[21];
2962
 
    gpt_irqs[3] = pic[22];
2963
 
    gpt_irqs[4] = pic[23];
 
3439
    gpt_irqs[0] = pic[12];
 
3440
    gpt_irqs[1] = pic[11];
 
3441
    gpt_irqs[2] = pic[10];
 
3442
    gpt_irqs[3] = pic[9];
 
3443
    gpt_irqs[4] = pic[8];
2964
3444
    ppc4xx_gpt_init(env, mmio, 0x000, gpt_irqs);
2965
3445
    /* PCI */
2966
 
    /* Uses pic[3], pic[16], pic[18] */
 
3446
    /* Uses pic[28], pic[15], pic[13] */
2967
3447
    /* MAL */
2968
 
    mal_irqs[0] = pic[11];
2969
 
    mal_irqs[1] = pic[12];
2970
 
    mal_irqs[2] = pic[13];
2971
 
    mal_irqs[3] = pic[14];
 
3448
    mal_irqs[0] = pic[20];
 
3449
    mal_irqs[1] = pic[19];
 
3450
    mal_irqs[2] = pic[18];
 
3451
    mal_irqs[3] = pic[17];
2972
3452
    ppc405_mal_init(env, mal_irqs);
2973
3453
    /* Ethernet */
2974
 
    /* Uses pic[9], pic[15], pic[17] */
 
3454
    /* Uses pic[22], pic[16], pic[14] */
2975
3455
    /* CPU control */
2976
3456
    ppc405ep_cpc_init(env, clk_setup, sysclk);
2977
3457
    *offsetp = offset;