summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2009-04-06 23:52:23 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2009-04-06 23:52:23 +0000
commitf40b52712db701a1b0cc0f455d64411618181a01 (patch)
treee31aae329c2d3cbfaa3a423eb65ef757c6a9fd02
parente83491fb40cebf2a318b94a7bfc52ab98ab9760b (diff)
Convert the savage freelist over to TAILQ.
-rw-r--r--sys/dev/pci/drm/savage_bci.c84
-rw-r--r--sys/dev/pci/drm/savage_drv.c2
-rw-r--r--sys/dev/pci/drm/savage_drv.h14
-rw-r--r--sys/dev/pci/drm/savage_state.c4
4 files changed, 49 insertions, 55 deletions
diff --git a/sys/dev/pci/drm/savage_bci.c b/sys/dev/pci/drm/savage_bci.c
index f513e8040d6..87e2b963dba 100644
--- a/sys/dev/pci/drm/savage_bci.c
+++ b/sys/dev/pci/drm/savage_bci.c
@@ -203,22 +203,17 @@ uint16_t savage_bci_emit_event(drm_savage_private_t *dev_priv,
/*
* Freelist management
*/
-static int savage_freelist_init(struct drm_device *dev)
+static int
+savage_freelist_init(struct drm_device *dev)
{
- drm_savage_private_t *dev_priv = dev->dev_private;
- struct drm_device_dma *dma = dev->dma;
- struct drm_buf *buf;
- drm_savage_buf_priv_t *entry;
- int i;
+ drm_savage_private_t *dev_priv = dev->dev_private;
+ struct drm_device_dma *dma = dev->dma;
+ struct drm_buf *buf;
+ struct savagedrm_buf_priv *entry;
+ int i;
DRM_DEBUG("count=%d\n", dma->buf_count);
- dev_priv->head.next = &dev_priv->tail;
- dev_priv->head.prev = NULL;
- dev_priv->head.buf = NULL;
-
- dev_priv->tail.next = NULL;
- dev_priv->tail.prev = &dev_priv->head;
- dev_priv->tail.buf = NULL;
+ TAILQ_INIT(&dev_priv->freelist);
for (i = 0; i < dma->buf_count; i++) {
buf = dma->buflist[i];
@@ -226,22 +221,21 @@ static int savage_freelist_init(struct drm_device *dev)
SET_AGE(&entry->age, 0, 0);
entry->buf = buf;
+ entry->free = 1;
- entry->next = dev_priv->head.next;
- entry->prev = &dev_priv->head;
- dev_priv->head.next->prev = entry;
- dev_priv->head.next = entry;
+ TAILQ_INSERT_HEAD(&dev_priv->freelist, entry, link);
}
- return 0;
+ return (0);
}
-static struct drm_buf *savage_freelist_get(struct drm_device *dev)
+static struct drm_buf *
+savage_freelist_get(struct drm_device *dev)
{
- drm_savage_private_t *dev_priv = dev->dev_private;
- drm_savage_buf_priv_t *tail = dev_priv->tail.prev;
- uint16_t event;
- unsigned int wrap;
+ drm_savage_private_t *dev_priv = dev->dev_private;
+ struct savagedrm_buf_priv *tail;
+ uint16_t event;
+ unsigned int wrap;
DRM_DEBUG("\n");
UPDATE_EVENT_COUNTER();
@@ -256,37 +250,36 @@ static struct drm_buf *savage_freelist_get(struct drm_device *dev)
DRM_DEBUG(" tail=0x%04x %d\n", tail->age.event, tail->age.wrap);
DRM_DEBUG(" head=0x%04x %d\n", event, wrap);
- if (tail->buf && (TEST_AGE(&tail->age, event, wrap) || event == 0)) {
- drm_savage_buf_priv_t *next = tail->next;
- drm_savage_buf_priv_t *prev = tail->prev;
- prev->next = next;
- next->prev = prev;
- tail->next = tail->prev = NULL;
- return tail->buf;
+ if (TAILQ_EMPTY(&dev_priv->freelist))
+ goto out;
+
+ tail = TAILQ_LAST(&dev_priv->freelist, savage_freelist);
+ if (TEST_AGE(&tail->age, event, wrap) || event == 0) {
+ TAILQ_REMOVE(&dev_priv->freelist, tail, link);
+ tail->free = 0;
+ return (tail->buf);
}
+out:
DRM_DEBUG("returning NULL, tail->buf=%p!\n", tail->buf);
return NULL;
}
-void savage_freelist_put(struct drm_device *dev, struct drm_buf *buf)
+void
+savage_freelist_put(struct drm_device *dev, struct drm_buf *buf)
{
- drm_savage_private_t *dev_priv = dev->dev_private;
- drm_savage_buf_priv_t *entry = buf->dev_private, *prev, *next;
+ drm_savage_private_t *dev_priv = dev->dev_private;
+ struct savagedrm_buf_priv *entry = buf->dev_private;
DRM_DEBUG("age=0x%04x wrap=%d\n", entry->age.event, entry->age.wrap);
- if (entry->next != NULL || entry->prev != NULL) {
+ if (entry->free == 1) {
DRM_ERROR("entry already on freelist.\n");
return;
}
- prev = &dev_priv->head;
- next = prev->next;
- prev->next = entry;
- next->prev = entry;
- entry->prev = prev;
- entry->next = next;
+ entry->free = 1;
+ TAILQ_INSERT_HEAD(&dev_priv->freelist, entry, link);
}
/*
@@ -950,9 +943,9 @@ savage_bci_buffers(struct drm_device *dev, struct drm_dma *d,
void savage_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
{
- struct drm_device_dma *dma = dev->dma;
- drm_savage_private_t *dev_priv = dev->dev_private;
- int i;
+ struct drm_device_dma *dma = dev->dma;
+ drm_savage_private_t *dev_priv = dev->dev_private;
+ int i;
if (!dma)
return;
@@ -963,11 +956,12 @@ void savage_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
for (i = 0; i < dma->buf_count; i++) {
struct drm_buf *buf = dma->buflist[i];
- drm_savage_buf_priv_t *buf_priv = buf->dev_private;
+ struct savagedrm_buf_priv *buf_priv = buf->dev_private;
if (buf->file_priv == file_priv && buf_priv &&
- buf_priv->next == NULL && buf_priv->prev == NULL) {
+ buf_priv->free == 0) {
uint16_t event;
+
DRM_DEBUG("reclaimed from client\n");
event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
diff --git a/sys/dev/pci/drm/savage_drv.c b/sys/dev/pci/drm/savage_drv.c
index 3ecb2fe5420..8ba435653fd 100644
--- a/sys/dev/pci/drm/savage_drv.c
+++ b/sys/dev/pci/drm/savage_drv.c
@@ -64,7 +64,7 @@ const static struct drm_pcidev savagedrm_pciidlist[] = {
};
static const struct drm_driver_info savagedrm_driver = {
- .buf_priv_size = sizeof(drm_savage_buf_priv_t),
+ .buf_priv_size = sizeof(struct savagedrm_buf_priv),
.firstopen = savage_driver_firstopen,
.lastclose = savage_driver_lastclose,
.reclaim_buffers_locked = savage_reclaim_buffers,
diff --git a/sys/dev/pci/drm/savage_drv.h b/sys/dev/pci/drm/savage_drv.h
index cd0609b8004..6cca938de54 100644
--- a/sys/dev/pci/drm/savage_drv.h
+++ b/sys/dev/pci/drm/savage_drv.h
@@ -54,12 +54,12 @@ typedef struct drm_savage_age {
unsigned int wrap;
} drm_savage_age_t;
-typedef struct drm_savage_buf_priv {
- struct drm_savage_buf_priv *next;
- struct drm_savage_buf_priv *prev;
- drm_savage_age_t age;
- struct drm_buf *buf;
-} drm_savage_buf_priv_t;
+struct savagedrm_buf_priv {
+ TAILQ_ENTRY(savagedrm_buf_priv) link;
+ drm_savage_age_t age;
+ struct drm_buf *buf;
+ int free;
+};
typedef struct drm_savage_dma_page {
drm_savage_age_t age;
@@ -132,7 +132,7 @@ typedef struct drm_savage_private {
bus_size_t fb_size;
bus_addr_t aperture_base;
- drm_savage_buf_priv_t head, tail;
+ TAILQ_HEAD(savage_freelist, savagedrm_buf_priv) freelist;
/* who am I? */
enum savage_family chipset;
diff --git a/sys/dev/pci/drm/savage_state.c b/sys/dev/pci/drm/savage_state.c
index 39aa9183abc..8b1d1622ec9 100644
--- a/sys/dev/pci/drm/savage_state.c
+++ b/sys/dev/pci/drm/savage_state.c
@@ -1140,9 +1140,9 @@ int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_
DMA_FLUSH();
if (dmabuf && cmdbuf->discard) {
- drm_savage_buf_priv_t *buf_priv =
- (drm_savage_buf_priv_t *)dmabuf;
+ struct savagedrm_buf_priv *buf_priv = dmabuf->dev_private;
uint16_t event;
+
event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
savage_freelist_put(dev, dmabuf);