xref: /openbmc/qemu/hw/xen/xen_devconfig.c (revision 2f926bfd)
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_nic(NICInfo *nic)
50 {
51     char fe[256], be[256];
52     char mac[20];
53     int vlan_id = -1;
54 
55     net_hub_id_for_client(nic->netdev, &vlan_id);
56     snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
57              nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
58              nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
59     xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
60     xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
61 
62     /* frontend */
63     xenstore_write_int(fe, "handle",     vlan_id);
64     xenstore_write_str(fe, "mac",        mac);
65 
66     /* backend */
67     xenstore_write_int(be, "handle",     vlan_id);
68     xenstore_write_str(be, "mac",        mac);
69 
70     /* common stuff */
71     return xen_config_dev_all(fe, be);
72 }
73 
74 int xen_config_dev_vfb(int vdev, const char *type)
75 {
76     char fe[256], be[256];
77 
78     xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
79 
80     /* backend */
81     xenstore_write_str(be, "type",  type);
82 
83     /* common stuff */
84     return xen_config_dev_all(fe, be);
85 }
86 
87 int xen_config_dev_vkbd(int vdev)
88 {
89     char fe[256], be[256];
90 
91     xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
92     return xen_config_dev_all(fe, be);
93 }
94 
95 int xen_config_dev_console(int vdev)
96 {
97     char fe[256], be[256];
98 
99     xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
100     return xen_config_dev_all(fe, be);
101 }
102