Skip to contentSkip to conversation

MIPS: Loongson-3: Improve kernel functionality

PATCH Superseded Huacai Chen 1 participant 10 messages Sep 13, 2014

Subsystems (2)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover MIPS: Loongson-3: Improve kernel functionality

This patchset is prepared for the next 3.18 release for Linux/MIPS. In this series we promote Loongson-3's ISA level to MIPS64R1 since it is not fully compatible with MIPS64R2. Multi-node DMA and coherent cache features are both added here. LEFI firmware interface is improved to make the kernel more generic (machtypes can be dropped). Besides, we add some basic platform drivers (GPIO, CPU Hwmon, ACPI init, oprofile, HPET and CPUFreq) for Loongson-3.

Huacai Chen(11):
MIPS: Loongson: set Loongson-3's ISA level to MIPS64R1.
MIPS: Loongson-3: Add PHYS48_TO_HT40 support.
MIPS: Loongson: Introduce and use cpu_has_coherent_cache feature.
MIPS: Loongson: Allow booting from any core.
MIPS: Loongson: Improve LEFI firmware interface.
MIPS: Loongson: Add Loongson-3A/3B GPIO support.
MIPS: Loongson-3: Add CPU Hwmon platform driver.
MIPS: Loongson-3: Add chipset ACPI platform driver.
MIPS: Loongson-3: Add oprofile support.
MIPS: Loongson-3: Add RS780/SBX00 HPET support.
MIPS: Loongson: Make CPUFreq usable for Loongson-3.

---
 arch/mips/Kconfig                                  |    4 +
 arch/mips/include/asm/bootinfo.h                   |    5 +-
 arch/mips/include/asm/cpu-features.h               |    3 +
 arch/mips/include/asm/hpet.h                       |   73 ++++++
 arch/mips/include/asm/mach-loongson/boot_param.h   |   49 ++++-
 .../asm/mach-loongson/cpu-feature-overrides.h      |    3 +-
 .../mips/include/asm/mach-loongson/dma-coherence.h |   30 +++-
 arch/mips/include/asm/mach-loongson/irq.h          |    3 +-
 arch/mips/include/asm/mach-loongson/loongson.h     |    7 +-
 .../include/asm/mach-loongson/loongson_hwmon.h     |   55 +++++
 arch/mips/include/asm/mach-loongson/machine.h      |    2 +-
 arch/mips/include/asm/mach-loongson/topology.h     |    2 +-
 arch/mips/include/asm/mach-loongson/workarounds.h  |    7 +
 arch/mips/kernel/cpu-probe.c                       |    5 +-
 arch/mips/kernel/smp.c                             |    3 +-
 arch/mips/loongson/Kconfig                         |   18 ++
 arch/mips/loongson/common/dma-swiotlb.c            |   10 +
 arch/mips/loongson/common/early_printk.c           |    2 +-
 arch/mips/loongson/common/env.c                    |   37 +++-
 arch/mips/loongson/common/gpio.c                   |   53 +++--
 arch/mips/loongson/common/machtype.c               |    5 +-
 arch/mips/loongson/common/pci.c                    |    6 +
 arch/mips/loongson/common/platform.c               |   13 +-
 arch/mips/loongson/common/serial.c                 |   48 +++-
 arch/mips/loongson/common/time.c                   |    5 +
 arch/mips/loongson/common/uart_base.c              |   30 +--
 arch/mips/loongson/loongson-3/Makefile             |    4 +-
 arch/mips/loongson/loongson-3/clock.c              |  191 +++++++++++++++
 arch/mips/loongson/loongson-3/hpet.c               |  257 ++++++++++++++++++++
 arch/mips/loongson/loongson-3/irq.c                |   16 +-
 arch/mips/loongson/loongson-3/numa.c               |   12 +-
 arch/mips/loongson/loongson-3/platform.c           |   43 ++++
 arch/mips/loongson/loongson-3/smp.c                |   70 ++++--
 arch/mips/mm/c-r4k.c                               |   18 ++
 arch/mips/oprofile/Makefile                        |    1 +
 arch/mips/oprofile/common.c                        |    4 +
 arch/mips/oprofile/op_model_loongson3.c            |  220 +++++++++++++++++
 drivers/cpufreq/Kconfig                            |   14 +
 drivers/cpufreq/Makefile                           |    1 +
 drivers/cpufreq/loongson3_cpufreq.c                |  240 ++++++++++++++++++
 drivers/platform/Makefile                          |    1 +
 drivers/platform/mips/Makefile                     |    1 +
 drivers/platform/mips/acpi_init.c                  |  131 ++++++++++
 drivers/platform/mips/cpu_hwmon.c                  |  206 ++++++++++++++++
 44 files changed, 1798 insertions(+), 110 deletions(-)
 create mode 100644 arch/mips/include/asm/hpet.h
 create mode 100644 arch/mips/include/asm/mach-loongson/loongson_hwmon.h
 create mode 100644 arch/mips/include/asm/mach-loongson/workarounds.h
 create mode 100644 arch/mips/loongson/loongson-3/clock.c
 create mode 100644 arch/mips/loongson/loongson-3/hpet.c
 create mode 100644 arch/mips/loongson/loongson-3/platform.c
 create mode 100644 arch/mips/oprofile/op_model_loongson3.c
 create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
 create mode 100644 drivers/platform/mips/Makefile
 create mode 100644 drivers/platform/mips/acpi_init.c
 create mode 100644 drivers/platform/mips/cpu_hwmon.c

--
1.7.7.3

#1 lore raw

PATCH 1/11 MIPS: Loongson: set Loongson-3's ISA level to MIPS64R1

In CPU manual Loongson-3 is MIPS64R2 compatible, but during tests we found that its EI/DI instructions have problems. So we just set the ISA level to MIPS64R1.

