Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86 unify INTx, MSI and MSI-X APIs without alloc. (...



details:   https://anonhg.NetBSD.org/src/rev/c048529c149f
branches:  trunk
changeset: 808366:c048529c149f
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Fri May 15 08:26:44 2015 +0000

description:
unify INTx, MSI and MSI-X APIs without alloc. (alloc API is under discussion)

diffstat:

 sys/arch/x86/include/pci_machdep_common.h |  14 ++-------
 sys/arch/x86/pci/pci_intr_machdep.c       |  38 +++++++++++++++++++++----
 sys/arch/x86/pci/pci_msi_machdep.c        |  33 ++++++++++------------
 sys/arch/x86/pci/pci_msi_machdep.h        |  44 +++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 35 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 757c8685d5a5 -r c048529c149f sys/arch/x86/include/pci_machdep_common.h
--- a/sys/arch/x86/include/pci_machdep_common.h Fri May 15 08:19:48 2015 +0000
+++ b/sys/arch/x86/include/pci_machdep_common.h Fri May 15 08:26:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep_common.h,v 1.16 2015/05/08 04:27:48 knakahara Exp $        */
+/*     $NetBSD: pci_machdep_common.h,v 1.17 2015/05/15 08:26:44 knakahara Exp $        */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -127,7 +127,6 @@
  */
 int            pci_intx_alloc(const struct pci_attach_args *,
                    pci_intr_handle_t **);
-void           pci_intx_release(pci_chipset_tag_t, pci_intr_handle_t *);
 
 /* experimental MSI support */
 const char     *pci_msi_string(pci_chipset_tag_t, pci_intr_handle_t, char *, size_t);
@@ -136,10 +135,6 @@
                    pci_intr_handle_t **, int *);
 int            pci_msi_alloc_exact(const struct pci_attach_args *,
                    pci_intr_handle_t **, int);
-void           pci_msi_release(pci_chipset_tag_t, pci_intr_handle_t **, int);
-void           *pci_msi_establish(pci_chipset_tag_t, pci_intr_handle_t,
-                   int, int (*)(void *), void *);
-void           pci_msi_disestablish(pci_chipset_tag_t, void *);
 
 /* experimental MSI-X support */
 int            pci_msix_count(const struct pci_attach_args *);
@@ -149,10 +144,9 @@
                    pci_intr_handle_t **, int);
 int            pci_msix_alloc_map(const struct pci_attach_args *,
                    pci_intr_handle_t **, u_int *, int);
-void           pci_msix_release(pci_chipset_tag_t, pci_intr_handle_t **, int);
-void           *pci_msix_establish(pci_chipset_tag_t, pci_intr_handle_t,
-                   int, int (*)(void *), void *);
-void           pci_msix_disestablish(pci_chipset_tag_t, void *);
+
+void           pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *,
+                   int);
 
 /*
  * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED
diff -r 757c8685d5a5 -r c048529c149f sys/arch/x86/pci/pci_intr_machdep.c
--- a/sys/arch/x86/pci/pci_intr_machdep.c       Fri May 15 08:19:48 2015 +0000
+++ b/sys/arch/x86/pci/pci_intr_machdep.c       Fri May 15 08:26:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_intr_machdep.c,v 1.30 2015/04/27 07:03:58 knakahara Exp $  */
+/*     $NetBSD: pci_intr_machdep.c,v 1.31 2015/05/15 08:26:44 knakahara Exp $  */
 
 /*-
  * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.30 2015/04/27 07:03:58 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.31 2015/05/15 08:26:44 knakahara Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -102,6 +102,7 @@
 #include <machine/mpconfig.h>
 #include <machine/mpbiosvar.h>
 #include <machine/pic.h>
+#include <x86/pci/pci_msi_machdep.h>
 #endif
 
 #ifdef MPBIOS
@@ -292,6 +293,13 @@
                    pc, ih, level, func, arg);
        }
 
+       if (INT_VIA_MSI(ih)) {
+               if (MSI_INT_IS_MSIX(ih))
+                       return x86_pci_msix_establish(pc, ih, level, func, arg);
+               else
+                       return x86_pci_msi_establish(pc, ih, level, func, arg);
+       }
+
        pic = &i8259_pic;
        pin = irq = APIC_IRQ_LEGACY_IRQ(ih);
        mpsafe = ((ih & MPSAFE_MASK) != 0);
@@ -328,6 +336,7 @@
                return;
        }
 
+       /* MSI/MSI-X processing is switched in intr_disestablish(). */
        intr_disestablish(cookie);
 }
 
@@ -381,15 +390,12 @@
        return error;
 }
 
-void
-pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih)
+static void
+x86_pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih)
 {
        char intrstr_buf[INTRIDBUF];
        const char *intrstr;
 
-       if (pih == NULL)
-               return;
-
        intrstr = pci_intr_string(NULL, *pih, intrstr_buf, sizeof(intrstr_buf));
        mutex_enter(&cpu_lock);
        intr_free_io_intrsource(intrstr);
@@ -397,4 +403,22 @@
 
        kmem_free(pih, sizeof(*pih));
 }
+
+void
+pci_intr_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih, int count)
+{
+       if (pih == NULL)
+               return;
+
+       if (INT_VIA_MSI(*pih)) {
+               if (MSI_INT_IS_MSIX(*pih))
+                       return x86_pci_msix_release(pc, pih, count);
+               else
+                       return x86_pci_msi_release(pc, pih, count);
+       } else {
+               KASSERT(count == 1);
+               return x86_pci_intx_release(pc, pih);
+       }
+
+}
 #endif
