Skip to contentSkip to conversation

sparc64: Hibernation support

PATCH Superseded Kirill Tkhai 2 participants 3 messages Mar 8, 2013 – Mar 20, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc64: Hibernation support

Hi!

This patch is for hibernation support on sparc64.

Two steps to try:
1)"echo disk > /sys/power/state" makes a system sleeping 2)kernel parameter "resume=/dev/[swap_partition]" will say the system which swap partition to use for restore.

Use MMU bypass to copy data pages. This allowes not to create temporary page table as on some other architectures.

I changed mm/init_64.c because of restore may be called from initcall. This moment is before free_initmem(), so num_physpages must not be changed in it. Otherwise, restore fails by the reason of mismatched sizes of the loaded image and the system.

I tested the patch on single-core mcst-r1000 variant of v9. Everything work, but everybody is welcome to test it on any more standard v9 :)

---

arch/sparc/Kconfig +7 -0
index 9bff3db..9e1256f 100644
@@ -103,6 +103,9 @@ config HAVE_LATENCYTOP_SUPPORT
 	bool
 	default y if SPARC64
 
+config ARCH_HIBERNATION_POSSIBLE
+	def_bool y if SPARC64
+
 config AUDIT_ARCH
 	bool
 	default y
@@ -333,6 +336,10 @@ config ARCH_SPARSEMEM_DEFAULT
 
 source "mm/Kconfig"
 
+if SPARC64
+source "kernel/power/Kconfig"
+endif
+
 config SCHED_SMT
 	bool "SMT (Hyperthreading) scheduler support"
 	depends on SPARC64 && SMP
arch/sparc/Makefile +1 -0
index 541b8b0..9ff4236 100644
@@ -57,6 +57,7 @@ core-y                 += arch/sparc/
 libs-y                 += arch/sparc/prom/
 libs-y                 += arch/sparc/lib/
 
+drivers-$(CONFIG_PM) += arch/sparc/power/
 drivers-$(CONFIG_OPROFILE)	+= arch/sparc/oprofile/
 
 boot := arch/sparc/boot
arch/sparc/kernel/head_64.S +0 -0
index 2feb15c..1a2ce1e 100644
arch/sparc/lib/Makefile +0 -0
index 8410065..d4fc2f0 100644
arch/sparc/mm/init_64.c +1 -3
index 5c2c6e6..a40a845 100644
@@ -2061,7 +2061,7 @@ void __init mem_init(void)
 	 * allocated below.
 	 */
 	totalram_pages -= 1;
-	num_physpages = totalram_pages;
+	num_physpages = memblock_mem_size(last_valid_pfn) >> PAGE_SHIFT;
 
 	/*
 	 * Set up the zero page, mark it reserved, so that page count
@@ -2125,7 +2125,6 @@ void free_initmem(void)
 			ClearPageReserved(p);
 			init_page_count(p);
 			__free_page(p);
-			num_physpages++;
 			totalram_pages++;
 		}
 	}
@@ -2142,7 +2141,6 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 		ClearPageReserved(p);
 		init_page_count(p);
 		__free_page(p);
-		num_physpages++;
 		totalram_pages++;
 	}
 }
drivers/block/virtio_blk.c +0 -0
index 8ad21a2..380e1a1 100644
arch/sparc/power/Makefile new file +3 -0
new file mode 100644
index 0000000..3201ace
@@ -0,0 +1,3 @@
+# Makefile for Sparc-specific hibernate files.
+
+obj-$(CONFIG_HIBERNATION)	+= hibernate.o hibernate_asm.o
arch/sparc/power/hibernate.c new file +65 -0

65 lines not on this page · raw message

arch/sparc/power/hibernate.h new file +21 -0
new file mode 100644
index 0000000..6c002f4
@@ -0,0 +1,21 @@
+/*
+ * hibernate.c:  Hibernaton support specific for sparc64.
+ *
+ * Copyright (C) 2013 Kirill V Tkhai ([email protected])
+ */
+
+#ifndef ___SPARC_HIBERNATE_H
+#define ___SPARC_HIBERNATE_H
+
+#define SC_REG_FP	0
+#define SC_REG_CWP	8
+#define SC_REG_WSTATE	16
+
+#define SC_REG_TICK	24
+#define SC_REG_PSTATE	32
+
+#define SC_REG_G4	40
+#define SC_REG_G5	48
+#define SC_REG_G6	56
+
+#endif
arch/sparc/power/hibernate_asm.S new file +129 -0