---
 .../asm/mach-loongson/cpu-feature-overrides.h      |    2 --
 arch/mips/kernel/cpu-probe.c                       |    5 ++++-
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h +0 -2
index 7d28f95..6d69332 100644
@@ -41,10 +41,8 @@
 #define cpu_has_mcheck		0
 #define cpu_has_mdmx		0
 #define cpu_has_mips16		0
-#define cpu_has_mips32r1	0
 #define cpu_has_mips32r2	0
 #define cpu_has_mips3d		0
-#define cpu_has_mips64r1	0
 #define cpu_has_mips64r2	0
 #define cpu_has_mipsmt		0
 #define cpu_has_prefetch	0
arch/mips/kernel/cpu-probe.c +4 -1
index 08dc945..d5a4f38 100644
@@ -757,26 +757,29 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
 			c->cputype = CPU_LOONGSON2;
 			__cpu_name[cpu] = "ICT Loongson-2";
 			set_elf_platform(cpu, "loongson2e");
+			set_isa(c, MIPS_CPU_ISA_III);
 			break;
 		case PRID_REV_LOONGSON2F:
 			c->cputype = CPU_LOONGSON2;
 			__cpu_name[cpu] = "ICT Loongson-2";
 			set_elf_platform(cpu, "loongson2f");
+			set_isa(c, MIPS_CPU_ISA_III);
 			break;
 		case PRID_REV_LOONGSON3A:
 			c->cputype = CPU_LOONGSON3;
 			__cpu_name[cpu] = "ICT Loongson-3";
 			set_elf_platform(cpu, "loongson3a");
+			set_isa(c, MIPS_CPU_ISA_M64R1);
 			break;
 		case PRID_REV_LOONGSON3B_R1:
 		case PRID_REV_LOONGSON3B_R2:
 			c->cputype = CPU_LOONGSON3;
 			__cpu_name[cpu] = "ICT Loongson-3";
 			set_elf_platform(cpu, "loongson3b");
+			set_isa(c, MIPS_CPU_ISA_M64R1);
 			break;
 		}
 
-		set_isa(c, MIPS_CPU_ISA_III);
 		c->options = R4K_OPTS |
 			     MIPS_CPU_FPU | MIPS_CPU_LLSC |
 			     MIPS_CPU_32FPR;
Signature · 1 line
1.7.7.3
#2 lore raw

PATCH 2/11 MIPS: Loongson-3: Add PHYS48_TO_HT40 support

In reply to Huacai Chen

The width of HT-bus is only 40-bit, but Loongson-3 has 48-bit physical address. This implies only node-0's memory is DMAable because high bits (Node ID) will lost. Fortunately, by configuring address windows in firmware, we can extract 2bit Node ID (bit 44~47, only bit 44~45 used now) from Loongson-3's 48-bit address space and embed it into 40-bit (bit 37~38). Every NUMA node can do DMA now (however, maximum memory of each node is reduced to 2^37 = 128GB).

---
 .../mips/include/asm/mach-loongson/dma-coherence.h |   30 ++++++++++++++++++-
 arch/mips/loongson/Kconfig                         |    5 +++
 arch/mips/loongson/common/dma-swiotlb.c            |   10 ++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
arch/mips/include/asm/mach-loongson/dma-coherence.h +28 -2
index 6a90275..aff3261 100644
@@ -23,7 +23,17 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 					  size_t size)
 {
 #ifdef CONFIG_CPU_LOONGSON3
-	return virt_to_phys(addr);
+	long nid;
+	dma_addr_t daddr;
+
+	daddr = virt_to_phys(addr);
+#ifdef CONFIG_PHYS48_TO_HT40
+	 /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
+	  * Loongson-3's 48bit address space and embed it into 40bit */
+	nid = (daddr >> 44) & 0x3;
+	daddr = ((nid << 44) ^ daddr) | (nid << 37);
+#endif
+	return daddr;
 #else
 	return virt_to_phys(addr) | 0x80000000;
 #endif
@@ -33,7 +43,17 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
 					       struct page *page)
 {
 #ifdef CONFIG_CPU_LOONGSON3
-	return page_to_phys(page);
+	long nid;
+	dma_addr_t daddr;
+
+	daddr = page_to_phys(page);
+#ifdef CONFIG_PHYS48_TO_HT40
+	 /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
+	  * Loongson-3's 48bit address space and embed it into 40bit */
+	nid = (daddr >> 44) & 0x3;
+	daddr = ((nid << 44) ^ daddr) | (nid << 37);
+#endif
+	return daddr;
 #else
 	return page_to_phys(page) | 0x80000000;
 #endif
@@ -43,6 +63,12 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
 #if defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_64BIT)
+	long nid;
+
+#ifdef CONFIG_PHYS48_TO_HT40
+	nid = (dma_addr >> 37) & 0x3;
+	dma_addr = ((nid << 37) ^ dma_addr) | (nid << 44);
+#endif
 	return dma_addr;
 #elif defined(CONFIG_CPU_LOONGSON2F) && defined(CONFIG_64BIT)
 	return (dma_addr > 0x8fffffff) ? dma_addr : (dma_addr & 0x0fffffff);
arch/mips/loongson/Kconfig +5 -0
index 1b91fc6..72f830ac 100644
@@ -86,6 +86,7 @@ config LOONGSON_MACH3X
 	select LOONGSON_MC146818
 	select ZONE_DMA32
 	select LEFI_FIRMWARE_INTERFACE
+	select PHYS48_TO_HT40
 	help
 		Generic Loongson 3 family machines utilize the 3A/3B revision
 		of Loongson processor and RS780/SBX00 chipset.
@@ -131,6 +132,10 @@ config SWIOTLB
 	select NEED_SG_DMA_LENGTH
 	select NEED_DMA_MAP_STATE
 
+config PHYS48_TO_HT40
+	bool
+	default y if CPU_LOONGSON3
+
 config LOONGSON_MC146818
 	bool
 	default n
arch/mips/loongson/common/dma-swiotlb.c +10 -0
index c2be01f..d0d43ad 100644
@@ -105,11 +105,21 @@ static int loongson_dma_set_mask(struct device *dev, u64 mask)
 
 dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
+	long nid;
+#ifdef CONFIG_PHYS48_TO_HT40
+	nid = (paddr >> 44) & 0x3;
+	paddr = ((nid << 44) ^ paddr) | (nid << 37);
+#endif
 	return paddr;
 }
 
 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
