Subversion Repositories Kolibri OS

Rev

Rev 3192 | Rev 5078 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3192 Rev 3764
1
/*
1
/*
2
 * Copyright 2008 Advanced Micro Devices, Inc.
2
 * Copyright 2008 Advanced Micro Devices, Inc.
3
 * Copyright 2008 Red Hat Inc.
3
 * Copyright 2008 Red Hat Inc.
4
 * Copyright 2009 Jerome Glisse.
4
 * Copyright 2009 Jerome Glisse.
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
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
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:
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
12
 *
13
 * The above copyright notice and this permission notice shall be included in
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
14
 * all copies or substantial portions of the Software.
15
 *
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
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
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,
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
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 *
23
 *
24
 * Authors: Dave Airlie
24
 * Authors: Dave Airlie
25
 *          Alex Deucher
25
 *          Alex Deucher
26
 *          Jerome Glisse
26
 *          Jerome Glisse
27
 */
27
 */
28
/* RS600 / Radeon X1250/X1270 integrated GPU
28
/* RS600 / Radeon X1250/X1270 integrated GPU
29
 *
29
 *
30
 * This file gather function specific to RS600 which is the IGP of
30
 * This file gather function specific to RS600 which is the IGP of
31
 * the X1250/X1270 family supporting intel CPU (while RS690/RS740
31
 * the X1250/X1270 family supporting intel CPU (while RS690/RS740
32
 * is the X1250/X1270 supporting AMD CPU). The display engine are
32
 * is the X1250/X1270 supporting AMD CPU). The display engine are
33
 * the avivo one, bios is an atombios, 3D block are the one of the
33
 * the avivo one, bios is an atombios, 3D block are the one of the
34
 * R4XX family. The GART is different from the RS400 one and is very
34
 * R4XX family. The GART is different from the RS400 one and is very
35
 * close to the one of the R600 family (R600 likely being an evolution
35
 * close to the one of the R600 family (R600 likely being an evolution
36
 * of the RS600 GART block).
36
 * of the RS600 GART block).
37
 */
37
 */
38
#include 
38
#include 
39
#include "radeon.h"
39
#include "radeon.h"
40
#include "radeon_asic.h"
40
#include "radeon_asic.h"
41
#include "atom.h"
41
#include "atom.h"
42
#include "rs600d.h"
42
#include "rs600d.h"
43
 
43
 
44
#include "rs600_reg_safe.h"
44
#include "rs600_reg_safe.h"
45
 
45
 
46
static void rs600_gpu_init(struct radeon_device *rdev);
46
static void rs600_gpu_init(struct radeon_device *rdev);
47
int rs600_mc_wait_for_idle(struct radeon_device *rdev);
47
int rs600_mc_wait_for_idle(struct radeon_device *rdev);
48
 
48
 
49
static const u32 crtc_offsets[2] =
49
static const u32 crtc_offsets[2] =
50
{
50
{
51
	0,
51
	0,
52
	AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
52
	AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
53
};
53
};
-
 
54
 
-
 
55
static bool avivo_is_in_vblank(struct radeon_device *rdev, int crtc)
-
 
56
{
-
 
57
	if (RREG32(AVIVO_D1CRTC_STATUS + crtc_offsets[crtc]) & AVIVO_D1CRTC_V_BLANK)
-
 
58
		return true;
-
 
59
	else
-
 
60
		return false;
-
 
61
}
-
 
62
 
-
 
63
static bool avivo_is_counter_moving(struct radeon_device *rdev, int crtc)
-
 
64
{
-
 
65
	u32 pos1, pos2;
-
 
66
 
-
 
67
	pos1 = RREG32(AVIVO_D1CRTC_STATUS_POSITION + crtc_offsets[crtc]);
-
 
68
	pos2 = RREG32(AVIVO_D1CRTC_STATUS_POSITION + crtc_offsets[crtc]);
-
 
69
 
-
 
70
	if (pos1 != pos2)
-
 
71
		return true;
-
 
72
	else
-
 
73
		return false;
-
 
74
}
-
 
75
 
-
 
76
/**
-
 
77
 * avivo_wait_for_vblank - vblank wait asic callback.
-
 
78
 *
-
 
79
 * @rdev: radeon_device pointer
-
 
80
 * @crtc: crtc to wait for vblank on
-
 
81
 *
-
 
82
 * Wait for vblank on the requested crtc (r5xx-r7xx).
54
 
83
 */
55
void avivo_wait_for_vblank(struct radeon_device *rdev, int crtc)
84
void avivo_wait_for_vblank(struct radeon_device *rdev, int crtc)
56
{
85
{
57
	int i;
86
	unsigned i = 0;
58
 
87
 
59
	if (crtc >= rdev->num_crtc)
88
	if (crtc >= rdev->num_crtc)
60
		return;
89
		return;
61
 
90
 
-
 
91
	if (!(RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[crtc]) & AVIVO_CRTC_EN))
-
 
92
		return;
-
 
93
 
-
 
94
	/* depending on when we hit vblank, we may be close to active; if so,
-
 
95
	 * wait for another frame.
-
 
96
	 */
-
 
97
	while (avivo_is_in_vblank(rdev, crtc)) {
-
 
98
		if (i++ % 100 == 0) {
-
 
99
			if (!avivo_is_counter_moving(rdev, crtc))
-
 
100
				break;
-
 
101
		}
-
 
102
	}
62
	if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[crtc]) & AVIVO_CRTC_EN) {
103
 
-
 
104
	while (!avivo_is_in_vblank(rdev, crtc)) {
63
		for (i = 0; i < rdev->usec_timeout; i++) {
105
		if (i++ % 100 == 0) {
64
			if (!(RREG32(AVIVO_D1CRTC_STATUS + crtc_offsets[crtc]) & AVIVO_D1CRTC_V_BLANK))
106
			if (!avivo_is_counter_moving(rdev, crtc))
65
				break;
-
 
66
			udelay(1);
107
				break;
67
		}
108
		}
68
		for (i = 0; i < rdev->usec_timeout; i++) {
109
		for (i = 0; i < rdev->usec_timeout; i++) {
69
			if (RREG32(AVIVO_D1CRTC_STATUS + crtc_offsets[crtc]) & AVIVO_D1CRTC_V_BLANK)
110
			if (RREG32(AVIVO_D1CRTC_STATUS + crtc_offsets[crtc]) & AVIVO_D1CRTC_V_BLANK)
70
				break;
111
				break;
71
			udelay(1);
112
			udelay(1);
72
		}
113
		}
73
	}
114
	}
74
}
115
}
75
/* hpd for digital panel detect/disconnect */
116
/* hpd for digital panel detect/disconnect */
76
bool rs600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
117
bool rs600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
77
{
118
{
78
	u32 tmp;
119
	u32 tmp;
79
	bool connected = false;
120
	bool connected = false;
80
 
121
 
81
	switch (hpd) {
122
	switch (hpd) {
82
	case RADEON_HPD_1:
123
	case RADEON_HPD_1:
83
		tmp = RREG32(R_007D04_DC_HOT_PLUG_DETECT1_INT_STATUS);
124
		tmp = RREG32(R_007D04_DC_HOT_PLUG_DETECT1_INT_STATUS);
84
		if (G_007D04_DC_HOT_PLUG_DETECT1_SENSE(tmp))
125
		if (G_007D04_DC_HOT_PLUG_DETECT1_SENSE(tmp))
85
			connected = true;
126
			connected = true;
86
		break;
127
		break;
87
	case RADEON_HPD_2:
128
	case RADEON_HPD_2:
88
		tmp = RREG32(R_007D14_DC_HOT_PLUG_DETECT2_INT_STATUS);
129
		tmp = RREG32(R_007D14_DC_HOT_PLUG_DETECT2_INT_STATUS);
89
		if (G_007D14_DC_HOT_PLUG_DETECT2_SENSE(tmp))
130
		if (G_007D14_DC_HOT_PLUG_DETECT2_SENSE(tmp))
90
			connected = true;
131
			connected = true;
91
		break;
132
		break;
92
	default:
133
	default:
93
		break;
134
		break;
94
	}
135
	}
95
	return connected;
136
	return connected;
96
}
137
}
97
 
138
 
98
void rs600_hpd_set_polarity(struct radeon_device *rdev,
139
void rs600_hpd_set_polarity(struct radeon_device *rdev,
99
			    enum radeon_hpd_id hpd)
140
			    enum radeon_hpd_id hpd)
100
{
141
{
101
	u32 tmp;
142
	u32 tmp;
102
	bool connected = rs600_hpd_sense(rdev, hpd);
143
	bool connected = rs600_hpd_sense(rdev, hpd);
103
 
144
 
104
	switch (hpd) {
145
	switch (hpd) {
105
	case RADEON_HPD_1:
146
	case RADEON_HPD_1:
106
		tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
147
		tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
107
		if (connected)
148
		if (connected)
108
			tmp &= ~S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
149
			tmp &= ~S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
109
		else
150
		else
110
			tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
151
			tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
111
		WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
152
		WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
112
		break;
153
		break;
113
	case RADEON_HPD_2:
154
	case RADEON_HPD_2:
114
		tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
155
		tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
115
		if (connected)
156
		if (connected)
116
			tmp &= ~S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
157
			tmp &= ~S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
117
		else
158
		else
118
			tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
159
			tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
119
		WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
160
		WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
120
		break;
161
		break;
121
	default:
162
	default:
122
		break;
163
		break;
123
	}
164
	}
124
}
165
}
125
 
166
 
126
void rs600_hpd_init(struct radeon_device *rdev)
167
void rs600_hpd_init(struct radeon_device *rdev)
127
{
168
{
128
	struct drm_device *dev = rdev->ddev;
169
	struct drm_device *dev = rdev->ddev;
129
	struct drm_connector *connector;
170
	struct drm_connector *connector;
130
	unsigned enable = 0;
171
	unsigned enable = 0;
131
 
172
 
132
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
173
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
133
		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
174
		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
134
		switch (radeon_connector->hpd.hpd) {
175
		switch (radeon_connector->hpd.hpd) {
135
		case RADEON_HPD_1:
176
		case RADEON_HPD_1:
136
			WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
177
			WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
137
			       S_007D00_DC_HOT_PLUG_DETECT1_EN(1));
178
			       S_007D00_DC_HOT_PLUG_DETECT1_EN(1));
138
			break;
179
			break;
139
		case RADEON_HPD_2:
180
		case RADEON_HPD_2:
140
			WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
181
			WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
141
			       S_007D10_DC_HOT_PLUG_DETECT2_EN(1));
182
			       S_007D10_DC_HOT_PLUG_DETECT2_EN(1));
142
			break;
183
			break;
143
		default:
184
		default:
144
			break;
185
			break;
145
		}
186
		}
146
		enable |= 1 << radeon_connector->hpd.hpd;
187
		enable |= 1 << radeon_connector->hpd.hpd;
147
		radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
188
		radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
148
	}
189
	}
149
//	radeon_irq_kms_enable_hpd(rdev, enable);
190
//	radeon_irq_kms_enable_hpd(rdev, enable);
150
}
191
}
151
 
192
 
152
void rs600_hpd_fini(struct radeon_device *rdev)
193
void rs600_hpd_fini(struct radeon_device *rdev)
153
{
194
{
154
	struct drm_device *dev = rdev->ddev;
195
	struct drm_device *dev = rdev->ddev;
155
	struct drm_connector *connector;
196
	struct drm_connector *connector;
156
	unsigned disable = 0;
197
	unsigned disable = 0;
157
 
198
 
158
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
199
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
159
		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
200
		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
160
		switch (radeon_connector->hpd.hpd) {
201
		switch (radeon_connector->hpd.hpd) {
161
		case RADEON_HPD_1:
202
		case RADEON_HPD_1:
162
			WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
203
			WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
163
			       S_007D00_DC_HOT_PLUG_DETECT1_EN(0));
204
			       S_007D00_DC_HOT_PLUG_DETECT1_EN(0));
164
			break;
205
			break;
165
		case RADEON_HPD_2:
206
		case RADEON_HPD_2:
166
			WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
207
			WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
167
			       S_007D10_DC_HOT_PLUG_DETECT2_EN(0));
208
			       S_007D10_DC_HOT_PLUG_DETECT2_EN(0));
168
			break;
209
			break;
169
		default:
210
		default:
170
			break;
211
			break;
171
		}
212
		}
172
		disable |= 1 << radeon_connector->hpd.hpd;
213
		disable |= 1 << radeon_connector->hpd.hpd;
173
	}
214
	}
174
//	radeon_irq_kms_disable_hpd(rdev, disable);
215
//	radeon_irq_kms_disable_hpd(rdev, disable);
175
}
216
}
176
 
217
 
177
int rs600_asic_reset(struct radeon_device *rdev)
218
int rs600_asic_reset(struct radeon_device *rdev)
178
{
219
{
179
	struct rv515_mc_save save;
220
	struct rv515_mc_save save;
180
	u32 status, tmp;
221
	u32 status, tmp;
181
	int ret = 0;
222
	int ret = 0;
182
 
223
 
183
	status = RREG32(R_000E40_RBBM_STATUS);
224
	status = RREG32(R_000E40_RBBM_STATUS);
184
	if (!G_000E40_GUI_ACTIVE(status)) {
225
	if (!G_000E40_GUI_ACTIVE(status)) {
185
		return 0;
226
		return 0;
186
	}
227
	}
187
	/* Stops all mc clients */
228
	/* Stops all mc clients */
188
	rv515_mc_stop(rdev, &save);
229
	rv515_mc_stop(rdev, &save);
189
	status = RREG32(R_000E40_RBBM_STATUS);
230
	status = RREG32(R_000E40_RBBM_STATUS);
190
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
231
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
191
	/* stop CP */
232
	/* stop CP */
192
	WREG32(RADEON_CP_CSQ_CNTL, 0);
233
	WREG32(RADEON_CP_CSQ_CNTL, 0);
193
	tmp = RREG32(RADEON_CP_RB_CNTL);
234
	tmp = RREG32(RADEON_CP_RB_CNTL);
194
	WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
235
	WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
195
	WREG32(RADEON_CP_RB_RPTR_WR, 0);
236
	WREG32(RADEON_CP_RB_RPTR_WR, 0);
196
	WREG32(RADEON_CP_RB_WPTR, 0);
237
	WREG32(RADEON_CP_RB_WPTR, 0);
197
	WREG32(RADEON_CP_RB_CNTL, tmp);
238
	WREG32(RADEON_CP_RB_CNTL, tmp);
198
//   pci_save_state(rdev->pdev);
239
//   pci_save_state(rdev->pdev);
199
	/* disable bus mastering */
240
	/* disable bus mastering */
200
//	pci_clear_master(rdev->pdev);
241
//	pci_clear_master(rdev->pdev);
201
	mdelay(1);
242
	mdelay(1);
202
	/* reset GA+VAP */
243
	/* reset GA+VAP */
203
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_VAP(1) |
244
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_VAP(1) |
204
					S_0000F0_SOFT_RESET_GA(1));
245
					S_0000F0_SOFT_RESET_GA(1));
205
	RREG32(R_0000F0_RBBM_SOFT_RESET);
246
	RREG32(R_0000F0_RBBM_SOFT_RESET);
206
	mdelay(500);
247
	mdelay(500);
207
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
248
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
208
	mdelay(1);
249
	mdelay(1);
209
	status = RREG32(R_000E40_RBBM_STATUS);
250
	status = RREG32(R_000E40_RBBM_STATUS);
210
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
251
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
211
	/* reset CP */
252
	/* reset CP */
212
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1));
253
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1));
213
	RREG32(R_0000F0_RBBM_SOFT_RESET);
254
	RREG32(R_0000F0_RBBM_SOFT_RESET);
214
	mdelay(500);
255
	mdelay(500);
215
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
256
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
216
	mdelay(1);
257
	mdelay(1);
217
	status = RREG32(R_000E40_RBBM_STATUS);
258
	status = RREG32(R_000E40_RBBM_STATUS);
218
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
259
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
219
	/* reset MC */
260
	/* reset MC */
220
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_MC(1));
261
	WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_MC(1));
221
	RREG32(R_0000F0_RBBM_SOFT_RESET);
262
	RREG32(R_0000F0_RBBM_SOFT_RESET);
222
	mdelay(500);
263
	mdelay(500);
223
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
264
	WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
224
	mdelay(1);
265
	mdelay(1);
225
	status = RREG32(R_000E40_RBBM_STATUS);
266
	status = RREG32(R_000E40_RBBM_STATUS);
226
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
267
	dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
227
	/* restore PCI & busmastering */
268
	/* restore PCI & busmastering */
228
//   pci_restore_state(rdev->pdev);
269
//   pci_restore_state(rdev->pdev);
229
	/* Check if GPU is idle */
270
	/* Check if GPU is idle */
230
	if (G_000E40_GA_BUSY(status) || G_000E40_VAP_BUSY(status)) {
271
	if (G_000E40_GA_BUSY(status) || G_000E40_VAP_BUSY(status)) {
231
		dev_err(rdev->dev, "failed to reset GPU\n");
272
		dev_err(rdev->dev, "failed to reset GPU\n");
232
		ret = -1;
273
		ret = -1;
233
	} else
274
	} else
234
		dev_info(rdev->dev, "GPU reset succeed\n");
275
		dev_info(rdev->dev, "GPU reset succeed\n");
235
	rv515_mc_resume(rdev, &save);
276
	rv515_mc_resume(rdev, &save);
236
	return ret;
277
	return ret;
237
}
278
}
238
 
279
 
239
/*
280
/*
240
 * GART.
281
 * GART.
241
 */
282
 */
242
void rs600_gart_tlb_flush(struct radeon_device *rdev)
283
void rs600_gart_tlb_flush(struct radeon_device *rdev)
243
{
284
{
244
	uint32_t tmp;
285
	uint32_t tmp;
245
 
286
 
246
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
287
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
247
	tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
288
	tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
248
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
289
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
249
 
290
 
250
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
291
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
251
	tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) | S_000100_INVALIDATE_L2_CACHE(1);
292
	tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) | S_000100_INVALIDATE_L2_CACHE(1);
252
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
293
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
253
 
294
 
254
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
295
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
255
	tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
296
	tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
256
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
297
	WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
257
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
298
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
258
}
299
}
259
 
300
 
260
static int rs600_gart_init(struct radeon_device *rdev)
301
static int rs600_gart_init(struct radeon_device *rdev)
261
{
302
{
262
	int r;
303
	int r;
263
 
304
 
264
	if (rdev->gart.robj) {
305
	if (rdev->gart.robj) {
265
		WARN(1, "RS600 GART already initialized\n");
306
		WARN(1, "RS600 GART already initialized\n");
266
		return 0;
307
		return 0;
267
	}
308
	}
268
	/* Initialize common gart structure */
309
	/* Initialize common gart structure */
269
	r = radeon_gart_init(rdev);
310
	r = radeon_gart_init(rdev);
270
	if (r) {
311
	if (r) {
271
		return r;
312
		return r;
272
	}
313
	}
273
	rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
314
	rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
274
	return radeon_gart_table_vram_alloc(rdev);
315
	return radeon_gart_table_vram_alloc(rdev);
275
}
316
}
276
 
317
 
277
static int rs600_gart_enable(struct radeon_device *rdev)
318
static int rs600_gart_enable(struct radeon_device *rdev)
278
{
319
{
279
	u32 tmp;
320
	u32 tmp;
280
	int r, i;
321
	int r, i;
281
 
322
 
282
	if (rdev->gart.robj == NULL) {
323
	if (rdev->gart.robj == NULL) {
283
		dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
324
		dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
284
		return -EINVAL;
325
		return -EINVAL;
285
	}
326
	}
286
	r = radeon_gart_table_vram_pin(rdev);
327
	r = radeon_gart_table_vram_pin(rdev);
287
	if (r)
328
	if (r)
288
		return r;
329
		return r;
289
	radeon_gart_restore(rdev);
330
	radeon_gart_restore(rdev);
290
	/* Enable bus master */
331
	/* Enable bus master */
291
	tmp = RREG32(RADEON_BUS_CNTL) & ~RS600_BUS_MASTER_DIS;
332
	tmp = RREG32(RADEON_BUS_CNTL) & ~RS600_BUS_MASTER_DIS;
292
	WREG32(RADEON_BUS_CNTL, tmp);
333
	WREG32(RADEON_BUS_CNTL, tmp);
293
	/* FIXME: setup default page */
334
	/* FIXME: setup default page */
294
	WREG32_MC(R_000100_MC_PT0_CNTL,
335
	WREG32_MC(R_000100_MC_PT0_CNTL,
295
		 (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
336
		 (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
296
		  S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
337
		  S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
297
 
338
 
298
	for (i = 0; i < 19; i++) {
339
	for (i = 0; i < 19; i++) {
299
		WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
340
		WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
300
			S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
341
			S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
301
			S_00016C_SYSTEM_ACCESS_MODE_MASK(
342
			S_00016C_SYSTEM_ACCESS_MODE_MASK(
302
				  V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) |
343
				  V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) |
303
			S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
344
			S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
304
				  V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) |
345
				  V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) |
305
			  S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) |
346
			  S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) |
306
			S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
347
			S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
307
			  S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3));
348
			  S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3));
308
	}
349
	}
309
	/* enable first context */
350
	/* enable first context */
310
	WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
351
	WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
311
			S_000102_ENABLE_PAGE_TABLE(1) |
352
			S_000102_ENABLE_PAGE_TABLE(1) |
312
			S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
353
			S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
313
 
354
 
314
	/* disable all other contexts */
355
	/* disable all other contexts */
315
	for (i = 1; i < 8; i++)
356
	for (i = 1; i < 8; i++)
316
		WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
357
		WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
317
 
358
 
318
	/* setup the page table */
359
	/* setup the page table */
319
	WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
360
	WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
320
		 rdev->gart.table_addr);
361
		 rdev->gart.table_addr);
321
	WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
362
	WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
322
	WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
363
	WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
323
	WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
364
	WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
324
 
365
 
325
	/* System context maps to VRAM space */
366
	/* System context maps to VRAM space */
326
	WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start);
367
	WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start);
327
	WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end);
368
	WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end);
328
 
369
 
329
	/* enable page tables */
370
	/* enable page tables */
330
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
371
	tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
331
	WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
372
	WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
332
	tmp = RREG32_MC(R_000009_MC_CNTL1);
373
	tmp = RREG32_MC(R_000009_MC_CNTL1);
333
	WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
374
	WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
334
	rs600_gart_tlb_flush(rdev);
375
	rs600_gart_tlb_flush(rdev);
335
	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
376
	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
336
		 (unsigned)(rdev->mc.gtt_size >> 20),
377
		 (unsigned)(rdev->mc.gtt_size >> 20),
337
		 (unsigned long long)rdev->gart.table_addr);
378
		 (unsigned long long)rdev->gart.table_addr);
338
	rdev->gart.ready = true;
379
	rdev->gart.ready = true;
339
	return 0;
380
	return 0;
340
}
381
}
341
 
382
 
342
static void rs600_gart_disable(struct radeon_device *rdev)
383
static void rs600_gart_disable(struct radeon_device *rdev)
343
{
384
{
344
	u32 tmp;
385
	u32 tmp;
345
 
386
 
346
	/* FIXME: disable out of gart access */
387
	/* FIXME: disable out of gart access */
347
	WREG32_MC(R_000100_MC_PT0_CNTL, 0);
388
	WREG32_MC(R_000100_MC_PT0_CNTL, 0);
348
	tmp = RREG32_MC(R_000009_MC_CNTL1);
389
	tmp = RREG32_MC(R_000009_MC_CNTL1);
349
	WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
390
	WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
350
	radeon_gart_table_vram_unpin(rdev);
391
	radeon_gart_table_vram_unpin(rdev);
351
}
392
}
352
 
393
 
353
static void rs600_gart_fini(struct radeon_device *rdev)
394
static void rs600_gart_fini(struct radeon_device *rdev)
354
{
395
{
355
	radeon_gart_fini(rdev);
396
	radeon_gart_fini(rdev);
356
	rs600_gart_disable(rdev);
397
	rs600_gart_disable(rdev);
357
	radeon_gart_table_vram_free(rdev);
398
	radeon_gart_table_vram_free(rdev);
358
}
399
}
359
 
400
 
360
#define R600_PTE_VALID     (1 << 0)
401
#define R600_PTE_VALID     (1 << 0)
361
#define R600_PTE_SYSTEM    (1 << 1)
402
#define R600_PTE_SYSTEM    (1 << 1)
362
#define R600_PTE_SNOOPED   (1 << 2)
403
#define R600_PTE_SNOOPED   (1 << 2)
363
#define R600_PTE_READABLE  (1 << 5)
404
#define R600_PTE_READABLE  (1 << 5)
364
#define R600_PTE_WRITEABLE (1 << 6)
405
#define R600_PTE_WRITEABLE (1 << 6)
365
 
406
 
366
int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
407
int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
367
{
408
{
368
	void __iomem *ptr = (void *)rdev->gart.ptr;
409
	void __iomem *ptr = (void *)rdev->gart.ptr;
369
 
410
 
370
	if (i < 0 || i > rdev->gart.num_gpu_pages) {
411
	if (i < 0 || i > rdev->gart.num_gpu_pages) {
371
		return -EINVAL;
412
		return -EINVAL;
372
	}
413
	}
373
	addr = addr & 0xFFFFFFFFFFFFF000ULL;
414
	addr = addr & 0xFFFFFFFFFFFFF000ULL;
374
	addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
415
	addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
375
	addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
416
	addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
376
	writeq(addr, ptr + (i * 8));
417
	writeq(addr, ptr + (i * 8));
377
	return 0;
418
	return 0;
378
}
419
}
379
 
420
 
380
int rs600_irq_set(struct radeon_device *rdev)
421
int rs600_irq_set(struct radeon_device *rdev)
381
{
422
{
382
	uint32_t tmp = 0;
423
	uint32_t tmp = 0;
383
	uint32_t mode_int = 0;
424
	uint32_t mode_int = 0;
384
	u32 hpd1 = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL) &
425
	u32 hpd1 = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL) &
385
		~S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
426
		~S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
386
	u32 hpd2 = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL) &
427
	u32 hpd2 = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL) &
387
		~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
428
		~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
388
	u32 hdmi0;
429
	u32 hdmi0;
389
	if (ASIC_IS_DCE2(rdev))
430
	if (ASIC_IS_DCE2(rdev))
390
		hdmi0 = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL) &
431
		hdmi0 = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL) &
391
			~S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
432
			~S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
392
	else
433
	else
393
		hdmi0 = 0;
434
		hdmi0 = 0;
394
 
435
 
395
   if (!rdev->irq.installed) {
436
   if (!rdev->irq.installed) {
396
		WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
437
		WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
397
		WREG32(R_000040_GEN_INT_CNTL, 0);
438
		WREG32(R_000040_GEN_INT_CNTL, 0);
398
		return -EINVAL;
439
		return -EINVAL;
399
	}
440
	}
400
	if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
441
	if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
401
		tmp |= S_000040_SW_INT_EN(1);
442
		tmp |= S_000040_SW_INT_EN(1);
402
	}
443
	}
403
	if (rdev->irq.crtc_vblank_int[0] ||
444
	if (rdev->irq.crtc_vblank_int[0] ||
404
	    atomic_read(&rdev->irq.pflip[0])) {
445
	    atomic_read(&rdev->irq.pflip[0])) {
405
		mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
446
		mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
406
	}
447
	}
407
	if (rdev->irq.crtc_vblank_int[1] ||
448
	if (rdev->irq.crtc_vblank_int[1] ||
408
	    atomic_read(&rdev->irq.pflip[1])) {
449
	    atomic_read(&rdev->irq.pflip[1])) {
409
		mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
450
		mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
410
	}
451
	}
411
	if (rdev->irq.hpd[0]) {
452
	if (rdev->irq.hpd[0]) {
412
		hpd1 |= S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
453
		hpd1 |= S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
413
	}
454
	}
414
	if (rdev->irq.hpd[1]) {
455
	if (rdev->irq.hpd[1]) {
415
		hpd2 |= S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
456
		hpd2 |= S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
416
	}
457
	}
417
	if (rdev->irq.afmt[0]) {
458
	if (rdev->irq.afmt[0]) {
418
		hdmi0 |= S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
459
		hdmi0 |= S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
419
	}
460
	}
420
	WREG32(R_000040_GEN_INT_CNTL, tmp);
461
	WREG32(R_000040_GEN_INT_CNTL, tmp);
421
	WREG32(R_006540_DxMODE_INT_MASK, mode_int);
462
	WREG32(R_006540_DxMODE_INT_MASK, mode_int);
422
	WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
463
	WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
423
	WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
464
	WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
424
	if (ASIC_IS_DCE2(rdev))
465
	if (ASIC_IS_DCE2(rdev))
425
		WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
466
		WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
426
	return 0;
467
	return 0;
427
}
468
}
428
 
469
 
429
static inline u32 rs600_irq_ack(struct radeon_device *rdev)
470
static inline u32 rs600_irq_ack(struct radeon_device *rdev)
430
{
471
{
431
	uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
472
	uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
432
	uint32_t irq_mask = S_000044_SW_INT(1);
473
	uint32_t irq_mask = S_000044_SW_INT(1);
433
	u32 tmp;
474
	u32 tmp;
434
 
475
 
435
	if (G_000044_DISPLAY_INT_STAT(irqs)) {
476
	if (G_000044_DISPLAY_INT_STAT(irqs)) {
436
		rdev->irq.stat_regs.r500.disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
477
		rdev->irq.stat_regs.r500.disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
437
		if (G_007EDC_LB_D1_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
478
		if (G_007EDC_LB_D1_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
438
			WREG32(R_006534_D1MODE_VBLANK_STATUS,
479
			WREG32(R_006534_D1MODE_VBLANK_STATUS,
439
				S_006534_D1MODE_VBLANK_ACK(1));
480
				S_006534_D1MODE_VBLANK_ACK(1));
440
		}
481
		}
441
		if (G_007EDC_LB_D2_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
482
		if (G_007EDC_LB_D2_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
442
			WREG32(R_006D34_D2MODE_VBLANK_STATUS,
483
			WREG32(R_006D34_D2MODE_VBLANK_STATUS,
443
				S_006D34_D2MODE_VBLANK_ACK(1));
484
				S_006D34_D2MODE_VBLANK_ACK(1));
444
		}
485
		}
445
		if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
486
		if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
446
			tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
487
			tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
447
			tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_ACK(1);
488
			tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_ACK(1);
448
			WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
489
			WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
449
		}
490
		}
450
		if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
491
		if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
451
			tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
492
			tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
452
			tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_ACK(1);
493
			tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_ACK(1);
453
			WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
494
			WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
454
		}
495
		}
455
	} else {
496
	} else {
456
		rdev->irq.stat_regs.r500.disp_int = 0;
497
		rdev->irq.stat_regs.r500.disp_int = 0;
457
	}
498
	}
458
 
499
 
459
	if (ASIC_IS_DCE2(rdev)) {
500
	if (ASIC_IS_DCE2(rdev)) {
460
		rdev->irq.stat_regs.r500.hdmi0_status = RREG32(R_007404_HDMI0_STATUS) &
501
		rdev->irq.stat_regs.r500.hdmi0_status = RREG32(R_007404_HDMI0_STATUS) &
461
			S_007404_HDMI0_AZ_FORMAT_WTRIG(1);
502
			S_007404_HDMI0_AZ_FORMAT_WTRIG(1);
462
		if (G_007404_HDMI0_AZ_FORMAT_WTRIG(rdev->irq.stat_regs.r500.hdmi0_status)) {
503
		if (G_007404_HDMI0_AZ_FORMAT_WTRIG(rdev->irq.stat_regs.r500.hdmi0_status)) {
463
			tmp = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL);
504
			tmp = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL);
464
			tmp |= S_007408_HDMI0_AZ_FORMAT_WTRIG_ACK(1);
505
			tmp |= S_007408_HDMI0_AZ_FORMAT_WTRIG_ACK(1);
465
			WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, tmp);
506
			WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, tmp);
466
		}
507
		}
467
	} else
508
	} else
468
		rdev->irq.stat_regs.r500.hdmi0_status = 0;
509
		rdev->irq.stat_regs.r500.hdmi0_status = 0;
469
 
510
 
470
	if (irqs) {
511
	if (irqs) {
471
		WREG32(R_000044_GEN_INT_STATUS, irqs);
512
		WREG32(R_000044_GEN_INT_STATUS, irqs);
472
	}
513
	}
473
	return irqs & irq_mask;
514
	return irqs & irq_mask;
474
}
515
}
475
 
516
 
476
void rs600_irq_disable(struct radeon_device *rdev)
517
void rs600_irq_disable(struct radeon_device *rdev)
477
{
518
{
478
	u32 hdmi0 = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL) &
519
	u32 hdmi0 = RREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL) &
479
		~S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
520
		~S_007408_HDMI0_AZ_FORMAT_WTRIG_MASK(1);
480
	WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
521
	WREG32(R_007408_HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
481
	WREG32(R_000040_GEN_INT_CNTL, 0);
522
	WREG32(R_000040_GEN_INT_CNTL, 0);
482
	WREG32(R_006540_DxMODE_INT_MASK, 0);
523
	WREG32(R_006540_DxMODE_INT_MASK, 0);
483
	/* Wait and acknowledge irq */
524
	/* Wait and acknowledge irq */
484
	mdelay(1);
525
	mdelay(1);
485
	rs600_irq_ack(rdev);
526
	rs600_irq_ack(rdev);
486
}
527
}
487
 
528
 
