* [PATCH] hw/loongarch: Add VM mode in IOCSR feature register in kvm mode
@ 2024-05-14 2:51 Bibo Mao
2024-05-14 11:08 ` gaosong
0 siblings, 1 reply; 2+ messages in thread
From: Bibo Mao @ 2024-05-14 2:51 UTC (permalink / raw)
To: Song Gao; +Cc: qemu-devel
If VM runs in kvm mode, VM mode is added in IOCSR feature register.
So guest can detect kvm hypervisor type and enable possible pv functions.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
hw/loongarch/virt.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index d87d9be576..44bcf25aee 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -10,6 +10,7 @@
#include "qapi/error.h"
#include "hw/boards.h"
#include "hw/char/serial.h"
+#include "sysemu/kvm.h"
#include "sysemu/sysemu.h"
#include "sysemu/qtest.h"
#include "sysemu/runstate.h"
@@ -840,18 +841,23 @@ static void virt_iocsr_misc_write(void *opaque, hwaddr addr,
static uint64_t virt_iocsr_misc_read(void *opaque, hwaddr addr, unsigned size)
{
+ uint64_t ret;
+
switch (addr) {
case VERSION_REG:
return 0x11ULL;
case FEATURE_REG:
- return 1ULL << IOCSRF_MSI | 1ULL << IOCSRF_EXTIOI |
- 1ULL << IOCSRF_CSRIPI;
+ ret = BIT(IOCSRF_MSI) | BIT(IOCSRF_EXTIOI) | BIT(IOCSRF_CSRIPI);
+ if (kvm_enabled()) {
+ ret |= BIT(IOCSRF_VM);
+ }
+ return ret;
case VENDOR_REG:
return 0x6e6f73676e6f6f4cULL; /* "Loongson" */
case CPUNAME_REG:
return 0x303030354133ULL; /* "3A5000" */
case MISC_FUNC_REG:
- return 1ULL << IOCSRM_EXTIOI_EN;
+ return BIT_ULL(IOCSRM_EXTIOI_EN);
}
return 0ULL;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hw/loongarch: Add VM mode in IOCSR feature register in kvm mode
2024-05-14 2:51 [PATCH] hw/loongarch: Add VM mode in IOCSR feature register in kvm mode Bibo Mao
@ 2024-05-14 11:08 ` gaosong
0 siblings, 0 replies; 2+ messages in thread
From: gaosong @ 2024-05-14 11:08 UTC (permalink / raw)
To: Bibo Mao; +Cc: qemu-devel
在 2024/5/14 上午10:51, Bibo Mao 写道:
> If VM runs in kvm mode, VM mode is added in IOCSR feature register.
> So guest can detect kvm hypervisor type and enable possible pv functions.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
Reviewed-by: Song Gao <gaosong@loongson.cn>
Thanks.
Song Gao
> hw/loongarch/virt.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index d87d9be576..44bcf25aee 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -10,6 +10,7 @@
> #include "qapi/error.h"
> #include "hw/boards.h"
> #include "hw/char/serial.h"
> +#include "sysemu/kvm.h"
> #include "sysemu/sysemu.h"
> #include "sysemu/qtest.h"
> #include "sysemu/runstate.h"
> @@ -840,18 +841,23 @@ static void virt_iocsr_misc_write(void *opaque, hwaddr addr,
>
> static uint64_t virt_iocsr_misc_read(void *opaque, hwaddr addr, unsigned size)
> {
> + uint64_t ret;
> +
> switch (addr) {
> case VERSION_REG:
> return 0x11ULL;
> case FEATURE_REG:
> - return 1ULL << IOCSRF_MSI | 1ULL << IOCSRF_EXTIOI |
> - 1ULL << IOCSRF_CSRIPI;
> + ret = BIT(IOCSRF_MSI) | BIT(IOCSRF_EXTIOI) | BIT(IOCSRF_CSRIPI);
> + if (kvm_enabled()) {
> + ret |= BIT(IOCSRF_VM);
> + }
> + return ret;
> case VENDOR_REG:
> return 0x6e6f73676e6f6f4cULL; /* "Loongson" */
> case CPUNAME_REG:
> return 0x303030354133ULL; /* "3A5000" */
> case MISC_FUNC_REG:
> - return 1ULL << IOCSRM_EXTIOI_EN;
> + return BIT_ULL(IOCSRM_EXTIOI_EN);
> }
> return 0ULL;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-14 11:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 2:51 [PATCH] hw/loongarch: Add VM mode in IOCSR feature register in kvm mode Bibo Mao
2024-05-14 11:08 ` gaosong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).