Skip to contentSkip to conversation

lemote-fulong patch update

PATCH In review [email protected] 7 participants 38 messages Apr 15, 2007 – Apr 20, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

My boss Fuxin Zhang is busy, and I take the job.
It's my first time to submit patch, correct me if I have done anything wrong

#1 lore raw

PATCH 1/16 new files for lemote fulong mini-PC support

From: Fuxin Zhang <[email protected]>

---
 arch/mips/lemote/lm2e/Makefile               |    7 +
 arch/mips/lemote/lm2e/bonito-irq.c           |   74 +++++
 arch/mips/lemote/lm2e/dbg_io.c               |  146 ++++++++++
 arch/mips/lemote/lm2e/irq.c                  |  146 ++++++++++
 arch/mips/lemote/lm2e/pci.c                  |   72 +++++
 arch/mips/lemote/lm2e/prom.c                 |  109 ++++++++
 arch/mips/lemote/lm2e/reset.c                |   46 +++
 arch/mips/lemote/lm2e/setup.c                |  144 ++++++++++
 arch/mips/pci/fixup-lm2e.c                   |  256 +++++++++++++++++
 arch/mips/pci/ops-lm2e.c                     |  153 +++++++++++
 include/asm-mips/mach-lemote/bonito.h        |  381 ++++++++++++++++++++++++++
 include/asm-mips/mach-lemote/dma-coherence.h |   43 +++
 include/asm-mips/mach-lemote/mc146818rtc.h   |   36 +++
 13 files changed, 1613 insertions(+), 0 deletions(-)
arch/mips/lemote/lm2e/Makefile new file +7 -0
new file mode 100644
index 0000000..0ba6f12
@@ -0,0 +1,7 @@
+#
+# Makefile for Lemote Fulong mini-PC board.
+#
+
+obj-y += setup.o prom.o reset.o irq.o pci.o bonito-irq.o dbg_io.o
+EXTRA_AFLAGS := $(CFLAGS)
+
arch/mips/lemote/lm2e/bonito-irq.c new file +74 -0

74 lines not on this page · raw message

arch/mips/lemote/lm2e/dbg_io.c new file +146 -0

146 lines not on this page · raw message

arch/mips/lemote/lm2e/irq.c new file +146 -0

146 lines not on this page · raw message

arch/mips/lemote/lm2e/pci.c new file +72 -0

72 lines not on this page · raw message

arch/mips/lemote/lm2e/prom.c new file +109 -0

109 lines not on this page · raw message

arch/mips/lemote/lm2e/reset.c new file +46 -0

46 lines not on this page · raw message

arch/mips/lemote/lm2e/setup.c new file +144 -0

144 lines not on this page · raw message

arch/mips/pci/fixup-lm2e.c new file +256 -0

256 lines not on this page · raw message

arch/mips/pci/ops-lm2e.c new file +153 -0

153 lines not on this page · raw message

include/asm-mips/mach-lemote/bonito.h new file +381 -0

381 lines not on this page · raw message

include/asm-mips/mach-lemote/dma-coherence.h new file +43 -0

43 lines not on this page · raw message

include/asm-mips/mach-lemote/mc146818rtc.h new file +36 -0
new file mode 100644
index 0000000..7850f89
@@ -0,0 +1,36 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1998, 2001, 03 by Ralf Baechle
+ *
+ * RTC routines for PC style attached Dallas chip.
+ */
+#ifndef __ASM_MACH_GENERIC_MC146818RTC_H
+#define __ASM_MACH_GENERIC_MC146818RTC_H
+
+#include <asm/io.h>
+
+#define RTC_PORT(x)	(0x70 + (x))
+#define RTC_IRQ		8
+
+static inline unsigned char CMOS_READ(unsigned long addr)
+{
+	outb_p(addr, RTC_PORT(0));
+	return inb_p(RTC_PORT(1));
+}
+
+static inline void CMOS_WRITE(unsigned char data, unsigned long addr)
+{
+	outb_p(addr, RTC_PORT(0));
+	outb_p(data, RTC_PORT(1));
+}
+
+#define RTC_ALWAYS_BCD	0
+
+#ifndef mc146818_decode_year
+#define mc146818_decode_year(year) ((year) < 70 ? (year) + 2000 : (year) + 1970)
+#endif
+
+#endif /* __ASM_MACH_GENERIC_MC146818RTC_H */
Signature · 1 line
1.4.4.1
#2 lore raw

PATCH 2/16 arch related Makefile update for lemote fulong mini-PC

From: Fuxin Zhang <[email protected]>

---
 arch/mips/Makefile        |    8 ++++++++
 arch/mips/kernel/Makefile |    1 +
 arch/mips/lib-32/Makefile |    1 +
 arch/mips/lib-64/Makefile |    1 +
 arch/mips/mm/Makefile     |    1 +
 arch/mips/pci/Makefile    |    1 +
 6 files changed, 13 insertions(+), 0 deletions(-)
arch/mips/Makefile +8 -0
index 92bca6a..2a6742d 100644
@@ -118,6 +118,7 @@ cflags-$(CONFIG_CPU_R4300)	+= -march=r4300 -Wa,--trap
 cflags-$(CONFIG_CPU_VR41XX)	+= -march=r4100 -Wa,--trap
 cflags-$(CONFIG_CPU_R4X00)	+= -march=r4600 -Wa,--trap
 cflags-$(CONFIG_CPU_TX49XX)	+= -march=r4600 -Wa,--trap
+cflags-$(CONFIG_CPU_LOONGSON2)	+= -march=r4600 -Wa,--trap
 cflags-$(CONFIG_CPU_MIPS32_R1)	+= $(call cc-option,-march=mips32,-mips32 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \
 			-Wa,-mips32 -Wa,--trap
 cflags-$(CONFIG_CPU_MIPS32_R2)	+= $(call cc-option,-march=mips32r2,-mips32r2 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \
@@ -298,6 +299,13 @@ cflags-$(CONFIG_WR_PPMC)		+= -Iinclude/asm-mips/mach-wrppmc
 load-$(CONFIG_WR_PPMC)		+= 0xffffffff80100000
 
 #
+# lemote fulong mini-PC board
+#
+core-$(CONFIG_LEMOTE_FULONG) +=arch/mips/lemote/lm2e/
+load-$(CONFIG_LEMOTE_FULONG) +=0xffffffff80100000
+cflags-$(CONFIG_LEMOTE_FULONG) += -Iinclude/asm-mips/mach-lemote
+
+#
 # For all MIPS, Inc. eval boards
 #
 core-$(CONFIG_MIPS_BOARDS_GEN)	+= arch/mips/mips-boards/generic/
arch/mips/kernel/Makefile +1 -0
index 4924626..40fdf79 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_CPU_R10000)	+= r4k_fpu.o r4k_switch.o
 obj-$(CONFIG_CPU_SB1)		+= r4k_fpu.o r4k_switch.o
 obj-$(CONFIG_CPU_MIPS32)	+= r4k_fpu.o r4k_switch.o
 obj-$(CONFIG_CPU_MIPS64)	+= r4k_fpu.o r4k_switch.o
+obj-$(CONFIG_CPU_LOONGSON2)	+= r4k_fpu.o r4k_switch.o
 obj-$(CONFIG_CPU_R6000)		+= r6000_fpu.o r4k_switch.o
 
 obj-$(CONFIG_SMP)		+= smp.o
arch/mips/lib-32/Makefile +1 -0
index 8b94d4c..b4be604 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_CPU_SB1)		+= dump_tlb.o
 obj-$(CONFIG_CPU_TX39XX)	+= r3k_dump_tlb.o
 obj-$(CONFIG_CPU_TX49XX)	+= dump_tlb.o
 obj-$(CONFIG_CPU_VR41XX)	+= dump_tlb.o
+obj-$(CONFIG_CPU_LOONGSON2)	+= dump_tlb.o
arch/mips/lib-64/Makefile +1 -0
index 8b94d4c..b4be604 100644
@@ -21,3 +21,4 @@ obj-$(CONFIG_CPU_SB1)		+= dump_tlb.o
 obj-$(CONFIG_CPU_TX39XX)	+= r3k_dump_tlb.o
 obj-$(CONFIG_CPU_TX49XX)	+= dump_tlb.o
 obj-$(CONFIG_CPU_VR41XX)	+= dump_tlb.o
+obj-$(CONFIG_CPU_LOONGSON2)	+= dump_tlb.o
arch/mips/mm/Makefile +1 -0
index 293697b..ab24195 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_CPU_R5432)		+= c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
 obj-$(CONFIG_CPU_R8000)		+= c-r4k.o cex-gen.o pg-r4k.o tlb-r8k.o
 obj-$(CONFIG_CPU_RM7000)	+= c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
 obj-$(CONFIG_CPU_RM9000)	+= c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
+obj-$(CONFIG_CPU_LOONGSON2)	+= c-r4k.o cex-gen.o pg-r4k.o tlb-r4k.o
 obj-$(CONFIG_CPU_SB1)		+= c-sb1.o cerr-sb1.o cex-sb1.o pg-sb1.o \
 				   tlb-r4k.o
 obj-$(CONFIG_CPU_TX39XX)	+= c-tx39.o pg-r4k.o tlb-r3k.o
arch/mips/pci/Makefile +1 -0
index bf85995..3a77235 100644
@@ -53,3 +53,4 @@ obj-$(CONFIG_TOSHIBA_RBTX4938)	+= fixup-tx4938.o ops-tx4938.o
 obj-$(CONFIG_VICTOR_MPC30X)	+= fixup-mpc30x.o
 obj-$(CONFIG_ZAO_CAPCELLA)	+= fixup-capcella.o
 obj-$(CONFIG_WR_PPMC)		+= fixup-wrppmc.o
+obj-$(CONFIG_LEMOTE_FULONG)	+= fixup-lm2e.o ops-lm2e.o
Signature · 1 line
1.4.4.1
#3 lore raw

PATCH 3/16 Kconfig update for lemote fulong mini-PC

From: Fuxin Zhang <[email protected]>

---
 arch/mips/Kconfig |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
arch/mips/Kconfig +38 -0
index 338bfa3..c18a835 100644
@@ -16,6 +16,27 @@ choice
 	prompt "System type"
 	default SGI_IP22
 
+config LEMOTE_FULONG
+	bool "Support for Lemote's fulong mini-PC"
+	select SYS_HAS_CPU_LOONGSON2
+	select DMA_NONCOHERENT
+	select BOOT_ELF32
+	select BOARD_SCACHE
+	select HW_HAS_PCI
+	select I8259
+	select ISA
+	select IRQ_CPU
+	select SYS_SUPPORTS_32BIT_KERNEL
+	select SYS_SUPPORTS_64BIT_KERNEL
+	select SYS_SUPPORTS_LITTLE_ENDIAN
+	select SYS_SUPPORTS_HIGHMEM
+	select SYS_HAS_EARLY_PRINTK
+	select GENERIC_HARDIRQS_NO__DO_IRQ
+	select CPU_HAS_WB
+	help
+        Lemote Fulong mini-PC board, which uses Chinese Loongson-2E CPU and a fpga north bridge
+
+
 config MIPS_MTX1
 	bool "4G Systems MTX-1 board"
 	select DMA_NONCOHERENT
@@ -1142,6 +1163,13 @@ choice
 	prompt "CPU type"
 	default CPU_R4X00
 
+config CPU_LOONGSON2
+	bool "LOONGSON2"
+	depends on SYS_HAS_CPU_LOONGSON2
+	select CPU_SUPPORTS_32BIT_KERNEL
+	select CPU_SUPPORTS_64BIT_KERNEL
+	select CPU_SUPPORTS_HIGHMEM
+
 config CPU_MIPS32_R1
 	bool "MIPS32 Release 1"
 	depends on SYS_HAS_CPU_MIPS32_R1
@@ -1352,6 +1380,9 @@ config CPU_SB1
 
 endchoice
 
+config SYS_HAS_CPU_LOONGSON2
+	bool
+
 config SYS_HAS_CPU_MIPS32_R1
 	bool
 
@@ -1681,6 +1712,13 @@ config CPU_HAS_SMARTMIPS
 config CPU_HAS_WB
 	bool
 
+config 64BIT_CONTEXT
+	bool "Save 64bit integer registers" if CPU_LOONGSON2 && 32BIT
+	help
+	  Loongson2 CPU is 64bit , when used in 32BIT mode, its integer registers
+	  can still be accessed as 64bit, mainly for multimedia instructions. We must have
+	  all 64bit save/restored to make sure those instructions to get correct result.
+
 #
 # Vectored interrupt mode is an R2 feature
 #
Signature · 1 line
1.4.4.1
#4 lore raw

PATCH 4/16 TO_PHYS_MASK for loongson2

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/addrspace.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/asm-mips/addrspace.h +1 -1
index 964c5ed..a4d9a07 100644
@@ -145,7 +145,7 @@
 #define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif
 
-#if defined (CONFIG_CPU_R10000)
+#if defined (CONFIG_CPU_R10000) || defined (CONFIG_CPU_LOONGSON2)
 #define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif
 
Signature · 1 line
1.4.4.1
#5 lore raw

PATCH 5/16 add MACH_GROUP_LEMOTE & MACH_LEMOTE_FULONG

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/bootinfo.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/asm-mips/bootinfo.h +6 -0
index c7c945b..f4607f1 100644
@@ -213,6 +213,12 @@
 #define MACH_GROUP_NEC_EMMA2RH 25	/* NEC EMMA2RH (was 23)		*/
 #define  MACH_NEC_MARKEINS	0	/* NEC EMMA2RH Mark-eins	*/
 
+/*
+ * Valid machtype for group LEMOTE
+ */
+#define MACH_GROUP_LEMOTE          27
+#define  MACH_LEMOTE_FULONG        0
+
 #define CL_SIZE			COMMAND_LINE_SIZE
 
 const char *get_system_type(void);
Signature · 1 line
1.4.4.1
#6 lore raw

PATCH 6/16 define Hit_Invalidate_I to Index_Invalidate_I for loongson2

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/cacheops.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-mips/cacheops.h +4 -0
index c4a1ec3..df7f2de 100644
@@ -20,7 +20,11 @@
 #define Index_Load_Tag_D	0x05
 #define Index_Store_Tag_I	0x08
 #define Index_Store_Tag_D	0x09
+#if defined(CONFIG_CPU_LOONGSON2)
+#define Hit_Invalidate_I    	0x00
+#else
 #define Hit_Invalidate_I	0x10
+#endif
 #define Hit_Invalidate_D	0x11
 #define Hit_Writeback_Inv_D	0x15
 
Signature · 1 line
1.4.4.1
#7 lore raw

PATCH 7/16 add Loongson processor definitions

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/cpu.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
include/asm-mips/cpu.h +6 -1
index d38fdbf..d289359 100644
@@ -89,6 +89,8 @@
 #define PRID_IMP_34K		0x9500
 #define PRID_IMP_24KE		0x9600
 #define PRID_IMP_74K		0x9700
