Changed unsigned to uint32_t in some ioctl parameters. Introduced first
[platform/upstream/libdrm.git] / shared-core / via_map.c
1 /*
2  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
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.
23  */
24 #include "drmP.h"
25 #include "via_drv.h"
26
27 int via_do_init_map(drm_device_t * dev, drm_via_init_t * init)
28 {
29         drm_via_private_t *dev_priv;
30         unsigned int i;
31
32         DRM_DEBUG("%s\n", __FUNCTION__);
33
34         dev_priv = drm_alloc(sizeof(drm_via_private_t), DRM_MEM_DRIVER);
35         if (dev_priv == NULL)
36                 return -ENOMEM;
37
38         memset(dev_priv, 0, sizeof(drm_via_private_t));
39
40         DRM_GETSAREA();
41         if (!dev_priv->sarea) {
42                 DRM_ERROR("could not find sarea!\n");
43                 dev->dev_private = (void *)dev_priv;
44                 via_do_cleanup_map(dev);
45                 return -EINVAL;
46         }
47
48         dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
49         if (!dev_priv->fb) {
50                 DRM_ERROR("could not find framebuffer!\n");
51                 dev->dev_private = (void *)dev_priv;
52                 via_do_cleanup_map(dev);
53                 return -EINVAL;
54         }
55         dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
56         if (!dev_priv->mmio) {
57                 DRM_ERROR("could not find mmio region!\n");
58                 dev->dev_private = (void *)dev_priv;
59                 via_do_cleanup_map(dev);
60                 return -EINVAL;
61         }
62
63         dev_priv->sarea_priv =
64             (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
65                                  init->sarea_priv_offset);
66
67         dev_priv->agpAddr = init->agpAddr;
68
69         for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i)
70                 DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
71
72         dev->dev_private = (void *)dev_priv;
73
74         return 0;
75 }
76
77 int via_do_cleanup_map(drm_device_t * dev)
78 {
79         if (dev->dev_private) {
80
81                 drm_via_private_t *dev_priv = dev->dev_private;
82
83                 via_dma_cleanup(dev);
84
85                 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
86                 dev->dev_private = NULL;
87         }
88
89         return 0;
90 }
91
92 int via_map_init(DRM_IOCTL_ARGS)
93 {
94         DRM_DEVICE;
95         drm_via_init_t init;
96
97         DRM_DEBUG("%s\n", __FUNCTION__);
98
99         DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t *) data, sizeof(init));
100
101         switch (init.func) {
102         case VIA_INIT_MAP:
103                 return via_do_init_map(dev, &init);
104         case VIA_CLEANUP_MAP:
105                 return via_do_cleanup_map(dev);
106         }
107
108         return -EINVAL;
109 }
110
111 int via_decoder_futex(DRM_IOCTL_ARGS)
112 {
113         DRM_DEVICE;
114         drm_via_futex_t fx;
115         volatile int *lock;
116         drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
117         drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
118         int ret = 0;
119
120         DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t *) data, sizeof(fx));
121
122         if (fx.lock > VIA_NR_XVMC_LOCKS)
123                 return -EFAULT;
124
125         lock = XVMCLOCKPTR(sAPriv, fx.lock);
126
127         switch (fx.func) {
128         case VIA_FUTEX_WAIT:
129                 DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx.lock],
130                             (fx.ms / 10) * (DRM_HZ / 100), *lock != fx.val);
131                 return ret;
132         case VIA_FUTEX_WAKE:
133                 DRM_WAKEUP(&(dev_priv->decoder_queue[fx.lock]));
134                 return 0;
135         }
136         return 0;
137 }