--- pci-parm.orig 2008-10-08 17:51:39.000000000 +0100 +++ pci-parm 2008-10-08 19:00:35.000000000 +0100 @@ -1,4 +1,6 @@ #!/sbin/runscript +# (C) 2008 Gentoo Foundation +# Distributed under the terms of the GPLv2 # read this article to know what to do # http://gentoo.org/doc/en/articles/hardware-stability-p2.xml#doc_chap3_pre2 @@ -22,54 +24,61 @@ do_setpci() { #ewarn "do_setpci: /usr/sbin/setpci $SETPCI_OPT $@" - SWITCH=$1 - if [ "$SWITCH" = "-d" ]; then - DESC="(vendor)" - else - DESC="(bus)" - fi - shift + x= + case $1 in + -d) DESC=vendor +;; -s) DESC=bus +;; -x) x=1; shift; false +;; *) DESC=bus; SWITCH=-s +# [ "$VERBOSE" = yes ] && ewarn "do_setpci $*" + false +;; esac && { SWITCH=$1; shift; } SPEC_ID=$1 shift - ebegin "Setting PCI params for $DESC $SPEC_ID to $@" - /usr/sbin/setpci $SETPCI_OPT $SWITCH $SPEC_ID $@ - eend $? - SWITCH="" - SPEC_ID="" + [ -n "$SWITCH" -a -n "$SPEC_ID" -a -n "$1" ] || { + eerror "Bad call to: do_setpci $SWITCH $SPEC_ID $1" + return 1 + } + ebegin "Setting PCI params for ($DESC) $SPEC_ID to $@" + /usr/sbin/setpci $SETPCI_OPT "$SWITCH" "$SPEC_ID" "$@" + r=$? + [ -n "$x" ] && unset -v SPEC_ID || unset -v SWITCH SPEC_ID + eend "$r" + return "$r" +} + +dopci_array() { + case $1 in + -d) DESC=vendor +;; -s) DESC=bus +;; *) eerror "Unknown type to: dopci_array $*";return 1 +;; esac + SWITCH=$1; shift + i=0 + while true; do + eval opt="\$${1}_$i" + [ -n "$opt" ] || break + do_setpci -x $opt || return 1 + i=$(($i+1)) + done + unset -v opt i SWITCH } start() { - if get_bootparam "nopciparm" ; then + if get_bootparam nopciparm; then ewarn "Skipping pciparm init as requested in kernel cmdline" return 0 fi checkconfig || return 1 - SETPCI_OPT="" - if [ "$VERBOSE" = "yes" ]; then - SETPCI_OPT="$SETPCI_OPT -v" + if [ "$VERBOSE" = yes ]; then + SETPCI_OPT=' -v' + else SETPCI_OPT= fi if [ -n "$PCIPARM_ALL" ]; then do_setpci -d '*:*' $PCIPARM_ALL fi - SEQ_BUS=0 - while true; do - BUS_OPT=`eval echo '$'PCIPARM_BUS_${SEQ_BUS}` - if [ -z "$BUS_OPT" ]; then - break - fi - do_setpci -s $BUS_OPT - SEQ_BUS=$(($SEQ_BUS+1)) - done - SEQ_VENDOR=0 - while true; do - VENDOR_OPT=`eval echo '$'PCIPARM_VENDOR_${SEQ_VENDOR}` - if [ -z "$VENDOR_OPT" ]; then - break - fi - do_setpci -d $VENDOR_OPT - SEQ_VENDOR=$(($SEQ_VENDOR+1)) - done + dopci_array -s PCIPARM_BUS && dopci_array -d PCIPARM_VENDOR }