ia64/xen-unstable

view tools/misc/sbdf2devicepath @ 19648:f0e2df69a8eb

x86 hvm: Allow cross-vendor migration

Intercept #UD and emulate SYSCALL/SYSENTER/SYSEXIT as necessary.

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