Home | History | Annotate | Line # | Download | only in via
via_video.c revision 1.1.1.3
      1 /*	$NetBSD: via_video.c,v 1.1.1.3 2018/08/27 01:34:59 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the
     14  * next paragraph) shall be included in all copies or substantial portions
     15  * of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     20  * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     23  * DEALINGS IN THE SOFTWARE.
     24  *
     25  * Author: Thomas Hellstrom 2005.
     26  *
     27  * Video and XvMC related functions.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: via_video.c,v 1.1.1.3 2018/08/27 01:34:59 riastradh Exp $");
     32 
     33 #include <drm/drmP.h>
     34 #include <drm/via_drm.h>
     35 #include "via_drv.h"
     36 
     37 void via_init_futex(drm_via_private_t *dev_priv)
     38 {
     39 	unsigned int i;
     40 
     41 	DRM_DEBUG("\n");
     42 
     43 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
     44 		init_waitqueue_head(&(dev_priv->decoder_queue[i]));
     45 		XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
     46 	}
     47 }
     48 
     49 void via_cleanup_futex(drm_via_private_t *dev_priv)
     50 {
     51 }
     52 
     53 void via_release_futex(drm_via_private_t *dev_priv, int context)
     54 {
     55 	unsigned int i;
     56 	volatile int *lock;
     57 
     58 	if (!dev_priv->sarea_priv)
     59 		return;
     60 
     61 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
     62 		lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
     63 		if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
     64 			if (_DRM_LOCK_IS_HELD(*lock)
     65 			    && (*lock & _DRM_LOCK_CONT)) {
     66 				wake_up(&(dev_priv->decoder_queue[i]));
     67 			}
     68 			*lock = 0;
     69 		}
     70 	}
     71 }
     72 
     73 int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
     74 {
     75 	drm_via_futex_t *fx = data;
     76 	volatile int *lock;
     77 	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
     78 	drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
     79 	int ret = 0;
     80 
     81 	DRM_DEBUG("\n");
     82 
     83 	if (fx->lock >= VIA_NR_XVMC_LOCKS)
     84 		return -EFAULT;
     85 
     86 	lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
     87 
     88 	switch (fx->func) {
     89 	case VIA_FUTEX_WAIT:
     90 		DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
     91 			    (fx->ms / 10) * (HZ / 100), *lock != fx->val);
     92 		return ret;
     93 	case VIA_FUTEX_WAKE:
     94 		wake_up(&(dev_priv->decoder_queue[fx->lock]));
     95 		return 0;
     96 	}
     97 	return 0;
     98 }
     99