Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Cleanup:



details:   https://anonhg.NetBSD.org/src/rev/bdd0d10ee16b
branches:  trunk
changeset: 359147:bdd0d10ee16b
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Feb 01 08:18:47 2018 +0000

description:
Cleanup:
- Don't pass a capability pointer as a argument of pci_conf_find_cap() and
  determine the first pointer in the pci_conf_find_cap() function.
- Don't pass a capability pointer as a argument of pci_conf_find_extcap()
  because it's not used.
- Remove unsed code.

diffstat:

 sys/dev/pci/pci_subr.c |  103 ++++++++++++++++++++++++++----------------------
 1 files changed, 55 insertions(+), 48 deletions(-)

diffs (truncated from 365 to 300 lines):

diff -r fadb853f1b50 -r bdd0d10ee16b sys/dev/pci/pci_subr.c
--- a/sys/dev/pci/pci_subr.c    Thu Feb 01 07:49:19 2018 +0000
+++ b/sys/dev/pci/pci_subr.c    Thu Feb 01 08:18:47 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_subr.c,v 1.198 2018/02/01 02:50:51 msaitoh Exp $   */
+/*     $NetBSD: pci_subr.c,v 1.199 2018/02/01 08:18:47 msaitoh Exp $   */
 
 /*
  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.198 2018/02/01 02:50:51 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.199 2018/02/01 08:18:47 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -70,7 +70,8 @@
 #include <dev/pci/pcidevs_data.h>
 #endif
 
-static int pci_conf_find_cap(const pcireg_t *, int, unsigned int, int *);
+static int pci_conf_find_cap(const pcireg_t *, unsigned int, int *);
+static int pci_conf_find_extcap(const pcireg_t *, unsigned int, int *);
 static void pci_conf_print_pcie_power(uint8_t, unsigned int);
 
 /*
@@ -831,8 +832,7 @@
                int pcie_capoff;
                pcireg_t reg;
 
-               if (pci_conf_find_cap(regs, PCI_CAPLISTPTR_REG,
-                   PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
+               if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
                        reg = regs[o2i(pcie_capoff + PCIE_XCAP)];
                        if (PCIE_XCAP_TYPE(reg) == PCIE_XCAP_TYPE_ROOT_EVNTC)
                                subclass = PCI_SUBCLASS_SYSTEM_RCEC;
@@ -2446,13 +2446,29 @@
 };
 
 static int
-pci_conf_find_cap(const pcireg_t *regs, int capoff, unsigned int capid,
-    int *offsetp)
+pci_conf_find_cap(const pcireg_t *regs, unsigned int capid, int *offsetp)
 {
        pcireg_t rval;
+       unsigned int capptr;
        int off;
 
-       for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
+       if (!(regs[o2i(PCI_COMMAND_STATUS_REG)] & PCI_STATUS_CAPLIST_SUPPORT))
+               return 0;
+
+       /* Determine the Capability List Pointer register to start with. */
+       switch (PCI_HDRTYPE_TYPE(regs[o2i(PCI_BHLC_REG)])) {
+       case 0: /* standard device header */
+       case 1: /* PCI-PCI bridge header */
+               capptr = PCI_CAPLISTPTR_REG;
+               break;
+       case 2: /* PCI-CardBus Bridge header */
+               capptr = PCI_CARDBUS_CAPLISTPTR_REG;
+               break;
+       default:
+               return 0;
+       }
+       
+       for (off = PCI_CAPLIST_PTR(regs[o2i(capptr)]);
             off != 0; off = PCI_CAPLIST_NEXT(rval)) {
                rval = regs[o2i(off)];
                if (capid == PCI_CAPLIST_CAP(rval)) {
@@ -2511,13 +2527,6 @@
                 * the same. This is required because some capabilities
                 * appear multiple times (e.g. HyperTransport capability).
                 */
-#if 0
-               if (pci_conf_find_cap(regs, capoff, i, &off)) {
-                       rval = regs[o2i(off)];
-                       if (pci_captab[i].printfunc != NULL)
-                               pci_captab[i].printfunc(regs, off);
-               }
-#else
                for (off = PCI_CAPLIST_PTR(regs[o2i(capoff)]);
                     off != 0; off = PCI_CAPLIST_NEXT(regs[o2i(off)])) {
                        rval = regs[o2i(off)];
@@ -2525,7 +2534,6 @@
                            && (pci_captab[i].printfunc != NULL))
                                pci_captab[i].printfunc(regs, off);
                }
-#endif
        }
 }
 
@@ -2633,14 +2641,14 @@
 }
 
 static void