129 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Kirill Tkhai

Hi!

This patch is for hibernation support on sparc64.

Hi Kirill.
Some late nitpick feedback.

Sam

Quoted 37 lines

Two steps to try:
1)"echo disk > /sys/power/state" makes a system sleeping 2)kernel parameter "resume=/dev/[swap_partition]" will say the system which swap partition to use for restore.

Use MMU bypass to copy data pages. This allowes not to create temporary page table as on some other architectures.

I changed mm/init_64.c because of restore may be called from initcall. This moment is before free_initmem(), so num_physpages must not be changed in it. Otherwise, restore fails by the reason of mismatched sizes of the loaded image and the system.

I tested the patch on single-core mcst-r1000 variant of v9. Everything work, but everybody is welcome to test it on any more standard v9 :)

---

arch/sparc/Kconfig +3 -0
index 9bff3db..9e1256f 100644
@@ -103,6 +103,9 @@ config HAVE_LATENCYTOP_SUPPORT
 	bool
 	default y if SPARC64
 
+config ARCH_HIBERNATION_POSSIBLE
+	def_bool y if SPARC64
+
 config AUDIT_ARCH
 	bool
 	default y

arch/sparc/Kconfig config ARCH_SPARSEMEM_DEFAULT · line 341

Quoted 6 lines
arch/sparc/Kconfig +3 -0
@@ -333,6 +336,10 @@ config ARCH_SPARSEMEM_DEFAULT
 
 source "mm/Kconfig"
 
+if SPARC64
+source "kernel/power/Kconfig"
+endif

The if SPARC64 is really not needed. As far as I could see we do not enable anything uin there for sparc32 anyway.
So the only purpose of adding the "if" thing is for documentation.

arch/sparc/lib/Makefile

Quoted 21 lines
arch/sparc/Kconfig +1 -0
+
 config SCHED_SMT
 	bool "SMT (Hyperthreading) scheduler support"
 	depends on SPARC64 && SMP
arch/sparc/Makefile +1 -0
index 541b8b0..9ff4236 100644
@@ -57,6 +57,7 @@ core-y                 += arch/sparc/
 libs-y                 += arch/sparc/prom/
 libs-y                 += arch/sparc/lib/
 
+drivers-$(CONFIG_PM) += arch/sparc/power/
 drivers-$(CONFIG_OPROFILE)	+= arch/sparc/oprofile/
 
 boot := arch/sparc/boot
arch/sparc/kernel/head_64.S +0 -0
index 2feb15c..1a2ce1e 100644
arch/sparc/lib/Makefile +0 -0
index 8410065..d4fc2f0 100644

These looks bogus. Did you touch file permissions?

Quoted 22 lines
arch/sparc/mm/init_64.c +1 -2
index 5c2c6e6..a40a845 100644
@@ -2061,7 +2061,7 @@ void __init mem_init(void)
 	 * allocated below.
 	 */
 	totalram_pages -= 1;
-	num_physpages = totalram_pages;
+	num_physpages = memblock_mem_size(last_valid_pfn) >> PAGE_SHIFT;
 
 	/*
 	 * Set up the zero page, mark it reserved, so that page count
@@ -2125,7 +2125,6 @@ void free_initmem(void)
 			ClearPageReserved(p);
 			init_page_count(p);
 			__free_page(p);
-			num_physpages++;
 			totalram_pages++;
 		}
 	}

arch/sparc/mm/init_64.c void free_initrd_mem(unsigned long start, unsigned long end) · line 2146

Quoted 7 lines
arch/sparc/mm/init_64.c +0 -1
@@ -2142,7 +2141,6 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 		ClearPageReserved(p);
 		init_page_count(p);
 		__free_page(p);
-		num_physpages++;
 		totalram_pages++;
 	}
 }

Could you separate this out as an independent change? I must admit I do not see why what you do here is OK.

drivers/block/virtio_blk.c

Quoted 2 lines
drivers/block/virtio_blk.c +0 -0
index 8ad21a2..380e1a1 100644

Looks bogus.

Quoted 15 lines
arch/sparc/power/Makefile new file +3 -0
new file mode 100644
index 0000000..3201ace
@@ -0,0 +1,3 @@
+# Makefile for Sparc-specific hibernate files.
+
+obj-$(CONFIG_HIBERNATION)	+= hibernate.o hibernate_asm.o
arch/sparc/power/hibernate.c new file +0 -0
new file mode 100644
index 0000000..89ca059

arch/sparc/power/hibernate.c line 7

Quoted 7 lines
arch/sparc/power/hibernate.c new file +7 -0
@@ -0,0 +1,65 @@
+/*
+ * hibernate.c:  Hibernaton support specific for sparc64.
+ *
+ * Copyright (C) 2013 Kirill V Tkhai ([email protected])
+ */
+
+#include <linux/mm.h>

