Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jul 2012 07:43:10 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 213884 for review
Message-ID:  <201207040743.q647hAsI094878@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@213884?ac=10

Change 213884 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/07/04 07:43:08

	At the low-level console layer of the Altera JTAG UART driver,
	introduce a new "adaptive" model for write flow control, which
	attempts to provide full reliability only when the JTAG client
	is present.  This is somewhat awkward to implement, as JTAG
	presence is indicated by the setting of a bit at an uncertain
	polling interval, which must be routinely cleared by software
	to detect continued presence.
	
	At higher layers in the driver, we will be able to rely on
	timers to "time out" an absent JTAG client, but at the console
	layer, we instead detect JTAG disappearing only at write-time,
	where we will spin polling for space in the write FIFO as long
	as the AC bit keeps being set bysoftware.  This requires some
	hand-waving at a poll interval; I'vechosen 10ms arbitrarily,
	which appears to work thus far, but might need re-tuning.  As
	with other properties at the low-level console layer, I've
	exposed the symbol for in-flight JTAG state up the stack so
	that the TTY layer can see and manipulate it as well.
	
	This removes the need for ALTERA_JTAG_UART_FC_DISABLE.  I will
	separately commit the changes to the TTY-layer driver.

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/sys/conf/options.mips#6 edit
.. //depot/projects/ctsrd/beribsd/src/sys/dev/altera/jtag_uart/altera_jtag_uart_cons.c#4 edit
.. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_DE4_MDROOT#6 edit
.. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_DE4_SDROOT#7 edit
.. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_SIM_MDROOT#3 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/sys/conf/options.mips#6 (text+ko) ====

@@ -47,8 +47,6 @@
 ISA_MIPS64	opt_cputype.h
 ISA_MIPS64v2	opt_cputype.h
 
-ALTERA_JTAG_UART_FC_DISABLE	opt_jtag_uart.h
-
 COMPAT_FREEBSD32	opt_compat.h
 
 YAMON		opt_global.h

==== //depot/projects/ctsrd/beribsd/src/sys/dev/altera/jtag_uart/altera_jtag_uart_cons.c#4 (text+ko) ====

@@ -31,8 +31,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include "opt_jtag_uart.h"
-
 #include <sys/param.h>
 #include <sys/cons.h>
 #include <sys/endian.h>
@@ -57,6 +55,7 @@
  */
 char		aju_cons_buffer_data;
 int		aju_cons_buffer_valid;
+int		aju_cons_jtag_present;
 struct mtx	aju_cons_lock;
 
 /*
@@ -71,6 +70,14 @@
 static cn_ungrab_t	aju_cnungrab;
 
 /*
+ * JTAG sets the ALTERA_JTAG_UART_CONTROL_AC bit whenever it accesses the
+ * FIFO.  This allows us to (sort of) tell when JTAG is present, so that we
+ * can adopt lossy, rather than blocking, behaviour when JTAG isn't there.
+ * When it is present, we do full flow control.
+ */
+#define	ALTERA_JTAG_UART_AC_POLL_DELAY	10000
+
+/*
  * I/O routines lifted from Deimos.  This is not only MIPS-specific, but also
  * BERI-specific, as we're hard coding the the address at which we expect to
  * find the Altera JTAG UART and using it unconditionally.  We use these
@@ -165,49 +172,9 @@
 }
 
 /*
- * Routines to query (and clear) the AC bit, which indicates that a JTAG
- * client has polled since it was last cleared.
- */
-__unused static int
-aju_cons_ac_get(void)
-{
-	uint32_t v;
-
-	AJU_CONSOLE_LOCK_ASSERT();
-
-	v = aju_cons_control_read();
-	return ((v & ALTERA_JTAG_UART_CONTROL_AC) != 0);
-
-}
-
-__unused static int
-aju_cons_ac_clear(void)
-{
-	uint32_t v;
-
-	AJU_CONSOLE_LOCK_ASSERT();
-
-	v = aju_cons_control_read();
-	v &= ~ALTERA_JTAG_UART_CONTROL_AC;
-	aju_cons_control_write(v);
-}
-
-/*
  * Slightly higher-level routines aware of buffering and flow control.
  */
 static int
