|
|
#!/sbin/runscript | #!/sbin/runscript |
|
# (C) 2008 Gentoo Foundation |
|
# Distributed under the terms of the GPLv2 |
# read this article to know what to do | # read this article to know what to do |
# http://gentoo.org/doc/en/articles/hardware-stability-p2.xml#doc_chap3_pre2 | # http://gentoo.org/doc/en/articles/hardware-stability-p2.xml#doc_chap3_pre2 |
| |
|
|
| |
do_setpci() { | do_setpci() { |
#ewarn "do_setpci: /usr/sbin/setpci $SETPCI_OPT $@" | #ewarn "do_setpci: /usr/sbin/setpci $SETPCI_OPT $@" |
SWITCH=$1 |
x= |
if [ "$SWITCH" = "-d" ]; then |
case $1 in |
DESC="(vendor)" |
-d) DESC=vendor |
else |
;; -s) DESC=bus |
DESC="(bus)" |
;; -x) x=1; shift; false |
fi |
;; *) DESC=bus; SWITCH=-s |
shift |
# [ "$VERBOSE" = yes ] && ewarn "do_setpci $*" |
|
false |
|
;; esac && { SWITCH=$1; shift; } |
SPEC_ID=$1 | SPEC_ID=$1 |
shift | shift |
ebegin "Setting PCI params for $DESC $SPEC_ID to $@" |
[ -n "$SWITCH" -a -n "$SPEC_ID" -a -n "$1" ] || { |
/usr/sbin/setpci $SETPCI_OPT $SWITCH $SPEC_ID $@ |
eerror "Bad call to: do_setpci $SWITCH $SPEC_ID $1" |
eend $? |
return 1 |
SWITCH="" |
} |
SPEC_ID="" |
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() { | start() { |
if get_bootparam "nopciparm" ; then |
if get_bootparam nopciparm; then |
ewarn "Skipping pciparm init as requested in kernel cmdline" | ewarn "Skipping pciparm init as requested in kernel cmdline" |
return 0 | return 0 |
fi | fi |
| |
checkconfig || return 1 | checkconfig || return 1 |
| |
SETPCI_OPT="" |
if [ "$VERBOSE" = yes ]; then |
if [ "$VERBOSE" = "yes" ]; then |
SETPCI_OPT=' -v' |
SETPCI_OPT="$SETPCI_OPT -v" |
else SETPCI_OPT= |
fi | fi |
| |
if [ -n "$PCIPARM_ALL" ]; then | if [ -n "$PCIPARM_ALL" ]; then |
do_setpci -d '*:*' $PCIPARM_ALL | do_setpci -d '*:*' $PCIPARM_ALL |
fi | fi |
SEQ_BUS=0 |
dopci_array -s PCIPARM_BUS && dopci_array -d PCIPARM_VENDOR |
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 |
|
} | } |