ia64/xen-unstable

changeset 9203:5ea87acc07dc

Adds a new device interface to xend/xm similar to the one for ioports
where an interrupt (irq) can be specified in the configuration file
and permission to bind to that interrupt will be given to a driver
domain.

This functionality could be used when trying to give a legacy device
to a driver domain. For example, by specifying the i/o ports and the
interrupt of your serial controller, you can use this patch to put a
serial port in a driver domain. This was discussed briefly on
xen-users in regards to using an external modem in a domU:

http://article.gmane.org/gmane.comp.emulators.xen.devel/20573
http://article.gmane.org/gmane.comp.emulators.xen.user/8754

Also adds the ability to specify irqs on the xm command-line when
creating a domain (the following examples show a serial port being
given to a domU):

xm create serial-dd irq=4 ioports=03f8-03ff

or in a flat config-file:

irq = [4]
ioports = ['03f8-03ff']

or in an SXP config file:

(device (irq (irq 4)))
(device (ioports (from '0x03f8')(to '0x03ff')))

The ioports functionality is already in xen, but this patch also fixes a
bug with it that I assume cropped up due to changes in xend since it was
submitted ('dev' doesn't exist in iopif.py, returning 'None' seems to be
the solution).

Also adds some in-line documentation in tools/python/xen/xm/create.py
to be more accurate regarding adding pci devices and i/o ports on the
command-line.

