aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorScott Wood <scottwood@freescale.com>2013-04-12 10:08:45 -0400
committerAlexander Graf <agraf@suse.de>2013-04-26 14:27:22 -0400
commitf0f5c481a91c56f1ee5b3809bf3943115143b1a7 (patch)
tree3d847ef618656c310e7d4daffe6ed9891095b0e1 /arch/powerpc
parent6dd830a09a245c068aad2d10ff6d35c5d81cf2b6 (diff)
kvm/ppc/mpic: adapt to kernel style and environment
Remove braces that Linux style doesn't permit, remove space after '*' that Lindent added, keep error/debug strings contiguous, etc. Substitute type names, debug prints, etc. Signed-off-by: Scott Wood <scottwood@freescale.com> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/kvm/mpic.c445
1 files changed, 208 insertions, 237 deletions
diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index d6d70a473d7f..1df67aed7a91 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -42,22 +42,22 @@
42#define OPENPIC_TMR_REG_SIZE 0x220 42#define OPENPIC_TMR_REG_SIZE 0x220
43#define OPENPIC_MSI_REG_START 0x1600 43#define OPENPIC_MSI_REG_START 0x1600
44#define OPENPIC_MSI_REG_SIZE 0x200 44#define OPENPIC_MSI_REG_SIZE 0x200
45#define OPENPIC_SUMMARY_REG_START 0x3800 45#define OPENPIC_SUMMARY_REG_START 0x3800
46#define OPENPIC_SUMMARY_REG_SIZE 0x800 46#define OPENPIC_SUMMARY_REG_SIZE 0x800
47#define OPENPIC_SRC_REG_START 0x10000 47#define OPENPIC_SRC_REG_START 0x10000
48#define OPENPIC_SRC_REG_SIZE (MAX_SRC * 0x20) 48#define OPENPIC_SRC_REG_SIZE (MAX_SRC * 0x20)
49#define OPENPIC_CPU_REG_START 0x20000 49#define OPENPIC_CPU_REG_START 0x20000
50#define OPENPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000) 50#define OPENPIC_CPU_REG_SIZE (0x100 + ((MAX_CPU - 1) * 0x1000))
51 51
52typedef struct FslMpicInfo { 52struct fsl_mpic_info {
53 int max_ext; 53 int max_ext;
54} FslMpicInfo; 54};
55 55
56static FslMpicInfo fsl_mpic_20 = { 56static struct fsl_mpic_info fsl_mpic_20 = {
57 .max_ext = 12, 57 .max_ext = 12,
58}; 58};
59 59
60static FslMpicInfo fsl_mpic_42 = { 60static struct fsl_mpic_info fsl_mpic_42 = {
61 .max_ext = 12, 61 .max_ext = 12,
62}; 62};
63 63
@@ -100,44 +100,43 @@ static int get_current_cpu(void)
100{ 100{
101 CPUState *cpu_single_cpu; 101 CPUState *cpu_single_cpu;
102 102
103 if (!cpu_single_env) { 103 if (!cpu_single_env)
104 return -1; 104 return -1;
105 }
106 105
107 cpu_single_cpu = ENV_GET_CPU(cpu_single_env); 106 cpu_single_cpu = ENV_GET_CPU(cpu_single_env);
108 return cpu_single_cpu->cpu_index; 107 return cpu_single_cpu->cpu_index;
109} 108}
110 109
111static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, int idx); 110static uint32_t openpic_cpu_read_internal(void *opaque, gpa_t addr, int idx);
112static void openpic_cpu_write_internal(void *opaque, hwaddr addr, 111static void openpic_cpu_write_internal(void *opaque, gpa_t addr,
113 uint32_t val, int idx); 112 uint32_t val, int idx);
114 113
115typedef enum IRQType { 114enum irq_type {
116 IRQ_TYPE_NORMAL = 0, 115 IRQ_TYPE_NORMAL = 0,
117 IRQ_TYPE_FSLINT, /* FSL internal interrupt -- level only */ 116 IRQ_TYPE_FSLINT, /* FSL internal interrupt -- level only */
118 IRQ_TYPE_FSLSPECIAL, /* FSL timer/IPI interrupt, edge, no polarity */ 117 IRQ_TYPE_FSLSPECIAL, /* FSL timer/IPI interrupt, edge, no polarity */
119} IRQType; 118};
120 119
121typedef struct IRQQueue { 120struct irq_queue {
122 /* Round up to the nearest 64 IRQs so that the queue length 121 /* Round up to the nearest 64 IRQs so that the queue length
123 * won't change when moving between 32 and 64 bit hosts. 122 * won't change when moving between 32 and 64 bit hosts.
124 */ 123 */
125 unsigned long queue[BITS_TO_LONGS((MAX_IRQ + 63) & ~63)]; 124 unsigned long queue[BITS_TO_LONGS((MAX_IRQ + 63) & ~63)];
126 int next; 125 int next;
127 int priority; 126 int priority;
128} IRQQueue; 127};
129 128
130typedef struct IRQSource { 129struct irq_source {
131 uint32_t ivpr; /* IRQ vector/priority register */ 130 uint32_t ivpr; /* IRQ vector/priority register */
132 uint32_t idr; /* IRQ destination register */ 131 uint32_t idr; /* IRQ destination register */
133 uint32_t destmask; /* bitmap of CPU destinations */ 132 uint32_t destmask; /* bitmap of CPU destinations */
134 int last_cpu; 133 int last_cpu;
135 int output; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */ 134 int output; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
136 int pending; /* TRUE if IRQ is pending */ 135 int pending; /* TRUE if IRQ is pending */
137 IRQType type; 136 enum irq_type type;
138 bool level:1; /* level-triggered */ 137 bool level:1; /* level-triggered */
139 bool nomask:1; /* critical interrupts ignore mask on some FSL MPICs */ 138 bool nomask:1; /* critical interrupts ignore mask on some FSL MPICs */
140} IRQSource; 139};
141 140
142#define IVPR_MASK_SHIFT 31 141#define IVPR_MASK_SHIFT 31
143#define IVPR_MASK_MASK (1 << IVPR_MASK_SHIFT) 142#define IVPR_MASK_MASK (1 << IVPR_MASK_SHIFT)
@@ -158,22 +157,19 @@ typedef struct IRQSource {
158#define IDR_EP 0x80000000 /* external pin */ 157#define IDR_EP 0x80000000 /* external pin */
159#define IDR_CI 0x40000000 /* critical interrupt */ 158#define IDR_CI 0x40000000 /* critical interrupt */
160 159
161typedef struct IRQDest { 160struct irq_dest {
162 int32_t ctpr; /* CPU current task priority */ 161 int32_t ctpr; /* CPU current task priority */
163 IRQQueue raised; 162 struct irq_queue raised;
164 IRQQueue servicing; 163 struct irq_queue servicing;
165 qemu_irq *irqs; 164 qemu_irq *irqs;
166 165
167 /* Count of IRQ sources asserting on non-INT outputs */ 166 /* Count of IRQ sources asserting on non-INT outputs */
168 uint32_t outputs_active[OPENPIC_OUTPUT_NB]; 167 uint32_t outputs_active[OPENPIC_OUTPUT_NB];
169} IRQDest; 168};
170
171typedef struct OpenPICState {
172 SysBusDevice busdev;
173 MemoryRegion mem;
174 169
170struct openpic {
175 /* Behavior control */ 171 /* Behavior control */
176 FslMpicInfo *fsl; 172 struct fsl_mpic_info *fsl;
177 uint32_t model; 173 uint32_t model;
178 uint32_t flags; 174 uint32_t flags;
179 uint32_t nb_irqs; 175 uint32_t nb_irqs;
@@ -186,9 +182,6 @@ typedef struct OpenPICState {
186 uint32_t brr1; 182 uint32_t brr1;
187 uint32_t mpic_mode_mask; 183 uint32_t mpic_mode_mask;
188 184
189 /* Sub-regions */
190 MemoryRegion sub_io_mem[6];
191
192 /* Global registers */ 185 /* Global registers */
193 uint32_t frr; /* Feature reporting register */ 186 uint32_t frr; /* Feature reporting register */
194 uint32_t gcr; /* Global configuration register */ 187 uint32_t gcr; /* Global configuration register */
@@ -196,9 +189,9 @@ typedef struct OpenPICState {
196 uint32_t spve; /* Spurious vector register */ 189 uint32_t spve; /* Spurious vector register */
197 uint32_t tfrr; /* Timer frequency reporting register */ 190 uint32_t tfrr; /* Timer frequency reporting register */
198 /* Source registers */ 191 /* Source registers */
199 IRQSource src[MAX_IRQ]; 192 struct irq_source src[MAX_IRQ];
200 /* Local registers per output pin */ 193 /* Local registers per output pin */
201 IRQDest dst[MAX_CPU]; 194 struct irq_dest dst[MAX_CPU];
202 uint32_t nb_cpus; 195 uint32_t nb_cpus;
203 /* Timer registers */ 196 /* Timer registers */
204 struct { 197 struct {
@@ -213,24 +206,24 @@ typedef struct OpenPICState {
213 uint32_t irq_ipi0; 206 uint32_t irq_ipi0;
214 uint32_t irq_tim0; 207 uint32_t irq_tim0;
215 uint32_t irq_msi; 208 uint32_t irq_msi;
216} OpenPICState; 209};
217 210
218static inline void IRQ_setbit(IRQQueue * q, int n_IRQ) 211static inline void IRQ_setbit(struct irq_queue *q, int n_IRQ)
219{ 212{
220 set_bit(n_IRQ, q->queue); 213 set_bit(n_IRQ, q->queue);
221} 214}
222 215
223static inline void IRQ_resetbit(IRQQueue * q, int n_IRQ) 216static inline void IRQ_resetbit(struct irq_queue *q, int n_IRQ)
224{ 217{
225 clear_bit(n_IRQ, q->queue); 218 clear_bit(n_IRQ, q->queue);
226} 219}
227 220
228static inline int IRQ_testbit(IRQQueue * q, int n_IRQ) 221static inline int IRQ_testbit(struct irq_queue *q, int n_IRQ)
229{ 222{
230 return test_bit(n_IRQ, q->queue); 223 return test_bit(n_IRQ, q->queue);
231} 224}
232 225
233static void IRQ_check(OpenPICState * opp, IRQQueue * q) 226static void IRQ_check(struct openpic *opp, struct irq_queue *q)
234{ 227{
235 int irq = -1; 228 int irq = -1;
236 int next = -1; 229 int next = -1;
@@ -238,11 +231,10 @@ static void IRQ_check(OpenPICState * opp, IRQQueue * q)
238 231
239 for (;;) { 232 for (;;) {
240 irq = find_next_bit(q->queue, opp->max_irq, irq + 1); 233 irq = find_next_bit(q->queue, opp->max_irq, irq + 1);
241 if (irq == opp->max_irq) { 234 if (irq == opp->max_irq)
242 break; 235 break;
243 }
244 236
245 DPRINTF("IRQ_check: irq %d set ivpr_pr=%d pr=%d\n", 237 pr_debug("IRQ_check: irq %d set ivpr_pr=%d pr=%d\n",
246 irq, IVPR_PRIORITY(opp->src[irq].ivpr), priority); 238 irq, IVPR_PRIORITY(opp->src[irq].ivpr), priority);
247 239
248 if (IVPR_PRIORITY(opp->src[irq].ivpr) > priority) { 240 if (IVPR_PRIORITY(opp->src[irq].ivpr) > priority) {
@@ -255,7 +247,7 @@ static void IRQ_check(OpenPICState * opp, IRQQueue * q)
255 q->priority = priority; 247 q->priority = priority;
256} 248}
257 249
258static int IRQ_get_next(OpenPICState * opp, IRQQueue * q) 250static int IRQ_get_next(struct openpic *opp, struct irq_queue *q)
259{ 251{
260 /* XXX: optimize */ 252 /* XXX: optimize */
261 IRQ_check(opp, q); 253 IRQ_check(opp, q);
@@ -263,21 +255,21 @@ static int IRQ_get_next(OpenPICState * opp, IRQQueue * q)
263 return q->next; 255 return q->next;
264} 256}
265 257
266static void IRQ_local_pipe(OpenPICState * opp, int n_CPU, int n_IRQ, 258static void IRQ_local_pipe(struct openpic *opp, int n_CPU, int n_IRQ,
267 bool active, bool was_active) 259 bool active, bool was_active)
268{ 260{
269 IRQDest *dst; 261 struct irq_dest *dst;
270 IRQSource *src; 262 struct irq_source *src;
271 int priority; 263 int priority;
272 264
273 dst = &opp->dst[n_CPU]; 265 dst = &opp->dst[n_CPU];
274 src = &opp->src[n_IRQ]; 266 src = &opp->src[n_IRQ];
275 267
276 DPRINTF("%s: IRQ %d active %d was %d\n", 268 pr_debug("%s: IRQ %d active %d was %d\n",
277 __func__, n_IRQ, active, was_active); 269 __func__, n_IRQ, active, was_active);
278 270
279 if (src->output != OPENPIC_OUTPUT_INT) { 271 if (src->output != OPENPIC_OUTPUT_INT) {
280 DPRINTF("%s: output %d irq %d active %d was %d count %d\n", 272 pr_debug("%s: output %d irq %d active %d was %d count %d\n",
281 __func__, src->output, n_IRQ, active, was_active, 273 __func__, src->output, n_IRQ, active, was_active,
282 dst->outputs_active[src->output]); 274 dst->outputs_active[src->output]);
283 275
@@ -286,19 +278,17 @@ static void IRQ_local_pipe(OpenPICState * opp, int n_CPU, int n_IRQ,
286 * masking. 278 * masking.
287 */ 279 */
288 if (active) { 280 if (active) {
289 if (!was_active 281 if (!was_active &&
290 && dst->outputs_active[src->output]++ == 0) { 282 dst->outputs_active[src->output]++ == 0) {
291 DPRINTF 283 pr_debug("%s: Raise OpenPIC output %d cpu %d irq %d\n",
292 ("%s: Raise OpenPIC output %d cpu %d irq %d\n", 284 __func__, src->output, n_CPU, n_IRQ);
293 __func__, src->output, n_CPU, n_IRQ);
294 qemu_irq_raise(dst->irqs[src->output]); 285 qemu_irq_raise(dst->irqs[src->output]);
295 } 286 }
296 } else { 287 } else {
297 if (was_active 288 if (was_active &&
298 && --dst->outputs_active[src->output] == 0) { 289 --dst->outputs_active[src->output] == 0) {
299 DPRINTF 290 pr_debug("%s: Lower OpenPIC output %d cpu %d irq %d\n",
300 ("%s: Lower OpenPIC output %d cpu %d irq %d\n", 291 __func__, src->output, n_CPU, n_IRQ);
301 __func__, src->output, n_CPU, n_IRQ);
302 qemu_irq_lower(dst->irqs[src->output]); 292 qemu_irq_lower(dst->irqs[src->output]);
303 } 293 }
304 } 294 }
@@ -311,31 +301,27 @@ static void IRQ_local_pipe(OpenPICState * opp, int n_CPU, int n_IRQ,
311 /* Even if the interrupt doesn't have enough priority, 301 /* Even if the interrupt doesn't have enough priority,
312 * it is still raised, in case ctpr is lowered later. 302 * it is still raised, in case ctpr is lowered later.
313 */ 303 */
314 if (active) { 304 if (active)
315 IRQ_setbit(&dst->raised, n_IRQ); 305 IRQ_setbit(&dst->raised, n_IRQ);
316 } else { 306 else
317 IRQ_resetbit(&dst->raised, n_IRQ); 307 IRQ_resetbit(&dst->raised, n_IRQ);
318 }
319 308
320 IRQ_check(opp, &dst->raised); 309 IRQ_check(opp, &dst->raised);
321 310
322 if (active && priority <= dst->ctpr) { 311 if (active && priority <= dst->ctpr) {
323 DPRINTF 312 pr_debug("%s: IRQ %d priority %d too low for ctpr %d on CPU %d\n",
324 ("%s: IRQ %d priority %d too low for ctpr %d on CPU %d\n", 313 __func__, n_IRQ, priority, dst->ctpr, n_CPU);
325 __func__, n_IRQ, priority, dst->ctpr, n_CPU);
326 active = 0; 314 active = 0;
327 } 315 }
328 316
329 if (active) { 317 if (active) {
330 if (IRQ_get_next(opp, &dst->servicing) >= 0 && 318 if (IRQ_get_next(opp, &dst->servicing) >= 0 &&
331 priority <= dst->servicing.priority) { 319 priority <= dst->servicing.priority) {
332 DPRINTF 320 pr_debug("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n",
333 ("%s: IRQ %d is hidden by servicing IRQ %d on CPU %d\n", 321 __func__, n_IRQ, dst->servicing.next, n_CPU);
334 __func__, n_IRQ, dst->servicing.next, n_CPU);
335 } else { 322 } else {
336 DPRINTF 323 pr_debug("%s: Raise OpenPIC INT output cpu %d irq %d/%d\n",
337 ("%s: Raise OpenPIC INT output cpu %d irq %d/%d\n", 324 __func__, n_CPU, n_IRQ, dst->raised.next);
338 __func__, n_CPU, n_IRQ, dst->raised.next);
339 qemu_irq_raise(opp->dst[n_CPU]. 325 qemu_irq_raise(opp->dst[n_CPU].
340 irqs[OPENPIC_OUTPUT_INT]); 326 irqs[OPENPIC_OUTPUT_INT]);
341 } 327 }
@@ -343,17 +329,15 @@ static void IRQ_local_pipe(OpenPICState * opp, int n_CPU, int n_IRQ,
343 IRQ_get_next(opp, &dst->servicing); 329 IRQ_get_next(opp, &dst->servicing);
344 if (dst->raised.priority > dst->ctpr && 330 if (dst->raised.priority > dst->ctpr &&
345 dst->raised.priority > dst->servicing.priority) { 331 dst->raised.priority > dst->servicing.priority) {
346 DPRINTF 332 pr_debug("%s: IRQ %d inactive, IRQ %d prio %d above %d/%d, CPU %d\n",
347 ("%s: IRQ %d inactive, IRQ %d prio %d above %d/%d, CPU %d\n", 333 __func__, n_IRQ, dst->raised.next,
348 __func__, n_IRQ, dst->raised.next, 334 dst->raised.priority, dst->ctpr,
349 dst->raised.priority, dst->ctpr, 335 dst->servicing.priority, n_CPU);
350 dst->servicing.priority, n_CPU);
351 /* IRQ line stays asserted */ 336 /* IRQ line stays asserted */
352 } else { 337 } else {
353 DPRINTF 338 pr_debug("%s: IRQ %d inactive, current prio %d/%d, CPU %d\n",
354 ("%s: IRQ %d inactive, current prio %d/%d, CPU %d\n", 339 __func__, n_IRQ, dst->ctpr,
355 __func__, n_IRQ, dst->ctpr, 340 dst->servicing.priority, n_CPU);
356 dst->servicing.priority, n_CPU);
357 qemu_irq_lower(opp->dst[n_CPU]. 341 qemu_irq_lower(opp->dst[n_CPU].
358 irqs[OPENPIC_OUTPUT_INT]); 342 irqs[OPENPIC_OUTPUT_INT]);
359 } 343 }
@@ -361,9 +345,9 @@ static void IRQ_local_pipe(OpenPICState * opp, int n_CPU, int n_IRQ,
361} 345}
362 346
363/* update pic state because registers for n_IRQ have changed value */ 347/* update pic state because registers for n_IRQ have changed value */
364static void openpic_update_irq(OpenPICState * opp, int n_IRQ) 348static void openpic_update_irq(struct openpic *opp, int n_IRQ)
365{ 349{
366 IRQSource *src; 350 struct irq_source *src;
367 bool active, was_active; 351 bool active, was_active;
368 int i; 352 int i;
369 353
@@ -372,30 +356,29 @@ static void openpic_update_irq(OpenPICState * opp, int n_IRQ)
372 356
373 if ((src->ivpr & IVPR_MASK_MASK) && !src->nomask) { 357 if ((src->ivpr & IVPR_MASK_MASK) && !src->nomask) {
374 /* Interrupt source is disabled */ 358 /* Interrupt source is disabled */
375 DPRINTF("%s: IRQ %d is disabled\n", __func__, n_IRQ); 359 pr_debug("%s: IRQ %d is disabled\n", __func__, n_IRQ);
376 active = false; 360 active = false;
377 } 361 }
378 362
379 was_active = ! !(src->ivpr & IVPR_ACTIVITY_MASK); 363 was_active = !!(src->ivpr & IVPR_ACTIVITY_MASK);
380 364
381 /* 365 /*
382 * We don't have a similar check for already-active because 366 * We don't have a similar check for already-active because
383 * ctpr may have changed and we need to withdraw the interrupt. 367 * ctpr may have changed and we need to withdraw the interrupt.
384 */ 368 */
385 if (!active && !was_active) { 369 if (!active && !was_active) {
386 DPRINTF("%s: IRQ %d is already inactive\n", __func__, n_IRQ); 370 pr_debug("%s: IRQ %d is already inactive\n", __func__, n_IRQ);
387 return; 371 return;
388 } 372 }
389 373
390 if (active) { 374 if (active)
391 src->ivpr |= IVPR_ACTIVITY_MASK; 375 src->ivpr |= IVPR_ACTIVITY_MASK;
392 } else { 376 else
393 src->ivpr &= ~IVPR_ACTIVITY_MASK; 377 src->ivpr &= ~IVPR_ACTIVITY_MASK;
394 }
395 378
396 if (src->destmask == 0) { 379 if (src->destmask == 0) {
397 /* No target */ 380 /* No target */
398 DPRINTF("%s: IRQ %d has no target\n", __func__, n_IRQ); 381 pr_debug("%s: IRQ %d has no target\n", __func__, n_IRQ);
399 return; 382 return;
400 } 383 }
401 384
@@ -413,9 +396,9 @@ static void openpic_update_irq(OpenPICState * opp, int n_IRQ)
413 } else { 396 } else {
414 /* Distributed delivery mode */ 397 /* Distributed delivery mode */
415 for (i = src->last_cpu + 1; i != src->last_cpu; i++) { 398 for (i = src->last_cpu + 1; i != src->last_cpu; i++) {
416 if (i == opp->nb_cpus) { 399 if (i == opp->nb_cpus)
417 i = 0; 400 i = 0;
418 } 401
419 if (src->destmask & (1 << i)) { 402 if (src->destmask & (1 << i)) {
420 IRQ_local_pipe(opp, i, n_IRQ, active, 403 IRQ_local_pipe(opp, i, n_IRQ, active,
421 was_active); 404 was_active);
@@ -428,16 +411,16 @@ static void openpic_update_irq(OpenPICState * opp, int n_IRQ)
428 411
429static void openpic_set_irq(void *opaque, int n_IRQ, int level) 412static void openpic_set_irq(void *opaque, int n_IRQ, int level)
430{ 413{
431 OpenPICState *opp = opaque; 414 struct openpic *opp = opaque;
432 IRQSource *src; 415 struct irq_source *src;
433 416
434 if (n_IRQ >= MAX_IRQ) { 417 if (n_IRQ >= MAX_IRQ) {
435 fprintf(stderr, "%s: IRQ %d out of range\n", __func__, n_IRQ); 418 pr_err("%s: IRQ %d out of range\n", __func__, n_IRQ);
436 abort(); 419 abort();
437 } 420 }
438 421
439 src = &opp->src[n_IRQ]; 422 src = &opp->src[n_IRQ];
440 DPRINTF("openpic: set irq %d = %d ivpr=0x%08x\n", 423 pr_debug("openpic: set irq %d = %d ivpr=0x%08x\n",
441 n_IRQ, level, src->ivpr); 424 n_IRQ, level, src->ivpr);
442 if (src->level) { 425 if (src->level) {
443 /* level-sensitive irq */ 426 /* level-sensitive irq */
@@ -463,9 +446,9 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int level)
463 } 446 }
464} 447}
465 448
466static void openpic_reset(DeviceState * d) 449static void openpic_reset(DeviceState *d)
467{ 450{
468 OpenPICState *opp = FROM_SYSBUS(typeof(*opp), SYS_BUS_DEVICE(d)); 451 struct openpic *opp = FROM_SYSBUS(typeof(*opp), SYS_BUS_DEVICE(d));
469 int i; 452 int i;
470 453
471 opp->gcr = GCR_RESET; 454 opp->gcr = GCR_RESET;
@@ -485,7 +468,7 @@ static void openpic_reset(DeviceState * d)
485 switch (opp->src[i].type) { 468 switch (opp->src[i].type) {
486 case IRQ_TYPE_NORMAL: 469 case IRQ_TYPE_NORMAL:
487 opp->src[i].level = 470 opp->src[i].level =
488 ! !(opp->ivpr_reset & IVPR_SENSE_MASK); 471 !!(opp->ivpr_reset & IVPR_SENSE_MASK);
489 break; 472 break;
490 473
491 case IRQ_TYPE_FSLINT: 474 case IRQ_TYPE_FSLINT:
@@ -499,9 +482,9 @@ static void openpic_reset(DeviceState * d)
499 /* Initialise IRQ destinations */ 482 /* Initialise IRQ destinations */
500 for (i = 0; i < MAX_CPU; i++) { 483 for (i = 0; i < MAX_CPU; i++) {
501 opp->dst[i].ctpr = 15; 484 opp->dst[i].ctpr = 15;
502 memset(&opp->dst[i].raised, 0, sizeof(IRQQueue)); 485 memset(&opp->dst[i].raised, 0, sizeof(struct irq_queue));
503 opp->dst[i].raised.next = -1; 486 opp->dst[i].raised.next = -1;
504 memset(&opp->dst[i].servicing, 0, sizeof(IRQQueue)); 487 memset(&opp->dst[i].servicing, 0, sizeof(struct irq_queue));
505 opp->dst[i].servicing.next = -1; 488 opp->dst[i].servicing.next = -1;
506 } 489 }
507 /* Initialise timers */ 490 /* Initialise timers */
@@ -513,28 +496,28 @@ static void openpic_reset(DeviceState * d)
513 opp->gcr = 0; 496 opp->gcr = 0;
514} 497}
515 498
516static inline uint32_t read_IRQreg_idr(OpenPICState * opp, int n_IRQ) 499static inline uint32_t read_IRQreg_idr(struct openpic *opp, int n_IRQ)
517{ 500{
518 return opp->src[n_IRQ].idr; 501 return opp->src[n_IRQ].idr;
519} 502}
520 503
521static inline uint32_t read_IRQreg_ilr(OpenPICState * opp, int n_IRQ) 504static inline uint32_t read_IRQreg_ilr(struct openpic *opp, int n_IRQ)
522{ 505{
523 if (opp->flags & OPENPIC_FLAG_ILR) { 506 if (opp->flags & OPENPIC_FLAG_ILR)
524 return output_to_inttgt(opp->src[n_IRQ].output); 507 return output_to_inttgt(opp->src[n_IRQ].output);
525 }
526 508
527 return 0xffffffff; 509 return 0xffffffff;
528} 510}
529 511
530static inline uint32_t read_IRQreg_ivpr(OpenPICState * opp, int n_IRQ) 512static inline uint32_t read_IRQreg_ivpr(struct openpic *opp, int n_IRQ)
531{ 513{
532 return opp->src[n_IRQ].ivpr; 514 return opp->src[n_IRQ].ivpr;
533} 515}
534 516
535static inline void write_IRQreg_idr(OpenPICState * opp, int n_IRQ, uint32_t val) 517static inline void write_IRQreg_idr(struct openpic *opp, int n_IRQ,
518 uint32_t val)
536{ 519{
537 IRQSource *src = &opp->src[n_IRQ]; 520 struct irq_source *src = &opp->src[n_IRQ];
538 uint32_t normal_mask = (1UL << opp->nb_cpus) - 1; 521 uint32_t normal_mask = (1UL << opp->nb_cpus) - 1;
539 uint32_t crit_mask = 0; 522 uint32_t crit_mask = 0;
540 uint32_t mask = normal_mask; 523 uint32_t mask = normal_mask;
@@ -547,14 +530,13 @@ static inline void write_IRQreg_idr(OpenPICState * opp, int n_IRQ, uint32_t val)
547 } 530 }
548 531
549 src->idr = val & mask; 532 src->idr = val & mask;
550 DPRINTF("Set IDR %d to 0x%08x\n", n_IRQ, src->idr); 533 pr_debug("Set IDR %d to 0x%08x\n", n_IRQ, src->idr);
551 534
552 if (opp->flags & OPENPIC_FLAG_IDR_CRIT) { 535 if (opp->flags & OPENPIC_FLAG_IDR_CRIT) {
553 if (src->idr & crit_mask) { 536 if (src->idr & crit_mask) {
554 if (src->idr & normal_mask) { 537 if (src->idr & normal_mask) {
555 DPRINTF 538 pr_debug("%s: IRQ configured for multiple output types, using critical\n",
556 ("%s: IRQ configured for multiple output types, using " 539 __func__);
557 "critical\n", __func__);
558 } 540 }
559 541
560 src->output = OPENPIC_OUTPUT_CINT; 542 src->output = OPENPIC_OUTPUT_CINT;
@@ -564,9 +546,8 @@ static inline void write_IRQreg_idr(OpenPICState * opp, int n_IRQ, uint32_t val)
564 for (i = 0; i < opp->nb_cpus; i++) { 546 for (i = 0; i < opp->nb_cpus; i++) {
565 int n_ci = IDR_CI0_SHIFT - i; 547 int n_ci = IDR_CI0_SHIFT - i;
566 548
567 if (src->idr & (1UL << n_ci)) { 549 if (src->idr & (1UL << n_ci))
568 src->destmask |= 1UL << i; 550 src->destmask |= 1UL << i;
569 }
570 } 551 }
571 } else { 552 } else {
572 src->output = OPENPIC_OUTPUT_INT; 553 src->output = OPENPIC_OUTPUT_INT;
@@ -578,20 +559,21 @@ static inline void write_IRQreg_idr(OpenPICState * opp, int n_IRQ, uint32_t val)
578 } 559 }
579} 560}
580 561
581static inline void write_IRQreg_ilr(OpenPICState * opp, int n_IRQ, uint32_t val) 562static inline void write_IRQreg_ilr(struct openpic *opp, int n_IRQ,
563 uint32_t val)
582{ 564{
583 if (opp->flags & OPENPIC_FLAG_ILR) { 565 if (opp->flags & OPENPIC_FLAG_ILR) {
584 IRQSource *src = &opp->src[n_IRQ]; 566 struct irq_source *src = &opp->src[n_IRQ];
585 567
586 src->output = inttgt_to_output(val & ILR_INTTGT_MASK); 568 src->output = inttgt_to_output(val & ILR_INTTGT_MASK);
587 DPRINTF("Set ILR %d to 0x%08x, output %d\n", n_IRQ, src->idr, 569 pr_debug("Set ILR %d to 0x%08x, output %d\n", n_IRQ, src->idr,
588 src->output); 570 src->output);
589 571
590 /* TODO: on MPIC v4.0 only, set nomask for non-INT */ 572 /* TODO: on MPIC v4.0 only, set nomask for non-INT */
591 } 573 }
592} 574}
593 575
594static inline void write_IRQreg_ivpr(OpenPICState * opp, int n_IRQ, 576static inline void write_IRQreg_ivpr(struct openpic *opp, int n_IRQ,
595 uint32_t val) 577 uint32_t val)
596{ 578{
597 uint32_t mask; 579 uint32_t mask;
@@ -613,7 +595,7 @@ static inline void write_IRQreg_ivpr(OpenPICState * opp, int n_IRQ,
613 switch (opp->src[n_IRQ].type) { 595 switch (opp->src[n_IRQ].type) {
614 case IRQ_TYPE_NORMAL: 596 case IRQ_TYPE_NORMAL:
615 opp->src[n_IRQ].level = 597 opp->src[n_IRQ].level =
616 ! !(opp->src[n_IRQ].ivpr & IVPR_SENSE_MASK); 598 !!(opp->src[n_IRQ].ivpr & IVPR_SENSE_MASK);
617 break; 599 break;
618 600
619 case IRQ_TYPE_FSLINT: 601 case IRQ_TYPE_FSLINT:
@@ -626,11 +608,11 @@ static inline void write_IRQreg_ivpr(OpenPICState * opp, int n_IRQ,
626 } 608 }
627 609
628 openpic_update_irq(opp, n_IRQ); 610 openpic_update_irq(opp, n_IRQ);
629 DPRINTF("Set IVPR %d to 0x%08x -> 0x%08x\n", n_IRQ, val, 611 pr_debug("Set IVPR %d to 0x%08x -> 0x%08x\n", n_IRQ, val,
630 opp->src[n_IRQ].ivpr); 612 opp->src[n_IRQ].ivpr);
631} 613}
632 614
633static void openpic_gcr_write(OpenPICState * opp, uint64_t val) 615static void openpic_gcr_write(struct openpic *opp, uint64_t val)
634{ 616{
635 bool mpic_proxy = false; 617 bool mpic_proxy = false;
636 618
@@ -643,27 +625,26 @@ static void openpic_gcr_write(OpenPICState * opp, uint64_t val)
643 opp->gcr |= val & opp->mpic_mode_mask; 625 opp->gcr |= val & opp->mpic_mode_mask;
644 626
645 /* Set external proxy mode */ 627 /* Set external proxy mode */
646 if ((val & opp->mpic_mode_mask) == GCR_MODE_PROXY) { 628 if ((val & opp->mpic_mode_mask) == GCR_MODE_PROXY)
647 mpic_proxy = true; 629 mpic_proxy = true;
648 }
649 630
650 ppce500_set_mpic_proxy(mpic_proxy); 631 ppce500_set_mpic_proxy(mpic_proxy);
651} 632}
652 633
653static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val, 634static void openpic_gbl_write(void *opaque, gpa_t addr, uint64_t val,
654 unsigned len) 635 unsigned len)
655{ 636{
656 OpenPICState *opp = opaque; 637 struct openpic *opp = opaque;
657 IRQDest *dst; 638 struct irq_dest *dst;
658 int idx; 639 int idx;
659 640
660 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n", 641 pr_debug("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n",
661 __func__, addr, val); 642 __func__, addr, val);
662 if (addr & 0xF) { 643 if (addr & 0xF)
663 return; 644 return;
664 } 645
665 switch (addr) { 646 switch (addr) {
666 case 0x00: /* Block Revision Register1 (BRR1) is Readonly */ 647 case 0x00: /* Block Revision Register1 (BRR1) is Readonly */
667 break; 648 break;
668 case 0x40: 649 case 0x40:
669 case 0x50: 650 case 0x50:
@@ -685,16 +666,14 @@ static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,
685 case 0x1090: /* PIR */ 666 case 0x1090: /* PIR */
686 for (idx = 0; idx < opp->nb_cpus; idx++) { 667 for (idx = 0; idx < opp->nb_cpus; idx++) {
687 if ((val & (1 << idx)) && !(opp->pir & (1 << idx))) { 668 if ((val & (1 << idx)) && !(opp->pir & (1 << idx))) {
688 DPRINTF 669 pr_debug("Raise OpenPIC RESET output for CPU %d\n",
689 ("Raise OpenPIC RESET output for CPU %d\n", 670 idx);
690 idx);
691 dst = &opp->dst[idx]; 671 dst = &opp->dst[idx];
692 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_RESET]); 672 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_RESET]);
693 } else if (!(val & (1 << idx)) 673 } else if (!(val & (1 << idx)) &&
694 && (opp->pir & (1 << idx))) { 674 (opp->pir & (1 << idx))) {
695 DPRINTF 675 pr_debug("Lower OpenPIC RESET output for CPU %d\n",
696 ("Lower OpenPIC RESET output for CPU %d\n", 676 idx);
697 idx);
698 dst = &opp->dst[idx]; 677 dst = &opp->dst[idx];
699 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_RESET]); 678 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_RESET]);
700 } 679 }
@@ -704,13 +683,12 @@ static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,
704 case 0x10A0: /* IPI_IVPR */ 683 case 0x10A0: /* IPI_IVPR */
705 case 0x10B0: 684 case 0x10B0:
706 case 0x10C0: 685 case 0x10C0:
707 case 0x10D0: 686 case 0x10D0: {
708 { 687 int idx;
709 int idx; 688 idx = (addr - 0x10A0) >> 4;
710 idx = (addr - 0x10A0) >> 4; 689 write_IRQreg_ivpr(opp, opp->irq_ipi0 + idx, val);
711 write_IRQreg_ivpr(opp, opp->irq_ipi0 + idx, val);
712 }
713 break; 690 break;
691 }
714 case 0x10E0: /* SPVE */ 692 case 0x10E0: /* SPVE */
715 opp->spve = val & opp->vector_mask; 693 opp->spve = val & opp->vector_mask;
716 break; 694 break;
@@ -719,16 +697,16 @@ static void openpic_gbl_write(void *opaque, hwaddr addr, uint64_t val,
719 } 697 }
720} 698}
721 699
722static uint64_t openpic_gbl_read(void *opaque, hwaddr addr, unsigned len) 700static uint64_t openpic_gbl_read(void *opaque, gpa_t addr, unsigned len)
723{ 701{
724 OpenPICState *opp = opaque; 702 struct openpic *opp = opaque;
725 uint32_t retval; 703 uint32_t retval;
726 704
727 DPRINTF("%s: addr %#" HWADDR_PRIx "\n", __func__, addr); 705 pr_debug("%s: addr %#" HWADDR_PRIx "\n", __func__, addr);
728 retval = 0xFFFFFFFF; 706 retval = 0xFFFFFFFF;
729 if (addr & 0xF) { 707 if (addr & 0xF)
730 return retval; 708 return retval;
731 } 709
732 switch (addr) { 710 switch (addr) {
733 case 0x1000: /* FRR */ 711 case 0x1000: /* FRR */
734 retval = opp->frr; 712 retval = opp->frr;
@@ -772,24 +750,23 @@ static uint64_t openpic_gbl_read(void *opaque, hwaddr addr, unsigned len)
772 default: 750 default:
773 break; 751 break;
774 } 752 }
775 DPRINTF("%s: => 0x%08x\n", __func__, retval); 753 pr_debug("%s: => 0x%08x\n", __func__, retval);
776 754
777 return retval; 755 return retval;
778} 756}
779 757
780static void openpic_tmr_write(void *opaque, hwaddr addr, uint64_t val, 758static void openpic_tmr_write(void *opaque, gpa_t addr, uint64_t val,
781 unsigned len) 759 unsigned len)
782{ 760{
783 OpenPICState *opp = opaque; 761 struct openpic *opp = opaque;
784 int idx; 762 int idx;
785 763
786 addr += 0x10f0; 764 addr += 0x10f0;
787 765
788 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n", 766 pr_debug("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n",
789 __func__, addr, val); 767 __func__, addr, val);
790 if (addr & 0xF) { 768 if (addr & 0xF)
791 return; 769 return;
792 }
793 770
794 if (addr == 0x10f0) { 771 if (addr == 0x10f0) {
795 /* TFRR */ 772 /* TFRR */
@@ -806,9 +783,9 @@ static void openpic_tmr_write(void *opaque, hwaddr addr, uint64_t val,
806 case 0x10: /* TBCR */ 783 case 0x10: /* TBCR */
807 if ((opp->timers[idx].tccr & TCCR_TOG) != 0 && 784 if ((opp->timers[idx].tccr & TCCR_TOG) != 0 &&
808 (val & TBCR_CI) == 0 && 785 (val & TBCR_CI) == 0 &&
809 (opp->timers[idx].tbcr & TBCR_CI) != 0) { 786 (opp->timers[idx].tbcr & TBCR_CI) != 0)
810 opp->timers[idx].tccr &= ~TCCR_TOG; 787 opp->timers[idx].tccr &= ~TCCR_TOG;
811 } 788
812 opp->timers[idx].tbcr = val; 789 opp->timers[idx].tbcr = val;
813 break; 790 break;
814 case 0x20: /* TVPR */ 791 case 0x20: /* TVPR */
@@ -820,16 +797,16 @@ static void openpic_tmr_write(void *opaque, hwaddr addr, uint64_t val,
820 } 797 }
821} 798}
822 799
823static uint64_t openpic_tmr_read(void *opaque, hwaddr addr, unsigned len) 800static uint64_t openpic_tmr_read(void *opaque, gpa_t addr, unsigned len)
824{ 801{
825 OpenPICState *opp = opaque; 802 struct openpic *opp = opaque;
826 uint32_t retval = -1; 803 uint32_t retval = -1;
827 int idx; 804 int idx;
828 805
829 DPRINTF("%s: addr %#" HWADDR_PRIx "\n", __func__, addr); 806 pr_debug("%s: addr %#" HWADDR_PRIx "\n", __func__, addr);
830 if (addr & 0xF) { 807 if (addr & 0xF)
831 goto out; 808 goto out;
832 } 809
833 idx = (addr >> 6) & 0x3; 810 idx = (addr >> 6) & 0x3;
834 if (addr == 0x0) { 811 if (addr == 0x0) {
835 /* TFRR */ 812 /* TFRR */
@@ -852,18 +829,18 @@ static uint64_t openpic_tmr_read(void *opaque, hwaddr addr, unsigned len)
852 } 829 }
853 830
854out: 831out:
855 DPRINTF("%s: => 0x%08x\n", __func__, retval); 832 pr_debug("%s: => 0x%08x\n", __func__, retval);
856 833
857 return retval; 834 return retval;
858} 835}
859 836
860static void openpic_src_write(void *opaque, hwaddr addr, uint64_t val, 837static void openpic_src_write(void *opaque, gpa_t addr, uint64_t val,
861 unsigned len) 838 unsigned len)
862{ 839{
863 OpenPICState *opp = opaque; 840 struct openpic *opp = opaque;
864 int idx; 841 int idx;
865 842
866 DPRINTF("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n", 843 pr_debug("%s: addr %#" HWADDR_PRIx " <= %08" PRIx64 "\n",
867 __func__, addr, val); 844 __func__, addr, val);
868 845
869 addr = addr & 0xffff; 846 addr = addr & 0xffff;
@@ -884,11 +861,11 @@ static void openpic_src_write(void *opaque, hwaddr addr, uint64_t val,
884 861
885static uint64_t openpic_src_read(void *opaque, uint64_t addr, unsigned len) 862static uint64_t openpic_src_read(void *opaque, uint64_t addr, unsigned len)
886{ 863{
887 OpenPICState *opp = opaque; 864 struct openpic *opp = opaque;
888 uint32_t retval; 865 uint32_t retval;
889 int idx; 866 int idx;
890 867
891 DPRINTF("%s: addr %#" HWADDR_PRIx "\n", __func__, addr); 868 pr_debug("%s: addr %#" HWADDR_PRIx "\n", __func__, addr);
892 retval = 0xFFFFFFFF; 869 retval = 0xFFFFFFFF;
893 870
894 addr = addr & 0xffff; 871 addr = addr & 0xffff;
@@ -906,22 +883,21 @@ static uint64_t openpic_src_read(void *opaque, uint64_t addr, unsigned len)
906 break; 883 break;
907 } 884 }
908 885
909 DPRINTF("%s: => 0x%08x\n", __func__, retval); 886 pr_debug("%s: => 0x%08x\n", __func__, retval);
910 return retval; 887 return retval;
911} 888}
912 889
913static void openpic_msi_write(void *opaque, hwaddr addr, uint64_t val, 890static void openpic_msi_write(void *opaque, gpa_t addr, uint64_t val,
914 unsigned size) 891 unsigned size)
915{ 892{
916 OpenPICState *opp = opaque; 893 struct openpic *opp = opaque;
917 int idx = opp->irq_msi; 894 int idx = opp->irq_msi;
918 int srs, ibs; 895 int srs, ibs;
919 896
920 DPRINTF("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64 "\n", 897 pr_debug("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64 "\n",
921 __func__, addr, val); 898 __func__, addr, val);
922 if (addr & 0xF) { 899 if (addr & 0xF)
923 return; 900 return;
924 }
925 901
926 switch (addr) { 902 switch (addr) {
927 case MSIIR_OFFSET: 903 case MSIIR_OFFSET:
@@ -937,16 +913,15 @@ static void openpic_msi_write(void *opaque, hwaddr addr, uint64_t val,
937 } 913 }
938} 914}
939 915
940static uint64_t openpic_msi_read(void *opaque, hwaddr addr, unsigned size) 916static uint64_t openpic_msi_read(void *opaque, gpa_t addr, unsigned size)
941{ 917{
942 OpenPICState *opp = opaque; 918 struct openpic *opp = opaque;
943 uint64_t r = 0; 919 uint64_t r = 0;
944 int i, srs; 920 int i, srs;
945 921
946 DPRINTF("%s: addr %#" HWADDR_PRIx "\n", __func__, addr); 922 pr_debug("%s: addr %#" HWADDR_PRIx "\n", __func__, addr);
947 if (addr & 0xF) { 923 if (addr & 0xF)
948 return -1; 924 return -1;
949 }
950 925
951 srs = addr >> 4; 926 srs = addr >> 4;
952 927
@@ -965,53 +940,51 @@ static uint64_t openpic_msi_read(void *opaque, hwaddr addr, unsigned size)
965 openpic_set_irq(opp, opp->irq_msi + srs, 0); 940 openpic_set_irq(opp, opp->irq_msi + srs, 0);
966 break; 941 break;
967 case 0x120: /* MSISR */ 942 case 0x120: /* MSISR */
968 for (i = 0; i < MAX_MSI; i++) { 943 for (i = 0; i < MAX_MSI; i++)
969 r |= (opp->msi[i].msir ? 1 : 0) << i; 944 r |= (opp->msi[i].msir ? 1 : 0) << i;
970 }
971 break; 945 break;
972 } 946 }
973 947
974 return r; 948 return r;
975} 949}
976 950
977static uint64_t openpic_summary_read(void *opaque, hwaddr addr, unsigned size) 951static uint64_t openpic_summary_read(void *opaque, gpa_t addr, unsigned size)
978{ 952{
979 uint64_t r = 0; 953 uint64_t r = 0;
980 954
981 DPRINTF("%s: addr %#" HWADDR_PRIx "\n", __func__, addr); 955 pr_debug("%s: addr %#" HWADDR_PRIx "\n", __func__, addr);
982 956
983 /* TODO: EISR/EIMR */ 957 /* TODO: EISR/EIMR */
984 958
985 return r; 959 return r;
986} 960}
987 961
988static void openpic_summary_write(void *opaque, hwaddr addr, uint64_t val, 962static void openpic_summary_write(void *opaque, gpa_t addr, uint64_t val,
989 unsigned size) 963 unsigned size)
990{ 964{
991 DPRINTF("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64 "\n", 965 pr_debug("%s: addr %#" HWADDR_PRIx " <= 0x%08" PRIx64 "\n",
992 __func__, addr, val); 966 __func__, addr, val);
993 967
994 /* TODO: EISR/EIMR */ 968 /* TODO: EISR/EIMR */
995} 969}
996 970
997static void openpic_cpu_write_internal(void *opaque, hwaddr addr, 971static void openpic_cpu_write_internal(void *opaque, gpa_t addr,
998 uint32_t val, int idx) 972 uint32_t val, int idx)
999{ 973{
1000 OpenPICState *opp = opaque; 974 struct openpic *opp = opaque;
1001 IRQSource *src; 975 struct irq_source *src;
1002 IRQDest *dst; 976 struct irq_dest *dst;
1003 int s_IRQ, n_IRQ; 977 int s_IRQ, n_IRQ;
1004 978
1005 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx " <= 0x%08x\n", __func__, idx, 979 pr_debug("%s: cpu %d addr %#" HWADDR_PRIx " <= 0x%08x\n", __func__, idx,
1006 addr, val); 980 addr, val);
1007 981
1008 if (idx < 0) { 982 if (idx < 0)
1009 return; 983 return;
1010 }
1011 984
1012 if (addr & 0xF) { 985 if (addr & 0xF)
1013 return; 986 return;
1014 } 987
1015 dst = &opp->dst[idx]; 988 dst = &opp->dst[idx];
1016 addr &= 0xFF0; 989 addr &= 0xFF0;
1017 switch (addr) { 990 switch (addr) {
@@ -1028,17 +1001,16 @@ static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
1028 case 0x80: /* CTPR */ 1001 case 0x80: /* CTPR */
1029 dst->ctpr = val & 0x0000000F; 1002 dst->ctpr = val & 0x0000000F;
1030 1003
1031 DPRINTF("%s: set CPU %d ctpr to %d, raised %d servicing %d\n", 1004 pr_debug("%s: set CPU %d ctpr to %d, raised %d servicing %d\n",
1032 __func__, idx, dst->ctpr, dst->raised.priority, 1005 __func__, idx, dst->ctpr, dst->raised.priority,
1033 dst->servicing.priority); 1006 dst->servicing.priority);
1034 1007
1035 if (dst->raised.priority <= dst->ctpr) { 1008 if (dst->raised.priority <= dst->ctpr) {
1036 DPRINTF 1009 pr_debug("%s: Lower OpenPIC INT output cpu %d due to ctpr\n",
1037 ("%s: Lower OpenPIC INT output cpu %d due to ctpr\n", 1010 __func__, idx);
1038 __func__, idx);
1039 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]); 1011 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]);
1040 } else if (dst->raised.priority > dst->servicing.priority) { 1012 } else if (dst->raised.priority > dst->servicing.priority) {
1041 DPRINTF("%s: Raise OpenPIC INT output cpu %d irq %d\n", 1013 pr_debug("%s: Raise OpenPIC INT output cpu %d irq %d\n",
1042 __func__, idx, dst->raised.next); 1014 __func__, idx, dst->raised.next);
1043 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_INT]); 1015 qemu_irq_raise(dst->irqs[OPENPIC_OUTPUT_INT]);
1044 } 1016 }
@@ -1051,11 +1023,11 @@ static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
1051 /* Read-only register */ 1023 /* Read-only register */
1052 break; 1024 break;
1053 case 0xB0: /* EOI */ 1025 case 0xB0: /* EOI */
1054 DPRINTF("EOI\n"); 1026 pr_debug("EOI\n");
1055 s_IRQ = IRQ_get_next(opp, &dst->servicing); 1027 s_IRQ = IRQ_get_next(opp, &dst->servicing);
1056 1028
1057 if (s_IRQ < 0) { 1029 if (s_IRQ < 0) {
1058 DPRINTF("%s: EOI with no interrupt in service\n", 1030 pr_debug("%s: EOI with no interrupt in service\n",
1059 __func__); 1031 __func__);
1060 break; 1032 break;
1061 } 1033 }
@@ -1069,7 +1041,7 @@ static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
1069 if (n_IRQ != -1 && 1041 if (n_IRQ != -1 &&
1070 (s_IRQ == -1 || 1042 (s_IRQ == -1 ||
1071 IVPR_PRIORITY(src->ivpr) > dst->servicing.priority)) { 1043 IVPR_PRIORITY(src->ivpr) > dst->servicing.priority)) {
1072 DPRINTF("Raise OpenPIC INT output cpu %d irq %d\n", 1044 pr_debug("Raise OpenPIC INT output cpu %d irq %d\n",
1073 idx, n_IRQ); 1045 idx, n_IRQ);
1074 qemu_irq_raise(opp->dst[idx].irqs[OPENPIC_OUTPUT_INT]); 1046 qemu_irq_raise(opp->dst[idx].irqs[OPENPIC_OUTPUT_INT]);
1075 } 1047 }
@@ -1079,32 +1051,32 @@ static void openpic_cpu_write_internal(void *opaque, hwaddr addr,
1079 } 1051 }
1080} 1052}
1081 1053
1082static void openpic_cpu_write(void *opaque, hwaddr addr, uint64_t val, 1054static void openpic_cpu_write(void *opaque, gpa_t addr, uint64_t val,
1083 unsigned len) 1055 unsigned len)
1084{ 1056{
1085 openpic_cpu_write_internal(opaque, addr, val, (addr & 0x1f000) >> 12); 1057 openpic_cpu_write_internal(opaque, addr, val, (addr & 0x1f000) >> 12);
1086} 1058}
1087 1059
1088static uint32_t openpic_iack(OpenPICState * opp, IRQDest * dst, int cpu) 1060static uint32_t openpic_iack(struct openpic *opp, struct irq_dest *dst,
1061 int cpu)
1089{ 1062{
1090 IRQSource *src; 1063 struct irq_source *src;
1091 int retval, irq; 1064 int retval, irq;
1092 1065
1093 DPRINTF("Lower OpenPIC INT output\n"); 1066 pr_debug("Lower OpenPIC INT output\n");
1094 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]); 1067 qemu_irq_lower(dst->irqs[OPENPIC_OUTPUT_INT]);
1095 1068
1096 irq = IRQ_get_next(opp, &dst->raised); 1069 irq = IRQ_get_next(opp, &dst->raised);
1097 DPRINTF("IACK: irq=%d\n", irq); 1070 pr_debug("IACK: irq=%d\n", irq);
1098 1071
1099 if (irq == -1) { 1072 if (irq == -1)
1100 /* No more interrupt pending */ 1073 /* No more interrupt pending */
1101 return opp->spve; 1074 return opp->spve;
1102 }
1103 1075
1104 src = &opp->src[irq]; 1076 src = &opp->src[irq];
1105 if (!(src->ivpr & IVPR_ACTIVITY_MASK) || 1077 if (!(src->ivpr & IVPR_ACTIVITY_MASK) ||
1106 !(IVPR_PRIORITY(src->ivpr) > dst->ctpr)) { 1078 !(IVPR_PRIORITY(src->ivpr) > dst->ctpr)) {
1107 fprintf(stderr, "%s: bad raised IRQ %d ctpr %d ivpr 0x%08x\n", 1079 pr_err("%s: bad raised IRQ %d ctpr %d ivpr 0x%08x\n",
1108 __func__, irq, dst->ctpr, src->ivpr); 1080 __func__, irq, dst->ctpr, src->ivpr);
1109 openpic_update_irq(opp, irq); 1081 openpic_update_irq(opp, irq);
1110 retval = opp->spve; 1082 retval = opp->spve;
@@ -1135,22 +1107,21 @@ static uint32_t openpic_iack(OpenPICState * opp, IRQDest * dst, int cpu)
1135 return retval; 1107 return retval;
1136} 1108}
1137 1109
1138static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, int idx) 1110static uint32_t openpic_cpu_read_internal(void *opaque, gpa_t addr, int idx)
1139{ 1111{
1140 OpenPICState *opp = opaque; 1112 struct openpic *opp = opaque;
1141 IRQDest *dst; 1113 struct irq_dest *dst;
1142 uint32_t retval; 1114 uint32_t retval;
1143 1115
1144 DPRINTF("%s: cpu %d addr %#" HWADDR_PRIx "\n", __func__, idx, addr); 1116 pr_debug("%s: cpu %d addr %#" HWADDR_PRIx "\n", __func__, idx, addr);
1145 retval = 0xFFFFFFFF; 1117 retval = 0xFFFFFFFF;
1146 1118
1147 if (idx < 0) { 1119 if (idx < 0)
1148 return retval; 1120 return retval;
1149 }
1150 1121
1151 if (addr & 0xF) { 1122 if (addr & 0xF)
1152 return retval; 1123 return retval;
1153 } 1124
1154 dst = &opp->dst[idx]; 1125 dst = &opp->dst[idx];
1155 addr &= 0xFF0; 1126 addr &= 0xFF0;
1156 switch (addr) { 1127 switch (addr) {
@@ -1169,54 +1140,54 @@ static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, int idx)
1169 default: 1140 default:
1170 break; 1141 break;
1171 } 1142 }
1172 DPRINTF("%s: => 0x%08x\n", __func__, retval); 1143 pr_debug("%s: => 0x%08x\n", __func__, retval);
1173 1144
1174 return retval; 1145 return retval;
1175} 1146}
1176 1147
1177static uint64_t openpic_cpu_read(void *opaque, hwaddr addr, unsigned len) 1148static uint64_t openpic_cpu_read(void *opaque, gpa_t addr, unsigned len)
1178{ 1149{
1179 return openpic_cpu_read_internal(opaque, addr, (addr & 0x1f000) >> 12); 1150 return openpic_cpu_read_internal(opaque, addr, (addr & 0x1f000) >> 12);
1180} 1151}
1181 1152
1182static const MemoryRegionOps openpic_glb_ops_be = { 1153static const struct kvm_io_device_ops openpic_glb_ops_be = {
1183 .write = openpic_gbl_write, 1154 .write = openpic_gbl_write,
1184 .read = openpic_gbl_read, 1155 .read = openpic_gbl_read,
1185}; 1156};
1186 1157
1187static const MemoryRegionOps openpic_tmr_ops_be = { 1158static const struct kvm_io_device_ops openpic_tmr_ops_be = {
1188 .write = openpic_tmr_write, 1159 .write = openpic_tmr_write,
1189 .read = openpic_tmr_read, 1160 .read = openpic_tmr_read,
1190}; 1161};
1191 1162
1192static const MemoryRegionOps openpic_cpu_ops_be = { 1163static const struct kvm_io_device_ops openpic_cpu_ops_be = {
1193 .write = openpic_cpu_write, 1164 .write = openpic_cpu_write,
1194 .read = openpic_cpu_read, 1165 .read = openpic_cpu_read,
1195}; 1166};
1196 1167
1197static const MemoryRegionOps openpic_src_ops_be = { 1168static const struct kvm_io_device_ops openpic_src_ops_be = {
1198 .write = openpic_src_write, 1169 .write = openpic_src_write,
1199 .read = openpic_src_read, 1170 .read = openpic_src_read,
1200}; 1171};
1201 1172
1202static const MemoryRegionOps openpic_msi_ops_be = { 1173static const struct kvm_io_device_ops openpic_msi_ops_be = {
1203 .read = openpic_msi_read, 1174 .read = openpic_msi_read,
1204 .write = openpic_msi_write, 1175 .write = openpic_msi_write,
1205}; 1176};
1206 1177
1207static const MemoryRegionOps openpic_summary_ops_be = { 1178static const struct kvm_io_device_ops openpic_summary_ops_be = {
1208 .read = openpic_summary_read, 1179 .read = openpic_summary_read,
1209 .write = openpic_summary_write, 1180 .write = openpic_summary_write,
1210}; 1181};
1211 1182
1212typedef struct MemReg { 1183struct mem_reg {
1213 const char *name; 1184 const char *name;
1214 MemoryRegionOps const *ops; 1185 const struct kvm_io_device_ops *ops;
1215 hwaddr start_addr; 1186 gpa_t start_addr;
1216 ram_addr_t size; 1187 int size;
1217} MemReg; 1188};
1218 1189
1219static void fsl_common_init(OpenPICState * opp) 1190static void fsl_common_init(struct openpic *opp)
1220{ 1191{
1221 int i; 1192 int i;
1222 int virq = MAX_SRC; 1193 int virq = MAX_SRC;
@@ -1239,9 +1210,8 @@ static void fsl_common_init(OpenPICState * opp)
1239 opp->irq_msi = 224; 1210 opp->irq_msi = 224;
1240 1211
1241 msi_supported = true; 1212 msi_supported = true;
1242 for (i = 0; i < opp->fsl->max_ext; i++) { 1213 for (i = 0; i < opp->fsl->max_ext; i++)
1243 opp->src[i].level = false; 1214 opp->src[i].level = false;
1244 }
1245 1215
1246 /* Internal interrupts, including message and MSI */ 1216 /* Internal interrupts, including message and MSI */
1247 for (i = 16; i < MAX_SRC; i++) { 1217 for (i = 16; i < MAX_SRC; i++) {
@@ -1256,7 +1226,8 @@ static void fsl_common_init(OpenPICState * opp)
1256 } 1226 }
1257} 1227}
1258 1228
1259static void map_list(OpenPICState * opp, const MemReg * list, int *count) 1229static void map_list(struct openpic *opp, const struct mem_reg *list,
1230 int *count)
1260{ 1231{
1261 while (list->name) { 1232 while (list->name) {
1262 assert(*count < ARRAY_SIZE(opp->sub_io_mem)); 1233 assert(*count < ARRAY_SIZE(opp->sub_io_mem));
@@ -1272,12 +1243,12 @@ static void map_list(OpenPICState * opp, const MemReg * list, int *count)
1272 } 1243 }
1273} 1244}
1274 1245
1275static int openpic_init(SysBusDevice * dev) 1246static int openpic_init(SysBusDevice *dev)
1276{ 1247{
1277 OpenPICState *opp = FROM_SYSBUS(typeof(*opp), dev); 1248 struct openpic *opp = FROM_SYSBUS(typeof(*opp), dev);
1278 int i, j; 1249 int i, j;
1279 int list_count = 0; 1250 int list_count = 0;
1280 static const MemReg list_le[] = { 1251 static const struct mem_reg list_le[] = {
1281 {"glb", &openpic_glb_ops_le, 1252 {"glb", &openpic_glb_ops_le,
1282 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE}, 1253 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE},
1283 {"tmr", &openpic_tmr_ops_le, 1254 {"tmr", &openpic_tmr_ops_le,
@@ -1288,7 +1259,7 @@ static int openpic_init(SysBusDevice * dev)
1288 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE}, 1259 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE},
1289 {NULL} 1260 {NULL}
1290 }; 1261 };
1291 static const MemReg list_be[] = { 1262 static const struct mem_reg list_be[] = {
1292 {"glb", &openpic_glb_ops_be, 1263 {"glb", &openpic_glb_ops_be,
1293 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE}, 1264 OPENPIC_GLB_REG_START, OPENPIC_GLB_REG_SIZE},
1294 {"tmr", &openpic_tmr_ops_be, 1265 {"tmr", &openpic_tmr_ops_be,
@@ -1299,7 +1270,7 @@ static int openpic_init(SysBusDevice * dev)
1299 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE}, 1270 OPENPIC_CPU_REG_START, OPENPIC_CPU_REG_SIZE},
1300 {NULL} 1271 {NULL}
1301 }; 1272 };
1302 static const MemReg list_fsl[] = { 1273 static const struct mem_reg list_fsl[] = {
1303 {"msi", &openpic_msi_ops_be, 1274 {"msi", &openpic_msi_ops_be,
1304 OPENPIC_MSI_REG_START, OPENPIC_MSI_REG_SIZE}, 1275 OPENPIC_MSI_REG_START, OPENPIC_MSI_REG_SIZE},
1305 {"summary", &openpic_summary_ops_be, 1276 {"summary", &openpic_summary_ops_be,