-pci_conf_print_aer_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_aer_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
        int pcie_capoff;
        int pcie_devtype = -1;
        bool tlp_prefix_log = false;
 
-       if (pci_conf_find_cap(regs, capoff, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
+       if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)) {
                reg = regs[o2i(pcie_capoff)];
                pcie_devtype = PCIE_XCAP_TYPE(reg);
                /* PCIe DW9 to DW14 is for PCIe 2.0 and newer */
@@ -2727,7 +2735,7 @@
 }
 
 static void
-pci_conf_print_vc_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_vc_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, n;
        int parbtab, parbsize;
@@ -2918,7 +2926,7 @@
 }
 
 static void
-pci_conf_print_pwrbdgt_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_pwrbdgt_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
 
@@ -2967,7 +2975,7 @@
 }
 
 static void
-pci_conf_print_rclink_dcl_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_rclink_dcl_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
        unsigned char nent, linktype;
@@ -3046,7 +3054,7 @@
 /* XXX pci_conf_print_rclink_ctl_cap */
 
 static void
-pci_conf_print_rcec_assoc_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_rcec_assoc_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
 
@@ -3064,7 +3072,7 @@
 /* XXX pci_conf_print_cac_cap */
 
 static void
-pci_conf_print_acs_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_acs_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
        unsigned int size, i;
@@ -3107,7 +3115,7 @@
 }
 
 static void
-pci_conf_print_ari_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_ari_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
 
@@ -3129,7 +3137,7 @@
 }
 
 static void
-pci_conf_print_ats_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_ats_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
        unsigned int num;
@@ -3154,7 +3162,7 @@
 }
 
 static void
-pci_conf_print_sernum_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_sernum_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t lo, hi;
 
@@ -3168,7 +3176,7 @@
 }
 
 static void
-pci_conf_print_sriov_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_sriov_cap(const pcireg_t *regs, int extcapoff)
 {
        char buf[sizeof("99999 MB")];
        pcireg_t reg;
@@ -3280,7 +3288,7 @@
 /* XXX pci_conf_print_mriov_cap */
 
 static void
-pci_conf_print_multicast_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_multicast_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
        pcireg_t regl, regh;
@@ -3348,7 +3356,7 @@
 }
 
 static void
-pci_conf_print_page_req_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_page_req_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, ctl, sta;
 
@@ -3379,7 +3387,7 @@
 #define MEM_PBUFSIZE   sizeof("999GB")
 
 static void
-pci_conf_print_resizbar_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_resizbar_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t cap, ctl;
        unsigned int bars, i, n;
@@ -3436,7 +3444,7 @@
 }
 
 static void
-pci_conf_print_dpa_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_dpa_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
        unsigned int substmax, i;
@@ -3516,7 +3524,7 @@
 }
 
 static void
-pci_conf_print_tph_req_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_tph_req_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
        int size, i, j;
@@ -3587,7 +3595,7 @@
 }
 
 static void
-pci_conf_print_ltr_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_ltr_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
 
@@ -3604,7 +3612,7 @@
 }
 
 static void
-pci_conf_print_sec_pcie_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_sec_pcie_cap(const pcireg_t *regs, int extcapoff)
 {
        int pcie_capoff;
        pcireg_t reg;
@@ -3626,7 +3634,7 @@
        printf("    Lane Error Status register: 0x%08x\n", reg);
 
        /* Get Max Link Width */
-       if (pci_conf_find_cap(regs, capoff, PCI_CAP_PCIEXPRESS, &pcie_capoff)){
+       if (pci_conf_find_cap(regs, PCI_CAP_PCIEXPRESS, &pcie_capoff)){
                reg = regs[o2i(pcie_capoff + PCIE_LCAP)];
                maxlinkwidth = __SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH);
        } else {
@@ -3657,7 +3665,7 @@
 /* XXX pci_conf_print_pmux_cap */
 
 static void
-pci_conf_print_pasid_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_pasid_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
        unsigned int num;
@@ -3680,7 +3688,7 @@
 }
 
 static void
-pci_conf_print_lnr_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_lnr_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl;
        unsigned int num;
@@ -3718,7 +3726,7 @@
 }
 
 static void
-pci_conf_print_dpc_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_dpc_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg, cap, ctl, stat, errsrc;
        const char *trigstr;
@@ -3861,7 +3869,7 @@
 }
 
 static void
-pci_conf_print_l1pm_cap(const pcireg_t *regs, int capoff, int extcapoff)
+pci_conf_print_l1pm_cap(const pcireg_t *regs, int extcapoff)
 {
        pcireg_t reg;
        int scale, val;
@@ -3911,7 +3919,7 @@



Home | Main Index | Thread Index | Old Index