2 * LatticeMico32 CPU interrupt controller logic.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "hw/i386/pc.h"
24 #include "monitor/monitor.h"
25 #include "hw/sysbus.h"
27 #include "hw/lm32/lm32_pic.h"
29 #define TYPE_LM32_PIC "lm32-pic"
30 #define LM32_PIC(obj) OBJECT_CHECK(LM32PicState, (obj), TYPE_LM32_PIC)
33 SysBusDevice parent_obj
;
36 uint32_t im
; /* interrupt mask */
37 uint32_t ip
; /* interrupt pending */
41 uint32_t stats_irq_count
[32];
43 typedef struct LM32PicState LM32PicState
;
45 static LM32PicState
*pic
;
46 void lm32_do_pic_info(Monitor
*mon
, const QDict
*qdict
)
52 monitor_printf(mon
, "lm32-pic: im=%08x ip=%08x irq_state=%08x\n",
53 pic
->im
, pic
->ip
, pic
->irq_state
);
56 void lm32_irq_info(Monitor
*mon
, const QDict
*qdict
)
65 monitor_printf(mon
, "IRQ statistics:\n");
66 for (i
= 0; i
< 32; i
++) {
67 count
= pic
->stats_irq_count
[i
];
69 monitor_printf(mon
, "%2d: %u\n", i
, count
);
74 static void update_irq(LM32PicState
*s
)
76 s
->ip
|= s
->irq_state
;
79 trace_lm32_pic_raise_irq();
80 qemu_irq_raise(s
->parent_irq
);
82 trace_lm32_pic_lower_irq();
83 qemu_irq_lower(s
->parent_irq
);
87 static void irq_handler(void *opaque
, int irq
, int level
)
89 LM32PicState
*s
= opaque
;
92 trace_lm32_pic_interrupt(irq
, level
);
95 s
->irq_state
|= (1 << irq
);
96 s
->stats_irq_count
[irq
]++;
98 s
->irq_state
&= ~(1 << irq
);
104 void lm32_pic_set_im(DeviceState
*d
, uint32_t im
)
106 LM32PicState
*s
= LM32_PIC(d
);
108 trace_lm32_pic_set_im(im
);
114 void lm32_pic_set_ip(DeviceState
*d
, uint32_t ip
)
116 LM32PicState
*s
= LM32_PIC(d
);
118 trace_lm32_pic_set_ip(ip
);
126 uint32_t lm32_pic_get_im(DeviceState
*d
)
128 LM32PicState
*s
= LM32_PIC(d
);
130 trace_lm32_pic_get_im(s
->im
);
134 uint32_t lm32_pic_get_ip(DeviceState
*d
)
136 LM32PicState
*s
= LM32_PIC(d
);
138 trace_lm32_pic_get_ip(s
->ip
);
142 static void pic_reset(DeviceState
*d
)
144 LM32PicState
*s
= LM32_PIC(d
);
150 for (i
= 0; i
< 32; i
++) {
151 s
->stats_irq_count
[i
] = 0;
155 static int lm32_pic_init(SysBusDevice
*sbd
)
157 DeviceState
*dev
= DEVICE(sbd
);
158 LM32PicState
*s
= LM32_PIC(dev
);
160 qdev_init_gpio_in(dev
, irq_handler
, 32);
161 sysbus_init_irq(sbd
, &s
->parent_irq
);
168 static const VMStateDescription vmstate_lm32_pic
= {
171 .minimum_version_id
= 1,
172 .minimum_version_id_old
= 1,
173 .fields
= (VMStateField
[]) {
174 VMSTATE_UINT32(im
, LM32PicState
),
175 VMSTATE_UINT32(ip
, LM32PicState
),
176 VMSTATE_UINT32(irq_state
, LM32PicState
),
177 VMSTATE_UINT32_ARRAY(stats_irq_count
, LM32PicState
, 32),
178 VMSTATE_END_OF_LIST()
182 static void lm32_pic_class_init(ObjectClass
*klass
, void *data
)
184 DeviceClass
*dc
= DEVICE_CLASS(klass
);
185 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
187 k
->init
= lm32_pic_init
;
188 dc
->reset
= pic_reset
;
189 dc
->vmsd
= &vmstate_lm32_pic
;
192 static const TypeInfo lm32_pic_info
= {
193 .name
= TYPE_LM32_PIC
,
194 .parent
= TYPE_SYS_BUS_DEVICE
,
195 .instance_size
= sizeof(LM32PicState
),
196 .class_init
= lm32_pic_class_init
,
199 static void lm32_pic_register_types(void)
201 type_register_static(&lm32_pic_info
);
204 type_init(lm32_pic_register_types
)