hw/9pfs: Documentation changes related to proxy fs
[qemu/ar7.git] / hw / integratorcp.c
blob2551236d5cbd3e8ac70d040c94a2d52eb1574695
1 /*
2 * ARM Integrator CP System emulation.
4 * Copyright (c) 2005-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL
8 */
10 #include "sysbus.h"
11 #include "primecell.h"
12 #include "devices.h"
13 #include "boards.h"
14 #include "arm-misc.h"
15 #include "net.h"
16 #include "exec-memory.h"
17 #include "sysemu.h"
19 typedef struct {
20 SysBusDevice busdev;
21 MemoryRegion iomem;
22 uint32_t memsz;
23 MemoryRegion flash;
24 bool flash_mapped;
25 uint32_t cm_osc;
26 uint32_t cm_ctrl;
27 uint32_t cm_lock;
28 uint32_t cm_auxosc;
29 uint32_t cm_sdram;
30 uint32_t cm_init;
31 uint32_t cm_flags;
32 uint32_t cm_nvflags;
33 uint32_t int_level;
34 uint32_t irq_enabled;
35 uint32_t fiq_enabled;
36 } integratorcm_state;
38 static uint8_t integrator_spd[128] = {
39 128, 8, 4, 11, 9, 1, 64, 0, 2, 0xa0, 0xa0, 0, 0, 8, 0, 1,
40 0xe, 4, 0x1c, 1, 2, 0x20, 0xc0, 0, 0, 0, 0, 0x30, 0x28, 0x30, 0x28, 0x40
43 static uint64_t integratorcm_read(void *opaque, target_phys_addr_t offset,
44 unsigned size)
46 integratorcm_state *s = (integratorcm_state *)opaque;
47 if (offset >= 0x100 && offset < 0x200) {
48 /* CM_SPD */
49 if (offset >= 0x180)
50 return 0;
51 return integrator_spd[offset >> 2];
53 switch (offset >> 2) {
54 case 0: /* CM_ID */
55 return 0x411a3001;
56 case 1: /* CM_PROC */
57 return 0;
58 case 2: /* CM_OSC */
59 return s->cm_osc;
60 case 3: /* CM_CTRL */
61 return s->cm_ctrl;
62 case 4: /* CM_STAT */
63 return 0x00100000;
64 case 5: /* CM_LOCK */
65 if (s->cm_lock == 0xa05f) {
66 return 0x1a05f;
67 } else {
68 return s->cm_lock;
70 case 6: /* CM_LMBUSCNT */
71 /* ??? High frequency timer. */
72 hw_error("integratorcm_read: CM_LMBUSCNT");
73 case 7: /* CM_AUXOSC */
74 return s->cm_auxosc;
75 case 8: /* CM_SDRAM */
76 return s->cm_sdram;
77 case 9: /* CM_INIT */
78 return s->cm_init;
79 case 10: /* CM_REFCT */
80 /* ??? High frequency timer. */
81 hw_error("integratorcm_read: CM_REFCT");
82 case 12: /* CM_FLAGS */
83 return s->cm_flags;
84 case 14: /* CM_NVFLAGS */
85 return s->cm_nvflags;
86 case 16: /* CM_IRQ_STAT */
87 return s->int_level & s->irq_enabled;
88 case 17: /* CM_IRQ_RSTAT */
89 return s->int_level;
90 case 18: /* CM_IRQ_ENSET */
91 return s->irq_enabled;
92 case 20: /* CM_SOFT_INTSET */
93 return s->int_level & 1;
94 case 24: /* CM_FIQ_STAT */
95 return s->int_level & s->fiq_enabled;
96 case 25: /* CM_FIQ_RSTAT */
97 return s->int_level;
98 case 26: /* CM_FIQ_ENSET */
99 return s->fiq_enabled;
100 case 32: /* CM_VOLTAGE_CTL0 */
101 case 33: /* CM_VOLTAGE_CTL1 */
102 case 34: /* CM_VOLTAGE_CTL2 */
103 case 35: /* CM_VOLTAGE_CTL3 */
104 /* ??? Voltage control unimplemented. */
105 return 0;
106 default:
107 hw_error("integratorcm_read: Unimplemented offset 0x%x\n",
108 (int)offset);
109 return 0;
113 static void integratorcm_do_remap(integratorcm_state *s, int flash)
115 if (flash) {
116 if (s->flash_mapped) {
117 sysbus_del_memory(&s->busdev, &s->flash);
118 s->flash_mapped = false;
120 } else {
121 if (!s->flash_mapped) {
122 sysbus_add_memory_overlap(&s->busdev, 0, &s->flash, 1);
123 s->flash_mapped = true;
126 //??? tlb_flush (cpu_single_env, 1);
129 static void integratorcm_set_ctrl(integratorcm_state *s, uint32_t value)
131 if (value & 8) {
132 qemu_system_reset_request();
134 if ((s->cm_ctrl ^ value) & 4) {
135 integratorcm_do_remap(s, (value & 4) == 0);
137 if ((s->cm_ctrl ^ value) & 1) {
138 /* (value & 1) != 0 means the green "MISC LED" is lit.
139 * We don't have any nice place to display LEDs. printf is a bad
140 * idea because Linux uses the LED as a heartbeat and the output
141 * will swamp anything else on the terminal.
144 /* Note that the RESET bit [3] always reads as zero */
145 s->cm_ctrl = (s->cm_ctrl & ~5) | (value & 5);
148 static void integratorcm_update(integratorcm_state *s)
150 /* ??? The CPU irq/fiq is raised when either the core module or base PIC
151 are active. */
152 if (s->int_level & (s->irq_enabled | s->fiq_enabled))
153 hw_error("Core module interrupt\n");
156 static void integratorcm_write(void *opaque, target_phys_addr_t offset,
157 uint64_t value, unsigned size)
159 integratorcm_state *s = (integratorcm_state *)opaque;
160 switch (offset >> 2) {
161 case 2: /* CM_OSC */
162 if (s->cm_lock == 0xa05f)
163 s->cm_osc = value;
164 break;
165 case 3: /* CM_CTRL */
166 integratorcm_set_ctrl(s, value);
167 break;
168 case 5: /* CM_LOCK */
169 s->cm_lock = value & 0xffff;
170 break;
171 case 7: /* CM_AUXOSC */
172 if (s->cm_lock == 0xa05f)
173 s->cm_auxosc = value;
174 break;
175 case 8: /* CM_SDRAM */
176 s->cm_sdram = value;
177 break;
178 case 9: /* CM_INIT */
179 /* ??? This can change the memory bus frequency. */
180 s->cm_init = value;
181 break;
182 case 12: /* CM_FLAGSS */
183 s->cm_flags |= value;
184 break;
185 case 13: /* CM_FLAGSC */
186 s->cm_flags &= ~value;
187 break;
188 case 14: /* CM_NVFLAGSS */
189 s->cm_nvflags |= value;
190 break;
191 case 15: /* CM_NVFLAGSS */
192 s->cm_nvflags &= ~value;
193 break;
194 case 18: /* CM_IRQ_ENSET */
195 s->irq_enabled |= value;
196 integratorcm_update(s);
197 break;
198 case 19: /* CM_IRQ_ENCLR */
199 s->irq_enabled &= ~value;
200 integratorcm_update(s);
201 break;
202 case 20: /* CM_SOFT_INTSET */
203 s->int_level |= (value & 1);
204 integratorcm_update(s);
205 break;
206 case 21: /* CM_SOFT_INTCLR */
207 s->int_level &= ~(value & 1);
208 integratorcm_update(s);
209 break;
210 case 26: /* CM_FIQ_ENSET */
211 s->fiq_enabled |= value;
212 integratorcm_update(s);
213 break;
214 case 27: /* CM_FIQ_ENCLR */
215 s->fiq_enabled &= ~value;
216 integratorcm_update(s);
217 break;
218 case 32: /* CM_VOLTAGE_CTL0 */
219 case 33: /* CM_VOLTAGE_CTL1 */
220 case 34: /* CM_VOLTAGE_CTL2 */
221 case 35: /* CM_VOLTAGE_CTL3 */
222 /* ??? Voltage control unimplemented. */
223 break;
224 default:
225 hw_error("integratorcm_write: Unimplemented offset 0x%x\n",
226 (int)offset);
227 break;
231 /* Integrator/CM control registers. */
233 static const MemoryRegionOps integratorcm_ops = {
234 .read = integratorcm_read,
235 .write = integratorcm_write,
236 .endianness = DEVICE_NATIVE_ENDIAN,
239 static int integratorcm_init(SysBusDevice *dev)
241 integratorcm_state *s = FROM_SYSBUS(integratorcm_state, dev);
243 s->cm_osc = 0x01000048;
244 /* ??? What should the high bits of this value be? */
245 s->cm_auxosc = 0x0007feff;
246 s->cm_sdram = 0x00011122;
247 if (s->memsz >= 256) {
248 integrator_spd[31] = 64;
249 s->cm_sdram |= 0x10;
250 } else if (s->memsz >= 128) {
251 integrator_spd[31] = 32;
252 s->cm_sdram |= 0x0c;
253 } else if (s->memsz >= 64) {
254 integrator_spd[31] = 16;
255 s->cm_sdram |= 0x08;
256 } else if (s->memsz >= 32) {
257 integrator_spd[31] = 4;
258 s->cm_sdram |= 0x04;
259 } else {
260 integrator_spd[31] = 2;
262 memcpy(integrator_spd + 73, "QEMU-MEMORY", 11);
263 s->cm_init = 0x00000112;
264 memory_region_init_ram(&s->flash, NULL, "integrator.flash", 0x100000);
265 s->flash_mapped = false;
267 memory_region_init_io(&s->iomem, &integratorcm_ops, s,
268 "integratorcm", 0x00800000);
269 sysbus_init_mmio(dev, &s->iomem);
271 integratorcm_do_remap(s, 1);
272 /* ??? Save/restore. */
273 return 0;
276 /* Integrator/CP hardware emulation. */
277 /* Primary interrupt controller. */
279 typedef struct icp_pic_state
281 SysBusDevice busdev;
282 MemoryRegion iomem;
283 uint32_t level;
284 uint32_t irq_enabled;
285 uint32_t fiq_enabled;
286 qemu_irq parent_irq;
287 qemu_irq parent_fiq;
288 } icp_pic_state;
290 static void icp_pic_update(icp_pic_state *s)
292 uint32_t flags;
294 flags = (s->level & s->irq_enabled);
295 qemu_set_irq(s->parent_irq, flags != 0);
296 flags = (s->level & s->fiq_enabled);
297 qemu_set_irq(s->parent_fiq, flags != 0);
300 static void icp_pic_set_irq(void *opaque, int irq, int level)
302 icp_pic_state *s = (icp_pic_state *)opaque;
303 if (level)
304 s->level |= 1 << irq;
305 else
306 s->level &= ~(1 << irq);
307 icp_pic_update(s);
310 static uint64_t icp_pic_read(void *opaque, target_phys_addr_t offset,
311 unsigned size)
313 icp_pic_state *s = (icp_pic_state *)opaque;
315 switch (offset >> 2) {
316 case 0: /* IRQ_STATUS */
317 return s->level & s->irq_enabled;
318 case 1: /* IRQ_RAWSTAT */
319 return s->level;
320 case 2: /* IRQ_ENABLESET */
321 return s->irq_enabled;
322 case 4: /* INT_SOFTSET */
323 return s->level & 1;
324 case 8: /* FRQ_STATUS */
325 return s->level & s->fiq_enabled;
326 case 9: /* FRQ_RAWSTAT */
327 return s->level;
328 case 10: /* FRQ_ENABLESET */
329 return s->fiq_enabled;
330 case 3: /* IRQ_ENABLECLR */
331 case 5: /* INT_SOFTCLR */
332 case 11: /* FRQ_ENABLECLR */
333 default:
334 printf ("icp_pic_read: Bad register offset 0x%x\n", (int)offset);
335 return 0;
339 static void icp_pic_write(void *opaque, target_phys_addr_t offset,
340 uint64_t value, unsigned size)
342 icp_pic_state *s = (icp_pic_state *)opaque;
344 switch (offset >> 2) {
345 case 2: /* IRQ_ENABLESET */
346 s->irq_enabled |= value;
347 break;
348 case 3: /* IRQ_ENABLECLR */
349 s->irq_enabled &= ~value;
350 break;
351 case 4: /* INT_SOFTSET */
352 if (value & 1)
353 icp_pic_set_irq(s, 0, 1);
354 break;
355 case 5: /* INT_SOFTCLR */
356 if (value & 1)
357 icp_pic_set_irq(s, 0, 0);
358 break;
359 case 10: /* FRQ_ENABLESET */
360 s->fiq_enabled |= value;
361 break;
362 case 11: /* FRQ_ENABLECLR */
363 s->fiq_enabled &= ~value;
364 break;
365 case 0: /* IRQ_STATUS */
366 case 1: /* IRQ_RAWSTAT */
367 case 8: /* FRQ_STATUS */
368 case 9: /* FRQ_RAWSTAT */
369 default:
370 printf ("icp_pic_write: Bad register offset 0x%x\n", (int)offset);
371 return;
373 icp_pic_update(s);
376 static const MemoryRegionOps icp_pic_ops = {
377 .read = icp_pic_read,
378 .write = icp_pic_write,
379 .endianness = DEVICE_NATIVE_ENDIAN,
382 static int icp_pic_init(SysBusDevice *dev)
384 icp_pic_state *s = FROM_SYSBUS(icp_pic_state, dev);
386 qdev_init_gpio_in(&dev->qdev, icp_pic_set_irq, 32);
387 sysbus_init_irq(dev, &s->parent_irq);
388 sysbus_init_irq(dev, &s->parent_fiq);
389 memory_region_init_io(&s->iomem, &icp_pic_ops, s, "icp-pic", 0x00800000);
390 sysbus_init_mmio(dev, &s->iomem);
391 return 0;
394 /* CP control registers. */
396 static uint64_t icp_control_read(void *opaque, target_phys_addr_t offset,
397 unsigned size)
399 switch (offset >> 2) {
400 case 0: /* CP_IDFIELD */
401 return 0x41034003;
402 case 1: /* CP_FLASHPROG */
403 return 0;
404 case 2: /* CP_INTREG */
405 return 0;
406 case 3: /* CP_DECODE */
407 return 0x11;
408 default:
409 hw_error("icp_control_read: Bad offset %x\n", (int)offset);
410 return 0;
414 static void icp_control_write(void *opaque, target_phys_addr_t offset,
415 uint64_t value, unsigned size)
417 switch (offset >> 2) {
418 case 1: /* CP_FLASHPROG */
419 case 2: /* CP_INTREG */
420 case 3: /* CP_DECODE */
421 /* Nothing interesting implemented yet. */
422 break;
423 default:
424 hw_error("icp_control_write: Bad offset %x\n", (int)offset);
428 static const MemoryRegionOps icp_control_ops = {
429 .read = icp_control_read,
430 .write = icp_control_write,
431 .endianness = DEVICE_NATIVE_ENDIAN,
434 static void icp_control_init(target_phys_addr_t base)
436 MemoryRegion *io;
438 io = (MemoryRegion *)g_malloc0(sizeof(MemoryRegion));
439 memory_region_init_io(io, &icp_control_ops, NULL,
440 "control", 0x00800000);
441 memory_region_add_subregion(get_system_memory(), base, io);
442 /* ??? Save/restore. */
446 /* Board init. */
448 static struct arm_boot_info integrator_binfo = {
449 .loader_start = 0x0,
450 .board_id = 0x113,
453 static void integratorcp_init(ram_addr_t ram_size,
454 const char *boot_device,
455 const char *kernel_filename, const char *kernel_cmdline,
456 const char *initrd_filename, const char *cpu_model)
458 CPUState *env;
459 MemoryRegion *address_space_mem = get_system_memory();
460 MemoryRegion *ram = g_new(MemoryRegion, 1);
461 MemoryRegion *ram_alias = g_new(MemoryRegion, 1);
462 qemu_irq pic[32];
463 qemu_irq *cpu_pic;
464 DeviceState *dev;
465 int i;
467 if (!cpu_model)
468 cpu_model = "arm926";
469 env = cpu_init(cpu_model);
470 if (!env) {
471 fprintf(stderr, "Unable to find CPU definition\n");
472 exit(1);
474 memory_region_init_ram(ram, NULL, "integrator.ram", ram_size);
475 /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */
476 /* ??? RAM should repeat to fill physical memory space. */
477 /* SDRAM at address zero*/
478 memory_region_add_subregion(address_space_mem, 0, ram);
479 /* And again at address 0x80000000 */
480 memory_region_init_alias(ram_alias, "ram.alias", ram, 0, ram_size);
481 memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
483 dev = qdev_create(NULL, "integrator_core");
484 qdev_prop_set_uint32(dev, "memsz", ram_size >> 20);
485 qdev_init_nofail(dev);
486 sysbus_mmio_map((SysBusDevice *)dev, 0, 0x10000000);
488 cpu_pic = arm_pic_init_cpu(env);
489 dev = sysbus_create_varargs("integrator_pic", 0x14000000,
490 cpu_pic[ARM_PIC_CPU_IRQ],
491 cpu_pic[ARM_PIC_CPU_FIQ], NULL);
492 for (i = 0; i < 32; i++) {
493 pic[i] = qdev_get_gpio_in(dev, i);
495 sysbus_create_simple("integrator_pic", 0xca000000, pic[26]);
496 sysbus_create_varargs("integrator_pit", 0x13000000,
497 pic[5], pic[6], pic[7], NULL);
498 sysbus_create_simple("pl031", 0x15000000, pic[8]);
499 sysbus_create_simple("pl011", 0x16000000, pic[1]);
500 sysbus_create_simple("pl011", 0x17000000, pic[2]);
501 icp_control_init(0xcb000000);
502 sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
503 sysbus_create_simple("pl050_mouse", 0x19000000, pic[4]);
504 sysbus_create_varargs("pl181", 0x1c000000, pic[23], pic[24], NULL);
505 if (nd_table[0].vlan)
506 smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
508 sysbus_create_simple("pl110", 0xc0000000, pic[22]);
510 integrator_binfo.ram_size = ram_size;
511 integrator_binfo.kernel_filename = kernel_filename;
512 integrator_binfo.kernel_cmdline = kernel_cmdline;
513 integrator_binfo.initrd_filename = initrd_filename;
514 arm_load_kernel(env, &integrator_binfo);
517 static QEMUMachine integratorcp_machine = {
518 .name = "integratorcp",
519 .desc = "ARM Integrator/CP (ARM926EJ-S)",
520 .init = integratorcp_init,
521 .is_default = 1,
524 static void integratorcp_machine_init(void)
526 qemu_register_machine(&integratorcp_machine);
529 machine_init(integratorcp_machine_init);
531 static SysBusDeviceInfo core_info = {
532 .init = integratorcm_init,
533 .qdev.name = "integrator_core",
534 .qdev.size = sizeof(integratorcm_state),
535 .qdev.props = (Property[]) {
536 DEFINE_PROP_UINT32("memsz", integratorcm_state, memsz, 0),
537 DEFINE_PROP_END_OF_LIST(),
541 static void integratorcp_register_devices(void)
543 sysbus_register_dev("integrator_pic", sizeof(icp_pic_state), icp_pic_init);
544 sysbus_register_withprop(&core_info);
547 device_init(integratorcp_register_devices)