+	long nid;
+#ifdef CONFIG_PHYS48_TO_HT40
+	nid = (daddr >> 37) & 0x3;
+	daddr = ((nid << 37) ^ daddr) | (nid << 44);
+#endif
 	return daddr;
 }
 
Signature · 1 line
1.7.7.3
#3 lore raw

PATCH 3/11 MIPS: Loongson: Introduce and use cpu_has_coherent_cache feature

In reply to Huacai Chen

Loongson-3 maintains cache coherency by hardware. So we introduce a cpu feature named cpu_has_coherent_cache and use it to modify MIPS's cache flushing functions.

---
 arch/mips/Kconfig                                  |    3 +++
 arch/mips/include/asm/cpu-features.h               |    3 +++
 .../asm/mach-loongson/cpu-feature-overrides.h      |    1 +
 arch/mips/mm/c-r4k.c                               |   18 ++++++++++++++++++
 4 files changed, 25 insertions(+), 0 deletions(-)
arch/mips/Kconfig +3 -0
index 37c272c..c69ac9c 100644
@@ -1598,6 +1598,7 @@ config CPU_BMIPS5000
 config SYS_HAS_CPU_LOONGSON3
 	bool
 	select CPU_SUPPORTS_CPUFREQ
+	select CPU_SUPPORTS_COHERENT_CACHE
 
 config SYS_HAS_CPU_LOONGSON2E
 	bool
@@ -1761,6 +1762,8 @@ config CPU_SUPPORTS_HUGEPAGES
 	bool
 config CPU_SUPPORTS_UNCACHED_ACCELERATED
 	bool
+config CPU_SUPPORTS_COHERENT_CACHE
+	bool
 config MIPS_PGD_C0_CONTEXT
 	bool
 	default y if 64BIT && CPU_MIPSR2 && !CPU_XLP
arch/mips/include/asm/cpu-features.h +3 -0
index 3325f3e..0e85d60 100644
@@ -148,6 +148,9 @@
 #ifndef cpu_has_pindexed_dcache
 #define cpu_has_pindexed_dcache	(cpu_data[0].dcache.flags & MIPS_CACHE_PINDEX)
 #endif
+#ifndef cpu_has_coherent_cache
+#define cpu_has_coherent_cache	0
+#endif
 #ifndef cpu_has_local_ebase
 #define cpu_has_local_ebase	1
 #endif
arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h +1 -0
index 6d69332..7efb191 100644
@@ -58,5 +58,6 @@
 #define cpu_has_local_ebase	0
 
 #define cpu_has_wsbh		IS_ENABLED(CONFIG_CPU_LOONGSON3)
+#define cpu_has_coherent_cache	IS_ENABLED(CONFIG_CPU_SUPPORTS_COHERENT_CACHE)
 
 #endif /* __ASM_MACH_LOONGSON_CPU_FEATURE_OVERRIDES_H */
arch/mips/mm/c-r4k.c +18 -0
index fbcd867..68b3c3d 100644
@@ -420,6 +420,9 @@ static void r4k_blast_scache_setup(void)
 
 static inline void local_r4k___flush_cache_all(void * args)
 {
+	if (cpu_has_coherent_cache)
+		return;
+
 	switch (current_cpu_type()) {
 	case CPU_LOONGSON2:
 	case CPU_LOONGSON3:
@@ -480,6 +483,9 @@ static inline void local_r4k_flush_cache_range(void * args)
 	struct vm_area_struct *vma = args;
 	int exec = vma->vm_flags & VM_EXEC;
 
+	if (cpu_has_coherent_cache)
+		return;
+
 	if (!(has_valid_asid(vma->vm_mm)))
 		return;
 
@@ -550,6 +556,9 @@ static inline void local_r4k_flush_cache_page(void *args)
 	pte_t *ptep;
 	void *vaddr;
 
+	if (cpu_has_coherent_cache)
+		return;
+
 	/*
 	 * If ownes no valid ASID yet, cannot possibly have gotten
 	 * this page into the cache.
@@ -625,11 +634,17 @@ static void r4k_flush_cache_page(struct vm_area_struct *vma,
 
 static inline void local_r4k_flush_data_cache_page(void * addr)
 {
+	if (cpu_has_coherent_cache)
+		return;
+
 	r4k_blast_dcache_page((unsigned long) addr);
 }
 
 static void r4k_flush_data_cache_page(unsigned long addr)
 {
+	if (cpu_has_coherent_cache)
+		return;
+
 	if (in_atomic())
 		local_r4k_flush_data_cache_page((void *)addr);
 	else
@@ -783,6 +798,9 @@ static void local_r4k_flush_cache_sigtramp(void * arg)
 	unsigned long sc_lsize = cpu_scache_line_size();
 	unsigned long addr = (unsigned long) arg;
 
+	if (cpu_has_coherent_cache)
+		return;
+
 	R4600_HIT_CACHEOP_WAR_IMPL;
 	if (dc_lsize)
 		protected_writeback_dcache_line(addr & ~(dc_lsize - 1));
Signature · 1 line
1.7.7.3
#4 lore raw

PATCH 4/11 MIPS: Loongson: Allow booting from any core

In reply to Huacai Chen

By offering Logical->Physical core id mapping, so as to reserve some physical cores via mask. This allow booting from any core when core-0 has problems. Since the maximun cores supported by Loongson-3 is 16, 32-bit cpu_startup_core_id can be split to 16-bit cpu_startup_core_id and 16-bit reserved_cores_mask for compatibility.

---
 arch/mips/include/asm/mach-loongson/boot_param.h |    5 +-
 arch/mips/include/asm/mach-loongson/irq.h        |    3 +-
 arch/mips/include/asm/mach-loongson/topology.h   |    2 +-
 arch/mips/loongson/common/env.c                  |    2 +
 arch/mips/loongson/loongson-3/irq.c              |   14 +++--
 arch/mips/loongson/loongson-3/numa.c             |   12 +++-
 arch/mips/loongson/loongson-3/smp.c              |   65 ++++++++++++++--------
 7 files changed, 67 insertions(+), 36 deletions(-)
arch/mips/include/asm/mach-loongson/boot_param.h +4 -1
index 3388fc5..11ebf4c 100644
@@ -42,7 +42,8 @@ struct efi_cpuinfo_loongson {
 	u32 processor_id; /* PRID, e.g. 6305, 6306 */
 	u32 cputype;  /* Loongson_3A/3B, etc. */
 	u32 total_node;   /* num of total numa nodes */
-	u32 cpu_startup_core_id; /* Core id */
+	u16 cpu_startup_core_id; /* Boot core id */
+	u16 reserved_cores_mask;
 	u32 cpu_clock_freq; /* cpu_clock */
 	u32 nr_cpus;
 } __packed;
@@ -149,6 +150,8 @@ struct loongson_system_configuration {
 	u32 nr_nodes;
 	int cores_per_node;
 	int cores_per_package;
+	u16 boot_cpu_id;
+	u16 reserved_cpus_mask;
 	enum loongson_cpu_type cputype;
 	u64 ht_control_base;
 	u64 pci_mem_start_addr;
arch/mips/include/asm/mach-loongson/irq.h +1 -2
index 34560bd..a281cca 100644
@@ -32,8 +32,7 @@
 #define LOONGSON_INT_ROUTER_LPC		LOONGSON_INT_ROUTER_ENTRY(0x0a)
 #define LOONGSON_INT_ROUTER_HT1(n)	LOONGSON_INT_ROUTER_ENTRY(n + 0x18)
 
-#define LOONGSON_INT_CORE0_INT0		0x11 /* route to int 0 of core 0 */
-#define LOONGSON_INT_CORE0_INT1		0x21 /* route to int 1 of core 0 */
+#define LOONGSON_INT_COREx_INTy(x, y)	(1<<(x) | 1<<(y+4))	/* route to int y of core x */
 
 #endif
 
arch/mips/include/asm/mach-loongson/topology.h +1 -1
index 5598ba7..0d8f3b5 100644
@@ -3,7 +3,7 @@
 
 #ifdef CONFIG_NUMA
 
-#define cpu_to_node(cpu)	((cpu) >> 2)
+#define cpu_to_node(cpu)	(cpu_logical_map(cpu) >> 2)
 #define parent_node(node)	(node)
 #define cpumask_of_node(node)	(&__node_data[(node)]->cpumask)
 
arch/mips/loongson/common/env.c +2 -0
index f152285..d8be539 100644
@@ -119,6 +119,8 @@ void __init prom_init_env(void)
 	}
 
 	loongson_sysconf.nr_cpus = ecpu->nr_cpus;
+	loongson_sysconf.boot_cpu_id = ecpu->cpu_startup_core_id;
+	loongson_sysconf.reserved_cpus_mask = ecpu->reserved_cores_mask;
 	if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0)
 		loongson_sysconf.nr_cpus = NR_CPUS;
 	loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus +
arch/mips/loongson/loongson-3/irq.c +8 -6
index ca1c62a..5813d94 100644
@@ -55,8 +55,8 @@ static inline void mask_loongson_irq(struct irq_data *d)
 	/* Workaround: UART IRQ may deliver to any core */
 	if (d->irq == LOONGSON_UART_IRQ) {
 		int cpu = smp_processor_id();
-		int node_id = cpu / loongson_sysconf.cores_per_node;
-		int core_id = cpu % loongson_sysconf.cores_per_node;
+		int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node;
+		int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node;
 		u64 intenclr_addr = smp_group[node_id] |
 			(u64)(&LOONGSON_INT_ROUTER_INTENCLR);
 		u64 introuter_lpc_addr = smp_group[node_id] |
@@ -72,8 +72,8 @@ static inline void unmask_loongson_irq(struct irq_data *d)
 	/* Workaround: UART IRQ may deliver to any core */
 	if (d->irq == LOONGSON_UART_IRQ) {
 		int cpu = smp_processor_id();
-		int node_id = cpu / loongson_sysconf.cores_per_node;
-		int core_id = cpu % loongson_sysconf.cores_per_node;
+		int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node;
+		int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node;
 		u64 intenset_addr = smp_group[node_id] |
 			(u64)(&LOONGSON_INT_ROUTER_INTENSET);
 		u64 introuter_lpc_addr = smp_group[node_id] |
@@ -102,10 +102,12 @@ void irq_router_init(void)
 	int i;
 
 	/* route LPC int to cpu core0 int 0 */
-	LOONGSON_INT_ROUTER_LPC = LOONGSON_INT_CORE0_INT0;
+	LOONGSON_INT_ROUTER_LPC =
+		LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 0);
 	/* route HT1 int0 ~ int7 to cpu core0 INT1*/
 	for (i = 0; i < 8; i++)
-		LOONGSON_INT_ROUTER_HT1(i) = LOONGSON_INT_CORE0_INT1;
+		LOONGSON_INT_ROUTER_HT1(i) =
+			LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 1);
 	/* enable HT1 interrupt */
 	LOONGSON_HT1_INTN_EN(0) = 0xffffffff;
 	/* enable router interrupt intenset */
arch/mips/loongson/loongson-3/numa.c +9 -3
index 37ed184..5246043 100644
@@ -223,7 +223,7 @@ static void __init node_mem_init(unsigned int node)
 
 static __init void prom_meminit(void)
 {
-	unsigned int node, cpu;
+	unsigned int node, cpu, active_cpu = 0;
 
 	cpu_node_probe();
 	init_topology_matrix();
@@ -239,8 +239,14 @@ static __init void prom_meminit(void)
 		node = cpu / loongson_sysconf.cores_per_node;
 		if (node >= num_online_nodes())
 			node = 0;
-		pr_info("NUMA: set cpumask cpu %d on node %d\n", cpu, node);
-		cpu_set(cpu, __node_data[(node)]->cpumask);
+
+		if (loongson_sysconf.reserved_cpus_mask & (1<<cpu))
+			continue;
+
+		cpu_set(active_cpu, __node_data[(node)]->cpumask);
+		pr_info("NUMA: set cpumask cpu %d on node %d\n", active_cpu, node);
+
+		active_cpu++;
 	}
 }
 
arch/mips/loongson/loongson-3/smp.c +42 -23

125 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#5 lore raw

PATCH 5/11 MIPS: Loongson: Improve LEFI firmware interface

In reply to Huacai Chen

Machtypes of Loongson-3 machines become more and more, but there are only small differences among different machtypes. Keeping a large table of machtypes is very ugly and hard to extend. We found that the major machtype differences are UARTs information (number of UARTs, UART IRQs, UART clocks, etc.), platform devices (EC, temperature sensors, fan controllers, etc.) and some workarounds (because of some CPU bugs or mainboard bugs).

In this patch we improve the UEFI-like (LEFI) interface to make all Loongson-3 machines use a same machtype "generic-loongson-machine".

---
 arch/mips/include/asm/bootinfo.h                   |    5 +--
 arch/mips/include/asm/mach-loongson/boot_param.h   |   44 +++++++++++++++-
 arch/mips/include/asm/mach-loongson/loongson.h     |    2 +-
 .../include/asm/mach-loongson/loongson_hwmon.h     |   55 ++++++++++++++++++++
 arch/mips/include/asm/mach-loongson/machine.h      |    2 +-
 arch/mips/include/asm/mach-loongson/workarounds.h  |    7 +++
 arch/mips/loongson/common/early_printk.c           |    2 +-
 arch/mips/loongson/common/env.c                    |   26 +++++++++-
 arch/mips/loongson/common/machtype.c               |    5 +--
 arch/mips/loongson/common/serial.c                 |   48 ++++++++++++++---
 arch/mips/loongson/common/uart_base.c              |   30 +++++------
 arch/mips/loongson/loongson-3/Makefile             |    2 +-
 arch/mips/loongson/loongson-3/platform.c           |   43 +++++++++++++++
 arch/mips/loongson/loongson-3/smp.c                |    5 +-
 14 files changed, 234 insertions(+), 42 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-loongson/loongson_hwmon.h
 create mode 100644 arch/mips/include/asm/mach-loongson/workarounds.h
 create mode 100644 arch/mips/loongson/loongson-3/platform.c
arch/mips/include/asm/bootinfo.h +1 -4
index 1f7ca8b..8b2eaa1 100644
@@ -70,10 +70,7 @@ enum loongson_machine_type {
 	MACH_DEXXON_GDIUM2F10,
 	MACH_LEMOTE_NAS,
 	MACH_LEMOTE_LL2F,
-	MACH_LEMOTE_A1004,
-	MACH_LEMOTE_A1101,
-	MACH_LEMOTE_A1201,
-	MACH_LEMOTE_A1205,
+	MACH_LOONGSON_GENERIC,
 	MACH_LOONGSON_END
 };
 
arch/mips/include/asm/mach-loongson/boot_param.h +42 -2

68 lines not on this page · raw message

arch/mips/include/asm/mach-loongson/loongson.h +1 -1
index 92bf76c..5459ac0 100644
@@ -35,7 +35,7 @@ extern void __init prom_init_cmdline(void);
 extern void __init prom_init_machtype(void);
 extern void __init prom_init_env(void);
 #ifdef CONFIG_LOONGSON_UART_BASE
-extern unsigned long _loongson_uart_base, loongson_uart_base;
+extern unsigned long _loongson_uart_base[], loongson_uart_base[];
 extern void prom_init_loongson_uart_base(void);
 #endif
 
arch/mips/include/asm/mach-loongson/loongson_hwmon.h new file +55 -0

55 lines not on this page · raw message

arch/mips/include/asm/mach-loongson/machine.h +1 -1
index 228e3784..cb2b602 100644
@@ -26,7 +26,7 @@
 
 #ifdef CONFIG_LOONGSON_MACH3X
 
-#define LOONGSON_MACHTYPE MACH_LEMOTE_A1101
+#define LOONGSON_MACHTYPE MACH_LOONGSON_GENERIC
 
 #endif /* CONFIG_LOONGSON_MACH3X */
 
arch/mips/include/asm/mach-loongson/workarounds.h new file +7 -0
new file mode 100644
index 0000000..e180c14
@@ -0,0 +1,7 @@
+#ifndef __ASM_MACH_LOONGSON_WORKAROUNDS_H_
+#define __ASM_MACH_LOONGSON_WORKAROUNDS_H_
+
+#define WORKAROUND_CPUFREQ	0x00000001
+#define WORKAROUND_CPUHOTPLUG	0x00000002
+
+#endif
arch/mips/loongson/common/early_printk.c +1 -1
index ced461b..6ca632e 100644
@@ -30,7 +30,7 @@ void prom_putchar(char c)
 	int timeout;
 	unsigned char *uart_base;
 
