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 * make it possible for rumpcomp_pci_...



details:   https://anonhg.NetBSD.org/src/rev/05511b8e45eb
branches:  trunk
changeset: 328714:05511b8e45eb
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Apr 14 21:43:00 2014 +0000

description:
* make it possible for rumpcomp_pci_intr_establish() to know which
  device it's establishing the interrupt for
* make it possible to implement bus_dmamem_map() properly

diffstat:

 sys/rump/dev/lib/libpci/pci_user.h        |  14 ++++++++++--
 sys/rump/dev/lib/libpci/rumpdev_bus_dma.c |  32 ++++++++++++++++++++++++------
 sys/rump/dev/lib/libpci/rumpdev_pci.c     |  22 +++++++++++++++++---
 3 files changed, 54 insertions(+), 14 deletions(-)

diffs (161 lines):

diff -r f75d95276d1c -r 05511b8e45eb sys/rump/dev/lib/libpci/pci_user.h
--- a/sys/rump/dev/lib/libpci/pci_user.h        Mon Apr 14 21:36:22 2014 +0000
+++ b/sys/rump/dev/lib/libpci/pci_user.h        Mon Apr 14 21:43:00 2014 +0000
@@ -2,10 +2,18 @@
 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 *);
+int rumpcomp_pci_irq_map(unsigned, unsigned, unsigned, int, unsigned);
+void *rumpcomp_pci_irq_establish(unsigned, int (*)(void *), void *);
 
 /* XXX: needs work: support boundary-restricted allocations */
-int rumpcomp_pci_dmalloc(size_t, size_t, unsigned long *);
+int rumpcomp_pci_dmalloc(size_t, size_t, unsigned long *, unsigned long *);
 
-void *rumpcomp_pci_mach_to_virt(unsigned long);
+struct rumpcomp_pci_dmaseg {
+       unsigned long ds_pa;
+       unsigned long ds_len;
+       unsigned long ds_vacookie;
+};
+int rumpcomp_pci_dmamem_map(struct rumpcomp_pci_dmaseg *, size_t, size_t,
+                           void **);
+
 unsigned long rumpcomp_pci_virt_to_mach(void *);
diff -r f75d95276d1c -r 05511b8e45eb sys/rump/dev/lib/libpci/rumpdev_bus_dma.c
--- a/sys/rump/dev/lib/libpci/rumpdev_bus_dma.c Mon Apr 14 21:36:22 2014 +0000
+++ b/sys/rump/dev/lib/libpci/rumpdev_bus_dma.c Mon Apr 14 21:43:00 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpdev_bus_dma.c,v 1.2 2014/04/11 01:03:08 pooka Exp $        */
+/*     $NetBSD: rumpdev_bus_dma.c,v 1.3 2014/04/14 21:43:00 pooka Exp $        */
 
 /*-
  * Copyright (c) 2013 Antti Kantee
@@ -458,12 +458,25 @@
 bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
        size_t size, void **kvap, int flags)
 {
+       struct rumpcomp_pci_dmaseg *dss;
+       size_t allocsize = nsegs * sizeof(*dss);
+       int rv, i;
 
-       if (nsegs != 1)
-               panic("bus_dmamem_map: only nsegs == 1 supported");
-       *kvap = rumpcomp_pci_mach_to_virt(segs[0].ds_addr);
+       /*
+        * Though rumpcomp_pci_dmaseg "accidentally" matches the
+        * bus_dma segment descriptor (at least for now), act
+        * proper and actually translate it.
+        */
+       dss = kmem_alloc(allocsize, KM_SLEEP);
+       for (i = 0; i < nsegs; i++) {
+               dss[i].ds_pa = segs[i].ds_addr;
+               dss[i].ds_len = segs[i].ds_len;
+               dss[i].ds_vacookie = segs[i]._ds_vacookie;
+       }
+       rv = rumpcomp_pci_dmamem_map(dss, nsegs, size, kvap);
+       kmem_free(dss, allocsize);
 
