svn commit: r210311 - in head/sys: conf contrib/octeon-sdk mips/cavium mips/cavium/dev mips/cavium/octe mips/conf mips/include mips/mips

Juli Mallett jmallett at FreeBSD.org
Tue Jul 20 19:25:12 UTC 2010


Author: jmallett
Date: Tue Jul 20 19:25:11 2010
New Revision: 210311
URL: http://svn.freebsd.org/changeset/base/210311

Log:
  Update the port of FreeBSD to Cavium Octeon to use the Cavium Simple Executive
  library:
  o) Increase inline unit / large function growth limits for MIPS to accommodate
     the needs of the Simple Executive, which uses a shocking amount of inlining.
  o) Remove TARGET_OCTEON and use CPU_CNMIPS to do things required by cnMIPS and
     the Octeon SoC.
  o) Add OCTEON_VENDOR_LANNER to use Lanner's allocation of vendor-specific
     board numbers, specifically to support the MR320.
  o) Add OCTEON_BOARD_CAPK_0100ND to hard-wire configuration for the CAPK-0100nd,
     which improperly uses an evaluation board's board number and breaks board
     detection at runtime.  This board is sold by Portwell as the CAM-0100.
  o) Add support for the RTC available on some Octeon boards.
  o) Add support for the Octeon PCI bus.  Note that rman_[sg]et_virtual for IO
     ports can not work unless building for n64.
  o) Clean up the CompactFlash driver to use Simple Executive macros and
     structures where possible (it would be advisable to use the Simple Executive
     API to set the PIO mode, too, but that is not done presently.)  Also use
     structures from FreeBSD's ATA layer rather than structures copied from
     Linux.
  o) Print available Octeon SoC features on boot.
  o) Add support for the Octeon timecounter.
  o) Use the Simple Executive's routines rather than local copies for doing reads
     and writes to 64-bit addresses and use its macros for various device
     addresses rather than using local copies.
  o) Rename octeon_board_real to octeon_is_simulation to reduce differences with
     Cavium-provided code originally written for Linux.  Also make it use the
     same simplified test that the Simple Executive and Linux both use rather
     than our complex one.
  o) Add support for the Octeon CIU, which is the main interrupt unit, as a bus
     to use normal interrupt allocation and setup routines.
  o) Use the Simple Executive's bootmem facility to allocate physical memory for
     the kernel, rather than assuming we know which addresses we can steal.
     NB: This may reduce the amount of RAM the kernel reports you as having if
         you are leaving large temporary allocations made by U-Boot allocated
         when starting FreeBSD.
  o) Add a port of the Cavium-provided Ethernet driver for Linux.  This changes
     Ethernet interface naming from rgmxN to octeN.  The new driver has vast
     improvements over the old one, both in performance and functionality, but
     does still have some features which have not been ported entirely and there
     may be unimplemented code that can be hit in everyday use.  I will make
     every effort to correct those as they are reported.
  o) Support loading the kernel on non-contiguous cores.
  o) Add very conservative support for harvesting randomness from the Octeon
     random number device.
  o) Turn SMP on by default.
  o) Clean up the style of the Octeon kernel configurations a little and make
     them compile with -march=octeon.
  o) Add support for the Lanner MR320 and the CAPK-0100nd to the Simple
     Executive.
  o) Modify the Simple Executive to build on FreeBSD and to build without
     executive-config.h or cvmx-config.h.  In the future we may want to
     revert part of these changes and supply executive-config.h and
     cvmx-config.h and access to the options contained in those files via
     kernel configuration files.
  o) Modify the Simple Executive USB routines to support getting and setting
     of the USB PID.

Added:
  head/sys/mips/cavium/ciu.c   (contents, props changed)
  head/sys/mips/cavium/cvmx_config.h   (contents, props changed)
  head/sys/mips/cavium/octe/
  head/sys/mips/cavium/octe/cavium-ethernet.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-common.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-common.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-defines.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-headers.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-mdio.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-mdio.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-mem.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-mem.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-rgmii.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-rx.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-rx.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-sgmii.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-spi.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-tx.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-tx.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-util.h   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet-xaui.c   (contents, props changed)
  head/sys/mips/cavium/octe/ethernet.c   (contents, props changed)
  head/sys/mips/cavium/octe/octe.c   (contents, props changed)
  head/sys/mips/cavium/octe/octebus.c   (contents, props changed)
  head/sys/mips/cavium/octe/octebusvar.h   (contents, props changed)
  head/sys/mips/cavium/octe/wrapper-cvmx-includes.h   (contents, props changed)
  head/sys/mips/cavium/octeon_ds1337.c   (contents, props changed)
  head/sys/mips/cavium/octeon_rnd.c   (contents, props changed)
  head/sys/mips/cavium/octeon_rtc.c   (contents, props changed)
  head/sys/mips/cavium/octopci.c   (contents, props changed)
  head/sys/mips/cavium/octopci_bus_space.c   (contents, props changed)
  head/sys/mips/cavium/octopcireg.h   (contents, props changed)
  head/sys/mips/cavium/octopcivar.h   (contents, props changed)
Deleted:
  head/sys/contrib/octeon-sdk/perfzilla_screen.png
  head/sys/mips/cavium/dev/
  head/sys/mips/cavium/driveid.h
  head/sys/mips/cavium/octeon_ebt3000_cf.h
