Module Name:    src
Committed By:   knakahara
Date:           Fri May 15 08:26:44 UTC 2015

Modified Files:
        src/sys/arch/x86/include: pci_machdep_common.h
        src/sys/arch/x86/pci: pci_intr_machdep.c pci_msi_machdep.c
Added Files:
        src/sys/arch/x86/pci: pci_msi_machdep.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/include/pci_machdep_common.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/pci/pci_intr_machdep.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/pci/pci_msi_machdep.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/x86/pci/pci_msi_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/pci_machdep_common.h
diff -u src/sys/arch/x86/include/pci_machdep_common.h:1.16 src/sys/arch/x86/include/pci_machdep_common.h:1.17
--- src/sys/arch/x86/include/pci_machdep_common.h:1.16	Fri May  8 04:27:48 2015
+++ src/sys/arch/x86/include/pci_machdep_common.h	Fri May 15 08:26:44 2015
@@ -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_intr_distribute(void *, const k
  */
 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 @@ int		pci_msi_alloc(const struct pci_atta
 		    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 @@ int		pci_msix_alloc_exact(const struct p
 		    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

Index: src/sys/arch/x86/pci/pci_intr_machdep.c
diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.30 src/sys/arch/x86/pci/pci_intr_machdep.c:1.31
--- src/sys/arch/x86/pci/pci_intr_machdep.c:1.30	Mon Apr 27 07:03:58 2015
+++ src/sys/arch/x86/pci/pci_intr_machdep.c	Fri May 15 08:26:44 2015
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_mac
 #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 @@ pci_intr_establish(pci_chipset_tag_t pc,
 		    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 @@ pci_intr_disestablish(pci_chipset_tag_t 
 		return;
 	}
 
+	/* MSI/MSI-X processing is switched in intr_disestablish(). */
 	intr_disestablish(cookie);
 }
 
@@ -381,15 +390,12 @@ error:
 	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 @@ pci_intx_release(pci_chipset_tag_t pc, p
 
 	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

Index: src/sys/arch/x86/pci/pci_msi_machdep.c
diff -u src/sys/arch/x86/pci/pci_msi_machdep.c:1.2 src/sys/arch/x86/pci/pci_msi_machdep.c:1.3
--- src/sys/arch/x86/pci/pci_msi_machdep.c:1.2	Fri May  8 04:27:48 2015
+++ src/sys/arch/x86/pci/pci_msi_machdep.c	Fri May 15 08:26:44 2015
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pci_msi_mach
 #include <machine/pic.h>
 
 #include <x86/pci/msipic.h>
+#include <x86/pci/pci_msi_machdep.h>
 
 #ifdef INTRDEBUG
 #define MSIDEBUG
@@ -242,17 +243,15 @@ pci_msi_alloc_exact_md(pci_intr_handle_t
 }
 
 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 @@ pci_msix_alloc_map_md(pci_intr_handle_t 
 }
 
 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 @@ pci_msi_alloc_exact(const struct pci_att
  * 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 @@ pci_msi_release(pci_chipset_tag_t pc, pc
  * 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 @@ pci_msi_establish(pci_chipset_tag_t pc, 
  * 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 @@ pci_msix_alloc_map(const struct pci_atta
  * 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 @@ pci_msix_release(pci_chipset_tag_t pc, p
  * 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 @@ pci_msix_establish(pci_chipset_tag_t pc,
  * 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);

Added files:

Index: src/sys/arch/x86/pci/pci_msi_machdep.h
diff -u /dev/null src/sys/arch/x86/pci/pci_msi_machdep.h:1.1
--- /dev/null	Fri May 15 08:26:44 2015
+++ src/sys/arch/x86/pci/pci_msi_machdep.h	Fri May 15 08:26:44 2015
@@ -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 *);
+
+#endif /* _X86_PCI_PCI_MSI_MACHDEP_H_ */

Reply via email to