Subject: bin/24459: enhancement to pcictl
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <chuck_tuffli@agilent.com>
List: netbsd-bugs
Date: 02/17/2004 19:40:20
>Number:         24459
>Category:       bin
>Synopsis:       enhancement to pcictl
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 17 19:41:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Chuck Tuffli
>Release:        -current
>Organization:
Agilent Technologies
>Environment:
NetBSD tsdktest18.rose.agilent.com 1.6.1 NetBSD 1.6.1 (GENERIC) #0: Tue Apr  8 12:05:52 UTC 2003     autobuild@tgm.daemon.org:/autobuild/netbsd-1-6/i386/OBJ/autobuild/netbsd-1-6/src/sys/arch/i386/compile/GENERIC i386

>Description:
Adds a new command ("capability") to pcictl. capability walks a device's capabilities list and reports what if finds. E.g.

% pcictl pci2 capability
004:01:0: Intel i82545EM Gigabit Ethernet (1000BASE-T) (ethernet network, revision 0x01)
        PCI Power Management Interface
        PCI-X device
        Message Signaled Interrupts (MSI)
...
>How-To-Repeat:

>Fix:
Index: pcictl.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pcictl/pcictl.c,v
retrieving revision 1.7
diff -u -r1.7 pcictl.c
--- pcictl.c	2004/01/05 23:23:38	1.7
+++ pcictl.c	2004/02/17 19:18:01
@@ -77,6 +77,7 @@
 
 void	cmd_list(int, char *[]);
 void	cmd_dump(int, char *[]);
+void	cmd_cap(int, char *[]);
 
 const struct command commands[] = {
 	{ "list",
@@ -89,6 +90,11 @@
 	  cmd_dump,
 	  O_RDONLY },
 
+	{ "capability",
+	  "[-b bus] [-d device] [-f function]",
+	  cmd_cap,
+	  O_RDONLY },
+
 	{ 0 },
 };
 
@@ -98,6 +104,7 @@
 
 void	scan_pci_list(u_int, u_int, u_int);
 void	scan_pci_dump(u_int, u_int, u_int);
+void	scan_pci_cap(u_int, u_int, u_int);
 
 int
 main(int argc, char *argv[])
@@ -230,6 +237,39 @@
 	scan_pci(bus, dev, func, scan_pci_dump);
 }
 
+void
+cmd_cap(int argc, char *argv[])
+{
+	int bus, dev, func;
+	int ch;
+
+	bus = pci_businfo.busno;
+	dev = func = -1;
+
+	while ((ch = getopt(argc, argv, "b:d:f:")) != -1) {
+		switch (ch) {
+		case 'b':
+			bus = parse_bdf(optarg);
+			break;
+		case 'd':
+			dev = parse_bdf(optarg);
+			break;
+		case 'f':
+			func = parse_bdf(optarg);
+			break;
+		default:
+			usage();
+		}
+	}
+	argv += optind;
+	argc -= optind;
+
+	if (argc != 0)
+		usage();
+
+	scan_pci(bus, dev, func, scan_pci_cap);
+}
+
 int
 parse_bdf(const char *str)
 {
@@ -323,4 +363,76 @@
 {
 
 	pci_conf_print(pcifd, bus, dev, func);
+}
+
+void
+scan_pci_cap(u_int bus, u_int dev, u_int func)
+{
+	pcireg_t status, offset, cap;
+
+	scan_pci_list(bus, dev, func);
+
+	if (pcibus_conf_read(pcifd, bus, dev, func, PCI_COMMAND_STATUS_REG,
+				&status) != 0) {
+		return;
+	}
+	
+	if (status & PCI_STATUS_CAPLIST_SUPPORT) {
+		if (pcibus_conf_read(pcifd, bus, dev, func, PCI_CAPLISTPTR_REG,
+					&offset) != 0) {
+			return;
+		}
+		do {
+			if (pcibus_conf_read(pcifd, bus, dev, func, offset, &cap) != 0) {
+				return;
+			}
+			printf("\t");
+			switch (PCI_CAPLIST_CAP(cap)) {
+			case PCI_CAP_PWRMGMT:
+				printf("PCI Power Management Interface");
+				break;
+			case PCI_CAP_AGP:
+				printf("AGP");
+				break;
+			case PCI_CAP_VPD:
+				printf("Vital Product Data (VPD)");
+				break;
+			case PCI_CAP_SLOTID:
+				printf("Slot Identification");
+				break;
+			case PCI_CAP_MSI:
+				printf("Message Signaled Interrupts (MSI)");
+				break;
+			case PCI_CAP_CPCI_HOTSWAP:
+				printf("CompactPCI Hot Swap");
+				break;
+			case PCI_CAP_PCIX:
+				printf("PCI-X device");
+				break;
+			case PCI_CAP_LDT:
+				printf("Reserved for AMD");
+				break;
+			case PCI_CAP_VENDSPEC:
+				printf("Vendor Specific capability register");
+				break;
+			case PCI_CAP_DEBUGPORT:
+				printf("Debug port");
+				break;
+			case PCI_CAP_CPCI_RSRCCTL:
+				printf("CompactPCI central resource control");
+				break;
+			case PCI_CAP_HOTPLUG:
+				printf("PCI Hot-Plug");
+				break;
+			case PCI_CAP_PCIEXPRESS:
+				printf("PCI-Express device");
+				break;
+			default:
+				printf("Reserved");
+			}
+			printf("\n");
+
+			offset = PCI_CAPLIST_NEXT(cap);
+		} while (offset != 0);
+	}
 }

>Release-Note:
>Audit-Trail:
>Unformatted: