summaryrefslogtreecommitdiff
blob: 2388f0d951ea80769ac7d4c44a5caeb4794f960f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/sbin/openrc-run
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

depend() {
	before bootmisc hdparm
	after localmount
}

checkconfig() {
	if [ ! -f /etc/conf.d/pciparm ]; then
		ewarn "/etc/conf.d/pciparm does not exist, skipping"
		return 1
	fi

	if [ -z "${PCIPARM_ALL}" -a -z "${PCIPARM_BUS_0}" -a  -z "${PCIPARM_VENDOR_0}" ]; then
		ewarn "None of PCIPARM_ALL, PCIPARM_BUS_* or PCIPARM_VENDOR_* set in /etc/conf.d/pciparm"
		return 1
	fi
}

do_setpci() {
	#ewarn "do_setpci: /usr/sbin/setpci $SETPCI_OPT $@"
	SWITCH=$1
	SPEC_ID=$2
	shift 2
	case "$SWITCH" in
		-d) DESC=vendor ;;
		-s) DESC=bus ;;
		*) eerror "Unknown setpci type: $SWITCH" ; return 1 ;;
	esac

	if [ -z "$SPEC_ID" ]; then
		eerror "Missing device specifier!"
		return 1
	fi
	if [ -z "$*" ]; then
		eerror "Missing configuration to set for ($DESC) $SPEC_ID!"
		return 1
	fi

	ebegin "Setting PCI params for ($DESC) $SPEC_ID to $@"
	/usr/sbin/setpci $SETPCI_OPT $SWITCH $SPEC_ID "$@"
	rc=$?
	eend $rc
	return $rc
}

do_setpci_array() {
	name=$1
	shift
	i=0
	while true; do
		eval opt="\$${name}_$i"
		# End of loop
		[ -z "${opt}" ] && break
		# Pass in all other parameters here, in case we want to use multiple
		# arguments later.
		do_setpci "$@" $opt #|| return 1
		i=$(($i+1))
	done
}

start() {
	if get_bootparam "nopciparm" ; then
		ewarn "Skipping pciparm init as requested in kernel cmdline"
		return 0
	fi

	checkconfig || return 1
	
	# We do not exit after any errors presently, because it might be a
	# stability-related fix after a failure.
	[ -n "$PCIPARM_ALL" ] && \
		do_setpci -d '*:*' $PCIPARM_ALL #|| return 1

	do_setpci_array PCIPARM_BUS -s #|| return 1
	do_setpci_array PCIPARM_VENDOR -d #|| return 1
}