PL050 qdev conversion
[qemu] / hw / realview.c
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 realview_init(ram_addr_t ram_size,
28                      const char *boot_device,
29                      const char *kernel_filename, const char *kernel_cmdline,
30                      const char *initrd_filename, const char *cpu_model)
31 {
32     CPUState *env;
33     ram_addr_t ram_offset;
34     qemu_irq *pic;
35     void *scsi_hba;
36     PCIBus *pci_bus;
37     NICInfo *nd;
38     int n;
39     int done_smc = 0;
40     qemu_irq cpu_irq[4];
41     int ncpu;
42     int index;
43
44     if (!cpu_model)
45         cpu_model = "arm926";
46     /* FIXME: obey smp_cpus.  */
47     if (strcmp(cpu_model, "arm11mpcore") == 0) {
48         ncpu = 4;
49     } else {
50         ncpu = 1;
51     }
52
53     for (n = 0; n < ncpu; n++) {
54         env = cpu_init(cpu_model);
55         if (!env) {
56             fprintf(stderr, "Unable to find CPU definition\n");
57             exit(1);
58         }
59         pic = arm_pic_init_cpu(env);
60         cpu_irq[n] = pic[ARM_PIC_CPU_IRQ];
61         if (n > 0) {
62             /* Set entry point for secondary CPUs.  This assumes we're using
63                the init code from arm_boot.c.  Real hardware resets all CPUs
64                the same.  */
65             env->regs[15] = 0x80000000;
66         }
67     }
68
69     ram_offset = qemu_ram_alloc(ram_size);
70     /* ??? RAM should repeat to fill physical memory space.  */
71     /* SDRAM at address zero.  */
72     cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);
73
74     arm_sysctl_init(0x10000000, 0xc1400400);
75
76     if (ncpu == 1) {
77         /* ??? The documentation says GIC1 is nFIQ and either GIC2 or GIC3
78            is nIRQ (there are inconsistencies).  However Linux 2.6.17 expects
79            GIC1 to be nIRQ and ignores all the others, so do that for now.  */
80         pic = realview_gic_init(0x10040000, cpu_irq[0]);
81     } else {
82         pic = mpcore_irq_init(cpu_irq);
83     }
84
85     sysbus_create_simple("pl050_keyboard", 0x10006000, pic[20]);
86     sysbus_create_simple("pl050_mouse", 0x10007000, pic[21]);
87
88     sysbus_create_simple("pl011", 0x10009000, pic[12]);
89     sysbus_create_simple("pl011", 0x1000a000, pic[13]);
90     sysbus_create_simple("pl011", 0x1000b000, pic[14]);
91     sysbus_create_simple("pl011", 0x1000c000, pic[15]);
92
93     /* DMA controller is optional, apparently.  */
94     pl080_init(0x10030000, pic[24], 2);
95
96     sp804_init(0x10011000, pic[4]);
97     sp804_init(0x10012000, pic[5]);
98
99     sysbus_create_simple("pl110_versatile", 0x10020000, pic[23]);
100
101     index = drive_get_index(IF_SD, 0, 0);
102     if (index == -1) {
103         fprintf(stderr, "qemu: missing SecureDigital card\n");
104         exit(1);
105     }
106     pl181_init(0x10005000, drives_table[index].bdrv, pic[17], pic[18]);
107
108     pl031_init(0x10017000, pic[10]);
109
110     pci_bus = pci_vpb_init(pic, 48, 1);
111     if (usb_enabled) {
112         usb_ohci_init_pci(pci_bus, 3, -1);
113     }
114     if (drive_get_max_bus(IF_SCSI) > 0) {
115         fprintf(stderr, "qemu: too many SCSI bus\n");
116         exit(1);
117     }
118     scsi_hba = lsi_scsi_init(pci_bus, -1);
119     for (n = 0; n < LSI_MAX_DEVS; n++) {
120         index = drive_get_index(IF_SCSI, 0, n);
121         if (index == -1)
122             continue;
123         lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n);
124     }
125     for(n = 0; n < nb_nics; n++) {
126         nd = &nd_table[n];
127
128         if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
129             smc91c111_init(nd, 0x4e000000, pic[28]);
130             done_smc = 1;
131         } else {
132             pci_nic_init(pci_bus, nd, -1, "rtl8139");
133         }
134     }
135
136     /* Memory map for RealView Emulation Baseboard:  */
137     /* 0x10000000 System registers.  */
138     /*  0x10001000 System controller.  */
139     /*  0x10002000 Two-Wire Serial Bus.  */
140     /* 0x10003000 Reserved.  */
141     /*  0x10004000 AACI.  */
142     /*  0x10005000 MCI.  */
143     /* 0x10006000 KMI0.  */
144     /* 0x10007000 KMI1.  */
145     /*  0x10008000 Character LCD.  */
146     /* 0x10009000 UART0.  */
147     /* 0x1000a000 UART1.  */
148     /* 0x1000b000 UART2.  */
149     /* 0x1000c000 UART3.  */
150     /*  0x1000d000 SSPI.  */
151     /*  0x1000e000 SCI.  */
152     /* 0x1000f000 Reserved.  */
153     /*  0x10010000 Watchdog.  */
154     /* 0x10011000 Timer 0+1.  */
155     /* 0x10012000 Timer 2+3.  */
156     /*  0x10013000 GPIO 0.  */
157     /*  0x10014000 GPIO 1.  */
158     /*  0x10015000 GPIO 2.  */
159     /* 0x10016000 Reserved.  */
160     /* 0x10017000 RTC.  */
161     /*  0x10018000 DMC.  */
162     /*  0x10019000 PCI controller config.  */
163     /*  0x10020000 CLCD.  */
164     /* 0x10030000 DMA Controller.  */
165     /* 0x10040000 GIC1.  */
166     /* 0x10050000 GIC2.  */
167     /* 0x10060000 GIC3.  */
168     /* 0x10070000 GIC4.  */
169     /*  0x10080000 SMC.  */
170     /*  0x40000000 NOR flash.  */
171     /*  0x44000000 DoC flash.  */
172     /*  0x48000000 SRAM.  */
173     /*  0x4c000000 Configuration flash.  */
174     /* 0x4e000000 Ethernet.  */
175     /*  0x4f000000 USB.  */
176     /*  0x50000000 PISMO.  */
177     /*  0x54000000 PISMO.  */
178     /*  0x58000000 PISMO.  */
179     /*  0x5c000000 PISMO.  */
180     /* 0x60000000 PCI.  */
181     /* 0x61000000 PCI Self Config.  */
182     /* 0x62000000 PCI Config.  */
183     /* 0x63000000 PCI IO.  */
184     /* 0x64000000 PCI mem 0.  */
185     /* 0x68000000 PCI mem 1.  */
186     /* 0x6c000000 PCI mem 2.  */
187
188     /* ??? Hack to map an additional page of ram for the secondary CPU
189        startup code.  I guess this works on real hardware because the
190        BootROM happens to be in ROM/flash or in memory that isn't clobbered
191        until after Linux boots the secondary CPUs.  */
192     ram_offset = qemu_ram_alloc(0x1000);
193     cpu_register_physical_memory(0x80000000, 0x1000, ram_offset | IO_MEM_RAM);
194
195     realview_binfo.ram_size = ram_size;
196     realview_binfo.kernel_filename = kernel_filename;
197     realview_binfo.kernel_cmdline = kernel_cmdline;
198     realview_binfo.initrd_filename = initrd_filename;
199     realview_binfo.nb_cpus = ncpu;
200     arm_load_kernel(first_cpu, &realview_binfo);
201 }
202
203 QEMUMachine realview_machine = {
204     .name = "realview",
205     .desc = "ARM RealView Emulation Baseboard (ARM926EJ-S)",
206     .init = realview_init,
207     .use_scsi = 1,
208 };