Subject: Re: CVS commit: src/sys/dev/pci
To: None <fvdl@netbsd.org, source-changes@NetBSD.org>
From: Charles M. Hannum <abuse@spamalicious.com>
List: source-changes
Date: 11/16/2003 19:43:51
--Boundary-00=_3N9t/y7j45Dlrr1
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Wednesday 05 November 2003 04:03 pm, Frank van der Linden wrote:
> Module Name:	src
> Committed By:	fvdl
> Date:		Wed Nov  5 16:03:28 UTC 2003
>
> Modified Files:
> 	src/sys/dev/pci: amr.c
>
> Log Message:
> Apparently, Dell PERC 4/Di controllers can have two memory BARs, with the
> second one empty. The previous revision made it pick the empty one.
> Reinstate the BAR size check.

Using PCI_MAPREG_*_SIZE() this way is definitely not correct.  It does not do 
what you expect.

I believe the attached patch is a correct "fix".  And I note that cac, mlx and 
mly all have similar code that should be adjusted.

--Boundary-00=_3N9t/y7j45Dlrr1
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="amr-diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
	filename="amr-diff"

Index: amr.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/amr.c,v
retrieving revision 1.19
diff -u -r1.19 amr.c
--- amr.c	5 Nov 2003 16:03:27 -0000	1.19
+++ amr.c	16 Nov 2003 19:44:13 -0000
@@ -269,17 +269,15 @@
 
 	memreg = ioreg = 0;
 	for (i = 0x10; i <= 0x14; i += 4) {
-		reg = pci_conf_read(pc, pa->pa_tag, i);
+		if (pci_mapreg_probe(pc, pa->pa_tag, i, &reg) == 0)
+			continue;
 		switch (PCI_MAPREG_TYPE(reg)) {
 		case PCI_MAPREG_TYPE_MEM:
-			if (PCI_MAPREG_MEM_SIZE(reg) != 0)
-				memreg = i;
+			memreg = i;
 			break;
 		case PCI_MAPREG_TYPE_IO:
-			if (PCI_MAPREG_IO_SIZE(reg) != 0)
-				ioreg = i;
+			ioreg = i;
 			break;
-
 		}
 	}
 

--Boundary-00=_3N9t/y7j45Dlrr1--