Merge branch 'master' of git+ssh://git.freedesktop.org/git/mesa/drm into modesetting-101
[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, CONNECTOR_VGA, MT_NONE, 0, GPIO_DDC1,
62         {
63                 0, -1, -1, -1, -1, -1, -1, -1
64         },
65         "VGA"
66 };
67
68 static struct radeon_ms_connector radeon_ms_dvi_i_2 = {
69         NULL, NULL, NULL, CONNECTOR_DVI_I, MT_NONE, 0, GPIO_DDC2,
70         {
71                 1, -1, -1, -1, -1, -1, -1, -1
72         },
73         "DVI-I"
74 };
75
76 static struct radeon_ms_properties properties[] = {
77         /* default only one VGA connector */
78         {
79                 0, 0, 27000, 25000, 200000, 1, 1, 1, 1,
80                 {
81                         &radeon_ms_dac1, NULL, NULL, NULL, NULL, NULL, NULL,
82                         NULL
83                 },
84                 {
85                         &radeon_ms_vga, NULL, NULL, NULL, NULL, NULL, NULL,
86                         NULL
87                 }
88         },
89         {
90                 0x1043, 0x176, 27000, 25000, 200000, 1, 1, 1, 1,
91                 {
92                         &radeon_ms_dac1, &radeon_ms_dac2, NULL, NULL, NULL,
93                         NULL, NULL, NULL
94                 },
95                 {
96                         &radeon_ms_vga, &radeon_ms_dvi_i_2, NULL, NULL, NULL,
97                         NULL, NULL, NULL
98                 }
99         },
100         {
101                 0x1002, 0x4150, 27000, 25000, 200000, 1, 1, 1, 1,
102                 {
103                         &radeon_ms_dac1, &radeon_ms_dac2, NULL, NULL, NULL,
104                         NULL, NULL, NULL
105                 },
106                 {
107                         &radeon_ms_vga, &radeon_ms_dvi_i_2, NULL, NULL, NULL,
108                         NULL, NULL, NULL
109                 }
110         },
111 };
112
113 extern const uint32_t radeon_cp_microcode[];
114 extern const uint32_t r200_cp_microcode[];
115 extern const uint32_t r300_cp_microcode[];
116
117 static void radeon_flush_cache(struct drm_device *dev)
118 {
119         struct drm_radeon_private *dev_priv = dev->dev_private;
120         uint32_t cmd[6];
121         int i, ret;
122
123         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
124         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
125         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT, 0);
126         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
127         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT, 0);
128         cmd[5] = RB3D_ZCACHE_CTLSTAT__ZC_FLUSH;
129         /* try to wait but if we timeout we likely are in bad situation */
130         for (i = 0; i < dev_priv->usec_timeout; i++) {
131                 ret = radeon_ms_ring_emit(dev, cmd, 6);
132                 if (!ret) {
133                         break;
134                 }
135         }
136 }
137
138 static void r300_flush_cache(struct drm_device *dev)
139 {
140         struct drm_radeon_private *dev_priv = dev->dev_private;
141         uint32_t cmd[6];
142         int i, ret;
143
144         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
145         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
146         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT_R3, 0);
147         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT_R3, DC_FLUSH, 3);
148         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT_R3, 0);
149         cmd[5] = RB3D_ZCACHE_CTLSTAT_R3__ZC_FLUSH;
150         /* try to wait but if we timeout we likely are in bad situation */
151         for (i = 0; i < dev_priv->usec_timeout; i++) {
152                 ret = radeon_ms_ring_emit(dev, cmd, 6);
153                 if (!ret) {
154                         break;
155                 }
156         }
157 }
158
159 int radeon_ms_family_init(struct drm_device *dev)
160 {
161         struct drm_radeon_private *dev_priv = dev->dev_private;
162         int i;
163
164         dev_priv->microcode = radeon_cp_microcode;
165         dev_priv->irq_emit = radeon_ms_irq_emit;
166
167         switch (dev_priv->family) {
168         case CHIP_R100:
169         case CHIP_R200:
170                 dev_priv->microcode = radeon_cp_microcode;
171                 dev_priv->flush_cache = radeon_flush_cache;
172                 break;
173         case CHIP_RV200:
174         case CHIP_RV250:
175         case CHIP_RV280:
176         case CHIP_RS300:
177                 dev_priv->microcode = r200_cp_microcode;
178                 dev_priv->flush_cache = radeon_flush_cache;
179                 break;
180         case CHIP_R300:
181         case CHIP_R350:
182         case CHIP_R360:
183         case CHIP_RV350:
184         case CHIP_RV370:
185         case CHIP_RV380:
186         case CHIP_RS400:
187         case CHIP_RV410:
188         case CHIP_R420:
189         case CHIP_R430:
190         case CHIP_R480:
191                 dev_priv->microcode = r300_cp_microcode;
192                 dev_priv->flush_cache = r300_flush_cache;
193                 break;
194         default:
195                 DRM_ERROR("Unknown radeon family, aborting\n");
196                 return -EINVAL;
197         }
198         switch (dev_priv->bus_type) {
199         case RADEON_AGP:
200                 dev_priv->create_ttm = drm_agp_init_ttm;
201                 dev_priv->bus_init = radeon_ms_agp_init;
202                 dev_priv->bus_restore = radeon_ms_agp_restore;
203                 dev_priv->bus_save = radeon_ms_agp_save;
204                 break;
205         case RADEON_PCIE:
206                 dev_priv->create_ttm = radeon_ms_pcie_create_ttm;
207                 dev_priv->bus_finish = radeon_ms_pcie_finish;
208                 dev_priv->bus_init = radeon_ms_pcie_init;
209                 dev_priv->bus_restore = radeon_ms_pcie_restore;
210                 dev_priv->bus_save = radeon_ms_pcie_save;
211                 break;
212         default:
213                 DRM_ERROR("Unknown radeon bus type, aborting\n");
214                 return -EINVAL;
215         }
216         dev_priv->properties = NULL;
217         for (i = 1; i < sizeof(properties)/sizeof(properties[0]); i++) {
218                 if (dev->pdev->subsystem_vendor == properties[i].subvendor &&
219                     dev->pdev->subsystem_device == properties[i].subdevice) {
220                     DRM_INFO("[radeon_ms] found properties for 0x%04X:0x%04X\n",
221                              properties[i].subvendor, properties[i].subdevice);
222                     dev_priv->properties = &properties[i];
223                 }
224         }
225         if (dev_priv->properties == NULL) {
226                 dev_priv->properties = &properties[0];
227         }
228         return 0;
229 }