Subversion Repositories Kolibri OS

Rev

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

Rev 3031 Rev 3120
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
//#include 
28
//#include 
29
#include 
29
#include 
30
#include 
30
#include 
31
#include 
31
#include 
32
#include 
32
#include 
33
#include "radeon_reg.h"
33
#include "radeon_reg.h"
34
#include "radeon.h"
34
#include "radeon.h"
35
#include "atom.h"
35
#include "atom.h"
-
 
36
 
-
 
37
#include "bitmap.h"
36
#include "display.h"
38
#include "display.h"
-
 
39
 
37
 
40
 
38
#include 
41
#include 
39
 
42
 
40
 
43
 
41
int radeon_no_wb   =  1;
44
int radeon_no_wb   =  1;
42
int radeon_modeset = -1;
45
int radeon_modeset = -1;
43
int radeon_dynclks = -1;
46
int radeon_dynclks = -1;
44
int radeon_r4xx_atom = 0;
47
int radeon_r4xx_atom = 0;
45
int radeon_agpmode = 0;
48
int radeon_agpmode = 0;
46
int radeon_vram_limit = 0;
49
int radeon_vram_limit = 0;
47
int radeon_gart_size = 512; /* default gart size */
50
int radeon_gart_size = 512; /* default gart size */
48
int radeon_benchmarking = 0;
51
int radeon_benchmarking = 0;
49
int radeon_testing = 0;
52
int radeon_testing = 0;
50
int radeon_connector_table = 0;
53
int radeon_connector_table = 0;
51
int radeon_tv = 1;
54
int radeon_tv = 1;
52
int radeon_new_pll = -1;
55
int radeon_new_pll = -1;
53
int radeon_dynpm = -1;
56
int radeon_dynpm = -1;
54
int radeon_audio = 1;
57
int radeon_audio = 1;
55
int radeon_hw_i2c = 0;
58
int radeon_hw_i2c = 0;
56
int radeon_pcie_gen2 = 0;
59
int radeon_pcie_gen2 = 0;
57
int radeon_disp_priority = 0;
60
int radeon_disp_priority = 0;
58
int radeon_lockup_timeout = 10000;
61
int radeon_lockup_timeout = 10000;
59
 
62
 
60
 
63
 
61
int irq_override = 0;
64
int irq_override = 0;
62
 
65
 
63
 
66
 
64
extern display_t *rdisplay;
67
extern display_t *rdisplay;
-
 
68
struct drm_device *main_drm_device;
-
 
69
 
65
 
70
 
66
void parse_cmdline(char *cmdline, videomode_t *mode, char *log, int *kms);
71
void parse_cmdline(char *cmdline, videomode_t *mode, char *log, int *kms);
67
int init_display(struct radeon_device *rdev, videomode_t *mode);
72
int init_display(struct radeon_device *rdev, videomode_t *mode);
68
int init_display_kms(struct radeon_device *rdev, videomode_t *mode);
73
int init_display_kms(struct radeon_device *rdev, videomode_t *mode);
69
 
74
 
70
int get_modes(videomode_t *mode, u32_t *count);
75
int get_modes(videomode_t *mode, u32_t *count);
71
int set_user_mode(videomode_t *mode);
76
int set_user_mode(videomode_t *mode);
72
int r100_2D_test(struct radeon_device *rdev);
77
int r100_2D_test(struct radeon_device *rdev);
73
 
78
 
74
 
79
 
75
 /* Legacy VGA regions */
80
 /* Legacy VGA regions */
76
#define VGA_RSRC_NONE          0x00
81
#define VGA_RSRC_NONE          0x00
77
#define VGA_RSRC_LEGACY_IO     0x01
82
#define VGA_RSRC_LEGACY_IO     0x01
78
#define VGA_RSRC_LEGACY_MEM    0x02
83
#define VGA_RSRC_LEGACY_MEM    0x02
79
#define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
84
#define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
80
/* Non-legacy access */
85
/* Non-legacy access */
81
#define VGA_RSRC_NORMAL_IO     0x04
86
#define VGA_RSRC_NORMAL_IO     0x04
82
#define VGA_RSRC_NORMAL_MEM    0x08
87
#define VGA_RSRC_NORMAL_MEM    0x08
83
 
88
 
84
 
89
 
85
static const char radeon_family_name[][16] = {
90
static const char radeon_family_name[][16] = {
86
	"R100",
91
	"R100",
87
	"RV100",
92
	"RV100",
88
	"RS100",
93
	"RS100",
89
	"RV200",
94
	"RV200",
90
	"RS200",
95
	"RS200",
91
	"R200",
96
	"R200",
92
	"RV250",
97
	"RV250",
93
	"RS300",
98
	"RS300",
94
	"RV280",
99
	"RV280",
95
	"R300",
100
	"R300",
96
	"R350",
101
	"R350",
97
	"RV350",
102
	"RV350",
98
	"RV380",
103
	"RV380",
99
	"R420",
104
	"R420",
100
	"R423",
105
	"R423",
101
	"RV410",
106
	"RV410",
102
	"RS400",
107
	"RS400",
103
	"RS480",
108
	"RS480",
104
	"RS600",
109
	"RS600",
105
	"RS690",
110
	"RS690",
106
	"RS740",
111
	"RS740",
107
	"RV515",
112
	"RV515",
108
	"R520",
113
	"R520",
109
	"RV530",
114
	"RV530",
110
	"RV560",
115
	"RV560",
111
	"RV570",
116
	"RV570",
112
	"R580",
117
	"R580",
113
	"R600",
118
	"R600",
114
	"RV610",
119
	"RV610",
115
	"RV630",
120
	"RV630",
116
	"RV670",
121
	"RV670",
117
	"RV620",
122
	"RV620",
118
	"RV635",
123
	"RV635",
119
	"RS780",
124
	"RS780",
120
	"RS880",
125
	"RS880",
121
	"RV770",
126
	"RV770",
122
	"RV730",
127
	"RV730",
123
	"RV710",
128
	"RV710",
124
	"RV740",
129
	"RV740",
125
	"CEDAR",
130
	"CEDAR",
126
	"REDWOOD",
131
	"REDWOOD",
127
	"JUNIPER",
132
	"JUNIPER",
128
	"CYPRESS",
133
	"CYPRESS",
129
	"HEMLOCK",
134
	"HEMLOCK",
130
	"PALM",
135
	"PALM",
131
	"SUMO",
136
	"SUMO",
132
	"SUMO2",
137
	"SUMO2",
133
	"BARTS",
138
	"BARTS",
134
	"TURKS",
139
	"TURKS",
135
	"CAICOS",
140
	"CAICOS",
136
	"CAYMAN",
141
	"CAYMAN",
137
	"ARUBA",
142
	"ARUBA",
138
	"TAHITI",
143
	"TAHITI",
139
	"PITCAIRN",
144
	"PITCAIRN",
140
	"VERDE",
145
	"VERDE",
141
	"LAST",
146
	"LAST",
142
};
147
};
143
 
148
 
144
/**
149
/**
145
 * radeon_surface_init - Clear GPU surface registers.
150
 * radeon_surface_init - Clear GPU surface registers.
146
 *
151
 *
147
 * @rdev: radeon_device pointer
152
 * @rdev: radeon_device pointer
148
 *
153
 *
149
 * Clear GPU surface registers (r1xx-r5xx).
154
 * Clear GPU surface registers (r1xx-r5xx).
150
 */
155
 */
151
void radeon_surface_init(struct radeon_device *rdev)
156
void radeon_surface_init(struct radeon_device *rdev)
152
{
157
{
153
    /* FIXME: check this out */
158
    /* FIXME: check this out */
154
    if (rdev->family < CHIP_R600) {
159
    if (rdev->family < CHIP_R600) {
155
        int i;
160
        int i;
156
 
161
 
157
		for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
162
		for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
158
           radeon_clear_surface_reg(rdev, i);
163
           radeon_clear_surface_reg(rdev, i);
159
        }
164
        }
160
		/* enable surfaces */
165
		/* enable surfaces */
161
		WREG32(RADEON_SURFACE_CNTL, 0);
166
		WREG32(RADEON_SURFACE_CNTL, 0);
162
    }
167
    }
163
}
168
}
164
 
169
 
165
/*
170
/*
166
 * GPU scratch registers helpers function.
171
 * GPU scratch registers helpers function.
167
 */
172
 */
168
/**
173
/**
169
 * radeon_scratch_init - Init scratch register driver information.
174
 * radeon_scratch_init - Init scratch register driver information.
170
 *
175
 *
171
 * @rdev: radeon_device pointer
176
 * @rdev: radeon_device pointer
172
 *
177
 *
173
 * Init CP scratch register driver information (r1xx-r5xx)
178
 * Init CP scratch register driver information (r1xx-r5xx)
174
 */
179
 */
175
void radeon_scratch_init(struct radeon_device *rdev)
180
void radeon_scratch_init(struct radeon_device *rdev)
176
{
181
{
177
    int i;
182
    int i;
178
 
183
 
179
    /* FIXME: check this out */
184
    /* FIXME: check this out */
180
    if (rdev->family < CHIP_R300) {
185
    if (rdev->family < CHIP_R300) {
181
        rdev->scratch.num_reg = 5;
186
        rdev->scratch.num_reg = 5;
182
    } else {
187
    } else {
183
        rdev->scratch.num_reg = 7;
188
        rdev->scratch.num_reg = 7;
184
    }
189
    }
185
	rdev->scratch.reg_base = RADEON_SCRATCH_REG0;
190
	rdev->scratch.reg_base = RADEON_SCRATCH_REG0;
186
    for (i = 0; i < rdev->scratch.num_reg; i++) {
191
    for (i = 0; i < rdev->scratch.num_reg; i++) {
187
        rdev->scratch.free[i] = true;
192
        rdev->scratch.free[i] = true;
188
		rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
193
		rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
189
    }
194
    }
190
}
195
}
191
 
196
 
192
/**
197
/**
193
 * radeon_scratch_get - Allocate a scratch register
198
 * radeon_scratch_get - Allocate a scratch register
194
 *
199
 *
195
 * @rdev: radeon_device pointer
200
 * @rdev: radeon_device pointer
196
 * @reg: scratch register mmio offset
201
 * @reg: scratch register mmio offset
197
 *
202
 *
198
 * Allocate a CP scratch register for use by the driver (all asics).
203
 * Allocate a CP scratch register for use by the driver (all asics).
199
 * Returns 0 on success or -EINVAL on failure.
204
 * Returns 0 on success or -EINVAL on failure.
200
 */
205
 */
201
int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg)
206
int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg)
202
{
207
{
203
	int i;
208
	int i;
204
 
209
 
205
	for (i = 0; i < rdev->scratch.num_reg; i++) {
210
	for (i = 0; i < rdev->scratch.num_reg; i++) {
206
		if (rdev->scratch.free[i]) {
211
		if (rdev->scratch.free[i]) {
207
			rdev->scratch.free[i] = false;
212
			rdev->scratch.free[i] = false;
208
			*reg = rdev->scratch.reg[i];
213
			*reg = rdev->scratch.reg[i];
209
			return 0;
214
			return 0;
210
		}
215
		}
211
	}
216
	}
212
	return -EINVAL;
217
	return -EINVAL;
213
}
218
}
214
 
219
 
215
/**
220
/**
216
 * radeon_scratch_free - Free a scratch register
221
 * radeon_scratch_free - Free a scratch register
217
 *
222
 *
218
 * @rdev: radeon_device pointer
223
 * @rdev: radeon_device pointer
219
 * @reg: scratch register mmio offset
224
 * @reg: scratch register mmio offset
220
 *
225
 *
221
 * Free a CP scratch register allocated for use by the driver (all asics)
226
 * Free a CP scratch register allocated for use by the driver (all asics)
222
 */
227
 */
