]> Git Repo - qemu.git/blame - hw/alpha/typhoon.c
spapr: fix default DRC state for coldplugged LMBs
[qemu.git] / hw / alpha / typhoon.c
CommitLineData
80bb2ff7
RH
1/*
2 * DEC 21272 (TSUNAMI/TYPHOON) chipset emulation.
3 *
4 * Written by Richard Henderson.
5 *
6 * This work is licensed under the GNU GPL license version 2 or later.
7 */
8
e2e5e114 9#include "qemu/osdep.h"
da34e65c 10#include "qapi/error.h"
80bb2ff7 11#include "cpu.h"
83c9f4ca 12#include "hw/hw.h"
bd2be150 13#include "hw/devices.h"
9c17d615 14#include "sysemu/sysemu.h"
47b43a1f 15#include "alpha_sys.h"
022c62cb 16#include "exec/address-spaces.h"
80bb2ff7
RH
17
18
94dd91d6
AF
19#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost"
20
80bb2ff7
RH
21typedef struct TyphoonCchip {
22 MemoryRegion region;
23 uint64_t misc;
24 uint64_t drir;
25 uint64_t dim[4];
26 uint32_t iic[4];
ad601177 27 AlphaCPU *cpu[4];
80bb2ff7
RH
28} TyphoonCchip;
29
30typedef struct TyphoonWindow {
b83c4db8
RH
31 uint64_t wba;
32 uint64_t wsm;
33 uint64_t tba;
80bb2ff7
RH
34} TyphoonWindow;
35
36typedef struct TyphoonPchip {
37 MemoryRegion region;
38 MemoryRegion reg_iack;
39 MemoryRegion reg_mem;
40 MemoryRegion reg_io;
41 MemoryRegion reg_conf;
b83c4db8
RH
42
43 AddressSpace iommu_as;
44 MemoryRegion iommu;
45
80bb2ff7
RH
46 uint64_t ctl;
47 TyphoonWindow win[4];
48} TyphoonPchip;
49
94dd91d6
AF
50#define TYPHOON_PCI_HOST_BRIDGE(obj) \
51 OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE)
52
80bb2ff7 53typedef struct TyphoonState {
67c332fd 54 PCIHostState parent_obj;
94dd91d6 55
80bb2ff7
RH
56 TyphoonCchip cchip;
57 TyphoonPchip pchip;
58 MemoryRegion dchip_region;
59 MemoryRegion ram_region;
80bb2ff7
RH
60} TyphoonState;
61
62/* Called when one of DRIR or DIM changes. */
ad601177 63static void cpu_irq_change(AlphaCPU *cpu, uint64_t req)
80bb2ff7
RH
64{
65 /* If there are any non-masked interrupts, tell the cpu. */
ad601177 66 if (cpu != NULL) {
d8ed887b 67 CPUState *cs = CPU(cpu);
80bb2ff7 68 if (req) {
c3affe56 69 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
80bb2ff7 70 } else {
d8ed887b 71 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
80bb2ff7
RH
72 }
73 }
74}
75
a8170e5e 76static uint64_t cchip_read(void *opaque, hwaddr addr, unsigned size)
80bb2ff7 77{
4917cf44 78 CPUState *cpu = current_cpu;
80bb2ff7
RH
79 TyphoonState *s = opaque;
80 uint64_t ret = 0;
81
80bb2ff7
RH
82 switch (addr) {
83 case 0x0000:
84 /* CSC: Cchip System Configuration Register. */
85 /* All sorts of data here; probably the only thing relevant is
86 PIP<14> Pchip 1 Present = 0. */
87 break;
88
89 case 0x0040:
90 /* MTR: Memory Timing Register. */
91 /* All sorts of stuff related to real DRAM. */
92 break;
93
94 case 0x0080:
95 /* MISC: Miscellaneous Register. */
55e5c285 96 ret = s->cchip.misc | (cpu->cpu_index & 3);
80bb2ff7
RH
97 break;
98
99 case 0x00c0:
100 /* MPD: Memory Presence Detect Register. */
101 break;
102
103 case 0x0100: /* AAR0 */
104 case 0x0140: /* AAR1 */
105 case 0x0180: /* AAR2 */
106 case 0x01c0: /* AAR3 */
107 /* AAR: Array Address Register. */
108 /* All sorts of information about DRAM. */
109 break;
110
111 case 0x0200:
112 /* DIM0: Device Interrupt Mask Register, CPU0. */
113 ret = s->cchip.dim[0];
114 break;
115 case 0x0240:
116 /* DIM1: Device Interrupt Mask Register, CPU1. */
117 ret = s->cchip.dim[1];
118 break;
119 case 0x0280:
120 /* DIR0: Device Interrupt Request Register, CPU0. */
121 ret = s->cchip.dim[0] & s->cchip.drir;
122 break;
123 case 0x02c0:
124 /* DIR1: Device Interrupt Request Register, CPU1. */
125 ret = s->cchip.dim[1] & s->cchip.drir;
126 break;
127 case 0x0300:
128 /* DRIR: Device Raw Interrupt Request Register. */
129 ret = s->cchip.drir;
130 break;
131
132 case 0x0340:
133 /* PRBEN: Probe Enable Register. */
134 break;
135
136 case 0x0380:
137 /* IIC0: Interval Ignore Count Register, CPU0. */
138 ret = s->cchip.iic[0];
139 break;
140 case 0x03c0:
141 /* IIC1: Interval Ignore Count Register, CPU1. */
142 ret = s->cchip.iic[1];
143 break;
144
145 case 0x0400: /* MPR0 */
146 case 0x0440: /* MPR1 */
147 case 0x0480: /* MPR2 */
148 case 0x04c0: /* MPR3 */
149 /* MPR: Memory Programming Register. */
150 break;
151
152 case 0x0580:
153 /* TTR: TIGbus Timing Register. */
154 /* All sorts of stuff related to interrupt delivery timings. */
155 break;
156 case 0x05c0:
157 /* TDR: TIGbug Device Timing Register. */
158 break;
159
160 case 0x0600:
161 /* DIM2: Device Interrupt Mask Register, CPU2. */
162 ret = s->cchip.dim[2];
163 break;
164 case 0x0640:
165 /* DIM3: Device Interrupt Mask Register, CPU3. */
166 ret = s->cchip.dim[3];
167 break;
168 case 0x0680:
169 /* DIR2: Device Interrupt Request Register, CPU2. */
170 ret = s->cchip.dim[2] & s->cchip.drir;
171 break;
172 case 0x06c0:
173 /* DIR3: Device Interrupt Request Register, CPU3. */
174 ret = s->cchip.dim[3] & s->cchip.drir;
175 break;
176
177 case 0x0700:
178 /* IIC2: Interval Ignore Count Register, CPU2. */
179 ret = s->cchip.iic[2];
180 break;
181 case 0x0740:
182 /* IIC3: Interval Ignore Count Register, CPU3. */
183 ret = s->cchip.iic[3];
184 break;
185
186 case 0x0780:
187 /* PWR: Power Management Control. */
188 break;
189
190 case 0x0c00: /* CMONCTLA */
191 case 0x0c40: /* CMONCTLB */
192 case 0x0c80: /* CMONCNT01 */
193 case 0x0cc0: /* CMONCNT23 */
194 break;
195
196 default:
c658b94f 197 cpu_unassigned_access(cpu, addr, false, false, 0, size);
80bb2ff7
RH
198 return -1;
199 }
200
80bb2ff7
RH
201 return ret;
202}
203
a8170e5e 204static uint64_t dchip_read(void *opaque, hwaddr addr, unsigned size)
80bb2ff7
RH
205{
206 /* Skip this. It's all related to DRAM timing and setup. */
207 return 0;
208}
209
a8170e5e 210static uint64_t pchip_read(void *opaque, hwaddr addr, unsigned size)
80bb2ff7
RH
211{
212 TyphoonState *s = opaque;
213 uint64_t ret = 0;
214
80bb2ff7
RH
215 switch (addr) {
216 case 0x0000:
217 /* WSBA0: Window Space Base Address Register. */
b83c4db8 218 ret = s->pchip.win[0].wba;
80bb2ff7
RH
219 break;
220 case 0x0040:
221 /* WSBA1 */
b83c4db8 222 ret = s->pchip.win[1].wba;
80bb2ff7
RH
223 break;
224 case 0x0080:
225 /* WSBA2 */
b83c4db8 226 ret = s->pchip.win[2].wba;
80bb2ff7
RH
227 break;
228 case 0x00c0:
229 /* WSBA3 */
b83c4db8 230 ret = s->pchip.win[3].wba;
80bb2ff7
RH
231 break;
232
233 case 0x0100:
234 /* WSM0: Window Space Mask Register. */
b83c4db8 235 ret = s->pchip.win[0].wsm;
80bb2ff7
RH
236 break;
237 case 0x0140:
238 /* WSM1 */
b83c4db8 239 ret = s->pchip.win[1].wsm;
80bb2ff7
RH
240 break;
241 case 0x0180:
242 /* WSM2 */
b83c4db8 243 ret = s->pchip.win[2].wsm;
80bb2ff7
RH
244 break;
245 case 0x01c0:
246 /* WSM3 */
b83c4db8 247 ret = s->pchip.win[3].wsm;
80bb2ff7
RH
248 break;
249
250 case 0x0200:
251 /* TBA0: Translated Base Address Register. */
b83c4db8 252 ret = s->pchip.win[0].tba;
80bb2ff7
RH
253 break;
254 case 0x0240:
255 /* TBA1 */
b83c4db8 256 ret = s->pchip.win[1].tba;
80bb2ff7
RH
257 break;
258 case 0x0280:
259 /* TBA2 */
b83c4db8 260 ret = s->pchip.win[2].tba;
80bb2ff7
RH
261 break;
262 case 0x02c0:
263 /* TBA3 */
b83c4db8 264 ret = s->pchip.win[3].tba;
80bb2ff7
RH
265 break;
266
267 case 0x0300:
268 /* PCTL: Pchip Control Register. */
269 ret = s->pchip.ctl;
270 break;
271 case 0x0340:
272 /* PLAT: Pchip Master Latency Register. */
273 break;
274 case 0x03c0:
275 /* PERROR: Pchip Error Register. */
276 break;
277 case 0x0400:
278 /* PERRMASK: Pchip Error Mask Register. */
279 break;
280 case 0x0440:
281 /* PERRSET: Pchip Error Set Register. */
282 break;
283 case 0x0480:
284 /* TLBIV: Translation Buffer Invalidate Virtual Register (WO). */
285 break;
286 case 0x04c0:
287 /* TLBIA: Translation Buffer Invalidate All Register (WO). */
288 break;
289 case 0x0500: /* PMONCTL */
290 case 0x0540: /* PMONCNT */
291 case 0x0800: /* SPRST */
292 break;
293
294 default:
4917cf44 295 cpu_unassigned_access(current_cpu, addr, false, false, 0, size);
80bb2ff7
RH
296 return -1;
297 }
298
80bb2ff7
RH
299 return ret;
300}
301
a8170e5e 302static void cchip_write(void *opaque, hwaddr addr,
67842165 303 uint64_t val, unsigned size)
80bb2ff7
RH
304{
305 TyphoonState *s = opaque;
67842165 306 uint64_t oldval, newval;
80bb2ff7
RH
307
308 switch (addr) {
309 case 0x0000:
310 /* CSC: Cchip System Configuration Register. */
311 /* All sorts of data here; nothing relevant RW. */
312 break;
313
314 case 0x0040:
315 /* MTR: Memory Timing Register. */
316 /* All sorts of stuff related to real DRAM. */
317 break;
318
319 case 0x0080:
320 /* MISC: Miscellaneous Register. */
321 newval = oldval = s->cchip.misc;
322 newval &= ~(val & 0x10000ff0); /* W1C fields */
323 if (val & 0x100000) {
324 newval &= ~0xff0000ull; /* ACL clears ABT and ABW */
325 } else {
326 newval |= val & 0x00f00000; /* ABT field is W1S */
327 if ((newval & 0xf0000) == 0) {
328 newval |= val & 0xf0000; /* ABW field is W1S iff zero */
329 }
330 }
331 newval |= (val & 0xf000) >> 4; /* IPREQ field sets IPINTR. */
332
333 newval &= ~0xf0000000000ull; /* WO and RW fields */
334 newval |= val & 0xf0000000000ull;
335 s->cchip.misc = newval;
336
337 /* Pass on changes to IPI and ITI state. */
338 if ((newval ^ oldval) & 0xff0) {
339 int i;
340 for (i = 0; i < 4; ++i) {
ad601177
AF
341 AlphaCPU *cpu = s->cchip.cpu[i];
342 if (cpu != NULL) {
d8ed887b 343 CPUState *cs = CPU(cpu);
80bb2ff7
RH
344 /* IPI can be either cleared or set by the write. */
345 if (newval & (1 << (i + 8))) {
c3affe56 346 cpu_interrupt(cs, CPU_INTERRUPT_SMP);
80bb2ff7 347 } else {
d8ed887b 348 cpu_reset_interrupt(cs, CPU_INTERRUPT_SMP);
80bb2ff7
RH
349 }
350
351 /* ITI can only be cleared by the write. */
352 if ((newval & (1 << (i + 4))) == 0) {
d8ed887b 353 cpu_reset_interrupt(cs, CPU_INTERRUPT_TIMER);
80bb2ff7
RH
354 }
355 }
356 }
357 }
358 break;
359
360 case 0x00c0:
361 /* MPD: Memory Presence Detect Register. */
362 break;
363
364 case 0x0100: /* AAR0 */
365 case 0x0140: /* AAR1 */
366 case 0x0180: /* AAR2 */
367 case 0x01c0: /* AAR3 */
368 /* AAR: Array Address Register. */
369 /* All sorts of information about DRAM. */
370 break;
371
372 case 0x0200: /* DIM0 */
373 /* DIM: Device Interrupt Mask Register, CPU0. */
374 s->cchip.dim[0] = val;
375 cpu_irq_change(s->cchip.cpu[0], val & s->cchip.drir);
376 break;
377 case 0x0240: /* DIM1 */
378 /* DIM: Device Interrupt Mask Register, CPU1. */
424ad838 379 s->cchip.dim[1] = val;
80bb2ff7
RH
380 cpu_irq_change(s->cchip.cpu[1], val & s->cchip.drir);
381 break;
382
383 case 0x0280: /* DIR0 (RO) */
384 case 0x02c0: /* DIR1 (RO) */
385 case 0x0300: /* DRIR (RO) */
386 break;
387
388 case 0x0340:
389 /* PRBEN: Probe Enable Register. */
390 break;
391
392 case 0x0380: /* IIC0 */
393 s->cchip.iic[0] = val & 0xffffff;
394 break;
395 case 0x03c0: /* IIC1 */
396 s->cchip.iic[1] = val & 0xffffff;
397 break;
398
399 case 0x0400: /* MPR0 */
400 case 0x0440: /* MPR1 */
401 case 0x0480: /* MPR2 */
402 case 0x04c0: /* MPR3 */
403 /* MPR: Memory Programming Register. */
404 break;
405
406 case 0x0580:
407 /* TTR: TIGbus Timing Register. */
408 /* All sorts of stuff related to interrupt delivery timings. */
409 break;
410 case 0x05c0:
411 /* TDR: TIGbug Device Timing Register. */
412 break;
413
414 case 0x0600:
415 /* DIM2: Device Interrupt Mask Register, CPU2. */
416 s->cchip.dim[2] = val;
417 cpu_irq_change(s->cchip.cpu[2], val & s->cchip.drir);
418 break;
419 case 0x0640:
420 /* DIM3: Device Interrupt Mask Register, CPU3. */
421 s->cchip.dim[3] = val;
422 cpu_irq_change(s->cchip.cpu[3], val & s->cchip.drir);
423 break;
424
425 case 0x0680: /* DIR2 (RO) */
426 case 0x06c0: /* DIR3 (RO) */
427 break;
428
429 case 0x0700: /* IIC2 */
430 s->cchip.iic[2] = val & 0xffffff;
431 break;
432 case 0x0740: /* IIC3 */
433 s->cchip.iic[3] = val & 0xffffff;
434 break;
435
436 case 0x0780:
437 /* PWR: Power Management Control. */
438 break;
439
440 case 0x0c00: /* CMONCTLA */
441 case 0x0c40: /* CMONCTLB */
442 case 0x0c80: /* CMONCNT01 */
443 case 0x0cc0: /* CMONCNT23 */
444 break;
445
446 default:
4917cf44 447 cpu_unassigned_access(current_cpu, addr, true, false, 0, size);
80bb2ff7
RH
448 return;
449 }
450}
451
a8170e5e 452static void dchip_write(void *opaque, hwaddr addr,
80bb2ff7
RH
453 uint64_t val, unsigned size)
454{
455 /* Skip this. It's all related to DRAM timing and setup. */
456}
457
a8170e5e 458static void pchip_write(void *opaque, hwaddr addr,
67842165 459 uint64_t val, unsigned size)
80bb2ff7
RH
460{
461 TyphoonState *s = opaque;
67842165 462 uint64_t oldval;
80bb2ff7
RH
463
464 switch (addr) {
465 case 0x0000:
466 /* WSBA0: Window Space Base Address Register. */
b83c4db8 467 s->pchip.win[0].wba = val & 0xfff00003u;
80bb2ff7
RH
468 break;
469 case 0x0040:
470 /* WSBA1 */
b83c4db8 471 s->pchip.win[1].wba = val & 0xfff00003u;
80bb2ff7
RH
472 break;
473 case 0x0080:
474 /* WSBA2 */
b83c4db8 475 s->pchip.win[2].wba = val & 0xfff00003u;
80bb2ff7
RH
476 break;
477 case 0x00c0:
478 /* WSBA3 */
b83c4db8 479 s->pchip.win[3].wba = (val & 0x80fff00001ull) | 2;
80bb2ff7
RH
480 break;
481
482 case 0x0100:
483 /* WSM0: Window Space Mask Register. */
b83c4db8 484 s->pchip.win[0].wsm = val & 0xfff00000u;
80bb2ff7
RH
485 break;
486 case 0x0140:
487 /* WSM1 */
b83c4db8 488 s->pchip.win[1].wsm = val & 0xfff00000u;
80bb2ff7
RH
489 break;
490 case 0x0180:
491 /* WSM2 */
b83c4db8 492 s->pchip.win[2].wsm = val & 0xfff00000u;
80bb2ff7
RH
493 break;
494 case 0x01c0:
495 /* WSM3 */
b83c4db8 496 s->pchip.win[3].wsm = val & 0xfff00000u;
80bb2ff7
RH
497 break;
498
499 case 0x0200:
500 /* TBA0: Translated Base Address Register. */
b83c4db8 501 s->pchip.win[0].tba = val & 0x7fffffc00ull;
80bb2ff7
RH
502 break;
503 case 0x0240:
504 /* TBA1 */
b83c4db8 505 s->pchip.win[1].tba = val & 0x7fffffc00ull;
80bb2ff7
RH
506 break;
507 case 0x0280:
508 /* TBA2 */
b83c4db8 509 s->pchip.win[2].tba = val & 0x7fffffc00ull;
80bb2ff7
RH
510 break;
511 case 0x02c0:
512 /* TBA3 */
b83c4db8 513 s->pchip.win[3].tba = val & 0x7fffffc00ull;
80bb2ff7
RH
514 break;
515
516 case 0x0300:
517 /* PCTL: Pchip Control Register. */
518 oldval = s->pchip.ctl;
519 oldval &= ~0x00001cff0fc7ffull; /* RW fields */
520 oldval |= val & 0x00001cff0fc7ffull;
80bb2ff7
RH
521 s->pchip.ctl = oldval;
522 break;
523
524 case 0x0340:
525 /* PLAT: Pchip Master Latency Register. */
526 break;
527 case 0x03c0:
528 /* PERROR: Pchip Error Register. */
529 break;
530 case 0x0400:
531 /* PERRMASK: Pchip Error Mask Register. */
532 break;
533 case 0x0440:
534 /* PERRSET: Pchip Error Set Register. */
535 break;
536
537 case 0x0480:
538 /* TLBIV: Translation Buffer Invalidate Virtual Register. */
539 break;
540
541 case 0x04c0:
542 /* TLBIA: Translation Buffer Invalidate All Register (WO). */
543 break;
544
545 case 0x0500:
546 /* PMONCTL */
547 case 0x0540:
548 /* PMONCNT */
549 case 0x0800:
550 /* SPRST */
551 break;
552
553 default:
4917cf44 554 cpu_unassigned_access(current_cpu, addr, true, false, 0, size);
80bb2ff7
RH
555 return;
556 }
557}
558
559static const MemoryRegionOps cchip_ops = {
560 .read = cchip_read,
561 .write = cchip_write,
562 .endianness = DEVICE_LITTLE_ENDIAN,
563 .valid = {
67842165 564 .min_access_size = 8,
80bb2ff7
RH
565 .max_access_size = 8,
566 },
567 .impl = {
67842165
RH
568 .min_access_size = 8,
569 .max_access_size = 8,
80bb2ff7
RH
570 },
571};
572
573static const MemoryRegionOps dchip_ops = {
574 .read = dchip_read,
575 .write = dchip_write,
576 .endianness = DEVICE_LITTLE_ENDIAN,
577 .valid = {
67842165 578 .min_access_size = 8,
80bb2ff7
RH
579 .max_access_size = 8,
580 },
581 .impl = {
67842165 582 .min_access_size = 8,
80bb2ff7
RH
583 .max_access_size = 8,
584 },
585};
586
587static const MemoryRegionOps pchip_ops = {
588 .read = pchip_read,
589 .write = pchip_write,
590 .endianness = DEVICE_LITTLE_ENDIAN,
591 .valid = {
67842165 592 .min_access_size = 8,
80bb2ff7
RH
593 .max_access_size = 8,
594 },
595 .impl = {
67842165
RH
596 .min_access_size = 8,
597 .max_access_size = 8,
80bb2ff7
RH
598 },
599};
600
b83c4db8
RH
601/* A subroutine of typhoon_translate_iommu that builds an IOMMUTLBEntry
602 using the given translated address and mask. */
603static bool make_iommu_tlbe(hwaddr taddr, hwaddr mask, IOMMUTLBEntry *ret)
604{
605 *ret = (IOMMUTLBEntry) {
606 .target_as = &address_space_memory,
607 .translated_addr = taddr,
608 .addr_mask = mask,
609 .perm = IOMMU_RW,
610 };
611 return true;
612}
613
614/* A subroutine of typhoon_translate_iommu that handles scatter-gather
615 translation, given the address of the PTE. */
616static bool pte_translate(hwaddr pte_addr, IOMMUTLBEntry *ret)
617{
42874d3a
PM
618 uint64_t pte = address_space_ldq(&address_space_memory, pte_addr,
619 MEMTXATTRS_UNSPECIFIED, NULL);
b83c4db8
RH
620
621 /* Check valid bit. */
622 if ((pte & 1) == 0) {
623 return false;
624 }
625
626 return make_iommu_tlbe((pte & 0x3ffffe) << 12, 0x1fff, ret);
627}
628
629/* A subroutine of typhoon_translate_iommu that handles one of the
630 four single-address-cycle translation windows. */
631static bool window_translate(TyphoonWindow *win, hwaddr addr,
632 IOMMUTLBEntry *ret)
633{
634 uint32_t wba = win->wba;
635 uint64_t wsm = win->wsm;
636 uint64_t tba = win->tba;
637 uint64_t wsm_ext = wsm | 0xfffff;
638
639 /* Check for window disabled. */
640 if ((wba & 1) == 0) {
641 return false;
642 }
643
644 /* Check for window hit. */
645 if ((addr & ~wsm_ext) != (wba & 0xfff00000u)) {
646 return false;
647 }
648
649 if (wba & 2) {
650 /* Scatter-gather translation. */
651 hwaddr pte_addr;
652
653 /* See table 10-6, Generating PTE address for PCI DMA Address. */
654 pte_addr = tba & ~(wsm >> 10);
655 pte_addr |= (addr & (wsm | 0xfe000)) >> 10;
656 return pte_translate(pte_addr, ret);
657 } else {
658 /* Direct-mapped translation. */
659 return make_iommu_tlbe(tba & ~wsm_ext, wsm_ext, ret);
660 }
661}
662
663/* Handle PCI-to-system address translation. */
664/* TODO: A translation failure here ought to set PCI error codes on the
665 Pchip and generate a machine check interrupt. */
8d7b8cb9
LT
666static IOMMUTLBEntry typhoon_translate_iommu(MemoryRegion *iommu, hwaddr addr,
667 bool is_write)
b83c4db8
RH
668{
669 TyphoonPchip *pchip = container_of(iommu, TyphoonPchip, iommu);
670 IOMMUTLBEntry ret;
671 int i;
672
673 if (addr <= 0xffffffffu) {
674 /* Single-address cycle. */
675
676 /* Check for the Window Hole, inhibiting matching. */
677 if ((pchip->ctl & 0x20)
678 && addr >= 0x80000
679 && addr <= 0xfffff) {
680 goto failure;
681 }
682
683 /* Check the first three windows. */
684 for (i = 0; i < 3; ++i) {
685 if (window_translate(&pchip->win[i], addr, &ret)) {
686 goto success;
687 }
688 }
689
690 /* Check the fourth window for DAC disable. */
691 if ((pchip->win[3].wba & 0x80000000000ull) == 0
692 && window_translate(&pchip->win[3], addr, &ret)) {
693 goto success;
694 }
695 } else {
696 /* Double-address cycle. */
697
698 if (addr >= 0x10000000000ull && addr < 0x20000000000ull) {
699 /* Check for the DMA monster window. */
700 if (pchip->ctl & 0x40) {
701 /* See 10.1.4.4; in particular <39:35> is ignored. */
702 make_iommu_tlbe(0, 0x007ffffffffull, &ret);
703 goto success;
704 }
705 }
706
9b2caaf4 707 if (addr >= 0x80000000000ull && addr <= 0xfffffffffffull) {
b83c4db8
RH
708 /* Check the fourth window for DAC enable and window enable. */
709 if ((pchip->win[3].wba & 0x80000000001ull) == 0x80000000001ull) {
710 uint64_t pte_addr;
711
712 pte_addr = pchip->win[3].tba & 0x7ffc00000ull;
713 pte_addr |= (addr & 0xffffe000u) >> 10;
714 if (pte_translate(pte_addr, &ret)) {
715 goto success;
716 }
717 }
718 }
719 }
720
721 failure:
722 ret = (IOMMUTLBEntry) { .perm = IOMMU_NONE };
723 success:
724 return ret;
725}
726
727static const MemoryRegionIOMMUOps typhoon_iommu_ops = {
728 .translate = typhoon_translate_iommu,
729};
730
731static AddressSpace *typhoon_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
732{
733 TyphoonState *s = opaque;
734 return &s->pchip.iommu_as;
735}
736
80bb2ff7
RH
737static void typhoon_set_irq(void *opaque, int irq, int level)
738{
739 TyphoonState *s = opaque;
740 uint64_t drir;
741 int i;
742
743 /* Set/Reset the bit in CCHIP.DRIR based on IRQ+LEVEL. */
744 drir = s->cchip.drir;
745 if (level) {
746 drir |= 1ull << irq;
747 } else {
748 drir &= ~(1ull << irq);
749 }
750 s->cchip.drir = drir;
751
752 for (i = 0; i < 4; ++i) {
753 cpu_irq_change(s->cchip.cpu[i], s->cchip.dim[i] & drir);
754 }
755}
756
757static void typhoon_set_isa_irq(void *opaque, int irq, int level)
758{
759 typhoon_set_irq(opaque, 55, level);
760}
761
762static void typhoon_set_timer_irq(void *opaque, int irq, int level)
763{
764 TyphoonState *s = opaque;
765 int i;
766
767 /* Thankfully, the mc146818rtc code doesn't track the IRQ state,
768 and so we don't have to worry about missing interrupts just
769 because we never actually ACK the interrupt. Just ignore any
770 case of the interrupt level going low. */
771 if (level == 0) {
772 return;
773 }
774
775 /* Deliver the interrupt to each CPU, considering each CPU's IIC. */
776 for (i = 0; i < 4; ++i) {
ad601177
AF
777 AlphaCPU *cpu = s->cchip.cpu[i];
778 if (cpu != NULL) {
80bb2ff7
RH
779 uint32_t iic = s->cchip.iic[i];
780
781 /* ??? The verbage in Section 10.2.2.10 isn't 100% clear.
782 Bit 24 is the OverFlow bit, RO, and set when the count
783 decrements past 0. When is OF cleared? My guess is that
784 OF is actually cleared when the IIC is written, and that
785 the ICNT field always decrements. At least, that's an
786 interpretation that makes sense, and "allows the CPU to
787 determine exactly how mant interval timer ticks were
788 skipped". At least within the next 4M ticks... */
789
790 iic = ((iic - 1) & 0x1ffffff) | (iic & 0x1000000);
791 s->cchip.iic[i] = iic;
792
793 if (iic & 0x1000000) {
794 /* Set the ITI bit for this cpu. */
795 s->cchip.misc |= 1 << (i + 4);
796 /* And signal the interrupt. */
c3affe56 797 cpu_interrupt(CPU(cpu), CPU_INTERRUPT_TIMER);
80bb2ff7
RH
798 }
799 }
800 }
801}
802
c781cf96
RH
803static void typhoon_alarm_timer(void *opaque)
804{
805 TyphoonState *s = (TyphoonState *)((uintptr_t)opaque & ~3);
806 int cpu = (uintptr_t)opaque & 3;
807
808 /* Set the ITI bit for this cpu. */
809 s->cchip.misc |= 1 << (cpu + 4);
c3affe56 810 cpu_interrupt(CPU(s->cchip.cpu[cpu]), CPU_INTERRUPT_TIMER);
c781cf96
RH
811}
812
71baa303
HP
813PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
814 qemu_irq *p_rtc_irq,
ad601177 815 AlphaCPU *cpus[4], pci_map_irq_fn sys_map_irq)
80bb2ff7
RH
816{
817 const uint64_t MB = 1024 * 1024;
818 const uint64_t GB = 1024 * MB;
819 MemoryRegion *addr_space = get_system_memory();
80bb2ff7 820 DeviceState *dev;
80bb2ff7 821 TyphoonState *s;
94dd91d6 822 PCIHostState *phb;
80bb2ff7 823 PCIBus *b;
c781cf96 824 int i;
80bb2ff7 825
94dd91d6 826 dev = qdev_create(NULL, TYPE_TYPHOON_PCI_HOST_BRIDGE);
80bb2ff7 827
94dd91d6 828 s = TYPHOON_PCI_HOST_BRIDGE(dev);
8558d942 829 phb = PCI_HOST_BRIDGE(dev);
80bb2ff7 830
b83c4db8
RH
831 s->cchip.misc = 0x800000000ull; /* Revision: Typhoon. */
832 s->pchip.win[3].wba = 2; /* Window 3 SG always enabled. */
833
80bb2ff7 834 /* Remember the CPUs so that we can deliver interrupts to them. */
c781cf96 835 for (i = 0; i < 4; i++) {
ad601177
AF
836 AlphaCPU *cpu = cpus[i];
837 s->cchip.cpu[i] = cpu;
838 if (cpu != NULL) {
bc72ad67 839 cpu->alarm_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
c781cf96
RH
840 typhoon_alarm_timer,
841 (void *)((uintptr_t)s + i));
842 }
843 }
80bb2ff7 844
54292736 845 *p_rtc_irq = qemu_allocate_irq(typhoon_set_timer_irq, s, 0);
80bb2ff7
RH
846
847 /* Main memory region, 0x00.0000.0000. Real hardware supports 32GB,
848 but the address space hole reserved at this point is 8TB. */
58c24a47
DM
849 memory_region_allocate_system_memory(&s->ram_region, OBJECT(s), "ram",
850 ram_size);
80bb2ff7
RH
851 memory_region_add_subregion(addr_space, 0, &s->ram_region);
852
853 /* TIGbus, 0x801.0000.0000, 1GB. */
854 /* ??? The TIGbus is used for delivering interrupts, and access to
855 the flash ROM. I'm not sure that we need to implement it at all. */
856
857 /* Pchip0 CSRs, 0x801.8000.0000, 256MB. */
64bde0f3
PB
858 memory_region_init_io(&s->pchip.region, OBJECT(s), &pchip_ops, s, "pchip0",
859 256*MB);
02d6516c
SW
860 memory_region_add_subregion(addr_space, 0x80180000000ULL,
861 &s->pchip.region);
80bb2ff7
RH
862
863 /* Cchip CSRs, 0x801.A000.0000, 256MB. */
64bde0f3
PB
864 memory_region_init_io(&s->cchip.region, OBJECT(s), &cchip_ops, s, "cchip0",
865 256*MB);
02d6516c
SW
866 memory_region_add_subregion(addr_space, 0x801a0000000ULL,
867 &s->cchip.region);
80bb2ff7
RH
868
869 /* Dchip CSRs, 0x801.B000.0000, 256MB. */
64bde0f3
PB
870 memory_region_init_io(&s->dchip_region, OBJECT(s), &dchip_ops, s, "dchip0",
871 256*MB);
02d6516c
SW
872 memory_region_add_subregion(addr_space, 0x801b0000000ULL,
873 &s->dchip_region);
80bb2ff7
RH
874
875 /* Pchip0 PCI memory, 0x800.0000.0000, 4GB. */
64bde0f3 876 memory_region_init(&s->pchip.reg_mem, OBJECT(s), "pci0-mem", 4*GB);
02d6516c
SW
877 memory_region_add_subregion(addr_space, 0x80000000000ULL,
878 &s->pchip.reg_mem);
80bb2ff7
RH
879
880 /* Pchip0 PCI I/O, 0x801.FC00.0000, 32MB. */
3661049f
RH
881 memory_region_init_io(&s->pchip.reg_io, OBJECT(s), &alpha_pci_ignore_ops,
882 NULL, "pci0-io", 32*MB);
02d6516c
SW
883 memory_region_add_subregion(addr_space, 0x801fc000000ULL,
884 &s->pchip.reg_io);
80bb2ff7 885
94dd91d6 886 b = pci_register_bus(dev, "pci",
80bb2ff7 887 typhoon_set_irq, sys_map_irq, s,
056e6bae
RH
888 &s->pchip.reg_mem, &s->pchip.reg_io,
889 0, 64, TYPE_PCI_BUS);
94dd91d6 890 phb->bus = b;
50d3bba9 891 qdev_init_nofail(dev);
80bb2ff7 892
b83c4db8
RH
893 /* Host memory as seen from the PCI side, via the IOMMU. */
894 memory_region_init_iommu(&s->pchip.iommu, OBJECT(s), &typhoon_iommu_ops,
895 "iommu-typhoon", UINT64_MAX);
896 address_space_init(&s->pchip.iommu_as, &s->pchip.iommu, "pchip0-pci");
897 pci_setup_iommu(b, typhoon_pci_dma_iommu, s);
898
80bb2ff7 899 /* Pchip0 PCI special/interrupt acknowledge, 0x801.F800.0000, 64MB. */
056e6bae
RH
900 memory_region_init_io(&s->pchip.reg_iack, OBJECT(s), &alpha_pci_iack_ops,
901 b, "pci0-iack", 64*MB);
02d6516c
SW
902 memory_region_add_subregion(addr_space, 0x801f8000000ULL,
903 &s->pchip.reg_iack);
80bb2ff7
RH
904
905 /* Pchip0 PCI configuration, 0x801.FE00.0000, 16MB. */
056e6bae
RH
906 memory_region_init_io(&s->pchip.reg_conf, OBJECT(s), &alpha_pci_conf1_ops,
907 b, "pci0-conf", 16*MB);
02d6516c
SW
908 memory_region_add_subregion(addr_space, 0x801fe000000ULL,
909 &s->pchip.reg_conf);
80bb2ff7
RH
910
911 /* For the record, these are the mappings for the second PCI bus.
912 We can get away with not implementing them because we indicate
913 via the Cchip.CSC<PIP> bit that Pchip1 is not present. */
914 /* Pchip1 PCI memory, 0x802.0000.0000, 4GB. */
915 /* Pchip1 CSRs, 0x802.8000.0000, 256MB. */
916 /* Pchip1 PCI special/interrupt acknowledge, 0x802.F800.0000, 64MB. */
917 /* Pchip1 PCI I/O, 0x802.FC00.0000, 32MB. */
918 /* Pchip1 PCI configuration, 0x802.FE00.0000, 16MB. */
919
920 /* Init the ISA bus. */
921 /* ??? Technically there should be a cy82c693ub pci-isa bridge. */
922 {
54292736 923 qemu_irq *isa_irqs;
80bb2ff7 924
d10e5432
MA
925 *isa_bus = isa_bus_new(NULL, get_system_memory(), &s->pchip.reg_io,
926 &error_abort);
54292736
SZ
927 isa_irqs = i8259_init(*isa_bus,
928 qemu_allocate_irq(typhoon_set_isa_irq, s, 0));
71baa303 929 isa_bus_irqs(*isa_bus, isa_irqs);
80bb2ff7
RH
930 }
931
932 return b;
933}
934
935static int typhoon_pcihost_init(SysBusDevice *dev)
936{
937 return 0;
938}
939
999e12bb
AL
940static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
941{
942 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
943
944 k->init = typhoon_pcihost_init;
945}
946
4240abff 947static const TypeInfo typhoon_pcihost_info = {
94dd91d6 948 .name = TYPE_TYPHOON_PCI_HOST_BRIDGE,
8558d942 949 .parent = TYPE_PCI_HOST_BRIDGE,
39bffca2
AL
950 .instance_size = sizeof(TyphoonState),
951 .class_init = typhoon_pcihost_class_init,
80bb2ff7
RH
952};
953
83f7d43a 954static void typhoon_register_types(void)
80bb2ff7 955{
39bffca2 956 type_register_static(&typhoon_pcihost_info);
80bb2ff7 957}
83f7d43a
AF
958
959type_init(typhoon_register_types)
This page took 0.48275 seconds and 4 git commands to generate.