+#define PRID_IMP_LOONGSON1      0x4200
+#define PRID_IMP_LOONGSON2      0x6300
 
 /*
  * These are the PRID's for when 23:16 == PRID_COMP_SIBYTE
@@ -200,7 +202,10 @@
 #define CPU_SB1A		62
 #define CPU_74K			63
 #define CPU_R14000		64
-#define CPU_LAST		64
+#define CPU_LOONGSON1           65
+#define CPU_LOONGSON2           66
+
+#define CPU_LAST		66
 
 /*
  * ISA Level encodings
Signature · 1 line
1.4.4.1
#8 lore raw

PATCH 8/16 define MODULE_PROC_FAMILY for Loongson2

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/module.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/asm-mips/module.h +2 -0
index 399d03f..f615324 100644
@@ -112,6 +112,8 @@ search_module_dbetables(unsigned long addr)
 #define MODULE_PROC_FAMILY "RM9000 "
 #elif defined CONFIG_CPU_SB1
 #define MODULE_PROC_FAMILY "SB1 "
+#elif defined CONFIG_CPU_LOONGSON2
+#define MODULE_PROC_FAMILY "LOONGSON2 "
 #else
 #error MODULE_PROC_FAMILY undefined for your processor configuration
 #endif
Signature · 1 line
1.4.4.1
#9 lore raw

PATCH 9/16 add serial port definition for lemote fulong

From: Fuxin Zhang <[email protected]>

---
 include/asm-mips/serial.h |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
include/asm-mips/serial.h +8 -1
index d7a6513..0f78438 100644
@@ -204,6 +204,12 @@
 #define IP32_SERIAL_PORT_DEFNS
 #endif /* CONFIG_SGI_IP32 */
 
+#if defined(CONFIG_LEMOTE_FULONG)
+#define LEMOTE_FULONG_SERIAL_PORT_DEFNS			\
+	/* UART CLK   PORT IRQ     FLAGS        */	\
+	{ 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS },	/* ttyS0 */
+#endif
+
 #define SERIAL_PORT_DFNS				\
 	DDB5477_SERIAL_PORT_DEFNS			\
 	EV64120_SERIAL_PORT_DEFNS			\
@@ -213,6 +219,7 @@
 	MOMENCO_OCELOT_G_SERIAL_PORT_DEFNS		\
 	MOMENCO_OCELOT_C_SERIAL_PORT_DEFNS		\
 	MOMENCO_OCELOT_SERIAL_PORT_DEFNS		\
-	MOMENCO_OCELOT_3_SERIAL_PORT_DEFNS
+	MOMENCO_OCELOT_3_SERIAL_PORT_DEFNS		\
+	LEMOTE_FULONG_SERIAL_PORT_DEFNS
 
 #endif /* _ASM_SERIAL_H */
Signature · 1 line
1.4.4.1
#10 lore raw

PATCH 10/16 make cpu_probe recognize Loongson2

From: Fuxin Zhang <[email protected]>

---
 arch/mips/kernel/cpu-probe.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/mips/kernel/cpu-probe.c +8 -0
index ab755ea..c9e3637 100644
@@ -464,6 +464,14 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
 		             MIPS_CPU_LLSC;
 		c->tlbsize = 64;
 		break;
+	case PRID_IMP_LOONGSON2:
+		c->cputype = CPU_LOONGSON2;
+		c->isa_level = MIPS_CPU_ISA_III;
+		c->options = R4K_OPTS |
+			     MIPS_CPU_FPU | MIPS_CPU_LLSC |
+			     MIPS_CPU_32FPR;
+		c->tlbsize = 64;
+		break;
 	}
 }
 
Signature · 1 line
1.4.4.1
#11 lore raw

PATCH 11/16 add Loongson support to /proc/cpuinfo

From: Fuxin Zhang <[email protected]>

---
 arch/mips/kernel/proc.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/mips/kernel/proc.c +1 -0
index 5ddc2e9..e915117 100644
@@ -84,6 +84,7 @@ static const char *cpu_name[] = {
 	[CPU_VR4181A]	= "NEC VR4181A",
 	[CPU_SR71000]	= "Sandcraft SR71000",
 	[CPU_PR4450]	= "Philips PR4450",
+	[CPU_LOONGSON2]	= "ICT Loongson-2",
 };
 
 
Signature · 1 line
1.4.4.1
#12 lore raw

PATCH 12/16 cheat for support of more than 256MB memory

From: Fuxin Zhang <[email protected]>

---
 arch/mips/kernel/setup.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/mips/kernel/setup.c +8 -0
index 4975da0..62ef100 100644
@@ -509,6 +509,14 @@ static void __init resource_init(void)
 		res->end = end;
 
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+#if defined(CONFIG_LEMOTE_FULONG) && defined(CONFIG_64BIT)
+		/* to keep memory continous, we tell system 0x10000000 - 0x20000000 is reserved
+		 * for memory, in fact it is io region, don't occupy it
+		 *
+		 * SPARSEMEM?
+		 */
+		if (boot_mem_map.map[i].type != BOOT_MEM_RESERVED)
+#endif
 		request_resource(&iomem_resource, res);
 
 		/*
Signature · 1 line
1.4.4.1
#13 lore raw

PATCH 13/16 define MODULE_PROC_FAMILY for Loongson2

From: Fuxin Zhang <[email protected]>

---
 arch/mips/mm/c-r4k.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)
arch/mips/mm/c-r4k.c +57 -0
index df04a31..6e6eac6 100644
@@ -335,6 +335,10 @@ static void r4k_flush_cache_all(void)
 
 static inline void local_r4k___flush_cache_all(void * args)
 {
+#if defined(CONFIG_CPU_LOONGSON2)
+	r4k_blast_scache();
+	return;
+#endif
 	r4k_blast_dcache();
 	r4k_blast_icache();
 
@@ -848,6 +852,26 @@ static void __init probe_pcache(void)
 		c->options |= MIPS_CPU_PREFETCH;
 		break;
 
+	case CPU_LOONGSON2:
+		icache_size = 1 << (12 + ((config & CONF_IC) >> 9));
+		c->icache.linesz = 16 << ((config & CONF_IB) >> 5);
+		if (prid & 0x3) {
+		  c->icache.ways = 4;
+		} else {
+		  c->icache.ways = 2;
+		}
+		c->icache.waybit= 0;
+
+		dcache_size = 1 << (12 + ((config & CONF_DC) >> 6));
+		c->dcache.linesz = 16 << ((config & CONF_DB) >> 4);
+		if (prid & 0x3) {
+		  c->dcache.ways = 4;
+		} else {
+		  c->dcache.ways = 2;
+		}
+		c->dcache.waybit = 0;
+		break;
+
 	default:
 		if (!(config & MIPS_CONF_M))
 			panic("Don't know how to probe P-caches on this cpu.");
@@ -963,6 +987,14 @@ static void __init probe_pcache(void)
 		break;
 	}
 
+#ifdef  CONFIG_CPU_LOONGSON2
+	/* 
+	 * LOONGSON2 has 4 way icache, but when using indexed cache op, 
+	 * one op will act on all 4 ways
+	 */
+	c->icache.ways = 1;
+#endif
+
 	printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
 	       icache_size >> 10,
 	       cpu_has_vtag_icache ? "virtually tagged" : "physically tagged",
@@ -1036,6 +1068,25 @@ static int __init probe_scache(void)
 	return 1;
 }
 
+#if defined(CONFIG_CPU_LOONGSON2)
+static void __init loongson2_sc_init(void)
+{
+    struct cpuinfo_mips *c = &current_cpu_data;
+
+    scache_size = 512*1024;
+    c->scache.linesz = 32;
+    c->scache.ways = 4;
+    c->scache.waybit = 0;
+    c->scache.waysize = scache_size / (c->scache.ways);
+    c->scache.sets = scache_size /(c->scache.linesz * c->scache.ways);
+    printk("Unified secondary cache %ldkB %s, linesize %d bytes.\n",
+		    scache_size >> 10, way_string[c->scache.ways], c->scache.linesz);
+
+    c->options |= MIPS_CPU_INCLUSIVE_CACHES;
+    return;
+}
+#endif
+
 extern int r5k_sc_init(void);
 extern int rm7k_sc_init(void);
 extern int mips_sc_init(void);
@@ -1085,6 +1136,12 @@ static void __init setup_scache(void)
 #endif
 		return;
 
+#if defined(CONFIG_CPU_LOONGSON2)
+	case CPU_LOONGSON2:
+		loongson2_sc_init();
+		return;
+#endif
+
 	default:
 		if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
 		    c->isa_level == MIPS_CPU_ISA_M32R2 ||
Signature · 1 line
1.4.4.1
#14 lore raw

PATCH 14/16 tlb handling support for Loongson2 processor

From: Fuxin Zhang <[email protected]>

---
 arch/mips/mm/tlb-r4k.c |   23 ++++++++++++++++++++++-
 arch/mips/mm/tlbex.c   |    8 +++++---
 2 files changed, 27 insertions(+), 4 deletions(-)
arch/mips/mm/tlb-r4k.c +22 -1
index 65160d4..26284bd 100644
@@ -48,6 +48,22 @@ extern void build_tlb_refill_handler(void);
 
 #endif /* CONFIG_MIPS_MT_SMTC */
 
+#if defined(CONFIG_CPU_LOONGSON2)
+/* 
+ * LOONGSON2 has a 4 entry itlb which is a subset of dtlb, 
+ * unfortrunately, itlb is not totally transparent to software.
+ */
+#define FLUSH_ITLB write_c0_diag(4);
+
+#define FLUSH_ITLB_VM(vma) { if ((vma)->vm_flags & VM_EXEC)  write_c0_diag(4); }
+
+#else
+
+#define FLUSH_ITLB
+#define FLUSH_ITLB_VM(vma)
+
+#endif
+
 void local_flush_tlb_all(void)
 {
 	unsigned long flags;
@@ -73,6 +89,7 @@ void local_flush_tlb_all(void)
 	}
 	tlbw_use_hazard();
 	write_c0_entryhi(old_ctx);
+	FLUSH_ITLB;
 	EXIT_CRITICAL(flags);
 }
 
@@ -136,6 +153,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
 		} else {
 			drop_mmu_context(mm, cpu);
 		}
+		FLUSH_ITLB;
 		EXIT_CRITICAL(flags);
 	}
 }
@@ -178,6 +196,7 @@ void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
 	} else {
 		local_flush_tlb_all();
 	}
+	FLUSH_ITLB;
 	EXIT_CRITICAL(flags);
 }
 
@@ -210,6 +229,7 @@ void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
 
 	finish:
 		write_c0_entryhi(oldpid);
+		FLUSH_ITLB_VM(vma);
 		EXIT_CRITICAL(flags);
 	}
 }
@@ -241,7 +261,7 @@ void local_flush_tlb_one(unsigned long page)
 		tlbw_use_hazard();
 	}
 	write_c0_entryhi(oldpid);
-
+	FLUSH_ITLB;
 	EXIT_CRITICAL(flags);
 }
 
@@ -293,6 +313,7 @@ void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
 	else
 		tlb_write_indexed();
 	tlbw_use_hazard();
+	FLUSH_ITLB_VM(vma);
 	EXIT_CRITICAL(flags);
 }
 
arch/mips/mm/tlbex.c +5 -3
index 492c518..e1a58d9 100644
@@ -893,6 +893,7 @@ static __init void build_tlb_write_entry(u32 **p, struct label **l,
 	case CPU_4KSC:
 	case CPU_20KC:
 	case CPU_25KF:
+	case CPU_LOONGSON2:
 		tlbw(p);
 		break;
 
@@ -1276,7 +1277,8 @@ static void __init build_r4000_tlb_refill_handler(void)
 	 * need three, with the second nop'ed and the third being
 	 * unused.
 	 */
-#ifdef CONFIG_32BIT
+	/* Loongson2 ebase is different than r4k, we have more space */
+#if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2)
 	if ((p - tlb_handler) > 64)
 		panic("TLB refill handler space exceeded");
 #else
@@ -1289,7 +1291,7 @@ static void __init build_r4000_tlb_refill_handler(void)
 	/*
 	 * Now fold the handler in the TLB refill handler space.
 	 */
-#ifdef CONFIG_32BIT
+#if defined(CONFIG_32BIT) || defined(CONFIG_CPU_LOONGSON2)
 	f = final_handler;
 	/* Simplest case, just copy the handler. */
 	copy_handler(relocs, labels, tlb_handler, p, f);
@@ -1336,7 +1338,7 @@ static void __init build_r4000_tlb_refill_handler(void)
 		final_len);
 
 	f = final_handler;
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && !defined(CONFIG_CPU_LOONGSON2)
 	if (final_len > 32)
 		final_len = 64;
 	else
Signature · 1 line
1.4.4.1
#15 lore raw

PATCH 15/16 work around for more than 256MB memory support

From: Fuxin Zhang <[email protected]>

---
 drivers/char/mem.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/char/mem.c +4 -0
index f5c160c..580ad3e 100644
@@ -83,8 +83,12 @@ static inline int uncached_access(struct file *file, unsigned long addr)
 	 */
 	if (file->f_flags & O_SYNC)
 		return 1;
+#if defined(CONFIG_LEMOTE_FULONG) && defined(CONFIG_64BIT)
+	return (addr >= __pa(high_memory)) || ((addr >=0x10000000) && (addr < 0x20000000));
+#else
 	return addr >= __pa(high_memory);
 #endif
+#endif
 }
 
 #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
Signature · 1 line
1.4.4.1
#16 lore raw

PATCH 16/16 alsa sound support for mips

From: Fuxin Zhang <[email protected]>

---
 sound/core/pcm_native.c |   10 ++++++++++
 sound/core/sgbuf.c      |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
sound/core/pcm_native.c +10 -0
index 3e276fc..9005bac 100644
@@ -3145,7 +3145,11 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
 			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
 	} else {
 		vaddr = runtime->dma_area + offset;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		page = virt_to_page(CAC_ADDR(vaddr));
+#else
 		page = virt_to_page(vaddr);
+#endif
 	}
 	get_page(page);
 	if (type)
@@ -3261,6 +3265,12 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, return -ENXIO);
 
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);
+#endif
+
 	offset = area->vm_pgoff << PAGE_SHIFT;
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
sound/core/sgbuf.c +9 -0
index cefd228..535f0bc 100644
@@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
 		}
 		sgbuf->table[i].buf = tmpb.area;
 		sgbuf->table[i].addr = tmpb.addr;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));
+#else
 		sgbuf->page_table[i] = virt_to_page(tmpb.area);
+#endif
 		sgbuf->pages++;
 	}
 
 	sgbuf->size = size;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* maybe we should use uncached accelerated mode */
+	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
+#else
 	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
+#endif
 	if (! dmab->area)
 		goto _failed;
 	return dmab->area;