223
void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg)
228
void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg)
224
{
229
{
225
	int i;
230
	int i;
226
 
231
 
227
	for (i = 0; i < rdev->scratch.num_reg; i++) {
232
	for (i = 0; i < rdev->scratch.num_reg; i++) {
228
		if (rdev->scratch.reg[i] == reg) {
233
		if (rdev->scratch.reg[i] == reg) {
229
			rdev->scratch.free[i] = true;
234
			rdev->scratch.free[i] = true;
230
			return;
235
			return;
231
		}
236
		}
232
	}
237
	}
233
}
238
}
234
 
239
 
235
/*
240
/*
236
 * radeon_wb_*()
241
 * radeon_wb_*()
237
 * Writeback is the the method by which the the GPU updates special pages
242
 * Writeback is the the method by which the the GPU updates special pages
238
 * in memory with the status of certain GPU events (fences, ring pointers,
243
 * in memory with the status of certain GPU events (fences, ring pointers,
239
 * etc.).
244
 * etc.).
240
 */
245
 */
241
 
246
 
242
/**
247
/**
243
 * radeon_wb_disable - Disable Writeback
248
 * radeon_wb_disable - Disable Writeback
244
 *
249
 *
245
 * @rdev: radeon_device pointer
250
 * @rdev: radeon_device pointer
246
 *
251
 *
247
 * Disables Writeback (all asics).  Used for suspend.
252
 * Disables Writeback (all asics).  Used for suspend.
248
 */
253
 */
249
void radeon_wb_disable(struct radeon_device *rdev)
254
void radeon_wb_disable(struct radeon_device *rdev)
250
{
255
{
251
	int r;
256
	int r;
252
 
257
 
253
	if (rdev->wb.wb_obj) {
258
	if (rdev->wb.wb_obj) {
254
		r = radeon_bo_reserve(rdev->wb.wb_obj, false);
259
		r = radeon_bo_reserve(rdev->wb.wb_obj, false);
255
		if (unlikely(r != 0))
260
		if (unlikely(r != 0))
256
			return;
261
			return;
257
		radeon_bo_kunmap(rdev->wb.wb_obj);
262
		radeon_bo_kunmap(rdev->wb.wb_obj);
258
		radeon_bo_unpin(rdev->wb.wb_obj);
263
		radeon_bo_unpin(rdev->wb.wb_obj);
259
		radeon_bo_unreserve(rdev->wb.wb_obj);
264
		radeon_bo_unreserve(rdev->wb.wb_obj);
260
	}
265
	}
261
	rdev->wb.enabled = false;
266
	rdev->wb.enabled = false;
262
}
267
}
263
 
268
 
264
/**
269
/**
265
 * radeon_wb_fini - Disable Writeback and free memory
270
 * radeon_wb_fini - Disable Writeback and free memory
266
 *
271
 *
267
 * @rdev: radeon_device pointer
272
 * @rdev: radeon_device pointer
268
 *
273
 *
269
 * Disables Writeback and frees the Writeback memory (all asics).
274
 * Disables Writeback and frees the Writeback memory (all asics).
270
 * Used at driver shutdown.
275
 * Used at driver shutdown.
271
 */
276
 */
272
void radeon_wb_fini(struct radeon_device *rdev)
277
void radeon_wb_fini(struct radeon_device *rdev)
273
{
278
{
274
	radeon_wb_disable(rdev);
279
	radeon_wb_disable(rdev);
275
	if (rdev->wb.wb_obj) {
280
	if (rdev->wb.wb_obj) {
276
		radeon_bo_unref(&rdev->wb.wb_obj);
281
		radeon_bo_unref(&rdev->wb.wb_obj);
277
		rdev->wb.wb = NULL;
282
		rdev->wb.wb = NULL;
278
		rdev->wb.wb_obj = NULL;
283
		rdev->wb.wb_obj = NULL;
279
	}
284
	}
280
}
285
}
281
 
286
 
282
/**
287
/**
283
 * radeon_wb_init- Init Writeback driver info and allocate memory
288
 * radeon_wb_init- Init Writeback driver info and allocate memory
284
 *
289
 *
285
 * @rdev: radeon_device pointer
290
 * @rdev: radeon_device pointer
286
 *
291
 *
287
 * Disables Writeback and frees the Writeback memory (all asics).
292
 * Disables Writeback and frees the Writeback memory (all asics).
288
 * Used at driver startup.
293
 * Used at driver startup.
289
 * Returns 0 on success or an -error on failure.
294
 * Returns 0 on success or an -error on failure.
290
 */
295
 */
291
int radeon_wb_init(struct radeon_device *rdev)
296
int radeon_wb_init(struct radeon_device *rdev)
292
{
297
{
293
	int r;
298
	int r;
294
 
299
 
295
	if (rdev->wb.wb_obj == NULL) {
300
	if (rdev->wb.wb_obj == NULL) {
296
		r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
301
		r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
297
				     RADEON_GEM_DOMAIN_GTT, NULL, &rdev->wb.wb_obj);
302
				     RADEON_GEM_DOMAIN_GTT, NULL, &rdev->wb.wb_obj);
298
		if (r) {
303
		if (r) {
299
			dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
304
			dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
300
			return r;
305
			return r;
301
		}
306
		}
302
	}
307
	}
303
	r = radeon_bo_reserve(rdev->wb.wb_obj, false);
308
	r = radeon_bo_reserve(rdev->wb.wb_obj, false);
304
	if (unlikely(r != 0)) {
309
	if (unlikely(r != 0)) {
305
		radeon_wb_fini(rdev);
310
		radeon_wb_fini(rdev);
306
		return r;
311
		return r;
307
	}
312
	}
308
	r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
313
	r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
309
			  &rdev->wb.gpu_addr);
314
			  &rdev->wb.gpu_addr);
310
	if (r) {
315
	if (r) {
311
		radeon_bo_unreserve(rdev->wb.wb_obj);
316
		radeon_bo_unreserve(rdev->wb.wb_obj);
312
		dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
317
		dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
313
		radeon_wb_fini(rdev);
318
		radeon_wb_fini(rdev);
314
		return r;
319
		return r;
315
	}
320
	}
316
	r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
321
	r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
317
	radeon_bo_unreserve(rdev->wb.wb_obj);
322
	radeon_bo_unreserve(rdev->wb.wb_obj);
318
	if (r) {
323
	if (r) {
319
		dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
324
		dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
320
		radeon_wb_fini(rdev);
325
		radeon_wb_fini(rdev);
321
		return r;
326
		return r;
322
	}
327
	}
323
 
328
 
324
	/* clear wb memory */
329
	/* clear wb memory */
325
	memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE);
330
	memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE);
326
	/* disable event_write fences */
331
	/* disable event_write fences */
327
	rdev->wb.use_event = false;
332
	rdev->wb.use_event = false;
328
	/* disabled via module param */
333
	/* disabled via module param */
329
	if (radeon_no_wb == 1) {
334
	if (radeon_no_wb == 1) {
330
		rdev->wb.enabled = false;
335
		rdev->wb.enabled = false;
331
	} else {
336
	} else {
332
		if (rdev->flags & RADEON_IS_AGP) {
337
		if (rdev->flags & RADEON_IS_AGP) {
333
		/* often unreliable on AGP */
338
		/* often unreliable on AGP */
334
			rdev->wb.enabled = false;
339
			rdev->wb.enabled = false;
335
		} else if (rdev->family < CHIP_R300) {
340
		} else if (rdev->family < CHIP_R300) {
336
			/* often unreliable on pre-r300 */
341
			/* often unreliable on pre-r300 */
337
			rdev->wb.enabled = false;
342
			rdev->wb.enabled = false;
338
		} else {
343
		} else {
339
			rdev->wb.enabled = true;
344
			rdev->wb.enabled = true;
340
			/* event_write fences are only available on r600+ */
345
			/* event_write fences are only available on r600+ */
341
			if (rdev->family >= CHIP_R600) {
346
			if (rdev->family >= CHIP_R600) {
342
				rdev->wb.use_event = true;
347
				rdev->wb.use_event = true;
343
	}
348
	}
344
		}
349
		}
345
	}
350
	}
346
	/* always use writeback/events on NI, APUs */
351
	/* always use writeback/events on NI, APUs */
347
	if (rdev->family >= CHIP_PALM) {
352
	if (rdev->family >= CHIP_PALM) {
348
		rdev->wb.enabled = true;
353
		rdev->wb.enabled = true;
349
		rdev->wb.use_event = true;
354
		rdev->wb.use_event = true;
350
	}
355
	}
351
 
356
 
352
	dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis");
357
	dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis");
353
 
358
 
354
	return 0;
359
	return 0;
355
}
360
}
356
 
361
 
357
/**
362
/**
358
 * radeon_vram_location - try to find VRAM location
363
 * radeon_vram_location - try to find VRAM location
359
 * @rdev: radeon device structure holding all necessary informations
364
 * @rdev: radeon device structure holding all necessary informations
360
 * @mc: memory controller structure holding memory informations
365
 * @mc: memory controller structure holding memory informations
361
 * @base: base address at which to put VRAM
366
 * @base: base address at which to put VRAM
362
 *
367
 *
363
 * Function will place try to place VRAM at base address provided
368
 * Function will place try to place VRAM at base address provided
364
 * as parameter (which is so far either PCI aperture address or
369
 * as parameter (which is so far either PCI aperture address or
365
 * for IGP TOM base address).
370
 * for IGP TOM base address).
366
 *
371
 *
367
 * If there is not enough space to fit the unvisible VRAM in the 32bits
372
 * If there is not enough space to fit the unvisible VRAM in the 32bits
368
 * address space then we limit the VRAM size to the aperture.
373
 * address space then we limit the VRAM size to the aperture.
369
 *
374
 *
370
 * If we are using AGP and if the AGP aperture doesn't allow us to have
375
 * If we are using AGP and if the AGP aperture doesn't allow us to have
371
 * room for all the VRAM than we restrict the VRAM to the PCI aperture
376
 * room for all the VRAM than we restrict the VRAM to the PCI aperture
372
 * size and print a warning.
377
 * size and print a warning.
373
 *
378
 *
374
 * This function will never fails, worst case are limiting VRAM.
379
 * This function will never fails, worst case are limiting VRAM.
375
 *
380
 *
376
 * Note: GTT start, end, size should be initialized before calling this
381
 * Note: GTT start, end, size should be initialized before calling this
377
 * function on AGP platform.
382
 * function on AGP platform.
378
 *
383
 *
379
 * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size,
384
 * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size,
380
 * this shouldn't be a problem as we are using the PCI aperture as a reference.
385
 * this shouldn't be a problem as we are using the PCI aperture as a reference.
381
 * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but
386
 * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but
382
 * not IGP.
387
 * not IGP.
383
 *
388
 *
384
 * Note: we use mc_vram_size as on some board we need to program the mc to
389
 * Note: we use mc_vram_size as on some board we need to program the mc to
385
 * cover the whole aperture even if VRAM size is inferior to aperture size
390
 * cover the whole aperture even if VRAM size is inferior to aperture size
386
 * Novell bug 204882 + along with lots of ubuntu ones
391
 * Novell bug 204882 + along with lots of ubuntu ones
387
 *
392
 *
388
 * Note: when limiting vram it's safe to overwritte real_vram_size because
393
 * Note: when limiting vram it's safe to overwritte real_vram_size because
389
 * we are not in case where real_vram_size is inferior to mc_vram_size (ie
394
 * we are not in case where real_vram_size is inferior to mc_vram_size (ie
390
 * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu
395
 * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu
391
 * ones)
396
 * ones)
392
 *
397
 *
393
 * Note: IGP TOM addr should be the same as the aperture addr, we don't
398
 * Note: IGP TOM addr should be the same as the aperture addr, we don't
394
 * explicitly check for that thought.
399
 * explicitly check for that thought.
395
 *
400
 *
396
 * FIXME: when reducing VRAM size align new size on power of 2.
401
 * FIXME: when reducing VRAM size align new size on power of 2.
397
 */
402
 */
