root / hw / openpic.c @ 6cc721cf
History | View | Annotate | Download (25.7 kB)
1 | dbda808a | bellard | /*
|
---|---|---|---|
2 | dbda808a | bellard | * OpenPIC emulation
|
3 | dbda808a | bellard | *
|
4 | dbda808a | bellard | * Copyright (c) 2004 Jocelyn Mayer
|
5 | dbda808a | bellard | *
|
6 | dbda808a | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | dbda808a | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | dbda808a | bellard | * in the Software without restriction, including without limitation the rights
|
9 | dbda808a | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | dbda808a | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | dbda808a | bellard | * furnished to do so, subject to the following conditions:
|
12 | dbda808a | bellard | *
|
13 | dbda808a | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | dbda808a | bellard | * all copies or substantial portions of the Software.
|
15 | dbda808a | bellard | *
|
16 | dbda808a | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | dbda808a | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | dbda808a | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | dbda808a | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | dbda808a | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | dbda808a | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | dbda808a | bellard | * THE SOFTWARE.
|
23 | dbda808a | bellard | */
|
24 | dbda808a | bellard | /*
|
25 | dbda808a | bellard | *
|
26 | dbda808a | bellard | * Based on OpenPic implementations:
|
27 | dbda808a | bellard | * - Intel GW80314 I/O compagnion chip developper's manual
|
28 | dbda808a | bellard | * - Motorola MPC8245 & MPC8540 user manuals.
|
29 | dbda808a | bellard | * - Motorola MCP750 (aka Raven) programmer manual.
|
30 | dbda808a | bellard | * - Motorola Harrier programmer manuel
|
31 | dbda808a | bellard | *
|
32 | dbda808a | bellard | * Serial interrupts, as implemented in Raven chipset are not supported yet.
|
33 | dbda808a | bellard | *
|
34 | dbda808a | bellard | */
|
35 | dbda808a | bellard | #include "vl.h" |
36 | dbda808a | bellard | |
37 | 611493d9 | bellard | //#define DEBUG_OPENPIC
|
38 | dbda808a | bellard | |
39 | dbda808a | bellard | #ifdef DEBUG_OPENPIC
|
40 | dbda808a | bellard | #define DPRINTF(fmt, args...) do { printf(fmt , ##args); } while (0) |
41 | dbda808a | bellard | #else
|
42 | dbda808a | bellard | #define DPRINTF(fmt, args...) do { } while (0) |
43 | dbda808a | bellard | #endif
|
44 | dbda808a | bellard | #define ERROR(fmr, args...) do { printf("ERROR: " fmr , ##args); } while (0) |
45 | dbda808a | bellard | |
46 | dbda808a | bellard | #define USE_MPCxxx /* Intel model is broken, for now */ |
47 | dbda808a | bellard | |
48 | dbda808a | bellard | #if defined (USE_INTEL_GW80314)
|
49 | dbda808a | bellard | /* Intel GW80314 I/O Companion chip */
|
50 | dbda808a | bellard | |
51 | dbda808a | bellard | #define MAX_CPU 4 |
52 | dbda808a | bellard | #define MAX_IRQ 32 |
53 | dbda808a | bellard | #define MAX_DBL 4 |
54 | dbda808a | bellard | #define MAX_MBX 4 |
55 | dbda808a | bellard | #define MAX_TMR 4 |
56 | dbda808a | bellard | #define VECTOR_BITS 8 |
57 | dbda808a | bellard | #define MAX_IPI 0 |
58 | dbda808a | bellard | |
59 | dbda808a | bellard | #define VID (0x00000000) |
60 | dbda808a | bellard | |
61 | dbda808a | bellard | #define OPENPIC_LITTLE_ENDIAN 1 |
62 | dbda808a | bellard | #define OPENPIC_BIG_ENDIAN 0 |
63 | dbda808a | bellard | |
64 | dbda808a | bellard | #elif defined(USE_MPCxxx)
|
65 | dbda808a | bellard | |
66 | dbda808a | bellard | #define MAX_CPU 2 |
67 | dbda808a | bellard | #define MAX_IRQ 64 |
68 | 611493d9 | bellard | #define EXT_IRQ 48 |
69 | dbda808a | bellard | #define MAX_DBL 0 |
70 | dbda808a | bellard | #define MAX_MBX 0 |
71 | dbda808a | bellard | #define MAX_TMR 4 |
72 | dbda808a | bellard | #define VECTOR_BITS 8 |
73 | dbda808a | bellard | #define MAX_IPI 4 |
74 | dbda808a | bellard | #define VID 0x03 /* MPIC version ID */ |
75 | dbda808a | bellard | #define VENI 0x00000000 /* Vendor ID */ |
76 | dbda808a | bellard | |
77 | dbda808a | bellard | enum {
|
78 | dbda808a | bellard | IRQ_IPVP = 0,
|
79 | dbda808a | bellard | IRQ_IDE, |
80 | dbda808a | bellard | }; |
81 | dbda808a | bellard | |
82 | dbda808a | bellard | #define OPENPIC_LITTLE_ENDIAN 1 |
83 | dbda808a | bellard | #define OPENPIC_BIG_ENDIAN 0 |
84 | dbda808a | bellard | |
85 | dbda808a | bellard | #else
|
86 | dbda808a | bellard | #error "Please select which OpenPic implementation is to be emulated" |
87 | dbda808a | bellard | #endif
|
88 | dbda808a | bellard | |
89 | dbda808a | bellard | #if (OPENPIC_BIG_ENDIAN && !TARGET_WORDS_BIGENDIAN) || \
|
90 | dbda808a | bellard | (OPENPIC_LITTLE_ENDIAN && TARGET_WORDS_BIGENDIAN) |
91 | dbda808a | bellard | #define OPENPIC_SWAP
|
92 | dbda808a | bellard | #endif
|
93 | dbda808a | bellard | |
94 | dbda808a | bellard | /* Interrupt definitions */
|
95 | dbda808a | bellard | #define IRQ_FE (EXT_IRQ) /* Internal functional IRQ */ |
96 | dbda808a | bellard | #define IRQ_ERR (EXT_IRQ + 1) /* Error IRQ */ |
97 | dbda808a | bellard | #define IRQ_TIM0 (EXT_IRQ + 2) /* First timer IRQ */ |
98 | dbda808a | bellard | #if MAX_IPI > 0 |
99 | dbda808a | bellard | #define IRQ_IPI0 (IRQ_TIM0 + MAX_TMR) /* First IPI IRQ */ |
100 | dbda808a | bellard | #define IRQ_DBL0 (IRQ_IPI0 + (MAX_CPU * MAX_IPI)) /* First doorbell IRQ */ |
101 | dbda808a | bellard | #else
|
102 | dbda808a | bellard | #define IRQ_DBL0 (IRQ_TIM0 + MAX_TMR) /* First doorbell IRQ */ |
103 | dbda808a | bellard | #define IRQ_MBX0 (IRQ_DBL0 + MAX_DBL) /* First mailbox IRQ */ |
104 | dbda808a | bellard | #endif
|
105 | dbda808a | bellard | |
106 | dbda808a | bellard | #define BF_WIDTH(_bits_) \
|
107 | dbda808a | bellard | (((_bits_) + (sizeof(uint32_t) * 8) - 1) / (sizeof(uint32_t) * 8)) |
108 | dbda808a | bellard | |
109 | dbda808a | bellard | static inline void set_bit (uint32_t *field, int bit) |
110 | dbda808a | bellard | { |
111 | dbda808a | bellard | field[bit >> 5] |= 1 << (bit & 0x1F); |
112 | dbda808a | bellard | } |
113 | dbda808a | bellard | |
114 | dbda808a | bellard | static inline void reset_bit (uint32_t *field, int bit) |
115 | dbda808a | bellard | { |
116 | dbda808a | bellard | field[bit >> 5] &= ~(1 << (bit & 0x1F)); |
117 | dbda808a | bellard | } |
118 | dbda808a | bellard | |
119 | dbda808a | bellard | static inline int test_bit (uint32_t *field, int bit) |
120 | dbda808a | bellard | { |
121 | dbda808a | bellard | return (field[bit >> 5] & 1 << (bit & 0x1F)) != 0; |
122 | dbda808a | bellard | } |
123 | dbda808a | bellard | |
124 | dbda808a | bellard | enum {
|
125 | dbda808a | bellard | IRQ_EXTERNAL = 0x01,
|
126 | dbda808a | bellard | IRQ_INTERNAL = 0x02,
|
127 | dbda808a | bellard | IRQ_TIMER = 0x04,
|
128 | dbda808a | bellard | IRQ_SPECIAL = 0x08,
|
129 | dbda808a | bellard | } IRQ_src_type; |
130 | dbda808a | bellard | |
131 | dbda808a | bellard | typedef struct IRQ_queue_t { |
132 | dbda808a | bellard | uint32_t queue[BF_WIDTH(MAX_IRQ)]; |
133 | dbda808a | bellard | int next;
|
134 | dbda808a | bellard | int priority;
|
135 | dbda808a | bellard | } IRQ_queue_t; |
136 | dbda808a | bellard | |
137 | dbda808a | bellard | typedef struct IRQ_src_t { |
138 | dbda808a | bellard | uint32_t ipvp; /* IRQ vector/priority register */
|
139 | dbda808a | bellard | uint32_t ide; /* IRQ destination register */
|
140 | dbda808a | bellard | int type;
|
141 | dbda808a | bellard | int last_cpu;
|
142 | 611493d9 | bellard | int pending; /* TRUE if IRQ is pending */ |
143 | dbda808a | bellard | } IRQ_src_t; |
144 | dbda808a | bellard | |
145 | dbda808a | bellard | enum IPVP_bits {
|
146 | dbda808a | bellard | IPVP_MASK = 31,
|
147 | dbda808a | bellard | IPVP_ACTIVITY = 30,
|
148 | dbda808a | bellard | IPVP_MODE = 29,
|
149 | dbda808a | bellard | IPVP_POLARITY = 23,
|
150 | dbda808a | bellard | IPVP_SENSE = 22,
|
151 | dbda808a | bellard | }; |
152 | dbda808a | bellard | #define IPVP_PRIORITY_MASK (0x1F << 16) |
153 | 611493d9 | bellard | #define IPVP_PRIORITY(_ipvpr_) ((int)(((_ipvpr_) & IPVP_PRIORITY_MASK) >> 16)) |
154 | dbda808a | bellard | #define IPVP_VECTOR_MASK ((1 << VECTOR_BITS) - 1) |
155 | dbda808a | bellard | #define IPVP_VECTOR(_ipvpr_) ((_ipvpr_) & IPVP_VECTOR_MASK)
|
156 | dbda808a | bellard | |
157 | dbda808a | bellard | typedef struct IRQ_dst_t { |
158 | dbda808a | bellard | uint32_t pctp; /* CPU current task priority */
|
159 | dbda808a | bellard | uint32_t pcsr; /* CPU sensitivity register */
|
160 | dbda808a | bellard | IRQ_queue_t raised; |
161 | dbda808a | bellard | IRQ_queue_t servicing; |
162 | dbda808a | bellard | CPUState *env; /* Needed if we did SMP */
|
163 | dbda808a | bellard | } IRQ_dst_t; |
164 | dbda808a | bellard | |
165 | 611493d9 | bellard | struct openpic_t {
|
166 | dbda808a | bellard | PCIDevice pci_dev; |
167 | 91d848eb | bellard | int mem_index;
|
168 | dbda808a | bellard | /* Global registers */
|
169 | dbda808a | bellard | uint32_t frep; /* Feature reporting register */
|
170 | dbda808a | bellard | uint32_t glbc; /* Global configuration register */
|
171 | dbda808a | bellard | uint32_t micr; /* MPIC interrupt configuration register */
|
172 | dbda808a | bellard | uint32_t veni; /* Vendor identification register */
|
173 | dbda808a | bellard | uint32_t spve; /* Spurious vector register */
|
174 | dbda808a | bellard | uint32_t tifr; /* Timer frequency reporting register */
|
175 | dbda808a | bellard | /* Source registers */
|
176 | dbda808a | bellard | IRQ_src_t src[MAX_IRQ]; |
177 | dbda808a | bellard | /* Local registers per output pin */
|
178 | dbda808a | bellard | IRQ_dst_t dst[MAX_CPU]; |
179 | dbda808a | bellard | int nb_cpus;
|
180 | dbda808a | bellard | /* Timer registers */
|
181 | dbda808a | bellard | struct {
|
182 | dbda808a | bellard | uint32_t ticc; /* Global timer current count register */
|
183 | dbda808a | bellard | uint32_t tibc; /* Global timer base count register */
|
184 | dbda808a | bellard | } timers[MAX_TMR]; |
185 | dbda808a | bellard | #if MAX_DBL > 0 |
186 | dbda808a | bellard | /* Doorbell registers */
|
187 | dbda808a | bellard | uint32_t dar; /* Doorbell activate register */
|
188 | dbda808a | bellard | struct {
|
189 | dbda808a | bellard | uint32_t dmr; /* Doorbell messaging register */
|
190 | dbda808a | bellard | } doorbells[MAX_DBL]; |
191 | dbda808a | bellard | #endif
|
192 | dbda808a | bellard | #if MAX_MBX > 0 |
193 | dbda808a | bellard | /* Mailbox registers */
|
194 | dbda808a | bellard | struct {
|
195 | dbda808a | bellard | uint32_t mbr; /* Mailbox register */
|
196 | dbda808a | bellard | } mailboxes[MAX_MAILBOXES]; |
197 | dbda808a | bellard | #endif
|
198 | 611493d9 | bellard | }; |
199 | dbda808a | bellard | |
200 | dbda808a | bellard | static inline void IRQ_setbit (IRQ_queue_t *q, int n_IRQ) |
201 | dbda808a | bellard | { |
202 | dbda808a | bellard | set_bit(q->queue, n_IRQ); |
203 | dbda808a | bellard | } |
204 | dbda808a | bellard | |
205 | dbda808a | bellard | static inline void IRQ_resetbit (IRQ_queue_t *q, int n_IRQ) |
206 | dbda808a | bellard | { |
207 | dbda808a | bellard | reset_bit(q->queue, n_IRQ); |
208 | dbda808a | bellard | } |
209 | dbda808a | bellard | |
210 | dbda808a | bellard | static inline int IRQ_testbit (IRQ_queue_t *q, int n_IRQ) |
211 | dbda808a | bellard | { |
212 | dbda808a | bellard | return test_bit(q->queue, n_IRQ);
|
213 | dbda808a | bellard | } |
214 | dbda808a | bellard | |
215 | dbda808a | bellard | static void IRQ_check (openpic_t *opp, IRQ_queue_t *q) |
216 | dbda808a | bellard | { |
217 | dbda808a | bellard | int next, i;
|
218 | dbda808a | bellard | int priority;
|
219 | dbda808a | bellard | |
220 | dbda808a | bellard | next = -1;
|
221 | dbda808a | bellard | priority = -1;
|
222 | dbda808a | bellard | for (i = 0; i < MAX_IRQ; i++) { |
223 | dbda808a | bellard | if (IRQ_testbit(q, i)) {
|
224 | 611493d9 | bellard | DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
|
225 | 611493d9 | bellard | i, IPVP_PRIORITY(opp->src[i].ipvp), priority); |
226 | dbda808a | bellard | if (IPVP_PRIORITY(opp->src[i].ipvp) > priority) {
|
227 | dbda808a | bellard | next = i; |
228 | dbda808a | bellard | priority = IPVP_PRIORITY(opp->src[i].ipvp); |
229 | dbda808a | bellard | } |
230 | dbda808a | bellard | } |
231 | dbda808a | bellard | } |
232 | dbda808a | bellard | q->next = next; |
233 | dbda808a | bellard | q->priority = priority; |
234 | dbda808a | bellard | } |
235 | dbda808a | bellard | |
236 | dbda808a | bellard | static int IRQ_get_next (openpic_t *opp, IRQ_queue_t *q) |
237 | dbda808a | bellard | { |
238 | dbda808a | bellard | if (q->next == -1) { |
239 | 611493d9 | bellard | /* XXX: optimize */
|
240 | dbda808a | bellard | IRQ_check(opp, q); |
241 | dbda808a | bellard | } |
242 | dbda808a | bellard | |
243 | dbda808a | bellard | return q->next;
|
244 | dbda808a | bellard | } |
245 | dbda808a | bellard | |
246 | dbda808a | bellard | static void IRQ_local_pipe (openpic_t *opp, int n_CPU, int n_IRQ) |
247 | dbda808a | bellard | { |
248 | dbda808a | bellard | IRQ_dst_t *dst; |
249 | dbda808a | bellard | IRQ_src_t *src; |
250 | dbda808a | bellard | int priority;
|
251 | dbda808a | bellard | |
252 | dbda808a | bellard | dst = &opp->dst[n_CPU]; |
253 | dbda808a | bellard | src = &opp->src[n_IRQ]; |
254 | dbda808a | bellard | priority = IPVP_PRIORITY(src->ipvp); |
255 | dbda808a | bellard | if (priority <= dst->pctp) {
|
256 | dbda808a | bellard | /* Too low priority */
|
257 | dbda808a | bellard | return;
|
258 | dbda808a | bellard | } |
259 | dbda808a | bellard | if (IRQ_testbit(&dst->raised, n_IRQ)) {
|
260 | dbda808a | bellard | /* Interrupt miss */
|
261 | dbda808a | bellard | return;
|
262 | dbda808a | bellard | } |
263 | dbda808a | bellard | set_bit(&src->ipvp, IPVP_ACTIVITY); |
264 | dbda808a | bellard | IRQ_setbit(&dst->raised, n_IRQ); |
265 | dbda808a | bellard | if (priority > dst->raised.priority) {
|
266 | dbda808a | bellard | IRQ_get_next(opp, &dst->raised); |
267 | dbda808a | bellard | DPRINTF("Raise CPU IRQ\n");
|
268 | dbda808a | bellard | cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HARD); |
269 | dbda808a | bellard | } |
270 | dbda808a | bellard | } |
271 | dbda808a | bellard | |
272 | 611493d9 | bellard | /* update pic state because registers for n_IRQ have changed value */
|
273 | 611493d9 | bellard | static void openpic_update_irq(openpic_t *opp, int n_IRQ) |
274 | dbda808a | bellard | { |
275 | dbda808a | bellard | IRQ_src_t *src; |
276 | dbda808a | bellard | int i;
|
277 | dbda808a | bellard | |
278 | dbda808a | bellard | src = &opp->src[n_IRQ]; |
279 | 611493d9 | bellard | |
280 | 611493d9 | bellard | if (!src->pending) {
|
281 | 611493d9 | bellard | /* no irq pending */
|
282 | 611493d9 | bellard | return;
|
283 | 611493d9 | bellard | } |
284 | 611493d9 | bellard | if (test_bit(&src->ipvp, IPVP_MASK)) {
|
285 | dbda808a | bellard | /* Interrupt source is disabled */
|
286 | dbda808a | bellard | return;
|
287 | dbda808a | bellard | } |
288 | dbda808a | bellard | if (IPVP_PRIORITY(src->ipvp) == 0) { |
289 | dbda808a | bellard | /* Priority set to zero */
|
290 | dbda808a | bellard | return;
|
291 | dbda808a | bellard | } |
292 | 611493d9 | bellard | if (test_bit(&src->ipvp, IPVP_ACTIVITY)) {
|
293 | 611493d9 | bellard | /* IRQ already active */
|
294 | 611493d9 | bellard | return;
|
295 | 611493d9 | bellard | } |
296 | dbda808a | bellard | if (src->ide == 0x00000000) { |
297 | dbda808a | bellard | /* No target */
|
298 | dbda808a | bellard | return;
|
299 | dbda808a | bellard | } |
300 | 611493d9 | bellard | |
301 | 611493d9 | bellard | if (!test_bit(&src->ipvp, IPVP_MODE) ||
|
302 | 611493d9 | bellard | src->ide == (1 << src->last_cpu)) {
|
303 | 611493d9 | bellard | /* Directed delivery mode */
|
304 | 611493d9 | bellard | for (i = 0; i < opp->nb_cpus; i++) { |
305 | 611493d9 | bellard | if (test_bit(&src->ide, i))
|
306 | 611493d9 | bellard | IRQ_local_pipe(opp, i, n_IRQ); |
307 | 611493d9 | bellard | } |
308 | dbda808a | bellard | } else {
|
309 | 611493d9 | bellard | /* Distributed delivery mode */
|
310 | 611493d9 | bellard | /* XXX: incorrect code */
|
311 | 611493d9 | bellard | for (i = src->last_cpu; i < src->last_cpu; i++) {
|
312 | 611493d9 | bellard | if (i == MAX_IRQ)
|
313 | 611493d9 | bellard | i = 0;
|
314 | 611493d9 | bellard | if (test_bit(&src->ide, i)) {
|
315 | 611493d9 | bellard | IRQ_local_pipe(opp, i, n_IRQ); |
316 | 611493d9 | bellard | src->last_cpu = i; |
317 | 611493d9 | bellard | break;
|
318 | 611493d9 | bellard | } |
319 | 611493d9 | bellard | } |
320 | 611493d9 | bellard | } |
321 | 611493d9 | bellard | } |
322 | 611493d9 | bellard | |
323 | 54fa5af5 | bellard | void openpic_set_irq(void *opaque, int n_IRQ, int level) |
324 | 611493d9 | bellard | { |
325 | 54fa5af5 | bellard | openpic_t *opp = opaque; |
326 | 611493d9 | bellard | IRQ_src_t *src; |
327 | 611493d9 | bellard | |
328 | 611493d9 | bellard | src = &opp->src[n_IRQ]; |
329 | 611493d9 | bellard | DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
|
330 | 611493d9 | bellard | n_IRQ, level, src->ipvp); |
331 | 611493d9 | bellard | if (test_bit(&src->ipvp, IPVP_SENSE)) {
|
332 | 611493d9 | bellard | /* level-sensitive irq */
|
333 | 611493d9 | bellard | src->pending = level; |
334 | 611493d9 | bellard | if (!level)
|
335 | 611493d9 | bellard | reset_bit(&src->ipvp, IPVP_ACTIVITY); |
336 | 611493d9 | bellard | } else {
|
337 | 611493d9 | bellard | /* edge-sensitive irq */
|
338 | 611493d9 | bellard | if (level)
|
339 | 611493d9 | bellard | src->pending = 1;
|
340 | dbda808a | bellard | } |
341 | 611493d9 | bellard | openpic_update_irq(opp, n_IRQ); |
342 | dbda808a | bellard | } |
343 | dbda808a | bellard | |
344 | dbda808a | bellard | static void openpic_reset (openpic_t *opp) |
345 | dbda808a | bellard | { |
346 | dbda808a | bellard | int i;
|
347 | dbda808a | bellard | |
348 | dbda808a | bellard | opp->glbc = 0x80000000;
|
349 | f8407028 | bellard | /* Initialise controller registers */
|
350 | dbda808a | bellard | opp->frep = ((EXT_IRQ - 1) << 16) | ((MAX_CPU - 1) << 8) | VID; |
351 | dbda808a | bellard | opp->veni = VENI; |
352 | dbda808a | bellard | opp->spve = 0x000000FF;
|
353 | dbda808a | bellard | opp->tifr = 0x003F7A00;
|
354 | dbda808a | bellard | /* ? */
|
355 | dbda808a | bellard | opp->micr = 0x00000000;
|
356 | dbda808a | bellard | /* Initialise IRQ sources */
|
357 | dbda808a | bellard | for (i = 0; i < MAX_IRQ; i++) { |
358 | dbda808a | bellard | opp->src[i].ipvp = 0xA0000000;
|
359 | dbda808a | bellard | opp->src[i].ide = 0x00000000;
|
360 | dbda808a | bellard | } |
361 | dbda808a | bellard | /* Initialise IRQ destinations */
|
362 | dbda808a | bellard | for (i = 0; i < opp->nb_cpus; i++) { |
363 | dbda808a | bellard | opp->dst[i].pctp = 0x0000000F;
|
364 | dbda808a | bellard | opp->dst[i].pcsr = 0x00000000;
|
365 | dbda808a | bellard | memset(&opp->dst[i].raised, 0, sizeof(IRQ_queue_t)); |
366 | dbda808a | bellard | memset(&opp->dst[i].servicing, 0, sizeof(IRQ_queue_t)); |
367 | dbda808a | bellard | } |
368 | dbda808a | bellard | /* Initialise timers */
|
369 | dbda808a | bellard | for (i = 0; i < MAX_TMR; i++) { |
370 | dbda808a | bellard | opp->timers[i].ticc = 0x00000000;
|
371 | dbda808a | bellard | opp->timers[i].tibc = 0x80000000;
|
372 | dbda808a | bellard | } |
373 | dbda808a | bellard | /* Initialise doorbells */
|
374 | dbda808a | bellard | #if MAX_DBL > 0 |
375 | dbda808a | bellard | opp->dar = 0x00000000;
|
376 | dbda808a | bellard | for (i = 0; i < MAX_DBL; i++) { |
377 | dbda808a | bellard | opp->doorbells[i].dmr = 0x00000000;
|
378 | dbda808a | bellard | } |
379 | dbda808a | bellard | #endif
|
380 | dbda808a | bellard | /* Initialise mailboxes */
|
381 | dbda808a | bellard | #if MAX_MBX > 0 |
382 | dbda808a | bellard | for (i = 0; i < MAX_MBX; i++) { /* ? */ |
383 | dbda808a | bellard | opp->mailboxes[i].mbr = 0x00000000;
|
384 | dbda808a | bellard | } |
385 | dbda808a | bellard | #endif
|
386 | dbda808a | bellard | /* Go out of RESET state */
|
387 | dbda808a | bellard | opp->glbc = 0x00000000;
|
388 | dbda808a | bellard | } |
389 | dbda808a | bellard | |
390 | dbda808a | bellard | static inline uint32_t read_IRQreg (openpic_t *opp, int n_IRQ, uint32_t reg) |
391 | dbda808a | bellard | { |
392 | dbda808a | bellard | uint32_t retval; |
393 | dbda808a | bellard | |
394 | dbda808a | bellard | switch (reg) {
|
395 | dbda808a | bellard | case IRQ_IPVP:
|
396 | dbda808a | bellard | retval = opp->src[n_IRQ].ipvp; |
397 | dbda808a | bellard | break;
|
398 | dbda808a | bellard | case IRQ_IDE:
|
399 | dbda808a | bellard | retval = opp->src[n_IRQ].ide; |
400 | dbda808a | bellard | break;
|
401 | dbda808a | bellard | } |
402 | dbda808a | bellard | |
403 | dbda808a | bellard | return retval;
|
404 | dbda808a | bellard | } |
405 | dbda808a | bellard | |
406 | dbda808a | bellard | static inline void write_IRQreg (openpic_t *opp, int n_IRQ, |
407 | dbda808a | bellard | uint32_t reg, uint32_t val) |
408 | dbda808a | bellard | { |
409 | dbda808a | bellard | uint32_t tmp; |
410 | dbda808a | bellard | |
411 | dbda808a | bellard | switch (reg) {
|
412 | dbda808a | bellard | case IRQ_IPVP:
|
413 | 611493d9 | bellard | /* NOTE: not fully accurate for special IRQs, but simple and
|
414 | 611493d9 | bellard | sufficient */
|
415 | 611493d9 | bellard | /* ACTIVITY bit is read-only */
|
416 | 611493d9 | bellard | opp->src[n_IRQ].ipvp = |
417 | 611493d9 | bellard | (opp->src[n_IRQ].ipvp & 0x40000000) |
|
418 | 611493d9 | bellard | (val & 0x800F00FF);
|
419 | 611493d9 | bellard | openpic_update_irq(opp, n_IRQ); |
420 | 611493d9 | bellard | DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n",
|
421 | 611493d9 | bellard | n_IRQ, val, opp->src[n_IRQ].ipvp); |
422 | dbda808a | bellard | break;
|
423 | dbda808a | bellard | case IRQ_IDE:
|
424 | dbda808a | bellard | tmp = val & 0xC0000000;
|
425 | dbda808a | bellard | tmp |= val & ((1 << MAX_CPU) - 1); |
426 | dbda808a | bellard | opp->src[n_IRQ].ide = tmp; |
427 | dbda808a | bellard | DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ, opp->src[n_IRQ].ide);
|
428 | dbda808a | bellard | break;
|
429 | dbda808a | bellard | } |
430 | dbda808a | bellard | } |
431 | dbda808a | bellard | |
432 | dbda808a | bellard | #if 0 // Code provision for Intel model
|
433 | dbda808a | bellard | #if MAX_DBL > 0
|
434 | dbda808a | bellard | static uint32_t read_doorbell_register (openpic_t *opp,
|
435 | dbda808a | bellard | int n_dbl, uint32_t offset)
|
436 | dbda808a | bellard | {
|
437 | dbda808a | bellard | uint32_t retval;
|
438 | dbda808a | bellard | |
439 | dbda808a | bellard | switch (offset) {
|
440 | dbda808a | bellard | case DBL_IPVP_OFFSET:
|
441 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IPVP);
|
442 | dbda808a | bellard | break;
|
443 | dbda808a | bellard | case DBL_IDE_OFFSET:
|
444 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IDE);
|
445 | dbda808a | bellard | break;
|
446 | dbda808a | bellard | case DBL_DMR_OFFSET:
|
447 | dbda808a | bellard | retval = opp->doorbells[n_dbl].dmr;
|
448 | dbda808a | bellard | break;
|
449 | dbda808a | bellard | }
|
450 | dbda808a | bellard | |
451 | dbda808a | bellard | return retval;
|
452 | dbda808a | bellard | }
|
453 | dbda808a | bellard |
|
454 | dbda808a | bellard | static void write_doorbell_register (penpic_t *opp, int n_dbl,
|
455 | dbda808a | bellard | uint32_t offset, uint32_t value)
|
456 | dbda808a | bellard | {
|
457 | dbda808a | bellard | switch (offset) {
|
458 | dbda808a | bellard | case DBL_IVPR_OFFSET:
|
459 | dbda808a | bellard | write_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IPVP, value);
|
460 | dbda808a | bellard | break;
|
461 | dbda808a | bellard | case DBL_IDE_OFFSET:
|
462 | dbda808a | bellard | write_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IDE, value);
|
463 | dbda808a | bellard | break;
|
464 | dbda808a | bellard | case DBL_DMR_OFFSET:
|
465 | dbda808a | bellard | opp->doorbells[n_dbl].dmr = value;
|
466 | dbda808a | bellard | break;
|
467 | dbda808a | bellard | }
|
468 | dbda808a | bellard | }
|
469 | dbda808a | bellard | #endif
|
470 | dbda808a | bellard | |
471 | dbda808a | bellard | #if MAX_MBX > 0 |
472 | dbda808a | bellard | static uint32_t read_mailbox_register (openpic_t *opp,
|
473 | dbda808a | bellard | int n_mbx, uint32_t offset)
|
474 | dbda808a | bellard | { |
475 | dbda808a | bellard | uint32_t retval; |
476 | dbda808a | bellard | |
477 | dbda808a | bellard | switch (offset) {
|
478 | dbda808a | bellard | case MBX_MBR_OFFSET:
|
479 | dbda808a | bellard | retval = opp->mailboxes[n_mbx].mbr; |
480 | dbda808a | bellard | break;
|
481 | dbda808a | bellard | case MBX_IVPR_OFFSET:
|
482 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IPVP); |
483 | dbda808a | bellard | break;
|
484 | dbda808a | bellard | case MBX_DMR_OFFSET:
|
485 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IDE); |
486 | dbda808a | bellard | break;
|
487 | dbda808a | bellard | } |
488 | dbda808a | bellard | |
489 | dbda808a | bellard | return retval;
|
490 | dbda808a | bellard | } |
491 | dbda808a | bellard | |
492 | dbda808a | bellard | static void write_mailbox_register (openpic_t *opp, int n_mbx, |
493 | dbda808a | bellard | uint32_t address, uint32_t value) |
494 | dbda808a | bellard | { |
495 | dbda808a | bellard | switch (offset) {
|
496 | dbda808a | bellard | case MBX_MBR_OFFSET:
|
497 | dbda808a | bellard | opp->mailboxes[n_mbx].mbr = value; |
498 | dbda808a | bellard | break;
|
499 | dbda808a | bellard | case MBX_IVPR_OFFSET:
|
500 | dbda808a | bellard | write_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IPVP, value); |
501 | dbda808a | bellard | break;
|
502 | dbda808a | bellard | case MBX_DMR_OFFSET:
|
503 | dbda808a | bellard | write_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IDE, value); |
504 | dbda808a | bellard | break;
|
505 | dbda808a | bellard | } |
506 | dbda808a | bellard | } |
507 | dbda808a | bellard | #endif
|
508 | dbda808a | bellard | #endif /* 0 : Code provision for Intel model */ |
509 | dbda808a | bellard | |
510 | dbda808a | bellard | static void openpic_gbl_write (void *opaque, uint32_t addr, uint32_t val) |
511 | dbda808a | bellard | { |
512 | dbda808a | bellard | openpic_t *opp = opaque; |
513 | dbda808a | bellard | |
514 | dbda808a | bellard | DPRINTF("%s: addr %08x <= %08x\n", __func__, addr, val);
|
515 | dbda808a | bellard | if (addr & 0xF) |
516 | dbda808a | bellard | return;
|
517 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
518 | dbda808a | bellard | val = bswap32(val); |
519 | dbda808a | bellard | #endif
|
520 | dbda808a | bellard | addr &= 0xFF;
|
521 | dbda808a | bellard | switch (addr) {
|
522 | dbda808a | bellard | case 0x00: /* FREP */ |
523 | dbda808a | bellard | break;
|
524 | dbda808a | bellard | case 0x20: /* GLBC */ |
525 | dbda808a | bellard | if (val & 0x80000000) |
526 | dbda808a | bellard | openpic_reset(opp); |
527 | dbda808a | bellard | opp->glbc = val & ~0x80000000;
|
528 | dbda808a | bellard | break;
|
529 | dbda808a | bellard | case 0x80: /* VENI */ |
530 | dbda808a | bellard | break;
|
531 | dbda808a | bellard | case 0x90: /* PINT */ |
532 | dbda808a | bellard | /* XXX: Should be able to reset any CPU */
|
533 | dbda808a | bellard | if (val & 1) { |
534 | dbda808a | bellard | DPRINTF("Reset CPU IRQ\n");
|
535 | dbda808a | bellard | // cpu_interrupt(cpu_single_env, CPU_INTERRUPT_RESET);
|
536 | dbda808a | bellard | } |
537 | dbda808a | bellard | break;
|
538 | dbda808a | bellard | #if MAX_IPI > 0 |
539 | dbda808a | bellard | case 0xA0: /* IPI_IPVP */ |
540 | dbda808a | bellard | case 0xB0: |
541 | dbda808a | bellard | case 0xC0: |
542 | dbda808a | bellard | case 0xD0: |
543 | dbda808a | bellard | { |
544 | dbda808a | bellard | int idx;
|
545 | dbda808a | bellard | idx = (addr - 0xA0) >> 4; |
546 | dbda808a | bellard | write_IRQreg(opp, IRQ_IPI0 + idx, IRQ_IPVP, val); |
547 | dbda808a | bellard | } |
548 | dbda808a | bellard | break;
|
549 | dbda808a | bellard | #endif
|
550 | dbda808a | bellard | case 0xE0: /* SPVE */ |
551 | dbda808a | bellard | opp->spve = val & 0x000000FF;
|
552 | dbda808a | bellard | break;
|
553 | dbda808a | bellard | case 0xF0: /* TIFR */ |
554 | dbda808a | bellard | opp->tifr = val; |
555 | dbda808a | bellard | break;
|
556 | dbda808a | bellard | default:
|
557 | dbda808a | bellard | break;
|
558 | dbda808a | bellard | } |
559 | dbda808a | bellard | } |
560 | dbda808a | bellard | |
561 | dbda808a | bellard | static uint32_t openpic_gbl_read (void *opaque, uint32_t addr) |
562 | dbda808a | bellard | { |
563 | dbda808a | bellard | openpic_t *opp = opaque; |
564 | dbda808a | bellard | uint32_t retval; |
565 | dbda808a | bellard | |
566 | dbda808a | bellard | DPRINTF("%s: addr %08x\n", __func__, addr);
|
567 | dbda808a | bellard | retval = 0xFFFFFFFF;
|
568 | dbda808a | bellard | if (addr & 0xF) |
569 | dbda808a | bellard | return retval;
|
570 | dbda808a | bellard | addr &= 0xFF;
|
571 | dbda808a | bellard | switch (addr) {
|
572 | dbda808a | bellard | case 0x00: /* FREP */ |
573 | dbda808a | bellard | retval = opp->frep; |
574 | dbda808a | bellard | break;
|
575 | dbda808a | bellard | case 0x20: /* GLBC */ |
576 | dbda808a | bellard | retval = opp->glbc; |
577 | dbda808a | bellard | break;
|
578 | dbda808a | bellard | case 0x80: /* VENI */ |
579 | dbda808a | bellard | retval = opp->veni; |
580 | dbda808a | bellard | break;
|
581 | dbda808a | bellard | case 0x90: /* PINT */ |
582 | dbda808a | bellard | retval = 0x00000000;
|
583 | dbda808a | bellard | break;
|
584 | dbda808a | bellard | #if MAX_IPI > 0 |
585 | dbda808a | bellard | case 0xA0: /* IPI_IPVP */ |
586 | dbda808a | bellard | case 0xB0: |
587 | dbda808a | bellard | case 0xC0: |
588 | dbda808a | bellard | case 0xD0: |
589 | dbda808a | bellard | { |
590 | dbda808a | bellard | int idx;
|
591 | dbda808a | bellard | idx = (addr - 0xA0) >> 4; |
592 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_IPI0 + idx, IRQ_IPVP); |
593 | dbda808a | bellard | } |
594 | dbda808a | bellard | break;
|
595 | dbda808a | bellard | #endif
|
596 | dbda808a | bellard | case 0xE0: /* SPVE */ |
597 | dbda808a | bellard | retval = opp->spve; |
598 | dbda808a | bellard | break;
|
599 | dbda808a | bellard | case 0xF0: /* TIFR */ |
600 | dbda808a | bellard | retval = opp->tifr; |
601 | dbda808a | bellard | break;
|
602 | dbda808a | bellard | default:
|
603 | dbda808a | bellard | break;
|
604 | dbda808a | bellard | } |
605 | dbda808a | bellard | DPRINTF("%s: => %08x\n", __func__, retval);
|
606 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
607 | dbda808a | bellard | retval = bswap32(retval); |
608 | dbda808a | bellard | #endif
|
609 | dbda808a | bellard | |
610 | dbda808a | bellard | return retval;
|
611 | dbda808a | bellard | } |
612 | dbda808a | bellard | |
613 | dbda808a | bellard | static void openpic_timer_write (void *opaque, uint32_t addr, uint32_t val) |
614 | dbda808a | bellard | { |
615 | dbda808a | bellard | openpic_t *opp = opaque; |
616 | dbda808a | bellard | int idx;
|
617 | dbda808a | bellard | |
618 | dbda808a | bellard | DPRINTF("%s: addr %08x <= %08x\n", __func__, addr, val);
|
619 | dbda808a | bellard | if (addr & 0xF) |
620 | dbda808a | bellard | return;
|
621 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
622 | dbda808a | bellard | val = bswap32(val); |
623 | dbda808a | bellard | #endif
|
624 | dbda808a | bellard | addr -= 0x1100;
|
625 | dbda808a | bellard | addr &= 0xFFFF;
|
626 | dbda808a | bellard | idx = (addr & 0xFFF0) >> 6; |
627 | dbda808a | bellard | addr = addr & 0x30;
|
628 | dbda808a | bellard | switch (addr) {
|
629 | dbda808a | bellard | case 0x00: /* TICC */ |
630 | dbda808a | bellard | break;
|
631 | dbda808a | bellard | case 0x10: /* TIBC */ |
632 | dbda808a | bellard | if ((opp->timers[idx].ticc & 0x80000000) != 0 && |
633 | 8adbc566 | bellard | (val & 0x80000000) == 0 && |
634 | dbda808a | bellard | (opp->timers[idx].tibc & 0x80000000) != 0) |
635 | dbda808a | bellard | opp->timers[idx].ticc &= ~0x80000000;
|
636 | dbda808a | bellard | opp->timers[idx].tibc = val; |
637 | dbda808a | bellard | break;
|
638 | dbda808a | bellard | case 0x20: /* TIVP */ |
639 | dbda808a | bellard | write_IRQreg(opp, IRQ_TIM0 + idx, IRQ_IPVP, val); |
640 | dbda808a | bellard | break;
|
641 | dbda808a | bellard | case 0x30: /* TIDE */ |
642 | dbda808a | bellard | write_IRQreg(opp, IRQ_TIM0 + idx, IRQ_IDE, val); |
643 | dbda808a | bellard | break;
|
644 | dbda808a | bellard | } |
645 | dbda808a | bellard | } |
646 | dbda808a | bellard | |
647 | dbda808a | bellard | static uint32_t openpic_timer_read (void *opaque, uint32_t addr) |
648 | dbda808a | bellard | { |
649 | dbda808a | bellard | openpic_t *opp = opaque; |
650 | dbda808a | bellard | uint32_t retval; |
651 | dbda808a | bellard | int idx;
|
652 | dbda808a | bellard | |
653 | dbda808a | bellard | DPRINTF("%s: addr %08x\n", __func__, addr);
|
654 | dbda808a | bellard | retval = 0xFFFFFFFF;
|
655 | dbda808a | bellard | if (addr & 0xF) |
656 | dbda808a | bellard | return retval;
|
657 | dbda808a | bellard | addr -= 0x1100;
|
658 | dbda808a | bellard | addr &= 0xFFFF;
|
659 | dbda808a | bellard | idx = (addr & 0xFFF0) >> 6; |
660 | dbda808a | bellard | addr = addr & 0x30;
|
661 | dbda808a | bellard | switch (addr) {
|
662 | dbda808a | bellard | case 0x00: /* TICC */ |
663 | dbda808a | bellard | retval = opp->timers[idx].ticc; |
664 | dbda808a | bellard | break;
|
665 | dbda808a | bellard | case 0x10: /* TIBC */ |
666 | dbda808a | bellard | retval = opp->timers[idx].tibc; |
667 | dbda808a | bellard | break;
|
668 | dbda808a | bellard | case 0x20: /* TIPV */ |
669 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_TIM0 + idx, IRQ_IPVP); |
670 | dbda808a | bellard | break;
|
671 | dbda808a | bellard | case 0x30: /* TIDE */ |
672 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_TIM0 + idx, IRQ_IDE); |
673 | dbda808a | bellard | break;
|
674 | dbda808a | bellard | } |
675 | dbda808a | bellard | DPRINTF("%s: => %08x\n", __func__, retval);
|
676 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
677 | dbda808a | bellard | retval = bswap32(retval); |
678 | dbda808a | bellard | #endif
|
679 | dbda808a | bellard | |
680 | dbda808a | bellard | return retval;
|
681 | dbda808a | bellard | } |
682 | dbda808a | bellard | |
683 | dbda808a | bellard | static void openpic_src_write (void *opaque, uint32_t addr, uint32_t val) |
684 | dbda808a | bellard | { |
685 | dbda808a | bellard | openpic_t *opp = opaque; |
686 | dbda808a | bellard | int idx;
|
687 | dbda808a | bellard | |
688 | dbda808a | bellard | DPRINTF("%s: addr %08x <= %08x\n", __func__, addr, val);
|
689 | dbda808a | bellard | if (addr & 0xF) |
690 | dbda808a | bellard | return;
|
691 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
692 | dbda808a | bellard | val = tswap32(val); |
693 | dbda808a | bellard | #endif
|
694 | dbda808a | bellard | addr = addr & 0xFFF0;
|
695 | dbda808a | bellard | idx = addr >> 5;
|
696 | dbda808a | bellard | if (addr & 0x10) { |
697 | dbda808a | bellard | /* EXDE / IFEDE / IEEDE */
|
698 | dbda808a | bellard | write_IRQreg(opp, idx, IRQ_IDE, val); |
699 | dbda808a | bellard | } else {
|
700 | dbda808a | bellard | /* EXVP / IFEVP / IEEVP */
|
701 | dbda808a | bellard | write_IRQreg(opp, idx, IRQ_IPVP, val); |
702 | dbda808a | bellard | } |
703 | dbda808a | bellard | } |
704 | dbda808a | bellard | |
705 | dbda808a | bellard | static uint32_t openpic_src_read (void *opaque, uint32_t addr) |
706 | dbda808a | bellard | { |
707 | dbda808a | bellard | openpic_t *opp = opaque; |
708 | dbda808a | bellard | uint32_t retval; |
709 | dbda808a | bellard | int idx;
|
710 | dbda808a | bellard | |
711 | dbda808a | bellard | DPRINTF("%s: addr %08x\n", __func__, addr);
|
712 | dbda808a | bellard | retval = 0xFFFFFFFF;
|
713 | dbda808a | bellard | if (addr & 0xF) |
714 | dbda808a | bellard | return retval;
|
715 | dbda808a | bellard | addr = addr & 0xFFF0;
|
716 | dbda808a | bellard | idx = addr >> 5;
|
717 | dbda808a | bellard | if (addr & 0x10) { |
718 | dbda808a | bellard | /* EXDE / IFEDE / IEEDE */
|
719 | dbda808a | bellard | retval = read_IRQreg(opp, idx, IRQ_IDE); |
720 | dbda808a | bellard | } else {
|
721 | dbda808a | bellard | /* EXVP / IFEVP / IEEVP */
|
722 | dbda808a | bellard | retval = read_IRQreg(opp, idx, IRQ_IPVP); |
723 | dbda808a | bellard | } |
724 | dbda808a | bellard | DPRINTF("%s: => %08x\n", __func__, retval);
|
725 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
726 | dbda808a | bellard | retval = tswap32(retval); |
727 | dbda808a | bellard | #endif
|
728 | dbda808a | bellard | |
729 | dbda808a | bellard | return retval;
|
730 | dbda808a | bellard | } |
731 | dbda808a | bellard | |
732 | dbda808a | bellard | static void openpic_cpu_write (void *opaque, uint32_t addr, uint32_t val) |
733 | dbda808a | bellard | { |
734 | dbda808a | bellard | openpic_t *opp = opaque; |
735 | dbda808a | bellard | IRQ_src_t *src; |
736 | dbda808a | bellard | IRQ_dst_t *dst; |
737 | dbda808a | bellard | int idx, n_IRQ;
|
738 | dbda808a | bellard | |
739 | dbda808a | bellard | DPRINTF("%s: addr %08x <= %08x\n", __func__, addr, val);
|
740 | dbda808a | bellard | if (addr & 0xF) |
741 | dbda808a | bellard | return;
|
742 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
743 | dbda808a | bellard | val = bswap32(val); |
744 | dbda808a | bellard | #endif
|
745 | dbda808a | bellard | addr &= 0x1FFF0;
|
746 | dbda808a | bellard | idx = addr / 0x1000;
|
747 | dbda808a | bellard | dst = &opp->dst[idx]; |
748 | dbda808a | bellard | addr &= 0xFF0;
|
749 | dbda808a | bellard | switch (addr) {
|
750 | dbda808a | bellard | #if MAX_IPI > 0 |
751 | dbda808a | bellard | case 0x40: /* PIPD */ |
752 | dbda808a | bellard | case 0x50: |
753 | dbda808a | bellard | case 0x60: |
754 | dbda808a | bellard | case 0x70: |
755 | dbda808a | bellard | idx = (addr - 0x40) >> 4; |
756 | dbda808a | bellard | write_IRQreg(opp, IRQ_IPI0 + idx, IRQ_IDE, val); |
757 | 611493d9 | bellard | openpic_set_irq(opp, IRQ_IPI0 + idx, 1);
|
758 | 611493d9 | bellard | openpic_set_irq(opp, IRQ_IPI0 + idx, 0);
|
759 | dbda808a | bellard | break;
|
760 | dbda808a | bellard | #endif
|
761 | dbda808a | bellard | case 0x80: /* PCTP */ |
762 | dbda808a | bellard | dst->pctp = val & 0x0000000F;
|
763 | dbda808a | bellard | break;
|
764 | dbda808a | bellard | case 0x90: /* WHOAMI */ |
765 | dbda808a | bellard | /* Read-only register */
|
766 | dbda808a | bellard | break;
|
767 | dbda808a | bellard | case 0xA0: /* PIAC */ |
768 | dbda808a | bellard | /* Read-only register */
|
769 | dbda808a | bellard | break;
|
770 | dbda808a | bellard | case 0xB0: /* PEOI */ |
771 | dbda808a | bellard | DPRINTF("PEOI\n");
|
772 | dbda808a | bellard | n_IRQ = IRQ_get_next(opp, &dst->servicing); |
773 | dbda808a | bellard | IRQ_resetbit(&dst->servicing, n_IRQ); |
774 | dbda808a | bellard | dst->servicing.next = -1;
|
775 | dbda808a | bellard | src = &opp->src[n_IRQ]; |
776 | dbda808a | bellard | /* Set up next servicing IRQ */
|
777 | dbda808a | bellard | IRQ_get_next(opp, &dst->servicing); |
778 | dbda808a | bellard | /* Check queued interrupts. */
|
779 | dbda808a | bellard | n_IRQ = IRQ_get_next(opp, &dst->raised); |
780 | dbda808a | bellard | if (n_IRQ != -1) { |
781 | dbda808a | bellard | src = &opp->src[n_IRQ]; |
782 | dbda808a | bellard | if (IPVP_PRIORITY(src->ipvp) > dst->servicing.priority) {
|
783 | dbda808a | bellard | DPRINTF("Raise CPU IRQ\n");
|
784 | dbda808a | bellard | cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HARD); |
785 | dbda808a | bellard | } |
786 | dbda808a | bellard | } |
787 | dbda808a | bellard | break;
|
788 | dbda808a | bellard | default:
|
789 | dbda808a | bellard | break;
|
790 | dbda808a | bellard | } |
791 | dbda808a | bellard | } |
792 | dbda808a | bellard | |
793 | dbda808a | bellard | static uint32_t openpic_cpu_read (void *opaque, uint32_t addr) |
794 | dbda808a | bellard | { |
795 | dbda808a | bellard | openpic_t *opp = opaque; |
796 | dbda808a | bellard | IRQ_src_t *src; |
797 | dbda808a | bellard | IRQ_dst_t *dst; |
798 | dbda808a | bellard | uint32_t retval; |
799 | dbda808a | bellard | int idx, n_IRQ;
|
800 | dbda808a | bellard | |
801 | dbda808a | bellard | DPRINTF("%s: addr %08x\n", __func__, addr);
|
802 | dbda808a | bellard | retval = 0xFFFFFFFF;
|
803 | dbda808a | bellard | if (addr & 0xF) |
804 | dbda808a | bellard | return retval;
|
805 | dbda808a | bellard | addr &= 0x1FFF0;
|
806 | dbda808a | bellard | idx = addr / 0x1000;
|
807 | dbda808a | bellard | dst = &opp->dst[idx]; |
808 | dbda808a | bellard | addr &= 0xFF0;
|
809 | dbda808a | bellard | switch (addr) {
|
810 | dbda808a | bellard | case 0x80: /* PCTP */ |
811 | dbda808a | bellard | retval = dst->pctp; |
812 | dbda808a | bellard | break;
|
813 | dbda808a | bellard | case 0x90: /* WHOAMI */ |
814 | dbda808a | bellard | retval = idx; |
815 | dbda808a | bellard | break;
|
816 | dbda808a | bellard | case 0xA0: /* PIAC */ |
817 | dbda808a | bellard | n_IRQ = IRQ_get_next(opp, &dst->raised); |
818 | dbda808a | bellard | DPRINTF("PIAC: irq=%d\n", n_IRQ);
|
819 | dbda808a | bellard | if (n_IRQ == -1) { |
820 | dbda808a | bellard | /* No more interrupt pending */
|
821 | dbda808a | bellard | retval = opp->spve; |
822 | dbda808a | bellard | } else {
|
823 | dbda808a | bellard | src = &opp->src[n_IRQ]; |
824 | dbda808a | bellard | if (!test_bit(&src->ipvp, IPVP_ACTIVITY) ||
|
825 | dbda808a | bellard | !(IPVP_PRIORITY(src->ipvp) > dst->pctp)) { |
826 | dbda808a | bellard | /* - Spurious level-sensitive IRQ
|
827 | dbda808a | bellard | * - Priorities has been changed
|
828 | dbda808a | bellard | * and the pending IRQ isn't allowed anymore
|
829 | dbda808a | bellard | */
|
830 | dbda808a | bellard | reset_bit(&src->ipvp, IPVP_ACTIVITY); |
831 | dbda808a | bellard | retval = IPVP_VECTOR(opp->spve); |
832 | dbda808a | bellard | } else {
|
833 | dbda808a | bellard | /* IRQ enter servicing state */
|
834 | dbda808a | bellard | IRQ_setbit(&dst->servicing, n_IRQ); |
835 | dbda808a | bellard | retval = IPVP_VECTOR(src->ipvp); |
836 | dbda808a | bellard | } |
837 | dbda808a | bellard | IRQ_resetbit(&dst->raised, n_IRQ); |
838 | dbda808a | bellard | dst->raised.next = -1;
|
839 | 611493d9 | bellard | if (!test_bit(&src->ipvp, IPVP_SENSE)) {
|
840 | 611493d9 | bellard | /* edge-sensitive IRQ */
|
841 | dbda808a | bellard | reset_bit(&src->ipvp, IPVP_ACTIVITY); |
842 | 611493d9 | bellard | src->pending = 0;
|
843 | 611493d9 | bellard | } |
844 | dbda808a | bellard | } |
845 | dbda808a | bellard | break;
|
846 | dbda808a | bellard | case 0xB0: /* PEOI */ |
847 | dbda808a | bellard | retval = 0;
|
848 | dbda808a | bellard | break;
|
849 | dbda808a | bellard | #if MAX_IPI > 0 |
850 | dbda808a | bellard | case 0x40: /* IDE */ |
851 | dbda808a | bellard | case 0x50: |
852 | dbda808a | bellard | idx = (addr - 0x40) >> 4; |
853 | dbda808a | bellard | retval = read_IRQreg(opp, IRQ_IPI0 + idx, IRQ_IDE); |
854 | dbda808a | bellard | break;
|
855 | dbda808a | bellard | #endif
|
856 | dbda808a | bellard | default:
|
857 | dbda808a | bellard | break;
|
858 | dbda808a | bellard | } |
859 | dbda808a | bellard | DPRINTF("%s: => %08x\n", __func__, retval);
|
860 | dbda808a | bellard | #if defined OPENPIC_SWAP
|
861 | dbda808a | bellard | retval= bswap32(retval); |
862 | dbda808a | bellard | #endif
|
863 | dbda808a | bellard | |
864 | dbda808a | bellard | return retval;
|
865 | dbda808a | bellard | } |
866 | dbda808a | bellard | |
867 | dbda808a | bellard | static void openpic_buggy_write (void *opaque, |
868 | dbda808a | bellard | target_phys_addr_t addr, uint32_t val) |
869 | dbda808a | bellard | { |
870 | dbda808a | bellard | printf("Invalid OPENPIC write access !\n");
|
871 | dbda808a | bellard | } |
872 | dbda808a | bellard | |
873 | dbda808a | bellard | static uint32_t openpic_buggy_read (void *opaque, target_phys_addr_t addr) |
874 | dbda808a | bellard | { |
875 | dbda808a | bellard | printf("Invalid OPENPIC read access !\n");
|
876 | dbda808a | bellard | |
877 | dbda808a | bellard | return -1; |
878 | dbda808a | bellard | } |
879 | dbda808a | bellard | |
880 | dbda808a | bellard | static void openpic_writel (void *opaque, |
881 | dbda808a | bellard | target_phys_addr_t addr, uint32_t val) |
882 | dbda808a | bellard | { |
883 | dbda808a | bellard | openpic_t *opp = opaque; |
884 | dbda808a | bellard | |
885 | dbda808a | bellard | addr &= 0x3FFFF;
|
886 | 611493d9 | bellard | DPRINTF("%s: offset %08x val: %08x\n", __func__, (int)addr, val); |
887 | dbda808a | bellard | if (addr < 0x1100) { |
888 | dbda808a | bellard | /* Global registers */
|
889 | dbda808a | bellard | openpic_gbl_write(opp, addr, val); |
890 | dbda808a | bellard | } else if (addr < 0x10000) { |
891 | dbda808a | bellard | /* Timers registers */
|
892 | dbda808a | bellard | openpic_timer_write(opp, addr, val); |
893 | dbda808a | bellard | } else if (addr < 0x20000) { |
894 | dbda808a | bellard | /* Source registers */
|
895 | dbda808a | bellard | openpic_src_write(opp, addr, val); |
896 | dbda808a | bellard | } else {
|
897 | dbda808a | bellard | /* CPU registers */
|
898 | dbda808a | bellard | openpic_cpu_write(opp, addr, val); |
899 | dbda808a | bellard | } |
900 | dbda808a | bellard | } |
901 | dbda808a | bellard | |
902 | dbda808a | bellard | static uint32_t openpic_readl (void *opaque,target_phys_addr_t addr) |
903 | dbda808a | bellard | { |
904 | dbda808a | bellard | openpic_t *opp = opaque; |
905 | dbda808a | bellard | uint32_t retval; |
906 | dbda808a | bellard | |
907 | dbda808a | bellard | addr &= 0x3FFFF;
|
908 | 611493d9 | bellard | DPRINTF("%s: offset %08x\n", __func__, (int)addr); |
909 | dbda808a | bellard | if (addr < 0x1100) { |
910 | dbda808a | bellard | /* Global registers */
|
911 | dbda808a | bellard | retval = openpic_gbl_read(opp, addr); |
912 | dbda808a | bellard | } else if (addr < 0x10000) { |
913 | dbda808a | bellard | /* Timers registers */
|
914 | dbda808a | bellard | retval = openpic_timer_read(opp, addr); |
915 | dbda808a | bellard | } else if (addr < 0x20000) { |
916 | dbda808a | bellard | /* Source registers */
|
917 | dbda808a | bellard | retval = openpic_src_read(opp, addr); |
918 | dbda808a | bellard | } else {
|
919 | dbda808a | bellard | /* CPU registers */
|
920 | dbda808a | bellard | retval = openpic_cpu_read(opp, addr); |
921 | dbda808a | bellard | } |
922 | dbda808a | bellard | |
923 | dbda808a | bellard | return retval;
|
924 | dbda808a | bellard | } |
925 | dbda808a | bellard | |
926 | dbda808a | bellard | static CPUWriteMemoryFunc *openpic_write[] = {
|
927 | dbda808a | bellard | &openpic_buggy_write, |
928 | dbda808a | bellard | &openpic_buggy_write, |
929 | dbda808a | bellard | &openpic_writel, |
930 | dbda808a | bellard | }; |
931 | dbda808a | bellard | |
932 | dbda808a | bellard | static CPUReadMemoryFunc *openpic_read[] = {
|
933 | dbda808a | bellard | &openpic_buggy_read, |
934 | dbda808a | bellard | &openpic_buggy_read, |
935 | dbda808a | bellard | &openpic_readl, |
936 | dbda808a | bellard | }; |
937 | dbda808a | bellard | |
938 | dbda808a | bellard | static void openpic_map(PCIDevice *pci_dev, int region_num, |
939 | dbda808a | bellard | uint32_t addr, uint32_t size, int type)
|
940 | dbda808a | bellard | { |
941 | dbda808a | bellard | openpic_t *opp; |
942 | dbda808a | bellard | |
943 | dbda808a | bellard | DPRINTF("Map OpenPIC\n");
|
944 | dbda808a | bellard | opp = (openpic_t *)pci_dev; |
945 | dbda808a | bellard | /* Global registers */
|
946 | dbda808a | bellard | DPRINTF("Register OPENPIC gbl %08x => %08x\n",
|
947 | dbda808a | bellard | addr + 0x1000, addr + 0x1000 + 0x100); |
948 | dbda808a | bellard | /* Timer registers */
|
949 | dbda808a | bellard | DPRINTF("Register OPENPIC timer %08x => %08x\n",
|
950 | dbda808a | bellard | addr + 0x1100, addr + 0x1100 + 0x40 * MAX_TMR); |
951 | dbda808a | bellard | /* Interrupt source registers */
|
952 | dbda808a | bellard | DPRINTF("Register OPENPIC src %08x => %08x\n",
|
953 | dbda808a | bellard | addr + 0x10000, addr + 0x10000 + 0x20 * (EXT_IRQ + 2)); |
954 | dbda808a | bellard | /* Per CPU registers */
|
955 | dbda808a | bellard | DPRINTF("Register OPENPIC dst %08x => %08x\n",
|
956 | dbda808a | bellard | addr + 0x20000, addr + 0x20000 + 0x1000 * MAX_CPU); |
957 | 91d848eb | bellard | cpu_register_physical_memory(addr, 0x40000, opp->mem_index);
|
958 | dbda808a | bellard | #if 0 // Don't implement ISU for now
|
959 | dbda808a | bellard | opp_io_memory = cpu_register_io_memory(0, openpic_src_read,
|
960 | dbda808a | bellard | openpic_src_write);
|
961 | dbda808a | bellard | cpu_register_physical_memory(isu_base, 0x20 * (EXT_IRQ + 2),
|
962 | dbda808a | bellard | opp_io_memory);
|
963 | dbda808a | bellard | #endif
|
964 | dbda808a | bellard | } |
965 | dbda808a | bellard | |
966 | 91d848eb | bellard | openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus) |
967 | dbda808a | bellard | { |
968 | dbda808a | bellard | openpic_t *opp; |
969 | dbda808a | bellard | uint8_t *pci_conf; |
970 | dbda808a | bellard | int i, m;
|
971 | dbda808a | bellard | |
972 | dbda808a | bellard | /* XXX: for now, only one CPU is supported */
|
973 | dbda808a | bellard | if (nb_cpus != 1) |
974 | dbda808a | bellard | return NULL; |
975 | 91d848eb | bellard | if (bus) {
|
976 | 91d848eb | bellard | opp = (openpic_t *)pci_register_device(bus, "OpenPIC", sizeof(openpic_t), |
977 | 91d848eb | bellard | -1, NULL, NULL); |
978 | 91d848eb | bellard | if (opp == NULL) |
979 | 91d848eb | bellard | return NULL; |
980 | 91d848eb | bellard | pci_conf = opp->pci_dev.config; |
981 | 91d848eb | bellard | pci_conf[0x00] = 0x14; // IBM MPIC2 |
982 | 91d848eb | bellard | pci_conf[0x01] = 0x10; |
983 | 91d848eb | bellard | pci_conf[0x02] = 0xFF; |
984 | 91d848eb | bellard | pci_conf[0x03] = 0xFF; |
985 | 91d848eb | bellard | pci_conf[0x0a] = 0x80; // PIC |
986 | 91d848eb | bellard | pci_conf[0x0b] = 0x08; |
987 | 91d848eb | bellard | pci_conf[0x0e] = 0x00; // header_type |
988 | 91d848eb | bellard | pci_conf[0x3d] = 0x00; // no interrupt pin |
989 | 91d848eb | bellard | |
990 | 91d848eb | bellard | /* Register I/O spaces */
|
991 | 91d848eb | bellard | pci_register_io_region((PCIDevice *)opp, 0, 0x40000, |
992 | 91d848eb | bellard | PCI_ADDRESS_SPACE_MEM, &openpic_map); |
993 | 91d848eb | bellard | } else {
|
994 | 91d848eb | bellard | opp = qemu_mallocz(sizeof(openpic_t));
|
995 | 91d848eb | bellard | } |
996 | 91d848eb | bellard | |
997 | 91d848eb | bellard | opp->mem_index = cpu_register_io_memory(0, openpic_read,
|
998 | 91d848eb | bellard | openpic_write, opp); |
999 | 91d848eb | bellard | |
1000 | 91d848eb | bellard | // isu_base &= 0xFFFC0000;
|
1001 | dbda808a | bellard | opp->nb_cpus = nb_cpus; |
1002 | dbda808a | bellard | /* Set IRQ types */
|
1003 | dbda808a | bellard | for (i = 0; i < EXT_IRQ; i++) { |
1004 | dbda808a | bellard | opp->src[i].type = IRQ_EXTERNAL; |
1005 | dbda808a | bellard | } |
1006 | dbda808a | bellard | for (; i < IRQ_TIM0; i++) {
|
1007 | dbda808a | bellard | opp->src[i].type = IRQ_SPECIAL; |
1008 | dbda808a | bellard | } |
1009 | dbda808a | bellard | #if MAX_IPI > 0 |
1010 | dbda808a | bellard | m = IRQ_IPI0; |
1011 | dbda808a | bellard | #else
|
1012 | dbda808a | bellard | m = IRQ_DBL0; |
1013 | dbda808a | bellard | #endif
|
1014 | dbda808a | bellard | for (; i < m; i++) {
|
1015 | dbda808a | bellard | opp->src[i].type = IRQ_TIMER; |
1016 | dbda808a | bellard | } |
1017 | dbda808a | bellard | for (; i < MAX_IRQ; i++) {
|
1018 | dbda808a | bellard | opp->src[i].type = IRQ_INTERNAL; |
1019 | dbda808a | bellard | } |
1020 | dbda808a | bellard | openpic_reset(opp); |
1021 | 91d848eb | bellard | if (pmem_index)
|
1022 | 91d848eb | bellard | *pmem_index = opp->mem_index; |
1023 | dbda808a | bellard | return opp;
|
1024 | dbda808a | bellard | } |