Skip to content

Commit ca85f62

Browse files
Marc Zyngierchazy
authored andcommitted
KVM: ARM: introduce vgic_params structure
Move all the data specific to a given GIC implementation into its own little structure. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent da8dafd commit ca85f62

2 files changed

Lines changed: 44 additions & 37 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ struct vgic_ops {
102102
void (*enable)(struct kvm_vcpu *vcpu);
103103
};
104104

105+
struct vgic_params {
106+
/* Physical address of vgic virtual cpu interface */
107+
phys_addr_t vcpu_base;
108+
/* Number of list registers */
109+
u32 nr_lr;
110+
/* Interrupt number */
111+
unsigned int maint_irq;
112+
/* Virtual control interface base address */
113+
void __iomem *vctrl_base;
114+
};
115+
105116
struct vgic_dist {
106117
#ifdef CONFIG_KVM_ARM_VGIC
107118
spinlock_t lock;

‎virt/kvm/arm/vgic.c‎

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@
7676
#define IMPLEMENTER_ARM 0x43b
7777
#define GICC_ARCH_VERSION_V2 0x2
7878

79-
/* Physical address of vgic virtual cpu interface */
80-
static phys_addr_t vgic_vcpu_base;
81-
82-
/* Virtual control interface base address */
83-
static void __iomem *vgic_vctrl_base;
84-
85-
static struct device_node *vgic_node;
86-
8779
#define ACCESS_READ_VALUE (1 << 0)
8880
#define ACCESS_READ_RAZ (0 << 0)
8981
#define ACCESS_READ_MASK(x) ((x) & (1 << 0))
@@ -103,8 +95,7 @@ static void vgic_set_lr(struct kvm_vcpu *vcpu, int lr, struct vgic_lr lr_desc);
10395
static void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
10496
static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);
10597

106-
static u32 vgic_nr_lr;
107-
static unsigned int vgic_maint_irq;
98+
static struct vgic_params vgic;
10899

109100
static u32 *vgic_bitmap_get_reg(struct vgic_bitmap *x,
110101
int cpuid, u32 offset)
@@ -1206,7 +1197,7 @@ static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu)
12061197
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
12071198
int lr;
12081199

1209-
for_each_set_bit(lr, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
1200+
for_each_set_bit(lr, vgic_cpu->lr_used, vgic.nr_lr) {
12101201
struct vgic_lr vlr = vgic_get_lr(vcpu, lr);
12111202

12121203
if (!vgic_irq_is_enabled(vcpu, vlr.irq)) {
@@ -1250,8 +1241,8 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
12501241

12511242
/* Try to use another LR for this interrupt */
12521243
lr = find_first_zero_bit((unsigned long *)vgic_cpu->lr_used,
1253-
vgic_cpu->nr_lr);
1254-
if (lr >= vgic_cpu->nr_lr)
1244+
vgic.nr_lr);
1245+
if (lr >= vgic.nr_lr)
12551246
return false;
12561247

12571248
kvm_debug("LR%d allocated for IRQ%d %x\n", lr, irq, sgi_source_id);
@@ -1377,7 +1368,6 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)
13771368

13781369
static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)
13791370
{
1380-
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
13811371
u32 status = vgic_get_interrupt_status(vcpu);
13821372
bool level_pending = false;
13831373

@@ -1392,7 +1382,7 @@ static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)
13921382
unsigned long *eisr_ptr = (unsigned long *)&eisr;
13931383
int lr;
13941384

1395-
for_each_set_bit(lr, eisr_ptr, vgic_cpu->nr_lr) {
1385+
for_each_set_bit(lr, eisr_ptr, vgic.nr_lr) {
13961386
struct vgic_lr vlr = vgic_get_lr(vcpu, lr);
13971387

13981388
vgic_irq_clear_active(vcpu, vlr.irq);
@@ -1440,7 +1430,7 @@ static void __kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu)
14401430
elrsr_ptr = (unsigned long *)&elrsr;
14411431

14421432
/* Clear mappings for empty LRs */
1443-
for_each_set_bit(lr, elrsr_ptr, vgic_cpu->nr_lr) {
1433+
for_each_set_bit(lr, elrsr_ptr, vgic.nr_lr) {
14441434
struct vgic_lr vlr;
14451435

14461436
if (!test_and_clear_bit(lr, vgic_cpu->lr_used))
@@ -1453,8 +1443,8 @@ static void __kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu)
14531443
}
14541444

14551445
/* Check if we still have something up our sleeve... */
1456-
pending = find_first_zero_bit(elrsr_ptr, vgic_cpu->nr_lr);
1457-
if (level_pending || pending < vgic_cpu->nr_lr)
1446+
pending = find_first_zero_bit(elrsr_ptr, vgic.nr_lr);
1447+
if (level_pending || pending < vgic.nr_lr)
14581448
set_bit(vcpu->vcpu_id, &dist->irq_pending_on_cpu);
14591449
}
14601450

@@ -1643,7 +1633,12 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
16431633
vgic_cpu->vgic_irq_lr_map[i] = LR_EMPTY;
16441634
}
16451635

1646-
vgic_cpu->nr_lr = vgic_nr_lr;
1636+
/*
1637+
* Store the number of LRs per vcpu, so we don't have to go
1638+
* all the way to the distributor structure to find out. Only
1639+
* assembly code should use this one.
1640+
*/
1641+
vgic_cpu->nr_lr = vgic.nr_lr;
16471642

16481643
vgic_enable(vcpu);
16491644

@@ -1652,7 +1647,7 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
16521647

