uint32_t diff;
uint32_t relevant;
drm_fence_manager_t *fm = &dev->fm;
+ drm_fence_class_manager_t *fc = &fm->class[class];
drm_fence_driver_t *driver = dev->driver->fence_driver;
struct list_head *list, *prev;
drm_fence_object_t *fence;
int found = 0;
- if (list_empty(&fm->ring))
+ if (list_empty(&fc->ring))
return;
- list_for_each_entry(fence, &fm->ring, ring) {
+ list_for_each_entry(fence, &fc->ring, ring) {
diff = (sequence - fence->sequence) & driver->sequence_mask;
if (diff > driver->wrap_diff) {
found = 1;
}
}
- list = (found) ? fence->ring.prev : fm->ring.prev;
+ list = (found) ? fence->ring.prev : fc->ring.prev;
prev = list->prev;
- for (; list != &fm->ring; list = prev, prev = list->prev) {
+ for (; list != &fc->ring; list = prev, prev = list->prev) {
fence = list_entry(list, drm_fence_object_t, ring);
type |= fence->native_type;
~(fence->signaled | fence->submitted_flush);
if (relevant) {
- fm->pending_flush |= relevant;
+ fc->pending_flush |= relevant;
fence->submitted_flush = fence->flush_mask;
}
}
if (wake) {
- DRM_WAKEUP(&fm->fence_queue);
+ DRM_WAKEUP(&fc->fence_queue);
}
}
return signaled;
}
-static void drm_fence_flush_exe(drm_fence_manager_t * fm,
+static void drm_fence_flush_exe(drm_fence_class_manager_t * fc,
drm_fence_driver_t * driver, uint32_t sequence)
{
uint32_t diff;
- if (!fm->pending_exe_flush) {
+ if (!fc->pending_exe_flush) {
struct list_head *list;
/*
* Last_exe_flush is invalid. Find oldest sequence.
*/
- list = &fm->ring;
- if (list->next == &fm->ring) {
+ list = &fc->ring;
+ if (list->next == &fc->ring) {
return;
} else {
drm_fence_object_t *fence =
list_entry(list->next, drm_fence_object_t, ring);
- fm->last_exe_flush = (fence->sequence - 1) &
+ fc->last_exe_flush = (fence->sequence - 1) &
driver->sequence_mask;
}
- diff = (sequence - fm->last_exe_flush) & driver->sequence_mask;
+ diff = (sequence - fc->last_exe_flush) & driver->sequence_mask;
if (diff >= driver->wrap_diff)
return;
- fm->exe_flush_sequence = sequence;
- fm->pending_exe_flush = 1;
+ fc->exe_flush_sequence = sequence;
+ fc->pending_exe_flush = 1;
} else {
diff =
- (sequence - fm->exe_flush_sequence) & driver->sequence_mask;
+ (sequence - fc->exe_flush_sequence) & driver->sequence_mask;
if (diff < driver->wrap_diff) {
- fm->exe_flush_sequence = sequence;
+ fc->exe_flush_sequence = sequence;
}
}
}
uint32_t type)
{
drm_fence_manager_t *fm = &dev->fm;
+ drm_fence_class_manager_t *fc = &fm->class[fence->class];
drm_fence_driver_t *driver = dev->driver->fence_driver;
unsigned long flags;
if (fence->submitted_flush == fence->signaled) {
if ((fence->type & DRM_FENCE_TYPE_EXE) &&
!(fence->submitted_flush & DRM_FENCE_TYPE_EXE)) {
- drm_fence_flush_exe(fm, driver, fence->sequence);
+ drm_fence_flush_exe(fc, driver, fence->sequence);
fence->submitted_flush |= DRM_FENCE_TYPE_EXE;
} else {
- fm->pending_flush |= (fence->flush_mask &
+ fc->pending_flush |= (fence->flush_mask &
~fence->submitted_flush);
fence->submitted_flush = fence->flush_mask;
}
* wrapped around and reused.
*/
-void drm_fence_flush_old(drm_device_t * dev, uint32_t sequence)
+void drm_fence_flush_old(drm_device_t * dev, uint32_t class, uint32_t sequence)
{
drm_fence_manager_t *fm = &dev->fm;
+ drm_fence_class_manager_t *fc = &fm->class[class];
drm_fence_driver_t *driver = dev->driver->fence_driver;
uint32_t old_sequence;
unsigned long flags;
mutex_lock(&dev->struct_mutex);
read_lock_irqsave(&fm->lock, flags);
- if (fm->ring.next == &fm->ring) {
+ if (fc->ring.next == &fc->ring) {
read_unlock_irqrestore(&fm->lock, flags);
mutex_unlock(&dev->struct_mutex);
return;
}
old_sequence = (sequence - driver->flush_diff) & driver->sequence_mask;
- fence = list_entry(fm->ring.next, drm_fence_object_t, ring);
+ fence = list_entry(fc->ring.next, drm_fence_object_t, ring);
atomic_inc(&fence->usage);
mutex_unlock(&dev->struct_mutex);
diff = (old_sequence - fence->sequence) & driver->sequence_mask;
int ignore_signals, uint32_t mask)
{
drm_fence_manager_t *fm = &dev->fm;
+ drm_fence_class_manager_t *fc = &fm->class[fence->class];
+
unsigned long _end = jiffies + 3*DRM_HZ;
int ret = 0;
do {
- DRM_WAIT_ON(ret, fm->fence_queue, 3 * DRM_HZ,
+ DRM_WAIT_ON(ret, fc->fence_queue, 3 * DRM_HZ,
fence_signaled(dev, fence, mask, 1));
if (time_after_eq(jiffies, _end))
break;
}
int drm_fence_object_emit(drm_device_t * dev, drm_fence_object_t * fence,
- uint32_t fence_flags, uint32_t type)
+ uint32_t fence_flags, uint32_t class, uint32_t type)
{
drm_fence_manager_t *fm = &dev->fm;
drm_fence_driver_t *driver = dev->driver->fence_driver;
int ret;
drm_fence_unring(dev, &fence->ring);
- ret = driver->emit(dev, fence->class, fence_flags, &sequence, &native_type);
+ ret = driver->emit(dev, class, fence_flags, &sequence, &native_type);
if (ret)
return ret;
write_lock_irqsave(&fm->lock, flags);
+ fence->class = class;
fence->type = type;
fence->flush_mask = 0x00;
fence->submitted_flush = 0x00;
fence->signaled = 0x00;
fence->sequence = sequence;
fence->native_type = native_type;
- list_add_tail(&fence->ring, &fm->ring);
+ list_add_tail(&fence->ring, &fm->class[class].ring);
write_unlock_irqrestore(&fm->lock, flags);
return 0;
}
-static int drm_fence_object_init(drm_device_t * dev, uint32_t type,
+static int drm_fence_object_init(drm_device_t * dev, uint32_t class,
+ uint32_t type,
uint32_t fence_flags,
drm_fence_object_t * fence)
{
write_lock_irqsave(&fm->lock, flags);
INIT_LIST_HEAD(&fence->ring);
- fence->class = 0;
+ fence->class = class;
fence->type = type;
fence->flush_mask = 0;
fence->submitted_flush = 0;
fence->sequence = 0;
write_unlock_irqrestore(&fm->lock, flags);
if (fence_flags & DRM_FENCE_FLAG_EMIT) {
- ret = drm_fence_object_emit(dev, fence, fence_flags, type);
+ ret = drm_fence_object_emit(dev, fence, fence_flags,
+ fence->class, type);
}
return ret;
}
EXPORT_SYMBOL(drm_fence_add_user_object);
-int drm_fence_object_create(drm_device_t * dev, uint32_t type,
+int drm_fence_object_create(drm_device_t * dev, uint32_t class, uint32_t type,
unsigned flags, drm_fence_object_t ** c_fence)
{
drm_fence_object_t *fence;
fence = drm_ctl_alloc(sizeof(*fence), DRM_MEM_FENCE);
if (!fence)
return -ENOMEM;
- ret = drm_fence_object_init(dev, type, flags, fence);
+ ret = drm_fence_object_init(dev, class, type, flags, fence);
if (ret) {
drm_fence_usage_deref_unlocked(dev, fence);
return ret;
void drm_fence_manager_init(drm_device_t * dev)
{
drm_fence_manager_t *fm = &dev->fm;
+ drm_fence_class_manager_t *class;
drm_fence_driver_t *fed = dev->driver->fence_driver;
int i;
+
fm->lock = RW_LOCK_UNLOCKED;
write_lock(&fm->lock);
- INIT_LIST_HEAD(&fm->ring);
- fm->pending_flush = 0;
- DRM_INIT_WAITQUEUE(&fm->fence_queue);
fm->initialized = 0;
- if (fed) {
- fm->initialized = 1;
- atomic_set(&fm->count, 0);
- for (i = 0; i < fed->no_types; ++i) {
- fm->fence_types[i] = &fm->ring;
- }
+ if (!fed)
+ goto out_unlock;
+
+ fm->initialized = 1;
+ fm->num_classes = fed->num_classes;
+ BUG_ON(fm->num_classes > _DRM_FENCE_CLASSES);
+
+ for (i=0; i<fm->num_classes; ++i) {
+ class = &fm->class[i];
+
+ INIT_LIST_HEAD(&class->ring);
+ class->pending_flush = 0;
+ DRM_INIT_WAITQUEUE(&class->fence_queue);
}
+
+ atomic_set(&fm->count, 0);
+ out_unlock:
write_unlock(&fm->lock);
}
case drm_fence_create:
if (arg.flags & DRM_FENCE_FLAG_EMIT)
LOCK_TEST_WITH_RETURN(dev, filp);
- ret = drm_fence_object_create(dev, arg.type, arg.flags, &fence);
+ ret = drm_fence_object_create(dev, arg.class,
+ arg.type, arg.flags, &fence);
if (ret)
return ret;
ret = drm_fence_add_user_object(priv, fence,
fence = drm_lookup_fence_object(priv, arg.handle);
if (!fence)
return -EINVAL;
- ret = drm_fence_object_emit(dev, fence, arg.flags, arg.type);
+ ret = drm_fence_object_emit(dev, fence, arg.flags, arg.class,
+ arg.type);
break;
case drm_fence_buffers:
if (!dev->bm.initialized) {
uint32_t submitted_flush;
} drm_fence_object_t;
+#define _DRM_FENCE_CLASSES 8
#define _DRM_FENCE_TYPE_EXE 0x00
-typedef struct drm_fence_manager {
- int initialized;
- rwlock_t lock;
-
- /*
- * The list below should be maintained in sequence order and
- * access is protected by the above spinlock.
- */
-
+typedef struct drm_fence_class_manager {
struct list_head ring;
- struct list_head *fence_types[32];
- volatile uint32_t pending_flush;
+ uint32_t pending_flush;
wait_queue_head_t fence_queue;
int pending_exe_flush;
uint32_t last_exe_flush;
uint32_t exe_flush_sequence;
+} drm_fence_class_manager_t;
+
+typedef struct drm_fence_manager {
+ int initialized;
+ rwlock_t lock;
+ drm_fence_class_manager_t class[_DRM_FENCE_CLASSES];
+ uint32_t num_classes;
atomic_t count;
} drm_fence_manager_t;
typedef struct drm_fence_driver {
- int no_types;
+ uint32_t num_classes;
uint32_t wrap_diff;
uint32_t flush_diff;
uint32_t sequence_mask;
uint32_t sequence, uint32_t type);
extern void drm_fence_manager_init(struct drm_device *dev);
extern void drm_fence_manager_takedown(struct drm_device *dev);
-extern void drm_fence_flush_old(struct drm_device *dev, uint32_t sequence);
+extern void drm_fence_flush_old(struct drm_device *dev, uint32_t class,
+ uint32_t sequence);
extern int drm_fence_object_flush(struct drm_device *dev,
drm_fence_object_t * fence, uint32_t type);
extern int drm_fence_object_signaled(drm_fence_object_t * fence, uint32_t type);
drm_fence_object_t * fence,
int lazy, int ignore_signals, uint32_t mask);
extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
- uint32_t fence_flags,
+ uint32_t fence_flags, uint32_t class,
drm_fence_object_t ** c_fence);
extern int drm_fence_add_user_object(drm_file_t * priv,
drm_fence_object_t * fence, int shareable);
extern int drm_bo_move_accel_cleanup(drm_buffer_object_t * bo,
int evict,
int no_wait,
+ uint32_t fence_class,
uint32_t fence_type,
uint32_t fence_flags,
drm_bo_mem_reg_t * new_mem);