ppc/pnv: Remove useless checks in set_irq handlers
[qemu.git] / hw / xen / xen_devconfig.c
blob46ee4a7f0248642af610a6550f32f70143fff273
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"
7 /* ------------------------------------------------------------- */
9 static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
10 char *fe, char *be, int len)
12 char *dom;
14 dom = xs_get_domain_path(xenstore, xen_domid);
15 snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
16 free(dom);
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);
22 xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
23 xenstore_mkdir(be, XS_PERM_READ);
24 return 0;
27 static int xen_config_dev_all(char *fe, char *be)
29 /* frontend */
30 if (xen_protocol)
31 xenstore_write_str(fe, "protocol", xen_protocol);
33 xenstore_write_int(fe, "state", XenbusStateInitialising);
34 xenstore_write_int(fe, "backend-id", 0);
35 xenstore_write_str(fe, "backend", be);
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);
44 return 0;
47 /* ------------------------------------------------------------- */
49 int xen_config_dev_blk(DriveInfo *disk)
51 char fe[256], be[256], device_name[32];
52 int vdev = 202 * 256 + 16 * disk->unit;
53 int cdrom = disk->media_cd;
54 const char *devtype = cdrom ? "cdrom" : "disk";
55 const char *mode = cdrom ? "r" : "w";
56 const char *filename = qemu_opt_get(disk->opts, "file");
58 snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit);
59 xen_pv_printf(NULL, 1, "config disk %d [%s]: %s\n",
60 disk->unit, device_name, filename);
61 xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
63 /* frontend */
64 xenstore_write_int(fe, "virtual-device", vdev);
65 xenstore_write_str(fe, "device-type", devtype);
67 /* backend */
68 xenstore_write_str(be, "dev", device_name);
69 xenstore_write_str(be, "type", "file");
70 xenstore_write_str(be, "params", filename);
71 xenstore_write_str(be, "mode", mode);
73 /* common stuff */
74 return xen_config_dev_all(fe, be);
77 int xen_config_dev_nic(NICInfo *nic)
79 char fe[256], be[256];
80 char mac[20];
81 int vlan_id = -1;
83 net_hub_id_for_client(nic->netdev, &vlan_id);
84 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
85 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]);
87 xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
88 xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
90 /* frontend */
91 xenstore_write_int(fe, "handle", vlan_id);
92 xenstore_write_str(fe, "mac", mac);
94 /* backend */
95 xenstore_write_int(be, "handle", vlan_id);
96 xenstore_write_str(be, "mac", mac);
98 /* common stuff */
99 return xen_config_dev_all(fe, be);
102 int xen_config_dev_vfb(int vdev, const char *type)
104 char fe[256], be[256];
106 xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
108 /* backend */
109 xenstore_write_str(be, "type", type);
111 /* common stuff */
112 return xen_config_dev_all(fe, be);
115 int xen_config_dev_vkbd(int vdev)
117 char fe[256], be[256];
119 xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
120 return xen_config_dev_all(fe, be);
123 int xen_config_dev_console(int vdev)
125 char fe[256], be[256];
127 xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
128 return xen_config_dev_all(fe, be);