blob: 44e8c19e3d56db8784d04a0390d2f33461890831 [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Zyngierde29faa2016-12-19 19:25:00 +00002/*
3 * Copyright (C) 2016,2017 ARM Limited, All Rights Reserved.
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
Marc Zyngierde29faa2016-12-19 19:25:00 +00005 */
6
7#ifndef __LINUX_IRQCHIP_ARM_GIC_V4_H
8#define __LINUX_IRQCHIP_ARM_GIC_V4_H
9
10struct its_vpe;
11
Marc Zyngierab604912017-10-08 18:48:06 +010012/*
13 * Maximum number of ITTs when GITS_TYPER.VMOVP == 0, using the
14 * ITSList mechanism to perform inter-ITS synchronization.
15 */
16#define GICv4_ITS_LIST_MAX 16
17
Marc Zyngierde29faa2016-12-19 19:25:00 +000018/* Embedded in kvm.arch */
19struct its_vm {
20 struct fwnode_handle *fwnode;
21 struct irq_domain *domain;
22 struct page *vprop_page;
23 struct its_vpe **vpes;
24 int nr_vpes;
25 irq_hw_number_t db_lpi_base;
26 unsigned long *db_bitmap;
27 int nr_db_lpis;
Marc Zyngier2247e1b2017-10-08 18:50:36 +010028 u32 vlpi_count[GICv4_ITS_LIST_MAX];
Marc Zyngierde29faa2016-12-19 19:25:00 +000029};
30
31/* Embedded in kvm_vcpu.arch */
32struct its_vpe {
33 struct page *vpt_page;
34 struct its_vm *its_vm;
Marc Zyngier5bd90b02019-11-07 16:04:11 +000035 /* per-vPE VLPI tracking */
36 atomic_t vlpi_count;
Marc Zyngierde29faa2016-12-19 19:25:00 +000037 /* Doorbell interrupt */
38 int irq;
39 irq_hw_number_t vpe_db_lpi;
Marc Zyngier8e01d9a2019-10-27 14:41:59 +000040 /* VPE resident */
41 bool resident;
Marc Zyngier64edfaa2019-12-24 11:10:29 +000042 union {
43 /* GICv4.0 implementations */
44 struct {
45 /* VPE proxy mapping */
46 int vpe_proxy_event;
47 /* Implementation Defined Area Invalid */
48 bool idai;
49 };
50 /* GICv4.1 implementations */
51 struct {
Marc Zyngier166cba72020-03-04 20:33:15 +000052 struct {
53 u8 priority;
54 bool enabled;
55 bool group;
56 } sgi_config[16];
Marc Zyngier64edfaa2019-12-24 11:10:29 +000057 atomic_t vmapp_count;
58 };
59 };
60
Marc Zyngierde29faa2016-12-19 19:25:00 +000061 /*
Marc Zyngierf3a059212020-03-04 20:33:10 +000062 * Ensures mutual exclusion between affinity setting of the
63 * vPE and vLPI operations using vpe->col_idx.
64 */
65 raw_spinlock_t vpe_lock;
66 /*
Marc Zyngierde29faa2016-12-19 19:25:00 +000067 * This collection ID is used to indirect the target
68 * redistributor for this VPE. The ID itself isn't involved in
69 * programming of the ITS.
70 */
71 u16 col_idx;
72 /* Unique (system-wide) VPE identifier */
73 u16 vpe_id;
Marc Zyngierde29faa2016-12-19 19:25:00 +000074 /* Pending VLPIs on schedule out? */
75 bool pending_last;
76};
77
78/*
79 * struct its_vlpi_map: structure describing the mapping of a
80 * VLPI. Only to be interpreted in the context of a physical interrupt
81 * it complements. To be used as the vcpu_info passed to
82 * irq_set_vcpu_affinity().
83 *
84 * @vm: Pointer to the GICv4 notion of a VM
85 * @vpe: Pointer to the GICv4 notion of a virtual CPU (VPE)
86 * @vintid: Virtual LPI number
Marc Zyngierd4d7b4a2017-10-26 10:44:07 +010087 * @properties: Priority and enable bits (as written in the prop table)
Marc Zyngierde29faa2016-12-19 19:25:00 +000088 * @db_enabled: Is the VPE doorbell to be generated?
89 */
90struct its_vlpi_map {
91 struct its_vm *vm;
92 struct its_vpe *vpe;
93 u32 vintid;
Marc Zyngierd4d7b4a2017-10-26 10:44:07 +010094 u8 properties;
Marc Zyngierde29faa2016-12-19 19:25:00 +000095 bool db_enabled;
96};
97
98enum its_vcpu_info_cmd_type {
99 MAP_VLPI,
100 GET_VLPI,
101 PROP_UPDATE_VLPI,
102 PROP_UPDATE_AND_INV_VLPI,
103 SCHEDULE_VPE,
104 DESCHEDULE_VPE,
105 INVALL_VPE,
106};
107
108struct its_cmd_info {
109 enum its_vcpu_info_cmd_type cmd_type;
110 union {
111 struct its_vlpi_map *map;
112 u8 config;
Marc Zyngier91bf6392019-12-24 11:10:34 +0000113 bool req_db;
114 struct {
115 bool g0en;
116 bool g1en;
117 };
Marc Zyngierde29faa2016-12-19 19:25:00 +0000118 };
119};
120
Marc Zyngier7de5c0a2016-12-20 15:27:52 +0000121int its_alloc_vcpu_irqs(struct its_vm *vm);
122void its_free_vcpu_irqs(struct its_vm *vm);
Marc Zyngiereab84312016-12-20 15:31:02 +0000123int its_schedule_vpe(struct its_vpe *vpe, bool on);
124int its_invall_vpe(struct its_vpe *vpe);
Marc Zyngierf2eac752016-12-21 21:50:32 +0000125int its_map_vlpi(int irq, struct its_vlpi_map *map);
126int its_get_vlpi(int irq, struct its_vlpi_map *map);
127int its_unmap_vlpi(int irq);
128int its_prop_update_vlpi(int irq, u8 config, bool inv);
Marc Zyngier7de5c0a2016-12-20 15:27:52 +0000129
Marc Zyngier47f9d0b2017-11-13 16:21:33 +0000130struct irq_domain_ops;
Marc Zyngier166cba72020-03-04 20:33:15 +0000131int its_init_v4(struct irq_domain *domain,
132 const struct irq_domain_ops *vpe_ops,
133 const struct irq_domain_ops *sgi_ops);
Marc Zyngier3d63cb52016-12-20 15:31:54 +0000134
Marc Zyngierde29faa2016-12-19 19:25:00 +0000135#endif