1 /* 2 * Allwinner A10 SoC emulation 3 * 4 * Copyright (C) 2013 Li Guang 5 * Written by Li Guang <lig.fnst@cn.fujitsu.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * for more details. 16 */ 17 18 #include "hw/sysbus.h" 19 #include "hw/devices.h" 20 #include "hw/arm/allwinner-a10.h" 21 22 static void aw_a10_init(Object *obj) 23 { 24 AwA10State *s = AW_A10(obj); 25 26 object_initialize(&s->cpu, sizeof(s->cpu), "cortex-a8-" TYPE_ARM_CPU); 27 object_property_add_child(obj, "cpu", OBJECT(&s->cpu), NULL); 28 29 object_initialize(&s->intc, sizeof(s->intc), TYPE_AW_A10_PIC); 30 qdev_set_parent_bus(DEVICE(&s->intc), sysbus_get_default()); 31 32 object_initialize(&s->timer, sizeof(s->timer), TYPE_AW_A10_PIT); 33 qdev_set_parent_bus(DEVICE(&s->timer), sysbus_get_default()); 34 } 35 36 static void aw_a10_realize(DeviceState *dev, Error **errp) 37 { 38 AwA10State *s = AW_A10(dev); 39 SysBusDevice *sysbusdev; 40 uint8_t i; 41 qemu_irq fiq, irq; 42 Error *err = NULL; 43 44 object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err); 45 if (err != NULL) { 46 error_propagate(errp, err); 47 return; 48 } 49 irq = qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ); 50 fiq = qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ); 51 52 object_property_set_bool(OBJECT(&s->intc), true, "realized", &err); 53 if (err != NULL) { 54 error_propagate(errp, err); 55 return; 56 } 57 sysbusdev = SYS_BUS_DEVICE(&s->intc); 58 sysbus_mmio_map(sysbusdev, 0, AW_A10_PIC_REG_BASE); 59 sysbus_connect_irq(sysbusdev, 0, irq); 60 sysbus_connect_irq(sysbusdev, 1, fiq); 61 for (i = 0; i < AW_A10_PIC_INT_NR; i++) { 62 s->irq[i] = qdev_get_gpio_in(DEVICE(&s->intc), i); 63 } 64 65 object_property_set_bool(OBJECT(&s->timer), true, "realized", &err); 66 if (err != NULL) { 67 error_propagate(errp, err); 68 return; 69 } 70 sysbusdev = SYS_BUS_DEVICE(&s->timer); 71 sysbus_mmio_map(sysbusdev, 0, AW_A10_PIT_REG_BASE); 72 sysbus_connect_irq(sysbusdev, 0, s->irq[22]); 73 sysbus_connect_irq(sysbusdev, 1, s->irq[23]); 74 sysbus_connect_irq(sysbusdev, 2, s->irq[24]); 75 sysbus_connect_irq(sysbusdev, 3, s->irq[25]); 76 sysbus_connect_irq(sysbusdev, 4, s->irq[67]); 77 sysbus_connect_irq(sysbusdev, 5, s->irq[68]); 78 79 serial_mm_init(get_system_memory(), AW_A10_UART0_REG_BASE, 2, s->irq[1], 80 115200, serial_hds[0], DEVICE_NATIVE_ENDIAN); 81 } 82 83 static void aw_a10_class_init(ObjectClass *oc, void *data) 84 { 85 DeviceClass *dc = DEVICE_CLASS(oc); 86 87 dc->realize = aw_a10_realize; 88 } 89 90 static const TypeInfo aw_a10_type_info = { 91 .name = TYPE_AW_A10, 92 .parent = TYPE_DEVICE, 93 .instance_size = sizeof(AwA10State), 94 .instance_init = aw_a10_init, 95 .class_init = aw_a10_class_init, 96 }; 97 98 static void aw_a10_register_types(void) 99 { 100 type_register_static(&aw_a10_type_info); 101 } 102 103 type_init(aw_a10_register_types) 104