Source-Changes-HG archive

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

[src/trunk]: src/sys add pci_intr_alloc related stubs to reduce ifdef from de...



details:   https://anonhg.NetBSD.org/src/rev/a8274f6a5948
branches:  trunk
changeset: 811301:a8274f6a5948
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Thu Oct 22 09:45:32 2015 +0000

description:
add pci_intr_alloc related stubs to reduce ifdef from device drivers.

diffstat:

 sys/arch/x86/include/pci_machdep_common.h |  22 +++++++-------
 sys/dev/pci/pci_stub.c                    |  47 ++++++++++++++++++++++++++++++-
 sys/dev/pci/pcivar.h                      |  16 +++++++++-
 3 files changed, 72 insertions(+), 13 deletions(-)

diffs (170 lines):

diff -r d528571d9b5d -r a8274f6a5948 sys/arch/x86/include/pci_machdep_common.h
--- a/sys/arch/x86/include/pci_machdep_common.h Thu Oct 22 07:00:05 2015 +0000
+++ b/sys/arch/x86/include/pci_machdep_common.h Thu Oct 22 09:45:32 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep_common.h,v 1.21 2015/08/17 06:16:02 knakahara Exp $        */
+/*     $NetBSD: pci_machdep_common.h,v 1.22 2015/10/22 09:45:32 knakahara Exp $        */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -119,6 +119,7 @@
                    int, int (*)(void *), void *);
 void           pci_intr_disestablish(pci_chipset_tag_t, void *);
 
+#ifdef __HAVE_PCI_MSI_MSIX
 typedef enum {
        PCI_INTR_TYPE_INTX = 0,
        PCI_INTR_TYPE_MSI,
@@ -127,6 +128,15 @@
 } pci_intr_type_t;
 
 pci_intr_type_t        pci_intr_type(pci_intr_handle_t);
+/*
+ * Wrapper function for generally unitied allocation to fallback MSI-X/MSI/INTx
+ * automatically.
+ */
+int            pci_intr_alloc(const struct pci_attach_args *,
+                   pci_intr_handle_t **, int *, pci_intr_type_t);
+void           pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *,
+                   int);
+#endif
 
 /*
  * If device drivers use MSI/MSI-X, they should use these API for INTx
@@ -136,13 +146,6 @@
 int            pci_intx_alloc(const struct pci_attach_args *,
                    pci_intr_handle_t **);
 
-/*
- * Wrapper function for generally unitied allocation to fallback MSI-X/MSI/INTx
- * automatically.
- */
-int            pci_intr_alloc(const struct pci_attach_args *,
-                   pci_intr_handle_t **, int *, pci_intr_type_t);
-
 /* experimental MSI support */
 int            pci_msi_alloc(const struct pci_attach_args *,
                    pci_intr_handle_t **, int *);
@@ -157,9 +160,6 @@
 int            pci_msix_alloc_map(const struct pci_attach_args *,
                    pci_intr_handle_t **, u_int *, int);
 
-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
  * BY PORTABLE CODE.
diff -r d528571d9b5d -r a8274f6a5948 sys/dev/pci/pci_stub.c
--- a/sys/dev/pci/pci_stub.c    Thu Oct 22 07:00:05 2015 +0000
+++ b/sys/dev/pci/pci_stub.c    Thu Oct 22 09:45:32 2015 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_stub.c,v 1.3 2015/08/24 23:55:04 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_stub.c,v 1.4 2015/10/22 09:45:32 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -7,6 +7,7 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/kmem.h>
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
@@ -16,6 +17,10 @@
 int default_pci_chipset_tag_create(pci_chipset_tag_t, uint64_t,
     const struct pci_overrides *, void *, pci_chipset_tag_t *);
 void default_pci_chipset_tag_destroy(pci_chipset_tag_t);
+pci_intr_type_t default_pci_intr_type(pci_intr_handle_t);
+int default_pci_intr_alloc(const struct pci_attach_args *,
+    pci_intr_handle_t **, int *, pci_intr_type_t);
+void default_pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int);
 void *default_pci_intr_establish_xname(pci_chipset_tag_t, pci_intr_handle_t,
     int, int (*)(void *), void *, const char *);
 
@@ -23,6 +28,9 @@
 __strict_weak_alias(pci_chipset_tag_create, default_pci_chipset_tag_create);
 __strict_weak_alias(pci_chipset_tag_destroy, default_pci_chipset_tag_destroy);
 
+__strict_weak_alias(pci_intr_type, default_pci_intr_type);
+__strict_weak_alias(pci_intr_alloc, default_pci_intr_alloc);
+__strict_weak_alias(pci_intr_release, default_pci_intr_release);
 __strict_weak_alias(pci_intr_establish_xname, default_pci_intr_establish_xname);
 
 int
@@ -50,6 +58,43 @@
        return EOPNOTSUPP;
 }
 
+pci_intr_type_t
+default_pci_intr_type(pci_intr_handle_t ih)
+{
+
+       return PCI_INTR_TYPE_INTX;
+}
+
+int
+default_pci_intr_alloc(const struct pci_attach_args *pa,
+    pci_intr_handle_t **ihps, int *counts, pci_intr_type_t max_type)
+{
+       pci_intr_handle_t *ihp;
+
+       if (counts != NULL && counts[PCI_INTR_TYPE_INTX] == 0)
+               return EINVAL;
+
+       ihp = kmem_alloc(sizeof(*ihp), KM_SLEEP);
+       if (ihp == NULL)
+               return ENOMEM;
+
+       if (pci_intr_map(pa, ihp)) {
+               kmem_free(ihp, sizeof(*ihp));
+               return EINVAL;
+       }
+
+       ihps[0] = ihp;
+       return 0;
+}
+
+void
+default_pci_intr_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih,
+    int count)
+{
+
+       kmem_free(pih, sizeof(*pih));
+}
+
 void *
 default_pci_intr_establish_xname(pci_chipset_tag_t pc, pci_intr_handle_t ih,
     int level, int (*func)(void *), void *arg, const char *__nouse)
diff -r d528571d9b5d -r a8274f6a5948 sys/dev/pci/pcivar.h
--- a/sys/dev/pci/pcivar.h      Thu Oct 22 07:00:05 2015 +0000
+++ b/sys/dev/pci/pcivar.h      Thu Oct 22 09:45:32 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcivar.h,v 1.105 2015/10/02 05:22:53 msaitoh Exp $     */
+/*     $NetBSD: pcivar.h,v 1.106 2015/10/22 09:45:32 knakahara Exp $   */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -350,6 +350,20 @@
 int    pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
 void   *pci_intr_establish_xname(pci_chipset_tag_t, pci_intr_handle_t,
                                  int, int (*)(void *), void *, const char *);
+#ifndef __HAVE_PCI_MSI_MSIX
+typedef enum {
+       PCI_INTR_TYPE_INTX = 0,
+       PCI_INTR_TYPE_MSI,
+       PCI_INTR_TYPE_MSIX,
+       PCI_INTR_TYPE_SIZE,
+} pci_intr_type_t;
+
+pci_intr_type_t
+       pci_intr_type(pci_intr_handle_t);
+int    pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
+                      int *, pci_intr_type_t);
+void   pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int);
+#endif
 
 /*
  * Device abstraction for inheritance by elanpci(4), for example.



Home | Main Index | Thread Index | Old Index