linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: char: hvc: add Blackfin JTAG console support
@ 2011-01-11  2:43 Mike Frysinger
  2011-01-11  3:08 ` Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-01-11  2:43 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Alan Cox
  Cc: uclinux-dist-devel, linux-kernel, Arnd Bergmann

This converts the existing bfin_jtag_comm TTY driver to the HVC layer so
that the common HVC code can worry about all of the TTY/polling crap and
leave the Blackfin code to worry about the Blackfin bits.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/char/Kconfig         |    9 ++++
 drivers/char/Makefile        |    1 +
 drivers/char/hvc_bfin_jtag.c |  105 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/hvc_bfin_jtag.c

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 4498e2a..9c7fed8 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -731,6 +731,15 @@ config HVC_UDBG
        select HVC_DRIVER
        default n
 
+config HVC_BFIN_JTAG
+	bool "Blackfin JTAG console"
+	depends on BLACKFIN
+	select HVC_DRIVER
+	help
+	 This console uses the Blackfin JTAG to create a console under the
+	 the HVC driver.  If you don't have JTAG, then you probably don't
+	 want this option.
+
 config VIRTIO_CONSOLE
 	tristate "Virtio console"
 	depends on VIRTIO
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index ccd666f..ae0e062 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_HVC_IRQ)		+= hvc_irq.o
 obj-$(CONFIG_HVC_XEN)		+= hvc_xen.o
 obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
+obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
 obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
 obj-$(CONFIG_RAW_DRIVER)	+= raw.o
 obj-$(CONFIG_SGI_SNSC)		+= snsc.o snsc_event.o
diff --git a/drivers/char/hvc_bfin_jtag.c b/drivers/char/hvc_bfin_jtag.c
new file mode 100644
index 0000000..31d6cc6
--- /dev/null
+++ b/drivers/char/hvc_bfin_jtag.c
@@ -0,0 +1,105 @@
+/*
+ * Console via Blackfin JTAG Communication
+ *
+ * Copyright 2008-2011 Analog Devices Inc.
+ *
+ * Enter bugs at http://blackfin.uclinux.org/
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+
+#include "hvc_console.h"
+
+/* See the Debug/Emulation chapter in the HRM */
+#define EMUDOF   0x00000001	/* EMUDAT_OUT full & valid */
+#define EMUDIF   0x00000002	/* EMUDAT_IN full & valid */
+#define EMUDOOVF 0x00000004	/* EMUDAT_OUT overflow */
+#define EMUDIOVF 0x00000008	/* EMUDAT_IN overflow */
+
+/* Helper functions to glue the register API to simple C operations */
+static inline uint32_t bfin_write_emudat(uint32_t emudat)
+{
+	__asm__ __volatile__("emudat = %0;" : : "d"(emudat));
+	return emudat;
+}
+
+static inline uint32_t bfin_read_emudat(void)
+{
+	uint32_t emudat;
+	__asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
+	return emudat;
+}
+
+/* Send data to the host */
+static int hvc_bfin_put_chars(uint32_t vt, const char *buf, int count)
+{
+	static uint32_t outbound_len;
+	uint32_t emudat;
+	int ret;
+
+	if (bfin_read_DBGSTAT() & EMUDOF)
+		return 0;
+
+	if (!outbound_len) {
+		outbound_len = count;
+		bfin_write_emudat(outbound_len);
+		return 0;
+	}
+
+	ret = min(outbound_len, (uint32_t)4);
+	memcpy(&emudat, buf, ret);
+	bfin_write_emudat(emudat);
+	outbound_len -= ret;
+
+	return ret;
+}
+
+/* Receive data from the host */
+static int hvc_bfin_get_chars(uint32_t vt, char *buf, int count)
+{
+	static uint32_t inbound_len;
+	uint32_t emudat;
+	int ret;
+
+	if (!(bfin_read_DBGSTAT() & EMUDIF))
+		return 0;
+	emudat = bfin_read_emudat();
+
+	if (!inbound_len) {
+		inbound_len = emudat;
+		return 0;
+	}
+
+	ret = min(inbound_len, (uint32_t)4);
+	memcpy(buf, &emudat, ret);
+	inbound_len -= ret;
+
+	return ret;
+}
+
+/* Glue the HVC layers to the Blackfin layers */
+static const struct hv_ops hvc_bfin_get_put_ops = {
+	.get_chars = hvc_bfin_get_chars,
+	.put_chars = hvc_bfin_put_chars,
+};
+
+static int __init hvc_bfin_console_init(void)
+{
+	hvc_instantiate(0, 0, &hvc_bfin_get_put_ops);
+	return 0;
+}
+console_initcall(hvc_bfin_console_init);
+
+static int __init hvc_bfin_init(void)
+{
+	hvc_alloc(0, 0, &hvc_bfin_get_put_ops, 128);
+	return 0;
+}
+device_initcall(hvc_bfin_init);
-- 
1.7.4.rc1


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

* Re: [PATCH] drivers: char: hvc: add Blackfin JTAG console support
  2011-01-11  2:43 [PATCH] drivers: char: hvc: add Blackfin JTAG console support Mike Frysinger
@ 2011-01-11  3:08 ` Mike Frysinger
  2011-01-11  3:41   ` Arnd Bergmann
       [not found] ` <1294713837-4929-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
  2011-02-05  1:45 ` [PATCH v2] " Mike Frysinger
  2 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2011-01-11  3:08 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Alan Cox
  Cc: uclinux-dist-devel, linux-kernel, Arnd Bergmann

On Mon, Jan 10, 2011 at 21:43, Mike Frysinger wrote:
> This converts the existing bfin_jtag_comm TTY driver to the HVC layer so
> that the common HVC code can worry about all of the TTY/polling crap and
> leave the Blackfin code to worry about the Blackfin bits.

ive noticed a few downsides of converting to this ...

hvc cant be built as a module.  but not that big of a deal i guess.

throughput seems to be a bit lower.  the Blackfin JTAG hardware has
basically a 4 byte fifo that is filled/consumed in a single shot.  and
the Blackfin can produce much faster than the host can consume.  so
atm, i have it send out 4 bytes, and the hvc layers take care of
calling back into me at some point.  if i add a busy loop to run a few
hundred milliseconds (like HZ/4), it runs much nicer.  but obviously
doesnt give anyone else time to run.  i cant schedule or anything as
the write layers are called with a spin_lock_irqsave.  any tips for
how to speed this up a bit ?  or is it a wash with hvc ?

the code size also increased a bit ... old driver added up to ~1.7KiB
while hvc stuff is like ~4KiB.  but hvc does a nice job of keeping the
Blackfin-specific piece small.  so i guess it's a wash.
-mike

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

* Re: [PATCH] drivers: char: hvc: add Blackfin JTAG console support
  2011-01-11  3:08 ` Mike Frysinger
