Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Oct 2003 01:16:36 +0200
From:      Andrea Cocito <andrea.cocito@ieo-research.it>
To:        freebsd-hackers@freebsd.org
Subject:   agp broken for ali...  this is the patch, PLEASE import it :)
Message-ID:  <A27EE0A6-F5F7-11D7-9328-000A9573A0F0@ieo-research.it>

next in thread | raw e-mail | index | archive | help

--Apple-Mail-5-1016450387
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Hallo,

I sent a temporary patch a while ago, no answer. So sorry for
the report but *please* fix this: this makes non-bootable several
laptops and industrial systems.

On some ALI chipsets the agp bus returns an aperture size of zero,
and the kernel panics. The way it is handled for *any* agp bus if
the aperture size is zero (or the window can not be allocated)
is deadly broken.

Attached the patch to fix the broken code and handle it "at the best
effort" as the coded was supposed to do, PLEASE someone import it.
Sorry for attaching it. Is only 4k and I cannot currently send-pr it.

Thanks,

A.


--Apple-Mail-5-1016450387
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="agp.patch"
Content-Disposition: attachment;
	filename=agp.patch

diff -u -r /sys/pci/agp_ali.c /sys_patched/pci/agp_ali.c
--- /sys/pci/agp_ali.c	Mon Aug  4 09:25:13 2003
+++ /sys_patched/pci/agp_ali.c	Tue Aug  5 22:30:17 2003
@@ -101,21 +101,20 @@
 		return error;
 
 	sc->initial_aperture = AGP_GET_APERTURE(dev);
+	gatt = NULL;
 
-	for (;;) {
+	while (AGP_GET_APERTURE(dev) != 0) {
 		gatt = agp_alloc_gatt(dev);
-		if (gatt)
+		if (gatt != NULL)
 			break;
-
-		/*
-		 * Probably contigmalloc failure. Try reducing the
-		 * aperture so that the gatt size reduces.
-		 */
-		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
-			agp_generic_detach(dev);
-			return ENOMEM;
-		}
+		AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2);
+	}
+		
+	if (gatt == NULL) {
+		agp_generic_detach(dev);
+		return ENOMEM;
 	}
+
 	sc->gatt = gatt;
 
 	/* Install the gatt. */
diff -u -r /sys/pci/agp_amd.c /sys_patched/pci/agp_amd.c
--- /sys/pci/agp_amd.c	Mon Aug  4 09:33:42 2003
+++ /sys_patched/pci/agp_amd.c	Tue Aug  5 22:30:56 2003
@@ -239,19 +239,20 @@
 	sc->bsh = rman_get_bushandle(sc->regs);
 
 	sc->initial_aperture = AGP_GET_APERTURE(dev);
+	gatt = NULL;
 
-	for (;;) {
-		gatt = agp_amd_alloc_gatt(dev);
-		if (gatt)
+	while (AGP_GET_APERTURE(dev) != 0) {
+		gatt = agp_amd_alloc_gatt(dev);
+		if (gatt != NULL)
 			break;
+		AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2);
+	}
 
-		/*
-		 * Probably contigmalloc failure. Try reducing the
-		 * aperture so that the gatt size reduces.
-		 */
-		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
-			return ENOMEM;
+	if (gatt == NULL) {
+		agp_generic_detach(dev);
+		return ENOMEM;
 	}
+
 	sc->gatt = gatt;
 
 	/* Install the gatt. */
diff -u -r /sys/pci/agp_intel.c /sys_patched/pci/agp_intel.c
--- /sys/pci/agp_intel.c	Mon Aug  4 09:33:28 2003
+++ /sys_patched/pci/agp_intel.c	Tue Aug  5 22:36:23 2003
@@ -147,21 +147,20 @@
 	    MAX_APSIZE;
 	pci_write_config(dev, AGP_INTEL_APSIZE, value, 1);
 	sc->initial_aperture = AGP_GET_APERTURE(dev);
+	gatt = NULL;
 
-	for (;;) {
+	while (AGP_GET_APERTURE(dev) != 0) {
 		gatt = agp_alloc_gatt(dev);
-		if (gatt)
+		if (gatt != NULL)
 			break;
-
-		/*
-		 * Probably contigmalloc failure. Try reducing the
-		 * aperture so that the gatt size reduces.
-		 */
-		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
-			agp_generic_detach(dev);
-			return ENOMEM;
-		}
+		AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2);
+	}
+		
+	if (gatt == NULL) {
+		agp_generic_detach(dev);
+		return ENOMEM;
 	}
+
 	sc->gatt = gatt;
 
 	/* Install the gatt. */
diff -u -r /sys/pci/agp_sis.c /sys_patched/pci/agp_sis.c
--- /sys/pci/agp_sis.c	Tue Apr 15 06:37:29 2003
+++ /sys_patched/pci/agp_sis.c	Tue Aug  5 22:36:54 2003
@@ -103,21 +103,20 @@
 		return error;
 
 	sc->initial_aperture = AGP_GET_APERTURE(dev);
+	gatt = NULL;
 
-	for (;;) {
+	while (AGP_GET_APERTURE(dev) != 0) {
 		gatt = agp_alloc_gatt(dev);
-		if (gatt)
+		if (gatt != NULL)
 			break;
-
-		/*
-		 * Probably contigmalloc failure. Try reducing the
-		 * aperture so that the gatt size reduces.
-		 */
-		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
-			agp_generic_detach(dev);
-			return ENOMEM;
-		}
+		AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2);
+	}
+		
+	if (gatt == NULL) {
+		agp_generic_detach(dev);
+		return ENOMEM;
 	}
+
 	sc->gatt = gatt;
 
 	/* Install the gatt. */
diff -u -r /sys/pci/agp_via.c /sys_patched/pci/agp_via.c
--- /sys/pci/agp_via.c	Tue Apr 15 06:37:29 2003
+++ /sys_patched/pci/agp_via.c	Tue Aug  5 22:37:15 2003
@@ -109,21 +109,20 @@
 		return error;
 
 	sc->initial_aperture = AGP_GET_APERTURE(dev);
+	gatt = NULL;
 
-	for (;;) {
+	while (AGP_GET_APERTURE(dev) != 0) {
 		gatt = agp_alloc_gatt(dev);
-		if (gatt)
+		if (gatt != NULL)
 			break;
-
-		/*
-		 * Probably contigmalloc failure. Try reducing the
-		 * aperture so that the gatt size reduces.
-		 */
-		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
-			agp_generic_detach(dev);
-			return ENOMEM;
-		}
+		AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2);
+	}
+		
+	if (gatt == NULL) {
+		agp_generic_detach(dev);
+		return ENOMEM;
 	}
+
 	sc->gatt = gatt;
 
 	/* Install the gatt. */

--Apple-Mail-5-1016450387
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



--Apple-Mail-5-1016450387--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A27EE0A6-F5F7-11D7-9328-000A9573A0F0>