| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright 2005 Thomas Hellstrom. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a | 
					
						
							|  |  |  |  * copy of this software and associated documentation files (the "Software"), | 
					
						
							|  |  |  |  * to deal in the Software without restriction, including without limitation | 
					
						
							|  |  |  |  * the rights to use, copy, modify, merge, publish, distribute, sub license, | 
					
						
							|  |  |  |  * and/or sell copies of the Software, and to permit persons to whom the | 
					
						
							|  |  |  |  * Software is furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice (including the | 
					
						
							|  |  |  |  * next paragraph) shall be included in all copies or substantial portions | 
					
						
							|  |  |  |  * of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | 
					
						
							|  |  |  |  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 
					
						
							|  |  |  |  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
					
						
							|  |  |  |  * DEALINGS IN THE SOFTWARE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Author: Thomas Hellstrom 2005. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Video and XvMC related functions. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 18:01:07 +01:00
										 |  |  | #include <drm/drmP.h>
 | 
					
						
							|  |  |  | #include <drm/via_drm.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | #include "via_drv.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:32:42 +02:00
										 |  |  | void via_init_futex(drm_via_private_t *dev_priv) | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-24 15:58:57 +10:00
										 |  |  | 	DRM_DEBUG("\n"); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { | 
					
						
							| 
									
										
										
										
											2013-12-11 11:34:43 +01:00
										 |  |  | 		init_waitqueue_head(&(dev_priv->decoder_queue[i])); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 		XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:32:42 +02:00
										 |  |  | void via_cleanup_futex(drm_via_private_t *dev_priv) | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-09-25 14:28:13 +10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-11 15:32:42 +02:00
										 |  |  | void via_release_futex(drm_via_private_t *dev_priv, int context) | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int i; | 
					
						
							|  |  |  | 	volatile int *lock; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-12 21:52:46 +11:00
										 |  |  | 	if (!dev_priv->sarea_priv) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-25 14:28:13 +10:00
										 |  |  | 	for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { | 
					
						
							| 
									
										
										
										
											2005-11-12 21:52:46 +11:00
										 |  |  | 		lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i); | 
					
						
							| 
									
										
										
										
											2005-09-25 14:28:13 +10:00
										 |  |  | 		if ((_DRM_LOCKING_CONTEXT(*lock) == context)) { | 
					
						
							|  |  |  | 			if (_DRM_LOCK_IS_HELD(*lock) | 
					
						
							|  |  |  | 			    && (*lock & _DRM_LOCK_CONT)) { | 
					
						
							| 
									
										
										
										
											2013-12-11 11:34:43 +01:00
										 |  |  | 				wake_up(&(dev_priv->decoder_queue[i])); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			*lock = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-09-25 14:28:13 +10:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-03 12:06:45 +10:00
										 |  |  | int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv) | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-03 12:06:45 +10:00
										 |  |  | 	drm_via_futex_t *fx = data; | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 	volatile int *lock; | 
					
						
							|  |  |  | 	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; | 
					
						
							|  |  |  | 	drm_via_sarea_t *sAPriv = dev_priv->sarea_priv; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-24 15:58:57 +10:00
										 |  |  | 	DRM_DEBUG("\n"); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-27 14:11:03 -07:00
										 |  |  | 	if (fx->lock >= VIA_NR_XVMC_LOCKS) | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 		return -EFAULT; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-03 12:06:45 +10:00
										 |  |  | 	lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-03 12:06:45 +10:00
										 |  |  | 	switch (fx->func) { | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 	case VIA_FUTEX_WAIT: | 
					
						
							| 
									
										
										
										
											2007-09-03 12:06:45 +10:00
										 |  |  | 		DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock], | 
					
						
							| 
									
										
										
										
											2013-12-11 11:34:41 +01:00
										 |  |  | 			    (fx->ms / 10) * (HZ / 100), *lock != fx->val); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 		return ret; | 
					
						
							|  |  |  | 	case VIA_FUTEX_WAKE: | 
					
						
							| 
									
										
										
										
											2013-12-11 11:34:43 +01:00
										 |  |  | 		wake_up(&(dev_priv->decoder_queue[fx->lock])); | 
					
						
							| 
									
										
										
										
											2005-06-28 22:48:56 +10:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } |