Video adapter resuming

Peter Jones pjones at redhat.com
Thu Nov 30 11:02:07 PST 2006


On Tue, 2006-11-28 at 18:55 +0000, Richard Hughes wrote:
> You can use --disable-video for hal-info if you don't want to ship the
> video data. Now, we need to do the glue for pm-utils. I'm thinking the
> obvious is best:
>
> pm-suspend --vbemode --vbesave --dpmsoff --s3mode etc

So how's this look?

#!/bin/bash

. /etc/pm/functions

pv_vbe_mode=no
pv_vbe_save=no
pv_vbe_post=no
pv_radeon_off=no
pv_dpms_suspend=no
pv_dpms_off=no
pv_dpms_on=no
pv_s3_bios=no
pv_s3_mode=no

for arg in $PM_CMDLINE ; do
    case "$arg" in
        --vbemode*)
            x=${arg##--vbemode=}
            [ -z "$x" -o "$x" == "yes" ] && pv_vbe_mode=yes
            ;;
        --vbesave*)
            x=${arg##--vbesave=}
            [ -z "$x" -o "$x" == "yes" ] && pv_vbe_save=yes
            ;;
        --vbepost*)
            x=${arg##--vbepost=}
            [ -z "$x" -o "$x" == "yes" ] && pv_vbe_post=yes
            ;;

        --radeonoff*)
            x=${arg##--radeonoff=}
            [ -z "$x" -o "$x" == "yes" ] && pv_radeon_off=yes
            ;;

        --dpmssuspend*)
            x=${arg##--dpmssuspend=}
            [ -z "$x" -o "$x" == "yes" ] && pv_dpms_suspend=yes
            ;;
        --dpmsoff*)
            x=${arg##--dpmsoff=}
            [ -z "$x" -o "$x" == "yes" ] && pv_dpms_off=yes
            ;;
        --dpmson*)
            x=${arg##--dpmson=}
            [ -z "$x" -o "$x" == "yes" ] && pv_dpms_on=yes
            ;;

        --s3bios*)
            x=${arg##--s3bios=}
            [ -z "$x" -o "$x" == "yes" ] && pv_s3_bios=yes
            ;;
        --s3mode*)
            x=${arg##--s3mode=}
            [ -z "$x" -o "$x" == "yes" ] && pv_s3_mode=yes
            ;;
    esac
done

vbestub() { return 1; }
vbetool=$(type -p vbetool)
[ -z "$vbetool" ] && vbetool=vbestub

radeonstub() { return 1; }
$radeontool=$(type -p radeontool)
[ -z "$radeontool" ] && radeontool=vbestub

suspend_video()
{
    s3_flags=$(sysctl kernel.acpi_video_flags 2>/dev/null | awk '{ print $3 }')
    savestate s3_flags $s3_flags
    s3_flags=0
    if [ "$pv_s3_bios" == "yes" ]; then
        s3_flags=$(($s3_flags | 1))
    fi
    if [ "$pv_s3_mode" == "yes" ]; then
        s3_flags=$(($s3_flags  | 2))
    fi
    sysctl -w kernel.acpi_video_flags=$s3_flags >/dev/null 2>&1

    if [ "$pv_vbe_save" == "yes" ]; then
        rm -f /var/run/pm-vbestate 2>/dev/null
        $vbetool vbestate save > /var/run/pm-vbestate
    fi
    if [ "$pv_vbe_mode" == "yes" ]; then
        vbemode=$($vbetool vbemode get)
        savestate vbemode $vbemode
    fi
    if [ "$pv_dpms_suspend" == "yes" ]; then
        $vbetool dpms suspend
    fi
    if [ "$pv_dpms_off" == "yes" ]; then
        $vbetool dpms off
    fi
    if [ "$pv_radeon_off" == "yes" ]; then
        $radeontool dac off >/dev/null 2>&1
        $radeontool light off >/dev/null 2>&1
    fi
}

resume_video()
{
    if [ "$pv_radeon_off" == "yes" ]; then
        $radeontool dac on >/dev/null 2>&1
        $radeontool light on >/dev/null 2>&1
    fi
    if [ "$pv_vbe_post" == "yes" ]; then
        $vbetool post < /dev/tty1
    fi
    if [ "$pv_vbe_save" == "yes" ]; then
        $vbetool vbestate restore < /var/run/pm-vbestate
        rm -f /var/run/pm-vbestate 2>/dev/null
    fi
    if [ "$pv_vbe_mode" == "yes" ]; then
        vbemode=$(restorestate vbemode)
        [ -n "$vbemode" ] && $vbetool vbemode set $vbemode
    fi
    if [ "$pv_dpms_off" == "yes" ]; then
        $vbetool dpms on
    fi

    sysctl -w kernel.acpi_video_flags=$(restorestate s3_flags) >/dev/null 2>&1
}

case "$1" in
    suspend)
        suspend_video
        ;;
    resume)
        resume_video
        ;;
    hibernate)
        if [ "x$HIBERNATE_RESUME_POST_VIDEO" == "xyes" ]; then
            suspend_video
        fi
        ;;
    thaw)
        if [ "x$HIBERNATE_RESUME_POST_VIDEO" == "xyes" ]; then
            resume_video
        fi
        ;;
    *)
        ;;
esac

exit $?

# vim:ts=8:sts=4:sw=4:et

-- 
  Peter



More information about the hal mailing list