Module Name:    src
Committed By:   msaitoh
Date:           Thu Oct 19 05:52:57 UTC 2017

Modified Files:
        src/sys/dev/pci: pci_subr.c pcireg.h

Log Message:
 Fix a bug that the TPH ST table is decoded even if it's not in the TPH
Requester extended capability structure.


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/dev/pci/pci_subr.c
cvs rdiff -u -r1.134 -r1.135 src/sys/dev/pci/pcireg.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/dev/pci/pci_subr.c
diff -u src/sys/dev/pci/pci_subr.c:1.193 src/sys/dev/pci/pci_subr.c:1.194
--- src/sys/dev/pci/pci_subr.c:1.193	Thu Oct 12 02:40:34 2017
+++ src/sys/dev/pci/pci_subr.c	Thu Oct 19 05:52:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_subr.c,v 1.193 2017/10/12 02:40:34 msaitoh Exp $	*/
+/*	$NetBSD: pci_subr.c,v 1.194 2017/10/19 05:52:57 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.193 2017/10/12 02:40:34 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.194 2017/10/19 05:52:57 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -3499,15 +3499,15 @@ pci_conf_print_dpa_cap(const pcireg_t *r
 }
 
 static const char *
-pci_conf_print_tph_req_cap_sttabloc(unsigned char val)
+pci_conf_print_tph_req_cap_sttabloc(uint8_t val)
 {
 
 	switch (val) {
-	case 0x0:
+	case PCI_TPH_REQ_STTBLLOC_NONE:
 		return "Not Present";
-	case 0x1:
+	case PCI_TPH_REQ_STTBLLOC_TPHREQ:
 		return "in the TPH Requester Capability Structure";
-	case 0x2:
+	case PCI_TPH_REQ_STTBLLOC_MSIX:
 		return "in the MSI-X Table";
 	default:
 		return "Unknown";
@@ -3519,6 +3519,7 @@ pci_conf_print_tph_req_cap(const pcireg_
 {
 	pcireg_t reg;
 	int size, i, j;
+	uint8_t sttbloc;
 
 	printf("\n  TPH Requester Extended Capability\n");
 
@@ -3528,9 +3529,9 @@ pci_conf_print_tph_req_cap(const pcireg_
 	onoff("Interrupt Vector Mode Supported", reg, PCI_TPH_REQ_CAP_INTVEC);
 	onoff("Device Specific Mode Supported", reg, PCI_TPH_REQ_CAP_DEVSPEC);
 	onoff("Extend TPH Reqester Supported", reg, PCI_TPH_REQ_CAP_XTPHREQ);
+	sttbloc = __SHIFTOUT(reg, PCI_TPH_REQ_CAP_STTBLLOC);
 	printf("      ST Table Location: %s\n",
-	    pci_conf_print_tph_req_cap_sttabloc(
-		    (unsigned char)__SHIFTOUT(reg, PCI_TPH_REQ_CAP_STTBLLOC)));
+	    pci_conf_print_tph_req_cap_sttabloc(sttbloc));
 	size = __SHIFTOUT(reg, PCI_TPH_REQ_CAP_STTBLSIZ) + 1;
 	printf("      ST Table Size: %d\n", size);
 
@@ -3566,7 +3567,10 @@ pci_conf_print_tph_req_cap(const pcireg_
 		printf("(reserved vaule)\n");
 		break;
 	}
-	
+
+	if (sttbloc != PCI_TPH_REQ_STTBLLOC_TPHREQ)
+		return;
+
 	for (i = 0; i < size ; i += 2) {
 		reg = regs[o2i(extcapoff + PCI_TPH_REQ_STTBL + i / 2)];
 		for (j = 0; j < 2 ; j++) {

Index: src/sys/dev/pci/pcireg.h
diff -u src/sys/dev/pci/pcireg.h:1.134 src/sys/dev/pci/pcireg.h:1.135
--- src/sys/dev/pci/pcireg.h:1.134	Tue Oct 10 03:11:01 2017
+++ src/sys/dev/pci/pcireg.h	Thu Oct 19 05:52:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcireg.h,v 1.134 2017/10/10 03:11:01 msaitoh Exp $	*/
+/*	$NetBSD: pcireg.h,v 1.135 2017/10/19 05:52:57 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1999, 2000
@@ -1904,6 +1904,9 @@ struct pci_rom {
 #define	PCI_TPH_REQ_CAP_DEVSPEC	__BIT(2)   /* Device Specific Mode Supported */
 #define	PCI_TPH_REQ_CAP_XTPHREQ	__BIT(8)    /* Extend TPH Reqester Supported */
 #define	PCI_TPH_REQ_CAP_STTBLLOC __BITS(10, 9)	/* ST Table Location */
+#define	PCI_TPH_REQ_STTBLLOC_NONE 	0	/* not present */
+#define	PCI_TPH_REQ_STTBLLOC_TPHREQ 	1	/* in the TPHREQ cap */
+#define	PCI_TPH_REQ_STTBLLOC_MSIX 	2	/* in the MSI-X table */
 #define	PCI_TPH_REQ_CAP_STTBLSIZ __BITS(26, 16)	/* ST Table Size */
 #define	PCI_TPH_REQ_CTL	0x08	/* TPH Requester Control */
 #define	PCI_TPH_REQ_CTL_STSEL	__BITS(2, 0)	/* ST Mode Select */

Reply via email to