mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
pci: add pci test device
This adds a new device that we can use for testing PCI PIO and MMIO, with and without ioeventfd in different configurations. FAST_MMIO will be added if/when kvm supports it. Also included are minor cleanups in kvm APIs that it needs. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) iQEcBAABAgAGBQJRbIJQAAoJECgfDbjSjVRpQuoH/RfMHb6YYfsuwJKUsjCKxhdr 695YqNsBLmh7E/+wr1dwUsKrMGSF97VSGAIPeX0u4wwP6jrORhA9iycCevXYlh/S O7RTcePqVEQrwnMX5rOAEWGARVzg4hAT8i4Pdza1A+gBvaO/WLZIVJfUOHBAZNL7 2TTDymfixipErcTcxckITHfaShn9ajZgt/Yo8oVX70VqklWU+OEU/tYEXmvTC0H3 bTuTU3vpeAlCubF0AHHZqWA9g7myrKMCxwv4LWx7gmQGXoyQesy4s5C9KMrld1On RovLw0REbtjB2xGjAj3g82ESK5eoi295Th/E7Fu1NJNYyDyfhxB7/cnbRa+Wpsg= =jvZE -----END PGP SIGNATURE----- Merge remote-tracking branch 'mst/tags/for_anthony' into staging pci: add pci test device This adds a new device that we can use for testing PCI PIO and MMIO, with and without ioeventfd in different configurations. FAST_MMIO will be added if/when kvm supports it. Also included are minor cleanups in kvm APIs that it needs. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Mon 15 Apr 2013 05:42:24 PM CDT using RSA key ID D28D5469 # gpg: Can't check signature: public key not found # By Michael S. Tsirkin # Via Michael S. Tsirkin * mst/tags/for_anthony: pci: add pci test device kvm: support non datamatch ioeventfd kvm: support any size for pio eventfd kvm: remove unused APIs Message-id: cover.1366272004.git.mst@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
commit
5dff24beba
8 changed files with 422 additions and 79 deletions
133
kvm-all.c
133
kvm-all.c
|
@ -500,6 +500,66 @@ int kvm_check_extension(KVMState *s, unsigned int extension)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val,
|
||||
bool assign, uint32_t size, bool datamatch)
|
||||
{
|
||||
int ret;
|
||||
struct kvm_ioeventfd iofd;
|
||||
|
||||
iofd.datamatch = datamatch ? val : 0;
|
||||
iofd.addr = addr;
|
||||
iofd.len = size;
|
||||
iofd.flags = 0;
|
||||
iofd.fd = fd;
|
||||
|
||||
if (!kvm_enabled()) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
if (datamatch) {
|
||||
iofd.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH;
|
||||
}
|
||||
if (!assign) {
|
||||
iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
|
||||
}
|
||||
|
||||
ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &iofd);
|
||||
|
||||
if (ret < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint16_t val,
|
||||
bool assign, uint32_t size, bool datamatch)
|
||||
{
|
||||
struct kvm_ioeventfd kick = {
|
||||
.datamatch = datamatch ? val : 0,
|
||||
.addr = addr,
|
||||
.flags = KVM_IOEVENTFD_FLAG_PIO,
|
||||
.len = size,
|
||||
.fd = fd,
|
||||
};
|
||||
int r;
|
||||
if (!kvm_enabled()) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
if (datamatch) {
|
||||
kick.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH;
|
||||
}
|
||||
if (!assign) {
|
||||
kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
|
||||
}
|
||||
r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int kvm_check_many_ioeventfds(void)
|
||||
{
|
||||
/* Userspace can use ioeventfd for io notification. This requires a host
|
||||
|
@ -517,7 +577,7 @@ static int kvm_check_many_ioeventfds(void)
|
|||
if (ioeventfds[i] < 0) {
|
||||
break;
|
||||
}
|
||||
ret = kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, true);
|
||||
ret = kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, true, 2, true);
|
||||
if (ret < 0) {
|
||||
close(ioeventfds[i]);
|
||||
break;
|
||||
|
@ -528,7 +588,7 @@ static int kvm_check_many_ioeventfds(void)
|
|||
ret = i == ARRAY_SIZE(ioeventfds);
|
||||
|
||||
while (i-- > 0) {
|
||||
kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
|
||||
kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, false, 2, true);
|
||||
close(ioeventfds[i]);
|
||||
}
|
||||
return ret;
|
||||
|
@ -748,10 +808,8 @@ static void kvm_mem_ioeventfd_add(MemoryListener *listener,
|
|||
int fd = event_notifier_get_fd(e);
|
||||
int r;
|
||||
|
||||
assert(match_data && section->size <= 8);
|
||||
|
||||
r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
|
||||
data, true, section->size);
|
||||
data, true, section->size, match_data);
|
||||
if (r < 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -766,7 +824,7 @@ static void kvm_mem_ioeventfd_del(MemoryListener *listener,
|
|||
int r;
|
||||
|
||||
r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
|
||||
data, false, section->size);
|
||||
data, false, section->size, match_data);
|
||||
if (r < 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -780,10 +838,8 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener,
|
|||
int fd = event_notifier_get_fd(e);
|
||||
int r;
|
||||
|
||||
assert(match_data && section->size == 2);
|
||||
|
||||
r = kvm_set_ioeventfd_pio_word(fd, section->offset_within_address_space,
|
||||
data, true);
|
||||
r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
|
||||
data, true, section->size, match_data);
|
||||
if (r < 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -798,8 +854,8 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener,
|
|||
int fd = event_notifier_get_fd(e);
|
||||
int r;
|
||||
|
||||
r = kvm_set_ioeventfd_pio_word(fd, section->offset_within_address_space,
|
||||
data, false);
|
||||
r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
|
||||
data, false, section->size, match_data);
|
||||
if (r < 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -1967,59 +2023,6 @@ int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset)
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, bool assign,
|
||||
uint32_t size)
|
||||
{
|
||||
int ret;
|
||||
struct kvm_ioeventfd iofd;
|
||||
|
||||
iofd.datamatch = val;
|
||||
iofd.addr = addr;
|
||||
iofd.len = size;
|
||||
iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH;
|
||||
iofd.fd = fd;
|
||||
|
||||
if (!kvm_enabled()) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
if (!assign) {
|
||||
iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
|
||||
}
|
||||
|
||||
ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &iofd);
|
||||
|
||||
if (ret < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
|
||||
{
|
||||
struct kvm_ioeventfd kick = {
|
||||
.datamatch = val,
|
||||
.addr = addr,
|
||||
.len = 2,
|
||||
.flags = KVM_IOEVENTFD_FLAG_DATAMATCH | KVM_IOEVENTFD_FLAG_PIO,
|
||||
.fd = fd,
|
||||
};
|
||||
int r;
|
||||
if (!kvm_enabled()) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
if (!assign) {
|
||||
kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
|
||||
}
|
||||
r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
|
||||
{
|
||||
return kvm_arch_on_sigbus_vcpu(cpu, code, addr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue