All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anastasiia Lukianenko <vicooodin@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 06/17] xen: Port Xen event channel driver from mini-os
Date: Wed,  1 Jul 2020 19:29:48 +0300	[thread overview]
Message-ID: <20200701162959.9814-7-vicooodin@gmail.com> (raw)
In-Reply-To: <20200701162959.9814-1-vicooodin@gmail.com>

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Make required updates to run on u-boot. Strip functionality
not needed by U-boot.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com>
---
 drivers/xen/Makefile     |   1 +
 drivers/xen/events.c     | 177 +++++++++++++++++++++++++++++++++++++++
 drivers/xen/hypervisor.c |   6 +-
 include/xen/events.h     |  47 +++++++++++
 4 files changed, 228 insertions(+), 3 deletions(-)
 create mode 100644 drivers/xen/events.c
 create mode 100644 include/xen/events.h

diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 1211bf2386..0ad35edefb 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -3,3 +3,4 @@
 # (C) Copyright 2020 EPAM Systems Inc.
 
 obj-y += hypervisor.o
+obj-y += events.o
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
new file mode 100644
index 0000000000..eddc6b6e29
--- /dev/null
+++ b/drivers/xen/events.c
@@ -0,0 +1,177 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ ****************************************************************************
+ * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
+ * (C) 2005 - Grzegorz Milos - Intel Research Cambridge
+ * (C) 2020 - EPAM Systems Inc.
+ ****************************************************************************
+ *
+ *		File: events.c
+ *	  Author: Rolf Neugebauer (neugebar at dcs.gla.ac.uk)
+ *	 Changes: Grzegorz Milos (gm281 at cam.ac.uk)
+ *
+ *		Date: Jul 2003, changes Jun 2005
+ *
+ * Environment: Xen Minimal OS
+ * Description: Deals with events received on event channels
+ *
+ ****************************************************************************
+ */
+#include <common.h>
+#include <log.h>
+
+#include <asm/io.h>
+#include <asm/xen/system.h>
+
+#include <xen/events.h>
+#include <xen/hvm.h>
+
+#define NR_EVS 1024
+
+/* this represents a event handler. Chaining or sharing is not allowed */
+typedef struct _ev_action_t {
+	evtchn_handler_t handler;
+	void *data;
+	u32 count;
+} ev_action_t;
+
+static ev_action_t ev_actions[NR_EVS];
+void default_handler(evtchn_port_t port, struct pt_regs *regs, void *data);
+
+static unsigned long bound_ports[NR_EVS / (8 * sizeof(unsigned long))];
+
+void unbind_all_ports(void)
+{
+	int i;
+	int cpu = 0;
+	struct shared_info *s = HYPERVISOR_shared_info;
+	struct vcpu_info *vcpu_info = &s->vcpu_info[cpu];
+
+	for (i = 0; i < NR_EVS; i++) {
+		if (test_and_clear_bit(i, bound_ports)) {
+			printf("port %d still bound!\n", i);
+			unbind_evtchn(i);
+		}
+	}
+	vcpu_info->evtchn_upcall_pending = 0;
+	vcpu_info->evtchn_pending_sel = 0;
+}
+
+/*
+ * Demux events to different handlers.
+ */
+int do_event(evtchn_port_t port, struct pt_regs *regs)
+{
+	ev_action_t  *action;
+
+	clear_evtchn(port);
+
+	if (port >= NR_EVS) {
+		printk("WARN: do_event(): Port number too large: %d\n", port);
+		return 1;
+	}
+
+	action = &ev_actions[port];
+	action->count++;
+
+	/* call the handler */
+	action->handler(port, regs, action->data);
+
+	return 1;
+}
+
+evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler,
+			  void *data)
+{
+	if (ev_actions[port].handler != default_handler)
+		printf("WARN: Handler for port %d already registered, replacing\n",
+		       port);
+
+	ev_actions[port].data = data;
+	wmb();
+	ev_actions[port].handler = handler;
+	synch_set_bit(port, bound_ports);
+
+	return port;
+}
+
+void unbind_evtchn(evtchn_port_t port)
+{
+	struct evtchn_close close;
+	int rc;
+
+	if (ev_actions[port].handler == default_handler)
+		printf("WARN: No handler for port %d when unbinding\n", port);
+	mask_evtchn(port);
+	clear_evtchn(port);
+
+	ev_actions[port].handler = default_handler;
+	wmb();
+	ev_actions[port].data = NULL;
+	synch_clear_bit(port, bound_ports);
+
+	close.port = port;
+	rc = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
+	if (rc)
+		printf("WARN: close_port %d failed rc=%d. ignored\n", port, rc);
+}
+
+void default_handler(evtchn_port_t port, struct pt_regs *regs, void *ignore)
+{
+	debug("[Port %d] - event received\n", port);
+}
+
+/* Create a port available to the pal for exchanging notifications.
+ * Returns the result of the hypervisor call.
+ */
+
+/* Unfortunate confusion of terminology: the port is unbound as far
+ * as Xen is concerned, but we automatically bind a handler to it
+ * from inside mini-os.
+ */
+int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
+			 void *data, evtchn_port_t *port)
+{
+	int rc;
+
+	struct evtchn_alloc_unbound op;
+
+	op.dom = DOMID_SELF;
+	op.remote_dom = pal;
+	rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
+	if (rc) {
+		printf("ERROR: alloc_unbound failed with rc=%d", rc);
+		       return rc;
+	}
+	if (!handler)
+		handler = default_handler;
+	*port = bind_evtchn(op.port, handler, data);
+	return rc;
+}
+
+void eventchn_poll(void)
+{
+	do_hypervisor_callback(NULL);
+}
+
+/*
+ * Initially all events are without a handler and disabled
+ */
+void init_events(void)
+{
+	int i;
+
+	debug("%s\n", __func__);
+	/* initialize event handler */
+	for (i = 0; i < NR_EVS; i++) {
+		ev_actions[i].handler = default_handler;
+		mask_evtchn(i);
+	}
+}
+
+void fini_events(void)
+{
+	debug("%s\n", __func__);
+	/* Dealloc all events */
+	unbind_all_ports();
+}
+
diff --git a/drivers/xen/hypervisor.c b/drivers/xen/hypervisor.c
index 5883285142..975e552242 100644
--- a/drivers/xen/hypervisor.c
+++ b/drivers/xen/hypervisor.c
@@ -37,6 +37,7 @@
 #include <linux/bug.h>
 
 #include <xen/hvm.h>
