Subversion Repositories Kolibri OS

Rev

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

Rev 2160 Rev 2175
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
#ifndef __RADEON_H__
28
#ifndef __RADEON_H__
29
#define __RADEON_H__
29
#define __RADEON_H__
30
 
30
 
31
/* TODO: Here are things that needs to be done :
31
/* TODO: Here are things that needs to be done :
32
 *	- surface allocator & initializer : (bit like scratch reg) should
32
 *	- surface allocator & initializer : (bit like scratch reg) should
33
 *	  initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
33
 *	  initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
34
 *	  related to surface
34
 *	  related to surface
35
 *	- WB : write back stuff (do it bit like scratch reg things)
35
 *	- WB : write back stuff (do it bit like scratch reg things)
36
 *	- Vblank : look at Jesse's rework and what we should do
36
 *	- Vblank : look at Jesse's rework and what we should do
37
 *	- r600/r700: gart & cp
37
 *	- r600/r700: gart & cp
38
 *	- cs : clean cs ioctl use bitmap & things like that.
38
 *	- cs : clean cs ioctl use bitmap & things like that.
39
 *	- power management stuff
39
 *	- power management stuff
40
 *	- Barrier in gart code
40
 *	- Barrier in gart code
41
 *	- Unmappabled vram ?
41
 *	- Unmappabled vram ?
42
 *	- TESTING, TESTING, TESTING
42
 *	- TESTING, TESTING, TESTING
43
 */
43
 */
44
 
44
 
45
/* Initialization path:
45
/* Initialization path:
46
 *  We expect that acceleration initialization might fail for various
46
 *  We expect that acceleration initialization might fail for various
47
 *  reasons even thought we work hard to make it works on most
47
 *  reasons even thought we work hard to make it works on most
48
 *  configurations. In order to still have a working userspace in such
48
 *  configurations. In order to still have a working userspace in such
49
 *  situation the init path must succeed up to the memory controller
49
 *  situation the init path must succeed up to the memory controller
50
 *  initialization point. Failure before this point are considered as
50
 *  initialization point. Failure before this point are considered as
51
 *  fatal error. Here is the init callchain :
51
 *  fatal error. Here is the init callchain :
52
 *      radeon_device_init  perform common structure, mutex initialization
52
 *      radeon_device_init  perform common structure, mutex initialization
53
 *      asic_init           setup the GPU memory layout and perform all
53
 *      asic_init           setup the GPU memory layout and perform all
54
 *                          one time initialization (failure in this
54
 *                          one time initialization (failure in this
55
 *                          function are considered fatal)
55
 *                          function are considered fatal)
56
 *      asic_startup        setup the GPU acceleration, in order to
56
 *      asic_startup        setup the GPU acceleration, in order to
57
 *                          follow guideline the first thing this
57
 *                          follow guideline the first thing this
58
 *                          function should do is setting the GPU
58
 *                          function should do is setting the GPU
59
 *                          memory controller (only MC setup failure
59
 *                          memory controller (only MC setup failure
60
 *                          are considered as fatal)
60
 *                          are considered as fatal)
61
 */
61
 */
62
 
62
 
63
#include 
63
#include 
64
 
64
 
65
#include 
65
#include 
66
#include 
66
#include 
67
 
67
 
68
#include 
68
#include 
69
#include 
69
#include 
70
#include 
70
#include 
71
#include 
71
#include 
72
 
72
 
73
#include 
73
#include 
74
#include 
74
#include 
75
 
75
 
76
#include 
76
#include 
77
#include "drm_edid.h"
77
#include "drm_edid.h"
78
 
78
 
79
#include "radeon_family.h"
79
#include "radeon_family.h"
80
#include "radeon_mode.h"
80
#include "radeon_mode.h"
81
#include "radeon_reg.h"
81
#include "radeon_reg.h"
82
 
82
 
83
#include 
83
#include 
84
 
84
 
85
extern unsigned long volatile jiffies;
85
extern unsigned long volatile jiffies;
86
 
86
 
87
/*
87
/*
88
 * Modules parameters.
88
 * Modules parameters.
89
 */
89
 */
90
extern int radeon_no_wb;
90
extern int radeon_no_wb;
91
extern int radeon_modeset;
91
extern int radeon_modeset;
92
extern int radeon_dynclks;
92
extern int radeon_dynclks;
93
extern int radeon_r4xx_atom;
93
extern int radeon_r4xx_atom;
94
extern int radeon_agpmode;
94
extern int radeon_agpmode;
95
extern int radeon_vram_limit;
95
extern int radeon_vram_limit;
96
extern int radeon_gart_size;
96
extern int radeon_gart_size;
97
extern int radeon_benchmarking;
97
extern int radeon_benchmarking;
98
extern int radeon_testing;
98
extern int radeon_testing;
99
extern int radeon_connector_table;
99
extern int radeon_connector_table;
100
extern int radeon_tv;
100
extern int radeon_tv;
101
extern int radeon_audio;
101
extern int radeon_audio;
102
extern int radeon_disp_priority;
102
extern int radeon_disp_priority;
103
extern int radeon_hw_i2c;
103
extern int radeon_hw_i2c;
104
extern int radeon_pcie_gen2;
104
extern int radeon_pcie_gen2;
105
typedef struct pm_message {
105
typedef struct pm_message {
106
    int event;
106
    int event;
107
} pm_message_t;
107
} pm_message_t;
108
 
108
 
109
typedef struct
109
typedef struct
110
{
110
{
111
  int width;
111
  int width;
112
  int height;
112
  int height;
113
  int bpp;
113
  int bpp;
114
  int freq;
114
  int freq;
115
}videomode_t;
115
}videomode_t;
116
 
116
 
117
static inline uint8_t __raw_readb(const volatile void __iomem *addr)
117
static inline uint8_t __raw_readb(const volatile void __iomem *addr)
118
{
118
{
119
    return *(const volatile uint8_t __force *) addr;
119
    return *(const volatile uint8_t __force *) addr;
120
}
120
}
121
 
121
 
122
static inline uint16_t __raw_readw(const volatile void __iomem *addr)
122
static inline uint16_t __raw_readw(const volatile void __iomem *addr)
123
{
123
{
124
    return *(const volatile uint16_t __force *) addr;
124
    return *(const volatile uint16_t __force *) addr;
125
}
125
}
126
 
126
 
127
static inline uint32_t __raw_readl(const volatile void __iomem *addr)
127
static inline uint32_t __raw_readl(const volatile void __iomem *addr)
128
{
128
{
129
    return *(const volatile uint32_t __force *) addr;
129
    return *(const volatile uint32_t __force *) addr;
130
}
130
}
131
 
131
 
132
#define readb __raw_readb
132
#define readb __raw_readb
133
#define readw __raw_readw
133
#define readw __raw_readw
134
#define readl __raw_readl
134
#define readl __raw_readl
135
 
135
 
136
 
136
 
137
 
137
 
138
static inline void __raw_writeb(uint8_t b, volatile void __iomem *addr)
138
static inline void __raw_writeb(uint8_t b, volatile void __iomem *addr)
139
{
139
{
140
    *(volatile uint8_t __force *) addr = b;
140
    *(volatile uint8_t __force *) addr = b;
141
}
141
}
142
 
142
 
143
static inline void __raw_writew(uint16_t b, volatile void __iomem *addr)
143
static inline void __raw_writew(uint16_t b, volatile void __iomem *addr)
144
{
144
{
145
    *(volatile uint16_t __force *) addr = b;
145
    *(volatile uint16_t __force *) addr = b;
146
}
146
}
147
 
147
 
148
static inline void __raw_writel(uint32_t b, volatile void __iomem *addr)
148
static inline void __raw_writel(uint32_t b, volatile void __iomem *addr)
149
{
149
{
150
    *(volatile uint32_t __force *) addr = b;
150
    *(volatile uint32_t __force *) addr = b;
151
}
151
}
152
 
152
 
153
static inline void __raw_writeq(__u64 b, volatile void __iomem *addr)
153
static inline void __raw_writeq(__u64 b, volatile void __iomem *addr)
154
{
154
{
155
        *(volatile __u64 *)addr = b;
155
        *(volatile __u64 *)addr = b;
156
}
156
}
157
 
157
 
158
#define writeb __raw_writeb
158
#define writeb __raw_writeb
159
#define writew __raw_writew
159
#define writew __raw_writew
160
#define writel __raw_writel
160
#define writel __raw_writel
161
#define writeq __raw_writeq
161
#define writeq __raw_writeq
162
 
162
 
163
 
163
 
164
static inline u32 ioread32(const volatile void __iomem *addr)
164
static inline u32 ioread32(const volatile void __iomem *addr)
165
{
165
{
166
    return in32((u32)addr);
166
    return in32((u32)addr);
167
}
167
}
168
 
168
 
169
static inline void iowrite32(uint32_t b, volatile void __iomem *addr)
169
static inline void iowrite32(uint32_t b, volatile void __iomem *addr)
170
{
170
{
171
    out32((u32)addr, b);
171
    out32((u32)addr, b);
172
}
172
}
173
 
173
 
174
struct __wait_queue_head {
174
struct __wait_queue_head {
175
        spinlock_t lock;
175
        spinlock_t lock;
176
        struct list_head task_list;
176
        struct list_head task_list;
177
};
177
};
178
typedef struct __wait_queue_head wait_queue_head_t;
178
typedef struct __wait_queue_head wait_queue_head_t;
179
 
179
 
180
 
180
 
181
/*
181
/*
182
 * Copy from radeon_drv.h so we don't have to include both and have conflicting
182
 * Copy from radeon_drv.h so we don't have to include both and have conflicting
183
 * symbol;
183
 * symbol;
184
 */
184
 */
185
#define RADEON_MAX_USEC_TIMEOUT         100000  /* 100 ms */
185
#define RADEON_MAX_USEC_TIMEOUT         100000  /* 100 ms */
186
#define RADEON_FENCE_JIFFIES_TIMEOUT	(HZ / 2)
186
#define RADEON_FENCE_JIFFIES_TIMEOUT	(HZ / 2)
187
/* RADEON_IB_POOL_SIZE must be a power of 2 */
187
/* RADEON_IB_POOL_SIZE must be a power of 2 */
188
#define RADEON_IB_POOL_SIZE             16
188
#define RADEON_IB_POOL_SIZE             16
189
#define RADEON_DEBUGFS_MAX_NUM_FILES	32
189
#define RADEON_DEBUGFS_MAX_NUM_FILES	32
190
#define RADEONFB_CONN_LIMIT             4
190
#define RADEONFB_CONN_LIMIT             4
191
#define RADEON_BIOS_NUM_SCRATCH		8
191
#define RADEON_BIOS_NUM_SCRATCH		8
192
 
192
 
193
/*
193
/*
194
 * Errata workarounds.
194
 * Errata workarounds.
195
 */
195
 */
196
enum radeon_pll_errata {
196
enum radeon_pll_errata {
197
    CHIP_ERRATA_R300_CG             = 0x00000001,
197
    CHIP_ERRATA_R300_CG             = 0x00000001,
198
    CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
198
    CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
199
    CHIP_ERRATA_PLL_DELAY           = 0x00000004
199
    CHIP_ERRATA_PLL_DELAY           = 0x00000004
200
};
200
};
201
 
201
 
202
 
202
 
203
struct radeon_device;
203
struct radeon_device;
204
 
204
 
205
 
205
 
206
/*
206
/*
207
 * BIOS.
207
 * BIOS.
208
 */
208
 */
209
#define ATRM_BIOS_PAGE 4096
209
#define ATRM_BIOS_PAGE 4096
210
 
210
 
211
#if defined(CONFIG_VGA_SWITCHEROO)
211
#if defined(CONFIG_VGA_SWITCHEROO)
212
bool radeon_atrm_supported(struct pci_dev *pdev);
212
bool radeon_atrm_supported(struct pci_dev *pdev);
213
int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
213
int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
214
#else
214
#else
215
static inline bool radeon_atrm_supported(struct pci_dev *pdev)
215
static inline bool radeon_atrm_supported(struct pci_dev *pdev)
216
{
216
{
217
	return false;
217
	return false;
218
}
218
}
219
 
219
 
220
static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
220
static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
221
	return -EINVAL;
221
	return -EINVAL;
222
}
222
}
223
#endif
223
#endif
224
bool radeon_get_bios(struct radeon_device *rdev);
224
bool radeon_get_bios(struct radeon_device *rdev);
225
 
225
 
226
 
226
 
227
/*
227
/*
228
 * Dummy page
228
 * Dummy page
229
 */
229
 */
230
struct radeon_dummy_page {
230
struct radeon_dummy_page {
231
	struct page	*page;
231
	struct page	*page;
232
	dma_addr_t	addr;
232
	dma_addr_t	addr;
233
};
233
};
234
int radeon_dummy_page_init(struct radeon_device *rdev);
234
int radeon_dummy_page_init(struct radeon_device *rdev);
235
void radeon_dummy_page_fini(struct radeon_device *rdev);
235
void radeon_dummy_page_fini(struct radeon_device *rdev);
236
 
236
 
237
 
237
 
238
/*
238
/*
239
 * Clocks
239
 * Clocks
240
 */
240
 */
241
struct radeon_clock {
241
struct radeon_clock {
242
	struct radeon_pll p1pll;
242
	struct radeon_pll p1pll;
243
	struct radeon_pll p2pll;
243
	struct radeon_pll p2pll;
244
	struct radeon_pll dcpll;
244
	struct radeon_pll dcpll;
245
	struct radeon_pll spll;
245
	struct radeon_pll spll;
246
	struct radeon_pll mpll;
246
	struct radeon_pll mpll;
247
	/* 10 Khz units */
247
	/* 10 Khz units */
248
	uint32_t default_mclk;
248
	uint32_t default_mclk;
249
	uint32_t default_sclk;
249
	uint32_t default_sclk;
250
	uint32_t default_dispclk;
250
	uint32_t default_dispclk;
251
	uint32_t dp_extclk;
251
	uint32_t dp_extclk;
252
	uint32_t max_pixel_clock;
252
	uint32_t max_pixel_clock;
253
};
253
};
254
 
254
 
255
/*
255
/*
256
 * Power management
256
 * Power management
257
 */
257
 */
258
int radeon_pm_init(struct radeon_device *rdev);
258
int radeon_pm_init(struct radeon_device *rdev);
259
void radeon_pm_fini(struct radeon_device *rdev);
259
void radeon_pm_fini(struct radeon_device *rdev);
260
void radeon_pm_compute_clocks(struct radeon_device *rdev);
260
void radeon_pm_compute_clocks(struct radeon_device *rdev);
261
void radeon_pm_suspend(struct radeon_device *rdev);
261
void radeon_pm_suspend(struct radeon_device *rdev);
262
void radeon_pm_resume(struct radeon_device *rdev);
262
void radeon_pm_resume(struct radeon_device *rdev);
263
void radeon_combios_get_power_modes(struct radeon_device *rdev);
263
void radeon_combios_get_power_modes(struct radeon_device *rdev);
264
void radeon_atombios_get_power_modes(struct radeon_device *rdev);
264
void radeon_atombios_get_power_modes(struct radeon_device *rdev);
265
void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
265
void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
266
int radeon_atom_get_max_vddc(struct radeon_device *rdev, u16 *voltage);
266
int radeon_atom_get_max_vddc(struct radeon_device *rdev, u16 *voltage);
267
void rs690_pm_info(struct radeon_device *rdev);
267
void rs690_pm_info(struct radeon_device *rdev);
268
extern int rv6xx_get_temp(struct radeon_device *rdev);
268
extern int rv6xx_get_temp(struct radeon_device *rdev);
269
extern int rv770_get_temp(struct radeon_device *rdev);
269
extern int rv770_get_temp(struct radeon_device *rdev);
270
extern int evergreen_get_temp(struct radeon_device *rdev);
270
extern int evergreen_get_temp(struct radeon_device *rdev);
271
extern int sumo_get_temp(struct radeon_device *rdev);
271
extern int sumo_get_temp(struct radeon_device *rdev);
272
 
272
 
273
/*
273
/*
274
 * Fences.
274
 * Fences.
275
 */
275
 */
276
struct radeon_fence_driver {
276
struct radeon_fence_driver {
277
	uint32_t			scratch_reg;
277
	uint32_t			scratch_reg;
278
	atomic_t			seq;
278
	atomic_t			seq;
279
	uint32_t			last_seq;
279
	uint32_t			last_seq;
280
	unsigned long			last_jiffies;
280
	unsigned long			last_jiffies;
281
	unsigned long			last_timeout;
281
	unsigned long			last_timeout;
282
	wait_queue_head_t		queue;
282
	wait_queue_head_t		queue;
283
	rwlock_t			lock;
283
	rwlock_t			lock;
284
	struct list_head		created;
284
	struct list_head		created;
285
	struct list_head		emited;
285
	struct list_head		emited;
286
	struct list_head		signaled;
286
	struct list_head		signaled;
287
	bool				initialized;
287
	bool				initialized;
288
};
288
};
289
 
289
 
290
struct radeon_fence {
290
struct radeon_fence {
291
	struct radeon_device		*rdev;
291
	struct radeon_device		*rdev;
292
	struct kref			kref;
292
	struct kref			kref;
293
	struct list_head		list;
293
	struct list_head		list;
294
	/* protected by radeon_fence.lock */
294
	/* protected by radeon_fence.lock */
295
	uint32_t			seq;
295
	uint32_t			seq;
296
	bool				emited;
296
	bool				emited;
297
	bool				signaled;
297
	bool				signaled;
298
    evhandle_t              evnt;
298
    evhandle_t              evnt;
299
};
299
};
300
 
300
 
301
int radeon_fence_driver_init(struct radeon_device *rdev);
301
int radeon_fence_driver_init(struct radeon_device *rdev);
302
void radeon_fence_driver_fini(struct radeon_device *rdev);
302
void radeon_fence_driver_fini(struct radeon_device *rdev);
303
int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
303
int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
304
int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
304
int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
305
void radeon_fence_process(struct radeon_device *rdev);
305
void radeon_fence_process(struct radeon_device *rdev);
306
bool radeon_fence_signaled(struct radeon_fence *fence);
306
bool radeon_fence_signaled(struct radeon_fence *fence);
307
int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
307
int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
308
int radeon_fence_wait_next(struct radeon_device *rdev);
308
int radeon_fence_wait_next(struct radeon_device *rdev);
309
int radeon_fence_wait_last(struct radeon_device *rdev);
309
int radeon_fence_wait_last(struct radeon_device *rdev);
310
struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
310
struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
311
void radeon_fence_unref(struct radeon_fence **fence);
311
void radeon_fence_unref(struct radeon_fence **fence);
312
 
312
 
313
/*
313
/*
314
 * Tiling registers
314
 * Tiling registers
315
 */
315
 */
316
struct radeon_surface_reg {
316
struct radeon_surface_reg {
317
	struct radeon_bo *bo;
317
	struct radeon_bo *bo;
318
};
318
};
319
 
319
 
320
#define RADEON_GEM_MAX_SURFACES 8
320
#define RADEON_GEM_MAX_SURFACES 8
321
 
321
 
322
/*
322
/*
323
 * TTM.
323
 * TTM.
324
 */
324
 */
325
struct radeon_mman {
325
struct radeon_mman {
326
	struct ttm_bo_global_ref        bo_global_ref;
326
	struct ttm_bo_global_ref        bo_global_ref;
327
//	struct drm_global_reference	mem_global_ref;
327
//	struct drm_global_reference	mem_global_ref;
328
	struct ttm_bo_device		bdev;
328
	struct ttm_bo_device		bdev;
329
	bool				mem_global_referenced;
329
	bool				mem_global_referenced;
330
	bool				initialized;
330
	bool				initialized;
331
};
331
};
332
 
332
 
333
struct radeon_bo {
333
struct radeon_bo {
334
	/* Protected by gem.mutex */
334
	/* Protected by gem.mutex */
335
	struct list_head		list;
335
	struct list_head		list;
336
	/* Protected by tbo.reserved */
336
	/* Protected by tbo.reserved */
337
	u32				placements[3];
337
	u32				placements[3];
338
	struct ttm_placement		placement;
338
	struct ttm_placement		placement;
339
	struct ttm_buffer_object	tbo;
339
	struct ttm_buffer_object	tbo;
340
	struct ttm_bo_kmap_obj		kmap;
340
	struct ttm_bo_kmap_obj		kmap;
341
    unsigned                    pin_count;
341
    unsigned                    pin_count;
342
    void                       *kptr;
342
    void                       *kptr;
343
    void                       *uptr;
343
    void                       *uptr;
344
    u32                         cpu_addr;
344
    u32                         cpu_addr;
345
    u32                         tiling_flags;
345
    u32                         tiling_flags;
346
    u32                         pitch;
346
    u32                         pitch;
347
    int                         surface_reg;
347
    int                         surface_reg;
348
	/* Constant after initialization */
348
	/* Constant after initialization */
349
	struct radeon_device		*rdev;
349
	struct radeon_device		*rdev;
350
	struct drm_gem_object		gem_base;
350
	struct drm_gem_object		gem_base;
351
    u32                          domain;
351
    u32                          domain;
352
};
352
};
353
#define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
353
#define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
354
 
354
 
355
struct radeon_bo_list {
355
struct radeon_bo_list {
356
	struct radeon_bo	*bo;
356
	struct radeon_bo	*bo;
357
	uint64_t		gpu_offset;
357
	uint64_t		gpu_offset;
358
	unsigned		rdomain;
358
	unsigned		rdomain;
359
	unsigned		wdomain;
359
	unsigned		wdomain;
360
	u32			tiling_flags;
360
	u32			tiling_flags;
361
};
361
};
362
 
362
 
363
/*
363
/*
364
 * GEM objects.
364
 * GEM objects.
365
 */
365
 */
366
struct radeon_gem {
366
struct radeon_gem {
367
	struct mutex		mutex;
367
	struct mutex		mutex;
368
	struct list_head	objects;
368
	struct list_head	objects;
369
};
369
};
370
 
370
 
371
int radeon_gem_init(struct radeon_device *rdev);
371
int radeon_gem_init(struct radeon_device *rdev);
372
void radeon_gem_fini(struct radeon_device *rdev);
372
void radeon_gem_fini(struct radeon_device *rdev);
373
int radeon_gem_object_create(struct radeon_device *rdev, int size,
373
int radeon_gem_object_create(struct radeon_device *rdev, int size,
374
			     int alignment, int initial_domain,
374
			     int alignment, int initial_domain,
375
			     bool discardable, bool kernel,
375
			     bool discardable, bool kernel,
376
			     struct drm_gem_object **obj);
376
			     struct drm_gem_object **obj);
377
int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
377
int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
378
			  uint64_t *gpu_addr);
378
			  uint64_t *gpu_addr);
379
void radeon_gem_object_unpin(struct drm_gem_object *obj);
379
void radeon_gem_object_unpin(struct drm_gem_object *obj);
380
 
380
 
381
int radeon_mode_dumb_create(struct drm_file *file_priv,
381
int radeon_mode_dumb_create(struct drm_file *file_priv,
382
			    struct drm_device *dev,
382
			    struct drm_device *dev,
383
			    struct drm_mode_create_dumb *args);
383
			    struct drm_mode_create_dumb *args);
384
int radeon_mode_dumb_mmap(struct drm_file *filp,
384
int radeon_mode_dumb_mmap(struct drm_file *filp,
385
			  struct drm_device *dev,
385
			  struct drm_device *dev,
386
			  uint32_t handle, uint64_t *offset_p);
386
			  uint32_t handle, uint64_t *offset_p);
387
int radeon_mode_dumb_destroy(struct drm_file *file_priv,
387
int radeon_mode_dumb_destroy(struct drm_file *file_priv,
388
			     struct drm_device *dev,
388
			     struct drm_device *dev,
389
			     uint32_t handle);
389
			     uint32_t handle);
390
 
390
 
391
/*
391
/*
392
 * GART structures, functions & helpers
392
 * GART structures, functions & helpers
393
 */
393
 */
394
struct radeon_mc;
394
struct radeon_mc;
395
 
395
 
396
struct radeon_gart_table_ram {
396
struct radeon_gart_table_ram {
397
    volatile uint32_t       *ptr;
397
    volatile uint32_t       *ptr;
398
};
398
};
399
 
399
 
400
struct radeon_gart_table_vram {
400
struct radeon_gart_table_vram {
401
	struct radeon_bo		*robj;
401
	struct radeon_bo		*robj;
402
    volatile uint32_t       *ptr;
402
    volatile uint32_t       *ptr;
403
};
403
};
404
 
404
 
405
union radeon_gart_table {
405
union radeon_gart_table {
406
    struct radeon_gart_table_ram    ram;
406
    struct radeon_gart_table_ram    ram;
407
    struct radeon_gart_table_vram   vram;
407
    struct radeon_gart_table_vram   vram;
408
};
408
};
409
 
409
 
410
#define RADEON_GPU_PAGE_SIZE 4096
410
#define RADEON_GPU_PAGE_SIZE 4096
411
#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
411
#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
412
 
412
 
413
struct radeon_gart {
413
struct radeon_gart {
414
    dma_addr_t          table_addr;
414
    dma_addr_t          table_addr;
415
    unsigned            num_gpu_pages;
415
    unsigned            num_gpu_pages;
416
    unsigned            num_cpu_pages;
416
    unsigned            num_cpu_pages;
417
    unsigned            table_size;
417
    unsigned            table_size;
418
    union radeon_gart_table     table;
418
    union radeon_gart_table     table;
419
    struct page         **pages;
419
    struct page         **pages;
420
    dma_addr_t          *pages_addr;
420
    dma_addr_t          *pages_addr;
421
	bool				*ttm_alloced;
421
	bool				*ttm_alloced;
422
    bool                ready;
422
    bool                ready;
423
};
423
};
424
 
424
 
425
int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
425
int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
426
void radeon_gart_table_ram_free(struct radeon_device *rdev);
426
void radeon_gart_table_ram_free(struct radeon_device *rdev);
427
int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
427
int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
428
void radeon_gart_table_vram_free(struct radeon_device *rdev);
428
void radeon_gart_table_vram_free(struct radeon_device *rdev);
429
int radeon_gart_init(struct radeon_device *rdev);
429
int radeon_gart_init(struct radeon_device *rdev);
430
void radeon_gart_fini(struct radeon_device *rdev);
430
void radeon_gart_fini(struct radeon_device *rdev);
431
void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
431
void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
432
			int pages);
432
			int pages);
433
int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
433
int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
434
            int pages, u32_t *pagelist);
434
            int pages, u32_t *pagelist);
435
 
435
 
436
 
436
 
437
/*
437
/*
438
 * GPU MC structures, functions & helpers
438
 * GPU MC structures, functions & helpers
439
 */
439
 */
