blob: 46ee4a7f0248642af610a6550f32f70143fff273 [file] [log] [blame]
Peter Maydell21cbfe52016-01-26 18:17:06 +00001#include "qemu/osdep.h"
Paul Durrant2d0ed5e2019-01-08 14:48:46 +00002#include "hw/xen/xen-legacy-backend.h"
Markus Armbruster922a01a2018-02-01 12:18:46 +01003#include "qemu/option.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +01004#include "sysemu/blockdev.h"
Markus Armbruster46517dd2019-08-12 07:23:57 +02005#include "sysemu/sysemu.h"
aliguori2c8b24a2009-04-22 15:19:39 +00006
7/* ------------------------------------------------------------- */
8
aliguori2c8b24a2009-04-22 15:19:39 +00009static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
Paolo Bonzini7d374352018-12-13 23:37:37 +010010 char *fe, char *be, int len)
aliguori2c8b24a2009-04-22 15:19:39 +000011{
12 char *dom;
13
14 dom = xs_get_domain_path(xenstore, xen_domid);
15 snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
16 free(dom);
17
18 dom = xs_get_domain_path(xenstore, 0);
19 snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
20 free(dom);
21
Juergen Gross637c53f2016-05-12 16:13:40 +020022 xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
23 xenstore_mkdir(be, XS_PERM_READ);
aliguori2c8b24a2009-04-22 15:19:39 +000024 return 0;
25}
26
27static 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
49int xen_config_dev_blk(DriveInfo *disk)
50{
Markus Armbruster8814a052012-06-13 10:11:49 +020051 char fe[256], be[256], device_name[32];
aliguori2c8b24a2009-04-22 15:19:39 +000052 int vdev = 202 * 256 + 16 * disk->unit;
Markus Armbruster95b5edc2011-05-16 15:04:56 +020053 int cdrom = disk->media_cd;
aliguori2c8b24a2009-04-22 15:19:39 +000054 const char *devtype = cdrom ? "cdrom" : "disk";
55 const char *mode = cdrom ? "r" : "w";
Markus Armbruster093003b2012-06-13 10:11:50 +020056 const char *filename = qemu_opt_get(disk->opts, "file");
aliguori2c8b24a2009-04-22 15:19:39 +000057
Markus Armbruster8814a052012-06-13 10:11:49 +020058 snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit);
Emil Condrea96c77db2016-10-25 08:50:14 +030059 xen_pv_printf(NULL, 1, "config disk %d [%s]: %s\n",
Markus Armbruster093003b2012-06-13 10:11:50 +020060 disk->unit, device_name, filename);
aliguori2c8b24a2009-04-22 15:19:39 +000061 xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
62
63 /* frontend */
64 xenstore_write_int(fe, "virtual-device", vdev);
65 xenstore_write_str(fe, "device-type", devtype);
66
67 /* backend */
Markus Armbruster8814a052012-06-13 10:11:49 +020068 xenstore_write_str(be, "dev", device_name);
aliguori2c8b24a2009-04-22 15:19:39 +000069 xenstore_write_str(be, "type", "file");
Markus Armbruster093003b2012-06-13 10:11:50 +020070 xenstore_write_str(be, "params", filename);
aliguori2c8b24a2009-04-22 15:19:39 +000071 xenstore_write_str(be, "mode", mode);
72
73 /* common stuff */
74 return xen_config_dev_all(fe, be);
75}
76
77int xen_config_dev_nic(NICInfo *nic)
78{
79 char fe[256], be[256];
80 char mac[20];
Dunrong Huang161abfb2012-08-04 19:29:55 +080081 int vlan_id = -1;
aliguori2c8b24a2009-04-22 15:19:39 +000082
Dunrong Huang161abfb2012-08-04 19:29:55 +080083 net_hub_id_for_client(nic->netdev, &vlan_id);
aliguori2c8b24a2009-04-22 15:19:39 +000084 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
Jan Kiszka6eed1852011-07-20 12:20:22 +020085 nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
86 nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
Emil Condrea96c77db2016-10-25 08:50:14 +030087 xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
Dunrong Huang161abfb2012-08-04 19:29:55 +080088 xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
aliguori2c8b24a2009-04-22 15:19:39 +000089
90 /* frontend */
Dunrong Huang161abfb2012-08-04 19:29:55 +080091 xenstore_write_int(fe, "handle", vlan_id);
aliguori2c8b24a2009-04-22 15:19:39 +000092 xenstore_write_str(fe, "mac", mac);
93
94 /* backend */
Dunrong Huang161abfb2012-08-04 19:29:55 +080095 xenstore_write_int(be, "handle", vlan_id);
aliguori2c8b24a2009-04-22 15:19:39 +000096 xenstore_write_str(be, "mac", mac);
97
98 /* common stuff */
99 return xen_config_dev_all(fe, be);
100}
aliguori9306acb2009-04-22 15:19:44 +0000101
102int xen_config_dev_vfb(int vdev, const char *type)
103{
104 char fe[256], be[256];
105
106 xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
107
108 /* backend */
109 xenstore_write_str(be, "type", type);
110
111 /* common stuff */
112 return xen_config_dev_all(fe, be);
113}
114
115int xen_config_dev_vkbd(int vdev)
116{
117 char fe[256], be[256];
118
119 xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
120 return xen_config_dev_all(fe, be);
121}
122
123int xen_config_dev_console(int vdev)
124{
125 char fe[256], be[256];
126
127 xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
128 return xen_config_dev_all(fe, be);
129}