Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/dev/lib/libpci Add a rump kernel component for the ...



details:   https://anonhg.NetBSD.org/src/rev/ccac5a324d4a
branches:  trunk
changeset: 328484:ccac5a324d4a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Apr 04 12:53:59 2014 +0000

description:
Add a rump kernel component for the PCI bus.  It works both in Xen DomU
(via Xen's PCI passthrough) and Linux userspace (via uio_pci_generic).

diffstat:

 sys/rump/dev/lib/libpci/Makefile            |   29 +
 sys/rump/dev/lib/libpci/PCI.ioconf          |   12 +
 sys/rump/dev/lib/libpci/opt/opt_pci.h       |    1 +
 sys/rump/dev/lib/libpci/pci_at_mainbus.c    |   75 +++
 sys/rump/dev/lib/libpci/pci_user.h          |   11 +
 sys/rump/dev/lib/libpci/rumpdev_bus_dma.c   |  548 ++++++++++++++++++++++++++++
 sys/rump/dev/lib/libpci/rumpdev_bus_space.c |  177 +++++++++
 sys/rump/dev/lib/libpci/rumpdev_pci.c       |  139 +++++++
 sys/rump/dev/lib/libpci/shlib_version       |    2 +
 9 files changed, 994 insertions(+), 0 deletions(-)

diffs (truncated from 1030 to 300 lines):

diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/Makefile  Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,29 @@
+#      $NetBSD: Makefile,v 1.1 2014/04/04 12:53:59 pooka Exp $
+#
+
+RUMPTOP= ${TOPRUMP}
+
+.PATH: ${RUMPTOP}/../dev/pci
+
+LIB=   rumpdev_pci
+IOCONF=        PCI.ioconf
+
+SRCS+= pci.c pci_map.c pci_quirks.c pci_subr.c pci_stub.c pci_usrreq.c
+SRCS+= pcibusprint.c
+
+SRCS+= rumpdev_pci.c
+
+# ok, these don't _really_ belong here, but it's the only
+# place they're currently useful, so let it slide
+SRCS+= rumpdev_bus_space.c
+SRCS+= rumpdev_bus_dma.c
+
+SRCS+= pci_at_mainbus.c
+
+CPPFLAGS+= -I${.CURDIR}/opt -I${RUMPTOP}/librump/rumpkern
+
+#RUMPCOMP_USER_SRCS=   pci_user.c
+
+.include "${RUMPTOP}/Makefile.rump"
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/PCI.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/PCI.ioconf        Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,12 @@
+#      $NetBSD: PCI.ioconf,v 1.1 2014/04/04 12:53:59 pooka Exp $
+#
+
+ioconf pci
+
+include "conf/files"
+include "dev/pci/files.pci"
+include "rump/dev/files.rump"
+
+pseudo-root mainbus*
+
+pci*    at mainbus? bus ?
diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/opt/opt_pci.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/opt/opt_pci.h     Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,1 @@
+/*     $NetBSD: opt_pci.h,v 1.1 2014/04/04 12:53:59 pooka Exp $        */
diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/pci_at_mainbus.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/pci_at_mainbus.c  Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,75 @@
+/*     $NetBSD: pci_at_mainbus.c,v 1.1 2014/04/04 12:53:59 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  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 ``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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pci_at_mainbus.c,v 1.1 2014/04/04 12:53:59 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/mbuf.h>
+#include <sys/stat.h>
+#include <sys/bus.h>
+
+#include <dev/pci/pcivar.h>
+#include <machine/bus_private.h>
+
+#include "ioconf.c"
+
+#include "rump_private.h"
+
+RUMP_COMPONENT(RUMP_COMPONENT_DEV)
+{
+
+       config_init_component(cfdriver_ioconf_pci,
+           cfattach_ioconf_pci, cfdata_ioconf_pci);
+}
+
+RUMP_COMPONENT(RUMP_COMPONENT_DEV_AFTERMAINBUS)
+{
+       struct pcibus_attach_args pba;
+       device_t mainbus;
+
+       /* XXX: attach args should come from elsewhere */
+       memset(&pba, 0, sizeof(pba));
+       pba.pba_iot = (bus_space_tag_t)0;
+       pba.pba_memt = (bus_space_tag_t)1;
+       pba.pba_dmat = (void *)0x20;
+#ifdef _LP64
+       pba.pba_dmat64 = (void *)0x40;
+#endif
+       pba.pba_flags = PCI_FLAGS_MEM_OKAY |
+           PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;;
+#if 0
+       pba.pba_flags |= PCI_FLAGS_IO_OKAY;
+#endif
+
+       mainbus = device_find_by_driver_unit("mainbus", 0);
+       if (!mainbus)
+               panic("no mainbus.  use maintaxi instead?");
+       config_found_ia(mainbus, "pcibus", &pba, pcibusprint);
+}
diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/pci_user.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/pci_user.h        Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,11 @@
+void *rumpcomp_pci_map(unsigned long, unsigned long);
+int rumpcomp_pci_confread(unsigned, unsigned, unsigned, int, unsigned int *);
+int rumpcomp_pci_confwrite(unsigned, unsigned, unsigned, int, unsigned int); 
+
+void *rumpcomp_pci_irq_establish(int, int (*)(void *), void *);
+
+/* XXX: needs work: support boundary-restricted allocations */
+int rumpcomp_pci_dmalloc(size_t, size_t, unsigned long *);
+
+void *rumpcomp_pci_mach_to_virt(unsigned long);
+unsigned long rumpcomp_pci_virt_to_mach(void *);
diff -r 26640fee34be -r ccac5a324d4a sys/rump/dev/lib/libpci/rumpdev_bus_dma.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libpci/rumpdev_bus_dma.c Fri Apr 04 12:53:59 2014 +0000
@@ -0,0 +1,548 @@
+/*     $NetBSD: rumpdev_bus_dma.c,v 1.1 2014/04/04 12:53:59 pooka Exp $        */
+
+/*-
+ * Copyright (c) 2013 Antti Kantee
+ * 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 FOUNDATION 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.
+ */
+
+/*-
+ * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * bus_dma(9) implementation which runs on top of rump kernel hypercalls.
+ * It's essentially the same as the PowerPC implementation its based on,
+ * except with some indirection and PowerPC MD features removed.
+ * This should/could be expected to run on x86, other archs may need
+ * some cache flushing hooks.
+ *
+ * From sys/arch/powerpc/powerpc/bus_dma.c:
+ *     NetBSD: bus_dma.c,v 1.46 2012/02/01 09:54:03 matt Exp
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/bus.h>
+#include <sys/intr.h>
+
+#include <uvm/uvm.h>
+
+#include "pci_user.h"
+
+#define        EIEIO   membar_sync()
+
+int    _bus_dmamap_load_buffer (bus_dma_tag_t, bus_dmamap_t, void *,
+           bus_size_t, struct vmspace *, int, paddr_t *, int *, int);
+
+#undef PHYS_TO_BUS_MEM
+#define PHYS_TO_BUS_MEM(_t_, _a_) rumpcomp_pci_virt_to_mach((void *)_a_)
+#undef BUS_MEM_TO_PHYS
+#define BUS_MEM_TO_PHYS(_t_, _a_) rumpcomp_pci_mach_to_virt(_a_)
+
+/*
+ * Common function for DMA map creation.  May be called by bus-specific
+ * DMA map creation functions.
+ */
+int
+bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
+       bus_size_t maxsegsz, bus_size_t boundary, int flags,
+       bus_dmamap_t *dmamp)
+{
+       bus_dmamap_t map;
+       void *mapstore;
+       size_t mapsize;
+
+       /*
+        * Allocate and initialize the DMA map.  The end of the map
+        * is a variable-sized array of segments, so we allocate enough
+        * room for them in one shot.
+        *
+        * Note we don't preserve the WAITOK or NOWAIT flags.  Preservation
+        * of ALLOCNOW notifies others that we've reserved these resources,
+        * and they are not to be freed.
+        *
+        * The bus_dmamap_t includes one bus_dma_segment_t, hence
+        * the (nsegments - 1).
+        */
+       mapsize = sizeof(*map) + sizeof(bus_dma_segment_t [nsegments - 1]);
+       if ((mapstore = kmem_intr_alloc(mapsize,
+           (flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
+               return (ENOMEM);
+
+       memset(mapstore, 0, mapsize);
+       map = (void *)mapstore;
+       map->_dm_size = size;
+       map->_dm_segcnt = nsegments;
+       map->_dm_maxmaxsegsz = maxsegsz;
+       map->_dm_boundary = boundary;
+       map->_dm_bounce_thresh = 0;
+       map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT);
+       map->dm_maxsegsz = maxsegsz;
+       map->dm_mapsize = 0;            /* no valid mappings */
+       map->dm_nsegs = 0;
+
+       *dmamp = map;
+       return (0);
+}
+
+/*
+ * Common function for DMA map destruction.  May be called by bus-specific
+ * DMA map destruction functions.
+ */
+void
+bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
+{
+
+       size_t mapsize = sizeof(*map)



Home | Main Index | Thread Index | Old Index