398
void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base)
403
void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base)
399
{
404
{
400
	uint64_t limit = (uint64_t)radeon_vram_limit << 20;
405
	uint64_t limit = (uint64_t)radeon_vram_limit << 20;
401
 
406
 
402
	mc->vram_start = base;
407
	mc->vram_start = base;
403
	if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) {
408
	if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) {
404
		dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
409
		dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
405
		mc->real_vram_size = mc->aper_size;
410
		mc->real_vram_size = mc->aper_size;
406
		mc->mc_vram_size = mc->aper_size;
411
		mc->mc_vram_size = mc->aper_size;
407
	}
412
	}
408
	mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
413
	mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
409
	if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) {
414
	if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) {
410
		dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
415
		dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
411
		mc->real_vram_size = mc->aper_size;
416
		mc->real_vram_size = mc->aper_size;
412
		mc->mc_vram_size = mc->aper_size;
417
		mc->mc_vram_size = mc->aper_size;
413
		}
418
		}
414
	mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
419
	mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
415
	if (limit && limit < mc->real_vram_size)
420
	if (limit && limit < mc->real_vram_size)
416
		mc->real_vram_size = limit;
421
		mc->real_vram_size = limit;
417
	dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
422
	dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
418
			mc->mc_vram_size >> 20, mc->vram_start,
423
			mc->mc_vram_size >> 20, mc->vram_start,
419
			mc->vram_end, mc->real_vram_size >> 20);
424
			mc->vram_end, mc->real_vram_size >> 20);
420
}
425
}
421
 
426
 
422
/**
427
/**
423
 * radeon_gtt_location - try to find GTT location
428
 * radeon_gtt_location - try to find GTT location
424
 * @rdev: radeon device structure holding all necessary informations
429
 * @rdev: radeon device structure holding all necessary informations
425
 * @mc: memory controller structure holding memory informations
430
 * @mc: memory controller structure holding memory informations
426
 *
431
 *
427
 * Function will place try to place GTT before or after VRAM.
432
 * Function will place try to place GTT before or after VRAM.
428
 *
433
 *
429
 * If GTT size is bigger than space left then we ajust GTT size.
434
 * If GTT size is bigger than space left then we ajust GTT size.
430
 * Thus function will never fails.
435
 * Thus function will never fails.
431
 *
436
 *
432
 * FIXME: when reducing GTT size align new size on power of 2.
437
 * FIXME: when reducing GTT size align new size on power of 2.
433
 */
438
 */
434
void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
439
void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
435
{
440
{
436
	u64 size_af, size_bf;
441
	u64 size_af, size_bf;
437
 
442
 
438
	size_af = ((0xFFFFFFFF - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align;
443
	size_af = ((0xFFFFFFFF - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align;
439
	size_bf = mc->vram_start & ~mc->gtt_base_align;
444
	size_bf = mc->vram_start & ~mc->gtt_base_align;
440
	if (size_bf > size_af) {
445
	if (size_bf > size_af) {
441
		if (mc->gtt_size > size_bf) {
446
		if (mc->gtt_size > size_bf) {
442
			dev_warn(rdev->dev, "limiting GTT\n");
447
			dev_warn(rdev->dev, "limiting GTT\n");
443
			mc->gtt_size = size_bf;
448
			mc->gtt_size = size_bf;
444
		}
449
		}
445
		mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size;
450
		mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size;
446
	} else {
451
	} else {
447
		if (mc->gtt_size > size_af) {
452
		if (mc->gtt_size > size_af) {
448
			dev_warn(rdev->dev, "limiting GTT\n");
453
			dev_warn(rdev->dev, "limiting GTT\n");
449
			mc->gtt_size = size_af;
454
			mc->gtt_size = size_af;
450
		}
455
		}
451
		mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
456
		mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
452
	}
457
	}
453
	mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
458
	mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
454
	dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
459
	dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
455
			mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
460
			mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
456
}
461
}
457
 
462
 
458
/*
463
/*
459
 * GPU helpers function.
464
 * GPU helpers function.
460
 */
465
 */
461
/**
466
/**
462
 * radeon_card_posted - check if the hw has already been initialized
467
 * radeon_card_posted - check if the hw has already been initialized
463
 *
468
 *
464
 * @rdev: radeon_device pointer
469
 * @rdev: radeon_device pointer
465
 *
470
 *
466
 * Check if the asic has been initialized (all asics).
471
 * Check if the asic has been initialized (all asics).
467
 * Used at driver startup.
472
 * Used at driver startup.
468
 * Returns true if initialized or false if not.
473
 * Returns true if initialized or false if not.
469
 */
474
 */
470
bool radeon_card_posted(struct radeon_device *rdev)
475
bool radeon_card_posted(struct radeon_device *rdev)
471
{
476
{
472
	uint32_t reg;
477
	uint32_t reg;
473
 
478
 
474
	/* first check CRTCs */
479
	/* first check CRTCs */
475
	if (ASIC_IS_DCE41(rdev)) {
480
	if (ASIC_IS_DCE41(rdev)) {
476
		reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
481
		reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
477
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
482
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
478
		if (reg & EVERGREEN_CRTC_MASTER_EN)
483
		if (reg & EVERGREEN_CRTC_MASTER_EN)
479
			return true;
484
			return true;
480
	} else if (ASIC_IS_DCE4(rdev)) {
485
	} else if (ASIC_IS_DCE4(rdev)) {
481
		reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
486
		reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
482
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) |
487
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) |
483
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) |
488
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) |
484
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) |
489
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) |
485
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) |
490
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) |
486
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
491
			RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
487
		if (reg & EVERGREEN_CRTC_MASTER_EN)
492
		if (reg & EVERGREEN_CRTC_MASTER_EN)
488
			return true;
493
			return true;
489
	} else if (ASIC_IS_AVIVO(rdev)) {
494
	} else if (ASIC_IS_AVIVO(rdev)) {
490
		reg = RREG32(AVIVO_D1CRTC_CONTROL) |
495
		reg = RREG32(AVIVO_D1CRTC_CONTROL) |
491
		      RREG32(AVIVO_D2CRTC_CONTROL);
496
		      RREG32(AVIVO_D2CRTC_CONTROL);
492
		if (reg & AVIVO_CRTC_EN) {
497
		if (reg & AVIVO_CRTC_EN) {
493
			return true;
498
			return true;
494
		}
499
		}
495
	} else {
500
	} else {
496
		reg = RREG32(RADEON_CRTC_GEN_CNTL) |
501
		reg = RREG32(RADEON_CRTC_GEN_CNTL) |
497
		      RREG32(RADEON_CRTC2_GEN_CNTL);
502
		      RREG32(RADEON_CRTC2_GEN_CNTL);
498
		if (reg & RADEON_CRTC_EN) {
503
		if (reg & RADEON_CRTC_EN) {
499
			return true;
504
			return true;
500
		}
505
		}
501
	}
506
	}
502
 
507
 
503
	/* then check MEM_SIZE, in case the crtcs are off */
508
	/* then check MEM_SIZE, in case the crtcs are off */
504
	if (rdev->family >= CHIP_R600)
509
	if (rdev->family >= CHIP_R600)
505
		reg = RREG32(R600_CONFIG_MEMSIZE);
510
		reg = RREG32(R600_CONFIG_MEMSIZE);
506
	else
511
	else
507
		reg = RREG32(RADEON_CONFIG_MEMSIZE);
512
		reg = RREG32(RADEON_CONFIG_MEMSIZE);
508
 
513
 
509
	if (reg)
514
	if (reg)
510
		return true;
515
		return true;
511
 
516
 
512
	return false;
517
	return false;
513
 
518
 
514
}
519
}
515
 
520
 
516
/**
521
/**
517
 * radeon_update_bandwidth_info - update display bandwidth params
522
 * radeon_update_bandwidth_info - update display bandwidth params
518
 *
523
 *
519
 * @rdev: radeon_device pointer
524
 * @rdev: radeon_device pointer
520
 *
525
 *
521
 * Used when sclk/mclk are switched or display modes are set.
526
 * Used when sclk/mclk are switched or display modes are set.
522
 * params are used to calculate display watermarks (all asics)
527
 * params are used to calculate display watermarks (all asics)
523
 */
528
 */
524
void radeon_update_bandwidth_info(struct radeon_device *rdev)
529
void radeon_update_bandwidth_info(struct radeon_device *rdev)
525
{
530
{
526
	fixed20_12 a;
531
	fixed20_12 a;
527
	u32 sclk = rdev->pm.current_sclk;
532
	u32 sclk = rdev->pm.current_sclk;
528
	u32 mclk = rdev->pm.current_mclk;
533
	u32 mclk = rdev->pm.current_mclk;
529
 
534
 
530
	/* sclk/mclk in Mhz */
535
	/* sclk/mclk in Mhz */
531
		a.full = dfixed_const(100);
536
		a.full = dfixed_const(100);
532
		rdev->pm.sclk.full = dfixed_const(sclk);
537
		rdev->pm.sclk.full = dfixed_const(sclk);
533
		rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a);
538
		rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a);
534
		rdev->pm.mclk.full = dfixed_const(mclk);
539
		rdev->pm.mclk.full = dfixed_const(mclk);
535
		rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a);
540
		rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a);
536
 
541
 
537
	if (rdev->flags & RADEON_IS_IGP) {
542
	if (rdev->flags & RADEON_IS_IGP) {
538
		a.full = dfixed_const(16);
543
		a.full = dfixed_const(16);
539
		/* core_bandwidth = sclk(Mhz) * 16 */
544
		/* core_bandwidth = sclk(Mhz) * 16 */
540
		rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
545
		rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
541
	}
546
	}
542
}
547
}
543
 
548
 
544
/**
549
/**
545
 * radeon_boot_test_post_card - check and possibly initialize the hw
550
 * radeon_boot_test_post_card - check and possibly initialize the hw
546
 *
551
 *
547
 * @rdev: radeon_device pointer
552
 * @rdev: radeon_device pointer
548
 *
553
 *
549
 * Check if the asic is initialized and if not, attempt to initialize
554
 * Check if the asic is initialized and if not, attempt to initialize
550
 * it (all asics).
555
 * it (all asics).
551
 * Returns true if initialized or false if not.
556
 * Returns true if initialized or false if not.
552
 */
557
 */
553
bool radeon_boot_test_post_card(struct radeon_device *rdev)
558
bool radeon_boot_test_post_card(struct radeon_device *rdev)
554
{
559
{
555
	if (radeon_card_posted(rdev))
560
	if (radeon_card_posted(rdev))
556
		return true;
561
		return true;
557
 
562
 
558
	if (rdev->bios) {
563
	if (rdev->bios) {
559
		DRM_INFO("GPU not posted. posting now...\n");
564
		DRM_INFO("GPU not posted. posting now...\n");
560
		if (rdev->is_atom_bios)
565
		if (rdev->is_atom_bios)
561
			atom_asic_init(rdev->mode_info.atom_context);
566
			atom_asic_init(rdev->mode_info.atom_context);
562
		else
567
		else
563
			radeon_combios_asic_init(rdev->ddev);
568
			radeon_combios_asic_init(rdev->ddev);
564
		return true;
569
		return true;
565
	} else {
570
	} else {
566
		dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
571
		dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
567
		return false;
572
		return false;
568
	}
573
	}
569
}
574
}
570
 
575
 
571
/**
576
/**
572
 * radeon_dummy_page_init - init dummy page used by the driver
577
 * radeon_dummy_page_init - init dummy page used by the driver
573
 *
578
 *
574
 * @rdev: radeon_device pointer
579
 * @rdev: radeon_device pointer
575
 *
580
 *
576
 * Allocate the dummy page used by the driver (all asics).
581
 * Allocate the dummy page used by the driver (all asics).
577
 * This dummy page is used by the driver as a filler for gart entries
582
 * This dummy page is used by the driver as a filler for gart entries
578
 * when pages are taken out of the GART
583
 * when pages are taken out of the GART
579
 * Returns 0 on sucess, -ENOMEM on failure.
584
 * Returns 0 on sucess, -ENOMEM on failure.
580
 */
585
 */
581
int radeon_dummy_page_init(struct radeon_device *rdev)
586
int radeon_dummy_page_init(struct radeon_device *rdev)
582
{
587
{
583
	if (rdev->dummy_page.page)
588
	if (rdev->dummy_page.page)
584
		return 0;
589
		return 0;
585
    rdev->dummy_page.page = (void*)AllocPage();
590
    rdev->dummy_page.page = (void*)AllocPage();
586
	if (rdev->dummy_page.page == NULL)
591
	if (rdev->dummy_page.page == NULL)
587
		return -ENOMEM;
592
		return -ENOMEM;
588
    rdev->dummy_page.addr = MapIoMem((addr_t)rdev->dummy_page.page, 4096, 3);
593
    rdev->dummy_page.addr = MapIoMem((addr_t)rdev->dummy_page.page, 4096, 3);
589
	if (!rdev->dummy_page.addr) {
594
	if (!rdev->dummy_page.addr) {
590
//       __free_page(rdev->dummy_page.page);
595
//       __free_page(rdev->dummy_page.page);
591
		rdev->dummy_page.page = NULL;
596
		rdev->dummy_page.page = NULL;
592
		return -ENOMEM;
597
		return -ENOMEM;
593
	}
598
	}
594
	return 0;
599
	return 0;
595
}
600
}
596
 
601
 
597
/**
602
/**
598
 * radeon_dummy_page_fini - free dummy page used by the driver
603
 * radeon_dummy_page_fini - free dummy page used by the driver
599
 *
604
 *
600
 * @rdev: radeon_device pointer
605
 * @rdev: radeon_device pointer
601
 *
606
 *
602
 * Frees the dummy page used by the driver (all asics).
607
 * Frees the dummy page used by the driver (all asics).
603
 */
608
 */
604
void radeon_dummy_page_fini(struct radeon_device *rdev)
609
void radeon_dummy_page_fini(struct radeon_device *rdev)
605
{
610
{
606
	if (rdev->dummy_page.page == NULL)
611
	if (rdev->dummy_page.page == NULL)
607
		return;
612
		return;
608
    KernelFree((void*)rdev->dummy_page.addr);
613
    KernelFree((void*)rdev->dummy_page.addr);
609
	rdev->dummy_page.page = NULL;
614
	rdev->dummy_page.page = NULL;
610
}
615
}
611
 
616
 
612
 
617
 
613
/* ATOM accessor methods */
618
/* ATOM accessor methods */
614
/*
619
/*
615
 * ATOM is an interpreted byte code stored in tables in the vbios.  The
620
 * ATOM is an interpreted byte code stored in tables in the vbios.  The
616
 * driver registers callbacks to access registers and the interpreter
621
 * driver registers callbacks to access registers and the interpreter
617
 * in the driver parses the tables and executes then to program specific
622
 * in the driver parses the tables and executes then to program specific
618
 * actions (set display modes, asic init, etc.).  See radeon_atombios.c,
623
 * actions (set display modes, asic init, etc.).  See radeon_atombios.c,
619
 * atombios.h, and atom.c
624
 * atombios.h, and atom.c
620
 */
625
 */
621
 
626
 
622
/**
627
/**
623
 * cail_pll_read - read PLL register
628
 * cail_pll_read - read PLL register
624
 *
629
 *
625
 * @info: atom card_info pointer
630
 * @info: atom card_info pointer
626
 * @reg: PLL register offset
631
 * @reg: PLL register offset
627
 *
632
 *
628
 * Provides a PLL register accessor for the atom interpreter (r4xx+).
633
 * Provides a PLL register accessor for the atom interpreter (r4xx+).
629
 * Returns the value of the PLL register.
634
 * Returns the value of the PLL register.
630
 */
635
 */
631
static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
636
static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
632
{
637
{
633
    struct radeon_device *rdev = info->dev->dev_private;
638
    struct radeon_device *rdev = info->dev->dev_private;
634
    uint32_t r;
639
    uint32_t r;
635
 
640
 
636
    r = rdev->pll_rreg(rdev, reg);
641
    r = rdev->pll_rreg(rdev, reg);
637
    return r;
642
    return r;
638
}
643
}
639
 
644
 
640
/**
645
/**
641
 * cail_pll_write - write PLL register
646
 * cail_pll_write - write PLL register
642
 *
647
 *
643
 * @info: atom card_info pointer
648
 * @info: atom card_info pointer
644
 * @reg: PLL register offset
649
 * @reg: PLL register offset
645
 * @val: value to write to the pll register
650
 * @val: value to write to the pll register
646
 *
651
 *
647
 * Provides a PLL register accessor for the atom interpreter (r4xx+).
652
 * Provides a PLL register accessor for the atom interpreter (r4xx+).
648
 */
653
 */
649
static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
654
static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
650
{
655
{
651
    struct radeon_device *rdev = info->dev->dev_private;
656
    struct radeon_device *rdev = info->dev->dev_private;
652
 
657
 
653
    rdev->pll_wreg(rdev, reg, val);
658
    rdev->pll_wreg(rdev, reg, val);
654
}
659
}
655
 
660
 
656
/**
661
/**
657
 * cail_mc_read - read MC (Memory Controller) register
662
 * cail_mc_read - read MC (Memory Controller) register
658
 *
663
 *
659
 * @info: atom card_info pointer
664
 * @info: atom card_info pointer
660
 * @reg: MC register offset
665
 * @reg: MC register offset
661
 *
666
 *
662
 * Provides an MC register accessor for the atom interpreter (r4xx+).
667
 * Provides an MC register accessor for the atom interpreter (r4xx+).
663
 * Returns the value of the MC register.
668
 * Returns the value of the MC register.
664
 */
669
 */
665
static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
670
static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
666
{
671
{
667
    struct radeon_device *rdev = info->dev->dev_private;
672
    struct radeon_device *rdev = info->dev->dev_private;
668
    uint32_t r;
673
    uint32_t r;
669
 
674
 
670
    r = rdev->mc_rreg(rdev, reg);
675
    r = rdev->mc_rreg(rdev, reg);
671
    return r;
676
    return r;
672
}
677
}
673
 
678
 
674
/**
679
/**
675
 * cail_mc_write - write MC (Memory Controller) register
680
 * cail_mc_write - write MC (Memory Controller) register
676
 *
681
 *
677
 * @info: atom card_info pointer
682
 * @info: atom card_info pointer
678
 * @reg: MC register offset
683
 * @reg: MC register offset
679
 * @val: value to write to the pll register
684
 * @val: value to write to the pll register
680
 *
685
 *
681
 * Provides a MC register accessor for the atom interpreter (r4xx+).
686
 * Provides a MC register accessor for the atom interpreter (r4xx+).
682
 */
687
 */
683
static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
688
static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
684
{
689
{
685
    struct radeon_device *rdev = info->dev->dev_private;
690
    struct radeon_device *rdev = info->dev->dev_private;
686
 
691
 
687
    rdev->mc_wreg(rdev, reg, val);
692
    rdev->mc_wreg(rdev, reg, val);
688
}
693
}
689
 
694
 
690
/**
695
/**
691
 * cail_reg_write - write MMIO register
696
 * cail_reg_write - write MMIO register
692
 *
697
 *
693
 * @info: atom card_info pointer
698
 * @info: atom card_info pointer
694
 * @reg: MMIO register offset
699
 * @reg: MMIO register offset
695
 * @val: value to write to the pll register
700
 * @val: value to write to the pll register
696
 *
701
 *
697
 * Provides a MMIO register accessor for the atom interpreter (r4xx+).
702
 * Provides a MMIO register accessor for the atom interpreter (r4xx+).
698
 */
703
 */
699
static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
704
static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
700
{
705
{
701
    struct radeon_device *rdev = info->dev->dev_private;
706
    struct radeon_device *rdev = info->dev->dev_private;
702
 
707
 
703
    WREG32(reg*4, val);
708
    WREG32(reg*4, val);
704
}
709
}
705
 
710
 
706
/**
711
/**
707
 * cail_reg_read - read MMIO register
712
 * cail_reg_read - read MMIO register
708
 *
713
 *
709
 * @info: atom card_info pointer
714
 * @info: atom card_info pointer
710
 * @reg: MMIO register offset
715
 * @reg: MMIO register offset
711
 *
716
 *
712
 * Provides an MMIO register accessor for the atom interpreter (r4xx+).
717
 * Provides an MMIO register accessor for the atom interpreter (r4xx+).
713
 * Returns the value of the MMIO register.
718
 * Returns the value of the MMIO register.
714
 */
719
 */
715
static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
720
static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
716
{
721
{
717
    struct radeon_device *rdev = info->dev->dev_private;
722
    struct radeon_device *rdev = info->dev->dev_private;
718
    uint32_t r;
723
    uint32_t r;
719
 
724
 
720
    r = RREG32(reg*4);
725
    r = RREG32(reg*4);
721
    return r;
726
    return r;
722
}
727
}
723
 
728
 
724
/**
729
/**
725
 * cail_ioreg_write - write IO register
730
 * cail_ioreg_write - write IO register
726
 *
731
 *
727
 * @info: atom card_info pointer
732
 * @info: atom card_info pointer
728
 * @reg: IO register offset
733
 * @reg: IO register offset
729
 * @val: value to write to the pll register
734
 * @val: value to write to the pll register
730
 *
735
 *
731
 * Provides a IO register accessor for the atom interpreter (r4xx+).
736
 * Provides a IO register accessor for the atom interpreter (r4xx+).
732
 */
737
 */
733
static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
738
static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
734
{
739
{
735
	struct radeon_device *rdev = info->dev->dev_private;
740
	struct radeon_device *rdev = info->dev->dev_private;
736
 
741
 
737
	WREG32_IO(reg*4, val);
742
	WREG32_IO(reg*4, val);
738
}
743
}
739
 
744
 
740
/**
745
/**
741
 * cail_ioreg_read - read IO register
746
 * cail_ioreg_read - read IO register
742
 *
747
 *
743
 * @info: atom card_info pointer
748
 * @info: atom card_info pointer
744
 * @reg: IO register offset
749
 * @reg: IO register offset
745
 *
750
 *
746
 * Provides an IO register accessor for the atom interpreter (r4xx+).
751
 * Provides an IO register accessor for the atom interpreter (r4xx+).
747
 * Returns the value of the IO register.
752
 * Returns the value of the IO register.
748
 */
753
 */
749
static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
754
static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
750
{
755
{
751
	struct radeon_device *rdev = info->dev->dev_private;
756
	struct radeon_device *rdev = info->dev->dev_private;
752
	uint32_t r;
757
	uint32_t r;
753
 
758
 
754
	r = RREG32_IO(reg*4);
759
	r = RREG32_IO(reg*4);
755
	return r;
760
	return r;
756
}
761
}
757
 
762
 
758
/**
763
/**
759
 * radeon_atombios_init - init the driver info and callbacks for atombios
764
 * radeon_atombios_init - init the driver info and callbacks for atombios
760
 *
765
 *
761
 * @rdev: radeon_device pointer
766
 * @rdev: radeon_device pointer
762
 *
767
 *
763
 * Initializes the driver info and register access callbacks for the
768
 * Initializes the driver info and register access callbacks for the
764
 * ATOM interpreter (r4xx+).
769
 * ATOM interpreter (r4xx+).
765
 * Returns 0 on sucess, -ENOMEM on failure.
770
 * Returns 0 on sucess, -ENOMEM on failure.
766
 * Called at driver startup.
771
 * Called at driver startup.
767
 */
772
 */
