Module Name:    src
Committed By:   simonb
Date:           Mon Jun 15 07:48:12 UTC 2020

Modified Files:
        src/sys/arch/evbmips/cavium: machdep.c
        src/sys/arch/mips/cavium: octeonvar.h
        src/sys/arch/mips/cavium/dev: octeon_uart.c
        src/sys/arch/mips/conf: files.octeon
        src/sys/arch/mips/mips: mips_machdep.c
Added Files:
        src/sys/arch/mips/cavium: octeon_misc.c octeonreg.h

Log Message:
Finish CPU core support for Octeon Cavium CN70XX:
 - decode actual CPU name
 - per CPU core reset logic (partially adapted from OpenBSD)
 - handle Octeon 3 ioclock rate differences to other cores (from OpenBSD)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/evbmips/cavium/machdep.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/mips/cavium/octeon_misc.c \
    src/sys/arch/mips/cavium/octeonreg.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/mips/cavium/octeonvar.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/mips/cavium/dev/octeon_uart.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/mips/conf/files.octeon
cvs rdiff -u -r1.291 -r1.292 src/sys/arch/mips/mips/mips_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbmips/cavium/machdep.c
diff -u src/sys/arch/evbmips/cavium/machdep.c:1.13 src/sys/arch/evbmips/cavium/machdep.c:1.14
--- src/sys/arch/evbmips/cavium/machdep.c:1.13	Fri Jun  5 07:17:38 2020
+++ src/sys/arch/evbmips/cavium/machdep.c	Mon Jun 15 07:48:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.13 2020/06/05 07:17:38 simonb Exp $	*/
+/*	$NetBSD: machdep.c,v 1.14 2020/06/15 07:48:12 simonb Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -115,7 +115,7 @@
 #include "opt_cavium.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.13 2020/06/05 07:17:38 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.14 2020/06/15 07:48:12 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -191,7 +191,6 @@ void
 mach_init(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
 {
 	uint64_t btinfo_paddr;
-	int corefreq;
 
 	/* clear the BSS segment */
 	memset(edata, 0, end - edata);
@@ -205,20 +204,10 @@ mach_init(uint64_t arg0, uint64_t arg1, 
 	    (struct octeon_btinfo *)MIPS_PHYS_TO_KSEG0(btinfo_paddr),
 	    sizeof(octeon_btinfo));
 
-	corefreq = octeon_btinfo.obt_eclock_hz;
+	octeon_cal_timer(octeon_btinfo.obt_eclock_hz);
 
-	octeon_cal_timer(corefreq);
-
-	switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
-	case 0: cpu_setmodel("Cavium Octeon CN38XX/CN36XX"); break;
-	case 1: cpu_setmodel("Cavium Octeon CN31XX/CN3020"); break;
-	case 2: cpu_setmodel("Cavium Octeon CN3005/CN3010"); break;
-	case 3: cpu_setmodel("Cavium Octeon CN58XX"); break;
-	case 4: cpu_setmodel("Cavium Octeon CN5[4-7]XX"); break;
-	case 6: cpu_setmodel("Cavium Octeon CN50XX"); break;
-	case 7: cpu_setmodel("Cavium Octeon CN52XX"); break;
-	default: cpu_setmodel("Cavium Octeon"); break;
-	}
+	cpu_setmodel("Cavium Octeon %s",
+	    octeon_cpu_model(mips_options.mips_cpu_id));
 
 	mach_init_vector();
 
@@ -459,11 +448,7 @@ haltsys:
 	 */
 	delay(80000);
 
-	/* initiate chip soft-reset */
-	uint64_t fuse = octeon_read_csr(CIU_FUSE);
-	octeon_write_csr(CIU_SOFT_BIST, fuse);
-	octeon_read_csr(CIU_SOFT_RST);
-	octeon_write_csr(CIU_SOFT_RST, fuse);
+	octeon_soft_reset();
 
 	delay(1000000);
 

