1*41ec0267Sriastradh /* $NetBSD: radeon_r420.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $ */
2eb1c030bSriastradh
3eb1c030bSriastradh /*
4eb1c030bSriastradh * Copyright 2008 Advanced Micro Devices, Inc.
5eb1c030bSriastradh * Copyright 2008 Red Hat Inc.
6eb1c030bSriastradh * Copyright 2009 Jerome Glisse.
7eb1c030bSriastradh *
8eb1c030bSriastradh * Permission is hereby granted, free of charge, to any person obtaining a
9eb1c030bSriastradh * copy of this software and associated documentation files (the "Software"),
10eb1c030bSriastradh * to deal in the Software without restriction, including without limitation
11eb1c030bSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12eb1c030bSriastradh * and/or sell copies of the Software, and to permit persons to whom the
13eb1c030bSriastradh * Software is furnished to do so, subject to the following conditions:
14eb1c030bSriastradh *
15eb1c030bSriastradh * The above copyright notice and this permission notice shall be included in
16eb1c030bSriastradh * all copies or substantial portions of the Software.
17eb1c030bSriastradh *
18eb1c030bSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19eb1c030bSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20eb1c030bSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21eb1c030bSriastradh * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22eb1c030bSriastradh * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23eb1c030bSriastradh * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24eb1c030bSriastradh * OTHER DEALINGS IN THE SOFTWARE.
25eb1c030bSriastradh *
26eb1c030bSriastradh * Authors: Dave Airlie
27eb1c030bSriastradh * Alex Deucher
28eb1c030bSriastradh * Jerome Glisse
29eb1c030bSriastradh */
30eb1c030bSriastradh
31*41ec0267Sriastradh #include <sys/cdefs.h>
32*41ec0267Sriastradh __KERNEL_RCSID(0, "$NetBSD: radeon_r420.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $");
33*41ec0267Sriastradh
34*41ec0267Sriastradh #include <linux/pci.h>
35eb1c030bSriastradh #include <linux/seq_file.h>
36eb1c030bSriastradh #include <linux/slab.h>
37*41ec0267Sriastradh
38*41ec0267Sriastradh #include <drm/drm_debugfs.h>
39*41ec0267Sriastradh #include <drm/drm_device.h>
40*41ec0267Sriastradh #include <drm/drm_file.h>
41*41ec0267Sriastradh
42eb1c030bSriastradh #include "atom.h"
43eb1c030bSriastradh #include "r100d.h"
44eb1c030bSriastradh #include "r420_reg_safe.h"
45*41ec0267Sriastradh #include "r420d.h"
46*41ec0267Sriastradh #include "radeon.h"
47*41ec0267Sriastradh #include "radeon_asic.h"
48*41ec0267Sriastradh #include "radeon_reg.h"
49eb1c030bSriastradh
r420_pm_init_profile(struct radeon_device * rdev)50eb1c030bSriastradh void r420_pm_init_profile(struct radeon_device *rdev)
51eb1c030bSriastradh {
52eb1c030bSriastradh /* default */
53eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
54eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
55eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
56eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
57eb1c030bSriastradh /* low sh */
58eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
59eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
60eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
61eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
62eb1c030bSriastradh /* mid sh */
63eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
64eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
65eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
66eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
67eb1c030bSriastradh /* high sh */
68eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
69eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
70eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
71eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
72eb1c030bSriastradh /* low mh */
73eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
74eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
75eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
76eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
77eb1c030bSriastradh /* mid mh */
78eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
79eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
80eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
81eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
82eb1c030bSriastradh /* high mh */
83eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
84eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
85eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
86eb1c030bSriastradh rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
87eb1c030bSriastradh }
88eb1c030bSriastradh
r420_set_reg_safe(struct radeon_device * rdev)89eb1c030bSriastradh static void r420_set_reg_safe(struct radeon_device *rdev)
90eb1c030bSriastradh {
91eb1c030bSriastradh rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
92eb1c030bSriastradh rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm);
93eb1c030bSriastradh }
94eb1c030bSriastradh
r420_pipes_init(struct radeon_device * rdev)95eb1c030bSriastradh void r420_pipes_init(struct radeon_device *rdev)
96eb1c030bSriastradh {
97eb1c030bSriastradh unsigned tmp;
98eb1c030bSriastradh unsigned gb_pipe_select;
99eb1c030bSriastradh unsigned num_pipes;
100eb1c030bSriastradh
101eb1c030bSriastradh /* GA_ENHANCE workaround TCL deadlock issue */
102eb1c030bSriastradh WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
103eb1c030bSriastradh (1 << 2) | (1 << 3));
104eb1c030bSriastradh /* add idle wait as per freedesktop.org bug 24041 */
105eb1c030bSriastradh if (r100_gui_wait_for_idle(rdev)) {
106*41ec0267Sriastradh pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
107eb1c030bSriastradh }
108eb1c030bSriastradh /* get max number of pipes */
109eb1c030bSriastradh gb_pipe_select = RREG32(R400_GB_PIPE_SELECT);
110eb1c030bSriastradh num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
111eb1c030bSriastradh
112eb1c030bSriastradh /* SE chips have 1 pipe */
113eb1c030bSriastradh if ((rdev->pdev->device == 0x5e4c) ||
114eb1c030bSriastradh (rdev->pdev->device == 0x5e4f))
115eb1c030bSriastradh num_pipes = 1;
116eb1c030bSriastradh
117eb1c030bSriastradh rdev->num_gb_pipes = num_pipes;
118eb1c030bSriastradh tmp = 0;
119eb1c030bSriastradh switch (num_pipes) {
120eb1c030bSriastradh default:
121eb1c030bSriastradh /* force to 1 pipe */
122eb1c030bSriastradh num_pipes = 1;
123*41ec0267Sriastradh /* fall through */
124eb1c030bSriastradh case 1:
125eb1c030bSriastradh tmp = (0 << 1);
126eb1c030bSriastradh break;
127eb1c030bSriastradh case 2:
128eb1c030bSriastradh tmp = (3 << 1);
129eb1c030bSriastradh break;
130eb1c030bSriastradh case 3:
131eb1c030bSriastradh tmp = (6 << 1);
132eb1c030bSriastradh break;
133eb1c030bSriastradh case 4:
134eb1c030bSriastradh tmp = (7 << 1);
135eb1c030bSriastradh break;
136eb1c030bSriastradh }
137eb1c030bSriastradh WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
138eb1c030bSriastradh /* Sub pixel 1/12 so we can have 4K rendering according to doc */
139eb1c030bSriastradh tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
140eb1c030bSriastradh WREG32(R300_GB_TILE_CONFIG, tmp);
141eb1c030bSriastradh if (r100_gui_wait_for_idle(rdev)) {
142*41ec0267Sriastradh pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
143eb1c030bSriastradh }
144eb1c030bSriastradh
145eb1c030bSriastradh tmp = RREG32(R300_DST_PIPE_CONFIG);
146eb1c030bSriastradh WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
147eb1c030bSriastradh
148eb1c030bSriastradh WREG32(R300_RB2D_DSTCACHE_MODE,
149eb1c030bSriastradh RREG32(R300_RB2D_DSTCACHE_MODE) |
150eb1c030bSriastradh R300_DC_AUTOFLUSH_ENABLE |
151eb1c030bSriastradh R300_DC_DC_DISABLE_IGNORE_PE);
152eb1c030bSriastradh
153eb1c030bSriastradh if (r100_gui_wait_for_idle(rdev)) {
154*41ec0267Sriastradh pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
155eb1c030bSriastradh }
156eb1c030bSriastradh
157eb1c030bSriastradh if (rdev->family == CHIP_RV530) {
158eb1c030bSriastradh tmp = RREG32(RV530_GB_PIPE_SELECT2);
159eb1c030bSriastradh if ((tmp & 3) == 3)
160eb1c030bSriastradh rdev->num_z_pipes = 2;
161eb1c030bSriastradh else
162eb1c030bSriastradh rdev->num_z_pipes = 1;
163eb1c030bSriastradh } else
164eb1c030bSriastradh rdev->num_z_pipes = 1;
165eb1c030bSriastradh
166eb1c030bSriastradh DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
167eb1c030bSriastradh rdev->num_gb_pipes, rdev->num_z_pipes);
168eb1c030bSriastradh }
169eb1c030bSriastradh
r420_mc_rreg(struct radeon_device * rdev,u32 reg)170eb1c030bSriastradh u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
171eb1c030bSriastradh {
172eb1c030bSriastradh unsigned long flags;
173eb1c030bSriastradh u32 r;
174eb1c030bSriastradh
175eb1c030bSriastradh spin_lock_irqsave(&rdev->mc_idx_lock, flags);
176eb1c030bSriastradh WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
177eb1c030bSriastradh r = RREG32(R_0001FC_MC_IND_DATA);
178eb1c030bSriastradh spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
179eb1c030bSriastradh return r;
180eb1c030bSriastradh }
181eb1c030bSriastradh
r420_mc_wreg(struct radeon_device * rdev,u32 reg,u32 v)182eb1c030bSriastradh void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
183eb1c030bSriastradh {
184eb1c030bSriastradh unsigned long flags;
185eb1c030bSriastradh
186eb1c030bSriastradh spin_lock_irqsave(&rdev->mc_idx_lock, flags);
187eb1c030bSriastradh WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
188eb1c030bSriastradh S_0001F8_MC_IND_WR_EN(1));
189eb1c030bSriastradh WREG32(R_0001FC_MC_IND_DATA, v);
190eb1c030bSriastradh spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
191eb1c030bSriastradh }
192eb1c030bSriastradh
r420_debugfs(struct radeon_device * rdev)193eb1c030bSriastradh static void r420_debugfs(struct radeon_device *rdev)
194eb1c030bSriastradh {
195eb1c030bSriastradh if (r100_debugfs_rbbm_init(rdev)) {
196eb1c030bSriastradh DRM_ERROR("Failed to register debugfs file for RBBM !\n");
197eb1c030bSriastradh }
198eb1c030bSriastradh if (r420_debugfs_pipes_info_init(rdev)) {
199eb1c030bSriastradh DRM_ERROR("Failed to register debugfs file for pipes !\n");
200eb1c030bSriastradh }
201eb1c030bSriastradh }
202eb1c030bSriastradh
r420_clock_resume(struct radeon_device * rdev)203eb1c030bSriastradh static void r420_clock_resume(struct radeon_device *rdev)
204eb1c030bSriastradh {
205eb1c030bSriastradh u32 sclk_cntl;
206eb1c030bSriastradh
207eb1c030bSriastradh if (radeon_dynclks != -1 && radeon_dynclks)
208eb1c030bSriastradh radeon_atom_set_clock_gating(rdev, 1);
209eb1c030bSriastradh sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
210eb1c030bSriastradh sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
211eb1c030bSriastradh if (rdev->family == CHIP_R420)
212eb1c030bSriastradh sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
213eb1c030bSriastradh WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
214eb1c030bSriastradh }
215eb1c030bSriastradh
r420_cp_errata_init(struct radeon_device * rdev)216eb1c030bSriastradh static void r420_cp_errata_init(struct radeon_device *rdev)
217eb1c030bSriastradh {
218*41ec0267Sriastradh int r;
219eb1c030bSriastradh struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
220eb1c030bSriastradh
221eb1c030bSriastradh /* RV410 and R420 can lock up if CP DMA to host memory happens
222eb1c030bSriastradh * while the 2D engine is busy.
223eb1c030bSriastradh *
224eb1c030bSriastradh * The proper workaround is to queue a RESYNC at the beginning
225eb1c030bSriastradh * of the CP init, apparently.
226eb1c030bSriastradh */
227eb1c030bSriastradh radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
228*41ec0267Sriastradh r = radeon_ring_lock(rdev, ring, 8);
229*41ec0267Sriastradh WARN_ON(r);
230eb1c030bSriastradh radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1));
231eb1c030bSriastradh radeon_ring_write(ring, rdev->config.r300.resync_scratch);
232eb1c030bSriastradh radeon_ring_write(ring, 0xDEADBEEF);
233eb1c030bSriastradh radeon_ring_unlock_commit(rdev, ring, false);
234eb1c030bSriastradh }
235eb1c030bSriastradh
r420_cp_errata_fini(struct radeon_device * rdev)236eb1c030bSriastradh static void r420_cp_errata_fini(struct radeon_device *rdev)
237eb1c030bSriastradh {
238*41ec0267Sriastradh int r;
239eb1c030bSriastradh struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
240eb1c030bSriastradh
241eb1c030bSriastradh /* Catch the RESYNC we dispatched all the way back,
242eb1c030bSriastradh * at the very beginning of the CP init.
243eb1c030bSriastradh */
244*41ec0267Sriastradh r = radeon_ring_lock(rdev, ring, 8);
245*41ec0267Sriastradh WARN_ON(r);
246eb1c030bSriastradh radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
247eb1c030bSriastradh radeon_ring_write(ring, R300_RB3D_DC_FINISH);
248eb1c030bSriastradh radeon_ring_unlock_commit(rdev, ring, false);
249eb1c030bSriastradh radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
250eb1c030bSriastradh }
251eb1c030bSriastradh
r420_startup(struct radeon_device * rdev)252eb1c030bSriastradh static int r420_startup(struct radeon_device *rdev)
253eb1c030bSriastradh {
254eb1c030bSriastradh int r;
255eb1c030bSriastradh
256eb1c030bSriastradh /* set common regs */
257eb1c030bSriastradh r100_set_common_regs(rdev);
258eb1c030bSriastradh /* program mc */
259eb1c030bSriastradh r300_mc_program(rdev);
260eb1c030bSriastradh /* Resume clock */
261eb1c030bSriastradh r420_clock_resume(rdev);
262eb1c030bSriastradh /* Initialize GART (initialize after TTM so we can allocate
263eb1c030bSriastradh * memory through TTM but finalize after TTM) */
264eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE) {
265eb1c030bSriastradh r = rv370_pcie_gart_enable(rdev);
266eb1c030bSriastradh if (r)
267eb1c030bSriastradh return r;
268eb1c030bSriastradh }
269eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI) {
270eb1c030bSriastradh r = r100_pci_gart_enable(rdev);
271eb1c030bSriastradh if (r)
272eb1c030bSriastradh return r;
273eb1c030bSriastradh }
274eb1c030bSriastradh r420_pipes_init(rdev);
275eb1c030bSriastradh
276eb1c030bSriastradh /* allocate wb buffer */
277eb1c030bSriastradh r = radeon_wb_init(rdev);
278eb1c030bSriastradh if (r)
279eb1c030bSriastradh return r;
280eb1c030bSriastradh
281eb1c030bSriastradh r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
282eb1c030bSriastradh if (r) {
283eb1c030bSriastradh dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
284eb1c030bSriastradh return r;
285eb1c030bSriastradh }
286eb1c030bSriastradh
287eb1c030bSriastradh /* Enable IRQ */
288eb1c030bSriastradh if (!rdev->irq.installed) {
289eb1c030bSriastradh r = radeon_irq_kms_init(rdev);
290eb1c030bSriastradh if (r)
291eb1c030bSriastradh return r;
292eb1c030bSriastradh }
293eb1c030bSriastradh
294eb1c030bSriastradh r100_irq_set(rdev);
295eb1c030bSriastradh rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
296eb1c030bSriastradh /* 1M ring buffer */
297eb1c030bSriastradh r = r100_cp_init(rdev, 1024 * 1024);
298eb1c030bSriastradh if (r) {
299eb1c030bSriastradh dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
300eb1c030bSriastradh return r;
301eb1c030bSriastradh }
302eb1c030bSriastradh r420_cp_errata_init(rdev);
303eb1c030bSriastradh
304eb1c030bSriastradh r = radeon_ib_pool_init(rdev);
305eb1c030bSriastradh if (r) {
306eb1c030bSriastradh dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
307eb1c030bSriastradh return r;
308eb1c030bSriastradh }
309eb1c030bSriastradh
310eb1c030bSriastradh return 0;
311eb1c030bSriastradh }
312eb1c030bSriastradh
r420_resume(struct radeon_device * rdev)313eb1c030bSriastradh int r420_resume(struct radeon_device *rdev)
314eb1c030bSriastradh {
315eb1c030bSriastradh int r;
316eb1c030bSriastradh
317eb1c030bSriastradh /* Make sur GART are not working */
318eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE)
319eb1c030bSriastradh rv370_pcie_gart_disable(rdev);
320eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI)
321eb1c030bSriastradh r100_pci_gart_disable(rdev);
322eb1c030bSriastradh /* Resume clock before doing reset */
323eb1c030bSriastradh r420_clock_resume(rdev);
324eb1c030bSriastradh /* Reset gpu before posting otherwise ATOM will enter infinite loop */
325eb1c030bSriastradh if (radeon_asic_reset(rdev)) {
326eb1c030bSriastradh dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
327eb1c030bSriastradh RREG32(R_000E40_RBBM_STATUS),
328eb1c030bSriastradh RREG32(R_0007C0_CP_STAT));
329eb1c030bSriastradh }
330eb1c030bSriastradh /* check if cards are posted or not */
331eb1c030bSriastradh if (rdev->is_atom_bios) {
332eb1c030bSriastradh atom_asic_init(rdev->mode_info.atom_context);
333eb1c030bSriastradh } else {
334eb1c030bSriastradh radeon_combios_asic_init(rdev->ddev);
335eb1c030bSriastradh }
336eb1c030bSriastradh /* Resume clock after posting */
337eb1c030bSriastradh r420_clock_resume(rdev);
338eb1c030bSriastradh /* Initialize surface registers */
339eb1c030bSriastradh radeon_surface_init(rdev);
340eb1c030bSriastradh
341eb1c030bSriastradh rdev->accel_working = true;
342eb1c030bSriastradh r = r420_startup(rdev);
343eb1c030bSriastradh if (r) {
344eb1c030bSriastradh rdev->accel_working = false;
345eb1c030bSriastradh }
346eb1c030bSriastradh return r;
347eb1c030bSriastradh }
348eb1c030bSriastradh
r420_suspend(struct radeon_device * rdev)349eb1c030bSriastradh int r420_suspend(struct radeon_device *rdev)
350eb1c030bSriastradh {
351eb1c030bSriastradh radeon_pm_suspend(rdev);
352eb1c030bSriastradh r420_cp_errata_fini(rdev);
353eb1c030bSriastradh r100_cp_disable(rdev);
354eb1c030bSriastradh radeon_wb_disable(rdev);
355eb1c030bSriastradh r100_irq_disable(rdev);
356eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE)
357eb1c030bSriastradh rv370_pcie_gart_disable(rdev);
358eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI)
359eb1c030bSriastradh r100_pci_gart_disable(rdev);
360eb1c030bSriastradh return 0;
361eb1c030bSriastradh }
362eb1c030bSriastradh
r420_fini(struct radeon_device * rdev)363eb1c030bSriastradh void r420_fini(struct radeon_device *rdev)
364eb1c030bSriastradh {
365eb1c030bSriastradh radeon_pm_fini(rdev);
366eb1c030bSriastradh r100_cp_fini(rdev);
367eb1c030bSriastradh radeon_wb_fini(rdev);
368eb1c030bSriastradh radeon_ib_pool_fini(rdev);
369eb1c030bSriastradh radeon_gem_fini(rdev);
370eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE)
371eb1c030bSriastradh rv370_pcie_gart_fini(rdev);
372eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI)
373eb1c030bSriastradh r100_pci_gart_fini(rdev);
374eb1c030bSriastradh radeon_agp_fini(rdev);
375eb1c030bSriastradh radeon_irq_kms_fini(rdev);
376eb1c030bSriastradh radeon_fence_driver_fini(rdev);
377eb1c030bSriastradh radeon_bo_fini(rdev);
378eb1c030bSriastradh if (rdev->is_atom_bios) {
379eb1c030bSriastradh radeon_atombios_fini(rdev);
380eb1c030bSriastradh } else {
381eb1c030bSriastradh radeon_combios_fini(rdev);
382eb1c030bSriastradh }
383eb1c030bSriastradh kfree(rdev->bios);
384eb1c030bSriastradh rdev->bios = NULL;
385eb1c030bSriastradh }
386eb1c030bSriastradh
r420_init(struct radeon_device * rdev)387eb1c030bSriastradh int r420_init(struct radeon_device *rdev)
388eb1c030bSriastradh {
389eb1c030bSriastradh int r;
390eb1c030bSriastradh
391eb1c030bSriastradh /* Initialize scratch registers */
392eb1c030bSriastradh radeon_scratch_init(rdev);
393eb1c030bSriastradh /* Initialize surface registers */
394eb1c030bSriastradh radeon_surface_init(rdev);
395eb1c030bSriastradh /* TODO: disable VGA need to use VGA request */
396eb1c030bSriastradh /* restore some register to sane defaults */
397eb1c030bSriastradh r100_restore_sanity(rdev);
398eb1c030bSriastradh /* BIOS*/
399eb1c030bSriastradh if (!radeon_get_bios(rdev)) {
400eb1c030bSriastradh if (ASIC_IS_AVIVO(rdev))
401eb1c030bSriastradh return -EINVAL;
402eb1c030bSriastradh }
403eb1c030bSriastradh if (rdev->is_atom_bios) {
404eb1c030bSriastradh r = radeon_atombios_init(rdev);
405eb1c030bSriastradh if (r) {
406eb1c030bSriastradh return r;
407eb1c030bSriastradh }
408eb1c030bSriastradh } else {
409eb1c030bSriastradh r = radeon_combios_init(rdev);
410eb1c030bSriastradh if (r) {
411eb1c030bSriastradh return r;
412eb1c030bSriastradh }
413eb1c030bSriastradh }
414eb1c030bSriastradh /* Reset gpu before posting otherwise ATOM will enter infinite loop */
415eb1c030bSriastradh if (radeon_asic_reset(rdev)) {
416eb1c030bSriastradh dev_warn(rdev->dev,
417eb1c030bSriastradh "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
418eb1c030bSriastradh RREG32(R_000E40_RBBM_STATUS),
419eb1c030bSriastradh RREG32(R_0007C0_CP_STAT));
420eb1c030bSriastradh }
421eb1c030bSriastradh /* check if cards are posted or not */
422eb1c030bSriastradh if (radeon_boot_test_post_card(rdev) == false)
423eb1c030bSriastradh return -EINVAL;
424eb1c030bSriastradh
425eb1c030bSriastradh /* Initialize clocks */
426eb1c030bSriastradh radeon_get_clock_info(rdev->ddev);
427eb1c030bSriastradh /* initialize AGP */
428eb1c030bSriastradh if (rdev->flags & RADEON_IS_AGP) {
429eb1c030bSriastradh r = radeon_agp_init(rdev);
430eb1c030bSriastradh if (r) {
431eb1c030bSriastradh radeon_agp_disable(rdev);
432eb1c030bSriastradh }
433eb1c030bSriastradh }
434eb1c030bSriastradh /* initialize memory controller */
435eb1c030bSriastradh r300_mc_init(rdev);
436eb1c030bSriastradh r420_debugfs(rdev);
437eb1c030bSriastradh /* Fence driver */
438eb1c030bSriastradh r = radeon_fence_driver_init(rdev);
439eb1c030bSriastradh if (r) {
440eb1c030bSriastradh return r;
441eb1c030bSriastradh }
442eb1c030bSriastradh /* Memory manager */
443eb1c030bSriastradh r = radeon_bo_init(rdev);
444eb1c030bSriastradh if (r) {
445eb1c030bSriastradh return r;
446eb1c030bSriastradh }
447eb1c030bSriastradh if (rdev->family == CHIP_R420)
448eb1c030bSriastradh r100_enable_bm(rdev);
449eb1c030bSriastradh
450eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE) {
451eb1c030bSriastradh r = rv370_pcie_gart_init(rdev);
452eb1c030bSriastradh if (r)
453eb1c030bSriastradh return r;
454eb1c030bSriastradh }
455eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI) {
456eb1c030bSriastradh r = r100_pci_gart_init(rdev);
457eb1c030bSriastradh if (r)
458eb1c030bSriastradh return r;
459eb1c030bSriastradh }
460eb1c030bSriastradh r420_set_reg_safe(rdev);
461eb1c030bSriastradh
462eb1c030bSriastradh /* Initialize power management */
463eb1c030bSriastradh radeon_pm_init(rdev);
464eb1c030bSriastradh
465eb1c030bSriastradh rdev->accel_working = true;
466eb1c030bSriastradh r = r420_startup(rdev);
467eb1c030bSriastradh if (r) {
468eb1c030bSriastradh /* Somethings want wront with the accel init stop accel */
469eb1c030bSriastradh dev_err(rdev->dev, "Disabling GPU acceleration\n");
470eb1c030bSriastradh r100_cp_fini(rdev);
471eb1c030bSriastradh radeon_wb_fini(rdev);
472eb1c030bSriastradh radeon_ib_pool_fini(rdev);
473eb1c030bSriastradh radeon_irq_kms_fini(rdev);
474eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCIE)
475eb1c030bSriastradh rv370_pcie_gart_fini(rdev);
476eb1c030bSriastradh if (rdev->flags & RADEON_IS_PCI)
477eb1c030bSriastradh r100_pci_gart_fini(rdev);
478eb1c030bSriastradh radeon_agp_fini(rdev);
479eb1c030bSriastradh rdev->accel_working = false;
480eb1c030bSriastradh }
481eb1c030bSriastradh return 0;
482eb1c030bSriastradh }
483eb1c030bSriastradh
484eb1c030bSriastradh /*
485eb1c030bSriastradh * Debugfs info
486eb1c030bSriastradh */
487eb1c030bSriastradh #if defined(CONFIG_DEBUG_FS)
r420_debugfs_pipes_info(struct seq_file * m,void * data)488eb1c030bSriastradh static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
489eb1c030bSriastradh {
490eb1c030bSriastradh struct drm_info_node *node = (struct drm_info_node *) m->private;
491eb1c030bSriastradh struct drm_device *dev = node->minor->dev;
492eb1c030bSriastradh struct radeon_device *rdev = dev->dev_private;
493eb1c030bSriastradh uint32_t tmp;
494eb1c030bSriastradh
495eb1c030bSriastradh tmp = RREG32(R400_GB_PIPE_SELECT);
496eb1c030bSriastradh seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
497eb1c030bSriastradh tmp = RREG32(R300_GB_TILE_CONFIG);
498eb1c030bSriastradh seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
499eb1c030bSriastradh tmp = RREG32(R300_DST_PIPE_CONFIG);
500eb1c030bSriastradh seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
501eb1c030bSriastradh return 0;
502eb1c030bSriastradh }
503eb1c030bSriastradh
504eb1c030bSriastradh static struct drm_info_list r420_pipes_info_list[] = {
505eb1c030bSriastradh {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
506eb1c030bSriastradh };
507eb1c030bSriastradh #endif
508eb1c030bSriastradh
r420_debugfs_pipes_info_init(struct radeon_device * rdev)509eb1c030bSriastradh int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
510eb1c030bSriastradh {
511eb1c030bSriastradh #if defined(CONFIG_DEBUG_FS)
512eb1c030bSriastradh return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
513eb1c030bSriastradh #else
514eb1c030bSriastradh return 0;
515eb1c030bSriastradh #endif
516eb1c030bSriastradh }
517