768
int radeon_atombios_init(struct radeon_device *rdev)
773
int radeon_atombios_init(struct radeon_device *rdev)
769
{
774
{
770
	struct card_info *atom_card_info =
775
	struct card_info *atom_card_info =
771
	    kzalloc(sizeof(struct card_info), GFP_KERNEL);
776
	    kzalloc(sizeof(struct card_info), GFP_KERNEL);
772
 
777
 
773
	if (!atom_card_info)
778
	if (!atom_card_info)
774
		return -ENOMEM;
779
		return -ENOMEM;
775
 
780
 
776
	rdev->mode_info.atom_card_info = atom_card_info;
781
	rdev->mode_info.atom_card_info = atom_card_info;
777
	atom_card_info->dev = rdev->ddev;
782
	atom_card_info->dev = rdev->ddev;
778
	atom_card_info->reg_read = cail_reg_read;
783
	atom_card_info->reg_read = cail_reg_read;
779
	atom_card_info->reg_write = cail_reg_write;
784
	atom_card_info->reg_write = cail_reg_write;
780
	/* needed for iio ops */
785
	/* needed for iio ops */
781
	if (rdev->rio_mem) {
786
	if (rdev->rio_mem) {
782
		atom_card_info->ioreg_read = cail_ioreg_read;
787
		atom_card_info->ioreg_read = cail_ioreg_read;
783
		atom_card_info->ioreg_write = cail_ioreg_write;
788
		atom_card_info->ioreg_write = cail_ioreg_write;
784
	} else {
789
	} else {
785
		DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n");
790
		DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n");
786
		atom_card_info->ioreg_read = cail_reg_read;
791
		atom_card_info->ioreg_read = cail_reg_read;
787
		atom_card_info->ioreg_write = cail_reg_write;
792
		atom_card_info->ioreg_write = cail_reg_write;
788
	}
793
	}
789
	atom_card_info->mc_read = cail_mc_read;
794
	atom_card_info->mc_read = cail_mc_read;
790
	atom_card_info->mc_write = cail_mc_write;
795
	atom_card_info->mc_write = cail_mc_write;
791
	atom_card_info->pll_read = cail_pll_read;
796
	atom_card_info->pll_read = cail_pll_read;
792
	atom_card_info->pll_write = cail_pll_write;
797
	atom_card_info->pll_write = cail_pll_write;
793
 
798
 
794
	rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
799
	rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
795
	mutex_init(&rdev->mode_info.atom_context->mutex);
800
	mutex_init(&rdev->mode_info.atom_context->mutex);
796
    radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
801
    radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
797
	atom_allocate_fb_scratch(rdev->mode_info.atom_context);
802
	atom_allocate_fb_scratch(rdev->mode_info.atom_context);
798
    return 0;
803
    return 0;
799
}
804
}
800
 
805
 
801
/**
806
/**
802
 * radeon_atombios_fini - free the driver info and callbacks for atombios
807
 * radeon_atombios_fini - free the driver info and callbacks for atombios
803
 *
808
 *
804
 * @rdev: radeon_device pointer
809
 * @rdev: radeon_device pointer
805
 *
810
 *
806
 * Frees the driver info and register access callbacks for the ATOM
811
 * Frees the driver info and register access callbacks for the ATOM
807
 * interpreter (r4xx+).
812
 * interpreter (r4xx+).
808
 * Called at driver shutdown.
813
 * Called at driver shutdown.
809
 */
814
 */
810
void radeon_atombios_fini(struct radeon_device *rdev)
815
void radeon_atombios_fini(struct radeon_device *rdev)
811
{
816
{
812
	if (rdev->mode_info.atom_context) {
817
	if (rdev->mode_info.atom_context) {
813
		kfree(rdev->mode_info.atom_context->scratch);
818
		kfree(rdev->mode_info.atom_context->scratch);
814
	kfree(rdev->mode_info.atom_context);
819
	kfree(rdev->mode_info.atom_context);
815
	}
820
	}
816
	kfree(rdev->mode_info.atom_card_info);
821
	kfree(rdev->mode_info.atom_card_info);
817
}
822
}
818
 
823
 
819
/* COMBIOS */
824
/* COMBIOS */
820
/*
825
/*
821
 * COMBIOS is the bios format prior to ATOM. It provides
826
 * COMBIOS is the bios format prior to ATOM. It provides
822
 * command tables similar to ATOM, but doesn't have a unified
827
 * command tables similar to ATOM, but doesn't have a unified
823
 * parser.  See radeon_combios.c
828
 * parser.  See radeon_combios.c
824
 */
829
 */
825
 
830
 
826
/**
831
/**
827
 * radeon_combios_init - init the driver info for combios
832
 * radeon_combios_init - init the driver info for combios
828
 *
833
 *
829
 * @rdev: radeon_device pointer
834
 * @rdev: radeon_device pointer
830
 *
835
 *
831
 * Initializes the driver info for combios (r1xx-r3xx).
836
 * Initializes the driver info for combios (r1xx-r3xx).
832
 * Returns 0 on sucess.
837
 * Returns 0 on sucess.
833
 * Called at driver startup.
838
 * Called at driver startup.
834
 */
839
 */
835
int radeon_combios_init(struct radeon_device *rdev)
840
int radeon_combios_init(struct radeon_device *rdev)
836
{
841
{
837
	radeon_combios_initialize_bios_scratch_regs(rdev->ddev);
842
	radeon_combios_initialize_bios_scratch_regs(rdev->ddev);
838
	return 0;
843
	return 0;
839
}
844
}
840
 
845
 
841
/**
846
/**
842
 * radeon_combios_fini - free the driver info for combios
847
 * radeon_combios_fini - free the driver info for combios
843
 *
848
 *
844
 * @rdev: radeon_device pointer
849
 * @rdev: radeon_device pointer
845
 *
850
 *
846
 * Frees the driver info for combios (r1xx-r3xx).
851
 * Frees the driver info for combios (r1xx-r3xx).
847
 * Called at driver shutdown.
852
 * Called at driver shutdown.
848
 */
853
 */
849
void radeon_combios_fini(struct radeon_device *rdev)
854
void radeon_combios_fini(struct radeon_device *rdev)
850
{
855
{
851
}
856
}
852
 
857
 
853
/* if we get transitioned to only one device, take VGA back */
858
/* if we get transitioned to only one device, take VGA back */
854
/**
859
/**
855
 * radeon_vga_set_decode - enable/disable vga decode
860
 * radeon_vga_set_decode - enable/disable vga decode
856
 *
861
 *
857
 * @cookie: radeon_device pointer
862
 * @cookie: radeon_device pointer
858
 * @state: enable/disable vga decode
863
 * @state: enable/disable vga decode
859
 *
864
 *
860
 * Enable/disable vga decode (all asics).
865
 * Enable/disable vga decode (all asics).
861
 * Returns VGA resource flags.
866
 * Returns VGA resource flags.
862
 */
867
 */
863
static unsigned int radeon_vga_set_decode(void *cookie, bool state)
868
static unsigned int radeon_vga_set_decode(void *cookie, bool state)
864
{
869
{
865
	struct radeon_device *rdev = cookie;
870
	struct radeon_device *rdev = cookie;
866
	radeon_vga_set_state(rdev, state);
871
	radeon_vga_set_state(rdev, state);
867
	if (state)
872
	if (state)
868
		return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
873
		return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
869
		       VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
874
		       VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
870
	else
875
	else
871
		return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
876
		return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
872
}
877
}
873
 
878
 
874
/**
879
/**
875
 * radeon_check_pot_argument - check that argument is a power of two
880
 * radeon_check_pot_argument - check that argument is a power of two
876
 *
881
 *
877
 * @arg: value to check
882
 * @arg: value to check
878
 *
883
 *
879
 * Validates that a certain argument is a power of two (all asics).
884
 * Validates that a certain argument is a power of two (all asics).
880
 * Returns true if argument is valid.
885
 * Returns true if argument is valid.
881
 */
886
 */
882
static bool radeon_check_pot_argument(int arg)
887
static bool radeon_check_pot_argument(int arg)
883
{
888
{
884
	return (arg & (arg - 1)) == 0;
889
	return (arg & (arg - 1)) == 0;
885
}
890
}
886
 
891
 
887
/**
892
/**
888
 * radeon_check_arguments - validate module params
893
 * radeon_check_arguments - validate module params
889
 *
894
 *
890
 * @rdev: radeon_device pointer
895
 * @rdev: radeon_device pointer
891
 *
896
 *
892
 * Validates certain module parameters and updates
897
 * Validates certain module parameters and updates
893
 * the associated values used by the driver (all asics).
898
 * the associated values used by the driver (all asics).
894
 */
899
 */
895
static void radeon_check_arguments(struct radeon_device *rdev)
900
static void radeon_check_arguments(struct radeon_device *rdev)
896
{
901
{
897
	/* vramlimit must be a power of two */
902
	/* vramlimit must be a power of two */
898
	if (!radeon_check_pot_argument(radeon_vram_limit)) {
903
	if (!radeon_check_pot_argument(radeon_vram_limit)) {
899
		dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n",
904
		dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n",
900
				radeon_vram_limit);
905
				radeon_vram_limit);
901
		radeon_vram_limit = 0;
906
		radeon_vram_limit = 0;
902
	}
907
	}
903
 
908
 
904
	/* gtt size must be power of two and greater or equal to 32M */
909
	/* gtt size must be power of two and greater or equal to 32M */
905
	if (radeon_gart_size < 32) {
910
	if (radeon_gart_size < 32) {
906
		dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n",
911
		dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n",
907
				radeon_gart_size);
912
				radeon_gart_size);
908
		radeon_gart_size = 512;
913
		radeon_gart_size = 512;
909
 
914
 
910
	} else if (!radeon_check_pot_argument(radeon_gart_size)) {
915
	} else if (!radeon_check_pot_argument(radeon_gart_size)) {
911
		dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n",
916
		dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n",
912
				radeon_gart_size);
917
				radeon_gart_size);
913
		radeon_gart_size = 512;
918
		radeon_gart_size = 512;
914
	}
919
	}
915
	rdev->mc.gtt_size = (uint64_t)radeon_gart_size << 20;
920
	rdev->mc.gtt_size = (uint64_t)radeon_gart_size << 20;
916
 
921
 
917
	/* AGP mode can only be -1, 1, 2, 4, 8 */
922
	/* AGP mode can only be -1, 1, 2, 4, 8 */
918
	switch (radeon_agpmode) {
923
	switch (radeon_agpmode) {
919
	case -1:
924
	case -1:
920
	case 0:
925
	case 0:
921
	case 1:
926
	case 1:
922
	case 2:
927
	case 2:
923
	case 4:
928
	case 4:
924
	case 8:
929
	case 8:
925
		break;
930
		break;
926
	default:
931
	default:
927
		dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: "
932
		dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: "
928
				"-1, 0, 1, 2, 4, 8)\n", radeon_agpmode);
933
				"-1, 0, 1, 2, 4, 8)\n", radeon_agpmode);
929
		radeon_agpmode = 0;
934
		radeon_agpmode = 0;
930
		break;
935
		break;
931
	}
936
	}
932
}
937
}
933
 
938
 
934
int radeon_device_init(struct radeon_device *rdev,
939
int radeon_device_init(struct radeon_device *rdev,
935
               struct drm_device *ddev,
940
               struct drm_device *ddev,
936
               struct pci_dev *pdev,
941
               struct pci_dev *pdev,
937
               uint32_t flags)
942
               uint32_t flags)
938
{
943
{
939
	int r, i;
944
	int r, i;
940
	int dma_bits;
945
	int dma_bits;
941
 
946
 
942
    rdev->shutdown = false;
947
    rdev->shutdown = false;
943
    rdev->ddev = ddev;
948
    rdev->ddev = ddev;
944
    rdev->pdev = pdev;
949
    rdev->pdev = pdev;
945
    rdev->flags = flags;
950
    rdev->flags = flags;
946
    rdev->family = flags & RADEON_FAMILY_MASK;
951
    rdev->family = flags & RADEON_FAMILY_MASK;
947
    rdev->is_atom_bios = false;
952
    rdev->is_atom_bios = false;
948
    rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT;
953
    rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT;
949
    rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
954
    rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
950
	rdev->accel_working = false;
955
	rdev->accel_working = false;
951
	/* set up ring ids */
956
	/* set up ring ids */
952
	for (i = 0; i < RADEON_NUM_RINGS; i++) {
957
	for (i = 0; i < RADEON_NUM_RINGS; i++) {
953
		rdev->ring[i].idx = i;
958
		rdev->ring[i].idx = i;
954
	}
959
	}
955
 
960
 
956
	DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n",
961
	DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n",
957
		radeon_family_name[rdev->family], pdev->vendor, pdev->device,
962
		radeon_family_name[rdev->family], pdev->vendor, pdev->device,
958
		pdev->subsystem_vendor, pdev->subsystem_device);
963
		pdev->subsystem_vendor, pdev->subsystem_device);