diff -r 757c8685d5a5 -r c048529c149f sys/arch/x86/pci/pci_msi_machdep.c
--- a/sys/arch/x86/pci/pci_msi_machdep.c        Fri May 15 08:19:48 2015 +0000
+++ b/sys/arch/x86/pci/pci_msi_machdep.c        Fri May 15 08:26:44 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_msi_machdep.c,v 1.2 2015/05/08 04:27:48 knakahara Exp $    */
+/*     $NetBSD: pci_msi_machdep.c,v 1.3 2015/05/15 08:26:44 knakahara Exp $    */
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_msi_machdep.c,v 1.2 2015/05/08 04:27:48 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_msi_machdep.c,v 1.3 2015/05/15 08:26:44 knakahara Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -53,6 +53,7 @@
 #include <machine/pic.h>
 
 #include <x86/pci/msipic.h>
+#include <x86/pci/pci_msi_machdep.h>
 
 #ifdef INTRDEBUG
 #define MSIDEBUG
@@ -242,17 +243,15 @@
 }
 
 static void
-pci_msi_release_md(pci_intr_handle_t **pihs, int count)
+pci_msi_release_md(pci_intr_handle_t *pihs, int count)
 {
        struct pic *pic;
-       pci_intr_handle_t *vectors;
 
-       vectors = *pihs;
-       pic = msipic_find_msi_pic(MSI_INT_DEV(vectors[0]));
+       pic = msipic_find_msi_pic(MSI_INT_DEV(pihs[0]));
        if (pic == NULL)
                return;
 
-       pci_msi_free_vectors(pic, vectors, count);
+       pci_msi_free_vectors(pic, pihs, count);
        msipic_destruct_msi_pic(pic);
 }
 
@@ -359,17 +358,15 @@
 }
 
 static void
-pci_msix_release_md(pci_intr_handle_t **pihs, int count)
+pci_msix_release_md(pci_intr_handle_t *pihs, int count)
 {
        struct pic *pic;
-       pci_intr_handle_t *vectors;
 
-       vectors = *pihs;
-       pic = msipic_find_msi_pic(MSI_INT_DEV(vectors[0]));
+       pic = msipic_find_msi_pic(MSI_INT_DEV(pihs[0]));
        if (pic == NULL)
                return;
 
-       pci_msi_free_vectors(pic, vectors, count);
+       pci_msi_free_vectors(pic, pihs, count);
        msipic_destruct_msix_pic(pic);
 }
 
@@ -471,7 +468,7 @@
  * Release MSI handles.
  */
 void
-pci_msi_release(pci_chipset_tag_t pc, pci_intr_handle_t **pihs, int count)
+x86_pci_msi_release(pci_chipset_tag_t pc, pci_intr_handle_t *pihs, int count)
 {
 
        if (count < 1)
@@ -486,7 +483,7 @@
  * this function for each handle.
  */
 void *
-pci_msi_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih,
+x86_pci_msi_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih,
     int level, int (*func)(void *), void *arg)
 {
        struct pic *pic;
@@ -506,7 +503,7 @@
  * this function for each handle.
  */
 void
-pci_msi_disestablish(pci_chipset_tag_t pc, void *cookie)
+x86_pci_msi_disestablish(pci_chipset_tag_t pc, void *cookie)
 {
 
        pci_msi_common_disestablish(pc, cookie);
@@ -646,7 +643,7 @@
  * Release MSI-X handles.
  */
 void
-pci_msix_release(pci_chipset_tag_t pc, pci_intr_handle_t **pihs, int count)
+x86_pci_msix_release(pci_chipset_tag_t pc, pci_intr_handle_t *pihs, int count)
 {
 
        if (count < 1)
@@ -661,7 +658,7 @@
  * this function for each handle.
  */
 void *
-pci_msix_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih,
+x86_pci_msix_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih,
     int level, int (*func)(void *), void *arg)
 {
        struct pic *pic;
@@ -681,7 +678,7 @@
  * this function for each handle.
  */
 void
-pci_msix_disestablish(pci_chipset_tag_t pc, void *cookie)
+x86_pci_msix_disestablish(pci_chipset_tag_t pc, void *cookie)
 {
 
        pci_msi_common_disestablish(pc, cookie);
diff -r 757c8685d5a5 -r c048529c149f sys/arch/x86/pci/pci_msi_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/pci/pci_msi_machdep.h        Fri May 15 08:26:44 2015 +0000
@@ -0,0 +1,44 @@
+/*     $NetBSD: pci_msi_machdep.h,v 1.1 2015/05/15 08:26:44 knakahara Exp $    */
+
+/*
+ * Copyright (c) 2015 Internet Initiative Japan Inc.
+ * 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 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.
+ */
+
+#ifndef _X86_PCI_PCI_MSI_MACHDEP_H_
+#define _X86_PCI_PCI_MSI_MACHDEP_H_
+
+void           x86_pci_msi_release(pci_chipset_tag_t, pci_intr_handle_t *,
+                   int);
+void           *x86_pci_msi_establish(pci_chipset_tag_t, pci_intr_handle_t,
+                   int, int (*)(void *), void *);
+void           x86_pci_msi_disestablish(pci_chipset_tag_t, void *);
+
+void           x86_pci_msix_release(pci_chipset_tag_t, pci_intr_handle_t *,
+                   int);
+void           *x86_pci_msix_establish(pci_chipset_tag_t, pci_intr_handle_t,
+                   int, int (*)(void *), void *);
+void           x86_pci_msix_disestablish(pci_chipset_tag_t, void *);
+



Home | Main Index | Thread Index | Old Index