Statistics
| Branch: | Revision:

root / hw / realview.c @ 26e92f65

History | View | Annotate | Download (6.9 kB)

1
/*
2
 * ARM RealView Baseboard System emulation.
3
 *
4
 * Copyright (c) 2006-2007 CodeSourcery.
5
 * Written by Paul Brook
6
 *
7
 * This code is licenced under the GPL.
8
 */
9

    
10
#include "sysbus.h"
11
#include "arm-misc.h"
12
#include "primecell.h"
13
#include "devices.h"
14
#include "pci.h"
15
#include "net.h"
16
#include "sysemu.h"
17
#include "boards.h"
18

    
19
/* Board init.  */
20

    
21
static struct arm_boot_info realview_binfo = {
22
    .loader_start = 0x0,
23
    .smp_loader_start = 0x80000000,
24
    .board_id = 0x33b,
25
};
26

    
27
static void secondary_cpu_reset(void *opaque)
28
{
29
  CPUState *env = opaque;
30

    
31
  cpu_reset(env);
32
  /* Set entry point for secondary CPUs.  This assumes we're using
33
     the init code from arm_boot.c.  Real hardware resets all CPUs
34
     the same.  */
35
  env->regs[15] = 0x80000000;
36
}
37

    
38
static void realview_init(ram_addr_t ram_size,
39
                     const char *boot_device,
40
                     const char *kernel_filename, const char *kernel_cmdline,
41
                     const char *initrd_filename, const char *cpu_model)
42
{
43
    CPUState *env;
44
    ram_addr_t ram_offset;
45
    DeviceState *dev;
46
    qemu_irq *irqp;
47
    qemu_irq pic[64];
48
    PCIBus *pci_bus;
49
    NICInfo *nd;
50
    int n;
51
    int done_smc = 0;
52
    qemu_irq cpu_irq[4];
53
    int ncpu;
54
    uint32_t proc_id = 0;
55

    
56
    if (!cpu_model)
57
        cpu_model = "arm926";
58
    /* FIXME: obey smp_cpus.  */
59
    if (strcmp(cpu_model, "arm11mpcore") == 0) {
60
        ncpu = 4;
61
    } else {
62
        ncpu = 1;
63
    }
64

    
65
    for (n = 0; n < ncpu; n++) {
66
        env = cpu_init(cpu_model);
67
        if (!env) {
68
            fprintf(stderr, "Unable to find CPU definition\n");
69
            exit(1);
70
        }
71
        irqp = arm_pic_init_cpu(env);
72
        cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
73
        if (n > 0) {
74
            qemu_register_reset(secondary_cpu_reset, env);
75
        }
76
    }
77
    if (arm_feature(env, ARM_FEATURE_V7)) {
78
        proc_id = 0x0e000000;
79
    } else if (arm_feature(env, ARM_FEATURE_V6K)) {
80
        proc_id = 0x06000000;
81
    } else if (arm_feature(env, ARM_FEATURE_V6)) {
82
        proc_id = 0x04000000;
83
    } else {
84
        proc_id = 0x02000000;
85
    }
86

    
87
    ram_offset = qemu_ram_alloc(ram_size);
88
    /* ??? RAM should repeat to fill physical memory space.  */
89
    /* SDRAM at address zero.  */
90
    cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);
91

    
92
    arm_sysctl_init(0x10000000, 0xc1400400, proc_id);
93

    
94
    if (ncpu == 1) {
95
        /* ??? The documentation says GIC1 is nFIQ and either GIC2 or GIC3
96
           is nIRQ (there are inconsistencies).  However Linux 2.6.17 expects
97
           GIC1 to be nIRQ and ignores all the others, so do that for now.  */
98
        dev = sysbus_create_simple("realview_gic", 0x10040000, cpu_irq[0]);
99
    } else {
100
        dev = sysbus_create_varargs("realview_mpcore", -1,
101
                                    cpu_irq[0], cpu_irq[1], cpu_irq[2],
102
                                    cpu_irq[3], NULL);
103
    }
104
    for (n = 0; n < 64; n++) {
105
        pic[n] = qdev_get_gpio_in(dev, n);
106
    }
107

    
108
    sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
109
    sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
110

    
111
    sysbus_create_simple("pl011", 0x10009000, pic[12]);
112
    sysbus_create_simple("pl011", 0x1000a000, pic[13]);
113
    sysbus_create_simple("pl011", 0x1000b000, pic[14]);
114
    sysbus_create_simple("pl011", 0x1000c000, pic[15]);
115

    
116
    /* DMA controller is optional, apparently.  */
117
    sysbus_create_simple("pl081", 0x10030000, pic[24]);
118

    
119
    sysbus_create_simple("sp804", 0x10011000, pic[4]);
120
    sysbus_create_simple("sp804", 0x10012000, pic[5]);
121

    
122
    sysbus_create_simple("pl110_versatile", 0x10020000, pic[23]);
