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)
134 * Block Revision Register1 (BRR1): QEMU does not fully emulate
135 * any version on MPIC. So to start with, set the IP version to 0.
137 * NOTE: This is Freescale MPIC specific register. Keep it here till
138 * this code is refactored for different variants of OPENPIC and MPIC.
140 #define FSL_BRR1_IPID (0x0040 << 16) /* 16 bit IP-block ID */
141 #define FSL_BRR1_IPMJ (0x00 << 8) /* 8 bit IP major number */
142 #define FSL_BRR1_IPMN 0x00 /* 8 bit IP minor number */
153 #error "Please select which OpenPic implementation is to be emulated"
156 #define OPENPIC_PAGE_SIZE 4096
158 #define BF_WIDTH(_bits_) \
159 (((_bits_) + (sizeof(uint32_t) * 8) - 1) / (sizeof(uint32_t) * 8))
161 static inline void set_bit (uint32_t *field
, int bit
)
163 field
[bit
>> 5] |= 1 << (bit
& 0x1F);
166 static inline void reset_bit (uint32_t *field
, int bit
)
168 field
[bit
>> 5] &= ~(1 << (bit
& 0x1F));
171 static inline int test_bit (uint32_t *field
, int bit
)
173 return (field
[bit
>> 5] & 1 << (bit
& 0x1F)) != 0;
176 static int get_current_cpu(void)
178 return cpu_single_env
->cpu_index
;
181 static uint32_t openpic_cpu_read_internal(void *opaque
, hwaddr addr
,
183 static void openpic_cpu_write_internal(void *opaque
, hwaddr addr
,
184 uint32_t val
, int idx
);
193 typedef struct IRQ_queue_t
{
194 uint32_t queue
[BF_WIDTH(MAX_IRQ
)];
199 typedef struct IRQ_src_t
{
200 uint32_t ipvp
; /* IRQ vector/priority register */
201 uint32_t ide
; /* IRQ destination register */
204 int pending
; /* TRUE if IRQ is pending */
214 #define IPVP_PRIORITY_MASK (0x1F << 16)
215 #define IPVP_PRIORITY(_ipvpr_) ((int)(((_ipvpr_) & IPVP_PRIORITY_MASK) >> 16))
216 #define IPVP_VECTOR_MASK ((1 << VECTOR_BITS) - 1)
217 #define IPVP_VECTOR(_ipvpr_) ((_ipvpr_) & IPVP_VECTOR_MASK)
219 typedef struct IRQ_dst_t
{
221 uint32_t pctp
; /* CPU current task priority */
222 uint32_t pcsr
; /* CPU sensitivity register */
224 IRQ_queue_t servicing
;
228 typedef struct openpic_t
{
233 MemoryRegion sub_io_mem
[7];
235 /* Global registers */
236 uint32_t frep
; /* Feature reporting register */
237 uint32_t glbc
; /* Global configuration register */
238 uint32_t micr
; /* MPIC interrupt configuration register */
239 uint32_t veni
; /* Vendor identification register */
240 uint32_t pint
; /* Processor initialization register */
241 uint32_t spve
; /* Spurious vector register */
242 uint32_t tifr
; /* Timer frequency reporting register */
243 /* Source registers */
244 IRQ_src_t src
[MAX_IRQ
];
245 /* Local registers per output pin */
246 IRQ_dst_t dst
[MAX_CPU
];
248 /* Timer registers */
250 uint32_t ticc
; /* Global timer current count register */
251 uint32_t tibc
; /* Global timer base count register */
254 /* Doorbell registers */
255 uint32_t dar
; /* Doorbell activate register */
257 uint32_t dmr
; /* Doorbell messaging register */
258 } doorbells
[MAX_DBL
];
261 /* Mailbox registers */
263 uint32_t mbr
; /* Mailbox register */
264 } mailboxes
[MAX_MAILBOXES
];
266 /* IRQ out is used when in bypass mode (not implemented) */
271 void (*reset
) (void *);
272 void (*irq_raise
) (struct openpic_t
*, int, IRQ_src_t
*);
275 static inline void IRQ_setbit (IRQ_queue_t
*q
, int n_IRQ
)
277 set_bit(q
->queue
, n_IRQ
);
280 static inline void IRQ_resetbit (IRQ_queue_t
*q
, int n_IRQ
)
282 reset_bit(q
->queue
, n_IRQ
);
285 static inline int IRQ_testbit (IRQ_queue_t
*q
, int n_IRQ
)
287 return test_bit(q
->queue
, n_IRQ
);
290 static void IRQ_check (openpic_t
*opp
, IRQ_queue_t
*q
)
297 for (i
= 0; i
< opp
->max_irq
; i
++) {
298 if (IRQ_testbit(q
, i
)) {
299 DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
300 i
, IPVP_PRIORITY(opp
->src
[i
].ipvp
), priority
);
301 if (IPVP_PRIORITY(opp
->src
[i
].ipvp
) > priority
) {
303 priority
= IPVP_PRIORITY(opp
->src
[i
].ipvp
);
308 q
->priority
= priority
;
311 static int IRQ_get_next (openpic_t
*opp
, IRQ_queue_t
*q
)
321 static void IRQ_local_pipe (openpic_t
*opp
, int n_CPU
, int n_IRQ
)
327 dst
= &opp
->dst
[n_CPU
];
328 src
= &opp
->src
[n_IRQ
];
329 priority
= IPVP_PRIORITY(src
->ipvp
);
330 if (priority
<= dst
->pctp
) {
331 /* Too low priority */
332 DPRINTF("%s: IRQ %d has too low priority on CPU %d\n",
333 __func__
, n_IRQ
, n_CPU
);
336 if (IRQ_testbit(&dst
->raised
, n_IRQ
)) {
338 DPRINTF("%s: IRQ %d was missed on CPU %d\n",
339 __func__
, n_IRQ
, n_CPU
);
342 set_bit(&src
->ipvp
, IPVP_ACTIVITY
);
343 IRQ_setbit(&dst
->raised
, n_IRQ
);
344 if (priority
< dst
->raised
.priority
) {
345 /* An higher priority IRQ is already raised */
346 DPRINTF("%s: IRQ %d is hidden by raised IRQ %d on CPU %d\n",
347 __func__
, n_IRQ
, dst
->raised
.next
, n_CPU
);
350 IRQ_get_next(opp
, &dst
->raised
);
351 if (IRQ_get_next(opp
, &dst
->servicing
) != -1 &&
352 priority
<= dst
->servicing
.priority
) {
353 DPRINTF("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n",
354 __func__
, n_IRQ
, dst
->servicing
.next
, n_CPU
);
355 /* Already servicing a higher priority IRQ */
358 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n", n_CPU
, n_IRQ
);
359 opp
->irq_raise(opp
, n_CPU
, src
);
362 /* update pic state because registers for n_IRQ have changed value */
363 static void openpic_update_irq(openpic_t
*opp
, int n_IRQ
)
368 src
= &opp
->src
[n_IRQ
];
372 DPRINTF("%s: IRQ %d is not pending\n", __func__
, n_IRQ
);
375 if (test_bit(&src
->ipvp
, IPVP_MASK
)) {
376 /* Interrupt source is disabled */
377 DPRINTF("%s: IRQ %d is disabled\n", __func__
, n_IRQ
);
380 if (IPVP_PRIORITY(src
->ipvp
) == 0) {
381 /* Priority set to zero */
382 DPRINTF("%s: IRQ %d has 0 priority\n", __func__
, n_IRQ
);
385 if (test_bit(&src
->ipvp
, IPVP_ACTIVITY
)) {
386 /* IRQ already active */
387 DPRINTF("%s: IRQ %d is already active\n", __func__
, n_IRQ
);
390 if (src
->ide
== 0x00000000) {
392 DPRINTF("%s: IRQ %d has no target\n", __func__
, n_IRQ
);
396 if (src
->ide
== (1 << src
->last_cpu
)) {
397 /* Only one CPU is allowed to receive this IRQ */
398 IRQ_local_pipe(opp
, src
->last_cpu
, n_IRQ
);
399 } else if (!test_bit(&src
->ipvp
, IPVP_MODE
)) {
400 /* Directed delivery mode */
401 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
402 if (test_bit(&src
->ide
, i
))
403 IRQ_local_pipe(opp
, i
, n_IRQ
);
406 /* Distributed delivery mode */
407 for (i
= src
->last_cpu
+ 1; i
!= src
->last_cpu
; i
++) {
408 if (i
== opp
->nb_cpus
)
410 if (test_bit(&src
->ide
, i
)) {
411 IRQ_local_pipe(opp
, i
, n_IRQ
);
419 static void openpic_set_irq(void *opaque
, int n_IRQ
, int level
)
421 openpic_t
*opp
= opaque
;
424 src
= &opp
->src
[n_IRQ
];
425 DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
426 n_IRQ
, level
, src
->ipvp
);
427 if (test_bit(&src
->ipvp
, IPVP_SENSE
)) {
428 /* level-sensitive irq */
429 src
->pending
= level
;
431 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
433 /* edge-sensitive irq */
437 openpic_update_irq(opp
, n_IRQ
);
440 static void openpic_reset (void *opaque
)
442 openpic_t
*opp
= (openpic_t
*)opaque
;
445 opp
->glbc
= 0x80000000;
446 /* Initialise controller registers */
447 opp
->frep
= ((OPENPIC_EXT_IRQ
- 1) << 16) | ((MAX_CPU
- 1) << 8) | VID
;
449 opp
->pint
= 0x00000000;
450 opp
->spve
= 0x000000FF;
451 opp
->tifr
= 0x003F7A00;
453 opp
->micr
= 0x00000000;
454 /* Initialise IRQ sources */
455 for (i
= 0; i
< opp
->max_irq
; i
++) {
456 opp
->src
[i
].ipvp
= 0xA0000000;
457 opp
->src
[i
].ide
= 0x00000000;
459 /* Initialise IRQ destinations */
460 for (i
= 0; i
< MAX_CPU
; i
++) {
461 opp
->dst
[i
].pctp
= 0x0000000F;
462 opp
->dst
[i
].pcsr
= 0x00000000;
463 memset(&opp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
464 opp
->dst
[i
].raised
.next
= -1;
465 memset(&opp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
466 opp
->dst
[i
].servicing
.next
= -1;
468 /* Initialise timers */
469 for (i
= 0; i
< MAX_TMR
; i
++) {
470 opp
->timers
[i
].ticc
= 0x00000000;
471 opp
->timers
[i
].tibc
= 0x80000000;
473 /* Initialise doorbells */
475 opp
->dar
= 0x00000000;
476 for (i
= 0; i
< MAX_DBL
; i
++) {
477 opp
->doorbells
[i
].dmr
= 0x00000000;
480 /* Initialise mailboxes */
482 for (i
= 0; i
< MAX_MBX
; i
++) { /* ? */
483 opp
->mailboxes
[i
].mbr
= 0x00000000;
486 /* Go out of RESET state */
487 opp
->glbc
= 0x00000000;
490 static inline uint32_t read_IRQreg_ide(openpic_t
*opp
, int n_IRQ
)
492 return opp
->src
[n_IRQ
].ide
;
495 static inline uint32_t read_IRQreg_ipvp(openpic_t
*opp
, int n_IRQ
)
497 return opp
->src
[n_IRQ
].ipvp
;
500 static inline void write_IRQreg_ide(openpic_t
*opp
, int n_IRQ
, uint32_t val
)
504 tmp
= val
& 0xC0000000;
505 tmp
|= val
& ((1ULL << MAX_CPU
) - 1);
506 opp
->src
[n_IRQ
].ide
= tmp
;
507 DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ
, opp
->src
[n_IRQ
].ide
);
510 static inline void write_IRQreg_ipvp(openpic_t
*opp
, int n_IRQ
, uint32_t val
)
512 /* NOTE: not fully accurate for special IRQs, but simple and sufficient */
513 /* ACTIVITY bit is read-only */
514 opp
->src
[n_IRQ
].ipvp
= (opp
->src
[n_IRQ
].ipvp
& 0x40000000)
515 | (val
& 0x800F00FF);
516 openpic_update_irq(opp
, n_IRQ
);
517 DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n", n_IRQ
, val
,
518 opp
->src
[n_IRQ
].ipvp
);
521 #if 0 // Code provision for Intel model
523 static uint32_t read_doorbell_register (openpic_t
*opp
,
524 int n_dbl
, uint32_t offset
)
529 case DBL_IPVP_OFFSET
:
530 retval
= read_IRQreg_ipvp(opp
, IRQ_DBL0
+ n_dbl
);
533 retval
= read_IRQreg_ide(opp
, IRQ_DBL0
+ n_dbl
);
536 retval
= opp
->doorbells
[n_dbl
].dmr
;
543 static void write_doorbell_register (penpic_t
*opp
, int n_dbl
,
544 uint32_t offset
, uint32_t value
)
547 case DBL_IVPR_OFFSET
:
548 write_IRQreg_ipvp(opp
, IRQ_DBL0
+ n_dbl
, value
);
551 write_IRQreg_ide(opp
, IRQ_DBL0
+ n_dbl
, value
);
554 opp
->doorbells
[n_dbl
].dmr
= value
;
561 static uint32_t read_mailbox_register (openpic_t
*opp
,
562 int n_mbx
, uint32_t offset
)
568 retval
= opp
->mailboxes
[n_mbx
].mbr
;
570 case MBX_IVPR_OFFSET
:
571 retval
= read_IRQreg_ipvp(opp
, IRQ_MBX0
+ n_mbx
);
574 retval
= read_IRQreg_ide(opp
, IRQ_MBX0
+ n_mbx
);
581 static void write_mailbox_register (openpic_t
*opp
, int n_mbx
,
582 uint32_t address
, uint32_t value
)
586 opp
->mailboxes
[n_mbx
].mbr
= value
;
588 case MBX_IVPR_OFFSET
:
589 write_IRQreg_ipvp(opp
, IRQ_MBX0
+ n_mbx
, value
);
592 write_IRQreg_ide(opp
, IRQ_MBX0
+ n_mbx
, value
);
597 #endif /* 0 : Code provision for Intel model */
599 static void openpic_gbl_write (void *opaque
, hwaddr addr
, uint32_t val
)
601 openpic_t
*opp
= opaque
;
605 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
609 case 0x00: /* Block Revision Register1 (BRR1) is Readonly */
619 openpic_cpu_write_internal(opp
, addr
, val
, get_current_cpu());
621 case 0x1000: /* FREP */
623 case 0x1020: /* GLBC */
624 if (val
& 0x80000000 && opp
->reset
)
626 opp
->glbc
= val
& ~0x80000000;
628 case 0x1080: /* VENI */
630 case 0x1090: /* PINT */
631 for (idx
= 0; idx
< opp
->nb_cpus
; idx
++) {
632 if ((val
& (1 << idx
)) && !(opp
->pint
& (1 << idx
))) {
633 DPRINTF("Raise OpenPIC RESET output for CPU %d\n", idx
);
634 dst
= &opp
->dst
[idx
];
635 qemu_irq_raise(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
636 } else if (!(val
& (1 << idx
)) && (opp
->pint
& (1 << idx
))) {
637 DPRINTF("Lower OpenPIC RESET output for CPU %d\n", idx
);
638 dst
= &opp
->dst
[idx
];
639 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_RESET
]);
644 case 0x10A0: /* IPI_IPVP */
650 idx
= (addr
- 0x10A0) >> 4;
651 write_IRQreg_ipvp(opp
, opp
->irq_ipi0
+ idx
, val
);
654 case 0x10E0: /* SPVE */
655 opp
->spve
= val
& 0x000000FF;
657 case 0x10F0: /* TIFR */
665 static uint32_t openpic_gbl_read (void *opaque
, hwaddr addr
)
667 openpic_t
*opp
= opaque
;
670 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
675 case 0x1000: /* FREP */
678 case 0x1020: /* GLBC */
681 case 0x1080: /* VENI */
684 case 0x1090: /* PINT */
687 case 0x00: /* Block Revision Register1 (BRR1) */
696 retval
= openpic_cpu_read_internal(opp
, addr
, get_current_cpu());
698 case 0x10A0: /* IPI_IPVP */
704 idx
= (addr
- 0x10A0) >> 4;
705 retval
= read_IRQreg_ipvp(opp
, opp
->irq_ipi0
+ idx
);
708 case 0x10E0: /* SPVE */
711 case 0x10F0: /* TIFR */
717 DPRINTF("%s: => %08x\n", __func__
, retval
);
722 static void openpic_timer_write (void *opaque
, uint32_t addr
, uint32_t val
)
724 openpic_t
*opp
= opaque
;
727 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
732 idx
= (addr
& 0xFFF0) >> 6;
735 case 0x00: /* TICC */
737 case 0x10: /* TIBC */
738 if ((opp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
739 (val
& 0x80000000) == 0 &&
740 (opp
->timers
[idx
].tibc
& 0x80000000) != 0)
741 opp
->timers
[idx
].ticc
&= ~0x80000000;
742 opp
->timers
[idx
].tibc
= val
;
744 case 0x20: /* TIVP */
745 write_IRQreg_ipvp(opp
, opp
->irq_tim0
+ idx
, val
);
747 case 0x30: /* TIDE */
748 write_IRQreg_ide(opp
, opp
->irq_tim0
+ idx
, val
);
753 static uint32_t openpic_timer_read (void *opaque
, uint32_t addr
)
755 openpic_t
*opp
= opaque
;
759 DPRINTF("%s: addr %08x\n", __func__
, addr
);
765 idx
= (addr
& 0xFFF0) >> 6;
768 case 0x00: /* TICC */
769 retval
= opp
->timers
[idx
].ticc
;
771 case 0x10: /* TIBC */
772 retval
= opp
->timers
[idx
].tibc
;
774 case 0x20: /* TIPV */
775 retval
= read_IRQreg_ipvp(opp
, opp
->irq_tim0
+ idx
);
777 case 0x30: /* TIDE */
778 retval
= read_IRQreg_ide(opp
, opp
->irq_tim0
+ idx
);
781 DPRINTF("%s: => %08x\n", __func__
, retval
);
786 static void openpic_src_write (void *opaque
, uint32_t addr
, uint32_t val
)
788 openpic_t
*opp
= opaque
;
791 DPRINTF("%s: addr %08x <= %08x\n", __func__
, addr
, val
);
794 addr
= addr
& 0xFFF0;
797 /* EXDE / IFEDE / IEEDE */
798 write_IRQreg_ide(opp
, idx
, val
);
800 /* EXVP / IFEVP / IEEVP */
801 write_IRQreg_ipvp(opp
, idx
, val
);
805 static uint32_t openpic_src_read (void *opaque
, uint32_t addr
)
807 openpic_t
*opp
= opaque
;
811 DPRINTF("%s: addr %08x\n", __func__
, addr
);
815 addr
= addr
& 0xFFF0;
818 /* EXDE / IFEDE / IEEDE */
819 retval
= read_IRQreg_ide(opp
, idx
);
821 /* EXVP / IFEVP / IEEVP */
822 retval
= read_IRQreg_ipvp(opp
, idx
);
824 DPRINTF("%s: => %08x\n", __func__
, retval
);
829 static void openpic_cpu_write_internal(void *opaque
, hwaddr addr
,
830 uint32_t val
, int idx
)
832 openpic_t
*opp
= opaque
;
837 DPRINTF("%s: cpu %d addr " TARGET_FMT_plx
" <= %08x\n", __func__
, idx
,
841 dst
= &opp
->dst
[idx
];
845 case 0x40: /* IPIDR */
849 idx
= (addr
- 0x40) >> 4;
850 /* we use IDE as mask which CPUs to deliver the IPI to still. */
851 write_IRQreg_ide(opp
, opp
->irq_ipi0
+ idx
,
852 opp
->src
[opp
->irq_ipi0
+ idx
].ide
| val
);
853 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 1);
854 openpic_set_irq(opp
, opp
->irq_ipi0
+ idx
, 0);
857 case 0x80: /* PCTP */
858 dst
->pctp
= val
& 0x0000000F;
860 case 0x90: /* WHOAMI */
861 /* Read-only register */
863 case 0xA0: /* PIAC */
864 /* Read-only register */
866 case 0xB0: /* PEOI */
868 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
869 IRQ_resetbit(&dst
->servicing
, s_IRQ
);
870 dst
->servicing
.next
= -1;
871 /* Set up next servicing IRQ */
872 s_IRQ
= IRQ_get_next(opp
, &dst
->servicing
);
873 /* Check queued interrupts. */
874 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
875 src
= &opp
->src
[n_IRQ
];
878 IPVP_PRIORITY(src
->ipvp
) > dst
->servicing
.priority
)) {
879 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n",
881 opp
->irq_raise(opp
, idx
, src
);
889 static void openpic_cpu_write(void *opaque
, hwaddr addr
, uint32_t val
)
891 openpic_cpu_write_internal(opaque
, addr
, val
, (addr
& 0x1f000) >> 12);
894 static uint32_t openpic_cpu_read_internal(void *opaque
, hwaddr addr
,
897 openpic_t
*opp
= opaque
;
903 DPRINTF("%s: cpu %d addr " TARGET_FMT_plx
"\n", __func__
, idx
, addr
);
907 dst
= &opp
->dst
[idx
];
910 case 0x00: /* Block Revision Register1 (BRR1) */
911 retval
= FSL_BRR1_IPID
| FSL_BRR1_IPMJ
| FSL_BRR1_IPMN
;
913 case 0x80: /* PCTP */
916 case 0x90: /* WHOAMI */
919 case 0xA0: /* PIAC */
920 DPRINTF("Lower OpenPIC INT output\n");
921 qemu_irq_lower(dst
->irqs
[OPENPIC_OUTPUT_INT
]);
922 n_IRQ
= IRQ_get_next(opp
, &dst
->raised
);
923 DPRINTF("PIAC: irq=%d\n", n_IRQ
);
925 /* No more interrupt pending */
926 retval
= IPVP_VECTOR(opp
->spve
);
928 src
= &opp
->src
[n_IRQ
];
929 if (!test_bit(&src
->ipvp
, IPVP_ACTIVITY
) ||
930 !(IPVP_PRIORITY(src
->ipvp
) > dst
->pctp
)) {
931 /* - Spurious level-sensitive IRQ
932 * - Priorities has been changed
933 * and the pending IRQ isn't allowed anymore
935 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
936 retval
= IPVP_VECTOR(opp
->spve
);
938 /* IRQ enter servicing state */
939 IRQ_setbit(&dst
->servicing
, n_IRQ
);
940 retval
= IPVP_VECTOR(src
->ipvp
);
942 IRQ_resetbit(&dst
->raised
, n_IRQ
);
943 dst
->raised
.next
= -1;
944 if (!test_bit(&src
->ipvp
, IPVP_SENSE
)) {
945 /* edge-sensitive IRQ */
946 reset_bit(&src
->ipvp
, IPVP_ACTIVITY
);
950 if ((n_IRQ
>= opp
->irq_ipi0
) && (n_IRQ
< (opp
->irq_ipi0
+ MAX_IPI
))) {
951 src
->ide
&= ~(1 << idx
);
952 if (src
->ide
&& !test_bit(&src
->ipvp
, IPVP_SENSE
)) {
953 /* trigger on CPUs that didn't know about it yet */
954 openpic_set_irq(opp
, n_IRQ
, 1);
955 openpic_set_irq(opp
, n_IRQ
, 0);
956 /* if all CPUs knew about it, set active bit again */
957 set_bit(&src
->ipvp
, IPVP_ACTIVITY
);
962 case 0xB0: /* PEOI */
968 DPRINTF("%s: => %08x\n", __func__
, retval
);
973 static uint32_t openpic_cpu_read(void *opaque
, hwaddr addr
)
975 return openpic_cpu_read_internal(opaque
, addr
, (addr
& 0x1f000) >> 12);
978 static void openpic_buggy_write (void *opaque
,
979 hwaddr addr
, uint32_t val
)
981 printf("Invalid OPENPIC write access !\n");
984 static uint32_t openpic_buggy_read (void *opaque
, hwaddr addr
)
986 printf("Invalid OPENPIC read access !\n");
991 static void openpic_writel (void *opaque
,
992 hwaddr addr
, uint32_t val
)
994 openpic_t
*opp
= opaque
;
997 DPRINTF("%s: offset %08x val: %08x\n", __func__
, (int)addr
, val
);
999 /* Global registers */
1000 openpic_gbl_write(opp
, addr
, val
);
1001 } else if (addr
< 0x10000) {
1002 /* Timers registers */
1003 openpic_timer_write(opp
, addr
, val
);
1004 } else if (addr
< 0x20000) {
1005 /* Source registers */
1006 openpic_src_write(opp
, addr
, val
);
1009 openpic_cpu_write(opp
, addr
, val
);
1013 static uint32_t openpic_readl (void *opaque
,hwaddr addr
)
1015 openpic_t
*opp
= opaque
;
1019 DPRINTF("%s: offset %08x\n", __func__
, (int)addr
);
1020 if (addr
< 0x1100) {
1021 /* Global registers */
1022 retval
= openpic_gbl_read(opp
, addr
);
1023 } else if (addr
< 0x10000) {
1024 /* Timers registers */
1025 retval
= openpic_timer_read(opp
, addr
);
1026 } else if (addr
< 0x20000) {
1027 /* Source registers */
1028 retval
= openpic_src_read(opp
, addr
);
1031 retval
= openpic_cpu_read(opp
, addr
);
1037 static uint64_t openpic_read(void *opaque
, hwaddr addr
,
1040 openpic_t
*opp
= opaque
;
1043 case 4: return openpic_readl(opp
, addr
);
1044 default: return openpic_buggy_read(opp
, addr
);
1048 static void openpic_write(void *opaque
, hwaddr addr
,
1049 uint64_t data
, unsigned size
)
1051 openpic_t
*opp
= opaque
;
1054 case 4: return openpic_writel(opp
, addr
, data
);
1055 default: return openpic_buggy_write(opp
, addr
, data
);
1059 static const MemoryRegionOps openpic_ops
= {
1060 .read
= openpic_read
,
1061 .write
= openpic_write
,
1062 .endianness
= DEVICE_LITTLE_ENDIAN
,
1065 static void openpic_save_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1069 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1070 qemu_put_be32s(f
, &q
->queue
[i
]);
1072 qemu_put_sbe32s(f
, &q
->next
);
1073 qemu_put_sbe32s(f
, &q
->priority
);
1076 static void openpic_save(QEMUFile
* f
, void *opaque
)
1078 openpic_t
*opp
= (openpic_t
*)opaque
;
1081 qemu_put_be32s(f
, &opp
->frep
);
1082 qemu_put_be32s(f
, &opp
->glbc
);
1083 qemu_put_be32s(f
, &opp
->micr
);
1084 qemu_put_be32s(f
, &opp
->veni
);
1085 qemu_put_be32s(f
, &opp
->pint
);
1086 qemu_put_be32s(f
, &opp
->spve
);
1087 qemu_put_be32s(f
, &opp
->tifr
);
1089 for (i
= 0; i
< opp
->max_irq
; i
++) {
1090 qemu_put_be32s(f
, &opp
->src
[i
].ipvp
);
1091 qemu_put_be32s(f
, &opp
->src
[i
].ide
);
1092 qemu_put_sbe32s(f
, &opp
->src
[i
].type
);
1093 qemu_put_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1094 qemu_put_sbe32s(f
, &opp
->src
[i
].pending
);
1097 qemu_put_sbe32s(f
, &opp
->nb_cpus
);
1099 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1100 qemu_put_be32s(f
, &opp
->dst
[i
].tfrr
);
1101 qemu_put_be32s(f
, &opp
->dst
[i
].pctp
);
1102 qemu_put_be32s(f
, &opp
->dst
[i
].pcsr
);
1103 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1104 openpic_save_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1107 for (i
= 0; i
< MAX_TMR
; i
++) {
1108 qemu_put_be32s(f
, &opp
->timers
[i
].ticc
);
1109 qemu_put_be32s(f
, &opp
->timers
[i
].tibc
);
1113 qemu_put_be32s(f
, &opp
->dar
);
1115 for (i
= 0; i
< MAX_DBL
; i
++) {
1116 qemu_put_be32s(f
, &opp
->doorbells
[i
].dmr
);
1121 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1122 qemu_put_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1126 pci_device_save(&opp
->pci_dev
, f
);
1129 static void openpic_load_IRQ_queue(QEMUFile
* f
, IRQ_queue_t
*q
)
1133 for (i
= 0; i
< BF_WIDTH(MAX_IRQ
); i
++)
1134 qemu_get_be32s(f
, &q
->queue
[i
]);
1136 qemu_get_sbe32s(f
, &q
->next
);
1137 qemu_get_sbe32s(f
, &q
->priority
);
1140 static int openpic_load(QEMUFile
* f
, void *opaque
, int version_id
)
1142 openpic_t
*opp
= (openpic_t
*)opaque
;
1145 if (version_id
!= 1)
1148 qemu_get_be32s(f
, &opp
->frep
);
1149 qemu_get_be32s(f
, &opp
->glbc
);
1150 qemu_get_be32s(f
, &opp
->micr
);
1151 qemu_get_be32s(f
, &opp
->veni
);
1152 qemu_get_be32s(f
, &opp
->pint
);
1153 qemu_get_be32s(f
, &opp
->spve
);
1154 qemu_get_be32s(f
, &opp
->tifr
);
1156 for (i
= 0; i
< opp
->max_irq
; i
++) {
1157 qemu_get_be32s(f
, &opp
->src
[i
].ipvp
);
1158 qemu_get_be32s(f
, &opp
->src
[i
].ide
);
1159 qemu_get_sbe32s(f
, &opp
->src
[i
].type
);
1160 qemu_get_sbe32s(f
, &opp
->src
[i
].last_cpu
);
1161 qemu_get_sbe32s(f
, &opp
->src
[i
].pending
);
1164 qemu_get_sbe32s(f
, &opp
->nb_cpus
);
1166 for (i
= 0; i
< opp
->nb_cpus
; i
++) {
1167 qemu_get_be32s(f
, &opp
->dst
[i
].tfrr
);
1168 qemu_get_be32s(f
, &opp
->dst
[i
].pctp
);
1169 qemu_get_be32s(f
, &opp
->dst
[i
].pcsr
);
1170 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].raised
);
1171 openpic_load_IRQ_queue(f
, &opp
->dst
[i
].servicing
);
1174 for (i
= 0; i
< MAX_TMR
; i
++) {
1175 qemu_get_be32s(f
, &opp
->timers
[i
].ticc
);
1176 qemu_get_be32s(f
, &opp
->timers
[i
].tibc
);
1180 qemu_get_be32s(f
, &opp
->dar
);
1182 for (i
= 0; i
< MAX_DBL
; i
++) {
1183 qemu_get_be32s(f
, &opp
->doorbells
[i
].dmr
);
1188 for (i
= 0; i
< MAX_MAILBOXES
; i
++) {
1189 qemu_get_be32s(f
, &opp
->mailboxes
[i
].mbr
);
1193 return pci_device_load(&opp
->pci_dev
, f
);
1196 static void openpic_irq_raise(openpic_t
*opp
, int n_CPU
, IRQ_src_t
*src
)
1198 qemu_irq_raise(opp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1201 qemu_irq
*openpic_init (MemoryRegion
**pmem
, int nb_cpus
,
1202 qemu_irq
**irqs
, qemu_irq irq_out
)
1207 /* XXX: for now, only one CPU is supported */
1210 opp
= g_malloc0(sizeof(openpic_t
));
1211 memory_region_init_io(&opp
->mem
, &openpic_ops
, opp
, "openpic", 0x40000);
1213 // isu_base &= 0xFFFC0000;
1214 opp
->nb_cpus
= nb_cpus
;
1215 opp
->max_irq
= OPENPIC_MAX_IRQ
;
1216 opp
->irq_ipi0
= OPENPIC_IRQ_IPI0
;
1217 opp
->irq_tim0
= OPENPIC_IRQ_TIM0
;
1219 for (i
= 0; i
< OPENPIC_EXT_IRQ
; i
++) {
1220 opp
->src
[i
].type
= IRQ_EXTERNAL
;
1222 for (; i
< OPENPIC_IRQ_TIM0
; i
++) {
1223 opp
->src
[i
].type
= IRQ_SPECIAL
;
1226 m
= OPENPIC_IRQ_IPI0
;
1228 m
= OPENPIC_IRQ_DBL0
;
1230 for (; i
< m
; i
++) {
1231 opp
->src
[i
].type
= IRQ_TIMER
;
1233 for (; i
< OPENPIC_MAX_IRQ
; i
++) {
1234 opp
->src
[i
].type
= IRQ_INTERNAL
;
1236 for (i
= 0; i
< nb_cpus
; i
++)
1237 opp
->dst
[i
].irqs
= irqs
[i
];
1238 opp
->irq_out
= irq_out
;
1240 register_savevm(&opp
->pci_dev
.qdev
, "openpic", 0, 2,
1241 openpic_save
, openpic_load
, opp
);
1242 qemu_register_reset(openpic_reset
, opp
);
1244 opp
->irq_raise
= openpic_irq_raise
;
1245 opp
->reset
= openpic_reset
;
1250 return qemu_allocate_irqs(openpic_set_irq
, opp
, opp
->max_irq
);
1253 static void mpic_irq_raise(openpic_t
*mpp
, int n_CPU
, IRQ_src_t
*src
)
1255 int n_ci
= IDR_CI0
- n_CPU
;
1257 if(test_bit(&src
->ide
, n_ci
)) {
1258 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_CINT
]);
1261 qemu_irq_raise(mpp
->dst
[n_CPU
].irqs
[OPENPIC_OUTPUT_INT
]);
1265 static void mpic_reset (void *opaque
)
1267 openpic_t
*mpp
= (openpic_t
*)opaque
;
1270 mpp
->glbc
= 0x80000000;
1271 /* Initialise controller registers */
1272 mpp
->frep
= 0x004f0002 | ((mpp
->nb_cpus
- 1) << 8);
1274 mpp
->pint
= 0x00000000;
1275 mpp
->spve
= 0x0000FFFF;
1276 /* Initialise IRQ sources */
1277 for (i
= 0; i
< mpp
->max_irq
; i
++) {
1278 mpp
->src
[i
].ipvp
= 0x80800000;
1279 mpp
->src
[i
].ide
= 0x00000001;
1281 /* Set IDE for IPIs to 0 so we don't get spurious interrupts */
1282 for (i
= mpp
->irq_ipi0
; i
< (mpp
->irq_ipi0
+ MAX_IPI
); i
++) {
1283 mpp
->src
[i
].ide
= 0;
1285 /* Initialise IRQ destinations */
1286 for (i
= 0; i
< MAX_CPU
; i
++) {
1287 mpp
->dst
[i
].pctp
= 0x0000000F;
1288 mpp
->dst
[i
].tfrr
= 0x00000000;
1289 memset(&mpp
->dst
[i
].raised
, 0, sizeof(IRQ_queue_t
));
1290 mpp
->dst
[i
].raised
.next
= -1;
1291 memset(&mpp
->dst
[i
].servicing
, 0, sizeof(IRQ_queue_t
));
1292 mpp
->dst
[i
].servicing
.next
= -1;
1294 /* Initialise timers */
1295 for (i
= 0; i
< MAX_TMR
; i
++) {
1296 mpp
->timers
[i
].ticc
= 0x00000000;
1297 mpp
->timers
[i
].tibc
= 0x80000000;
1299 /* Go out of RESET state */
1300 mpp
->glbc
= 0x00000000;
1303 static void mpic_timer_write (void *opaque
, hwaddr addr
, uint32_t val
)
1305 openpic_t
*mpp
= opaque
;
1308 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1313 idx
= (addr
>> 6) & 0x3;
1314 switch (addr
& 0x30) {
1315 case 0x00: /* gtccr */
1317 case 0x10: /* gtbcr */
1318 if ((mpp
->timers
[idx
].ticc
& 0x80000000) != 0 &&
1319 (val
& 0x80000000) == 0 &&
1320 (mpp
->timers
[idx
].tibc
& 0x80000000) != 0)
1321 mpp
->timers
[idx
].ticc
&= ~0x80000000;
1322 mpp
->timers
[idx
].tibc
= val
;
1324 case 0x20: /* GTIVPR */
1325 write_IRQreg_ipvp(mpp
, MPIC_TMR_IRQ
+ idx
, val
);
1327 case 0x30: /* GTIDR & TFRR */
1328 if ((addr
& 0xF0) == 0xF0)
1329 mpp
->dst
[cpu
].tfrr
= val
;
1331 write_IRQreg_ide(mpp
, MPIC_TMR_IRQ
+ idx
, val
);
1336 static uint32_t mpic_timer_read (void *opaque
, hwaddr addr
)
1338 openpic_t
*mpp
= opaque
;
1342 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1343 retval
= 0xFFFFFFFF;
1348 idx
= (addr
>> 6) & 0x3;
1349 switch (addr
& 0x30) {
1350 case 0x00: /* gtccr */
1351 retval
= mpp
->timers
[idx
].ticc
;
1353 case 0x10: /* gtbcr */
1354 retval
= mpp
->timers
[idx
].tibc
;
1356 case 0x20: /* TIPV */
1357 retval
= read_IRQreg_ipvp(mpp
, MPIC_TMR_IRQ
+ idx
);
1359 case 0x30: /* TIDR */
1360 if ((addr
&0xF0) == 0XF0)
1361 retval
= mpp
->dst
[cpu
].tfrr
;
1363 retval
= read_IRQreg_ide(mpp
, MPIC_TMR_IRQ
+ idx
);
1366 DPRINTF("%s: => %08x\n", __func__
, retval
);
1371 static void mpic_src_ext_write (void *opaque
, hwaddr addr
,
1374 openpic_t
*mpp
= opaque
;
1375 int idx
= MPIC_EXT_IRQ
;
1377 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1381 if (addr
< MPIC_EXT_REG_SIZE
) {
1382 idx
+= (addr
& 0xFFF0) >> 5;
1384 /* EXDE / IFEDE / IEEDE */
1385 write_IRQreg_ide(mpp
, idx
, val
);
1387 /* EXVP / IFEVP / IEEVP */
1388 write_IRQreg_ipvp(mpp
, idx
, val
);
1393 static uint32_t mpic_src_ext_read (void *opaque
, hwaddr addr
)
1395 openpic_t
*mpp
= opaque
;
1397 int idx
= MPIC_EXT_IRQ
;
1399 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1400 retval
= 0xFFFFFFFF;
1404 if (addr
< MPIC_EXT_REG_SIZE
) {
1405 idx
+= (addr
& 0xFFF0) >> 5;
1407 /* EXDE / IFEDE / IEEDE */
1408 retval
= read_IRQreg_ide(mpp
, idx
);
1410 /* EXVP / IFEVP / IEEVP */
1411 retval
= read_IRQreg_ipvp(mpp
, idx
);
1413 DPRINTF("%s: => %08x\n", __func__
, retval
);
1419 static void mpic_src_int_write (void *opaque
, hwaddr addr
,
1422 openpic_t
*mpp
= opaque
;
1423 int idx
= MPIC_INT_IRQ
;
1425 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1429 if (addr
< MPIC_INT_REG_SIZE
) {
1430 idx
+= (addr
& 0xFFF0) >> 5;
1432 /* EXDE / IFEDE / IEEDE */
1433 write_IRQreg_ide(mpp
, idx
, val
);
1435 /* EXVP / IFEVP / IEEVP */
1436 write_IRQreg_ipvp(mpp
, idx
, val
);
1441 static uint32_t mpic_src_int_read (void *opaque
, hwaddr addr
)
1443 openpic_t
*mpp
= opaque
;
1445 int idx
= MPIC_INT_IRQ
;
1447 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1448 retval
= 0xFFFFFFFF;
1452 if (addr
< MPIC_INT_REG_SIZE
) {
1453 idx
+= (addr
& 0xFFF0) >> 5;
1455 /* EXDE / IFEDE / IEEDE */
1456 retval
= read_IRQreg_ide(mpp
, idx
);
1458 /* EXVP / IFEVP / IEEVP */
1459 retval
= read_IRQreg_ipvp(mpp
, idx
);
1461 DPRINTF("%s: => %08x\n", __func__
, retval
);
1467 static void mpic_src_msg_write (void *opaque
, hwaddr addr
,
1470 openpic_t
*mpp
= opaque
;
1471 int idx
= MPIC_MSG_IRQ
;
1473 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1477 if (addr
< MPIC_MSG_REG_SIZE
) {
1478 idx
+= (addr
& 0xFFF0) >> 5;
1480 /* EXDE / IFEDE / IEEDE */
1481 write_IRQreg_ide(mpp
, idx
, val
);
1483 /* EXVP / IFEVP / IEEVP */
1484 write_IRQreg_ipvp(mpp
, idx
, val
);
1489 static uint32_t mpic_src_msg_read (void *opaque
, hwaddr addr
)
1491 openpic_t
*mpp
= opaque
;
1493 int idx
= MPIC_MSG_IRQ
;
1495 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1496 retval
= 0xFFFFFFFF;
1500 if (addr
< MPIC_MSG_REG_SIZE
) {
1501 idx
+= (addr
& 0xFFF0) >> 5;
1503 /* EXDE / IFEDE / IEEDE */
1504 retval
= read_IRQreg_ide(mpp
, idx
);
1506 /* EXVP / IFEVP / IEEVP */
1507 retval
= read_IRQreg_ipvp(mpp
, idx
);
1509 DPRINTF("%s: => %08x\n", __func__
, retval
);
1515 static void mpic_src_msi_write (void *opaque
, hwaddr addr
,
1518 openpic_t
*mpp
= opaque
;
1519 int idx
= MPIC_MSI_IRQ
;
1521 DPRINTF("%s: addr " TARGET_FMT_plx
" <= %08x\n", __func__
, addr
, val
);
1525 if (addr
< MPIC_MSI_REG_SIZE
) {
1526 idx
+= (addr
& 0xFFF0) >> 5;
1528 /* EXDE / IFEDE / IEEDE */
1529 write_IRQreg_ide(mpp
, idx
, val
);
1531 /* EXVP / IFEVP / IEEVP */
1532 write_IRQreg_ipvp(mpp
, idx
, val
);
1536 static uint32_t mpic_src_msi_read (void *opaque
, hwaddr addr
)
1538 openpic_t
*mpp
= opaque
;
1540 int idx
= MPIC_MSI_IRQ
;
1542 DPRINTF("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1543 retval
= 0xFFFFFFFF;
1547 if (addr
< MPIC_MSI_REG_SIZE
) {
1548 idx
+= (addr
& 0xFFF0) >> 5;
1550 /* EXDE / IFEDE / IEEDE */
1551 retval
= read_IRQreg_ide(mpp
, idx
);
1553 /* EXVP / IFEVP / IEEVP */
1554 retval
= read_IRQreg_ipvp(mpp
, idx
);
1556 DPRINTF("%s: => %08x\n", __func__
, retval
);
1562 static const MemoryRegionOps mpic_glb_ops
= {
1564 .write
= { openpic_buggy_write
,
1565 openpic_buggy_write
,
1568 .read
= { openpic_buggy_read
,
1573 .endianness
= DEVICE_BIG_ENDIAN
,
1576 static const MemoryRegionOps mpic_tmr_ops
= {
1578 .write
= { openpic_buggy_write
,
1579 openpic_buggy_write
,
1582 .read
= { openpic_buggy_read
,
1587 .endianness
= DEVICE_BIG_ENDIAN
,
1590 static const MemoryRegionOps mpic_cpu_ops
= {
1592 .write
= { openpic_buggy_write
,
1593 openpic_buggy_write
,
1596 .read
= { openpic_buggy_read
,
1601 .endianness
= DEVICE_BIG_ENDIAN
,
1604 static const MemoryRegionOps mpic_ext_ops
= {
1606 .write
= { openpic_buggy_write
,
1607 openpic_buggy_write
,
1610 .read
= { openpic_buggy_read
,
1615 .endianness
= DEVICE_BIG_ENDIAN
,
1618 static const MemoryRegionOps mpic_int_ops
= {
1620 .write
= { openpic_buggy_write
,
1621 openpic_buggy_write
,
1624 .read
= { openpic_buggy_read
,
1629 .endianness
= DEVICE_BIG_ENDIAN
,
1632 static const MemoryRegionOps mpic_msg_ops
= {
1634 .write
= { openpic_buggy_write
,
1635 openpic_buggy_write
,
1638 .read
= { openpic_buggy_read
,
1643 .endianness
= DEVICE_BIG_ENDIAN
,
1646 static const MemoryRegionOps mpic_msi_ops
= {
1648 .write
= { openpic_buggy_write
,
1649 openpic_buggy_write
,
1652 .read
= { openpic_buggy_read
,
1657 .endianness
= DEVICE_BIG_ENDIAN
,
1660 qemu_irq
*mpic_init (MemoryRegion
*address_space
, hwaddr base
,
1661 int nb_cpus
, qemu_irq
**irqs
, qemu_irq irq_out
)
1667 MemoryRegionOps
const *ops
;
1671 {"glb", &mpic_glb_ops
, MPIC_GLB_REG_START
, MPIC_GLB_REG_SIZE
},
1672 {"tmr", &mpic_tmr_ops
, MPIC_TMR_REG_START
, MPIC_TMR_REG_SIZE
},
1673 {"ext", &mpic_ext_ops
, MPIC_EXT_REG_START
, MPIC_EXT_REG_SIZE
},
1674 {"int", &mpic_int_ops
, MPIC_INT_REG_START
, MPIC_INT_REG_SIZE
},
1675 {"msg", &mpic_msg_ops
, MPIC_MSG_REG_START
, MPIC_MSG_REG_SIZE
},
1676 {"msi", &mpic_msi_ops
, MPIC_MSI_REG_START
, MPIC_MSI_REG_SIZE
},
1677 {"cpu", &mpic_cpu_ops
, MPIC_CPU_REG_START
, MPIC_CPU_REG_SIZE
},
1680 mpp
= g_malloc0(sizeof(openpic_t
));
1682 memory_region_init(&mpp
->mem
, "mpic", 0x40000);
1683 memory_region_add_subregion(address_space
, base
, &mpp
->mem
);
1685 for (i
= 0; i
< sizeof(list
)/sizeof(list
[0]); i
++) {
1687 memory_region_init_io(&mpp
->sub_io_mem
[i
], list
[i
].ops
, mpp
,
1688 list
[i
].name
, list
[i
].size
);
1690 memory_region_add_subregion(&mpp
->mem
, list
[i
].start_addr
,
1691 &mpp
->sub_io_mem
[i
]);
1694 mpp
->nb_cpus
= nb_cpus
;
1695 mpp
->max_irq
= MPIC_MAX_IRQ
;
1696 mpp
->irq_ipi0
= MPIC_IPI_IRQ
;
1697 mpp
->irq_tim0
= MPIC_TMR_IRQ
;
1699 for (i
= 0; i
< nb_cpus
; i
++)
1700 mpp
->dst
[i
].irqs
= irqs
[i
];
1701 mpp
->irq_out
= irq_out
;
1703 mpp
->irq_raise
= mpic_irq_raise
;
1704 mpp
->reset
= mpic_reset
;
1706 register_savevm(NULL
, "mpic", 0, 2, openpic_save
, openpic_load
, mpp
);
1707 qemu_register_reset(mpic_reset
, mpp
);
1709 return qemu_allocate_irqs(openpic_set_irq
, mpp
, mpp
->max_irq
);