440
struct radeon_mc {
440
struct radeon_mc {
441
    resource_size_t     aper_size;
441
    resource_size_t     aper_size;
442
    resource_size_t     aper_base;
442
    resource_size_t     aper_base;
443
    resource_size_t     agp_base;
443
    resource_size_t     agp_base;
444
	/* for some chips with <= 32MB we need to lie
444
	/* for some chips with <= 32MB we need to lie
445
	 * about vram size near mc fb location */
445
	 * about vram size near mc fb location */
446
	u64			mc_vram_size;
446
	u64			mc_vram_size;
447
	u64			visible_vram_size;
447
	u64			visible_vram_size;
448
	u64			gtt_size;
448
	u64			gtt_size;
449
	u64			gtt_start;
449
	u64			gtt_start;
450
	u64			gtt_end;
450
	u64			gtt_end;
451
	u64			vram_start;
451
	u64			vram_start;
452
	u64			vram_end;
452
	u64			vram_end;
453
    unsigned            vram_width;
453
    unsigned            vram_width;
454
	u64			real_vram_size;
454
	u64			real_vram_size;
455
    int                 vram_mtrr;
455
    int                 vram_mtrr;
456
    bool                vram_is_ddr;
456
    bool                vram_is_ddr;
457
	bool                    igp_sideport_enabled;
457
	bool                    igp_sideport_enabled;
458
	u64                     gtt_base_align;
458
	u64                     gtt_base_align;
459
};
459
};
460
 
460
 
461
bool radeon_combios_sideport_present(struct radeon_device *rdev);
461
bool radeon_combios_sideport_present(struct radeon_device *rdev);
462
bool radeon_atombios_sideport_present(struct radeon_device *rdev);
462
bool radeon_atombios_sideport_present(struct radeon_device *rdev);
463
 
463
 
464
/*
464
/*
465
 * GPU scratch registers structures, functions & helpers
465
 * GPU scratch registers structures, functions & helpers
466
 */
466
 */
467
struct radeon_scratch {
467
struct radeon_scratch {
468
    unsigned        num_reg;
468
    unsigned        num_reg;
469
	uint32_t                reg_base;
469
	uint32_t                reg_base;
470
    bool            free[32];
470
    bool            free[32];
471
    uint32_t        reg[32];
471
    uint32_t        reg[32];
472
};
472
};
473
 
473
 
474
int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
474
int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
475
void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
475
void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
476
 
476
 
477
 
477
 
478
/*
478
/*
479
 * IRQS.
479
 * IRQS.
480
 */
480
 */
481
struct r500_irq_stat_regs {
481
struct r500_irq_stat_regs {
482
	u32 disp_int;
482
	u32 disp_int;
483
};
483
};
484
 
484
 
485
struct r600_irq_stat_regs {
485
struct r600_irq_stat_regs {
486
	u32 disp_int;
486
	u32 disp_int;
487
	u32 disp_int_cont;
487
	u32 disp_int_cont;
488
	u32 disp_int_cont2;
488
	u32 disp_int_cont2;
489
	u32 d1grph_int;
489
	u32 d1grph_int;
490
	u32 d2grph_int;
490
	u32 d2grph_int;
491
};
491
};
492
 
492
 
493
struct evergreen_irq_stat_regs {
493
struct evergreen_irq_stat_regs {
494
	u32 disp_int;
494
	u32 disp_int;
495
	u32 disp_int_cont;
495
	u32 disp_int_cont;
496
	u32 disp_int_cont2;
496
	u32 disp_int_cont2;
497
	u32 disp_int_cont3;
497
	u32 disp_int_cont3;
498
	u32 disp_int_cont4;
498
	u32 disp_int_cont4;
499
	u32 disp_int_cont5;
499
	u32 disp_int_cont5;
500
	u32 d1grph_int;
500
	u32 d1grph_int;
501
	u32 d2grph_int;
501
	u32 d2grph_int;
502
	u32 d3grph_int;
502
	u32 d3grph_int;
503
	u32 d4grph_int;
503
	u32 d4grph_int;
504
	u32 d5grph_int;
504
	u32 d5grph_int;
505
	u32 d6grph_int;
505
	u32 d6grph_int;
506
};
506
};
507
 
507
 
508
union radeon_irq_stat_regs {
508
union radeon_irq_stat_regs {
509
	struct r500_irq_stat_regs r500;
509
	struct r500_irq_stat_regs r500;
510
	struct r600_irq_stat_regs r600;
510
	struct r600_irq_stat_regs r600;
511
	struct evergreen_irq_stat_regs evergreen;
511
	struct evergreen_irq_stat_regs evergreen;
512
};
512
};
513
 
513
 
514
struct radeon_irq {
514
struct radeon_irq {
515
	bool		installed;
515
	bool		installed;
516
	bool		sw_int;
516
	bool		sw_int;
517
	/* FIXME: use a define max crtc rather than hardcode it */
517
	/* FIXME: use a define max crtc rather than hardcode it */
518
	bool		crtc_vblank_int[6];
518
	bool		crtc_vblank_int[6];
519
	bool		pflip[6];
519
	bool		pflip[6];
520
    wait_queue_head_t   vblank_queue;
520
    wait_queue_head_t   vblank_queue;
521
	/* FIXME: use defines for max hpd/dacs */
521
	/* FIXME: use defines for max hpd/dacs */
522
	bool            hpd[6];
522
	bool            hpd[6];
523
	bool            gui_idle;
523
	bool            gui_idle;
524
	bool            gui_idle_acked;
524
	bool            gui_idle_acked;
525
   wait_queue_head_t   idle_queue;
525
   wait_queue_head_t   idle_queue;
526
	/* FIXME: use defines for max HDMI blocks */
526
	/* FIXME: use defines for max HDMI blocks */
527
	bool		hdmi[2];
527
	bool		hdmi[2];
528
    spinlock_t  sw_lock;
528
    spinlock_t  sw_lock;
529
	int sw_refcount;
529
	int sw_refcount;
530
	union radeon_irq_stat_regs stat_regs;
530
	union radeon_irq_stat_regs stat_regs;
531
	spinlock_t pflip_lock[6];
531
	spinlock_t pflip_lock[6];
532
	int pflip_refcount[6];
532
	int pflip_refcount[6];
533
};
533
};
534
 
534
 
535
int radeon_irq_kms_init(struct radeon_device *rdev);
535
int radeon_irq_kms_init(struct radeon_device *rdev);
536
void radeon_irq_kms_fini(struct radeon_device *rdev);
536
void radeon_irq_kms_fini(struct radeon_device *rdev);
537
void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
537
void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
538
void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
538
void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
539
void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
539
void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
540
void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
540
void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
541
 
541
 
542
/*
542
/*
543
 * CP & ring.
543
 * CP & ring.
544
 */
544
 */
545
struct radeon_ib {
545
struct radeon_ib {
546
    struct list_head    list;
546
    struct list_head    list;
547
	unsigned		idx;
547
	unsigned		idx;
548
    uint64_t            gpu_addr;
548
    uint64_t            gpu_addr;
549
	struct radeon_fence	*fence;
549
	struct radeon_fence	*fence;
550
    uint32_t            *ptr;
550
    uint32_t            *ptr;
551
    uint32_t            length_dw;
551
    uint32_t            length_dw;
552
	bool			free;
552
	bool			free;
553
};
553
};
554
 
554
 
555
/*
555
/*
556
 * locking -
556
 * locking -
557
 * mutex protects scheduled_ibs, ready, alloc_bm
557
 * mutex protects scheduled_ibs, ready, alloc_bm
558
 */
558
 */
559
struct radeon_ib_pool {
559
struct radeon_ib_pool {
560
	struct mutex		mutex;
560
	struct mutex		mutex;
561
	struct radeon_bo	*robj;
561
	struct radeon_bo	*robj;
562
	struct list_head	bogus_ib;
562
	struct list_head	bogus_ib;
563
	struct radeon_ib	ibs[RADEON_IB_POOL_SIZE];
563
	struct radeon_ib	ibs[RADEON_IB_POOL_SIZE];
564
    bool                ready;
564
    bool                ready;
565
	unsigned		head_id;
565
	unsigned		head_id;
566
};
566
};
567
 
567
 
568
struct radeon_cp {
568
struct radeon_cp {
569
	struct radeon_bo	*ring_obj;
569
	struct radeon_bo	*ring_obj;
570
	volatile uint32_t	*ring;
570
	volatile uint32_t	*ring;
571
    unsigned            rptr;
571
    unsigned            rptr;
572
    unsigned            wptr;
572
    unsigned            wptr;
573
    unsigned            wptr_old;
573
    unsigned            wptr_old;
574
    unsigned            ring_size;
574
    unsigned            ring_size;
575
    unsigned            ring_free_dw;
575
    unsigned            ring_free_dw;
576
    int                 count_dw;
576
    int                 count_dw;
577
    uint64_t            gpu_addr;
577
    uint64_t            gpu_addr;
578
    uint32_t            align_mask;
578
    uint32_t            align_mask;
579
    uint32_t            ptr_mask;
579
    uint32_t            ptr_mask;
580
	struct mutex		mutex;
580
	struct mutex		mutex;
581
    bool                ready;
581
    bool                ready;
582
};
582
};
583
 
583
 
584
/*
584
/*
585
 * R6xx+ IH ring
585
 * R6xx+ IH ring
586
 */
586
 */
587
struct r600_ih {
587
struct r600_ih {
588
	struct radeon_bo	*ring_obj;
588
	struct radeon_bo	*ring_obj;
589
	volatile uint32_t	*ring;
589
	volatile uint32_t	*ring;
590
    unsigned            rptr;
590
    unsigned            rptr;
591
    unsigned            wptr;
591
    unsigned            wptr;
592
    unsigned            wptr_old;
592
    unsigned            wptr_old;
593
    unsigned            ring_size;
593
    unsigned            ring_size;
594
    uint64_t            gpu_addr;
594
    uint64_t            gpu_addr;
595
    uint32_t            ptr_mask;
595
    uint32_t            ptr_mask;
596
    spinlock_t              lock;
596
    spinlock_t              lock;
597
    bool                enabled;
597
    bool                enabled;
598
};
598
};
599
 
599
 
600
struct r600_blit {
600
struct r600_blit {
601
	struct mutex		mutex;
601
	struct mutex		mutex;
602
	struct radeon_bo	*shader_obj;
602
	struct radeon_bo	*shader_obj;
603
	u64 shader_gpu_addr;
603
	u64 shader_gpu_addr;
604
	u32 vs_offset, ps_offset;
604
	u32 vs_offset, ps_offset;
605
	u32 state_offset;
605
	u32 state_offset;
606
	u32 state_len;
606
	u32 state_len;
607
	u32 vb_used, vb_total;
607
	u32 vb_used, vb_total;
608
	struct radeon_ib *vb_ib;
608
	struct radeon_ib *vb_ib;
609
};
609
};
610
 
610
 
611
int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
611
int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
612
void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
612
void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
613
int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
613
int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
614
int radeon_ib_pool_init(struct radeon_device *rdev);
614
int radeon_ib_pool_init(struct radeon_device *rdev);
615
void radeon_ib_pool_fini(struct radeon_device *rdev);
615
void radeon_ib_pool_fini(struct radeon_device *rdev);
616
int radeon_ib_test(struct radeon_device *rdev);
616
int radeon_ib_test(struct radeon_device *rdev);
617
extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
617
extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
618
/* Ring access between begin & end cannot sleep */
618
/* Ring access between begin & end cannot sleep */
619
void radeon_ring_free_size(struct radeon_device *rdev);
619
void radeon_ring_free_size(struct radeon_device *rdev);
620
int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
620
int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
621
int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
621
int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
622
void radeon_ring_commit(struct radeon_device *rdev);
622
void radeon_ring_commit(struct radeon_device *rdev);
623
void radeon_ring_unlock_commit(struct radeon_device *rdev);
623
void radeon_ring_unlock_commit(struct radeon_device *rdev);
624
void radeon_ring_unlock_undo(struct radeon_device *rdev);
624
void radeon_ring_unlock_undo(struct radeon_device *rdev);
625
int radeon_ring_test(struct radeon_device *rdev);
625
int radeon_ring_test(struct radeon_device *rdev);
626
int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
626
int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
627
void radeon_ring_fini(struct radeon_device *rdev);
627
void radeon_ring_fini(struct radeon_device *rdev);
628
 
628
 
629
 
629
 
630
/*
630
/*
631
 * CS.
631
 * CS.
632
 */
632
 */
633
struct radeon_cs_reloc {
633
struct radeon_cs_reloc {
634
//	struct drm_gem_object		*gobj;
634
//	struct drm_gem_object		*gobj;
635
	struct radeon_bo		*robj;
635
	struct radeon_bo		*robj;
636
	struct radeon_bo_list		lobj;
636
	struct radeon_bo_list		lobj;
637
    uint32_t                handle;
637
    uint32_t                handle;
638
    uint32_t                flags;
638
    uint32_t                flags;
639
};
639
};
640
 
640
 
641
struct radeon_cs_chunk {
641
struct radeon_cs_chunk {
642
	uint32_t		chunk_id;
642
	uint32_t		chunk_id;
643
	uint32_t		length_dw;
643
	uint32_t		length_dw;
644
	int kpage_idx[2];
644
	int kpage_idx[2];
645
	uint32_t                *kpage[2];
645
	uint32_t                *kpage[2];
646
	uint32_t		*kdata;
646
	uint32_t		*kdata;
647
	void __user *user_ptr;
647
	void __user *user_ptr;
648
	int last_copied_page;
648
	int last_copied_page;
649
	int last_page_index;
649
	int last_page_index;
650
};
650
};
651
 
651
 
652
struct radeon_cs_parser {
652
struct radeon_cs_parser {
653
	struct device		*dev;
653
	struct device		*dev;
654
	struct radeon_device	*rdev;
654
	struct radeon_device	*rdev;
655
	struct drm_file		*filp;
655
	struct drm_file		*filp;
656
	/* chunks */
656
	/* chunks */
657
	unsigned		nchunks;
657
	unsigned		nchunks;
658
	struct radeon_cs_chunk	*chunks;
658
	struct radeon_cs_chunk	*chunks;
659
	uint64_t		*chunks_array;
659
	uint64_t		*chunks_array;
660
	/* IB */
660
	/* IB */
661
	unsigned		idx;
661
	unsigned		idx;
662
	/* relocations */
662
	/* relocations */
663
	unsigned		nrelocs;
663
	unsigned		nrelocs;
664
	struct radeon_cs_reloc	*relocs;
664
	struct radeon_cs_reloc	*relocs;
665
	struct radeon_cs_reloc	**relocs_ptr;
665
	struct radeon_cs_reloc	**relocs_ptr;
666
	struct list_head	validated;
666
	struct list_head	validated;
667
	/* indices of various chunks */
667
	/* indices of various chunks */
668
	int			chunk_ib_idx;
668
	int			chunk_ib_idx;
669
	int			chunk_relocs_idx;
669
	int			chunk_relocs_idx;
670
	struct radeon_ib	*ib;
670
	struct radeon_ib	*ib;
671
	void			*track;
671
	void			*track;
672
	unsigned		family;
672
	unsigned		family;
673
	int parser_error;
673
	int parser_error;
674
};
674
};
675
 
675
 
676
extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
676
extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
677
extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
677
extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
678
 
678
 
679
 
679
 
680
static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
680
static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
681
{
681
{
682
	struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
682
	struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
683
	u32 pg_idx, pg_offset;
683
	u32 pg_idx, pg_offset;
684
	u32 idx_value = 0;
684
	u32 idx_value = 0;
685
	int new_page;
685
	int new_page;
686
 
686
 
687
	pg_idx = (idx * 4) / PAGE_SIZE;
687
	pg_idx = (idx * 4) / PAGE_SIZE;
688
	pg_offset = (idx * 4) % PAGE_SIZE;
688
	pg_offset = (idx * 4) % PAGE_SIZE;
689
 
689
 
690
	if (ibc->kpage_idx[0] == pg_idx)
690
	if (ibc->kpage_idx[0] == pg_idx)
691
		return ibc->kpage[0][pg_offset/4];
691
		return ibc->kpage[0][pg_offset/4];
692
	if (ibc->kpage_idx[1] == pg_idx)
692
	if (ibc->kpage_idx[1] == pg_idx)
693
		return ibc->kpage[1][pg_offset/4];
693
		return ibc->kpage[1][pg_offset/4];
694
 
694
 
695
	new_page = radeon_cs_update_pages(p, pg_idx);
695
	new_page = radeon_cs_update_pages(p, pg_idx);
696
	if (new_page < 0) {
696
	if (new_page < 0) {
697
		p->parser_error = new_page;
697
		p->parser_error = new_page;
698
		return 0;
698
		return 0;
699
	}
699
	}
700
 
700
 
701
	idx_value = ibc->kpage[new_page][pg_offset/4];
701
	idx_value = ibc->kpage[new_page][pg_offset/4];
702
	return idx_value;
702
	return idx_value;
703
}
703
}
704
 
704
 
705
struct radeon_cs_packet {
705
struct radeon_cs_packet {
706
	unsigned	idx;
706
	unsigned	idx;
707
	unsigned	type;
707
	unsigned	type;
708
	unsigned	reg;
708
	unsigned	reg;
709
	unsigned	opcode;
709
	unsigned	opcode;
710
	int		count;
710
	int		count;
711
	unsigned	one_reg_wr;
711
	unsigned	one_reg_wr;
712
};
712
};
713
 
713
 
714
typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
714
typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
715
				      struct radeon_cs_packet *pkt,
715
				      struct radeon_cs_packet *pkt,
716
				      unsigned idx, unsigned reg);
716
				      unsigned idx, unsigned reg);
717
typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
717
typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
718
				      struct radeon_cs_packet *pkt);
718
				      struct radeon_cs_packet *pkt);
719
 
719
 
720
 
720
 
721
/*
721
/*
722
 * AGP
722
 * AGP
723
 */
723
 */
724
int radeon_agp_init(struct radeon_device *rdev);
724
int radeon_agp_init(struct radeon_device *rdev);
725
void radeon_agp_resume(struct radeon_device *rdev);
725
void radeon_agp_resume(struct radeon_device *rdev);
726
void radeon_agp_suspend(struct radeon_device *rdev);
726
void radeon_agp_suspend(struct radeon_device *rdev);
727
void radeon_agp_fini(struct radeon_device *rdev);
727
void radeon_agp_fini(struct radeon_device *rdev);
728
 
728
 
729
 
729
 
730
/*
730
/*
731
 * Writeback
731
 * Writeback
732
 */
732
 */
733
struct radeon_wb {
733
struct radeon_wb {
734
	struct radeon_bo	*wb_obj;
734
	struct radeon_bo	*wb_obj;
735
	volatile uint32_t	*wb;
735
	volatile uint32_t	*wb;
736
	uint64_t		gpu_addr;
736
	uint64_t		gpu_addr;
737
	bool                    enabled;
737
	bool                    enabled;
738
	bool                    use_event;
738
	bool                    use_event;
739
};
739
};
740
 
740
 
741
#define RADEON_WB_SCRATCH_OFFSET 0
741
#define RADEON_WB_SCRATCH_OFFSET 0
742
#define RADEON_WB_CP_RPTR_OFFSET 1024
742
#define RADEON_WB_CP_RPTR_OFFSET 1024
743
#define RADEON_WB_CP1_RPTR_OFFSET 1280
743
#define RADEON_WB_CP1_RPTR_OFFSET 1280
744
#define RADEON_WB_CP2_RPTR_OFFSET 1536
744
#define RADEON_WB_CP2_RPTR_OFFSET 1536
745
#define R600_WB_IH_WPTR_OFFSET   2048
745
#define R600_WB_IH_WPTR_OFFSET   2048
746
#define R600_WB_EVENT_OFFSET     3072
746
#define R600_WB_EVENT_OFFSET     3072
747
 
747
 
748
/**
748
/**
749
 * struct radeon_pm - power management datas
749
 * struct radeon_pm - power management datas
750
 * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
750
 * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
751
 * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
751
 * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
752
 * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
752
 * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
753
 * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
753
 * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
754
 * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
754
 * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
755
 * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
755
 * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
756
 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
756
 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
757
 * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
757
 * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
758
 * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
758
 * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
759
 * @sclk:          	GPU clock Mhz (core bandwidth depends of this clock)
759
 * @sclk:          	GPU clock Mhz (core bandwidth depends of this clock)
760
 * @needed_bandwidth:   current bandwidth needs
760
 * @needed_bandwidth:   current bandwidth needs
761
 *
761
 *
762
 * It keeps track of various data needed to take powermanagement decision.
762
 * It keeps track of various data needed to take powermanagement decision.
763
 * Bandwidth need is used to determine minimun clock of the GPU and memory.
763
 * Bandwidth need is used to determine minimun clock of the GPU and memory.
764
 * Equation between gpu/memory clock and available bandwidth is hw dependent
764
 * Equation between gpu/memory clock and available bandwidth is hw dependent
765
 * (type of memory, bus size, efficiency, ...)
765
 * (type of memory, bus size, efficiency, ...)
766
 */
766
 */
767
 
767
 
768
enum radeon_pm_method {
768
enum radeon_pm_method {
769
	PM_METHOD_PROFILE,
769
	PM_METHOD_PROFILE,
770
	PM_METHOD_DYNPM,
770
	PM_METHOD_DYNPM,
771
};
771
};
772
 
772
 
773
enum radeon_dynpm_state {
773
enum radeon_dynpm_state {
774
	DYNPM_STATE_DISABLED,
774
	DYNPM_STATE_DISABLED,
775
	DYNPM_STATE_MINIMUM,
775
	DYNPM_STATE_MINIMUM,
776
	DYNPM_STATE_PAUSED,
776
	DYNPM_STATE_PAUSED,
777
	DYNPM_STATE_ACTIVE,
777
	DYNPM_STATE_ACTIVE,
778
	DYNPM_STATE_SUSPENDED,
778
	DYNPM_STATE_SUSPENDED,
779
};
779
};
780
enum radeon_dynpm_action {
780
enum radeon_dynpm_action {
781
	DYNPM_ACTION_NONE,
781
	DYNPM_ACTION_NONE,
782
	DYNPM_ACTION_MINIMUM,
782
	DYNPM_ACTION_MINIMUM,
783
	DYNPM_ACTION_DOWNCLOCK,
783
	DYNPM_ACTION_DOWNCLOCK,
784
	DYNPM_ACTION_UPCLOCK,
784
	DYNPM_ACTION_UPCLOCK,
785
	DYNPM_ACTION_DEFAULT
785
	DYNPM_ACTION_DEFAULT
786
};
786
};
787
 
787
 
788
enum radeon_voltage_type {
788
enum radeon_voltage_type {
789
	VOLTAGE_NONE = 0,
789
	VOLTAGE_NONE = 0,
790
	VOLTAGE_GPIO,
790
	VOLTAGE_GPIO,
791
	VOLTAGE_VDDC,
791
	VOLTAGE_VDDC,
792
	VOLTAGE_SW
792
	VOLTAGE_SW
793
};
793
};
794
 
794
 
795
enum radeon_pm_state_type {
795
enum radeon_pm_state_type {
796
	POWER_STATE_TYPE_DEFAULT,
796
	POWER_STATE_TYPE_DEFAULT,
797
	POWER_STATE_TYPE_POWERSAVE,
797
	POWER_STATE_TYPE_POWERSAVE,
798
	POWER_STATE_TYPE_BATTERY,
798
	POWER_STATE_TYPE_BATTERY,
799
	POWER_STATE_TYPE_BALANCED,
799
	POWER_STATE_TYPE_BALANCED,
800
	POWER_STATE_TYPE_PERFORMANCE,
800
	POWER_STATE_TYPE_PERFORMANCE,
801
};
801
};
802
 
802
 
803
enum radeon_pm_profile_type {
803
enum radeon_pm_profile_type {
804
	PM_PROFILE_DEFAULT,
804
	PM_PROFILE_DEFAULT,
805
	PM_PROFILE_AUTO,
805
	PM_PROFILE_AUTO,
806
	PM_PROFILE_LOW,
806
	PM_PROFILE_LOW,
807
	PM_PROFILE_MID,
807
	PM_PROFILE_MID,
808
	PM_PROFILE_HIGH,
808
	PM_PROFILE_HIGH,
809
};
809
};
810
 
810
 
811
#define PM_PROFILE_DEFAULT_IDX 0
811
#define PM_PROFILE_DEFAULT_IDX 0
812
#define PM_PROFILE_LOW_SH_IDX  1
812
#define PM_PROFILE_LOW_SH_IDX  1
813
#define PM_PROFILE_MID_SH_IDX  2
813
#define PM_PROFILE_MID_SH_IDX  2
814
#define PM_PROFILE_HIGH_SH_IDX 3
814
#define PM_PROFILE_HIGH_SH_IDX 3
815
#define PM_PROFILE_LOW_MH_IDX  4
815
#define PM_PROFILE_LOW_MH_IDX  4
816
#define PM_PROFILE_MID_MH_IDX  5
816
#define PM_PROFILE_MID_MH_IDX  5
817
#define PM_PROFILE_HIGH_MH_IDX 6
817
#define PM_PROFILE_HIGH_MH_IDX 6
818
#define PM_PROFILE_MAX         7
818
#define PM_PROFILE_MAX         7
819
 
819
 
820
struct radeon_pm_profile {
820
struct radeon_pm_profile {
821
	int dpms_off_ps_idx;
821
	int dpms_off_ps_idx;
822
	int dpms_on_ps_idx;
822
	int dpms_on_ps_idx;
823
	int dpms_off_cm_idx;
823
	int dpms_off_cm_idx;
824
	int dpms_on_cm_idx;
824
	int dpms_on_cm_idx;
825
};
825
};
826
 
826
 
827
enum radeon_int_thermal_type {
827
enum radeon_int_thermal_type {
828
	THERMAL_TYPE_NONE,
828
	THERMAL_TYPE_NONE,
829
	THERMAL_TYPE_RV6XX,
829
	THERMAL_TYPE_RV6XX,
830
	THERMAL_TYPE_RV770,
830
	THERMAL_TYPE_RV770,
831
	THERMAL_TYPE_EVERGREEN,
831
	THERMAL_TYPE_EVERGREEN,
832
	THERMAL_TYPE_SUMO,
832
	THERMAL_TYPE_SUMO,
833
	THERMAL_TYPE_NI,
833
	THERMAL_TYPE_NI,
834
};
834
};
835
 
835
 
