1909d7f77SJonathan Austin #include "kvm/fdt.h" 2909d7f77SJonathan Austin #include "kvm/kvm.h" 3909d7f77SJonathan Austin #include "kvm/kvm-cpu.h" 4909d7f77SJonathan Austin #include "kvm/util.h" 5909d7f77SJonathan Austin 6909d7f77SJonathan Austin #include "arm-common/gic.h" 7909d7f77SJonathan Austin #include "arm-common/timer.h" 8909d7f77SJonathan Austin 9909d7f77SJonathan Austin void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs) 10909d7f77SJonathan Austin { 11909d7f77SJonathan Austin const char compatible[] = "arm,armv8-timer\0arm,armv7-timer"; 12909d7f77SJonathan Austin 13909d7f77SJonathan Austin u32 cpu_mask = (((1 << kvm->nrcpus) - 1) << GIC_FDT_IRQ_PPI_CPU_SHIFT) \ 14909d7f77SJonathan Austin & GIC_FDT_IRQ_PPI_CPU_MASK; 15909d7f77SJonathan Austin u32 irq_prop[] = { 16909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 17909d7f77SJonathan Austin cpu_to_fdt32(irqs[0]), 18*e4f04b19SMarc Zyngier cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), 19909d7f77SJonathan Austin 20909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 21909d7f77SJonathan Austin cpu_to_fdt32(irqs[1]), 22*e4f04b19SMarc Zyngier cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), 23909d7f77SJonathan Austin 24909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 25909d7f77SJonathan Austin cpu_to_fdt32(irqs[2]), 26*e4f04b19SMarc Zyngier cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), 27909d7f77SJonathan Austin 28909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 29909d7f77SJonathan Austin cpu_to_fdt32(irqs[3]), 30*e4f04b19SMarc Zyngier cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), 31909d7f77SJonathan Austin }; 32909d7f77SJonathan Austin 33909d7f77SJonathan Austin _FDT(fdt_begin_node(fdt, "timer")); 34909d7f77SJonathan Austin _FDT(fdt_property(fdt, "compatible", compatible, sizeof(compatible))); 35909d7f77SJonathan Austin _FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop))); 3600751da0SMarc Zyngier _FDT(fdt_property(fdt, "always-on", NULL, 0)); 37f4c0490cSRobin Murphy if (kvm->cfg.arch.force_cntfrq > 0) 38f4c0490cSRobin Murphy _FDT(fdt_property_cell(fdt, "clock-frequency", kvm->cfg.arch.force_cntfrq)); 39909d7f77SJonathan Austin _FDT(fdt_end_node(fdt)); 40909d7f77SJonathan Austin } 41f4c0490cSRobin Murphy 42