|
27 | 27 | #include "qemu/fifo8.h" |
28 | 28 | #include "sysemu/char.h" |
29 | 29 |
|
| 30 | +#include "hw/misc/ivshmem.h" |
| 31 | + |
30 | 32 | #include <sys/mman.h> |
31 | 33 | #include <sys/types.h> |
32 | 34 | #include <limits.h> |
@@ -596,6 +598,31 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) |
596 | 598 | } |
597 | 599 | } |
598 | 600 |
|
| 601 | +static void ivshmem_check_version(void *opaque, const uint8_t * buf, int size) |
| 602 | +{ |
| 603 | + IVShmemState *s = opaque; |
| 604 | + int tmp; |
| 605 | + long version; |
| 606 | + |
| 607 | + if (!fifo_update_and_get(s, buf, size, |
| 608 | + &version, sizeof(version))) { |
| 609 | + return; |
| 610 | + } |
| 611 | + |
| 612 | + tmp = qemu_chr_fe_get_msgfd(s->server_chr); |
| 613 | + if (tmp != -1 || version != IVSHMEM_PROTOCOL_VERSION) { |
| 614 | + fprintf(stderr, "incompatible version, you are connecting to a ivshmem-" |
| 615 | + "server using a different protocol please check your setup\n"); |
| 616 | + qemu_chr_delete(s->server_chr); |
| 617 | + s->server_chr = NULL; |
| 618 | + return; |
| 619 | + } |
| 620 | + |
| 621 | + IVSHMEM_DPRINTF("version check ok, switch to real chardev handler\n"); |
| 622 | + qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read, |
| 623 | + ivshmem_event, s); |
| 624 | +} |
| 625 | + |
599 | 626 | /* Select the MSI-X vectors used by device. |
600 | 627 | * ivshmem maps events to vectors statically, so |
601 | 628 | * we just enable all vectors on init and after reset. */ |
@@ -769,8 +796,8 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp) |
769 | 796 |
|
770 | 797 | s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *)); |
771 | 798 |
|
772 | | - qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read, |
773 | | - ivshmem_event, s); |
| 799 | + qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, |
| 800 | + ivshmem_check_version, ivshmem_event, s); |
774 | 801 | } else { |
775 | 802 | /* just map the file immediately, we're not using a server */ |
776 | 803 | int fd; |
|
0 commit comments