959
 
964
 
960
    /* mutex initialization are all done here so we
965
    /* mutex initialization are all done here so we
961
     * can recall function without having locking issues */
966
     * can recall function without having locking issues */
962
	mutex_init(&rdev->ring_lock);
967
	mutex_init(&rdev->ring_lock);
963
	mutex_init(&rdev->dc_hw_i2c_mutex);
968
	mutex_init(&rdev->dc_hw_i2c_mutex);
964
	atomic_set(&rdev->ih.lock, 0);
969
	atomic_set(&rdev->ih.lock, 0);
965
	mutex_init(&rdev->gem.mutex);
970
	mutex_init(&rdev->gem.mutex);
966
	mutex_init(&rdev->pm.mutex);
971
	mutex_init(&rdev->pm.mutex);
967
	mutex_init(&rdev->gpu_clock_mutex);
972
	mutex_init(&rdev->gpu_clock_mutex);
968
	init_rwsem(&rdev->pm.mclk_lock);
973
	init_rwsem(&rdev->pm.mclk_lock);
969
	init_rwsem(&rdev->exclusive_lock);
974
	init_rwsem(&rdev->exclusive_lock);
970
	init_waitqueue_head(&rdev->irq.vblank_queue);
975
	init_waitqueue_head(&rdev->irq.vblank_queue);
971
	r = radeon_gem_init(rdev);
976
	r = radeon_gem_init(rdev);
972
	if (r)
977
	if (r)
973
		return r;
978
		return r;
974
	/* initialize vm here */
979
	/* initialize vm here */
975
	mutex_init(&rdev->vm_manager.lock);
980
	mutex_init(&rdev->vm_manager.lock);
976
	/* Adjust VM size here.
981
	/* Adjust VM size here.
977
	 * Currently set to 4GB ((1 << 20) 4k pages).
982
	 * Currently set to 4GB ((1 << 20) 4k pages).
978
	 * Max GPUVM size for cayman and SI is 40 bits.
983
	 * Max GPUVM size for cayman and SI is 40 bits.
979
	 */
984
	 */
980
	rdev->vm_manager.max_pfn = 1 << 20;
985
	rdev->vm_manager.max_pfn = 1 << 20;
981
	INIT_LIST_HEAD(&rdev->vm_manager.lru_vm);
986
	INIT_LIST_HEAD(&rdev->vm_manager.lru_vm);
982
 
987
 
983
	/* Set asic functions */
988
	/* Set asic functions */
984
	r = radeon_asic_init(rdev);
989
	r = radeon_asic_init(rdev);
985
	if (r)
990
	if (r)
986
		return r;
991
		return r;
987
	radeon_check_arguments(rdev);
992
	radeon_check_arguments(rdev);
988
 
993
 
989
	/* all of the newer IGP chips have an internal gart
994
	/* all of the newer IGP chips have an internal gart
990
	 * However some rs4xx report as AGP, so remove that here.
995
	 * However some rs4xx report as AGP, so remove that here.
991
	 */
996
	 */
992
	if ((rdev->family >= CHIP_RS400) &&
997
	if ((rdev->family >= CHIP_RS400) &&
993
	    (rdev->flags & RADEON_IS_IGP)) {
998
	    (rdev->flags & RADEON_IS_IGP)) {
994
		rdev->flags &= ~RADEON_IS_AGP;
999
		rdev->flags &= ~RADEON_IS_AGP;
995
	}
1000
	}
996
 
1001
 
997
	if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) {
1002
	if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) {
998
		radeon_agp_disable(rdev);
1003
		radeon_agp_disable(rdev);
999
    }
1004
    }
1000
 
1005
 
1001
	/* set DMA mask + need_dma32 flags.
1006
	/* set DMA mask + need_dma32 flags.
1002
	 * PCIE - can handle 40-bits.
1007
	 * PCIE - can handle 40-bits.
1003
	 * IGP - can handle 40-bits
1008
	 * IGP - can handle 40-bits
1004
	 * AGP - generally dma32 is safest
1009
	 * AGP - generally dma32 is safest
1005
	 * PCI - dma32 for legacy pci gart, 40 bits on newer asics
1010
	 * PCI - dma32 for legacy pci gart, 40 bits on newer asics
1006
	 */
1011
	 */
1007
	rdev->need_dma32 = false;
1012
	rdev->need_dma32 = false;
1008
	if (rdev->flags & RADEON_IS_AGP)
1013
	if (rdev->flags & RADEON_IS_AGP)
1009
		rdev->need_dma32 = true;
1014
		rdev->need_dma32 = true;
1010
	if ((rdev->flags & RADEON_IS_PCI) &&
1015
	if ((rdev->flags & RADEON_IS_PCI) &&
1011
	    (rdev->family <= CHIP_RS740))
1016
	    (rdev->family <= CHIP_RS740))
1012
		rdev->need_dma32 = true;
1017
		rdev->need_dma32 = true;
1013
 
1018
 
1014
	dma_bits = rdev->need_dma32 ? 32 : 40;
1019
	dma_bits = rdev->need_dma32 ? 32 : 40;
1015
	r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
1020
	r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
1016
    if (r) {
1021
    if (r) {
1017
		rdev->need_dma32 = true;
1022
		rdev->need_dma32 = true;
1018
		dma_bits = 32;
1023
		dma_bits = 32;
1019
        printk(KERN_WARNING "radeon: No suitable DMA available.\n");
1024
        printk(KERN_WARNING "radeon: No suitable DMA available.\n");
1020
    }
1025
    }
1021
 
1026
 
1022
    /* Registers mapping */
1027
    /* Registers mapping */
1023
    /* TODO: block userspace mapping of io register */
1028
    /* TODO: block userspace mapping of io register */
1024
    rdev->rmmio_base = pci_resource_start(rdev->pdev, 2);
1029
    rdev->rmmio_base = pci_resource_start(rdev->pdev, 2);
1025
    rdev->rmmio_size = pci_resource_len(rdev->pdev, 2);
1030
    rdev->rmmio_size = pci_resource_len(rdev->pdev, 2);
1026
	rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size);
1031
	rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size);
1027
    if (rdev->rmmio == NULL) {
1032
    if (rdev->rmmio == NULL) {
1028
        return -ENOMEM;
1033
        return -ENOMEM;
1029
    }
1034
    }
1030
    DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base);
1035
    DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base);
1031
    DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size);
1036
    DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size);
1032
 
1037
 
1033
	/* io port mapping */
1038
	/* io port mapping */
1034
	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
1039
	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
1035
		if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) {
1040
		if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) {
1036
			rdev->rio_mem_size = pci_resource_len(rdev->pdev, i);
1041
			rdev->rio_mem_size = pci_resource_len(rdev->pdev, i);
1037
			rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size);
1042
			rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size);
1038
			break;
1043
			break;
1039
		}
1044
		}
1040
	}
1045
	}
1041
	if (rdev->rio_mem == NULL)
1046
	if (rdev->rio_mem == NULL)
1042
		DRM_ERROR("Unable to find PCI I/O BAR\n");
1047
		DRM_ERROR("Unable to find PCI I/O BAR\n");
1043
 
1048
 
1044
 
1049
 
1045
	r = radeon_init(rdev);
1050
	r = radeon_init(rdev);
1046
	if (r)
1051
	if (r)
1047
        return r;
1052
        return r;
1048
 
1053
 
1049
	if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) {
1054
	if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) {
1050
		/* Acceleration not working on AGP card try again
1055
		/* Acceleration not working on AGP card try again
1051
		 * with fallback to PCI or PCIE GART
1056
		 * with fallback to PCI or PCIE GART
1052
		 */
1057
		 */
1053
		radeon_asic_reset(rdev);
1058
		radeon_asic_reset(rdev);
1054
		radeon_fini(rdev);
1059
		radeon_fini(rdev);
1055
		radeon_agp_disable(rdev);
1060
		radeon_agp_disable(rdev);
1056
		r = radeon_init(rdev);
1061
		r = radeon_init(rdev);
1057
		if (r)
1062
		if (r)
1058
		return r;
1063
		return r;
1059
	}
1064
	}
1060
//	if (radeon_testing) {
1065
//	if (radeon_testing) {
1061
//		radeon_test_moves(rdev);
1066
//		radeon_test_moves(rdev);
1062
//    }
1067
//    }
1063
//	if ((radeon_testing & 2)) {
1068
//	if ((radeon_testing & 2)) {
1064
//		radeon_test_syncing(rdev);
1069
//		radeon_test_syncing(rdev);
1065
//	}
1070
//	}
1066
   if (radeon_benchmarking) {
1071
   if (radeon_benchmarking) {
1067
		radeon_benchmark(rdev, radeon_benchmarking);
1072
		radeon_benchmark(rdev, radeon_benchmarking);
1068
    }
1073
    }
1069
	return 0;
1074
	return 0;
1070
}
1075
}
1071
 
1076
 
1072
/**
1077
/**
1073
 * radeon_gpu_reset - reset the asic
1078
 * radeon_gpu_reset - reset the asic
1074
 *
1079
 *
1075
 * @rdev: radeon device pointer
1080
 * @rdev: radeon device pointer
1076
 *
1081
 *
1077
 * Attempt the reset the GPU if it has hung (all asics).
1082
 * Attempt the reset the GPU if it has hung (all asics).
1078
 * Returns 0 for success or an error on failure.
1083
 * Returns 0 for success or an error on failure.
1079
 */
1084
 */
1080
int radeon_gpu_reset(struct radeon_device *rdev)
1085
int radeon_gpu_reset(struct radeon_device *rdev)
1081
{
1086
{
1082
    unsigned ring_sizes[RADEON_NUM_RINGS];
1087
    unsigned ring_sizes[RADEON_NUM_RINGS];
1083
    uint32_t *ring_data[RADEON_NUM_RINGS];
1088
    uint32_t *ring_data[RADEON_NUM_RINGS];
1084
 
1089
 
1085
    bool saved = false;
1090
    bool saved = false;
1086
 
1091
 
1087
    int i, r;
1092
    int i, r;
1088
    int resched;
1093
    int resched;
1089
 
1094
 
1090
//    down_write(&rdev->exclusive_lock);
1095
//    down_write(&rdev->exclusive_lock);
1091
    radeon_save_bios_scratch_regs(rdev);
1096
    radeon_save_bios_scratch_regs(rdev);
1092
    /* block TTM */
1097
    /* block TTM */
1093
//    resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev);
1098
//    resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev);
1094
    radeon_suspend(rdev);
1099
    radeon_suspend(rdev);
1095
 
1100
 
1096
    for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1101
    for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1097
        ring_sizes[i] = radeon_ring_backup(rdev, &rdev->ring[i],
1102
        ring_sizes[i] = radeon_ring_backup(rdev, &rdev->ring[i],
1098
                           &ring_data[i]);
1103
                           &ring_data[i]);
1099
        if (ring_sizes[i]) {
1104
        if (ring_sizes[i]) {
1100
            saved = true;
1105
            saved = true;
1101
            dev_info(rdev->dev, "Saved %d dwords of commands "
1106
            dev_info(rdev->dev, "Saved %d dwords of commands "
1102
                 "on ring %d.\n", ring_sizes[i], i);
1107
                 "on ring %d.\n", ring_sizes[i], i);
1103
        }
1108
        }
1104
    }
1109
    }
1105
 
