xref: /kvmtool/arm/timer.c (revision d9fdaad02dfdb0ea079245218058d60270264660)
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 
timer__generate_fdt_nodes(void * fdt,struct kvm * kvm,int * irqs)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";
12*d9fdaad0SAndre Przywara 	u32 cpu_mask = gic__get_fdt_irq_cpumask(kvm);
13909d7f77SJonathan Austin 	u32 irq_prop[] = {
14909d7f77SJonathan Austin 		cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
15909d7f77SJonathan Austin 		cpu_to_fdt32(irqs[0]),
16e4f04b19SMarc Zyngier 		cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
17909d7f77SJonathan Austin 
18909d7f77SJonathan Austin 		cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
19909d7f77SJonathan Austin 		cpu_to_fdt32(irqs[1]),
20e4f04b19SMarc Zyngier 		cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
21909d7f77SJonathan Austin 
22909d7f77SJonathan Austin 		cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
23909d7f77SJonathan Austin 		cpu_to_fdt32(irqs[2]),
24e4f04b19SMarc Zyngier 		cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
25909d7f77SJonathan Austin 
26909d7f77SJonathan Austin 		cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
27909d7f77SJonathan Austin 		cpu_to_fdt32(irqs[3]),
28e4f04b19SMarc Zyngier 		cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
29909d7f77SJonathan Austin 	};
30909d7f77SJonathan Austin 
31909d7f77SJonathan Austin 	_FDT(fdt_begin_node(fdt, "timer"));
32909d7f77SJonathan Austin 	_FDT(fdt_property(fdt, "compatible", compatible, sizeof(compatible)));
33909d7f77SJonathan Austin 	_FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop)));
3400751da0SMarc Zyngier 	_FDT(fdt_property(fdt, "always-on", NULL, 0));
35f4c0490cSRobin Murphy 	if (kvm->cfg.arch.force_cntfrq > 0)
36f4c0490cSRobin Murphy 		_FDT(fdt_property_cell(fdt, "clock-frequency", kvm->cfg.arch.force_cntfrq));
37909d7f77SJonathan Austin 	_FDT(fdt_end_node(fdt));
38909d7f77SJonathan Austin }
39f4c0490cSRobin Murphy 
40