]> git.proxmox.com Git - mirror_qemu.git/blame - hw/xen/xen_devconfig.c
hw/xen: automatically assign device index to block devices
[mirror_qemu.git] / hw / xen / xen_devconfig.c
CommitLineData
21cbfe5f 1#include "qemu/osdep.h"
2d0ed5e6 2#include "hw/xen/xen-legacy-backend.h"
922a01a0 3#include "qemu/option.h"
9c17d615 4#include "sysemu/blockdev.h"
46517dd4 5#include "sysemu/sysemu.h"
2c8b24a3
AL
6
7/* ------------------------------------------------------------- */
8
2c8b24a3 9static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
7d37435b 10 char *fe, char *be, int len)
2c8b24a3
AL
11{
12 char *dom;
13
ba2a92db 14 dom = qemu_xen_xs_get_domain_path(xenstore, xen_domid);
2c8b24a3
AL
15 snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
16 free(dom);
17
ba2a92db 18 dom = qemu_xen_xs_get_domain_path(xenstore, 0);
2c8b24a3
AL
19 snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
20 free(dom);
21
637c53ff
JG
22 xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
23 xenstore_mkdir(be, XS_PERM_READ);
2c8b24a3
AL
24 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
2c8b24a3
AL
49int xen_config_dev_nic(NICInfo *nic)
50{
51 char fe[256], be[256];
52 char mac[20];
161abfb5 53 int vlan_id = -1;
2c8b24a3 54
161abfb5 55 net_hub_id_for_client(nic->netdev, &vlan_id);
2c8b24a3 56 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
6eed1856
JK
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]);
96c77dba 59 xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
161abfb5 60 xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
2c8b24a3
AL
61
62 /* frontend */
161abfb5 63 xenstore_write_int(fe, "handle", vlan_id);
2c8b24a3
AL
64 xenstore_write_str(fe, "mac", mac);
65
66 /* backend */
161abfb5 67 xenstore_write_int(be, "handle", vlan_id);
2c8b24a3
AL
68 xenstore_write_str(be, "mac", mac);
69
70 /* common stuff */
71 return xen_config_dev_all(fe, be);
72}
9306acb5
AL
73
74int 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
87int 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
95int 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}