Modified:
  head/sys/conf/kern.pre.mk
  head/sys/conf/options.mips
  head/sys/contrib/octeon-sdk/cvmx-access-native.h
  head/sys/contrib/octeon-sdk/cvmx-app-init.h
  head/sys/contrib/octeon-sdk/cvmx-asm.h
  head/sys/contrib/octeon-sdk/cvmx-cmd-queue.c
  head/sys/contrib/octeon-sdk/cvmx-cmd-queue.h
  head/sys/contrib/octeon-sdk/cvmx-fpa.c
  head/sys/contrib/octeon-sdk/cvmx-helper-board.c
  head/sys/contrib/octeon-sdk/cvmx-helper-errata.c
  head/sys/contrib/octeon-sdk/cvmx-helper-fpa.c
  head/sys/contrib/octeon-sdk/cvmx-helper-loop.c
  head/sys/contrib/octeon-sdk/cvmx-helper-npi.c
  head/sys/contrib/octeon-sdk/cvmx-helper-rgmii.c
  head/sys/contrib/octeon-sdk/cvmx-helper-sgmii.c
  head/sys/contrib/octeon-sdk/cvmx-helper-spi.c
  head/sys/contrib/octeon-sdk/cvmx-helper-util.c
  head/sys/contrib/octeon-sdk/cvmx-helper-util.h
  head/sys/contrib/octeon-sdk/cvmx-helper-xaui.c
  head/sys/contrib/octeon-sdk/cvmx-helper.c
  head/sys/contrib/octeon-sdk/cvmx-helper.h
  head/sys/contrib/octeon-sdk/cvmx-pko.c
  head/sys/contrib/octeon-sdk/cvmx-platform.h
  head/sys/contrib/octeon-sdk/cvmx-rtc.h
  head/sys/contrib/octeon-sdk/cvmx-spi.c
  head/sys/contrib/octeon-sdk/cvmx-thunder.c
  head/sys/contrib/octeon-sdk/cvmx-usb.c
  head/sys/contrib/octeon-sdk/cvmx-usb.h
  head/sys/contrib/octeon-sdk/octeon-model.h
  head/sys/mips/cavium/files.octeon1
  head/sys/mips/cavium/obio.c
  head/sys/mips/cavium/octeon_ebt3000_cf.c
  head/sys/mips/cavium/octeon_machdep.c
  head/sys/mips/cavium/octeon_mp.c
  head/sys/mips/cavium/octeon_pcmap_regs.h
  head/sys/mips/cavium/std.octeon1
  head/sys/mips/cavium/uart_bus_octeonusart.c
  head/sys/mips/cavium/uart_cpu_octeonusart.c
  head/sys/mips/cavium/uart_dev_oct16550.c
  head/sys/mips/conf/OCTEON1
  head/sys/mips/conf/OCTEON1-32
  head/sys/mips/conf/OCTEON1.hints
  head/sys/mips/include/_bus.h
  head/sys/mips/include/cache_mipsNN.h
  head/sys/mips/include/cpufunc.h
  head/sys/mips/include/cpuregs.h
  head/sys/mips/mips/bus_space_generic.c
  head/sys/mips/mips/cache.c
  head/sys/mips/mips/cache_mipsNN.c
  head/sys/mips/mips/cpu.c
  head/sys/mips/mips/exception.S
  head/sys/mips/mips/locore.S
  head/sys/mips/mips/machdep.c
  head/sys/mips/mips/mainbus.c
  head/sys/mips/mips/mpboot.S
  head/sys/mips/mips/pm_machdep.c
  head/sys/mips/mips/support.S
  head/sys/mips/mips/vm_machdep.c

Modified: head/sys/conf/kern.pre.mk
==============================================================================
--- head/sys/conf/kern.pre.mk	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/conf/kern.pre.mk	Tue Jul 20 19:25:11 2010	(r210311)
@@ -94,8 +94,14 @@ CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBU
 CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
 .if ${CC} != "icc"
 CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
+.if ${MACHINE_CPUARCH} != "mips"
 CFLAGS+= --param inline-unit-growth=100
 CFLAGS+= --param large-function-growth=1000
+.else
+# XXX Actually a gross hack just for Octeon because of the Simple Executive.
+CFLAGS+= --param inline-unit-growth=1000
+CFLAGS+= --param large-function-growth=100000
+.endif
 WERROR?= -Werror
 .endif
 

Modified: head/sys/conf/options.mips
==============================================================================
--- head/sys/conf/options.mips	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/conf/options.mips	Tue Jul 20 19:25:11 2010	(r210311)
@@ -50,7 +50,6 @@ CFE_ENV		opt_global.h
 CFE_ENV_SIZE	opt_global.h
 
 NOFPU		opt_global.h
-TARGET_OCTEON	opt_global.h
 TARGET_EMULATOR	opt_ddb.h
 TARGET_XLR_XLS  opt_global.h
 
@@ -61,3 +60,9 @@ TICK_USE_MALTA_RTC	opt_global.h
 # The highest memory address that can be used by the kernel in units of KB.
 #
 MAXMEM			opt_global.h
+
+#
+# Options that control the Cavium Simple Executive.
+#
+OCTEON_VENDOR_LANNER		opt_cvmx.h
+OCTEON_BOARD_CAPK_0100ND	opt_cvmx.h