Signature · 1 line
1.4.4.1
#17 lore raw

Re: [PATCH 16/16] alsa sound support for mips

On Sun, Apr 15, 2007 at 11:26:05PM +0800, [email protected] wrote:

(Adding a few more people to the cc'list)

sound/core/pcm_native.c static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area, · line 3148

Quoted 13 lines
 sound/core/pcm_native.c |   10 ++++++++++
 sound/core/sgbuf.c      |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
sound/core/pcm_native.c +1 -0
index 3e276fc..9005bac 100644
@@ -3145,7 +3145,11 @@ static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area,
 			return NOPAGE_OOM; /* XXX: is this really due to OOM? */
 	} else {
 		vaddr = runtime->dma_area + offset;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)

Please use CONFIG_MIPS instead of __mips__ in #if / #ifdefs.

The question if #ifdefing is the right approach to solve this problem is something else but I think no, ....

sound/core/pcm_native.c static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area, · line 3152

Quoted 4 lines
sound/core/pcm_native.c +3 -0
+		page = virt_to_page(CAC_ADDR(vaddr));
+#else
 		page = virt_to_page(vaddr);
+#endif

So this is needed because the MIPS virt_to_page is returning a unsuitable value if vaddress is not a KSEG0 (64-bit: cached XKPHYS) address which is what GFP allocations and the slab will return. So now we have to deciede if

a) the MIPS __pa() should be changed to handle uncached addresses.
b) the sound code here is simply broken.

Some drivers seem to allocate runtime->dma_area from vmalloc, so this whole area in the sound code is looking like built on quicksand ...

sound/core/pcm_native.c static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) · line 3271

Quoted 11 lines
sound/core/pcm_native.c +4 -0
 	}
 	get_page(page);
 	if (type)
@@ -3261,6 +3265,12 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
 	substream = pcm_file->substream;
 	snd_assert(substream != NULL, return -ENXIO);
 
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);

VM_RESERVED will prevent the buffer from being freed. I assume that is another workaround for some kernel subsystem blowing up when being fed a pointer to an uncached RAM address? This smells like a memory leak.

Quoted 10 lines
sound/core/pcm_native.c +2 -0
+#endif
+
 	offset = area->vm_pgoff << PAGE_SHIFT;
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
sound/core/sgbuf.c +0 -0
index cefd228..535f0bc 100644

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device, · line 95

Quoted 5 lines
sound/core/sgbuf.c +2 -0
@@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
 		}
 		sgbuf->table[i].buf = tmpb.area;
 		sgbuf->table[i].addr = tmpb.addr;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));

VM_RESERVED will prevent the buffer from being freed. I assume that is another workaround for some kernel subsystem blowing up when being fed a pointer to an uncached RAM address? This smells like a memory leak.

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device, · line 108

Quoted 13 lines
sound/core/sgbuf.c +7 -0
+#else
 		sgbuf->page_table[i] = virt_to_page(tmpb.area);
+#endif
 		sgbuf->pages++;
 	}
 
 	sgbuf->size = size;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* maybe we should use uncached accelerated mode */
+	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
+#else
 	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
+#endif

I would suggest to get rid of this ifdef with a new arch-specific function like vmap_io_buffer which will do whatever a platform seems fit for this case?

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device, · line 111

Quoted 3 lines
sound/core/sgbuf.c +0 -0
 	if (! dmab->area)
 		goto _failed;
 	return dmab->area;

Ralf

#18 lore raw

Re: [PATCH 16/16] alsa sound support for mips

Quoted 10 lines

sound/core/pcm_native.c static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area, · line 3148

Quoted 4 lines
sound/core/pcm_native.c +1 -0
 		vaddr = runtime->dma_area + offset;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)

Please use CONFIG_MIPS instead of __mips__ in #if / #ifdefs.

The question if #ifdefing is the right approach to solve this problem is something else but I think no, ....

I would agree that it is quite ugly, but changing virt_to_page for it does not seem right either.

Quoted 18 lines

sound/core/pcm_native.c static struct page *snd_pcm_mmap_data_nopage(struct vm_area_struct *area, · line 3152

Quoted 6 lines
sound/core/pcm_native.c +3 -0
+		page = virt_to_page(CAC_ADDR(vaddr));
+#else
 		page = virt_to_page(vaddr);
+#endif

So this is needed because the MIPS virt_to_page is returning a unsuitable value if vaddress is not a KSEG0 (64-bit: cached XKPHYS) address which is what GFP allocations and the slab will return. So now we have to deciede if

a) the MIPS __pa() should be changed to handle uncached addresses.
b) the sound code here is simply broken.

Some drivers seem to allocate runtime->dma_area from vmalloc, so this whole area in the sound code is looking like built on quicksand ...

Quoted 11 lines

sound/core/pcm_native.c static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) · line 3271

Quoted 5 lines
sound/core/pcm_native.c +4 -0
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);

VM_RESERVED will prevent the buffer from being freed. I assume that is another workaround for some kernel subsystem blowing up when being fed a pointer to an uncached RAM address? This smells like a memory leak.

Oh, VM_RESERVED should be a memory leak problem, we can remove it. I don't remember any case of other subsystem's problem, just did not think much to add those flags.

Quoted 28 lines
Quoted 10 lines
sound/core/pcm_native.c +2 -0
+#endif
+
 	offset = area->vm_pgoff << PAGE_SHIFT;
 	switch (offset) {
 	case SNDRV_PCM_MMAP_OFFSET_STATUS:
sound/core/sgbuf.c +0 -0
index cefd228..535f0bc 100644

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device, · line 96

Quoted 6 lines
sound/core/sgbuf.c +2 -0
@@ -91,12 +91,21 @@ void *snd_malloc_sgbuf_pages(struct device *device,
 		}
 		sgbuf->table[i].buf = tmpb.area;
 		sgbuf->table[i].addr = tmpb.addr;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+		sgbuf->page_table[i] = virt_to_page(CAC_ADDR(tmpb.area));
 

VM_RESERVED will prevent the buffer from being freed. I assume that is another workaround for some kernel subsystem blowing up when being fed a pointer to an uncached RAM address? This smells like a memory leak.

Quoted 6 lines
sound/core/sgbuf.c +2 -0
+#else
 		sgbuf->page_table[i] = virt_to_page(tmpb.area);
+#endif
 		sgbuf->pages++;
 	}
 
Quoted 13 lines

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device,

Quoted 8 lines
sound/core/sgbuf.c +5 -0
 	sgbuf->size = size;
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* maybe we should use uncached accelerated mode */
+	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP | VM_IO, pgprot_noncached(PAGE_KERNEL));
+#else
 	dmab->area = vmap(sgbuf->page_table, sgbuf->pages, VM_MAP, PAGE_KERNEL);
+#endif
 

I would suggest to get rid of this ifdef with a new arch-specific function like vmap_io_buffer which will do whatever a platform seems fit for this case?

I think arch-specific function is the correct way, but don't know what the alsa gods think.

Quoted 12 lines

sound/core/sgbuf.c void *snd_malloc_sgbuf_pages(struct device *device, · line 111

Quoted 5 lines
sound/core/sgbuf.c +0 -0
 	if (! dmab->area)
sound/core/sgbuf.c +0 -0
 		goto _failed;
 	return dmab->area;

Ralf

#19 lore raw

Re: [PATCH 16/16] alsa sound support for mips

Quoted 11 lines · Fuxin Zhang
Quoted 11 lines

sound/core/pcm_native.c static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) · line 3271

Quoted 5 lines
sound/core/pcm_native.c +4 -0
+#if defined(__mips__) && defined(CONFIG_DMA_NONCOHERENT)
+	/* all mmap using uncached mode */
+	area->vm_page_prot = pgprot_noncached(area->vm_page_prot);
+	area->vm_flags |= ( VM_RESERVED | VM_IO);

VM_RESERVED will prevent the buffer from being freed. I assume that is another workaround for some kernel subsystem blowing up when being fed a pointer to an uncached RAM address? This smells like a memory leak.

Quoted 4 lines

Oh, VM_RESERVED should be a memory leak problem, we can remove it. I don't remember any case of other subsystem's problem, just did not think much
to add those flags.

I think pgprot_noncached() is needed because user mapping for a DMA buffer (runtime->dma_area) should be uncache. If so, doing this in snd_pcm_mmap() looks a bit suspicious. It seems snd_pcm_mmap_data() is a place to do such an adjustment. But for now, both snd_pcm_mmap_status() and snd_pcm_mmap_control() returns -ENXIO for MIPS so this is not a real problem.

And I wonder if VM_IO is really needed. The area is a DMA buffer, _not_ a memory mapped IO area, isn't it?

Quoted 6 lines
Quoted 4 lines

I would suggest to get rid of this ifdef with a new arch-specific function like vmap_io_buffer which will do whatever a platform seems fit for this case?

I think arch-specific function is the correct way, but don't know what the alsa gods think.

JFYI, there were some discussions on this topic a while ago:

http://lkml.org/lkml/2006/1/25/117

and I'v seen MIPS version of dma_mmap_coherent(), etc. somewhere...

---
Atsushi Nemoto

#20 lore raw

Re: [PATCH 6/16] define Hit_Invalidate_I to Index_Invalidate_I for loongson2

In reply to [email protected]

include/asm-mips/cacheops.h line 24

Quoted 2 lines · On Sun, Apr 15, 2007 at 11:25:55PM +0800, [email protected] wrote:
include/asm-mips/cacheops.h +2 -0
+#if defined(CONFIG_CPU_LOONGSON2)
+#define Hit_Invalidate_I    	0x00

This #ifdef means Index_Invalidate_I and Hit_Invalidate_I will both be defined as zero, is that really correct?

(This is the point where I would really like to have a CPU manual ...)

include/asm-mips/cacheops.h line 27

Quoted 3 lines
include/asm-mips/cacheops.h +2 -0
+#else
 #define Hit_Invalidate_I	0x10
+#endif

Ralf

#21 lore raw

Re: [PATCH 6/16] define Hit_Invalidate_I to Index_Invalidate_I for loongson2

Yes, Loongson2 has no Hit_invalidate_I in fact. And although it has 4-way icache, one Index_invalidate_I will invalidate all 4 ways of the same set.

The usermanual and datasheet can be downloaded from:

http://www.lemote.com/upfiles/godson2e-user-manual-V0.6.pdf

Quoted 24 lines · Ralf Baechle

include/asm-mips/cacheops.h line 24

Quoted 3 lines · On Sun, Apr 15, 2007 at 11:25:55PM +0800, [email protected] wrote:
include/asm-mips/cacheops.h +2 -0
+#if defined(CONFIG_CPU_LOONGSON2)
+#define Hit_Invalidate_I    	0x00

This #ifdef means Index_Invalidate_I and Hit_Invalidate_I will both be defined as zero, is that really correct?

(This is the point where I would really like to have a CPU manual ...)

include/asm-mips/cacheops.h line 27

Quoted 4 lines
include/asm-mips/cacheops.h +2 -0
+#else
 #define Hit_Invalidate_I	0x10
+#endif

Ralf

#22 lore raw

Re: [PATCH 6/16] define Hit_Invalidate_I to Index_Invalidate_I for loongson2

Sorry, no english version of datasheet yet.

Quoted 36 lines · Fuxin Zhang

Yes, Loongson2 has no Hit_invalidate_I in fact. And although it has 4-way icache, one Index_invalidate_I will invalidate all 4 ways of the same set.

The usermanual and datasheet can be downloaded from:

http://www.lemote.com/upfiles/godson2e-user-manual-V0.6.pdf

Quoted 24 lines · Ralf Baechle

include/asm-mips/cacheops.h line 24

Quoted 3 lines · On Sun, Apr 15, 2007 at 11:25:55PM +0800, [email protected] wrote:
include/asm-mips/cacheops.h +2 -0
+#if defined(CONFIG_CPU_LOONGSON2)
+#define Hit_Invalidate_I        0x00

This #ifdef means Index_Invalidate_I and Hit_Invalidate_I will both be defined as zero, is that really correct?

(This is the point where I would really like to have a CPU manual ...)

include/asm-mips/cacheops.h line 27

Quoted 4 lines
include/asm-mips/cacheops.h +2 -0
+#else
 #define Hit_Invalidate_I    0x10
+#endif

Ralf

#23 lore raw

Re: [PATCH 4/16] TO_PHYS_MASK for loongson2

In reply to [email protected]

include/asm-mips/addrspace.h line 150

Quoted 12 lines · On Sun, Apr 15, 2007 at 11:25:53PM +0800, [email protected] wrote:
include/asm-mips/addrspace.h +1 -1
index 964c5ed..a4d9a07 100644
@@ -145,7 +145,7 @@
 #define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif
 
-#if defined (CONFIG_CPU_R10000)
+#if defined (CONFIG_CPU_R10000) || defined (CONFIG_CPU_LOONGSON2)
 #define TO_PHYS_MASK	_CONST64_(0x000000ffffffffff)	/* 2^^40 - 1 */
 #endif

How about we define TO_PHYS_MASK to 2^57-1 for all processors instead?

The use of TO_PHYS_MASK is to strip of the high bits of of a XKPHYS kernel virtual address. Allowing for the top 2 region and 3 cache mode bits that would leave 59 bits. If we also allow for the macro to be used for stripping off the 2 R10000 "uncached attribute" bits we would be down to 57 bits. Not sure if that would be useful - but we got gobs of address space to burn and adding yet another #ifdef for every new 64-bit processor or even variant to addrspace.h isn't really the way to go.

Ralf

#24 lore raw

Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

In reply to [email protected]

arch/mips/Kconfig config CPU_HAS_SMARTMIPS · line 1721

Quoted 11 lines · On Sun, Apr 15, 2007 at 11:25:52PM +0800, [email protected] wrote:
arch/mips/Kconfig +7 -0
@@ -1681,6 +1712,13 @@ config CPU_HAS_SMARTMIPS
 config CPU_HAS_WB
 	bool
 
+config 64BIT_CONTEXT
+	bool "Save 64bit integer registers" if CPU_LOONGSON2 && 32BIT
+	help
+	  Loongson2 CPU is 64bit , when used in 32BIT mode, its integer registers
+	  can still be accessed as 64bit, mainly for multimedia instructions. We must have
+	  all 64bit save/restored to make sure those instructions to get correct result.
+

Is there anything in implementation of this option Loongson2-specific? If not then I suggest we make this option loook like:

   bool "Save 64bit integer registers" if CPU_SUPPORTS_64BIT_KERNEL && 32BIT

Somebody else might have a use for it!

Ralf

#25 lore raw

Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 6 lines
Quoted 3 lines

+

Is there anything in implementation of this option Loongson2-specific?

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

Loongson2 has no 32/64 mode bit in fact.

And the usage arise from Loongson2's multimedia extension, which is also uniq.

Quoted 12 lines

