Skip to contentSkip to conversation

VFP context save/restore for OMAP3

PATCH New Tero Kristo 5 participants 9 messages Dec 3, 2009 – May 13, 2010

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

v2 cover VFP context save/restore for OMAP3

From: Tero Kristo <[email protected]>

Contains following fixes compared to previous version:

- vfp_pm_suspend uses the same routine as context save
- uses get_cpu / put_cpu to get current CPU id
- removed restore context call completely from OMAP3 idle (not needed)

#1 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

From: Tero Kristo <[email protected]>

In some ARM architectures, like OMAP3, the VFP context can be lost during dynamic sleep cycle. For this purpose, there is now a function vfp_pm_save_context() that should be called before the VFP is assumed to lose context. Next VFP trap will then restore context automatically.

We need to have the last_VFP_context[cpu] cleared after the save in idle, else the restore would fail to restore when it sees that the last_VFP_context is same as the current threads vfp_state. This happens when the same process/thread traps an exception post idle.

This patch also fixes a potential problem with vfp_pm_suspend(), where VFP context can be lost if the current process does not have VFP enabled. Fixed by calling vfp_pm_save_context().

Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>
---
 arch/arm/vfp/vfpmodule.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
arch/arm/vfp/vfpmodule.c +20 -8
index 2d7423a..920a33b 100644
@@ -329,22 +329,34 @@ static void vfp_enable(void *unused)
 #ifdef CONFIG_PM
 #include <linux/sysdev.h>
 
