- 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
This commit is contained in:
msaitoh 2015-08-13 04:39:33 +00:00
parent ef5463a999
commit b62abb6e08
6 changed files with 63 additions and 71 deletions

View File

@ -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_attach_args *,
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 *,

View File

@ -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 pci_attach_args *pa)
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;

View File

@ -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_args *pa, pci_intr_handle_t **ihps,
/* 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_args *pa, pci_intr_handle_t **ihps,
/* 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) {

View File

@ -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"
@ -471,35 +471,6 @@ x86_pci_msix_disestablish(pci_chipset_tag_t pc, void *cookie)
* extern for MI code.
*/
/*
* 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().
*
@ -518,7 +489,7 @@ pci_msi_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
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_attach_args *pa, pci_intr_handle_t **ihps,
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;
@ -560,28 +531,6 @@ pci_msi_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
return x86_pci_msi_alloc_exact(ihps, count, pa);
}
/*
* 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().
*
@ -597,7 +546,7 @@ pci_msix_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
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_attach_args *pa, pci_intr_handle_t **ihps,
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_attach_args *pa, pci_intr_handle_t **ihps,
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;

View File

@ -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 pc, pcitag_t tag, int capid,
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 *))

View File

@ -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_args *, bus_space_tag_t,
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.