If not then I suggest we make this option loook like:

   bool "Save 64bit integer registers" if CPU_SUPPORTS_64BIT_KERNEL && 32BIT

Somebody else might have a use for it!

Ralf

#26 lore raw

RE: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 2 lines

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

For clarity, there is no 32/64-bit mode in MIPS processors. There is a mode in which 64-bit OPERATIONS are enabled (that is, those instructions which operate on the full width of the registers) - See the definition of 64-bit Operations Enable in the MIPS64 Architecture for Programmers, volume III. Note that such operations are always enabled while the processor is running in Kernel Mode.

The patch is a little short on context, but if you've got a 64-bit kernel, I had always assumed that save/restore of context is always done with LD/SD, not by figuring out whether a process has 64-bit operations enabled, then doing a conditional LD/SD or LW/SW.

/gmu
---
Michael Uhler, Chief Technology Officer
MIPS Technologies, Inc. Email: uhler AT mips.com
1225 Charleston Road Voice: (650)567-5025 FAX: (650)567-5225
Mountain View, CA 94043

Quoted 38 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Fuxin Zhang
Sent: Wednesday, April 18, 2007 6:32 AM
To: Ralf Baechle
Cc: [email protected]; [email protected]; Fuxin Zhang
Subject: Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 4 lines
Quoted 2 lines

+

Is there anything in implementation of this option

Loongson2-specific?

Quoted 1 line

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

Loongson2 has no 32/64 mode bit in fact.

And the usage arise from Loongson2's multimedia extension, which is also uniq.

Quoted 3 lines

If not then I suggest we make this option loook like:

bool "Save 64bit integer registers" if

CPU_SUPPORTS_64BIT_KERNEL &&

Quoted 10 lines

32BIT

Somebody else might have a use for it!

Ralf

#27 lore raw

Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 10 lines · Mike
Quoted 2 lines

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

For clarity, there is no 32/64-bit mode in MIPS processors. There is a mode in which 64-bit OPERATIONS are enabled (that is, those instructions which operate on the full width of the registers) - See the definition of 64-bit Operations Enable in the MIPS64 Architecture for Programmers, volume III. Note that such operations are always enabled while the processor is running in Kernel Mode.

Quoted 6 lines

The patch is a little short on context, but if you've got a 64-bit kernel, I had always assumed that save/restore of context is always done with LD/SD, not by figuring out whether a process has 64-bit operations enabled, then doing a conditional LD/SD or LW/SW.

This patch for 32bit kernel. We want to save/restore 64bit register content because the high 32bit of register might be used by multimedia programs for loongson processor, such as mplayer.

Quoted 56 lines

/gmu
---
Michael Uhler, Chief Technology Officer
MIPS Technologies, Inc. Email: uhler AT mips.com
1225 Charleston Road Voice: (650)567-5025 FAX: (650)567-5225
Mountain View, CA 94043

Quoted 42 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Fuxin Zhang
Sent: Wednesday, April 18, 2007 6:32 AM
To: Ralf Baechle
Cc: [email protected]; [email protected]; Fuxin Zhang
Subject: Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 5 lines
Quoted 3 lines

+

Is there anything in implementation of this option

Loongson2-specific?

Quoted 2 lines

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

Loongson2 has no 32/64 mode bit in fact.

And the usage arise from Loongson2's multimedia extension, which is also uniq.

Quoted 4 lines

If not then I suggest we make this option loook like:

bool "Save 64bit integer registers" if

CPU_SUPPORTS_64BIT_KERNEL &&

Quoted 11 lines

32BIT

Somebody else might have a use for it!

Ralf

#28 lore raw

Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

In reply to Uhler, Mike
Quoted 10 lines · Mike
Quoted 2 lines

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

For clarity, there is no 32/64-bit mode in MIPS processors. There is a mode in which 64-bit OPERATIONS are enabled (that is, those instructions which operate on the full width of the registers) - See the definition of 64-bit Operations Enable in the MIPS64 Architecture for Programmers, volume III. Note that such operations are always enabled while the processor is running in Kernel Mode.

Quoted 4 lines

The patch is a little short on context, but if you've got a 64-bit kernel, I had always assumed that save/restore of context is always done with LD/SD, not by figuring out whether a process has 64-bit operations enabled, then doing a conditional LD/SD or LW/SW.

Here's a funny one where we have something like a mode. This is a reposting from Bill Earl:

[...]
One other issue is that UX should always be set, to allow use of
MIPS3 instructions, and that XX (bit 31) should be set on R5000 and R10000 processors, to enable MIPS4 instructions. This in turn means that, to avoid various illegal address exceptions, the VM system should not allow a 32-bit user program to map anything into the top 32 KB of the user address space.

The problem has to do with some compilers using integer
arithmetic to compute a base for some variables in the current stack frame, and then using negative displacements to address the variables, for cases where the stack frame exceeds 32 KB, but is located near the top of memory. The 32-bit unsigned integer add to, say, 0x7fffff00 (64-bit address 0x000000007fffff00) produces a signed 32-bit value such as 0x80000f00, which is the 64-bit value 0xffffffff80000f00, since all 32-bit values, signed or unsigned, are stored as 32-bit signed values sign-extended to 64 bits. When you do a load with a negative offset of, say, -0x1000, you get an address 0xffffffff7fffff00, not 0x000000007fffff00. With UX=0, this would be fine, but, with UX=1 (to enable MIPS3 instructions), the above address is illegal. If the $sp is always at least 32 KB below the top of the address space, this problem does not arise, since any such intermediate pointer generated by the compiler will always be below 0x80000000. [...]

The original posting is at http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=14452.59571.970106.514001%40liveoak.engr.sgi.com

Ralf

#29 lore raw

RE: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Note that both of these apply to pre-MIPS64 processors. In a MIPS64 implementation, The Status.PX bit should be used to enable 64-bit operations without enabling 64-bit addressing. The Status.XX bit is gone and can't be set. The addressing boundary condition that Bill mentioned is explicitly address in the Architecture for Programmer's manual, Volume III, section 4.10 as a requirement for hardware in exactly this case.

I realize that Loongson is a MIPS III processor where Bill's suggestion may apply, but it's not a general problem moving forward to MIPS64.

/gmu
---
Michael Uhler, Chief Technology Officer
MIPS Technologies, Inc. Email: uhler AT mips.com
1225 Charleston Road Voice: (650)567-5025 FAX: (650)567-5225
Mountain View, CA 94043

Quoted 59 lines

-----Original Message-----
From: Ralf Baechle [mailto:[email protected]]
Sent: Wednesday, April 18, 2007 9:38 AM
To: Uhler, Mike
Cc: Fuxin Zhang; [email protected]; [email protected]; Fuxin Zhang
Subject: Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 4 lines · Mike
Quoted 2 lines

Yes. Most 64bit MIPS processors cannot access 64bit content of registers when it is in 32bit mode.

For clarity, there is no 32/64-bit mode in MIPS processors.

There is

Quoted 2 lines

a mode in which 64-bit OPERATIONS are enabled (that is, those instructions which operate on the full width of the

registers) - See

Quoted 1 line

the definition of 64-bit Operations Enable in the MIPS64

Architecture

Quoted 7 lines

for Programmers, volume III. Note that such operations are always enabled while the processor is running in Kernel Mode.

The patch is a little short on context, but if you've got a 64-bit kernel, I had always assumed that save/restore of context is always done with LD/SD, not by figuring out whether a process has 64-bit operations enabled, then doing a conditional LD/SD or LW/SW.

Here's a funny one where we have something like a mode. This is a reposting from Bill Earl:

