Subject: AGP code
To: None <port-i386@netbsd.org>
From: Frank van der Linden <fvdl@wasabisystems.com>
List: port-i386
Date: 09/10/2001 23:45:21
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

As you may have noticed, added AGP code (derived from the FreeBSD code)
to the tree. It was moderately modified to use bus_dma, etc. I
have only been able to test a few chipsets, unfortunately. So if you
have a VIA, Intel, SiS or AMD chipset with AGP GART support, and
don't mind trying out a -current kernel and a small testprogram,
perhaps you could:

	1) enable "agp* at pchb?" in your kernel config file
	2) mail me what the bootmessages say about agp
	   (should be: "agp0 at pchb0: aperture at xxxx size xxxx")
	3) run 'make includes' in src/sys
	4) compile and run the following small testprogram.

And of course, it crashes, try go get a traceback if you can and
mail that to me..

If it fails to probe agp0, send me a dmesg output of a different,
working kernel, showing which (probed and unprobed) PCI devices
are present.

Currently, there is a problem in the i810 code causing it not
to map the graphics aperture. If you have an i810-based machine
and can test some patches, let me know.

- Frank

-- 
Frank van der Linden                           fvdl@wasabisystems.com
======================================================================
Quality NetBSD CDs, Support & Service.   http://www.wasabisystems.com/

--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="agp.c"

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/agpio.h>
#include <fcntl.h>
#include <err.h>

int
main(int argc, char **argv)
{
	int fd;
	agp_info info;
	agp_allocate alloc;
	agp_setup setup;
	agp_bind bind;
	agp_unbind unbind;

	fd = open("/dev/agp0", O_RDWR);
	if (fd < 0)
		err(1, "open");

	if (ioctl(fd, AGPIOC_INFO, &info) < 0)
		err(2, "ioctl AGPIOC_INFO");

	printf("version:	%u.%u\n", info.version.major,
	    info.version.minor);
	
	printf("id:		%x\n", info.bridge_id);
	printf("mode:		%x\n", info.agp_mode);
	printf("base:		%x\n", info.aper_base);
	printf("size:		%uM\n", info.aper_size);
	printf("total mem:	%u\n", info.pg_total);
	printf("system mem:	%u\n", info.pg_system);
	printf("used mem:	%u\n\n", info.pg_used);

	setup.agp_mode = info.agp_mode;

	if (ioctl(fd, AGPIOC_SETUP, &setup) < 0)
		err(3, "ioctl AGPIOC_SETUP");

	if (ioctl(fd, AGPIOC_ACQUIRE, 0) < 0)
		err(3, "ioctl AGPIOC_ACQUIRE");

	alloc.type = 0;
	alloc.pg_count = 64;

	if (ioctl(fd, AGPIOC_ALLOCATE, &alloc) < 0)
		err(4, "ioctl AGPIOC_ALLOCATE");

	printf("alloc key %d, paddr %x\n", alloc.key, alloc.physical);
	if (ioctl(fd, AGPIOC_INFO, &info) < 0)
		err(5, "ioctl AGPIOC_INFO");

	bind.key = alloc.key;
	bind.pg_start = 0x1000;

	if (ioctl(fd, AGPIOC_BIND, &bind) < 0)
		err(6, "ioctl AGPIOC_BIND");

	printf("used mem now:	%u\n\n", info.pg_used);

	unbind.key = alloc.key;
	unbind.priority = 0;

	if (ioctl(fd, AGPIOC_UNBIND, &unbind) < 0)
		err(6, "ioctl AGPIOC_BIND");

	if (ioctl(fd, AGPIOC_DEALLOCATE, &alloc.key) < 0)
		err(6, "ioctl AGPIOC_DEALLOCATE");

	if (ioctl(fd, AGPIOC_RELEASE, 0) < 0)
		err(7, "ioctl AGPIOC_RELEASE");

	close(fd);

	printf("agp test successful\n");

	return 0;
}

--YZ5djTAD1cGYuMQK--