hw/watchdog/wdt_i6300esb: Convert away from old_mmio
[qemu/ar7.git] / hw / xen / xen_backend.c
blob9a8e8771eca071bab3c9367a7267c35115dd6283
1 /*
2 * xen backend driver infrastructure
3 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; under version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Contributions after 2012-01-13 are licensed under the terms of the
18 * GNU GPL, version 2 or (at your option) any later version.
22 * TODO: add some xenbus / xenstore concepts overview here.
25 #include "qemu/osdep.h"
26 #include <sys/signal.h>
28 #include "hw/hw.h"
29 #include "hw/sysbus.h"
30 #include "hw/boards.h"
31 #include "qemu/log.h"
32 #include "qapi/error.h"
33 #include "hw/xen/xen_backend.h"
34 #include "hw/xen/xen_pvdev.h"
35 #include "monitor/qdev.h"
37 #include <xen/grant_table.h>
39 DeviceState *xen_sysdev;
40 BusState *xen_sysbus;
42 /* ------------------------------------------------------------- */
44 /* public */
45 struct xs_handle *xenstore = NULL;
46 const char *xen_protocol;
48 /* private */
49 static bool xen_feature_grant_copy;
50 static int debug;
52 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val)
54 return xenstore_write_str(xendev->be, node, val);
57 int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival)
59 return xenstore_write_int(xendev->be, node, ival);
62 int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival)
64 return xenstore_write_int64(xendev->be, node, ival);
67 char *xenstore_read_be_str(struct XenDevice *xendev, const char *node)
69 return xenstore_read_str(xendev->be, node);
72 int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival)
74 return xenstore_read_int(xendev->be, node, ival);
77 char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node)
79 return xenstore_read_str(xendev->fe, node);
82 int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival)
84 return xenstore_read_int(xendev->fe, node, ival);
87 int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node,
88 uint64_t *uval)
90 return xenstore_read_uint64(xendev->fe, node, uval);
93 /* ------------------------------------------------------------- */
95 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state)
97 int rc;
99 rc = xenstore_write_be_int(xendev, "state", state);
100 if (rc < 0) {
101 return rc;
103 xen_pv_printf(xendev, 1, "backend state: %s -> %s\n",
104 xenbus_strstate(xendev->be_state), xenbus_strstate(state));
105 xendev->be_state = state;
106 return 0;
109 void xen_be_set_max_grant_refs(struct XenDevice *xendev,
110 unsigned int nr_refs)
112 assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
114 if (xengnttab_set_max_grants(xendev->gnttabdev, nr_refs)) {
115 xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
116 strerror(errno));
120 void *xen_be_map_grant_refs(struct XenDevice *xendev, uint32_t *refs,
121 unsigned int nr_refs, int prot)
123 void *ptr;
125 assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
127 ptr = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_refs,
128 xen_domid, refs, prot);
129 if (!ptr) {
130 xen_pv_printf(xendev, 0,
131 "xengnttab_map_domain_grant_refs failed: %s\n",
132 strerror(errno));
135 return ptr;
138 void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr,
139 unsigned int nr_refs)
141 assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
143 if (xengnttab_unmap(xendev->gnttabdev, ptr, nr_refs)) {
144 xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
145 strerror(errno));
149 static int compat_copy_grant_refs(struct XenDevice *xendev,
150 bool to_domain,
151 XenGrantCopySegment segs[],
152 unsigned int nr_segs)
154 uint32_t *refs = g_new(uint32_t, nr_segs);
155 int prot = to_domain ? PROT_WRITE : PROT_READ;
156 void *pages;
157 unsigned int i;
159 for (i = 0; i < nr_segs; i++) {
160 XenGrantCopySegment *seg = &segs[i];
162 refs[i] = to_domain ?
163 seg->dest.foreign.ref : seg->source.foreign.ref;
166 pages = xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_segs,
167 xen_domid, refs, prot);
168 if (!pages) {
169 xen_pv_printf(xendev, 0,
170 "xengnttab_map_domain_grant_refs failed: %s\n",
171 strerror(errno));
172 g_free(refs);
173 return -1;
176 for (i = 0; i < nr_segs; i++) {
177 XenGrantCopySegment *seg = &segs[i];
178 void *page = pages + (i * XC_PAGE_SIZE);
180 if (to_domain) {
181 memcpy(page + seg->dest.foreign.offset, seg->source.virt,
182 seg->len);
183 } else {
184 memcpy(seg->dest.virt, page + seg->source.foreign.offset,
185 seg->len);
189 if (xengnttab_unmap(xendev->gnttabdev, pages, nr_segs)) {
190 xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n",
191 strerror(errno));
194 g_free(refs);
195 return 0;
198 int xen_be_copy_grant_refs(struct XenDevice *xendev,
199 bool to_domain,
200 XenGrantCopySegment segs[],
201 unsigned int nr_segs)
203 xengnttab_grant_copy_segment_t *xengnttab_segs;
204 unsigned int i;
205 int rc;
207 assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV);
209 if (!xen_feature_grant_copy) {
210 return compat_copy_grant_refs(xendev, to_domain, segs, nr_segs);
213 xengnttab_segs = g_new0(xengnttab_grant_copy_segment_t, nr_segs);
215 for (i = 0; i < nr_segs; i++) {
216 XenGrantCopySegment *seg = &segs[i];
217 xengnttab_grant_copy_segment_t *xengnttab_seg = &xengnttab_segs[i];
219 if (to_domain) {
220 xengnttab_seg->flags = GNTCOPY_dest_gref;
221 xengnttab_seg->dest.foreign.domid = xen_domid;
222 xengnttab_seg->dest.foreign.ref = seg->dest.foreign.ref;
223 xengnttab_seg->dest.foreign.offset = seg->dest.foreign.offset;
224 xengnttab_seg->source.virt = seg->source.virt;
225 } else {
226 xengnttab_seg->flags = GNTCOPY_source_gref;
227 xengnttab_seg->source.foreign.domid = xen_domid;
228 xengnttab_seg->source.foreign.ref = seg->source.foreign.ref;
229 xengnttab_seg->source.foreign.offset =
230 seg->source.foreign.offset;
231 xengnttab_seg->dest.virt = seg->dest.virt;
234 xengnttab_seg->len = seg->len;
237 rc = xengnttab_grant_copy(xendev->gnttabdev, nr_segs, xengnttab_segs);
239 if (rc) {
240 xen_pv_printf(xendev, 0, "xengnttab_copy failed: %s\n",
241 strerror(errno));
244 for (i = 0; i < nr_segs; i++) {
245 xengnttab_grant_copy_segment_t *xengnttab_seg =
246 &xengnttab_segs[i];
248 if (xengnttab_seg->status != GNTST_okay) {
249 xen_pv_printf(xendev, 0, "segment[%u] status: %d\n", i,
250 xengnttab_seg->status);
251 rc = -1;
255 g_free(xengnttab_segs);
256 return rc;
260 * get xen backend device, allocate a new one if it doesn't exist.
262 static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
263 struct XenDevOps *ops)
265 struct XenDevice *xendev;
267 xendev = xen_pv_find_xendev(type, dom, dev);
268 if (xendev) {
269 return xendev;
272 /* init new xendev */
273 xendev = g_malloc0(ops->size);
274 object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND);
275 OBJECT(xendev)->free = g_free;
276 qdev_set_parent_bus(DEVICE(xendev), xen_sysbus);
277 qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev));
278 qdev_init_nofail(DEVICE(xendev));
279 object_unref(OBJECT(xendev));
281 xendev->type = type;
282 xendev->dom = dom;
283 xendev->dev = dev;
284 xendev->ops = ops;
286 snprintf(xendev->be, sizeof(xendev->be), "backend/%s/%d/%d",
287 xendev->type, xendev->dom, xendev->dev);
288 snprintf(xendev->name, sizeof(xendev->name), "%s-%d",
289 xendev->type, xendev->dev);
291 xendev->debug = debug;
292 xendev->local_port = -1;
294 xendev->evtchndev = xenevtchn_open(NULL, 0);
295 if (xendev->evtchndev == NULL) {
296 xen_pv_printf(NULL, 0, "can't open evtchn device\n");
297 qdev_unplug(DEVICE(xendev), NULL);
298 return NULL;
300 qemu_set_cloexec(xenevtchn_fd(xendev->evtchndev));
302 xen_pv_insert_xendev(xendev);
304 if (xendev->ops->alloc) {
305 xendev->ops->alloc(xendev);
308 return xendev;
313 * Sync internal data structures on xenstore updates.
314 * Node specifies the changed field. node = NULL means
315 * update all fields (used for initialization).
317 static void xen_be_backend_changed(struct XenDevice *xendev, const char *node)
319 if (node == NULL || strcmp(node, "online") == 0) {
320 if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1) {
321 xendev->online = 0;
325 if (node) {
326 xen_pv_printf(xendev, 2, "backend update: %s\n", node);
327 if (xendev->ops->backend_changed) {
328 xendev->ops->backend_changed(xendev, node);
333 static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node)
335 int fe_state;
337 if (node == NULL || strcmp(node, "state") == 0) {
338 if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) {
339 fe_state = XenbusStateUnknown;
341 if (xendev->fe_state != fe_state) {
342 xen_pv_printf(xendev, 1, "frontend state: %s -> %s\n",
343 xenbus_strstate(xendev->fe_state),
344 xenbus_strstate(fe_state));
346 xendev->fe_state = fe_state;
348 if (node == NULL || strcmp(node, "protocol") == 0) {
349 g_free(xendev->protocol);
350 xendev->protocol = xenstore_read_fe_str(xendev, "protocol");
351 if (xendev->protocol) {
352 xen_pv_printf(xendev, 1, "frontend protocol: %s\n",
353 xendev->protocol);
357 if (node) {
358 xen_pv_printf(xendev, 2, "frontend update: %s\n", node);
359 if (xendev->ops->frontend_changed) {
360 xendev->ops->frontend_changed(xendev, node);
365 /* ------------------------------------------------------------- */
366 /* Check for possible state transitions and perform them. */
369 * Initial xendev setup. Read frontend path, register watch for it.
370 * Should succeed once xend finished setting up the backend device.
372 * Also sets initial state (-> Initializing) when done. Which
373 * only affects the xendev->be_state variable as xenbus should
374 * already be put into that state by xend.
376 static int xen_be_try_setup(struct XenDevice *xendev)
378 char token[XEN_BUFSIZE];
379 int be_state;
381 if (xenstore_read_be_int(xendev, "state", &be_state) == -1) {
382 xen_pv_printf(xendev, 0, "reading backend state failed\n");
383 return -1;
386 if (be_state != XenbusStateInitialising) {
387 xen_pv_printf(xendev, 0, "initial backend state is wrong (%s)\n",
388 xenbus_strstate(be_state));
389 return -1;
392 xendev->fe = xenstore_read_be_str(xendev, "frontend");
393 if (xendev->fe == NULL) {
394 xen_pv_printf(xendev, 0, "reading frontend path failed\n");
395 return -1;
398 /* setup frontend watch */
399 snprintf(token, sizeof(token), "fe:%p", xendev);
400 if (!xs_watch(xenstore, xendev->fe, token)) {
401 xen_pv_printf(xendev, 0, "watching frontend path (%s) failed\n",
402 xendev->fe);
403 return -1;
405 xen_be_set_state(xendev, XenbusStateInitialising);
407 xen_be_backend_changed(xendev, NULL);
408 xen_be_frontend_changed(xendev, NULL);
409 return 0;
413 * Try initialize xendev. Prepare everything the backend can do
414 * without synchronizing with the frontend. Fakes hotplug-status. No
415 * hotplug involved here because this is about userspace drivers, thus
416 * there are kernel backend devices which could invoke hotplug.
418 * Goes to InitWait on success.
420 static int xen_be_try_init(struct XenDevice *xendev)
422 int rc = 0;
424 if (!xendev->online) {
425 xen_pv_printf(xendev, 1, "not online\n");
426 return -1;
429 if (xendev->ops->init) {
430 rc = xendev->ops->init(xendev);
432 if (rc != 0) {
433 xen_pv_printf(xendev, 1, "init() failed\n");
434 return rc;
437 xenstore_write_be_str(xendev, "hotplug-status", "connected");
438 xen_be_set_state(xendev, XenbusStateInitWait);
439 return 0;
443 * Try to initialise xendev. Depends on the frontend being ready
444 * for it (shared ring and evtchn info in xenstore, state being
445 * Initialised or Connected).
447 * Goes to Connected on success.
449 static int xen_be_try_initialise(struct XenDevice *xendev)
451 int rc = 0;
453 if (xendev->fe_state != XenbusStateInitialised &&
454 xendev->fe_state != XenbusStateConnected) {
455 if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
456 xen_pv_printf(xendev, 2, "frontend not ready, ignoring\n");
457 } else {
458 xen_pv_printf(xendev, 2, "frontend not ready (yet)\n");
459 return -1;
463 if (xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
464 xendev->gnttabdev = xengnttab_open(NULL, 0);
465 if (xendev->gnttabdev == NULL) {
466 xen_pv_printf(NULL, 0, "can't open gnttab device\n");
467 return -1;
469 } else {
470 xendev->gnttabdev = NULL;
473 if (xendev->ops->initialise) {
474 rc = xendev->ops->initialise(xendev);
476 if (rc != 0) {
477 xen_pv_printf(xendev, 0, "initialise() failed\n");
478 return rc;
481 xen_be_set_state(xendev, XenbusStateConnected);
482 return 0;
486 * Try to let xendev know that it is connected. Depends on the
487 * frontend being Connected. Note that this may be called more
488 * than once since the backend state is not modified.
490 static void xen_be_try_connected(struct XenDevice *xendev)
492 if (!xendev->ops->connected) {
493 return;
496 if (xendev->fe_state != XenbusStateConnected) {
497 if (xendev->ops->flags & DEVOPS_FLAG_IGNORE_STATE) {
498 xen_pv_printf(xendev, 2, "frontend not ready, ignoring\n");
499 } else {
500 xen_pv_printf(xendev, 2, "frontend not ready (yet)\n");
501 return;
505 xendev->ops->connected(xendev);
509 * Teardown connection.
511 * Goes to Closed when done.
513 static void xen_be_disconnect(struct XenDevice *xendev, enum xenbus_state state)
515 if (xendev->be_state != XenbusStateClosing &&
516 xendev->be_state != XenbusStateClosed &&
517 xendev->ops->disconnect) {
518 xendev->ops->disconnect(xendev);
520 if (xendev->gnttabdev) {
521 xengnttab_close(xendev->gnttabdev);
522 xendev->gnttabdev = NULL;
524 if (xendev->be_state != state) {
525 xen_be_set_state(xendev, state);
530 * Try to reset xendev, for reconnection by another frontend instance.
532 static int xen_be_try_reset(struct XenDevice *xendev)
534 if (xendev->fe_state != XenbusStateInitialising) {
535 return -1;
538 xen_pv_printf(xendev, 1, "device reset (for re-connect)\n");
539 xen_be_set_state(xendev, XenbusStateInitialising);
540 return 0;
544 * state change dispatcher function
546 void xen_be_check_state(struct XenDevice *xendev)
548 int rc = 0;
550 /* frontend may request shutdown from almost anywhere */
551 if (xendev->fe_state == XenbusStateClosing ||
552 xendev->fe_state == XenbusStateClosed) {
553 xen_be_disconnect(xendev, xendev->fe_state);
554 return;
557 /* check for possible backend state transitions */
558 for (;;) {
559 switch (xendev->be_state) {
560 case XenbusStateUnknown:
561 rc = xen_be_try_setup(xendev);
562 break;
563 case XenbusStateInitialising:
564 rc = xen_be_try_init(xendev);
565 break;
566 case XenbusStateInitWait:
567 rc = xen_be_try_initialise(xendev);
568 break;
569 case XenbusStateConnected:
570 /* xendev->be_state doesn't change */
571 xen_be_try_connected(xendev);
572 rc = -1;
573 break;
574 case XenbusStateClosed:
575 rc = xen_be_try_reset(xendev);
576 break;
577 default:
578 rc = -1;
580 if (rc != 0) {
581 break;
586 /* ------------------------------------------------------------- */
588 static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
590 struct XenDevice *xendev;
591 char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
592 char **dev = NULL;
593 unsigned int cdev, j;
595 /* setup watch */
596 snprintf(token, sizeof(token), "be:%p:%d:%p", type, dom, ops);
597 snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
598 if (!xs_watch(xenstore, path, token)) {
599 xen_pv_printf(NULL, 0, "xen be: watching backend path (%s) failed\n",
600 path);
601 return -1;
604 /* look for backends */
605 dev = xs_directory(xenstore, 0, path, &cdev);
606 if (!dev) {
607 return 0;
609 for (j = 0; j < cdev; j++) {
610 xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops);
611 if (xendev == NULL) {
612 continue;
614 xen_be_check_state(xendev);
616 free(dev);
617 return 0;
620 void xenstore_update_be(char *watch, char *type, int dom,
621 struct XenDevOps *ops)
623 struct XenDevice *xendev;
624 char path[XEN_BUFSIZE], *bepath;
625 unsigned int len, dev;
627 len = snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
628 if (strncmp(path, watch, len) != 0) {
629 return;
631 if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) {
632 strcpy(path, "");
633 if (sscanf(watch+len, "/%u", &dev) != 1) {
634 dev = -1;
637 if (dev == -1) {
638 return;
641 xendev = xen_be_get_xendev(type, dom, dev, ops);
642 if (xendev != NULL) {
643 bepath = xs_read(xenstore, 0, xendev->be, &len);
644 if (bepath == NULL) {
645 xen_pv_del_xendev(xendev);
646 } else {
647 free(bepath);
648 xen_be_backend_changed(xendev, path);
649 xen_be_check_state(xendev);
654 void xenstore_update_fe(char *watch, struct XenDevice *xendev)
656 char *node;
657 unsigned int len;
659 len = strlen(xendev->fe);
660 if (strncmp(xendev->fe, watch, len) != 0) {
661 return;
663 if (watch[len] != '/') {
664 return;
666 node = watch + len + 1;
668 xen_be_frontend_changed(xendev, node);
669 xen_be_check_state(xendev);
671 /* -------------------------------------------------------------------- */
673 int xen_be_init(void)
675 xengnttab_handle *gnttabdev;
677 xenstore = xs_daemon_open();
678 if (!xenstore) {
679 xen_pv_printf(NULL, 0, "can't connect to xenstored\n");
680 return -1;
683 qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL);
685 if (xen_xc == NULL || xen_fmem == NULL) {
686 /* Check if xen_init() have been called */
687 goto err;
690 gnttabdev = xengnttab_open(NULL, 0);
691 if (gnttabdev != NULL) {
692 if (xengnttab_grant_copy(gnttabdev, 0, NULL) == 0) {
693 xen_feature_grant_copy = true;
695 xengnttab_close(gnttabdev);
698 xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
699 qdev_init_nofail(xen_sysdev);
700 xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
701 qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);
703 return 0;
705 err:
706 qemu_set_fd_handler(xs_fileno(xenstore), NULL, NULL, NULL);
707 xs_daemon_close(xenstore);
708 xenstore = NULL;
710 return -1;
713 static void xen_set_dynamic_sysbus(void)
715 Object *machine = qdev_get_machine();
716 ObjectClass *oc = object_get_class(machine);
717 MachineClass *mc = MACHINE_CLASS(oc);
719 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_XENSYSDEV);
722 int xen_be_register(const char *type, struct XenDevOps *ops)
724 char path[50];
725 int rc;
727 if (ops->backend_register) {
728 rc = ops->backend_register();
729 if (rc) {
730 return rc;
734 snprintf(path, sizeof(path), "device-model/%u/backends/%s", xen_domid,
735 type);
736 xenstore_mkdir(path, XS_PERM_NONE);
738 return xenstore_scan(type, xen_domid, ops);
741 void xen_be_register_common(void)
743 xen_set_dynamic_sysbus();
745 xen_be_register("console", &xen_console_ops);
746 xen_be_register("vkbd", &xen_kbdmouse_ops);
747 xen_be_register("qdisk", &xen_blkdev_ops);
748 #ifdef CONFIG_VIRTFS
749 xen_be_register("9pfs", &xen_9pfs_ops);
750 #endif
751 #ifdef CONFIG_USB_LIBUSB
752 xen_be_register("qusb", &xen_usb_ops);
753 #endif
756 int xen_be_bind_evtchn(struct XenDevice *xendev)
758 if (xendev->local_port != -1) {
759 return 0;
761 xendev->local_port = xenevtchn_bind_interdomain
762 (xendev->evtchndev, xendev->dom, xendev->remote_port);
763 if (xendev->local_port == -1) {
764 xen_pv_printf(xendev, 0, "xenevtchn_bind_interdomain failed\n");
765 return -1;
767 xen_pv_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
768 qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev),
769 xen_pv_evtchn_event, NULL, xendev);
770 return 0;
774 static Property xendev_properties[] = {
775 DEFINE_PROP_END_OF_LIST(),
778 static void xendev_class_init(ObjectClass *klass, void *data)
780 DeviceClass *dc = DEVICE_CLASS(klass);
782 dc->props = xendev_properties;
783 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
784 /* xen-backend devices can be plugged/unplugged dynamically */
785 dc->user_creatable = true;
788 static const TypeInfo xendev_type_info = {
789 .name = TYPE_XENBACKEND,
790 .parent = TYPE_XENSYSDEV,
791 .class_init = xendev_class_init,
792 .instance_size = sizeof(struct XenDevice),
795 static void xen_sysbus_class_init(ObjectClass *klass, void *data)
797 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
799 hc->unplug = qdev_simple_device_unplug_cb;
802 static const TypeInfo xensysbus_info = {
803 .name = TYPE_XENSYSBUS,
804 .parent = TYPE_BUS,
805 .class_init = xen_sysbus_class_init,
806 .interfaces = (InterfaceInfo[]) {
807 { TYPE_HOTPLUG_HANDLER },
812 static int xen_sysdev_init(SysBusDevice *dev)
814 return 0;
817 static Property xen_sysdev_properties[] = {
818 {/* end of property list */},
821 static void xen_sysdev_class_init(ObjectClass *klass, void *data)
823 DeviceClass *dc = DEVICE_CLASS(klass);
824 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
826 k->init = xen_sysdev_init;
827 dc->props = xen_sysdev_properties;
828 dc->bus_type = TYPE_XENSYSBUS;
831 static const TypeInfo xensysdev_info = {
832 .name = TYPE_XENSYSDEV,
833 .parent = TYPE_SYS_BUS_DEVICE,
834 .instance_size = sizeof(SysBusDevice),
835 .class_init = xen_sysdev_class_init,
838 static void xenbe_register_types(void)
840 type_register_static(&xensysbus_info);
841 type_register_static(&xensysdev_info);
842 type_register_static(&xendev_type_info);
845 type_init(xenbe_register_types)