Modified: head/sys/contrib/octeon-sdk/cvmx-access-native.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-access-native.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-access-native.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -122,6 +122,8 @@ static inline uint64_t cvmx_ptr_to_phys(
         return address + 0x400000000ull;   /* 256MB-512MB is a virtual mapping for the 2nd 256MB */
     else
         return address; /* Looks to be a 1:1 mapped userspace pointer */
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+    return (pmap_kextract((vm_offset_t)ptr));
 #else
 #if CVMX_USE_1_TO_1_TLB_MAPPINGS
     /* We are assumung we're running the Simple Executive standalone. In this
@@ -201,6 +203,15 @@ static inline void *cvmx_phys_to_ptr(uin
         return CASTPTR(void, physical_address - 0x400000000ull);
     else
         return CASTPTR(void, physical_address);
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+#if defined(__mips_n64)
+    return CASTPTR(void, CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, physical_address));
+#else
+    if (physical_address < 0x20000000)
+	return CASTPTR(void, CVMX_ADD_SEG32(CVMX_MIPS32_SPACE_KSEG0, physical_address));
+    else
+	panic("%s: mapping high address (%#jx) not yet supported.\n", __func__, (uintmax_t)physical_address);
+#endif
 #else
 
 #if CVMX_USE_1_TO_1_TLB_MAPPINGS

Modified: head/sys/contrib/octeon-sdk/cvmx-app-init.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-app-init.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-app-init.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -194,6 +194,9 @@ enum cvmx_board_types_enum {
     /* Set aside a range for customer private use.  The SDK won't
     ** use any numbers in this range. */
     CVMX_BOARD_TYPE_CUST_PRIVATE_MIN = 20001,
+#if defined(OCTEON_VENDOR_LANNER)
+    CVMX_BOARD_TYPE_CUST_LANNER_MR320= 20002,
+#endif
     CVMX_BOARD_TYPE_CUST_PRIVATE_MAX = 30000,
 
     /* The remaining range is reserved for future use. */
@@ -265,6 +268,9 @@ static inline const char *cvmx_board_typ
 
         /* Customer private range */
         ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_PRIVATE_MIN)
+#if defined(OCTEON_VENDOR_LANNER)
+	ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_LANNER_MR320)
+#endif
         ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_PRIVATE_MAX)
     }
     return "Unsupported Board";

Modified: head/sys/contrib/octeon-sdk/cvmx-asm.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-asm.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-asm.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -225,12 +225,12 @@ extern "C" {
       unsigned long _v;							\
       ASM_STMT ("rdhwr\t%0,$31\n"					\
 		"\tsll\t%0,%0,0" : "=d"(_v));				\
-      result = (typeof(result))_v;					\
+      result = (__typeof(result))_v;					\
     }									\
   } else {								\
     unsigned long _v;							\
     ASM_STMT ("rdhwr\t%0,$" CVMX_TMP_STR(regstr) : "=d"(_v));		\
-    result = (typeof(result))_v;					\
+    result = (__typeof(result))_v;					\
   }})
   
 

Modified: head/sys/contrib/octeon-sdk/cvmx-cmd-queue.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-cmd-queue.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-cmd-queue.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,7 +49,6 @@
  *
  * <hr>$Revision: 42150 $<hr>
  */
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-fpa.h"
 #include "cvmx-cmd-queue.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-cmd-queue.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-cmd-queue.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-cmd-queue.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -92,8 +92,10 @@
 #ifndef __CVMX_CMD_QUEUE_H__
 #define __CVMX_CMD_QUEUE_H__
 
+#ifndef CVMX_DONT_INCLUDE_CONFIG
 #include "executive-config.h"
 #include "cvmx-config.h"
+#endif
 #include "cvmx-fpa.h"
 
 #ifdef	__cplusplus
@@ -168,6 +170,8 @@ typedef struct
     __cvmx_cmd_queue_state_t state[(CVMX_CMD_QUEUE_END>>16) * 256];
 } __cvmx_cmd_queue_all_state_t;
 