16531648
static void vgic_init_maintenance_interrupt(void *info)
16541649
{
1655-
enable_percpu_irq(vgic_maint_irq, 0);
1650+
enable_percpu_irq(vgic.maint_irq, 0);
16561651
}
16571652

16581653
static int vgic_cpu_notify(struct notifier_block *self,
@@ -1665,7 +1660,7 @@ static int vgic_cpu_notify(struct notifier_block *self,
16651660
break;
16661661
case CPU_DYING:
16671662
case CPU_DYING_FROZEN:
1668-
disable_percpu_irq(vgic_maint_irq);
1663+
disable_percpu_irq(vgic.maint_irq);
16691664
break;
16701665
}
16711666

@@ -1681,24 +1676,25 @@ int kvm_vgic_hyp_init(void)
16811676
int ret;
16821677
struct resource vctrl_res;
16831678
struct resource vcpu_res;
1679+
struct device_node *vgic_node;
16841680

16851681
vgic_node = of_find_compatible_node(NULL, NULL, "arm,cortex-a15-gic");
16861682
if (!vgic_node) {
16871683
kvm_err("error: no compatible vgic node in DT\n");
16881684
return -ENODEV;
16891685
}
16901686

1691-
vgic_maint_irq = irq_of_parse_and_map(vgic_node, 0);
1692-
if (!vgic_maint_irq) {
1687+
vgic.maint_irq = irq_of_parse_and_map(vgic_node, 0);
1688+
if (!vgic.maint_irq) {
16931689
kvm_err("error getting vgic maintenance irq from DT\n");
16941690
ret = -ENXIO;
16951691
goto out;
16961692
}
16971693

1698-
ret = request_percpu_irq(vgic_maint_irq, vgic_maintenance_handler,
1694+
ret = request_percpu_irq(vgic.maint_irq, vgic_maintenance_handler,
16991695
"vgic", kvm_get_running_vcpus());
17001696
if (ret) {
1701-
kvm_err("Cannot register interrupt %d\n", vgic_maint_irq);
1697+
kvm_err("Cannot register interrupt %d\n", vgic.maint_irq);
17021698
goto out;
17031699
}
17041700

@@ -1714,41 +1710,41 @@ int kvm_vgic_hyp_init(void)
17141710
goto out_free_irq;
17151711
}
17161712

1717-
vgic_vctrl_base = of_iomap(vgic_node, 2);
1718-
if (!vgic_vctrl_base) {
1713+
vgic.vctrl_base = of_iomap(vgic_node, 2);
1714+
if (!vgic.vctrl_base) {
17191715
kvm_err("Cannot ioremap VCTRL\n");
17201716
ret = -ENOMEM;
17211717
goto out_free_irq;
17221718
}
17231719

1724-
vgic_nr_lr = readl_relaxed(vgic_vctrl_base + GICH_VTR);
1725-
vgic_nr_lr = (vgic_nr_lr & 0x3f) + 1;
1720+
vgic.nr_lr = readl_relaxed(vgic.vctrl_base + GICH_VTR);
1721+
vgic.nr_lr = (vgic.nr_lr & 0x3f) + 1;
17261722

1727-
ret = create_hyp_io_mappings(vgic_vctrl_base,
1728-
vgic_vctrl_base + resource_size(&vctrl_res),
1723+
ret = create_hyp_io_mappings(vgic.vctrl_base,
1724+
vgic.vctrl_base + resource_size(&vctrl_res),
17291725
vctrl_res.start);
17301726
if (ret) {
17311727
kvm_err("Cannot map VCTRL into hyp\n");
17321728
goto out_unmap;
17331729
}
17341730

17351731
kvm_info("%s@%llx IRQ%d\n", vgic_node->name,
1736-
vctrl_res.start, vgic_maint_irq);
1732+
vctrl_res.start, vgic.maint_irq);
17371733
on_each_cpu(vgic_init_maintenance_interrupt, NULL, 1);
17381734

17391735
if (of_address_to_resource(vgic_node, 3, &vcpu_res)) {
17401736
kvm_err("Cannot obtain VCPU resource\n");
17411737
ret = -ENXIO;
17421738
goto out_unmap;
17431739
}
1744-
vgic_vcpu_base = vcpu_res.start;
1740+
vgic.vcpu_base = vcpu_res.start;
17451741

17461742
goto out;
17471743

17481744
out_unmap:
1749-
iounmap(vgic_vctrl_base);
1745+
iounmap(vgic.vctrl_base);
17501746
out_free_irq:
1751-
free_percpu_irq(vgic_maint_irq, kvm_get_running_vcpus());
1747+
free_percpu_irq(vgic.maint_irq, kvm_get_running_vcpus());
17521748
out:
17531749
of_node_put(vgic_node);
17541750
return ret;
@@ -1783,7 +1779,7 @@ int kvm_vgic_init(struct kvm *kvm)
17831779
}
17841780

17851781
ret = kvm_phys_addr_ioremap(kvm, kvm->arch.vgic.vgic_cpu_base,
1786-
vgic_vcpu_base, KVM_VGIC_V2_CPU_SIZE);
1782+
vgic.vcpu_base, KVM_VGIC_V2_CPU_SIZE);
17871783
if (ret) {
17881784
kvm_err("Unable to remap VGIC CPU to VCPU\n");
17891785
goto out;
@@ -1829,7 +1825,7 @@ int kvm_vgic_create(struct kvm *kvm)
18291825
}
18301826

18311827
spin_lock_init(&kvm->arch.vgic.lock);
1832-
kvm->arch.vgic.vctrl_base = vgic_vctrl_base;
1828+
kvm->arch.vgic.vctrl_base = vgic.vctrl_base;
18331829
kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
18341830
kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
18351831

0 commit comments

Comments
 (0)