-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RISC-V: KVM: Initial skeletal support for AIA
To incrementally implement AIA support, we first add minimal skeletal support which only compiles and detects AIA hardware support at the boot-time but does not provide any functionality. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
- Loading branch information
Anup Patel
authored and
Anup Patel
committed
Apr 21, 2023
1 parent
e290dbb
commit 54e4332
Showing
9 changed files
with
255 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright (C) 2021 Western Digital Corporation or its affiliates. | ||
* Copyright (C) 2022 Ventana Micro Systems Inc. | ||
* | ||
* Authors: | ||
* Anup Patel <apatel@ventanamicro.com> | ||
*/ | ||
|
||
#ifndef __KVM_RISCV_AIA_H | ||
#define __KVM_RISCV_AIA_H | ||
|
||
#include <linux/jump_label.h> | ||
#include <linux/kvm_types.h> | ||
|
||
struct kvm_aia { | ||
/* In-kernel irqchip created */ | ||
bool in_kernel; | ||
|
||
/* In-kernel irqchip initialized */ | ||
bool initialized; | ||
}; | ||
|
||
struct kvm_vcpu_aia { | ||
}; | ||
|
||
#define kvm_riscv_aia_initialized(k) ((k)->arch.aia.initialized) | ||
|
||
#define irqchip_in_kernel(k) ((k)->arch.aia.in_kernel) | ||
|
||
DECLARE_STATIC_KEY_FALSE(kvm_riscv_aia_available); | ||
#define kvm_riscv_aia_available() \ | ||
static_branch_unlikely(&kvm_riscv_aia_available) | ||
|
||
static inline void kvm_riscv_vcpu_aia_flush_interrupts(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_sync_interrupts(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline bool kvm_riscv_vcpu_aia_has_interrupts(struct kvm_vcpu *vcpu, | ||
u64 mask) | ||
{ | ||
return false; | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_update_hvip(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_load(struct kvm_vcpu *vcpu, int cpu) | ||
{ | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_put(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline int kvm_riscv_vcpu_aia_get_csr(struct kvm_vcpu *vcpu, | ||
unsigned long reg_num, | ||
unsigned long *out_val) | ||
{ | ||
*out_val = 0; | ||
return 0; | ||
} | ||
|
||
static inline int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu, | ||
unsigned long reg_num, | ||
unsigned long val) | ||
{ | ||
return 0; | ||
} | ||
|
||
#define KVM_RISCV_VCPU_AIA_CSR_FUNCS | ||
|
||
static inline int kvm_riscv_vcpu_aia_update(struct kvm_vcpu *vcpu) | ||
{ | ||
return 1; | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_reset(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline int kvm_riscv_vcpu_aia_init(struct kvm_vcpu *vcpu) | ||
{ | ||
return 0; | ||
} | ||
|
||
static inline void kvm_riscv_vcpu_aia_deinit(struct kvm_vcpu *vcpu) | ||
{ | ||
} | ||
|
||
static inline void kvm_riscv_aia_init_vm(struct kvm *kvm) | ||
{ | ||
} | ||
|
||
static inline void kvm_riscv_aia_destroy_vm(struct kvm *kvm) | ||
{ | ||
} | ||
|
||
void kvm_riscv_aia_enable(void); | ||
void kvm_riscv_aia_disable(void); | ||
int kvm_riscv_aia_init(void); | ||
void kvm_riscv_aia_exit(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (C) 2021 Western Digital Corporation or its affiliates. | ||
* Copyright (C) 2022 Ventana Micro Systems Inc. | ||
* | ||
* Authors: | ||
* Anup Patel <apatel@ventanamicro.com> | ||
*/ | ||
|
||
#include <linux/kvm_host.h> | ||
#include <asm/hwcap.h> | ||
|
||
DEFINE_STATIC_KEY_FALSE(kvm_riscv_aia_available); | ||
|
||
static void aia_set_hvictl(bool ext_irq_pending) | ||
{ | ||
unsigned long hvictl; | ||
|
||
/* | ||
* HVICTL.IID == 9 and HVICTL.IPRIO == 0 represents | ||
* no interrupt in HVICTL. | ||
*/ | ||
|
||
hvictl = (IRQ_S_EXT << HVICTL_IID_SHIFT) & HVICTL_IID; | ||
hvictl |= ext_irq_pending; | ||
csr_write(CSR_HVICTL, hvictl); | ||
} | ||
|
||
void kvm_riscv_aia_enable(void) | ||
{ | ||
if (!kvm_riscv_aia_available()) | ||
return; | ||
|
||
aia_set_hvictl(false); | ||
csr_write(CSR_HVIPRIO1, 0x0); | ||
csr_write(CSR_HVIPRIO2, 0x0); | ||
#ifdef CONFIG_32BIT | ||
csr_write(CSR_HVIPH, 0x0); | ||
csr_write(CSR_HIDELEGH, 0x0); | ||
csr_write(CSR_HVIPRIO1H, 0x0); | ||
csr_write(CSR_HVIPRIO2H, 0x0); | ||
#endif | ||
} | ||
|
||
void kvm_riscv_aia_disable(void) | ||
{ | ||
if (!kvm_riscv_aia_available()) | ||
return; | ||
|
||
aia_set_hvictl(false); | ||
} | ||
|
||
int kvm_riscv_aia_init(void) | ||
{ | ||
if (!riscv_isa_extension_available(NULL, SxAIA)) | ||
return -ENODEV; | ||
|
||
/* Enable KVM AIA support */ | ||
static_branch_enable(&kvm_riscv_aia_available); | ||
|
||
return 0; | ||
} | ||
|
||
void kvm_riscv_aia_exit(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.