From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Date: Tue, 11 Nov 2003 20:23:05 +0000 Subject: Re: pci coldplug Message-Id: List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org On Thu, Nov 06, Olaf Hering wrote: > On Wed, Nov 05, Olaf Hering wrote: >=20 > > Hello, > >=20 > > what is the purpose of pci_boot_events() in pci.rc? I mean, how can that > > ever work in the current cvs? I did it that way and it appears to work > > ok for a 2.4 kernel (probably also for 2.6): Here is another try: modules will be loaded during boot, should work for 2.4 and 2.6 make pcimodules obsolete PCI_CLASS is matched twice PCI_CLASS is passed as 4 digit value from the kernel. some pci variables already have the 0x prefix in sysfs Index: etc/hotplug/pci.agent =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3DRCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/= pci.agent,v retrieving revision 1.13 diff -u -p -r1.13 pci.agent --- etc/hotplug/pci.agent 16 Sep 2003 19:42:17 -0000 1.13 +++ etc/hotplug/pci.agent 10 Nov 2003 12:06:55 -0000 @@ -9,7 +9,7 @@ # Kernel Cardbus/PCI params are: #=09 # ACTION=3D%s [add or remove] -# PCI_CLASS=3D%06X +# PCI_CLASS=3D%04X # PCI_ID=3D%04X:%04X # PCI_SLOT_NAME=3D%s # PCI_SUBSYS_ID=3D%04X:%04X @@ -41,7 +41,7 @@ MAP_CURRENT=3D$MODULE_DIR/modules.pcimap # accumulates list of modules we may care about DRIVERS=20 -if [ "$PCI_CLASS" =3D "" -o "$PCI_CLASS" =3D "" ]; then +if [ "$PCI_CLASS" =3D "" ]; then mesg Bad PCI agent invocation exit 1 fi @@ -69,13 +69,30 @@ pci_convert_vars () exit 1 fi =20 - pci_class=3D0x$PCI_CLASS - - set `echo $PCI_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` '' + case "$PCI_CLASS" in + 0x*) pci_class=3D$PCI_CLASS ;; + *) pci_class=3D0x$PCI_CLASS ;; + esac + + case "$PCI_ID" in + 0x*) + set `echo $PCI_ID | $AWK -F: '{print $1, $2 }'` '' + ;; + *) + set `echo $PCI_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` '' + ;; + esac pci_id_vendor=3D$1 pci_id_device=3D$2 =20 - set `echo $PCI_SUBSYS_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` '' + case "$PCI_SUBSYS_ID" in + 0x*) + set `echo $PCI_SUBSYS_ID | $AWK -F: '{print $1, $2 }'` '' + ;; + *) + set `echo $PCI_SUBSYS_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` '' + ;; + esac pci_subid_vendor=3D$1 pci_subid_device=3D$2 } Index: etc/hotplug/pci.rc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3DRCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/= pci.rc,v retrieving revision 1.7 diff -u -p -r1.7 pci.rc --- etc/hotplug/pci.rc 6 Jun 2003 18:27:23 -0000 1.7 +++ etc/hotplug/pci.rc 10 Nov 2003 12:06:55 -0000 @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # vim: syntax=3Dsh # # pci.rc mostly to recover lost boot-time pci hotplug events @@ -10,61 +10,78 @@ PATH=3D/sbin:/bin:/usr/sbin:/usr/bin =20 cd /etc/hotplug =20 -# source function library -if [ -f /etc/init.d/functions ]; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ]; then - . /etc/rc.d/init.d/functions -fi - -. hotplug.functions - - -# # override any of the defaults? -# if [ -f /etc/sysconfig/pci ]; then -# . /etc/sysconfig/pci -# fi - -pci_boot_events () -{ - # - # FIXME on 2.5, /sys/bus/pci/devices gives some of this - # information, and more can be gotten with 'lspci'. - # don't expect pcimodules to exist!! - # - LISTER=3D`type -p pcimodules` - if [ "$LISTER" =3D "" -o ! -f /proc/bus/pci/devices -o ! -x pci.agent = ]; then - echo $"** can't synthesize pci hotplug events" +pci_boot_events_24 () { +=09 + if [ ! -x /sbin/lspci -o ! -f /proc/bus/pci/devices ]; then + echo $" ** can't synthesize pci hotplug events" return fi + echo + /sbin/lspci -nm | sed 's/"//g' | while read pci_data ; do + set - $pci_data '' + ACTION=ADd + PCI_SLOT=3D$1 + shift 2 + PCI_CLASS=3D$1 + shift + PCI_ID=3D$1:$2 + shift 2 + case "$1" in + -r*) shift;; + esac + case "$1" in + -p*) pci_progif=3D${1#-p} ; shift ;; + *) pci_progif=00 ;; + esac + if [ "$1" =3D "" ] ; then + PCI_SUBSYS_ID=3D0:0 + else + PCI_SUBSYS_ID=3D$1:$2 + fi + echo PCI_CLASS=3D$PCI_CLASS$pci_progif PCI_ID=3D$PCI_ID PCI_SLOT_NAME=3D= $PCI_SLOT PCI_SUBSYS_ID=3D$PCI_SUBSYS_ID + $ENV ACTION=3D$ACTION PCI_CLASS=3D$PCI_CLASS$pci_progif PCI_ID=3D$PCI_ID = PCI_SLOT_NAME=3D$PCI_SLOT PCI_SUBSYS_ID=3D$PCI_SUBSYS_ID /sbin/hotplug pci + done +} =20 - # make sure the pci agent will run - ACTION=ADd - PCI_CLASS=3D0 - PCI_ID=3D0:0 - PCI_SLOT=3D0:0.0 - PCI_SUBSYS_ID=3D0:0 - export ACTION PCI_CLASS PCI_ID PCI_SLOT PCI_SUBSYS_ID - - # these notifications will be handled by pcimodules - for BUS in `cd /proc/bus/pci;find * -type d -print`; do - for SLOT_FUNC in `cd /proc/bus/pci/$BUS; echo *`; do - PCI_SLOT=3D$BUS:$SLOT_FUNC - : hotplug pci for $PCI_SLOT - /sbin/hotplug pci +pci_boot_events_26 () { + cd /sys/bus/pci/devices + echo + for i in * ; do + echo PCI_SLOT_NAME=3D$i PCI_CLASS=3D$(< $i/class) PCI_ID=3D"$(< $i/vendor= ):$(< $i/device)" PCI_SUBSYS_ID=3D"$(< $i/subsystem_vendor):$(< $i/subsyste= m_device)" + $ENV ACTION=ADd PCI_CLASS=3D$(< $i/class) PCI_ID=3D"$(< $i/vendor):$(< $i= /device)" PCI_SLOT_NAME=3D$i PCI_SUBSYS_ID=3D"$(< $i/subsystem_vendor):$(< = $i/subsystem_device)" /sbin/hotplug pci done - done +} + +pci_boot_events () +{ + local ENV + if [ ! -x pci.agent ]; then + echo $" ** can't synthesize pci hotplug events" + return + fi + if [ -x /usr/bin/env ] ; then + ENV=3D'env -i - ' + else + ENV+ fi + if [ -d /sys/bus/pci/devices ] ; then + pci_boot_events_26 + else + pci_boot_events_24 + fi } =20 # See how we were called. case "$1" in start) - pci_boot_events + pci_boot_events ; : ;; stop) # echo $"pci stop -- ignored" ;; status) + ;; + status-verbose) echo $"PCI Status for kernel: " `uname -srm` echo '' =20 @@ -93,4 +110,5 @@ case "$1" in *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 + ;; esac --=20 USB is for mice, FireWire is for men! sUse lINUX ag, n=C3=9CRNBERG ------------------------------------------------------- This SF.Net email sponsored by: ApacheCon 2003, 16-19 November in Las Vegas. Learn firsthand the latest developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! http://www.apachecon.com/ _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel