Subject: Re: losing with i815, NetBSD 1.6-stable, current xsrc
To: None <port-i386@netbsd.org>
From: Greg Troxel <gdt@ir.bbn.com>
List: port-i386
Date: 07/07/2003 10:01:24
A long time ago (January 2003) I wrote:

  I have a Dell desktop with i810/i815 graphics, and am trying to get X
  working.  I built xsrc today after from cvs updating from anoncvs.
  The kernel and userland are from netbsd-1-6 on 2002-11-20.

  I get this in XFree86.0.log:

    (WW) I810(0): xf86BindGARTMemory: binding of gart memory with key 15
            at offset 0x0 failed (Cannot allocate memory)

  and this in dmesg

    agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing

I added a bunch of debug printfs (patch at end) to get more details
when allocation fails.  Since then, I've been starting xdm at boot,
logging in and out every day, and not having problems.  Today, someone
else asked me about my status, and I replied that it was ok.

Then, I was in a text console rebuilding gnome packages, and for some
reason the X server had exited.   '/etc/rc.d/xdm start' did not
start up the server, and I find in dmesg

  agp0: about to bind individual pages
  agp0: about to bind individual pages
  agp0: about to bind individual pages

apparently successful

  agp0: contigpages down to 0!

note that his happens once before the PGTBL_CTL lines

  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!
  agp_i810_bind_memory: PGTBL_CTL is 0x0 - fixing
  agp0: contigpages down to 0!


top shows the system with little free memory (1-2MB), but huge amounts of
inactive  and file (total 512M).  While trying to grab a top line, it
freed up lot of memory:

Memory: 110M Act, 14M Inact, 1968K Wired, 7952K Exec, 50M File, 322M Free

but xdm still would not start (same kernel messages as above) and X reports:

(WW) I810(0): xf86BindGARTMemory: binding of gart memory with key 116
	at offset 0x0 failed (Cannot allocate memory)


Two questions arise:

should the AGP binding code provoke freeing of file/inactive memory,
if there isn't enough to get video memory?

is there something else wrong?

        Greg Troxel <gdt@ir.bbn.com>

Index: agp.c
===================================================================
RCS file: /QUIST-CVS/netbsd/src/sys/dev/pci/agp.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 agp.c
--- agp.c	2003/02/06 13:29:12	1.1.1.2
+++ agp.c	2003/03/05 14:33:29
@@ -515,6 +515,8 @@
 		nseg = (mem->am_size / (contigpages * PAGE_SIZE)) + 1;
 		segs = malloc(nseg * sizeof *segs, M_AGP, M_WAITOK);
 		if (segs == NULL) {
+			printf("%s: can't allocate %d bus_dma_segment_t (size 0x%x)\n",
+			       sc->as_dev.dv_xname, nseg, (int) mem->am_size);
 			lockmgr(&sc->as_lock, LK_RELEASE, 0);
 			return ENOMEM;
 		}
@@ -544,10 +546,13 @@
 	}
 
 	if (contigpages == 0) {
+		printf("%s: contigpages down to 0!\n",
+		       sc->as_dev.dv_xname);
 		lockmgr(&sc->as_lock, LK_RELEASE, 0);
 		return ENOMEM;
 	}
 
+	printf("%s: about to bind individual pages\n", sc->as_dev.dv_xname);
 
 	/*
 	 * Bind the individual pages and flush the chipset's
@@ -583,6 +588,8 @@
 				bus_dmamem_free(sc->as_dmat, mem->am_dmaseg,
 						mem->am_nseg);
 				free(mem->am_dmaseg, M_AGP);
+				printf("%s, error %d in AGP_BIND_PAGE\n",
+				       sc->as_dev.dv_xname, error);
 				lockmgr(&sc->as_lock, LK_RELEASE, 0);
 				return error;
 			}