2 * DEC 21272 (TSUNAMI/TYPHOON) chipset emulation.
4 * Written by Richard Henderson.
6 * This work is licensed under the GNU GPL license version 2 or later.
14 #include "alpha_sys.h"
15 #include "exec-memory.h"
18 typedef struct TyphoonCchip
{
27 typedef struct TyphoonWindow
{
30 uint32_t translated_base_pfn
;
33 typedef struct TyphoonPchip
{
35 MemoryRegion reg_iack
;
38 MemoryRegion reg_conf
;
43 typedef struct TyphoonState
{
47 MemoryRegion dchip_region
;
48 MemoryRegion ram_region
;
50 /* QEMU emulation state. */
54 /* Called when one of DRIR or DIM changes. */
55 static void cpu_irq_change(CPUState
*env
, uint64_t req
)
57 /* If there are any non-masked interrupts, tell the cpu. */
60 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
62 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);
67 static uint64_t cchip_read(void *opaque
, target_phys_addr_t addr
, unsigned size
)
69 CPUState
*env
= cpu_single_env
;
70 TyphoonState
*s
= opaque
;
79 /* CSC: Cchip System Configuration Register. */
80 /* All sorts of data here; probably the only thing relevant is
81 PIP<14> Pchip 1 Present = 0. */
85 /* MTR: Memory Timing Register. */
86 /* All sorts of stuff related to real DRAM. */
90 /* MISC: Miscellaneous Register. */
91 ret
= s
->cchip
.misc
| (env
->cpu_index
& 3);
95 /* MPD: Memory Presence Detect Register. */
98 case 0x0100: /* AAR0 */
99 case 0x0140: /* AAR1 */
100 case 0x0180: /* AAR2 */
101 case 0x01c0: /* AAR3 */
102 /* AAR: Array Address Register. */
103 /* All sorts of information about DRAM. */
107 /* DIM0: Device Interrupt Mask Register, CPU0. */
108 ret
= s
->cchip
.dim
[0];
111 /* DIM1: Device Interrupt Mask Register, CPU1. */
112 ret
= s
->cchip
.dim
[1];
115 /* DIR0: Device Interrupt Request Register, CPU0. */
116 ret
= s
->cchip
.dim
[0] & s
->cchip
.drir
;
119 /* DIR1: Device Interrupt Request Register, CPU1. */
120 ret
= s
->cchip
.dim
[1] & s
->cchip
.drir
;
123 /* DRIR: Device Raw Interrupt Request Register. */
128 /* PRBEN: Probe Enable Register. */
132 /* IIC0: Interval Ignore Count Register, CPU0. */
133 ret
= s
->cchip
.iic
[0];
136 /* IIC1: Interval Ignore Count Register, CPU1. */
137 ret
= s
->cchip
.iic
[1];
140 case 0x0400: /* MPR0 */
141 case 0x0440: /* MPR1 */
142 case 0x0480: /* MPR2 */
143 case 0x04c0: /* MPR3 */
144 /* MPR: Memory Programming Register. */
148 /* TTR: TIGbus Timing Register. */
149 /* All sorts of stuff related to interrupt delivery timings. */
152 /* TDR: TIGbug Device Timing Register. */
156 /* DIM2: Device Interrupt Mask Register, CPU2. */
157 ret
= s
->cchip
.dim
[2];
160 /* DIM3: Device Interrupt Mask Register, CPU3. */
161 ret
= s
->cchip
.dim
[3];
164 /* DIR2: Device Interrupt Request Register, CPU2. */
165 ret
= s
->cchip
.dim
[2] & s
->cchip
.drir
;
168 /* DIR3: Device Interrupt Request Register, CPU3. */
169 ret
= s
->cchip
.dim
[3] & s
->cchip
.drir
;
173 /* IIC2: Interval Ignore Count Register, CPU2. */
174 ret
= s
->cchip
.iic
[2];
177 /* IIC3: Interval Ignore Count Register, CPU3. */
178 ret
= s
->cchip
.iic
[3];
182 /* PWR: Power Management Control. */
185 case 0x0c00: /* CMONCTLA */
186 case 0x0c40: /* CMONCTLB */
187 case 0x0c80: /* CMONCNT01 */
188 case 0x0cc0: /* CMONCNT23 */
192 cpu_unassigned_access(cpu_single_env
, addr
, 0, 0, 0, size
);
196 s
->latch_tmp
= ret
>> 32;
200 static uint64_t dchip_read(void *opaque
, target_phys_addr_t addr
, unsigned size
)
202 /* Skip this. It's all related to DRAM timing and setup. */
206 static uint64_t pchip_read(void *opaque
, target_phys_addr_t addr
, unsigned size
)
208 TyphoonState
*s
= opaque
;
217 /* WSBA0: Window Space Base Address Register. */
218 ret
= s
->pchip
.win
[0].base_addr
;
222 ret
= s
->pchip
.win
[1].base_addr
;
226 ret
= s
->pchip
.win
[2].base_addr
;
230 ret
= s
->pchip
.win
[3].base_addr
;
234 /* WSM0: Window Space Mask Register. */
235 ret
= s
->pchip
.win
[0].mask
;
239 ret
= s
->pchip
.win
[1].mask
;
243 ret
= s
->pchip
.win
[2].mask
;
247 ret
= s
->pchip
.win
[3].mask
;
251 /* TBA0: Translated Base Address Register. */
252 ret
= (uint64_t)s
->pchip
.win
[0].translated_base_pfn
<< 10;
256 ret
= (uint64_t)s
->pchip
.win
[1].translated_base_pfn
<< 10;
260 ret
= (uint64_t)s
->pchip
.win
[2].translated_base_pfn
<< 10;
264 ret
= (uint64_t)s
->pchip
.win
[3].translated_base_pfn
<< 10;
268 /* PCTL: Pchip Control Register. */
272 /* PLAT: Pchip Master Latency Register. */
275 /* PERROR: Pchip Error Register. */
278 /* PERRMASK: Pchip Error Mask Register. */
281 /* PERRSET: Pchip Error Set Register. */
284 /* TLBIV: Translation Buffer Invalidate Virtual Register (WO). */
287 /* TLBIA: Translation Buffer Invalidate All Register (WO). */
289 case 0x0500: /* PMONCTL */
290 case 0x0540: /* PMONCNT */
291 case 0x0800: /* SPRST */
295 cpu_unassigned_access(cpu_single_env
, addr
, 0, 0, 0, size
);
299 s
->latch_tmp
= ret
>> 32;
303 static void cchip_write(void *opaque
, target_phys_addr_t addr
,
304 uint64_t v32
, unsigned size
)
306 TyphoonState
*s
= opaque
;
307 uint64_t val
, oldval
, newval
;
310 val
= v32
<< 32 | s
->latch_tmp
;
319 /* CSC: Cchip System Configuration Register. */
320 /* All sorts of data here; nothing relevant RW. */
324 /* MTR: Memory Timing Register. */
325 /* All sorts of stuff related to real DRAM. */
329 /* MISC: Miscellaneous Register. */
330 newval
= oldval
= s
->cchip
.misc
;
331 newval
&= ~(val
& 0x10000ff0); /* W1C fields */
332 if (val
& 0x100000) {
333 newval
&= ~0xff0000ull
; /* ACL clears ABT and ABW */
335 newval
|= val
& 0x00f00000; /* ABT field is W1S */
336 if ((newval
& 0xf0000) == 0) {
337 newval
|= val
& 0xf0000; /* ABW field is W1S iff zero */
340 newval
|= (val
& 0xf000) >> 4; /* IPREQ field sets IPINTR. */
342 newval
&= ~0xf0000000000ull
; /* WO and RW fields */
343 newval
|= val
& 0xf0000000000ull
;
344 s
->cchip
.misc
= newval
;
346 /* Pass on changes to IPI and ITI state. */
347 if ((newval
^ oldval
) & 0xff0) {
349 for (i
= 0; i
< 4; ++i
) {
350 CPUState
*env
= s
->cchip
.cpu
[i
];
352 /* IPI can be either cleared or set by the write. */
353 if (newval
& (1 << (i
+ 8))) {
354 cpu_interrupt(env
, CPU_INTERRUPT_SMP
);
356 cpu_reset_interrupt(env
, CPU_INTERRUPT_SMP
);
359 /* ITI can only be cleared by the write. */
360 if ((newval
& (1 << (i
+ 4))) == 0) {
361 cpu_reset_interrupt(env
, CPU_INTERRUPT_TIMER
);
369 /* MPD: Memory Presence Detect Register. */
372 case 0x0100: /* AAR0 */
373 case 0x0140: /* AAR1 */
374 case 0x0180: /* AAR2 */
375 case 0x01c0: /* AAR3 */
376 /* AAR: Array Address Register. */
377 /* All sorts of information about DRAM. */
380 case 0x0200: /* DIM0 */
381 /* DIM: Device Interrupt Mask Register, CPU0. */
382 s
->cchip
.dim
[0] = val
;
383 cpu_irq_change(s
->cchip
.cpu
[0], val
& s
->cchip
.drir
);
385 case 0x0240: /* DIM1 */
386 /* DIM: Device Interrupt Mask Register, CPU1. */
387 s
->cchip
.dim
[0] = val
;
388 cpu_irq_change(s
->cchip
.cpu
[1], val
& s
->cchip
.drir
);
391 case 0x0280: /* DIR0 (RO) */
392 case 0x02c0: /* DIR1 (RO) */
393 case 0x0300: /* DRIR (RO) */
397 /* PRBEN: Probe Enable Register. */
400 case 0x0380: /* IIC0 */
401 s
->cchip
.iic
[0] = val
& 0xffffff;
403 case 0x03c0: /* IIC1 */
404 s
->cchip
.iic
[1] = val
& 0xffffff;
407 case 0x0400: /* MPR0 */
408 case 0x0440: /* MPR1 */
409 case 0x0480: /* MPR2 */
410 case 0x04c0: /* MPR3 */
411 /* MPR: Memory Programming Register. */
415 /* TTR: TIGbus Timing Register. */
416 /* All sorts of stuff related to interrupt delivery timings. */
419 /* TDR: TIGbug Device Timing Register. */
423 /* DIM2: Device Interrupt Mask Register, CPU2. */
424 s
->cchip
.dim
[2] = val
;
425 cpu_irq_change(s
->cchip
.cpu
[2], val
& s
->cchip
.drir
);
428 /* DIM3: Device Interrupt Mask Register, CPU3. */
429 s
->cchip
.dim
[3] = val
;
430 cpu_irq_change(s
->cchip
.cpu
[3], val
& s
->cchip
.drir
);
433 case 0x0680: /* DIR2 (RO) */
434 case 0x06c0: /* DIR3 (RO) */
437 case 0x0700: /* IIC2 */
438 s
->cchip
.iic
[2] = val
& 0xffffff;
440 case 0x0740: /* IIC3 */
441 s
->cchip
.iic
[3] = val
& 0xffffff;
445 /* PWR: Power Management Control. */
448 case 0x0c00: /* CMONCTLA */
449 case 0x0c40: /* CMONCTLB */
450 case 0x0c80: /* CMONCNT01 */
451 case 0x0cc0: /* CMONCNT23 */
455 cpu_unassigned_access(cpu_single_env
, addr
, 1, 0, 0, size
);
460 static void dchip_write(void *opaque
, target_phys_addr_t addr
,
461 uint64_t val
, unsigned size
)
463 /* Skip this. It's all related to DRAM timing and setup. */
466 static void pchip_write(void *opaque
, target_phys_addr_t addr
,
467 uint64_t v32
, unsigned size
)
469 TyphoonState
*s
= opaque
;
470 uint64_t val
, oldval
;
473 val
= v32
<< 32 | s
->latch_tmp
;
482 /* WSBA0: Window Space Base Address Register. */
483 s
->pchip
.win
[0].base_addr
= val
;
487 s
->pchip
.win
[1].base_addr
= val
;
491 s
->pchip
.win
[2].base_addr
= val
;
495 s
->pchip
.win
[3].base_addr
= val
;
499 /* WSM0: Window Space Mask Register. */
500 s
->pchip
.win
[0].mask
= val
;
504 s
->pchip
.win
[1].mask
= val
;
508 s
->pchip
.win
[2].mask
= val
;
512 s
->pchip
.win
[3].mask
= val
;
516 /* TBA0: Translated Base Address Register. */
517 s
->pchip
.win
[0].translated_base_pfn
= val
>> 10;
521 s
->pchip
.win
[1].translated_base_pfn
= val
>> 10;
525 s
->pchip
.win
[2].translated_base_pfn
= val
>> 10;
529 s
->pchip
.win
[3].translated_base_pfn
= val
>> 10;
533 /* PCTL: Pchip Control Register. */
534 oldval
= s
->pchip
.ctl
;
535 oldval
&= ~0x00001cff0fc7ffull
; /* RW fields */
536 oldval
|= val
& 0x00001cff0fc7ffull
;
538 s
->pchip
.ctl
= oldval
;
542 /* PLAT: Pchip Master Latency Register. */
545 /* PERROR: Pchip Error Register. */
548 /* PERRMASK: Pchip Error Mask Register. */
551 /* PERRSET: Pchip Error Set Register. */
555 /* TLBIV: Translation Buffer Invalidate Virtual Register. */
559 /* TLBIA: Translation Buffer Invalidate All Register (WO). */
571 cpu_unassigned_access(cpu_single_env
, addr
, 1, 0, 0, size
);
576 static const MemoryRegionOps cchip_ops
= {
578 .write
= cchip_write
,
579 .endianness
= DEVICE_LITTLE_ENDIAN
,
581 .min_access_size
= 4, /* ??? Should be 8. */
582 .max_access_size
= 8,
585 .min_access_size
= 4,
586 .max_access_size
= 4,
590 static const MemoryRegionOps dchip_ops
= {
592 .write
= dchip_write
,
593 .endianness
= DEVICE_LITTLE_ENDIAN
,
595 .min_access_size
= 4, /* ??? Should be 8. */
596 .max_access_size
= 8,
599 .min_access_size
= 4,
600 .max_access_size
= 8,
604 static const MemoryRegionOps pchip_ops
= {
606 .write
= pchip_write
,
607 .endianness
= DEVICE_LITTLE_ENDIAN
,
609 .min_access_size
= 4, /* ??? Should be 8. */
610 .max_access_size
= 8,
613 .min_access_size
= 4,
614 .max_access_size
= 4,
618 static void typhoon_set_irq(void *opaque
, int irq
, int level
)
620 TyphoonState
*s
= opaque
;
624 /* Set/Reset the bit in CCHIP.DRIR based on IRQ+LEVEL. */
625 drir
= s
->cchip
.drir
;
629 drir
&= ~(1ull << irq
);
631 s
->cchip
.drir
= drir
;
633 for (i
= 0; i
< 4; ++i
) {
634 cpu_irq_change(s
->cchip
.cpu
[i
], s
->cchip
.dim
[i
] & drir
);
638 static void typhoon_set_isa_irq(void *opaque
, int irq
, int level
)
640 typhoon_set_irq(opaque
, 55, level
);
643 static void typhoon_set_timer_irq(void *opaque
, int irq
, int level
)
645 TyphoonState
*s
= opaque
;
648 /* Thankfully, the mc146818rtc code doesn't track the IRQ state,
649 and so we don't have to worry about missing interrupts just
650 because we never actually ACK the interrupt. Just ignore any
651 case of the interrupt level going low. */
656 /* Deliver the interrupt to each CPU, considering each CPU's IIC. */
657 for (i
= 0; i
< 4; ++i
) {
658 CPUState
*env
= s
->cchip
.cpu
[i
];
660 uint32_t iic
= s
->cchip
.iic
[i
];
662 /* ??? The verbage in Section 10.2.2.10 isn't 100% clear.
663 Bit 24 is the OverFlow bit, RO, and set when the count
664 decrements past 0. When is OF cleared? My guess is that
665 OF is actually cleared when the IIC is written, and that
666 the ICNT field always decrements. At least, that's an
667 interpretation that makes sense, and "allows the CPU to
668 determine exactly how mant interval timer ticks were
669 skipped". At least within the next 4M ticks... */
671 iic
= ((iic
- 1) & 0x1ffffff) | (iic
& 0x1000000);
672 s
->cchip
.iic
[i
] = iic
;
674 if (iic
& 0x1000000) {
675 /* Set the ITI bit for this cpu. */
676 s
->cchip
.misc
|= 1 << (i
+ 4);
677 /* And signal the interrupt. */
678 cpu_interrupt(env
, CPU_INTERRUPT_TIMER
);
684 static void typhoon_alarm_timer(void *opaque
)
686 TyphoonState
*s
= (TyphoonState
*)((uintptr_t)opaque
& ~3);
687 int cpu
= (uintptr_t)opaque
& 3;
689 /* Set the ITI bit for this cpu. */
690 s
->cchip
.misc
|= 1 << (cpu
+ 4);
691 cpu_interrupt(s
->cchip
.cpu
[cpu
], CPU_INTERRUPT_TIMER
);
694 PCIBus
*typhoon_init(ram_addr_t ram_size
, qemu_irq
*p_rtc_irq
,
695 CPUState
*cpus
[4], pci_map_irq_fn sys_map_irq
)
697 const uint64_t MB
= 1024 * 1024;
698 const uint64_t GB
= 1024 * MB
;
699 MemoryRegion
*addr_space
= get_system_memory();
700 MemoryRegion
*addr_space_io
= get_system_io();
707 dev
= qdev_create(NULL
, "typhoon-pcihost");
708 qdev_init_nofail(dev
);
710 p
= FROM_SYSBUS(PCIHostState
, sysbus_from_qdev(dev
));
711 s
= container_of(p
, TyphoonState
, host
);
713 /* Remember the CPUs so that we can deliver interrupts to them. */
714 for (i
= 0; i
< 4; i
++) {
715 CPUState
*env
= cpus
[i
];
716 s
->cchip
.cpu
[i
] = env
;
718 env
->alarm_timer
= qemu_new_timer_ns(rtc_clock
,
720 (void *)((uintptr_t)s
+ i
));
724 *p_rtc_irq
= *qemu_allocate_irqs(typhoon_set_timer_irq
, s
, 1);
726 /* Main memory region, 0x00.0000.0000. Real hardware supports 32GB,
727 but the address space hole reserved at this point is 8TB. */
728 memory_region_init_ram(&s
->ram_region
, NULL
, "ram", ram_size
);
729 memory_region_add_subregion(addr_space
, 0, &s
->ram_region
);
731 /* TIGbus, 0x801.0000.0000, 1GB. */
732 /* ??? The TIGbus is used for delivering interrupts, and access to
733 the flash ROM. I'm not sure that we need to implement it at all. */
735 /* Pchip0 CSRs, 0x801.8000.0000, 256MB. */
736 memory_region_init_io(&s
->pchip
.region
, &pchip_ops
, s
, "pchip0", 256*MB
);
737 memory_region_add_subregion(addr_space
, 0x80180000000ULL
,
740 /* Cchip CSRs, 0x801.A000.0000, 256MB. */
741 memory_region_init_io(&s
->cchip
.region
, &cchip_ops
, s
, "cchip0", 256*MB
);
742 memory_region_add_subregion(addr_space
, 0x801a0000000ULL
,
745 /* Dchip CSRs, 0x801.B000.0000, 256MB. */
746 memory_region_init_io(&s
->dchip_region
, &dchip_ops
, s
, "dchip0", 256*MB
);
747 memory_region_add_subregion(addr_space
, 0x801b0000000ULL
,
750 /* Pchip0 PCI memory, 0x800.0000.0000, 4GB. */
751 memory_region_init(&s
->pchip
.reg_mem
, "pci0-mem", 4*GB
);
752 memory_region_add_subregion(addr_space
, 0x80000000000ULL
,
755 /* Pchip0 PCI I/O, 0x801.FC00.0000, 32MB. */
756 /* ??? Ideally we drop the "system" i/o space on the floor and give the
757 PCI subsystem the full address space reserved by the chipset.
758 We can't do that until the MEM and IO paths in memory.c are unified. */
759 memory_region_init_io(&s
->pchip
.reg_io
, &alpha_pci_bw_io_ops
, NULL
,
761 memory_region_add_subregion(addr_space
, 0x801fc000000ULL
,
764 b
= pci_register_bus(&s
->host
.busdev
.qdev
, "pci",
765 typhoon_set_irq
, sys_map_irq
, s
,
766 &s
->pchip
.reg_mem
, addr_space_io
, 0, 64);
769 /* Pchip0 PCI special/interrupt acknowledge, 0x801.F800.0000, 64MB. */
770 memory_region_init_io(&s
->pchip
.reg_iack
, &alpha_pci_iack_ops
, b
,
772 memory_region_add_subregion(addr_space
, 0x801f8000000ULL
,
775 /* Pchip0 PCI configuration, 0x801.FE00.0000, 16MB. */
776 memory_region_init_io(&s
->pchip
.reg_conf
, &alpha_pci_conf1_ops
, b
,
778 memory_region_add_subregion(addr_space
, 0x801fe000000ULL
,
781 /* For the record, these are the mappings for the second PCI bus.
782 We can get away with not implementing them because we indicate
783 via the Cchip.CSC<PIP> bit that Pchip1 is not present. */
784 /* Pchip1 PCI memory, 0x802.0000.0000, 4GB. */
785 /* Pchip1 CSRs, 0x802.8000.0000, 256MB. */
786 /* Pchip1 PCI special/interrupt acknowledge, 0x802.F800.0000, 64MB. */
787 /* Pchip1 PCI I/O, 0x802.FC00.0000, 32MB. */
788 /* Pchip1 PCI configuration, 0x802.FE00.0000, 16MB. */
790 /* Init the ISA bus. */
791 /* ??? Technically there should be a cy82c693ub pci-isa bridge. */
793 qemu_irq isa_pci_irq
, *isa_irqs
;
795 isa_bus_new(NULL
, addr_space_io
);
796 isa_pci_irq
= *qemu_allocate_irqs(typhoon_set_isa_irq
, s
, 1);
797 isa_irqs
= i8259_init(isa_pci_irq
);
798 isa_bus_irqs(isa_irqs
);
804 static int typhoon_pcihost_init(SysBusDevice
*dev
)
809 static SysBusDeviceInfo typhoon_pcihost_info
= {
810 .init
= typhoon_pcihost_init
,
811 .qdev
.name
= "typhoon-pcihost",
812 .qdev
.size
= sizeof(TyphoonState
),
816 static void typhoon_register(void)
818 sysbus_register_withprop(&typhoon_pcihost_info
);
820 device_init(typhoon_register
);