xen-disk: add support for multi-page shared rings
[qemu.git] / hw / xen / xen_devconfig.c
bloba80e78c0dc739cbcfa3764db0edd878d44c55a25
1 #include "qemu/osdep.h"
2 #include "hw/xen/xen_backend.h"
3 #include "sysemu/block-backend.h"
4 #include "sysemu/blockdev.h"
6 /* ------------------------------------------------------------- */
8 static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
9 char *fe, char *be, int len)
11 char *dom;
13 dom = xs_get_domain_path(xenstore, xen_domid);
14 snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
15 free(dom);
17 dom = xs_get_domain_path(xenstore, 0);
18 snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
19 free(dom);
21 xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
22 xenstore_mkdir(be, XS_PERM_READ);
23 return 0;
26 static int xen_config_dev_all(char *fe, char *be)
28 /* frontend */
29 if (xen_protocol)
30 xenstore_write_str(fe, "protocol", xen_protocol);
32 xenstore_write_int(fe, "state", XenbusStateInitialising);
33 xenstore_write_int(fe, "backend-id", 0);
34 xenstore_write_str(fe, "backend", be);
36 /* backend */
37 xenstore_write_str(be, "domain", qemu_name ? qemu_name : "no-name");
38 xenstore_write_int(be, "online", 1);
39 xenstore_write_int(be, "state", XenbusStateInitialising);
40 xenstore_write_int(be, "frontend-id", xen_domid);
41 xenstore_write_str(be, "frontend", fe);
43 return 0;
46 /* ------------------------------------------------------------- */
48 int xen_config_dev_blk(DriveInfo *disk)
50 char fe[256], be[256], device_name[32];
51 int vdev = 202 * 256 + 16 * disk->unit;
52 int cdrom = disk->media_cd;
53 const char *devtype = cdrom ? "cdrom" : "disk";
54 const char *mode = cdrom ? "r" : "w";
55 const char *filename = qemu_opt_get(disk->opts, "file");
57 snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit);
58 xen_pv_printf(NULL, 1, "config disk %d [%s]: %s\n",
59 disk->unit, device_name, filename);
60 xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
62 /* frontend */
63 xenstore_write_int(fe, "virtual-device", vdev);
64 xenstore_write_str(fe, "device-type", devtype);
66 /* backend */
67 xenstore_write_str(be, "dev", device_name);
68 xenstore_write_str(be, "type", "file");
69 xenstore_write_str(be, "params", filename);
70 xenstore_write_str(be, "mode", mode);
72 /* common stuff */
73 return xen_config_dev_all(fe, be);
76 int xen_config_dev_nic(NICInfo *nic)
78 char fe[256], be[256];
79 char mac[20];
80 int vlan_id = -1;
82 net_hub_id_for_client(nic->netdev, &vlan_id);
83 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
84 nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
85 nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
86 xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
87 xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
89 /* frontend */
90 xenstore_write_int(fe, "handle", vlan_id);
91 xenstore_write_str(fe, "mac", mac);
93 /* backend */
94 xenstore_write_int(be, "handle", vlan_id);
95 xenstore_write_str(be, "mac", mac);
97 /* common stuff */
98 return xen_config_dev_all(fe, be);
101 int xen_config_dev_vfb(int vdev, const char *type)
103 char fe[256], be[256];
105 xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
107 /* backend */
108 xenstore_write_str(be, "type", type);
110 /* common stuff */
111 return xen_config_dev_all(fe, be);
114 int xen_config_dev_vkbd(int vdev)
116 char fe[256], be[256];
118 xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
119 return xen_config_dev_all(fe, be);
122 int xen_config_dev_console(int vdev)
124 char fe[256], be[256];
126 xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
127 return xen_config_dev_all(fe, be);