[Pm-utils] [PATCH RFC] Merge 20video and 99video

Victor Lowther victor.lowther at gmail.com
Sat Feb 16 16:53:37 PST 2008


After examining the source to s2ram and seeing how it does the video
quirk handling, I cannot see why 20video an 99video are seperate hooks.

This patch aims to rectify that. It does the following things:
* Merge the functionality of 20video and 99video by folding the state
  saving that 20video does into 99video.
* Modifies the state saving and restoring code in pm/functions.in to 
  make savestate also accept the state to save on stdin.  This allows
  savestate and restorestate to be symmetric and to ensure that they
  can handle any type of data without it getting mangled by using a
  shell variable as an intermediate stage.
* Make 99video use savestate and restorestate to save and restore vbe
  state information across suspend/resume instead of using their own
  temporary files.
* Add support for --quirk-none.  The latest HAL can run us with it, but
  we did not handle it.  We do now.
* While I am at it, fix up 94cpufreq to use the new state handling
  functionality. This also improves readability.


 pm/functions.in      |   13 ++++++-
 pm/sleep.d/20video   |   67 ---------------------------------------
 pm/sleep.d/94cpufreq |    7 ++--
 pm/sleep.d/99video   |   84 +++++++++++++++++++++++++++++++------------------
 src/pm-action.in     |    3 ++
 5 files changed, 70 insertions(+), 104 deletions(-)
 delete mode 100755 pm/sleep.d/20video

diff --git a/pm/functions.in b/pm/functions.in
index 6fb7c94..bacfeaf 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -299,10 +299,19 @@ restartservice()
 
 savestate()
 {
-	echo "$2" > "${STORAGEDIR}/state:$1"
+	if [ -z "$2" ]; then
+		exec > "${STORAGEDIR}/state:$1"
+	else
+		echo "$2" > "${STORAGEDIR}/state:$1"
+	fi
+}
+
+state_exists() 
+{
+	[ -O "${STORAGEDIR}/state:${1}" ] 
 }
 
 restorestate()
 {
-	[ -O "${STORAGEDIR}/state:${1}" ] && cat "${STORAGEDIR}/state:${1}"
+	state_exists "$1" && cat "${STORAGEDIR}/state:${1}"
 }
diff --git a/pm/sleep.d/20video b/pm/sleep.d/20video
deleted file mode 100755
index 05d91ee..0000000
--- a/pm/sleep.d/20video
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-#
-# Copyright 2006-2007 Richard Hughes <richard at hughsie.com>
-# Copyright 2007 Peter Jones <pjones at redhat.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of version 2 of the GNU General Public License as
-# published by the Free Software Foundation.
-
-. "${PM_FUNCTIONS}"
-
-if command_exists vbetool; then
-	vbe() { vbetool "$@"; }
-else 
-	vbe() { echo "vbetool not found" 1>&2; return 1; }
-fi
-
-if command_exists radeontool; then
-	radeon() { radeontool "$@"; }
-else
-	radeon() { echo "radeontool not found" 1>&2; return 1; }
-fi
-
-suspend_video()
-{
-	# 0=nothing, 1=s3_bios, 2=s3_mode, 3=both
-	if [ "${DISPLAY_QUIRK_S3_BIOS}" = "true" -a \
-		"${DISPLAY_QUIRK_S3_MODE}" = "true" ]; then
-		sysctl -w kernel.acpi_video_flags=3
-	elif [ "${DISPLAY_QUIRK_S3_BIOS}" = "true" ]; then
-		sysctl -w kernel.acpi_video_flags=1
-	elif [ "${DISPLAY_QUIRK_S3_MODE}" = "true" ]; then
-		sysctl -w kernel.acpi_video_flags=2
-	else
-		sysctl -w kernel.acpi_video_flags=0
-	fi
-
-	# We might need to do one or many of these quirks
-	if [ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ]; then
-		radeon dac off
-		radeon light off
-	fi
-	if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ]; then
-		vbe vbestate save > /var/run/vbestate
-	fi
-	if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ]; then
-		vbe vbemode get > /var/run/vbemode
-	fi
-	if [ "${DISPLAY_QUIRK_VGA_MODE_3}" = "true" ]; then
-		vbe vbemode set 3
-	fi
-	if [ "${DISPLAY_QUIRK_DPMS_SUSPEND}" = "true" ]; then
-		vbe dpms suspend
-	fi
-}
-
-
-case "$1" in
-	suspend)
-		suspend_video
-		;;
-	hibernate)
-		if [ "$HIBERNATE_RESUME_POST_VIDEO" = "yes" ]; then
-			suspend_video
-		fi
-		;;
-esac
diff --git a/pm/sleep.d/94cpufreq b/pm/sleep.d/94cpufreq
index 12dfc1f..4a4412e 100755
--- a/pm/sleep.d/94cpufreq
+++ b/pm/sleep.d/94cpufreq
@@ -11,7 +11,7 @@ hibernate_cpufreq()
 		[ -f "$x" ] || continue
 		grep -q "$TEMPORARY_CPUFREQ_GOVERNOR" \
 			"${x%/*}/scaling_available_governors" || continue
-		savestate "${x%%/*}_governor" $(cat "$x")
+		cat "$x" |savestate "${x%%/*}_governor"
 		echo "$TEMPORARY_CPUFREQ_GOVERNOR" > "$x"
 	done )
 }
