summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2008-09-05 23:51:04 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2008-09-05 23:51:04 +0000
commit2f96ad35136fa139ba5033b2fdb3172ec0a37287 (patch)
tree84c7d726ff572cb7d6391cba8db0d2ac825182ac /sys/dev
parent7e298400ce415ce7a4e878189d5924b93244e774 (diff)
The code for cleaning up errored buffers and for cleaning up at the end
is the same. Factor them into one function. Saves another 450 bytes on amd64.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/drm/drmP.h1
-rw-r--r--sys/dev/pci/drm/drm_bufs.c40
-rw-r--r--sys/dev/pci/drm/drm_dma.c58
3 files changed, 37 insertions, 62 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h
index 26b52e2571e..d1d4e1c747b 100644
--- a/sys/dev/pci/drm/drmP.h
+++ b/sys/dev/pci/drm/drmP.h
@@ -704,6 +704,7 @@ int drm_addbufs_agp(struct drm_device *, struct drm_buf_desc *);
/* DMA support (drm_dma.c) */
int drm_dma_setup(struct drm_device *);
void drm_dma_takedown(struct drm_device *);
+void drm_cleanup_buf(struct drm_device *, drm_buf_entry_t *);
void drm_free_buffer(struct drm_device *, drm_buf_t *);
void drm_reclaim_buffers(struct drm_device *, struct drm_file *);
#define drm_core_reclaim_buffers drm_reclaim_buffers
diff --git a/sys/dev/pci/drm/drm_bufs.c b/sys/dev/pci/drm/drm_bufs.c
index a5166ab53b5..c3e77f08a0f 100644
--- a/sys/dev/pci/drm/drm_bufs.c
+++ b/sys/dev/pci/drm/drm_bufs.c
@@ -38,7 +38,6 @@
#include "drmP.h"
int drm_alloc_resource(struct drm_device *, int);
-void drm_cleanup_buf_error(struct drm_device *, drm_buf_entry_t *);
int drm_do_addbufs_agp(struct drm_device *, drm_buf_desc_t *);
int drm_do_addbufs_pci(struct drm_device *, drm_buf_desc_t *);
int drm_do_addbufs_sg(struct drm_device *, drm_buf_desc_t *);
@@ -398,31 +397,6 @@ drm_rmmap_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
}
-void
-drm_cleanup_buf_error(struct drm_device *dev, drm_buf_entry_t *entry)
-{
- int i;
-
- if (entry->seg_count) {
- for (i = 0; i < entry->seg_count; i++)
- drm_pci_free(dev, entry->seglist[i]);
- drm_free(entry->seglist, entry->seg_count *
- sizeof(*entry->seglist), DRM_MEM_BUFS);
-
- entry->seg_count = 0;
- }
-
- if (entry->buf_count) {
- for (i = 0; i < entry->buf_count; i++) {
- drm_free(entry->buflist[i].dev_private,
- entry->buflist[i].dev_priv_size, DRM_MEM_BUFS);
- }
- drm_free(entry->buflist, entry->buf_count *
- sizeof(*entry->buflist), DRM_MEM_BUFS);
-
- entry->buf_count = 0;
- }
-}
int
drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
@@ -519,7 +493,7 @@ drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
return ENOMEM;
}
@@ -536,7 +510,7 @@ drm_do_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request)
(dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM);
if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
return ENOMEM;
}
dma->buflist = temp_buflist;
@@ -631,7 +605,7 @@ drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
entry->seg_count = count;
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
drm_free(temp_pagelist, (dma->page_count +
(count << page_order)) * sizeof(*dma->pagelist),
DRM_MEM_BUFS);
@@ -667,7 +641,7 @@ drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
/* Set count so we free the proper amount. */
entry->buf_count = count;
entry->seg_count = count;
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
drm_free(temp_pagelist, (dma->page_count +
(count << page_order)) *
sizeof(*dma->pagelist),
@@ -686,7 +660,7 @@ drm_do_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request)
(dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM);
if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
drm_free(temp_pagelist, (dma->page_count +
(count << page_order)) * sizeof(*dma->pagelist),
DRM_MEM_BUFS);
@@ -785,7 +759,7 @@ drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request)
if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
return ENOMEM;
}
@@ -803,7 +777,7 @@ drm_do_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request)
(dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), M_DRM);
if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
- drm_cleanup_buf_error(dev, entry);
+ drm_cleanup_buf(dev, entry);
return ENOMEM;
}
dma->buflist = temp_buflist;
diff --git a/sys/dev/pci/drm/drm_dma.c b/sys/dev/pci/drm/drm_dma.c
index 4922a0344c3..91e51cfaf96 100644
--- a/sys/dev/pci/drm/drm_dma.c
+++ b/sys/dev/pci/drm/drm_dma.c
@@ -52,43 +52,43 @@ drm_dma_setup(struct drm_device *dev)
}
void
+drm_cleanup_buf(struct drm_device *dev, drm_buf_entry_t *entry)
+{
+ int i;
+
+ if (entry->seg_count) {
+ for (i = 0; i < entry->seg_count; i++)
+ drm_pci_free(dev, entry->seglist[i]);
+ drm_free(entry->seglist, entry->seg_count *
+ sizeof(*entry->seglist), DRM_MEM_BUFS);
+
+ entry->seg_count = 0;
+ }
+
+ if (entry->buf_count) {
+ for (i = 0; i < entry->buf_count; i++) {
+ drm_free(entry->buflist[i].dev_private,
+ entry->buflist[i].dev_priv_size, DRM_MEM_BUFS);
+ }
+ drm_free(entry->buflist, entry->buf_count *
+ sizeof(*entry->buflist), DRM_MEM_BUFS);
+
+ entry->buf_count = 0;
+ }
+}
+
+void
drm_dma_takedown(struct drm_device *dev)
{
drm_device_dma_t *dma = dev->dma;
- int i, j;
+ int i;
if (dma == NULL)
return;
/* Clear dma buffers */
- for (i = 0; i <= DRM_MAX_ORDER; i++) {
- if (dma->bufs[i].seg_count) {
- DRM_DEBUG("order %d: buf_count = %d,"
- " seg_count = %d\n", i, dma->bufs[i].buf_count,
- dma->bufs[i].seg_count);
- for (j = 0; j < dma->bufs[i].seg_count; j++) {
- drm_pci_free(dev, dma->bufs[i].seglist[j]);
- }
- if (dma->bufs[i].seglist)
- drm_free(dma->bufs[i].seglist,
- dma->bufs[i].seg_count *
- sizeof(*dma->bufs[i].seglist),
- DRM_MEM_BUFS);
- }
-
- if (dma->bufs[i].buf_count) {
- for (j = 0; j < dma->bufs[i].buf_count; j++) {
- drm_free(dma->bufs[i].buflist[j].dev_private,
- dma->bufs[i].buflist[j].dev_priv_size,
- DRM_MEM_BUFS);
- }
- if (dma->bufs[i].buflist)
- drm_free(dma->bufs[i].buflist,
- dma->bufs[i].buf_count *
- sizeof(*dma->bufs[i].buflist),
- DRM_MEM_BUFS);
- }
- }
+ for (i = 0; i <= DRM_MAX_ORDER; i++)
+ drm_cleanup_buf(dev, &dma->bufs[i]);
drm_free(dma->buflist, dma->buf_count * sizeof(*dma->buflist),
DRM_MEM_BUFS);