Skip to contentSkip to conversation

MIPS: Loongson-3: Improve kernel functionality

PATCH In review Huacai Chen 2 participants 8 messages Mar 29, 2015 – Apr 2, 2015

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

PATCH v9 2/7 MIPS: Hibernate: Restructure files and functions

In reply to Huacai Chen

This patch has no functional changes, it just to keep the assembler code to a minimum. Files and functions naming is borrowed from X86.

---
 arch/mips/power/Makefile        |    2 +-
 arch/mips/power/hibernate.S     |   63 ---------------------------------------
 arch/mips/power/hibernate.c     |   10 ++++++
 arch/mips/power/hibernate_asm.S |   61 +++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 64 deletions(-)
 delete mode 100644 arch/mips/power/hibernate.S
 create mode 100644 arch/mips/power/hibernate.c
 create mode 100644 arch/mips/power/hibernate_asm.S
arch/mips/power/Makefile +1 -1
index 73d56b8..70bd788 100644
@@ -1 +1 @@
-obj-$(CONFIG_HIBERNATION) += cpu.o hibernate.o
+obj-$(CONFIG_HIBERNATION) += cpu.o hibernate.o hibernate_asm.o
arch/mips/power/hibernate.S deleted +0 -63

63 lines not on this page · raw message

arch/mips/power/hibernate.c new file +10 -0
new file mode 100644
index 0000000..19a9af6
@@ -0,0 +1,10 @@
+#include <asm/tlbflush.h>
+
+extern int restore_image(void);
+
+int swsusp_arch_resume(void)
+{
+	/* Avoid TLB mismatch during and after kernel resume */
+	local_flush_tlb_all();
+	return restore_image();
+}
arch/mips/power/hibernate_asm.S new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#5 lore raw

PATCH v9 5/7 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/Kconfig                       |    3 +
 drivers/platform/Makefile                      |    1 +
 drivers/platform/mips/Kconfig                  |   26 +++
 drivers/platform/mips/Makefile                 |    1 +
 drivers/platform/mips/cpu_hwmon.c              |  207 ++++++++++++++++++++++++
 7 files changed, 251 insertions(+), 0 deletions(-)
 create mode 100644 drivers/platform/mips/Kconfig
 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/Kconfig +3 -0
index 09fde58..0adccbf 100644
@@ -1,6 +1,9 @@
 if X86
 source "drivers/platform/x86/Kconfig"
 endif
+if MIPS
+source "drivers/platform/mips/Kconfig"
+endif
 if GOLDFISH
 source "drivers/platform/goldfish/Kconfig"
 endif
drivers/platform/Makefile +1 -0
index 3656b7b..ca26925 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_X86)		+= x86/
+obj-$(CONFIG_MIPS)		+= mips/
 obj-$(CONFIG_OLPC)		+= olpc/
 obj-$(CONFIG_GOLDFISH)		+= goldfish/
 obj-$(CONFIG_CHROME_PLATFORMS)	+= chrome/
drivers/platform/mips/Kconfig new file +26 -0
new file mode 100644
index 0000000..b3ae30a
@@ -0,0 +1,26 @@
+#
+# MIPS Platform Specific Drivers
+#
+
+menuconfig MIPS_PLATFORM_DEVICES
+	bool "MIPS Platform Specific Device Drivers"
+	default y
+	help
+	  Say Y here to get to see options for device drivers of various
+	  MIPS platforms, including vendor-specific netbook/laptop/desktop
+	  extension and hardware monitor drivers. This option itself does
+	  not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped and disabled.
+
+if MIPS_PLATFORM_DEVICES
+
+config CPU_HWMON
+	tristate "Loongson CPU HWMon Driver"
+	depends on LOONGSON_MACH3X
+	select HWMON
+	default y
+	help
+	  Loongson-3A/3B CPU Hwmon (temperature sensor) driver.
+
+endif # MIPS_PLATFORM_DEVICES
drivers/platform/mips/Makefile new file +1 -0
new file mode 100644
index 0000000..8dfd039
@@ -0,0 +1 @@
+obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o
drivers/platform/mips/cpu_hwmon.c new file +207 -0

207 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#1 lore raw

PATCH v9 1/7 MIPS: Hibernate: flush TLB entries earlier

In reply to Huacai Chen

We found that TLB mismatch not only happens after kernel resume, but also happens during snapshot restore. So move it to the beginning of swsusp_arch_suspend().

---
 arch/mips/power/hibernate.S |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/mips/power/hibernate.S +2 -1
index 32a7c82..e7567c8 100644
@@ -30,6 +30,8 @@ LEAF(swsusp_arch_suspend)
 END(swsusp_arch_suspend)
 
 LEAF(swsusp_arch_resume)
+	/* Avoid TLB mismatch during and after kernel resume */
+	jal local_flush_tlb_all
 	PTR_L t0, restore_pblist
 0:
 	PTR_L t1, PBE_ADDRESS(t0)   /* source */
@@ -43,7 +45,6 @@ LEAF(swsusp_arch_resume)
 	bne t1, t3, 1b
 	PTR_L t0, PBE_NEXT(t0)
 	bnez t0, 0b
-	jal local_flush_tlb_all /* Avoid TLB mismatch after kernel resume */
 	PTR_LA t0, saved_regs
 	PTR_L ra, PT_R31(t0)
 	PTR_L sp, PT_R29(t0)
Signature · 1 line
1.7.7.3
#4 lore raw

PATCH v9 4/7 MIPS: perf: Add hardware perf events support for Loongson-3

In reply to Huacai Chen

This patch enable hardware performance counter support for Loongson-3's perf events.

---
 arch/mips/Kconfig                    |    2 +-
 arch/mips/kernel/perf_event_mipsxx.c |   71 ++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletions(-)
arch/mips/Kconfig +1 -1
index 4d75a1d..4c813a6 100644
@@ -2429,7 +2429,7 @@ config NODES_SHIFT
 
 config HW_PERF_EVENTS
 	bool "Enable hardware performance counter support for perf events"
-	depends on PERF_EVENTS && OPROFILE=n && (CPU_MIPS32 || CPU_MIPS64 || CPU_R10000 || CPU_SB1 || CPU_CAVIUM_OCTEON || CPU_XLP)
+	depends on PERF_EVENTS && OPROFILE=n && (CPU_MIPS32 || CPU_MIPS64 || CPU_R10000 || CPU_SB1 || CPU_CAVIUM_OCTEON || CPU_XLP || CPU_LOONGSON3)
 	default y
 	help
 	  Enable hardware performance counter support for perf events. If
arch/mips/kernel/perf_event_mipsxx.c +71 -0

95 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#6 lore raw

PATCH v9 6/7 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    |    3 +
 drivers/platform/mips/acpi_init.c |  150 +++++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+), 0 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 +3 -0
index 8dfd039..522c8e1 100644
@@ -1 +1,4 @@
+ifdef CONFIG_CPU_LOONGSON3
+obj-y += acpi_init.o
 obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o
+endif
drivers/platform/mips/acpi_init.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#3 lore raw

PATCH v9 3/7 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                               |   21 ++++++++++++++++++++
 4 files changed, 28 insertions(+), 0 deletions(-)
arch/mips/Kconfig +3 -0
index 47e9353..4d75a1d 100644
@@ -1749,6 +1749,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
@@ -1930,6 +1931,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 62a5be7..58f0091 100644
@@ -154,6 +154,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 +21 -0
index 3f80596..36f553f 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:
@@ -447,6 +450,9 @@ static inline void local_r4k___flush_cache_all(void * args)
 
 static void r4k___flush_cache_all(void)
 {
+	if (cpu_has_coherent_cache)
+		return;
+
 	r4k_on_each_cpu(local_r4k___flush_cache_all, NULL);
 }
 
@@ -493,6 +499,9 @@ static void r4k_flush_cache_range(struct vm_area_struct *vma,
 {
 	int exec = vma->vm_flags & VM_EXEC;
 
+	if (cpu_has_coherent_cache)
+		return;
+
 	if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc))
 		r4k_on_each_cpu(local_r4k_flush_cache_range, vma);
 }
@@ -616,6 +625,9 @@ static void r4k_flush_cache_page(struct vm_area_struct *vma,
 {
 	struct flush_cache_page_args args;
 
+	if (cpu_has_coherent_cache)
+		return;
+
 	args.vma = vma;
 	args.addr = addr;
 	args.pfn = pfn;
@@ -625,11 +637,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
@@ -814,6 +832,9 @@ static void local_r4k_flush_cache_sigtramp(void * arg)
 
 static void r4k_flush_cache_sigtramp(unsigned long addr)
 {
+	if (cpu_has_coherent_cache)
+		return;
+
 	r4k_on_each_cpu(local_r4k_flush_cache_sigtramp, (void *) addr);
 }
 
Signature · 1 line
1.7.7.3
#0 lore raw

v9 cover MIPS: Loongson-3: Improve kernel functionality

This patchset is prepared for the next 4.1 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.

V1 -> V2:
1, Add a patch to fix Loongson's CCA setting.
2, Rework the third patch.
3, Rebase the code for 3.19.

V2 -> V3:
1, Remove patches which have merged in upstream.
2, Moving GPIO driver from arch/mips to drivers/gpio directory. 3, Optimize cacheflush by moving cpu_has_coherent_cache checking from
local version to global version.

V3 -> V4:
1, Don't build CPU Hwmon driver unconditionally.
2, Split the 2nd patch (Loongson GPIO driver) to two patches.

V4 -> V5:
1, Cleanup Loongson-2F's GPIO driver before move to drivers/gpio.

V5 -> V6:
1, Add perf support for Loongson-3.
2, Rebase the code for 3.20.

V6 -> V7:
1, Rework the third and fifth patches.

V7 -> V8:
1, Improve the seventh patch (ACPI init).
2, Rebase the code for 4.1.

V8 -> V9:
1, Add two patches to fix hibernation bugs.
2, Add MODULE_LICENSE("GPL") in platform drivers.
3, Adjust Kconfig and Makefile in platform drivers.
4, Remove the 3rd~5th patches since they will be merged in gpio tree.

Huacai Chen(7):
MIPS: Hibernate: flush TLB entries earlier.
MIPS: Hibernate: Restructure files and functions.
MIPS: Loongson: Introduce and use cpu_has_coherent_cache feature.
MIPS: perf: Add hardware perf events support for Loongson-3.
MIPS: Loongson-3: Add CPU Hwmon platform driver.
MIPS: Loongson-3: Add chipset ACPI platform driver.
MIPS: Loongson: Make CPUFreq usable for Loongson-3.

---
 arch/mips/Kconfig                                  |    5 +-
 arch/mips/include/asm/cpu-features.h               |    3 +
 .../asm/mach-loongson/cpu-feature-overrides.h      |    1 +
 arch/mips/include/asm/mach-loongson/loongson.h     |    5 +
 arch/mips/kernel/perf_event_mipsxx.c               |   71 ++++++
 arch/mips/kernel/smp.c                             |    3 +-
 arch/mips/loongson/Kconfig                         |    1 +
 arch/mips/loongson/common/env.c                    |    9 +
 arch/mips/loongson/common/pci.c                    |    6 +
 arch/mips/loongson/common/platform.c               |   13 +-
 arch/mips/loongson/loongson-3/Makefile             |    2 +-
 arch/mips/loongson/loongson-3/clock.c              |  191 ++++++++++++++++
 arch/mips/mm/c-r4k.c                               |   21 ++
 arch/mips/power/Makefile                           |    2 +-
 arch/mips/power/hibernate.S                        |   62 -----
 arch/mips/power/hibernate.c                        |   10 +
 arch/mips/power/hibernate_asm.S                    |   61 +++++
 drivers/cpufreq/Kconfig                            |   15 ++
 drivers/cpufreq/Makefile                           |    1 +
 drivers/cpufreq/loongson3_cpufreq.c                |  240 ++++++++++++++++++++
 drivers/platform/Kconfig                           |    3 +
 drivers/platform/Makefile                          |    1 +
 drivers/platform/mips/Kconfig                      |   26 ++
 drivers/platform/mips/Makefile                     |    4 +
 drivers/platform/mips/acpi_init.c                  |  150 ++++++++++++
 drivers/platform/mips/cpu_hwmon.c                  |  207 +++++++++++++++++
 26 files changed, 1044 insertions(+), 69 deletions(-)
 create mode 100644 arch/mips/loongson/loongson-3/clock.c
 delete mode 100644 arch/mips/power/hibernate.S
 create mode 100644 arch/mips/power/hibernate.c
 create mode 100644 arch/mips/power/hibernate_asm.S
 create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
 create mode 100644 drivers/platform/mips/Kconfig
 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

#7 lore raw

Re: [PATCH V9 6/7] MIPS: Loongson-3: Add chipset ACPI platform driver

In reply to Huacai Chen
Quoted 3 lines · Huacai Chen
 arch/mips/loongson/common/pci.c   |    6 ++
 drivers/platform/mips/Makefile    |    3 +
 drivers/platform/mips/acpi_init.c |  150 +++++++++++++++++++++++++++++++++++++

Applied - but:

This isn't even a proper driver but rather a collection of subroutines. I wonder this has to reside in drivers/platform/mips, not in drivers/acpi/ or even in the Loongson arch code?

drivers/platform/mips/Makefile line 4

Quoted 9 lines
drivers/platform/mips/Makefile +3 -0
index 8dfd039..522c8e1 100644
@@ -1 +1,4 @@
+ifdef CONFIG_CPU_LOONGSON3
+obj-y += acpi_init.o
 obj-$(CONFIG_CPU_HWMON) += cpu_hwmon.o
+endif

This is where the yelling starts. A Makefile that doesn't define any obj-* or lib-* variables such as this one if CONFIG_CPU_LOONGSON3 is undefined, will break the build. In other words, this hasn't been tested on even a single other platform. I've fixed this but it's normally up to the submitter to ensure this sort of thing doesn't happen.

Ralf