+extern CVMX_SHARED __cvmx_cmd_queue_all_state_t *__cvmx_cmd_queue_state_ptr;
+
 /**
  * Initialize a command queue for use. The initial FPA buffer is
  * allocated and the hardware unit is configured to point to the
@@ -246,7 +250,6 @@ static inline int __cvmx_cmd_queue_get_i
  */
 static inline void __cvmx_cmd_queue_lock(cvmx_cmd_queue_id_t queue_id, __cvmx_cmd_queue_state_t *qptr)
 {
-    extern CVMX_SHARED __cvmx_cmd_queue_all_state_t *__cvmx_cmd_queue_state_ptr;
     int tmp;
     int my_ticket;
     CVMX_PREFETCH(qptr, 0);
@@ -304,7 +307,6 @@ static inline void __cvmx_cmd_queue_unlo
  */
 static inline __cvmx_cmd_queue_state_t *__cvmx_cmd_queue_get_state(cvmx_cmd_queue_id_t queue_id)
 {
-    extern CVMX_SHARED __cvmx_cmd_queue_all_state_t *__cvmx_cmd_queue_state_ptr;
     if (CVMX_ENABLE_PARAMETER_CHECKING)
     {
         if (cvmx_unlikely(queue_id >= CVMX_CMD_QUEUE_END))

Modified: head/sys/contrib/octeon-sdk/cvmx-fpa.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-fpa.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-fpa.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -50,7 +50,6 @@
  *
  */
 
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-fpa.h"
 #include "cvmx-ipd.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-board.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-board.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-board.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -85,6 +85,26 @@ CVMX_SHARED cvmx_helper_link_info_t (*cv
  */
 int cvmx_helper_board_get_mii_address(int ipd_port)
 {
+    /*
+     * Board types we have to know at compile-time.
+     */
+#ifdef OCTEON_BOARD_CAPK_0100ND
+    switch (ipd_port) {
+    case 0:
+	return 2;
+    case 1:
+	return 3;
+    case 2:
+	/* XXX Switch PHY?  */
+	return -1;
+    default:
+	return -1;
+    }
+#endif
+
+    /*
+     * For board types we can determine at runtime.
+     */
     switch (cvmx_sysinfo_get()->board_type)
     {
         case CVMX_BOARD_TYPE_SIM:
@@ -154,6 +174,22 @@ int cvmx_helper_board_get_mii_address(in
                 return -1;
         case CVMX_BOARD_TYPE_BBGW_REF:
             return -1;  /* No PHYs are connected to Octeon, everything is through switch */
+
+	/* Private vendor-defined boards.  */
+#if defined(OCTEON_VENDOR_LANNER)
+	case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
+	    switch (ipd_port) {
+	    case 0:
+		/* XXX Switch PHY?  */
+		return -1;
+	    case 1:
+		return 1;
+	    case 2:
+		return 2;
+	    default:
+		return -1;
+	    }
+#endif
     }
 
     /* Some unknown board. Somebody forgot to update this function... */
@@ -195,6 +231,7 @@ cvmx_helper_link_info_t __cvmx_helper_bo
     /* Unless we fix it later, all links are defaulted to down */
     result.u64 = 0;
 
+#if !defined(OCTEON_BOARD_CAPK_0100ND)
     /* This switch statement should handle all ports that either don't use
         Marvell PHYS, or don't support in-band status */
     switch (cvmx_sysinfo_get()->board_type)
@@ -248,7 +285,21 @@ cvmx_helper_link_info_t __cvmx_helper_bo
                 return result;
             }
             break;
+	/* Private vendor-defined boards.  */
+#if defined(OCTEON_VENDOR_LANNER)
+	case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
+	    /* Port 0 connects to the switch */
+	    if (ipd_port == 0)
+	    {
+                result.s.link_up = 1;
+                result.s.full_duplex = 1;
+                result.s.speed = 1000;
+		return result;
+	    }
+	    break;
+#endif
     }
+#endif
 
     phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
     if (phy_addr != -1)
@@ -322,7 +373,11 @@ cvmx_helper_link_info_t __cvmx_helper_bo
                 and set the resolved bit (bit 11) */
             if (phy_status & (1<<11))
             {
+#if defined(OCTEON_BOARD_CAPK_0100ND)
+                result.s.link_up = (phy_status>>10)&1;
+#else
                 result.s.link_up = 1;
+#endif
                 result.s.full_duplex = ((phy_status>>13)&1);
                 switch ((phy_status>>14)&3)
                 {
@@ -635,6 +690,9 @@ cvmx_helper_board_usb_clock_types_t __cv
 {
     switch (cvmx_sysinfo_get()->board_type) {
     case CVMX_BOARD_TYPE_BBGW_REF:
+#if defined(OCTEON_VENDOR_LANNER)
+    case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
+#endif
             return USB_CLOCK_TYPE_CRYSTAL_12;
     }
     return USB_CLOCK_TYPE_REF_48;

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-errata.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-errata.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-errata.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -51,9 +51,6 @@
  *
  * <hr>$Revision: 42150 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-
 #include "cvmx.h"
 #include "cvmx-fpa.h"
 #include "cvmx-pip.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-fpa.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-fpa.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-fpa.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -48,8 +48,6 @@
  *
  * <hr>$Revision: 41586 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-bootmem.h"
 #include "cvmx-fpa.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-loop.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-loop.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-loop.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,14 +49,11 @@
  *
  * <hr>$Revision: 41586 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-helper.h"
 
 
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /**
  * @INTERNAL
  * Probe a LOOP interface and determine the number of ports

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-npi.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-npi.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-npi.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,14 +49,10 @@
  *
  * <hr>$Revision: 41586 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-helper.h"
 
-
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /**
  * @INTERNAL
  * Probe a NPI interface and determine the number of ports

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-rgmii.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-rgmii.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-rgmii.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,10 +49,6 @@
  *
  * <hr>$Revision: 42417 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-sysinfo.h"
 #include "cvmx-mdio.h"
@@ -60,6 +56,7 @@
 #include "cvmx-helper.h"
 #include "cvmx-helper-board.h"
 
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /**
  * @INTERNAL
  * Probe RGMII ports and determine the number present
@@ -202,6 +199,31 @@ int __cvmx_helper_rgmii_enable(int inter
         cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_TIME(port, interface), 20000);
         cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_INTERVAL(port, interface), 19000);
 
+        /*
+         * Board types we have to know at compile-time.
+         */
+#if defined(OCTEON_BOARD_CAPK_0100ND)
+        cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 26);
+        cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface), 26);
+#else
+	/*
+	 * Vendor-defined board types.
+	 */
+#if defined(OCTEON_VENDOR_LANNER)
+	switch (cvmx_sysinfo_get()->board_type) {
+	case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
+            if (port == 0) {
+                cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 4);
+	    } else {
+                cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 7);
+            }
+            cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface), 0);
+	    break;
+	}
+#else
+        /*
+         * For board types we can determine at runtime.
+         */
         if (OCTEON_IS_MODEL(OCTEON_CN50XX))
         {
             cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 16);
