#include "qemu/main-loop.h"
#include "qemu/log.h"
#include "qapi/error.h"
+#include "qapi/qapi-commands-misc.h"
#include "qom/object.h"
#include "exec/target_page.h"
#include "exec/address-spaces.h"
"ipi"
};
-void hmp_xen_event_list(Monitor *mon, const QDict *qdict)
+EvtchnInfoList *qmp_xen_event_list(Error **errp)
{
XenEvtchnState *s = xen_evtchn_singleton;
+ EvtchnInfoList *head = NULL, **tail = &head;
void *shinfo, *pending, *mask;
int i;
if (!s) {
- monitor_printf(mon, "Xen event channel emulation not enabled\n");
- return;
+ error_setg(errp, "Xen event channel emulation not enabled\n");
+ return NULL;
}
shinfo = xen_overlay_get_shinfo_ptr();
if (!shinfo) {
- monitor_printf(mon, "Xen shared info page not allocated\n");
- return;
+ error_setg(errp, "Xen shared info page not allocated\n");
+ return NULL;
}
if (xen_is_long_mode()) {
pending = shinfo + offsetof(struct shared_info, evtchn_pending);
for (i = 0; i < s->nr_ports; i++) {
XenEvtchnPort *p = &s->port_table[i];
+ EvtchnInfo *info;
if (p->type == EVTCHNSTAT_closed) {
continue;
}
- monitor_printf(mon, "port %4u %s/%d vcpu:%d pending:%d mask:%d\n", i,
- type_names[p->type], p->type_val, p->vcpu,
- test_bit(i, pending), test_bit(i, mask));
+ info = g_new0(EvtchnInfo, 1);
+
+ info->port = i;
+ info->type = g_strdup(type_names[p->type]);
+ if (p->type == EVTCHNSTAT_interdomain) {
+ info->remote_domain = g_strdup((p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) ?
+ "qemu" : "loopback");
+ info->target = p->type_val & PORT_INFO_TYPEVAL_REMOTE_PORT_MASK;
+ } else {
+ info->target = p->type_val;
+ }
+ info->vcpu = p->vcpu;
+ info->pending = test_bit(i, pending);
+ info->masked = test_bit(i, mask);
+
+ QAPI_LIST_APPEND(tail, info);
}
qemu_mutex_unlock(&s->port_lock);
+
+ return head;
+}
+
+HumanReadableText *hmp_xen_event_list(Error **errp)
+{
+ EvtchnInfoList *iter, *info_list;
+ g_autoptr(GString) buf = g_string_new("");
+
+
+ info_list = qmp_xen_event_list(errp);
+ if (*errp) {
+ return NULL;
+ }
+
+ for (iter = info_list; iter; iter = iter->next) {
+ EvtchnInfo *info = iter->value;
+
+ g_string_append_printf(buf, "port %4lu: %s", info->port, info->type);
+ if (strcmp(info->type, "ipi")) {
+ g_string_append_printf(buf, "(");
+ if (info->remote_domain) {
+ g_string_append_printf(buf, "%s:", info->remote_domain);
+ }
+ g_string_append_printf(buf, "%ld)", info->target);
+ }
+ g_string_append_printf(buf, " vcpu:%ld", info->vcpu);
+ if (info->pending) {
+ g_string_append_printf(buf, " PENDING");
+ }
+ if (info->masked) {
+ g_string_append_printf(buf, " MASKED");
+ }
+ g_string_append_printf(buf, "\n");
+ }
+
+ qapi_free_EvtchnInfoList(info_list);
+ return human_readable_text_from_str(buf);
}
void hmp_xen_event_inject(Monitor *mon, const QDict *qdict)
{ 'event': 'VFU_CLIENT_HANGUP',
'data': { 'vfu-id': 'str', 'vfu-qom-path': 'str',
'dev-id': 'str', 'dev-qom-path': 'str' } }
+
+##
+# @EvtchnInfo:
+#
+# Information about a Xen event channel port
+#
+# @port: the port number
+#
+# @type: the port type
+#
+# @remote-domain: remote domain for interdomain ports
+#
+# @target: remote port ID, or virq/pirq number
+#
+# @pending: port is currently active pending delivery
+#
+# @masked: port is masked
+#
+# Since: x.xx
+##
+{ 'struct': 'EvtchnInfo',
+ 'data': {'port': 'int',
+ 'type': 'str',
+ 'remote-domain': 'str',
+ 'vcpu': 'int',
+ 'target': 'int',
+ 'pending': 'bool',
+ 'masked': 'bool'}}
+
+
+##
+# @xen-event-list:
+#
+# Query the Xen event channels opened by the guest.
+#
+# Returns: list of open event channel ports.
+#
+# Since: x.xx
+#
+# Example:
+#
+# -> { "execute": "xen-event-list" }
+# <- { "return": [
+# {
+# "pending": false,
+# "port": 1,
+# "vcpu": 1,
+# "remote-domain": "qemu",
+# "masked": false,
+# "type": "interdomain",
+# "target": 1
+# },
+# {
+# "pending": false,
+# "port": 2,
+# "vcpu": 0,
+# "remote-domain": "",
+# "masked": false,
+# "type": "virq",
+# "target": 0
+# }
+# ]
+# }
+#
+##
+{ 'command': 'xen-event-list',
+ 'returns': ['EvtchnInfo'] }