4 * Copyright (c) 2004 Jocelyn Mayer
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * Based on OpenPic implementations:
27 * - Intel GW80314 I/O companion chip developer's manual
28 * - Motorola MPC8245 & MPC8540 user manuals.
29 * - Motorola MCP750 (aka Raven) programmer manual.
30 * - Motorola Harrier programmer manuel
32 * Serial interrupts, as implemented in Raven chipset are not supported yet.
40 //#define DEBUG_OPENPIC
43 #define DPRINTF(fmt, ...) do { printf(fmt , ## __VA_ARGS__); } while (0)
45 #define DPRINTF(fmt, ...) do { } while (0)
48 #define USE_MPCxxx /* Intel model is broken, for now */
50 #if defined (USE_INTEL_GW80314)
51 /* Intel GW80314 I/O Companion chip */
61 #define VID (0x00000000)
63 #elif defined(USE_MPCxxx)
72 #define VID 0x03 /* MPIC version ID */
73 #define VENI 0x00000000 /* Vendor ID */
81 #define OPENPIC_MAX_CPU 2
82 #define OPENPIC_MAX_IRQ 64
83 #define OPENPIC_EXT_IRQ 48
84 #define OPENPIC_MAX_TMR MAX_TMR
85 #define OPENPIC_MAX_IPI MAX_IPI
87 /* Interrupt definitions */
88 #define OPENPIC_IRQ_FE (OPENPIC_EXT_IRQ) /* Internal functional IRQ */
89 #define OPENPIC_IRQ_ERR (OPENPIC_EXT_IRQ + 1) /* Error IRQ */
90 #define OPENPIC_IRQ_TIM0 (OPENPIC_EXT_IRQ + 2) /* First timer IRQ */
91 #if OPENPIC_MAX_IPI > 0
92 #define OPENPIC_IRQ_IPI0 (OPENPIC_IRQ_TIM0 + OPENPIC_MAX_TMR) /* First IPI IRQ */
93 #define OPENPIC_IRQ_DBL0 (OPENPIC_IRQ_IPI0 + (OPENPIC_MAX_CPU * OPENPIC_MAX_IPI)) /* First doorbell IRQ */
95 #define OPENPIC_IRQ_DBL0 (OPENPIC_IRQ_TIM0 + OPENPIC_MAX_TMR) /* First doorbell IRQ */
96 #define OPENPIC_IRQ_MBX0 (OPENPIC_IRQ_DBL0 + OPENPIC_MAX_DBL) /* First mailbox IRQ */
100 #define MPIC_MAX_CPU 1
101 #define MPIC_MAX_EXT 12
102 #define MPIC_MAX_INT 64
103 #define MPIC_MAX_MSG 4
104 #define MPIC_MAX_MSI 8
105 #define MPIC_MAX_TMR MAX_TMR
106 #define MPIC_MAX_IPI MAX_IPI
107 #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))
109 /* Interrupt definitions */
110 #define MPIC_EXT_IRQ 0
111 #define MPIC_INT_IRQ (MPIC_EXT_IRQ + MPIC_MAX_EXT)
112 #define MPIC_TMR_IRQ (MPIC_INT_IRQ + MPIC_MAX_INT)
113 #define MPIC_MSG_IRQ (MPIC_TMR_IRQ + MPIC_MAX_TMR)
114 #define MPIC_MSI_IRQ (MPIC_MSG_IRQ + MPIC_MAX_MSG)
115 #define MPIC_IPI_IRQ (MPIC_MSI_IRQ + MPIC_MAX_MSI)
117 #define MPIC_GLB_REG_START 0x0
118 #define MPIC_GLB_REG_SIZE 0x10F0
119 #define MPIC_TMR_REG_START 0x10F0
120 #define MPIC_TMR_REG_SIZE 0x220
121 #define MPIC_EXT_REG_START 0x10000
122 #define MPIC_EXT_REG_SIZE 0x180
123 #define MPIC_INT_REG_START 0x10200
124 #define MPIC_INT_REG_SIZE 0x800
125 #define MPIC_MSG_REG_START 0x11600
126 #define MPIC_MSG_REG_SIZE 0x100
127 #define MPIC_MSI_REG_START 0x11C00
128 #define MPIC_MSI_REG_SIZE 0x100
129 #define MPIC_CPU_REG_START 0x20000
130 #define MPIC_CPU_REG_SIZE 0x100
141 #error "Please select which OpenPic implementation is to be emulated"
144 #define OPENPIC_PAGE_SIZE 4096
146 #define BF_WIDTH(_bits_) \
147 (((_bits_) + (sizeof(uint32_t) * 8) - 1) / (sizeof(uint32_t) * 8))
149 static inline void set_bit (uint32_t *field
, int bit
)
151 field
[bit
>> 5] |= 1 << (bit
& 0x1F);
154 static inline void reset_bit (uint32_t *field
, int bit
)
156 field
[bit
>> 5] &= ~(1 << (bit
& 0x1F));
159 static inline int test_bit (uint32_t *field
, int bit
)
161 return (field
[bit
>> 5] & 1 << (bit
& 0x1F)) != 0;
171 typedef struct IRQ_queue_t
{
172 uint32_t queue
[BF_WIDTH(MAX_IRQ
)];
177 typedef struct IRQ_src_t
{
178 uint32_t ipvp
; /* IRQ vector/priority register */
179 uint32_t ide
; /* IRQ destination register */
182 int pending
; /* TRUE if IRQ is pending */
192 #define IPVP_PRIORITY_MASK (0x1F << 16)
193 #define IPVP_PRIORITY(_ipvpr_) ((int)(((_ipvpr_) & IPVP_PRIORITY_MASK) >> 16))
194 #define IPVP_VECTOR_MASK ((1 << VECTOR_BITS) - 1)
195 #define IPVP_VECTOR(_ipvpr_) ((_ipvpr_) & IPVP_VECTOR_MASK)
197 typedef struct IRQ_dst_t
{
199 uint32_t pctp
; /* CPU current task priority */
200 uint32_t pcsr
; /* CPU sensitivity register */
202 IRQ_queue_t servicing
;
206 typedef struct openpic_t
{
209 /* Global registers */
210 uint32_t frep
; /* Feature reporting register */
211 uint32_t glbc
; /* Global configuration register */
212 uint32_t micr
; /* MPIC interrupt configuration register */
213 uint32_t veni
; /* Vendor identification register */
214 uint32_t pint
; /* Processor initialization register */
215 uint32_t spve
; /* Spurious vector register */
216 uint32_t tifr
; /* Timer frequency reporting register */
217 /* Source registers */
218 IRQ_src_t src
[MAX_IRQ
];
219 /* Local registers per output pin */
220 IRQ_dst_t dst
[MAX_CPU
];
222 /* Timer registers */
224 uint32_t ticc
; /* Global timer current count register */
225 uint32_t tibc
; /* Global timer base count register */
228 /* Doorbell registers */
229 uint32_t dar
; /* Doorbell activate register */
231 uint32_t dmr
; /* Doorbell messaging register */
232 } doorbells
[MAX_DBL
];
235 /* Mailbox registers */
237 uint32_t mbr
; /* Mailbox register */
238 } mailboxes
[MAX_MAILBOXES
];
240 /* IRQ out is used when in bypass mode (not implemented) */
245 void (*reset
) (void *);
246 void (*irq_raise
) (struct openpic_t
*, int, IRQ_src_t
*);
249 static inline void IRQ_setbit (IRQ_queue_t
*q
, int n_IRQ
)
251 set_bit(q
->queue
, n_IRQ
);
254 static inline void IRQ_resetbit (IRQ_queue_t
*q
, int n_IRQ
)
256 reset_bit(q
->queue
, n_IRQ
);
259 static inline int IRQ_testbit (IRQ_queue_t
*q
, int n_IRQ
)
261 return test_bit(q
->queue
, n_IRQ
);
264 static void IRQ_check (openpic_t
*opp
, IRQ_queue_t
*q
)
271 for (i
= 0; i
< opp
->max_irq
; i
++) {
272 if (IRQ_testbit(q
, i
)) {
273 DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
274 i
, IPVP_PRIORITY(opp
->src
[i
].ipvp
), priority
);
275 if (IPVP_PRIORITY(opp
->src
[i
].ipvp
) > priority
) {
277 priority
= IPVP_PRIORITY(opp
->src
[i
].ipvp
);
282 q
->priority
= priority
;
285 static int IRQ_get_next (openpic_t
*opp
, IRQ_queue_t
*q
)
295 static void IRQ_local_pipe (openpic_t
*opp
, int n_CPU
, int n_IRQ
)
301 dst
= &opp
->dst
[n_CPU
];
302 src
= &opp
->src
[n_IRQ
];
303 priority
= IPVP_PRIORITY(src
->ipvp
);
304 if (priority
<= dst
->pctp
) {
305 /* Too low priority */
306 DPRINTF("%s: IRQ %d has too low priority on CPU %d\n",
307 __func__
, n_IRQ
, n_CPU
);
310 if (IRQ_testbit(&dst
->raised
, n_IRQ
)) {
312 DPRINTF("%s: IRQ %d was missed on CPU %d\n",
313 __func__
, n_IRQ
, n_CPU
);
316 set_bit(&src
->ipvp
, IPVP_ACTIVITY
);
317 IRQ_setbit(&dst
->raised
, n_IRQ
);
318 if (priority
< dst
->raised
.priority
) {
319 /* An higher priority IRQ is already raised */
320 DPRINTF("%s: IRQ %d is hidden by raised IRQ %d on CPU %d\n",
321 __func__
, n_IRQ
, dst
->raised
.next
, n_CPU
);
324 IRQ_get_next(opp
, &dst
->raised
);
325 if (IRQ_get_next(opp
, &dst
->servicing
) != -1 &&
326 priority
<= dst
->servicing
.priority
) {
327 DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n",
328 __func__
, n_IRQ
, dst
->servicing
.next
, n_CPU
);
329 /* Already servicing a higher priority IRQ */
332 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n", n_CPU
, n_IRQ
);
333 opp
->irq_raise(opp
, n_CPU
, src
);
336 /* update pic state because registers for n_IRQ have changed value */
337 static void openpic_update_irq(openpic_t
*opp
, int n_IRQ
)
342 src
= &opp
->src
[n_IRQ
];
346 DPRINTF("%s: IRQ %d is not pending\n", __func__
, n_IRQ
);
349 if (test_bit(&src
->ipvp
, IPVP_MASK
)) {
350 /* Interrupt source is disabled */
351 DPRINTF("%s: IRQ %d is disabled\n", __func__
, n_IRQ
);
354 if (IPVP_PRIORITY(src
->ipvp
) == 0) {
355 /* Priority set to zero */
356 DPRINTF("%s: IRQ %d has 0 priority\n", __func__
, n_IRQ
);
359 if (test_bit(&src
->ipvp
, IPVP_ACTIVITY
)) {
360 /* IRQ already active */
361 DPRINTF("%s: IRQ %d is already active\n", __func__
, n_IRQ
);
364 if (src
->ide
== 0x00000000) {
366 DPRINTF("%s: IRQ %d has no target\n", __func__
, n_IRQ
);
370 if (src
->ide
== (1 << src
->last_cpu
)) {
371 /* Only one CPU is allowed to receive this IRQ */
372 IRQ_local_pipe(opp
, src
->last_cpu
, n_IRQ
);
373 } else if (!test_bit(&src
->ipvp
, IPVP_MODE
)) {
374 /* Directed delivery mode */
375 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
376 if (test_bit(&src
->ide
, i
))
377 IRQ_local_pipe(opp
, i
, n_IRQ
);
380 /* Distributed delivery mode */
381 for (i
= src
->last_cpu
+ 1; i
!= src
->last_cpu
; i
++) {
382 if (i
== opp
->nb_cpus
)
384 if (test_bit(&src
->ide
, i
)) {
385 IRQ_local_pipe(opp
, i
, n_IRQ
);
393 static void openpic_set_irq(void *opaque
, int n_IRQ
, int level
)
395 openpic_t
*opp
= opaque
;
398 src
= &opp
->src
[n_IRQ
];
399 DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
400 n_IRQ
, level
, src
->ipvp
);
401 if (test_bit(&src
->ipvp
, IPVP_SENSE
)) {
402 /* level-sensitive irq */
403 src
->pending
= level
;
405 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
407 /* edge-sensitive irq */
411 openpic_update_irq(opp
, n_IRQ
);
414 static void openpic_reset (void *opaque
)
416 openpic_t
*opp
= (openpic_t
*)opaque
;
419 opp
->glbc
= 0x80000000;
420 /* Initialise controller registers */
421 opp
->frep
= ((OPENPIC_EXT_IRQ
- 1) << 16) | ((MAX_CPU
- 1) << 8) | VID
;
423 opp
->pint
= 0x00000000;
424 opp
->spve
= 0x000000FF;
425 opp
->tifr
= 0x003F7A00;
427 opp
->micr
= 0x00000000;
428 /* Initialise IRQ sources */
429 for (i
= 0; i
< opp
->max_irq
; i
++) {
430 opp
->src
[i
].ipvp
= 0xA0000000;
431 opp
->src
[i
].ide
= 0x00000000;
433 /* Initialise IRQ destinations */
434 for (i
= 0; i
< MAX_CPU
; i
++) {
435 opp
->dst
[i
].pctp
= 0x0000000F;
436 opp
->dst
[i
].pcsr
= 0x00000000;
437 memset(&opp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
438 opp
->dst
[i
].raised
.next
= -1;
439 memset(&opp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
440 opp
->dst
[i
].servicing
.next
= -1;
442 /* Initialise timers */
443 for (i
= 0; i
< MAX_TMR
; i
++) {
444 opp
->timers
[i
].ticc
= 0x00000000;
445 opp
->timers
[i
].tibc
= 0x80000000;
447 /* Initialise doorbells */
449 opp
->dar
= 0x00000000;
450 for (i
= 0; i
< MAX_DBL
; i
++) {
451 opp
->doorbells
[i
].dmr
= 0x00000000;
454 /* Initialise mailboxes */
456 for (i
= 0; i
< MAX_MBX
; i
++) { /* ? */
457 opp
->mailboxes
[i
].mbr
= 0x00000000;
460 /* Go out of RESET state */
461 opp
->glbc
= 0x00000000;
464 static inline uint32_t read_IRQreg (openpic_t
*opp
, int n_IRQ
, uint32_t reg
)
470 retval
= opp
->src
[n_IRQ
].ipvp
;
473 retval
= opp
->src
[n_IRQ
].ide
;
480 static inline void write_IRQreg (openpic_t
*opp
, int n_IRQ
,
481 uint32_t reg
, uint32_t val
)
487 /* NOTE: not fully accurate for special IRQs, but simple and
489 /* ACTIVITY bit is read-only */
490 opp
->src
[n_IRQ
].ipvp
=
491 (opp
->src
[n_IRQ
].ipvp
& 0x40000000) |
493 openpic_update_irq(opp
, n_IRQ
);
494 DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n",
495 n_IRQ
, val
, opp
->src
[n_IRQ
].ipvp
);
498 tmp
= val
& 0xC0000000;
499 tmp
|= val
& ((1 << MAX_CPU
) - 1);
500 opp
->src
[n_IRQ
].ide
= tmp
;
501 DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ
, opp
->src
[n_IRQ
].ide
);
506 #if 0 // Code provision for Intel model
508 static uint32_t read_doorbell_register (openpic_t
*opp
,
509 int n_dbl
, uint32_t offset
)
514 case DBL_IPVP_OFFSET
:
515 retval
= read_IRQreg(opp
, IRQ_DBL0
+ n_dbl
, IRQ_IPVP
);
518 retval
= read_IRQreg(opp
, IRQ_DBL0
+ n_dbl
, IRQ_IDE
);
521 retval
= opp
->doorbells
[n_dbl
].dmr
;
528 static void write_doorbell_register (penpic_t
*opp
, int n_dbl
,
529 uint32_t offset
, uint32_t value
)
532 case DBL_IVPR_OFFSET
:
533 write_IRQreg(opp
, IRQ_DBL0
+ n_dbl
, IRQ_IPVP
, value
);
536 write_IRQreg(opp
, IRQ_DBL0
+ n_dbl
, IRQ_IDE
, value
);
539 opp
->doorbells
[n_dbl
].dmr
= value
;
546 static uint32_t read_mailbox_register (openpic_t
*opp
,
547 int n_mbx
, uint32_t offset
)
553 retval
= opp
->mailboxes
[n_mbx
].mbr
;
555 case MBX_IVPR_OFFSET
:
556 retval
= read_IRQreg(opp
, IRQ_MBX0
+ n_mbx
, IRQ_IPVP
);
559 retval
= read_IRQreg(opp
, IRQ_MBX0
+ n_mbx
, IRQ_IDE
);
566 static void write_mailbox_register (openpic_t
*opp
, int n_mbx
,
567 uint32_t address
, uint32_t value
)
571 opp
->mailboxes
[n_mbx
].mbr
= value
;
573 case MBX_IVPR_OFFSET
:
574 write_IRQreg(opp
, IRQ_MBX0
+ n_mbx
, IRQ_IPVP
, value
);
577 write_IRQreg(opp
, IRQ_MBX0
+ n_mbx
, IRQ_IDE
, value
);
582 #endif /* 0 : Code provision for Intel model */
584 static void openpic_gbl_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
586 openpic_t
*opp
= opaque
;
590 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
595 case 0x00: /* FREP */
597 case 0x20: /* GLBC */
598 if (val
& 0x80000000 && opp
->reset
)
600 opp
->glbc
= val
& ~0x80000000;
602 case 0x80: /* VENI */
604 case 0x90: /* PINT */
605 for (idx
= 0; idx
< opp
->nb_cpus
; idx
++) {
606 if ((val
& (1 << idx
)) && !(opp
->pint
& (1 << idx
))) {
607 DPRINTF("Raise OpenPIC RESET output for CPU %d\n", idx
);
608 dst
= &opp
->dst
[idx
];
609 qemu_irq_raise(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
610 } else if (!(val
& (1 << idx
)) && (opp
->pint
& (1 << idx
))) {
611 DPRINTF("Lower OpenPIC RESET output for CPU %d\n", idx
);
612 dst
= &opp
->dst
[idx
];
613 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
619 case 0xA0: /* IPI_IPVP */
625 idx
= (addr
- 0xA0) >> 4;
626 write_IRQreg(opp
, opp
->irq_ipi0
+ idx
, IRQ_IPVP
, val
);
630 case 0xE0: /* SPVE */
631 opp
->spve
= val
& 0x000000FF;
633 case 0xF0: /* TIFR */
641 static uint32_t openpic_gbl_read (void *opaque
, target_phys_addr_t addr
)
643 openpic_t
*opp
= opaque
;
646 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
652 case 0x00: /* FREP */
655 case 0x20: /* GLBC */
658 case 0x80: /* VENI */
661 case 0x90: /* PINT */
665 case 0xA0: /* IPI_IPVP */
671 idx
= (addr
- 0xA0) >> 4;
672 retval
= read_IRQreg(opp
, opp
->irq_ipi0
+ idx
, IRQ_IPVP
);
676 case 0xE0: /* SPVE */
679 case 0xF0: /* TIFR */
685 DPRINTF("%s: => %08x\n", __func__
, retval
);
690 static void openpic_timer_write (void *opaque
, uint32_t addr
, uint32_t val
)
692 openpic_t
*opp
= opaque
;
695 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
700 idx
= (addr
& 0xFFF0) >> 6;
703 case 0x00: /* TICC */
705 case 0x10: /* TIBC */
706 if ((opp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
707 (val
& 0x80000000) == 0 &&
708 (opp
->timers
[idx
].tibc
& 0x80000000) != 0)
709 opp
->timers
[idx
].ticc
&= ~0x80000000;
710 opp
->timers
[idx
].tibc
= val
;
712 case 0x20: /* TIVP */
713 write_IRQreg(opp
, opp
->irq_tim0
+ idx
, IRQ_IPVP
, val
);
715 case 0x30: /* TIDE */
716 write_IRQreg(opp
, opp
->irq_tim0
+ idx
, IRQ_IDE
, val
);
721 static uint32_t openpic_timer_read (void *opaque
, uint32_t addr
)
723 openpic_t
*opp
= opaque
;
727 DPRINTF("%s: addr %08x\n", __func__
, addr
);
733 idx
= (addr
& 0xFFF0) >> 6;
736 case 0x00: /* TICC */
737 retval
= opp
->timers
[idx
].ticc
;
739 case 0x10: /* TIBC */
740 retval
= opp
->timers
[idx
].tibc
;
742 case 0x20: /* TIPV */
743 retval
= read_IRQreg(opp
, opp
->irq_tim0
+ idx
, IRQ_IPVP
);
745 case 0x30: /* TIDE */
746 retval
= read_IRQreg(opp
, opp
->irq_tim0
+ idx
, IRQ_IDE
);
749 DPRINTF("%s: => %08x\n", __func__
, retval
);
754 static void openpic_src_write (void *opaque
, uint32_t addr
, uint32_t val
)
756 openpic_t
*opp
= opaque
;
759 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
762 addr
= addr
& 0xFFF0;
765 /* EXDE / IFEDE / IEEDE */
766 write_IRQreg(opp
, idx
, IRQ_IDE
, val
);
768 /* EXVP / IFEVP / IEEVP */
769 write_IRQreg(opp
, idx
, IRQ_IPVP
, val
);
773 static uint32_t openpic_src_read (void *opaque
, uint32_t addr
)
775 openpic_t
*opp
= opaque
;
779 DPRINTF("%s: addr %08x\n", __func__
, addr
);
783 addr
= addr
& 0xFFF0;
786 /* EXDE / IFEDE / IEEDE */
787 retval
= read_IRQreg(opp
, idx
, IRQ_IDE
);
789 /* EXVP / IFEVP / IEEVP */
790 retval
= read_IRQreg(opp
, idx
, IRQ_IPVP
);
792 DPRINTF("%s: => %08x\n", __func__
, retval
);
797 static void openpic_cpu_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
799 openpic_t
*opp
= opaque
;
802 int idx
, s_IRQ
, n_IRQ
;
804 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
809 dst
= &opp
->dst
[idx
];
813 case 0x40: /* PIPD */
817 idx
= (addr
- 0x40) >> 4;
818 write_IRQreg(opp
, opp
->irq_ipi0
+ idx
, IRQ_IDE
, val
);
819 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 1);
820 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 0);
823 case 0x80: /* PCTP */
824 dst
->pctp
= val
& 0x0000000F;
826 case 0x90: /* WHOAMI */
827 /* Read-only register */
829 case 0xA0: /* PIAC */
830 /* Read-only register */
832 case 0xB0: /* PEOI */
834 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
835 IRQ_resetbit(&dst
->servicing
, s_IRQ
);
836 dst
->servicing
.next
= -1;
837 /* Set up next servicing IRQ */
838 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
839 /* Check queued interrupts. */
840 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
841 src
= &opp
->src
[n_IRQ
];
844 IPVP_PRIORITY(src
->ipvp
) > dst
->servicing
.priority
)) {
845 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n",
847 opp
->irq_raise(opp
, idx
, src
);
855 static uint32_t openpic_cpu_read (void *opaque
, target_phys_addr_t addr
)
857 openpic_t
*opp
= opaque
;
863 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
869 dst
= &opp
->dst
[idx
];
872 case 0x80: /* PCTP */
875 case 0x90: /* WHOAMI */
878 case 0xA0: /* PIAC */
879 DPRINTF("Lower OpenPIC INT output\n");
880 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
881 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
882 DPRINTF("PIAC: irq=%d\n", n_IRQ
);
884 /* No more interrupt pending */
885 retval
= IPVP_VECTOR(opp
->spve
);
887 src
= &opp
->src
[n_IRQ
];
888 if (!test_bit(&src
->ipvp
, IPVP_ACTIVITY
) ||
889 !(IPVP_PRIORITY(src
->ipvp
) > dst
->pctp
)) {
890 /* - Spurious level-sensitive IRQ
891 * - Priorities has been changed
892 * and the pending IRQ isn't allowed anymore
894 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
895 retval
= IPVP_VECTOR(opp
->spve
);
897 /* IRQ enter servicing state */
898 IRQ_setbit(&dst
->servicing
, n_IRQ
);
899 retval
= IPVP_VECTOR(src
->ipvp
);
901 IRQ_resetbit(&dst
->raised
, n_IRQ
);
902 dst
->raised
.next
= -1;
903 if (!test_bit(&src
->ipvp
, IPVP_SENSE
)) {
904 /* edge-sensitive IRQ */
905 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
910 case 0xB0: /* PEOI */
916 idx
= (addr
- 0x40) >> 4;
917 retval
= read_IRQreg(opp
, opp
->irq_ipi0
+ idx
, IRQ_IDE
);
923 DPRINTF("%s: => %08x\n", __func__
, retval
);
928 static void openpic_buggy_write (void *opaque
,
929 target_phys_addr_t addr
, uint32_t val
)
931 printf("Invalid OPENPIC write access !\n");
934 static uint32_t openpic_buggy_read (void *opaque
, target_phys_addr_t addr
)
936 printf("Invalid OPENPIC read access !\n");
941 static void openpic_writel (void *opaque
,
942 target_phys_addr_t addr
, uint32_t val
)
944 openpic_t
*opp
= opaque
;
947 DPRINTF("%s: offset %08x val: %08x\n", __func__
, (int)addr
, val
);
949 /* Global registers */
950 openpic_gbl_write(opp
, addr
, val
);
951 } else if (addr
< 0x10000) {
952 /* Timers registers */
953 openpic_timer_write(opp
, addr
, val
);
954 } else if (addr
< 0x20000) {
955 /* Source registers */
956 openpic_src_write(opp
, addr
, val
);
959 openpic_cpu_write(opp
, addr
, val
);
963 static uint32_t openpic_readl (void *opaque
,target_phys_addr_t addr
)
965 openpic_t
*opp
= opaque
;
969 DPRINTF("%s: offset %08x\n", __func__
, (int)addr
);
971 /* Global registers */
972 retval
= openpic_gbl_read(opp
, addr
);
973 } else if (addr
< 0x10000) {
974 /* Timers registers */
975 retval
= openpic_timer_read(opp
, addr
);
976 } else if (addr
< 0x20000) {
977 /* Source registers */
978 retval
= openpic_src_read(opp
, addr
);
981 retval
= openpic_cpu_read(opp
, addr
);
987 static CPUWriteMemoryFunc
* const openpic_write
[] = {
988 &openpic_buggy_write
,
989 &openpic_buggy_write
,
993 static CPUReadMemoryFunc
* const openpic_read
[] = {
999 static void openpic_map(PCIDevice
*pci_dev
, int region_num
,
1000 pcibus_t addr
, pcibus_t size
, int type
)
1004 DPRINTF("Map OpenPIC\n");
1005 opp
= (openpic_t
*)pci_dev
;
1006 /* Global registers */
1007 DPRINTF("Register OPENPIC gbl %08x => %08x\n",
1008 addr
+ 0x1000, addr
+ 0x1000 + 0x100);
1009 /* Timer registers */
1010 DPRINTF("Register OPENPIC timer %08x => %08x\n",
1011 addr
+ 0x1100, addr
+ 0x1100 + 0x40 * MAX_TMR
);
1012 /* Interrupt source registers */
1013 DPRINTF("Register OPENPIC src %08x => %08x\n",
1014 addr
+ 0x10000, addr
+ 0x10000 + 0x20 * (OPENPIC_EXT_IRQ
+ 2));
1015 /* Per CPU registers */
1016 DPRINTF("Register OPENPIC dst %08x => %08x\n",
1017 addr
+ 0x20000, addr
+ 0x20000 + 0x1000 * MAX_CPU
);
1018 cpu_register_physical_memory(addr
, 0x40000, opp
->mem_index
);
1019 #if 0 // Don't implement ISU for now
1020 opp_io_memory
= cpu_register_io_memory(openpic_src_read
,
1021 openpic_src_write
, NULL
1022 DEVICE_NATIVE_ENDIAN
);
1023 cpu_register_physical_memory(isu_base
, 0x20 * (EXT_IRQ
+ 2),
1028 static void openpic_save_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1032 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1033 qemu_put_be32s(f
, &q
->queue
[i
]);
1035 qemu_put_sbe32s(f
, &q
->next
);
1036 qemu_put_sbe32s(f
, &q
->priority
);
1039 static void openpic_save(QEMUFile
* f
, void *opaque
)
1041 openpic_t
*opp
= (openpic_t
*)opaque
;
1044 qemu_put_be32s(f
, &opp
->frep
);
1045 qemu_put_be32s(f
, &opp
->glbc
);
1046 qemu_put_be32s(f
, &opp
->micr
);
1047 qemu_put_be32s(f
, &opp
->veni
);
1048 qemu_put_be32s(f
, &opp
->pint
);
1049 qemu_put_be32s(f
, &opp
->spve
);
1050 qemu_put_be32s(f
, &opp
->tifr
);
1052 for (i
= 0; i
< opp
->max_irq
; i
++) {
1053 qemu_put_be32s(f
, &opp
->src
[i
].ipvp
);
1054 qemu_put_be32s(f
, &opp
->src
[i
].ide
);
1055 qemu_put_sbe32s(f
, &opp
->src
[i
].type
);
1056 qemu_put_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1057 qemu_put_sbe32s(f
, &opp
->src
[i
].pending
);
1060 qemu_put_sbe32s(f
, &opp
->nb_cpus
);
1062 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1063 qemu_put_be32s(f
, &opp
->dst
[i
].tfrr
);
1064 qemu_put_be32s(f
, &opp
->dst
[i
].pctp
);
1065 qemu_put_be32s(f
, &opp
->dst
[i
].pcsr
);
1066 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1067 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1070 for (i
= 0; i
< MAX_TMR
; i
++) {
1071 qemu_put_be32s(f
, &opp
->timers
[i
].ticc
);
1072 qemu_put_be32s(f
, &opp
->timers
[i
].tibc
);
1076 qemu_put_be32s(f
, &opp
->dar
);
1078 for (i
= 0; i
< MAX_DBL
; i
++) {
1079 qemu_put_be32s(f
, &opp
->doorbells
[i
].dmr
);
1084 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1085 qemu_put_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1089 pci_device_save(&opp
->pci_dev
, f
);
1092 static void openpic_load_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1096 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1097 qemu_get_be32s(f
, &q
->queue
[i
]);
1099 qemu_get_sbe32s(f
, &q
->next
);
1100 qemu_get_sbe32s(f
, &q
->priority
);
1103 static int openpic_load(QEMUFile
* f
, void *opaque
, int version_id
)
1105 openpic_t
*opp
= (openpic_t
*)opaque
;
1108 if (version_id
!= 1)
1111 qemu_get_be32s(f
, &opp
->frep
);
1112 qemu_get_be32s(f
, &opp
->glbc
);
1113 qemu_get_be32s(f
, &opp
->micr
);
1114 qemu_get_be32s(f
, &opp
->veni
);
1115 qemu_get_be32s(f
, &opp
->pint
);
1116 qemu_get_be32s(f
, &opp
->spve
);
1117 qemu_get_be32s(f
, &opp
->tifr
);
1119 for (i
= 0; i
< opp
->max_irq
; i
++) {
1120 qemu_get_be32s(f
, &opp
->src
[i
].ipvp
);
1121 qemu_get_be32s(f
, &opp
->src
[i
].ide
);
1122 qemu_get_sbe32s(f
, &opp
->src
[i
].type
);
1123 qemu_get_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1124 qemu_get_sbe32s(f
, &opp
->src
[i
].pending
);
1127 qemu_get_sbe32s(f
, &opp
->nb_cpus
);
1129 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1130 qemu_get_be32s(f
, &opp
->dst
[i
].tfrr
);
1131 qemu_get_be32s(f
, &opp
->dst
[i
].pctp
);
1132 qemu_get_be32s(f
, &opp
->dst
[i
].pcsr
);
1133 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1134 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1137 for (i
= 0; i
< MAX_TMR
; i
++) {
1138 qemu_get_be32s(f
, &opp
->timers
[i
].ticc
);
1139 qemu_get_be32s(f
, &opp
->timers
[i
].tibc
);
1143 qemu_get_be32s(f
, &opp
->dar
);
1145 for (i
= 0; i
< MAX_DBL
; i
++) {
1146 qemu_get_be32s(f
, &opp
->doorbells
[i
].dmr
);
1151 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1152 qemu_get_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1156 return pci_device_load(&opp
->pci_dev
, f
);
1159 static void openpic_irq_raise(openpic_t
*opp
, int n_CPU
, IRQ_src_t
*src
)
1161 qemu_irq_raise(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1164 qemu_irq
*openpic_init (PCIBus
*bus
, int *pmem_index
, int nb_cpus
,
1165 qemu_irq
**irqs
, qemu_irq irq_out
)
1171 /* XXX: for now, only one CPU is supported */
1175 opp
= (openpic_t
*)pci_register_device(bus
, "OpenPIC", sizeof(openpic_t
),
1177 pci_conf
= opp
->pci_dev
.config
;
1178 pci_config_set_vendor_id(pci_conf
, PCI_VENDOR_ID_IBM
);
1179 pci_config_set_device_id(pci_conf
, PCI_DEVICE_ID_IBM_OPENPIC2
);
1180 pci_config_set_class(pci_conf
, PCI_CLASS_SYSTEM_OTHER
); // FIXME?
1181 pci_conf
[0x3d] = 0x00; // no interrupt pin
1183 /* Register I/O spaces */
1184 pci_register_bar(&opp
->pci_dev
, 0, 0x40000,
1185 PCI_BASE_ADDRESS_SPACE_MEMORY
, &openpic_map
);
1187 opp
= qemu_mallocz(sizeof(openpic_t
));
1189 opp
->mem_index
= cpu_register_io_memory(openpic_read
, openpic_write
, opp
,
1190 DEVICE_LITTLE_ENDIAN
);
1192 // isu_base &= 0xFFFC0000;
1193 opp
->nb_cpus
= nb_cpus
;
1194 opp
->max_irq
= OPENPIC_MAX_IRQ
;
1195 opp
->irq_ipi0
= OPENPIC_IRQ_IPI0
;
1196 opp
->irq_tim0
= OPENPIC_IRQ_TIM0
;
1198 for (i
= 0; i
< OPENPIC_EXT_IRQ
; i
++) {
1199 opp
->src
[i
].type
= IRQ_EXTERNAL
;
1201 for (; i
< OPENPIC_IRQ_TIM0
; i
++) {
1202 opp
->src
[i
].type
= IRQ_SPECIAL
;
1205 m
= OPENPIC_IRQ_IPI0
;
1207 m
= OPENPIC_IRQ_DBL0
;
1209 for (; i
< m
; i
++) {
1210 opp
->src
[i
].type
= IRQ_TIMER
;
1212 for (; i
< OPENPIC_MAX_IRQ
; i
++) {
1213 opp
->src
[i
].type
= IRQ_INTERNAL
;
1215 for (i
= 0; i
< nb_cpus
; i
++)
1216 opp
->dst
[i
].irqs
= irqs
[i
];
1217 opp
->irq_out
= irq_out
;
1219 register_savevm(&opp
->pci_dev
.qdev
, "openpic", 0, 2,
1220 openpic_save
, openpic_load
, opp
);
1221 qemu_register_reset(openpic_reset
, opp
);
1223 opp
->irq_raise
= openpic_irq_raise
;
1224 opp
->reset
= openpic_reset
;
1227 *pmem_index
= opp
->mem_index
;
1229 return qemu_allocate_irqs(openpic_set_irq
, opp
, opp
->max_irq
);
1232 static void mpic_irq_raise(openpic_t
*mpp
, int n_CPU
, IRQ_src_t
*src
)
1234 int n_ci
= IDR_CI0
- n_CPU
;
1236 if(test_bit(&src
->ide
, n_ci
)) {
1237 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_CINT
]);
1240 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1244 static void mpic_reset (void *opaque
)
1246 openpic_t
*mpp
= (openpic_t
*)opaque
;
1249 mpp
->glbc
= 0x80000000;
1250 /* Initialise controller registers */
1251 mpp
->frep
= 0x004f0002;
1253 mpp
->pint
= 0x00000000;
1254 mpp
->spve
= 0x0000FFFF;
1255 /* Initialise IRQ sources */
1256 for (i
= 0; i
< mpp
->max_irq
; i
++) {
1257 mpp
->src
[i
].ipvp
= 0x80800000;
1258 mpp
->src
[i
].ide
= 0x00000001;
1260 /* Initialise IRQ destinations */
1261 for (i
= 0; i
< MAX_CPU
; i
++) {
1262 mpp
->dst
[i
].pctp
= 0x0000000F;
1263 mpp
->dst
[i
].tfrr
= 0x00000000;
1264 memset(&mpp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
1265 mpp
->dst
[i
].raised
.next
= -1;
1266 memset(&mpp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
1267 mpp
->dst
[i
].servicing
.next
= -1;
1269 /* Initialise timers */
1270 for (i
= 0; i
< MAX_TMR
; i
++) {
1271 mpp
->timers
[i
].ticc
= 0x00000000;
1272 mpp
->timers
[i
].tibc
= 0x80000000;
1274 /* Go out of RESET state */
1275 mpp
->glbc
= 0x00000000;
1278 static void mpic_timer_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
1280 openpic_t
*mpp
= opaque
;
1283 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1288 idx
= (addr
>> 6) & 0x3;
1289 switch (addr
& 0x30) {
1290 case 0x00: /* gtccr */
1292 case 0x10: /* gtbcr */
1293 if ((mpp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
1294 (val
& 0x80000000) == 0 &&
1295 (mpp
->timers
[idx
].tibc
& 0x80000000) != 0)
1296 mpp
->timers
[idx
].ticc
&= ~0x80000000;
1297 mpp
->timers
[idx
].tibc
= val
;
1299 case 0x20: /* GTIVPR */
1300 write_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IPVP
, val
);
1302 case 0x30: /* GTIDR & TFRR */
1303 if ((addr
& 0xF0) == 0xF0)
1304 mpp
->dst
[cpu
].tfrr
= val
;
1306 write_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IDE
, val
);
1311 static uint32_t mpic_timer_read (void *opaque
, target_phys_addr_t addr
)
1313 openpic_t
*mpp
= opaque
;
1317 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1318 retval
= 0xFFFFFFFF;
1323 idx
= (addr
>> 6) & 0x3;
1324 switch (addr
& 0x30) {
1325 case 0x00: /* gtccr */
1326 retval
= mpp
->timers
[idx
].ticc
;
1328 case 0x10: /* gtbcr */
1329 retval
= mpp
->timers
[idx
].tibc
;
1331 case 0x20: /* TIPV */
1332 retval
= read_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IPVP
);
1334 case 0x30: /* TIDR */
1335 if ((addr
&0xF0) == 0XF0)
1336 retval
= mpp
->dst
[cpu
].tfrr
;
1338 retval
= read_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IDE
);
1341 DPRINTF("%s: => %08x\n", __func__
, retval
);
1346 static void mpic_src_ext_write (void *opaque
, target_phys_addr_t addr
,
1349 openpic_t
*mpp
= opaque
;
1350 int idx
= MPIC_EXT_IRQ
;
1352 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1356 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1357 if (addr
< MPIC_EXT_REG_SIZE
) {
1358 idx
+= (addr
& 0xFFF0) >> 5;
1360 /* EXDE / IFEDE / IEEDE */
1361 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1363 /* EXVP / IFEVP / IEEVP */
1364 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1369 static uint32_t mpic_src_ext_read (void *opaque
, target_phys_addr_t addr
)
1371 openpic_t
*mpp
= opaque
;
1373 int idx
= MPIC_EXT_IRQ
;
1375 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1376 retval
= 0xFFFFFFFF;
1380 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1381 if (addr
< MPIC_EXT_REG_SIZE
) {
1382 idx
+= (addr
& 0xFFF0) >> 5;
1384 /* EXDE / IFEDE / IEEDE */
1385 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1387 /* EXVP / IFEVP / IEEVP */
1388 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1390 DPRINTF("%s: => %08x\n", __func__
, retval
);
1396 static void mpic_src_int_write (void *opaque
, target_phys_addr_t addr
,
1399 openpic_t
*mpp
= opaque
;
1400 int idx
= MPIC_INT_IRQ
;
1402 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1406 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1407 if (addr
< MPIC_INT_REG_SIZE
) {
1408 idx
+= (addr
& 0xFFF0) >> 5;
1410 /* EXDE / IFEDE / IEEDE */
1411 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1413 /* EXVP / IFEVP / IEEVP */
1414 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1419 static uint32_t mpic_src_int_read (void *opaque
, target_phys_addr_t addr
)
1421 openpic_t
*mpp
= opaque
;
1423 int idx
= MPIC_INT_IRQ
;
1425 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1426 retval
= 0xFFFFFFFF;
1430 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1431 if (addr
< MPIC_INT_REG_SIZE
) {
1432 idx
+= (addr
& 0xFFF0) >> 5;
1434 /* EXDE / IFEDE / IEEDE */
1435 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1437 /* EXVP / IFEVP / IEEVP */
1438 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1440 DPRINTF("%s: => %08x\n", __func__
, retval
);
1446 static void mpic_src_msg_write (void *opaque
, target_phys_addr_t addr
,
1449 openpic_t
*mpp
= opaque
;
1450 int idx
= MPIC_MSG_IRQ
;
1452 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1456 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1457 if (addr
< MPIC_MSG_REG_SIZE
) {
1458 idx
+= (addr
& 0xFFF0) >> 5;
1460 /* EXDE / IFEDE / IEEDE */
1461 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1463 /* EXVP / IFEVP / IEEVP */
1464 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1469 static uint32_t mpic_src_msg_read (void *opaque
, target_phys_addr_t addr
)
1471 openpic_t
*mpp
= opaque
;
1473 int idx
= MPIC_MSG_IRQ
;
1475 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1476 retval
= 0xFFFFFFFF;
1480 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1481 if (addr
< MPIC_MSG_REG_SIZE
) {
1482 idx
+= (addr
& 0xFFF0) >> 5;
1484 /* EXDE / IFEDE / IEEDE */
1485 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1487 /* EXVP / IFEVP / IEEVP */
1488 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1490 DPRINTF("%s: => %08x\n", __func__
, retval
);
1496 static void mpic_src_msi_write (void *opaque
, target_phys_addr_t addr
,
1499 openpic_t
*mpp
= opaque
;
1500 int idx
= MPIC_MSI_IRQ
;
1502 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1506 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1507 if (addr
< MPIC_MSI_REG_SIZE
) {
1508 idx
+= (addr
& 0xFFF0) >> 5;
1510 /* EXDE / IFEDE / IEEDE */
1511 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1513 /* EXVP / IFEVP / IEEVP */
1514 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1518 static uint32_t mpic_src_msi_read (void *opaque
, target_phys_addr_t addr
)
1520 openpic_t
*mpp
= opaque
;
1522 int idx
= MPIC_MSI_IRQ
;
1524 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1525 retval
= 0xFFFFFFFF;
1529 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1530 if (addr
< MPIC_MSI_REG_SIZE
) {
1531 idx
+= (addr
& 0xFFF0) >> 5;
1533 /* EXDE / IFEDE / IEEDE */
1534 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1536 /* EXVP / IFEVP / IEEVP */
1537 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1539 DPRINTF("%s: => %08x\n", __func__
, retval
);
1545 static CPUWriteMemoryFunc
* const mpic_glb_write
[] = {
1546 &openpic_buggy_write
,
1547 &openpic_buggy_write
,
1551 static CPUReadMemoryFunc
* const mpic_glb_read
[] = {
1552 &openpic_buggy_read
,
1553 &openpic_buggy_read
,
1557 static CPUWriteMemoryFunc
* const mpic_tmr_write
[] = {
1558 &openpic_buggy_write
,
1559 &openpic_buggy_write
,
1563 static CPUReadMemoryFunc
* const mpic_tmr_read
[] = {
1564 &openpic_buggy_read
,
1565 &openpic_buggy_read
,
1569 static CPUWriteMemoryFunc
* const mpic_cpu_write
[] = {
1570 &openpic_buggy_write
,
1571 &openpic_buggy_write
,
1575 static CPUReadMemoryFunc
* const mpic_cpu_read
[] = {
1576 &openpic_buggy_read
,
1577 &openpic_buggy_read
,
1581 static CPUWriteMemoryFunc
* const mpic_ext_write
[] = {
1582 &openpic_buggy_write
,
1583 &openpic_buggy_write
,
1584 &mpic_src_ext_write
,
1587 static CPUReadMemoryFunc
* const mpic_ext_read
[] = {
1588 &openpic_buggy_read
,
1589 &openpic_buggy_read
,
1593 static CPUWriteMemoryFunc
* const mpic_int_write
[] = {
1594 &openpic_buggy_write
,
1595 &openpic_buggy_write
,
1596 &mpic_src_int_write
,
1599 static CPUReadMemoryFunc
* const mpic_int_read
[] = {
1600 &openpic_buggy_read
,
1601 &openpic_buggy_read
,
1605 static CPUWriteMemoryFunc
* const mpic_msg_write
[] = {
1606 &openpic_buggy_write
,
1607 &openpic_buggy_write
,
1608 &mpic_src_msg_write
,
1611 static CPUReadMemoryFunc
* const mpic_msg_read
[] = {
1612 &openpic_buggy_read
,
1613 &openpic_buggy_read
,
1616 static CPUWriteMemoryFunc
* const mpic_msi_write
[] = {
1617 &openpic_buggy_write
,
1618 &openpic_buggy_write
,
1619 &mpic_src_msi_write
,
1622 static CPUReadMemoryFunc
* const mpic_msi_read
[] = {
1623 &openpic_buggy_read
,
1624 &openpic_buggy_read
,
1628 qemu_irq
*mpic_init (target_phys_addr_t base
, int nb_cpus
,
1629 qemu_irq
**irqs
, qemu_irq irq_out
)
1634 CPUReadMemoryFunc
* const *read
;
1635 CPUWriteMemoryFunc
* const *write
;
1636 target_phys_addr_t start_addr
;
1639 {mpic_glb_read
, mpic_glb_write
, MPIC_GLB_REG_START
, MPIC_GLB_REG_SIZE
},
1640 {mpic_tmr_read
, mpic_tmr_write
, MPIC_TMR_REG_START
, MPIC_TMR_REG_SIZE
},
1641 {mpic_ext_read
, mpic_ext_write
, MPIC_EXT_REG_START
, MPIC_EXT_REG_SIZE
},
1642 {mpic_int_read
, mpic_int_write
, MPIC_INT_REG_START
, MPIC_INT_REG_SIZE
},
1643 {mpic_msg_read
, mpic_msg_write
, MPIC_MSG_REG_START
, MPIC_MSG_REG_SIZE
},
1644 {mpic_msi_read
, mpic_msi_write
, MPIC_MSI_REG_START
, MPIC_MSI_REG_SIZE
},
1645 {mpic_cpu_read
, mpic_cpu_write
, MPIC_CPU_REG_START
, MPIC_CPU_REG_SIZE
},
1648 /* XXX: for now, only one CPU is supported */
1652 mpp
= qemu_mallocz(sizeof(openpic_t
));
1654 for (i
= 0; i
< sizeof(list
)/sizeof(list
[0]); i
++) {
1657 mem_index
= cpu_register_io_memory(list
[i
].read
, list
[i
].write
, mpp
,
1659 if (mem_index
< 0) {
1662 cpu_register_physical_memory(base
+ list
[i
].start_addr
,
1663 list
[i
].size
, mem_index
);
1666 mpp
->nb_cpus
= nb_cpus
;
1667 mpp
->max_irq
= MPIC_MAX_IRQ
;
1668 mpp
->irq_ipi0
= MPIC_IPI_IRQ
;
1669 mpp
->irq_tim0
= MPIC_TMR_IRQ
;
1671 for (i
= 0; i
< nb_cpus
; i
++)
1672 mpp
->dst
[i
].irqs
= irqs
[i
];
1673 mpp
->irq_out
= irq_out
;
1675 mpp
->irq_raise
= mpic_irq_raise
;
1676 mpp
->reset
= mpic_reset
;
1678 register_savevm(NULL
, "mpic", 0, 2, openpic_save
, openpic_load
, mpp
);
1679 qemu_register_reset(mpic_reset
, mpp
);
1681 return qemu_allocate_irqs(openpic_set_irq
, mpp
, mpp
->max_irq
);