From 5291aedf005b652cf6e6b19d848dcd5b262c3e60 Mon Sep 17 00:00:00 2001
From: Michal Toman <mtoman@fedoraproject.org>
Date: Wed, 11 May 2016 10:27:56 +0200
Subject: [PATCH] Add support for mipsel (malta) and mips64el (malta, octeon)

---
 ...emulation-for-unaligned-LS-DXC1-instructi.patch | 32 ++++++++
 ...-Add-Octeon-III-CN7xxx-interface-detectio.patch | 89 ++++++++++++++++++++++
 ...t-restoration-of-MSA-context-in-non-MSA-k.patch | 66 ++++++++++++++++
 MIPS-Soften-VDSO-Werror.patch                      | 35 +++++++++
 Makefile.config                                    | 24 +++++-
 config-mips-generic                                | 70 +++++++++++++++++
 config-mips32r2                                    | 35 +++++++++
 config-mips64r2                                    | 40 ++++++++++
 config-mips64r2-octeon                             | 31 ++++++++
 filter-mips64el.sh                                 | 12 +++
 filter-mipsel.sh                                   | 12 +++
 kernel.spec                                        | 69 ++++++++++++++++-
 12 files changed, 509 insertions(+), 6 deletions(-)
 create mode 100644 MIPS-Allow-emulation-for-unaligned-LS-DXC1-instructi.patch
 create mode 100644 MIPS-Octeon-Add-Octeon-III-CN7xxx-interface-detectio.patch
 create mode 100644 MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-k.patch
 create mode 100644 MIPS-Soften-VDSO-Werror.patch
 create mode 100644 config-mips-generic
 create mode 100644 config-mips32r2
 create mode 100644 config-mips64r2
 create mode 100644 config-mips64r2-octeon
 create mode 100644 filter-mips64el.sh
 create mode 100644 filter-mipsel.sh

