Home | History | Annotate | Line # | Download | only in via
via_video.c revision 1.1.1.4
      1 /*	$NetBSD: via_video.c,v 1.1.1.4 2021/12/18 20:15:54 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.4 2021/12/18 20:15:54 riastradh Exp $");
     32 
     33 #include <drm/drm_device.h>
     34 #include <drm/via_drm.h>
     35 
     36 #include "via_drv.h"
     37 
     38 void via_init_futex(drm_via_private_t *dev_priv)
     39 {
     40 	unsigned int i;
     41 
     42 	DRM_DEBUG("\n");
     43 
     44 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
     45 		init_waitqueue_head(&(dev_priv->decoder_queue[i]));
     46 		XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
     47 	}
     48 }
     49 
     50 void via_cleanup_futex(drm_via_private_t *dev_priv)
     51 {
     52 }
     53 
     54 void via_release_futex(drm_via_private_t *dev_priv, int context)
     55 {
     56 	unsigned int i;
     57 	volatile int *lock;
     58 
     59 	if (!dev_priv->sarea_priv)
     60 		return;
     61 
     62 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
     63 		lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
     64 		if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
     65 			if (_DRM_LOCK_IS_HELD(*lock)
     66 			    && (*lock & _DRM_LOCK_CONT)) {
     67 				wake_up(&(dev_priv->decoder_queue[i]));
     68 			}
     69 			*lock = 0;
     70 		}
     71 	}
     72 }
     73 
     74 int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
     75 {
     76 	drm_via_futex_t *fx = data;
     77 	volatile int *lock;
     78 	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
     79 	drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
     80 	int ret = 0;
     81 
     82 	DRM_DEBUG("\n");
     83 
     84 	if (fx->lock >= VIA_NR_XVMC_LOCKS)
     85 		return -EFAULT;
     86 
     87 	lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
     88 
     89 	switch (fx->func) {
     90 	case VIA_FUTEX_WAIT:
     91 		VIA_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
     92 			    (fx->ms / 10) * (HZ / 100), *lock != fx->val);
     93 		return ret;
     94 	case VIA_FUTEX_WAKE:
     95 		wake_up(&(dev_priv->decoder_queue[fx->lock]));
     96 		return 0;
     97 	}
     98 	return 0;
     99 }
    100