# -*- 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

# 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.9 2004/02/19 03:31:22 martins Exp $

[ -d "/proc/ide" ] || return 0

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

function list_os_adapters_ide ()
{
    for i in /proc/ide/ide[0-9]* ; do
	[ -d "$i" ] && basename "$i"
    done
}

function do_adapter_ide ()
{
    local node="$1"

    local ax osname
    adapter_set_ax_osname_hook

    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 ds=$(get_adapter_ds "ide")

	    local mf=$(pci_lookup "${libdir}/pci.ids" "$vendor")
	    local tm=$(pci_lookup "${libdir}/pci.ids" "$vendor" "$device")

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

	    # Hook sets these variables.
	    local yl
	    do_adapter_hook "ide"

	    # Explicitly unset some variables.
	    local cd rl rm

	    print_adapter_vpd_hook >"${node}/linux,vpd"
	fi
    else
	do_adapter_DEFAULT "ide" "$node"
    fi
}

function get_pci_info_ide ()
{
    local name="$1"

    local x bus devfun
    read x x bus x devfun x <"/proc/ide/${name}/config"
    
    # FIXME (domain)!
    local dom="00"
    local dev=$((0x$devfun >> 3))
    local fun=$((0x$devfun & 0x7))

    echo "0x${dom} 0x${bus} 0x${dev} 0x${fun}"
}
