Submitted By: Alexander E. Patrakov Date: 2004-05-15 Initial Package Version: 2004_04_01 Origin: Marco d'Itri, Simone Gotti Upstream Status: posted to linux-hotplug-devel list, no useful response yet Description: Includes two versions of ISAPNP hardware detection script. The one by Simone Gotti (isapnp.{rc,agent}) gives more precise results for hardware properly supported in kernel, while the version by Marco d'Itri (pnp.rc) is much simpler and contains workarounds for some modules, including floppy, PC speaker and PS/2 mouse. The version by Marco d'Itri needs the following entries in /etc/modprobe.conf, due to a kernel bug: alias pnp:dPNP0510 irtty-sir alias pnp:dPNP0511 irtty-sir alias pnp:dPNP0700 floppy alias pnp:dPNP0800 pcspkr alias pnp:dPNP0B00 rtc alias pnp:dPNP0303 atkbd alias pnp:dPNP0F13 psmouse alias pnp:dPNPB02F analog The script by Simone Gotti requires a 2.6.6 kernel. 2.6.4 is too old. diff -urN hotplug-2004_04_01.orig/etc/hotplug/isapnp.agent hotplug-2004_04_01/etc/hotplug/isapnp.agent --- hotplug-2004_04_01.orig/etc/hotplug/isapnp.agent 1970-01-01 05:00:00.000000000 +0500 +++ hotplug-2004_04_01/etc/hotplug/isapnp.agent 2004-05-16 12:22:20.000000000 +0600 @@ -0,0 +1,103 @@ +#!/bin/sh +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# ISAPNP-specific hotplug policy agent. +# +# This should handle 2.4.* and 2.6.* ISAPNP (for now only coldplugging), +# +# Kernel ISAPNP params are: +# +# ACTION=%s [add or remove] +# ISAPNP_ID=%08X +# +# Copyright (C) 2004 Simone Gotti, All Rights Reserved. +# +# HISTORY: +# +# 2004/04/08 Simone Gotti first version +# 2004/04/11 Simone Gotti make the modules.isapnp parsing more fast +# we don't need the isapnpmodules C program anymore. +# + +cd /etc/hotplug +. ./hotplug.functions + +# generated by modutils, for current 2.4.x kernels +MAP_CURRENT=$MODULE_DIR/modules.isapnpmap + +# accumulates list of modules we may care about +DRIVERS= + +if [ "$ISAPNP_ID" = "" ]; then + mesg Bad ISAPNP agent invocation + exit 1 +fi + +# +# stdin is "modules.isapnpmap" syntax +# on return, ONE matching module was added to $DRIVERS +# +isapnp_map_modules () +{ + local module ignored + + # comment line lists (current) isapnp_device_id field names + read ignored + + while read module cardvendor carddevice driver_data therest + do + # comments are lines that start with "#" ... + # be careful, they still get parsed by bash! + case "$module" in + \#*) continue ;; + esac + + : checkmatch $module + + set $therest + while [ $# -gt 0 ] + do + id_temp=$2$1 + if [ $id_temp == $CHECKED_ID ]; then + DRIVERS="$module $DRIVERS" + : drivers $DRIVERS + break + fi + shift + shift + done + done +} + +# +# What to do with this ISAPNP hotplug event? +# +case $ACTION in + +add) + + LABEL="ISAPNP id $ISAPNP_ID" + CHECKED_ID="0x`echo $ISAPNP_ID | cut -b1-4`0x`echo $ISAPNP_ID | cut -b5-8`" + + # on 2.4 systems, modutils maintains MAP_CURRENT + if [ -r $MAP_CURRENT ]; then + load_drivers isapnp $MAP_CURRENT "$LABEL" + fi + + if [ "$DRIVERS" = "" ]; then + debug_mesg "... no modules for $LABEL" + exit 2 + fi + ;; + +*) + debug_mesg ISAPNP $ACTION event not supported + exit 1 + ;; + +esac diff -urN hotplug-2004_04_01.orig/etc/hotplug/isapnp.rc hotplug-2004_04_01/etc/hotplug/isapnp.rc --- hotplug-2004_04_01.orig/etc/hotplug/isapnp.rc 1970-01-01 05:00:00.000000000 +0500 +++ hotplug-2004_04_01/etc/hotplug/isapnp.rc 2004-04-12 18:51:59.000000000 +0600 @@ -0,0 +1,106 @@ +#!/bin/sh +# vim: syntax=sh +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# isapnp.rc mostly to recover lost boot-time isapnp hotplug events +# +# Copyright (C) 2004 Simone Gotti, All Rights Reserved. +# +# 2004/04/08 Simone Gotti (simone.gotti@email.it) +# 2004/04/11 Alexander E. Patrakov (patrakov@ums.usu.ru) +# Bash functions for converting ISAPNP_STRING to ID +# +# + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +cd /etc/hotplug +. ./hotplug.functions + +decode_isapnp_vendor() { + echo -n $1 | od -A n -t d1 | ( read A B C + printf '%x\n' $(( ( ( $A & 0x3f ) << 2) | \ + ( ( $B & 0x18 ) >> 3) | \ + ( ( $B & 0x07 ) <<13) | \ + ( ( $C & 0x1f ) << 8) )) ) +} + +hex_swab() { + echo `echo $1 | cut -b3-4``echo $1 | cut -b1-2` +} + +isapnp_boot_events () +{ + # make sure the isapnp agent will run + ACTION=add + DOCK=0/0/0 + ISAPNP_SLOT=00:00 + ISAPNP_ID= + + export ACTION DOCK ISAPNP_ID + + if [ -d /sys/bus ]; then + # 2.6 kernels + if [ -d /sys/bus/pnp/devices/ ]; then + cd /sys/bus/pnp/devices/ + for ISAPNP_DEVICE in *; do + # read the String id value + ISAPNP_STRING=`cat $ISAPNP_DEVICE/id` + #convert the string in the ISAPNP_ID + rawcardvendor=`echo $ISAPNP_STRING | cut -b1-3` + rawcarddevice=`echo $ISAPNP_STRING | cut -b4-7` + cardvendor=`decode_isapnp_vendor $rawcardvendor` + carddevice=`hex_swab $rawcarddevice` + ISAPNP_ID=$carddevice$cardvendor + /sbin/hotplug isapnp + done + fi + else + # Check for /proc/bus/pnp/ + if [ -d /proc/bus/pnp/ ]; then + cat /proc/bus/pnp/devices | + while read line + do + ISAPNP_ID=`echo $line | cut -d' ' -f2` + /sbin/hotplug isapnp + done + + # Check for /proc/bus/isapnp/ + elif [ -d /proc/bus/isapnp/ ]; then + cat /proc/bus/isapnp/devices | + while read line + do + ISAPNP_ID=`echo $line | cut -d' ' -f2` + /sbin/hotplug isapnp + done + #else + #echo "/proc/bus/pnp/ or /proc/bus/isapnp/ not found, Is it enabled in your kernel?" + fi + fi + return 0 +} + +# See how we were called. +case "$1" in + start) + isapnp_boot_events + ;; + stop) + # echo $"isapnp stop -- ignored" + ;; + status) + # echo $"isapnp status -- ignored" + ;; + restart) + # always invoke by absolute path, else PATH=$PATH: + $0 stop && $0 start + ;; + *) + echo $"Usage: $0 {start|stop|status|restart}" + exit 1 +esac diff -urN hotplug-2004_04_01.orig/etc/hotplug/pnp.rc hotplug-2004_04_01/etc/hotplug/pnp.rc --- hotplug-2004_04_01.orig/etc/hotplug/pnp.rc 1970-01-01 05:00:00.000000000 +0500 +++ hotplug-2004_04_01/etc/hotplug/pnp.rc 2004-05-16 12:05:32.000000000 +0600 @@ -0,0 +1,56 @@ +#!/bin/sh -e +# +# isapnp.rc synthesizes isapnp hotplug events at boot time +# it requires a 2.6 kernel with CONFIG_ISAPNP defined +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Copyright (C) 2004 Simone Gotti +# Copyright (C) 2004 Marco d'Itri +# + +# only 2.6 kernels are supported +[ -d /sys/bus/pnp/devices/ ] || return 0 + +cd /etc/hotplug +. ./hotplug.functions + +isapnp_boot_events() +{ + if [ "$(echo /sys/bus/pnp/devices/*/id)" = "/sys/bus/pnp/devices/*/id" ]; + then + return 0 + fi + + cat /sys/bus/pnp/devices/*/id \ + | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ + | while read MODULE; do + # ignore blacklisted devices + if grep -qi "^$MODULE\$" /etc/hotplug/blacklist; then + return 0 + fi + + # see do_pnp_entry() in /usr/src/linux/scripts/file2alias.c + $MODPROBE -q pnp:d$MODULE || true + done +} + +# See how we were called. +case "$1" in + start|restart) + isapnp_boot_events + ;; + stop) + # echo "isapnp stop -- ignored" + ;; + status) + # echo "isapnp status -- ignored" + ;; + *) + echo "Usage: $0 {start|stop|status|restart}" + exit 1 +esac +