Peter Maydell | 21cbfe5 | 2016-01-26 18:17:06 +0000 | [diff] [blame] | 1 | #include "qemu/osdep.h" |
Paul Durrant | 2d0ed5e | 2019-01-08 14:48:46 +0000 | [diff] [blame] | 2 | #include "hw/xen/xen-legacy-backend.h" |
Markus Armbruster | 922a01a | 2018-02-01 12:18:46 +0100 | [diff] [blame] | 3 | #include "qemu/option.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 4 | #include "sysemu/blockdev.h" |
Markus Armbruster | 46517dd | 2019-08-12 07:23:57 +0200 | [diff] [blame] | 5 | #include "sysemu/sysemu.h" |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 6 | |
| 7 | /* ------------------------------------------------------------- */ |
| 8 | |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 9 | static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev, |
Paolo Bonzini | 7d37435 | 2018-12-13 23:37:37 +0100 | [diff] [blame] | 10 | char *fe, char *be, int len) |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 11 | { |
| 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 Gross | 637c53f | 2016-05-12 16:13:40 +0200 | [diff] [blame] | 22 | xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE); |
| 23 | xenstore_mkdir(be, XS_PERM_READ); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 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_blk(DriveInfo *disk) |
| 50 | { |
Markus Armbruster | 8814a05 | 2012-06-13 10:11:49 +0200 | [diff] [blame] | 51 | char fe[256], be[256], device_name[32]; |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 52 | int vdev = 202 * 256 + 16 * disk->unit; |
Markus Armbruster | 95b5edc | 2011-05-16 15:04:56 +0200 | [diff] [blame] | 53 | int cdrom = disk->media_cd; |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 54 | const char *devtype = cdrom ? "cdrom" : "disk"; |
| 55 | const char *mode = cdrom ? "r" : "w"; |
Markus Armbruster | 093003b | 2012-06-13 10:11:50 +0200 | [diff] [blame] | 56 | const char *filename = qemu_opt_get(disk->opts, "file"); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 57 | |
Markus Armbruster | 8814a05 | 2012-06-13 10:11:49 +0200 | [diff] [blame] | 58 | snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit); |
Emil Condrea | 96c77db | 2016-10-25 08:50:14 +0300 | [diff] [blame] | 59 | xen_pv_printf(NULL, 1, "config disk %d [%s]: %s\n", |
Markus Armbruster | 093003b | 2012-06-13 10:11:50 +0200 | [diff] [blame] | 60 | disk->unit, device_name, filename); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 61 | 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 Armbruster | 8814a05 | 2012-06-13 10:11:49 +0200 | [diff] [blame] | 68 | xenstore_write_str(be, "dev", device_name); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 69 | xenstore_write_str(be, "type", "file"); |
Markus Armbruster | 093003b | 2012-06-13 10:11:50 +0200 | [diff] [blame] | 70 | xenstore_write_str(be, "params", filename); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 71 | xenstore_write_str(be, "mode", mode); |
| 72 | |
| 73 | /* common stuff */ |
| 74 | return xen_config_dev_all(fe, be); |
| 75 | } |
| 76 | |
| 77 | int xen_config_dev_nic(NICInfo *nic) |
| 78 | { |
| 79 | char fe[256], be[256]; |
| 80 | char mac[20]; |
Dunrong Huang | 161abfb | 2012-08-04 19:29:55 +0800 | [diff] [blame] | 81 | int vlan_id = -1; |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 82 | |
Dunrong Huang | 161abfb | 2012-08-04 19:29:55 +0800 | [diff] [blame] | 83 | net_hub_id_for_client(nic->netdev, &vlan_id); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 84 | snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", |
Jan Kiszka | 6eed185 | 2011-07-20 12:20:22 +0200 | [diff] [blame] | 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]); |
Emil Condrea | 96c77db | 2016-10-25 08:50:14 +0300 | [diff] [blame] | 87 | xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac); |
Dunrong Huang | 161abfb | 2012-08-04 19:29:55 +0800 | [diff] [blame] | 88 | xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe)); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 89 | |
| 90 | /* frontend */ |
Dunrong Huang | 161abfb | 2012-08-04 19:29:55 +0800 | [diff] [blame] | 91 | xenstore_write_int(fe, "handle", vlan_id); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 92 | xenstore_write_str(fe, "mac", mac); |
| 93 | |
| 94 | /* backend */ |
Dunrong Huang | 161abfb | 2012-08-04 19:29:55 +0800 | [diff] [blame] | 95 | xenstore_write_int(be, "handle", vlan_id); |
aliguori | 2c8b24a | 2009-04-22 15:19:39 +0000 | [diff] [blame] | 96 | xenstore_write_str(be, "mac", mac); |
| 97 | |
| 98 | /* common stuff */ |
| 99 | return xen_config_dev_all(fe, be); |
| 100 | } |
aliguori | 9306acb | 2009-04-22 15:19:44 +0000 | [diff] [blame] | 101 | |
| 102 | int 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 | |
| 115 | int 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 | |
| 123 | int 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 | } |