@@ -21,9 +21,8 @@ thaw_cpufreq()
 	( cd /sys/devices/system/cpu/
 	for x in cpu[0-9]*/cpufreq/scaling_governor ; do
 		[ -f "$x" ] || continue
-		local gov="$(restorestate "${x%%/*}_governor")"
-		[ -z "$gov" ] && continue
-		echo "$gov" > "$x"
+		state_exists "${x%%/*}_governor" || continue
+		restorestate "${x%%/*}_governor" > "$x"
 	done )
 }
 
diff --git a/pm/sleep.d/99video b/pm/sleep.d/99video
index 2797a06..b780174 100755
--- a/pm/sleep.d/99video
+++ b/pm/sleep.d/99video
@@ -9,6 +9,9 @@
 
 . "${PM_FUNCTIONS}"
 
+# exit if we were explicitly told to ignore the quirks
+[ "$DISPLAY_QUIRK_NONE" = "true" ] && exit $NA
+
 reset_brightness()
 {
 	for bl in /sys/class/backlight/* ; do
@@ -31,6 +34,9 @@ else
 	radeon() { echo "radeontool not found" 1>&2; return 1; }
 fi
 
+radeon_light() { radeon dac $1; radeon light $1; }
+vbe_post() { vbe post; sleep 0.1; }
+
 save_fbcon()
 {
 	local con
@@ -49,44 +55,60 @@ resume_fbcon()
 	done
 }
 
-resume_video()
+
+vbe_state() 
+{
+	case $1 in
+		save) vbe vbestate save |savestate vbestate ;;
+		restore) restorestate vbestate |vbe vbestate restore ;;
+	esac
+}
+
+vbe_mode() 
+{
+	case $1 in
+		save) vbe vbemode get |savestate vbemode ;;
+		restore) restorestate vbemode | vbe vbemode set ;;
+	esac
+}
+
+
+suspend_video()
 {
-	if [ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ]; then
-		radeon dac on
-		radeon light on
-	fi
+	# 0=nothing, 1=s3_bios, 2=s3_mode, 3=both
+	local acpi_flag=0
+	[ "${DISPLAY_QUIRK_S3_BIOS}" = "true" ] && acpi_flag=$(($acpi_flag + 1))
+	[ "${DISPLAY_QUIRK_S3_MODE}" = "true" ] && acpi_flag=$(($acpi_flag + 2))
+	sysctl -w kernel.acpi_video_flags=$acpi_flag
+
 	# We might need to do one or many of these quirks
-	if [ "${DISPLAY_QUIRK_VBE_POST}" = "true" ]; then
-		vbe post
-		sleep 0.1
-	fi
-	if [ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ]; then
-		vbe vbestate restore < /var/run/vbestate
-	fi
-	if [ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ]; then
-		vbe vbemode set "$(cat /var/run/vbemode)"
-	fi
-	# based on data from s2ram
+	[ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ] && radeon_light off
+	[ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ] && vbe_state save
+	[ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ] && vbe_mode save
+	[ "${DISPLAY_QUIRK_VGA_MODE_3}" = "true" ] && vbe vbemode set 3
+	[ "${DISPLAY_QUIRK_DPMS_SUSPEND}" = "true" ] && vbe dpms suspend
+	suspend_fbcon
+}
+
+resume_video()
+{
+	[ "${DISPLAY_QUIRK_VBE_POST}" = "true" ] && vbe_post
 	resume_fbcon
-	if [ "${DISPLAY_QUIRK_DPMS_ON}" = "true" ]; then
-		vbe dpms on
-	fi
-	if [ "${DISPLAY_QUIRK_RESET_BRIGHTNESS}" = "true" ]; then
-		reset_brightness
-	fi
+	[ "${DISPLAY_QUIRK_VBESTATE_RESTORE}" = "true" ] && vbe_state restore
+	[ "${DISPLAY_QUIRK_VBEMODE_RESTORE}" = "true" ] && vbe_mode restore
+	[ "${DISPLAY_QUIRK_DPMS_ON}" = "true" ] && vbe dpms on
+	[ "${DISPLAY_QUIRK_RADEON_OFF}" = "true" ] && radeon_light on
+	[ "${DISPLAY_QUIRK_RESET_BRIGHTNESS}" = "true" ] && reset_brightness
 }
 
 
 case "$1" in
-	suspend)
-		save_fbcon
+	suspend) suspend_video ;;
+	resume) resume_video ;;
+	hibernate)
+		[ "${HIBERNATE_RESUME_POST_VIDEO}" = "yes" ] && suspend_video
 		;;
-	resume)
-		resume_video
-		;;
-	thaw)
-		if [ "${HIBERNATE_RESUME_POST_VIDEO}" = "yes" ]; then
-			resume_video
-		fi
+
+	thaw)	[ "${HIBERNATE_RESUME_POST_VIDEO}" = "yes" ] && resume_video
 		;;
 esac
diff --git a/src/pm-action.in b/src/pm-action.in
index e48b9c2..ed537ca 100644
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -44,6 +44,7 @@ help_options()
 	echo "  --quirk-vbemode-restore"
 	echo "  --quirk-vbestate-restore"
 	echo "  --quirk-vga-mode3"
+	echo "  --quirk-none"
 	echo
 }
 
@@ -76,6 +77,8 @@ do
 			export DISPLAY_QUIRK_VBESTATE_RESTORE="true" ;;
 		--quirk-vga-mode3)
 			export DISPLAY_QUIRK_VGA_MODE_3="true" ;;
+		--quirk-none)
+			export DISPLAY_QUIRK_NONE="true" ;;
 		--help)
 			help_options
 			exit 0 ;;
-- 
Victor Lowther
Ubuntu Certified Professional


More information about the Pm-utils mailing list