+#include <xen/events.h>
 #include <xen/interface/memory.h>
 
 #define active_evtchns(cpu, sh, idx)	\
@@ -198,9 +199,7 @@ void do_hypervisor_callback(struct pt_regs *regs)
 			l2 &= ~(1UL << l2i);
 
 			port = (l1i * (sizeof(unsigned long) * 8)) + l2i;
-			/* TODO: handle new event: do_event(port, regs); */
-			/* Suppress -Wunused-but-set-variable */
-			(void)(port);
+			do_event(port, regs);
 		}
 	}
 
@@ -273,5 +272,6 @@ void xen_init(void)
 	debug("%s\n", __func__);
 
 	map_shared_info(NULL);
+	init_events();
 }
 
diff --git a/include/xen/events.h b/include/xen/events.h
new file mode 100644
index 0000000000..63abdf426b
--- /dev/null
+++ b/include/xen/events.h
@@ -0,0 +1,47 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ ****************************************************************************
+ * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
+ * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge
+ * (C) 2020 - EPAM Systems Inc.
+ ****************************************************************************
+ *
+ *        File: events.h
+ *      Author: Rolf Neugebauer (neugebar at dcs.gla.ac.uk)
+ *     Changes: Grzegorz Milos (gm281@cam.ac.uk)
+ *
+ *        Date: Jul 2003, changes Jun 2005
+ *
+ * Environment: Xen Minimal OS
+ * Description: Deals with events on the event channels
+ *
+ ****************************************************************************
+ */
+
+#ifndef _EVENTS_H_
+#define _EVENTS_H_
+
+#include <asm/xen/hypercall.h>
+#include <xen/interface/event_channel.h>
+
+typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *);
+
+void init_events(void);
+void fini_events(void);
+
+int do_event(evtchn_port_t port, struct pt_regs *regs);
+void unbind_evtchn(evtchn_port_t port);
+void unbind_all_ports(void);
+int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
+			 void *data, evtchn_port_t *port);
+
+static inline int notify_remote_via_evtchn(evtchn_port_t port)
+{
+	struct evtchn_send op;
+
+	op.port = port;
+	return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op);
+}
+
+void eventchn_poll(void);
+
+#endif /* _EVENTS_H_ */
-- 
2.17.1

  parent reply	other threads:[~2020-07-01 16:29 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 16:29 [PATCH 00/17] Add new board: Xen guest for ARM64 Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 01/17] armv8: Fix SMCC and ARM_PSCI_FW dependencies Anastasiia Lukianenko
