2 * INTC device simulation in PKUnity SoC
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
25 /* Update interrupt status after enabled or pending bits have been changed. */
26 static void puv3_intc_update(PUV3INTCState
*s
)
28 if (s
->reg_ICMR
& s
->reg_ICPR
) {
29 qemu_irq_raise(s
->parent_irq
);
31 qemu_irq_lower(s
->parent_irq
);
35 /* Process a change in an external INTC input. */
36 static void puv3_intc_handler(void *opaque
, int irq
, int level
)
38 PUV3INTCState
*s
= opaque
;
40 DPRINTF("irq 0x%x, level 0x%x\n", irq
, level
);
42 s
->reg_ICPR
|= (1 << irq
);
44 s
->reg_ICPR
&= ~(1 << irq
);
49 static uint64_t puv3_intc_read(void *opaque
, target_phys_addr_t offset
,
52 PUV3INTCState
*s
= opaque
;
56 case 0x04: /* INTC_ICMR */
59 case 0x0c: /* INTC_ICIP */
60 ret
= s
->reg_ICPR
; /* the same value with ICPR */
63 DPRINTF("Bad offset %x\n", (int)offset
);
65 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
69 static void puv3_intc_write(void *opaque
, target_phys_addr_t offset
,
70 uint64_t value
, unsigned size
)
72 PUV3INTCState
*s
= opaque
;
74 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
76 case 0x00: /* INTC_ICLR */
77 case 0x14: /* INTC_ICCR */
79 case 0x04: /* INTC_ICMR */
83 DPRINTF("Bad offset 0x%x\n", (int)offset
);
89 static const MemoryRegionOps puv3_intc_ops
= {
90 .read
= puv3_intc_read
,
91 .write
= puv3_intc_write
,
96 .endianness
= DEVICE_NATIVE_ENDIAN
,
99 static int puv3_intc_init(SysBusDevice
*dev
)
101 PUV3INTCState
*s
= FROM_SYSBUS(PUV3INTCState
, dev
);
103 qdev_init_gpio_in(&s
->busdev
.qdev
, puv3_intc_handler
, PUV3_IRQS_NR
);
104 sysbus_init_irq(&s
->busdev
, &s
->parent_irq
);
109 memory_region_init_io(&s
->iomem
, &puv3_intc_ops
, s
, "puv3_intc",
111 sysbus_init_mmio(dev
, &s
->iomem
);
116 static void puv3_intc_class_init(ObjectClass
*klass
, void *data
)
118 SysBusDeviceClass
*sdc
= SYS_BUS_DEVICE_CLASS(klass
);
120 sdc
->init
= puv3_intc_init
;
123 static const TypeInfo puv3_intc_info
= {
125 .parent
= TYPE_SYS_BUS_DEVICE
,
126 .instance_size
= sizeof(PUV3INTCState
),
127 .class_init
= puv3_intc_class_init
,
130 static void puv3_intc_register_type(void)
132 type_register_static(&puv3_intc_info
);
135 type_init(puv3_intc_register_type
)