836
struct radeon_voltage {
836
struct radeon_voltage {
837
	enum radeon_voltage_type type;
837
	enum radeon_voltage_type type;
838
	/* gpio voltage */
838
	/* gpio voltage */
839
	struct radeon_gpio_rec gpio;
839
	struct radeon_gpio_rec gpio;
840
	u32 delay; /* delay in usec from voltage drop to sclk change */
840
	u32 delay; /* delay in usec from voltage drop to sclk change */
841
	bool active_high; /* voltage drop is active when bit is high */
841
	bool active_high; /* voltage drop is active when bit is high */
842
	/* VDDC voltage */
842
	/* VDDC voltage */
843
	u8 vddc_id; /* index into vddc voltage table */
843
	u8 vddc_id; /* index into vddc voltage table */
844
	u8 vddci_id; /* index into vddci voltage table */
844
	u8 vddci_id; /* index into vddci voltage table */
845
	bool vddci_enabled;
845
	bool vddci_enabled;
846
	/* r6xx+ sw */
846
	/* r6xx+ sw */
847
	u16 voltage;
847
	u16 voltage;
848
	/* evergreen+ vddci */
848
	/* evergreen+ vddci */
849
	u16 vddci;
849
	u16 vddci;
850
};
850
};
851
 
851
 
852
/* clock mode flags */
852
/* clock mode flags */
853
#define RADEON_PM_MODE_NO_DISPLAY          (1 << 0)
853
#define RADEON_PM_MODE_NO_DISPLAY          (1 << 0)
854
 
854
 
855
struct radeon_pm_clock_info {
855
struct radeon_pm_clock_info {
856
	/* memory clock */
856
	/* memory clock */
857
	u32 mclk;
857
	u32 mclk;
858
	/* engine clock */
858
	/* engine clock */
859
	u32 sclk;
859
	u32 sclk;
860
	/* voltage info */
860
	/* voltage info */
861
	struct radeon_voltage voltage;
861
	struct radeon_voltage voltage;
862
	/* standardized clock flags */
862
	/* standardized clock flags */
863
	u32 flags;
863
	u32 flags;
864
};
864
};
865
 
865
 
866
/* state flags */
866
/* state flags */
867
#define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
867
#define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
868
 
868
 
869
struct radeon_power_state {
869
struct radeon_power_state {
870
	enum radeon_pm_state_type type;
870
	enum radeon_pm_state_type type;
871
	/* XXX: use a define for num clock modes */
871
	/* XXX: use a define for num clock modes */
872
	struct radeon_pm_clock_info clock_info[8];
872
	struct radeon_pm_clock_info clock_info[8];
873
	/* number of valid clock modes in this power state */
873
	/* number of valid clock modes in this power state */
874
	int num_clock_modes;
874
	int num_clock_modes;
875
	struct radeon_pm_clock_info *default_clock_mode;
875
	struct radeon_pm_clock_info *default_clock_mode;
876
	/* standardized state flags */
876
	/* standardized state flags */
877
	u32 flags;
877
	u32 flags;
878
	u32 misc; /* vbios specific flags */
878
	u32 misc; /* vbios specific flags */
879
	u32 misc2; /* vbios specific flags */
879
	u32 misc2; /* vbios specific flags */
880
	int pcie_lanes; /* pcie lanes */
880
	int pcie_lanes; /* pcie lanes */
881
};
881
};
882
 
882
 
883
/*
883
/*
884
 * Some modes are overclocked by very low value, accept them
884
 * Some modes are overclocked by very low value, accept them
885
 */
885
 */
886
#define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
886
#define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
887
 
887
 
888
struct radeon_pm {
888
struct radeon_pm {
889
	struct mutex		mutex;
889
	struct mutex		mutex;
890
	u32			active_crtcs;
890
	u32			active_crtcs;
891
	int			active_crtc_count;
891
	int			active_crtc_count;
892
	int			req_vblank;
892
	int			req_vblank;
893
	bool			vblank_sync;
893
	bool			vblank_sync;
894
	bool			gui_idle;
894
	bool			gui_idle;
895
	fixed20_12		max_bandwidth;
895
	fixed20_12		max_bandwidth;
896
	fixed20_12		igp_sideport_mclk;
896
	fixed20_12		igp_sideport_mclk;
897
	fixed20_12		igp_system_mclk;
897
	fixed20_12		igp_system_mclk;
898
	fixed20_12		igp_ht_link_clk;
898
	fixed20_12		igp_ht_link_clk;
899
	fixed20_12		igp_ht_link_width;
899
	fixed20_12		igp_ht_link_width;
900
	fixed20_12		k8_bandwidth;
900
	fixed20_12		k8_bandwidth;
901
	fixed20_12		sideport_bandwidth;
901
	fixed20_12		sideport_bandwidth;
902
	fixed20_12		ht_bandwidth;
902
	fixed20_12		ht_bandwidth;
903
	fixed20_12		core_bandwidth;
903
	fixed20_12		core_bandwidth;
904
	fixed20_12		sclk;
904
	fixed20_12		sclk;
905
	fixed20_12		mclk;
905
	fixed20_12		mclk;
906
	fixed20_12		needed_bandwidth;
906
	fixed20_12		needed_bandwidth;
907
	struct radeon_power_state *power_state;
907
	struct radeon_power_state *power_state;
908
	/* number of valid power states */
908
	/* number of valid power states */
909
	int                     num_power_states;
909
	int                     num_power_states;
910
	int                     current_power_state_index;
910
	int                     current_power_state_index;
911
	int                     current_clock_mode_index;
911
	int                     current_clock_mode_index;
912
	int                     requested_power_state_index;
912
	int                     requested_power_state_index;
913
	int                     requested_clock_mode_index;
913
	int                     requested_clock_mode_index;
914
	int                     default_power_state_index;
914
	int                     default_power_state_index;
915
	u32                     current_sclk;
915
	u32                     current_sclk;
916
	u32                     current_mclk;
916
	u32                     current_mclk;
917
	u16                     current_vddc;
917
	u16                     current_vddc;
918
	u16                     current_vddci;
918
	u16                     current_vddci;
919
	u32                     default_sclk;
919
	u32                     default_sclk;
920
	u32                     default_mclk;
920
	u32                     default_mclk;
921
	u16                     default_vddc;
921
	u16                     default_vddc;
922
	u16                     default_vddci;
922
	u16                     default_vddci;
923
	struct radeon_i2c_chan *i2c_bus;
923
	struct radeon_i2c_chan *i2c_bus;
924
	/* selected pm method */
924
	/* selected pm method */
925
	enum radeon_pm_method     pm_method;
925
	enum radeon_pm_method     pm_method;
926
	/* dynpm power management */
926
	/* dynpm power management */
927
//   struct delayed_work dynpm_idle_work;
927
//   struct delayed_work dynpm_idle_work;
928
	enum radeon_dynpm_state	dynpm_state;
928
	enum radeon_dynpm_state	dynpm_state;
929
	enum radeon_dynpm_action	dynpm_planned_action;
929
	enum radeon_dynpm_action	dynpm_planned_action;
930
	unsigned long		dynpm_action_timeout;
930
	unsigned long		dynpm_action_timeout;
931
	bool                    dynpm_can_upclock;
931
	bool                    dynpm_can_upclock;
932
	bool                    dynpm_can_downclock;
932
	bool                    dynpm_can_downclock;
933
	/* profile-based power management */
933
	/* profile-based power management */
934
	enum radeon_pm_profile_type profile;
934
	enum radeon_pm_profile_type profile;
935
	int                     profile_index;
935
	int                     profile_index;
936
	struct radeon_pm_profile profiles[PM_PROFILE_MAX];
936
	struct radeon_pm_profile profiles[PM_PROFILE_MAX];
937
	/* internal thermal controller on rv6xx+ */
937
	/* internal thermal controller on rv6xx+ */
938
	enum radeon_int_thermal_type int_thermal_type;
938
	enum radeon_int_thermal_type int_thermal_type;
939
	struct device	        *int_hwmon_dev;
939
	struct device	        *int_hwmon_dev;
940
};
940
};
941
 
941
 
942
/*
942
/*
943
 * ASIC specific functions.
943
 * ASIC specific functions.
944
 */
944
 */
945
struct radeon_asic {
945
struct radeon_asic {
946
	int (*init)(struct radeon_device *rdev);
946
	int (*init)(struct radeon_device *rdev);
947
	void (*fini)(struct radeon_device *rdev);
947
	void (*fini)(struct radeon_device *rdev);
948
	int (*resume)(struct radeon_device *rdev);
948
	int (*resume)(struct radeon_device *rdev);
949
	int (*suspend)(struct radeon_device *rdev);
949
	int (*suspend)(struct radeon_device *rdev);
950
	void (*vga_set_state)(struct radeon_device *rdev, bool state);
950
	void (*vga_set_state)(struct radeon_device *rdev, bool state);
951
	bool (*gpu_is_lockup)(struct radeon_device *rdev);
951
	bool (*gpu_is_lockup)(struct radeon_device *rdev);
952
	int (*asic_reset)(struct radeon_device *rdev);
952
	int (*asic_reset)(struct radeon_device *rdev);
953
	void (*gart_tlb_flush)(struct radeon_device *rdev);
953
	void (*gart_tlb_flush)(struct radeon_device *rdev);
954
	int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
954
	int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
955
	int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
955
	int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
956
	void (*cp_fini)(struct radeon_device *rdev);
956
	void (*cp_fini)(struct radeon_device *rdev);
957
	void (*cp_disable)(struct radeon_device *rdev);
957
	void (*cp_disable)(struct radeon_device *rdev);
958
	void (*cp_commit)(struct radeon_device *rdev);
958
	void (*cp_commit)(struct radeon_device *rdev);
959
	void (*ring_start)(struct radeon_device *rdev);
959
	void (*ring_start)(struct radeon_device *rdev);
960
	int (*ring_test)(struct radeon_device *rdev);
960
	int (*ring_test)(struct radeon_device *rdev);
961
	void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
961
	void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
962
	int (*irq_set)(struct radeon_device *rdev);
962
	int (*irq_set)(struct radeon_device *rdev);
963
	int (*irq_process)(struct radeon_device *rdev);
963
	int (*irq_process)(struct radeon_device *rdev);
964
	u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
964
	u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
965
	void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
965
	void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
966
	int (*cs_parse)(struct radeon_cs_parser *p);
966
	int (*cs_parse)(struct radeon_cs_parser *p);
967
	int (*copy_blit)(struct radeon_device *rdev,
967
	int (*copy_blit)(struct radeon_device *rdev,
968
			 uint64_t src_offset,
968
			 uint64_t src_offset,
969
			 uint64_t dst_offset,
969
			 uint64_t dst_offset,
970
			 unsigned num_pages,
970
			 unsigned num_pages,
971
			 struct radeon_fence *fence);
971
			 struct radeon_fence *fence);
972
	int (*copy_dma)(struct radeon_device *rdev,
972
	int (*copy_dma)(struct radeon_device *rdev,
973
			uint64_t src_offset,
973
			uint64_t src_offset,
974
			uint64_t dst_offset,
974
			uint64_t dst_offset,
975
			unsigned num_pages,
975
			unsigned num_pages,
976
			struct radeon_fence *fence);
976
			struct radeon_fence *fence);
977
	int (*copy)(struct radeon_device *rdev,
977
	int (*copy)(struct radeon_device *rdev,
978
		    uint64_t src_offset,
978
		    uint64_t src_offset,
979
		    uint64_t dst_offset,
979
		    uint64_t dst_offset,
980
		    unsigned num_pages,
980
		    unsigned num_pages,
981
		    struct radeon_fence *fence);
981
		    struct radeon_fence *fence);
982
	uint32_t (*get_engine_clock)(struct radeon_device *rdev);
982
	uint32_t (*get_engine_clock)(struct radeon_device *rdev);
983
	void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
983
	void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
984
	uint32_t (*get_memory_clock)(struct radeon_device *rdev);
984
	uint32_t (*get_memory_clock)(struct radeon_device *rdev);
985
	void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
985
	void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
986
	int (*get_pcie_lanes)(struct radeon_device *rdev);
986
	int (*get_pcie_lanes)(struct radeon_device *rdev);
987
	void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
987
	void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
988
	void (*set_clock_gating)(struct radeon_device *rdev, int enable);
988
	void (*set_clock_gating)(struct radeon_device *rdev, int enable);
989
	int (*set_surface_reg)(struct radeon_device *rdev, int reg,
989
	int (*set_surface_reg)(struct radeon_device *rdev, int reg,
990
			       uint32_t tiling_flags, uint32_t pitch,
990
			       uint32_t tiling_flags, uint32_t pitch,
991
			       uint32_t offset, uint32_t obj_size);
991
			       uint32_t offset, uint32_t obj_size);
992
	void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
992
	void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
993
	void (*bandwidth_update)(struct radeon_device *rdev);
993
	void (*bandwidth_update)(struct radeon_device *rdev);
994
	void (*hpd_init)(struct radeon_device *rdev);
994
	void (*hpd_init)(struct radeon_device *rdev);
995
	void (*hpd_fini)(struct radeon_device *rdev);
995
	void (*hpd_fini)(struct radeon_device *rdev);
996
	bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
996
	bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
997
	void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
997
	void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
998
	/* ioctl hw specific callback. Some hw might want to perform special
998
	/* ioctl hw specific callback. Some hw might want to perform special
999
	 * operation on specific ioctl. For instance on wait idle some hw
999
	 * operation on specific ioctl. For instance on wait idle some hw
1000
	 * might want to perform and HDP flush through MMIO as it seems that
1000
	 * might want to perform and HDP flush through MMIO as it seems that
1001
	 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
1001
	 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
1002
	 * through ring.
1002
	 * through ring.
1003
	 */
1003
	 */
1004
	void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
1004
	void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
1005
	bool (*gui_idle)(struct radeon_device *rdev);
1005
	bool (*gui_idle)(struct radeon_device *rdev);
1006
	/* power management */
1006
	/* power management */
1007
	void (*pm_misc)(struct radeon_device *rdev);
1007
	void (*pm_misc)(struct radeon_device *rdev);
1008
	void (*pm_prepare)(struct radeon_device *rdev);
1008
	void (*pm_prepare)(struct radeon_device *rdev);
1009
	void (*pm_finish)(struct radeon_device *rdev);
1009
	void (*pm_finish)(struct radeon_device *rdev);
1010
	void (*pm_init_profile)(struct radeon_device *rdev);
1010
	void (*pm_init_profile)(struct radeon_device *rdev);
1011
	void (*pm_get_dynpm_state)(struct radeon_device *rdev);
1011
	void (*pm_get_dynpm_state)(struct radeon_device *rdev);
1012
	/* pageflipping */
1012
	/* pageflipping */
1013
	void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
1013
	void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
1014
	u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
1014
	u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
1015
	void (*post_page_flip)(struct radeon_device *rdev, int crtc);
1015
	void (*post_page_flip)(struct radeon_device *rdev, int crtc);
1016
};
1016
};
1017
 
