qemu-ga: build_fs_mount_list(): take an Error argument
[qemu.git] / hw / ivshmem.c
blobfcf5d05bae7b375dca7c82f596be1c450af6b03a
1 /*
2 * Inter-VM Shared Memory PCI device.
4 * Author:
5 * Cam Macdonell <cam@cs.ualberta.ca>
7 * Based On: cirrus_vga.c
8 * Copyright (c) 2004 Fabrice Bellard
9 * Copyright (c) 2004 Makoto Suzuki (suzu)
11 * and rtl8139.c
12 * Copyright (c) 2006 Igor Kovalenko
14 * This code is licensed under the GNU GPL v2.
16 * Contributions after 2012-01-13 are licensed under the terms of the
17 * GNU GPL, version 2 or (at your option) any later version.
19 #include "hw.h"
20 #include "pc.h"
21 #include "pci/pci.h"
22 #include "pci/msix.h"
23 #include "sysemu/kvm.h"
24 #include "migration/migration.h"
25 #include "qapi/qmp/qerror.h"
26 #include "qemu/event_notifier.h"
27 #include "char/char.h"
29 #include <sys/mman.h>
30 #include <sys/types.h>
32 #define IVSHMEM_IOEVENTFD 0
33 #define IVSHMEM_MSI 1
35 #define IVSHMEM_PEER 0
36 #define IVSHMEM_MASTER 1
38 #define IVSHMEM_REG_BAR_SIZE 0x100
40 //#define DEBUG_IVSHMEM
41 #ifdef DEBUG_IVSHMEM
42 #define IVSHMEM_DPRINTF(fmt, ...) \
43 do {printf("IVSHMEM: " fmt, ## __VA_ARGS__); } while (0)
44 #else
45 #define IVSHMEM_DPRINTF(fmt, ...)
46 #endif
48 typedef struct Peer {
49 int nb_eventfds;
50 EventNotifier *eventfds;
51 } Peer;
53 typedef struct EventfdEntry {
54 PCIDevice *pdev;
55 int vector;
56 } EventfdEntry;
58 typedef struct IVShmemState {
59 PCIDevice dev;
60 uint32_t intrmask;
61 uint32_t intrstatus;
62 uint32_t doorbell;
64 CharDriverState **eventfd_chr;
65 CharDriverState *server_chr;
66 MemoryRegion ivshmem_mmio;
68 /* We might need to register the BAR before we actually have the memory.
69 * So prepare a container MemoryRegion for the BAR immediately and
70 * add a subregion when we have the memory.
72 MemoryRegion bar;
73 MemoryRegion ivshmem;
74 uint64_t ivshmem_size; /* size of shared memory region */
75 uint32_t ivshmem_attr;
76 uint32_t ivshmem_64bit;
77 int shm_fd; /* shared memory file descriptor */
79 Peer *peers;
80 int nb_peers; /* how many guests we have space for */
81 int max_peer; /* maximum numbered peer */
83 int vm_id;
84 uint32_t vectors;
85 uint32_t features;
86 EventfdEntry *eventfd_table;
88 Error *migration_blocker;
90 char * shmobj;
91 char * sizearg;
92 char * role;
93 int role_val; /* scalar to avoid multiple string comparisons */
94 } IVShmemState;
96 /* registers for the Inter-VM shared memory device */
97 enum ivshmem_registers {
98 INTRMASK = 0,
99 INTRSTATUS = 4,
100 IVPOSITION = 8,
101 DOORBELL = 12,
104 static inline uint32_t ivshmem_has_feature(IVShmemState *ivs,
105 unsigned int feature) {
106 return (ivs->features & (1 << feature));
109 static inline bool is_power_of_two(uint64_t x) {
110 return (x & (x - 1)) == 0;
113 /* accessing registers - based on rtl8139 */
114 static void ivshmem_update_irq(IVShmemState *s, int val)
116 int isr;
117 isr = (s->intrstatus & s->intrmask) & 0xffffffff;
119 /* don't print ISR resets */
120 if (isr) {
121 IVSHMEM_DPRINTF("Set IRQ to %d (%04x %04x)\n",
122 isr ? 1 : 0, s->intrstatus, s->intrmask);
125 qemu_set_irq(s->dev.irq[0], (isr != 0));
128 static void ivshmem_IntrMask_write(IVShmemState *s, uint32_t val)
130 IVSHMEM_DPRINTF("IntrMask write(w) val = 0x%04x\n", val);
132 s->intrmask = val;
134 ivshmem_update_irq(s, val);
137 static uint32_t ivshmem_IntrMask_read(IVShmemState *s)
139 uint32_t ret = s->intrmask;
141 IVSHMEM_DPRINTF("intrmask read(w) val = 0x%04x\n", ret);
143 return ret;
146 static void ivshmem_IntrStatus_write(IVShmemState *s, uint32_t val)
148 IVSHMEM_DPRINTF("IntrStatus write(w) val = 0x%04x\n", val);
150 s->intrstatus = val;
152 ivshmem_update_irq(s, val);
155 static uint32_t ivshmem_IntrStatus_read(IVShmemState *s)
157 uint32_t ret = s->intrstatus;
159 /* reading ISR clears all interrupts */
160 s->intrstatus = 0;
162 ivshmem_update_irq(s, 0);
164 return ret;
167 static void ivshmem_io_write(void *opaque, hwaddr addr,
168 uint64_t val, unsigned size)
170 IVShmemState *s = opaque;
172 uint16_t dest = val >> 16;
173 uint16_t vector = val & 0xff;
175 addr &= 0xfc;
177 IVSHMEM_DPRINTF("writing to addr " TARGET_FMT_plx "\n", addr);
178 switch (addr)
180 case INTRMASK:
181 ivshmem_IntrMask_write(s, val);
182 break;
184 case INTRSTATUS:
185 ivshmem_IntrStatus_write(s, val);
186 break;
188 case DOORBELL:
189 /* check that dest VM ID is reasonable */
190 if (dest > s->max_peer) {
191 IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest);
192 break;
195 /* check doorbell range */
196 if (vector < s->peers[dest].nb_eventfds) {
197 IVSHMEM_DPRINTF("Notifying VM %d on vector %d\n", dest, vector);
198 event_notifier_set(&s->peers[dest].eventfds[vector]);
200 break;
201 default:
202 IVSHMEM_DPRINTF("Invalid VM Doorbell VM %d\n", dest);
206 static uint64_t ivshmem_io_read(void *opaque, hwaddr addr,
207 unsigned size)
210 IVShmemState *s = opaque;
211 uint32_t ret;
213 switch (addr)
215 case INTRMASK:
216 ret = ivshmem_IntrMask_read(s);
217 break;
219 case INTRSTATUS:
220 ret = ivshmem_IntrStatus_read(s);
221 break;
223 case IVPOSITION:
224 /* return my VM ID if the memory is mapped */
225 if (s->shm_fd > 0) {
226 ret = s->vm_id;
227 } else {
228 ret = -1;
230 break;
232 default:
233 IVSHMEM_DPRINTF("why are we reading " TARGET_FMT_plx "\n", addr);
234 ret = 0;
237 return ret;
240 static const MemoryRegionOps ivshmem_mmio_ops = {
241 .read = ivshmem_io_read,
242 .write = ivshmem_io_write,
243 .endianness = DEVICE_NATIVE_ENDIAN,
244 .impl = {
245 .min_access_size = 4,
246 .max_access_size = 4,
250 static void ivshmem_receive(void *opaque, const uint8_t *buf, int size)
252 IVShmemState *s = opaque;
254 ivshmem_IntrStatus_write(s, *buf);
256 IVSHMEM_DPRINTF("ivshmem_receive 0x%02x\n", *buf);
259 static int ivshmem_can_receive(void * opaque)
261 return 8;
264 static void ivshmem_event(void *opaque, int event)
266 IVSHMEM_DPRINTF("ivshmem_event %d\n", event);
269 static void fake_irqfd(void *opaque, const uint8_t *buf, int size) {
271 EventfdEntry *entry = opaque;
272 PCIDevice *pdev = entry->pdev;
274 IVSHMEM_DPRINTF("interrupt on vector %p %d\n", pdev, entry->vector);
275 msix_notify(pdev, entry->vector);
278 static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *n,
279 int vector)
281 /* create a event character device based on the passed eventfd */
282 IVShmemState *s = opaque;
283 CharDriverState * chr;
284 int eventfd = event_notifier_get_fd(n);
286 chr = qemu_chr_open_eventfd(eventfd);
288 if (chr == NULL) {
289 fprintf(stderr, "creating eventfd for eventfd %d failed\n", eventfd);
290 exit(-1);
293 /* if MSI is supported we need multiple interrupts */
294 if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
295 s->eventfd_table[vector].pdev = &s->dev;
296 s->eventfd_table[vector].vector = vector;
298 qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
299 ivshmem_event, &s->eventfd_table[vector]);
300 } else {
301 qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
302 ivshmem_event, s);
305 return chr;
309 static int check_shm_size(IVShmemState *s, int fd) {
310 /* check that the guest isn't going to try and map more memory than the
311 * the object has allocated return -1 to indicate error */
313 struct stat buf;
315 fstat(fd, &buf);
317 if (s->ivshmem_size > buf.st_size) {
318 fprintf(stderr,
319 "IVSHMEM ERROR: Requested memory size greater"
320 " than shared object size (%" PRIu64 " > %" PRIu64")\n",
321 s->ivshmem_size, (uint64_t)buf.st_size);
322 return -1;
323 } else {
324 return 0;
328 /* create the shared memory BAR when we are not using the server, so we can
329 * create the BAR and map the memory immediately */
330 static void create_shared_memory_BAR(IVShmemState *s, int fd) {
332 void * ptr;
334 s->shm_fd = fd;
336 ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
338 memory_region_init_ram_ptr(&s->ivshmem, "ivshmem.bar2",
339 s->ivshmem_size, ptr);
340 vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
341 memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
343 /* region for shared memory */
344 pci_register_bar(&s->dev, 2, s->ivshmem_attr, &s->bar);
347 static void ivshmem_add_eventfd(IVShmemState *s, int posn, int i)
349 memory_region_add_eventfd(&s->ivshmem_mmio,
350 DOORBELL,
352 true,
353 (posn << 16) | i,
354 &s->peers[posn].eventfds[i]);
357 static void ivshmem_del_eventfd(IVShmemState *s, int posn, int i)
359 memory_region_del_eventfd(&s->ivshmem_mmio,
360 DOORBELL,
362 true,
363 (posn << 16) | i,
364 &s->peers[posn].eventfds[i]);
367 static void close_guest_eventfds(IVShmemState *s, int posn)
369 int i, guest_curr_max;
371 if (!ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
372 return;
375 guest_curr_max = s->peers[posn].nb_eventfds;
377 memory_region_transaction_begin();
378 for (i = 0; i < guest_curr_max; i++) {
379 ivshmem_del_eventfd(s, posn, i);
381 memory_region_transaction_commit();
382 for (i = 0; i < guest_curr_max; i++) {
383 event_notifier_cleanup(&s->peers[posn].eventfds[i]);
386 g_free(s->peers[posn].eventfds);
387 s->peers[posn].nb_eventfds = 0;
390 /* this function increase the dynamic storage need to store data about other
391 * guests */
392 static void increase_dynamic_storage(IVShmemState *s, int new_min_size) {
394 int j, old_nb_alloc;
396 old_nb_alloc = s->nb_peers;
398 while (new_min_size >= s->nb_peers)
399 s->nb_peers = s->nb_peers * 2;
401 IVSHMEM_DPRINTF("bumping storage to %d guests\n", s->nb_peers);
402 s->peers = g_realloc(s->peers, s->nb_peers * sizeof(Peer));
404 /* zero out new pointers */
405 for (j = old_nb_alloc; j < s->nb_peers; j++) {
406 s->peers[j].eventfds = NULL;
407 s->peers[j].nb_eventfds = 0;
411 static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)
413 IVShmemState *s = opaque;
414 int incoming_fd, tmp_fd;
415 int guest_max_eventfd;
416 long incoming_posn;
418 memcpy(&incoming_posn, buf, sizeof(long));
419 /* pick off s->server_chr->msgfd and store it, posn should accompany msg */
420 tmp_fd = qemu_chr_fe_get_msgfd(s->server_chr);
421 IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, tmp_fd);
423 /* make sure we have enough space for this guest */
424 if (incoming_posn >= s->nb_peers) {
425 increase_dynamic_storage(s, incoming_posn);
428 if (tmp_fd == -1) {
429 /* if posn is positive and unseen before then this is our posn*/
430 if ((incoming_posn >= 0) &&
431 (s->peers[incoming_posn].eventfds == NULL)) {
432 /* receive our posn */
433 s->vm_id = incoming_posn;
434 return;
435 } else {
436 /* otherwise an fd == -1 means an existing guest has gone away */
437 IVSHMEM_DPRINTF("posn %ld has gone away\n", incoming_posn);
438 close_guest_eventfds(s, incoming_posn);
439 return;
443 /* because of the implementation of get_msgfd, we need a dup */
444 incoming_fd = dup(tmp_fd);
446 if (incoming_fd == -1) {
447 fprintf(stderr, "could not allocate file descriptor %s\n",
448 strerror(errno));
449 return;
452 /* if the position is -1, then it's shared memory region fd */
453 if (incoming_posn == -1) {
455 void * map_ptr;
457 s->max_peer = 0;
459 if (check_shm_size(s, incoming_fd) == -1) {
460 exit(-1);
463 /* mmap the region and map into the BAR2 */
464 map_ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED,
465 incoming_fd, 0);
466 memory_region_init_ram_ptr(&s->ivshmem,
467 "ivshmem.bar2", s->ivshmem_size, map_ptr);
468 vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
470 IVSHMEM_DPRINTF("guest h/w addr = %" PRIu64 ", size = %" PRIu64 "\n",
471 s->ivshmem_offset, s->ivshmem_size);
473 memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
475 /* only store the fd if it is successfully mapped */
476 s->shm_fd = incoming_fd;
478 return;
481 /* each guest has an array of eventfds, and we keep track of how many
482 * guests for each VM */
483 guest_max_eventfd = s->peers[incoming_posn].nb_eventfds;
485 if (guest_max_eventfd == 0) {
486 /* one eventfd per MSI vector */
487 s->peers[incoming_posn].eventfds = g_new(EventNotifier, s->vectors);
490 /* this is an eventfd for a particular guest VM */
491 IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
492 guest_max_eventfd, incoming_fd);
493 event_notifier_init_fd(&s->peers[incoming_posn].eventfds[guest_max_eventfd],
494 incoming_fd);
496 /* increment count for particular guest */
497 s->peers[incoming_posn].nb_eventfds++;
499 /* keep track of the maximum VM ID */
500 if (incoming_posn > s->max_peer) {
501 s->max_peer = incoming_posn;
504 if (incoming_posn == s->vm_id) {
505 s->eventfd_chr[guest_max_eventfd] = create_eventfd_chr_device(s,
506 &s->peers[s->vm_id].eventfds[guest_max_eventfd],
507 guest_max_eventfd);
510 if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
511 ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd);
515 /* Select the MSI-X vectors used by device.
516 * ivshmem maps events to vectors statically, so
517 * we just enable all vectors on init and after reset. */
518 static void ivshmem_use_msix(IVShmemState * s)
520 int i;
522 if (!msix_present(&s->dev)) {
523 return;
526 for (i = 0; i < s->vectors; i++) {
527 msix_vector_use(&s->dev, i);
531 static void ivshmem_reset(DeviceState *d)
533 IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d);
535 s->intrstatus = 0;
536 ivshmem_use_msix(s);
539 static uint64_t ivshmem_get_size(IVShmemState * s) {
541 uint64_t value;
542 char *ptr;
544 value = strtoull(s->sizearg, &ptr, 10);
545 switch (*ptr) {
546 case 0: case 'M': case 'm':
547 value <<= 20;
548 break;
549 case 'G': case 'g':
550 value <<= 30;
551 break;
552 default:
553 fprintf(stderr, "qemu: invalid ram size: %s\n", s->sizearg);
554 exit(1);
557 /* BARs must be a power of 2 */
558 if (!is_power_of_two(value)) {
559 fprintf(stderr, "ivshmem: size must be power of 2\n");
560 exit(1);
563 return value;
566 static void ivshmem_setup_msi(IVShmemState * s)
568 if (msix_init_exclusive_bar(&s->dev, s->vectors, 1)) {
569 IVSHMEM_DPRINTF("msix initialization failed\n");
570 exit(1);
573 IVSHMEM_DPRINTF("msix initialized (%d vectors)\n", s->vectors);
575 /* allocate QEMU char devices for receiving interrupts */
576 s->eventfd_table = g_malloc0(s->vectors * sizeof(EventfdEntry));
578 ivshmem_use_msix(s);
581 static void ivshmem_save(QEMUFile* f, void *opaque)
583 IVShmemState *proxy = opaque;
585 IVSHMEM_DPRINTF("ivshmem_save\n");
586 pci_device_save(&proxy->dev, f);
588 if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
589 msix_save(&proxy->dev, f);
590 } else {
591 qemu_put_be32(f, proxy->intrstatus);
592 qemu_put_be32(f, proxy->intrmask);
597 static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
599 IVSHMEM_DPRINTF("ivshmem_load\n");
601 IVShmemState *proxy = opaque;
602 int ret;
604 if (version_id > 0) {
605 return -EINVAL;
608 if (proxy->role_val == IVSHMEM_PEER) {
609 fprintf(stderr, "ivshmem: 'peer' devices are not migratable\n");
610 return -EINVAL;
613 ret = pci_device_load(&proxy->dev, f);
614 if (ret) {
615 return ret;
618 if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
619 msix_load(&proxy->dev, f);
620 ivshmem_use_msix(proxy);
621 } else {
622 proxy->intrstatus = qemu_get_be32(f);
623 proxy->intrmask = qemu_get_be32(f);
626 return 0;
629 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
630 uint32_t val, int len)
632 pci_default_write_config(pci_dev, address, val, len);
633 msix_write_config(pci_dev, address, val, len);
636 static int pci_ivshmem_init(PCIDevice *dev)
638 IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
639 uint8_t *pci_conf;
641 if (s->sizearg == NULL)
642 s->ivshmem_size = 4 << 20; /* 4 MB default */
643 else {
644 s->ivshmem_size = ivshmem_get_size(s);
647 register_savevm(&s->dev.qdev, "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
648 dev);
650 /* IRQFD requires MSI */
651 if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
652 !ivshmem_has_feature(s, IVSHMEM_MSI)) {
653 fprintf(stderr, "ivshmem: ioeventfd/irqfd requires MSI\n");
654 exit(1);
657 /* check that role is reasonable */
658 if (s->role) {
659 if (strncmp(s->role, "peer", 5) == 0) {
660 s->role_val = IVSHMEM_PEER;
661 } else if (strncmp(s->role, "master", 7) == 0) {
662 s->role_val = IVSHMEM_MASTER;
663 } else {
664 fprintf(stderr, "ivshmem: 'role' must be 'peer' or 'master'\n");
665 exit(1);
667 } else {
668 s->role_val = IVSHMEM_MASTER; /* default */
671 if (s->role_val == IVSHMEM_PEER) {
672 error_set(&s->migration_blocker, QERR_DEVICE_FEATURE_BLOCKS_MIGRATION,
673 "peer mode", "ivshmem");
674 migrate_add_blocker(s->migration_blocker);
677 pci_conf = s->dev.config;
678 pci_conf[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
680 pci_config_set_interrupt_pin(pci_conf, 1);
682 s->shm_fd = 0;
684 memory_region_init_io(&s->ivshmem_mmio, &ivshmem_mmio_ops, s,
685 "ivshmem-mmio", IVSHMEM_REG_BAR_SIZE);
687 /* region for registers*/
688 pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY,
689 &s->ivshmem_mmio);
691 memory_region_init(&s->bar, "ivshmem-bar2-container", s->ivshmem_size);
692 s->ivshmem_attr = PCI_BASE_ADDRESS_SPACE_MEMORY |
693 PCI_BASE_ADDRESS_MEM_PREFETCH;
694 if (s->ivshmem_64bit) {
695 s->ivshmem_attr |= PCI_BASE_ADDRESS_MEM_TYPE_64;
698 if ((s->server_chr != NULL) &&
699 (strncmp(s->server_chr->filename, "unix:", 5) == 0)) {
700 /* if we get a UNIX socket as the parameter we will talk
701 * to the ivshmem server to receive the memory region */
703 if (s->shmobj != NULL) {
704 fprintf(stderr, "WARNING: do not specify both 'chardev' "
705 "and 'shm' with ivshmem\n");
708 IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
709 s->server_chr->filename);
711 if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
712 ivshmem_setup_msi(s);
715 /* we allocate enough space for 16 guests and grow as needed */
716 s->nb_peers = 16;
717 s->vm_id = -1;
719 /* allocate/initialize space for interrupt handling */
720 s->peers = g_malloc0(s->nb_peers * sizeof(Peer));
722 pci_register_bar(&s->dev, 2, s->ivshmem_attr, &s->bar);
724 s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
726 qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
727 ivshmem_event, s);
728 } else {
729 /* just map the file immediately, we're not using a server */
730 int fd;
732 if (s->shmobj == NULL) {
733 fprintf(stderr, "Must specify 'chardev' or 'shm' to ivshmem\n");
736 IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
738 /* try opening with O_EXCL and if it succeeds zero the memory
739 * by truncating to 0 */
740 if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
741 S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
742 /* truncate file to length PCI device's memory */
743 if (ftruncate(fd, s->ivshmem_size) != 0) {
744 fprintf(stderr, "ivshmem: could not truncate shared file\n");
747 } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
748 S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
749 fprintf(stderr, "ivshmem: could not open shared file\n");
750 exit(-1);
754 if (check_shm_size(s, fd) == -1) {
755 exit(-1);
758 create_shared_memory_BAR(s, fd);
762 s->dev.config_write = ivshmem_write_config;
764 return 0;
767 static void pci_ivshmem_uninit(PCIDevice *dev)
769 IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
771 if (s->migration_blocker) {
772 migrate_del_blocker(s->migration_blocker);
773 error_free(s->migration_blocker);
776 memory_region_destroy(&s->ivshmem_mmio);
777 memory_region_del_subregion(&s->bar, &s->ivshmem);
778 vmstate_unregister_ram(&s->ivshmem, &s->dev.qdev);
779 memory_region_destroy(&s->ivshmem);
780 memory_region_destroy(&s->bar);
781 unregister_savevm(&dev->qdev, "ivshmem", s);
784 static Property ivshmem_properties[] = {
785 DEFINE_PROP_CHR("chardev", IVShmemState, server_chr),
786 DEFINE_PROP_STRING("size", IVShmemState, sizearg),
787 DEFINE_PROP_UINT32("vectors", IVShmemState, vectors, 1),
788 DEFINE_PROP_BIT("ioeventfd", IVShmemState, features, IVSHMEM_IOEVENTFD, false),
789 DEFINE_PROP_BIT("msi", IVShmemState, features, IVSHMEM_MSI, true),
790 DEFINE_PROP_STRING("shm", IVShmemState, shmobj),
791 DEFINE_PROP_STRING("role", IVShmemState, role),
792 DEFINE_PROP_UINT32("use64", IVShmemState, ivshmem_64bit, 1),
793 DEFINE_PROP_END_OF_LIST(),
796 static void ivshmem_class_init(ObjectClass *klass, void *data)
798 DeviceClass *dc = DEVICE_CLASS(klass);
799 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
801 k->init = pci_ivshmem_init;
802 k->exit = pci_ivshmem_uninit;
803 k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
804 k->device_id = 0x1110;
805 k->class_id = PCI_CLASS_MEMORY_RAM;
806 dc->reset = ivshmem_reset;
807 dc->props = ivshmem_properties;
810 static TypeInfo ivshmem_info = {
811 .name = "ivshmem",
812 .parent = TYPE_PCI_DEVICE,
813 .instance_size = sizeof(IVShmemState),
814 .class_init = ivshmem_class_init,
817 static void ivshmem_register_types(void)
819 type_register_static(&ivshmem_info);
822 type_init(ivshmem_register_types)