-static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+void vfp_pm_save_context(void)
 {
-	struct thread_info *ti = current_thread_info();
 	u32 fpexc = fmrx(FPEXC);
+	unsigned int cpu = get_cpu();
+
+	/* Save last_VFP_context if needed */
+	if (last_VFP_context[cpu]) {
+		/* Enable vfp to save context */
+		if (!(fpexc & FPEXC_EN)) {
+			vfp_enable(NULL);
+			fmxr(FPEXC, fpexc | FPEXC_EN);
+		}
 
-	/* if vfp is on, then save state for resumption */
-	if (fpexc & FPEXC_EN) {
 		printk(KERN_DEBUG "%s: saving vfp state\n", __func__);
-		vfp_save_state(&ti->vfpstate, fpexc);
+		vfp_save_state(last_VFP_context[cpu], fpexc);
 
 		/* disable, just in case */
-		fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+		fmxr(FPEXC, fpexc & ~FPEXC_EN);
+
+		last_VFP_context[cpu] = NULL;
 	}
 
-	/* clear any information we had about last context state */
-	memset(last_VFP_context, 0, sizeof(last_VFP_context));
+	put_cpu();
+}
+
+static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+{
+	vfp_pm_save_context();
 
 	return 0;
 }
Signature · 1 line
1.5.4.3
#2 lore raw

PATCH v2 2/2 OMAP3: Implemented VFP restore/save context

From: Tero Kristo <[email protected]>

VFP save context is called before MPU/NEON off. Restore is not needed as the next VFP trap will restore context automatically. Uses the support routine implemented in arch/arm/vfp/vfpmodule.c.

Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>
---
 arch/arm/mach-omap2/pm.h     |    1 +
 arch/arm/mach-omap2/pm34xx.c |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/pm.h +1 -0
index e0c94ea..bf9b7f9 100644
@@ -23,6 +23,7 @@ extern void omap_sram_idle(void);
 extern int omap3_can_sleep(void);
 extern int set_pwrdm_state(struct powerdomain *pwrdm, u32 state);
 extern int omap3_idle_init(void);
+extern void vfp_pm_save_context(void);
 
 struct prm_setup_times_vc {
 	u16 clksetup;
arch/arm/mach-omap2/pm34xx.c +13 -1
index 009bc55..624a7af 100644
@@ -321,6 +321,13 @@ static void restore_control_register(u32 val)
 	__asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
 }
 
+static inline void omap3_save_neon_context(void)
+{
+#ifdef CONFIG_VFP
+	vfp_pm_save_context();
+#endif
+}
+
 /* Function to restore the table entry that was modified for enabling MMU */
 static void restore_table_entry(void)
 {
@@ -365,6 +372,7 @@ void omap_sram_idle(void)
 	/* save_state = 3 => L1, L2 and logic lost */
 	int save_state = 0;
 	int mpu_next_state = PWRDM_POWER_ON;
+	int neon_next_state = PWRDM_POWER_ON;
 	int per_next_state = PWRDM_POWER_ON;
 	int core_next_state = PWRDM_POWER_ON;
 	int core_prev_state, per_prev_state;
@@ -398,8 +406,12 @@ void omap_sram_idle(void)
 	pwrdm_pre_transition();
 
 	/* NEON control */
-	if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
+	if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON) {
 		pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
+		neon_next_state = mpu_next_state;
+		if (neon_next_state == PWRDM_POWER_OFF)
+			omap3_save_neon_context();
+	}
 
 	/* PER */
 	per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
Signature · 1 line
1.5.4.3
#3 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

In reply to Tero Kristo

hi, Russell, Tony

Is this patch ignored by you? I do not see any ack for this patch.

Thanks

Janboe Ye

2009/12/3 Tero Kristo <[email protected]>:

Quoted 80 lines

From: Tero Kristo <[email protected]>

In some ARM architectures, like OMAP3, the VFP context can be lost during dynamic sleep cycle. For this purpose, there is now a function vfp_pm_save_context() that should be called before the VFP is assumed to lose context. Next VFP trap will then restore context automatically.

We need to have the last_VFP_context[cpu] cleared after the save in idle, else the restore would fail to restore when it sees that the last_VFP_context is same as the current threads vfp_state. This happens when the same process/thread traps an exception post idle.

This patch also fixes a potential problem with vfp_pm_suspend(), where VFP context can be lost if the current process does not have VFP enabled. Fixed by calling vfp_pm_save_context().

Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>

---
?arch/arm/vfp/vfpmodule.c | ? 28 ++++++++++++++++++++-------- ?1 files changed, 20 insertions(+), 8 deletions(-)

arch/arm/vfp/vfpmodule.c +0 -0
index 2d7423a..920a33b 100644
@@ -329,22 +329,34 @@ static void vfp_enable(void *unused)

?#ifdef CONFIG_PM
?#include <linux/sysdev.h>

arch/arm/vfp/vfpmodule.c +1 -1
-static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+void vfp_pm_save_context(void)

?{
- ? ? ? struct thread_info *ti = current_thread_info(); ? ? ? ?u32 fpexc = fmrx(FPEXC);
+ ? ? ? unsigned int cpu = get_cpu();
+
+ ? ? ? /* Save last_VFP_context if needed */
+ ? ? ? if (last_VFP_context[cpu]) {
+ ? ? ? ? ? ? ? /* Enable vfp to save context */
+ ? ? ? ? ? ? ? if (!(fpexc & FPEXC_EN)) {
+ ? ? ? ? ? ? ? ? ? ? ? vfp_enable(NULL);
+ ? ? ? ? ? ? ? ? ? ? ? fmxr(FPEXC, fpexc | FPEXC_EN);
+ ? ? ? ? ? ? ? }

- ? ? ? /* if vfp is on, then save state for resumption */
- ? ? ? if (fpexc & FPEXC_EN) {
? ? ? ? ? ? ? ?printk(KERN_DEBUG "%s: saving vfp state\n", __func__);
- ? ? ? ? ? ? ? vfp_save_state(&ti->vfpstate, fpexc);
+ ? ? ? ? ? ? ? vfp_save_state(last_VFP_context[cpu], fpexc);

? ? ? ? ? ? ? ?/* disable, just in case */
- ? ? ? ? ? ? ? fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+ ? ? ? ? ? ? ? fmxr(FPEXC, fpexc & ~FPEXC_EN); +
+ ? ? ? ? ? ? ? last_VFP_context[cpu] = NULL; ? ? ? ?}

- ? ? ? /* clear any information we had about last context state */
- ? ? ? memset(last_VFP_context, 0, sizeof(last_VFP_context));
+ ? ? ? put_cpu();

arch/arm/vfp/vfpmodule.c +5 -0
+}
+
+static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+{
+ ? ? ? vfp_pm_save_context();

? ? ? ?return 0;
?}
--
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

Quoted 3 lines · ye janboe

hi, Russell, Tony

Is this patch ignored by you? I do not see any ack for this patch.

I guess we're still waiting to hear from Russell. AFAIK, this is needed in addition to the three patches from Imre.

Quoted 85 lines

Thanks

Janboe Ye

2009/12/3 Tero Kristo <[email protected]>:

Quoted 80 lines

From: Tero Kristo <[email protected]>

In some ARM architectures, like OMAP3, the VFP context can be lost during dynamic sleep cycle. For this purpose, there is now a function vfp_pm_save_context() that should be called before the VFP is assumed to lose context. Next VFP trap will then restore context automatically.

We need to have the last_VFP_context[cpu] cleared after the save in idle, else the restore would fail to restore when it sees that the last_VFP_context is same as the current threads vfp_state. This happens when the same process/thread traps an exception post idle.

This patch also fixes a potential problem with vfp_pm_suspend(), where VFP context can be lost if the current process does not have VFP enabled. Fixed by calling vfp_pm_save_context().

Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>

---
?arch/arm/vfp/vfpmodule.c | ? 28 ++++++++++++++++++++-------- ?1 files changed, 20 insertions(+), 8 deletions(-)

arch/arm/vfp/vfpmodule.c +0 -0
index 2d7423a..920a33b 100644
@@ -329,22 +329,34 @@ static void vfp_enable(void *unused)

?#ifdef CONFIG_PM
?#include <linux/sysdev.h>

arch/arm/vfp/vfpmodule.c +1 -1
-static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+void vfp_pm_save_context(void)

?{
- ? ? ? struct thread_info *ti = current_thread_info(); ? ? ? ?u32 fpexc = fmrx(FPEXC);
+ ? ? ? unsigned int cpu = get_cpu();
+
+ ? ? ? /* Save last_VFP_context if needed */
+ ? ? ? if (last_VFP_context[cpu]) {
+ ? ? ? ? ? ? ? /* Enable vfp to save context */
+ ? ? ? ? ? ? ? if (!(fpexc & FPEXC_EN)) {
+ ? ? ? ? ? ? ? ? ? ? ? vfp_enable(NULL);
+ ? ? ? ? ? ? ? ? ? ? ? fmxr(FPEXC, fpexc | FPEXC_EN);
+ ? ? ? ? ? ? ? }

- ? ? ? /* if vfp is on, then save state for resumption */
- ? ? ? if (fpexc & FPEXC_EN) {
? ? ? ? ? ? ? ?printk(KERN_DEBUG "%s: saving vfp state\n", __func__);
- ? ? ? ? ? ? ? vfp_save_state(&ti->vfpstate, fpexc);
+ ? ? ? ? ? ? ? vfp_save_state(last_VFP_context[cpu], fpexc);

? ? ? ? ? ? ? ?/* disable, just in case */
- ? ? ? ? ? ? ? fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
+ ? ? ? ? ? ? ? fmxr(FPEXC, fpexc & ~FPEXC_EN); +
+ ? ? ? ? ? ? ? last_VFP_context[cpu] = NULL; ? ? ? ?}

- ? ? ? /* clear any information we had about last context state */
- ? ? ? memset(last_VFP_context, 0, sizeof(last_VFP_context));
+ ? ? ? put_cpu();

arch/arm/vfp/vfpmodule.c +5 -0
+}
+
+static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
+{
+ ? ? ? vfp_pm_save_context();

? ? ? ?return 0;
?}
--
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

In reply to ye janboe
Quoted 1 line · ye janboe

Is this patch ignored by you? I do not see any ack for this patch.

Patch is fine, shame some of the people on the Cc haven't acked it though. Can we get acks from anyone of those, and then submit it to the patch system?

Quoted 5 lines
Quoted 5 lines
Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>
#6 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

Thanks for Russell and Tony.

I think this patch is needed when MPU support OFF mode, special on omap. Otherwise, VFP state will be lost.

2010/5/12 Russell King - ARM Linux <[email protected]>:

Quoted 13 lines · ye janboe
Quoted 1 line

Is this patch ignored by you? I do not see any ack for this patch.

Patch is fine, shame some of the people on the Cc haven't acked it though. Can we get acks from anyone of those, and then submit it to the patch system?

Quoted 5 lines
Quoted 5 lines
Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>
#7 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

+ peoples who are in CC list.

Janboe Ye

2010/5/13 ye janboe <[email protected]>:

Quoted 22 lines

Thanks for Russell and Tony.

I think this patch is needed when MPU support OFF mode, special on omap. Otherwise, VFP state will be lost.

2010/5/12 Russell King - ARM Linux <[email protected]>:

Quoted 13 lines · ye janboe
Quoted 1 line

Is this patch ignored by you? I do not see any ack for this patch.

Patch is fine, shame some of the people on the Cc haven't acked it though. Can we get acks from anyone of those, and then submit it to the patch system?

Quoted 5 lines
Quoted 5 lines
Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>
#8 lore raw

PATCH v2 1/2 ARM: VFP: Fixed suspend and added context save support

Ack.

Regards
Vishwa

Quoted 37 lines

-----Original Message-----
From: ye janboe [mailto:janboe.ye at gmail.com]
Sent: Thursday, May 13, 2010 2:44 PM
To: Tero Kristo; Sripathy, Vishwanath; Nayak, Rajendra; Woodruff, Richard; peter.de- schrijver at nokia.com
Cc: tony at atomide.com; linux-arm-kernel at lists.infradead.org; linux- omap at vger.kernel.org; Russell King - ARM Linux
Subject: Re: [PATCHv2 1/2] ARM: VFP: Fixed suspend and added context save support

+ peoples who are in CC list.

Janboe Ye

2010/5/13 ye janboe <[email protected]>:

Quoted 22 lines

Thanks for Russell and Tony.

I think this patch is needed when MPU support OFF mode, special on omap. Otherwise, VFP state will be lost.

2010/5/12 Russell King - ARM Linux <[email protected]>:

Quoted 13 lines · ye janboe
Quoted 1 line

Is this patch ignored by you? I do not see any ack for this patch.

Patch is fine, shame some of the people on the Cc haven't acked it though. Can we get acks from anyone of those, and then submit it to the patch system?

Quoted 5 lines
Quoted 5 lines
Cc Vishwanath Sripathy <[email protected]>
Cc Rajendra Nayak <[email protected]>
Cc Richard Woodruff <[email protected]>
Cc Peter 'p2' De Schrijver <[email protected]>