@ 2011-01-11  3:41   ` Arnd Bergmann
  2011-01-11  5:31     ` Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2011-01-11  3:41 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: linux-serial, Greg Kroah-Hartman, Alan Cox, uclinux-dist-devel,
	linux-kernel

On Tuesday 11 January 2011, Mike Frysinger wrote:
> throughput seems to be a bit lower.  the Blackfin JTAG hardware has
> basically a 4 byte fifo that is filled/consumed in a single shot.  and
> the Blackfin can produce much faster than the host can consume.  so
> atm, i have it send out 4 bytes, and the hvc layers take care of
> calling back into me at some point.  if i add a busy loop to run a few
> hundred milliseconds (like HZ/4), it runs much nicer.  but obviously
> doesnt give anyone else time to run.  i cant schedule or anything as
> the write layers are called with a spin_lock_irqsave.  any tips for
> how to speed this up a bit ?  or is it a wash with hvc ?

You could try lowering the hvc MIN_TIMEOUT value. If you want to
change it for blackfin, you could probably make it a configuration
option. However, if it really takes a few milliseconds that you need
to wait between two accesses, MIN_TIMEOUT should already be small
enough.

You should really not need to sleep in your output function, as
the khvcd() timeout logic tries handling this in the best way.
There may be a bug in that logic though (wouldn't be the first one
there), so try to see what the timeouts are when you get into 
this problem.

	Arnd

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

* Re: [PATCH] drivers: char: hvc: add Blackfin JTAG console support
  2011-01-11  3:41   ` Arnd Bergmann
@ 2011-01-11  5:31     ` Mike Frysinger
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-01-11  5:31 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-serial, Greg Kroah-Hartman, Alan Cox, uclinux-dist-devel,
	linux-kernel

