Matthew Fioravante
2012-Sep-18  18:22 UTC
[PATCH xm/xl enhancements for vptm 6/6] add iomem feature to xm
This adds the iomem feature from patch 3 to xm as well.
Signed off by Matthew Fioravante matthew.fioravante@jhuapl.edu
diff --git a/tools/python/xen/xend/XendDevices.py
b/tools/python/xen/xend/XendDevices.py
--- a/tools/python/xen/xend/XendDevices.py
+++ b/tools/python/xen/xend/XendDevices.py
@@ -19,7 +19,7 @@
 # A collection of DevControllers
 #
 
-from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif,
vfbif, vscsiif, netif2, vusbif
+from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif,
iomemif, vfbif, vscsiif, netif2, vusbif
 from xen.xend.server.BlktapController import BlktapController,
Blktap2Controller
 from xen.xend.server.ConsoleController import ConsoleController
 
@@ -42,6 +42,7 @@ class XendDevices:
         ''pci'': pciif.PciController,
         ''ioports'': iopif.IOPortsController,
         ''irq'': irqif.IRQController,
+        ''iomem'': iomemif.IOMEMController,
         ''tap'': BlktapController,
         ''tap2'': Blktap2Controller,
         ''vfb'': vfbif.VfbifController,
diff --git a/tools/python/xen/xend/server/iomemif.py
b/tools/python/xen/xend/server/iomemif.py
--- /dev/null
+++ b/tools/python/xen/xend/server/iomemif.py
@@ -0,0 +1,103 @@
+#===========================================================================+#
This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#===========================================================================+#
Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (C) 2005 XenSource Ltd
+# Copyright (C) 2005 Jody Belka
+#===========================================================================+
+
+import types
+
+import xen.lowlevel.xc
+
+from xen.xend.XendError import VmError
+
+from xen.xend.server.DevController import DevController
+
+
+xc = xen.lowlevel.xc.xc()
+
+
+def parse_iomemaddr(val):
+    """Parse an iomem address
+    """
+    if isinstance(val, types.StringType):
+        radix = 10
+        if val.startswith(''0x'') or
val.startswith(''0X''):
+            radix = 16
+        v = int(val, radix)
+    else:
+        v = val
+    return v
+
+
+class IOMEMController(DevController):
+
+    valid_cfg = [''mfn'', ''nmfns'',
''enable'']
+
+    def __init__(self, vm):
+        DevController.__init__(self, vm)
+
+    def getDeviceConfiguration(self, devid, transaction = None):
+        result = DevController.getDeviceConfiguration(self, devid,
transaction)
+        if transaction is None:
+            devinfo = self.readBackend(devid, *self.valid_cfg)
+        else:
+            devinfo = self.readBackendTxn(transaction, devid,
*self.valid_cfg)
+        config = dict(zip(self.valid_cfg, devinfo))
+        config = dict([(key, val) for key, val in config.items()
+                       if val != None])
+        return config
+
+    def getDeviceDetails(self, config):
+        """@see DevController.getDeviceDetails"""
+
+        def get_param(field):
+            try:
+                val = config.get(field)
+
+                if not val:
+                    raise VmError(''iomem: Missing %s config
setting'' %
field)
+
+                return parse_iomemaddr(val)
+            except:
+                raise VmError(''iomem: Invalid config setting %s:
%s'' %
+                              (field, val))
+      
+        mfn = get_param(''mfn'')
+        nmfns = get_param(''nmfns'')
+        enable = get_param(''enable'')
+
+    if nmfns <= 0:
+        raise VmError(''iomem: invalid number of mfns: %s'' %
str(nmfns))
+    #FIXME: Bounds check for max iomem range??
+
+        rc = xc.domain_iomem_permission(domid        = self.getDomid(),
+                                         first_pfn    = mfn,
+                     nr_pfns      = nmfns,
+                                         allow_access = enable)
+
+        if rc < 0:
+            #todo non-fatal
+            raise VmError(
+                ''iomem: Failed to configure memory mapped i/o range:
%s,%s'' %
+                (str(mfn), str(nmfns)))
+
+        back = dict([(k, config[k]) for k in self.valid_cfg if k in
config])
+        return (self.allocateDeviceID(), back, {})
+
+    def waitForDevice(self, devid):
+        # don''t wait for hotplug
+        return
diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py
+++ b/tools/python/xen/xm/create.py
@@ -378,6 +378,14 @@ gopts.var(''irq'',
val=''IRQ'',
          For example ''irq=7''.
          This option may be repeated to add more than one
IRQ.""")
 
+gopts.var(''iomem'', val=''MFN,NMFNS,ENABLE'',
+          fn=append_value, default=[],
+          use="""Allow access to memory mapped IO pages, using
the
given params.
+     For example ''iomem=e4df0,5,1'', to allow access to 5
pages starting
+     at page number 0xe4df0. The first arg is in hex, the second in
decimal.
+         The last argument is a 1 or 0, to either enable or disable the
memory region.
+     This option may be repeated to add more than one memory
range""")
+
 gopts.var(''vfb'',
val="vnc=1,sdl=1,vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD,opengl=1,keymap=FILE,serial=FILE,monitor=FILE",
           fn=append_value, default=[],
           use="""Make the domain a framebuffer backend.
@@ -947,6 +955,13 @@ def configure_irq(config_devs, vals):
         config_irq = [''irq'', [''irq'', irq]]
         config_devs.append([''device'', config_irq])
 
+def configure_iomem(config_devs, vals):
+    """Create the config for iomem.
+    """
+    for (mfn, nmfns, enable) in vals.iomem:
+        config_iomem = [''iomem'', [''mfn'',
mfn], [''nmfns'', nmfns],
[''enable'', enable]]
+    config_devs.append([''device'', config_iomem])
+
 def configure_vfbs(config_devs, vals):
     for f in vals.vfb:
         d = comma_sep_kv_to_dict(f)
@@ -1191,6 +1206,7 @@ def make_config(vals):
     configure_vscsis(config_devs, vals)
     configure_vusbs(config_devs, vals)
     configure_ioports(config_devs, vals)
+    configure_iomem(config_devs, vals)
     configure_irq(config_devs, vals)
     configure_vifs(config_devs, vals)
     configure_vtpm(config_devs, vals)
@@ -1307,6 +1323,18 @@ def preprocess_irq(vals):
         irq.append(d)
     vals.irq = irq
 
+def preprocess_iomem(vals):
+    if not vals.iomem: return
+    iomem = []
+    for v in vals.iomem:
+        d = v.split('','')
+    if len(d) < 1 or len(d) > 3:
+       err(''Invalid iomem range specifier: '' + v)
+    #Add hex specifier to the page number
+    d[0] = ''0x'' + d[0]
+    iomem.append(d)
+    vals.iomem = iomem
+
 def preprocess_vtpm(vals):
     if not vals.vtpm: return
     vtpms = []
@@ -1398,6 +1426,7 @@ def preprocess(vals):
     preprocess_pci(vals)
     preprocess_vscsi(vals)
     preprocess_ioports(vals)
+    preprocess_iomem(vals)
     preprocess_ip(vals)
     preprocess_irq(vals)
     preprocess_nfs(vals)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel