From owner-svn-src-head@FreeBSD.ORG Wed Nov 19 14:49:30 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 44B996EC; Wed, 19 Nov 2014 14:49:30 +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 25608A2; Wed, 19 Nov 2014 14:49:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAJEnU40028695; Wed, 19 Nov 2014 14:49:30 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAJEnTj7028693; Wed, 19 Nov 2014 14:49:29 GMT (envelope-from br@FreeBSD.org) Message-Id: <201411191449.sAJEnTj7028693@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Wed, 19 Nov 2014 14:49:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274714 - head/sys/dev/beri/virtio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Nov 2014 14:49:30 -0000 Author: br Date: Wed Nov 19 14:49:29 2014 New Revision: 274714 URL: https://svnweb.freebsd.org/changeset/base/274714 Log: Add BERI-specific virtio mmio "platform" device. This device provides a connector to Altera PIO allowing us to interrupt software-implemented virtio mmio backend. Sponsored by: DARPA, AFRL Added: head/sys/dev/beri/virtio/ head/sys/dev/beri/virtio/virtio_mmio_platform.c (contents, props changed) head/sys/dev/beri/virtio/virtio_mmio_platform.h (contents, props changed) Added: head/sys/dev/beri/virtio/virtio_mmio_platform.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/beri/virtio/virtio_mmio_platform.c Wed Nov 19 14:49:29 2014 (r274714) @@ -0,0 +1,227 @@ +/*- + * Copyright (c) 2014 Ruslan Bukin + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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. + */ + +/* + * BERI interface for Virtio MMIO bus. + * + * This driver provides interrupt-engine for software-implemented + * Virtio MMIO backend. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "virtio_mmio_if.h" +#include "pio_if.h" + +static void platform_intr(void *arg); + +struct virtio_mmio_platform_softc { + struct resource *res[1]; + bus_space_tag_t bst; + bus_space_handle_t bsh; + device_t dev; + void (*intr_handler)(void *); + void *ih_user; + device_t pio_recv; + device_t pio_send; +}; + +static int +setup_pio(struct virtio_mmio_platform_softc *sc, char *name, device_t *dev) +{ + phandle_t pio_node; + struct fdt_ic *ic; + phandle_t xref; + phandle_t node; + + if ((node = ofw_bus_get_node(sc->dev)) == -1) + return (ENXIO); + + if (OF_searchencprop(node, name, &xref, + sizeof(xref)) == -1) { + return (ENXIO); + } + + pio_node = OF_node_from_xref(xref); + SLIST_FOREACH(ic, &fdt_ic_list_head, fdt_ics) { + if (ic->iph == pio_node) { + *dev = ic->dev; + PIO_CONFIGURE(*dev, PIO_OUT_ALL, + PIO_UNMASK_ALL); + return (0); + } + } + + return (ENXIO); +} + +static int +virtio_mmio_platform_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "beri,virtio_mmio_platform")) + return (ENXIO); + + device_set_desc(dev, "Virtio MMIO platform"); + return (BUS_PROBE_DEFAULT); +} + +static int +virtio_mmio_platform_attach(device_t dev) +{ + struct virtio_mmio_platform_softc *sc; + struct fdt_ic *fic; + phandle_t node; + + sc = device_get_softc(dev); + sc->dev = dev; + + if (setup_pio(sc, "pio-send", &sc->pio_send) != 0) + return (ENXIO); + if (setup_pio(sc, "pio-recv", &sc->pio_recv) != 0) + return (ENXIO); + + if ((node = ofw_bus_get_node(sc->dev)) == -1) + return (ENXIO); + + fic = malloc(sizeof(*fic), M_DEVBUF, M_WAITOK|M_ZERO); + fic->iph = node; + fic->dev = dev; + SLIST_INSERT_HEAD(&fdt_ic_list_head, fic, fdt_ics); + + return (0); +} + +static int +platform_note(device_t dev, size_t offset) +{ + struct virtio_mmio_platform_softc *sc; + + sc = device_get_softc(dev); + + if (offset == VIRTIO_MMIO_QUEUE_NOTIFY) { + mips_dcache_wbinv_all(); + PIO_SET(sc->pio_send, Q_NOTIFY, 1); + } + + if (offset == VIRTIO_MMIO_QUEUE_PFN) { + mips_dcache_wbinv_all(); + PIO_SET(sc->pio_send, Q_PFN, 1); + } + + return (0); +} + +static void +platform_intr(void *arg) +{ + struct virtio_mmio_platform_softc *sc; + int reg; + + sc = arg; + + /* Read pending */ + reg = PIO_READ(sc->pio_recv); + + /* Ack */ + PIO_SET(sc->pio_recv, reg, 0); + + /* Writeback, invalidate cache */ + mips_dcache_wbinv_all(); + + if (sc->intr_handler != NULL) + sc->intr_handler(sc->ih_user); +} + +static int +platform_setup_intr(device_t dev, device_t mmio_dev, + void *intr_handler, void *ih_user) +{ + struct virtio_mmio_platform_softc *sc; + + sc = device_get_softc(dev); + + sc->intr_handler = intr_handler; + sc->ih_user = ih_user; + + PIO_SETUP_IRQ(sc->pio_recv, platform_intr, sc); + + return (0); +} + +static device_method_t virtio_mmio_platform_methods[] = { + DEVMETHOD(device_probe, virtio_mmio_platform_probe), + DEVMETHOD(device_attach, virtio_mmio_platform_attach), + + /* virtio_mmio_if.h */ + DEVMETHOD(virtio_mmio_note, platform_note), + DEVMETHOD(virtio_mmio_setup_intr, platform_setup_intr), + DEVMETHOD_END +}; + +static driver_t virtio_mmio_platform_driver = { + "virtio_mmio_platform", + virtio_mmio_platform_methods, + sizeof(struct virtio_mmio_platform_softc), +}; + +static devclass_t virtio_mmio_platform_devclass; + +DRIVER_MODULE(virtio_mmio_platform, simplebus, virtio_mmio_platform_driver, + virtio_mmio_platform_devclass, 0, 0); Added: head/sys/dev/beri/virtio/virtio_mmio_platform.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/beri/virtio/virtio_mmio_platform.h Wed Nov 19 14:49:29 2014 (r274714) @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2014 Ruslan Bukin + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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. + * + * $FreeBSD$ + */ + +#define Q_NOTIFY 0x1 +#define Q_PFN 0x2 +#define Q_INTR 0x4