Empty line..

arch/sparc/power/hibernate.c line 10

Quoted 3 lines
arch/sparc/power/hibernate.c new file +3 -0
+#include <asm/page.h>
+#include <asm/tlb.h>
+#include <asm/visasm.h>

Inverse christmas tree. Longest lines first.

arch/sparc/power/hibernate.c line 16

Quoted 6 lines
arch/sparc/power/hibernate.c new file +6 -0
+
+
+#include "hibernate.h"
+
+/* References to section boundaries */
+extern const void __nosave_begin, __nosave_end;

These belong in asm-generic/sections.h
Consider submitting a separate patch to Arnd.

Quoted 12 lines
arch/sparc/power/hibernate.c new file +12 -0
+
+struct saved_context {
+	unsigned long fp;
+	unsigned long cwp;
+	unsigned long wstate;
+
+	unsigned long tick;
+	unsigned long pstate;
+
+	unsigned long g4;
+	unsigned long g5;
+	unsigned long g6;

arch/sparc/power/hibernate.c line 38

Quoted 10 lines
arch/sparc/power/hibernate.c new file +10 -0
+} saved_context;
+
+/*
+ *	pfn_is_nosave - check if given pfn is in the 'nosave' section
+ */
+
+int pfn_is_nosave(unsigned long pfn)
+{
+	unsigned long nosave_begin_pfn = ((unsigned long)&__nosave_begin) >> PAGE_SHIFT;
+	unsigned long nosave_end_pfn = ((unsigned long)&__nosave_end) >> PAGE_SHIFT;

Use PFN_DOWN

arch/sparc/power/hibernate.c line 49

Quoted 11 lines
arch/sparc/power/hibernate.c new file +11 -0
+
+	BUILD_BUG_ON(SC_REG_FP != offsetof(struct saved_context, fp));
+	BUILD_BUG_ON(SC_REG_CWP != offsetof(struct saved_context, cwp));
+	BUILD_BUG_ON(SC_REG_WSTATE != offsetof(struct saved_context, wstate));
+
+	BUILD_BUG_ON(SC_REG_TICK != offsetof(struct saved_context, tick));
+	BUILD_BUG_ON(SC_REG_PSTATE != offsetof(struct saved_context, pstate));
+
+	BUILD_BUG_ON(SC_REG_G4 != offsetof(struct saved_context, g4));
+	BUILD_BUG_ON(SC_REG_G5 != offsetof(struct saved_context, g5));
+	BUILD_BUG_ON(SC_REG_G6 != offsetof(struct saved_context, g6));

Hmmm... See below.

Quoted 31 lines
arch/sparc/power/hibernate.c new file +16 -0
+
+	return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
+}
+
+void save_processor_state(void)
+{
+	save_and_clear_fpu();
+}
+
+void restore_processor_state(void)
+{
+	struct mm_struct *mm = current->active_mm;
+
+	load_secondary_context(mm);
+	tsb_context_switch(mm);
+}
arch/sparc/power/hibernate.h new file +9 -0
new file mode 100644
index 0000000..6c002f4
@@ -0,0 +1,21 @@
+/*
+ * hibernate.c:  Hibernaton support specific for sparc64.
+ *
+ * Copyright (C) 2013 Kirill V Tkhai ([email protected])
+ */
+
+#ifndef ___SPARC_HIBERNATE_H
+#define ___SPARC_HIBERNATE_H
+

arch/sparc/power/hibernate.h line 19

Quoted 10 lines
arch/sparc/power/hibernate.h new file +10 -0
+#define SC_REG_FP	0
+#define SC_REG_CWP	8
+#define SC_REG_WSTATE	16
+
+#define SC_REG_TICK	24
+#define SC_REG_PSTATE	32
+
+#define SC_REG_G4	40
+#define SC_REG_G5	48
+#define SC_REG_G6	56

Use kernel/asm-offsets.c to generate these constants. This is relaiable and you can skip the run-time checks above.

