Subject: kern/19256: agpdev_match does not match agp devices correctly
To: None <gnats-bugs@gnats.netbsd.org>
From: Quentin Garnier <cube@cubidou.net>
List: netbsd-bugs
Date: 12/03/2002 22:18:00
>Number:         19256
>Category:       kern
>Synopsis:       agpdev_match does not match agp devices correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 03 13:19:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        NetBSD 1.6K
>Organization:
>Environment:
	
	
System: NetBSD padme 1.6K NetBSD 1.6K (NVIDIA-$Revision: 1.2 $) #24: Tue Dec 3 20:45:20 CET 2002 cube@padme:/amd/c3po/home/cube/src/nv-netbsd/nvidia_patch/src/sys/arch/i386/compile/NVIDIA i386
Architecture: i386
Machine: i386
>Description:
	
	In src/sys/dev/pci/agp.c, agpdev_match is a matching function used
	with pci_find_device in agp_enable. But agpdev_match only checks
	if the iterated device is a video card, which can be insufficient
	in the case where there is more than one video card and a PCI one
	is tried before the AGP one.
	agpdev_enable then gets an incorrect device and fails.
>How-To-Repeat:
	
	Use agp_enable on a system with both a PCI card and an AGP card.
>Fix:
	
	The following patch fix the bug, although as a side effect
	pci_get_capability is called multiple times, and notably twice
	for the AGP card.

Index: agp.c
===================================================================
RCS file: /rep/CVS/nvidia_patch/src/sys/dev/pci/agp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- agp.c	2002/11/10 19:10:13	1.1
+++ agp.c	2002/12/03 21:08:55	1.2
@@ -358,6 +358,8 @@
 {
 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY &&
 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_DISPLAY_VGA)
+		if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP,
+		    NULL, NULL))
 		return 1;
 
 	return 0;
>Release-Note:
>Audit-Trail:
>Unformatted: