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.
11 #include "qemu/osdep.h"
12 #include "hw/sysbus.h"
15 #include "hw/unicore32/puv3.h"
17 #define TYPE_PUV3_INTC "puv3_intc"
18 #define PUV3_INTC(obj) OBJECT_CHECK(PUV3INTCState, (obj), TYPE_PUV3_INTC)
20 typedef struct PUV3INTCState
{
21 SysBusDevice parent_obj
;
30 /* Update interrupt status after enabled or pending bits have been changed. */
31 static void puv3_intc_update(PUV3INTCState
*s
)
33 if (s
->reg_ICMR
& s
->reg_ICPR
) {
34 qemu_irq_raise(s
->parent_irq
);
36 qemu_irq_lower(s
->parent_irq
);
40 /* Process a change in an external INTC input. */
41 static void puv3_intc_handler(void *opaque
, int irq
, int level
)
43 PUV3INTCState
*s
= opaque
;
45 DPRINTF("irq 0x%x, level 0x%x\n", irq
, level
);
47 s
->reg_ICPR
|= (1 << irq
);
49 s
->reg_ICPR
&= ~(1 << irq
);
54 static uint64_t puv3_intc_read(void *opaque
, hwaddr offset
,
57 PUV3INTCState
*s
= opaque
;
61 case 0x04: /* INTC_ICMR */
64 case 0x0c: /* INTC_ICIP */
65 ret
= s
->reg_ICPR
; /* the same value with ICPR */
68 DPRINTF("Bad offset %x\n", (int)offset
);
70 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
74 static void puv3_intc_write(void *opaque
, hwaddr offset
,
75 uint64_t value
, unsigned size
)
77 PUV3INTCState
*s
= opaque
;
79 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
81 case 0x00: /* INTC_ICLR */
82 case 0x14: /* INTC_ICCR */
84 case 0x04: /* INTC_ICMR */
88 DPRINTF("Bad offset 0x%x\n", (int)offset
);
94 static const MemoryRegionOps puv3_intc_ops
= {
95 .read
= puv3_intc_read
,
96 .write
= puv3_intc_write
,
101 .endianness
= DEVICE_NATIVE_ENDIAN
,
104 static void puv3_intc_realize(DeviceState
*dev
, Error
**errp
)
106 PUV3INTCState
*s
= PUV3_INTC(dev
);
107 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
109 qdev_init_gpio_in(dev
, puv3_intc_handler
, PUV3_IRQS_NR
);
110 sysbus_init_irq(sbd
, &s
->parent_irq
);
115 memory_region_init_io(&s
->iomem
, OBJECT(s
), &puv3_intc_ops
, s
, "puv3_intc",
117 sysbus_init_mmio(sbd
, &s
->iomem
);
120 static void puv3_intc_class_init(ObjectClass
*klass
, void *data
)
122 DeviceClass
*dc
= DEVICE_CLASS(klass
);
123 dc
->realize
= puv3_intc_realize
;
126 static const TypeInfo puv3_intc_info
= {
127 .name
= TYPE_PUV3_INTC
,
128 .parent
= TYPE_SYS_BUS_DEVICE
,
129 .instance_size
= sizeof(PUV3INTCState
),
130 .class_init
= puv3_intc_class_init
,
133 static void puv3_intc_register_type(void)
135 type_register_static(&puv3_intc_info
);
138 type_init(puv3_intc_register_type
)