All of lore.kernel.org
 help / color / mirror / Atom feed
* [rfc/patch] use hvc for xen console
@ 2007-02-13 10:36 Gerd Hoffmann
  2007-02-13 10:38 ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2007-02-13 10:36 UTC (permalink / raw)
  To: Virtualization Mailing List, Xen devel list

  Hi,

Here is a patch (on top of the paravirt patch queue) which makes xen
guests use the hvc_console.c infrastructure for the console, thereby
greatly reducing the amount console code.  xvc0 is gone too, hvc0 is
used instead.

cheers,
  Gerd

-- 
Gerd Hoffmann <kraxel@suse.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfc/patch] use hvc for xen console
  2007-02-13 10:36 [rfc/patch] use hvc for xen console Gerd Hoffmann
@ 2007-02-13 10:38 ` Gerd Hoffmann
  2007-02-13 16:13   ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2007-02-13 10:38 UTC (permalink / raw)
  To: Virtualization Mailing List, Xen devel list

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

Gerd Hoffmann wrote:
>   Hi,
> 
> Here is a patch (on top of the paravirt patch queue) which makes xen

Oops, forgot the patch here is it ...

[-- Attachment #2: hvc --]
[-- Type: text/plain, Size: 5908 bytes --]

---
 arch/i386/Kconfig.debug       |   24 ++++----
 arch/i386/xen/Kconfig         |    1 
 drivers/char/hvc_console.c    |    4 +
 drivers/xen/console/Makefile  |    3 -
 drivers/xen/console/hvc_xen.c |  124 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 13 deletions(-)

Index: paravirt-2.6.20-hg749/arch/i386/Kconfig.debug
===================================================================
--- paravirt-2.6.20-hg749.orig/arch/i386/Kconfig.debug
+++ paravirt-2.6.20-hg749/arch/i386/Kconfig.debug
@@ -6,18 +6,18 @@ config TRACE_IRQFLAGS_SUPPORT
 
 source "lib/Kconfig.debug"
 
-config EARLY_PRINTK
-	bool "Early printk" if EMBEDDED && DEBUG_KERNEL
-	default y
-	help
-	  Write kernel log output directly into the VGA buffer or to a serial
-	  port.
-
-	  This is useful for kernel debugging when your machine crashes very
-	  early before the console code is initialized. For normal operation
-	  it is not recommended because it looks ugly and doesn't cooperate
-	  with klogd/syslogd or the X server. You should normally N here,
-	  unless you want to debug such a crash.
+#config EARLY_PRINTK
+#	bool "Early printk" if EMBEDDED && DEBUG_KERNEL
+#	default y
+#	help
+#	  Write kernel log output directly into the VGA buffer or to a serial
+#	  port.
+#
+#	  This is useful for kernel debugging when your machine crashes very
+#	  early before the console code is initialized. For normal operation
+#	  it is not recommended because it looks ugly and doesn't cooperate
+#	  with klogd/syslogd or the X server. You should normally N here,
+#	  unless you want to debug such a crash.
 
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
Index: paravirt-2.6.20-hg749/arch/i386/xen/Kconfig
===================================================================
--- paravirt-2.6.20-hg749.orig/arch/i386/xen/Kconfig
+++ paravirt-2.6.20-hg749/arch/i386/xen/Kconfig
@@ -5,6 +5,7 @@
 config XEN
 	bool "Enable support for Xen hypervisor"
 	depends PARAVIRT
+	select HVC_DRIVER
 	default y
 	help
 	  This is the Linux Xen port.
Index: paravirt-2.6.20-hg749/drivers/char/hvc_console.c
===================================================================
--- paravirt-2.6.20-hg749.orig/drivers/char/hvc_console.c
+++ paravirt-2.6.20-hg749/drivers/char/hvc_console.c
@@ -49,6 +49,10 @@
 
 #define TIMEOUT		(10)
 
+#ifndef NO_IRQ
+#define NO_IRQ 0
+#endif
+
 /*
  * Wait this long per iteration while trying to push buffered data to the
  * hypervisor before allowing the tty to complete a close operation.
Index: paravirt-2.6.20-hg749/drivers/xen/console/Makefile
===================================================================
--- paravirt-2.6.20-hg749.orig/drivers/xen/console/Makefile
+++ paravirt-2.6.20-hg749/drivers/xen/console/Makefile
@@ -1,2 +1,3 @@
 
-obj-y	:= console.o xencons_ring.o
+#obj-y	:= console.o xencons_ring.o
+obj-y	:= hvc_xen.o xencons_ring.o
Index: paravirt-2.6.20-hg749/drivers/xen/console/hvc_xen.c
===================================================================
--- /dev/null
+++ paravirt-2.6.20-hg749/drivers/xen/console/hvc_xen.c
@@ -0,0 +1,124 @@
+/*
+ * xen console driver interface to hvc_console.c
+ *
+ * (c) 2007 Gerd Hoffmann <kraxel@suse.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/types.h>
+
+#include <xen/xencons.h>
+#include <asm/hypervisor.h>
+
+#include "../../char/hvc_console.h"
+
+#define HVC_COOKIE   0x58656e /* "Xen" in hex */
+#define HVC_READBUF       256
+
+static DEFINE_SPINLOCK(lock);
+static struct hvc_struct *hvc;
+static char rbuf[HVC_READBUF];
+static int rin, rout;
+
+static int write_console(uint32_t vtermno, const char *buf, int count)
+{
+	int rc;
+
+	rc = xencons_ring_send(buf, count);
+	return rc;
+}
+
+static int read_console(uint32_t vtermno, char *buf, int len)
+{
+	unsigned long flags;
+	int count;
+
+	spin_lock_irqsave(&lock, flags);
+	count = rin - rout;
+	if (count > len)
+		count = len;
+	if (count) {
+		memcpy(buf, rbuf + rout, count);
+		rout += count;
+		if (rin == rout)
+			rin = 0, rout = 0;
+	}
+	spin_unlock_irqrestore(&lock, flags);
+	return count;
+}
+
+void xencons_rx(char *buf, unsigned len)
+{
+	unsigned long flags;
+	int count;
+
+	spin_lock_irqsave(&lock, flags);
+	count = HVC_READBUF - rin;
+	if (count > len)
+		count = len;
+	memcpy(rbuf + rin, buf, count);
+	rin += count;
+	spin_unlock_irqrestore(&lock, flags);
+}
+
+void xencons_tx(void)
+{
+	/* make xencons_ring.c happy */
+}
+
+static struct hv_ops hvc_ops = {
+	.get_chars = read_console,
+	.put_chars = write_console,
+};
+
+static int __init xen_init(void)
+{
+	struct hvc_struct *hp;
+
+	if (!is_running_on_xen())
+		return 0;
+
+	xencons_ring_init();
+	hp = hvc_alloc(HVC_COOKIE, 0 /* NO_IRQ */, &hvc_ops, HVC_READBUF);
+	if (IS_ERR(hp))
+		return PTR_ERR(hp);
+
+	hvc = hp;
+	return 0;
+}
+
+static void __exit xen_fini(void)
+{
+	if (hvc)
+		hvc_remove(hvc);
+}
+
+static int xen_cons_init(void)
+{
+	if (!is_running_on_xen())
+		return 0;
+
+	hvc_instantiate(HVC_COOKIE, 0, &hvc_ops);
+	return 0;
+}
+
+module_init(xen_init);
+module_exit(xen_fini);
+console_initcall(xen_cons_init);

[-- Attachment #3: Type: text/plain, Size: 165 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfc/patch] use hvc for xen console
  2007-02-13 10:38 ` Gerd Hoffmann
