kvm: allow arbitrarily sized mmio ioeventfd

We use a 2 byte ioeventfd for virtio memory,
add support for this.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Amos Kong <akong@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
Michael S. Tsirkin 2012-03-20 14:31:38 +02:00 committed by Marcelo Tosatti
parent 56b9ead234
commit 4b8f1c88e9
4 changed files with 15 additions and 13 deletions

View File

@ -354,8 +354,8 @@ static void close_guest_eventfds(IVShmemState *s, int posn)
guest_curr_max = s->peers[posn].nb_eventfds; guest_curr_max = s->peers[posn].nb_eventfds;
for (i = 0; i < guest_curr_max; i++) { for (i = 0; i < guest_curr_max; i++) {
kvm_set_ioeventfd_mmio_long(s->peers[posn].eventfds[i], kvm_set_ioeventfd_mmio(s->peers[posn].eventfds[i],
s->mmio_addr + DOORBELL, (posn << 16) | i, 0); s->mmio_addr + DOORBELL, (posn << 16) | i, 0, 4);
close(s->peers[posn].eventfds[i]); close(s->peers[posn].eventfds[i]);
} }
@ -500,8 +500,8 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)
} }
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) { if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
if (kvm_set_ioeventfd_mmio_long(incoming_fd, s->mmio_addr + DOORBELL, if (kvm_set_ioeventfd_mmio(incoming_fd, s->mmio_addr + DOORBELL,
(incoming_posn << 16) | guest_max_eventfd, 1) < 0) { (incoming_posn << 16) | guest_max_eventfd, 1, 4) < 0) {
fprintf(stderr, "ivshmem: ioeventfd not available\n"); fprintf(stderr, "ivshmem: ioeventfd not available\n");
} }
} }

View File

@ -747,10 +747,10 @@ static void kvm_mem_ioeventfd_add(MemoryRegionSection *section,
{ {
int r; int r;
assert(match_data && section->size == 4); assert(match_data && section->size <= 8);
r = kvm_set_ioeventfd_mmio_long(fd, section->offset_within_address_space, r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
data, true); data, true, section->size);
if (r < 0) { if (r < 0) {
abort(); abort();
} }
@ -761,8 +761,8 @@ static void kvm_mem_ioeventfd_del(MemoryRegionSection *section,
{ {
int r; int r;
r = kvm_set_ioeventfd_mmio_long(fd, section->offset_within_address_space, r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
data, false); data, false, section->size);
if (r < 0) { if (r < 0) {
abort(); abort();
} }
@ -1642,14 +1642,15 @@ int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset)
return r; return r;
} }
int kvm_set_ioeventfd_mmio_long(int fd, uint32_t addr, uint32_t val, bool assign) int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, bool assign,
uint32_t size)
{ {
int ret; int ret;
struct kvm_ioeventfd iofd; struct kvm_ioeventfd iofd;
iofd.datamatch = val; iofd.datamatch = val;
iofd.addr = addr; iofd.addr = addr;
iofd.len = 4; iofd.len = size;
iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH; iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH;
iofd.fd = fd; iofd.fd = fd;

View File

@ -120,7 +120,7 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
return -ENOSYS; return -ENOSYS;
} }
int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign) int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t val, bool assign, uint32_t len)
{ {
return -ENOSYS; return -ENOSYS;
} }

3
kvm.h
View File

@ -210,7 +210,8 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
#endif #endif
#endif #endif
int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign); int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t val, bool assign,
uint32_t size);
int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);
#endif #endif