]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/gpu/drm/radeon/r420.c
drm/radeon/kms: add R4XX mc register access helper.
[net-next-2.6.git] / drivers / gpu / drm / radeon / r420.c
1 /*
2  * Copyright 2008 Advanced Micro Devices, Inc.
3  * Copyright 2008 Red Hat Inc.
4  * Copyright 2009 Jerome Glisse.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions 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 NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Dave Airlie
25  *          Alex Deucher
26  *          Jerome Glisse
27  */
28 #include <linux/seq_file.h>
29 #include "drmP.h"
30 #include "radeon_reg.h"
31 #include "radeon.h"
32 #include "r420d.h"
33
34 /* r420,r423,rv410 depends on : */
35 void r100_pci_gart_disable(struct radeon_device *rdev);
36 void r100_hdp_reset(struct radeon_device *rdev);
37 void r100_mc_setup(struct radeon_device *rdev);
38 int r100_gui_wait_for_idle(struct radeon_device *rdev);
39 void r100_mc_disable_clients(struct radeon_device *rdev);
40 void r300_vram_info(struct radeon_device *rdev);
41 int r300_mc_wait_for_idle(struct radeon_device *rdev);
42 int rv370_pcie_gart_enable(struct radeon_device *rdev);
43 void rv370_pcie_gart_disable(struct radeon_device *rdev);
44
45 /* This files gather functions specifics to :
46  * r420,r423,rv410
47  *
48  * Some of these functions might be used by newer ASICs.
49  */
50 void r420_gpu_init(struct radeon_device *rdev);
51 int r420_debugfs_pipes_info_init(struct radeon_device *rdev);
52
53
54 /*
55  * MC
56  */
57 int r420_mc_init(struct radeon_device *rdev)
58 {
59         int r;
60
61         if (r100_debugfs_rbbm_init(rdev)) {
62                 DRM_ERROR("Failed to register debugfs file for RBBM !\n");
63         }
64         if (r420_debugfs_pipes_info_init(rdev)) {
65                 DRM_ERROR("Failed to register debugfs file for pipes !\n");
66         }
67
68         r420_gpu_init(rdev);
69         r100_pci_gart_disable(rdev);
70         if (rdev->flags & RADEON_IS_PCIE) {
71                 rv370_pcie_gart_disable(rdev);
72         }
73
74         /* Setup GPU memory space */
75         rdev->mc.vram_location = 0xFFFFFFFFUL;
76         rdev->mc.gtt_location = 0xFFFFFFFFUL;
77         if (rdev->flags & RADEON_IS_AGP) {
78                 r = radeon_agp_init(rdev);
79                 if (r) {
80                         printk(KERN_WARNING "[drm] Disabling AGP\n");
81                         rdev->flags &= ~RADEON_IS_AGP;
82                         rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
83                 } else {
84                         rdev->mc.gtt_location = rdev->mc.agp_base;
85                 }
86         }
87         r = radeon_mc_setup(rdev);
88         if (r) {
89                 return r;
90         }
91
92         /* Program GPU memory space */
93         r100_mc_disable_clients(rdev);
94         if (r300_mc_wait_for_idle(rdev)) {
95                 printk(KERN_WARNING "Failed to wait MC idle while "
96                        "programming pipes. Bad things might happen.\n");
97         }
98         r100_mc_setup(rdev);
99         return 0;
100 }
101
102 void r420_mc_fini(struct radeon_device *rdev)
103 {
104         rv370_pcie_gart_disable(rdev);
105         radeon_gart_table_vram_free(rdev);
106         radeon_gart_fini(rdev);
107 }
108
109
110 /*
111  * Global GPU functions
112  */
113 void r420_errata(struct radeon_device *rdev)
114 {
115         rdev->pll_errata = 0;
116 }
117
118 void r420_pipes_init(struct radeon_device *rdev)
119 {
120         unsigned tmp;
121         unsigned gb_pipe_select;
122         unsigned num_pipes;
123
124         /* GA_ENHANCE workaround TCL deadlock issue */
125         WREG32(0x4274, (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
126         /* get max number of pipes */
127         gb_pipe_select = RREG32(0x402C);
128         num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
129         rdev->num_gb_pipes = num_pipes;
130         tmp = 0;
131         switch (num_pipes) {
132         default:
133                 /* force to 1 pipe */
134                 num_pipes = 1;
135         case 1:
136                 tmp = (0 << 1);
137                 break;
138         case 2:
139                 tmp = (3 << 1);
140                 break;
141         case 3:
142                 tmp = (6 << 1);
143                 break;
144         case 4:
145                 tmp = (7 << 1);
146                 break;
147         }
148         WREG32(0x42C8, (1 << num_pipes) - 1);
149         /* Sub pixel 1/12 so we can have 4K rendering according to doc */
150         tmp |= (1 << 4) | (1 << 0);
151         WREG32(0x4018, tmp);
152         if (r100_gui_wait_for_idle(rdev)) {
153                 printk(KERN_WARNING "Failed to wait GUI idle while "
154                        "programming pipes. Bad things might happen.\n");
155         }
156
157         tmp = RREG32(0x170C);
158         WREG32(0x170C, tmp | (1 << 31));
159
160         WREG32(R300_RB2D_DSTCACHE_MODE,
161                RREG32(R300_RB2D_DSTCACHE_MODE) |
162                R300_DC_AUTOFLUSH_ENABLE |
163                R300_DC_DC_DISABLE_IGNORE_PE);
164
165         if (r100_gui_wait_for_idle(rdev)) {
166                 printk(KERN_WARNING "Failed to wait GUI idle while "
167                        "programming pipes. Bad things might happen.\n");
168         }
169
170         if (rdev->family == CHIP_RV530) {
171                 tmp = RREG32(RV530_GB_PIPE_SELECT2);
172                 if ((tmp & 3) == 3)
173                         rdev->num_z_pipes = 2;
174                 else
175                         rdev->num_z_pipes = 1;
176         } else
177                 rdev->num_z_pipes = 1;
178
179         DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
180                  rdev->num_gb_pipes, rdev->num_z_pipes);
181 }
182
183 void r420_gpu_init(struct radeon_device *rdev)
184 {
185         r100_hdp_reset(rdev);
186         r420_pipes_init(rdev);
187         if (r300_mc_wait_for_idle(rdev)) {
188                 printk(KERN_WARNING "Failed to wait MC idle while "
189                        "programming pipes. Bad things might happen.\n");
190         }
191 }
192
193
194 /*
195  * r420,r423,rv410 VRAM info
196  */
197 void r420_vram_info(struct radeon_device *rdev)
198 {
199         r300_vram_info(rdev);
200 }
201
202
203 /*
204  * Debugfs info
205  */
206 #if defined(CONFIG_DEBUG_FS)
207 static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
208 {
209         struct drm_info_node *node = (struct drm_info_node *) m->private;
210         struct drm_device *dev = node->minor->dev;
211         struct radeon_device *rdev = dev->dev_private;
212         uint32_t tmp;
213
214         tmp = RREG32(R400_GB_PIPE_SELECT);
215         seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
216         tmp = RREG32(R300_GB_TILE_CONFIG);
217         seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
218         tmp = RREG32(R300_DST_PIPE_CONFIG);
219         seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
220         return 0;
221 }
222
223 static struct drm_info_list r420_pipes_info_list[] = {
224         {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
225 };
226 #endif
227
228 int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
229 {
230 #if defined(CONFIG_DEBUG_FS)
231         return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
232 #else
233         return 0;
234 #endif
235 }
236
237 u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
238 {
239         u32 r;
240
241         WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
242         r = RREG32(R_0001FC_MC_IND_DATA);
243         return r;
244 }
245
246 void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
247 {
248         WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
249                 S_0001F8_MC_IND_WR_EN(1));
250         WREG32(R_0001FC_MC_IND_DATA, v);
251 }