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