Index: src/sys/arch/mips/cavium/octeonvar.h
diff -u src/sys/arch/mips/cavium/octeonvar.h:1.9 src/sys/arch/mips/cavium/octeonvar.h:1.10
--- src/sys/arch/mips/cavium/octeonvar.h:1.9	Fri Jun  5 09:18:35 2020
+++ src/sys/arch/mips/cavium/octeonvar.h	Mon Jun 15 07:48:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: octeonvar.h,v 1.9 2020/06/05 09:18:35 simonb Exp $	*/
+/*	$NetBSD: octeonvar.h,v 1.10 2020/06/15 07:48:12 simonb Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -63,6 +63,14 @@
 	    (((uint64_t)(subbits) << name##_SHIFT) & name)
 #endif
 
+#ifdef _KERNEL
+extern int	octeon_core_ver;
+#endif /* _KERNEL */
+#define	OCTEON_1		1
+#define	OCTEON_PLUS		10	/* arbitary, keep sequence for others */
+#define	OCTEON_2		2
+#define	OCTEON_3		3
+
 struct octeon_config {
 	struct mips_bus_space mc_iobus_bust;
 	struct mips_bus_space mc_bootbus_bust;
@@ -221,24 +229,28 @@ struct octfau_map {
 #ifdef _KERNEL
 extern struct octeon_config	octeon_configuration;
 #ifdef MULTIPROCESSOR
-extern kcpuset_t *cpus_booted;
+extern kcpuset_t		*cpus_booted;
 extern struct cpu_softc		octeon_cpu1_softc;
 #endif
 
-void	octeon_bus_io_init(bus_space_tag_t, void *);
-void	octeon_bus_mem_init(bus_space_tag_t, void *);
-void	octeon_cal_timer(int);
-void	octeon_dma_init(struct octeon_config *);
-void	octeon_intr_init(struct cpu_info *);
-void	octeon_iointr(int, vaddr_t, uint32_t);
-void	octpci_init(pci_chipset_tag_t, struct octeon_config *);
-void	*octeon_intr_establish(int, int, int (*)(void *), void *);
-void	octeon_intr_disestablish(void *cookie);
-
-void	octeon_reset_vector(void);
-uint64_t mips_cp0_cvmctl_read(void);
-void	 mips_cp0_cvmctl_write(uint64_t);
+const char	*octeon_cpu_model(mips_prid_t);
 
+void		octeon_bus_io_init(bus_space_tag_t, void *);
+void		octeon_bus_mem_init(bus_space_tag_t, void *);
+void		octeon_cal_timer(int);
+void		octeon_dma_init(struct octeon_config *);
+void		octeon_intr_init(struct cpu_info *);
+void		octeon_iointr(int, vaddr_t, uint32_t);
+void		octpci_init(pci_chipset_tag_t, struct octeon_config *);
+void		*octeon_intr_establish(int, int, int (*)(void *), void *);
+void		octeon_intr_disestablish(void *cookie);
+
+int		octeon_ioclock_speed(void);
+void		octeon_soft_reset(void);
+
+void		octeon_reset_vector(void);
+uint64_t	mips_cp0_cvmctl_read(void);
+void		mips_cp0_cvmctl_write(uint64_t);
 #endif /* _KERNEL */
 
 #if defined(__mips_n32)

Index: src/sys/arch/mips/cavium/dev/octeon_uart.c
diff -u src/sys/arch/mips/cavium/dev/octeon_uart.c:1.5 src/sys/arch/mips/cavium/dev/octeon_uart.c:1.6
--- src/sys/arch/mips/cavium/dev/octeon_uart.c:1.5	Sun May 31 14:05:21 2020
+++ src/sys/arch/mips/cavium/dev/octeon_uart.c	Mon Jun 15 07:48:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: octeon_uart.c,v 1.5 2020/05/31 14:05:21 simonb Exp $	*/
+/*	$NetBSD: octeon_uart.c,v 1.6 2020/06/15 07:48:12 simonb Exp $	*/
 
 /*
  * Copyright (c) 2007 Internet Initiative Japan, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: octeon_uart.c,v 1.5 2020/05/31 14:05:21 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: octeon_uart.c,v 1.6 2020/06/15 07:48:12 simonb Exp $");
 
 #include "opt_octeon.h"
 
@@ -139,7 +139,7 @@ octuart_iobus_attach(device_t parent, de
 	}
 
 	sc_com->sc_type = COM_TYPE_16550_NOERS;
-	sc_com->sc_frequency = curcpu()->ci_cpu_freq;
+	sc_com->sc_frequency = octeon_ioclock_speed();
 	sc_com->enable = octuart_com_enable;
 	sc_com->disable = octuart_com_disable;
 
@@ -205,7 +205,7 @@ octuart_com_cnattach(bus_space_tag_t bus
 	return comcnattach1(
 		&regs,
 		speed,
-		curcpu()->ci_cpu_freq,
+		octeon_ioclock_speed(),
 		COM_TYPE_16550_NOERS,
 		CONMODE);
 }

Index: src/sys/arch/mips/conf/files.octeon
diff -u src/sys/arch/mips/conf/files.octeon:1.6 src/sys/arch/mips/conf/files.octeon:1.7
--- src/sys/arch/mips/conf/files.octeon:1.6	Sun May 31 06:27:06 2020
+++ src/sys/arch/mips/conf/files.octeon	Mon Jun 15 07:48:12 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.octeon,v 1.6 2020/05/31 06:27:06 simonb Exp $
+#	$NetBSD: files.octeon,v 1.7 2020/06/15 07:48:12 simonb Exp $
 
 file	arch/mips/mips/locore_octeon.S
 file	arch/mips/mips/bus_dma.c
@@ -7,6 +7,7 @@ file	arch/mips/mips/mips3_clockintr.c
 
 file	arch/mips/cavium/octeon_dma.c
 file	arch/mips/cavium/octeon_intr.c
+file	arch/mips/cavium/octeon_misc.c
 file	arch/mips/cavium/dev/octeon_ciu.c
 
 defparam	opt_octeon.h			OCTEON_ECLK

Index: src/sys/arch/mips/mips/mips_machdep.c
diff -u src/sys/arch/mips/mips/mips_machdep.c:1.291 src/sys/arch/mips/mips/mips_machdep.c:1.292
--- src/sys/arch/mips/mips/mips_machdep.c:1.291	Mon Jun 15 00:31:21 2020
+++ src/sys/arch/mips/mips/mips_machdep.c	Mon Jun 15 07:48:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_machdep.c,v 1.291 2020/06/15 00:31:21 simonb Exp $	*/
+/*	$NetBSD: mips_machdep.c,v 1.292 2020/06/15 07:48:12 simonb Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.291 2020/06/15 00:31:21 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.292 2020/06/15 07:48:12 simonb Exp $");
 
 #define __INTR_PRIVATE
 #include "opt_cputype.h"
@@ -167,6 +167,10 @@ __KERNEL_RCSID(0, "$NetBSD: mips_machdep
 #include <machine/bootinfo.h>
 #endif
 
+#ifdef MIPS64_OCTEON
+#include <mips/cavium/octeonvar.h>
+#endif
+
 #if (MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) > 0
 #include <mips/mipsNN.h>		/* MIPS32/MIPS64 registers */
 
@@ -1479,6 +1483,11 @@ cpu_identify(device_t dev)
 	int i;
 
 	cpuname = opts->mips_cpu->cpu_name;
+#ifdef MIPS64_OCTEON
+	if (MIPS_PRID_CID(cpu_id) == MIPS_PRID_CID_CAVIUM) {
+		cpuname = octeon_cpu_model(cpu_id);
+	}
+#endif
 
 	fpuname = NULL;
 	for (i = 0; i < sizeof(fputab)/sizeof(fputab[0]); i++) {

Added files:

Index: src/sys/arch/mips/cavium/octeon_misc.c
diff -u /dev/null src/sys/arch/mips/cavium/octeon_misc.c:1.1
--- /dev/null	Mon Jun 15 07:48:12 2020
+++ src/sys/arch/mips/cavium/octeon_misc.c	Mon Jun 15 07:48:12 2020
@@ -0,0 +1,273 @@
+/*	$NetBSD: octeon_misc.c,v 1.1 2020/06/15 07:48:12 simonb Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Simon Burge.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 Miodrag Vallat.
+ * Copyright (c) 2019 Visa Hankala.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * Copyright (c) 2003-2004 Opsycon AB  (www.opsycon.se / www.opsycon.com)
+ *
+ * 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 ``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 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: octeon_misc.c,v 1.1 2020/06/15 07:48:12 simonb Exp $");
+
+#include <sys/param.h>
+
+#include <mips/cavium/octeonreg.h>
+#include <mips/cavium/octeonvar.h>
+#include <mips/cavium/dev/octeon_ciureg.h>
+
+int	octeon_core_ver;
+
+/*
+ * Return the name of the CPU model we are running on.
+ * Side effect: sets the octeon_core_ver variable.
+ */
+const char *
+octeon_cpu_model(mips_prid_t cpu_id)
+{
+	const uint64_t fuse = octeon_xkphys_read_8(CIU_FUSE);
+	const int numcores = popcount64(fuse);
+	const int clock_mhz = curcpu()->ci_cpu_freq / 1000000;
+	const char *family;
+	const char *coremodel;
+	bool tested;
+	static char buf[sizeof("CNnnXX-NNNN (unverified)")] = {};
+
+	if (buf[0] != 0)
+		return buf;		/* we've been here before */
+
+	/* 
+	 * Don't print "pass X.Y", but if needed:
+	 *	passhi = ((cpu_id >> 3) & 7) + '0';
+	 *	passlo = (cpu_id & 7) + '0';
+	 * Note some chips use different representation for the pass number.
+	 */
+
+#ifdef OCTEON_DEBUG
+	printf("cpuid = 0x%x\n", cpu_id);
+#endif
+
+	switch (numcores) {
+	case  1: coremodel = "10"; break;
+	case  2: coremodel = "20"; break;
+	case  3: coremodel = "25"; break;
+	case  4: coremodel = "30"; break;
+	case  5: coremodel = "32"; break;
+	case  6: coremodel = "34"; break;
+	case  7: coremodel = "38"; break;
+	case  8: coremodel = "40"; break;
+	case  9: coremodel = "42"; break;
+	case 10: coremodel = "45"; break;
+	case 11: coremodel = "48"; break;
+	case 12: coremodel = "50"; break;
+	case 13: coremodel = "52"; break;
+	case 14: coremodel = "55"; break;
+	case 15: coremodel = "58"; break;
+	case 16: coremodel = "60"; break;
+	case 24: coremodel = "70"; break;
+	case 32: coremodel = "80"; break;
+	case 40: coremodel = "85"; break;
+	case 44: coremodel = "88"; break;
+	case 48: coremodel = "90"; break;
+	default:
+		coremodel = "XX"; break;
+	}
+
+	/*
+         * Assume all CPU families haven't been tested unless explicitly
+         * noted.  Sources of extra information for determining actual
+         * CPU models include chip documentation and U-Boot source code.
+	 */
+	tested = false;
+
+	switch (MIPS_PRID_IMPL(cpu_id)) {
+	/* the order of these cases is the numeric value of MIPS_CNnnXX */
+	case MIPS_CN38XX:
+		family = "38";	/* XXX may also be family "36" or "37" */
+		octeon_core_ver = OCTEON_1;
+		break;
+	case MIPS_CN31XX:
+		family = "31";	/* XXX may also be model "3020" */
+		octeon_core_ver = OCTEON_1;
+		break;
+	case MIPS_CN30XX:
+		family = "30";	/* XXX half cache model is "3005" */
+		octeon_core_ver = OCTEON_1;
+		break;
+	case MIPS_CN58XX:
+		family = "58";
+		octeon_core_ver = OCTEON_PLUS;
+		break;
+	case MIPS_CN56XX:
+		family = "56";	/* XXX may also be family "54", "55" or "57" */
+		octeon_core_ver = OCTEON_PLUS;
+		break;
+	case MIPS_CN50XX:
+		family = "50";
+		octeon_core_ver = OCTEON_PLUS;
+		tested = true;
+		break;
+	case MIPS_CN52XX:
+		family = "52";	/* XXX may also be family "51" */
+		octeon_core_ver = OCTEON_PLUS;
+		break;
+	case MIPS_CN63XX:
+		family = "63";	/* XXX may also be family "62" */
+		octeon_core_ver = OCTEON_2;
+		break;
+	case MIPS_CN68XX:
+		family = "68";
+		octeon_core_ver = OCTEON_2;
+		break;
+	case MIPS_CN66XX:
+		family = "66";
+		octeon_core_ver = OCTEON_2;
+		break;
+	case MIPS_CN61XX:
+		family = "61";	/* XXX may also be family "60" */
+		octeon_core_ver = OCTEON_2;
+		break;
+	case MIPS_CN78XX:
+		family = "78";	/* XXX may also be family "76" or "77" */
+		octeon_core_ver = OCTEON_3;
+		break;
+	case MIPS_CN70XX:
+		family = "70";
+		if (octeon_xkphys_read_8(MIO_FUS_PDF) & MIO_FUS_PDF_IS_71XX)
+			family = "71";
+		octeon_core_ver = OCTEON_3;
+		tested = true;
+		break;
+	case MIPS_CN73XX:
+		family = "73";	/* XXX may also be family "72" */
+		octeon_core_ver = OCTEON_3;
+		tested = true;
+		break;
+	default:
+		panic("IMPL 0x%02x not implmented", MIPS_PRID_IMPL(cpu_id));
+	}
+
+	snprintf(buf, sizeof(buf), "CN%s%s-%d%s", family, coremodel,
+	    clock_mhz, tested ? "" : " (unverified)");
+
+	if (!tested)
+		printf(">>> model %s\n", buf);
+
+	return buf;
+}
+
+/*
+ * Return the coprocessor clock speed (IO clock speed).
+ *
+ * Octeon I and Octeon Plus use the CPU core clock speed.
+ * Octeon II and III use a configurable multiplier against
+ * the PLL reference clock speed (50MHz).
+ */
+int
+octeon_ioclock_speed(void)
+{
+	u_int64_t mio_rst_boot, rst_boot;
+
+	switch (octeon_core_ver) {
+	case OCTEON_1:
+	case OCTEON_PLUS:
+		return curcpu()->ci_cpu_freq;
+	case OCTEON_2:
+		mio_rst_boot = octeon_xkphys_read_8(MIO_RST_BOOT);
+		return OCTEON_PLL_REF_CLK *
+		    __SHIFTOUT(mio_rst_boot, MIO_RST_BOOT_PNR_MUL);
+	case OCTEON_3:
+		rst_boot = octeon_xkphys_read_8(RST_BOOT);
+		return OCTEON_PLL_REF_CLK *
+		    __SHIFTOUT(rst_boot, RST_BOOT_PNR_MUL);
+	default:
+		panic("%s: unknown Octeon core type %d", __func__,
+		    octeon_core_ver);
+	}
+}
+
+/*
+ * Initiate chip soft-reset.
+ */
+void
+octeon_soft_reset(void)
+{
+
+	/* XXX should invalidate caches, tlb, watchdog? */
+	switch (octeon_core_ver) {
+	case OCTEON_1:
+	case OCTEON_PLUS:
+	case OCTEON_2:
+		octeon_xkphys_write_8(CIU_SOFT_BIST, CIU_SOFT_BIST_SOFT_BIST);
+		octeon_xkphys_write_8(CIU_SOFT_RST, CIU_SOFT_RST_SOFT_RST);
+	case OCTEON_3:
+		octeon_xkphys_write_8(RST_SOFT_RST, CIU_SOFT_RST_SOFT_RST);
+	default:
+		panic("%s: unknown Octeon core type %d", __func__,
+		    octeon_core_ver);
+	}
+}
Index: src/sys/arch/mips/cavium/octeonreg.h
diff -u /dev/null src/sys/arch/mips/cavium/octeonreg.h:1.1
--- /dev/null	Mon Jun 15 07:48:12 2020
+++ src/sys/arch/mips/cavium/octeonreg.h	Mon Jun 15 07:48:12 2020
@@ -0,0 +1,66 @@
+/*	$NetBSD: octeonreg.h,v 1.1 2020/06/15 07:48:12 simonb Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Simon Burge.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+
+#ifndef _OCTEONREG_H_
+#define	_OCTEONREG_H_
+
+#define	OCTEON_PLL_REF_CLK		50000000	/* defined as 50MHz */
+
+
+/* OCTEON II */
+#define	MIO_RST_BOOT			UINT64_C(0x1180000001600)
+#define	  MIO_RST_BOOT_C_MUL		__BITS(36,30)
+#define	  MIO_RST_BOOT_PNR_MUL		__BITS(29,24)
+
+
+/* OCTEON III */
+#define	MIO_FUS_PDF			UINT64_C(0x1180000001428)
+#define	  MIO_FUS_PDF_IS_71XX		__BIT(32)
+
+#define	RST_BOOT			UINT64_C(0x1180006001600)
+#define	  RST_BOOT_C_MUL		__BITS(36,30)
+#define	  RST_BOOT_PNR_MUL		__BITS(29,24)
+#define	RST_DELAY			UINT64_C(0x1180006001608)
+#define	RST_CFG				UINT64_C(0x1180006001610)
+#define	RST_OCX				UINT64_C(0x1180006001618)
+#define	RST_INT				UINT64_C(0x1180006001628)
+#define	RST_CKILL			UINT64_C(0x1180006001638)
+#define	RST_CTL(n)			(UINT64_C(0x1180006001640) + (n) * 0x8)
+#define	RST_SOFT_RST			UINT64_C(0x1180006001680)
+#define	RST_SOFT_PRST(n)		(UINT64_C(0x11800060016c0) + (n) * 0x8)
+#define	RST_PP_POWER			UINT64_C(0x1180006001700)
+#define	RST_POWER_DBG			UINT64_C(0x1180006001708)
+#define	RST_REF_CNTR			UINT64_C(0x1180006001758)
+#define	RST_COLD_DATA(n)		(UINT64_C(0x11800060017c0) + (n) * 0x8)
+
+
+#endif /* !_OCTEONREG_H_ */

Reply via email to