@@ -212,6 +234,8 @@ int __cvmx_helper_rgmii_enable(int inter
             cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface), 24);
             cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface), 24);
         }
+#endif
+#endif
     }
 
     __cvmx_helper_setup_gmx(interface, num_ports);

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-sgmii.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-sgmii.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-sgmii.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,17 +49,13 @@
  *
  * <hr>$Revision: 42417 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-sysinfo.h"
 #include "cvmx-mdio.h"
 #include "cvmx-helper.h"
 #include "cvmx-helper-board.h"
 
-
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /**
  * @INTERNAL
  * Perform initialization required only once for an SGMII port.

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-spi.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-spi.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-spi.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,15 +49,12 @@
  *
  * <hr>$Revision: 42417 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-spi.h"
 #include "cvmx-sysinfo.h"
 #include "cvmx-helper.h"
 
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /* CVMX_HELPER_SPI_TIMEOUT is used to determine how long the SPI initialization
     routines wait for SPI training. You can override the value using
     executive-config.h if necessary */

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-util.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-util.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-util.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -48,8 +48,6 @@
  *
  * <hr>$Revision: 42493 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-bootmem.h"
 #include "cvmx-fpa.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-util.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-util.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-util.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -157,8 +157,6 @@ static inline int cvmx_helper_get_first_
  */
 static inline int cvmx_helper_get_last_ipd_port (int interface)
 {
-    extern int cvmx_helper_ports_on_interface (int interface);
-
     return (cvmx_helper_get_first_ipd_port (interface) +
   	    cvmx_helper_ports_on_interface (interface) - 1);
 }

Modified: head/sys/contrib/octeon-sdk/cvmx-helper-xaui.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper-xaui.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper-xaui.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -49,14 +49,10 @@
  *
  * <hr>$Revision: 42417 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
-#ifdef CVMX_ENABLE_PKO_FUNCTIONS
-
 #include "cvmx.h"
 #include "cvmx-helper.h"
 
-
+#ifdef CVMX_ENABLE_PKO_FUNCTIONS
 /**
  * @INTERNAL
  * Probe a XAUI interface and determine the number of ports

Modified: head/sys/contrib/octeon-sdk/cvmx-helper.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -48,8 +48,6 @@
  *
  * <hr>$Revision: 42150 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-bootmem.h"
 #include "cvmx-fpa.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-helper.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-helper.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-helper.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -52,8 +52,10 @@
 #ifndef __CVMX_HELPER_H__
 #define __CVMX_HELPER_H__
 
+#ifndef CVMX_DONT_INCLUDE_CONFIG
 #include "executive-config.h"
 #include "cvmx-config.h"
+#endif
 #include "cvmx-fpa.h"
 #include "cvmx-wqe.h"
 
@@ -97,7 +99,6 @@ typedef union
 #include "cvmx-helper-rgmii.h"
 #include "cvmx-helper-sgmii.h"
 #include "cvmx-helper-spi.h"
-#include "cvmx-helper-util.h"
 #include "cvmx-helper-xaui.h"
 
 /**
@@ -250,6 +251,8 @@ extern int cvmx_helper_interface_probe(i
  */
 extern int cvmx_helper_configure_loopback(int ipd_port, int enable_internal, int enable_external);
 
+#include "cvmx-helper-util.h"
+
 #endif /* CVMX_ENABLE_PKO_FUNCTIONS */
 
 #ifdef	__cplusplus

Modified: head/sys/contrib/octeon-sdk/cvmx-pko.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-pko.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-pko.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -48,8 +48,6 @@
  *
  * <hr>$Revision: 42150 $<hr>
  */
-#include "executive-config.h"
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-pko.h"
 #include "cvmx-sysinfo.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-platform.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-platform.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-platform.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -103,6 +103,8 @@
     /* To build the simple exec toolchain runtime (newlib) library. We
        should only use features available on all Octeon models.  */
     #define CVMX_BUILD_FOR_TOOLCHAIN
+#elif defined(__FreeBSD__) && defined(_KERNEL)
+    #define CVMX_BUILD_FOR_FREEBSD
 #else
     /* We are building a simple exec standalone image for Octeon */
     #define CVMX_BUILD_FOR_STANDALONE
@@ -117,7 +119,11 @@
  * This is for data structures use by software ONLY,
  * as it is not 1-1 VA-PA mapped.
  */
+#if defined(CVMX_BUILD_FOR_FREEBSD)
+#define CVMX_SHARED
+#else
 #define CVMX_SHARED __attribute__ ((cvmx_shared))
+#endif
 
 
 #if defined(CVMX_BUILD_FOR_UBOOT)
@@ -187,6 +193,10 @@
     #include <string.h>
     #include <assert.h>
 
+#elif defined(CVMX_BUILD_FOR_FREEBSD)
+
+    #include <mips/cavium/cvmx_config.h>
+
 #else
 
     #error Unexpected CVMX_BUILD_FOR_* macro

