blob: 7138b8d92350d1e8419052f8e47b5b90b9e77108 [file] [log] [blame]
Cam Macdonell6cbf4c82010-07-27 10:54:13 -06001/*
2 * Inter-VM Shared Memory PCI device.
3 *
4 * Author:
5 * Cam Macdonell <cam@cs.ualberta.ca>
6 *
7 * Based On: cirrus_vga.c
8 * Copyright (c) 2004 Fabrice Bellard
9 * Copyright (c) 2004 Makoto Suzuki (suzu)
10 *
11 * and rtl8139.c
12 * Copyright (c) 2006 Igor Kovalenko
13 *
14 * This code is licensed under the GNU GPL v2.
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010015 *
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.
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060018 */
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010019#include "hw/hw.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010020#include "hw/i386/pc.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010021#include "hw/pci/pci.h"
22#include "hw/pci/msix.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010023#include "sysemu/kvm.h"
Paolo Bonzinicaf71f82012-12-17 18:19:50 +010024#include "migration/migration.h"
Markus Armbrusterd49b6832015-03-17 18:29:20 +010025#include "qemu/error-report.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010026#include "qemu/event_notifier.h"
Stefan Hajnoczia2e90112014-09-15 18:40:05 +020027#include "qemu/fifo8.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +020028#include "sysemu/char.h"
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060029
30#include <sys/mman.h>
31#include <sys/types.h>
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +020032#include <limits.h>
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060033
Paolo Bonzinib8ef62a2012-12-13 10:19:37 +010034#define PCI_VENDOR_ID_IVSHMEM PCI_VENDOR_ID_REDHAT_QUMRANET
35#define PCI_DEVICE_ID_IVSHMEM 0x1110
36
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060037#define IVSHMEM_IOEVENTFD 0
38#define IVSHMEM_MSI 1
39
40#define IVSHMEM_PEER 0
41#define IVSHMEM_MASTER 1
42
43#define IVSHMEM_REG_BAR_SIZE 0x100
44
45//#define DEBUG_IVSHMEM
46#ifdef DEBUG_IVSHMEM
47#define IVSHMEM_DPRINTF(fmt, ...) \
48 do {printf("IVSHMEM: " fmt, ## __VA_ARGS__); } while (0)
49#else
50#define IVSHMEM_DPRINTF(fmt, ...)
51#endif
52
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +100053#define TYPE_IVSHMEM "ivshmem"
54#define IVSHMEM(obj) \
55 OBJECT_CHECK(IVShmemState, (obj), TYPE_IVSHMEM)
56
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060057typedef struct Peer {
58 int nb_eventfds;
Paolo Bonzini563027c2012-07-05 17:16:25 +020059 EventNotifier *eventfds;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060060} Peer;
61
62typedef struct EventfdEntry {
63 PCIDevice *pdev;
64 int vector;
65} EventfdEntry;
66
67typedef struct IVShmemState {
Andreas Färberb7578ea2013-06-30 15:15:15 +020068 /*< private >*/
69 PCIDevice parent_obj;
70 /*< public >*/
71
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060072 uint32_t intrmask;
73 uint32_t intrstatus;
74 uint32_t doorbell;
75
76 CharDriverState **eventfd_chr;
77 CharDriverState *server_chr;
Stefan Hajnoczia2e90112014-09-15 18:40:05 +020078 Fifo8 incoming_fifo;
Avi Kivitycb066082011-08-08 16:09:12 +030079 MemoryRegion ivshmem_mmio;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060080
Avi Kivitycb066082011-08-08 16:09:12 +030081 /* We might need to register the BAR before we actually have the memory.
82 * So prepare a container MemoryRegion for the BAR immediately and
83 * add a subregion when we have the memory.
84 */
85 MemoryRegion bar;
86 MemoryRegion ivshmem;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060087 uint64_t ivshmem_size; /* size of shared memory region */
Gerd Hoffmannc08ba662012-09-13 11:08:02 +020088 uint32_t ivshmem_64bit;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -060089 int shm_fd; /* shared memory file descriptor */
90
91 Peer *peers;
92 int nb_peers; /* how many guests we have space for */
93 int max_peer; /* maximum numbered peer */
94
95 int vm_id;
96 uint32_t vectors;
97 uint32_t features;
98 EventfdEntry *eventfd_table;
99
Anthony Liguori38e07352011-11-14 15:09:44 -0600100 Error *migration_blocker;
101
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600102 char * shmobj;
103 char * sizearg;
104 char * role;
105 int role_val; /* scalar to avoid multiple string comparisons */
106} IVShmemState;
107
108/* registers for the Inter-VM shared memory device */
109enum ivshmem_registers {
110 INTRMASK = 0,
111 INTRSTATUS = 4,
112 IVPOSITION = 8,
113 DOORBELL = 12,
114};
115
116static inline uint32_t ivshmem_has_feature(IVShmemState *ivs,
117 unsigned int feature) {
118 return (ivs->features & (1 << feature));
119}
120
121static inline bool is_power_of_two(uint64_t x) {
122 return (x & (x - 1)) == 0;
123}
124
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600125/* accessing registers - based on rtl8139 */
126static void ivshmem_update_irq(IVShmemState *s, int val)
127{
Andreas Färberb7578ea2013-06-30 15:15:15 +0200128 PCIDevice *d = PCI_DEVICE(s);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600129 int isr;
130 isr = (s->intrstatus & s->intrmask) & 0xffffffff;
131
132 /* don't print ISR resets */
133 if (isr) {
134 IVSHMEM_DPRINTF("Set IRQ to %d (%04x %04x)\n",
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200135 isr ? 1 : 0, s->intrstatus, s->intrmask);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600136 }
137
Marcel Apfelbaum9e64f8a2013-10-07 10:36:39 +0300138 pci_set_irq(d, (isr != 0));
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600139}
140
141static void ivshmem_IntrMask_write(IVShmemState *s, uint32_t val)
142{
143 IVSHMEM_DPRINTF("IntrMask write(w) val = 0x%04x\n", val);
144
145 s->intrmask = val;
146
147 ivshmem_update_irq(s, val);
148}
149
150static uint32_t ivshmem_IntrMask_read(IVShmemState *s)
151{
152 uint32_t ret = s->intrmask;
153
154 IVSHMEM_DPRINTF("intrmask read(w) val = 0x%04x\n", ret);
155
156 return ret;
157}
158
159static void ivshmem_IntrStatus_write(IVShmemState *s, uint32_t val)
160{
161 IVSHMEM_DPRINTF("IntrStatus write(w) val = 0x%04x\n", val);
162
163 s->intrstatus = val;
164
165 ivshmem_update_irq(s, val);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600166}
167
168static uint32_t ivshmem_IntrStatus_read(IVShmemState *s)
169{
170 uint32_t ret = s->intrstatus;
171
172 /* reading ISR clears all interrupts */
173 s->intrstatus = 0;
174
175 ivshmem_update_irq(s, 0);
176
177 return ret;
178}
179
Avi Kivitya8170e52012-10-23 12:30:10 +0200180static void ivshmem_io_write(void *opaque, hwaddr addr,
Avi Kivitycb066082011-08-08 16:09:12 +0300181 uint64_t val, unsigned size)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600182{
183 IVShmemState *s = opaque;
184
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600185 uint16_t dest = val >> 16;
186 uint16_t vector = val & 0xff;
187
188 addr &= 0xfc;
189
190 IVSHMEM_DPRINTF("writing to addr " TARGET_FMT_plx "\n", addr);
191 switch (addr)
192 {
193 case INTRMASK:
194 ivshmem_IntrMask_write(s, val);
195 break;
196
197 case INTRSTATUS:
198 ivshmem_IntrStatus_write(s, val);
199 break;
200
201 case DOORBELL:
202 /* check that dest VM ID is reasonable */
Jes Sorensen1b27d7a2010-08-30 12:31:33 +0200203 if (dest > s->max_peer) {
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600204 IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest);
205 break;
206 }
207
208 /* check doorbell range */
Jes Sorensen1b27d7a2010-08-30 12:31:33 +0200209 if (vector < s->peers[dest].nb_eventfds) {
Paolo Bonzini563027c2012-07-05 17:16:25 +0200210 IVSHMEM_DPRINTF("Notifying VM %d on vector %d\n", dest, vector);
211 event_notifier_set(&s->peers[dest].eventfds[vector]);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600212 }
213 break;
214 default:
215 IVSHMEM_DPRINTF("Invalid VM Doorbell VM %d\n", dest);
216 }
217}
218
Avi Kivitya8170e52012-10-23 12:30:10 +0200219static uint64_t ivshmem_io_read(void *opaque, hwaddr addr,
Avi Kivitycb066082011-08-08 16:09:12 +0300220 unsigned size)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600221{
222
223 IVShmemState *s = opaque;
224 uint32_t ret;
225
226 switch (addr)
227 {
228 case INTRMASK:
229 ret = ivshmem_IntrMask_read(s);
230 break;
231
232 case INTRSTATUS:
233 ret = ivshmem_IntrStatus_read(s);
234 break;
235
236 case IVPOSITION:
237 /* return my VM ID if the memory is mapped */
238 if (s->shm_fd > 0) {
239 ret = s->vm_id;
240 } else {
241 ret = -1;
242 }
243 break;
244
245 default:
246 IVSHMEM_DPRINTF("why are we reading " TARGET_FMT_plx "\n", addr);
247 ret = 0;
248 }
249
250 return ret;
251}
252
Avi Kivitycb066082011-08-08 16:09:12 +0300253static const MemoryRegionOps ivshmem_mmio_ops = {
254 .read = ivshmem_io_read,
255 .write = ivshmem_io_write,
256 .endianness = DEVICE_NATIVE_ENDIAN,
257 .impl = {
258 .min_access_size = 4,
259 .max_access_size = 4,
260 },
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600261};
262
263static void ivshmem_receive(void *opaque, const uint8_t *buf, int size)
264{
265 IVShmemState *s = opaque;
266
267 ivshmem_IntrStatus_write(s, *buf);
268
269 IVSHMEM_DPRINTF("ivshmem_receive 0x%02x\n", *buf);
270}
271
272static int ivshmem_can_receive(void * opaque)
273{
Marc-André Lureaub8ab8542015-06-19 13:00:32 +0200274 return sizeof(long);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600275}
276
277static void ivshmem_event(void *opaque, int event)
278{
279 IVSHMEM_DPRINTF("ivshmem_event %d\n", event);
280}
281
282static void fake_irqfd(void *opaque, const uint8_t *buf, int size) {
283
284 EventfdEntry *entry = opaque;
285 PCIDevice *pdev = entry->pdev;
286
287 IVSHMEM_DPRINTF("interrupt on vector %p %d\n", pdev, entry->vector);
288 msix_notify(pdev, entry->vector);
289}
290
Paolo Bonzini563027c2012-07-05 17:16:25 +0200291static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *n,
292 int vector)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600293{
294 /* create a event character device based on the passed eventfd */
295 IVShmemState *s = opaque;
296 CharDriverState * chr;
Paolo Bonzini563027c2012-07-05 17:16:25 +0200297 int eventfd = event_notifier_get_fd(n);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600298
299 chr = qemu_chr_open_eventfd(eventfd);
300
301 if (chr == NULL) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200302 error_report("creating eventfd for eventfd %d failed", eventfd);
303 exit(1);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600304 }
Hans de Goede456d6062013-03-27 20:29:40 +0100305 qemu_chr_fe_claim_no_fail(chr);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600306
307 /* if MSI is supported we need multiple interrupts */
308 if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
Andreas Färberb7578ea2013-06-30 15:15:15 +0200309 s->eventfd_table[vector].pdev = PCI_DEVICE(s);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600310 s->eventfd_table[vector].vector = vector;
311
312 qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
313 ivshmem_event, &s->eventfd_table[vector]);
314 } else {
315 qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
316 ivshmem_event, s);
317 }
318
319 return chr;
320
321}
322
323static int check_shm_size(IVShmemState *s, int fd) {
324 /* check that the guest isn't going to try and map more memory than the
325 * the object has allocated return -1 to indicate error */
326
327 struct stat buf;
328
zhanghailiang5edbdbc2014-08-14 15:29:15 +0800329 if (fstat(fd, &buf) < 0) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200330 error_report("exiting: fstat on fd %d failed: %s",
331 fd, strerror(errno));
zhanghailiang5edbdbc2014-08-14 15:29:15 +0800332 return -1;
333 }
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600334
335 if (s->ivshmem_size > buf.st_size) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200336 error_report("Requested memory size greater"
337 " than shared object size (%" PRIu64 " > %" PRIu64")",
338 s->ivshmem_size, (uint64_t)buf.st_size);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600339 return -1;
340 } else {
341 return 0;
342 }
343}
344
345/* create the shared memory BAR when we are not using the server, so we can
346 * create the BAR and map the memory immediately */
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200347static void create_shared_memory_BAR(IVShmemState *s, int fd, uint8_t attr) {
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600348
349 void * ptr;
350
351 s->shm_fd = fd;
352
353 ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
354
Paolo Bonzini3c161542013-06-06 21:25:08 -0400355 memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2",
Avi Kivitycb066082011-08-08 16:09:12 +0300356 s->ivshmem_size, ptr);
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000357 vmstate_register_ram(&s->ivshmem, DEVICE(s));
Avi Kivitycb066082011-08-08 16:09:12 +0300358 memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600359
360 /* region for shared memory */
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200361 pci_register_bar(PCI_DEVICE(s), 2, attr, &s->bar);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600362}
363
Paolo Bonzini563027c2012-07-05 17:16:25 +0200364static void ivshmem_add_eventfd(IVShmemState *s, int posn, int i)
365{
366 memory_region_add_eventfd(&s->ivshmem_mmio,
367 DOORBELL,
368 4,
369 true,
370 (posn << 16) | i,
Paolo Bonzini753d5e12012-07-05 17:16:27 +0200371 &s->peers[posn].eventfds[i]);
Paolo Bonzini563027c2012-07-05 17:16:25 +0200372}
373
374static void ivshmem_del_eventfd(IVShmemState *s, int posn, int i)
375{
376 memory_region_del_eventfd(&s->ivshmem_mmio,
377 DOORBELL,
378 4,
379 true,
380 (posn << 16) | i,
Paolo Bonzini753d5e12012-07-05 17:16:27 +0200381 &s->peers[posn].eventfds[i]);
Paolo Bonzini563027c2012-07-05 17:16:25 +0200382}
383
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600384static void close_guest_eventfds(IVShmemState *s, int posn)
385{
386 int i, guest_curr_max;
387
Paolo Bonzini98609cd2012-08-22 23:09:47 +0200388 if (!ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
389 return;
390 }
Stefan Hajnoczi363ba1c2014-09-15 18:40:06 +0200391 if (posn < 0 || posn >= s->nb_peers) {
392 return;
393 }
Paolo Bonzini98609cd2012-08-22 23:09:47 +0200394
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600395 guest_curr_max = s->peers[posn].nb_eventfds;
396
Paolo Bonzinib6a1f3a2012-07-05 17:16:26 +0200397 memory_region_transaction_begin();
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600398 for (i = 0; i < guest_curr_max; i++) {
Paolo Bonzini563027c2012-07-05 17:16:25 +0200399 ivshmem_del_eventfd(s, posn, i);
Paolo Bonzinib6a1f3a2012-07-05 17:16:26 +0200400 }
401 memory_region_transaction_commit();
402 for (i = 0; i < guest_curr_max; i++) {
Paolo Bonzini563027c2012-07-05 17:16:25 +0200403 event_notifier_cleanup(&s->peers[posn].eventfds[i]);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600404 }
405
Anthony Liguori7267c092011-08-20 22:09:37 -0500406 g_free(s->peers[posn].eventfds);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600407 s->peers[posn].nb_eventfds = 0;
408}
409
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600410/* this function increase the dynamic storage need to store data about other
411 * guests */
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200412static int increase_dynamic_storage(IVShmemState *s, int new_min_size)
413{
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600414
415 int j, old_nb_alloc;
416
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200417 /* check for integer overflow */
418 if (new_min_size >= INT_MAX / sizeof(Peer) - 1 || new_min_size <= 0) {
419 return -1;
420 }
421
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600422 old_nb_alloc = s->nb_peers;
423
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200424 if (new_min_size >= s->nb_peers) {
425 /* +1 because #new_min_size is used as last array index */
426 s->nb_peers = new_min_size + 1;
427 } else {
428 return 0;
429 }
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600430
431 IVSHMEM_DPRINTF("bumping storage to %d guests\n", s->nb_peers);
Anthony Liguori7267c092011-08-20 22:09:37 -0500432 s->peers = g_realloc(s->peers, s->nb_peers * sizeof(Peer));
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600433
434 /* zero out new pointers */
435 for (j = old_nb_alloc; j < s->nb_peers; j++) {
436 s->peers[j].eventfds = NULL;
437 s->peers[j].nb_eventfds = 0;
438 }
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200439
440 return 0;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600441}
442
Marc-André Lureau0f14fd72015-06-23 17:56:37 +0200443static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size,
444 void *data, size_t len)
445{
446 const uint8_t *p;
447 uint32_t num;
448
449 assert(len <= sizeof(long)); /* limitation of the fifo */
450 if (fifo8_is_empty(&s->incoming_fifo) && size == len) {
451 memcpy(data, buf, size);
452 return true;
453 }
454
455 IVSHMEM_DPRINTF("short read of %d bytes\n", size);
456
457 num = MIN(size, sizeof(long) - fifo8_num_used(&s->incoming_fifo));
458 fifo8_push_all(&s->incoming_fifo, buf, num);
459
460 if (fifo8_num_used(&s->incoming_fifo) < len) {
461 assert(num == 0);
462 return false;
463 }
464
465 size -= num;
466 buf += num;
467 p = fifo8_pop_buf(&s->incoming_fifo, len, &num);
468 assert(num == len);
469
470 memcpy(data, p, len);
471
472 if (size > 0) {
473 fifo8_push_all(&s->incoming_fifo, buf, size);
474 }
475
476 return true;
477}
478
Stefan Hajnoczia2e90112014-09-15 18:40:05 +0200479static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600480{
481 IVShmemState *s = opaque;
Marc-André Lureaudee21512015-06-22 12:38:34 +0200482 int incoming_fd;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600483 int guest_max_eventfd;
484 long incoming_posn;
485
Marc-André Lureau0f14fd72015-06-23 17:56:37 +0200486 if (!fifo_update_and_get(s, buf, size,
487 &incoming_posn, sizeof(incoming_posn))) {
488 return;
Stefan Hajnoczia2e90112014-09-15 18:40:05 +0200489 }
490
Stefan Hajnoczi363ba1c2014-09-15 18:40:06 +0200491 if (incoming_posn < -1) {
492 IVSHMEM_DPRINTF("invalid incoming_posn %ld\n", incoming_posn);
493 return;
494 }
495
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600496 /* pick off s->server_chr->msgfd and store it, posn should accompany msg */
Marc-André Lureaudee21512015-06-22 12:38:34 +0200497 incoming_fd = qemu_chr_fe_get_msgfd(s->server_chr);
498 IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, incoming_fd);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600499
500 /* make sure we have enough space for this guest */
501 if (incoming_posn >= s->nb_peers) {
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200502 if (increase_dynamic_storage(s, incoming_posn) < 0) {
503 error_report("increase_dynamic_storage() failed");
Marc-André Lureaudee21512015-06-22 12:38:34 +0200504 if (incoming_fd != -1) {
505 close(incoming_fd);
Sebastian Krahmer34bc07c2014-09-15 18:40:07 +0200506 }
507 return;
508 }
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600509 }
510
Marc-André Lureaudee21512015-06-22 12:38:34 +0200511 if (incoming_fd == -1) {
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600512 /* if posn is positive and unseen before then this is our posn*/
513 if ((incoming_posn >= 0) &&
514 (s->peers[incoming_posn].eventfds == NULL)) {
515 /* receive our posn */
516 s->vm_id = incoming_posn;
517 return;
518 } else {
519 /* otherwise an fd == -1 means an existing guest has gone away */
520 IVSHMEM_DPRINTF("posn %ld has gone away\n", incoming_posn);
521 close_guest_eventfds(s, incoming_posn);
522 return;
523 }
524 }
525
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600526 /* if the position is -1, then it's shared memory region fd */
527 if (incoming_posn == -1) {
528
529 void * map_ptr;
530
531 s->max_peer = 0;
532
533 if (check_shm_size(s, incoming_fd) == -1) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200534 exit(1);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600535 }
536
537 /* mmap the region and map into the BAR2 */
538 map_ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED,
539 incoming_fd, 0);
Paolo Bonzini3c161542013-06-06 21:25:08 -0400540 memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
Avi Kivitycb066082011-08-08 16:09:12 +0300541 "ivshmem.bar2", s->ivshmem_size, map_ptr);
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000542 vmstate_register_ram(&s->ivshmem, DEVICE(s));
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600543
Levente Kurusa7f9efb62014-08-04 17:06:20 +0200544 IVSHMEM_DPRINTF("guest h/w addr = %p, size = %" PRIu64 "\n",
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200545 map_ptr, s->ivshmem_size);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600546
Avi Kivitycb066082011-08-08 16:09:12 +0300547 memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600548
549 /* only store the fd if it is successfully mapped */
550 s->shm_fd = incoming_fd;
551
552 return;
553 }
554
555 /* each guest has an array of eventfds, and we keep track of how many
556 * guests for each VM */
557 guest_max_eventfd = s->peers[incoming_posn].nb_eventfds;
558
559 if (guest_max_eventfd == 0) {
560 /* one eventfd per MSI vector */
Paolo Bonzini563027c2012-07-05 17:16:25 +0200561 s->peers[incoming_posn].eventfds = g_new(EventNotifier, s->vectors);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600562 }
563
564 /* this is an eventfd for a particular guest VM */
565 IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200566 guest_max_eventfd, incoming_fd);
Paolo Bonzini563027c2012-07-05 17:16:25 +0200567 event_notifier_init_fd(&s->peers[incoming_posn].eventfds[guest_max_eventfd],
568 incoming_fd);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600569
570 /* increment count for particular guest */
571 s->peers[incoming_posn].nb_eventfds++;
572
573 /* keep track of the maximum VM ID */
574 if (incoming_posn > s->max_peer) {
575 s->max_peer = incoming_posn;
576 }
577
578 if (incoming_posn == s->vm_id) {
579 s->eventfd_chr[guest_max_eventfd] = create_eventfd_chr_device(s,
Paolo Bonzini563027c2012-07-05 17:16:25 +0200580 &s->peers[s->vm_id].eventfds[guest_max_eventfd],
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600581 guest_max_eventfd);
582 }
583
584 if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
Paolo Bonzini563027c2012-07-05 17:16:25 +0200585 ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600586 }
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600587}
588
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200589/* Select the MSI-X vectors used by device.
590 * ivshmem maps events to vectors statically, so
591 * we just enable all vectors on init and after reset. */
592static void ivshmem_use_msix(IVShmemState * s)
593{
Andreas Färberb7578ea2013-06-30 15:15:15 +0200594 PCIDevice *d = PCI_DEVICE(s);
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200595 int i;
596
Andreas Färberb7578ea2013-06-30 15:15:15 +0200597 if (!msix_present(d)) {
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200598 return;
599 }
600
601 for (i = 0; i < s->vectors; i++) {
Andreas Färberb7578ea2013-06-30 15:15:15 +0200602 msix_vector_use(d, i);
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200603 }
604}
605
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600606static void ivshmem_reset(DeviceState *d)
607{
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000608 IVShmemState *s = IVSHMEM(d);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600609
610 s->intrstatus = 0;
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200611 ivshmem_use_msix(s);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600612}
613
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600614static uint64_t ivshmem_get_size(IVShmemState * s) {
615
616 uint64_t value;
617 char *ptr;
618
619 value = strtoull(s->sizearg, &ptr, 10);
620 switch (*ptr) {
621 case 0: case 'M': case 'm':
622 value <<= 20;
623 break;
624 case 'G': case 'g':
625 value <<= 30;
626 break;
627 default:
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200628 error_report("invalid ram size: %s", s->sizearg);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600629 exit(1);
630 }
631
632 /* BARs must be a power of 2 */
633 if (!is_power_of_two(value)) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200634 error_report("size must be power of 2");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600635 exit(1);
636 }
637
638 return value;
639}
640
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200641static void ivshmem_setup_msi(IVShmemState * s)
642{
Andreas Färberb7578ea2013-06-30 15:15:15 +0200643 if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1)) {
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600644 IVSHMEM_DPRINTF("msix initialization failed\n");
645 exit(1);
646 }
647
Alex Williamson1116b532012-06-14 12:16:01 -0600648 IVSHMEM_DPRINTF("msix initialized (%d vectors)\n", s->vectors);
649
Stefan Weil5cbdb3a2012-04-07 09:23:39 +0200650 /* allocate QEMU char devices for receiving interrupts */
Anthony Liguori7267c092011-08-20 22:09:37 -0500651 s->eventfd_table = g_malloc0(s->vectors * sizeof(EventfdEntry));
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200652
653 ivshmem_use_msix(s);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600654}
655
656static void ivshmem_save(QEMUFile* f, void *opaque)
657{
658 IVShmemState *proxy = opaque;
Andreas Färberb7578ea2013-06-30 15:15:15 +0200659 PCIDevice *pci_dev = PCI_DEVICE(proxy);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600660
661 IVSHMEM_DPRINTF("ivshmem_save\n");
Andreas Färberb7578ea2013-06-30 15:15:15 +0200662 pci_device_save(pci_dev, f);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600663
664 if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
Andreas Färberb7578ea2013-06-30 15:15:15 +0200665 msix_save(pci_dev, f);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600666 } else {
667 qemu_put_be32(f, proxy->intrstatus);
668 qemu_put_be32(f, proxy->intrmask);
669 }
670
671}
672
673static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
674{
675 IVSHMEM_DPRINTF("ivshmem_load\n");
676
677 IVShmemState *proxy = opaque;
Andreas Färberb7578ea2013-06-30 15:15:15 +0200678 PCIDevice *pci_dev = PCI_DEVICE(proxy);
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200679 int ret;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600680
681 if (version_id > 0) {
682 return -EINVAL;
683 }
684
685 if (proxy->role_val == IVSHMEM_PEER) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200686 error_report("'peer' devices are not migratable");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600687 return -EINVAL;
688 }
689
Andreas Färberb7578ea2013-06-30 15:15:15 +0200690 ret = pci_device_load(pci_dev, f);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600691 if (ret) {
692 return ret;
693 }
694
695 if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) {
Andreas Färberb7578ea2013-06-30 15:15:15 +0200696 msix_load(pci_dev, f);
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200697 ivshmem_use_msix(proxy);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600698 } else {
699 proxy->intrstatus = qemu_get_be32(f);
700 proxy->intrmask = qemu_get_be32(f);
701 }
702
703 return 0;
704}
705
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200706static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
707 uint32_t val, int len)
708{
709 pci_default_write_config(pci_dev, address, val, len);
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200710}
711
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600712static int pci_ivshmem_init(PCIDevice *dev)
713{
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000714 IVShmemState *s = IVSHMEM(dev);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600715 uint8_t *pci_conf;
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200716 uint8_t attr = PCI_BASE_ADDRESS_SPACE_MEMORY |
717 PCI_BASE_ADDRESS_MEM_PREFETCH;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600718
719 if (s->sizearg == NULL)
720 s->ivshmem_size = 4 << 20; /* 4 MB default */
721 else {
722 s->ivshmem_size = ivshmem_get_size(s);
723 }
724
Stefan Hajnoczia2e90112014-09-15 18:40:05 +0200725 fifo8_create(&s->incoming_fifo, sizeof(long));
726
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000727 register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600728 dev);
729
730 /* IRQFD requires MSI */
731 if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
732 !ivshmem_has_feature(s, IVSHMEM_MSI)) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200733 error_report("ioeventfd/irqfd requires MSI");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600734 exit(1);
735 }
736
737 /* check that role is reasonable */
738 if (s->role) {
739 if (strncmp(s->role, "peer", 5) == 0) {
740 s->role_val = IVSHMEM_PEER;
741 } else if (strncmp(s->role, "master", 7) == 0) {
742 s->role_val = IVSHMEM_MASTER;
743 } else {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200744 error_report("'role' must be 'peer' or 'master'");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600745 exit(1);
746 }
747 } else {
748 s->role_val = IVSHMEM_MASTER; /* default */
749 }
750
751 if (s->role_val == IVSHMEM_PEER) {
Cole Robinsonf231b882014-03-21 19:42:26 -0400752 error_setg(&s->migration_blocker,
753 "Migration is disabled when using feature 'peer mode' in device 'ivshmem'");
Anthony Liguori38e07352011-11-14 15:09:44 -0600754 migrate_add_blocker(s->migration_blocker);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600755 }
756
Andreas Färberb7578ea2013-06-30 15:15:15 +0200757 pci_conf = dev->config;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600758 pci_conf[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600759
760 pci_config_set_interrupt_pin(pci_conf, 1);
761
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600762 s->shm_fd = 0;
763
Paolo Bonzini3c161542013-06-06 21:25:08 -0400764 memory_region_init_io(&s->ivshmem_mmio, OBJECT(s), &ivshmem_mmio_ops, s,
Avi Kivitycb066082011-08-08 16:09:12 +0300765 "ivshmem-mmio", IVSHMEM_REG_BAR_SIZE);
766
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600767 /* region for registers*/
Andreas Färberb7578ea2013-06-30 15:15:15 +0200768 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY,
Avi Kivitye824b2c2011-08-08 16:09:31 +0300769 &s->ivshmem_mmio);
Avi Kivitycb066082011-08-08 16:09:12 +0300770
Paolo Bonzini3c161542013-06-06 21:25:08 -0400771 memory_region_init(&s->bar, OBJECT(s), "ivshmem-bar2-container", s->ivshmem_size);
Gerd Hoffmannc08ba662012-09-13 11:08:02 +0200772 if (s->ivshmem_64bit) {
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200773 attr |= PCI_BASE_ADDRESS_MEM_TYPE_64;
Gerd Hoffmannc08ba662012-09-13 11:08:02 +0200774 }
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600775
776 if ((s->server_chr != NULL) &&
777 (strncmp(s->server_chr->filename, "unix:", 5) == 0)) {
778 /* if we get a UNIX socket as the parameter we will talk
779 * to the ivshmem server to receive the memory region */
780
781 if (s->shmobj != NULL) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200782 error_report("WARNING: do not specify both 'chardev' "
783 "and 'shm' with ivshmem");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600784 }
785
786 IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200787 s->server_chr->filename);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600788
789 if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
790 ivshmem_setup_msi(s);
791 }
792
793 /* we allocate enough space for 16 guests and grow as needed */
794 s->nb_peers = 16;
795 s->vm_id = -1;
796
797 /* allocate/initialize space for interrupt handling */
Anthony Liguori7267c092011-08-20 22:09:37 -0500798 s->peers = g_malloc0(s->nb_peers * sizeof(Peer));
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600799
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200800 pci_register_bar(dev, 2, attr, &s->bar);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600801
Anthony Liguori7267c092011-08-20 22:09:37 -0500802 s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600803
804 qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
805 ivshmem_event, s);
806 } else {
807 /* just map the file immediately, we're not using a server */
808 int fd;
809
810 if (s->shmobj == NULL) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200811 error_report("Must specify 'chardev' or 'shm' to ivshmem");
Stefan Hajnoczibaefb8b2013-06-03 10:58:31 +0200812 exit(1);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600813 }
814
815 IVSHMEM_DPRINTF("using shm_open (shm object = %s)\n", s->shmobj);
816
817 /* try opening with O_EXCL and if it succeeds zero the memory
818 * by truncating to 0 */
819 if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR|O_EXCL,
820 S_IRWXU|S_IRWXG|S_IRWXO)) > 0) {
821 /* truncate file to length PCI device's memory */
822 if (ftruncate(fd, s->ivshmem_size) != 0) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200823 error_report("could not truncate shared file");
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600824 }
825
826 } else if ((fd = shm_open(s->shmobj, O_CREAT|O_RDWR,
827 S_IRWXU|S_IRWXG|S_IRWXO)) < 0) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200828 error_report("could not open shared file");
829 exit(1);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600830
831 }
832
833 if (check_shm_size(s, fd) == -1) {
Andrew Jonesdbc464d2014-10-07 13:24:02 +0200834 exit(1);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600835 }
836
Marc-André Lureau9113e3f2015-06-18 16:24:33 +0200837 create_shared_memory_BAR(s, fd, attr);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600838 }
839
Andreas Färberb7578ea2013-06-30 15:15:15 +0200840 dev->config_write = ivshmem_write_config;
Michael S. Tsirkin4490c712011-12-05 21:48:43 +0200841
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600842 return 0;
843}
844
Alex Williamsonf90c2bc2012-07-03 22:39:27 -0600845static void pci_ivshmem_uninit(PCIDevice *dev)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600846{
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000847 IVShmemState *s = IVSHMEM(dev);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600848
Anthony Liguori38e07352011-11-14 15:09:44 -0600849 if (s->migration_blocker) {
850 migrate_del_blocker(s->migration_blocker);
851 error_free(s->migration_blocker);
852 }
853
Avi Kivitycb066082011-08-08 16:09:12 +0300854 memory_region_del_subregion(&s->bar, &s->ivshmem);
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000855 vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000856 unregister_savevm(DEVICE(dev), "ivshmem", s);
Stefan Hajnoczia2e90112014-09-15 18:40:05 +0200857 fifo8_destroy(&s->incoming_fifo);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600858}
859
Anthony Liguori40021f02011-12-04 12:22:06 -0600860static Property ivshmem_properties[] = {
861 DEFINE_PROP_CHR("chardev", IVShmemState, server_chr),
862 DEFINE_PROP_STRING("size", IVShmemState, sizearg),
863 DEFINE_PROP_UINT32("vectors", IVShmemState, vectors, 1),
864 DEFINE_PROP_BIT("ioeventfd", IVShmemState, features, IVSHMEM_IOEVENTFD, false),
865 DEFINE_PROP_BIT("msi", IVShmemState, features, IVSHMEM_MSI, true),
866 DEFINE_PROP_STRING("shm", IVShmemState, shmobj),
867 DEFINE_PROP_STRING("role", IVShmemState, role),
Gerd Hoffmannc08ba662012-09-13 11:08:02 +0200868 DEFINE_PROP_UINT32("use64", IVShmemState, ivshmem_64bit, 1),
Anthony Liguori40021f02011-12-04 12:22:06 -0600869 DEFINE_PROP_END_OF_LIST(),
870};
871
872static void ivshmem_class_init(ObjectClass *klass, void *data)
873{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600874 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -0600875 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
876
877 k->init = pci_ivshmem_init;
878 k->exit = pci_ivshmem_uninit;
Paolo Bonzinib8ef62a2012-12-13 10:19:37 +0100879 k->vendor_id = PCI_VENDOR_ID_IVSHMEM;
880 k->device_id = PCI_DEVICE_ID_IVSHMEM;
Anthony Liguori40021f02011-12-04 12:22:06 -0600881 k->class_id = PCI_CLASS_MEMORY_RAM;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600882 dc->reset = ivshmem_reset;
883 dc->props = ivshmem_properties;
Marcel Apfelbaum125ee0e2013-07-29 17:17:45 +0300884 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
Anthony Liguori40021f02011-12-04 12:22:06 -0600885}
886
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100887static const TypeInfo ivshmem_info = {
Peter Crosthwaiteeb3fedf2013-06-24 16:59:29 +1000888 .name = TYPE_IVSHMEM,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600889 .parent = TYPE_PCI_DEVICE,
890 .instance_size = sizeof(IVShmemState),
891 .class_init = ivshmem_class_init,
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600892};
893
Andreas Färber83f7d432012-02-09 15:20:55 +0100894static void ivshmem_register_types(void)
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600895{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600896 type_register_static(&ivshmem_info);
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600897}
898
Andreas Färber83f7d432012-02-09 15:20:55 +0100899type_init(ivshmem_register_types)