[...]
One other issue is that UX should always be set, to allow use of
MIPS3 instructions, and that XX (bit 31) should be set on R5000 and R10000 processors, to enable MIPS4 instructions. This in turn means that, to avoid various illegal address exceptions, the VM system should not allow a 32-bit user program to map anything into the top 32 KB of the user address space.

The problem has to do with some compilers using integer
arithmetic to compute a base for some variables in the current stack frame, and then using negative displacements to address the variables, for cases where the stack frame exceeds 32 KB, but is located near the top of memory. The 32-bit unsigned integer add to, say, 0x7fffff00 (64-bit address 0x000000007fffff00) produces a signed 32-bit value such as 0x80000f00, which is the 64-bit value 0xffffffff80000f00, since all 32-bit values, signed or unsigned, are stored as 32-bit signed values sign-extended to 64 bits. When you do a load with a negative offset of, say, -0x1000, you get an address 0xffffffff7fffff00, not 0x000000007fffff00. With UX=0, this would be fine, but, with UX=1 (to enable MIPS3 instructions), the above address is illegal. If the $sp is always at least 32 KB below the top of the address space, this problem does not arise, since any such intermediate pointer generated by the compiler will always be below 0x80000000.
[...]

Quoted 2 lines

The original posting is at
http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=1445

2.59571.970106.514001%40liveoak.engr.sgi.com

Quoted 3 lines

Ralf

#30 lore raw

Re: [PATCH 3/16] Kconfig update for lemote fulong mini-PC

Quoted 10 lines · Mike

Note that both of these apply to pre-MIPS64 processors. In a MIPS64 implementation, The Status.PX bit should be used to enable 64-bit operations without enabling 64-bit addressing. The Status.XX bit is gone and can't be set. The addressing boundary condition that Bill mentioned is explicitly address in the Architecture for Programmer's manual, Volume III, section 4.10 as a requirement for hardware in exactly this case.

I realize that Loongson is a MIPS III processor where Bill's suggestion may apply, but it's not a general problem moving forward to MIPS64.

Linux limits the address space to 0x7fff8000 for 32-bit processes. For sake of simplicity and symmetry we do this on both 32-bit and 64-bit kernels, on all processors. A 64-bit kernel always runs userspace processes with UX=1. Since a 32-bit process cannot create mappings above the low 2GB there isn't an actual need to use PX.

(I think there is a small bug in this scheme though, a process that is accessing a 64-bit userspace address that isn't a 32-bit address should be sent a SIGBUS but will actually receive a SIGSEGV. But that's a subtility and also requires extrapolating from an API documents that only covers a strict 32-bit universe.)

Ralf

#31 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

In reply to [email protected]

[email protected] wrote:
[snip]

arch/mips/Makefile cflags-$(CONFIG_CPU_R4300) += -march=r4300 -Wa,--trap · line 121

Quoted 9 lines
arch/mips/Makefile +1 -0
index 92bca6a..2a6742d 100644
@@ -118,6 +118,7 @@ cflags-$(CONFIG_CPU_R4300)	+= -march=r4300 -Wa,--trap
 cflags-$(CONFIG_CPU_VR41XX)	+= -march=r4100 -Wa,--trap
 cflags-$(CONFIG_CPU_R4X00)	+= -march=r4600 -Wa,--trap
 cflags-$(CONFIG_CPU_TX49XX)	+= -march=r4600 -Wa,--trap
+cflags-$(CONFIG_CPU_LOONGSON2)	+= -march=r4600 -Wa,--trap

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Thiemo

author
#32 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

Quoted 18 lines · Thiemo Seufer

[email protected] wrote:
[snip]

arch/mips/Makefile cflags-$(CONFIG_CPU_R4300) += -march=r4300 -Wa,--trap · line 122

Quoted 10 lines
arch/mips/Makefile +1 -0
index 92bca6a..2a6742d 100644
@@ -118,6 +118,7 @@ cflags-$(CONFIG_CPU_R4300)	+= -march=r4300 -Wa,--trap
 cflags-$(CONFIG_CPU_VR41XX)	+= -march=r4100 -Wa,--trap
 cflags-$(CONFIG_CPU_R4X00)	+= -march=r4600 -Wa,--trap
 cflags-$(CONFIG_CPU_TX49XX)	+= -march=r4600 -Wa,--trap
+cflags-$(CONFIG_CPU_LOONGSON2)	+= -march=r4600 -Wa,--trap
 

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Quoted 3 lines

Thiemo

I check the datasheet I have and i don't see loongson2e has implemented mips iv instructions.

Songmao

#33 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

In reply to Thiemo Seufer
Quoted 4 lines
Quoted 1 line

+cflags-$(CONFIG_CPU_LOONGSON2) += -march=r4600 -Wa,--trap

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Presently Loongson-2E is nearly MIPS III compatible(with some self-defined extensions), next version will be mips64 release2 compatible.

-march=r4600 is inherited from loongson-1, -march=mips3 might be a better choice.

Quoted 7 lines

Thiemo

#34 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

In reply to Thiemo Seufer
Quoted 4 lines
Quoted 1 line

+cflags-$(CONFIG_CPU_LOONGSON2) += -march=r4600 -Wa,--trap

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Presently Loongson-2E is nearly MIPS III compatible(with some self-defined extensions), next version will be mips64 release2 compatible.

-march=r4600 is inherited from loongson-1, -march=mips3 might be a better choice.

Quoted 7 lines

Thiemo

#35 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

Quoted 7 lines · Zhang Fuxin
Quoted 4 lines
Quoted 1 line

+cflags-$(CONFIG_CPU_LOONGSON2) += -march=r4600 -Wa,--trap

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Presently Loongson-2E is nearly MIPS III compatible(with some self-defined extensions), next version will be mips64 release2 compatible.

I see.

Quoted 2 lines

-march=r4600 is inherited from loongson-1, -march=mips3 might be a better choice.

Maybe. The 'mips3' maps to -march=r4000, it would assume more memory latency and a slower integer divider then -march=r4600.

Thiemo

#36 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

Quoted 9 lines · Thiemo Seufer
Quoted 7 lines · Zhang Fuxin
Quoted 4 lines
Quoted 1 line

+cflags-$(CONFIG_CPU_LOONGSON2) += -march=r4600 -Wa,--trap

I wonder why this is r4600. I heard the Loongson2 is MIPS IV compatible, so r5000 / r8000 / r10000 would be better choices.

Presently Loongson-2E is nearly MIPS III compatible(with some self-defined extensions), next version will be mips64 release2 compatible.

Quoted 7 lines

I see.

Quoted 2 lines

-march=r4600 is inherited from loongson-1, -march=mips3 might be a better choice.

Maybe. The 'mips3' maps to -march=r4000, it would assume more memory latency and a slower integer divider then -march=r4600.

I don't really have an issue with that since I see it as a temporary solution until gcc and binutils know about Loongson 2 specifics. Given the bit I know about the Loognson 2 processor architecture I would not expect a significant performance boost from trying different values for -march with current toolchains.

Ralf

#37 lore raw

Re: [PATCH 2/16] arch related Makefile update for lemote fulong mini-PC

In reply to Thiemo Seufer
Quoted 3 lines · Thiemo Seufer

Maybe. The 'mips3' maps to -march=r4000, it would assume more memory latency and a slower integer divider then -march=r4600.

Just like Ralf has said, -march might not lead to significant performance difference, but -mtune=
may. Two years ago, I found that adding a machine.def to descripe pipeline and resources for loongson2
and -mtune=loongson boost many programs by 2-5%。

Quoted 5 lines

Thiemo