#include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { agp_info info; agp_allocate alloc; agp_setup setup; agp_bind bind; agp_unbind unbind; int fd; fd = open("/dev/agpgart", 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: %jx\n", (uintmax_t)info.aper_base); printf("size: %juM\n", (uintmax_t)info.aper_size); printf("total mem: %ju\n", (uintmax_t)info.pg_total); printf("system mem: %ju\n", (uintmax_t)info.pg_system); printf("used mem: %ju\n\n", (uintmax_t)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 = 32764 * 1024 >> AGP_PAGE_SHIFT; if (ioctl(fd, AGPIOC_BIND, &bind) < 0) err(6, "ioctl AGPIOC_BIND"); printf("used mem now: %ju\n\n", (uintmax_t)info.pg_used); printf("Testing chipset flush\n"); if (ioctl(fd, AGPIOC_CHIPSET_FLUSH, 0) < 0) err(7, "ioctl AGPIOC_CHIPSET_FLUSH"); unbind.key = alloc.key; unbind.priority = 0; if (ioctl(fd, AGPIOC_UNBIND, &unbind) < 0) err(7, "ioctl AGPIOC_BIND"); if (ioctl(fd, AGPIOC_DEALLOCATE, &alloc.key) < 0) err(8, "ioctl AGPIOC_DEALLOCATE"); if (ioctl(fd, AGPIOC_RELEASE, 0) < 0) err(9, "ioctl AGPIOC_RELEASE"); close(fd); printf("agp test successful\n"); return (0); }