1110
 
1106
retry:
1111
retry:
1107
    r = radeon_asic_reset(rdev);
1112
    r = radeon_asic_reset(rdev);
1108
    if (!r) {
1113
    if (!r) {
1109
        dev_info(rdev->dev, "GPU reset succeeded, trying to resume\n");
1114
        dev_info(rdev->dev, "GPU reset succeeded, trying to resume\n");
1110
        radeon_resume(rdev);
1115
        radeon_resume(rdev);
1111
    }
1116
    }
1112
 
1117
 
1113
    radeon_restore_bios_scratch_regs(rdev);
1118
    radeon_restore_bios_scratch_regs(rdev);
1114
    drm_helper_resume_force_mode(rdev->ddev);
1119
    drm_helper_resume_force_mode(rdev->ddev);
1115
 
1120
 
1116
    if (!r) {
1121
    if (!r) {
1117
        for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1122
        for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1118
            radeon_ring_restore(rdev, &rdev->ring[i],
1123
            radeon_ring_restore(rdev, &rdev->ring[i],
1119
                        ring_sizes[i], ring_data[i]);
1124
                        ring_sizes[i], ring_data[i]);
1120
            ring_sizes[i] = 0;
1125
            ring_sizes[i] = 0;
1121
            ring_data[i] = NULL;
1126
            ring_data[i] = NULL;
1122
        }
1127
        }
1123
 
1128
 
1124
        r = radeon_ib_ring_tests(rdev);
1129
        r = radeon_ib_ring_tests(rdev);
1125
        if (r) {
1130
        if (r) {
1126
            dev_err(rdev->dev, "ib ring test failed (%d).\n", r);
1131
            dev_err(rdev->dev, "ib ring test failed (%d).\n", r);
1127
            if (saved) {
1132
            if (saved) {
1128
                saved = false;
1133
                saved = false;
1129
                radeon_suspend(rdev);
1134
                radeon_suspend(rdev);
1130
                goto retry;
1135
                goto retry;
1131
            }
1136
            }
1132
        }
1137
        }
1133
    } else {
1138
    } else {
1134
        for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1139
        for (i = 0; i < RADEON_NUM_RINGS; ++i) {
1135
            kfree(ring_data[i]);
1140
            kfree(ring_data[i]);
1136
        }
1141
        }
1137
    }
1142
    }
1138
 
1143
 
1139
//    ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched);
1144
//    ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched);
1140
    if (r) {
1145
    if (r) {
1141
        /* bad news, how to tell it to userspace ? */
1146
        /* bad news, how to tell it to userspace ? */
1142
        dev_info(rdev->dev, "GPU reset failed\n");
1147
        dev_info(rdev->dev, "GPU reset failed\n");
1143
    }
1148
    }
1144
 
1149
 
1145
//    up_write(&rdev->exclusive_lock);
1150
//    up_write(&rdev->exclusive_lock);
1146
    return r;
1151
    return r;
1147
}
1152
}
1148
 
1153
 
1149
 
1154
 
1150
 
1155
 
1151
/*
1156
/*
1152
 * Driver load/unload
1157
 * Driver load/unload
1153
 */
1158
 */
1154
int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
1159
int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
1155
{
1160
{
1156
    struct radeon_device *rdev;
1161
    struct radeon_device *rdev;
1157
    int r;
1162
    int r;
1158
 
1163
 
1159
    ENTER();
1164
    ENTER();
1160
 
1165
 
1161
    rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
1166
    rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
1162
    if (rdev == NULL) {
1167
    if (rdev == NULL) {
1163
        return -ENOMEM;
1168
        return -ENOMEM;
1164
    };
1169
    };
1165
 
1170
 
1166
    dev->dev_private = (void *)rdev;
1171
    dev->dev_private = (void *)rdev;
1167
 
1172
 
1168
    /* update BUS flag */
1173
    /* update BUS flag */
1169
    if (drm_device_is_agp(dev)) {
1174
    if (drm_device_is_agp(dev)) {
1170
        flags |= RADEON_IS_AGP;
1175
        flags |= RADEON_IS_AGP;
1171
    } else if (drm_device_is_pcie(dev)) {
1176
    } else if (drm_device_is_pcie(dev)) {
1172
        flags |= RADEON_IS_PCIE;
1177
        flags |= RADEON_IS_PCIE;
1173
    } else {
1178
    } else {
1174
        flags |= RADEON_IS_PCI;
1179
        flags |= RADEON_IS_PCI;
1175
    }
1180
    }
1176
 
1181
 
1177
    /* radeon_device_init should report only fatal error
1182
    /* radeon_device_init should report only fatal error
1178
     * like memory allocation failure or iomapping failure,
1183
     * like memory allocation failure or iomapping failure,
1179
     * or memory manager initialization failure, it must
1184
     * or memory manager initialization failure, it must
1180
     * properly initialize the GPU MC controller and permit
1185
     * properly initialize the GPU MC controller and permit
1181
     * VRAM allocation
1186
     * VRAM allocation
1182
     */
1187
     */
1183
    r = radeon_device_init(rdev, dev, dev->pdev, flags);
1188
    r = radeon_device_init(rdev, dev, dev->pdev, flags);
1184
    if (r) {
1189
    if (r) {
1185
        DRM_ERROR("Fatal error while trying to initialize radeon.\n");
1190
        DRM_ERROR("Fatal error while trying to initialize radeon.\n");
1186
        return r;
1191
        return r;
1187
    }
1192
    }
1188
    /* Again modeset_init should fail only on fatal error
1193
    /* Again modeset_init should fail only on fatal error
1189
     * otherwise it should provide enough functionalities
1194
     * otherwise it should provide enough functionalities
1190
     * for shadowfb to run
1195
     * for shadowfb to run
1191
     */
1196
     */
1192
    if( radeon_modeset )
1197
    if( radeon_modeset )
1193
    {
1198
    {
1194
        r = radeon_modeset_init(rdev);
1199
        r = radeon_modeset_init(rdev);
1195
        if (r) {
1200
        if (r) {
1196
            return r;
1201
            return r;
1197
        }
1202
        }
1198
    };
1203
    };
1199
    return 0;
1204
    return 0;
1200
}
1205
}
1201
 
1206
 
1202
videomode_t usermode;
1207
videomode_t usermode;
1203
 
1208
 
1204
 
1209
 
1205
int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
1210
int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
1206
{
1211
{
1207
    static struct drm_device *dev;
1212
    static struct drm_device *dev;
1208
    int ret;
1213
    int ret;
1209
 
1214
 
1210
    ENTER();
1215
    ENTER();
1211
 
1216
 
1212
    dev = kzalloc(sizeof(*dev), 0);
1217
    dev = kzalloc(sizeof(*dev), 0);
1213
    if (!dev)
1218
    if (!dev)
1214
        return -ENOMEM;
1219
        return -ENOMEM;
1215
 
1220
 
1216
 //   ret = pci_enable_device(pdev);
1221
 //   ret = pci_enable_device(pdev);
1217
 //   if (ret)
1222
 //   if (ret)
1218
 //       goto err_g1;
1223
 //       goto err_g1;
1219
 
1224
 
1220
 //   pci_set_master(pdev);
1225
 //   pci_set_master(pdev);
1221
 
1226
 
1222
 //   if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
1227
 //   if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
1223
 //       printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
1228
 //       printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
1224
 //       goto err_g2;
1229
 //       goto err_g2;
1225
 //   }
1230
 //   }
1226
 
1231
 
1227
    dev->pdev = pdev;
1232
    dev->pdev = pdev;
1228
    dev->pci_device = pdev->device;
1233
    dev->pci_device = pdev->device;
1229
    dev->pci_vendor = pdev->vendor;
1234
    dev->pci_vendor = pdev->vendor;
1230
 
1235
 
1231
    INIT_LIST_HEAD(&dev->filelist);
1236
    INIT_LIST_HEAD(&dev->filelist);
1232
    INIT_LIST_HEAD(&dev->ctxlist);
1237
    INIT_LIST_HEAD(&dev->ctxlist);
1233
    INIT_LIST_HEAD(&dev->vmalist);
1238
    INIT_LIST_HEAD(&dev->vmalist);
1234
    INIT_LIST_HEAD(&dev->maplist);
1239
    INIT_LIST_HEAD(&dev->maplist);
1235
 
1240
 
1236
    spin_lock_init(&dev->count_lock);
1241
    spin_lock_init(&dev->count_lock);
1237
    mutex_init(&dev->struct_mutex);
1242
    mutex_init(&dev->struct_mutex);
1238
    mutex_init(&dev->ctxlist_mutex);
1243
    mutex_init(&dev->ctxlist_mutex);
1239
 
1244
 
1240
 
1245
 
1241
    ret = radeon_driver_load_kms(dev, ent->driver_data );
1246
    ret = radeon_driver_load_kms(dev, ent->driver_data );
1242
    if (ret)
1247
    if (ret)
1243
        goto err_g4;
1248
        goto err_g4;
-
 
1249
 
-
 
1250
    main_drm_device = dev;
1244
 
1251
 
1245
    if( radeon_modeset )
1252
    if( radeon_modeset )
1246
        init_display_kms(dev->dev_private, &usermode);
1253
        init_display_kms(dev->dev_private, &usermode);
1247
    else
1254
    else
1248
        init_display(dev->dev_private, &usermode);
1255
        init_display(dev->dev_private, &usermode);
1249
 
1256
 
1250
 
1257
 
1251
    LEAVE();
1258
    LEAVE();
1252
 
1259
 
1253
    return 0;
1260
    return 0;
1254
 
1261
 
1255
err_g4:
1262
err_g4:
1256
//    drm_put_minor(&dev->primary);
1263
//    drm_put_minor(&dev->primary);
1257
//err_g3:
1264
//err_g3:
1258
//    if (drm_core_check_feature(dev, DRIVER_MODESET))
1265
//    if (drm_core_check_feature(dev, DRIVER_MODESET))
1259
//        drm_put_minor(&dev->control);
1266
//        drm_put_minor(&dev->control);
1260
//err_g2:
1267
//err_g2:
1261
//    pci_disable_device(pdev);
1268
//    pci_disable_device(pdev);
1262
//err_g1:
1269
//err_g1:
1263
    free(dev);
1270
    free(dev);
1264
 
1271
 
1265
    LEAVE();
1272
    LEAVE();
1266
 
1273
 
1267
    return ret;
1274
    return ret;
1268
}
1275
}
1269
 
1276
 
1270
resource_size_t drm_get_resource_start(struct drm_device *dev, unsigned int resource)
1277
resource_size_t drm_get_resource_start(struct drm_device *dev, unsigned int resource)
1271
{
1278
{
1272
    return pci_resource_start(dev->pdev, resource);
1279
    return pci_resource_start(dev->pdev, resource);
1273
}
1280
}
1274
 
1281
 
1275
resource_size_t drm_get_resource_len(struct drm_device *dev, unsigned int resource)
1282
resource_size_t drm_get_resource_len(struct drm_device *dev, unsigned int resource)
1276
{
1283
{
1277
    return pci_resource_len(dev->pdev, resource);
1284
    return pci_resource_len(dev->pdev, resource);
1278
}
1285
}
1279
 
1286
 
1280
 
1287
 