Quoted 8 lines
arch/sparc/power/hibernate.h new file +2 -0
+
+#endif
arch/sparc/power/hibernate_asm.S new file +0 -0
new file mode 100644
index 0000000..8cc5c4e

arch/sparc/power/hibernate_asm.S line 10

Quoted 10 lines
arch/sparc/power/hibernate_asm.S new file +10 -0
@@ -0,0 +1,129 @@
+/*
+ * hibernate.c:  Hibernaton support specific for sparc64.
+ *
+ * Copyright (C) 2013 Kirill V Tkhai ([email protected])
+ */
+
+#include <linux/linkage.h>
+#include <asm/page.h>
+#include <asm/cpudata.h>
+#include "hibernate.h"

Empty lines between the blocks.
And inverse christmas tree again.

For the asm part I did not look at it carefully.
But a few comments anyway.

arch/sparc/power/hibernate_asm.S line 14

Quoted 4 lines
arch/sparc/power/hibernate_asm.S new file +4 -0
+
+ENTRY(swsusp_arch_suspend)
+	save	%sp, -192, %sp
+	save	%sp, -192, %sp

This looks strange. Why two times?

Quoted 19 lines
arch/sparc/power/hibernate_asm.S new file +19 -0
+	flushw
+
+	setuw	saved_context, %g3
+	
+	/* Save window regs */
+	rdpr	%cwp, %g2
+	stx	%g2, [%g3 + SC_REG_CWP]
+	rdpr	%wstate, %g2
+	stx	%g2, [%g3 + SC_REG_WSTATE]
+	stx	%fp, [%g3 + SC_REG_FP]
+
+	/* Save state regs */
+	rdpr	%tick, %g2
+	stx	%g2, [%g3 + SC_REG_TICK]
+	rdpr	%pstate, %g2
+	stx	%g2, [%g3 + SC_REG_PSTATE]
+
+	/* Save global regs */
+	stx	%g4, [%g3 + SC_REG_G4]

arch/sparc/power/hibernate_asm.S line 43

Quoted 10 lines
arch/sparc/power/hibernate_asm.S new file +10 -0
+	stx	%g5, [%g3 + SC_REG_G5]
+	stx	%g6, [%g3 + SC_REG_G6]
+
+	call	swsusp_save
+	 nop
+
+	mov	%o0, %i0
+	restore
+
+        mov	%o0, %i0

Uses space for indent => use tab

arch/sparc/power/hibernate_asm.S line 50

Quoted 7 lines
arch/sparc/power/hibernate_asm.S new file +7 -0
+	ret
+	 restore
+
+ENTRY(swsusp_arch_resume)
+	/* Write restore_pblist to %l0 */
+	sethi	%hi(restore_pblist), %l0
+        ldx	[%l0 + %lo(restore_pblist)], %l0

Uses space for indent => use tab

Quoted 12 lines
arch/sparc/power/hibernate_asm.S new file +12 -0
+
+	call	__flush_tlb_all
+	 nop
+	
+	/* Write PAGE_OFFSET to %g7 */
+	sethi	%uhi(PAGE_OFFSET), %g7
+	sllx	%g7, 32, %g7
+
+	setuw	(PAGE_SIZE-8), %g3
+	
+	/* Use MMU Bypass */
+	rd	%asi, %g1

arch/sparc/power/hibernate_asm.S line 72

Quoted 10 lines
arch/sparc/power/hibernate_asm.S new file +10 -0
+	wr	%g0, ASI_PHYS_USE_EC, %asi
+
+	/* Fill ITLB */
+	ba	16f
+	 nop
+
+pbe_loop:
+	cmp	%l0, %g0
+	be	restore_ctx
+	 sub	%l0, %g7, %l0

Add empty line after delay slot

