Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2730723b authored by Francisco Jerez's avatar Francisco Jerez Committed by Ben Skeggs
Browse files

drm/nouveau: Minor refactoring/cleanup of the fence code.



Mainly to make room for inter-channel sync.

Signed-off-by: default avatarFrancisco Jerez <currojerez@riseup.net>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 0cba1b76
Loading
Loading
Loading
Loading
+0 −15
Original line number Original line Diff line number Diff line
@@ -36,21 +36,6 @@
#include <linux/log2.h>
#include <linux/log2.h>
#include <linux/slab.h>
#include <linux/slab.h>


int
nouveau_bo_sync_gpu(struct nouveau_bo *nvbo, struct nouveau_channel *chan)
{
	struct nouveau_fence *prev_fence = nvbo->bo.sync_obj;
	int ret;

	if (!prev_fence || nouveau_fence_channel(prev_fence) == chan)
		return 0;

	spin_lock(&nvbo->bo.lock);
	ret = ttm_bo_wait(&nvbo->bo, false, false, false);
	spin_unlock(&nvbo->bo.lock);
	return ret;
}

static void
static void
nouveau_bo_del_ttm(struct ttm_buffer_object *bo)
nouveau_bo_del_ttm(struct ttm_buffer_object *bo)
{
{
+2 −2
Original line number Original line Diff line number Diff line
@@ -223,7 +223,7 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,


	ret = nouveau_dma_init(chan);
	ret = nouveau_dma_init(chan);
	if (!ret)
	if (!ret)
		ret = nouveau_fence_init(chan);
		ret = nouveau_fence_channel_init(chan);
	if (ret) {
	if (ret) {
		nouveau_channel_free(chan);
		nouveau_channel_free(chan);
		return ret;
		return ret;
@@ -270,7 +270,7 @@ nouveau_channel_free(struct nouveau_channel *chan)
	 * above attempts at idling were OK, but if we failed this'll tell TTM
	 * above attempts at idling were OK, but if we failed this'll tell TTM
	 * we're done with the buffers.
	 * we're done with the buffers.
	 */
	 */
	nouveau_fence_fini(chan);
	nouveau_fence_channel_fini(chan);


	/* This will prevent pfifo from switching channels. */
	/* This will prevent pfifo from switching channels. */
	pfifo->reassign(dev, false);
	pfifo->reassign(dev, false);
+0 −17
Original line number Original line Diff line number Diff line
@@ -73,16 +73,6 @@ nouveau_dma_init(struct nouveau_channel *chan)
	if (ret)
	if (ret)
		return ret;
		return ret;


	/* Create an NV_SW object for various sync purposes */
	ret = nouveau_gpuobj_sw_new(chan, NV_SW, &obj);
	if (ret)
		return ret;

	ret = nouveau_ramht_insert(chan, NvSw, obj);
	nouveau_gpuobj_ref(NULL, &obj);
	if (ret)
		return ret;

	/* NV_MEMORY_TO_MEMORY_FORMAT requires a notifier object */
	/* NV_MEMORY_TO_MEMORY_FORMAT requires a notifier object */
	ret = nouveau_notifier_alloc(chan, NvNotify0, 32, &chan->m2mf_ntfy);
	ret = nouveau_notifier_alloc(chan, NvNotify0, 32, &chan->m2mf_ntfy);
	if (ret)
	if (ret)
@@ -110,13 +100,6 @@ nouveau_dma_init(struct nouveau_channel *chan)
	BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1);
	BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1);
	OUT_RING(chan, NvNotify0);
	OUT_RING(chan, NvNotify0);


	/* Initialise NV_SW */
	ret = RING_SPACE(chan, 2);
	if (ret)
		return ret;
	BEGIN_RING(chan, NvSubSw, 0, 1);
	OUT_RING(chan, NvSw);

	/* Sit back and pray the channel works.. */
	/* Sit back and pray the channel works.. */
	FIRE_RING(chan);
	FIRE_RING(chan);


+9 −2
Original line number Original line Diff line number Diff line
@@ -705,6 +705,12 @@ struct drm_nouveau_private {
	struct apertures_struct *apertures;
	struct apertures_struct *apertures;
};
};


static inline struct drm_nouveau_private *
nouveau_private(struct drm_device *dev)
{
	return dev->dev_private;
}

static inline struct drm_nouveau_private *
static inline struct drm_nouveau_private *
nouveau_bdev(struct ttm_bo_device *bd)
nouveau_bdev(struct ttm_bo_device *bd)
{
{
@@ -1231,8 +1237,8 @@ extern int nouveau_bo_sync_gpu(struct nouveau_bo *, struct nouveau_channel *);


/* nouveau_fence.c */
/* nouveau_fence.c */
struct nouveau_fence;
struct nouveau_fence;
extern int nouveau_fence_init(struct nouveau_channel *);
extern int nouveau_fence_channel_init(struct nouveau_channel *);
extern void nouveau_fence_fini(struct nouveau_channel *);
extern void nouveau_fence_channel_fini(struct nouveau_channel *);
extern void nouveau_fence_update(struct nouveau_channel *);
extern void nouveau_fence_update(struct nouveau_channel *);
extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
			     bool emit);
			     bool emit);
@@ -1240,6 +1246,7 @@ extern int nouveau_fence_emit(struct nouveau_fence *);
struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
extern bool nouveau_fence_signalled(void *obj, void *arg);
extern bool nouveau_fence_signalled(void *obj, void *arg);
extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *);
extern int nouveau_fence_flush(void *obj, void *arg);
extern int nouveau_fence_flush(void *obj, void *arg);
extern void nouveau_fence_unref(void **obj);
extern void nouveau_fence_unref(void **obj);
extern void *nouveau_fence_ref(void *obj);
extern void *nouveau_fence_ref(void *obj);
+46 −17
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@
#include "nouveau_drv.h"
#include "nouveau_drv.h"
#include "nouveau_dma.h"
#include "nouveau_dma.h"


