mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
intc/gic: Extract some reusable vGIC code
Some functions previously used only by vGICv2 are useful also for vGICv3 implementation. Untie them from GICState and make accessible from within other modules: - kvm_arm_gic_set_irq() - kvm_gic_supports_attr() - moved to common code and renamed to kvm_device_check_attr() - kvm_gic_access() - turned into GIC-independent kvm_device_access(). Data pointer changed to void * because some GICv3 registers are 64-bit wide Some of these changes are not used right now, but they will be helpful for implementing live migration. Actually kvm_dist_get() and kvm_dist_put() could also be made reusable, but they would require two extra parameters (s->dev_fd and s->num_cpu) as well as lots of typecasts of 's' to DeviceState * and back to GICState *. This makes the code very ugly so i decided to stop at this point. I tried also an approach with making a base class for all possible GICs, but it would contain only three variables (dev_fd, cpu_num and irq_num), and accessing them through the rest of the code would be again tedious (either ugly casts or qemu-style separate object pointer). So i disliked it too. Signed-off-by: Pavel Fedin <p.fedin@samsung.com> Tested-by: Ashok kumar <ashoks@broadcom.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 2ef56d1dd64ffb75ed02a10dcdaf605e5b8ff4f8.1441784344.git.p.fedin@samsung.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
ff8f06ee76
commit
4b3cfe72d9
4 changed files with 129 additions and 66 deletions
34
kvm-all.c
34
kvm-all.c
|
|
@ -24,6 +24,7 @@
|
|||
#include "qemu/atomic.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/config-file.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/pci/msi.h"
|
||||
#include "hw/s390x/adapter.h"
|
||||
|
|
@ -2008,6 +2009,39 @@ int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr)
|
|||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)
|
||||
{
|
||||
struct kvm_device_attr attribute = {
|
||||
.group = group,
|
||||
.attr = attr,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
return kvm_device_ioctl(dev_fd, KVM_HAS_DEVICE_ATTR, &attribute) ? 0 : 1;
|
||||
}
|
||||
|
||||
void kvm_device_access(int fd, int group, uint64_t attr,
|
||||
void *val, bool write)
|
||||
{
|
||||
struct kvm_device_attr kvmattr;
|
||||
int err;
|
||||
|
||||
kvmattr.flags = 0;
|
||||
kvmattr.group = group;
|
||||
kvmattr.attr = attr;
|
||||
kvmattr.addr = (uintptr_t)val;
|
||||
|
||||
err = kvm_device_ioctl(fd,
|
||||
write ? KVM_SET_DEVICE_ATTR : KVM_GET_DEVICE_ATTR,
|
||||
&kvmattr);
|
||||
if (err < 0) {
|
||||
error_report("KVM_%s_DEVICE_ATTR failed: %s\n"
|
||||
"Group %d attr 0x%016" PRIx64, write ? "SET" : "GET",
|
||||
strerror(-err), group, attr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int kvm_has_sync_mmu(void)
|
||||
{
|
||||
return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue