~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/python/xen/xend/server/iopif.py

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
# Copyright (C) 2005 Jody Belka
 
18
#============================================================================
 
19
 
 
20
 
 
21
import types
 
22
 
 
23
import xen.lowlevel.xc
 
24
 
 
25
from xen.xend.XendError import VmError
 
26
 
 
27
from xen.xend.server.DevController import DevController
 
28
 
 
29
 
 
30
xc = xen.lowlevel.xc.xc()
 
31
 
 
32
 
 
33
def parse_ioport(val):
 
34
    """Parse an i/o port field.
 
35
    """
 
36
    if isinstance(val, types.StringType):
 
37
        radix = 10
 
38
        if val.startswith('0x') or val.startswith('0X'):
 
39
            radix = 16
 
40
        v = int(val, radix)
 
41
    else:
 
42
        v = val
 
43
    return v
 
44
 
 
45
 
 
46
class IOPortsController(DevController):
 
47
 
 
48
    valid_cfg = ['to', 'from', 'uuid']
 
49
 
 
50
    def __init__(self, vm):
 
51
        DevController.__init__(self, vm)
 
52
 
 
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)
 
57
        else:
 
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()
 
61
                       if val != None])
 
62
        return config
 
63
 
 
64
    def getDeviceDetails(self, config):
 
65
        """@see DevController.getDeviceDetails"""
 
66
 
 
67
        def get_param(field):
 
68
            try:
 
69
                val = config.get(field)
 
70
 
 
71
                if not val:
 
72
                    raise VmError('ioports: Missing %s config setting' % field)
 
73
 
 
74
                return parse_ioport(val)
 
75
            except:
 
76
                raise VmError('ioports: Invalid config setting %s: %s' %
 
77
                              (field, val))
 
78
       
 
79
        io_from = get_param('from')
 
80
        io_to = get_param('to') 
 
81
 
 
82
        if io_to < io_from or io_to >= 65536:
 
83
            raise VmError('ioports: Invalid i/o range: %s - %s' %
 
84
                          (io_from, io_to))
 
85
 
 
86
        rc = xc.domain_ioport_permission(domid        = self.getDomid(),
 
87
                                         first_port   = io_from,
 
88
                                         nr_ports     = io_to - io_from + 1,
 
89
                                         allow_access = True)
 
90
 
 
91
        if rc < 0:
 
92
            #todo non-fatal
 
93
            raise VmError(
 
94
                'ioports: Failed to configure legacy i/o range: %s - %s' %
 
95
                (io_from, io_to))
 
96
 
 
97
        back = dict([(k, config[k]) for k in self.valid_cfg if k in config])
 
98
        return (self.allocateDeviceID(), back, {})
 
99
 
 
100
    def waitForDevice(self, devid):
 
101
        # don't wait for hotplug
 
102
        return