Module Name: src Committed By: knakahara Date: Thu Oct 22 09:45:32 UTC 2015
Modified Files: src/sys/arch/x86/include: pci_machdep_common.h src/sys/dev/pci: pci_stub.c pcivar.h Log Message: add pci_intr_alloc related stubs to reduce ifdef from device drivers. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/include/pci_machdep_common.h cvs rdiff -u -r1.3 -r1.4 src/sys/dev/pci/pci_stub.c cvs rdiff -u -r1.105 -r1.106 src/sys/dev/pci/pcivar.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.21 src/sys/arch/x86/include/pci_machdep_common.h:1.22 --- src/sys/arch/x86/include/pci_machdep_common.h:1.21 Mon Aug 17 06:16:02 2015 +++ src/sys/arch/x86/include/pci_machdep_common.h Thu Oct 22 09:45:32 2015 @@ -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 @@ void *pci_intr_establish(pci_chipset_ta 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 @@ typedef enum { } 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 @@ pci_intr_type_t pci_intr_type(pci_intr_h 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_exact(const struct p 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. Index: src/sys/dev/pci/pci_stub.c diff -u src/sys/dev/pci/pci_stub.c:1.3 src/sys/dev/pci/pci_stub.c:1.4 --- src/sys/dev/pci/pci_stub.c:1.3 Mon Aug 24 23:55:04 2015 +++ src/sys/dev/pci/pci_stub.c Thu Oct 22 09:45:32 2015 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pci_stub.c,v #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_bus_devorder(pci_chipset 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_bus_devorder, de __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 @@ default_pci_chipset_tag_create(pci_chips 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) Index: src/sys/dev/pci/pcivar.h diff -u src/sys/dev/pci/pcivar.h:1.105 src/sys/dev/pci/pcivar.h:1.106 --- src/sys/dev/pci/pcivar.h:1.105 Fri Oct 2 05:22:53 2015 +++ src/sys/dev/pci/pcivar.h Thu Oct 22 09:45:32 2015 @@ -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 @@ void pci_chipset_tag_destroy(pci_chipset 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.