ACC SHELL
#!/bin/sh
# disable processing of 90chvt and 99video.
# s2ram and s2disk handle all this stuff internally.
uswsusp_hooks()
{
disablehook 99video "disabled by uswsusp"
disablehook 90chvt "disabled by uswsusp"
}
# Since we disabled 99video, we need to take responsibility for proper
# quirk handling. s2ram handles all common video quirks internally,
# so all we have to do is translate the HAL standard options to s2ram options.
uswsusp_get_quirks()
{
OPTS=""
ACPI_SLEEP=0
for opt in $PM_CMDLINE; do
case "${opt##--quirk-}" in # just quirks, please
dpms-on) ;; # no-op
dpms-suspend) ;; # no-op
radeon-off) OPTS="$OPTS --radeontool" ;;
reset-brightness) ;; # no-op
s3-bios) ACPI_SLEEP=$(($ACPI_SLEEP + 1)) ;;
s3-mode) ACPI_SLEEP=$(($ACPI_SLEEP + 2)) ;;
vbe-post) OPTS="$OPTS --vbe_post" ;;
vbemode-restore) OPTS="$OPTS --vbe_mode" ;;
vbestate-restore) OPTS="$OPTS --vbe_save" ;;
vga-mode-3) ;; # no-op
save-pci) OPTS="$OPTS --pci_save" ;;
none) QUIRK_NONE="true" ;;
*) continue ;;
esac
done
[ $ACPI_SLEEP -ne 0 ] && OPTS="$OPTS --acpi_sleep $ACPI_SLEEP"
# if we were told to ignore quirks, do so.
# This is arguably not the best way to do things, but...
[ "$QUIRK_NONE" = "true" ] && OPTS=""
S2RAM_OPTS="$S2RAM_OPTS $OPTS"
echo "INFO: S2RAM_OPTS from HAL quirks: '$S2RAM_OPTS'."
}
# this function tries to assemble the best s2ram options from various sources, falling back
# to other methods...
get_s2ram_opts()
{
# if S2RAM_OPTS is set - then use it. The user told us so. Obey his wish.
if [ -n "$S2RAM_OPTS" ]; then
echo "INFO: using user-supplied options: S2RAM_OPTS='$S2RAM_OPTS' for suspending."
return
fi
# ... try to use s2ram as a source
if [ "$S2RAM_QUIRKS_SOURCE" = "s2ram" ]; then
if /usr/sbin/s2ram -n >/dev/null; then
echo "INFO: using s2ram built-in database, machine is supported."
return
else
echo "WARN: S2RAM_QUIRKS_SOURCE=s2ram, but machine is unknown, continuing..."
fi
fi
# ... if is not known or not set as a source, use the built-in database
echo "INFO: using built-in quirks database from HAL."
uswsusp_get_quirks
if [ -n "$S2RAM_OPTS" ]; then
S2RAM_OPTS="--force "$S2RAM_OPTS
fi
# ... in a case we still don't have any quirk, try s2ram for sure
if [ -z "$S2RAM_OPTS" ]; then
# ... machine could be in s2ram whitelist
if /usr/sbin/s2ram -n >/dev/null; then
echo "INFO: machine is in s2ram database, using it."
return;
else
# if we came here and S2RAM_OPTS is empty, suspend won't work :-(
echo "WARNING: smart uswsusp did not found any appropriate option, suspend probably don't work"
fi
fi
}
# Since we disabled 99video, we also need to handle displaying
# help info for the quirks we handle.
uswsusp_help()
{
echo # first echo makes it look nicer.
echo "s2ram video quirk handler options:"
echo
echo " --quirk-radeon-off"
echo " --quirk-s3-bios"
echo " --quirk-s3-mode"
echo " --quirk-vbe-post"
echo " --quirk-vbemode-restore"
echo " --quirk-vbestate-restore"
echo " --quirk-save-pci"
echo " --quirk-none"
}
# This idiom is used for all sleep methods. Only declare the actual
# do_ method if:
# 1: some other sleep module has not already done so, and
# 2: this sleep method can actually work on this system.
#
# For suspend, if SUSPEND_MODULE is set then something else has already
# implemented do_suspend. We could just check to see of do_suspend was
# already declared using command_exists, but using a dedicated environment
# variable makes it easier to debug when we have to know what sleep module
# ended up claiming ownership of a given sleep method.
if [ -z "$SUSPEND_MODULE" ] && command_exists s2ram && \
( grep -q mem /sys/power/state || \
( [ -c /dev/pmu ] && pm-pmu --check; ); ); then
SUSPEND_MODULE="uswsusp"
do_suspend()
{
get_s2ram_opts
s2ram $S2RAM_OPTS
}
if [ "$METHOD" = "suspend" ]; then
add_before_hooks uswsusp_hooks
add_module_help uswsusp_help
fi
fi
if [ -z "$HIBERNATE_MODULE" ] && \
[ -f /sys/power/disk ] && \
grep -q disk /sys/power/state && \
[ -c /dev/snapshot ] &&
command_exists s2disk; then
HIBERNATE_MODULE="uswsusp"
do_hibernate()
{
# bnc#304995 workaround
export SUSE_IGNORE_FBMODES="true"
get_s2ram_opts
if [ -z "${S2DISK_CONF}" ]; then
s2disk
else
s2disk --config $S2DISK_CONF
fi
}
fi
if [ -z "$SUSPEND_HYBRID_MODULE" ] &&
grep -q mem /sys/power/state && \
command_exists s2both && \
check_hibernate; then
SUSPEND_HYBRID_MODULE="uswsusp"
do_suspend_hybrid()
{
# bnc#304995 workaround
export SUSE_IGNORE_FBMODES="true"
get_s2ram_opts
if [ -z "${S2DISK_CONF}" ]; then
s2both --force $S2RAM_OPTS
else
s2both --config $S2DISK_CONF $S2RAM_OPTS
fi
}
if [ "$METHOD" = "suspend_hybrid" ]; then
add_before_hooks uswsusp_hooks
add_module_help uswsusp_help
fi
fi
ACC SHELL 2018