debuggers.hg

annotate tools/misc/sbdf2devicepath @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 0b9b6d5a61c1
children
rev   line source
keir@19565 1 #!/usr/bin/env python
keir@19565 2 # -*- mode: python; -*-
keir@19565 3 #============================================================================
keir@19565 4 # This library is free software; you can redistribute it and/or
keir@19565 5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
keir@19565 6 # License as published by the Free Software Foundation.
keir@19565 7 #
keir@19565 8 # This library is distributed in the hope that it will be useful,
keir@19565 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
keir@19565 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
keir@19565 11 # Lesser General Public License for more details.
keir@19565 12 #
keir@19565 13 # You should have received a copy of the GNU Lesser General Public
keir@19565 14 # License along with this library; if not, write to the Free Software
keir@19565 15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
keir@19565 16 #============================================================================
keir@19565 17 # Copyright (c) 2009, NEC Corporation.
keir@19565 18 #============================================================================
keir@19565 19 # This script converts SBDF into device path.
keir@19565 20 # 'SBDF' format is "[SEG#:]BUS#:DEV#.FUNC#"
keir@19565 21 # ex) 0000:0a:1f.3
keir@19565 22 # Device path format is "HID[:UID]-DEV#.FUNC#[-DEV#.FUNC#[...]]"
keir@19565 23 # ex) PNP0A08:0-2.0-0.0
keir@19565 24 #=============================================================================
keir@19565 25
keir@19565 26 import sys
keir@19565 27 import os
keir@19565 28
keir@19565 29 # add fallback path for non-native python path installs if needed
keir@19565 30 sys.path.append('/usr/lib/python')
keir@19565 31 sys.path.append('/usr/lib64/python')
keir@19565 32 from xen.util.pci import *
keir@19565 33
keir@19565 34 SYSFS_ACPI_DEVS_PATH = '/firmware/acpi/namespace/ACPI/_SB'
keir@19565 35
keir@19565 36 def find_hid_uid(dom, b, d, f):
keir@19565 37 obj_list = os.listdir(sb_path)
keir@19565 38 for obj in obj_list:
keir@19565 39 obj_path = sb_path + '/' + obj.strip() + '/'
keir@19565 40 if os.path.exists(obj_path + 'seg') and \
keir@19565 41 os.path.exists(obj_path + 'bbn'):
keir@19565 42 seg = open(obj_path + 'seg').read()
keir@19565 43 bbn = open(obj_path + 'bbn').read()
keir@19565 44 if int(seg) == dom and int(bbn) == b:
keir@19565 45 hid = open(obj_path + 'hid').read()
keir@19565 46 if os.path.exists(obj_path + 'uid') is False:
keir@19565 47 path_str = hid.strip()
keir@19565 48 else:
keir@19565 49 uid = open(obj_path + 'uid').read()
keir@19565 50 path_str = hid.strip() + ':' + uid.strip()
keir@19565 51 return path_str
keir@19565 52 return None
keir@19565 53
keir@19565 54 def make_device_path(dom, b, d, f):
keir@19565 55 dev = PciDevice(dom, b, d, f)
keir@19565 56 parent = dev.find_parent()
keir@19565 57 if parent is None:
keir@19565 58 path_str = find_hid_uid(dom, b, d, f)
keir@19565 59 path_str = path_str + '-' + hex(d).replace('0x', '') + '.' + \
keir@19565 60 hex(f).replace('0x', '')
keir@19565 61 return path_str
keir@19565 62 (pdom, pb, pd, pf) = parent
keir@19565 63 path_str = make_device_path(pdom, pb, pd, pf)
keir@19565 64 path_str = path_str + '-' + hex(d).replace('0x', '') + '.' + \
keir@19565 65 hex(f).replace('0x', '')
keir@19565 66 return path_str
keir@19565 67
keir@19565 68 # main
keir@19565 69 if len(sys.argv) <> 2:
keir@19565 70 print 'Usage: sbdf2devicepath SBDF\n'
keir@19565 71 else:
keir@19565 72 sb_path = find_sysfs_mnt() + SYSFS_ACPI_DEVS_PATH
keir@19565 73 if os.path.exists(sb_path):
keir@19565 74 path = os.environ['PATH']
keir@19565 75 os.environ['PATH'] = path + ':/sbin' + ':/user/sbin'
keir@19565 76 sbdf = sys.argv[1]
keir@19565 77 (dom, b, d, f) = parse_pci_name(sbdf)
keir@19565 78 path_str = make_device_path(dom, b, d, f)
keir@19565 79 print path_str
keir@19565 80 else:
keir@19565 81 print sb_path + ' not found.\n'
keir@19565 82 print 'This command is only for linux 2.6.18.8 xen kernel.\n'