-       return 0;
+       return rv;
 }
 
 /*
@@ -495,6 +508,7 @@
        int flags)
 {
        paddr_t curaddr, lastaddr, pa;
+       vaddr_t vacookie;
        int curseg, error;
 
        /* Always round the size. */
@@ -509,7 +523,7 @@
 #else
        /* XXX: ignores boundary, nsegs, etc. */
        //printf("dma allocation %lx %lx %d\n", alignment, boundary, nsegs);
-       error = rumpcomp_pci_dmalloc(size, alignment, &pa);
+       error = rumpcomp_pci_dmalloc(size, alignment, &pa, &vacookie);
 #endif
        if (error)
                return (error);
@@ -521,10 +535,13 @@
        curseg = 0;
        lastaddr = segs[curseg].ds_addr = pa;
        segs[curseg].ds_len = PAGE_SIZE;
+       segs[curseg]._ds_vacookie = vacookie;
        size -= PAGE_SIZE;
        pa += PAGE_SIZE;
+       vacookie += PAGE_SIZE;
 
-       for (; size; pa += PAGE_SIZE, size -= PAGE_SIZE) {
+       for (; size;
+           pa += PAGE_SIZE, vacookie += PAGE_SIZE, size -= PAGE_SIZE) {
                curaddr = pa;
                if (curaddr == (lastaddr + PAGE_SIZE) &&
                    (lastaddr & boundary) == (curaddr & boundary)) {
@@ -535,6 +552,7 @@
                                return EFBIG;
                        segs[curseg].ds_addr = curaddr;
                        segs[curseg].ds_len = PAGE_SIZE;
+                       segs[curseg]._ds_vacookie = vacookie;
                }
                lastaddr = curaddr;
        }
diff -r f75d95276d1c -r 05511b8e45eb sys/rump/dev/lib/libpci/rumpdev_pci.c
--- a/sys/rump/dev/lib/libpci/rumpdev_pci.c     Mon Apr 14 21:36:22 2014 +0000
+++ b/sys/rump/dev/lib/libpci/rumpdev_pci.c     Mon Apr 14 21:43:00 2014 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpdev_pci.c,v 1.1 2014/04/04 12:53:59 pooka Exp $   */
+/*      $NetBSD: rumpdev_pci.c,v 1.2 2014/04/14 21:43:00 pooka Exp $   */
 
 /*
  * Copyright (c) 2013 Antti Kantee.  All Rights Reserved.
@@ -26,10 +26,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpdev_pci.c,v 1.1 2014/04/04 12:53:59 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpdev_pci.c,v 1.2 2014/04/14 21:43:00 pooka Exp $");
 
 #include <sys/cdefs.h>
 #include <sys/param.h>
+#include <sys/atomic.h>
 
 #include <dev/pci/pcivar.h>
 
@@ -108,11 +109,24 @@
        *fp = (*t >> 0)  & 0xff;
 }
 
+/*
+ * Well, yay, deal with the wonders of weird_t.  We'll just
+ * assume it's an integral type (which, btw, isn't universally true).
+ * The hypercall will map "cookie" to its internal structure.
+ * Dial _t for a good time.
+ */
 int
 pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ih)
 {
+       static unsigned int intrhandle;
+       unsigned cookie;
+       int rv;
 
-       *ih = pa->pa_intrline;
+       cookie = atomic_inc_uint_nv(&intrhandle);
+       rv = rumpcomp_pci_irq_map(pa->pa_bus,
+           pa->pa_device, pa->pa_function, pa->pa_intrline, cookie);
+       if (rv == 0)
+               *ih = cookie;
        return 0;
 }
 
@@ -132,7 +146,7 @@
 }
 
 void
-pci_intr_disestablish(pci_chipset_tag_t pc, void *ih)
+pci_intr_disestablish(pci_chipset_tag_t pc, void *not_your_above_ih)
 {
 
        panic("%s: unimplemented", __func__);



Home | Main Index | Thread Index | Old Index