Commit 807a3784 authored by Marc Zyngier's avatar Marc Zyngier

KVM: arm/arm64: Move ioremap calls to create_hyp_io_mappings

Both HYP io mappings call ioremap, followed by create_hyp_io_mappings.
Let's move the ioremap call into create_hyp_io_mappings itself, which
simplifies the code a bit and allows for further refactoring.
Reviewed-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
parent b4ef0499
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
#include <asm/stage2_pgtable.h> #include <asm/stage2_pgtable.h>
int create_hyp_mappings(void *from, void *to, pgprot_t prot); int create_hyp_mappings(void *from, void *to, pgprot_t prot);
int create_hyp_io_mappings(void *from, void *to, phys_addr_t); int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
void __iomem **kaddr);
void free_hyp_pgds(void); void free_hyp_pgds(void);
void stage2_unmap_vm(struct kvm *kvm); void stage2_unmap_vm(struct kvm *kvm);
......
...@@ -140,7 +140,8 @@ static inline unsigned long __kern_hyp_va(unsigned long v) ...@@ -140,7 +140,8 @@ static inline unsigned long __kern_hyp_va(unsigned long v)
#include <asm/stage2_pgtable.h> #include <asm/stage2_pgtable.h>
int create_hyp_mappings(void *from, void *to, pgprot_t prot); int create_hyp_mappings(void *from, void *to, pgprot_t prot);
int create_hyp_io_mappings(void *from, void *to, phys_addr_t); int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
void __iomem **kaddr);
void free_hyp_pgds(void); void free_hyp_pgds(void);
void stage2_unmap_vm(struct kvm *kvm); void stage2_unmap_vm(struct kvm *kvm);
......
...@@ -709,26 +709,30 @@ int create_hyp_mappings(void *from, void *to, pgprot_t prot) ...@@ -709,26 +709,30 @@ int create_hyp_mappings(void *from, void *to, pgprot_t prot)
} }
/** /**
* create_hyp_io_mappings - duplicate a kernel IO mapping into Hyp mode * create_hyp_io_mappings - Map IO into both kernel and HYP
* @from: The kernel start VA of the range
* @to: The kernel end VA of the range (exclusive)
* @phys_addr: The physical start address which gets mapped * @phys_addr: The physical start address which gets mapped
* @size: Size of the region being mapped
* @kaddr: Kernel VA for this mapping
* *
* The resulting HYP VA is the same as the kernel VA, modulo * The resulting HYP VA is the same as the kernel VA, modulo
* HYP_PAGE_OFFSET. * HYP_PAGE_OFFSET.
*/ */
int create_hyp_io_mappings(void *from, void *to, phys_addr_t phys_addr) int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
void __iomem **kaddr)
{ {
unsigned long start = kern_hyp_va((unsigned long)from); unsigned long start, end;
unsigned long end = kern_hyp_va((unsigned long)to);
if (is_kernel_in_hyp_mode()) *kaddr = ioremap(phys_addr, size);
if (!*kaddr)
return -ENOMEM;
if (is_kernel_in_hyp_mode()) {
return 0; return 0;
}
/* Check for a valid kernel IO mapping */
if (!is_vmalloc_addr(from) || !is_vmalloc_addr(to - 1))
return -EINVAL;
start = kern_hyp_va((unsigned long)*kaddr);
end = kern_hyp_va((unsigned long)*kaddr + size);
return __create_hyp_mappings(hyp_pgd, PTRS_PER_PGD, start, end, return __create_hyp_mappings(hyp_pgd, PTRS_PER_PGD, start, end,
__phys_to_pfn(phys_addr), PAGE_HYP_DEVICE); __phys_to_pfn(phys_addr), PAGE_HYP_DEVICE);
} }
......
...@@ -360,16 +360,10 @@ int vgic_v2_probe(const struct gic_kvm_info *info) ...@@ -360,16 +360,10 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
if (!PAGE_ALIGNED(info->vcpu.start) || if (!PAGE_ALIGNED(info->vcpu.start) ||
!PAGE_ALIGNED(resource_size(&info->vcpu))) { !PAGE_ALIGNED(resource_size(&info->vcpu))) {
kvm_info("GICV region size/alignment is unsafe, using trapping (reduced performance)\n"); kvm_info("GICV region size/alignment is unsafe, using trapping (reduced performance)\n");
kvm_vgic_global_state.vcpu_base_va = ioremap(info->vcpu.start,
resource_size(&info->vcpu));
if (!kvm_vgic_global_state.vcpu_base_va) {
kvm_err("Cannot ioremap GICV\n");
return -ENOMEM;
}
ret = create_hyp_io_mappings(kvm_vgic_global_state.vcpu_base_va, ret = create_hyp_io_mappings(info->vcpu.start,
kvm_vgic_global_state.vcpu_base_va + resource_size(&info->vcpu), resource_size(&info->vcpu),
info->vcpu.start); &kvm_vgic_global_state.vcpu_base_va);
if (ret) { if (ret) {
kvm_err("Cannot map GICV into hyp\n"); kvm_err("Cannot map GICV into hyp\n");
goto out; goto out;
...@@ -378,26 +372,17 @@ int vgic_v2_probe(const struct gic_kvm_info *info) ...@@ -378,26 +372,17 @@ int vgic_v2_probe(const struct gic_kvm_info *info)
static_branch_enable(&vgic_v2_cpuif_trap); static_branch_enable(&vgic_v2_cpuif_trap);
} }
kvm_vgic_global_state.vctrl_base = ioremap(info->vctrl.start, ret = create_hyp_io_mappings(info->vctrl.start,
resource_size(&info->vctrl)); resource_size(&info->vctrl),
if (!kvm_vgic_global_state.vctrl_base) { &kvm_vgic_global_state.vctrl_base);
kvm_err("Cannot ioremap GICH\n"); if (ret) {
ret = -ENOMEM; kvm_err("Cannot map VCTRL into hyp\n");
goto out; goto out;
} }
vtr = readl_relaxed(kvm_vgic_global_state.vctrl_base + GICH_VTR); vtr = readl_relaxed(kvm_vgic_global_state.vctrl_base + GICH_VTR);
kvm_vgic_global_state.nr_lr = (vtr & 0x3f) + 1; kvm_vgic_global_state.nr_lr = (vtr & 0x3f) + 1;
ret = create_hyp_io_mappings(kvm_vgic_global_state.vctrl_base,
kvm_vgic_global_state.vctrl_base +
resource_size(&info->vctrl),
info->vctrl.start);
if (ret) {
kvm_err("Cannot map VCTRL into hyp\n");
goto out;
}
ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2); ret = kvm_register_vgic_device(KVM_DEV_TYPE_ARM_VGIC_V2);
if (ret) { if (ret) {
kvm_err("Cannot register GICv2 KVM device\n"); kvm_err("Cannot register GICv2 KVM device\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment