summaryrefslogtreecommitdiff
path: root/bsd-core/drm_agpsupport.c
diff options
context:
space:
mode:
Diffstat (limited to 'bsd-core/drm_agpsupport.c')
-rw-r--r--bsd-core/drm_agpsupport.c153
1 files changed, 107 insertions, 46 deletions
diff --git a/bsd-core/drm_agpsupport.c b/bsd-core/drm_agpsupport.c
index a78410a8..58293566 100644
--- a/bsd-core/drm_agpsupport.c
+++ b/bsd-core/drm_agpsupport.c
@@ -194,10 +194,8 @@ int drm_agp_enable_ioctl(DRM_IOCTL_ARGS)
return drm_agp_enable(dev, mode);
}
-int drm_agp_alloc(DRM_IOCTL_ARGS)
+int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request)
{
- DRM_DEVICE;
- drm_agp_buffer_t request;
drm_agp_mem_t *entry;
void *handle;
unsigned long pages;
@@ -207,16 +205,17 @@ int drm_agp_alloc(DRM_IOCTL_ARGS)
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
- request = *(drm_agp_buffer_t *) data;
-
entry = malloc(sizeof(*entry), M_DRM, M_NOWAIT | M_ZERO);
if (entry == NULL)
return ENOMEM;
- pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
- type = (u_int32_t) request.type;
+ pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
+ type = (u_int32_t) request->type;
- if (!(handle = drm_agp_allocate_memory(pages, type))) {
+ DRM_UNLOCK();
+ handle = drm_agp_allocate_memory(pages, type);
+ DRM_LOCK();
+ if (handle == NULL) {
free(entry, M_DRM);
return ENOMEM;
}
@@ -232,12 +231,27 @@ int drm_agp_alloc(DRM_IOCTL_ARGS)
agp_memory_info(dev->agp->agpdev, entry->handle, &info);
- request.handle = (unsigned long) entry->handle;
- request.physical = info.ami_physical;
+ request->handle = (unsigned long) entry->handle;
+ request->physical = info.ami_physical;
+
+ return 0;
+}
+
+int drm_agp_alloc_ioctl(DRM_IOCTL_ARGS)
+{
+ DRM_DEVICE;
+ drm_agp_buffer_t request;
+ int retcode;
+
+ request = *(drm_agp_buffer_t *) data;
+
+ DRM_LOCK();
+ retcode = drm_agp_alloc(dev, &request);
+ DRM_UNLOCK();
*(drm_agp_buffer_t *) data = request;
- return 0;
+ return retcode;
}
static drm_agp_mem_t * drm_agp_lookup_entry(drm_device_t *dev, void *handle)
@@ -250,64 +264,94 @@ static drm_agp_mem_t * drm_agp_lookup_entry(drm_device_t *dev, void *handle)
return NULL;
}
-int drm_agp_unbind(DRM_IOCTL_ARGS)
+int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request)
{
- DRM_DEVICE;
- 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)))
+
+ entry = drm_agp_lookup_entry(dev, (void *)request->handle);
+ if (entry == NULL || !entry->bound)
return EINVAL;
- if (!entry->bound) return EINVAL;
+
+ DRM_UNLOCK();
retcode = drm_agp_unbind_memory(entry->handle);
- if (!retcode)
- {
- entry->bound=0;
- return 0;
- }
- else
- return retcode;
+ DRM_LOCK();
+
+ if (retcode == 0)
+ entry->bound = 0;
+
+ return retcode;
}
-int drm_agp_bind(DRM_IOCTL_ARGS)
+int drm_agp_unbind_ioctl(DRM_IOCTL_ARGS)
{
DRM_DEVICE;
drm_agp_binding_t request;
+ int retcode;
+
+ request = *(drm_agp_binding_t *) data;
+
+ DRM_LOCK();
+ retcode = drm_agp_unbind(dev, &request);
+ DRM_UNLOCK();
+
+ return retcode;
+}
+
+int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request)
+{
drm_agp_mem_t *entry;
int retcode;
int page;
- DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
- request = *(drm_agp_binding_t *) data;
- if (!(entry = drm_agp_lookup_entry(dev, (void *)request.handle)))
+
+ DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE);
+
+ entry = drm_agp_lookup_entry(dev, (void *)request->handle);
+ if (entry == NULL || entry->bound)
return EINVAL;
- if (entry->bound) return EINVAL;
- page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
- if ((retcode = drm_agp_bind_memory(entry->handle, page)))
- return retcode;
- entry->bound = dev->agp->base + (page << PAGE_SHIFT);
- return 0;
+
+ page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
+
+ DRM_UNLOCK();
+ retcode = drm_agp_bind_memory(entry->handle, page);
+ DRM_LOCK();
+ if (retcode == 0)
+ entry->bound = dev->agp->base + (page << PAGE_SHIFT);
+
+ return retcode;
}
-int drm_agp_free(DRM_IOCTL_ARGS)
+int drm_agp_bind_ioctl(DRM_IOCTL_ARGS)
{
DRM_DEVICE;
- drm_agp_buffer_t request;
+ drm_agp_binding_t request;
+ int retcode;
+
+ request = *(drm_agp_binding_t *) data;
+
+ DRM_LOCK();
+ retcode = drm_agp_bind(dev, &request);
+ DRM_UNLOCK();
+
+ return retcode;
+}
+
+int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request)
+{
drm_agp_mem_t *entry;
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
- request = *(drm_agp_buffer_t *) data;
- if (!(entry = drm_agp_lookup_entry(dev, (void*)request.handle)))
+
+ entry = drm_agp_lookup_entry(dev, (void*)request->handle);
+ if (entry == NULL)
return EINVAL;
- if (entry->bound)
- drm_agp_unbind_memory(entry->handle);
if (entry->prev)
entry->prev->next = entry->next;
@@ -315,9 +359,32 @@ int drm_agp_free(DRM_IOCTL_ARGS)
dev->agp->memory = entry->next;
if (entry->next)
entry->next->prev = entry->prev;
+
+ DRM_UNLOCK();
+ if (entry->bound)
+ drm_agp_unbind_memory(entry->handle);
drm_agp_free_memory(entry->handle);
+ DRM_LOCK();
+
free(entry, M_DRM);
+
return 0;
+
+}
+
+int drm_agp_free_ioctl(DRM_IOCTL_ARGS)
+{
+ DRM_DEVICE;
+ drm_agp_buffer_t request;
+ int retcode;
+
+ request = *(drm_agp_buffer_t *) data;
+
+ DRM_LOCK();
+ retcode = drm_agp_free(dev, &request);
+ DRM_UNLOCK();
+
+ return retcode;
}
drm_agp_head_t *drm_agp_init(void)
@@ -346,12 +413,6 @@ drm_agp_head_t *drm_agp_init(void)
return head;
}
-void drm_agp_uninit(void)
-{
-/* FIXME: What goes here */
-}
-
-
void *drm_agp_allocate_memory(size_t pages, u32 type)
{
device_t agpdev;