ia64/xen-unstable

view tools/python/xen/xend/server/pciif.py @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 #============================================================================
18 import types
20 import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
22 from xen.xend import sxp
23 from xen.xend.XendError import VmError
25 from controller import Dev, DevController
27 def parse_pci(val):
28 """Parse a pci field.
29 """
30 if isinstance(val, types.StringType):
31 radix = 10
32 if val.startswith('0x') or val.startswith('0X'):
33 radix = 16
34 v = int(val, radix)
35 else:
36 v = val
37 return v
39 class PciDev(Dev):
41 def __init__(self, controller, id, config, recreate=False):
42 Dev.__init__(self, controller, id, config, recreate=recreate)
43 bus = sxp.child_value(self.config, 'bus')
44 if not bus:
45 raise VmError('pci: Missing bus')
46 dev = sxp.child_value(self.config, 'dev')
47 if not dev:
48 raise VmError('pci: Missing dev')
49 func = sxp.child_value(self.config, 'func')
50 if not func:
51 raise VmError('pci: Missing func')
52 try:
53 bus = parse_pci(bus)
54 dev = parse_pci(dev)
55 func = parse_pci(func)
56 except:
57 raise VmError('pci: invalid parameter')
59 def attach(self, recreate=False, change=False):
60 rc = xc.physdev_pci_access_modify(dom = self.getDomain(),
61 bus = bus,
62 dev = dev,
63 func = func,
64 enable = True)
65 if rc < 0:
66 #todo non-fatal
67 raise VmError('pci: Failed to configure device: bus=%s dev=%s func=%s' %
68 (bus, dev, func))
70 def destroy(self, change=False, reboot=False):
71 pass
73 class PciController(DevController):
75 def newDevice(self, id, config, recreate=False):
76 return PciDev(self, id, config, recreate=recreate)