-	uart_base = (unsigned char *)_loongson_uart_base;
+	uart_base = (unsigned char *)_loongson_uart_base[0];
 	timeout = 1024;
 
 	while (((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0) &&
arch/mips/loongson/common/env.c +24 -2
index d8be539..045ea3d 100644
@@ -21,6 +21,7 @@
 #include <asm/bootinfo.h>
 #include <loongson.h>
 #include <boot_param.h>
+#include <workarounds.h>
 
 u32 cpu_clock_freq;
 EXPORT_SYMBOL(cpu_clock_freq);
@@ -31,7 +32,6 @@ u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
 u64 loongson_freqctrl[MAX_PACKAGES];
 
 unsigned long long smp_group[4];
-int cpuhotplug_workaround = 0;
 
 #define parse_even_earlier(res, option, p)				\
 do {									\
@@ -67,6 +67,7 @@ void __init prom_init_env(void)
 #else
 	struct boot_params *boot_p;
 	struct loongson_params *loongson_p;
+	struct system_loongson *esys;
 	struct efi_cpuinfo_loongson *ecpu;
 	struct irq_source_routing_table *eirq_source;
 
@@ -74,6 +75,8 @@ void __init prom_init_env(void)
 	boot_p = (struct boot_params *)fw_arg2;
 	loongson_p = &(boot_p->efi.smbios.lp);
 
+	esys = (struct system_loongson *)
+		((u64)loongson_p + loongson_p->system_offset);
 	ecpu = (struct efi_cpuinfo_loongson *)
 		((u64)loongson_p + loongson_p->cpu_offset);
 	eirq_source = (struct irq_source_routing_table *)
@@ -95,6 +98,7 @@ void __init prom_init_env(void)
 		loongson_chipcfg[2] = 0x900020001fe00180;
 		loongson_chipcfg[3] = 0x900030001fe00180;
 		loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
+		loongson_sysconf.workarounds = WORKAROUND_CPUFREQ;
 	} else if (ecpu->cputype == Loongson_3B) {
 		loongson_sysconf.cores_per_node = 4; /* One chip has 2 nodes */
 		loongson_sysconf.cores_per_package = 8;
@@ -111,7 +115,7 @@ void __init prom_init_env(void)
 		loongson_freqctrl[2] = 0x900040001fe001d0;
 		loongson_freqctrl[3] = 0x900060001fe001d0;
 		loongson_sysconf.ht_control_base = 0x90001EFDFB000000;
-		cpuhotplug_workaround = 1;
+		loongson_sysconf.workarounds = WORKAROUND_CPUHOTPLUG;
 	} else {
 		loongson_sysconf.cores_per_node = 1;
 		loongson_sysconf.cores_per_package = 1;
@@ -143,6 +147,24 @@ void __init prom_init_env(void)
 	pr_debug("Shutdown Addr: %llx, Restart Addr: %llx, VBIOS Addr: %llx\n",
 		loongson_sysconf.poweroff_addr, loongson_sysconf.restart_addr,
 		loongson_sysconf.vgabios_addr);
+
+	memset(loongson_sysconf.ecname, 0, 32);
+	if (esys->has_ec)
+		memcpy(loongson_sysconf.ecname, esys->ec_name, 32);
+	loongson_sysconf.workarounds |= esys->workarounds;
+
+	loongson_sysconf.nr_uarts = esys->nr_uarts;
+	if (esys->nr_uarts < 1 || esys->nr_uarts > MAX_UARTS)
+		loongson_sysconf.nr_uarts = 1;
+	memcpy(loongson_sysconf.uarts, esys->uarts,
+		sizeof(struct uart_device) * loongson_sysconf.nr_uarts);
+
+	loongson_sysconf.nr_sensors = esys->nr_sensors;
+	if (loongson_sysconf.nr_sensors > MAX_SENSORS)
+		loongson_sysconf.nr_sensors = 0;
+	if (loongson_sysconf.nr_sensors)
+		memcpy(loongson_sysconf.sensors, esys->sensors,
+			sizeof(struct sensor_device) * loongson_sysconf.nr_sensors);
 #endif
 	if (cpu_clock_freq == 0) {
 		processor_id = (&current_cpu_data)->processor_id;
arch/mips/loongson/common/machtype.c +1 -4
index 1a47979..26629ab 100644
@@ -27,10 +27,7 @@ static const char *system_types[] = {
 	[MACH_DEXXON_GDIUM2F10]		"dexxon-gdium-2f",
 	[MACH_LEMOTE_NAS]		"lemote-nas-2f",
 	[MACH_LEMOTE_LL2F]		"lemote-lynloong-2f",
-	[MACH_LEMOTE_A1004]		"lemote-3a-notebook-a1004",
-	[MACH_LEMOTE_A1101]		"lemote-3a-itx-a1101",
-	[MACH_LEMOTE_A1201]		"lemote-2gq-notebook-a1201",
-	[MACH_LEMOTE_A1205]		"lemote-2gq-aio-a1205",
+	[MACH_LOONGSON_GENERIC]		"generic-loongson-machine",
 	[MACH_LOONGSON_END]		NULL,
 };
 
arch/mips/loongson/common/serial.c +40 -8

74 lines not on this page · raw message

arch/mips/loongson/common/uart_base.c +14 -16
index 1e1eeea..9de559d 100644
@@ -13,22 +13,27 @@
 
 #include <loongson.h>
 
-/* ioremapped */
-unsigned long _loongson_uart_base;
-EXPORT_SYMBOL(_loongson_uart_base);
 /* raw */
-unsigned long loongson_uart_base;
+unsigned long loongson_uart_base[MAX_UARTS] = {};
+/* ioremapped */
+unsigned long _loongson_uart_base[MAX_UARTS] = {};
+
 EXPORT_SYMBOL(loongson_uart_base);
+EXPORT_SYMBOL(_loongson_uart_base);
 
 void prom_init_loongson_uart_base(void)
 {
 	switch (mips_machtype) {
+	case MACH_LOONGSON_GENERIC:
+		/* The CPU provided serial port (CPU) */
+		loongson_uart_base[0] = LOONGSON_REG_BASE + 0x1e0;
+		break;
 	case MACH_LEMOTE_FL2E:
-		loongson_uart_base = LOONGSON_PCIIO_BASE + 0x3f8;
+		loongson_uart_base[0] = LOONGSON_PCIIO_BASE + 0x3f8;
 		break;
 	case MACH_LEMOTE_FL2F:
 	case MACH_LEMOTE_LL2F:
-		loongson_uart_base = LOONGSON_PCIIO_BASE + 0x2f8;
+		loongson_uart_base[0] = LOONGSON_PCIIO_BASE + 0x2f8;
 		break;
 	case MACH_LEMOTE_ML2F7:
 	case MACH_LEMOTE_YL2F89:
@@ -36,17 +41,10 @@ void prom_init_loongson_uart_base(void)
 	case MACH_LEMOTE_NAS:
 	default:
 		/* The CPU provided serial port (LPC) */
-		loongson_uart_base = LOONGSON_LIO1_BASE + 0x3f8;
-		break;
-	case MACH_LEMOTE_A1004:
-	case MACH_LEMOTE_A1101:
-	case MACH_LEMOTE_A1201:
-	case MACH_LEMOTE_A1205:
-		/* The CPU provided serial port (CPU) */
-		loongson_uart_base = LOONGSON_REG_BASE + 0x1e0;
+		loongson_uart_base[0] = LOONGSON_LIO1_BASE + 0x3f8;
 		break;
 	}
 
-	_loongson_uart_base =
-		(unsigned long)ioremap_nocache(loongson_uart_base, 8);
+	_loongson_uart_base[0] =
+		(unsigned long)ioremap_nocache(loongson_uart_base[0], 8);
 }
arch/mips/loongson/loongson-3/Makefile +1 -1
index b4df775..69809a3 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for Loongson-3 family machines
 #
-obj-y			+= irq.o cop2-ex.o
+obj-y			+= irq.o cop2-ex.o platform.o
 
 obj-$(CONFIG_SMP)	+= smp.o
 
arch/mips/loongson/loongson-3/platform.c new file +43 -0

43 lines not on this page · raw message

arch/mips/loongson/loongson-3/smp.c +3 -2
index e53d015..46e9f5e 100644
@@ -25,6 +25,7 @@
 #include <asm/tlbflush.h>
 #include <asm/cacheflush.h>
 #include <loongson.h>
+#include <workarounds.h>
 
 #include "smp.h"
 
@@ -587,7 +588,7 @@ void loongson3_disable_clock(int cpu)
 	if (loongson_sysconf.cputype == Loongson_3A) {
 		LOONGSON_CHIPCFG(package_id) &= ~(1 << (12 + core_id));
 	} else if (loongson_sysconf.cputype == Loongson_3B) {
-		if (!cpuhotplug_workaround)
+		if (!(loongson_sysconf.workarounds & WORKAROUND_CPUHOTPLUG))
 			LOONGSON_FREQCTRL(package_id) &= ~(1 << (core_id * 4 + 3));
 	}
 }
@@ -600,7 +601,7 @@ void loongson3_enable_clock(int cpu)
 	if (loongson_sysconf.cputype == Loongson_3A) {
 		LOONGSON_CHIPCFG(package_id) |= 1 << (12 + core_id);
 	} else if (loongson_sysconf.cputype == Loongson_3B) {
-		if (!cpuhotplug_workaround)
+		if (!(loongson_sysconf.workarounds & WORKAROUND_CPUHOTPLUG))
 			LOONGSON_FREQCTRL(package_id) |= 1 << (core_id * 4 + 3);
 	}
 }
Signature · 1 line
1.7.7.3
#6 lore raw

PATCH 6/11 MIPS: Loongson: Add Loongson-3A/3B GPIO support

In reply to Huacai Chen
---
 arch/mips/Kconfig                |    1 +
 arch/mips/loongson/common/gpio.c |   53 ++++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 22 deletions(-)
arch/mips/Kconfig +1 -0
index c69ac9c..46fc4d4 100644
@@ -1200,6 +1200,7 @@ config CPU_LOONGSON3
 	select CPU_SUPPORTS_HUGEPAGES
 	select WEAK_ORDERING
 	select WEAK_REORDERING_BEYOND_LLSC
+	select ARCH_REQUIRE_GPIOLIB
 	help
 		The Loongson 3 processor implements the MIPS64R2 instruction
 		set with many extensions.
arch/mips/loongson/common/gpio.c +31 -22

124 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#7 lore raw

PATCH 7/11 MIPS: Loongson-3: Add CPU Hwmon platform driver

In reply to Huacai Chen

This add CPU Hwmon (temperature sensor) platform driver for Loongson-3.

---
 arch/mips/include/asm/mach-loongson/loongson.h |    4 +
 arch/mips/loongson/common/env.c                |    9 +
 drivers/platform/Makefile                      |    1 +
 drivers/platform/mips/Makefile                 |    1 +
 drivers/platform/mips/cpu_hwmon.c              |  206 ++++++++++++++++++++++++
 5 files changed, 221 insertions(+), 0 deletions(-)
 create mode 100644 drivers/platform/mips/Makefile
 create mode 100644 drivers/platform/mips/cpu_hwmon.c
arch/mips/include/asm/mach-loongson/loongson.h +4 -0
index 5459ac0..9783103 100644
@@ -255,6 +255,10 @@ static inline void do_perfcnt_IRQ(void)
 extern u64 loongson_chipcfg[MAX_PACKAGES];
 #define LOONGSON_CHIPCFG(id) (*(volatile u32 *)(loongson_chipcfg[id]))
 
+/* Chip Temperature registor of each physical cpu package, PRid >= Loongson-3A */
+extern u64 loongson_chiptemp[MAX_PACKAGES];
+#define LOONGSON_CHIPTEMP(id) (*(volatile u32 *)(loongson_chiptemp[id]))
+
 /* Freq Control register of each physical cpu package, PRid >= Loongson-3B */
 extern u64 loongson_freqctrl[MAX_PACKAGES];
 #define LOONGSON_FREQCTRL(id) (*(volatile u32 *)(loongson_freqctrl[id]))
arch/mips/loongson/common/env.c +9 -0
index 045ea3d..22f04ca 100644
@@ -29,6 +29,7 @@ struct efi_memory_map_loongson *loongson_memmap;
 struct loongson_system_configuration loongson_sysconf;
 
 u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
+u64 loongson_chiptemp[MAX_PACKAGES];
 u64 loongson_freqctrl[MAX_PACKAGES];
 
 unsigned long long smp_group[4];
@@ -97,6 +98,10 @@ void __init prom_init_env(void)
 		loongson_chipcfg[1] = 0x900010001fe00180;
 		loongson_chipcfg[2] = 0x900020001fe00180;
 		loongson_chipcfg[3] = 0x900030001fe00180;
+		loongson_chiptemp[0] = 0x900000001fe0019c;
+		loongson_chiptemp[1] = 0x900010001fe0019c;
+		loongson_chiptemp[2] = 0x900020001fe0019c;
+		loongson_chiptemp[3] = 0x900030001fe0019c;
 		loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
 		loongson_sysconf.workarounds = WORKAROUND_CPUFREQ;
 	} else if (ecpu->cputype == Loongson_3B) {
@@ -110,6 +115,10 @@ void __init prom_init_env(void)
 		loongson_chipcfg[1] = 0x900020001fe00180;
 		loongson_chipcfg[2] = 0x900040001fe00180;
 		loongson_chipcfg[3] = 0x900060001fe00180;
+		loongson_chiptemp[0] = 0x900000001fe0019c;
+		loongson_chiptemp[1] = 0x900020001fe0019c;
+		loongson_chiptemp[2] = 0x900040001fe0019c;
+		loongson_chiptemp[3] = 0x900060001fe0019c;
 		loongson_freqctrl[0] = 0x900000001fe001d0;
 		loongson_freqctrl[1] = 0x900020001fe001d0;
 		loongson_freqctrl[2] = 0x900040001fe001d0;
drivers/platform/Makefile +1 -0
index 3656b7b..f2dbc00 100644
@@ -5,4 +5,5 @@
 obj-$(CONFIG_X86)		+= x86/
 obj-$(CONFIG_OLPC)		+= olpc/
 obj-$(CONFIG_GOLDFISH)		+= goldfish/
+obj-$(CONFIG_CPU_LOONGSON3)	+= mips/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
drivers/platform/mips/Makefile new file +1 -0
new file mode 100644
index 0000000..15723a6
@@ -0,0 +1 @@
+obj-y += cpu_hwmon.o
drivers/platform/mips/cpu_hwmon.c new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#8 lore raw

PATCH 8/11 MIPS: Loongson-3: Add chipset ACPI platform driver

In reply to Huacai Chen

This add south-bridge (SB700/SB710/SB800 chipset) ACPI platform driver for Loongson-3. This will be used by EC (Embedded Controller, used by laptops) driver and STR (Suspend To RAM).

---
 arch/mips/loongson/common/pci.c   |    6 ++
 drivers/platform/mips/Makefile    |    2 +-
 drivers/platform/mips/acpi_init.c |  131 +++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 1 deletions(-)
 create mode 100644 drivers/platform/mips/acpi_init.c
arch/mips/loongson/common/pci.c +6 -0
index 003ab4e..4e25756 100644
@@ -78,6 +78,8 @@ static void __init setup_pcimap(void)
 #endif
 }
 
+extern int sbx00_acpi_init(void);
+
 static int __init pcibios_init(void)
 {
 	setup_pcimap();
@@ -89,6 +91,10 @@ static int __init pcibios_init(void)
 #endif
 	register_pci_controller(&loongson_pci_controller);
 
+#ifdef CONFIG_CPU_LOONGSON3
+	sbx00_acpi_init();
+#endif
+
 	return 0;
 }
 
drivers/platform/mips/Makefile +1 -1
index 15723a6..acf0084 100644
@@ -1 +1 @@
-obj-y += cpu_hwmon.o
+obj-y += acpi_init.o cpu_hwmon.o
drivers/platform/mips/acpi_init.c new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#9 lore raw

PATCH 9/11 MIPS: Loongson-3: Add oprofile support

In reply to Huacai Chen

Loongson-3 has two groups of performance counters, they are 4 sub- registers of CP0's REG25. This patch add oprofile support.

REG25, sel 0: Perf Control of group 0;
REG25, sel 1: Perf Counter of group 0;
REG25, sel 2: Perf Control of group 1;
REG25, sel 3: Perf Counter of group 1.

---
 arch/mips/oprofile/Makefile             |    1 +
 arch/mips/oprofile/common.c             |    4 +
 arch/mips/oprofile/op_model_loongson3.c |  220 +++++++++++++++++++++++++++++++
 3 files changed, 225 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/oprofile/op_model_loongson3.c
arch/mips/oprofile/Makefile +1 -0
index 9c0a678..070afdb 100644
@@ -14,3 +14,4 @@ oprofile-$(CONFIG_CPU_R10000)		+= op_model_mipsxx.o
 oprofile-$(CONFIG_CPU_SB1)		+= op_model_mipsxx.o
 oprofile-$(CONFIG_CPU_XLR)		+= op_model_mipsxx.o
 oprofile-$(CONFIG_CPU_LOONGSON2)	+= op_model_loongson2.o
+oprofile-$(CONFIG_CPU_LOONGSON3)	+= op_model_loongson3.o
arch/mips/oprofile/common.c +4 -0
index e747324..feb9879 100644
@@ -18,6 +18,7 @@
 
 extern struct op_mips_model op_model_mipsxx_ops __weak;
 extern struct op_mips_model op_model_loongson2_ops __weak;
+extern struct op_mips_model op_model_loongson3_ops __weak;
 
 static struct op_mips_model *model;
 
@@ -104,6 +105,9 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
 	case CPU_LOONGSON2:
 		lmodel = &op_model_loongson2_ops;
 		break;
+	case CPU_LOONGSON3:
+		lmodel = &op_model_loongson3_ops;
+		break;
 	};
 
 	if (!lmodel)
arch/mips/oprofile/op_model_loongson3.c new file +220 -0

220 lines not on this page · raw message

Signature · 1 line
1.7.7.3