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 uint64_t openpic_read(void *opaque
, target_phys_addr_t addr
,
990 openpic_t
*opp
= opaque
;
993 case 4: return openpic_readl(opp
, addr
);
994 default: return openpic_buggy_read(opp
, addr
);
998 static void openpic_write(void *opaque
, target_phys_addr_t addr
,
999 uint64_t data
, unsigned size
)
1001 openpic_t
*opp
= opaque
;
1004 case 4: return openpic_writel(opp
, addr
, data
);
1005 default: return openpic_buggy_write(opp
, addr
, data
);
1009 static const MemoryRegionOps openpic_ops
= {
1010 .read
= openpic_read
,
1011 .write
= openpic_write
,
1012 .endianness
= DEVICE_LITTLE_ENDIAN
,
1015 static void openpic_save_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1019 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1020 qemu_put_be32s(f
, &q
->queue
[i
]);
1022 qemu_put_sbe32s(f
, &q
->next
);
1023 qemu_put_sbe32s(f
, &q
->priority
);
1026 static void openpic_save(QEMUFile
* f
, void *opaque
)
1028 openpic_t
*opp
= (openpic_t
*)opaque
;
1031 qemu_put_be32s(f
, &opp
->frep
);
1032 qemu_put_be32s(f
, &opp
->glbc
);
1033 qemu_put_be32s(f
, &opp
->micr
);
1034 qemu_put_be32s(f
, &opp
->veni
);
1035 qemu_put_be32s(f
, &opp
->pint
);
1036 qemu_put_be32s(f
, &opp
->spve
);
1037 qemu_put_be32s(f
, &opp
->tifr
);
1039 for (i
= 0; i
< opp
->max_irq
; i
++) {
1040 qemu_put_be32s(f
, &opp
->src
[i
].ipvp
);
1041 qemu_put_be32s(f
, &opp
->src
[i
].ide
);
1042 qemu_put_sbe32s(f
, &opp
->src
[i
].type
);
1043 qemu_put_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1044 qemu_put_sbe32s(f
, &opp
->src
[i
].pending
);
1047 qemu_put_sbe32s(f
, &opp
->nb_cpus
);
1049 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1050 qemu_put_be32s(f
, &opp
->dst
[i
].tfrr
);
1051 qemu_put_be32s(f
, &opp
->dst
[i
].pctp
);
1052 qemu_put_be32s(f
, &opp
->dst
[i
].pcsr
);
1053 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1054 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1057 for (i
= 0; i
< MAX_TMR
; i
++) {
1058 qemu_put_be32s(f
, &opp
->timers
[i
].ticc
);
1059 qemu_put_be32s(f
, &opp
->timers
[i
].tibc
);
1063 qemu_put_be32s(f
, &opp
->dar
);
1065 for (i
= 0; i
< MAX_DBL
; i
++) {
1066 qemu_put_be32s(f
, &opp
->doorbells
[i
].dmr
);
1071 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1072 qemu_put_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1076 pci_device_save(&opp
->pci_dev
, f
);
1079 static void openpic_load_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1083 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1084 qemu_get_be32s(f
, &q
->queue
[i
]);
1086 qemu_get_sbe32s(f
, &q
->next
);
1087 qemu_get_sbe32s(f
, &q
->priority
);
1090 static int openpic_load(QEMUFile
* f
, void *opaque
, int version_id
)
1092 openpic_t
*opp
= (openpic_t
*)opaque
;
1095 if (version_id
!= 1)
1098 qemu_get_be32s(f
, &opp
->frep
);
1099 qemu_get_be32s(f
, &opp
->glbc
);
1100 qemu_get_be32s(f
, &opp
->micr
);
1101 qemu_get_be32s(f
, &opp
->veni
);
1102 qemu_get_be32s(f
, &opp
->pint
);
1103 qemu_get_be32s(f
, &opp
->spve
);
1104 qemu_get_be32s(f
, &opp
->tifr
);
1106 for (i
= 0; i
< opp
->max_irq
; i
++) {
1107 qemu_get_be32s(f
, &opp
->src
[i
].ipvp
);
1108 qemu_get_be32s(f
, &opp
->src
[i
].ide
);
1109 qemu_get_sbe32s(f
, &opp
->src
[i
].type
);
1110 qemu_get_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1111 qemu_get_sbe32s(f
, &opp
->src
[i
].pending
);
1114 qemu_get_sbe32s(f
, &opp
->nb_cpus
);
1116 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1117 qemu_get_be32s(f
, &opp
->dst
[i
].tfrr
);
1118 qemu_get_be32s(f
, &opp
->dst
[i
].pctp
);
1119 qemu_get_be32s(f
, &opp
->dst
[i
].pcsr
);
1120 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1121 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1124 for (i
= 0; i
< MAX_TMR
; i
++) {
1125 qemu_get_be32s(f
, &opp
->timers
[i
].ticc
);
1126 qemu_get_be32s(f
, &opp
->timers
[i
].tibc
);
1130 qemu_get_be32s(f
, &opp
->dar
);
1132 for (i
= 0; i
< MAX_DBL
; i
++) {
1133 qemu_get_be32s(f
, &opp
->doorbells
[i
].dmr
);
1138 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1139 qemu_get_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1143 return pci_device_load(&opp
->pci_dev
, f
);
1146 static void openpic_irq_raise(openpic_t
*opp
, int n_CPU
, IRQ_src_t
*src
)
1148 qemu_irq_raise(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1151 qemu_irq
*openpic_init (PCIBus
*bus
, MemoryRegion
**pmem
, int nb_cpus
,
1152 qemu_irq
**irqs
, qemu_irq irq_out
)
1158 /* XXX: for now, only one CPU is supported */
1162 opp
= (openpic_t
*)pci_register_device(bus
, "OpenPIC", sizeof(openpic_t
),
1164 pci_conf
= opp
->pci_dev
.config
;
1165 pci_config_set_vendor_id(pci_conf
, PCI_VENDOR_ID_IBM
);
1166 pci_config_set_device_id(pci_conf
, PCI_DEVICE_ID_IBM_OPENPIC2
);
1167 pci_config_set_class(pci_conf
, PCI_CLASS_SYSTEM_OTHER
); // FIXME?
1168 pci_conf
[0x3d] = 0x00; // no interrupt pin
1170 memory_region_init_io(&opp
->mem
, &openpic_ops
, opp
, "openpic", 0x40000);
1171 #if 0 // Don't implement ISU for now
1172 opp_io_memory
= cpu_register_io_memory(openpic_src_read
,
1173 openpic_src_write
, NULL
1174 DEVICE_NATIVE_ENDIAN
);
1175 cpu_register_physical_memory(isu_base
, 0x20 * (EXT_IRQ
+ 2),
1179 /* Register I/O spaces */
1180 pci_register_bar(&opp
->pci_dev
, 0,
1181 PCI_BASE_ADDRESS_SPACE_MEMORY
, &opp
->mem
);
1183 opp
= qemu_mallocz(sizeof(openpic_t
));
1184 memory_region_init_io(&opp
->mem
, &openpic_ops
, opp
, "openpic", 0x40000);
1187 // isu_base &= 0xFFFC0000;
1188 opp
->nb_cpus
= nb_cpus
;
1189 opp
->max_irq
= OPENPIC_MAX_IRQ
;
1190 opp
->irq_ipi0
= OPENPIC_IRQ_IPI0
;
1191 opp
->irq_tim0
= OPENPIC_IRQ_TIM0
;
1193 for (i
= 0; i
< OPENPIC_EXT_IRQ
; i
++) {
1194 opp
->src
[i
].type
= IRQ_EXTERNAL
;
1196 for (; i
< OPENPIC_IRQ_TIM0
; i
++) {
1197 opp
->src
[i
].type
= IRQ_SPECIAL
;
1200 m
= OPENPIC_IRQ_IPI0
;
1202 m
= OPENPIC_IRQ_DBL0
;
1204 for (; i
< m
; i
++) {
1205 opp
->src
[i
].type
= IRQ_TIMER
;
1207 for (; i
< OPENPIC_MAX_IRQ
; i
++) {
1208 opp
->src
[i
].type
= IRQ_INTERNAL
;
1210 for (i
= 0; i
< nb_cpus
; i
++)
1211 opp
->dst
[i
].irqs
= irqs
[i
];
1212 opp
->irq_out
= irq_out
;
1214 register_savevm(&opp
->pci_dev
.qdev
, "openpic", 0, 2,
1215 openpic_save
, openpic_load
, opp
);
1216 qemu_register_reset(openpic_reset
, opp
);
1218 opp
->irq_raise
= openpic_irq_raise
;
1219 opp
->reset
= openpic_reset
;
1224 return qemu_allocate_irqs(openpic_set_irq
, opp
, opp
->max_irq
);
1227 static void mpic_irq_raise(openpic_t
*mpp
, int n_CPU
, IRQ_src_t
*src
)
1229 int n_ci
= IDR_CI0
- n_CPU
;
1231 if(test_bit(&src
->ide
, n_ci
)) {
1232 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_CINT
]);
1235 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1239 static void mpic_reset (void *opaque
)
1241 openpic_t
*mpp
= (openpic_t
*)opaque
;
1244 mpp
->glbc
= 0x80000000;
1245 /* Initialise controller registers */
1246 mpp
->frep
= 0x004f0002;
1248 mpp
->pint
= 0x00000000;
1249 mpp
->spve
= 0x0000FFFF;
1250 /* Initialise IRQ sources */
1251 for (i
= 0; i
< mpp
->max_irq
; i
++) {
1252 mpp
->src
[i
].ipvp
= 0x80800000;
1253 mpp
->src
[i
].ide
= 0x00000001;
1255 /* Initialise IRQ destinations */
1256 for (i
= 0; i
< MAX_CPU
; i
++) {
1257 mpp
->dst
[i
].pctp
= 0x0000000F;
1258 mpp
->dst
[i
].tfrr
= 0x00000000;
1259 memset(&mpp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
1260 mpp
->dst
[i
].raised
.next
= -1;
1261 memset(&mpp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
1262 mpp
->dst
[i
].servicing
.next
= -1;
1264 /* Initialise timers */
1265 for (i
= 0; i
< MAX_TMR
; i
++) {
1266 mpp
->timers
[i
].ticc
= 0x00000000;
1267 mpp
->timers
[i
].tibc
= 0x80000000;
1269 /* Go out of RESET state */
1270 mpp
->glbc
= 0x00000000;
1273 static void mpic_timer_write (void *opaque
, target_phys_addr_t addr
, uint32_t val
)
1275 openpic_t
*mpp
= opaque
;
1278 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1283 idx
= (addr
>> 6) & 0x3;
1284 switch (addr
& 0x30) {
1285 case 0x00: /* gtccr */
1287 case 0x10: /* gtbcr */
1288 if ((mpp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
1289 (val
& 0x80000000) == 0 &&
1290 (mpp
->timers
[idx
].tibc
& 0x80000000) != 0)
1291 mpp
->timers
[idx
].ticc
&= ~0x80000000;
1292 mpp
->timers
[idx
].tibc
= val
;
1294 case 0x20: /* GTIVPR */
1295 write_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IPVP
, val
);
1297 case 0x30: /* GTIDR & TFRR */
1298 if ((addr
& 0xF0) == 0xF0)
1299 mpp
->dst
[cpu
].tfrr
= val
;
1301 write_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IDE
, val
);
1306 static uint32_t mpic_timer_read (void *opaque
, target_phys_addr_t addr
)
1308 openpic_t
*mpp
= opaque
;
1312 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1313 retval
= 0xFFFFFFFF;
1318 idx
= (addr
>> 6) & 0x3;
1319 switch (addr
& 0x30) {
1320 case 0x00: /* gtccr */
1321 retval
= mpp
->timers
[idx
].ticc
;
1323 case 0x10: /* gtbcr */
1324 retval
= mpp
->timers
[idx
].tibc
;
1326 case 0x20: /* TIPV */
1327 retval
= read_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IPVP
);
1329 case 0x30: /* TIDR */
1330 if ((addr
&0xF0) == 0XF0)
1331 retval
= mpp
->dst
[cpu
].tfrr
;
1333 retval
= read_IRQreg(mpp
, MPIC_TMR_IRQ
+ idx
, IRQ_IDE
);
1336 DPRINTF("%s: => %08x\n", __func__
, retval
);
1341 static void mpic_src_ext_write (void *opaque
, target_phys_addr_t addr
,
1344 openpic_t
*mpp
= opaque
;
1345 int idx
= MPIC_EXT_IRQ
;
1347 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1351 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1352 if (addr
< MPIC_EXT_REG_SIZE
) {
1353 idx
+= (addr
& 0xFFF0) >> 5;
1355 /* EXDE / IFEDE / IEEDE */
1356 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1358 /* EXVP / IFEVP / IEEVP */
1359 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1364 static uint32_t mpic_src_ext_read (void *opaque
, target_phys_addr_t addr
)
1366 openpic_t
*mpp
= opaque
;
1368 int idx
= MPIC_EXT_IRQ
;
1370 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1371 retval
= 0xFFFFFFFF;
1375 addr
-= MPIC_EXT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1376 if (addr
< MPIC_EXT_REG_SIZE
) {
1377 idx
+= (addr
& 0xFFF0) >> 5;
1379 /* EXDE / IFEDE / IEEDE */
1380 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1382 /* EXVP / IFEVP / IEEVP */
1383 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1385 DPRINTF("%s: => %08x\n", __func__
, retval
);
1391 static void mpic_src_int_write (void *opaque
, target_phys_addr_t addr
,
1394 openpic_t
*mpp
= opaque
;
1395 int idx
= MPIC_INT_IRQ
;
1397 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1401 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1402 if (addr
< MPIC_INT_REG_SIZE
) {
1403 idx
+= (addr
& 0xFFF0) >> 5;
1405 /* EXDE / IFEDE / IEEDE */
1406 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1408 /* EXVP / IFEVP / IEEVP */
1409 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1414 static uint32_t mpic_src_int_read (void *opaque
, target_phys_addr_t addr
)
1416 openpic_t
*mpp
= opaque
;
1418 int idx
= MPIC_INT_IRQ
;
1420 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1421 retval
= 0xFFFFFFFF;
1425 addr
-= MPIC_INT_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1426 if (addr
< MPIC_INT_REG_SIZE
) {
1427 idx
+= (addr
& 0xFFF0) >> 5;
1429 /* EXDE / IFEDE / IEEDE */
1430 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1432 /* EXVP / IFEVP / IEEVP */
1433 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1435 DPRINTF("%s: => %08x\n", __func__
, retval
);
1441 static void mpic_src_msg_write (void *opaque
, target_phys_addr_t addr
,
1444 openpic_t
*mpp
= opaque
;
1445 int idx
= MPIC_MSG_IRQ
;
1447 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1451 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1452 if (addr
< MPIC_MSG_REG_SIZE
) {
1453 idx
+= (addr
& 0xFFF0) >> 5;
1455 /* EXDE / IFEDE / IEEDE */
1456 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1458 /* EXVP / IFEVP / IEEVP */
1459 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1464 static uint32_t mpic_src_msg_read (void *opaque
, target_phys_addr_t addr
)
1466 openpic_t
*mpp
= opaque
;
1468 int idx
= MPIC_MSG_IRQ
;
1470 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1471 retval
= 0xFFFFFFFF;
1475 addr
-= MPIC_MSG_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1476 if (addr
< MPIC_MSG_REG_SIZE
) {
1477 idx
+= (addr
& 0xFFF0) >> 5;
1479 /* EXDE / IFEDE / IEEDE */
1480 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1482 /* EXVP / IFEVP / IEEVP */
1483 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1485 DPRINTF("%s: => %08x\n", __func__
, retval
);
1491 static void mpic_src_msi_write (void *opaque
, target_phys_addr_t addr
,
1494 openpic_t
*mpp
= opaque
;
1495 int idx
= MPIC_MSI_IRQ
;
1497 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1501 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1502 if (addr
< MPIC_MSI_REG_SIZE
) {
1503 idx
+= (addr
& 0xFFF0) >> 5;
1505 /* EXDE / IFEDE / IEEDE */
1506 write_IRQreg(mpp
, idx
, IRQ_IDE
, val
);
1508 /* EXVP / IFEVP / IEEVP */
1509 write_IRQreg(mpp
, idx
, IRQ_IPVP
, val
);
1513 static uint32_t mpic_src_msi_read (void *opaque
, target_phys_addr_t addr
)
1515 openpic_t
*mpp
= opaque
;
1517 int idx
= MPIC_MSI_IRQ
;
1519 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1520 retval
= 0xFFFFFFFF;
1524 addr
-= MPIC_MSI_REG_START
& (OPENPIC_PAGE_SIZE
- 1);
1525 if (addr
< MPIC_MSI_REG_SIZE
) {
1526 idx
+= (addr
& 0xFFF0) >> 5;
1528 /* EXDE / IFEDE / IEEDE */
1529 retval
= read_IRQreg(mpp
, idx
, IRQ_IDE
);
1531 /* EXVP / IFEVP / IEEVP */
1532 retval
= read_IRQreg(mpp
, idx
, IRQ_IPVP
);
1534 DPRINTF("%s: => %08x\n", __func__
, retval
);
1540 static CPUWriteMemoryFunc
* const mpic_glb_write
[] = {
1541 &openpic_buggy_write
,
1542 &openpic_buggy_write
,
1546 static CPUReadMemoryFunc
* const mpic_glb_read
[] = {
1547 &openpic_buggy_read
,
1548 &openpic_buggy_read
,
1552 static CPUWriteMemoryFunc
* const mpic_tmr_write
[] = {
1553 &openpic_buggy_write
,
1554 &openpic_buggy_write
,
1558 static CPUReadMemoryFunc
* const mpic_tmr_read
[] = {
1559 &openpic_buggy_read
,
1560 &openpic_buggy_read
,
1564 static CPUWriteMemoryFunc
* const mpic_cpu_write
[] = {
1565 &openpic_buggy_write
,
1566 &openpic_buggy_write
,
1570 static CPUReadMemoryFunc
* const mpic_cpu_read
[] = {
1571 &openpic_buggy_read
,
1572 &openpic_buggy_read
,
1576 static CPUWriteMemoryFunc
* const mpic_ext_write
[] = {
1577 &openpic_buggy_write
,
1578 &openpic_buggy_write
,
1579 &mpic_src_ext_write
,
1582 static CPUReadMemoryFunc
* const mpic_ext_read
[] = {
1583 &openpic_buggy_read
,
1584 &openpic_buggy_read
,
1588 static CPUWriteMemoryFunc
* const mpic_int_write
[] = {
1589 &openpic_buggy_write
,
1590 &openpic_buggy_write
,
1591 &mpic_src_int_write
,
1594 static CPUReadMemoryFunc
* const mpic_int_read
[] = {
1595 &openpic_buggy_read
,
1596 &openpic_buggy_read
,
1600 static CPUWriteMemoryFunc
* const mpic_msg_write
[] = {
1601 &openpic_buggy_write
,
1602 &openpic_buggy_write
,
1603 &mpic_src_msg_write
,
1606 static CPUReadMemoryFunc
* const mpic_msg_read
[] = {
1607 &openpic_buggy_read
,
1608 &openpic_buggy_read
,
1611 static CPUWriteMemoryFunc
* const mpic_msi_write
[] = {
1612 &openpic_buggy_write
,
1613 &openpic_buggy_write
,
1614 &mpic_src_msi_write
,
1617 static CPUReadMemoryFunc
* const mpic_msi_read
[] = {
1618 &openpic_buggy_read
,
1619 &openpic_buggy_read
,
1623 qemu_irq
*mpic_init (target_phys_addr_t base
, int nb_cpus
,
1624 qemu_irq
**irqs
, qemu_irq irq_out
)
1629 CPUReadMemoryFunc
* const *read
;
1630 CPUWriteMemoryFunc
* const *write
;
1631 target_phys_addr_t start_addr
;
1634 {mpic_glb_read
, mpic_glb_write
, MPIC_GLB_REG_START
, MPIC_GLB_REG_SIZE
},
1635 {mpic_tmr_read
, mpic_tmr_write
, MPIC_TMR_REG_START
, MPIC_TMR_REG_SIZE
},
1636 {mpic_ext_read
, mpic_ext_write
, MPIC_EXT_REG_START
, MPIC_EXT_REG_SIZE
},
1637 {mpic_int_read
, mpic_int_write
, MPIC_INT_REG_START
, MPIC_INT_REG_SIZE
},
1638 {mpic_msg_read
, mpic_msg_write
, MPIC_MSG_REG_START
, MPIC_MSG_REG_SIZE
},
1639 {mpic_msi_read
, mpic_msi_write
, MPIC_MSI_REG_START
, MPIC_MSI_REG_SIZE
},
1640 {mpic_cpu_read
, mpic_cpu_write
, MPIC_CPU_REG_START
, MPIC_CPU_REG_SIZE
},
1643 /* XXX: for now, only one CPU is supported */
1647 mpp
= qemu_mallocz(sizeof(openpic_t
));
1649 for (i
= 0; i
< sizeof(list
)/sizeof(list
[0]); i
++) {
1652 mem_index
= cpu_register_io_memory(list
[i
].read
, list
[i
].write
, mpp
,
1654 if (mem_index
< 0) {
1657 cpu_register_physical_memory(base
+ list
[i
].start_addr
,
1658 list
[i
].size
, mem_index
);
1661 mpp
->nb_cpus
= nb_cpus
;
1662 mpp
->max_irq
= MPIC_MAX_IRQ
;
1663 mpp
->irq_ipi0
= MPIC_IPI_IRQ
;
1664 mpp
->irq_tim0
= MPIC_TMR_IRQ
;
1666 for (i
= 0; i
< nb_cpus
; i
++)
1667 mpp
->dst
[i
].irqs
= irqs
[i
];
1668 mpp
->irq_out
= irq_out
;
1670 mpp
->irq_raise
= mpic_irq_raise
;
1671 mpp
->reset
= mpic_reset
;
1673 register_savevm(NULL
, "mpic", 0, 2, openpic_save
, openpic_load
, mpp
);
1674 qemu_register_reset(mpic_reset
, mpp
);
1676 return qemu_allocate_irqs(openpic_set_irq
, mpp
, mpp
->max_irq
);