2016-01-26 21:17:06 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-01-08 17:48:46 +03:00
|
|
|
#include "hw/xen/xen-legacy-backend.h"
|
2018-02-01 14:18:46 +03:00
|
|
|
#include "qemu/option.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/blockdev.h"
|
2019-08-12 08:23:57 +03:00
|
|
|
#include "sysemu/sysemu.h"
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int xen_config_dev_dirs(const char *ftype, const char *btype, int vdev,
|
2018-12-14 01:37:37 +03:00
|
|
|
char *fe, char *be, int len)
|
2009-04-22 19:19:39 +04:00
|
|
|
{
|
|
|
|
char *dom;
|
|
|
|
|
2023-01-02 14:05:16 +03:00
|
|
|
dom = qemu_xen_xs_get_domain_path(xenstore, xen_domid);
|
2009-04-22 19:19:39 +04:00
|
|
|
snprintf(fe, len, "%s/device/%s/%d", dom, ftype, vdev);
|
|
|
|
free(dom);
|
|
|
|
|
2023-01-02 14:05:16 +03:00
|
|
|
dom = qemu_xen_xs_get_domain_path(xenstore, 0);
|
2009-04-22 19:19:39 +04:00
|
|
|
snprintf(be, len, "%s/backend/%s/%d/%d", dom, btype, xen_domid, vdev);
|
|
|
|
free(dom);
|
|
|
|
|
2016-05-12 17:13:40 +03:00
|
|
|
xenstore_mkdir(fe, XS_PERM_READ | XS_PERM_WRITE);
|
|
|
|
xenstore_mkdir(be, XS_PERM_READ);
|
2009-04-22 19:19:39 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_config_dev_all(char *fe, char *be)
|
|
|
|
{
|
|
|
|
/* frontend */
|
|
|
|
if (xen_protocol)
|
|
|
|
xenstore_write_str(fe, "protocol", xen_protocol);
|
|
|
|
|
|
|
|
xenstore_write_int(fe, "state", XenbusStateInitialising);
|
|
|
|
xenstore_write_int(fe, "backend-id", 0);
|
|
|
|
xenstore_write_str(fe, "backend", be);
|
|
|
|
|
|
|
|
/* backend */
|
|
|
|
xenstore_write_str(be, "domain", qemu_name ? qemu_name : "no-name");
|
|
|
|
xenstore_write_int(be, "online", 1);
|
|
|
|
xenstore_write_int(be, "state", XenbusStateInitialising);
|
|
|
|
xenstore_write_int(be, "frontend-id", xen_domid);
|
|
|
|
xenstore_write_str(be, "frontend", fe);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int xen_config_dev_nic(NICInfo *nic)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
char mac[20];
|
2012-08-04 15:29:55 +04:00
|
|
|
int vlan_id = -1;
|
2009-04-22 19:19:39 +04:00
|
|
|
|
2012-08-04 15:29:55 +04:00
|
|
|
net_hub_id_for_client(nic->netdev, &vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
|
2011-07-20 14:20:22 +04:00
|
|
|
nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
|
|
|
|
nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
|
2016-10-25 08:50:14 +03:00
|
|
|
xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
|
2012-08-04 15:29:55 +04:00
|
|
|
xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));
|
2009-04-22 19:19:39 +04:00
|
|
|
|
|
|
|
/* frontend */
|
2012-08-04 15:29:55 +04:00
|
|
|
xenstore_write_int(fe, "handle", vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(fe, "mac", mac);
|
|
|
|
|
|
|
|
/* backend */
|
2012-08-04 15:29:55 +04:00
|
|
|
xenstore_write_int(be, "handle", vlan_id);
|
2009-04-22 19:19:39 +04:00
|
|
|
xenstore_write_str(be, "mac", mac);
|
|
|
|
|
|
|
|
/* common stuff */
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
2009-04-22 19:19:44 +04:00
|
|
|
|
|
|
|
int xen_config_dev_vfb(int vdev, const char *type)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("vfb", "vfb", vdev, fe, be, sizeof(fe));
|
|
|
|
|
|
|
|
/* backend */
|
|
|
|
xenstore_write_str(be, "type", type);
|
|
|
|
|
|
|
|
/* common stuff */
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_config_dev_vkbd(int vdev)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("vkbd", "vkbd", vdev, fe, be, sizeof(fe));
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xen_config_dev_console(int vdev)
|
|
|
|
{
|
|
|
|
char fe[256], be[256];
|
|
|
|
|
|
|
|
xen_config_dev_dirs("console", "console", vdev, fe, be, sizeof(fe));
|
|
|
|
return xen_config_dev_all(fe, be);
|
|
|
|
}
|