diff --git a/MIPS-Allow-emulation-for-unaligned-LS-DXC1-instructi.patch b/MIPS-Allow-emulation-for-unaligned-LS-DXC1-instructi.patch
new file mode 100644
index 0000000..e76adcc
--- /dev/null
+++ b/MIPS-Allow-emulation-for-unaligned-LS-DXC1-instructi.patch
@@ -0,0 +1,32 @@
+From 9bee311af5365f0a1711c7b254db13c160d9b5c9 Mon Sep 17 00:00:00 2001
+From: Paul Burton <paul.burton@imgtec.com>
+Date: Thu, 21 Apr 2016 12:25:38 +0100
+Subject: MIPS: Allow emulation for unaligned [LS]DXC1 instructions
+
+If an address error exception occurs for a LDXC1 or SDXC1 instruction,
+within the cop1x opcode space, allow it to be passed through to the FPU
+emulator rather than resulting in a SIGILL. This causes LDXC1 & SDXC1 to
+be handled in a manner consistent with the more common LDC1 & SDC1
+instructions.
+
+Signed-off-by: Paul Burton <paul.burton@imgtec.com>
+Cc: Aurelien Jarno <aurelien@aurel32.net>
+---
+ arch/mips/kernel/unaligned.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
+index 5c62065..28b3af7 100644
+--- a/arch/mips/kernel/unaligned.c
++++ b/arch/mips/kernel/unaligned.c
+@@ -1191,6 +1191,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
+ 	case ldc1_op:
+ 	case swc1_op:
+ 	case sdc1_op:
++	case cop1x_op:
+ 		die_if_kernel("Unaligned FP access in kernel code", regs);
+ 		BUG_ON(!used_math());
+ 
+-- 
+2.5.0
+
diff --git a/MIPS-Octeon-Add-Octeon-III-CN7xxx-interface-detectio.patch b/MIPS-Octeon-Add-Octeon-III-CN7xxx-interface-detectio.patch
new file mode 100644
index 0000000..72145e7
--- /dev/null
+++ b/MIPS-Octeon-Add-Octeon-III-CN7xxx-interface-detectio.patch
@@ -0,0 +1,89 @@
+From 9f33d523753c81dd1a3199de304d958018082df4 Mon Sep 17 00:00:00 2001
+From: Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com>
+Date: Wed, 3 Feb 2016 18:01:36 +0000
+Subject: MIPS: Octeon: Add Octeon III CN7xxx interface detection
+
+Add basic CN7XXX interface detection.
+
+This allows the kernel to boot with ethernet working as it initializes
+the ethernet ports with SGMII instead of defaulting to RGMII routines.
+
+Tested on the utm8 from Rhino Labs with a CN7130.
+
+Signed-off-by: Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com>
+Acked-by: David Daney <david.daney@cavium.com>
+---
+ arch/mips/cavium-octeon/executive/cvmx-helper.c | 43 +++++++++++++++++++++++++
+ 1 file changed, 43 insertions(+)
+
+diff --git a/arch/mips/cavium-octeon/executive/cvmx-helper.c b/arch/mips/cavium-octeon/executive/cvmx-helper.c
+index 376701f..ff26d02 100644
+--- a/arch/mips/cavium-octeon/executive/cvmx-helper.c
++++ b/arch/mips/cavium-octeon/executive/cvmx-helper.c
+@@ -87,6 +87,8 @@ int cvmx_helper_get_number_of_interfaces(void)
+ 		return 9;
+ 	if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
+ 		return 4;
++	if (OCTEON_IS_MODEL(OCTEON_CN7XXX))
++		return 5;
+ 	else
+ 		return 3;
+ }
+@@ -260,6 +262,41 @@ static cvmx_helper_interface_mode_t __cvmx_get_mode_octeon2(int interface)
+ }
+ 
+ /**
++ * @INTERNAL
++ * Return interface mode for CN7XXX.
++ */
++static cvmx_helper_interface_mode_t __cvmx_get_mode_cn7xxx(int interface)
++{
++	union cvmx_gmxx_inf_mode mode;
++
++	mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
++
++	switch (interface) {
++	case 0:
++	case 1:
++		switch (mode.cn68xx.mode) {
++		case 0:
++			return CVMX_HELPER_INTERFACE_MODE_DISABLED;
++		case 1:
++		case 2:
++			return CVMX_HELPER_INTERFACE_MODE_SGMII;
++		case 3:
++			return CVMX_HELPER_INTERFACE_MODE_XAUI;
++		default:
++			return CVMX_HELPER_INTERFACE_MODE_SGMII;
++		}
++	case 2:
++		return CVMX_HELPER_INTERFACE_MODE_NPI;
++	case 3:
++		return CVMX_HELPER_INTERFACE_MODE_LOOP;
++	case 4:
++		return CVMX_HELPER_INTERFACE_MODE_RGMII;
++	default:
++		return CVMX_HELPER_INTERFACE_MODE_DISABLED;
++	}
++}
++
++/**
+  * Get the operating mode of an interface. Depending on the Octeon
+  * chip and configuration, this function returns an enumeration
+  * of the type of packet I/O supported by an interface.
+@@ -278,6 +315,12 @@ cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface)
+ 		return CVMX_HELPER_INTERFACE_MODE_DISABLED;
+ 
+ 	/*
++	 * OCTEON III models
++	 */
++	if (OCTEON_IS_MODEL(OCTEON_CN7XXX))
++		return __cvmx_get_mode_cn7xxx(interface);
++
++	/*
+ 	 * Octeon II models
+ 	 */
+ 	if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF71XX))
+-- 
+2.5.0
+
diff --git a/MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-k.patch b/MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-k.patch
new file mode 100644
index 0000000..0e855c6
--- /dev/null
+++ b/MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-k.patch
@@ -0,0 +1,66 @@
+From 2a05aa9e54c0cdf51998cf94caea1ac182d862be Mon Sep 17 00:00:00 2001
+From: Paul Burton <paul.burton@imgtec.com>
+Date: Thu, 21 Apr 2016 18:04:53 +0100
+Subject: MIPS: Prevent "restoration" of MSA context in non-MSA kernels
+
+If a kernel doesn't support MSA context (ie. CONFIG_CPU_HAS_MSA=n) then
+it will only keep 64 bits per FP register in thread context, and the
+calls to set_fpr64 in restore_msa_extcontext will overrun the end of the
+FP register context into the FCSR & MSACSR values. GCC 6.x has become
+smart enough to detect this & complain like so:
+
+    arch/mips/kernel/signal.c: In function 'protected_restore_fp_context':
+    ./arch/mips/include/asm/processor.h:114:17: error: array subscript is above array bounds [-Werror=array-bounds]
+      fpr->val##width[FPR_IDX(width, idx)] = val;   \
+      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
+    ./arch/mips/include/asm/processor.h:118:1: note: in expansion of macro 'BUILD_FPR_ACCESS'
+     BUILD_FPR_ACCESS(64)
+
+The only way to trigger this code to run would be for a program to set
+up an artificial extended MSA context structure following a sigframe &
+execute sigreturn. Whilst this doesn't allow a program to write to any
+state that it couldn't already, it makes little sense to allow this
+"restoration" of MSA context in a system that doesn't support MSA.
+
+Fix this by killing a program with SIGSYS if it tries something as crazy
+as "restoring" fake MSA context in this way, also fixing the build error
+& allowing for most of restore_msa_extcontext to be optimised out of
+kernels without support for MSA.
+
+Signed-off-by: Paul Burton <paul.burton@imgtec.com>
+Reported-by: Michal Toman <michal.toman@imgtec.com>
+Fixes: bf82cb30c7e5 ("MIPS: Save MSA extended context around signals")
+Cc: James Hogan <james.hogan@imgtec.com>
+Cc: stable <stable@vger.kernel.org> # v4.3+
+---
+ arch/mips/kernel/signal.c | 7 +++++--
+ 1 file changed, 5 insertions(+), 2 deletions(-)
+
+diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
+index bf792e2..fc7c1f0 100644
+--- a/arch/mips/kernel/signal.c
++++ b/arch/mips/kernel/signal.c
+@@ -195,6 +195,9 @@ static int restore_msa_extcontext(void __user *buf, unsigned int size)
+ 	unsigned int csr;
+ 	int i, err;
+ 
++	if (!config_enabled(CONFIG_CPU_HAS_MSA))
++		return SIGSYS;
++
+ 	if (size != sizeof(*msa))
+ 		return -EINVAL;
+ 
+@@ -398,8 +401,8 @@ int protected_restore_fp_context(void __user *sc)
+ 	}
+ 
+ fp_done:
+-	if (used & USED_EXTCONTEXT)
+-		err |= restore_extcontext(sc_to_extcontext(sc));
++	if (!err && (used & USED_EXTCONTEXT))
++		err = restore_extcontext(sc_to_extcontext(sc));
+ 
+ 	return err ?: sig;
+ }
+-- 
+2.5.0
+
diff --git a/MIPS-Soften-VDSO-Werror.patch b/MIPS-Soften-VDSO-Werror.patch
new file mode 100644
index 0000000..e901910
--- /dev/null
+++ b/MIPS-Soften-VDSO-Werror.patch
@@ -0,0 +1,35 @@
+From 016e546b997aade58011f5e3b2ca71a7634e39cf Mon Sep 17 00:00:00 2001
+From: Michal Toman <mtoman@fedoraproject.org>
+Date: Tue, 19 Apr 2016 15:29:26 +0200
+Subject: MIPS: Soften VDSO -Werror
+
+Signed-off-by: Michal Toman <mtoman@fedoraproject.org>
+---
+ arch/mips/vdso/Makefile | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
+index ee3617c..4b361da 100644
+--- a/arch/mips/vdso/Makefile
++++ b/arch/mips/vdso/Makefile
+@@ -95,7 +95,7 @@ ifdef CONFIG_MIPS32_O32
+ 
+ obj-vdso-o32 := $(obj-vdso-y:%.o=$(obj)/%-o32.o)
+ 
+-$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32
++$(obj-vdso-o32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=32 -Wno-error=shift-count-overflow
+ $(obj-vdso-o32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=32
+ 
+ $(obj)/%-o32.o: $(src)/%.S FORCE
+@@ -131,7 +131,7 @@ ifdef CONFIG_MIPS32_N32
+ 
+ obj-vdso-n32 := $(obj-vdso-y:%.o=$(obj)/%-n32.o)
+ 
+-$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32
++$(obj-vdso-n32): KBUILD_CFLAGS := $(cflags-vdso) -mabi=n32 -Wno-error=shift-count-overflow
+ $(obj-vdso-n32): KBUILD_AFLAGS := $(aflags-vdso) -mabi=n32
+ 
+ $(obj)/%-n32.o: $(src)/%.S FORCE
+-- 
+2.5.0
+
diff --git a/Makefile.config b/Makefile.config
index 148e21f..e4dcf1e 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -12,9 +12,11 @@ CONFIGFILES	= \
 	$(CFG)-armv7hl.config $(CFG)-armv7hl-lpae.config \
 	$(CFG)-aarch64.config \
 	$(CFG)-ppc64.config $(CFG)-ppc64p7.config $(CFG)-ppc64-debug.config \
-	$(CFG)-ppc64le.config $(CFG)-ppc64le-debug.config
+	$(CFG)-ppc64le.config $(CFG)-ppc64le-debug.config \
+	$(CFG)-mipsel.config \
+	$(CFG)-mips64el.config $(CFG)-mips64el-octeon.config
 
-PLATFORMS	= x86 x86_64 powerpc s390x arm arm64
+PLATFORMS	= x86 x86_64 powerpc s390x arm arm64 mips
 TEMPFILES	= $(addprefix temp-, $(addsuffix -generic, $(PLATFORMS)))
 
 configs: $(CONFIGFILES)
@@ -83,6 +85,15 @@ temp-powerpc64-debug-generic: config-powerpc64-generic temp-debug-generic
 temp-s390-generic: config-s390x temp-generic
 	perl merge.pl $^ > $@
 
+temp-mips-generic: config-mips-generic temp-generic
+	perl merge.pl $^ > $@
+
+temp-mipsel: config-mips32r2 temp-mips-generic
+	perl merge.pl $^ > $@
+
+temp-mips64el: config-mips64r2 temp-mips-generic
+	perl merge.pl $^ > $@
+
 $(CFG)-i686-PAE.config: config-i686-PAE temp-x86-32-generic
 	perl merge.pl $^ i386 > $@
 
@@ -127,3 +138,12 @@ $(CFG)-armv7hl-lpae.config: /dev/null temp-armv7-lpae
 
 $(CFG)-aarch64.config: /dev/null temp-arm64
 	perl merge.pl $^ arm64 > $@
+
+$(CFG)-mipsel.config: /dev/null temp-mipsel
+	perl merge.pl $^ mips > $@
+
+$(CFG)-mips64el.config: /dev/null temp-mips64el
+	perl merge.pl $^ mips > $@
+
+$(CFG)-mips64el-octeon.config: config-mips64r2-octeon temp-mips64el
+	perl merge.pl $^ mips > $@
diff --git a/config-mips-generic b/config-mips-generic
new file mode 100644
index 0000000..6f54be5
--- /dev/null
+++ b/config-mips-generic
@@ -0,0 +1,70 @@
+CONFIG_MIPS_MALTA=y
+CONFIG_CPU_LITTLE_ENDIAN=y
+# CONFIG_CPU_HAS_MSA is not set
+CONFIG_PAGE_SIZE_4KB=y
+CONFIG_KVM=m
+CONFIG_MIPS_O32_FP64_SUPPORT=y
+# CONFIG_IRQ_DOMAIN_DEBUG is not set
+CONFIG_BRCMSTB_GISB_ARB=y
+# CONFIG_MIPS_CDMM is not set
+CONFIG_MTD_OF_PARTS=m
+# CONFIG_OF_UNITTEST is not set
+# CONFIG_OF_OVERLAY is not set
+CONFIG_DM9000=m
+CONFIG_DM9000_FORCE_SIMPLE_PHY_POLL=y
+CONFIG_AX88796=m
+CONFIG_AX88796_93CX6=y
+CONFIG_SMC91X=m
+CONFIG_MDIO_BUS_MUX_GPIO=m
+CONFIG_MDIO_BUS_MUX_MMIOREG=m
+CONFIG_KEYBOARD_BCM=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_SERIAL_BCM63XX=y
+CONFIG_SERIAL_BCM63XX_CONSOLE=y
+CONFIG_I2C_IMG=m
+# CONFIG_GPIO_74XX_MMIO is not set
+# CONFIG_POWER_RESET_BRCMSTB is not set
+# CONFIG_POWER_RESET_GPIO is not set
+# CONFIG_POWER_RESET_GPIO_RESTART is not set
+CONFIG_HW_PERF_EVENTS=y
+CONFIG_THERMAL=y
+# CONFIG_SENSORS_NTC_THERMISTOR is not set
+CONFIG_IMGPDC_WDT=y
+CONFIG_SSB_DRIVER_MIPS=y
+CONFIG_SSB_DRIVER_EXTIF=y
+# CONFIG_SSB_PCICORE_HOSTMODE is not set
+CONFIG_BCMA_DRIVER_MIPS=y
+# CONFIG_BCMA_DRIVER_PCI_HOSTMODE is not set
+CONFIG_FB_SSD1307=m
+CONFIG_SND_MIPS=y
+# CONFIG_SND_SUN4I_CODEC is not set
+# CONFIG_SND_SUN4I_SPDIF is not set
+CONFIG_SND_SOC_AC97_CODEC=m
+CONFIG_SND_SOC_TAS571X=m
+CONFIG_MMC_DW=m
+CONFIG_IMG_MDC_DMA=m
+CONFIG_MIPS_PLATFORM_DEVICES=y
+CONFIG_RAS=y
+CONFIG_DEBUG_STACKOVERFLOW=y
+# CONFIG_DEBUG_OBJECTS_WORK is not set
+# CONFIG_CMDLINE_BOOL is not set
+# CONFIG_SPINLOCK_TEST is not set
+# CONFIG_SCACHE_DEBUGFS is not set
+CONFIG_CRYPTO_DEV_IMGTEC_HASH=m
+# CONFIG_IRQ_POLL is not set
+# CONFIG_KVM_GUEST is not set
+# CONFIG_DEBUG_ZBOOT is not set
+# CONFIG_MTD_BCM47XXSFLASH is not set
+CONFIG_INPUT_PWM_BEEPER=m
+CONFIG_MIPS_EJTAG_FDC_TTY=y
+CONFIG_MIPS_EJTAG_FDC_EARLYCON=y
+CONFIG_MIPS_EJTAG_FDC_KGDB=y
+CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN=3
+CONFIG_BACKLIGHT_PWM=m
+CONFIG_MMC_DW_PLTFM=m
+CONFIG_MMC_DW_EXYNOS=m
+CONFIG_MMC_DW_K3=m
+CONFIG_COMMON_CLK_SI570=y
+# CONFIG_ARM_TIMER_SP804 is not set
+# CONFIG_CRASH is not set
+# CONFIG_CRASH_DUMP is not set
diff --git a/config-mips32r2 b/config-mips32r2
new file mode 100644
index 0000000..26190f1
--- /dev/null
+++ b/config-mips32r2
@@ -0,0 +1,35 @@
+CONFIG_32BIT=y
+CONFIG_CPU_MIPS32_R2=y
+# CONFIG_CPU_MIPS32_3_5_FEATURES is not set
+# CONFIG_CPU_MIPS32_R5_FEATURES is not set
+# CONFIG_KVM_GUEST is not set
+CONFIG_FORCE_MAX_ZONEORDER=11
+CONFIG_HIGHMEM=y
+CONFIG_NR_CPUS=64
+CONFIG_RAPIDIO_TSI721=m
+CONFIG_RAPIDIO_DISC_TIMEOUT=30
+CONFIG_RAPIDIO_ENABLE_RX_TX_PORTS=y
+CONFIG_RAPIDIO_DMA_ENGINE=y
+# CONFIG_RAPIDIO_DEBUG is not set
+CONFIG_RAPIDIO_TSI57X=m
+CONFIG_RAPIDIO_CPS_XX=m
+CONFIG_RAPIDIO_TSI568=m
+CONFIG_RAPIDIO_CPS_GEN2=m
+# CONFIG_RAPIDIO_MPORT_CDEV is not set
+CONFIG_RIONET=m
+# CONFIG_MIPS_CPS_NS16550 is not set
+CONFIG_KVM_MIPS_DYN_TRANS=y
+CONFIG_KVM_MIPS_DEBUG_COP0_COUNTERS=y
+CONFIG_LBDAF=y
+# CONFIG_MIPS_MT_SMP is not set
+# CONFIG_MIPS_VPE_LOADER is not set
+# CONFIG_MIPS_CMP is not set
+CONFIG_MIPS_CPS=y
+CONFIG_HOTPLUG_PCI_SHPC=m
+CONFIG_RAPIDIO=m
+CONFIG_NET_VENDOR_TOSHIBA=y
+CONFIG_TC35815=m
+CONFIG_MMC_DW_PCI=m
+CONFIG_RIONET_TX_SIZE=128
+CONFIG_RIONET_RX_SIZE=128
+CONFIG_SSB_DRIVER_GIGE=y
diff --git a/config-mips64r2 b/config-mips64r2
new file mode 100644
index 0000000..e01e779
--- /dev/null
+++ b/config-mips64r2
@@ -0,0 +1,40 @@
+CONFIG_64BIT=y
+CONFIG_CPU_MIPS64_R2=y
+CONFIG_MIPS32_O32=y
+CONFIG_MIPS32_N32=y
+CONFIG_FORCE_MAX_ZONEORDER=12
+CONFIG_TRANSPARENT_HUGEPAGE=y
+CONFIG_NR_CPUS=32
+CONFIG_MIPS_O32_FP64_SUPPORT=y
+# CONFIG_MTD_BCM47XXSFLASH is not set
+# CONFIG_MTD_PCMCIA is not set
+# CONFIG_MTD_GPIO_ADDR is not set
+# CONFIG_MTD_LATCH_ADDR is not set
+CONFIG_INPUT_PWM_BEEPER=m
+CONFIG_MIPS_EJTAG_FDC_TTY=y
+CONFIG_MIPS_EJTAG_FDC_EARLYCON=y
+CONFIG_MIPS_EJTAG_FDC_KGDB=y
+CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN=3
+CONFIG_SSB_DRIVER_EXTIF=y
+CONFIG_BACKLIGHT_PWM=m
+CONFIG_MMC_DW_PLTFM=m
+CONFIG_MMC_DW_EXYNOS=m
+CONFIG_MMC_DW_K3=m
+# CONFIG_EDAC is not set
+CONFIG_MIPS_MT_SMP=y
+CONFIG_SCHED_SMT=y
+CONFIG_MIPS_MT_FPAFF=y
+# CONFIG_MIPS_VPE_LOADER is not set
+CONFIG_MIPS_CMP=y
+CONFIG_MIPS_CPS=y
+CONFIG_HOTPLUG_PCI_SHPC=y
+# CONFIG_RAPIDIO is not set
+CONFIG_NET_VENDOR_TOSHIBA=y
+# CONFIG_TC35815 is not set
+# CONFIG_MDIO_OCTEON is not set
+CONFIG_SSB_DRIVER_GIGE=y
+# CONFIG_MIPS_CPS_NS16550 is not set
+CONFIG_MMC_DW_PCI=y
+CONFIG_COMMON_CLK_SI570=y
+# CONFIG_ARM_TIMER_SP804 is not set
+# CONFIG_DEBUG_ZBOOT is not set
diff --git a/config-mips64r2-octeon b/config-mips64r2-octeon
new file mode 100644
index 0000000..3948857
--- /dev/null
+++ b/config-mips64r2-octeon
@@ -0,0 +1,31 @@
+# CONFIG_MIPS_MALTA is not set
+# CONFIG_PCI is not set
+CONFIG_CAVIUM_OCTEON_SOC=y
+CONFIG_CAVIUM_CN63XXP1=y
+CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE=2
+# CONFIG_CAVIUM_OCTEON_2ND_KERNEL is not set
+CONFIG_CAVIUM_OCTEON_LOCK_L2=y
+CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB=y
+CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION=y
+CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT=y
+CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT=y
+CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY=y
+# CONFIG_OCTEON_ILM is not set
+CONFIG_MTD=y
+CONFIG_SATA_AHCI_PLATFORM=y
+CONFIG_AHCI_OCTEON=y
+CONFIG_PATA_OCTEON_CF=y
+CONFIG_OCTEON_MGMT_ETHERNET=y
+CONFIG_HW_RANDOM_OCTEON=m
+CONFIG_I2C_OCTEON=m
+CONFIG_GPIO_OCTEON=y
+CONFIG_OCTEON_WDT=m
+CONFIG_USB_OCTEON_EHCI=y
+CONFIG_USB_OCTEON_OHCI=y
+CONFIG_MMC_OCTEON=m
+CONFIG_OCTEON_ETHERNET=y
+CONFIG_OCTEON_USB=y
+CONFIG_CRYPTO_MD5_OCTEON=y
+CONFIG_CRYPTO_SHA1_OCTEON=y
+CONFIG_CRYPTO_SHA256_OCTEON=y
+CONFIG_CRYPTO_SHA512_OCTEON=y
diff --git a/filter-mips64el.sh b/filter-mips64el.sh
new file mode 100644
index 0000000..325e0d3
--- /dev/null
+++ b/filter-mips64el.sh
@@ -0,0 +1,12 @@
+#! /bin/bash
+
+# This is the mips64el override file for the core/drivers package split.  The
+# module directories listed here and in the generic list in filter-modules.sh
+# will be moved to the resulting kernel-modules package for this arch.
+# Anything not listed in those files will be in the kernel-core package.
+#
+# Please review the default list in filter-modules.sh before making
+# modifications to the overrides below.  If something should be removed across
+# all arches, remove it in the default instead of per-arch.
+
+# Defaults work so no need to override
diff --git a/filter-mipsel.sh b/filter-mipsel.sh
new file mode 100644
index 0000000..3051880
--- /dev/null
+++ b/filter-mipsel.sh
@@ -0,0 +1,12 @@
+#! /bin/bash
+
+# This is the mipsel override file for the core/drivers package split.  The
+# module directories listed here and in the generic list in filter-modules.sh
+# will be moved to the resulting kernel-modules package for this arch.
+# Anything not listed in those files will be in the kernel-core package.
+#
+# Please review the default list in filter-modules.sh before making
+# modifications to the overrides below.  If something should be removed across
+# all arches, remove it in the default instead of per-arch.
+
+# Defaults work so no need to override
diff --git a/kernel.spec b/kernel.spec
index 0b76a1a..cec1da5 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -42,7 +42,7 @@ Summary: The Linux kernel
 # For non-released -rc kernels, this will be appended after the rcX and
 # gitX tags, so a 3 here would become part of release "0.rcX.gitX.3"
 #
-%global baserelease 1
+%global baserelease 2
 %global fedora_build %{baserelease}
 
 # base_sublevel is the kernel version we're starting with and patching
@@ -99,6 +99,8 @@ Summary: The Linux kernel
 %define with_tools     %{?_without_tools:     0} %{?!_without_tools:     1}
 # kernel-debuginfo
 %define with_debuginfo %{?_without_debuginfo: 0} %{?!_without_debuginfo: 1}
+# kernel-octeon
+%define with_octeon    %{?_without_octeon:    0} %{?!_without_octeon:    1}
 # kernel-bootwrapper (for creating zImages from kernel + initrd)
 %define with_bootwrapper %{?_without_bootwrapper: 0} %{?!_without_bootwrapper: 1}
 # Want to build a the vsdo directories installed
@@ -189,6 +191,11 @@ Summary: The Linux kernel
 %define with_pae 0
 %endif
 
+# kernel octeon is only built on mips64el
+%ifnarch mips64el
+%define with_octeon 0
+%endif
+
 # if requested, only build base kernel
 %if %{with_baseonly}
 %define with_pae 0
@@ -309,6 +316,14 @@ Summary: The Linux kernel
 %define kernel_image arch/arm64/boot/Image.gz
 %endif
 
+%ifarch %{mips}
+%define all_arch_configs kernel-%{version}-mips*.config
+%define asmarch mips
+%define hdrarch mips
+%define make_target vmlinux
+%define kernel_image vmlinux
+%endif
+
 # Should make listnewconfig fail if there's config options
 # printed out?
 %if %{nopatches}
@@ -341,7 +356,7 @@ Summary: The Linux kernel
 %endif
 
 # Architectures we build tools/cpupower on
-%define cpupowerarchs %{ix86} x86_64 %{power64} %{arm} aarch64 
+%define cpupowerarchs %{ix86} x86_64 %{power64} %{arm} aarch64 %{mips}
 
 #
 # Packages that need to be installed before the kernel is, because the %%post
@@ -359,7 +374,7 @@ Version: %{rpmversion}
 Release: %{pkg_release}
 # DO NOT CHANGE THE 'ExclusiveArch' LINE TO TEMPORARILY EXCLUDE AN ARCHITECTURE BUILD.
 # SET %%nobuildarches (ABOVE) INSTEAD
-ExclusiveArch: %{all_x86} x86_64 ppc64 ppc64p7 s390 s390x %{arm} aarch64 ppc64le
+ExclusiveArch: %{all_x86} x86_64 ppc64 ppc64p7 s390 s390x %{arm} aarch64 ppc64le mipsel mips64el
 ExclusiveOS: Linux
 %ifnarch %{nobuildarches}
 Requires: kernel-core-uname-r = %{KVERREL}%{?variant}
@@ -414,6 +429,8 @@ Source15: merge.pl
 Source16: mod-extra.list
 Source17: mod-extra.sh
 Source18: mod-sign.sh
+Source88: filter-mipsel.sh
+Source89: filter-mips64el.sh
 Source90: filter-x86_64.sh
 Source91: filter-armv7hl.sh
 Source92: filter-i686.sh
@@ -454,6 +471,11 @@ Source103: config-armv7-lpae
 
 Source110: config-arm64
 
+Source120: config-mips-generic
+Source121: config-mips32r2
+Source122: config-mips64r2
+Source123: config-mips64r2-octeon
+
 # This file is intentionally left empty in the stock kernel. Its a nicety
 # added for those wanting to do custom rebuilds with altered config opts.
 Source1000: config-local
@@ -619,6 +641,19 @@ Patch714: ALSA-timer-Fix-leak-in-SNDRV_TIMER_IOCTL_PARAMS.patch
 Patch715: ALSA-timer-Fix-leak-in-events-via-snd_timer_user_cca.patch
 Patch716: ALSA-timer-Fix-leak-in-events-via-snd_timer_user_tin.patch
 
+# Fix ethernet handling on Octeon III CN7xxx boards
+Patch717: MIPS-Octeon-Add-Octeon-III-CN7xxx-interface-detectio.patch
+
+# Do not restore MSA context in non-MSA kernels
+Patch718: MIPS-Prevent-restoration-of-MSA-context-in-non-MSA-k.patch
+
+# Do not die with SIGILL after unaligned {L,S}DCX1 - required for java
+Patch719: MIPS-Allow-emulation-for-unaligned-LS-DXC1-instructi.patch
+
+# Do not die on a harmles Octeon VDSO warning
+Patch720: MIPS-Soften-VDSO-Werror.patch
+
+
 # END OF PATCH DEFINITIONS
 
 %endif
@@ -962,6 +997,18 @@ This variant of the kernel has numerous debugging options enabled.
 It should only be installed when trying to gather additional information
 on kernel bugs, as some of these options impact performance noticably.
 
+
+%define variant_summary The Linux kernel compiled with extra options enabled to run on Octeon based machines
+%kernel_variant_package octeon
+%description octeon-core
+The kernel package contains the Linux kernel (vmlinuz), the core of any
+Linux operating system.  The kernel handles the basic functions
+of the operating system:  memory allocation, process allocation, device
+input and output, etc.
+
+This variant of the kernel has numerous options enabled
+to ensure it runs properly on Octeon based MIPS machines.
+
 # And finally the main -core package
 
 %define variant_summary The Linux kernel
@@ -1653,6 +1700,10 @@ BuildKernel %make_target %kernel_image %{pae}debug
 BuildKernel %make_target %kernel_image %{pae}
 %endif
 
+%if %{with_octeon}
+BuildKernel %make_target %kernel_image octeon
+%endif
+
 %if %{with_up}
 BuildKernel %make_target %kernel_image
 %endif
@@ -1716,6 +1767,9 @@ popd
     if [ "%{with_pae_debug}" -ne "0" ]; then \
       %{modsign_cmd} certs/signing_key.pem.sign+%{pae}debug certs/signing_key.x509.sign+%{pae}debug $RPM_BUILD_ROOT/lib/modules/%{KVERREL}+%{pae}debug/ \
     fi \
+    if [ "%{with_octeon}" -ne "0" ]; then \
+      %{modsign_cmd} certs/signing_key.pem.sign+octeon certs/signing_key.x509.sign+octeon $RPM_BUILD_ROOT/lib/modules/%{KVERREL}+octeon/ \
+    fi \
     if [ "%{with_up}" -ne "0" ]; then \
       %{modsign_cmd} certs/signing_key.pem.sign certs/signing_key.x509.sign $RPM_BUILD_ROOT/lib/modules/%{KVERREL}/ \
     fi \
@@ -1740,7 +1794,7 @@ popd
 
 %ifnarch noarch
 %global __debug_package 1
-%files -f debugfiles.list debuginfo-common-%{_target_cpu}
+%files debuginfo-common-%{_target_cpu}
 %defattr(-,root,root)
 %endif
 
@@ -1977,6 +2031,9 @@ fi}\
 %kernel_variant_preun debug
 %kernel_variant_post -v debug
 
+%kernel_variant_preun octeon
+%kernel_variant_post -v octeon
+
 if [ -x /sbin/ldconfig ]
 then
     /sbin/ldconfig -X || exit $?
@@ -2138,12 +2195,16 @@ fi
 %kernel_variant_files %{with_debug} debug
 %kernel_variant_files %{with_pae} %{pae}
 %kernel_variant_files %{with_pae_debug} %{pae}debug
+%kernel_variant_files %{with_octeon} octeon
 
 # plz don't put in a version string unless you're going to tag
 # and build.
 #
 # 
 %changelog
+* Tue May 10 2016 Michal Toman <mtoman@fedoraproject.org>
+- Add support for mipsel (malta) and mips64el (malta, octeon)
+
 * Tue May 10 2016 Josh Boyer <jwboyer@fedoraproject.org> - 4.6.0-0.rc7.git1.1
 - Linux v4.6-rc7-45-g2d0bd9534c8d
 
-- 
2.5.5

