]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/arm/include/asm/irqchip.h
arm: GICv3: handle IRQs
[jailhouse.git] / hypervisor / arch / arm / include / asm / irqchip.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) ARM Limited, 2014
5  *
6  * Authors:
7  *  Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #ifndef _JAILHOUSE_ASM_IRQCHIP_H
14 #define _JAILHOUSE_ASM_IRQCHIP_H
15
16 /*
17  * Since there is no finer-grained allocation than page-alloc for the moment,
18  * and it is very complicated to predict the total size needed at
19  * initialisation, each cpu is allocated one page of pending irqs.
20  * This allows for 256 pending IRQs, which should be sufficient.
21  */
22 #define MAX_PENDING_IRQS        (PAGE_SIZE / sizeof(struct pending_irq))
23
24 #include <asm/percpu.h>
25
26 #ifndef __ASSEMBLY__
27
28 struct sgi {
29         /*
30          * Routing mode values:
31          * 0: use aff3.aff2.aff1.targets
32          * 1: all processors in the cell except this CPU
33          * 2: only this CPU
34          */
35         u8      routing_mode;
36         /* GICv2 only uses 8bit in targets, and no affinity routing */
37         u8      aff1;
38         u8      aff2;
39         /* Only available on 64-bit, when CTLR.A3V is 1 */
40         u8      aff3;
41         u16     targets;
42         u16     id;
43 };
44
45 struct irqchip_ops {
46         int     (*init)(void);
47         int     (*cpu_init)(struct per_cpu *cpu_data);
48
49         int     (*send_sgi)(struct sgi *sgi);
50         void    (*handle_irq)(struct per_cpu *cpu_data);
51         int     (*inject_irq)(struct per_cpu *cpu_data, struct pending_irq *irq);
52 };
53
54 /* Virtual interrupts waiting to be injected */
55 struct pending_irq {
56         u32     virt_id;
57
58         u8      priority;
59         u8      hw;
60         union {
61                 /* Physical id, when hw is 1 */
62                 u16 irq;
63                 struct {
64                         /* GICv2 needs cpuid for SGIs */
65                         u16 cpuid       : 15;
66                         /* EOI generates a maintenance irq */
67                         u16 maintenance : 1;
68                 } sgi __attribute__((packed));
69         } type;
70
71         struct pending_irq *next;
72         struct pending_irq *prev;
73 } __attribute__((packed));
74
75 int irqchip_init(void);
76 int irqchip_cpu_init(struct per_cpu *cpu_data);
77
78 int irqchip_send_sgi(struct sgi *sgi);
79 void irqchip_handle_irq(struct per_cpu *cpu_data);
80
81 int irqchip_inject_pending(struct per_cpu *cpu_data);
82 int irqchip_insert_pending(struct per_cpu *cpu_data, struct pending_irq *irq);
83 int irqchip_remove_pending(struct per_cpu *cpu_data, struct pending_irq *irq);
84 int irqchip_set_pending(struct per_cpu *cpu_data, u32 irq_id, bool try_inject);
85
86 #endif /* __ASSEMBLY__ */
87 #endif /* _JAILHOUSE_ASM_IRQCHIP_H */