1281
uint32_t __div64_32(uint64_t *n, uint32_t base)
1288
uint32_t __div64_32(uint64_t *n, uint32_t base)
1282
{
1289
{
1283
        uint64_t rem = *n;
1290
        uint64_t rem = *n;
1284
        uint64_t b = base;
1291
        uint64_t b = base;
1285
        uint64_t res, d = 1;
1292
        uint64_t res, d = 1;
1286
        uint32_t high = rem >> 32;
1293
        uint32_t high = rem >> 32;
1287
 
1294
 
1288
        /* Reduce the thing a bit first */
1295
        /* Reduce the thing a bit first */
1289
        res = 0;
1296
        res = 0;
1290
        if (high >= base) {
1297
        if (high >= base) {
1291
                high /= base;
1298
                high /= base;
1292
                res = (uint64_t) high << 32;
1299
                res = (uint64_t) high << 32;
1293
                rem -= (uint64_t) (high*base) << 32;
1300
                rem -= (uint64_t) (high*base) << 32;
1294
        }
1301
        }
1295
 
1302
 
1296
        while ((int64_t)b > 0 && b < rem) {
1303
        while ((int64_t)b > 0 && b < rem) {
1297
                b = b+b;
1304
                b = b+b;
1298
                d = d+d;
1305
                d = d+d;
1299
        }
1306
        }
1300
 
1307
 
1301
        do {
1308
        do {
1302
                if (rem >= b) {
1309
                if (rem >= b) {
1303
                        rem -= b;
1310
                        rem -= b;
1304
                        res += d;
1311
                        res += d;
1305
                }
1312
                }
1306
                b >>= 1;
1313
                b >>= 1;
1307
                d >>= 1;
1314
                d >>= 1;
1308
        } while (d);
1315
        } while (d);
1309
 
1316
 
1310
        *n = res;
1317
        *n = res;
1311
        return rem;
1318
        return rem;
1312
}
1319
}
1313
 
1320
 
1314
 
1321
 
1315
static struct pci_device_id pciidlist[] = {
1322
static struct pci_device_id pciidlist[] = {
1316
    radeon_PCI_IDS
1323
    radeon_PCI_IDS
1317
};
1324
};
1318
 
1325
 
-
 
1326
 
-
 
1327
#define CURRENT_API     0x0200      /*      2.00     */
-
 
1328
#define COMPATIBLE_API  0x0100      /*      1.00     */
1319
 
1329
 
1320
#define API_VERSION     0x01000100
1330
#define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
1321
 
1331
 
1322
#define SRV_GETVERSION      0
1332
#define SRV_GETVERSION      0
1323
#define SRV_ENUM_MODES      1
1333
#define SRV_ENUM_MODES      1
1324
#define SRV_SET_MODE        2
1334
#define SRV_SET_MODE        2
-
 
1335
#define SRV_GET_CAPS            3
-
 
1336
 
-
 
1337
#define SRV_CREATE_SURFACE      10
-
 
1338
#define SRV_DESTROY_SURFACE     11
-
 
1339
#define SRV_LOCK_SURFACE        12
-
 
1340
#define SRV_UNLOCK_SURFACE      13
-
 
1341
#define SRV_RESIZE_SURFACE      14
-
 
1342
#define SRV_BLIT_BITMAP         15
-
 
1343
#define SRV_BLIT_TEXTURE        16
-
 
1344
#define SRV_BLIT_VIDEO          17
1325
 
-
 
1326
#define SRV_CREATE_VIDEO    9
-
 
1327
#define SRV_BLIT_VIDEO     10
-
 
1328
#define SRV_CREATE_BITMAP  11
1345
 
1329
 
1346
 
1330
 
1347
 
1331
int r600_video_blit(uint64_t src_offset, int  x, int y,
1348
int r600_video_blit(uint64_t src_offset, int  x, int y,
1332
                    int w, int h, int pitch);
1349
                    int w, int h, int pitch);
1333
 
1350
 
1334
#define check_input(size) \
1351
#define check_input(size) \
1335
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
1352
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
1336
        break;
1353
        break;
1337
 
1354
 
1338
#define check_output(size) \
1355
#define check_output(size) \
1339
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
1356
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
1340
        break;
1357
        break;
1341
 
1358
 
1342
int _stdcall display_handler(ioctl_t *io)
1359
int _stdcall display_handler(ioctl_t *io)
1343
{
1360
{
1344
    int    retval = -1;
1361
    int    retval = -1;
1345
    u32_t *inp;
1362
    u32_t *inp;
1346
    u32_t *outp;
1363
    u32_t *outp;
1347
 
1364
 
1348
    inp = io->input;
1365
    inp = io->input;
1349
    outp = io->output;
1366
    outp = io->output;
1350
 
1367
 
1351
    switch(io->io_code)
1368
    switch(io->io_code)
1352
    {
1369
    {
1353
        case SRV_GETVERSION:
1370
        case SRV_GETVERSION:
1354
            check_output(4);
1371
            check_output(4);
1355
            *outp  = API_VERSION;
1372
            *outp  = API_VERSION;
1356
            retval = 0;
1373
            retval = 0;
1357
            break;
1374
            break;
1358
 
1375
 
1359
        case SRV_ENUM_MODES:
1376
        case SRV_ENUM_MODES:
1360
            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
1377
            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
1361
                       inp, io->inp_size, io->out_size );
1378
                       inp, io->inp_size, io->out_size );
1362
            check_output(4);
1379
            check_output(4);
1363
            if( radeon_modeset)
1380
            if( radeon_modeset)
1364
                retval = get_modes((videomode_t*)inp, outp);
1381
                retval = get_modes((videomode_t*)inp, outp);
1365
            break;
1382
            break;
1366
 
1383
 
1367
        case SRV_SET_MODE:
1384
        case SRV_SET_MODE:
1368
            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
1385
            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
1369
                       inp, io->inp_size);
1386
                       inp, io->inp_size);
1370
            check_input(sizeof(videomode_t));
1387
            check_input(sizeof(videomode_t));
1371
            if( radeon_modeset )
1388
            if( radeon_modeset )
1372
                retval = set_user_mode((videomode_t*)inp);
1389
                retval = set_user_mode((videomode_t*)inp);
1373
            break;
1390
            break;
1374
 
1391
 
1375
        case SRV_CREATE_VIDEO:
1392
        case SRV_GET_CAPS:
1376
//            retval = r600_create_video(inp[0], inp[1], outp);
1393
            retval = get_driver_caps((hwcaps_t*)inp);
1377
            break;
1394
            break;
1378
 
-
 
1379
        case SRV_BLIT_VIDEO:
1395
 
1380
//            r600_video_blit( ((uint64_t*)inp)[0], inp[2], inp[3],
-
 
1381
//                    inp[4], inp[5], inp[6]);
1396
        case SRV_CREATE_SURFACE:
1382
 
1397
//            check_input(8);
1383
            retval = 0;
1398
            retval = create_surface(main_drm_device, (struct io_call_10*)inp);
1384
            break;
-
 
1385
 
-
 
1386
        case SRV_CREATE_BITMAP:
1399
            break;
1387
            check_input(8);
1400
 
-
 
1401
        case SRV_LOCK_SURFACE:
-
 
1402
            retval = lock_surface((struct io_call_12*)inp);
-
 
1403
            break;
-
 
1404
 
1388
            check_output(4);
1405
        case SRV_BLIT_BITMAP:
1389
//            retval = create_bitmap(outp, inp[0], inp[1]);
1406
            srv_blit_bitmap( inp[0], inp[1], inp[2],
1390
            break;
1407
                        inp[3], inp[4], inp[5], inp[6]);
1391
 
1408
 
1392
    };
1409
    };
1393
 
1410
 
1394
    return retval;
1411
    return retval;
1395
}
1412
}
1396
 
1413
 
1397
static char  log[256];
1414
static char  log[256];
1398
static pci_dev_t device;
1415
static pci_dev_t device;
1399
 
1416
 
1400
u32_t drvEntry(int action, char *cmdline)
1417
u32_t drvEntry(int action, char *cmdline)
1401
{
1418
{
1402
    struct radeon_device *rdev = NULL;
1419
    struct radeon_device *rdev = NULL;
1403
 
1420
 
1404
    const struct pci_device_id  *ent;
1421
    const struct pci_device_id  *ent;
1405
 
1422
 
1406
    int     err;
1423
    int     err;
1407
    u32_t   retval = 0;
1424
    u32_t   retval = 0;
1408
 
1425
 
1409
    if(action != 1)
1426
    if(action != 1)
1410
        return 0;
1427
        return 0;
1411
 
1428
 
1412
    if( GetService("DISPLAY") != 0 )
1429
    if( GetService("DISPLAY") != 0 )
1413
        return 0;
1430
        return 0;
1414
 
1431
 
1415
    if( cmdline && *cmdline )
1432
    if( cmdline && *cmdline )
1416
        parse_cmdline(cmdline, &usermode, log, &radeon_modeset);
1433
        parse_cmdline(cmdline, &usermode, log, &radeon_modeset);
1417
 
1434
 
1418
    if(!dbg_open(log))
1435
    if(!dbg_open(log))
1419
    {
1436
    {
1420
        strcpy(log, "/RD/1/DRIVERS/atikms.log");
1437
        strcpy(log, "/RD/1/DRIVERS/atikms.log");
1421
 
1438
 
1422
        if(!dbg_open(log))
1439
        if(!dbg_open(log))
1423
        {
1440
        {
1424
            printf("Can't open %s\nExit\n", log);
1441
            printf("Can't open %s\nExit\n", log);
1425
            return 0;
1442
            return 0;
1426
        };
1443
        };
1427
    }
1444
    }
1428
    dbgprintf("Radeon RC12 preview 1 cmdline %s\n", cmdline);
1445
    dbgprintf("Radeon RC12 preview 1 cmdline %s\n", cmdline);
1429
 
1446
 
1430
    enum_pci_devices();
1447
    enum_pci_devices();
1431
 
1448
 
1432
    ent = find_pci_device(&device, pciidlist);
1449
    ent = find_pci_device(&device, pciidlist);
1433
 
1450
 
1434
    if( unlikely(ent == NULL) )
1451
    if( unlikely(ent == NULL) )
1435
    {
1452
    {
1436
        dbgprintf("device not found\n");
1453
        dbgprintf("device not found\n");
1437
        return 0;
1454
        return 0;
1438
    };
1455
    };
1439
 
1456
 
1440
    dbgprintf("device %x:%x\n", device.pci_dev.vendor,
1457
    dbgprintf("device %x:%x\n", device.pci_dev.vendor,
1441
                                device.pci_dev.device);
1458
                                device.pci_dev.device);
1442
 
1459
 
1443
    err = drm_get_dev(&device.pci_dev, ent);
1460
    err = drm_get_dev(&device.pci_dev, ent);
1444
 
1461
 
1445
    rdev = rdisplay->ddev->dev_private;
1462
    rdev = rdisplay->ddev->dev_private;
1446
 
1463
 
1447
    err = RegService("DISPLAY", display_handler);
1464
    err = RegService("DISPLAY", display_handler);
1448
 
1465
 
1449
    if( err != 0)
1466
    if( err != 0)
1450
        dbgprintf("Set DISPLAY handler\n");
1467
        dbgprintf("Set DISPLAY handler\n");
1451
 
1468
 
1452
    return err;
1469
    return err;
1453
};
1470
};
1454
 
1471
 
1455
#define PCI_CLASS_REVISION      0x08
1472
#define PCI_CLASS_REVISION      0x08
1456
#define PCI_CLASS_DISPLAY_VGA   0x0300
1473
#define PCI_CLASS_DISPLAY_VGA   0x0300
1457
 
1474
 
1458
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
1475
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
1459
{
1476
{
1460
    u16_t vendor, device;
1477
    u16_t vendor, device;
1461
    u32_t class;
1478
    u32_t class;
1462
    int   ret = 0;
1479
    int   ret = 0;
1463
 
1480
 
1464
    vendor   = id & 0xffff;
1481
    vendor   = id & 0xffff;
1465
    device   = (id >> 16) & 0xffff;
1482
    device   = (id >> 16) & 0xffff;
1466
 
1483
 
1467
    if(vendor == 0x1002)
1484
    if(vendor == 0x1002)
1468
    {
1485
    {
1469
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
1486
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
1470
        class >>= 16;
1487
        class >>= 16;
1471
 
1488
 
1472
        if( class == PCI_CLASS_DISPLAY_VGA)
1489
        if( class == PCI_CLASS_DISPLAY_VGA)
1473
            ret = 1;
1490
            ret = 1;
1474
    }
1491
    }
1475
    return ret;
1492
    return ret;
1476
}
1493
}