488
int rs600_irq_process(struct radeon_device *rdev)
529
int rs600_irq_process(struct radeon_device *rdev)
489
{
530
{
490
	u32 status, msi_rearm;
531
	u32 status, msi_rearm;
491
	bool queue_hotplug = false;
532
	bool queue_hotplug = false;
492
	bool queue_hdmi = false;
533
	bool queue_hdmi = false;
493
 
534
 
494
	status = rs600_irq_ack(rdev);
535
	status = rs600_irq_ack(rdev);
495
	if (!status &&
536
	if (!status &&
496
	    !rdev->irq.stat_regs.r500.disp_int &&
537
	    !rdev->irq.stat_regs.r500.disp_int &&
497
	    !rdev->irq.stat_regs.r500.hdmi0_status) {
538
	    !rdev->irq.stat_regs.r500.hdmi0_status) {
498
		return IRQ_NONE;
539
		return IRQ_NONE;
499
	}
540
	}
500
	while (status ||
541
	while (status ||
501
	       rdev->irq.stat_regs.r500.disp_int ||
542
	       rdev->irq.stat_regs.r500.disp_int ||
502
	       rdev->irq.stat_regs.r500.hdmi0_status) {
543
	       rdev->irq.stat_regs.r500.hdmi0_status) {
503
		/* SW interrupt */
544
		/* SW interrupt */
504
		if (G_000044_SW_INT(status)) {
545
		if (G_000044_SW_INT(status)) {
505
			radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
546
			radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
506
		}
547
		}
507
		/* Vertical blank interrupts */
548
		/* Vertical blank interrupts */
508
		if (G_007EDC_LB_D1_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
549
		if (G_007EDC_LB_D1_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
509
			if (rdev->irq.crtc_vblank_int[0]) {
550
			if (rdev->irq.crtc_vblank_int[0]) {
510
//				drm_handle_vblank(rdev->ddev, 0);
551
//				drm_handle_vblank(rdev->ddev, 0);
511
				rdev->pm.vblank_sync = true;
552
				rdev->pm.vblank_sync = true;
512
//				wake_up(&rdev->irq.vblank_queue);
553
//				wake_up(&rdev->irq.vblank_queue);
513
			}
554
			}
514
//			if (rdev->irq.pflip[0])
555
//			if (rdev->irq.pflip[0])
515
//				radeon_crtc_handle_flip(rdev, 0);
556
//				radeon_crtc_handle_flip(rdev, 0);
516
		}
557
		}
517
		if (G_007EDC_LB_D2_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
558
		if (G_007EDC_LB_D2_VBLANK_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
518
			if (rdev->irq.crtc_vblank_int[1]) {
559
			if (rdev->irq.crtc_vblank_int[1]) {
519
//				drm_handle_vblank(rdev->ddev, 1);
560
//				drm_handle_vblank(rdev->ddev, 1);
520
				rdev->pm.vblank_sync = true;
561
				rdev->pm.vblank_sync = true;
521
//				wake_up(&rdev->irq.vblank_queue);
562
//				wake_up(&rdev->irq.vblank_queue);
522
			}
563
			}
523
//			if (rdev->irq.pflip[1])
564
//			if (rdev->irq.pflip[1])
524
//				radeon_crtc_handle_flip(rdev, 1);
565
//				radeon_crtc_handle_flip(rdev, 1);
525
		}
566
		}
526
		if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
567
		if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
527
			queue_hotplug = true;
568
			queue_hotplug = true;
528
			DRM_DEBUG("HPD1\n");
569
			DRM_DEBUG("HPD1\n");
529
		}
570
		}
530
		if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
571
		if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(rdev->irq.stat_regs.r500.disp_int)) {
531
			queue_hotplug = true;
572
			queue_hotplug = true;
532
			DRM_DEBUG("HPD2\n");
573
			DRM_DEBUG("HPD2\n");
533
		}
574
		}
534
		if (G_007404_HDMI0_AZ_FORMAT_WTRIG(rdev->irq.stat_regs.r500.hdmi0_status)) {
575
		if (G_007404_HDMI0_AZ_FORMAT_WTRIG(rdev->irq.stat_regs.r500.hdmi0_status)) {
535
			queue_hdmi = true;
576
			queue_hdmi = true;
536
			DRM_DEBUG("HDMI0\n");
577
			DRM_DEBUG("HDMI0\n");
537
		}
578
		}
538
		status = rs600_irq_ack(rdev);
579
		status = rs600_irq_ack(rdev);
539
	}
580
	}
540
//	if (queue_hotplug)
581
//	if (queue_hotplug)
541
//		schedule_work(&rdev->hotplug_work);
582
//		schedule_work(&rdev->hotplug_work);
542
//	if (queue_hdmi)
583
//	if (queue_hdmi)
543
//		schedule_work(&rdev->audio_work);
584
//		schedule_work(&rdev->audio_work);
544
	if (rdev->msi_enabled) {
585
	if (rdev->msi_enabled) {
545
		switch (rdev->family) {
586
		switch (rdev->family) {
546
		case CHIP_RS600:
587
		case CHIP_RS600:
547
		case CHIP_RS690:
588
		case CHIP_RS690:
548
		case CHIP_RS740:
589
		case CHIP_RS740:
549
			msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM;
590
			msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM;
550
			WREG32(RADEON_BUS_CNTL, msi_rearm);
591
			WREG32(RADEON_BUS_CNTL, msi_rearm);
551
			WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM);
592
			WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM);
552
			break;
593
			break;
553
		default:
594
		default:
554
			WREG32(RADEON_MSI_REARM_EN, RV370_MSI_REARM_EN);
595
			WREG32(RADEON_MSI_REARM_EN, RV370_MSI_REARM_EN);
555
			break;
596
			break;
556
		}
597
		}
557
	}
598
	}
558
	return IRQ_HANDLED;
599
	return IRQ_HANDLED;
559
}
600
}
560
 
601
 
561
u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
602
u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
562
{
603
{
563
	if (crtc == 0)
604
	if (crtc == 0)
564
		return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
605
		return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
565
	else
606
	else
566
		return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
607
		return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
567
}
608
}
568
 
609
 
569
int rs600_mc_wait_for_idle(struct radeon_device *rdev)
610
int rs600_mc_wait_for_idle(struct radeon_device *rdev)
570
{
611
{
571
	unsigned i;
612
	unsigned i;
572
 
613
 
573
	for (i = 0; i < rdev->usec_timeout; i++) {
614
	for (i = 0; i < rdev->usec_timeout; i++) {
574
		if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
615
		if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
575
			return 0;
616
			return 0;
576
		udelay(1);
617
		udelay(1);
577
	}
618
	}
578
	return -1;
619
	return -1;
579
}
620
}
580
 
621
 
581
static void rs600_gpu_init(struct radeon_device *rdev)
622
static void rs600_gpu_init(struct radeon_device *rdev)
582
{
623
{
583
	r420_pipes_init(rdev);
624
	r420_pipes_init(rdev);
584
	/* Wait for mc idle */
625
	/* Wait for mc idle */
585
	if (rs600_mc_wait_for_idle(rdev))
626
	if (rs600_mc_wait_for_idle(rdev))
586
		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
627
		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
587
}
628
}
588
 
629
 