@ 2007-02-13 16:13   ` Gerd Hoffmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2007-02-13 16:13 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Virtualization Mailing List, Xen devel list

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

Gerd Hoffmann wrote:
> Gerd Hoffmann wrote:
>>   Hi,
>>
>> Here is a patch (on top of the paravirt patch queue) which makes xen
> 
> Oops, forgot the patch here is it ...

New version of the patch, drops the dependency on xencons_ring.c, drops
a bunch of glue code, features a irq-driven console.

cheers,
  Gerd

-- 
Gerd Hoffmann <kraxel@suse.de>

[-- Attachment #2: hvc --]
[-- Type: text/plain, Size: 7624 bytes --]

---
 arch/i386/Kconfig.debug       |   24 +++----
 arch/i386/xen/Kconfig         |    1 
 arch/i386/xen/events.c        |    3 
 drivers/char/hvc_console.c    |    4 +
 drivers/xen/console/Makefile  |    3 
 drivers/xen/console/hvc_xen.c |  135 ++++++++++++++++++++++++++++++++++++++++++
 include/xen/events.h          |    1 
 7 files changed, 157 insertions(+), 14 deletions(-)

Index: paravirt-2.6.20-hg749/arch/i386/Kconfig.debug
===================================================================
--- paravirt-2.6.20-hg749.orig/arch/i386/Kconfig.debug
+++ paravirt-2.6.20-hg749/arch/i386/Kconfig.debug
@@ -6,18 +6,18 @@ config TRACE_IRQFLAGS_SUPPORT
 
 source "lib/Kconfig.debug"
 
-config EARLY_PRINTK
-	bool "Early printk" if EMBEDDED && DEBUG_KERNEL
-	default y
-	help
-	  Write kernel log output directly into the VGA buffer or to a serial
-	  port.
-
-	  This is useful for kernel debugging when your machine crashes very
-	  early before the console code is initialized. For normal operation
-	  it is not recommended because it looks ugly and doesn't cooperate
-	  with klogd/syslogd or the X server. You should normally N here,
-	  unless you want to debug such a crash.
+#config EARLY_PRINTK
+#	bool "Early printk" if EMBEDDED && DEBUG_KERNEL
+#	default y
+#	help
+#	  Write kernel log output directly into the VGA buffer or to a serial
+#	  port.
+#
+#	  This is useful for kernel debugging when your machine crashes very
+#	  early before the console code is initialized. For normal operation
+#	  it is not recommended because it looks ugly and doesn't cooperate
+#	  with klogd/syslogd or the X server. You should normally N here,
+#	  unless you want to debug such a crash.
 
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
Index: paravirt-2.6.20-hg749/arch/i386/xen/Kconfig
===================================================================
--- paravirt-2.6.20-hg749.orig/arch/i386/xen/Kconfig
+++ paravirt-2.6.20-hg749/arch/i386/xen/Kconfig
@@ -5,6 +5,7 @@
 config XEN
 	bool "Enable support for Xen hypervisor"
 	depends PARAVIRT
+	select HVC_DRIVER
 	default y
 	help
 	  This is the Linux Xen port.
Index: paravirt-2.6.20-hg749/drivers/char/hvc_console.c
===================================================================
--- paravirt-2.6.20-hg749.orig/drivers/char/hvc_console.c
+++ paravirt-2.6.20-hg749/drivers/char/hvc_console.c
@@ -49,6 +49,10 @@
 
 #define TIMEOUT		(10)
 
+#ifndef NO_IRQ
+#define NO_IRQ 0
+#endif
+
 /*
  * Wait this long per iteration while trying to push buffered data to the
  * hypervisor before allowing the tty to complete a close operation.
Index: paravirt-2.6.20-hg749/drivers/xen/console/Makefile
===================================================================
--- paravirt-2.6.20-hg749.orig/drivers/xen/console/Makefile
+++ paravirt-2.6.20-hg749/drivers/xen/console/Makefile
@@ -1,2 +1,3 @@
 
-obj-y	:= console.o xencons_ring.o
+#obj-y	:= console.o xencons_ring.o
+obj-y	:= hvc_xen.o
Index: paravirt-2.6.20-hg749/drivers/xen/console/hvc_xen.c
===================================================================
--- /dev/null
+++ paravirt-2.6.20-hg749/drivers/xen/console/hvc_xen.c
@@ -0,0 +1,135 @@
+/*
+ * xen console driver interface to hvc_console.c
+ *
+ * (c) 2007 Gerd Hoffmann <kraxel@suse.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/types.h>
+
+#include <asm/hypervisor.h>
+#include <xen/page.h>
+#include <xen/events.h>
+#include <xen/xencons.h>
+#include <xen/interface/io/console.h>
+
+#include "../../char/hvc_console.h"
+
+#define HVC_COOKIE   0x58656e /* "Xen" in hex */
+
+static struct hvc_struct *hvc;
+static int xencons_irq;
+
+/* ------------------------------------------------------------------ */
+
+static inline struct xencons_interface *xencons_interface(void)
+{
+	return mfn_to_virt(xen_start_info->console.domU.mfn);
+}
+
+static inline void notify_daemon(void)
+{
+	/* Use evtchn: this is called early, before irq is set up. */
+	notify_remote_via_evtchn(xen_start_info->console.domU.evtchn);
+}
+
+static int write_console(uint32_t vtermno, const char *data, int len)
+{
+	struct xencons_interface *intf = xencons_interface();
+	XENCONS_RING_IDX cons, prod;
+	int sent = 0;
+
+	cons = intf->out_cons;
+	prod = intf->out_prod;
+	mb();
+	BUG_ON((prod - cons) > sizeof(intf->out));
+
+	while ((sent < len) && ((prod - cons) < sizeof(intf->out)))
+		intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++];
+
+	wmb();
+	intf->out_prod = prod;
+
+	notify_daemon();
+	return sent;
+}
+
+static int read_console(uint32_t vtermno, char *buf, int len)
+{
+	struct xencons_interface *intf = xencons_interface();
+	XENCONS_RING_IDX cons, prod;
+	int recv = 0;
+
+	cons = intf->in_cons;
+	prod = intf->in_prod;
+	mb();
+	BUG_ON((prod - cons) > sizeof(intf->in));
+
+	while (cons != prod && recv < len)
+		buf[recv++] = intf->in[MASK_XENCONS_IDX(cons++,intf->in)];
+
+	mb();
+	intf->in_cons = cons;
+
+	notify_daemon();
+	return recv;
+}
+
+static struct hv_ops hvc_ops = {
+	.get_chars = read_console,
+	.put_chars = write_console,
+};
+
+static int __init xen_init(void)
+{
+	struct hvc_struct *hp;
+
+	if (!is_running_on_xen())
+		return 0;
+
+	xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn);
+	if (xencons_irq < 0)
+		xencons_irq = 0 /* NO_IRQ */;
+	hp = hvc_alloc(HVC_COOKIE, xencons_irq, &hvc_ops, 256);
+	if (IS_ERR(hp))
+		return PTR_ERR(hp);
+
+	hvc = hp;
+	return 0;
+}
+
+static void __exit xen_fini(void)
+{
+	if (hvc)
+		hvc_remove(hvc);
+}
+
+static int xen_cons_init(void)
+{
+	if (!is_running_on_xen())
+		return 0;
+
+	hvc_instantiate(HVC_COOKIE, 0, &hvc_ops);
+	return 0;
+}
+
+module_init(xen_init);
+module_exit(xen_fini);
+console_initcall(xen_cons_init);
Index: paravirt-2.6.20-hg749/arch/i386/xen/events.c
===================================================================
--- paravirt-2.6.20-hg749.orig/arch/i386/xen/events.c
+++ paravirt-2.6.20-hg749/arch/i386/xen/events.c
@@ -202,7 +202,7 @@ static int find_unbound_irq(void)
 	return irq;
 }
 
-static int bind_evtchn_to_irq(unsigned int evtchn)
+int bind_evtchn_to_irq(unsigned int evtchn)
 {
 	int irq;
 
@@ -226,6 +226,7 @@ static int bind_evtchn_to_irq(unsigned i
 
 	return irq;
 }
+EXPORT_SYMBOL_GPL(bind_evtchn_to_irq);
 
 static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
 {
Index: paravirt-2.6.20-hg749/include/xen/events.h
===================================================================
--- paravirt-2.6.20-hg749.orig/include/xen/events.h
+++ paravirt-2.6.20-hg749/include/xen/events.h
@@ -5,6 +5,7 @@
 #include <xen/interface/event_channel.h>
 #include <asm/hypercall.h>
 
+int bind_evtchn_to_irq(unsigned int evtchn);
 int bind_evtchn_to_irqhandler(unsigned int evtchn,
 			      irqreturn_t (*handler)(int, void *),
 			      unsigned long irqflags, const char *devname,

[-- Attachment #3: Type: text/plain, Size: 165 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-13 16:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-13 10:36 [rfc/patch] use hvc for xen console Gerd Hoffmann
2007-02-13 10:38 ` Gerd Hoffmann
2007-02-13 16:13   ` Gerd Hoffmann

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.