123

    
124
    sysbus_create_varargs("pl181", 0x10005000, pic[17], pic[18], NULL);
125

    
126
    sysbus_create_simple("pl031", 0x10017000, pic[10]);
127

    
128
    dev = sysbus_create_varargs("realview_pci", 0x60000000,
129
                                pic[48], pic[49], pic[50], pic[51], NULL);
130
    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
131
    if (usb_enabled) {
132
        usb_ohci_init_pci(pci_bus, -1);
133
    }
134
    n = drive_get_max_bus(IF_SCSI);
135
    while (n >= 0) {
136
        pci_create_simple(pci_bus, -1, "lsi53c895a");
137
        n--;
138
    }
139
    for(n = 0; n < nb_nics; n++) {
140
        nd = &nd_table[n];
141

    
142
        if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
143
            smc91c111_init(nd, 0x4e000000, pic[28]);
144
            done_smc = 1;
145
        } else {
146
            pci_nic_init_nofail(nd, "rtl8139", NULL);
147
        }
148
    }
149

    
150
    /* Memory map for RealView Emulation Baseboard:  */
151
    /* 0x10000000 System registers.  */
152
    /*  0x10001000 System controller.  */
153
    /*  0x10002000 Two-Wire Serial Bus.  */
154
    /* 0x10003000 Reserved.  */
155
    /*  0x10004000 AACI.  */
156
    /*  0x10005000 MCI.  */
157
    /* 0x10006000 KMI0.  */
158
    /* 0x10007000 KMI1.  */
159
    /*  0x10008000 Character LCD.  */
160
    /* 0x10009000 UART0.  */
161
    /* 0x1000a000 UART1.  */
162
    /* 0x1000b000 UART2.  */
163
    /* 0x1000c000 UART3.  */
164
    /*  0x1000d000 SSPI.  */
165
    /*  0x1000e000 SCI.  */
166
    /* 0x1000f000 Reserved.  */
167
    /*  0x10010000 Watchdog.  */
168
    /* 0x10011000 Timer 0+1.  */
169
    /* 0x10012000 Timer 2+3.  */
170
    /*  0x10013000 GPIO 0.  */
171
    /*  0x10014000 GPIO 1.  */
172
    /*  0x10015000 GPIO 2.  */
173
    /* 0x10016000 Reserved.  */
174
    /* 0x10017000 RTC.  */
175
    /*  0x10018000 DMC.  */
176
    /*  0x10019000 PCI controller config.  */
177
    /*  0x10020000 CLCD.  */
178
    /* 0x10030000 DMA Controller.  */
179
    /* 0x10040000 GIC1.  */
180
    /* 0x10050000 GIC2.  */
181
    /* 0x10060000 GIC3.  */
182
    /* 0x10070000 GIC4.  */
183
    /*  0x10080000 SMC.  */
184
    /*  0x40000000 NOR flash.  */
185
    /*  0x44000000 DoC flash.  */
186
    /*  0x48000000 SRAM.  */
187
    /*  0x4c000000 Configuration flash.  */
188
    /* 0x4e000000 Ethernet.  */
189
    /*  0x4f000000 USB.  */
190
    /*  0x50000000 PISMO.  */
191
    /*  0x54000000 PISMO.  */
192
    /*  0x58000000 PISMO.  */
193
    /*  0x5c000000 PISMO.  */
194
    /* 0x60000000 PCI.  */
195
    /* 0x61000000 PCI Self Config.  */
196
    /* 0x62000000 PCI Config.  */
197
    /* 0x63000000 PCI IO.  */
198
    /* 0x64000000 PCI mem 0.  */
199
    /* 0x68000000 PCI mem 1.  */
200
    /* 0x6c000000 PCI mem 2.  */
201

    
202
    /* ??? Hack to map an additional page of ram for the secondary CPU
203
       startup code.  I guess this works on real hardware because the
204
       BootROM happens to be in ROM/flash or in memory that isn't clobbered
205
       until after Linux boots the secondary CPUs.  */
206
    ram_offset = qemu_ram_alloc(0x1000);
207
    cpu_register_physical_memory(0x80000000, 0x1000, ram_offset | IO_MEM_RAM);
208

    
209
    realview_binfo.ram_size = ram_size;
210
    realview_binfo.kernel_filename = kernel_filename;
211
    realview_binfo.kernel_cmdline = kernel_cmdline;
212
    realview_binfo.initrd_filename = initrd_filename;
213
    realview_binfo.nb_cpus = ncpu;
214
    arm_load_kernel(first_cpu, &realview_binfo);
215
}
216

    
217
static QEMUMachine realview_machine = {
218
    .name = "realview",
219
    .desc = "ARM RealView Emulation Baseboard (ARM926EJ-S)",
220
    .init = realview_init,
221
    .use_scsi = 1,
222
};
223

    
224
static void realview_machine_init(void)
225
{
226
    qemu_register_machine(&realview_machine);
227
}
228

    
229
machine_init(realview_machine_init);