]> Git Repo - qemu.git/blame - hw/intc/armv7m_nvic.c
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2015-02-16-v2-tag' into...
[qemu.git] / hw / intc / armv7m_nvic.c
CommitLineData
9ee6e8bb
PB
1/*
2 * ARM Nested Vectored Interrupt Controller
3 *
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
6 *
8e31bf38 7 * This code is licensed under the GPL.
9ee6e8bb
PB
8 *
9 * The ARMv7M System controller is fairly tightly tied in with the
10 * NVIC. Much of that is also implemented here.
11 */
12
83c9f4ca 13#include "hw/sysbus.h"
1de7afc9 14#include "qemu/timer.h"
bd2be150 15#include "hw/arm/arm.h"
022c62cb 16#include "exec/address-spaces.h"
47b43a1f 17#include "gic_internal.h"
9ee6e8bb
PB
18
19typedef struct {
fae15286 20 GICState gic;
9ee6e8bb
PB
21 struct {
22 uint32_t control;
23 uint32_t reload;
24 int64_t tick;
25 QEMUTimer *timer;
26 } systick;
2a29ddee
PM
27 MemoryRegion sysregmem;
28 MemoryRegion gic_iomem_alias;
29 MemoryRegion container;
a32134aa 30 uint32_t num_irq;
9ee6e8bb
PB
31} nvic_state;
32
1e8cae4d
PM
33#define TYPE_NVIC "armv7m_nvic"
34/**
35 * NVICClass:
36 * @parent_reset: the parent class' reset handler.
37 *
38 * A model of the v7M NVIC and System Controller
39 */
40typedef struct NVICClass {
41 /*< private >*/
42 ARMGICClass parent_class;
43 /*< public >*/
53111180 44 DeviceRealize parent_realize;
1e8cae4d
PM
45 void (*parent_reset)(DeviceState *dev);
46} NVICClass;
47
48#define NVIC_CLASS(klass) \
49 OBJECT_CLASS_CHECK(NVICClass, (klass), TYPE_NVIC)
50#define NVIC_GET_CLASS(obj) \
51 OBJECT_GET_CLASS(NVICClass, (obj), TYPE_NVIC)
52#define NVIC(obj) \
53 OBJECT_CHECK(nvic_state, (obj), TYPE_NVIC)
54
2a29ddee
PM
55static const uint8_t nvic_id[] = {
56 0x00, 0xb0, 0x1b, 0x00, 0x0d, 0xe0, 0x05, 0xb1
57};
58
9ee6e8bb
PB
59/* qemu timers run at 1GHz. We want something closer to 1MHz. */
60#define SYSTICK_SCALE 1000ULL
61
62#define SYSTICK_ENABLE (1 << 0)
63#define SYSTICK_TICKINT (1 << 1)
64#define SYSTICK_CLKSOURCE (1 << 2)
65#define SYSTICK_COUNTFLAG (1 << 16)
66
7ee930d0
BS
67int system_clock_scale;
68
e57ec016 69/* Conversion factor from qemu timer to SysTick frequencies. */
9ee6e8bb
PB
70static inline int64_t systick_scale(nvic_state *s)
71{
72 if (s->systick.control & SYSTICK_CLKSOURCE)
e57ec016 73 return system_clock_scale;
9ee6e8bb
PB
74 else
75 return 1000;
76}
77
78static void systick_reload(nvic_state *s, int reset)
79{
80 if (reset)
bc72ad67 81 s->systick.tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
9ee6e8bb 82 s->systick.tick += (s->systick.reload + 1) * systick_scale(s);
bc72ad67 83 timer_mod(s->systick.timer, s->systick.tick);
9ee6e8bb
PB
84}
85
86static void systick_timer_tick(void * opaque)
87{
88 nvic_state *s = (nvic_state *)opaque;
89 s->systick.control |= SYSTICK_COUNTFLAG;
90 if (s->systick.control & SYSTICK_TICKINT) {
91 /* Trigger the interrupt. */
92 armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK);
93 }
94 if (s->systick.reload == 0) {
95 s->systick.control &= ~SYSTICK_ENABLE;
96 } else {
97 systick_reload(s, 0);
98 }
99}
100
aecff692
PM
101static void systick_reset(nvic_state *s)
102{
103 s->systick.control = 0;
104 s->systick.reload = 0;
105 s->systick.tick = 0;
bc72ad67 106 timer_del(s->systick.timer);
aecff692
PM
107}
108
9ee6e8bb
PB
109/* The external routines use the hardware vector numbering, ie. the first
110 IRQ is #16. The internal GIC routines use #32 as the first IRQ. */
111void armv7m_nvic_set_pending(void *opaque, int irq)
112{
113 nvic_state *s = (nvic_state *)opaque;
114 if (irq >= 16)
115 irq += 16;
fe7e8758 116 gic_set_pending_private(&s->gic, 0, irq);
9ee6e8bb
PB
117}
118
119/* Make pending IRQ active. */
120int armv7m_nvic_acknowledge_irq(void *opaque)
121{
122 nvic_state *s = (nvic_state *)opaque;
123 uint32_t irq;
124
fe7e8758 125 irq = gic_acknowledge_irq(&s->gic, 0);
9ee6e8bb 126 if (irq == 1023)
2ac71179 127 hw_error("Interrupt but no vector\n");
9ee6e8bb
PB
128 if (irq >= 32)
129 irq -= 16;
130 return irq;
131}
132
133void armv7m_nvic_complete_irq(void *opaque, int irq)
134{
135 nvic_state *s = (nvic_state *)opaque;
136 if (irq >= 16)
137 irq += 16;
fe7e8758 138 gic_complete_irq(&s->gic, 0, irq);
9ee6e8bb
PB
139}
140
0e8153dd 141static uint32_t nvic_readl(nvic_state *s, uint32_t offset)
9ee6e8bb 142{
4917cf44 143 ARMCPU *cpu;
9ee6e8bb
PB
144 uint32_t val;
145 int irq;
146
147 switch (offset) {
148 case 4: /* Interrupt Control Type. */
a32134aa 149 return (s->num_irq / 32) - 1;
9ee6e8bb
PB
150 case 0x10: /* SysTick Control and Status. */
151 val = s->systick.control;
152 s->systick.control &= ~SYSTICK_COUNTFLAG;
153 return val;
154 case 0x14: /* SysTick Reload Value. */
155 return s->systick.reload;
156 case 0x18: /* SysTick Current Value. */
157 {
158 int64_t t;
159 if ((s->systick.control & SYSTICK_ENABLE) == 0)
160 return 0;
bc72ad67 161 t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
9ee6e8bb
PB
162 if (t >= s->systick.tick)
163 return 0;
164 val = ((s->systick.tick - (t + 1)) / systick_scale(s)) + 1;
165 /* The interrupt in triggered when the timer reaches zero.
166 However the counter is not reloaded until the next clock
167 tick. This is a hack to return zero during the first tick. */
168 if (val > s->systick.reload)
169 val = 0;
170 return val;
171 }
172 case 0x1c: /* SysTick Calibration Value. */
173 return 10000;
174 case 0xd00: /* CPUID Base. */
4917cf44 175 cpu = ARM_CPU(current_cpu);
e3da9921 176 return cpu->midr;
e03ba136 177 case 0xd04: /* Interrupt Control State. */
9ee6e8bb 178 /* VECTACTIVE */
fe7e8758 179 val = s->gic.running_irq[0];
9ee6e8bb
PB
180 if (val == 1023) {
181 val = 0;
182 } else if (val >= 32) {
183 val -= 16;
184 }
185 /* RETTOBASE */
fe7e8758
PB
186 if (s->gic.running_irq[0] == 1023
187 || s->gic.last_active[s->gic.running_irq[0]][0] == 1023) {
9ee6e8bb
PB
188 val |= (1 << 11);
189 }
190 /* VECTPENDING */
fe7e8758
PB
191 if (s->gic.current_pending[0] != 1023)
192 val |= (s->gic.current_pending[0] << 12);
9ee6e8bb 193 /* ISRPENDING */
a32134aa 194 for (irq = 32; irq < s->num_irq; irq++) {
fe7e8758 195 if (s->gic.irq_state[irq].pending) {
9ee6e8bb
PB
196 val |= (1 << 22);
197 break;
198 }
199 }
200 /* PENDSTSET */
fe7e8758 201 if (s->gic.irq_state[ARMV7M_EXCP_SYSTICK].pending)
9ee6e8bb
PB
202 val |= (1 << 26);
203 /* PENDSVSET */
fe7e8758 204 if (s->gic.irq_state[ARMV7M_EXCP_PENDSV].pending)
9ee6e8bb
PB
205 val |= (1 << 28);
206 /* NMIPENDSET */
fe7e8758 207 if (s->gic.irq_state[ARMV7M_EXCP_NMI].pending)
9ee6e8bb
PB
208 val |= (1 << 31);
209 return val;
210 case 0xd08: /* Vector Table Offset. */
4917cf44
AF
211 cpu = ARM_CPU(current_cpu);
212 return cpu->env.v7m.vecbase;
9ee6e8bb 213 case 0xd0c: /* Application Interrupt/Reset Control. */
b6fb3a89 214 return 0xfa050000;
9ee6e8bb
PB
215 case 0xd10: /* System Control. */
216 /* TODO: Implement SLEEPONEXIT. */
217 return 0;
218 case 0xd14: /* Configuration Control. */
219 /* TODO: Implement Configuration Control bits. */
220 return 0;
9ee6e8bb
PB
221 case 0xd24: /* System Handler Status. */
222 val = 0;
fe7e8758
PB
223 if (s->gic.irq_state[ARMV7M_EXCP_MEM].active) val |= (1 << 0);
224 if (s->gic.irq_state[ARMV7M_EXCP_BUS].active) val |= (1 << 1);
225 if (s->gic.irq_state[ARMV7M_EXCP_USAGE].active) val |= (1 << 3);
226 if (s->gic.irq_state[ARMV7M_EXCP_SVC].active) val |= (1 << 7);
227 if (s->gic.irq_state[ARMV7M_EXCP_DEBUG].active) val |= (1 << 8);
228 if (s->gic.irq_state[ARMV7M_EXCP_PENDSV].active) val |= (1 << 10);
229 if (s->gic.irq_state[ARMV7M_EXCP_SYSTICK].active) val |= (1 << 11);
230 if (s->gic.irq_state[ARMV7M_EXCP_USAGE].pending) val |= (1 << 12);
231 if (s->gic.irq_state[ARMV7M_EXCP_MEM].pending) val |= (1 << 13);
232 if (s->gic.irq_state[ARMV7M_EXCP_BUS].pending) val |= (1 << 14);
233 if (s->gic.irq_state[ARMV7M_EXCP_SVC].pending) val |= (1 << 15);
234 if (s->gic.irq_state[ARMV7M_EXCP_MEM].enabled) val |= (1 << 16);
235 if (s->gic.irq_state[ARMV7M_EXCP_BUS].enabled) val |= (1 << 17);
236 if (s->gic.irq_state[ARMV7M_EXCP_USAGE].enabled) val |= (1 << 18);
9ee6e8bb
PB
237 return val;
238 case 0xd28: /* Configurable Fault Status. */
239 /* TODO: Implement Fault Status. */
e72e3ffc 240 qemu_log_mask(LOG_UNIMP, "Configurable Fault Status unimplemented\n");
9ee6e8bb
PB
241 return 0;
242 case 0xd2c: /* Hard Fault Status. */
243 case 0xd30: /* Debug Fault Status. */
244 case 0xd34: /* Mem Manage Address. */
245 case 0xd38: /* Bus Fault Address. */
246 case 0xd3c: /* Aux Fault Status. */
247 /* TODO: Implement fault status registers. */
e72e3ffc
PM
248 qemu_log_mask(LOG_UNIMP, "Fault status registers unimplemented\n");
249 return 0;
9ee6e8bb
PB
250 case 0xd40: /* PFR0. */
251 return 0x00000030;
252 case 0xd44: /* PRF1. */
253 return 0x00000200;
254 case 0xd48: /* DFR0. */
255 return 0x00100000;
256 case 0xd4c: /* AFR0. */
257 return 0x00000000;
258 case 0xd50: /* MMFR0. */
259 return 0x00000030;
260 case 0xd54: /* MMFR1. */
261 return 0x00000000;
262 case 0xd58: /* MMFR2. */
263 return 0x00000000;
264 case 0xd5c: /* MMFR3. */
265 return 0x00000000;
266 case 0xd60: /* ISAR0. */
267 return 0x01141110;
268 case 0xd64: /* ISAR1. */
269 return 0x02111000;
270 case 0xd68: /* ISAR2. */
271 return 0x21112231;
272 case 0xd6c: /* ISAR3. */
273 return 0x01111110;
274 case 0xd70: /* ISAR4. */
275 return 0x01310102;
276 /* TODO: Implement debug registers. */
277 default:
e72e3ffc
PM
278 qemu_log_mask(LOG_GUEST_ERROR, "NVIC: Bad read offset 0x%x\n", offset);
279 return 0;
9ee6e8bb
PB
280 }
281}
282
0e8153dd 283static void nvic_writel(nvic_state *s, uint32_t offset, uint32_t value)
9ee6e8bb 284{
4917cf44 285 ARMCPU *cpu;
9ee6e8bb
PB
286 uint32_t oldval;
287 switch (offset) {
288 case 0x10: /* SysTick Control and Status. */
289 oldval = s->systick.control;
290 s->systick.control &= 0xfffffff8;
291 s->systick.control |= value & 7;
292 if ((oldval ^ value) & SYSTICK_ENABLE) {
bc72ad67 293 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
9ee6e8bb
PB
294 if (value & SYSTICK_ENABLE) {
295 if (s->systick.tick) {
296 s->systick.tick += now;
bc72ad67 297 timer_mod(s->systick.timer, s->systick.tick);
9ee6e8bb
PB
298 } else {
299 systick_reload(s, 1);
300 }
301 } else {
bc72ad67 302 timer_del(s->systick.timer);
9ee6e8bb
PB
303 s->systick.tick -= now;
304 if (s->systick.tick < 0)
305 s->systick.tick = 0;
306 }
307 } else if ((oldval ^ value) & SYSTICK_CLKSOURCE) {
308 /* This is a hack. Force the timer to be reloaded
309 when the reference clock is changed. */
310 systick_reload(s, 1);
311 }
312 break;
313 case 0x14: /* SysTick Reload Value. */
314 s->systick.reload = value;
315 break;
316 case 0x18: /* SysTick Current Value. Writes reload the timer. */
317 systick_reload(s, 1);
318 s->systick.control &= ~SYSTICK_COUNTFLAG;
319 break;
320 case 0xd04: /* Interrupt Control State. */
321 if (value & (1 << 31)) {
322 armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI);
323 }
324 if (value & (1 << 28)) {
325 armv7m_nvic_set_pending(s, ARMV7M_EXCP_PENDSV);
326 } else if (value & (1 << 27)) {
fe7e8758
PB
327 s->gic.irq_state[ARMV7M_EXCP_PENDSV].pending = 0;
328 gic_update(&s->gic);
9ee6e8bb
PB
329 }
330 if (value & (1 << 26)) {
331 armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK);
332 } else if (value & (1 << 25)) {
fe7e8758
PB
333 s->gic.irq_state[ARMV7M_EXCP_SYSTICK].pending = 0;
334 gic_update(&s->gic);
9ee6e8bb
PB
335 }
336 break;
337 case 0xd08: /* Vector Table Offset. */
4917cf44
AF
338 cpu = ARM_CPU(current_cpu);
339 cpu->env.v7m.vecbase = value & 0xffffff80;
9ee6e8bb
PB
340 break;
341 case 0xd0c: /* Application Interrupt/Reset Control. */
342 if ((value >> 16) == 0x05fa) {
343 if (value & 2) {
e72e3ffc 344 qemu_log_mask(LOG_UNIMP, "VECTCLRACTIVE unimplemented\n");
9ee6e8bb
PB
345 }
346 if (value & 5) {
e72e3ffc 347 qemu_log_mask(LOG_UNIMP, "AIRCR system reset unimplemented\n");
9ee6e8bb 348 }
b6fb3a89
OA
349 if (value & 0x700) {
350 qemu_log_mask(LOG_UNIMP, "PRIGROUP unimplemented\n");
351 }
9ee6e8bb
PB
352 }
353 break;
354 case 0xd10: /* System Control. */
355 case 0xd14: /* Configuration Control. */
356 /* TODO: Implement control registers. */
e72e3ffc
PM
357 qemu_log_mask(LOG_UNIMP, "NVIC: SCR and CCR unimplemented\n");
358 break;
9ee6e8bb
PB
359 case 0xd24: /* System Handler Control. */
360 /* TODO: Real hardware allows you to set/clear the active bits
361 under some circumstances. We don't implement this. */
fe7e8758
PB
362 s->gic.irq_state[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
363 s->gic.irq_state[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
364 s->gic.irq_state[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
9ee6e8bb
PB
365 break;
366 case 0xd28: /* Configurable Fault Status. */
367 case 0xd2c: /* Hard Fault Status. */
368 case 0xd30: /* Debug Fault Status. */
369 case 0xd34: /* Mem Manage Address. */
370 case 0xd38: /* Bus Fault Address. */
371 case 0xd3c: /* Aux Fault Status. */
e72e3ffc
PM
372 qemu_log_mask(LOG_UNIMP,
373 "NVIC: fault status registers unimplemented\n");
374 break;
2a29ddee
PM
375 case 0xf00: /* Software Triggered Interrupt Register */
376 if ((value & 0x1ff) < s->num_irq) {
377 gic_set_pending_private(&s->gic, 0, value & 0x1ff);
378 }
379 break;
9ee6e8bb 380 default:
e72e3ffc
PM
381 qemu_log_mask(LOG_GUEST_ERROR,
382 "NVIC: Bad write offset 0x%x\n", offset);
9ee6e8bb
PB
383 }
384}
385
a8170e5e 386static uint64_t nvic_sysreg_read(void *opaque, hwaddr addr,
2a29ddee
PM
387 unsigned size)
388{
0e8153dd 389 nvic_state *s = (nvic_state *)opaque;
2a29ddee 390 uint32_t offset = addr;
0e8153dd
AB
391 int i;
392 uint32_t val;
393
394 switch (offset) {
395 case 0xd18 ... 0xd23: /* System Handler Priority. */
396 val = 0;
397 for (i = 0; i < size; i++) {
398 val |= s->gic.priority1[(offset - 0xd14) + i][0] << (i * 8);
399 }
400 return val;
401 case 0xfe0 ... 0xfff: /* ID. */
2a29ddee
PM
402 if (offset & 3) {
403 return 0;
404 }
405 return nvic_id[(offset - 0xfe0) >> 2];
406 }
407 if (size == 4) {
0e8153dd 408 return nvic_readl(s, offset);
2a29ddee 409 }
e72e3ffc
PM
410 qemu_log_mask(LOG_GUEST_ERROR,
411 "NVIC: Bad read of size %d at offset 0x%x\n", size, offset);
412 return 0;
2a29ddee
PM
413}
414
a8170e5e 415static void nvic_sysreg_write(void *opaque, hwaddr addr,
2a29ddee
PM
416 uint64_t value, unsigned size)
417{
0e8153dd 418 nvic_state *s = (nvic_state *)opaque;
2a29ddee 419 uint32_t offset = addr;
0e8153dd
AB
420 int i;
421
422 switch (offset) {
423 case 0xd18 ... 0xd23: /* System Handler Priority. */
424 for (i = 0; i < size; i++) {
425 s->gic.priority1[(offset - 0xd14) + i][0] =
426 (value >> (i * 8)) & 0xff;
427 }
428 gic_update(&s->gic);
429 return;
430 }
2a29ddee 431 if (size == 4) {
0e8153dd 432 nvic_writel(s, offset, value);
2a29ddee
PM
433 return;
434 }
e72e3ffc
PM
435 qemu_log_mask(LOG_GUEST_ERROR,
436 "NVIC: Bad write of size %d at offset 0x%x\n", size, offset);
2a29ddee
PM
437}
438
439static const MemoryRegionOps nvic_sysreg_ops = {
440 .read = nvic_sysreg_read,
441 .write = nvic_sysreg_write,
442 .endianness = DEVICE_NATIVE_ENDIAN,
443};
444
0797226c
JQ
445static const VMStateDescription vmstate_nvic = {
446 .name = "armv7m_nvic",
447 .version_id = 1,
448 .minimum_version_id = 1,
8f1e884b 449 .fields = (VMStateField[]) {
0797226c
JQ
450 VMSTATE_UINT32(systick.control, nvic_state),
451 VMSTATE_UINT32(systick.reload, nvic_state),
452 VMSTATE_INT64(systick.tick, nvic_state),
e720677e 453 VMSTATE_TIMER_PTR(systick.timer, nvic_state),
0797226c
JQ
454 VMSTATE_END_OF_LIST()
455 }
456};
23e39294 457
aecff692
PM
458static void armv7m_nvic_reset(DeviceState *dev)
459{
1e8cae4d
PM
460 nvic_state *s = NVIC(dev);
461 NVICClass *nc = NVIC_GET_CLASS(s);
462 nc->parent_reset(dev);
b3387ede
PM
463 /* Common GIC reset resets to disabled; the NVIC doesn't have
464 * per-CPU interfaces so mark our non-existent CPU interface
ee3f0956
PM
465 * as enabled by default, and with a priority mask which allows
466 * all interrupts through.
b3387ede 467 */
c3037774 468 s->gic.cpu_enabled[0] = true;
ee3f0956 469 s->gic.priority_mask[0] = 0x100;
b3387ede 470 /* The NVIC as a whole is always enabled. */
c3037774 471 s->gic.enabled = true;
aecff692
PM
472 systick_reset(s);
473}
474
53111180 475static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
9ee6e8bb 476{
1e8cae4d
PM
477 nvic_state *s = NVIC(dev);
478 NVICClass *nc = NVIC_GET_CLASS(s);
0175ba10 479 Error *local_err = NULL;
9ee6e8bb 480
c48c6522
PM
481 /* The NVIC always has only one CPU */
482 s->gic.num_cpu = 1;
306a571a
PM
483 /* Tell the common code we're an NVIC */
484 s->gic.revision = 0xffffffff;
55e00a19 485 s->num_irq = s->gic.num_irq;
0175ba10
MA
486 nc->parent_realize(dev, &local_err);
487 if (local_err) {
488 error_propagate(errp, local_err);
53111180
PM
489 return;
490 }
7b95a508 491 gic_init_irqs_and_distributor(&s->gic);
2a29ddee
PM
492 /* The NVIC and system controller register area looks like this:
493 * 0..0xff : system control registers, including systick
494 * 0x100..0xcff : GIC-like registers
495 * 0xd00..0xfff : system control registers
496 * We use overlaying to put the GIC like registers
497 * over the top of the system control register region.
498 */
1437c94b 499 memory_region_init(&s->container, OBJECT(s), "nvic", 0x1000);
2a29ddee
PM
500 /* The system register region goes at the bottom of the priority
501 * stack as it covers the whole page.
502 */
1437c94b 503 memory_region_init_io(&s->sysregmem, OBJECT(s), &nvic_sysreg_ops, s,
2a29ddee
PM
504 "nvic_sysregs", 0x1000);
505 memory_region_add_subregion(&s->container, 0, &s->sysregmem);
506 /* Alias the GIC region so we can get only the section of it
507 * we need, and layer it on top of the system register region.
508 */
1437c94b
PB
509 memory_region_init_alias(&s->gic_iomem_alias, OBJECT(s),
510 "nvic-gic", &s->gic.iomem,
2a29ddee 511 0x100, 0xc00);
9892cae3
MI
512 memory_region_add_subregion_overlap(&s->container, 0x100,
513 &s->gic_iomem_alias, 1);
2a29ddee
PM
514 /* Map the whole thing into system memory at the location required
515 * by the v7M architecture.
516 */
517 memory_region_add_subregion(get_system_memory(), 0xe000e000, &s->container);
bc72ad67 518 s->systick.timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s);
9ee6e8bb 519}
fe7e8758 520
55e00a19
PM
521static void armv7m_nvic_instance_init(Object *obj)
522{
523 /* We have a different default value for the num-irq property
524 * than our superclass. This function runs after qdev init
525 * has set the defaults from the Property array and before
526 * any user-specified property setting, so just modify the
fae15286 527 * value in the GICState struct.
55e00a19 528 */
fae15286 529 GICState *s = ARM_GIC_COMMON(obj);
39bffca2
AL
530 /* The ARM v7m may have anything from 0 to 496 external interrupt
531 * IRQ lines. We default to 64. Other boards may differ and should
55e00a19 532 * set the num-irq property appropriately.
39bffca2 533 */
55e00a19
PM
534 s->num_irq = 64;
535}
39bffca2 536
999e12bb
AL
537static void armv7m_nvic_class_init(ObjectClass *klass, void *data)
538{
1e8cae4d 539 NVICClass *nc = NVIC_CLASS(klass);
39bffca2 540 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 541
1e8cae4d 542 nc->parent_reset = dc->reset;
53111180 543 nc->parent_realize = dc->realize;
39bffca2 544 dc->vmsd = &vmstate_nvic;
aecff692 545 dc->reset = armv7m_nvic_reset;
53111180 546 dc->realize = armv7m_nvic_realize;
999e12bb
AL
547}
548
8c43a6f0 549static const TypeInfo armv7m_nvic_info = {
1e8cae4d
PM
550 .name = TYPE_NVIC,
551 .parent = TYPE_ARM_GIC_COMMON,
55e00a19 552 .instance_init = armv7m_nvic_instance_init,
39bffca2
AL
553 .instance_size = sizeof(nvic_state),
554 .class_init = armv7m_nvic_class_init,
1e8cae4d 555 .class_size = sizeof(NVICClass),
a32134aa
ML
556};
557
83f7d43a 558static void armv7m_nvic_register_types(void)
fe7e8758 559{
39bffca2 560 type_register_static(&armv7m_nvic_info);
fe7e8758
PB
561}
562
83f7d43a 563type_init(armv7m_nvic_register_types)
This page took 0.722097 seconds and 4 git commands to generate.