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.
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.
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
# Copyright (C) 2005 Jody Belka
18
#============================================================================
23
import xen.lowlevel.xc
25
from xen.xend.XendError import VmError
27
from xen.xend.server.DevController import DevController
30
xc = xen.lowlevel.xc.xc()
33
def parse_ioport(val):
34
"""Parse an i/o port field.
36
if isinstance(val, types.StringType):
38
if val.startswith('0x') or val.startswith('0X'):
46
class IOPortsController(DevController):
48
valid_cfg = ['to', 'from', 'uuid']
50
def __init__(self, vm):
51
DevController.__init__(self, vm)
53
def getDeviceConfiguration(self, devid, transaction = None):
54
result = DevController.getDeviceConfiguration(self, devid, transaction)
55
if transaction is None:
56
devinfo = self.readBackend(devid, *self.valid_cfg)
58
devinfo = self.readBackendTxn(transaction, devid, *self.valid_cfg)
59
config = dict(zip(self.valid_cfg, devinfo))
60
config = dict([(key, val) for key, val in config.items()
64
def getDeviceDetails(self, config):
65
"""@see DevController.getDeviceDetails"""
69
val = config.get(field)
72
raise VmError('ioports: Missing %s config setting' % field)
74
return parse_ioport(val)
76
raise VmError('ioports: Invalid config setting %s: %s' %
79
io_from = get_param('from')
80
io_to = get_param('to')
82
if io_to < io_from or io_to >= 65536:
83
raise VmError('ioports: Invalid i/o range: %s - %s' %
86
rc = xc.domain_ioport_permission(domid = self.getDomid(),
88
nr_ports = io_to - io_from + 1,
94
'ioports: Failed to configure legacy i/o range: %s - %s' %
97
back = dict([(k, config[k]) for k in self.valid_cfg if k in config])
98
return (self.allocateDeviceID(), back, {})
100
def waitForDevice(self, devid):
101
# don't wait for hotplug