Quoted 47 lines
arch/sparc/power/hibernate_asm.S new file +47 -0
+	ldxa	[%l0    ] %asi, %l1 /* address */
+	ldxa	[%l0 + 8] %asi, %l2 /* orig_address */
+
+	/* phys addr */
+	sub	%l1, %g7, %l1
+	sub	%l2, %g7, %l2
+
+	mov	%g3, %l3 /* PAGE_SIZE-8 */
+copy_loop:
+	ldxa	[%l1 + %l3] ASI_PHYS_USE_EC, %g2
+	stxa	%g2, [%l2 + %l3] ASI_PHYS_USE_EC
+	cmp	%l3, %g0
+	bne	copy_loop
+	 sub	%l3, 8, %l3
+
+	/* next pbe */
+	ba	pbe_loop
+	 ldxa	[%l0 + 16] %asi, %l0
+
+restore_ctx:
+	setuw	saved_context, %g3
+	wrpr	%g0, 15, %pil
+
+	/* Restore window regs */
+	wrpr    %g0, 0, %canrestore
+	wrpr    %g0, 0, %otherwin
+	wrpr	%g0, 6, %cansave
+	wrpr    %g0, 0, %cleanwin
+
+	ldxa	[%g3 + SC_REG_CWP] %asi, %g2
+	wrpr	%g2, %cwp
+	ldxa	[%g3 + SC_REG_WSTATE] %asi, %g2
+	wrpr	%g2, %wstate
+	ldxa	[%g3 + SC_REG_FP] %asi, %fp
+
+	/* Restore state regs */
+	ldxa	[%g3 + SC_REG_PSTATE] %asi, %g2
+	wrpr	%g2, %pstate
+	ldxa	[%g3 + SC_REG_TICK] %asi, %g2
+	wrpr	%g2, %tick
+
+	/* Restore global regs */
+	ldxa	[%g3 + SC_REG_G4] %asi, %g4
+	ldxa	[%g3 + SC_REG_G5] %asi, %g5
+	ldxa	[%g3 + SC_REG_G6] %asi, %g6
+
+	wr	%g1, %g0, %asi

arch/sparc/power/hibernate_asm.S line 129

Quoted 10 lines
arch/sparc/power/hibernate_asm.S new file +10 -0
+
+	restore
+	restore
+
+	wrpr	%g0, 14, %pil
+
+	retl
+	 mov	%g0, %o0
+
+16:	ba,a	pbe_loop

All other labels have nice names - and then suddenly a label named "16"? And you are missing an instruction in the delay slot here.

Sam

#2 lore raw
In reply to Kirill Tkhai

20.03.2013, 01:37, "Sam Ravnborg" <[email protected]>:

Quoted 9 lines · Kirill Tkhai
Quoted 4 lines

šHi!

šThis patch is for hibernation support on sparc64.

Hi Kirill.
Some late nitpick feedback.

Hi, Sam.

Quoted 39 lines
Quoted 39 lines

šTwo steps to try:
š1)"echo disk > /sys/power/state" makes a system sleeping š2)kernel parameter "resume=/dev/[swap_partition]" will say šthe system which swap partition to use for restore.

šUse MMU bypass to copy data pages. This allowes not to šcreate temporary page table as on some other architectures.

šI changed mm/init_64.c because of restore may be called šfrom initcall. This moment is before free_initmem(), so šnum_physpages must not be changed in it. Otherwise, šrestore fails by the reason of mismatched sizes of the loaded šimage and the system.

šI tested the patch on single-core mcst-r1000 variant of v9. šEverything work, but everybody is welcome to test it on any šmore standard v9 :)

šSigned-off-by: Kirill Tkhai <[email protected]> šCC: David Miller <[email protected]>
š---
šdiff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig šindex 9bff3db..9e1256f 100644
š--- a/arch/sparc/Kconfig
š+++ b/arch/sparc/Kconfig
š@@ -103,6 +103,9 @@ config HAVE_LATENCYTOP_SUPPORT ššššššššššbool
ššššššššššdefault y if SPARC64

š+config ARCH_HIBERNATION_POSSIBLE
š+ def_bool y if SPARC64
š+
ššconfig AUDIT_ARCH
ššššššššššbool
ššššššššššdefault y
š@@ -333,6 +336,10 @@ config ARCH_SPARSEMEM_DEFAULT

ššsource "mm/Kconfig"

Quoted 7 lines
Quoted 3 lines

š+if SPARC64
š+source "kernel/power/Kconfig"
š+endif

The if SPARC64 is really not needed. As far as I could see we do not enable anything uin there for sparc32 anyway.
So the only purpose of adding the "if" thing is for documentation.

Otherwise it is shown at xconfig when "Show all options" is turned on. I copied the way how "drivers/cpufreq/Kconfig" is included.

Quoted 16 lines
Quoted 16 lines

š+
ššconfig SCHED_SMT
ššššššššššbool "SMT (Hyperthreading) scheduler support" ššššššššššdepends on SPARC64 && SMP
šdiff --git a/arch/sparc/Makefile b/arch/sparc/Makefile šindex 541b8b0..9ff4236 100644
š--- a/arch/sparc/Makefile
š+++ b/arch/sparc/Makefile
š@@ -57,6 +57,7 @@ core-y šššššššššššššššš+= arch/sparc/ ššlibs-y šššššššššššššššš+= arch/sparc/prom/ ššlibs-y šššššššššššššššš+= arch/sparc/lib/

