|
Added
Link Here
|
| 1 |
#!/bin/bash |
| 2 |
# $Id: pci.agent,v 1.10 2004/04/03 15:46:50 zoz Exp $ |
| 3 |
# |
| 4 |
# PCI and CardBus hotplug policy agent. |
| 5 |
# |
| 6 |
# Kernel Cardbus/PCI params are: |
| 7 |
# |
| 8 |
# ACTION=%s [add or remove] |
| 9 |
# DEVPATH=%s [device path in sysfs] |
| 10 |
# PCI_CLASS=%04X |
| 11 |
# PCI_ID=%04X:%04X |
| 12 |
# PCI_SLOT_NAME=%s |
| 13 |
# PCI_SUBSYS_ID=%04X:%04X |
| 14 |
# |
| 15 |
# If /proc is mounted, /proc/bus/pci/$PCI_SLOT_NAME is almost the name |
| 16 |
# of the binary device descriptor file ... just change ':' to '/'. |
| 17 |
|
| 18 |
: ${ACTION?Bad invocation: \$ACTION is not set} |
| 19 |
: ${DEVPATH?Bad invocation: \$DEVPATH is not set} |
| 20 |
: ${PCI_CLASS?Bad invocation: \$PCI_CLASS is not set} |
| 21 |
: ${PCI_ID?Bad invocation: \$PCI_ID is not set} |
| 22 |
: ${PCI_SLOT_NAME?Bad invocation: \$PCI_SLOT_NAME is not set} |
| 23 |
: ${PCI_SUBSYS_ID?Bad invocation: \$PCI_SUBSYS_ID is not set} |
| 24 |
|
| 25 |
cd /etc/hotplug |
| 26 |
. ./hotplug.functions |
| 27 |
|
| 28 |
# ALSA config |
| 29 |
if [ -r /etc/sysconfig/sound ]; then |
| 30 |
. /etc/sysconfig/sound |
| 31 |
fi |
| 32 |
|
| 33 |
# generated by modutils, for kernels 2.4.x and newer |
| 34 |
MAP_CURRENT=$MODULE_DIR/modules.pcimap |
| 35 |
|
| 36 |
# |
| 37 |
# Each modules.pcimap format line corresponds to one entry in a |
| 38 |
# MODULE_DEVICE_TABLE(pci,...) declaration in a kernel file. |
| 39 |
# |
| 40 |
# Think of it as a database column with up to three "match specs" |
| 41 |
# to associate kernel modules with particular devices or classes |
| 42 |
# of device. The match specs provide a reasonably good filtering |
| 43 |
# mechanism, but some driver probe() routines need to provide |
| 44 |
# extra filtering. |
| 45 |
# |
| 46 |
|
| 47 |
# inputs to the match algorithm, from kernel by way of /sbin/hotplug |
| 48 |
declare -i pci_class |
| 49 |
declare -i pci_id_vendor pci_id_device |
| 50 |
declare -i pci_subid_vendor pci_subid_device |
| 51 |
|
| 52 |
pci_convert_vars () |
| 53 |
{ |
| 54 |
pci_class=0x$PCI_CLASS |
| 55 |
|
| 56 |
set -- `IFS=:; echo $PCI_ID` |
| 57 |
pci_id_vendor=0x$1 |
| 58 |
pci_id_device=0x$2 |
| 59 |
|
| 60 |
set -- `IFS=:; echo $PCI_SUBSYS_ID` |
| 61 |
pci_subid_vendor=0x$1 |
| 62 |
pci_subid_device=0x$2 |
| 63 |
|
| 64 |
pci_revision=`lspci -ns ${DEVPATH##*/} 2>/dev/null | sed "s/^.*(rev *\([0-9]*\).*$/\1/"` |
| 65 |
} |
| 66 |
|
| 67 |
declare -i PCI_ANY=0xffffffff |
| 68 |
|
| 69 |
# stdin is "modules.pcimap" syntax |
| 70 |
# on return, ONE matching module was added to $DRIVERS |
| 71 |
# |
| 72 |
sound_map_modules () |
| 73 |
{ |
| 74 |
# convert the usb_device_id fields to integers as we read them |
| 75 |
local line module ignored |
| 76 |
declare -i vendor device |
| 77 |
declare -i subvendor subdevice |
| 78 |
declare -i class class_mask |
| 79 |
declare -i class_temp |
| 80 |
|
| 81 |
# look at each pci_device_id entry |
| 82 |
# collect one match in $DRIVERS |
| 83 |
while read line |
| 84 |
do |
| 85 |
# comments are lines that start with "#" ... |
| 86 |
# be careful, they still get parsed by bash! |
| 87 |
case "$line" in |
| 88 |
\#*|"") continue ;; |
| 89 |
esac |
| 90 |
|
| 91 |
set -- $line |
| 92 |
module=$1 |
| 93 |
vendor=$(($2)) |
| 94 |
device=$(($3)) |
| 95 |
subvendor=$(($4)) |
| 96 |
subdevice=$(($5)) |
| 97 |
class=$(($6)) |
| 98 |
class_mask=$(($7)) |
| 99 |
|
| 100 |
: checkmatch $module |
| 101 |
case $module in |
| 102 |
snd-*|snd_*) ;; |
| 103 |
*) continue ;; |
| 104 |
esac |
| 105 |
|
| 106 |
: vendor $vendor $pci_id_vendor |
| 107 |
if [ $vendor -ne $PCI_ANY -a $vendor -ne $pci_id_vendor ]; then |
| 108 |
continue |
| 109 |
fi |
| 110 |
: device $device $pci_id_device |
| 111 |
if [ $device -ne $PCI_ANY -a $device -ne $pci_id_device ]; then |
| 112 |
continue |
| 113 |
fi |
| 114 |
: sub-vendor $subvendor $pci_subid_vendor |
| 115 |
if [ $subvendor -ne $PCI_ANY -a $subvendor -ne $pci_subid_vendor ]; then |
| 116 |
continue |
| 117 |
fi |
| 118 |
: sub-device $subdevice $pci_subid_device |
| 119 |
if [ $subdevice -ne $PCI_ANY -a $subdevice -ne $pci_subid_device ]; then |
| 120 |
continue |
| 121 |
fi |
| 122 |
|
| 123 |
class_temp="$pci_class & $class_mask" |
| 124 |
if [ $class_temp -eq $class ]; then |
| 125 |
DRIVERS="$module $DRIVERS" |
| 126 |
: drivers $DRIVERS |
| 127 |
break |
| 128 |
fi |
| 129 |
done |
| 130 |
} |
| 131 |
|
| 132 |
# |
| 133 |
# check the card indices |
| 134 |
# |
| 135 |
check_alsa_cards () |
| 136 |
{ |
| 137 |
NCARD="" |
| 138 |
if [ -f /proc/asound/cards ]; then |
| 139 |
while read line; do |
| 140 |
case "$line" in |
| 141 |
[0-9]*) ;; |
| 142 |
*) continue ;; |
| 143 |
esac |
| 144 |
|
| 145 |
set -- $line |
| 146 |
card=$1 |
| 147 |
NCARD="$NCARD${card:+ $card}" |
| 148 |
done < /proc/asound/cards |
| 149 |
fi |
| 150 |
} |
| 151 |
|
| 152 |
# |
| 153 |
# insert sequencer modules |
| 154 |
# |
| 155 |
load_sequencer() |
| 156 |
{ |
| 157 |
if [ "$LOAD_SEQUENCER" = "yes" -a -r /proc/asound/seq/drivers ]; then |
| 158 |
cut -d , -f 1 /proc/asound/seq/drivers | \ |
| 159 |
while read t ; do |
| 160 |
/sbin/modprobe $t >/dev/null 2>&1 |
| 161 |
done |
| 162 |
fi |
| 163 |
} |
| 164 |
|
| 165 |
# |
| 166 |
# run card-dependent scripts |
| 167 |
# |
| 168 |
load_carddeps() |
| 169 |
{ |
| 170 |
for i in $*; do |
| 171 |
i=${i##snd-} |
| 172 |
i=${i##snd_} |
| 173 |
if [ -x $alsascrdir/$i ]; then |
| 174 |
$alsascrdir/$i |
| 175 |
fi |
| 176 |
done |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
# |
| 181 |
# What to do with this PCI hotplug event? |
| 182 |
# |
| 183 |
case $ACTION in |
| 184 |
|
| 185 |
add) |
| 186 |
|
| 187 |
pci_convert_vars |
| 188 |
LABEL="PCI slot $PCI_SLOT_NAME" |
| 189 |
|
| 190 |
check_alsa_cards |
| 191 |
OLD_NCARD="$NCARD" |
| 192 |
|
| 193 |
# since kernel 2.4 modutils maintains MAP_CURRENT |
| 194 |
sound_map_modules < $MAP_CURRENT |
| 195 |
|
| 196 |
[ -e /usr/sbin/hwscanqueue ] && hwscanqueue --pci |
| 197 |
|
| 198 |
if [ "$DRIVERS" = "" ]; then |
| 199 |
# mesg "... no modules for $LABEL" |
| 200 |
exit 2 |
| 201 |
fi |
| 202 |
|
| 203 |
$MODPROBE $DRIVERS |
| 204 |
|
| 205 |
if [ "$LOAD_OSS_EMUL_MODULES" = "yes" ]; then |
| 206 |
$MODPROBE snd-pcm-oss |
| 207 |
if [ "$LOAD_SEQUENCER" = "yes" ]; then |
| 208 |
$MODPROBE snd-seq-oss |
| 209 |
fi |
| 210 |
fi |
| 211 |
|
| 212 |
load_sequencer |
| 213 |
|
| 214 |
# unmute volumes which are not initialized yet |
| 215 |
check_alsa_cards |
| 216 |
for i in $NCARD; do |
| 217 |
for j in $OLD_NCARD; do |
| 218 |
if [ "$i" = "$j" ]; then |
| 219 |
continue 2 |
| 220 |
fi |
| 221 |
done |
| 222 |
/usr/bin/set_default_volume -f $i |
| 223 |
done |
| 224 |
|
| 225 |
load_carddeps $DRIVERS |
| 226 |
|
| 227 |
;; |
| 228 |
|
| 229 |
remove) |
| 230 |
|
| 231 |
;; |
| 232 |
*) |
| 233 |
debug_mesg PCI $ACTION event not supported |
| 234 |
exit 1 |
| 235 |
;; |
| 236 |
|
| 237 |
esac |