589
static void rs600_mc_init(struct radeon_device *rdev)
630
static void rs600_mc_init(struct radeon_device *rdev)
590
{
631
{
591
	u64 base;
632
	u64 base;
592
 
633
 
593
	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
634
	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
594
	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
635
	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
595
	rdev->mc.vram_is_ddr = true;
636
	rdev->mc.vram_is_ddr = true;
596
	rdev->mc.vram_width = 128;
637
	rdev->mc.vram_width = 128;
597
	rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
638
	rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
598
	rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
639
	rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
599
	rdev->mc.visible_vram_size = rdev->mc.aper_size;
640
	rdev->mc.visible_vram_size = rdev->mc.aper_size;
600
	rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
641
	rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
601
	base = RREG32_MC(R_000004_MC_FB_LOCATION);
642
	base = RREG32_MC(R_000004_MC_FB_LOCATION);
602
	base = G_000004_MC_FB_START(base) << 16;
643
	base = G_000004_MC_FB_START(base) << 16;
603
	radeon_vram_location(rdev, &rdev->mc, base);
644
	radeon_vram_location(rdev, &rdev->mc, base);
604
	rdev->mc.gtt_base_align = 0;
645
	rdev->mc.gtt_base_align = 0;
605
	radeon_gtt_location(rdev, &rdev->mc);
646
	radeon_gtt_location(rdev, &rdev->mc);
606
	radeon_update_bandwidth_info(rdev);
647
	radeon_update_bandwidth_info(rdev);
607
}
648
}
608
 
649
 
609
void rs600_bandwidth_update(struct radeon_device *rdev)
650
void rs600_bandwidth_update(struct radeon_device *rdev)
610
{
651
{
611
	struct drm_display_mode *mode0 = NULL;
652
	struct drm_display_mode *mode0 = NULL;
612
	struct drm_display_mode *mode1 = NULL;
653
	struct drm_display_mode *mode1 = NULL;
613
	u32 d1mode_priority_a_cnt, d2mode_priority_a_cnt;
654
	u32 d1mode_priority_a_cnt, d2mode_priority_a_cnt;
614
	/* FIXME: implement full support */
655
	/* FIXME: implement full support */
615
 
656
 
616
	radeon_update_display_priority(rdev);
657
	radeon_update_display_priority(rdev);
617
 
658
 
618
	if (rdev->mode_info.crtcs[0]->base.enabled)
659
	if (rdev->mode_info.crtcs[0]->base.enabled)
619
		mode0 = &rdev->mode_info.crtcs[0]->base.mode;
660
		mode0 = &rdev->mode_info.crtcs[0]->base.mode;
620
	if (rdev->mode_info.crtcs[1]->base.enabled)
661
	if (rdev->mode_info.crtcs[1]->base.enabled)
621
		mode1 = &rdev->mode_info.crtcs[1]->base.mode;
662
		mode1 = &rdev->mode_info.crtcs[1]->base.mode;
622
 
663
 
623
	rs690_line_buffer_adjust(rdev, mode0, mode1);
664
	rs690_line_buffer_adjust(rdev, mode0, mode1);
624
 
665
 
625
	if (rdev->disp_priority == 2) {
666
	if (rdev->disp_priority == 2) {
626
		d1mode_priority_a_cnt = RREG32(R_006548_D1MODE_PRIORITY_A_CNT);
667
		d1mode_priority_a_cnt = RREG32(R_006548_D1MODE_PRIORITY_A_CNT);
627
		d2mode_priority_a_cnt = RREG32(R_006D48_D2MODE_PRIORITY_A_CNT);
668
		d2mode_priority_a_cnt = RREG32(R_006D48_D2MODE_PRIORITY_A_CNT);
628
		d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
669
		d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
629
		d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
670
		d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
630
		WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
671
		WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
631
		WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
672
		WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
632
		WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
673
		WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
633
		WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
674
		WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
634
	}
675
	}
635
}
676
}
636
 
677
 
637
uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
678
uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
638
{
679
{
639
	WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
680
	WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
640
		S_000070_MC_IND_CITF_ARB0(1));
681
		S_000070_MC_IND_CITF_ARB0(1));
641
	return RREG32(R_000074_MC_IND_DATA);
682
	return RREG32(R_000074_MC_IND_DATA);
642
}
683
}
643
 
684
 
644
void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
685
void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
645
{
686
{
646
	WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
687
	WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
647
		S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
688
		S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
648
	WREG32(R_000074_MC_IND_DATA, v);
689
	WREG32(R_000074_MC_IND_DATA, v);
649
}
690
}
650
 
691
 
651
static void rs600_debugfs(struct radeon_device *rdev)
692
static void rs600_debugfs(struct radeon_device *rdev)
652
{
693
{
653
	if (r100_debugfs_rbbm_init(rdev))
694
	if (r100_debugfs_rbbm_init(rdev))
654
		DRM_ERROR("Failed to register debugfs file for RBBM !\n");
695
		DRM_ERROR("Failed to register debugfs file for RBBM !\n");
655
}
696
}
656
 
697
 
657
void rs600_set_safe_registers(struct radeon_device *rdev)
698
void rs600_set_safe_registers(struct radeon_device *rdev)
658
{
699
{
659
	rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
700
	rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
660
	rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
701
	rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
661
}
702
}
662
 
703
 
