Subject: AGP kludge
To: None <tech-kern@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 04/13/2002 19:43:01
--EP0wieDxd4TSJjHq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

So, until the bus_dma problem with the AGP code is addressed, I'd
like to propose the following temporary kludge which allowed me to
get an i815 system up and running with XF 4.2.0 today.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--EP0wieDxd4TSJjHq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=agp-patch

Index: agp.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/pci/agp.c,v
retrieving revision 1.14
diff -u -r1.14 agp.c
--- agp.c	2002/01/22 17:29:36	1.14
+++ agp.c	2002/04/14 02:31:18
@@ -511,6 +511,7 @@
 	 * a bus_dma_segment per page would be overkill.
 	 */
 
+#if 0
 	for (contigpages = 8; contigpages > 0; contigpages >>= 1) {
 		nseg = (mem->am_size / (contigpages * PAGE_SIZE)) + 1;
 		segs = malloc(nseg * sizeof *segs, M_AGP, M_WAITOK);
@@ -539,6 +540,31 @@
 		mem->am_dmaseg = segs;
 		break;
 	}
+#else
+	/*
+	 * XXX THIS IS A DISGUSTING KLUDGE.  But the memory allocator
+	 * XXX used by the bus_dma back-end doesn't do the right thing
+	 * XXX with multiple-segment allocations right now.  However,
+	 * XXX the following should work on any currently-supported
+	 * XXX platform which also supports AGP.
+	 */
+
+	contigpages = 1;
+
+	nseg = (mem->am_size / (contigpages * PAGE_SIZE)) + 1;
+	segs = malloc(nseg * sizeof *segs, M_AGP, M_WAITOK);
+	if (segs == NULL)
+		return ENOMEM;
+	mem->am_virtual = (caddr_t) uvm_km_alloc(kernel_map, mem->am_size);
+	if (bus_dmamap_load(sc->as_dmat, mem->am_dmamap,
+	    mem->am_virtual, mem->am_size, NULL, BUS_DMA_WAITOK) != 0) {
+		uvm_km_free(kernel_map, (vaddr_t) mem->am_virtual,
+		    mem->am_size);
+		free(segs, M_AGP);
+		contigpages = 0;
+	} else
+		mem->am_dmaseg = segs;
+#endif
 
 	if (contigpages == 0) {
 		lockmgr(&sc->as_lock, LK_RELEASE, 0);

--EP0wieDxd4TSJjHq--