š+drivers-$(CONFIG_PM) += arch/sparc/power/ ššdrivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/

Quoted 7 lines
Quoted 5 lines

ššboot := arch/sparc/boot
šdiff --git a/arch/sparc/kernel/head_64.S b/arch/sparc/kernel/head_64.S šindex 2feb15c..1a2ce1e 100644
šdiff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile šindex 8410065..d4fc2f0 100644

These looks bogus. Did you touch file permissions?

It's a wrong diff metadata. And one more below. Sorry.

Quoted 30 lines
Quoted 21 lines

šdiff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c šindex 5c2c6e6..a40a845 100644
š--- a/arch/sparc/mm/init_64.c
š+++ b/arch/sparc/mm/init_64.c
š@@ -2061,7 +2061,7 @@ void __init mem_init(void) ššššššššššš* allocated below.
ššššššššššš*/
šššššššššštotalram_pages -= 1;
š- num_physpages = totalram_pages;
š+ num_physpages = memblock_mem_size(last_valid_pfn) >> PAGE_SHIFT;

šššššššššš/*
ššššššššššš* Set up the zero page, mark it reserved, so that page count š@@ -2125,7 +2125,6 @@ void free_initmem(void) ššššššššššššššššššššššššššClearPageReserved(p); ššššššššššššššššššššššššššinit_page_count(p); šššššššššššššššššššššššššš__free_page(p);
š- num_physpages++; šššššššššššššššššššššššššštotalram_pages++; šššššššššššššššššš}
šššššššššš}

Quoted 8 lines

š@@ -2142,7 +2141,6 @@ void free_initrd_mem(unsigned long start, unsigned long end) ššššššššššššššššššClearPageReserved(p); ššššššššššššššššššinit_page_count(p); šššššššššššššššššš__free_page(p);
š- num_physpages++;
šššššššššššššššššštotalram_pages++;
šššššššššš}
šš}

Quoted 3 lines

Could you separate this out as an independent change? I must admit I do not see why what you do here is OK.

The arch-independent places where num_physpages
is used are

inet_frags_init()
sanitize_global_limit()
__online_page_set_limits()
and hibernation code.

It looks like everything is OK with all of them.

Quoted 28 lines
Quoted 2 lines

šdiff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c šindex 8ad21a2..380e1a1 100644

Looks bogus.

Quoted 14 lines

šdiff --git a/arch/sparc/power/Makefile b/arch/sparc/power/Makefile šnew file mode 100644
šindex 0000000..3201ace
š--- /dev/null
š+++ b/arch/sparc/power/Makefile
š@@ -0,0 +1,3 @@
š+# Makefile for Sparc-specific hibernate files.
š+
š+obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate_asm.o šdiff --git a/arch/sparc/power/hibernate.c b/arch/sparc/power/hibernate.c šnew file mode 100644
šindex 0000000..89ca059
š--- /dev/null
š+++ b/arch/sparc/power/hibernate.c

Quoted 8 lines

š@@ -0,0 +1,65 @@
š+/*
š+ * hibernate.c: šHibernaton support specific for sparc64. š+ *
š+ * Copyright (C) 2013 Kirill V Tkhai ([email protected]) š+ */
š+
š+#include <linux/mm.h>

Quoted 2 lines

Empty line..

Yes, thanks for this and for other formatting points.

Quoted 96 lines
Quoted 3 lines

š+#include <asm/page.h>
š+#include <asm/tlb.h>
š+#include <asm/visasm.h>

Inverse christmas tree. Longest lines first.

Quoted 6 lines

š+
š+
š+#include "hibernate.h"
š+
š+/* References to section boundaries */
š+extern const void __nosave_begin, __nosave_end;

These belong in asm-generic/sections.h
Consider submitting a separate patch to Arnd.

Quoted 14 lines

š+
š+struct saved_context {
š+ unsigned long fp;
š+ unsigned long cwp;
š+ unsigned long wstate;
š+
š+ unsigned long tick;
š+ unsigned long pstate;
š+
š+ unsigned long g4;
š+ unsigned long g5;
š+ unsigned long g6;
š+} saved_context;
š+

Quoted 8 lines

