From owner-svn-src-all@FreeBSD.ORG Tue Sep 30 17:37:27 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3DCE1E37; Tue, 30 Sep 2014 17:37:27 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 296B6E80; Tue, 30 Sep 2014 17:37:27 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8UHbQL9017192; Tue, 30 Sep 2014 17:37:26 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8UHbQXL017190; Tue, 30 Sep 2014 17:37:26 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201409301737.s8UHbQXL017190@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: Roger Pau Monné Date: Tue, 30 Sep 2014 17:37:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r272319 - in head/sys: conf dev/xen/xenstore X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Sep 2014 17:37:27 -0000 Author: royger Date: Tue Sep 30 17:37:26 2014 New Revision: 272319 URL: http://svnweb.freebsd.org/changeset/base/272319 Log: xen: add xenstored user-space device This device is used by the user-space daemon that runs xenstore (xenstored). It allows xenstored to map the xenstore memory page, and reports the event channel xenstore is using. Sponsored by: Citrix Systems R&D dev/xen/xenstore/xenstored_dev.c: - Add the xenstored character device that's used to map the xenstore memory into user-space, and to report the event channel used by xenstore. conf/files: - Add the device to the build process. Added: head/sys/dev/xen/xenstore/xenstored_dev.c (contents, props changed) Modified: head/sys/conf/files Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Tue Sep 30 17:31:04 2014 (r272318) +++ head/sys/conf/files Tue Sep 30 17:37:26 2014 (r272319) @@ -2640,6 +2640,7 @@ dev/xen/timer/timer.c optional xen | xe dev/xen/pvcpu/pvcpu.c optional xen | xenhvm dev/xen/xenstore/xenstore.c optional xen | xenhvm dev/xen/xenstore/xenstore_dev.c optional xen | xenhvm +dev/xen/xenstore/xenstored_dev.c optional xen | xenhvm dev/xl/if_xl.c optional xl pci dev/xl/xlphy.c optional xl pci fs/autofs/autofs.c optional autofs Added: head/sys/dev/xen/xenstore/xenstored_dev.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/xen/xenstore/xenstored_dev.c Tue Sep 30 17:37:26 2014 (r272319) @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2014 Roger Pau Monné + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#define XSD_READ_SIZE 20 + +static int xsd_dev_read(struct cdev *dev, struct uio *uio, int ioflag); +static int xsd_dev_mmap(struct cdev *dev, vm_ooffset_t offset, + vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr); + + +static struct cdevsw xsd_dev_cdevsw = { + .d_version = D_VERSION, + .d_read = xsd_dev_read, + .d_mmap = xsd_dev_mmap, + .d_name = "xsd_dev", +}; + +static int +xsd_dev_read(struct cdev *dev, struct uio *uio, int ioflag) +{ + char evtchn[XSD_READ_SIZE]; + int error, len; + + len = snprintf(evtchn, sizeof(evtchn), "%u", + HYPERVISOR_start_info->store_evtchn); + if (len < 0 || len > uio->uio_resid) + return (EINVAL); + + error = uiomove(evtchn, len, uio); + if (error) + return (error); + + return (0); +} + +static int +xsd_dev_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, + int nprot, vm_memattr_t *memattr) +{ + + if (offset != 0) + return (EINVAL); + + *paddr = pmap_kextract((vm_offset_t)xen_store); + + return (0); +} + +/*------------------ Private Device Attachment Functions --------------------*/ +/** + * \brief Identify instances of this device type in the system. + * + * \param driver The driver performing this identify action. + * \param parent The NewBus parent device for any devices this method adds. + */ +static void +xsd_dev_identify(driver_t *driver __unused, device_t parent) +{ + + if (!xen_pv_domain()) + return; + if (HYPERVISOR_start_info->store_mfn != 0) + return; + + /* + * Only attach if xenstore is not available, because we are the + * domain that's supposed to run it. + */ + BUS_ADD_CHILD(parent, 0, driver->name, 0); +} + +/** + * \brief Probe for the existence of the Xenstored device + * + * \param dev NewBus device_t for this instance. + * + * \return Always returns 0 indicating success. + */ +static int +xsd_dev_probe(device_t dev) +{ + + device_set_desc(dev, "Xenstored user-space device"); + return (BUS_PROBE_NOWILDCARD); +} + +/** + * \brief Attach the Xenstored device. + * + * \param dev NewBus device_t for this instance. + * + * \return On success, 0. Otherwise an errno value indicating the + * type of failure. + */ +static int +xsd_dev_attach(device_t dev) +{ + struct cdev *xsd_cdev; + + xsd_cdev = make_dev(&xsd_dev_cdevsw, 0, UID_ROOT, GID_WHEEL, 0400, + "xen/xenstored"); + if (xsd_cdev == NULL) + return (EINVAL); + + return (0); +} + +/*-------------------- Private Device Attachment Data -----------------------*/ +static device_method_t xsd_dev_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, xsd_dev_identify), + DEVMETHOD(device_probe, xsd_dev_probe), + DEVMETHOD(device_attach, xsd_dev_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(xsd_dev, xsd_dev_driver, xsd_dev_methods, 0); +devclass_t xsd_dev_devclass; + +DRIVER_MODULE(xsd_dev, xenpv, xsd_dev_driver, xsd_dev_devclass, + NULL, NULL);