From owner-p4-projects@FreeBSD.ORG Wed Jul 4 07:43:13 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B250E1065673; Wed, 4 Jul 2012 07:43:11 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 32CDC106566B for ; Wed, 4 Jul 2012 07:43:11 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 191778FC17 for ; Wed, 4 Jul 2012 07:43:11 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q647hAjJ094881 for ; Wed, 4 Jul 2012 07:43:10 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q647hAsI094878 for perforce@freebsd.org; Wed, 4 Jul 2012 07:43:10 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 4 Jul 2012 07:43:10 GMT Message-Id: <201207040743.q647hAsI094878@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 213884 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2012 07:43:13 -0000 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 __FBSDID("$FreeBSD$"); -#include "opt_jtag_uart.h" - #include #include #include @@ -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