lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210627073806.32564-1-zhangqing@loongson.cn>
Date:   Sun, 27 Jun 2021 15:38:06 +0800
From:   Qing Zhang <zhangqing@...ngson.cn>
To:     Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
        Rob Herring <robh+dt@...nel.org>,
        Jiaxun Yang <jiaxun.yang@...goat.com>,
        Huacai Chen <chenhuacai@...nel.org>
Cc:     devicetree@...r.kernel.org, linux-mips@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH v2] MIPS: Loongson64: Add Loongson-2K1000 reset support

Add power management register operations to support reboot and poweroff.

Signed-off-by: Qing Zhang <zhangqing@...ngson.cn>
---

v1-v2:
- Add pm block node

Signed-off-by: Qing Zhang <zhangqing@...ngson.cn>

diff --git a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
index 569e814def83..929e8ddf86eb 100644
--- a/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
+++ b/arch/mips/boot/dts/loongson/loongson64-2k1000.dtsi
@@ -101,6 +101,14 @@ uart0: serial@...00000 {
 			no-loopback-test;
 		};
 
+		pm: power-controller {
+			device_type = "power management";
+			reg = <0 0x1fe0700c 0 0x8>,
+				<0 0x1fe07014 0 0x8>,
+				<0 0x1fe07030 0 0x8>;
+			reg-names = "pm1_sts", "pm1_cnt", "rst_cnt";
+		};
+
 		pci@...00000 {
 			compatible = "loongson,ls2k-pci";
 			device_type = "pci";
diff --git a/arch/mips/loongson64/reset.c b/arch/mips/loongson64/reset.c
index c97bfdc8c922..ea125e925d44 100644
--- a/arch/mips/loongson64/reset.c
+++ b/arch/mips/loongson64/reset.c
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/kexec.h>
+#include <linux/of_address.h>
 #include <linux/pm.h>
 #include <linux/slab.h>
 
@@ -20,12 +21,50 @@
 #include <loongson.h>
 #include <boot_param.h>
 
+static char *pm_reg_name[] = {"pm1_sts", "pm1_cnt", "rst_cnt"};
+
+static void __iomem *get_reg_byname(struct device_node *node, const char *name)
+{
+	int index = of_property_match_string(node, "reg-names", name);
+
+	if (index < 0)
+		return NULL;
+
+	return of_iomap(node, index);
+}
+
+static int  __init loongson_fdt_reset_init(void)
+{
+	struct device_node *np;
+	int i;
+
+	np = of_find_node_by_type(NULL, "power management");
+	if (!np) {
+		pr_info("Failed to get PM node\n");
+		return -ENODEV;
+	}
+
+	for (i = 0; i < sizeof(pm_reg_name)/sizeof(char *); i++) {
+		pm_reg_name[i] = get_reg_byname(np, pm_reg_name[i]);
+		if (!pm_reg_name[i])
+			iounmap(pm_reg_name[i]);
+	}
+
+	of_node_put(np);
+	return 0;
+}
+arch_initcall(loongson_fdt_reset_init);
+
 static void loongson_restart(char *command)
 {
+	if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
+		writel(0x1, (void *)pm_reg_name[2]);
+	} else {
+		void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
 
-	void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
+		fw_restart();
+	}
 
-	fw_restart();
 	while (1) {
 		if (cpu_wait)
 			cpu_wait();
@@ -34,9 +73,18 @@ static void loongson_restart(char *command)
 
 static void loongson_poweroff(void)
 {
-	void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
+	if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R) {
+		/* Clear */
+		writel((readl((void *)pm_reg_name[0]) & 0xffffffff), (void *)pm_reg_name[0]);
+		/* Sleep Enable | Soft Off*/
+		writel(GENMASK(12, 10)|BIT(13), (void *)pm_reg_name[1]);
+	} else {
+
+		void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
+
+		fw_poweroff();
+	}
 
-	fw_poweroff();
 	while (1) {
 		if (cpu_wait)
 			cpu_wait();
-- 
2.31.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