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]), 18909d7f77SJonathan Austin cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), 19909d7f77SJonathan Austin 20909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 21909d7f77SJonathan Austin cpu_to_fdt32(irqs[1]), 22909d7f77SJonathan Austin cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), 23909d7f77SJonathan Austin 24909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 25909d7f77SJonathan Austin cpu_to_fdt32(irqs[2]), 26909d7f77SJonathan Austin cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), 27909d7f77SJonathan Austin 28909d7f77SJonathan Austin cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), 29909d7f77SJonathan Austin cpu_to_fdt32(irqs[3]), 30909d7f77SJonathan Austin cpu_to_fdt32(cpu_mask | GIC_FDT_IRQ_FLAGS_EDGE_LO_HI), 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))); 36*f4c0490cSRobin Murphy if (kvm->cfg.arch.force_cntfrq > 0) 37*f4c0490cSRobin Murphy _FDT(fdt_property_cell(fdt, "clock-frequency", kvm->cfg.arch.force_cntfrq)); 38909d7f77SJonathan Austin _FDT(fdt_end_node(fdt)); 39909d7f77SJonathan Austin } 40*f4c0490cSRobin Murphy 41