apply Eric's fixes for AGP support

This commit is contained in:
Alan Hourihane 2001-05-16 09:05:29 +00:00
parent 388fe88fc2
commit fc51415542
4 changed files with 152 additions and 102 deletions

View file

@ -31,6 +31,14 @@
#include "drmP.h"
#ifdef __FreeBSD__
#include <vm/vm.h>
#include <vm/pmap.h>
#if __REALLY_HAVE_AGP
#include <sys/agpio.h>
#endif
#endif
int DRM(agp_info)(dev_t kdev, u_long cmd, caddr_t data,
int flags, struct proc *p)
{
@ -82,6 +90,15 @@ int DRM(agp_release)(dev_t kdev, u_long cmd, caddr_t data,
}
void DRM(agp_do_release)(void)
{
device_t agpdev;
agpdev = agp_find_device();
if (agpdev)
agp_release(agpdev);
}
int DRM(agp_enable)(dev_t kdev, u_long cmd, caddr_t data,
int flags, struct proc *p)
{
@ -161,13 +178,21 @@ int DRM(agp_unbind)(dev_t kdev, u_long cmd, caddr_t data,
drm_device_t *dev = kdev->si_drv1;
drm_agp_binding_t request;
drm_agp_mem_t *entry;
int retcode;
if (!dev->agp || !dev->agp->acquired) return EINVAL;
request = *(drm_agp_binding_t *) data;
if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
return EINVAL;
if (!entry->bound) return EINVAL;
return DRM(unbind_agp)(entry->handle);
retcode=DRM(unbind_agp)(entry->handle);
if (!retcode)
{
entry->bound=0;
return 0;
}
else
return retcode;
}
int DRM(agp_bind)(dev_t kdev, u_long cmd, caddr_t data,
@ -183,20 +208,12 @@ int DRM(agp_bind)(dev_t kdev, u_long cmd, caddr_t data,
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
request = *(drm_agp_binding_t *) data;
DRM_DEBUG("agp_bind:lookup\n");
if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
return EINVAL;
DRM_DEBUG("agp_bind:page\n");
if (entry->bound) return EINVAL;
page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
DRM_DEBUG("agp_bind:bind it\n");
if ((retcode = DRM(bind_agp)(entry->handle, page)))
return retcode;
DRM_DEBUG("agp_bind:bound\n");
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
return 0;
}
@ -269,12 +286,51 @@ drm_agp_head_t *DRM(agp_init)(void)
void DRM(agp_uninit)(void)
{
/* FIXME: What goes here */
}
agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev)
return NULL;
return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
}
int DRM(agp_free_memory)(agp_memory *handle)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return 0;
agp_free_memory(agpdev, handle);
return 1;
}
int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return EINVAL;
return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
}
int DRM(agp_unbind_memory)(agp_memory *handle)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return EINVAL;
return agp_unbind_memory(agpdev, handle);
}

View file

