]> git.proxmox.com Git - mirror_qemu.git/blame - hw/arm/versatilepb.c
hw: Deprecate -drive if=scsi with non-onboard HBAs
[mirror_qemu.git] / hw / arm / versatilepb.c
CommitLineData
5fafdf24 1/*
16406950 2 * ARM Versatile Platform/Application Baseboard System emulation.
cdbdb648 3 *
a1bb27b1 4 * Copyright (c) 2005-2007 CodeSourcery.
cdbdb648
PB
5 * Written by Paul Brook
6 *
8e31bf38 7 * This code is licensed under the GPL.
cdbdb648
PB
8 */
9
12b16722 10#include "qemu/osdep.h"
da34e65c 11#include "qapi/error.h"
4771d756
PB
12#include "qemu-common.h"
13#include "cpu.h"
83c9f4ca 14#include "hw/sysbus.h"
bd2be150
PM
15#include "hw/arm/arm.h"
16#include "hw/devices.h"
1422e32d 17#include "net/net.h"
9c17d615 18#include "sysemu/sysemu.h"
83c9f4ca 19#include "hw/pci/pci.h"
0d09e41a 20#include "hw/i2c/i2c.h"
83c9f4ca 21#include "hw/boards.h"
fa1d36df 22#include "sysemu/block-backend.h"
022c62cb 23#include "exec/address-spaces.h"
0d09e41a 24#include "hw/block/flash.h"
223a72f1 25#include "qemu/error-report.h"
f0d1d2c1 26#include "hw/char/pl011.h"
964c695a
EB
27
28#define VERSATILE_FLASH_ADDR 0x34000000
29#define VERSATILE_FLASH_SIZE (64 * 1024 * 1024)
30#define VERSATILE_FLASH_SECT_SIZE (256 * 1024)
cdbdb648 31
cdbdb648
PB
32/* Primary interrupt controller. */
33
cfc6b245
AF
34#define TYPE_VERSATILE_PB_SIC "versatilepb_sic"
35#define VERSATILE_PB_SIC(obj) \
36 OBJECT_CHECK(vpb_sic_state, (obj), TYPE_VERSATILE_PB_SIC)
37
38typedef struct vpb_sic_state {
39 SysBusDevice parent_obj;
40
41 MemoryRegion iomem;
42 uint32_t level;
43 uint32_t mask;
44 uint32_t pic_enable;
45 qemu_irq parent[32];
46 int irq;
cdbdb648
PB
47} vpb_sic_state;
48
a796d0ac
PM
49static const VMStateDescription vmstate_vpb_sic = {
50 .name = "versatilepb_sic",
51 .version_id = 1,
52 .minimum_version_id = 1,
53 .fields = (VMStateField[]) {
54 VMSTATE_UINT32(level, vpb_sic_state),
55 VMSTATE_UINT32(mask, vpb_sic_state),
56 VMSTATE_UINT32(pic_enable, vpb_sic_state),
57 VMSTATE_END_OF_LIST()
58 }
59};
60
cdbdb648
PB
61static void vpb_sic_update(vpb_sic_state *s)
62{
63 uint32_t flags;
64
65 flags = s->level & s->mask;
d537cf6c 66 qemu_set_irq(s->parent[s->irq], flags != 0);
cdbdb648
PB
67}
68
69static void vpb_sic_update_pic(vpb_sic_state *s)
70{
71 int i;
72 uint32_t mask;
73
74 for (i = 21; i <= 30; i++) {
75 mask = 1u << i;
76 if (!(s->pic_enable & mask))
77 continue;
d537cf6c 78 qemu_set_irq(s->parent[i], (s->level & mask) != 0);
cdbdb648
PB
79 }
80}
81
82static void vpb_sic_set_irq(void *opaque, int irq, int level)
83{
84 vpb_sic_state *s = (vpb_sic_state *)opaque;
85 if (level)
86 s->level |= 1u << irq;
87 else
88 s->level &= ~(1u << irq);
89 if (s->pic_enable & (1u << irq))
d537cf6c 90 qemu_set_irq(s->parent[irq], level);
cdbdb648
PB
91 vpb_sic_update(s);
92}
93
a8170e5e 94static uint64_t vpb_sic_read(void *opaque, hwaddr offset,
62ceeb2c 95 unsigned size)
cdbdb648
PB
96{
97 vpb_sic_state *s = (vpb_sic_state *)opaque;
98
cdbdb648
PB
99 switch (offset >> 2) {
100 case 0: /* STATUS */
101 return s->level & s->mask;
102 case 1: /* RAWSTAT */
103 return s->level;
104 case 2: /* ENABLE */
105 return s->mask;
106 case 4: /* SOFTINT */
107 return s->level & 1;
108 case 8: /* PICENABLE */
109 return s->pic_enable;
110 default:
e69954b9 111 printf ("vpb_sic_read: Bad register offset 0x%x\n", (int)offset);
cdbdb648
PB
112 return 0;
113 }
114}
115
a8170e5e 116static void vpb_sic_write(void *opaque, hwaddr offset,
62ceeb2c 117 uint64_t value, unsigned size)
cdbdb648
PB
118{
119 vpb_sic_state *s = (vpb_sic_state *)opaque;
cdbdb648
PB
120
121 switch (offset >> 2) {
122 case 2: /* ENSET */
123 s->mask |= value;
124 break;
125 case 3: /* ENCLR */
126 s->mask &= ~value;
127 break;
128 case 4: /* SOFTINTSET */
129 if (value)
130 s->mask |= 1;
131 break;
132 case 5: /* SOFTINTCLR */
133 if (value)
134 s->mask &= ~1u;
135 break;
136 case 8: /* PICENSET */
137 s->pic_enable |= (value & 0x7fe00000);
138 vpb_sic_update_pic(s);
139 break;
140 case 9: /* PICENCLR */
141 s->pic_enable &= ~value;
142 vpb_sic_update_pic(s);
143 break;
144 default:
e69954b9 145 printf ("vpb_sic_write: Bad register offset 0x%x\n", (int)offset);
cdbdb648
PB
146 return;
147 }
148 vpb_sic_update(s);
149}
150
62ceeb2c
AK
151static const MemoryRegionOps vpb_sic_ops = {
152 .read = vpb_sic_read,
153 .write = vpb_sic_write,
154 .endianness = DEVICE_NATIVE_ENDIAN,
cdbdb648
PB
155};
156
0bc91ab3 157static void vpb_sic_init(Object *obj)
cdbdb648 158{
0bc91ab3
XZ
159 DeviceState *dev = DEVICE(obj);
160 vpb_sic_state *s = VERSATILE_PB_SIC(obj);
161 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
97aff481 162 int i;
cdbdb648 163
cfc6b245 164 qdev_init_gpio_in(dev, vpb_sic_set_irq, 32);
97aff481 165 for (i = 0; i < 32; i++) {
cfc6b245 166 sysbus_init_irq(sbd, &s->parent[i]);
97aff481 167 }
3950f18b 168 s->irq = 31;
0bc91ab3 169 memory_region_init_io(&s->iomem, obj, &vpb_sic_ops, s,
64bde0f3 170 "vpb-sic", 0x1000);
cfc6b245 171 sysbus_init_mmio(sbd, &s->iomem);
cdbdb648
PB
172}
173
174/* Board init. */
175
16406950 176/* The AB and PB boards both use the same core, just with different
370de023 177 peripherals and expansion busses. For now we emulate a subset of the
16406950 178 PB peripherals and just change the board ID. */
cdbdb648 179
f93eb9ff
AZ
180static struct arm_boot_info versatile_binfo;
181
3ef96221 182static void versatile_init(MachineState *machine, int board_id)
cdbdb648 183{
223a72f1
GB
184 ObjectClass *cpu_oc;
185 Object *cpuobj;
20e93374 186 ARMCPU *cpu;
62ceeb2c
AK
187 MemoryRegion *sysmem = get_system_memory();
188 MemoryRegion *ram = g_new(MemoryRegion, 1);
97aff481 189 qemu_irq pic[32];
3950f18b 190 qemu_irq sic[32];
242ea2c6 191 DeviceState *dev, *sysctl;
7d6e771f 192 SysBusDevice *busdev;
d028d02d 193 DeviceState *pl041;
502a5395
PB
194 PCIBus *pci_bus;
195 NICInfo *nd;
a5c82852 196 I2CBus *i2c;
502a5395
PB
197 int n;
198 int done_smc = 0;
964c695a 199 DriveInfo *dinfo;
cdbdb648 200
5c8c2aaf
JCD
201 if (machine->ram_size > 0x10000000) {
202 /* Device starting at address 0x10000000,
203 * and memory cannot overlap with devices.
204 * Refuse to run rather than behaving very confusingly.
205 */
206 error_report("versatilepb: memory size must not exceed 256MB");
207 exit(1);
208 }
209
3ef96221
MA
210 if (!machine->cpu_model) {
211 machine->cpu_model = "arm926";
20e93374 212 }
223a72f1
GB
213
214 cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, machine->cpu_model);
215 if (!cpu_oc) {
aaed909a
FB
216 fprintf(stderr, "Unable to find CPU definition\n");
217 exit(1);
218 }
223a72f1
GB
219
220 cpuobj = object_new(object_class_get_name(cpu_oc));
221
61e2f352
GB
222 /* By default ARM1176 CPUs have EL3 enabled. This board does not
223 * currently support EL3 so the CPU EL3 property is disabled before
224 * realization.
225 */
226 if (object_property_find(cpuobj, "has_el3", NULL)) {
007b0657 227 object_property_set_bool(cpuobj, false, "has_el3", &error_fatal);
61e2f352
GB
228 }
229
007b0657 230 object_property_set_bool(cpuobj, true, "realized", &error_fatal);
223a72f1
GB
231
232 cpu = ARM_CPU(cpuobj);
233
c8623c02
DM
234 memory_region_allocate_system_memory(ram, NULL, "versatile.ram",
235 machine->ram_size);
1235fc06 236 /* ??? RAM should repeat to fill physical memory space. */
cdbdb648 237 /* SDRAM at address zero. */
62ceeb2c 238 memory_region_add_subregion(sysmem, 0, ram);
cdbdb648 239
242ea2c6
PM
240 sysctl = qdev_create(NULL, "realview_sysctl");
241 qdev_prop_set_uint32(sysctl, "sys_id", 0x41007004);
242ea2c6 242 qdev_prop_set_uint32(sysctl, "proc_id", 0x02000000);
7a65c8cc 243 qdev_init_nofail(sysctl);
1356b98d 244 sysbus_mmio_map(SYS_BUS_DEVICE(sysctl), 0, 0x10000000);
242ea2c6 245
97aff481 246 dev = sysbus_create_varargs("pl190", 0x10140000,
bace999f
PM
247 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ),
248 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ),
249 NULL);
97aff481 250 for (n = 0; n < 32; n++) {
067a3ddc 251 pic[n] = qdev_get_gpio_in(dev, n);
97aff481 252 }
cfc6b245 253 dev = sysbus_create_simple(TYPE_VERSATILE_PB_SIC, 0x10003000, NULL);
3950f18b 254 for (n = 0; n < 32; n++) {
1356b98d 255 sysbus_connect_irq(SYS_BUS_DEVICE(dev), n, pic[n]);
067a3ddc 256 sic[n] = qdev_get_gpio_in(dev, n);
3950f18b 257 }
86394e96
PB
258
259 sysbus_create_simple("pl050_keyboard", 0x10006000, sic[3]);
260 sysbus_create_simple("pl050_mouse", 0x10007000, sic[4]);
cdbdb648 261
7d6e771f 262 dev = qdev_create(NULL, "versatile_pci");
1356b98d 263 busdev = SYS_BUS_DEVICE(dev);
7d6e771f 264 qdev_init_nofail(dev);
7468d73a
PM
265 sysbus_mmio_map(busdev, 0, 0x10001000); /* PCI controller regs */
266 sysbus_mmio_map(busdev, 1, 0x41000000); /* PCI self-config */
267 sysbus_mmio_map(busdev, 2, 0x42000000); /* PCI config */
268 sysbus_mmio_map(busdev, 3, 0x43000000); /* PCI I/O */
89a32d32
PM
269 sysbus_mmio_map(busdev, 4, 0x44000000); /* PCI memory window 1 */
270 sysbus_mmio_map(busdev, 5, 0x50000000); /* PCI memory window 2 */
271 sysbus_mmio_map(busdev, 6, 0x60000000); /* PCI memory window 3 */
7d6e771f
PM
272 sysbus_connect_irq(busdev, 0, sic[27]);
273 sysbus_connect_irq(busdev, 1, sic[28]);
274 sysbus_connect_irq(busdev, 2, sic[29]);
275 sysbus_connect_irq(busdev, 3, sic[30]);
02e2da45 276 pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
0027b06d 277
502a5395
PB
278 for(n = 0; n < nb_nics; n++) {
279 nd = &nd_table[n];
0ae18cee 280
e6b3c8ca 281 if (!done_smc && (!nd->model || strcmp(nd->model, "smc91c111") == 0)) {
d537cf6c 282 smc91c111_init(nd, 0x10010000, sic[25]);
0ae18cee 283 done_smc = 1;
cdbdb648 284 } else {
29b358f9 285 pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
cdbdb648
PB
286 }
287 }
4bcbe0b6 288 if (machine_usb(machine)) {
afb9a60e 289 pci_create_simple(pci_bus, -1, "pci-ohci");
0d92ed30 290 }
9be5dafe
PB
291 n = drive_get_max_bus(IF_SCSI);
292 while (n >= 0) {
a64aa578 293 lsi53c895a_create(pci_bus);
9be5dafe 294 n--;
7d8406be 295 }
cdbdb648 296
f0d1d2c1
XZ
297 pl011_create(0x101f1000, pic[12], serial_hds[0]);
298 pl011_create(0x101f2000, pic[13], serial_hds[1]);
299 pl011_create(0x101f3000, pic[14], serial_hds[2]);
300 pl011_create(0x10009000, sic[6], serial_hds[3]);
cdbdb648 301
b4496b13 302 sysbus_create_simple("pl080", 0x10130000, pic[17]);
6a824ec3
PB
303 sysbus_create_simple("sp804", 0x101e2000, pic[4]);
304 sysbus_create_simple("sp804", 0x101e3000, pic[5]);
cdbdb648 305
853e65e0
JCPV
306 sysbus_create_simple("pl061", 0x101e4000, pic[6]);
307 sysbus_create_simple("pl061", 0x101e5000, pic[7]);
308 sysbus_create_simple("pl061", 0x101e6000, pic[8]);
309 sysbus_create_simple("pl061", 0x101e7000, pic[9]);
310
cdbdb648
PB
311 /* The versatile/PB actually has a modified Color LCD controller
312 that includes hardware cursor support from the PL111. */
242ea2c6
PM
313 dev = sysbus_create_simple("pl110_versatile", 0x10120000, pic[16]);
314 /* Wire up the mux control signals from the SYS_CLCD register */
315 qdev_connect_gpio_out(sysctl, 0, qdev_get_gpio_in(dev, 0));
cdbdb648 316
aa9311d8
PB
317 sysbus_create_varargs("pl181", 0x10005000, sic[22], sic[1], NULL);
318 sysbus_create_varargs("pl181", 0x1000b000, sic[23], sic[2], NULL);
a1bb27b1 319
7e1543c2 320 /* Add PL031 Real Time Clock. */
a63bdb31 321 sysbus_create_simple("pl031", 0x101e8000, pic[10]);
7e1543c2 322
b1f05696 323 dev = sysbus_create_simple("versatile_i2c", 0x10002000, NULL);
a5c82852 324 i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
b1f05696
OA
325 i2c_create_slave(i2c, "ds1338", 0x68);
326
d028d02d
MS
327 /* Add PL041 AACI Interface to the LM4549 codec */
328 pl041 = qdev_create(NULL, "pl041");
329 qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
330 qdev_init_nofail(pl041);
1356b98d
AF
331 sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, 0x10004000);
332 sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, sic[24]);
d028d02d 333
16406950 334 /* Memory map for Versatile/PB: */
cdbdb648
PB
335 /* 0x10000000 System registers. */
336 /* 0x10001000 PCI controller config registers. */
337 /* 0x10002000 Serial bus interface. */
338 /* 0x10003000 Secondary interrupt controller. */
339 /* 0x10004000 AACI (audio). */
a1bb27b1 340 /* 0x10005000 MMCI0. */
cdbdb648
PB
341 /* 0x10006000 KMI0 (keyboard). */
342 /* 0x10007000 KMI1 (mouse). */
343 /* 0x10008000 Character LCD Interface. */
344 /* 0x10009000 UART3. */
345 /* 0x1000a000 Smart card 1. */
a1bb27b1 346 /* 0x1000b000 MMCI1. */
cdbdb648
PB
347 /* 0x10010000 Ethernet. */
348 /* 0x10020000 USB. */
349 /* 0x10100000 SSMC. */
350 /* 0x10110000 MPMC. */
351 /* 0x10120000 CLCD Controller. */
352 /* 0x10130000 DMA Controller. */
353 /* 0x10140000 Vectored interrupt controller. */
354 /* 0x101d0000 AHB Monitor Interface. */
355 /* 0x101e0000 System Controller. */
356 /* 0x101e1000 Watchdog Interface. */
357 /* 0x101e2000 Timer 0/1. */
358 /* 0x101e3000 Timer 2/3. */
359 /* 0x101e4000 GPIO port 0. */
360 /* 0x101e5000 GPIO port 1. */
361 /* 0x101e6000 GPIO port 2. */
362 /* 0x101e7000 GPIO port 3. */
363 /* 0x101e8000 RTC. */
364 /* 0x101f0000 Smart card 0. */
365 /* 0x101f1000 UART0. */
366 /* 0x101f2000 UART1. */
367 /* 0x101f3000 UART2. */
368 /* 0x101f4000 SSPI. */
964c695a
EB
369 /* 0x34000000 NOR Flash */
370
371 dinfo = drive_get(IF_PFLASH, 0, 0);
372 if (!pflash_cfi01_register(VERSATILE_FLASH_ADDR, NULL, "versatile.flash",
fa1d36df 373 VERSATILE_FLASH_SIZE,
4be74634 374 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
964c695a
EB
375 VERSATILE_FLASH_SECT_SIZE,
376 VERSATILE_FLASH_SIZE / VERSATILE_FLASH_SECT_SIZE,
377 4, 0x0089, 0x0018, 0x0000, 0x0, 0)) {
378 fprintf(stderr, "qemu: Error registering flash memory.\n");
379 }
cdbdb648 380
3ef96221
MA
381 versatile_binfo.ram_size = machine->ram_size;
382 versatile_binfo.kernel_filename = machine->kernel_filename;
383 versatile_binfo.kernel_cmdline = machine->kernel_cmdline;
384 versatile_binfo.initrd_filename = machine->initrd_filename;
f93eb9ff 385 versatile_binfo.board_id = board_id;
3aaa8dfa 386 arm_load_kernel(cpu, &versatile_binfo);
16406950
PB
387}
388
3ef96221 389static void vpb_init(MachineState *machine)
16406950 390{
3ef96221 391 versatile_init(machine, 0x183);
16406950
PB
392}
393
3ef96221 394static void vab_init(MachineState *machine)
16406950 395{
3ef96221 396 versatile_init(machine, 0x25e);
cdbdb648
PB
397}
398
8a661aea 399static void versatilepb_class_init(ObjectClass *oc, void *data)
e264d29d 400{
8a661aea
AF
401 MachineClass *mc = MACHINE_CLASS(oc);
402
e264d29d
EH
403 mc->desc = "ARM Versatile/PB (ARM926EJ-S)";
404 mc->init = vpb_init;
405 mc->block_default_type = IF_SCSI;
406}
16406950 407
8a661aea
AF
408static const TypeInfo versatilepb_type = {
409 .name = MACHINE_TYPE_NAME("versatilepb"),
410 .parent = TYPE_MACHINE,
411 .class_init = versatilepb_class_init,
412};
3950f18b 413
8a661aea 414static void versatileab_class_init(ObjectClass *oc, void *data)
f80f9ec9 415{
8a661aea
AF
416 MachineClass *mc = MACHINE_CLASS(oc);
417
e264d29d
EH
418 mc->desc = "ARM Versatile/AB (ARM926EJ-S)";
419 mc->init = vab_init;
420 mc->block_default_type = IF_SCSI;
f80f9ec9
AL
421}
422
8a661aea
AF
423static const TypeInfo versatileab_type = {
424 .name = MACHINE_TYPE_NAME("versatileab"),
425 .parent = TYPE_MACHINE,
426 .class_init = versatileab_class_init,
427};
428
429static void versatile_machine_init(void)
430{
431 type_register_static(&versatilepb_type);
432 type_register_static(&versatileab_type);
433}
434
0e6aac87 435type_init(versatile_machine_init)
f80f9ec9 436
999e12bb
AL
437static void vpb_sic_class_init(ObjectClass *klass, void *data)
438{
39bffca2 439 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 440
39bffca2 441 dc->vmsd = &vmstate_vpb_sic;
999e12bb
AL
442}
443
8c43a6f0 444static const TypeInfo vpb_sic_info = {
cfc6b245 445 .name = TYPE_VERSATILE_PB_SIC,
39bffca2
AL
446 .parent = TYPE_SYS_BUS_DEVICE,
447 .instance_size = sizeof(vpb_sic_state),
0bc91ab3 448 .instance_init = vpb_sic_init,
39bffca2 449 .class_init = vpb_sic_class_init,
a796d0ac
PM
450};
451
83f7d43a 452static void versatilepb_register_types(void)
3950f18b 453{
39bffca2 454 type_register_static(&vpb_sic_info);
3950f18b
PB
455}
456
83f7d43a 457type_init(versatilepb_register_types)