2020-07-02  1:14   ` Peng Fan
2020-07-03  9:57     ` Nastya Vicodin
2020-07-01 16:29 ` [PATCH 02/17] Kconfig: Introduce CONFIG_XEN Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-03 12:42     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 03/17] board: Introduce xenguest_arm64 board Anastasiia Lukianenko
2020-07-02  1:28   ` Peng Fan
2020-07-02  7:18     ` Oleksandr Andrushchenko
2020-07-02  7:26       ` Heinrich Schuchardt
2020-07-02  7:57         ` Oleksandr Andrushchenko
2020-07-01 16:29 ` [PATCH 04/17] xen: Add essential and required interface headers Anastasiia Lukianenko
2020-07-02  1:30   ` Peng Fan
2020-07-03 12:46     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 05/17] xen: Port Xen hypervizor related code from mini-os Anastasiia Lukianenko
2020-07-01 17:46   ` Julien Grall
2020-07-03 12:21     ` Anastasiia Lukianenko
2020-07-03 13:38       ` Julien Grall
2020-07-08  8:55         ` Anastasiia Lukianenko
2020-07-16 13:16     ` Anastasiia Lukianenko
2020-07-01 16:29 ` Anastasiia Lukianenko [this message]
2020-07-03  3:50   ` [PATCH 06/17] xen: Port Xen event channel driver " Simon Glass
2020-07-03 12:34     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 07/17] serial: serial_xen: Add Xen PV serial driver Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-03 12:59     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 08/17] linux/compat.h: Add wait_event_timeout macro Anastasiia Lukianenko
2020-07-02  4:08   ` Heinrich Schuchardt
2020-07-03 13:02     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 09/17] lib: sscanf: add sscanf implementation Anastasiia Lukianenko
2020-07-02  4:04   ` Heinrich Schuchardt
2020-07-01 16:29 ` [PATCH 10/17] xen: Port Xen bus driver from mini-os Anastasiia Lukianenko
2020-07-02  4:43   ` Heinrich Schuchardt
2020-07-01 16:29 ` [PATCH 11/17] xen: Port Xen grant table " Anastasiia Lukianenko
2020-07-01 16:59   ` Julien Grall
2020-07-03 13:09     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 12/17] xen: pvblock: Add initial support for para-virtualized block driver Anastasiia Lukianenko
2020-07-02  4:17   ` Heinrich Schuchardt
2020-07-03 13:25     ` Anastasiia Lukianenko
2020-07-02  4:29   ` Heinrich Schuchardt
2020-07-02  5:30     ` Peng Fan
2020-07-03 14:14     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 13/17] xen: pvblock: Enumerate virtual block devices Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-01 16:29 ` [PATCH 14/17] xen: pvblock: Read XenStore configuration and initialize Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:08     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 15/17] xen: pvblock: Implement front-back protocol and do IO Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:10     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 16/17] xen: pvblock: Print found devices indices Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-01 16:29 ` [PATCH 17/17] board: xen: De-initialize before jumping to Linux Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:13     ` Anastasiia Lukianenko
2020-07-01 16:51 ` [PATCH 00/17] Add new board: Xen guest for ARM64 Anastasiia Lukianenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200701162959.9814-7-vicooodin@gmail.com \
    --to=vicooodin@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.