1
2
3
4
5
6
7
8
9
10
11
12#include "qemu/osdep.h"
13#include "qemu/log.h"
14#include "trace.h"
15#include "gicv3_internal.h"
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32typedef uint32_t maskfn(GICv3State *s, int irq);
33
34static uint32_t mask_nsacr_ge1(GICv3State *s, int irq)
35{
36
37 uint64_t raw_nsacr = s->gicd_nsacr[irq / 16 + 1];
38
39 raw_nsacr = raw_nsacr << 32 | s->gicd_nsacr[irq / 16];
40 raw_nsacr = (raw_nsacr >> 1) | raw_nsacr;
41 return half_unshuffle64(raw_nsacr);
42}
43
44static uint32_t mask_nsacr_ge2(GICv3State *s, int irq)
45{
46
47 uint64_t raw_nsacr = s->gicd_nsacr[irq / 16 + 1];
48
49 raw_nsacr = raw_nsacr << 32 | s->gicd_nsacr[irq / 16];
50 raw_nsacr = raw_nsacr >> 1;
51 return half_unshuffle64(raw_nsacr);
52}
53
54
55
56
57
58
59static uint32_t mask_group_and_nsacr(GICv3State *s, MemTxAttrs attrs,
60 maskfn *maskfn, int irq)
61{
62
63
64
65
66 uint32_t mask;
67
68 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
69
70
71
72 mask = *gic_bmp_ptr32(s->group, irq);
73 if (maskfn) {
74 mask |= maskfn(s, irq);
75 }
76 return mask;
77 }
78 return 0xFFFFFFFFU;
79}
80
81static int gicd_ns_access(GICv3State *s, int irq)
82{
83
84
85
86 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
87 return 0;
88 }
89 return extract32(s->gicd_nsacr[irq / 16], (irq % 16) * 2, 2);
90}
91
92static void gicd_write_set_bitmap_reg(GICv3State *s, MemTxAttrs attrs,
93 uint32_t *bmp,
94 maskfn *maskfn,
95 int offset, uint32_t val)
96{
97
98
99
100
101
102
103
104
105
106 int irq = offset * 8;
107
108 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
109 return;
110 }
111 val &= mask_group_and_nsacr(s, attrs, maskfn, irq);
112 *gic_bmp_ptr32(bmp, irq) |= val;
113 gicv3_update(s, irq, 32);
114}
115
116static void gicd_write_clear_bitmap_reg(GICv3State *s, MemTxAttrs attrs,
117 uint32_t *bmp,
118 maskfn *maskfn,
119 int offset, uint32_t val)
120{
121
122
123
124
125
126
127
128
129
130 int irq = offset * 8;
131
132 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
133 return;
134 }
135 val &= mask_group_and_nsacr(s, attrs, maskfn, irq);
136 *gic_bmp_ptr32(bmp, irq) &= ~val;
137 gicv3_update(s, irq, 32);
138}
139
140static uint32_t gicd_read_bitmap_reg(GICv3State *s, MemTxAttrs attrs,
141 uint32_t *bmp,
142 maskfn *maskfn,
143 int offset)
144{
145
146
147
148
149
150
151
152
153 int irq = offset * 8;
154 uint32_t val;
155
156 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
157 return 0;
158 }
159 val = *gic_bmp_ptr32(bmp, irq);
160 if (bmp == s->pending) {
161
162
163
164
165 uint32_t edge = *gic_bmp_ptr32(s->edge_trigger, irq);
166 uint32_t level = *gic_bmp_ptr32(s->level, irq);
167 val |= (~edge & level);
168 }
169 val &= mask_group_and_nsacr(s, attrs, maskfn, irq);
170 return val;
171}
172
173static uint8_t gicd_read_ipriorityr(GICv3State *s, MemTxAttrs attrs, int irq)
174{
175
176
177
178
179 uint32_t prio;
180
181 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
182 return 0;
183 }
184
185 prio = s->gicd_ipriority[irq];
186
187 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
188 if (!gicv3_gicd_group_test(s, irq)) {
189
190 return 0;
191 }
192
193 prio = (prio << 1) & 0xff;
194 }
195 return prio;
196}
197
198static void gicd_write_ipriorityr(GICv3State *s, MemTxAttrs attrs, int irq,
199 uint8_t value)
200{
201
202
203
204
205 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
206 return;
207 }
208
209 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
210 if (!gicv3_gicd_group_test(s, irq)) {
211
212 return;
213 }
214
215 value = 0x80 | (value >> 1);
216 }
217 s->gicd_ipriority[irq] = value;
218}
219
220static uint64_t gicd_read_irouter(GICv3State *s, MemTxAttrs attrs, int irq)
221{
222
223
224
225 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
226 return 0;
227 }
228
229 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
230
231 if (!gicv3_gicd_group_test(s, irq)) {
232 if (gicd_ns_access(s, irq) != 3) {
233 return 0;
234 }
235 }
236 }
237
238 return s->gicd_irouter[irq];
239}
240
241static void gicd_write_irouter(GICv3State *s, MemTxAttrs attrs, int irq,
242 uint64_t val)
243{
244
245
246
247 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
248 return;
249 }
250
251 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
252
253 if (!gicv3_gicd_group_test(s, irq)) {
254 if (gicd_ns_access(s, irq) != 3) {
255 return;
256 }
257 }
258 }
259
260 s->gicd_irouter[irq] = val;
261 gicv3_cache_target_cpustate(s, irq);
262 gicv3_update(s, irq, 1);
263}
264
265static MemTxResult gicd_readb(GICv3State *s, hwaddr offset,
266 uint64_t *data, MemTxAttrs attrs)
267{
268
269 switch (offset) {
270 case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf:
271 case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf:
272 case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:
273
274
275
276 return MEMTX_OK;
277 case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff:
278 *data = gicd_read_ipriorityr(s, attrs, offset - GICD_IPRIORITYR);
279 return MEMTX_OK;
280 default:
281 return MEMTX_ERROR;
282 }
283}
284
285static MemTxResult gicd_writeb(GICv3State *s, hwaddr offset,
286 uint64_t value, MemTxAttrs attrs)
287{
288
289 switch (offset) {
290 case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf:
291 case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf:
292 case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:
293
294
295
296 return MEMTX_OK;
297 case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff:
298 {
299 int irq = offset - GICD_IPRIORITYR;
300
301 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
302 return MEMTX_OK;
303 }
304 gicd_write_ipriorityr(s, attrs, irq, value);
305 gicv3_update(s, irq, 1);
306 return MEMTX_OK;
307 }
308 default:
309 return MEMTX_ERROR;
310 }
311}
312
313static MemTxResult gicd_readw(GICv3State *s, hwaddr offset,
314 uint64_t *data, MemTxAttrs attrs)
315{
316
317
318
319
320
321
322 return MEMTX_ERROR;
323}
324
325static MemTxResult gicd_writew(GICv3State *s, hwaddr offset,
326 uint64_t value, MemTxAttrs attrs)
327{
328
329
330
331
332
333
334 return MEMTX_ERROR;
335}
336
337static MemTxResult gicd_readl(GICv3State *s, hwaddr offset,
338 uint64_t *data, MemTxAttrs attrs)
339{
340
341
342
343
344
345 switch (offset) {
346 case GICD_CTLR:
347 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
348
349
350
351
352
353
354
355
356
357
358
359
360 *data = s->gicd_ctlr & (GICD_CTLR_ARE_S |
361 GICD_CTLR_EN_GRP1NS |
362 GICD_CTLR_RWP);
363 } else {
364 *data = s->gicd_ctlr;
365 }
366 return MEMTX_OK;
367 case GICD_TYPER:
368 {
369
370
371
372
373
374
375
376
377
378
379
380 int itlinesnumber = ((s->num_irq - GIC_INTERNAL) / 32) - 1;
381
382
383
384
385
386 bool sec_extn = !(s->gicd_ctlr & GICD_CTLR_DS);
387
388 *data = (1 << 25) | (1 << 24) | (sec_extn << 10) |
389 (0xf << 19) | itlinesnumber;
390 return MEMTX_OK;
391 }
392 case GICD_IIDR:
393
394
395
396 *data = gicv3_iidr();
397 return MEMTX_OK;
398 case GICD_STATUSR:
399
400
401
402 *data = 0;
403 return MEMTX_OK;
404 case GICD_IGROUPR ... GICD_IGROUPR + 0x7f:
405 {
406 int irq;
407
408 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
409 *data = 0;
410 return MEMTX_OK;
411 }
412
413 irq = (offset - GICD_IGROUPR) * 8;
414 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
415 *data = 0;
416 return MEMTX_OK;
417 }
418 *data = *gic_bmp_ptr32(s->group, irq);
419 return MEMTX_OK;
420 }
421 case GICD_ISENABLER ... GICD_ISENABLER + 0x7f:
422 *data = gicd_read_bitmap_reg(s, attrs, s->enabled, NULL,
423 offset - GICD_ISENABLER);
424 return MEMTX_OK;
425 case GICD_ICENABLER ... GICD_ICENABLER + 0x7f:
426 *data = gicd_read_bitmap_reg(s, attrs, s->enabled, NULL,
427 offset - GICD_ICENABLER);
428 return MEMTX_OK;
429 case GICD_ISPENDR ... GICD_ISPENDR + 0x7f:
430 *data = gicd_read_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge1,
431 offset - GICD_ISPENDR);
432 return MEMTX_OK;
433 case GICD_ICPENDR ... GICD_ICPENDR + 0x7f:
434 *data = gicd_read_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge2,
435 offset - GICD_ICPENDR);
436 return MEMTX_OK;
437 case GICD_ISACTIVER ... GICD_ISACTIVER + 0x7f:
438 *data = gicd_read_bitmap_reg(s, attrs, s->active, mask_nsacr_ge2,
439 offset - GICD_ISACTIVER);
440 return MEMTX_OK;
441 case GICD_ICACTIVER ... GICD_ICACTIVER + 0x7f:
442 *data = gicd_read_bitmap_reg(s, attrs, s->active, mask_nsacr_ge2,
443 offset - GICD_ICACTIVER);
444 return MEMTX_OK;
445 case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff:
446 {
447 int i, irq = offset - GICD_IPRIORITYR;
448 uint32_t value = 0;
449
450 for (i = irq + 3; i >= irq; i--) {
451 value <<= 8;
452 value |= gicd_read_ipriorityr(s, attrs, i);
453 }
454 *data = value;
455 return MEMTX_OK;
456 }
457 case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:
458
459 *data = 0;
460 return MEMTX_OK;
461 case GICD_ICFGR ... GICD_ICFGR + 0xff:
462 {
463
464 int irq = (offset - GICD_ICFGR) * 4;
465 uint32_t value = 0;
466
467 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
468 *data = 0;
469 return MEMTX_OK;
470 }
471
472
473
474
475
476 value = *gic_bmp_ptr32(s->edge_trigger, irq & ~0x1f);
477 value &= mask_group_and_nsacr(s, attrs, NULL, irq & ~0x1f);
478 value = extract32(value, (irq & 0x1f) ? 16 : 0, 16);
479 value = half_shuffle32(value) << 1;
480 *data = value;
481 return MEMTX_OK;
482 }
483 case GICD_IGRPMODR ... GICD_IGRPMODR + 0xff:
484 {
485 int irq;
486
487 if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) {
488
489
490
491 *data = 0;
492 return MEMTX_OK;
493 }
494
495 irq = (offset - GICD_IGRPMODR) * 8;
496 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
497 *data = 0;
498 return MEMTX_OK;
499 }
500 *data = *gic_bmp_ptr32(s->grpmod, irq);
501 return MEMTX_OK;
502 }
503 case GICD_NSACR ... GICD_NSACR + 0xff:
504 {
505
506 int irq = (offset - GICD_NSACR) * 4;
507
508 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
509 *data = 0;
510 return MEMTX_OK;
511 }
512
513 if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) {
514
515
516
517 *data = 0;
518 return MEMTX_OK;
519 }
520
521 *data = s->gicd_nsacr[irq / 16];
522 return MEMTX_OK;
523 }
524 case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf:
525 case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf:
526
527 *data = 0;
528 return MEMTX_OK;
529 case GICD_IROUTER ... GICD_IROUTER + 0x1fdf:
530 {
531 uint64_t r;
532 int irq = (offset - GICD_IROUTER) / 8;
533
534 r = gicd_read_irouter(s, attrs, irq);
535 if (offset & 7) {
536 *data = r >> 32;
537 } else {
538 *data = (uint32_t)r;
539 }
540 return MEMTX_OK;
541 }
542 case GICD_IDREGS ... GICD_IDREGS + 0x2f:
543
544 *data = gicv3_idreg(offset - GICD_IDREGS);
545 return MEMTX_OK;
546 case GICD_SGIR:
547
548 qemu_log_mask(LOG_GUEST_ERROR,
549 "%s: invalid guest read from WO register at offset "
550 TARGET_FMT_plx "\n", __func__, offset);
551 *data = 0;
552 return MEMTX_OK;
553 default:
554 return MEMTX_ERROR;
555 }
556}
557
558static MemTxResult gicd_writel(GICv3State *s, hwaddr offset,
559 uint64_t value, MemTxAttrs attrs)
560{
561
562
563
564
565 switch (offset) {
566 case GICD_CTLR:
567 {
568 uint32_t mask;
569
570 if (s->gicd_ctlr & GICD_CTLR_DS) {
571
572
573
574
575 mask = GICD_CTLR_EN_GRP0 | GICD_CTLR_EN_GRP1NS;
576 } else {
577 if (attrs.secure) {
578
579
580
581
582
583
584 mask = GICD_CTLR_DS | GICD_CTLR_EN_GRP0 | GICD_CTLR_EN_GRP1_ALL;
585 } else {
586
587
588
589
590 mask = GICD_CTLR_EN_GRP1NS;
591 }
592 }
593 s->gicd_ctlr = (s->gicd_ctlr & ~mask) | (value & mask);
594 if (value & mask & GICD_CTLR_DS) {
595
596
597
598
599
600 s->gicd_ctlr &= ~(GICD_CTLR_EN_GRP1S | GICD_CTLR_ARE_NS);
601 }
602 gicv3_full_update(s);
603 return MEMTX_OK;
604 }
605 case GICD_STATUSR:
606
607 return MEMTX_OK;
608 case GICD_IGROUPR ... GICD_IGROUPR + 0x7f:
609 {
610 int irq;
611
612 if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) {
613 return MEMTX_OK;
614 }
615
616 irq = (offset - GICD_IGROUPR) * 8;
617 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
618 return MEMTX_OK;
619 }
620 *gic_bmp_ptr32(s->group, irq) = value;
621 gicv3_update(s, irq, 32);
622 return MEMTX_OK;
623 }
624 case GICD_ISENABLER ... GICD_ISENABLER + 0x7f:
625 gicd_write_set_bitmap_reg(s, attrs, s->enabled, NULL,
626 offset - GICD_ISENABLER, value);
627 return MEMTX_OK;
628 case GICD_ICENABLER ... GICD_ICENABLER + 0x7f:
629 gicd_write_clear_bitmap_reg(s, attrs, s->enabled, NULL,
630 offset - GICD_ICENABLER, value);
631 return MEMTX_OK;
632 case GICD_ISPENDR ... GICD_ISPENDR + 0x7f:
633 gicd_write_set_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge1,
634 offset - GICD_ISPENDR, value);
635 return MEMTX_OK;
636 case GICD_ICPENDR ... GICD_ICPENDR + 0x7f:
637 gicd_write_clear_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge2,
638 offset - GICD_ICPENDR, value);
639 return MEMTX_OK;
640 case GICD_ISACTIVER ... GICD_ISACTIVER + 0x7f:
641 gicd_write_set_bitmap_reg(s, attrs, s->active, NULL,
642 offset - GICD_ISACTIVER, value);
643 return MEMTX_OK;
644 case GICD_ICACTIVER ... GICD_ICACTIVER + 0x7f:
645 gicd_write_clear_bitmap_reg(s, attrs, s->active, NULL,
646 offset - GICD_ICACTIVER, value);
647 return MEMTX_OK;
648 case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff:
649 {
650 int i, irq = offset - GICD_IPRIORITYR;
651
652 if (irq < GIC_INTERNAL || irq + 3 >= s->num_irq) {
653 return MEMTX_OK;
654 }
655
656 for (i = irq; i < irq + 4; i++, value >>= 8) {
657 gicd_write_ipriorityr(s, attrs, i, value);
658 }
659 gicv3_update(s, irq, 4);
660 return MEMTX_OK;
661 }
662 case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff:
663
664 return MEMTX_OK;
665 case GICD_ICFGR ... GICD_ICFGR + 0xff:
666 {
667
668 int irq = (offset - GICD_ICFGR) * 4;
669 uint32_t mask, oldval;
670
671 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
672 return MEMTX_OK;
673 }
674
675
676
677
678
679 value = half_unshuffle32(value >> 1);
680 mask = mask_group_and_nsacr(s, attrs, NULL, irq & ~0x1f);
681 if (irq & 0x1f) {
682 value <<= 16;
683 mask &= 0xffff0000U;
684 } else {
685 mask &= 0xffff;
686 }
687 oldval = *gic_bmp_ptr32(s->edge_trigger, (irq & ~0x1f));
688 value = (oldval & ~mask) | (value & mask);
689 *gic_bmp_ptr32(s->edge_trigger, irq & ~0x1f) = value;
690 return MEMTX_OK;
691 }
692 case GICD_IGRPMODR ... GICD_IGRPMODR + 0xff:
693 {
694 int irq;
695
696 if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) {
697
698
699
700 return MEMTX_OK;
701 }
702
703 irq = (offset - GICD_IGRPMODR) * 8;
704 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
705 return MEMTX_OK;
706 }
707 *gic_bmp_ptr32(s->grpmod, irq) = value;
708 gicv3_update(s, irq, 32);
709 return MEMTX_OK;
710 }
711 case GICD_NSACR ... GICD_NSACR + 0xff:
712 {
713
714 int irq = (offset - GICD_NSACR) * 4;
715
716 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
717 return MEMTX_OK;
718 }
719
720 if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) {
721
722
723
724 return MEMTX_OK;
725 }
726
727 s->gicd_nsacr[irq / 16] = value;
728
729 return MEMTX_OK;
730 }
731 case GICD_SGIR:
732
733 return MEMTX_OK;
734 case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf:
735 case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf:
736
737 return MEMTX_OK;
738 case GICD_IROUTER ... GICD_IROUTER + 0x1fdf:
739 {
740 uint64_t r;
741 int irq = (offset - GICD_IROUTER) / 8;
742
743 if (irq < GIC_INTERNAL || irq >= s->num_irq) {
744 return MEMTX_OK;
745 }
746
747
748 r = gicd_read_irouter(s, attrs, irq);
749 r = deposit64(r, (offset & 7) ? 32 : 0, 32, value);
750 gicd_write_irouter(s, attrs, irq, r);
751 return MEMTX_OK;
752 }
753 case GICD_IDREGS ... GICD_IDREGS + 0x2f:
754 case GICD_TYPER:
755 case GICD_IIDR:
756
757 qemu_log_mask(LOG_GUEST_ERROR,
758 "%s: invalid guest write to RO register at offset "
759 TARGET_FMT_plx "\n", __func__, offset);
760 return MEMTX_OK;
761 default:
762 return MEMTX_ERROR;
763 }
764}
765
766static MemTxResult gicd_writell(GICv3State *s, hwaddr offset,
767 uint64_t value, MemTxAttrs attrs)
768{
769
770 int irq;
771
772 switch (offset) {
773 case GICD_IROUTER ... GICD_IROUTER + 0x1fdf:
774 irq = (offset - GICD_IROUTER) / 8;
775 gicd_write_irouter(s, attrs, irq, value);
776 return MEMTX_OK;
777 default:
778 return MEMTX_ERROR;
779 }
780}
781
782static MemTxResult gicd_readll(GICv3State *s, hwaddr offset,
783 uint64_t *data, MemTxAttrs attrs)
784{
785
786 int irq;
787
788 switch (offset) {
789 case GICD_IROUTER ... GICD_IROUTER + 0x1fdf:
790 irq = (offset - GICD_IROUTER) / 8;
791 *data = gicd_read_irouter(s, attrs, irq);
792 return MEMTX_OK;
793 default:
794 return MEMTX_ERROR;
795 }
796}
797
798MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data,
799 unsigned size, MemTxAttrs attrs)
800{
801 GICv3State *s = (GICv3State *)opaque;
802 MemTxResult r;
803
804 switch (size) {
805 case 1:
806 r = gicd_readb(s, offset, data, attrs);
807 break;
808 case 2:
809 r = gicd_readw(s, offset, data, attrs);
810 break;
811 case 4:
812 r = gicd_readl(s, offset, data, attrs);
813 break;
814 case 8:
815 r = gicd_readll(s, offset, data, attrs);
816 break;
817 default:
818 r = MEMTX_ERROR;
819 break;
820 }
821
822 if (r == MEMTX_ERROR) {
823 qemu_log_mask(LOG_GUEST_ERROR,
824 "%s: invalid guest read at offset " TARGET_FMT_plx
825 "size %u\n", __func__, offset, size);
826 trace_gicv3_dist_badread(offset, size, attrs.secure);
827
828
829
830
831
832 r = MEMTX_OK;
833 *data = 0;
834 } else {
835 trace_gicv3_dist_read(offset, *data, size, attrs.secure);
836 }
837 return r;
838}
839
840MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data,
841 unsigned size, MemTxAttrs attrs)
842{
843 GICv3State *s = (GICv3State *)opaque;
844 MemTxResult r;
845
846 switch (size) {
847 case 1:
848 r = gicd_writeb(s, offset, data, attrs);
849 break;
850 case 2:
851 r = gicd_writew(s, offset, data, attrs);
852 break;
853 case 4:
854 r = gicd_writel(s, offset, data, attrs);
855 break;
856 case 8:
857 r = gicd_writell(s, offset, data, attrs);
858 break;
859 default:
860 r = MEMTX_ERROR;
861 break;
862 }
863
864 if (r == MEMTX_ERROR) {
865 qemu_log_mask(LOG_GUEST_ERROR,
866 "%s: invalid guest write at offset " TARGET_FMT_plx
867 "size %u\n", __func__, offset, size);
868 trace_gicv3_dist_badwrite(offset, data, size, attrs.secure);
869
870
871
872
873
874 r = MEMTX_OK;
875 } else {
876 trace_gicv3_dist_write(offset, data, size, attrs.secure);
877 }
878 return r;
879}
880
881void gicv3_dist_set_irq(GICv3State *s, int irq, int level)
882{
883
884 if (level == gicv3_gicd_level_test(s, irq)) {
885 return;
886 }
887
888 trace_gicv3_dist_set_irq(irq, level);
889
890 gicv3_gicd_level_replace(s, irq, level);
891
892 if (level) {
893
894 if (gicv3_gicd_edge_trigger_test(s, irq)) {
895 gicv3_gicd_pending_set(s, irq);
896 }
897 }
898
899 gicv3_update(s, irq, 1);
900}
901