ia64/xen-unstable

view tools/python/xen/xend/server/pciif.py @ 9648:07af1b34d4c4

I used the wrong operator in a couple places for putting together some
error messages out of format strings. This patch corrects those
operators and fixes the strings.

Signed-off-by: Ryan Wilson <hap9@epoch.ncsc.mil>
author emellor@leeni.uk.xensource.com
date Mon Apr 10 14:47:51 2006 +0100 (2006-04-10)
parents 05daa762a8e2
children 7801e09f518c
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 # Copyright (C) 2005 XenSource Ltd
17 #============================================================================
20 import types
22 from xen.xend import sxp
23 from xen.xend.XendError import VmError
24 from xen.xend.XendLogging import log
26 from xen.xend.xenstore.xstransact import xstransact
28 from xen.xend.server.DevController import DevController
30 import xen.lowlevel.xc
32 from xen.util.pci import PciDevice
33 import resource
35 xc = xen.lowlevel.xc.xc()
37 #Calculate PAGE_SHIFT: number of bits to shift an address to get the page number
38 PAGE_SIZE = resource.getpagesize()
39 PAGE_SHIFT = 0
40 t = PAGE_SIZE
41 while not (t&1):
42 t>>=1
43 PAGE_SHIFT+=1
45 class PciController(DevController):
47 def __init__(self, vm):
48 DevController.__init__(self, vm)
51 def getDeviceDetails(self, config):
52 """@see DevController.getDeviceDetails"""
53 #log.debug('pci config='+sxp.to_string(config))
55 def get_param(config, field, default=None):
56 try:
57 val = sxp.child_value(config, field)
59 if not val:
60 if default==None:
61 raise VmError('pci: Missing %s config setting' % field)
62 else:
63 return default
65 if isinstance(val, types.StringType):
66 return int(val, 16)
67 else:
68 return val
69 except:
70 if default==None:
71 raise VmError('pci: Invalid config setting %s: %s' %
72 (field, val))
73 else:
74 return default
76 back = {}
78 val = sxp.child_value(config, 'dev')
79 if isinstance(val, list):
80 pcidevid = 0
81 for dev_config in sxp.children(config, 'dev'):
82 domain = get_param(dev_config, 'domain', 0)
83 bus = get_param(dev_config,'bus')
84 slot = get_param(dev_config,'slot')
85 func = get_param(dev_config,'func')
87 self.setupDevice(domain, bus, slot, func)
89 back['dev-%i'%(pcidevid)]="%04x:%02x:%02x.%02x"% \
90 (domain, bus, slot, func)
91 pcidevid+=1
93 back['num_devs']=str(pcidevid)
95 else:
96 # Xen 2.0 configuration compatibility
97 domain = get_param(dev_config, 'domain', 0)
98 bus = get_param(config, 'bus')
99 slot = get_param(config, 'dev')
100 func = get_param(config, 'func')
102 self.setupDevice(domain, bus, slot, func)
104 back['dev-0']="%04x:%02x:%02x.%02x"%(domain, bus, slot, func)
105 back['num_devs']=str(1)
107 return (0, back, {})
109 def setupDevice(self, domain, bus, slot, func):
110 """ Attach I/O resources for device to frontend domain
111 """
112 fe_domid = self.getDomid()
114 try:
115 dev = PciDevice(domain, bus, slot, func)
116 except Exception, e:
117 raise VmError("pci: failed to locate device and "+
118 "parse it's resources - "+str(e))
120 if dev.driver!='pciback':
121 raise VmError(("pci: PCI Backend does not own device "+ \
122 "%s\n"+ \
123 "See the pciback.hide kernel "+ \
124 "command-line parameter or\n"+ \
125 "bind your slot/device to the PCI backend using sysfs" \
126 )%(dev.name))
128 for (start, size) in dev.ioports:
129 log.debug('pci: enabling ioport 0x%x/0x%x'%(start,size))
130 rc = xc.domain_ioport_permission(dom = fe_domid, first_port = start,
131 nr_ports = size, allow_access = True)
132 if rc<0:
133 raise VmError(('pci: failed to configure I/O ports on device '+
134 '%s - errno=%d')%(dev.name,rc))
136 for (start, size) in dev.iomem:
137 # Convert start/size from bytes to page frame sizes
138 start_pfn = start>>PAGE_SHIFT
139 # Round number of pages up to nearest page boundary (if not on one)
140 nr_pfns = (size+(PAGE_SIZE-1))>>PAGE_SHIFT
142 log.debug('pci: enabling iomem 0x%x/0x%x pfn 0x%x/0x%x'% \
143 (start,size,start_pfn,nr_pfns))
144 rc = xc.domain_iomem_permission(dom = fe_domid,
145 first_pfn = start_pfn,
146 nr_pfns = nr_pfns,
147 allow_access = True)
148 if rc<0:
149 raise VmError(('pci: failed to configure I/O memory on device '+
150 '%s - errno=%d')%(dev.name,rc))
152 if dev.irq>0:
153 log.debug('pci: enabling irq %d'%dev.irq)
154 rc = xc.domain_irq_permission(dom = fe_domid, pirq = dev.irq,
155 allow_access = True)
156 if rc<0:
157 raise VmError(('pci: failed to configure irq on device '+
158 '%s - errno=%d')%(dev.name,rc))
160 def waitForBackend(self,devid):
161 return (0, "ok - no hotplug")