From owner-svn-src-all@freebsd.org Wed Aug 17 20:24:15 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D47FCBBCAF6; Wed, 17 Aug 2016 20:24:15 +0000 (UTC) (envelope-from landonf@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B09A6165C; Wed, 17 Aug 2016 20:24:15 +0000 (UTC) (envelope-from landonf@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7HKOEIN002396; Wed, 17 Aug 2016 20:24:14 GMT (envelope-from landonf@FreeBSD.org) Received: (from landonf@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7HKOECi002393; Wed, 17 Aug 2016 20:24:14 GMT (envelope-from landonf@FreeBSD.org) Message-Id: <201608172024.u7HKOECi002393@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: landonf set sender to landonf@FreeBSD.org using -f From: "Landon J. Fuller" Date: Wed, 17 Aug 2016 20:24:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304314 - in head/sys/mips: broadcom conf X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2016 20:24:15 -0000 Author: landonf Date: Wed Aug 17 20:24:14 2016 New Revision: 304314 URL: https://svnweb.freebsd.org/changeset/base/304314 Log: mips/broadcom: Implement CFE-based EARLY_PRINTF support. This adds support for EARLY_PRINTF via the CFE console; the aim is to provide a fix for the otherwise cyclic dependency between PMU discovery and console printf/DELAY: - We need to parse the bhnd(4) core table to determine the address (and type) of the PMU/PLL registers and calculate the CPU clock frequency. - The core table parsing code will emit a printf() if a parse error is hit. - Safely calling printf() without EARLY_PRINTF requires a working DELAY+cninit, which means we need the PMU. Errors in core table parsing shouldn't happen, but lack of EARLY_PRINTF makes debugging more difficult. Approved by: adrian (mentor) Differential Revision: https://reviews.freebsd.org/D7498 Modified: head/sys/mips/broadcom/bcm_machdep.c head/sys/mips/conf/BCM head/sys/mips/conf/SENTRY5 Modified: head/sys/mips/broadcom/bcm_machdep.c ============================================================================== --- head/sys/mips/broadcom/bcm_machdep.c Wed Aug 17 20:21:33 2016 (r304313) +++ head/sys/mips/broadcom/bcm_machdep.c Wed Aug 17 20:24:14 2016 (r304314) @@ -198,6 +198,21 @@ platform_start(__register_t a0, __regist /* Initialize pcpu stuff */ mips_pcpu0_init(); +#ifdef CFE + /* + * Initialize CFE firmware trampolines. This must be done + * before any CFE APIs are called, including writing + * to the CFE console. + * + * CFE passes the following values in registers: + * a0: firmware handle + * a2: firmware entry point + * a3: entry point seal + */ + if (a3 == CFE_EPTSEAL) + cfe_init(a0, a2); +#endif + #if 0 /* * Probe the Broadcom on-chip PLL clock registers @@ -234,23 +249,40 @@ platform_start(__register_t a0, __regist mips_timer_early_init(platform_counter_freq); -#ifdef CFE - /* - * Initialize CFE firmware trampolines before - * we initialize the low-level console. - * - * CFE passes the following values in registers: - * a0: firmware handle - * a2: firmware entry point - * a3: entry point seal - */ - if (a3 == CFE_EPTSEAL) - cfe_init(a0, a2); -#endif - cninit(); mips_init(); mips_timer_init_params(platform_counter_freq, socinfo->double_count); } + +/* + * CFE-based EARLY_PRINTF support. To use, add the following to the kernel + * config: + * option EARLY_PRINTF + * option CFE + * device cfe + */ +#if defined(EARLY_PRINTF) && defined(CFE) +static void +bcm_cfe_eputc(int c) +{ + static int fd = -1; + unsigned char ch; + + ch = (unsigned char) c; + + if (fd == -1) { + if ((fd = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE)) < 0) + return; + } + + if (ch == '\n') + early_putc('\r'); + + while ((cfe_write(fd, &ch, 1)) == 0) + continue; +} + +early_putc_t *early_putc = bcm_cfe_eputc; +#endif /* EARLY_PRINTF */ Modified: head/sys/mips/conf/BCM ============================================================================== --- head/sys/mips/conf/BCM Wed Aug 17 20:21:33 2016 (r304313) +++ head/sys/mips/conf/BCM Wed Aug 17 20:24:14 2016 (r304314) @@ -52,6 +52,7 @@ options INVARIANT_SUPPORT #options BHND_LOGLEVEL=BHND_DEBUG_LEVEL #options BUS_DEBUG #makeoptions BUS_DEBUG +options EARLY_PRINTF #options VERBOSE_SYSINIT #makeoptions VERBOSE_SYSINIT Modified: head/sys/mips/conf/SENTRY5 ============================================================================== --- head/sys/mips/conf/SENTRY5 Wed Aug 17 20:21:33 2016 (r304313) +++ head/sys/mips/conf/SENTRY5 Wed Aug 17 20:24:14 2016 (r304314) @@ -31,9 +31,8 @@ makeoptions TRAMPLOADADDR=0x807963c0 hints "SENTRY5.hints" include "../broadcom/std.broadcom" -# sentry5 normally ships with cfe firmware; use the console for now +# sentry5 normally ships with cfe firmware options CFE -options CFE_CONSOLE options ALT_BREAK_TO_DEBUGGER device cfe @@ -57,6 +56,7 @@ options INVARIANT_SUPPORT #options BUS_DEBUG #makeoptions BUS_DEBUG +options EARLY_PRINTF device bhnd device siba