# -*- shell-script -*-

# 03adapter_ide_proc - IDE adapter support using /proc/ide.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2003, 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# 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, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 03adapter_ide_proc,v 1.23 2005/05/13 03:27:17 martins Exp $

[ -f "/proc/ide/drivers" ] || return 0

######################################################################

add_adapter_ide ()
{
    local bus_info="$1"

    # FIXME: Probably shouldn't do this here!
    local ax osname
    adapter_set_ax_osname_hook "ide" "$bus_info"

    local adapter_bus_dir
    set_adapter_bus_dir "ide" "$bus_info"

    if [ -z "$adapter_bus_dir" ] ; then
	debug "add_adapter_ide: bus directory not found for \"${bus_info}\""
	return 1
    fi

    local d="/proc/ide/${ax}"
    local f="${d}/config"

    if [ -f "$f" ] ; then
	local x vendor device
	read x x x x x x vendor x device x <"$f"
    
	if [ -n "$vendor" -a -n "$device" ] ; then
	    local subvendor subdevice
	    pci_set_mf_tm_hook

	    local channel
	    local cf="${d}/channel"
	    [ -f "$cf" ] && read channel <"$cf"

	    local adapter_is_a_channel
	    check_if_adapter_is_a_channel "ide" "$bus_info" "$adapter_bus_dir"

	    # Hook sets these variables.
	    local ds yl
	    add_adapter_hook \
		"ide" "$bus_info" "$adapter_bus_dir" $adapter_is_a_channel

	    # Explicitly unset some variables.
	    local cd rl rm sn

	    vpd_create_hook "$adapter_bus_dir"

	    adapter_extra_vpd_hook "$type" "$bus_info" "$adapter_bus_dir"
	fi
    else
	add_adapter_DEFAULT "ide" "$adapter_bus_dir"
    fi
}