Modified: head/sys/contrib/octeon-sdk/cvmx-rtc.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-rtc.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-rtc.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -74,7 +74,7 @@ typedef enum
  *
  * @return Supported options, or 0 if RTC is not supported
  */
-static inline cvmx_rtc_options_t cvmx_rtc_supported()
+static inline cvmx_rtc_options_t cvmx_rtc_supported(void)
 {
     static int supported = -1;
 

Modified: head/sys/contrib/octeon-sdk/cvmx-spi.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-spi.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-spi.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -48,7 +48,6 @@
  *
  * <hr>$Revision: 41586 $<hr>
  */
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-mio.h"
 #include "cvmx-pko.h"

Modified: head/sys/contrib/octeon-sdk/cvmx-thunder.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-thunder.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-thunder.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -50,7 +50,6 @@
  *
  */
 
-#include "cvmx-config.h"
 #include "cvmx.h"
 #include "cvmx-sysinfo.h"
 #include "cvmx-thunder.h"
@@ -121,7 +120,7 @@ int cvmx_rtc_ds1374_write(uint32_t time)
     return (rc ? -1 : 0);
 }
 
-int cvmx_rtc_ds1374_alarm_config(int WD, int WDSTR, int AIE)
+static int cvmx_rtc_ds1374_alarm_config(int WD, int WDSTR, int AIE)
 {
     int val;
 
@@ -134,7 +133,7 @@ int cvmx_rtc_ds1374_alarm_config(int WD,
     return 0;
 }
 
-int cvmx_rtc_ds1374_alarm_set(int alarm_on)
+static int cvmx_rtc_ds1374_alarm_set(int alarm_on)
 {
     uint8_t val;
 
@@ -152,7 +151,7 @@ int cvmx_rtc_ds1374_alarm_set(int alarm_
 }
 
 
-int cvmx_rtc_ds1374_alarm_counter_set(uint32_t interval)
+static int cvmx_rtc_ds1374_alarm_counter_set(uint32_t interval)
 {
     int i;
     int rc = 0;
@@ -165,7 +164,8 @@ int cvmx_rtc_ds1374_alarm_counter_set(ui
     return rc;
 }
 
-uint32_t cvmx_rtc_ds1374_alarm_counter_get(void)
+#if 0 /* XXX unused */
+static uint32_t cvmx_rtc_ds1374_alarm_counter_get(void)
 {
     int i;
     uint32_t interval = 0;
@@ -176,6 +176,7 @@ uint32_t cvmx_rtc_ds1374_alarm_counter_g
     }
     return interval;
 }
+#endif
 
 
 #ifdef CVMX_RTC_DEBUG

Modified: head/sys/contrib/octeon-sdk/cvmx-usb.c
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-usb.c	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-usb.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -194,7 +194,7 @@ typedef struct
 /* This macro logs out when a function returns a value */
 #define CVMX_USB_RETURN(v)                                              \
     do {                                                                \
-        typeof(v) r = v;                                                \
+        __typeof(v) r = v;                                              \
         if (cvmx_unlikely(usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_DEBUG_CALLS))    \
             cvmx_dprintf("%*s%s: returned %s(%d)\n", 2*--usb->indent, "", __FUNCTION__, #v, r); \
         return r;                                                       \
@@ -3648,3 +3648,20 @@ cvmx_usb_status_t cvmx_usb_device_disabl
     CVMX_USB_RETURN(CVMX_USB_SUCCESS);
 }
 
+extern void cvmx_usb_set_toggle(cvmx_usb_state_t *state, int endpoint_num, int toggle)
+{
+    cvmx_usb_internal_state_t *usb = (cvmx_usb_internal_state_t*)state;
+    cvmx_usb_pipe_t *pipe = usb->pipe + endpoint_num;
+
+    pipe->pid_toggle = !!toggle;
+}
+
+extern int cvmx_usb_get_toggle(cvmx_usb_state_t *state, int endpoint_num)
+{
+    cvmx_usb_internal_state_t *usb = (cvmx_usb_internal_state_t*)state;
+    cvmx_usb_pipe_t *pipe = usb->pipe + endpoint_num;
+
+    if (pipe->pid_toggle)
+	    return (1);
+    return (0);
+}

Modified: head/sys/contrib/octeon-sdk/cvmx-usb.h
==============================================================================
--- head/sys/contrib/octeon-sdk/cvmx-usb.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/cvmx-usb.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -1122,6 +1122,13 @@ extern cvmx_usb_status_t cvmx_usb_device
 extern cvmx_usb_status_t cvmx_usb_device_disable_endpoint(cvmx_usb_state_t *state,
                                                           int endpoint_num);
 
+/*
+ * The FreeBSD host driver uses these functions to manipulate the toggle to deal
+ * more easily with endpoint management.
+ */
+extern void cvmx_usb_set_toggle(cvmx_usb_state_t *state, int endpoint_num, int toggle);
+extern int cvmx_usb_get_toggle(cvmx_usb_state_t *state, int endpoint_num);
+
 #ifdef	__cplusplus
 }
 #endif

Modified: head/sys/contrib/octeon-sdk/octeon-model.h
==============================================================================
--- head/sys/contrib/octeon-sdk/octeon-model.h	Tue Jul 20 19:13:31 2010	(r210310)
+++ head/sys/contrib/octeon-sdk/octeon-model.h	Tue Jul 20 19:25:11 2010	(r210311)
@@ -254,7 +254,7 @@ extern "C" {
        && (((chip_model) & OCTEON_58XX_MODEL_MASK) < ((arg_model) & OCTEON_58XX_MODEL_MASK))) \
     )))
 
-#if defined(USE_RUNTIME_MODEL_CHECKS) || defined(__U_BOOT__) || (defined(__linux__) && defined(__KERNEL__))
+#if defined(USE_RUNTIME_MODEL_CHECKS) || defined(__U_BOOT__) || (defined(__linux__) && defined(__KERNEL__)) || (defined(__FreeBSD__) && defined(_KERNEL))
 
 /* NOTE: This for internal use only!!!!! */
 static inline int __octeon_is_model_runtime__(uint32_t model)

Added: head/sys/mips/cavium/ciu.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/mips/cavium/ciu.c	Tue Jul 20 19:25:11 2010	(r210311)
@@ -0,0 +1,359 @@
+/*-
+ * Copyright (c) 2010 Juli Mallett <jmallett at FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/interrupt.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/rman.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+#include <machine/intr_machdep.h>
+
+#include <contrib/octeon-sdk/cvmx.h>
+#include <contrib/octeon-sdk/cvmx-interrupt.h>
+
+/*
+ * This bus sits between devices/buses and nexus and handles CIU interrupts
+ * and passes everything else through.  It should really be a nexus subclass
+ * or something, but for now this will be sufficient.
+ */
+
+#define	CIU_IRQ_HARD		(0)
+
+#define	CIU_IRQ_EN0_BEGIN	CVMX_IRQ_WORKQ0
+#define	CIU_IRQ_EN0_END		CVMX_IRQ_BOOTDMA
+#define	CIU_IRQ_EN0_COUNT	((CIU_IRQ_EN0_END - CIU_IRQ_EN0_BEGIN) + 1)
+
+#define	CIU_IRQ_EN1_BEGIN	CVMX_IRQ_WDOG0
+#define	CIU_IRQ_EN1_END		CVMX_IRQ_WDOG15
+#define	CIU_IRQ_EN1_COUNT	((CIU_IRQ_EN1_END - CIU_IRQ_EN1_BEGIN) + 1)
+
+struct ciu_softc {
+	struct rman irq_rman;
+	struct resource *ciu_irq;
+};
+
+static mips_intrcnt_t ciu_en0_intrcnt[CIU_IRQ_EN0_COUNT];
+static mips_intrcnt_t ciu_en1_intrcnt[CIU_IRQ_EN1_COUNT];
+
+static struct intr_event *ciu_en0_intr_events[CIU_IRQ_EN0_COUNT];
+static struct intr_event *ciu_en1_intr_events[CIU_IRQ_EN1_COUNT];
+
+static int		ciu_probe(device_t);
+static int		ciu_attach(device_t);
+static struct resource	*ciu_alloc_resource(device_t, device_t, int, int *,
+					    u_long, u_long, u_long, u_int);
+static int		ciu_setup_intr(device_t, device_t, struct resource *,
+				       int, driver_filter_t *, driver_intr_t *,
+				       void *, void **);
+static void		ciu_hinted_child(device_t, const char *, int);
+
+static void		ciu_en0_intr_mask(void *);
+static void		ciu_en0_intr_unmask(void *);
+
+static void		ciu_en1_intr_mask(void *);
+static void		ciu_en1_intr_unmask(void *);
+
+static int		ciu_intr(void *);
+
+static int
+ciu_probe(device_t dev)
+{
+	if (device_get_unit(dev) != 0)
+		return (ENXIO);
+
+	device_set_desc(dev, "Cavium Octeon Central Interrupt Unit");
+	return (0);
+}
+
+static int
+ciu_attach(device_t dev)
+{
+	char name[MAXCOMLEN + 1];
+	struct ciu_softc *sc;
+	unsigned i;
+	int error;
+	int rid;
+
+	sc = device_get_softc(dev);
+
+	rid = 0;
+	sc->ciu_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, CIU_IRQ_HARD,
+					 CIU_IRQ_HARD, 1, RF_ACTIVE);
+	if (sc->ciu_irq == NULL) {
+		device_printf(dev, "could not allocate irq%d\n", CIU_IRQ_HARD);
+		return (ENXIO);
+	}
+
+	error = bus_setup_intr(dev, sc->ciu_irq, INTR_TYPE_MISC, ciu_intr,
+			       NULL, sc, NULL);
+	if (error != 0) {
+		device_printf(dev, "bus_setup_intr failed: %d\n", error);
+		return (error);
+	}
+
+	sc->irq_rman.rm_type = RMAN_ARRAY;
+	sc->irq_rman.rm_descr = "CIU IRQ";
+	
+	error = rman_init(&sc->irq_rman);
+	if (error != 0)
+		return (error);
+
+	/*
+	 * We have two contiguous IRQ regions, use a single rman.
+	 */
+	error = rman_manage_region(&sc->irq_rman, CIU_IRQ_EN0_BEGIN,
+				   CIU_IRQ_EN1_END);
+	if (error != 0)
+		return (error);
+
+	for (i = 0; i < CIU_IRQ_EN0_COUNT; i++) {
+		snprintf(name, sizeof name, "int%d:", i + CIU_IRQ_EN0_BEGIN);
+		ciu_en0_intrcnt[i] = mips_intrcnt_create(name);
+	}
+
+	for (i = 0; i < CIU_IRQ_EN1_COUNT; i++) {
+		snprintf(name, sizeof name, "int%d:", i + CIU_IRQ_EN1_BEGIN);
+		ciu_en1_intrcnt[i] = mips_intrcnt_create(name);
+	}
+
+	bus_generic_probe(dev);
+	bus_generic_attach(dev);
+
+	return (0);
+}
+
+static struct resource *
+ciu_alloc_resource(device_t bus, device_t child, int type, int *rid,
+		   u_long start, u_long end, u_long count, u_int flags)
+{
+	struct resource *res;
+	struct ciu_softc *sc;
+	
+	sc = device_get_softc(bus);
+
+	switch (type) {
+	case SYS_RES_IRQ:
+		break;
+	default:
+		return (bus_alloc_resource(device_get_parent(bus), type, rid,
+					   start, end, count, flags));
+	}
+
+	/*
+	 * One interrupt at a time for now.
+	 */
+	if (start != end)
+		return (NULL);
+
+	res = rman_reserve_resource(&sc->irq_rman, start, end, count, flags,
+				    child);
+	if (res != NULL)
+		return (res);
+
+	return (NULL);
+}
+
+static int
+ciu_setup_intr(device_t bus, device_t child, struct resource *res, int flags,
+	       driver_filter_t *filter, driver_intr_t *intr, void *arg,
+	       void **cookiep)
+{
+	struct intr_event *event, **eventp;
+	void (*mask_func)(void *);
+	void (*unmask_func)(void *);
+	mips_intrcnt_t intrcnt;
+	int error;
+	int irq;
+
+	irq = rman_get_start(res);
+	if (irq <= CIU_IRQ_EN0_END) {
+		eventp = &ciu_en0_intr_events[irq - CIU_IRQ_EN0_BEGIN];
+		intrcnt = ciu_en0_intrcnt[irq - CIU_IRQ_EN0_BEGIN];
+		mask_func = ciu_en0_intr_mask;
+		unmask_func = ciu_en0_intr_unmask;
+	} else {
+		eventp = &ciu_en1_intr_events[irq - CIU_IRQ_EN1_BEGIN];
+		intrcnt = ciu_en1_intrcnt[irq - CIU_IRQ_EN1_BEGIN];
+		mask_func = ciu_en1_intr_mask;
+		unmask_func = ciu_en1_intr_unmask;
+	}
+
+	if ((event = *eventp) == NULL) {
+		error = intr_event_create(eventp, (void *)(uintptr_t)irq, 0,
+		    irq, mask_func, unmask_func, NULL, NULL, "int%d", irq);
+		if (error != 0)
+			return (error);
+
+		event = *eventp;
+
+		unmask_func((void *)(uintptr_t)irq);
+	}
+
+	intr_event_add_handler(event, device_get_nameunit(child),
+	    filter, intr, arg, intr_priority(flags), flags, cookiep);
+
+	mips_intrcnt_setname(intrcnt, event->ie_fullname);
+
+	return (0);
+}
+
+static void
+ciu_hinted_child(device_t bus, const char *dname, int dunit)
+{
+	BUS_ADD_CHILD(bus, 0, dname, dunit);
+}
+
+static void
+ciu_en0_intr_mask(void *arg)
+{
+	uint64_t mask;
+	int irq;
+
+	irq = (uintptr_t)arg;
+	mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num()*2));
+	mask &= ~(1ull << (irq - CIU_IRQ_EN0_BEGIN));
+	cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num()*2), mask);
+}
+
+static void
+ciu_en0_intr_unmask(void *arg)
+{
+	uint64_t mask;
+	int irq;
+
+	irq = (uintptr_t)arg;
+	mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num()*2));
+	mask |= 1ull << (irq - CIU_IRQ_EN0_BEGIN);
+	cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num()*2), mask);
+}
+
+static void
+ciu_en1_intr_mask(void *arg)
+{
+	uint64_t mask;
+	int irq;
+
+	irq = (uintptr_t)arg;
+	mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num()*2));
+	mask &= ~(1ull << (irq - CIU_IRQ_EN1_BEGIN));
+	cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num()*2), mask);
+}
+
+static void
+ciu_en1_intr_unmask(void *arg)
+{
+	uint64_t mask;
+	int irq;
+
+	irq = (uintptr_t)arg;
+	mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num()*2));
+	mask |= 1ull << (irq - CIU_IRQ_EN1_BEGIN);
+	cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num()*2), mask);
+}
+
+static int
+ciu_intr(void *arg)
+{
+	struct ciu_softc *sc;
+	uint64_t en0_sum, en1_sum;
+	uint64_t en0_mask, en1_mask;
+	int irq_index;
+	int error;
+
+	sc = arg;
+	(void)sc;
+
+	en0_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(cvmx_get_core_num()*2));
+	en1_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
+
+	en0_mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num()*2));
+	en1_mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num()*2));
+
+	en0_sum &= en0_mask;
+	en1_sum &= en1_mask;
+
+	if (en0_sum == 0 && en1_sum == 0)
+		return (FILTER_STRAY);
+

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list