xref: /openbmc/qemu/hw/xen/xen_devconfig.c (revision c76c86fb)
1 #include "qemu/osdep.h"
2 #include "hw/xen/xen-legacy-backend.h"
3 #include "qemu/option.h"
4 #include "sysemu/blockdev.h"
5 #include "sysemu/sysemu.h"
6 
7 /* ------------------------------------------------------------- */
8 
9 static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
10                                char *fe, char *be, int len)
11 {
12     char *dom;
13 
14     dom = qemu_xen_xs_get_domain_path(xenstore, xen_domid);
15     snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
16     free(dom);
17 
18     dom = qemu_xen_xs_get_domain_path(xenstore, 0);
19     snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
20     free(dom);
21 
22     xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
23     xenstore_mkdir(be, XS_PERM_READ);
24     return 0;
25 }
26 
27 static int xen_config_dev_all(char *fe, char *be)
28 {
29     /* frontend */
30     if (xen_protocol)
31         xenstore_write_str(fe, "protocol", xen_protocol);
32 
33     xenstore_write_int(fe, "state",           XenbusStateInitialising);
34     xenstore_write_int(fe, "backend-id",      0);
35     xenstore_write_str(fe, "backend",         be);
36 
37     /* backend */
38     xenstore_write_str(be, "domain",          qemu_name ? qemu_name : "no-name");
39     xenstore_write_int(be, "online",          1);
40     xenstore_write_int(be, "state",           XenbusStateInitialising);
41     xenstore_write_int(be, "frontend-id",     xen_domid);
42     xenstore_write_str(be, "frontend",        fe);
43 
44     return 0;
45 }
46 
47 /* ------------------------------------------------------------- */
48 
49 int xen_config_dev_vfb(int vdev, const char *type)
50 {
51     char fe[256], be[256];
52 
53     xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
54 
55     /* backend */
56     xenstore_write_str(be, "type",  type);
57 
58     /* common stuff */
59     return xen_config_dev_all(fe, be);
60 }
61 
62 int xen_config_dev_vkbd(int vdev)
63 {
64     char fe[256], be[256];
65 
66     xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
67     return xen_config_dev_all(fe, be);
68 }
69