ia64/xen-unstable

changeset 19506:3fecb8f43617

tools: Add device-path command to convert SBDF into device path.

'SBDF' format is "[SEG#:]BUS#:DEV#.FUNC#"
ex) 0000:0a:1f.3
Device path format is "HID[:UID]-DEV#.FUNC#[-DEV#.FUNC#[...]]"
ex) PNP0A08:0-2.0-0.0

The command can be executed as follows.

# device_path 0a:1f.3
PNP0A08:0-2.0-0.0

Signed-off-by: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 06 13:52:56 2009 +0100 (2009-04-06)
parents bdbe5232b068
children 1f705f0a32e2
files Makefile tools/misc/Makefile tools/misc/device-path
line diff
     1.1 --- a/Makefile	Mon Apr 06 13:49:59 2009 +0100
     1.2 +++ b/Makefile	Mon Apr 06 13:52:56 2009 +0100
     1.3 @@ -224,7 +224,7 @@ uninstall:
     1.4  	rm -rf $(D)$(LIBDIR)/xen/
     1.5  	rm -rf $(D)/usr/lib/xen/
     1.6  	rm -rf $(D)/usr/local/sbin/setmask $(D)/usr/local/sbin/xen*
     1.7 -	rm -rf $(D)/usr/sbin/xen* $(D)/usr/sbin/netfix $(D)/usr/sbin/xm
     1.8 +	rm -rf $(D)/usr/sbin/xen* $(D)/usr/sbin/netfix $(D)/usr/sbin/xm $(D)/usr/sbin/device-path
     1.9  	rm -rf $(D)/usr/share/doc/xen
    1.10  	rm -rf $(D)/usr/share/xen
    1.11  	rm -rf $(D)/usr/share/man/man1/xen*
     2.1 --- a/tools/misc/Makefile	Mon Apr 06 13:49:59 2009 +0100
     2.2 +++ b/tools/misc/Makefile	Mon Apr 06 13:52:56 2009 +0100
     2.3 @@ -22,7 +22,7 @@ INSTALL_BIN-y := xencons
     2.4  INSTALL_BIN-$(CONFIG_X86) += xen-detect
     2.5  INSTALL_BIN := $(INSTALL_BIN-y)
     2.6  
     2.7 -INSTALL_SBIN-y := netfix xm xen-bugtool xen-python-path xend xenperf xsview xenpm
     2.8 +INSTALL_SBIN-y := netfix xm xen-bugtool xen-python-path xend xenperf xsview xenpm device-path
     2.9  INSTALL_SBIN := $(INSTALL_SBIN-y)
    2.10  
    2.11  DEFAULT_PYTHON_PATH := $(shell $(XEN_ROOT)/tools/python/get-path)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/misc/device-path	Mon Apr 06 13:52:56 2009 +0100
     3.3 @@ -0,0 +1,78 @@
     3.4 +#!/usr/bin/env python
     3.5 +#  -*- mode: python; -*-
     3.6 +#============================================================================
     3.7 +# This library is free software; you can redistribute it and/or
     3.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     3.9 +# License as published by the Free Software Foundation.
    3.10 +#
    3.11 +# This library is distributed in the hope that it will be useful,
    3.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.14 +# Lesser General Public License for more details.
    3.15 +#
    3.16 +# You should have received a copy of the GNU Lesser General Public
    3.17 +# License along with this library; if not, write to the Free Software
    3.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.19 +#============================================================================
    3.20 +# Copyright (c) 2009, NEC Corporation.
    3.21 +#============================================================================
    3.22 +# This script converts SBDF into device path.
    3.23 +#   'SBDF' format is "[SEG#:]BUS#:DEV#.FUNC#"
    3.24 +#       ex) 0000:0a:1f.3
    3.25 +#   Device path format is "HID[:UID]-DEV#.FUNC#[-DEV#.FUNC#[...]]"
    3.26 +#       ex) PNP0A08:0-2.0-0.0
    3.27 +#============================================================================
    3.28 +
    3.29 +import sys
    3.30 +import os
    3.31 +
    3.32 +# add fallback path for non-native python path installs if needed
    3.33 +sys.path.append('/usr/lib/python')
    3.34 +sys.path.append('/usr/lib64/python')
    3.35 +from xen.util.pci import *
    3.36 +
    3.37 +SYSFS_ACPI_DEVS_PATH = '/firmware/acpi/namespace/ACPI/_SB'
    3.38 +
    3.39 +def find_hid_uid(dom, b, d, f):
    3.40 +    sb_path = find_sysfs_mnt() + SYSFS_ACPI_DEVS_PATH
    3.41 +    obj_list = os.listdir(sb_path)
    3.42 +    for obj in obj_list:
    3.43 +        obj_path = sb_path + '/' + obj.strip() + '/'
    3.44 +        if os.path.exists(obj_path + 'seg') and \
    3.45 +            os.path.exists(obj_path + 'bbn'):
    3.46 +            seg = open(obj_path + 'seg').read()
    3.47 +            bbn = open(obj_path + 'bbn').read()
    3.48 +            if int(seg) == dom and int(bbn) == b:
    3.49 +                hid = open(obj_path + 'hid').read()
    3.50 +                if os.path.exists(obj_path + 'uid') is False:
    3.51 +                    path_str = hid.strip()
    3.52 +                else:
    3.53 +                    uid = open(obj_path + 'uid').read()
    3.54 +                    path_str = hid.strip() + ':' + uid.strip()
    3.55 +                return path_str
    3.56 +    return None
    3.57 +
    3.58 +def make_device_path(dom, b, d, f):
    3.59 +    dev = PciDevice(dom, b, d, f)
    3.60 +    parent = dev.find_parent()
    3.61 +    if parent is None:
    3.62 +        path_str = find_hid_uid(dom, b, d, f)
    3.63 +        path_str = path_str + '-' + hex(d).replace('0x', '') + '.' + \
    3.64 +            hex(f).replace('0x', '')
    3.65 +        return path_str
    3.66 +    (pdom, pb, pd, pf) = parent
    3.67 +    path_str = make_device_path(pdom, pb, pd, pf)
    3.68 +    path_str = path_str + '-' + hex(d).replace('0x', '') + '.' + \
    3.69 +        hex(f).replace('0x', '')
    3.70 +    return path_str
    3.71 +
    3.72 +# main
    3.73 +if len(sys.argv) <> 2:
    3.74 +    print 'Usage: device-path SBDF\n'
    3.75 +else:
    3.76 +    path = os.environ['PATH']
    3.77 +    os.environ['PATH'] = path + ':/sbin' + ':/user/sbin'
    3.78 +    sbdf = sys.argv[1]
    3.79 +    (dom, b, d, f) = parse_pci_name(sbdf)
    3.80 +    path_str = make_device_path(dom, b, d, f)
    3.81 +    print path_str