radeon_ms: update to follow lastest modesetting change
[platform/upstream/libdrm.git] / shared-core / radeon_ms_family.c
1 /*
2  * Copyright 2007 Jérôme Glisse
3  * 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, sublicense,
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 next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
19  * PRECISION INSIGHT 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 /*
25  * Authors:
26  *    Jerome Glisse <glisse@freedesktop.org>
27  */
28 #include "drmP.h"
29 #include "drm.h"
30 #include "radeon_ms.h"
31
32 static struct radeon_ms_output radeon_ms_dac1 = {
33         OUTPUT_DAC1,
34         NULL,
35         NULL,
36         radeon_ms_dac1_initialize,
37         radeon_ms_dac1_detect,
38         radeon_ms_dac1_dpms,
39         radeon_ms_dac1_get_modes,
40         radeon_ms_dac1_mode_fixup,
41         radeon_ms_dac1_mode_set,
42         radeon_ms_dac1_restore,
43         radeon_ms_dac1_save
44 };
45
46 static struct radeon_ms_output radeon_ms_dac2 = {
47         OUTPUT_DAC2,
48         NULL,
49         NULL,
50         radeon_ms_dac2_initialize,
51         radeon_ms_dac2_detect,
52         radeon_ms_dac2_dpms,
53         radeon_ms_dac2_get_modes,
54         radeon_ms_dac2_mode_fixup,
55         radeon_ms_dac2_mode_set,
56         radeon_ms_dac2_restore,
57         radeon_ms_dac2_save
58 };
59
60 static struct radeon_ms_connector radeon_ms_vga = {
61         NULL, NULL, NULL, ConnectorVGA, MT_NONE, 0, GPIO_DDC1,
62         {
63                 0, -1, -1, -1, -1, -1, -1, -1
64         }
65 };
66
67 static struct radeon_ms_connector radeon_ms_dvi_i_2 = {
68         NULL, NULL, NULL, ConnectorDVII, MT_NONE, 0, GPIO_DDC2,
69         {
70                 1, -1, -1, -1, -1, -1, -1, -1
71         }
72 };
73
74 static struct radeon_ms_properties properties[] = {
75         /* default only one VGA connector */
76         {
77                 0, 0, 27000, 25000, 200000, 1, 1, 1, 1,
78                 {
79                         &radeon_ms_dac1, NULL, NULL, NULL, NULL, NULL, NULL,
80                         NULL
81                 },
82                 {
83                         &radeon_ms_vga, NULL, NULL, NULL, NULL, NULL, NULL,
84                         NULL
85                 }
86         },
87         {
88                 0x1043, 0x176, 27000, 25000, 200000, 1, 1, 1, 1,
89                 {
90                         &radeon_ms_dac1, &radeon_ms_dac2, NULL, NULL, NULL,
91                         NULL, NULL, NULL
92                 },
93                 {
94                         &radeon_ms_vga, &radeon_ms_dvi_i_2, NULL, NULL, NULL,
95                         NULL, NULL, NULL
96                 }
97         },
98         {
99                 0x1002, 0x4150, 27000, 25000, 200000, 1, 1, 1, 1,
100                 {
101                         &radeon_ms_dac1, &radeon_ms_dac2, NULL, NULL, NULL,
102                         NULL, NULL, NULL
103                 },
104                 {
105                         &radeon_ms_vga, &radeon_ms_dvi_i_2, NULL, NULL, NULL,
106                         NULL, NULL, NULL
107                 }
108         },
109 };
110
111 extern const uint32_t radeon_cp_microcode[];
112 extern const uint32_t r200_cp_microcode[];
113 extern const uint32_t r300_cp_microcode[];
114
115 static void radeon_flush_cache(struct drm_device *dev)
116 {
117         struct drm_radeon_private *dev_priv = dev->dev_private;
118         uint32_t cmd[6];
119         int i, ret;
120
121         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
122         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
123         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT, 0);
124         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
125         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT, 0);
126         cmd[5] = RB3D_ZCACHE_CTLSTAT__ZC_FLUSH;
127         /* try to wait but if we timeout we likely are in bad situation */
128         for (i = 0; i < dev_priv->usec_timeout; i++) {
129                 ret = radeon_ms_ring_emit(dev, cmd, 6);
130                 if (!ret) {
131                         break;
132                 }
133         }
134 }
135
136 static void r300_flush_cache(struct drm_device *dev)
137 {
138         struct drm_radeon_private *dev_priv = dev->dev_private;
139         uint32_t cmd[6];
140         int i, ret;
141
142         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
143         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
144         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT_R3, 0);
145         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT_R3, DC_FLUSH, 3);
146         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT_R3, 0);
147         cmd[5] = RB3D_ZCACHE_CTLSTAT_R3__ZC_FLUSH;
148         /* try to wait but if we timeout we likely are in bad situation */
149         for (i = 0; i < dev_priv->usec_timeout; i++) {
150                 ret = radeon_ms_ring_emit(dev, cmd, 6);
151                 if (!ret) {
152                         break;
153                 }
154         }
155 }
156
157 int radeon_ms_family_init(struct drm_device *dev)
158 {
159         struct drm_radeon_private *dev_priv = dev->dev_private;
160         int i;
161
162         dev_priv->microcode = radeon_cp_microcode;
163         dev_priv->irq_emit = radeon_ms_irq_emit;
164
165         switch (dev_priv->family) {
166         case CHIP_R100:
167         case CHIP_R200:
168                 dev_priv->microcode = radeon_cp_microcode;
169                 dev_priv->flush_cache = radeon_flush_cache;
170                 break;
171         case CHIP_RV200:
172         case CHIP_RV250:
173         case CHIP_RV280:
174         case CHIP_RS300:
175                 dev_priv->microcode = r200_cp_microcode;
176                 dev_priv->flush_cache = radeon_flush_cache;
177                 break;
178         case CHIP_R300:
179         case CHIP_R350:
180         case CHIP_R360:
181         case CHIP_RV350:
182         case CHIP_RV370:
183         case CHIP_RV380:
184         case CHIP_RS400:
185         case CHIP_RV410:
186         case CHIP_R420:
187         case CHIP_R430:
188         case CHIP_R480:
189                 dev_priv->microcode = r300_cp_microcode;
190                 dev_priv->flush_cache = r300_flush_cache;
191                 break;
192         default:
193                 DRM_ERROR("Unknown radeon family, aborting\n");
194                 return -EINVAL;
195         }
196         switch (dev_priv->bus_type) {
197         case RADEON_AGP:
198                 dev_priv->create_ttm = drm_agp_init_ttm;
199                 dev_priv->bus_init = radeon_ms_agp_init;
200                 dev_priv->bus_restore = radeon_ms_agp_restore;
201                 dev_priv->bus_save = radeon_ms_agp_save;
202                 break;
203         case RADEON_PCIE:
204                 dev_priv->create_ttm = radeon_ms_pcie_create_ttm;
205                 dev_priv->bus_finish = radeon_ms_pcie_finish;
206                 dev_priv->bus_init = radeon_ms_pcie_init;
207                 dev_priv->bus_restore = radeon_ms_pcie_restore;
208                 dev_priv->bus_save = radeon_ms_pcie_save;
209                 break;
210         default:
211                 DRM_ERROR("Unknown radeon bus type, aborting\n");
212                 return -EINVAL;
213         }
214         dev_priv->properties = NULL;
215         for (i = 1; i < sizeof(properties)/sizeof(properties[0]); i++) {
216                 if (dev->pdev->subsystem_vendor == properties[i].subvendor &&
217                     dev->pdev->subsystem_device == properties[i].subdevice) {
218                     DRM_INFO("[radeon_ms] found properties for 0x%04X:0x%04X\n",
219                              properties[i].subvendor, properties[i].subdevice);
220                     dev_priv->properties = &properties[i];
221                 }
222         }
223         if (dev_priv->properties == NULL) {
224                 dev_priv->properties = &properties[0];
225         }
226         return 0;
227 }