š+/*
š+ * pfn_is_nosave - check if given pfn is in the 'nosave' section
š+ */
š+
š+int pfn_is_nosave(unsigned long pfn)
š+{
š+ unsigned long nosave_begin_pfn = ((unsigned long)&__nosave_begin) >> PAGE_SHIFT; š+ unsigned long nosave_end_pfn = ((unsigned long)&__nosave_end) >> PAGE_SHIFT;

Use PFN_DOWN

Quoted 11 lines

š+
š+ BUILD_BUG_ON(SC_REG_FP != offsetof(struct saved_context, fp)); š+ BUILD_BUG_ON(SC_REG_CWP != offsetof(struct saved_context, cwp)); š+ BUILD_BUG_ON(SC_REG_WSTATE != offsetof(struct saved_context, wstate)); š+
š+ BUILD_BUG_ON(SC_REG_TICK != offsetof(struct saved_context, tick)); š+ BUILD_BUG_ON(SC_REG_PSTATE != offsetof(struct saved_context, pstate)); š+
š+ BUILD_BUG_ON(SC_REG_G4 != offsetof(struct saved_context, g4)); š+ BUILD_BUG_ON(SC_REG_G5 != offsetof(struct saved_context, g5)); š+ BUILD_BUG_ON(SC_REG_G6 != offsetof(struct saved_context, g6));

Hmmm... See below.

Quoted 33 lines

š+
š+ return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn); š+}
š+
š+void save_processor_state(void)
š+{
š+ save_and_clear_fpu();
š+}
š+
š+void restore_processor_state(void)
š+{
š+ struct mm_struct *mm = current->active_mm;
š+
š+ load_secondary_context(mm);
š+ tsb_context_switch(mm);
š+}
šdiff --git a/arch/sparc/power/hibernate.h b/arch/sparc/power/hibernate.h šnew file mode 100644
šindex 0000000..6c002f4
š--- /dev/null
š+++ b/arch/sparc/power/hibernate.h
š@@ -0,0 +1,21 @@
š+/*
š+ * hibernate.c: šHibernaton support specific for sparc64. š+ *
š+ * Copyright (C) 2013 Kirill V Tkhai ([email protected])
š+ */
š+
š+#ifndef ___SPARC_HIBERNATE_H
š+#define ___SPARC_HIBERNATE_H
š+
š+#define SC_REG_FP 0
š+#define SC_REG_CWP 8

Quoted 8 lines

š+#define SC_REG_WSTATE 16
š+
š+#define SC_REG_TICK 24
š+#define SC_REG_PSTATE 32
š+
š+#define SC_REG_G4 40
š+#define SC_REG_G5 48
š+#define SC_REG_G6 56

Quoted 3 lines

Use kernel/asm-offsets.c to generate these constants. This is relaiable and you can skip the run-time checks above.

Good advice. I'll follow it.

Quoted 25 lines
Quoted 10 lines

š+
š+#endif
šdiff --git a/arch/sparc/power/hibernate_asm.S b/arch/sparc/power/hibernate_asm.S šnew file mode 100644
šindex 0000000..8cc5c4e
š--- /dev/null
š+++ b/arch/sparc/power/hibernate_asm.S
š@@ -0,0 +1,129 @@
š+/*
š+ * hibernate.c: šHibernaton support specific for sparc64.

Quoted 8 lines

š+ *
š+ * Copyright (C) 2013 Kirill V Tkhai ([email protected]) š+ */
š+
š+#include <linux/linkage.h>
š+#include <asm/page.h>
š+#include <asm/cpudata.h>
š+#include "hibernate.h"

Empty lines between the blocks.
And inverse christmas tree again.

For the asm part I did not look at it carefully.
But a few comments anyway.

Quoted 6 lines
Quoted 4 lines

š+
š+ENTRY(swsusp_arch_suspend)
š+ save %sp, -192, %sp
š+ save %sp, -192, %sp

This looks strange. Why two times?

It's because I want save only
one %o or %i register -- %i6 (fp). Othervise
it's necessary to save at least one more -- %i7.

Quoted 126 lines
Quoted 22 lines

š+ flushw
š+
š+ setuw saved_context, %g3
š+
š+ /* Save window regs */
š+ rdpr %cwp, %g2
š+ stx %g2, [%g3 + SC_REG_CWP]
š+ rdpr %wstate, %g2
š+ stx %g2, [%g3 + SC_REG_WSTATE]
š+ stx %fp, [%g3 + SC_REG_FP]
š+
š+ /* Save state regs */
š+ rdpr %tick, %g2
š+ stx %g2, [%g3 + SC_REG_TICK]
š+ rdpr %pstate, %g2
š+ stx %g2, [%g3 + SC_REG_PSTATE]
š+
š+ /* Save global regs */
š+ stx %g4, [%g3 + SC_REG_G4]
š+ stx %g5, [%g3 + SC_REG_G5]
š+ stx %g6, [%g3 + SC_REG_G6]

Quoted 8 lines

š+
š+ call swsusp_save
š+ nop
š+
š+ mov %o0, %i0
š+ restore
š+
š+ šššššššmov %o0, %i0

Uses space for indent => use tab

Quoted 7 lines

š+ ret
š+ restore
š+
š+ENTRY(swsusp_arch_resume)
š+ /* Write restore_pblist to %l0 */
š+ sethi %hi(restore_pblist), %l0
š+ šššššššldx [%l0 + %lo(restore_pblist)], %l0

Uses space for indent => use tab

Quoted 14 lines

š+
š+ call __flush_tlb_all
š+ nop
š+
š+ /* Write PAGE_OFFSET to %g7 */
š+ sethi %uhi(PAGE_OFFSET), %g7
š+ sllx %g7, 32, %g7
š+
š+ setuw (PAGE_SIZE-8), %g3
š+
š+ /* Use MMU Bypass */
š+ rd %asi, %g1
š+ wr %g0, ASI_PHYS_USE_EC, %asi
š+

Quoted 8 lines

š+ /* Fill ITLB */
š+ ba 16f
š+ nop
š+
š+pbe_loop:
š+ cmp %l0, %g0
š+ be restore_ctx
š+ sub %l0, %g7, %l0

Add empty line after delay slot

Quoted 49 lines

š+ ldxa [%l0 ššš] %asi, %l1 /* address */
š+ ldxa [%l0 + 8] %asi, %l2 /* orig_address */
š+
š+ /* phys addr */
š+ sub %l1, %g7, %l1
š+ sub %l2, %g7, %l2
š+
š+ mov %g3, %l3 /* PAGE_SIZE-8 */
š+copy_loop:
š+ ldxa [%l1 + %l3] ASI_PHYS_USE_EC, %g2
š+ stxa %g2, [%l2 + %l3] ASI_PHYS_USE_EC
š+ cmp %l3, %g0
š+ bne copy_loop
š+ sub %l3, 8, %l3
š+
š+ /* next pbe */
š+ ba pbe_loop
š+ ldxa [%l0 + 16] %asi, %l0
š+
š+restore_ctx:
š+ setuw saved_context, %g3
š+ wrpr %g0, 15, %pil
š+
š+ /* Restore window regs */
š+ wrpr ššš%g0, 0, %canrestore
š+ wrpr ššš%g0, 0, %otherwin
š+ wrpr %g0, 6, %cansave
š+ wrpr ššš%g0, 0, %cleanwin
š+
š+ ldxa [%g3 + SC_REG_CWP] %asi, %g2
š+ wrpr %g2, %cwp
š+ ldxa [%g3 + SC_REG_WSTATE] %asi, %g2
š+ wrpr %g2, %wstate
š+ ldxa [%g3 + SC_REG_FP] %asi, %fp
š+
š+ /* Restore state regs */
š+ ldxa [%g3 + SC_REG_PSTATE] %asi, %g2
š+ wrpr %g2, %pstate
š+ ldxa [%g3 + SC_REG_TICK] %asi, %g2
š+ wrpr %g2, %tick
š+
š+ /* Restore global regs */
š+ ldxa [%g3 + SC_REG_G4] %asi, %g4
š+ ldxa [%g3 + SC_REG_G5] %asi, %g5
š+ ldxa [%g3 + SC_REG_G6] %asi, %g6
š+
š+ wr %g1, %g0, %asi
š+
š+ restore

Quoted 8 lines

š+ restore
š+
š+ wrpr %g0, 14, %pil
š+
š+ retl
š+ mov %g0, %o0
š+
š+16: ba,a pbe_loop

Quoted 2 lines

All other labels have nice names - and then suddenly a label named "16"? And you are missing an instruction in the delay slot here.

Now, I think mask NMI earlier and put this action as delayed instruction for this for the present unnamed branch. Looks like all copying must processes with level.

Thanks for feedback, I will send new patch a little later.

Kirill