2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 static int via_do_init_map(drm_device_t * dev, drm_via_init_t * init)
30 drm_via_private_t *dev_priv;
33 DRM_DEBUG("%s\n", __FUNCTION__);
35 dev_priv = drm_alloc(sizeof(drm_via_private_t), DRM_MEM_DRIVER);
39 memset(dev_priv, 0, sizeof(drm_via_private_t));
42 if (!dev_priv->sarea) {
43 DRM_ERROR("could not find sarea!\n");
44 dev->dev_private = (void *)dev_priv;
45 via_do_cleanup_map(dev);
49 dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
51 DRM_ERROR("could not find framebuffer!\n");
52 dev->dev_private = (void *)dev_priv;
53 via_do_cleanup_map(dev);
56 dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
57 if (!dev_priv->mmio) {
58 DRM_ERROR("could not find mmio region!\n");
59 dev->dev_private = (void *)dev_priv;
60 via_do_cleanup_map(dev);
64 dev_priv->sarea_priv =
65 (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
66 init->sarea_priv_offset);
68 dev_priv->agpAddr = init->agpAddr;
70 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
71 DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
72 XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
75 dev->dev_private = (void *)dev_priv;
80 int via_do_cleanup_map(drm_device_t * dev)
82 if (dev->dev_private) {
84 drm_via_private_t *dev_priv = dev->dev_private;
88 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
89 dev->dev_private = NULL;
95 int via_map_init(DRM_IOCTL_ARGS)
100 DRM_DEBUG("%s\n", __FUNCTION__);
102 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t *) data, sizeof(init));
106 return via_do_init_map(dev, &init);
107 case VIA_CLEANUP_MAP:
108 return via_do_cleanup_map(dev);
115 int via_decoder_futex(DRM_IOCTL_ARGS)
120 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
121 drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
124 DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t *) data, sizeof(fx));
126 if (fx.lock > VIA_NR_XVMC_LOCKS)
129 lock = (int *)XVMCLOCKPTR(sAPriv, fx.lock);
133 DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx.lock],
134 (fx.ms / 10) * (DRM_HZ / 100), *lock != fx.val);
137 DRM_WAKEUP(&(dev_priv->decoder_queue[fx.lock]));