@ -31,6 +31,14 @@
#include "drmP.h"
#ifdef __FreeBSD__
#include <vm/vm.h>
#include <vm/pmap.h>
#if __REALLY_HAVE_AGP
#include <sys/agpio.h>
#endif
#endif
int DRM(agp_info)(dev_t kdev, u_long cmd, caddr_t data,
int flags, struct proc *p)
{
@ -82,6 +90,15 @@ int DRM(agp_release)(dev_t kdev, u_long cmd, caddr_t data,
}
void DRM(agp_do_release)(void)
{
device_t agpdev;
agpdev = agp_find_device();
if (agpdev)
agp_release(agpdev);
}
int DRM(agp_enable)(dev_t kdev, u_long cmd, caddr_t data,
int flags, struct proc *p)
{
@ -161,13 +178,21 @@ int DRM(agp_unbind)(dev_t kdev, u_long cmd, caddr_t data,
drm_device_t *dev = kdev->si_drv1;
drm_agp_binding_t request;
drm_agp_mem_t *entry;
int retcode;
if (!dev->agp || !dev->agp->acquired) return EINVAL;
request = *(drm_agp_binding_t *) data;
if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
return EINVAL;
if (!entry->bound) return EINVAL;
return DRM(unbind_agp)(entry->handle);
retcode=DRM(unbind_agp)(entry->handle);
if (!retcode)
{
entry->bound=0;
return 0;
}
else
return retcode;
}
int DRM(agp_bind)(dev_t kdev, u_long cmd, caddr_t data,
@ -183,20 +208,12 @@ int DRM(agp_bind)(dev_t kdev, u_long cmd, caddr_t data,
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
request = *(drm_agp_binding_t *) data;
DRM_DEBUG("agp_bind:lookup\n");
if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
return EINVAL;
DRM_DEBUG("agp_bind:page\n");
if (entry->bound) return EINVAL;
page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
DRM_DEBUG("agp_bind:bind it\n");
if ((retcode = DRM(bind_agp)(entry->handle, page)))
return retcode;
DRM_DEBUG("agp_bind:bound\n");
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
return 0;
}
@ -269,12 +286,51 @@ drm_agp_head_t *DRM(agp_init)(void)
void DRM(agp_uninit)(void)
{
/* FIXME: What goes here */
}
agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev)
return NULL;
return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT);
}
int DRM(agp_free_memory)(agp_memory *handle)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return 0;
agp_free_memory(agpdev, handle);
return 1;
}
int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return EINVAL;
return agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
}
int DRM(agp_unbind_memory)(agp_memory *handle)
{
device_t agpdev;
agpdev = agp_find_device();
if (!agpdev || !handle)
return EINVAL;
return agp_unbind_memory(agpdev, handle);
}

View file

@ -474,24 +474,13 @@ void DRM(ioremapfree)(void *pt, unsigned long size)
agp_memory *DRM(alloc_agp)(int pages, u32 type)
{
agp_memory *handle;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
if (!dev)
return NULL;
#endif
if (!pages) {
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
return NULL;
}
#ifdef __linux__
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
#endif
#ifdef __FreeBSD__
if ((handle = agp_alloc_memory(dev, type, pages << AGP_PAGE_SHIFT))) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
@ -509,27 +498,14 @@ int DRM(free_agp)(agp_memory *handle, int pages)
{
int alloc_count;
int free_count;
int retval = -EINVAL;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
if (!dev)
return EINVAL;
#endif
if (!handle) {
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
"Attempt to free NULL AGP handle\n");
return retval;
DRM_OS_RETURN(EINVAL);
}
#ifdef __FreeBSD__
agp_free_memory(dev, handle);
#endif
#ifdef __linux__
if (DRM(agp_free_memory)(handle)) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
free_count = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
alloc_count = DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
@ -542,15 +518,13 @@ int DRM(free_agp)(agp_memory *handle, int pages)
free_count, alloc_count);
}
return 0;
#ifdef __linux__
}
#endif
return retval;
DRM_OS_RETURN(EINVAL);
}
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
{
int retcode = EINVAL;
int retcode;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
struct agp_memory_info info;
@ -562,15 +536,10 @@ int DRM(bind_agp)(agp_memory *handle, unsigned int start)
if (!handle) {
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
"Attempt to bind NULL AGP handle\n");
DRM_OS_RETURN(retcode);
DRM_OS_RETURN(EINVAL);
}
#ifdef __linux__
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
#endif
#ifdef __FreeBSD__
if (!(retcode = agp_bind_memory(dev, handle,start << AGP_PAGE_SHIFT))) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
#ifdef __linux__
@ -583,7 +552,7 @@ int DRM(bind_agp)(agp_memory *handle, unsigned int start)
+= info.ami_size;
#endif
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
DRM_OS_RETURN(retcode);
DRM_OS_RETURN(0);
}
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
@ -610,22 +579,22 @@ int DRM(unbind_agp)(agp_memory *handle)
DRM_OS_RETURN(retcode);
}
#ifdef __linux__
if ((retcode = DRM(agp_unbind_memory)(handle)))
#endif
#ifdef __FreeBSD__
agp_memory_info(dev, handle, &info);
if ((retcode = agp_unbind_memory(dev, handle)))
#endif
if ((retcode = DRM(agp_unbind_memory)(handle)))
DRM_OS_RETURN(retcode);
DRM_OS_SPINLOCK(&DRM(mem_lock));
free_count = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
#ifdef __linux__
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
+= handle->page_count << PAGE_SHIFT;
#endif
#ifdef __FreeBSD__
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
+= info.ami_size;
#endif
DRM_OS_SPINUNLOCK(&DRM(mem_lock));

View file

@ -474,24 +474,13 @@ void DRM(ioremapfree)(void *pt, unsigned long size)
agp_memory *DRM(alloc_agp)(int pages, u32 type)
{
agp_memory *handle;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
if (!dev)
return NULL;
#endif
if (!pages) {
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
return NULL;
}
#ifdef __linux__
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
#endif
#ifdef __FreeBSD__
if ((handle = agp_alloc_memory(dev, type, pages << AGP_PAGE_SHIFT))) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
@ -509,27 +498,14 @@ int DRM(free_agp)(agp_memory *handle, int pages)
{
int alloc_count;
int free_count;
int retval = -EINVAL;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
if (!dev)
return EINVAL;
#endif
if (!handle) {
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
"Attempt to free NULL AGP handle\n");
return retval;
DRM_OS_RETURN(EINVAL);
}
#ifdef __FreeBSD__
agp_free_memory(dev, handle);
#endif
#ifdef __linux__
if (DRM(agp_free_memory)(handle)) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
free_count = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
alloc_count = DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
@ -542,15 +518,13 @@ int DRM(free_agp)(agp_memory *handle, int pages)
free_count, alloc_count);
}
return 0;
#ifdef __linux__
}
#endif
return retval;
DRM_OS_RETURN(EINVAL);
}
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
{
int retcode = EINVAL;
int retcode;
#ifdef __FreeBSD__
device_t dev = agp_find_device();
struct agp_memory_info info;
@ -562,15 +536,10 @@ int DRM(bind_agp)(agp_memory *handle, unsigned int start)
if (!handle) {
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
"Attempt to bind NULL AGP handle\n");
DRM_OS_RETURN(retcode);
DRM_OS_RETURN(EINVAL);
}
#ifdef __linux__
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
#endif
#ifdef __FreeBSD__
if (!(retcode = agp_bind_memory(dev, handle,start << AGP_PAGE_SHIFT))) {
#endif
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
#ifdef __linux__
@ -583,7 +552,7 @@ int DRM(bind_agp)(agp_memory *handle, unsigned int start)
+= info.ami_size;
#endif
DRM_OS_SPINUNLOCK(&DRM(mem_lock));
DRM_OS_RETURN(retcode);
DRM_OS_RETURN(0);
}
DRM_OS_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
@ -610,22 +579,22 @@ int DRM(unbind_agp)(agp_memory *handle)
DRM_OS_RETURN(retcode);
}
#ifdef __linux__
if ((retcode = DRM(agp_unbind_memory)(handle)))
#endif
#ifdef __FreeBSD__
agp_memory_info(dev, handle, &info);
if ((retcode = agp_unbind_memory(dev, handle)))
#endif
if ((retcode = DRM(agp_unbind_memory)(handle)))
DRM_OS_RETURN(retcode);
DRM_OS_SPINLOCK(&DRM(mem_lock));
free_count = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
#ifdef __linux__
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
+= handle->page_count << PAGE_SHIFT;
#endif
#ifdef __FreeBSD__
DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
+= info.ami_size;
#endif
DRM_OS_SPINUNLOCK(&DRM(mem_lock));