VTPM mini-os: mmio= option for domain config files to pass iomem regions
PATCH 1/12 VTPM mini-os: mmio= option for domain config files to pass iomem regions
Currently IO ports and irqs can be passed through to domU's using the domain config file.
This patch adds support for passing through iomem regions when booting domains using xm. It works almost exactly the same as the ioports option.
The format for the option is
mmio = ['pagenum,npages']
Where the first is the page number (in a hex string) and the second is the number of pages. An example for passing through the tpm is:
mmio = ['fed40',5]
Signed off by: Matthew Fioravante <[email protected]>
tools/python/xen/xend/server/mmioif.py +102 -0
@@ -0,0 +1,102 @@ +#============================================================================ +# 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 <[email protected]> +# 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_mmioaddr(val): + """Parse an mmio 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 MMIOController(DevController): + + valid_cfg = ['mfn', 'nmfns', 'uuid'] + + 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('mmio: Missing %s config setting' % field) + + return parse_mmioaddr(val) + except: + raise VmError('mmio: Invalid config setting %s: %s' % + (field, val)) + + mfn = get_param('mfn') + nmfns = get_param('nmfns') + + if nmfns <= 0: + raise VmError('mmio: invalid number of mfns: %s' % str(nmfns)) + #FIXME: Bounds check for max mmio range?? + + rc = xc.domain_iomem_permission(domid = self.getDomid(), + first_pfn = mfn, + nr_pfns = nmfns, + allow_access = True) + + if rc < 0: + #todo non-fatal + raise VmError( + 'mmio: 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
tools/python/xen/xend/XendDevices.py +2 -1
@@ -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, mmioif, vfbif, vscsiif, netif2, vusbif from xen.xend.server.BlktapController import BlktapController, Blktap2Controller from xen.xend.server.ConsoleController import ConsoleController
@@ -42,6 +42,7 @@ 'pci': pciif.PciController, 'ioports': iopif.IOPortsController, 'irq': irqif.IRQController, + 'mmio': mmioif.MMIOController, 'tap': BlktapController, 'tap2': Blktap2Controller, 'vfb': vfbif.VfbifController,
tools/python/xen/xm/create.py +28 -0
@@ -378,6 +378,13 @@ For example 'irq=7'. This option may be repeated to add more than one IRQ.""") +gopts.var('mmio', val='MFN,NMFNS', + fn=append_value, default=[], + use="""Allow access to memory mapped IO pages, using the given params. + For example 'mmio=e4df0,5', to allow access to 5 pages starting + at page number 0xe4df0. The first arg is in hex, the second in decimal. + 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.
@@ -942,6 +949,13 @@ config_irq = ['irq', ['irq', irq]] config_devs.append(['device', config_irq]) +def configure_mmio(config_devs, vals): + """Create the config for mmio. + """ + for (mfn, nmfns) in vals.mmio: + config_mmio = ['mmio', ['mfn', mfn], ['nmfns', nmfns]] + config_devs.append(['device', config_mmio]) + def configure_vfbs(config_devs, vals): for f in vals.vfb: d = comma_sep_kv_to_dict(f)
@@ -1186,6 +1200,7 @@ configure_vscsis(config_devs, vals) configure_vusbs(config_devs, vals) configure_ioports(config_devs, vals) + configure_mmio(config_devs, vals) configure_irq(config_devs, vals) configure_vifs(config_devs, vals) configure_vtpm(config_devs, vals)
@@ -1302,6 +1317,18 @@ irq.append(d) vals.irq = irq +def preprocess_mmio(vals): + if not vals.mmio: return + mmio = [] + for v in vals.mmio: + d = v.split(',') + if len(d) < 1 or len(d) > 2: + err('Invalid mmio range specifier: ' + v) + #Add hex specifier to the page number + d[0] = '0x' + d[0] + mmio.append(d) + vals.mmio = mmio + def preprocess_vtpm(vals): if not vals.vtpm: return vtpms = []
@@ -1393,6 +1420,7 @@ preprocess_pci(vals) preprocess_vscsi(vals) preprocess_ioports(vals) + preprocess_mmio(vals) preprocess_ip(vals) preprocess_irq(vals) preprocess_nfs(vals)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel