Skip to content

Commit 63000dd

Browse files
author
Marc Zyngier
committed
KVM: arm/arm64: vgic-v3: Add accessors for the ICH_APxRn_EL2 registers
As we're about to access the Active Priority registers a lot more, let's define accessors that take the register number as a parameter. Tested-by: Alexander Graf <agraf@suse.de> Acked-by: David Daney <david.daney@cavium.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <cdall@linaro.org>
1 parent d251f67 commit 63000dd

1 file changed

Lines changed: 100 additions & 16 deletions

File tree

‎virt/kvm/arm/hyp/vgic-v3-sr.c‎

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,90 @@ static void __hyp_text __gic_v3_set_lr(u64 val, int lr)
118118
}
119119
}
120120

121+
static void __hyp_text __vgic_v3_write_ap0rn(u32 val, int n)
122+
{
123+
switch (n) {
124+
case 0:
125+
write_gicreg(val, ICH_AP0R0_EL2);
126+
break;
127+
case 1:
128+
write_gicreg(val, ICH_AP0R1_EL2);
129+
break;
130+
case 2:
131+
write_gicreg(val, ICH_AP0R2_EL2);
132+
break;
133+
case 3:
134+
write_gicreg(val, ICH_AP0R3_EL2);
135+
break;
136+
}
137+
}
138+
139+
static void __hyp_text __vgic_v3_write_ap1rn(u32 val, int n)
140+
{
141+
switch (n) {
142+
case 0:
143+
write_gicreg(val, ICH_AP1R0_EL2);
144+
break;
145+
case 1:
146+
write_gicreg(val, ICH_AP1R1_EL2);
147+
break;
148+
case 2:
149+
write_gicreg(val, ICH_AP1R2_EL2);
150+
break;
151+
case 3:
152+
write_gicreg(val, ICH_AP1R3_EL2);
153+
break;
154+
}
155+
}
156+
157+
static u32 __hyp_text __vgic_v3_read_ap0rn(int n)
158+
{
159+
u32 val;
160+
161+
switch (n) {
162+
case 0:
163+
val = read_gicreg(ICH_AP0R0_EL2);
164+
break;
165+
case 1:
166+
val = read_gicreg(ICH_AP0R1_EL2);
167+
break;
168+
case 2:
169+
val = read_gicreg(ICH_AP0R2_EL2);
170+
break;
171+
case 3:
172+
val = read_gicreg(ICH_AP0R3_EL2);
173+
break;
174+
default:
175+
unreachable();
176+
}
177+
178+
return val;
179+
}
180+
181+
static u32 __hyp_text __vgic_v3_read_ap1rn(int n)
182+
{
183+
u32 val;
184+
185+
switch (n) {
186+
case 0:
187+
val = read_gicreg(ICH_AP1R0_EL2);
188+
break;
189+
case 1:
190+
val = read_gicreg(ICH_AP1R1_EL2);
191+
break;
192+
case 2:
193+
val = read_gicreg(ICH_AP1R2_EL2);
194+
break;
195+
case 3:
196+
val = read_gicreg(ICH_AP1R3_EL2);
197+
break;
198+
default:
199+
unreachable();
200+
}
201+
202+
return val;
203+
}
204+
121205
void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
122206
{
123207
struct vgic_v3_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v3;
@@ -154,22 +238,22 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
154238

155239
switch (nr_pre_bits) {
156240
case 7:
157-
cpu_if->vgic_ap0r[3] = read_gicreg(ICH_AP0R3_EL2);
158-
cpu_if->vgic_ap0r[2] = read_gicreg(ICH_AP0R2_EL2);
241+
cpu_if->vgic_ap0r[3] = __vgic_v3_read_ap0rn(3);
242+
cpu_if->vgic_ap0r[2] = __vgic_v3_read_ap0rn(2);
159243
case 6:
160-
cpu_if->vgic_ap0r[1] = read_gicreg(ICH_AP0R1_EL2);
244+
cpu_if->vgic_ap0r[1] = __vgic_v3_read_ap0rn(1);
161245
default:
162-
cpu_if->vgic_ap0r[0] = read_gicreg(ICH_AP0R0_EL2);
246+
cpu_if->vgic_ap0r[0] = __vgic_v3_read_ap0rn(0);
163247
}
164248

165249
switch (nr_pre_bits) {
166250
case 7:
167-
cpu_if->vgic_ap1r[3] = read_gicreg(ICH_AP1R3_EL2);
168-
cpu_if->vgic_ap1r[2] = read_gicreg(ICH_AP1R2_EL2);
251+
cpu_if->vgic_ap1r[3] = __vgic_v3_read_ap1rn(3);
252+
cpu_if->vgic_ap1r[2] = __vgic_v3_read_ap1rn(2);
169253
case 6:
170-
cpu_if->vgic_ap1r[1] = read_gicreg(ICH_AP1R1_EL2);
254+
cpu_if->vgic_ap1r[1] = __vgic_v3_read_ap1rn(1);
171255
default:
172-
cpu_if->vgic_ap1r[0] = read_gicreg(ICH_AP1R0_EL2);
256+
cpu_if->vgic_ap1r[0] = __vgic_v3_read_ap1rn(0);
173257
}
174258
} else {
175259
cpu_if->vgic_elrsr = 0xffff;
@@ -224,22 +308,22 @@ void __hyp_text __vgic_v3_restore_state(struct kvm_vcpu *vcpu)
224308

225309
switch (nr_pre_bits) {
226310
case 7:
227-
write_gicreg(cpu_if->vgic_ap0r[3], ICH_AP0R3_EL2);
228-
write_gicreg(cpu_if->vgic_ap0r[2], ICH_AP0R2_EL2);
311+
__vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[3], 3);
312+
__vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[2], 2);
229313
case 6:
230-
write_gicreg(cpu_if->vgic_ap0r[1], ICH_AP0R1_EL2);
314+
__vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[1], 1);
231315
default:
232-
write_gicreg(cpu_if->vgic_ap0r[0], ICH_AP0R0_EL2);
316+
__vgic_v3_write_ap0rn(cpu_if->vgic_ap0r[0], 0);
233317
}
234318

235319
switch (nr_pre_bits) {
236320
case 7:
237-
write_gicreg(cpu_if->vgic_ap1r[3], ICH_AP1R3_EL2);
238-
write_gicreg(cpu_if->vgic_ap1r[2], ICH_AP1R2_EL2);
321+
__vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[3], 3);
322+
__vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[2], 2);
239323
case 6:
240-
write_gicreg(cpu_if->vgic_ap1r[1], ICH_AP1R1_EL2);
324+
__vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[1], 1);
241325
default:
242-
write_gicreg(cpu_if->vgic_ap1r[0], ICH_AP1R0_EL2);
326+
__vgic_v3_write_ap1rn(cpu_if->vgic_ap1r[0], 0);
243327
}
244328

245329
for (i = 0; i < used_lrs; i++)

0 commit comments

Comments
 (0)