Module Name: src Committed By: msaitoh Date: Thu Aug 13 04:39:33 UTC 2015
Modified Files: src/sys/arch/x86/include: pci_machdep_common.h src/sys/arch/x86/pci: msipic.c pci_intr_machdep.c pci_msi_machdep.c src/sys/dev/pci: pci.c pcivar.h Log Message: - Don't take pci_attach_args as an argument in pci_msi[x]_count(). - Move prototypes of pci_msi[x]_count() from x86/x86/pci_machdep_common to sys/dev/pci/pcivar.h. - Move pci_msi[x]_count() from x86/pci/pci_msi_machdep.c to sys/dev/pci/pci.c To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/include/pci_machdep_common.h cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/pci/msipic.c cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/pci/pci_intr_machdep.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/pci/pci_msi_machdep.c cvs rdiff -u -r1.146 -r1.147 src/sys/dev/pci/pci.c cvs rdiff -u -r1.102 -r1.103 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.19 src/sys/arch/x86/include/pci_machdep_common.h:1.20 --- src/sys/arch/x86/include/pci_machdep_common.h:1.19 Tue Jul 21 03:10:42 2015 +++ src/sys/arch/x86/include/pci_machdep_common.h Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep_common.h,v 1.19 2015/07/21 03:10:42 knakahara Exp $ */ +/* $NetBSD: pci_machdep_common.h,v 1.20 2015/08/13 04:39:33 msaitoh Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. @@ -145,14 +145,12 @@ int pci_intr_alloc(const struct pci_att pci_intr_handle_t **, int *, pci_intr_type_t); /* experimental MSI support */ -int pci_msi_count(const struct pci_attach_args *); int pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **, int *); int pci_msi_alloc_exact(const struct pci_attach_args *, pci_intr_handle_t **, int); /* experimental MSI-X support */ -int pci_msix_count(const struct pci_attach_args *); int pci_msix_alloc(const struct pci_attach_args *, pci_intr_handle_t **, int *); int pci_msix_alloc_exact(const struct pci_attach_args *, Index: src/sys/arch/x86/pci/msipic.c diff -u src/sys/arch/x86/pci/msipic.c:1.5 src/sys/arch/x86/pci/msipic.c:1.6 --- src/sys/arch/x86/pci/msipic.c:1.5 Tue Aug 11 04:04:36 2015 +++ src/sys/arch/x86/pci/msipic.c Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: msipic.c,v 1.5 2015/08/11 04:04:36 msaitoh Exp $ */ +/* $NetBSD: msipic.c,v 1.6 2015/08/13 04:39:33 msaitoh Exp $ */ /* * Copyright (c) 2015 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.5 2015/08/11 04:04:36 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.6 2015/08/13 04:39:33 msaitoh Exp $"); #include "opt_intrdebug.h" @@ -622,7 +622,7 @@ msipic_construct_msix_pic(const struct p int bir, bar, err, off, table_nentry; char pic_name_buf[MSIPICNAMEBUF]; - table_nentry = pci_msix_count(pa); + table_nentry = pci_msix_count(pa->pa_pc, pa->pa_tag); if (table_nentry == 0) { DPRINTF(("MSI-X table entry is 0.\n")); return NULL; Index: src/sys/arch/x86/pci/pci_intr_machdep.c diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.35 src/sys/arch/x86/pci/pci_intr_machdep.c:1.36 --- src/sys/arch/x86/pci/pci_intr_machdep.c:1.35 Fri Jul 24 06:49:58 2015 +++ src/sys/arch/x86/pci/pci_intr_machdep.c Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_intr_machdep.c,v 1.35 2015/07/24 06:49:58 knakahara Exp $ */ +/* $NetBSD: pci_intr_machdep.c,v 1.36 2015/08/13 04:39:33 msaitoh 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.35 2015/07/24 06:49:58 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.36 2015/08/13 04:39:33 msaitoh Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -490,7 +490,7 @@ pci_intr_alloc(const struct pci_attach_a /* try MSI-X */ if (msix_count == -1) /* use hardware max */ - msix_count = pci_msix_count(pa); + msix_count = pci_msix_count(pa->pa_pc, pa->pa_tag); if (msix_count > 0) { error = pci_msix_alloc_exact(pa, ihps, msix_count); if (error == 0) { @@ -503,7 +503,7 @@ pci_intr_alloc(const struct pci_attach_a /* try MSI */ if (msi_count == -1) /* use hardware max */ - msi_count = pci_msi_count(pa); + msi_count = pci_msi_count(pa->pa_pc, pa->pa_tag); if (msi_count > 0) { error = pci_msi_alloc_exact(pa, ihps, msi_count); if (error == 0) { Index: src/sys/arch/x86/pci/pci_msi_machdep.c diff -u src/sys/arch/x86/pci/pci_msi_machdep.c:1.7 src/sys/arch/x86/pci/pci_msi_machdep.c:1.8 --- src/sys/arch/x86/pci/pci_msi_machdep.c:1.7 Tue Aug 11 04:04:36 2015 +++ src/sys/arch/x86/pci/pci_msi_machdep.c Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_msi_machdep.c,v 1.7 2015/08/11 04:04:36 msaitoh Exp $ */ +/* $NetBSD: pci_msi_machdep.c,v 1.8 2015/08/13 04:39:33 msaitoh 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.7 2015/08/11 04:04:36 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_msi_machdep.c,v 1.8 2015/08/13 04:39:33 msaitoh Exp $"); #include "opt_intrdebug.h" @@ -472,35 +472,6 @@ x86_pci_msix_disestablish(pci_chipset_ta */ /* - * return number of the devices's MSI vectors - * return 0 if the device does not support MSI - */ -int -pci_msi_count(const struct pci_attach_args *pa) -{ - pci_chipset_tag_t pc; - pcitag_t tag; - pcireg_t reg; - uint32_t mmc; - int count, offset; - - pc = pa->pa_pc; - tag = pa->pa_tag; - if (pci_get_capability(pc, tag, PCI_CAP_MSI, &offset, NULL) == 0) - return 0; - - reg = pci_conf_read(pc, tag, offset + PCI_MSI_CTL); - mmc = PCI_MSI_CTL_MMC(reg); - count = 1 << mmc; - if (count > PCI_MSI_MAX_VECTORS) { - aprint_error("detect an illegal device! The device use reserved MMC values.\n"); - return 0; - } - - return count; -} - -/* * This function is used by device drivers like pci_intr_map(). * * "ihps" is the array of vector numbers which MSI used instead of IRQ number. @@ -518,7 +489,7 @@ pci_msi_alloc(const struct pci_attach_ar KASSERT(*count > 0); KASSERT(((*count - 1) & *count) == 0); - hw_max = pci_msi_count(pa); + hw_max = pci_msi_count(pa->pa_pc, pa->pa_tag); if (hw_max == 0) return ENODEV; @@ -548,7 +519,7 @@ pci_msi_alloc_exact(const struct pci_att KASSERT(count > 0); KASSERT(((count - 1) & count) == 0); - hw_max = pci_msi_count(pa); + hw_max = pci_msi_count(pa->pa_pc, pa->pa_tag); if (hw_max == 0) return ENODEV; @@ -561,28 +532,6 @@ pci_msi_alloc_exact(const struct pci_att } /* - * return number of the devices's MSI-X vectors - * return 0 if the device does not support MSI-X - */ -int -pci_msix_count(const struct pci_attach_args *pa) -{ - pci_chipset_tag_t pc; - pcitag_t tag; - pcireg_t reg; - int offset; - - pc = pa->pa_pc; - tag = pa->pa_tag; - if (pci_get_capability(pc, tag, PCI_CAP_MSIX, &offset, NULL) == 0) - return 0; - - reg = pci_conf_read(pc, tag, offset + PCI_MSIX_CTL); - - return PCI_MSIX_CTL_TBLSIZE(reg); -} - -/* * This function is used by device drivers like pci_intr_map(). * * "ihps" is the array of vector numbers which MSI-X used instead of IRQ number. @@ -597,7 +546,7 @@ pci_msix_alloc(const struct pci_attach_a KASSERT(*count > 0); - hw_max = pci_msix_count(pa); + hw_max = pci_msix_count(pa->pa_pc, pa->pa_tag); if (hw_max == 0) return ENODEV; @@ -624,7 +573,7 @@ pci_msix_alloc_exact(const struct pci_at KASSERT(count > 0); - hw_max = pci_msix_count(pa); + hw_max = pci_msix_count(pa->pa_pc, pa->pa_tag); if (hw_max == 0) return ENODEV; @@ -658,7 +607,7 @@ pci_msix_alloc_map(const struct pci_atta KASSERT(count > 0); - hw_max = pci_msix_count(pa); + hw_max = pci_msix_count(pa->pa_pc, pa->pa_tag); if (hw_max == 0) return ENODEV; Index: src/sys/dev/pci/pci.c diff -u src/sys/dev/pci/pci.c:1.146 src/sys/dev/pci/pci.c:1.147 --- src/sys/dev/pci/pci.c:1.146 Mon Apr 27 07:03:58 2015 +++ src/sys/dev/pci/pci.c Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pci.c,v 1.146 2015/04/27 07:03:58 knakahara Exp $ */ +/* $NetBSD: pci.c,v 1.147 2015/08/13 04:39:33 msaitoh Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998 @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.146 2015/04/27 07:03:58 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.147 2015/08/13 04:39:33 msaitoh Exp $"); #include "opt_pci.h" @@ -568,6 +568,49 @@ pci_get_ht_capability(pci_chipset_tag_t return 0; } +/* + * return number of the devices's MSI vectors + * return 0 if the device does not support MSI + */ +int +pci_msi_count(pci_chipset_tag_t pc, pcitag_t tag) +{ + pcireg_t reg; + uint32_t mmc; + int count, offset; + + if (pci_get_capability(pc, tag, PCI_CAP_MSI, &offset, NULL) == 0) + return 0; + + reg = pci_conf_read(pc, tag, offset + PCI_MSI_CTL); + mmc = PCI_MSI_CTL_MMC(reg); + count = 1 << mmc; + if (count > PCI_MSI_MAX_VECTORS) { + aprint_error("detect an illegal device! The device use reserved MMC values.\n"); + return 0; + } + + return count; +} + +/* + * return number of the devices's MSI-X vectors + * return 0 if the device does not support MSI-X + */ +int +pci_msix_count(pci_chipset_tag_t pc, pcitag_t tag) +{ + pcireg_t reg; + int offset; + + if (pci_get_capability(pc, tag, PCI_CAP_MSIX, &offset, NULL) == 0) + return 0; + + reg = pci_conf_read(pc, tag, offset + PCI_MSIX_CTL); + + return PCI_MSIX_CTL_TBLSIZE(reg); +} + int pci_find_device(struct pci_attach_args *pa, int (*match)(const struct pci_attach_args *)) Index: src/sys/dev/pci/pcivar.h diff -u src/sys/dev/pci/pcivar.h:1.102 src/sys/dev/pci/pcivar.h:1.103 --- src/sys/dev/pci/pcivar.h:1.102 Mon Apr 27 07:03:58 2015 +++ src/sys/dev/pci/pcivar.h Thu Aug 13 04:39:33 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pcivar.h,v 1.102 2015/04/27 07:03:58 knakahara Exp $ */ +/* $NetBSD: pcivar.h,v 1.103 2015/08/13 04:39:33 msaitoh Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -280,6 +280,8 @@ int pci_find_rom(const struct pci_attach int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); int pci_get_ht_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); +int pci_msi_count(pci_chipset_tag_t, pcitag_t); +int pci_msix_count(pci_chipset_tag_t, pcitag_t); /* * Helper functions for autoconfiguration.