OSDN Git Service

libdrm/nouveau: incr refcount on ref fence before decr on old fence
[android-x86/external-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_drm.h"
26 #include "via_drv.h"
27
28 static int via_do_init_map(struct drm_device * dev, drm_via_init_t * init)
29 {
30         drm_via_private_t *dev_priv = dev->dev_private;
31         int ret = 0;
32
33         DRM_DEBUG("\n");
34
35         dev_priv->sarea = drm_getsarea(dev);
36         if (!dev_priv->sarea) {
37                 DRM_ERROR("could not find sarea!\n");
38                 dev->dev_private = (void *)dev_priv;
39                 via_do_cleanup_map(dev);
40                 return -EINVAL;
41         }
42
43         dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
44         if (!dev_priv->fb) {
45                 DRM_ERROR("could not find framebuffer!\n");
46                 dev->dev_private = (void *)dev_priv;
47                 via_do_cleanup_map(dev);
48                 return -EINVAL;
49         }
50         dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
51         if (!dev_priv->mmio) {
52                 DRM_ERROR("could not find mmio region!\n");
53                 dev->dev_private = (void *)dev_priv;
54                 via_do_cleanup_map(dev);
55                 return -EINVAL;
56         }
57
58         dev_priv->sarea_priv =
59             (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
60                                  init->sarea_priv_offset);
61
62         dev_priv->agpAddr = init->agpAddr;
63
64         via_init_futex( dev_priv );
65 #ifdef VIA_HAVE_DMABLIT
66         via_init_dmablit( dev );
67 #endif
68 #ifdef VIA_HAVE_FENCE
69         dev_priv->emit_0_sequence = 0;
70         dev_priv->have_idlelock = 0;
71         spin_lock_init(&dev_priv->fence_lock);
72 #endif /* VIA_HAVE_FENCE */
73         dev->dev_private = (void *)dev_priv;
74 #ifdef VIA_HAVE_BUFFER
75         ret = drm_bo_driver_init(dev);
76         if (ret)
77                 DRM_ERROR("Could not initialize buffer object driver.\n");
78 #endif
79         return ret;
80
81 }
82
83 int via_do_cleanup_map(struct drm_device * dev)
84 {
85         via_dma_cleanup(dev);
86
87         return 0;
88 }
89
90
91 int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
92 {
93         drm_via_init_t *init = data;
94
95         DRM_DEBUG("\n");
96
97         switch (init->func) {
98         case VIA_INIT_MAP:
99                 return via_do_init_map(dev, init);
100         case VIA_CLEANUP_MAP:
101                 return via_do_cleanup_map(dev);
102         }
103
104         return -EINVAL;
105 }
106
107 int via_driver_load(struct drm_device *dev, unsigned long chipset)
108 {
109         drm_via_private_t *dev_priv;
110         int ret = 0;
111
112         dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
113         if (dev_priv == NULL)
114                 return -ENOMEM;
115
116         dev->dev_private = (void *)dev_priv;
117
118         dev_priv->chipset = chipset;
119
120 #ifdef VIA_HAVE_CORE_MM
121         ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
122         if (ret) {
123                 drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
124                 return ret;
125         }
126 #endif
127
128         ret = drm_vblank_init(dev, 1);
129         if (ret) {
130                 drm_sman_takedown(&dev_priv->sman);
131                 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
132                 return ret;
133         }
134
135         return 0;
136
137 }
138
139 int via_driver_unload(struct drm_device *dev)
140 {
141         drm_via_private_t *dev_priv = dev->dev_private;
142
143 #ifdef VIA_HAVE_CORE_MM
144         drm_sman_takedown(&dev_priv->sman);
145 #endif
146         drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
147
148         return 0;
149 }