Signed-off-by: Ryan Wilson <hap9@epoch.ncsc.mil>
author kaf24@firebug.cl.cam.ac.uk
date Thu Mar 09 11:20:31 2006 +0100 (2006-03-09)
parents 37f3f5ad9110
children 899532500ada
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/iopif.py tools/python/xen/xend/server/irqif.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 09 11:17:29 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 09 11:20:31 2006 +0100
     1.3 @@ -1580,10 +1580,11 @@ def addControllerClass(device_class, cls
     1.4      controllerClasses[device_class] = cls
     1.5  
     1.6  
     1.7 -from xen.xend.server import blkif, netif, tpmif, pciif, iopif, usbif
     1.8 +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
     1.9  addControllerClass('vbd',  blkif.BlkifController)
    1.10  addControllerClass('vif',  netif.NetifController)
    1.11  addControllerClass('vtpm', tpmif.TPMifController)
    1.12  addControllerClass('pci',  pciif.PciController)
    1.13  addControllerClass('ioports', iopif.IOPortsController)
    1.14 +addControllerClass('irq',  irqif.IRQController)
    1.15  addControllerClass('usb',  usbif.UsbifController)
     2.1 --- a/tools/python/xen/xend/server/iopif.py	Thu Mar 09 11:17:29 2006 +0100
     2.2 +++ b/tools/python/xen/xend/server/iopif.py	Thu Mar 09 11:20:31 2006 +0100
     2.3 @@ -83,4 +83,4 @@ class IOPortsController(DevController):
     2.4                  'ioports: Failed to configure legacy i/o range: %s - %s' %
     2.5                  (io_from, io_to))
     2.6  
     2.7 -        return (dev, {}, {})
     2.8 +        return (None, {}, {})
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/python/xen/xend/server/irqif.py	Thu Mar 09 11:20:31 2006 +0100
     3.3 @@ -0,0 +1,73 @@
     3.4 +#============================================================================
     3.5 +# This library is free software; you can redistribute it and/or
     3.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     3.7 +# License as published by the Free Software Foundation.
     3.8 +#
     3.9 +# This library is distributed in the hope that it will be useful,
    3.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.12 +# Lesser General Public License for more details.
    3.13 +#
    3.14 +# You should have received a copy of the GNU Lesser General Public
    3.15 +# License along with this library; if not, write to the Free Software
    3.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.17 +#============================================================================
    3.18 +# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
    3.19 +# Copyright (C) 2005 XenSource Ltd
    3.20 +# Copyright (C) 2005 Jody Belka
    3.21 +#============================================================================
    3.22 +# This code based on tools/python/xen/xend/server/iopif.py and modified
    3.23 +# to handle interrupts
    3.24 +#============================================================================
    3.25 +
    3.26 +
    3.27 +import types
    3.28 +
    3.29 +import xen.lowlevel.xc;
    3.30 +
    3.31 +from xen.xend import sxp
    3.32 +from xen.xend.XendError import VmError
    3.33 +
    3.34 +from xen.xend.server.DevController import DevController
    3.35 +
    3.36 +
    3.37 +xc = xen.lowlevel.xc.xc()
    3.38 +
    3.39 +
    3.40 +class IRQController(DevController):
    3.41 +
    3.42 +    def __init__(self, vm):
    3.43 +        DevController.__init__(self, vm)
    3.44 +
    3.45 +
    3.46 +    def getDeviceDetails(self, config):
    3.47 +        """@see DevController.getDeviceDetails"""
    3.48 +
    3.49 +        def get_param(field):
    3.50 +            try:
    3.51 +                val = sxp.child_value(config, field)
    3.52 +
    3.53 +                if not val:
    3.54 +                    raise VmError('irq: Missing %s config setting' % field)
    3.55 +
    3.56 +                if isinstance(val, types.StringType):
    3.57 +                    return int(val,10)
    3.58 +                    radix = 10
    3.59 +                else:
    3.60 +                    return val
    3.61 +            except:
    3.62 +                raise VmError('irq: Invalid config setting %s: %s' %
    3.63 +                              (field, val))
    3.64 +       
    3.65 +        pirq = get_param('irq')
    3.66 +
    3.67 +        rc = xc.domain_irq_permission(dom          = self.getDomid(),
    3.68 +                                      pirq         = pirq,
    3.69 +                                      allow_access = True)
    3.70 +
    3.71 +        if rc < 0:
    3.72 +            #todo non-fatal
    3.73 +            raise VmError(
    3.74 +                'irq: Failed to configure irq: %d' % (pirq))
    3.75 +
    3.76 +        return (None, {}, {})
     4.1 --- a/tools/python/xen/xm/create.py	Thu Mar 09 11:17:29 2006 +0100
     4.2 +++ b/tools/python/xen/xm/create.py	Thu Mar 09 11:20:31 2006 +0100
     4.3 @@ -252,15 +252,21 @@ gopts.var('disk', val='phy:DEV,VDEV,MODE
     4.4  gopts.var('pci', val='BUS:DEV.FUNC',
     4.5            fn=append_value, default=[],
     4.6            use="""Add a PCI device to a domain, using given params (in hex).
     4.7 -         For example '-pci c0:02.1a'.
     4.8 +         For example 'pci=c0:02.1a'.
     4.9           The option may be repeated to add more than one pci device.""")
    4.10  
    4.11  gopts.var('ioports', val='FROM[-TO]',
    4.12            fn=append_value, default=[],
    4.13            use="""Add a legacy I/O range to a domain, using given params (in hex).
    4.14 -         For example '-ioports 02f8-02ff'.
    4.15 +         For example 'ioports=02f8-02ff'.
    4.16           The option may be repeated to add more than one i/o range.""")
    4.17  
    4.18 +gopts.var('irq', val='IRQ',
    4.19 +          fn=append_value, default=[],
    4.20 +          use="""Add an IRQ (interrupt line) to a domain.
    4.21 +         For example 'irq=7'.
    4.22 +         This option may be repeated to add more than one IRQ.""")
    4.23 +
    4.24  gopts.var('usb', val='PATH',
    4.25            fn=append_value, default=[],
    4.26            use="""Add a physical USB port to a domain, as specified by the path
    4.27 @@ -488,6 +494,13 @@ def configure_ioports(config_devs, vals)
    4.28          config_ioports = ['ioports', ['from', io_from], ['to', io_to]]
    4.29          config_devs.append(['device', config_ioports])
    4.30  
    4.31 +def configure_irq(config_devs, vals):
    4.32 +    """Create the config for irqs.
    4.33 +    """
    4.34 +    for irq in vals.irq:
    4.35 +        config_irq = ['irq', ['irq', irq]]
    4.36 +        config_devs.append(['device', config_irq])
    4.37 +
    4.38  def configure_usb(config_devs, vals):
    4.39      for path in vals.usb:
    4.40          config_usb = ['usb', ['path', path]]
    4.41 @@ -615,6 +628,7 @@ def make_config(vals):
    4.42      configure_disks(config_devs, vals)
    4.43      configure_pci(config_devs, vals)
    4.44      configure_ioports(config_devs, vals)
    4.45 +    configure_irq(config_devs, vals)
    4.46      configure_vifs(config_devs, vals)
    4.47      configure_usb(config_devs, vals)
    4.48      configure_vtpm(config_devs, vals)