Index: head/sys/mips/broadcom/bcm_machdep.c =================================================================== --- head/sys/mips/broadcom/bcm_machdep.c (revision 304313) +++ head/sys/mips/broadcom/bcm_machdep.c (revision 304314) @@ -1,256 +1,288 @@ /*- * Copyright (c) 2007 Bruce M. Simpson. * Copyright (c) 2016 Michael Zhilin * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_ddb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bcm_socinfo.h" #ifdef CFE #include #endif #if 0 #define BCM_TRACE(_fmt, ...) printf(_fmt, ##__VA_ARGS__) #else #define BCM_TRACE(_fmt, ...) #endif extern int *edata; extern int *end; void platform_cpu_init() { /* Nothing special */ } static void mips_init(void) { int i, j; printf("entry: mips_init()\n"); #ifdef CFE /* * Query DRAM memory map from CFE. */ physmem = 0; for (i = 0; i < 10; i += 2) { int result; uint64_t addr, len, type; result = cfe_enummem(i / 2, 0, &addr, &len, &type); if (result < 0) { BCM_TRACE("There is no phys memory for: %d\n", i); phys_avail[i] = phys_avail[i + 1] = 0; break; } if (type != CFE_MI_AVAILABLE) { BCM_TRACE("phys memory is not available: %d\n", i); continue; } phys_avail[i] = addr; if (i == 0 && addr == 0) { /* * If this is the first physical memory segment probed * from CFE, omit the region at the start of physical * memory where the kernel has been loaded. */ phys_avail[i] += MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); } BCM_TRACE("phys memory is available for: %d\n", i); BCM_TRACE(" => addr = %jx\n", addr); BCM_TRACE(" => len = %jd\n", len); phys_avail[i + 1] = addr + len; physmem += len; } BCM_TRACE("Total phys memory is : %ld\n", physmem); realmem = btoc(physmem); #endif for (j = 0; j < i; j++) dump_avail[j] = phys_avail[j]; physmem = realmem; init_param1(); init_param2(physmem); mips_cpu_init(); pmap_bootstrap(); mips_proc0_init(); mutex_init(); kdb_init(); #ifdef KDB if (boothowto & RB_KDB) kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); #endif } void platform_reset(void) { printf("bcm::platform_reset()\n"); intr_disable(); #if defined(CFE) cfe_exit(0, 0); #else /* PMU watchdog reset */ BCM_WRITE_REG32(BCM_REG_CHIPC_PMUWD_OFFS, 2); /* PMU watchdog */ #endif #if 0 /* Non-PMU reset * XXX: Need chipc capability flags */ *((volatile uint8_t *)MIPS_PHYS_TO_KSEG1(SENTRY5_EXTIFADR)) = 0x80; #endif for (;;); } void platform_start(__register_t a0, __register_t a1, __register_t a2, __register_t a3) { vm_offset_t kernend; uint64_t platform_counter_freq; struct bcm_socinfo *socinfo; /* clear the BSS and SBSS segments */ kernend = (vm_offset_t)&end; memset(&edata, 0, kernend - (vm_offset_t)(&edata)); mips_postboot_fixup(); /* 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 * and discover the CPU pipeline clock and bus clock * multipliers from this. * XXX: Wrong place. You have to ask the ChipCommon * or External Interface cores on the SiBa. */ uint32_t busmult, cpumult, refclock, clkcfg1; #define S5_CLKCFG1_REFCLOCK_MASK 0x0000001F #define S5_CLKCFG1_BUSMULT_MASK 0x000003E0 #define S5_CLKCFG1_BUSMULT_SHIFT 5 #define S5_CLKCFG1_CPUMULT_MASK 0xFFFFFC00 #define S5_CLKCFG1_CPUMULT_SHIFT 10 counter_freq = 100000000; /* XXX */ clkcfg1 = s5_rd_clkcfg1(); printf("clkcfg1 = 0x%08x\n", clkcfg1); refclock = clkcfg1 & 0x1F; busmult = ((clkcfg1 & 0x000003E0) >> 5) + 1; cpumult = ((clkcfg1 & 0xFFFFFC00) >> 10) + 1; printf("refclock = %u\n", refclock); printf("busmult = %u\n", busmult); printf("cpumult = %u\n", cpumult); counter_freq = cpumult * refclock; #endif socinfo = bcm_get_socinfo(); platform_counter_freq = socinfo->cpurate * 1000 * 1000; /* BCM4718 is 480MHz */ 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 */ Index: head/sys/mips/conf/BCM =================================================================== --- head/sys/mips/conf/BCM (revision 304313) +++ head/sys/mips/conf/BCM (revision 304314) @@ -1,100 +1,101 @@ # # $FreeBSD$ # # The Broadcom 470x/471x/535x series of processors and boards is very commonly # used in COTS hardware including the ASUS RT-N12, RT-N16, RT-N53. # ident BCM cpu CPU_MIPS74K hints "BCM.hints" include "../broadcom/std.broadcom" # ships with cfe firmware options CFE device cfe options ALT_BREAK_TO_DEBUGGER options BREAK_TO_DEBUGGER options BOOTVERBOSE=0 makeoptions TRAMPLOADADDR=0x80800000 makeoptions DEBUG="-g3" #Build kernel with gdb(1) debug symbols makeoptions MODULES_OVERRIDE="" options DDB options KDB options SCHED_4BSD #4BSD scheduler options INET #InterNETworking options NFSCL #Network Filesystem Client #options NFS_ROOT #NFS usable as /, requires NFSCL options PSEUDOFS #Pseudo-filesystem framework options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions options FFS #Berkeley Fast Filesystem options SOFTUPDATES #Enable FFS soft updates support options UFS_ACL #Support for access control lists options UFS_DIRHASH #Improve performance on big directories device geom_uzip options GEOM_UZIP options GEOM_LABEL # Providers labelization. options ROOTDEVNAME=\"ufs:ufs/FBSD\" # assumes FW built by # freebsd-build-wifi # Debugging for use in -current #options DEADLKRES options INVARIANTS options INVARIANT_SUPPORT #options BHND_LOGLEVEL=BHND_DEBUG_LEVEL #options BUS_DEBUG #makeoptions BUS_DEBUG +options EARLY_PRINTF #options VERBOSE_SYSINIT #makeoptions VERBOSE_SYSINIT # bhnd(4) device bhnd device bcma # bcma backplane device bcma_nexus device pci device bhnd_pcib # PCIe-G1 core #device bgmac # Broadcom GMAC - not yet device mdio #Flash device spibus device mx25l # Serial Flash device cfi # Parallel Flash device cfid #UART device uart #Base device loop device ether device random device md #Performance #options HWPMC_HOOKS #device hwpmc #device hwpmc_mips74k #Ethernet # device bfe # XXX will build both pci and siba device miibus # attachments # pci devices # USB is not yet ready #options USB_DEBUG # enable debug msgs #device usb # USB Bus (required) #device uhci # UHCI PCI->USB interface #device ehci # EHCI PCI->USB interface (USB 2.0) Index: head/sys/mips/conf/SENTRY5 =================================================================== --- head/sys/mips/conf/SENTRY5 (revision 304313) +++ head/sys/mips/conf/SENTRY5 (revision 304314) @@ -1,89 +1,89 @@ # # $FreeBSD$ # # The Broadcom Sentry5 series of processors and boards is very commonly # used in COTS hardware including the Netgear WGT634U. # # Some tweaks are needed for use with this platform: # # * CFE firmware's ELF loader expects an ELF kernel which is linked so as # not to contain offsets in PT_LOAD which point behind the actual offset # of that PT header. FreeBSD normally links the first PT_LOAD header to # begin at offset 0. # # * Broadcom's support package for the internal bus, the Sonics # SiliconBackplane, needs to be integrated to detect and probe hardware # correctly. # # * The clock needs to be calibrated correctly, so that DELAY() may work. # One problem with this is that the low-level printf() routine calls DELAY(), # which currently causes divide-by-zero trap # # * The Broadcom CPUs have no FPU. Attempting to detect one by reading CP1's # status register causes an unhandled boot-time exception. An FPU emulator # will be necessary to support multi-user boot. # ident SENTRY5 cpu CPU_MIPS4KC 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 makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols makeoptions MODULES_OVERRIDE="" options DDB options KDB options SCHED_4BSD #4BSD scheduler options INET #InterNETworking options NFSCL #Network Filesystem Client options NFS_ROOT #NFS usable as /, requires NFSCL options PSEUDOFS #Pseudo-filesystem framework options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions # Debugging for use in -current #options DEADLKRES options INVARIANTS options INVARIANT_SUPPORT #options BUS_DEBUG #makeoptions BUS_DEBUG +options EARLY_PRINTF device bhnd device siba device siba_nexus device bhnd_pcib device pci # bhnd_pcib # device bfe # XXX will build both pci and siba # device miibus # attachments # pci devices # notyet: #device ath # in pci slot #device ath_pci # Atheros pci/cardbus glue #device ath_hal # pci chip support #options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors options USB_DEBUG # enable debug msgs device usb # USB Bus (required) device uhci # UHCI PCI->USB interface device ehci # EHCI PCI->USB interface (USB 2.0) device cfi # parallel flash device cfid device uart device loop device ether device md