On Mon, Jan 10, 2011 at 22:41, Arnd Bergmann wrote:
> On Tuesday 11 January 2011, Mike Frysinger wrote:
>> throughput seems to be a bit lower.  the Blackfin JTAG hardware has
>> basically a 4 byte fifo that is filled/consumed in a single shot.  and
>> the Blackfin can produce much faster than the host can consume.  so
>> atm, i have it send out 4 bytes, and the hvc layers take care of
>> calling back into me at some point.  if i add a busy loop to run a few
>> hundred milliseconds (like HZ/4), it runs much nicer.  but obviously
>> doesnt give anyone else time to run.  i cant schedule or anything as
>> the write layers are called with a spin_lock_irqsave.  any tips for
>> how to speed this up a bit ?  or is it a wash with hvc ?
>
> You could try lowering the hvc MIN_TIMEOUT value. If you want to
> change it for blackfin, you could probably make it a configuration
> option. However, if it really takes a few milliseconds that you need
> to wait between two accesses, MIN_TIMEOUT should already be small
> enough.
>
> You should really not need to sleep in your output function, as
> the khvcd() timeout logic tries handling this in the best way.
> There may be a bug in that logic though (wouldn't be the first one
> there), so try to see what the timeouts are when you get into
> this problem.

np, i'll poke around a bit.  i'm ok with merging this driver now since
it seems to be functionality equivalent to the old code.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] drivers: char: hvc: add Blackfin JTAG console support
       [not found] ` <1294713837-4929-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
@ 2011-02-03 22:20   ` Greg KH
  2011-02-04  0:14     ` [uclinux-dist-devel] " Mike Frysinger
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2011-02-03 22:20 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: Arnd Bergmann, Greg Kroah-Hartman,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Alan Cox

On Mon, Jan 10, 2011 at 09:43:57PM -0500, Mike Frysinger wrote:
> This converts the existing bfin_jtag_comm TTY driver to the HVC layer so
> that the common HVC code can worry about all of the TTY/polling crap and
> leave the Blackfin code to worry about the Blackfin bits.

This patch no longer applies to the linux-next tree.  Can you redo it
and resend it?

thanks,

greg k-h

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

* Re: [uclinux-dist-devel] [PATCH] drivers: char: hvc: add Blackfin JTAG console support
  2011-02-03 22:20   ` Greg KH
@ 2011-02-04  0:14     ` Mike Frysinger
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-02-04  0:14 UTC (permalink / raw)
  To: Greg KH
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, linux-serial,
	uclinux-dist-devel, Alan Cox

On Thu, Feb 3, 2011 at 17:20, Greg KH wrote:
> On Mon, Jan 10, 2011 at 09:43:57PM -0500, Mike Frysinger wrote:
>> This converts the existing bfin_jtag_comm TTY driver to the HVC layer so
>> that the common HVC code can worry about all of the TTY/polling crap and
>> leave the Blackfin code to worry about the Blackfin bits.
>
> This patch no longer applies to the linux-next tree.  Can you redo it
> and resend it?

guessing it's due to the tty reorg.  np.
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2] drivers: char: hvc: add Blackfin JTAG console support
  2011-01-11  2:43 [PATCH] drivers: char: hvc: add Blackfin JTAG console support Mike Frysinger
  2011-01-11  3:08 ` Mike Frysinger
       [not found] ` <1294713837-4929-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
@ 2011-02-05  1:45 ` Mike Frysinger
  2 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2011-02-05  1:45 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Alan Cox; +Cc: uclinux-dist-devel

This converts the existing bfin_jtag_comm TTY driver to the HVC layer so
that the common HVC code can worry about all of the TTY/polling crap and
leave the Blackfin code to worry about the Blackfin bits.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
	- rebase after tty reorg

 drivers/char/Kconfig            |    9 +++
 drivers/tty/hvc/Makefile        |    1 +
 drivers/tty/hvc/hvc_bfin_jtag.c |  105 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/hvc/hvc_bfin_jtag.c

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index b7980a83..17f9b96 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -691,6 +691,15 @@ config HVC_DCC
 	 driver. This console is used through a JTAG only on ARM. If you don't have
 	 a JTAG then you probably don't want this option.
 
+config HVC_BFIN_JTAG
+	bool "Blackfin JTAG console"
+	depends on BLACKFIN
+	select HVC_DRIVER
+	help
+	 This console uses the Blackfin JTAG to create a console under the
+	 the HVC driver.  If you don't have JTAG, then you probably don't
+	 want this option.
+
 config VIRTIO_CONSOLE
 	tristate "Virtio console"
 	depends on VIRTIO
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index e6bed5f..7b0edbc 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -9,5 +9,6 @@ obj-$(CONFIG_HVC_IRQ)		+= hvc_irq.o
 obj-$(CONFIG_HVC_XEN)		+= hvc_xen.o
 obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
+obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS)		+= hvcs.o
 obj-$(CONFIG_VIRTIO_CONSOLE)	+= virtio_console.o
diff --git a/drivers/tty/hvc/hvc_bfin_jtag.c b/drivers/tty/hvc/hvc_bfin_jtag.c
new file mode 100644
index 0000000..31d6cc6
--- /dev/null
+++ b/drivers/tty/hvc/hvc_bfin_jtag.c
@@ -0,0 +1,105 @@
+/*
+ * Console via Blackfin JTAG Communication
+ *
+ * Copyright 2008-2011 Analog Devices Inc.
+ *
+ * Enter bugs at http://blackfin.uclinux.org/
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+
+#include "hvc_console.h"
+
+/* See the Debug/Emulation chapter in the HRM */
+#define EMUDOF   0x00000001	/* EMUDAT_OUT full & valid */
+#define EMUDIF   0x00000002	/* EMUDAT_IN full & valid */
+#define EMUDOOVF 0x00000004	/* EMUDAT_OUT overflow */
+#define EMUDIOVF 0x00000008	/* EMUDAT_IN overflow */
+
+/* Helper functions to glue the register API to simple C operations */
+static inline uint32_t bfin_write_emudat(uint32_t emudat)
+{
+	__asm__ __volatile__("emudat = %0;" : : "d"(emudat));
+	return emudat;
+}
+
+static inline uint32_t bfin_read_emudat(void)
+{
+	uint32_t emudat;
+	__asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
+	return emudat;
+}
+
+/* Send data to the host */
+static int hvc_bfin_put_chars(uint32_t vt, const char *buf, int count)
+{
+	static uint32_t outbound_len;
+	uint32_t emudat;
+	int ret;
+
+	if (bfin_read_DBGSTAT() & EMUDOF)
+		return 0;
+
+	if (!outbound_len) {
+		outbound_len = count;
+		bfin_write_emudat(outbound_len);
+		return 0;
+	}
+
+	ret = min(outbound_len, (uint32_t)4);
+	memcpy(&emudat, buf, ret);
+	bfin_write_emudat(emudat);
+	outbound_len -= ret;
+
+	return ret;
+}
+
+/* Receive data from the host */
+static int hvc_bfin_get_chars(uint32_t vt, char *buf, int count)
+{
+	static uint32_t inbound_len;
+	uint32_t emudat;
+	int ret;
+
+	if (!(bfin_read_DBGSTAT() & EMUDIF))
+		return 0;
+	emudat = bfin_read_emudat();
+
+	if (!inbound_len) {
+		inbound_len = emudat;
+		return 0;
+	}
+
+	ret = min(inbound_len, (uint32_t)4);
+	memcpy(buf, &emudat, ret);
+	inbound_len -= ret;
+
+	return ret;
+}
+
+/* Glue the HVC layers to the Blackfin layers */
+static const struct hv_ops hvc_bfin_get_put_ops = {
+	.get_chars = hvc_bfin_get_chars,
+	.put_chars = hvc_bfin_put_chars,
+};
+
+static int __init hvc_bfin_console_init(void)
+{
+	hvc_instantiate(0, 0, &hvc_bfin_get_put_ops);
+	return 0;
+}
+console_initcall(hvc_bfin_console_init);
+
+static int __init hvc_bfin_init(void)
+{
+	hvc_alloc(0, 0, &hvc_bfin_get_put_ops, 128);
+	return 0;
+}
+device_initcall(hvc_bfin_init);
-- 
1.7.4


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

end of thread, other threads:[~2011-02-05  1:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-11  2:43 [PATCH] drivers: char: hvc: add Blackfin JTAG console support Mike Frysinger
2011-01-11  3:08 ` Mike Frysinger
2011-01-11  3:41   ` Arnd Bergmann
2011-01-11  5:31     ` Mike Frysinger
     [not found] ` <1294713837-4929-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2011-02-03 22:20   ` Greg KH
2011-02-04  0:14     ` [uclinux-dist-devel] " Mike Frysinger
2011-02-05  1:45 ` [PATCH v2] " Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).