#define USE_REFCNT (dev_priv->card_type >= NV_10)
#define USE_REFCNT(dev) (nouveau_private(dev)->chipset >= 0x10)


struct nouveau_fence {
struct nouveau_fence {
	struct nouveau_channel *channel;
	struct nouveau_channel *channel;
@@ -59,14 +59,13 @@ nouveau_fence_del(struct kref *ref)
void
void
nouveau_fence_update(struct nouveau_channel *chan)
nouveau_fence_update(struct nouveau_channel *chan)
{
{
	struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
	struct drm_device *dev = chan->dev;
	struct list_head *entry, *tmp;
	struct nouveau_fence *tmp, *fence;
	struct nouveau_fence *fence;
	uint32_t sequence;
	uint32_t sequence;


	spin_lock(&chan->fence.lock);
	spin_lock(&chan->fence.lock);


	if (USE_REFCNT)
	if (USE_REFCNT(dev))
		sequence = nvchan_rd32(chan, 0x48);
		sequence = nvchan_rd32(chan, 0x48);
	else
	else
		sequence = atomic_read(&chan->fence.last_sequence_irq);
		sequence = atomic_read(&chan->fence.last_sequence_irq);
@@ -75,9 +74,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
		goto out;
		goto out;
	chan->fence.sequence_ack = sequence;
	chan->fence.sequence_ack = sequence;


	list_for_each_safe(entry, tmp, &chan->fence.pending) {
	list_for_each_entry_safe(fence, tmp, &chan->fence.pending, entry) {
		fence = list_entry(entry, struct nouveau_fence, entry);

		sequence = fence->sequence;
		sequence = fence->sequence;
		fence->signalled = true;
		fence->signalled = true;
		list_del(&fence->entry);
		list_del(&fence->entry);
@@ -121,8 +118,8 @@ nouveau_fence_channel(struct nouveau_fence *fence)
int
int
nouveau_fence_emit(struct nouveau_fence *fence)
nouveau_fence_emit(struct nouveau_fence *fence)
{
{
	struct drm_nouveau_private *dev_priv = fence->channel->dev->dev_private;
	struct nouveau_channel *chan = fence->channel;
	struct nouveau_channel *chan = fence->channel;
	struct drm_device *dev = chan->dev;
	int ret;
	int ret;


	ret = RING_SPACE(chan, 2);
	ret = RING_SPACE(chan, 2);
@@ -143,7 +140,7 @@ nouveau_fence_emit(struct nouveau_fence *fence)
	list_add_tail(&fence->entry, &chan->fence.pending);
	list_add_tail(&fence->entry, &chan->fence.pending);
	spin_unlock(&chan->fence.lock);
	spin_unlock(&chan->fence.lock);


	BEGIN_RING(chan, NvSubSw, USE_REFCNT ? 0x0050 : 0x0150, 1);
	BEGIN_RING(chan, NvSubSw, USE_REFCNT(dev) ? 0x0050 : 0x0150, 1);
	OUT_RING(chan, fence->sequence);
	OUT_RING(chan, fence->sequence);
	FIRE_RING(chan);
	FIRE_RING(chan);


@@ -213,6 +210,19 @@ nouveau_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr)
	return ret;
	return ret;
}
}


int
nouveau_fence_sync(struct nouveau_fence *fence,
		   struct nouveau_channel *wchan)
{
	struct nouveau_channel *chan = nouveau_fence_channel(fence);

	if (likely(!fence || chan == wchan ||
		   nouveau_fence_signalled(fence, NULL)))
		return 0;

	return nouveau_fence_wait(fence, NULL, false, false);
}

int
int
nouveau_fence_flush(void *sync_obj, void *sync_arg)
nouveau_fence_flush(void *sync_obj, void *sync_arg)
{
{
@@ -220,23 +230,42 @@ nouveau_fence_flush(void *sync_obj, void *sync_arg)
}
}


int
int
nouveau_fence_init(struct nouveau_channel *chan)
nouveau_fence_channel_init(struct nouveau_channel *chan)
{
{
	struct nouveau_gpuobj *obj = NULL;
	int ret;

	/* Create an NV_SW object for various sync purposes */
	ret = nouveau_gpuobj_sw_new(chan, NV_SW, &obj);
	if (ret)
		return ret;

	ret = nouveau_ramht_insert(chan, NvSw, obj);
	nouveau_gpuobj_ref(NULL, &obj);
	if (ret)
		return ret;

	ret = RING_SPACE(chan, 2);
	if (ret)
		return ret;
	BEGIN_RING(chan, NvSubSw, 0, 1);
	OUT_RING(chan, NvSw);

	FIRE_RING(chan);

	INIT_LIST_HEAD(&chan->fence.pending);
	INIT_LIST_HEAD(&chan->fence.pending);
	spin_lock_init(&chan->fence.lock);
	spin_lock_init(&chan->fence.lock);
	atomic_set(&chan->fence.last_sequence_irq, 0);
	atomic_set(&chan->fence.last_sequence_irq, 0);

	return 0;
	return 0;
}
}


void
void
nouveau_fence_fini(struct nouveau_channel *chan)
nouveau_fence_channel_fini(struct nouveau_channel *chan)
{
{
	struct list_head *entry, *tmp;
	struct nouveau_fence *tmp, *fence;
	struct nouveau_fence *fence;

	list_for_each_safe(entry, tmp, &chan->fence.pending) {
		fence = list_entry(entry, struct nouveau_fence, entry);


	list_for_each_entry_safe(fence, tmp, &chan->fence.pending, entry) {
		fence->signalled = true;
		fence->signalled = true;
		list_del(&fence->entry);
		list_del(&fence->entry);
		kref_put(&fence->refcount, nouveau_fence_del);
		kref_put(&fence->refcount, nouveau_fence_del);
Loading