-aju_cons_writable(void)
-{
-
-#ifdef ALTERA_JTAG_UART_FC_DISABLE
-	return (1);
-#else
-	return ((aju_cons_control_read() &
-	    ALTERA_JTAG_UART_CONTROL_WSPACE) != 0);
-#endif
-}
-
-static int
 aju_cons_readable(void)
 {
 	uint32_t v;
@@ -228,10 +195,41 @@
 static void
 aju_cons_write(char ch)
 {
+	uint32_t v;
 
 	AJU_CONSOLE_LOCK_ASSERT();
 
-	while (!aju_cons_writable());
+	/*
+	 * The flow control logic here is somewhat subtle: we want to wait for
+	 * write buffer space only while JTAG is present.  However, we can't
+	 * directly ask if JTAG is present -- just whether it's been seen
+	 * since we last cleared the ALTERA_JTAG_UART_CONTROL_AC bit.  As
+	 * such, implement a polling loop in which we both wait for space and
+	 * try to decide whether JTAG has disappeared on us.  We will have to
+	 * wait one complete polling delay to detect that JTAG has gone away,
+	 * but otherwise shouldn't wait any further once it has gone.  And we
+	 * had to wait for buffer space anyway, if it was there.
+	 *
+	 * XXXRW: The polling delay may require tuning.
+	 */
+	v = aju_cons_control_read();
+	if (v & ALTERA_JTAG_UART_CONTROL_AC) {
+		aju_cons_jtag_present = 1;
+		v &= ~ALTERA_JTAG_UART_CONTROL_AC;
+		aju_cons_control_write(v);
+	}
+	while ((v & ALTERA_JTAG_UART_CONTROL_WSPACE) == 0) {
+		if (!aju_cons_jtag_present)
+			return;
+		DELAY(ALTERA_JTAG_UART_AC_POLL_DELAY);
+		v = aju_cons_control_read();
+		if (v & ALTERA_JTAG_UART_CONTROL_AC) {
+			aju_cons_jtag_present = 1;
+			v &= ~ALTERA_JTAG_UART_CONTROL_AC;
+			aju_cons_control_write(v);
+		} else
+			aju_cons_jtag_present = 0;
+	}
 	aju_cons_data_write(ch);
 }
 
@@ -260,8 +258,15 @@
 static void
 aju_cninit(struct consdev *cp)
 {
+	uint32_t v;
 
 	AJU_CONSOLE_LOCK_INIT();
+
+	AJU_CONSOLE_LOCK();
+	v = aju_cons_control_read();
+	v &= ~ALTERA_JTAG_UART_CONTROL_AC;
+	aju_cons_control_write(v);
+	AJU_CONSOLE_UNLOCK();
 }
 
 static void

==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_DE4_MDROOT#6 (text+ko) ====

@@ -21,8 +21,6 @@
 makeoptions	MFS_IMAGE=/local/scratch/rnw24/mdroot.img
 options 	ROOTDEVNAME=\"ufs:md0\"
 
-options 	ALTERA_JTAG_UART_FC_DISABLE
-
 device		altera_avgen
 device		altera_jtag_uart
 device		altera_sdcard

==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_DE4_SDROOT#7 (text+ko) ====

@@ -14,8 +14,6 @@
 
 options 	ROOTDEVNAME=\"ufs:altera_sdcard0\"
 
-options 	ALTERA_JTAG_UART_FC_DISABLE
-
 device		altera_avgen
 device		altera_jtag_uart
 device		altera_sdcard

==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_SIM_MDROOT#3 (text+ko) ====

@@ -20,8 +20,6 @@
 makeoptions	MFS_IMAGE=/local/scratch/rnw24/mdroot.img
 options 	ROOTDEVNAME=\"ufs:md0\"
 
-options 	ALTERA_JTAG_UART_FC_DISABLE
-
 device		altera_avgen
 device		altera_jtag_uart
 device		altera_sdcard



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207040743.q647hAsI094878>