1017
 
1018
/*
1018
/*
1019
 * Asic structures
1019
 * Asic structures
1020
 */
1020
 */
1021
struct r100_gpu_lockup {
1021
struct r100_gpu_lockup {
1022
	unsigned long	last_jiffies;
1022
	unsigned long	last_jiffies;
1023
	u32		last_cp_rptr;
1023
	u32		last_cp_rptr;
1024
};
1024
};
1025
 
1025
 
1026
struct r100_asic {
1026
struct r100_asic {
1027
	const unsigned	*reg_safe_bm;
1027
	const unsigned	*reg_safe_bm;
1028
	unsigned	reg_safe_bm_size;
1028
	unsigned	reg_safe_bm_size;
1029
	u32		hdp_cntl;
1029
	u32		hdp_cntl;
1030
	struct r100_gpu_lockup	lockup;
1030
	struct r100_gpu_lockup	lockup;
1031
};
1031
};
1032
 
1032
 
1033
struct r300_asic {
1033
struct r300_asic {
1034
	const unsigned	*reg_safe_bm;
1034
	const unsigned	*reg_safe_bm;
1035
	unsigned	reg_safe_bm_size;
1035
	unsigned	reg_safe_bm_size;
1036
	u32		resync_scratch;
1036
	u32		resync_scratch;
1037
	u32		hdp_cntl;
1037
	u32		hdp_cntl;
1038
	struct r100_gpu_lockup	lockup;
1038
	struct r100_gpu_lockup	lockup;
1039
};
1039
};
1040
 
1040
 
1041
struct r600_asic {
1041
struct r600_asic {
1042
	unsigned max_pipes;
1042
	unsigned max_pipes;
1043
	unsigned max_tile_pipes;
1043
	unsigned max_tile_pipes;
1044
	unsigned max_simds;
1044
	unsigned max_simds;
1045
	unsigned max_backends;
1045
	unsigned max_backends;
1046
	unsigned max_gprs;
1046
	unsigned max_gprs;
1047
	unsigned max_threads;
1047
	unsigned max_threads;
1048
	unsigned max_stack_entries;
1048
	unsigned max_stack_entries;
1049
	unsigned max_hw_contexts;
1049
	unsigned max_hw_contexts;
1050
	unsigned max_gs_threads;
1050
	unsigned max_gs_threads;
1051
	unsigned sx_max_export_size;
1051
	unsigned sx_max_export_size;
1052
	unsigned sx_max_export_pos_size;
1052
	unsigned sx_max_export_pos_size;
1053
	unsigned sx_max_export_smx_size;
1053
	unsigned sx_max_export_smx_size;
1054
	unsigned sq_num_cf_insts;
1054
	unsigned sq_num_cf_insts;
1055
	unsigned tiling_nbanks;
1055
	unsigned tiling_nbanks;
1056
	unsigned tiling_npipes;
1056
	unsigned tiling_npipes;
1057
	unsigned tiling_group_size;
1057
	unsigned tiling_group_size;
1058
	unsigned		tile_config;
1058
	unsigned		tile_config;
1059
	unsigned		backend_map;
1059
	unsigned		backend_map;
1060
	struct r100_gpu_lockup	lockup;
1060
	struct r100_gpu_lockup	lockup;
1061
};
1061
};
1062
 
1062
 
1063
struct rv770_asic {
1063
struct rv770_asic {
1064
	unsigned max_pipes;
1064
	unsigned max_pipes;
1065
	unsigned max_tile_pipes;
1065
	unsigned max_tile_pipes;
1066
	unsigned max_simds;
1066
	unsigned max_simds;
1067
	unsigned max_backends;
1067
	unsigned max_backends;
1068
	unsigned max_gprs;
1068
	unsigned max_gprs;
1069
	unsigned max_threads;
1069
	unsigned max_threads;
1070
	unsigned max_stack_entries;
1070
	unsigned max_stack_entries;
1071
	unsigned max_hw_contexts;
1071
	unsigned max_hw_contexts;
1072
	unsigned max_gs_threads;
1072
	unsigned max_gs_threads;
1073
	unsigned sx_max_export_size;
1073
	unsigned sx_max_export_size;
1074
	unsigned sx_max_export_pos_size;
1074
	unsigned sx_max_export_pos_size;
1075
	unsigned sx_max_export_smx_size;
1075
	unsigned sx_max_export_smx_size;
1076
	unsigned sq_num_cf_insts;
1076
	unsigned sq_num_cf_insts;
1077
	unsigned sx_num_of_sets;
1077
	unsigned sx_num_of_sets;
1078
	unsigned sc_prim_fifo_size;
1078
	unsigned sc_prim_fifo_size;
1079
	unsigned sc_hiz_tile_fifo_size;
1079
	unsigned sc_hiz_tile_fifo_size;
1080
	unsigned sc_earlyz_tile_fifo_fize;
1080
	unsigned sc_earlyz_tile_fifo_fize;
1081
	unsigned tiling_nbanks;
1081
	unsigned tiling_nbanks;
1082
	unsigned tiling_npipes;
1082
	unsigned tiling_npipes;
1083
	unsigned tiling_group_size;
1083
	unsigned tiling_group_size;
1084
	unsigned		tile_config;
1084
	unsigned		tile_config;
1085
	unsigned		backend_map;
1085
	unsigned		backend_map;
1086
	struct r100_gpu_lockup	lockup;
1086
	struct r100_gpu_lockup	lockup;
1087
};
1087
};
1088
 
1088
 
1089
struct evergreen_asic {
1089
struct evergreen_asic {
1090
	unsigned num_ses;
1090
	unsigned num_ses;
1091
	unsigned max_pipes;
1091
	unsigned max_pipes;
1092
	unsigned max_tile_pipes;
1092
	unsigned max_tile_pipes;
1093
	unsigned max_simds;
1093
	unsigned max_simds;
1094
	unsigned max_backends;
1094
	unsigned max_backends;
1095
	unsigned max_gprs;
1095
	unsigned max_gprs;
1096
	unsigned max_threads;
1096
	unsigned max_threads;
1097
	unsigned max_stack_entries;
1097
	unsigned max_stack_entries;
1098
	unsigned max_hw_contexts;
1098
	unsigned max_hw_contexts;
1099
	unsigned max_gs_threads;
1099
	unsigned max_gs_threads;
1100
	unsigned sx_max_export_size;
1100
	unsigned sx_max_export_size;
1101
	unsigned sx_max_export_pos_size;
1101
	unsigned sx_max_export_pos_size;
1102
	unsigned sx_max_export_smx_size;
1102
	unsigned sx_max_export_smx_size;
1103
	unsigned sq_num_cf_insts;
1103
	unsigned sq_num_cf_insts;
1104
	unsigned sx_num_of_sets;
1104
	unsigned sx_num_of_sets;
1105
	unsigned sc_prim_fifo_size;
1105
	unsigned sc_prim_fifo_size;
1106
	unsigned sc_hiz_tile_fifo_size;
1106
	unsigned sc_hiz_tile_fifo_size;
1107
	unsigned sc_earlyz_tile_fifo_size;
1107
	unsigned sc_earlyz_tile_fifo_size;
1108
	unsigned tiling_nbanks;
1108
	unsigned tiling_nbanks;
1109
	unsigned tiling_npipes;
1109
	unsigned tiling_npipes;
1110
	unsigned tiling_group_size;
1110
	unsigned tiling_group_size;
1111
	unsigned tile_config;
1111
	unsigned tile_config;
1112
	unsigned backend_map;
1112
	unsigned backend_map;
1113
	struct r100_gpu_lockup	lockup;
1113
	struct r100_gpu_lockup	lockup;
1114
};
1114
};
1115
 
1115
 
1116
struct cayman_asic {
1116
struct cayman_asic {
1117
	unsigned max_shader_engines;
1117
	unsigned max_shader_engines;
1118
	unsigned max_pipes_per_simd;
1118
	unsigned max_pipes_per_simd;
1119
	unsigned max_tile_pipes;
1119
	unsigned max_tile_pipes;
1120
	unsigned max_simds_per_se;
1120
	unsigned max_simds_per_se;
1121
	unsigned max_backends_per_se;
1121
	unsigned max_backends_per_se;
1122
	unsigned max_texture_channel_caches;
1122
	unsigned max_texture_channel_caches;
1123
	unsigned max_gprs;
1123
	unsigned max_gprs;
1124
	unsigned max_threads;
1124
	unsigned max_threads;
1125
	unsigned max_gs_threads;
1125
	unsigned max_gs_threads;
1126
	unsigned max_stack_entries;
1126
	unsigned max_stack_entries;
1127
	unsigned sx_num_of_sets;
1127
	unsigned sx_num_of_sets;
1128
	unsigned sx_max_export_size;
1128
	unsigned sx_max_export_size;
1129
	unsigned sx_max_export_pos_size;
1129
	unsigned sx_max_export_pos_size;
1130
	unsigned sx_max_export_smx_size;
1130
	unsigned sx_max_export_smx_size;
1131
	unsigned max_hw_contexts;
1131
	unsigned max_hw_contexts;
1132
	unsigned sq_num_cf_insts;
1132
	unsigned sq_num_cf_insts;
1133
	unsigned sc_prim_fifo_size;
1133
	unsigned sc_prim_fifo_size;
1134
	unsigned sc_hiz_tile_fifo_size;
1134
	unsigned sc_hiz_tile_fifo_size;
1135
	unsigned sc_earlyz_tile_fifo_size;
1135
	unsigned sc_earlyz_tile_fifo_size;
1136
 
1136
 
1137
	unsigned num_shader_engines;
1137
	unsigned num_shader_engines;
1138
	unsigned num_shader_pipes_per_simd;
1138
	unsigned num_shader_pipes_per_simd;
1139
	unsigned num_tile_pipes;
1139
	unsigned num_tile_pipes;
1140
	unsigned num_simds_per_se;
1140
	unsigned num_simds_per_se;
1141
	unsigned num_backends_per_se;
1141
	unsigned num_backends_per_se;
1142
	unsigned backend_disable_mask_per_asic;
1142
	unsigned backend_disable_mask_per_asic;
1143
	unsigned backend_map;
1143
	unsigned backend_map;
1144
	unsigned num_texture_channel_caches;
1144
	unsigned num_texture_channel_caches;
1145
	unsigned mem_max_burst_length_bytes;
1145
	unsigned mem_max_burst_length_bytes;
1146
	unsigned mem_row_size_in_kb;
1146
	unsigned mem_row_size_in_kb;
1147
	unsigned shader_engine_tile_size;
1147
	unsigned shader_engine_tile_size;
1148
	unsigned num_gpus;
1148
	unsigned num_gpus;
1149
	unsigned multi_gpu_tile_size;
1149
	unsigned multi_gpu_tile_size;
1150
 
1150
 
1151
	unsigned tile_config;
1151
	unsigned tile_config;
1152
	struct r100_gpu_lockup	lockup;
1152
	struct r100_gpu_lockup	lockup;
1153
};
1153
};
1154
 
1154
 
1155
union radeon_asic_config {
1155
union radeon_asic_config {
1156
	struct r300_asic	r300;
1156
	struct r300_asic	r300;
1157
	struct r100_asic	r100;
1157
	struct r100_asic	r100;
1158
	struct r600_asic	r600;
1158
	struct r600_asic	r600;
1159
	struct rv770_asic	rv770;
1159
	struct rv770_asic	rv770;
1160
	struct evergreen_asic	evergreen;
1160
	struct evergreen_asic	evergreen;
1161
	struct cayman_asic	cayman;
1161
	struct cayman_asic	cayman;
1162
};
1162
};
1163
 
1163
 
1164
/*
1164
/*
1165
 * asic initizalization from radeon_asic.c
1165
 * asic initizalization from radeon_asic.c
1166
 */
1166
 */
1167
void radeon_agp_disable(struct radeon_device *rdev);
1167
void radeon_agp_disable(struct radeon_device *rdev);
1168
int radeon_asic_init(struct radeon_device *rdev);
1168
int radeon_asic_init(struct radeon_device *rdev);
1169
 
1169
 
1170
 
1170
 
1171
 
1171
 
1172
/* VRAM scratch page for HDP bug */
1172
/* VRAM scratch page for HDP bug */
1173
struct r700_vram_scratch {
1173
struct r700_vram_scratch {
1174
	struct radeon_bo		*robj;
1174
	struct radeon_bo		*robj;
1175
	volatile uint32_t		*ptr;
1175
	volatile uint32_t		*ptr;
1176
};
1176
};
1177
 
1177
 
1178
/*
1178
/*
1179
 * Core structure, functions and helpers.
1179
 * Core structure, functions and helpers.
1180
 */
1180
 */
1181
typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1181
typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1182
typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1182
typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1183
 
1183
 
1184
struct radeon_device {
1184
struct radeon_device {
1185
	struct device			*dev;
1185
	struct device			*dev;
1186
    struct drm_device          *ddev;
1186
    struct drm_device          *ddev;
1187
    struct pci_dev             *pdev;
1187
    struct pci_dev             *pdev;
1188
    /* ASIC */
1188
    /* ASIC */
1189
    union radeon_asic_config    config;
1189
    union radeon_asic_config    config;
1190
    enum radeon_family          family;
1190
    enum radeon_family          family;
1191
    unsigned long               flags;
1191
    unsigned long               flags;
1192
    int                         usec_timeout;
1192
    int                         usec_timeout;
1193
    enum radeon_pll_errata      pll_errata;
1193
    enum radeon_pll_errata      pll_errata;
1194
    int                         num_gb_pipes;
1194
    int                         num_gb_pipes;
1195
	int				            num_z_pipes;
1195
	int				            num_z_pipes;
1196
    int                         disp_priority;
1196
    int                         disp_priority;
1197
    /* BIOS */
1197
    /* BIOS */
1198
    uint8_t                     *bios;
1198
    uint8_t                     *bios;
1199
    bool                        is_atom_bios;
1199
    bool                        is_atom_bios;
1200
    uint16_t                    bios_header_start;
1200
    uint16_t                    bios_header_start;
1201
	struct radeon_bo		    *stollen_vga_memory;
1201
	struct radeon_bo		    *stollen_vga_memory;
1202
    /* Register mmio */
1202
    /* Register mmio */
1203
	resource_size_t			rmmio_base;
1203
	resource_size_t			rmmio_base;
1204
	resource_size_t			rmmio_size;
1204
	resource_size_t			rmmio_size;
1205
    void                       *rmmio;
1205
    void                       *rmmio;
1206
    radeon_rreg_t               mc_rreg;
1206
    radeon_rreg_t               mc_rreg;
1207
    radeon_wreg_t               mc_wreg;
1207
    radeon_wreg_t               mc_wreg;
1208
    radeon_rreg_t               pll_rreg;
1208
    radeon_rreg_t               pll_rreg;
1209
    radeon_wreg_t               pll_wreg;
1209
    radeon_wreg_t               pll_wreg;
1210
	uint32_t                        pcie_reg_mask;
1210
	uint32_t                        pcie_reg_mask;
1211
    radeon_rreg_t               pciep_rreg;
1211
    radeon_rreg_t               pciep_rreg;
1212
    radeon_wreg_t               pciep_wreg;
1212
    radeon_wreg_t               pciep_wreg;
1213
	/* io port */
1213
	/* io port */
1214
	void __iomem                    *rio_mem;
1214
	void __iomem                    *rio_mem;
1215
	resource_size_t			rio_mem_size;
1215
	resource_size_t			rio_mem_size;
1216
    struct radeon_clock         clock;
1216
    struct radeon_clock         clock;
1217
    struct radeon_mc            mc;
1217
    struct radeon_mc            mc;
1218
    struct radeon_gart          gart;
1218
    struct radeon_gart          gart;
1219
	struct radeon_mode_info		mode_info;
1219
	struct radeon_mode_info		mode_info;
1220
    struct radeon_scratch       scratch;
1220
    struct radeon_scratch       scratch;
1221
    struct radeon_mman          mman;
1221
    struct radeon_mman          mman;
1222
	struct radeon_fence_driver	fence_drv;
1222
	struct radeon_fence_driver	fence_drv;
1223
    struct radeon_cp            cp;
1223
    struct radeon_cp            cp;
1224
	/* cayman compute rings */
1224
	/* cayman compute rings */
1225
	struct radeon_cp		cp1;
1225
	struct radeon_cp		cp1;
1226
	struct radeon_cp		cp2;
1226
	struct radeon_cp		cp2;
1227
    struct radeon_ib_pool       ib_pool;
1227
    struct radeon_ib_pool       ib_pool;
1228
    struct radeon_irq       irq;
1228
    struct radeon_irq       irq;
1229
    struct radeon_asic         *asic;
1229
    struct radeon_asic         *asic;
1230
    struct radeon_gem       gem;
1230
    struct radeon_gem       gem;
1231
	struct radeon_pm		pm;
1231
	struct radeon_pm		pm;
1232
	uint32_t			bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1232
	uint32_t			bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1233
	struct mutex			cs_mutex;
1233
	struct mutex			cs_mutex;
1234
    struct radeon_wb        wb;
1234
    struct radeon_wb        wb;
1235
	struct radeon_dummy_page	dummy_page;
1235
	struct radeon_dummy_page	dummy_page;
1236
    bool                gpu_lockup;
1236
    bool                gpu_lockup;
1237
    bool                shutdown;
1237
    bool                shutdown;
1238
    bool                suspend;
1238
    bool                suspend;
1239
	bool				need_dma32;
1239
	bool				need_dma32;
1240
	bool				accel_working;
1240
	bool				accel_working;
1241
	struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
1241
	struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
1242
	const struct firmware *me_fw;	/* all family ME firmware */
1242
	const struct firmware *me_fw;	/* all family ME firmware */
1243
	const struct firmware *pfp_fw;	/* r6/700 PFP firmware */
1243
	const struct firmware *pfp_fw;	/* r6/700 PFP firmware */
1244
	const struct firmware *rlc_fw;	/* r6/700 RLC firmware */
1244
	const struct firmware *rlc_fw;	/* r6/700 RLC firmware */
1245
	const struct firmware *mc_fw;	/* NI MC firmware */
1245
	const struct firmware *mc_fw;	/* NI MC firmware */
1246
	struct r600_blit r600_blit;
1246
	struct r600_blit r600_blit;
-
 
1247
    struct r600_blit r600_video;
1247
	struct r700_vram_scratch vram_scratch;
1248
	struct r700_vram_scratch vram_scratch;
1248
	int msi_enabled; /* msi enabled */
1249
	int msi_enabled; /* msi enabled */
1249
	struct r600_ih ih; /* r6/700 interrupt ring */
1250
	struct r600_ih ih; /* r6/700 interrupt ring */
1250
//	struct work_struct hotplug_work;
1251
//	struct work_struct hotplug_work;
1251
	int num_crtc; /* number of crtcs */
1252
	int num_crtc; /* number of crtcs */
1252
	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
1253
	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
1253
	struct mutex vram_mutex;
1254
	struct mutex vram_mutex;
1254
 
1255
 
1255
	/* audio stuff */
1256
	/* audio stuff */
1256
	bool			audio_enabled;
1257
	bool			audio_enabled;
1257
//	struct timer_list	audio_timer;
1258
//	struct timer_list	audio_timer;
1258
	int			audio_channels;
1259
	int			audio_channels;
1259
	int			audio_rate;
1260
	int			audio_rate;
1260
	int			audio_bits_per_sample;
1261
	int			audio_bits_per_sample;
1261
	uint8_t			audio_status_bits;
1262
	uint8_t			audio_status_bits;
1262
	uint8_t			audio_category_code;
1263
	uint8_t			audio_category_code;
1263
 
1264
 
1264
 
1265
 
1265
	/* i2c buses */
1266
	/* i2c buses */
1266
	struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1267
	struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1267
};
1268
};
1268
 
1269
 
1269
int radeon_device_init(struct radeon_device *rdev,
1270
int radeon_device_init(struct radeon_device *rdev,
1270
		       struct drm_device *ddev,
1271
		       struct drm_device *ddev,
1271
		       struct pci_dev *pdev,
1272
		       struct pci_dev *pdev,
1272
		       uint32_t flags);
1273
		       uint32_t flags);
1273
void radeon_device_fini(struct radeon_device *rdev);
1274
void radeon_device_fini(struct radeon_device *rdev);
1274
int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
1275
int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
1275
 
1276
 
1276
static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
1277
static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
1277
{
1278
{
1278
	if (reg < rdev->rmmio_size)
1279
	if (reg < rdev->rmmio_size)
1279
		return readl(((void __iomem *)rdev->rmmio) + reg);
1280
		return readl(((void __iomem *)rdev->rmmio) + reg);
1280
	else {
1281
	else {
1281
		writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1282
		writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1282
		return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1283
		return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1283
	}
1284
	}
1284
}
1285
}
1285
 
1286
 
1286
static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1287
static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1287
{
1288
{
1288
	if (reg < rdev->rmmio_size)
1289
	if (reg < rdev->rmmio_size)
1289
		writel(v, ((void __iomem *)rdev->rmmio) + reg);
1290
		writel(v, ((void __iomem *)rdev->rmmio) + reg);
1290
	else {
1291
	else {
1291
		writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1292
		writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1292
		writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1293
		writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1293
	}
1294
	}
1294
}
1295
}
1295
 
1296
 
1296
static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
1297
static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
1297
{
1298
{
1298
	if (reg < rdev->rio_mem_size)
1299
	if (reg < rdev->rio_mem_size)
1299
		return ioread32(rdev->rio_mem + reg);
1300
		return ioread32(rdev->rio_mem + reg);
1300
	else {
1301
	else {
1301
		iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1302
		iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1302
		return ioread32(rdev->rio_mem + RADEON_MM_DATA);
1303
		return ioread32(rdev->rio_mem + RADEON_MM_DATA);
1303
	}
1304
	}
1304
}
1305
}
1305
 
1306
 
1306
static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1307
static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1307
{
1308
{
1308
	if (reg < rdev->rio_mem_size)
1309
	if (reg < rdev->rio_mem_size)
1309
		iowrite32(v, rdev->rio_mem + reg);
1310
		iowrite32(v, rdev->rio_mem + reg);
1310
	else {
1311
	else {
1311
		iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1312
		iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1312
		iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
1313
		iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
1313
	}
1314
	}
1314
}
1315
}
1315
 
1316
 
1316
/*
1317
/*
1317
 * Cast helper
1318
 * Cast helper
1318
 */
1319
 */
1319
#define to_radeon_fence(p) ((struct radeon_fence *)(p))
1320
#define to_radeon_fence(p) ((struct radeon_fence *)(p))
1320
 
1321
 
1321
/*
1322
/*
1322
 * Registers read & write functions.
1323
 * Registers read & write functions.
1323
 */
1324
 */
1324
#define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
1325
#define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
1325
#define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
1326
#define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
1326
#define RREG16(reg) readw(((void __iomem *)rdev->rmmio) + (reg))
1327
#define RREG16(reg) readw(((void __iomem *)rdev->rmmio) + (reg))
1327
#define WREG16(reg, v) writew(v, ((void __iomem *)rdev->rmmio) + (reg))
1328
#define WREG16(reg, v) writew(v, ((void __iomem *)rdev->rmmio) + (reg))
1328
#define RREG32(reg) r100_mm_rreg(rdev, (reg))
1329
#define RREG32(reg) r100_mm_rreg(rdev, (reg))
1329
#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
1330
#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
1330
#define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
1331
#define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
1331
#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1332
#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1332
#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1333
#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1333
#define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1334
#define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1334
#define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1335
#define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1335
#define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1336
#define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1336
#define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
1337
#define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
1337
#define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1338
#define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1338
#define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
1339
#define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
1339
#define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1340
#define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1340
#define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
1341
#define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
1341
#define WREG32_P(reg, val, mask)				\
1342
#define WREG32_P(reg, val, mask)				\
1342
	do {							\
1343
	do {							\
1343
		uint32_t tmp_ = RREG32(reg);			\
1344
		uint32_t tmp_ = RREG32(reg);			\
1344
		tmp_ &= (mask);					\
1345
		tmp_ &= (mask);					\
1345
		tmp_ |= ((val) & ~(mask));			\
1346
		tmp_ |= ((val) & ~(mask));			\
1346
		WREG32(reg, tmp_);				\
1347
		WREG32(reg, tmp_);				\
1347
	} while (0)
1348
	} while (0)
1348
#define WREG32_PLL_P(reg, val, mask)				\
1349
#define WREG32_PLL_P(reg, val, mask)				\
1349
	do {							\
1350
	do {							\
1350
		uint32_t tmp_ = RREG32_PLL(reg);		\
1351
		uint32_t tmp_ = RREG32_PLL(reg);		\
1351
		tmp_ &= (mask);					\
1352
		tmp_ &= (mask);					\
1352
		tmp_ |= ((val) & ~(mask));			\
1353
		tmp_ |= ((val) & ~(mask));			\
1353
		WREG32_PLL(reg, tmp_);				\
1354
		WREG32_PLL(reg, tmp_);				\
1354
	} while (0)
1355
	} while (0)
1355
#define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
1356
#define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
1356
#define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
1357
#define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
1357
 
1358
 
1358
/*
1359
/*
1359
 * Indirect registers accessor
1360
 * Indirect registers accessor
1360
 */
1361
 */
1361
static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1362
static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1362
{
1363
{
1363
	uint32_t r;
1364
	uint32_t r;
1364
 
1365
 
1365
	WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1366
	WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1366
	r = RREG32(RADEON_PCIE_DATA);
1367
	r = RREG32(RADEON_PCIE_DATA);
1367
	return r;
1368
	return r;
1368
}
1369
}
1369
 
1370
 
1370
static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1371
static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1371
{
1372
{
1372
	WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1373
	WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1373
	WREG32(RADEON_PCIE_DATA, (v));
1374
	WREG32(RADEON_PCIE_DATA, (v));
1374
}
1375
}
1375
 
1376
 
1376
void r100_pll_errata_after_index(struct radeon_device *rdev);
1377
void r100_pll_errata_after_index(struct radeon_device *rdev);
1377
 
1378
 
1378
 
1379
 
1379
/*
1380
/*
1380
 * ASICs helpers.
1381
 * ASICs helpers.
1381
 */
1382
 */
1382
#define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1383
#define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1383
			    (rdev->pdev->device == 0x5969))
1384
			    (rdev->pdev->device == 0x5969))
1384
#define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1385
#define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1385
        (rdev->family == CHIP_RV200) || \
1386
        (rdev->family == CHIP_RV200) || \
1386
        (rdev->family == CHIP_RS100) || \
1387
        (rdev->family == CHIP_RS100) || \
1387
        (rdev->family == CHIP_RS200) || \
1388
        (rdev->family == CHIP_RS200) || \
1388
        (rdev->family == CHIP_RV250) || \
1389
        (rdev->family == CHIP_RV250) || \
1389
        (rdev->family == CHIP_RV280) || \
1390
        (rdev->family == CHIP_RV280) || \
1390
        (rdev->family == CHIP_RS300))
1391
        (rdev->family == CHIP_RS300))
1391
#define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  || \
1392
#define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  || \
1392
        (rdev->family == CHIP_RV350) ||         \
1393
        (rdev->family == CHIP_RV350) ||         \
1393
        (rdev->family == CHIP_R350)  ||         \
1394
        (rdev->family == CHIP_R350)  ||         \
1394
        (rdev->family == CHIP_RV380) ||         \
1395
        (rdev->family == CHIP_RV380) ||         \
1395
        (rdev->family == CHIP_R420)  ||         \
1396
        (rdev->family == CHIP_R420)  ||         \
1396
        (rdev->family == CHIP_R423)  ||         \
1397
        (rdev->family == CHIP_R423)  ||         \
1397
        (rdev->family == CHIP_RV410) ||         \
1398
        (rdev->family == CHIP_RV410) ||         \
1398
        (rdev->family == CHIP_RS400) ||         \
1399
        (rdev->family == CHIP_RS400) ||         \
1399
        (rdev->family == CHIP_RS480))
1400
        (rdev->family == CHIP_RS480))
1400
#define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
1401
#define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
1401
		(rdev->ddev->pdev->device == 0x9443) || \
1402
		(rdev->ddev->pdev->device == 0x9443) || \
1402
		(rdev->ddev->pdev->device == 0x944B) || \
1403
		(rdev->ddev->pdev->device == 0x944B) || \
1403
		(rdev->ddev->pdev->device == 0x9506) || \
1404
		(rdev->ddev->pdev->device == 0x9506) || \
1404
		(rdev->ddev->pdev->device == 0x9509) || \
1405
		(rdev->ddev->pdev->device == 0x9509) || \
1405
		(rdev->ddev->pdev->device == 0x950F) || \
1406
		(rdev->ddev->pdev->device == 0x950F) || \
1406
		(rdev->ddev->pdev->device == 0x689C) || \
1407
		(rdev->ddev->pdev->device == 0x689C) || \
1407
		(rdev->ddev->pdev->device == 0x689D))
1408
		(rdev->ddev->pdev->device == 0x689D))
1408
#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1409
#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1409
#define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600)  ||	\
1410
#define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600)  ||	\
1410
			    (rdev->family == CHIP_RS690)  ||	\
1411
			    (rdev->family == CHIP_RS690)  ||	\
1411
			    (rdev->family == CHIP_RS740)  ||	\
1412
			    (rdev->family == CHIP_RS740)  ||	\
1412
			    (rdev->family >= CHIP_R600))
1413
			    (rdev->family >= CHIP_R600))
1413
#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1414
#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1414
#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
1415
#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
1415
#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
1416
#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
1416
#define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
1417
#define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
1417
			     (rdev->flags & RADEON_IS_IGP))
1418
			     (rdev->flags & RADEON_IS_IGP))
1418
#define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
1419
#define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
1419
 
1420
 
1420
/*
1421
/*
1421
 * BIOS helpers.
1422
 * BIOS helpers.
1422
 */
1423
 */
1423
#define RBIOS8(i) (rdev->bios[i])
1424
#define RBIOS8(i) (rdev->bios[i])
1424
#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1425
#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1425
#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1426
#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1426
 
1427
 
1427
int radeon_combios_init(struct radeon_device *rdev);
1428
int radeon_combios_init(struct radeon_device *rdev);
1428
void radeon_combios_fini(struct radeon_device *rdev);
1429
void radeon_combios_fini(struct radeon_device *rdev);
1429
int radeon_atombios_init(struct radeon_device *rdev);
1430
int radeon_atombios_init(struct radeon_device *rdev);
1430
void radeon_atombios_fini(struct radeon_device *rdev);
1431
void radeon_atombios_fini(struct radeon_device *rdev);
1431
 
1432
 
1432
 
1433
 
1433
/*
1434
/*
1434
 * RING helpers.
1435
 * RING helpers.
1435
 */
1436
 */
1436
static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
1437
static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
1437
{
1438
{
1438
#if DRM_DEBUG_CODE
1439
#if DRM_DEBUG_CODE
1439
	if (rdev->cp.count_dw <= 0) {
1440
	if (rdev->cp.count_dw <= 0) {
1440
		DRM_ERROR("radeon: writting more dword to ring than expected !\n");
1441
		DRM_ERROR("radeon: writting more dword to ring than expected !\n");
1441
	}
1442
	}
1442
#endif
1443
#endif
1443
	rdev->cp.ring[rdev->cp.wptr++] = v;
1444
	rdev->cp.ring[rdev->cp.wptr++] = v;
1444
	rdev->cp.wptr &= rdev->cp.ptr_mask;
1445
	rdev->cp.wptr &= rdev->cp.ptr_mask;
1445
	rdev->cp.count_dw--;
1446
	rdev->cp.count_dw--;
1446
	rdev->cp.ring_free_dw--;
1447
	rdev->cp.ring_free_dw--;
1447
}
1448
}
1448
 
1449
 
1449
 
1450
 
1450
/*
1451
/*
1451
 * ASICs macro.
1452
 * ASICs macro.
1452
 */
1453
 */
1453
#define radeon_init(rdev) (rdev)->asic->init((rdev))
1454
#define radeon_init(rdev) (rdev)->asic->init((rdev))
1454
#define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1455
#define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1455
#define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1456
#define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1456
#define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
1457
#define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
1457
#define radeon_cs_parse(p) rdev->asic->cs_parse((p))
1458
#define radeon_cs_parse(p) rdev->asic->cs_parse((p))
1458
#define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
1459
#define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
1459
#define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
1460
#define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
1460
#define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
1461
#define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
1461
#define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1462
#define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1462
#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
1463
#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
1463
#define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
1464
#define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
1464
#define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
1465
#define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
1465
#define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1466
#define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1466
#define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
1467
#define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
1467
#define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1468
#define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1468
#define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
1469
#define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
1469
#define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
1470
#define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
1470
#define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1471
#define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1471
#define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1472
#define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1472
#define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1473
#define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1473
#define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
1474
#define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
1474
#define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
1475
#define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
1475
#define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
1476
#define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
1476
#define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
1477
#define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
1477
#define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
1478
#define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
1478
#define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
1479
#define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
1479
#define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1480
#define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1480
#define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
1481
#define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
1481
#define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1482
#define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1482
#define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
1483
#define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
1483
#define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
1484
#define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
1484
#define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1485
#define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1485
#define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1486
#define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1486
#define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1487
#define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1487
#define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
1488
#define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
1488
#define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
1489
#define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
1489
#define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
1490
#define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
1490
#define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
1491
#define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
1491
#define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
1492
#define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
1492
#define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
1493
#define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
1493
#define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
1494
#define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
1494
#define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
1495
#define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
1495
#define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
1496
#define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
1496
#define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
1497
#define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
1497
 
1498
 
1498
/* Common functions */
1499
/* Common functions */
1499
/* AGP */
1500
/* AGP */
1500
extern int radeon_gpu_reset(struct radeon_device *rdev);
1501
extern int radeon_gpu_reset(struct radeon_device *rdev);
1501
extern void radeon_agp_disable(struct radeon_device *rdev);
1502
extern void radeon_agp_disable(struct radeon_device *rdev);
1502
extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
1503
extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
1503
extern void radeon_gart_restore(struct radeon_device *rdev);
1504
extern void radeon_gart_restore(struct radeon_device *rdev);
1504
extern int radeon_modeset_init(struct radeon_device *rdev);
1505
extern int radeon_modeset_init(struct radeon_device *rdev);
1505
extern void radeon_modeset_fini(struct radeon_device *rdev);
1506
extern void radeon_modeset_fini(struct radeon_device *rdev);
1506
extern bool radeon_card_posted(struct radeon_device *rdev);
1507
extern bool radeon_card_posted(struct radeon_device *rdev);
1507
extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
1508
extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
1508
extern void radeon_update_display_priority(struct radeon_device *rdev);
1509
extern void radeon_update_display_priority(struct radeon_device *rdev);
1509
extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
1510
extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
1510
extern void radeon_scratch_init(struct radeon_device *rdev);
1511
extern void radeon_scratch_init(struct radeon_device *rdev);
1511
extern void radeon_wb_fini(struct radeon_device *rdev);
1512
extern void radeon_wb_fini(struct radeon_device *rdev);
1512
extern int radeon_wb_init(struct radeon_device *rdev);
1513
extern int radeon_wb_init(struct radeon_device *rdev);
1513
extern void radeon_wb_disable(struct radeon_device *rdev);
1514
extern void radeon_wb_disable(struct radeon_device *rdev);
1514
extern void radeon_surface_init(struct radeon_device *rdev);
1515
extern void radeon_surface_init(struct radeon_device *rdev);
1515
extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
1516
extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
1516
extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
1517
extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
1517
extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
1518
extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
1518
extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
1519
extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
1519
extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
1520
extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
1520
extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1521
extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1521
extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
1522
extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
1522
extern int radeon_resume_kms(struct drm_device *dev);
1523
extern int radeon_resume_kms(struct drm_device *dev);
1523
extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
1524
extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
1524
extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
1525
extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
1525
 
1526
 
1526
/*
1527
/*
1527
 * r600 functions used by radeon_encoder.c
1528
 * r600 functions used by radeon_encoder.c
1528
 */
1529
 */
1529
extern void r600_hdmi_enable(struct drm_encoder *encoder);
1530
extern void r600_hdmi_enable(struct drm_encoder *encoder);
1530
extern void r600_hdmi_disable(struct drm_encoder *encoder);
1531
extern void r600_hdmi_disable(struct drm_encoder *encoder);
1531
extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1532
extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1532
 
1533
 
1533
extern int ni_init_microcode(struct radeon_device *rdev);
1534
extern int ni_init_microcode(struct radeon_device *rdev);
1534
extern int ni_mc_load_microcode(struct radeon_device *rdev);
1535
extern int ni_mc_load_microcode(struct radeon_device *rdev);
1535
 
1536
 
1536
/* radeon_acpi.c */
1537
/* radeon_acpi.c */
1537
#if defined(CONFIG_ACPI)
1538
#if defined(CONFIG_ACPI)
1538
extern int radeon_acpi_init(struct radeon_device *rdev);
1539
extern int radeon_acpi_init(struct radeon_device *rdev);
1539
#else
1540
#else
1540
static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
1541
static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
1541
#endif
1542
#endif
1542
 
1543
 
1543
#include "radeon_object.h"
1544
#include "radeon_object.h"
1544
 
1545
 
1545
#define DRM_UDELAY(d)           udelay(d)
1546
#define DRM_UDELAY(d)           udelay(d)
1546
 
1547
 
1547
resource_size_t
1548
resource_size_t
1548
drm_get_resource_start(struct drm_device *dev, unsigned int resource);
1549
drm_get_resource_start(struct drm_device *dev, unsigned int resource);
1549
resource_size_t
1550
resource_size_t
1550
drm_get_resource_len(struct drm_device *dev, unsigned int resource);
1551
drm_get_resource_len(struct drm_device *dev, unsigned int resource);
1551
 
1552
 
1552
bool set_mode(struct drm_device *dev, struct drm_connector *connector,
1553
bool set_mode(struct drm_device *dev, struct drm_connector *connector,
1553
              videomode_t *mode, bool strict);
1554
              videomode_t *mode, bool strict);
1554
 
1555
 
1555
 
1556
 
1556
 
1557
 
1557
struct work_struct;
1558
struct work_struct;
1558
typedef void (*work_func_t)(struct work_struct *work);
1559
typedef void (*work_func_t)(struct work_struct *work);
1559
 
1560
 
1560
/*
1561
/*
1561
 * The first word is the work queue pointer and the flags rolled into
1562
 * The first word is the work queue pointer and the flags rolled into
1562
 * one
1563
 * one
1563
 */
1564
 */
1564
#define work_data_bits(work) ((unsigned long *)(&(work)->data))
1565
#define work_data_bits(work) ((unsigned long *)(&(work)->data))
1565
 
1566
 
1566
struct work_struct {
1567
struct work_struct {
1567
        atomic_long_t data;
1568
        atomic_long_t data;
1568
#define WORK_STRUCT_PENDING 0           /* T if work item pending execution */
1569
#define WORK_STRUCT_PENDING 0           /* T if work item pending execution */
1569
#define WORK_STRUCT_FLAG_MASK (3UL)
1570
#define WORK_STRUCT_FLAG_MASK (3UL)
1570
#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
1571
#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
1571
        struct list_head entry;
1572
        struct list_head entry;
1572
        work_func_t func;
1573
        work_func_t func;
1573
};
1574
};
1574
 
1575
 
1575
#endif
1576
#endif