4 * Copyright (c) 2004 Jocelyn Mayer
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * Based on OpenPic implementations:
28 * - Intel GW80314 I/O companion chip developer's manual
29 * - Motorola MPC8245 & MPC8540 user manuals.
30 * - Motorola MCP750 (aka Raven) programmer manual.
31 * - Motorola Harrier programmer manuel
33 * Serial interrupts, as implemented in Raven chipset are not supported yet.
41 //#define DEBUG_OPENPIC
44 #define DPRINTF(fmt, ...) do { printf(fmt , ## __VA_ARGS__); } while (0)
46 #define DPRINTF(fmt, ...) do { } while (0)
49 #define USE_MPCxxx /* Intel model is broken, for now */
51 #if defined (USE_INTEL_GW80314)
52 /* Intel GW80314 I/O Companion chip */
62 #define VID (0x00000000)
64 #elif defined(USE_MPCxxx)
73 #define VID 0x03 /* MPIC version ID */
74 #define VENI 0x00000000 /* Vendor ID */
82 #define OPENPIC_MAX_CPU 2
83 #define OPENPIC_MAX_IRQ 64
84 #define OPENPIC_EXT_IRQ 48
85 #define OPENPIC_MAX_TMR MAX_TMR
86 #define OPENPIC_MAX_IPI MAX_IPI
88 /* Interrupt definitions */
89 #define OPENPIC_IRQ_FE (OPENPIC_EXT_IRQ) /* Internal functional IRQ */
90 #define OPENPIC_IRQ_ERR (OPENPIC_EXT_IRQ + 1) /* Error IRQ */
91 #define OPENPIC_IRQ_TIM0 (OPENPIC_EXT_IRQ + 2) /* First timer IRQ */
92 #if OPENPIC_MAX_IPI > 0
93 #define OPENPIC_IRQ_IPI0 (OPENPIC_IRQ_TIM0 + OPENPIC_MAX_TMR) /* First IPI IRQ */
94 #define OPENPIC_IRQ_DBL0 (OPENPIC_IRQ_IPI0 + (OPENPIC_MAX_CPU * OPENPIC_MAX_IPI)) /* First doorbell IRQ */
96 #define OPENPIC_IRQ_DBL0 (OPENPIC_IRQ_TIM0 + OPENPIC_MAX_TMR) /* First doorbell IRQ */
97 #define OPENPIC_IRQ_MBX0 (OPENPIC_IRQ_DBL0 + OPENPIC_MAX_DBL) /* First mailbox IRQ */
101 #define MPIC_MAX_CPU 1
102 #define MPIC_MAX_EXT 12
103 #define MPIC_MAX_INT 64
104 #define MPIC_MAX_MSG 4
105 #define MPIC_MAX_MSI 8
106 #define MPIC_MAX_TMR MAX_TMR
107 #define MPIC_MAX_IPI MAX_IPI
108 #define MPIC_MAX_IRQ (MPIC_MAX_EXT + MPIC_MAX_INT + MPIC_MAX_TMR + MPIC_MAX_MSG + MPIC_MAX_MSI + (MPIC_MAX_IPI * MPIC_MAX_CPU))
110 /* Interrupt definitions */
111 #define MPIC_EXT_IRQ 0
112 #define MPIC_INT_IRQ (MPIC_EXT_IRQ + MPIC_MAX_EXT)
113 #define MPIC_TMR_IRQ (MPIC_INT_IRQ + MPIC_MAX_INT)
114 #define MPIC_MSG_IRQ (MPIC_TMR_IRQ + MPIC_MAX_TMR)
115 #define MPIC_MSI_IRQ (MPIC_MSG_IRQ + MPIC_MAX_MSG)
116 #define MPIC_IPI_IRQ (MPIC_MSI_IRQ + MPIC_MAX_MSI)
118 #define MPIC_GLB_REG_START 0x0
119 #define MPIC_GLB_REG_SIZE 0x10F0
120 #define MPIC_TMR_REG_START 0x10F0
121 #define MPIC_TMR_REG_SIZE 0x220
122 #define MPIC_EXT_REG_START 0x10000
123 #define MPIC_EXT_REG_SIZE 0x180
124 #define MPIC_INT_REG_START 0x10200
125 #define MPIC_INT_REG_SIZE 0x800
126 #define MPIC_MSG_REG_START 0x11600
127 #define MPIC_MSG_REG_SIZE 0x100
128 #define MPIC_MSI_REG_START 0x11C00
129 #define MPIC_MSI_REG_SIZE 0x100
130 #define MPIC_CPU_REG_START 0x20000
131 #define MPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000)
142 #error "Please select which OpenPic implementation is to be emulated"
145 #define OPENPIC_PAGE_SIZE 4096
147 #define BF_WIDTH(_bits_) \
148 (((_bits_) + (sizeof(uint32_t) * 8) - 1) / (sizeof(uint32_t) * 8))
150 static inline void set_bit (uint32_t *field
, int bit
)
152 field
[bit
>> 5] |= 1 << (bit
& 0x1F);
155 static inline void reset_bit (uint32_t *field
, int bit
)
157 field
[bit
>> 5] &= ~(1 << (bit
& 0x1F));
160 static inline int test_bit (uint32_t *field
, int bit
)
162 return (field
[bit
>> 5] & 1 << (bit
& 0x1F)) != 0;
165 static int get_current_cpu(void)
167 return cpu_single_env
->cpu_index
;
170 static uint32_t openpic_cpu_read_internal(void *opaque
, target_phys_addr_t addr
,
172 static void openpic_cpu_write_internal(void *opaque
, target_phys_addr_t addr
,
173 uint32_t val
, int idx
);
182 typedef struct IRQ_queue_t
{
183 uint32_t queue
[BF_WIDTH(MAX_IRQ
)];
188 typedef struct IRQ_src_t
{
189 uint32_t ipvp
; /* IRQ vector/priority register */
190 uint32_t ide
; /* IRQ destination register */
193 int pending
; /* TRUE if IRQ is pending */
203 #define IPVP_PRIORITY_MASK (0x1F << 16)
204 #define IPVP_PRIORITY(_ipvpr_) ((int)(((_ipvpr_) & IPVP_PRIORITY_MASK) >> 16))
205 #define IPVP_VECTOR_MASK ((1 << VECTOR_BITS) - 1)
206 #define IPVP_VECTOR(_ipvpr_) ((_ipvpr_) & IPVP_VECTOR_MASK)
208 typedef struct IRQ_dst_t
{
210 uint32_t pctp
; /* CPU current task priority */
211 uint32_t pcsr
; /* CPU sensitivity register */
213 IRQ_queue_t servicing
;
217 typedef struct openpic_t
{
222 MemoryRegion sub_io_mem
[7];
224 /* Global registers */
225 uint32_t frep
; /* Feature reporting register */
226 uint32_t glbc
; /* Global configuration register */
227 uint32_t micr
; /* MPIC interrupt configuration register */
228 uint32_t veni
; /* Vendor identification register */
229 uint32_t pint
; /* Processor initialization register */
230 uint32_t spve
; /* Spurious vector register */
231 uint32_t tifr
; /* Timer frequency reporting register */
232 /* Source registers */
233 IRQ_src_t src
[MAX_IRQ
];
234 /* Local registers per output pin */
235 IRQ_dst_t dst
[MAX_CPU
];
237 /* Timer registers */
239 uint32_t ticc
; /* Global timer current count register */
240 uint32_t tibc
; /* Global timer base count register */
243 /* Doorbell registers */
244 uint32_t dar
; /* Doorbell activate register */
246 uint32_t dmr
; /* Doorbell messaging register */
247 } doorbells
[MAX_DBL
];
250 /* Mailbox registers */
252 uint32_t mbr
; /* Mailbox register */
253 } mailboxes
[MAX_MAILBOXES
];
255 /* IRQ out is used when in bypass mode (not implemented) */
260 void (*reset
) (void *);
261 void (*irq_raise
) (struct openpic_t
*, int, IRQ_src_t
*);
264 static inline void IRQ_setbit (IRQ_queue_t
*q
, int n_IRQ
)
266 set_bit(q
->queue
, n_IRQ
);
269 static inline void IRQ_resetbit (IRQ_queue_t
*q
, int n_IRQ
)
271 reset_bit(q
->queue
, n_IRQ
);
274 static inline int IRQ_testbit (IRQ_queue_t
*q
, int n_IRQ
)
276 return test_bit(q
->queue
, n_IRQ
);
279 static void IRQ_check (openpic_t
*opp
, IRQ_queue_t
*q
)
286 for (i
= 0; i
< opp
->max_irq
; i
++) {
287 if (IRQ_testbit(q
, i
)) {
288 DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
289 i
, IPVP_PRIORITY(opp
->src
[i
].ipvp
), priority
);
290 if (IPVP_PRIORITY(opp
->src
[i
].ipvp
) > priority
) {
292 priority
= IPVP_PRIORITY(opp
->src
[i
].ipvp
);
297 q
->priority
= priority
;
300 static int IRQ_get_next (openpic_t
*opp
, IRQ_queue_t
*q
)
310 static void IRQ_local_pipe (openpic_t
*opp
, int n_CPU
, int n_IRQ
)
316 dst
= &opp
->dst
[n_CPU
];
317 src
= &opp
->src
[n_IRQ
];
318 priority
= IPVP_PRIORITY(src
->ipvp
);
319 if (priority
<= dst
->pctp
) {
320 /* Too low priority */
321 DPRINTF("%s: IRQ %d has too low priority on CPU %d\n",
322 __func__
, n_IRQ
, n_CPU
);
325 if (IRQ_testbit(&dst
->raised
, n_IRQ
)) {
327 DPRINTF("%s: IRQ %d was missed on CPU %d\n",
328 __func__
, n_IRQ
, n_CPU
);
331 set_bit(&src
->ipvp
, IPVP_ACTIVITY
);
332 IRQ_setbit(&dst
->raised
, n_IRQ
);
333 if (priority
< dst
->raised
.priority
) {
334 /* An higher priority IRQ is already raised */
335 DPRINTF("%s: IRQ %d is hidden by raised IRQ %d on CPU %d\n",
336 __func__
, n_IRQ
, dst
->raised
.next
, n_CPU
);
339 IRQ_get_next(opp
, &dst
->raised
);
340 if (IRQ_get_next(opp
, &dst
->servicing
) != -1 &&
341 priority
<= dst
->servicing
.priority
) {
342 DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n",
343 __func__
, n_IRQ
, dst
->servicing
.next
, n_CPU
);
344 /* Already servicing a higher priority IRQ */
347 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n", n_CPU
, n_IRQ
);
348 opp
->irq_raise(opp
, n_CPU
, src
);
351 /* update pic state because registers for n_IRQ have changed value */
352 static void openpic_update_irq(openpic_t
*opp
, int n_IRQ
)
357 src
= &opp
->src
[n_IRQ
];
361 DPRINTF("%s: IRQ %d is not pending\n", __func__
, n_IRQ
);
364 if (test_bit(&src
->ipvp
, IPVP_MASK
)) {
365 /* Interrupt source is disabled */
366 DPRINTF("%s: IRQ %d is disabled\n", __func__
, n_IRQ
);
369 if (IPVP_PRIORITY(src
->ipvp
) == 0) {
370 /* Priority set to zero */
371 DPRINTF("%s: IRQ %d has 0 priority\n", __func__
, n_IRQ
);
374 if (test_bit(&src
->ipvp
, IPVP_ACTIVITY
)) {
375 /* IRQ already active */
376 DPRINTF("%s: IRQ %d is already active\n", __func__
, n_IRQ
);
379 if (src
->ide
== 0x00000000) {
381 DPRINTF("%s: IRQ %d has no target\n", __func__
, n_IRQ
);
385 if (src
->ide
== (1 << src
->last_cpu
)) {
386 /* Only one CPU is allowed to receive this IRQ */
387 IRQ_local_pipe(opp
, src
->last_cpu
, n_IRQ
);
388 } else if (!test_bit(&src
->ipvp
, IPVP_MODE
)) {
389 /* Directed delivery mode */
390 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
391 if (test_bit(&src
->ide
, i
))
392 IRQ_local_pipe(opp
, i
, n_IRQ
);
395 /* Distributed delivery mode */
396 for (i
= src
->last_cpu
+ 1; i
!= src
->last_cpu
; i
++) {
397 if (i
== opp
->nb_cpus
)
399 if (test_bit(&src
->ide
, i
)) {
400 IRQ_local_pipe(opp
, i
, n_IRQ
);
408 static void openpic_set_irq(void *opaque
, int n_IRQ
, int level
)
410 openpic_t
*opp
= opaque
;
413 src
= &opp
->src
[n_IRQ
];
414 DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
415 n_IRQ
, level
, src
->ipvp
);
416 if (test_bit(&src
->ipvp
, IPVP_SENSE
)) {
417 /* level-sensitive irq */
418 src
->pending
= level
;
420 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
422 /* edge-sensitive irq */
426 openpic_update_irq(opp
, n_IRQ
);
429 static void openpic_reset (void *opaque
)
431 openpic_t
*opp
= (openpic_t
*)opaque
;
434 opp
->glbc
= 0x80000000;
435 /* Initialise controller registers */
436 opp
->frep
= ((OPENPIC_EXT_IRQ
- 1) << 16) | ((MAX_CPU
- 1) << 8) | VID
;
438 opp
->pint
= 0x00000000;
439 opp
->spve
= 0x000000FF;
440 opp
->tifr
= 0x003F7A00;
442 opp
->micr
= 0x00000000;
443 /* Initialise IRQ sources */
444 for (i
= 0; i
< opp
->max_irq
; i
++) {
445 opp
->src
[i
].ipvp
= 0xA0000000;
446 opp
->src
[i
].ide
= 0x00000000;
448 /* Initialise IRQ destinations */
449 for (i
= 0; i
< MAX_CPU
; i
++) {
450 opp
->dst
[i
].pctp
= 0x0000000F;
451 opp
->dst
[i
].pcsr
= 0x00000000;
452 memset(&opp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
453 opp
->dst
[i
].raised
.next
= -1;
454 memset(&opp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
455 opp
->dst
[i
].servicing
.next
= -1;
457 /* Initialise timers */
458 for (i
= 0; i
< MAX_TMR
; i
++) {
459 opp
->timers
[i
].ticc
= 0x00000000;
460 opp
->timers
[i
].tibc
= 0x80000000;
462 /* Initialise doorbells */
464 opp
->dar
= 0x00000000;
465 for (i
= 0; i
< MAX_DBL
; i
++) {
466 opp
->doorbells
[i
].dmr
= 0x00000000;
469 /* Initialise mailboxes */
471 for (i
= 0; i
< MAX_MBX
; i
++) { /* ? */
472 opp
->mailboxes
[i
].mbr
= 0x00000000;
475 /* Go out of RESET state */
476 opp
->glbc
= 0x00000000;
479 static inline uint32_t read_IRQreg_ide(openpic_t
*opp
, int n_IRQ
)
481 return opp
->src
[n_IRQ
].ide
;
484 static inline uint32_t read_IRQreg_ipvp(openpic_t
*opp
, int n_IRQ
)
486 return opp
->src
[n_IRQ
].ipvp
;
489 static inline void write_IRQreg_ide(openpic_t
*opp
, int n_IRQ
, uint32_t val
)
493 tmp
= val
& 0xC0000000;
494 tmp
|= val
& ((1ULL << MAX_CPU
) - 1);
495 opp
->src
[n_IRQ
].ide
= tmp
;
496 DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ
, opp
->src
[n_IRQ
].ide
);
499 static inline void write_IRQreg_ipvp(openpic_t
*opp
, int n_IRQ
, uint32_t val
)
501 /* NOTE: not fully accurate for special IRQs, but simple and sufficient */
502 /* ACTIVITY bit is read-only */
503 opp
->src
[n_IRQ
].ipvp
= (opp
->src
[n_IRQ
].ipvp
& 0x40000000)
504 | (val
& 0x800F00FF);
505 openpic_update_irq(opp
, n_IRQ
);
506 DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n", n_IRQ
, val
,
507 opp
->src
[n_IRQ
].ipvp
);
510 #if 0 // Code provision for Intel model
512 static uint32_t read_doorbell_register (openpic_t
*opp
,
513 int n_dbl
, uint32_t offset
)
518 case DBL_IPVP_OFFSET
:
519 retval
= read_IRQreg_ipvp(opp
, IRQ_DBL0
+ n_dbl
);
522 retval
= read_IRQreg_ide(opp
, IRQ_DBL0
+ n_dbl
);
525 retval
= opp
->doorbells
[n_dbl
].dmr
;
532 static void write_doorbell_register (penpic_t
*opp
, int n_dbl
,
533 uint32_t offset
, uint32_t value
)
536 case DBL_IVPR_OFFSET
:
537 write_IRQreg_ipvp(opp
, IRQ_DBL0
+ n_dbl
, value
);
540 write_IRQreg_ide(opp
, IRQ_DBL0
+ n_dbl
, value
);
543 opp
->doorbells
[n_dbl
].dmr
= value
;
550 static uint32_t read_mailbox_register (openpic_t
*opp
,
551 int n_mbx
, uint32_t offset
)
557 retval
= opp
->mailboxes
[n_mbx
].mbr
;
559 case MBX_IVPR_OFFSET
:
560 retval
= read_IRQreg_ipvp(opp
, IRQ_MBX0
+ n_mbx
);
563 retval
= read_IRQreg_ide(opp
, IRQ_MBX0
+ n_mbx
);
570 static void write_mailbox_register (openpic_t
*opp
, int n_mbx
,
571 uint32_t address
, uint32_t value
)
575 opp
->mailboxes
[n_mbx
].mbr
= value
;
577 case MBX_IVPR_OFFSET
:
578 write_IRQreg_ipvp(opp
, IRQ_MBX0
+ n_mbx
, value
);
581 write_IRQreg_ide(opp
, IRQ_MBX0
+ n_mbx
, value
);
586 #endif /* 0 : Code provision for Intel model */
588 static void openpic_gbl_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
590 openpic_t
*opp
= opaque
;
594 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
606 openpic_cpu_write_internal(opp
, addr
, val
, get_current_cpu());
608 case 0x1000: /* FREP */
610 case 0x1020: /* GLBC */
611 if (val
& 0x80000000 && opp
->reset
)
613 opp
->glbc
= val
& ~0x80000000;
615 case 0x1080: /* VENI */
617 case 0x1090: /* PINT */
618 for (idx
= 0; idx
< opp
->nb_cpus
; idx
++) {
619 if ((val
& (1 << idx
)) && !(opp
->pint
& (1 << idx
))) {
620 DPRINTF("Raise OpenPIC RESET output for CPU %d\n", idx
);
621 dst
= &opp
->dst
[idx
];
622 qemu_irq_raise(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
623 } else if (!(val
& (1 << idx
)) && (opp
->pint
& (1 << idx
))) {
624 DPRINTF("Lower OpenPIC RESET output for CPU %d\n", idx
);
625 dst
= &opp
->dst
[idx
];
626 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
631 case 0x10A0: /* IPI_IPVP */
637 idx
= (addr
- 0x10A0) >> 4;
638 write_IRQreg_ipvp(opp
, opp
->irq_ipi0
+ idx
, val
);
641 case 0x10E0: /* SPVE */
642 opp
->spve
= val
& 0x000000FF;
644 case 0x10F0: /* TIFR */
652 static uint32_t openpic_gbl_read (void *opaque
, target_phys_addr_t addr
)
654 openpic_t
*opp
= opaque
;
657 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
662 case 0x1000: /* FREP */
665 case 0x1020: /* GLBC */
668 case 0x1080: /* VENI */
671 case 0x1090: /* PINT */
682 retval
= openpic_cpu_read_internal(opp
, addr
, get_current_cpu());
684 case 0x10A0: /* IPI_IPVP */
690 idx
= (addr
- 0x10A0) >> 4;
691 retval
= read_IRQreg_ipvp(opp
, opp
->irq_ipi0
+ idx
);
694 case 0x10E0: /* SPVE */
697 case 0x10F0: /* TIFR */
703 DPRINTF("%s: => %08x\n", __func__
, retval
);
708 static void openpic_timer_write (void *opaque
, uint32_t addr
, uint32_t val
)
710 openpic_t
*opp
= opaque
;
713 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
718 idx
= (addr
& 0xFFF0) >> 6;
721 case 0x00: /* TICC */
723 case 0x10: /* TIBC */
724 if ((opp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
725 (val
& 0x80000000) == 0 &&
726 (opp
->timers
[idx
].tibc
& 0x80000000) != 0)
727 opp
->timers
[idx
].ticc
&= ~0x80000000;
728 opp
->timers
[idx
].tibc
= val
;
730 case 0x20: /* TIVP */
731 write_IRQreg_ipvp(opp
, opp
->irq_tim0
+ idx
, val
);
733 case 0x30: /* TIDE */
734 write_IRQreg_ide(opp
, opp
->irq_tim0
+ idx
, val
);
739 static uint32_t openpic_timer_read (void *opaque
, uint32_t addr
)
741 openpic_t
*opp
= opaque
;
745 DPRINTF("%s: addr %08x\n", __func__
, addr
);
751 idx
= (addr
& 0xFFF0) >> 6;
754 case 0x00: /* TICC */
755 retval
= opp
->timers
[idx
].ticc
;
757 case 0x10: /* TIBC */
758 retval
= opp
->timers
[idx
].tibc
;
760 case 0x20: /* TIPV */
761 retval
= read_IRQreg_ipvp(opp
, opp
->irq_tim0
+ idx
);
763 case 0x30: /* TIDE */
764 retval
= read_IRQreg_ide(opp
, opp
->irq_tim0
+ idx
);
767 DPRINTF("%s: => %08x\n", __func__
, retval
);
772 static void openpic_src_write (void *opaque
, uint32_t addr
, uint32_t val
)
774 openpic_t
*opp
= opaque
;
777 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
780 addr
= addr
& 0xFFF0;
783 /* EXDE / IFEDE / IEEDE */
784 write_IRQreg_ide(opp
, idx
, val
);
786 /* EXVP / IFEVP / IEEVP */
787 write_IRQreg_ipvp(opp
, idx
, val
);
791 static uint32_t openpic_src_read (void *opaque
, uint32_t addr
)
793 openpic_t
*opp
= opaque
;
797 DPRINTF("%s: addr %08x\n", __func__
, addr
);
801 addr
= addr
& 0xFFF0;
804 /* EXDE / IFEDE / IEEDE */
805 retval
= read_IRQreg_ide(opp
, idx
);
807 /* EXVP / IFEVP / IEEVP */
808 retval
= read_IRQreg_ipvp(opp
, idx
);
810 DPRINTF("%s: => %08x\n", __func__
, retval
);
815 static void openpic_cpu_write_internal(void *opaque
, target_phys_addr_t addr
,
816 uint32_t val
, int idx
)
818 openpic_t
*opp
= opaque
;
823 DPRINTF("%s: cpu %d addr " TARGET_FMT_plx
" <= %08x\n", __func__
, idx
,
827 dst
= &opp
->dst
[idx
];
831 case 0x40: /* IPIDR */
835 idx
= (addr
- 0x40) >> 4;
836 /* we use IDE as mask which CPUs to deliver the IPI to still. */
837 write_IRQreg_ide(opp
, opp
->irq_ipi0
+ idx
,
838 opp
->src
[opp
->irq_ipi0
+ idx
].ide
| val
);
839 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 1);
840 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 0);
843 case 0x80: /* PCTP */
844 dst
->pctp
= val
& 0x0000000F;
846 case 0x90: /* WHOAMI */
847 /* Read-only register */
849 case 0xA0: /* PIAC */
850 /* Read-only register */
852 case 0xB0: /* PEOI */
854 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
855 IRQ_resetbit(&dst
->servicing
, s_IRQ
);
856 dst
->servicing
.next
= -1;
857 /* Set up next servicing IRQ */
858 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
859 /* Check queued interrupts. */
860 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
861 src
= &opp
->src
[n_IRQ
];
864 IPVP_PRIORITY(src
->ipvp
) > dst
->servicing
.priority
)) {
865 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n",
867 opp
->irq_raise(opp
, idx
, src
);
875 static void openpic_cpu_write(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
877 openpic_cpu_write_internal(opaque
, addr
, val
, (addr
& 0x1f000) >> 12);
880 static uint32_t openpic_cpu_read_internal(void *opaque
, target_phys_addr_t addr
,
883 openpic_t
*opp
= opaque
;
889 DPRINTF("%s: cpu %d addr " TARGET_FMT_plx
"\n", __func__
, idx
, addr
);
893 dst
= &opp
->dst
[idx
];
896 case 0x80: /* PCTP */
899 case 0x90: /* WHOAMI */
902 case 0xA0: /* PIAC */
903 DPRINTF("Lower OpenPIC INT output\n");
904 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
905 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
906 DPRINTF("PIAC: irq=%d\n", n_IRQ
);
908 /* No more interrupt pending */
909 retval
= IPVP_VECTOR(opp
->spve
);
911 src
= &opp
->src
[n_IRQ
];
912 if (!test_bit(&src
->ipvp
, IPVP_ACTIVITY
) ||
913 !(IPVP_PRIORITY(src
->ipvp
) > dst
->pctp
)) {
914 /* - Spurious level-sensitive IRQ
915 * - Priorities has been changed
916 * and the pending IRQ isn't allowed anymore
918 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
919 retval
= IPVP_VECTOR(opp
->spve
);
921 /* IRQ enter servicing state */
922 IRQ_setbit(&dst
->servicing
, n_IRQ
);
923 retval
= IPVP_VECTOR(src
->ipvp
);
925 IRQ_resetbit(&dst
->raised
, n_IRQ
);
926 dst
->raised
.next
= -1;
927 if (!test_bit(&src
->ipvp
, IPVP_SENSE
)) {
928 /* edge-sensitive IRQ */
929 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
933 if ((n_IRQ
>= opp
->irq_ipi0
) && (n_IRQ
< (opp
->irq_ipi0
+ MAX_IPI
))) {
934 src
->ide
&= ~(1 << idx
);
935 if (src
->ide
&& !test_bit(&src
->ipvp
, IPVP_SENSE
)) {
936 /* trigger on CPUs that didn't know about it yet */
937 openpic_set_irq(opp
, n_IRQ
, 1);
938 openpic_set_irq(opp
, n_IRQ
, 0);
939 /* if all CPUs knew about it, set active bit again */
940 set_bit(&src
->ipvp
, IPVP_ACTIVITY
);
945 case 0xB0: /* PEOI */
951 DPRINTF("%s: => %08x\n", __func__
, retval
);
956 static uint32_t openpic_cpu_read(void *opaque
, target_phys_addr_t addr
)
958 return openpic_cpu_read_internal(opaque
, addr
, (addr
& 0x1f000) >> 12);
961 static void openpic_buggy_write (void *opaque
,
962 target_phys_addr_t addr
, uint32_t val
)
964 printf("Invalid OPENPIC write access !\n");
967 static uint32_t openpic_buggy_read (void *opaque
, target_phys_addr_t addr
)
969 printf("Invalid OPENPIC read access !\n");
974 static void openpic_writel (void *opaque
,
975 target_phys_addr_t addr
, uint32_t val
)
977 openpic_t
*opp
= opaque
;
980 DPRINTF("%s: offset %08x val: %08x\n", __func__
, (int)addr
, val
);
982 /* Global registers */
983 openpic_gbl_write(opp
, addr
, val
);
984 } else if (addr
< 0x10000) {
985 /* Timers registers */
986 openpic_timer_write(opp
, addr
, val
);
987 } else if (addr
< 0x20000) {
988 /* Source registers */
989 openpic_src_write(opp
, addr
, val
);
992 openpic_cpu_write(opp
, addr
, val
);
996 static uint32_t openpic_readl (void *opaque
,target_phys_addr_t addr
)
998 openpic_t
*opp
= opaque
;
1002 DPRINTF("%s: offset %08x\n", __func__
, (int)addr
);
1003 if (addr
< 0x1100) {
1004 /* Global registers */
1005 retval
= openpic_gbl_read(opp
, addr
);
1006 } else if (addr
< 0x10000) {
1007 /* Timers registers */
1008 retval
= openpic_timer_read(opp
, addr
);
1009 } else if (addr
< 0x20000) {
1010 /* Source registers */
1011 retval
= openpic_src_read(opp
, addr
);
1014 retval
= openpic_cpu_read(opp
, addr
);
1020 static uint64_t openpic_read(void *opaque
, target_phys_addr_t addr
,
1023 openpic_t
*opp
= opaque
;
1026 case 4: return openpic_readl(opp
, addr
);
1027 default: return openpic_buggy_read(opp
, addr
);
1031 static void openpic_write(void *opaque
, target_phys_addr_t addr
,
1032 uint64_t data
, unsigned size
)
1034 openpic_t
*opp
= opaque
;
1037 case 4: return openpic_writel(opp
, addr
, data
);
1038 default: return openpic_buggy_write(opp
, addr
, data
);
1042 static const MemoryRegionOps openpic_ops
= {
1043 .read
= openpic_read
,
1044 .write
= openpic_write
,
1045 .endianness
= DEVICE_LITTLE_ENDIAN
,
1048 static void openpic_save_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1052 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1053 qemu_put_be32s(f
, &q
->queue
[i
]);
1055 qemu_put_sbe32s(f
, &q
->next
);
1056 qemu_put_sbe32s(f
, &q
->priority
);
1059 static void openpic_save(QEMUFile
* f
, void *opaque
)
1061 openpic_t
*opp
= (openpic_t
*)opaque
;
1064 qemu_put_be32s(f
, &opp
->frep
);
1065 qemu_put_be32s(f
, &opp
->glbc
);
1066 qemu_put_be32s(f
, &opp
->micr
);
1067 qemu_put_be32s(f
, &opp
->veni
);
1068 qemu_put_be32s(f
, &opp
->pint
);
1069 qemu_put_be32s(f
, &opp
->spve
);
1070 qemu_put_be32s(f
, &opp
->tifr
);
1072 for (i
= 0; i
< opp
->max_irq
; i
++) {
1073 qemu_put_be32s(f
, &opp
->src
[i
].ipvp
);
1074 qemu_put_be32s(f
, &opp
->src
[i
].ide
);
1075 qemu_put_sbe32s(f
, &opp
->src
[i
].type
);
1076 qemu_put_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1077 qemu_put_sbe32s(f
, &opp
->src
[i
].pending
);
1080 qemu_put_sbe32s(f
, &opp
->nb_cpus
);
1082 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1083 qemu_put_be32s(f
, &opp
->dst
[i
].tfrr
);
1084 qemu_put_be32s(f
, &opp
->dst
[i
].pctp
);
1085 qemu_put_be32s(f
, &opp
->dst
[i
].pcsr
);
1086 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1087 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1090 for (i
= 0; i
< MAX_TMR
; i
++) {
1091 qemu_put_be32s(f
, &opp
->timers
[i
].ticc
);
1092 qemu_put_be32s(f
, &opp
->timers
[i
].tibc
);
1096 qemu_put_be32s(f
, &opp
->dar
);
1098 for (i
= 0; i
< MAX_DBL
; i
++) {
1099 qemu_put_be32s(f
, &opp
->doorbells
[i
].dmr
);
1104 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1105 qemu_put_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1109 pci_device_save(&opp
->pci_dev
, f
);
1112 static void openpic_load_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1116 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1117 qemu_get_be32s(f
, &q
->queue
[i
]);
1119 qemu_get_sbe32s(f
, &q
->next
);
1120 qemu_get_sbe32s(f
, &q
->priority
);
1123 static int openpic_load(QEMUFile
* f
, void *opaque
, int version_id
)
1125 openpic_t
*opp
= (openpic_t
*)opaque
;
1128 if (version_id
!= 1)
1131 qemu_get_be32s(f
, &opp
->frep
);
1132 qemu_get_be32s(f
, &opp
->glbc
);
1133 qemu_get_be32s(f
, &opp
->micr
);
1134 qemu_get_be32s(f
, &opp
->veni
);
1135 qemu_get_be32s(f
, &opp
->pint
);
1136 qemu_get_be32s(f
, &opp
->spve
);
1137 qemu_get_be32s(f
, &opp
->tifr
);
1139 for (i
= 0; i
< opp
->max_irq
; i
++) {
1140 qemu_get_be32s(f
, &opp
->src
[i
].ipvp
);
1141 qemu_get_be32s(f
, &opp
->src
[i
].ide
);
1142 qemu_get_sbe32s(f
, &opp
->src
[i
].type
);
1143 qemu_get_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1144 qemu_get_sbe32s(f
, &opp
->src
[i
].pending
);
1147 qemu_get_sbe32s(f
, &opp
->nb_cpus
);
1149 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1150 qemu_get_be32s(f
, &opp
->dst
[i
].tfrr
);
1151 qemu_get_be32s(f
, &opp
->dst
[i
].pctp
);
1152 qemu_get_be32s(f
, &opp
->dst
[i
].pcsr
);
1153 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1154 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1157 for (i
= 0; i
< MAX_TMR
; i
++) {
1158 qemu_get_be32s(f
, &opp
->timers
[i
].ticc
);
1159 qemu_get_be32s(f
, &opp
->timers
[i
].tibc
);
1163 qemu_get_be32s(f
, &opp
->dar
);
1165 for (i
= 0; i
< MAX_DBL
; i
++) {
1166 qemu_get_be32s(f
, &opp
->doorbells
[i
].dmr
);
1171 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1172 qemu_get_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1176 return pci_device_load(&opp
->pci_dev
, f
);
1179 static void openpic_irq_raise(openpic_t
*opp
, int n_CPU
, IRQ_src_t
*src
)
1181 qemu_irq_raise(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1184 qemu_irq
*openpic_init (MemoryRegion
**pmem
, int nb_cpus
,
1185 qemu_irq
**irqs
, qemu_irq irq_out
)
1190 /* XXX: for now, only one CPU is supported */
1193 opp
= g_malloc0(sizeof(openpic_t
));
1194 memory_region_init_io(&opp
->mem
, &openpic_ops
, opp
, "openpic", 0x40000);
1196 // isu_base &= 0xFFFC0000;
1197 opp
->nb_cpus
= nb_cpus
;
1198 opp
->max_irq
= OPENPIC_MAX_IRQ
;
1199 opp
->irq_ipi0
= OPENPIC_IRQ_IPI0
;
1200 opp
->irq_tim0
= OPENPIC_IRQ_TIM0
;
1202 for (i
= 0; i
< OPENPIC_EXT_IRQ
; i
++) {
1203 opp
->src
[i
].type
= IRQ_EXTERNAL
;
1205 for (; i
< OPENPIC_IRQ_TIM0
; i
++) {
1206 opp
->src
[i
].type
= IRQ_SPECIAL
;
1209 m
= OPENPIC_IRQ_IPI0
;
1211 m
= OPENPIC_IRQ_DBL0
;
1213 for (; i
< m
; i
++) {
1214 opp
->src
[i
].type
= IRQ_TIMER
;
1216 for (; i
< OPENPIC_MAX_IRQ
; i
++) {
1217 opp
->src
[i
].type
= IRQ_INTERNAL
;
1219 for (i
= 0; i
< nb_cpus
; i
++)
1220 opp
->dst
[i
].irqs
= irqs
[i
];
1221 opp
->irq_out
= irq_out
;
1223 register_savevm(&opp
->pci_dev
.qdev
, "openpic", 0, 2,
1224 openpic_save
, openpic_load
, opp
);
1225 qemu_register_reset(openpic_reset
, opp
);
1227 opp
->irq_raise
= openpic_irq_raise
;
1228 opp
->reset
= openpic_reset
;
1233 return qemu_allocate_irqs(openpic_set_irq
, opp
, opp
->max_irq
);
1236 static void mpic_irq_raise(openpic_t
*mpp
, int n_CPU
, IRQ_src_t
*src
)
1238 int n_ci
= IDR_CI0
- n_CPU
;
1240 if(test_bit(&src
->ide
, n_ci
)) {
1241 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_CINT
]);
1244 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1248 static void mpic_reset (void *opaque
)
1250 openpic_t
*mpp
= (openpic_t
*)opaque
;
1253 mpp
->glbc
= 0x80000000;
1254 /* Initialise controller registers */
1255 mpp
->frep
= 0x004f0002 | ((mpp
->nb_cpus
- 1) << 8);
1257 mpp
->pint
= 0x00000000;
1258 mpp
->spve
= 0x0000FFFF;
1259 /* Initialise IRQ sources */
1260 for (i
= 0; i
< mpp
->max_irq
; i
++) {
1261 mpp
->src
[i
].ipvp
= 0x80800000;
1262 mpp
->src
[i
].ide
= 0x00000001;
1264 /* Set IDE for IPIs to 0 so we don't get spurious interrupts */
1265 for (i
= mpp
->irq_ipi0
; i
< (mpp
->irq_ipi0
+ MAX_IPI
); i
++) {
1266 mpp
->src
[i
].ide
= 0;
1268 /* Initialise IRQ destinations */
1269 for (i
= 0; i
< MAX_CPU
; i
++) {
1270 mpp
->dst
[i
].pctp
= 0x0000000F;
1271 mpp
->dst
[i
].tfrr
= 0x00000000;
1272 memset(&mpp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
1273 mpp
->dst
[i
].raised
.next
= -1;
1274 memset(&mpp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
1275 mpp
->dst
[i
].servicing
.next
= -1;
1277 /* Initialise timers */
1278 for (i
= 0; i
< MAX_TMR
; i
++) {
1279 mpp
->timers
[i
].ticc
= 0x00000000;
1280 mpp
->timers
[i
].tibc
= 0x80000000;
1282 /* Go out of RESET state */
1283 mpp
->glbc
= 0x00000000;
1286 static void mpic_timer_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
1288 openpic_t
*mpp
= opaque
;
1291 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1296 idx
= (addr
>> 6) & 0x3;
1297 switch (addr
& 0x30) {
1298 case 0x00: /* gtccr */
1300 case 0x10: /* gtbcr */
1301 if ((mpp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
1302 (val
& 0x80000000) == 0 &&
1303 (mpp
->timers
[idx
].tibc
& 0x80000000) != 0)
1304 mpp
->timers
[idx
].ticc
&= ~0x80000000;
1305 mpp
->timers
[idx
].tibc
= val
;
1307 case 0x20: /* GTIVPR */
1308 write_IRQreg_ipvp(mpp
, MPIC_TMR_IRQ
+ idx
, val
);
1310 case 0x30: /* GTIDR & TFRR */
1311 if ((addr
& 0xF0) == 0xF0)
1312 mpp
->dst
[cpu
].tfrr
= val
;
1314 write_IRQreg_ide(mpp
, MPIC_TMR_IRQ
+ idx
, val
);
1319 static uint32_t mpic_timer_read (void *opaque
, target_phys_addr_t addr
)
1321 openpic_t
*mpp
= opaque
;
1325 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1326 retval
= 0xFFFFFFFF;
1331 idx
= (addr
>> 6) & 0x3;
1332 switch (addr
& 0x30) {
1333 case 0x00: /* gtccr */
1334 retval
= mpp
->timers
[idx
].ticc
;
1336 case 0x10: /* gtbcr */
1337 retval
= mpp
->timers
[idx
].tibc
;
1339 case 0x20: /* TIPV */
1340 retval
= read_IRQreg_ipvp(mpp
, MPIC_TMR_IRQ
+ idx
);
1342 case 0x30: /* TIDR */
1343 if ((addr
&0xF0) == 0XF0)
1344 retval
= mpp
->dst
[cpu
].tfrr
;
1346 retval
= read_IRQreg_ide(mpp
, MPIC_TMR_IRQ
+ idx
);
1349 DPRINTF("%s: => %08x\n", __func__
, retval
);
1354 static void mpic_src_ext_write (void *opaque
, target_phys_addr_t addr
,
1357 openpic_t
*mpp
= opaque
;
1358 int idx
= MPIC_EXT_IRQ
;
1360 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1364 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1365 if (addr
< MPIC_EXT_REG_SIZE
) {
1366 idx
+= (addr
& 0xFFF0) >> 5;
1368 /* EXDE / IFEDE / IEEDE */
1369 write_IRQreg_ide(mpp
, idx
, val
);
1371 /* EXVP / IFEVP / IEEVP */
1372 write_IRQreg_ipvp(mpp
, idx
, val
);
1377 static uint32_t mpic_src_ext_read (void *opaque
, target_phys_addr_t addr
)
1379 openpic_t
*mpp
= opaque
;
1381 int idx
= MPIC_EXT_IRQ
;
1383 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1384 retval
= 0xFFFFFFFF;
1388 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1389 if (addr
< MPIC_EXT_REG_SIZE
) {
1390 idx
+= (addr
& 0xFFF0) >> 5;
1392 /* EXDE / IFEDE / IEEDE */
1393 retval
= read_IRQreg_ide(mpp
, idx
);
1395 /* EXVP / IFEVP / IEEVP */
1396 retval
= read_IRQreg_ipvp(mpp
, idx
);
1398 DPRINTF("%s: => %08x\n", __func__
, retval
);
1404 static void mpic_src_int_write (void *opaque
, target_phys_addr_t addr
,
1407 openpic_t
*mpp
= opaque
;
1408 int idx
= MPIC_INT_IRQ
;
1410 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1414 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1415 if (addr
< MPIC_INT_REG_SIZE
) {
1416 idx
+= (addr
& 0xFFF0) >> 5;
1418 /* EXDE / IFEDE / IEEDE */
1419 write_IRQreg_ide(mpp
, idx
, val
);
1421 /* EXVP / IFEVP / IEEVP */
1422 write_IRQreg_ipvp(mpp
, idx
, val
);
1427 static uint32_t mpic_src_int_read (void *opaque
, target_phys_addr_t addr
)
1429 openpic_t
*mpp
= opaque
;
1431 int idx
= MPIC_INT_IRQ
;
1433 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1434 retval
= 0xFFFFFFFF;
1438 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1439 if (addr
< MPIC_INT_REG_SIZE
) {
1440 idx
+= (addr
& 0xFFF0) >> 5;
1442 /* EXDE / IFEDE / IEEDE */
1443 retval
= read_IRQreg_ide(mpp
, idx
);
1445 /* EXVP / IFEVP / IEEVP */
1446 retval
= read_IRQreg_ipvp(mpp
, idx
);
1448 DPRINTF("%s: => %08x\n", __func__
, retval
);
1454 static void mpic_src_msg_write (void *opaque
, target_phys_addr_t addr
,
1457 openpic_t
*mpp
= opaque
;
1458 int idx
= MPIC_MSG_IRQ
;
1460 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1464 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1465 if (addr
< MPIC_MSG_REG_SIZE
) {
1466 idx
+= (addr
& 0xFFF0) >> 5;
1468 /* EXDE / IFEDE / IEEDE */
1469 write_IRQreg_ide(mpp
, idx
, val
);
1471 /* EXVP / IFEVP / IEEVP */
1472 write_IRQreg_ipvp(mpp
, idx
, val
);
1477 static uint32_t mpic_src_msg_read (void *opaque
, target_phys_addr_t addr
)
1479 openpic_t
*mpp
= opaque
;
1481 int idx
= MPIC_MSG_IRQ
;
1483 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1484 retval
= 0xFFFFFFFF;
1488 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1489 if (addr
< MPIC_MSG_REG_SIZE
) {
1490 idx
+= (addr
& 0xFFF0) >> 5;
1492 /* EXDE / IFEDE / IEEDE */
1493 retval
= read_IRQreg_ide(mpp
, idx
);
1495 /* EXVP / IFEVP / IEEVP */
1496 retval
= read_IRQreg_ipvp(mpp
, idx
);
1498 DPRINTF("%s: => %08x\n", __func__
, retval
);
1504 static void mpic_src_msi_write (void *opaque
, target_phys_addr_t addr
,
1507 openpic_t
*mpp
= opaque
;
1508 int idx
= MPIC_MSI_IRQ
;
1510 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1514 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1515 if (addr
< MPIC_MSI_REG_SIZE
) {
1516 idx
+= (addr
& 0xFFF0) >> 5;
1518 /* EXDE / IFEDE / IEEDE */
1519 write_IRQreg_ide(mpp
, idx
, val
);
1521 /* EXVP / IFEVP / IEEVP */
1522 write_IRQreg_ipvp(mpp
, idx
, val
);
1526 static uint32_t mpic_src_msi_read (void *opaque
, target_phys_addr_t addr
)
1528 openpic_t
*mpp
= opaque
;
1530 int idx
= MPIC_MSI_IRQ
;
1532 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1533 retval
= 0xFFFFFFFF;
1537 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1538 if (addr
< MPIC_MSI_REG_SIZE
) {
1539 idx
+= (addr
& 0xFFF0) >> 5;
1541 /* EXDE / IFEDE / IEEDE */
1542 retval
= read_IRQreg_ide(mpp
, idx
);
1544 /* EXVP / IFEVP / IEEVP */
1545 retval
= read_IRQreg_ipvp(mpp
, idx
);
1547 DPRINTF("%s: => %08x\n", __func__
, retval
);
1553 static const MemoryRegionOps mpic_glb_ops
= {
1555 .write
= { openpic_buggy_write
,
1556 openpic_buggy_write
,
1559 .read
= { openpic_buggy_read
,
1564 .endianness
= DEVICE_BIG_ENDIAN
,
1567 static const MemoryRegionOps mpic_tmr_ops
= {
1569 .write
= { openpic_buggy_write
,
1570 openpic_buggy_write
,
1573 .read
= { openpic_buggy_read
,
1578 .endianness
= DEVICE_BIG_ENDIAN
,
1581 static const MemoryRegionOps mpic_cpu_ops
= {
1583 .write
= { openpic_buggy_write
,
1584 openpic_buggy_write
,
1587 .read
= { openpic_buggy_read
,
1592 .endianness
= DEVICE_BIG_ENDIAN
,
1595 static const MemoryRegionOps mpic_ext_ops
= {
1597 .write
= { openpic_buggy_write
,
1598 openpic_buggy_write
,
1601 .read
= { openpic_buggy_read
,
1606 .endianness
= DEVICE_BIG_ENDIAN
,
1609 static const MemoryRegionOps mpic_int_ops
= {
1611 .write
= { openpic_buggy_write
,
1612 openpic_buggy_write
,
1615 .read
= { openpic_buggy_read
,
1620 .endianness
= DEVICE_BIG_ENDIAN
,
1623 static const MemoryRegionOps mpic_msg_ops
= {
1625 .write
= { openpic_buggy_write
,
1626 openpic_buggy_write
,
1629 .read
= { openpic_buggy_read
,
1634 .endianness
= DEVICE_BIG_ENDIAN
,
1637 static const MemoryRegionOps mpic_msi_ops
= {
1639 .write
= { openpic_buggy_write
,
1640 openpic_buggy_write
,
1643 .read
= { openpic_buggy_read
,
1648 .endianness
= DEVICE_BIG_ENDIAN
,
1651 qemu_irq
*mpic_init (MemoryRegion
*address_space
, target_phys_addr_t base
,
1652 int nb_cpus
, qemu_irq
**irqs
, qemu_irq irq_out
)
1658 MemoryRegionOps
const *ops
;
1659 target_phys_addr_t start_addr
;
1662 {"glb", &mpic_glb_ops
, MPIC_GLB_REG_START
, MPIC_GLB_REG_SIZE
},
1663 {"tmr", &mpic_tmr_ops
, MPIC_TMR_REG_START
, MPIC_TMR_REG_SIZE
},
1664 {"ext", &mpic_ext_ops
, MPIC_EXT_REG_START
, MPIC_EXT_REG_SIZE
},
1665 {"int", &mpic_int_ops
, MPIC_INT_REG_START
, MPIC_INT_REG_SIZE
},
1666 {"msg", &mpic_msg_ops
, MPIC_MSG_REG_START
, MPIC_MSG_REG_SIZE
},
1667 {"msi", &mpic_msi_ops
, MPIC_MSI_REG_START
, MPIC_MSI_REG_SIZE
},
1668 {"cpu", &mpic_cpu_ops
, MPIC_CPU_REG_START
, MPIC_CPU_REG_SIZE
},
1671 mpp
= g_malloc0(sizeof(openpic_t
));
1673 memory_region_init(&mpp
->mem
, "mpic", 0x40000);
1674 memory_region_add_subregion(address_space
, base
, &mpp
->mem
);
1676 for (i
= 0; i
< sizeof(list
)/sizeof(list
[0]); i
++) {
1678 memory_region_init_io(&mpp
->sub_io_mem
[i
], list
[i
].ops
, mpp
,
1679 list
[i
].name
, list
[i
].size
);
1681 memory_region_add_subregion(&mpp
->mem
, list
[i
].start_addr
,
1682 &mpp
->sub_io_mem
[i
]);
1685 mpp
->nb_cpus
= nb_cpus
;
1686 mpp
->max_irq
= MPIC_MAX_IRQ
;
1687 mpp
->irq_ipi0
= MPIC_IPI_IRQ
;
1688 mpp
->irq_tim0
= MPIC_TMR_IRQ
;
1690 for (i
= 0; i
< nb_cpus
; i
++)
1691 mpp
->dst
[i
].irqs
= irqs
[i
];
1692 mpp
->irq_out
= irq_out
;
1694 mpp
->irq_raise
= mpic_irq_raise
;
1695 mpp
->reset
= mpic_reset
;
1697 register_savevm(NULL
, "mpic", 0, 2, openpic_save
, openpic_load
, mpp
);
1698 qemu_register_reset(mpic_reset
, mpp
);
1700 return qemu_allocate_irqs(openpic_set_irq
, mpp
, mpp
->max_irq
);