663
static void rs600_mc_program(struct radeon_device *rdev)
704
static void rs600_mc_program(struct radeon_device *rdev)
664
{
705
{
665
	struct rv515_mc_save save;
706
	struct rv515_mc_save save;
666
 
707
 
667
	/* Stops all mc clients */
708
	/* Stops all mc clients */
668
	rv515_mc_stop(rdev, &save);
709
	rv515_mc_stop(rdev, &save);
669
 
710
 
670
	/* Wait for mc idle */
711
	/* Wait for mc idle */
671
	if (rs600_mc_wait_for_idle(rdev))
712
	if (rs600_mc_wait_for_idle(rdev))
672
		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
713
		dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
673
 
714
 
674
	/* FIXME: What does AGP means for such chipset ? */
715
	/* FIXME: What does AGP means for such chipset ? */
675
	WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
716
	WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
676
	WREG32_MC(R_000006_AGP_BASE, 0);
717
	WREG32_MC(R_000006_AGP_BASE, 0);
677
	WREG32_MC(R_000007_AGP_BASE_2, 0);
718
	WREG32_MC(R_000007_AGP_BASE_2, 0);
678
	/* Program MC */
719
	/* Program MC */
679
	WREG32_MC(R_000004_MC_FB_LOCATION,
720
	WREG32_MC(R_000004_MC_FB_LOCATION,
680
			S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
721
			S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
681
			S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
722
			S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
682
	WREG32(R_000134_HDP_FB_LOCATION,
723
	WREG32(R_000134_HDP_FB_LOCATION,
683
		S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
724
		S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
684
 
725
 
685
	rv515_mc_resume(rdev, &save);
726
	rv515_mc_resume(rdev, &save);
686
}
727
}
687
 
728
 
688
static int rs600_startup(struct radeon_device *rdev)
729
static int rs600_startup(struct radeon_device *rdev)
689
{
730
{
690
	int r;
731
	int r;
691
 
732
 
692
	rs600_mc_program(rdev);
733
	rs600_mc_program(rdev);
693
	/* Resume clock */
734
	/* Resume clock */
694
	rv515_clock_startup(rdev);
735
	rv515_clock_startup(rdev);
695
	/* Initialize GPU configuration (# pipes, ...) */
736
	/* Initialize GPU configuration (# pipes, ...) */
696
	rs600_gpu_init(rdev);
737
	rs600_gpu_init(rdev);
697
	/* Initialize GART (initialize after TTM so we can allocate
738
	/* Initialize GART (initialize after TTM so we can allocate
698
	 * memory through TTM but finalize after TTM) */
739
	 * memory through TTM but finalize after TTM) */
699
	r = rs600_gart_enable(rdev);
740
	r = rs600_gart_enable(rdev);
700
	if (r)
741
	if (r)
701
	return r;
742
	return r;
702
 
743
 
703
	/* allocate wb buffer */
744
	/* allocate wb buffer */
704
	r = radeon_wb_init(rdev);
745
	r = radeon_wb_init(rdev);
705
	if (r)
746
	if (r)
706
		return r;
747
		return r;
707
 
748
 
708
	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
749
	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
709
	if (r) {
750
	if (r) {
710
		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
751
		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
711
		return r;
752
		return r;
712
	}
753
	}
713
 
754
 
714
	/* Enable IRQ */
755
	/* Enable IRQ */
-
 
756
	if (!rdev->irq.installed) {
-
 
757
		r = radeon_irq_kms_init(rdev);
-
 
758
		if (r)
-
 
759
			return r;
-
 
760
	}
-
 
761
 
715
	rs600_irq_set(rdev);
762
	rs600_irq_set(rdev);
716
	rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
763
	rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
717
	/* 1M ring buffer */
764
	/* 1M ring buffer */
718
	r = r100_cp_init(rdev, 1024 * 1024);
765
	r = r100_cp_init(rdev, 1024 * 1024);
719
	if (r) {
766
	if (r) {
720
		dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
767
		dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
721
		return r;
768
		return r;
722
	}
769
	}
723
 
770
 
724
	r = radeon_ib_pool_init(rdev);
771
	r = radeon_ib_pool_init(rdev);
725
	if (r) {
772
	if (r) {
726
		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
773
		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
727
		return r;
774
		return r;
728
	}
775
	}
729
 
776
 
730
 
777
 
731
	return 0;
778
	return 0;
732
}
779
}
733
 
780
 
734
 
781
 
735
 
782
 
736
int rs600_init(struct radeon_device *rdev)
783
int rs600_init(struct radeon_device *rdev)
737
{
784
{
738
	int r;
785
	int r;
739
 
786
 
740
	/* Disable VGA */
787
	/* Disable VGA */
741
	rv515_vga_render_disable(rdev);
788
	rv515_vga_render_disable(rdev);
742
	/* Initialize scratch registers */
789
	/* Initialize scratch registers */
743
	radeon_scratch_init(rdev);
790
	radeon_scratch_init(rdev);
744
	/* Initialize surface registers */
791
	/* Initialize surface registers */
745
	radeon_surface_init(rdev);
792
	radeon_surface_init(rdev);
746
	/* restore some register to sane defaults */
793
	/* restore some register to sane defaults */
747
	r100_restore_sanity(rdev);
794
	r100_restore_sanity(rdev);
748
	/* BIOS */
795
	/* BIOS */
749
	if (!radeon_get_bios(rdev)) {
796
	if (!radeon_get_bios(rdev)) {
750
		if (ASIC_IS_AVIVO(rdev))
797
		if (ASIC_IS_AVIVO(rdev))
751
			return -EINVAL;
798
			return -EINVAL;
752
	}
799
	}
753
	if (rdev->is_atom_bios) {
800
	if (rdev->is_atom_bios) {
754
		r = radeon_atombios_init(rdev);
801
		r = radeon_atombios_init(rdev);
755
		if (r)
802
		if (r)
756
			return r;
803
			return r;
757
	} else {
804
	} else {
758
		dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
805
		dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
759
		return -EINVAL;
806
		return -EINVAL;
760
	}
807
	}
761
	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
808
	/* Reset gpu before posting otherwise ATOM will enter infinite loop */
762
	if (radeon_asic_reset(rdev)) {
809
	if (radeon_asic_reset(rdev)) {
763
		dev_warn(rdev->dev,
810
		dev_warn(rdev->dev,
764
			"GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
811
			"GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
765
			RREG32(R_000E40_RBBM_STATUS),
812
			RREG32(R_000E40_RBBM_STATUS),
766
			RREG32(R_0007C0_CP_STAT));
813
			RREG32(R_0007C0_CP_STAT));
767
	}
814
	}
768
	/* check if cards are posted or not */
815
	/* check if cards are posted or not */
769
	if (radeon_boot_test_post_card(rdev) == false)
816
	if (radeon_boot_test_post_card(rdev) == false)
770
		return -EINVAL;
817
		return -EINVAL;
771
 
818
 
772
	/* Initialize clocks */
819
	/* Initialize clocks */
773
	radeon_get_clock_info(rdev->ddev);
820
	radeon_get_clock_info(rdev->ddev);
774
	/* initialize memory controller */
821
	/* initialize memory controller */
775
	rs600_mc_init(rdev);
822
	rs600_mc_init(rdev);
776
	rs600_debugfs(rdev);
823
	rs600_debugfs(rdev);
777
	/* Fence driver */
824
	/* Fence driver */
778
	r = radeon_fence_driver_init(rdev);
825
	r = radeon_fence_driver_init(rdev);
779
	if (r)
826
	if (r)
780
		return r;
-
 
781
	r = radeon_irq_kms_init(rdev);
-
 
782
	if (r)
-
 
783
		return r;
827
		return r;
784
	/* Memory manager */
828
	/* Memory manager */
785
	r = radeon_bo_init(rdev);
829
	r = radeon_bo_init(rdev);
786
	if (r)
830
	if (r)
787
		return r;
831
		return r;
788
	r = rs600_gart_init(rdev);
832
	r = rs600_gart_init(rdev);
789
	if (r)
833
	if (r)
790
		return r;
834
		return r;
791
	rs600_set_safe_registers(rdev);
835
	rs600_set_safe_registers(rdev);
792
 
836
 
793
	rdev->accel_working = true;
837
	rdev->accel_working = true;
794
	r = rs600_startup(rdev);
838
	r = rs600_startup(rdev);
795
	if (r) {
839
	if (r) {
796
		/* Somethings want wront with the accel init stop accel */
840
		/* Somethings want wront with the accel init stop accel */
797
		dev_err(rdev->dev, "Disabling GPU acceleration\n");
841
		dev_err(rdev->dev, "Disabling GPU acceleration\n");
798
//		r100_cp_fini(rdev);
842
//		r100_cp_fini(rdev);
799
//		r100_wb_fini(rdev);
843
//		r100_wb_fini(rdev);
800
//		r100_ib_fini(rdev);
844
//		r100_ib_fini(rdev);
801
		rs600_gart_fini(rdev);
845
		rs600_gart_fini(rdev);
802
//		radeon_irq_kms_fini(rdev);
846
//		radeon_irq_kms_fini(rdev);
803
		rdev->accel_working = false;
847
		rdev->accel_working = false;
804
	}
848
	}
805
	return 0;
849
	return 0;
806
}
850
}