blob: a168d644bf9e96724b5e717f2a8777bb8354f5e5 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#ifndef __RADEON_H__
29#define __RADEON_H__
30
Jerome Glisse771fe6b2009-06-05 14:42:42 +020031/* TODO: Here are things that needs to be done :
32 * - surface allocator & initializer : (bit like scratch reg) should
33 * initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
34 * related to surface
35 * - WB : write back stuff (do it bit like scratch reg things)
36 * - Vblank : look at Jesse's rework and what we should do
37 * - r600/r700: gart & cp
38 * - cs : clean cs ioctl use bitmap & things like that.
39 * - power management stuff
40 * - Barrier in gart code
41 * - Unmappabled vram ?
42 * - TESTING, TESTING, TESTING
43 */
44
Jerome Glissed39c3b82009-09-28 18:34:43 +020045/* Initialization path:
46 * We expect that acceleration initialization might fail for various
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
49 * situation the init path must succeed up to the memory controller
50 * initialization point. Failure before this point are considered as
51 * fatal error. Here is the init callchain :
52 * radeon_device_init perform common structure, mutex initialization
53 * asic_init setup the GPU memory layout and perform all
54 * one time initialization (failure in this
55 * function are considered fatal)
56 * asic_startup setup the GPU acceleration, in order to
57 * follow guideline the first thing this
58 * function should do is setting the GPU
59 * memory controller (only MC setup failure
60 * are considered as fatal)
61 */
62
Jerome Glisse771fe6b2009-06-05 14:42:42 +020063#include <asm/atomic.h>
64#include <linux/wait.h>
65#include <linux/list.h>
66#include <linux/kref.h>
67
Jerome Glisse4c788672009-11-20 14:29:23 +010068#include <ttm/ttm_bo_api.h>
69#include <ttm/ttm_bo_driver.h>
70#include <ttm/ttm_placement.h>
71#include <ttm/ttm_module.h>
72
Dave Airliec2142712009-09-22 08:50:10 +100073#include "radeon_family.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020074#include "radeon_mode.h"
75#include "radeon_reg.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020076
77/*
78 * Modules parameters.
79 */
80extern int radeon_no_wb;
81extern int radeon_modeset;
82extern int radeon_dynclks;
83extern int radeon_r4xx_atom;
84extern int radeon_agpmode;
85extern int radeon_vram_limit;
86extern int radeon_gart_size;
87extern int radeon_benchmarking;
Michel Dänzerecc0b322009-07-21 11:23:57 +020088extern int radeon_testing;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020089extern int radeon_connector_table;
Dave Airlie4ce001a2009-08-13 16:32:14 +100090extern int radeon_tv;
Alex Deucherb27b6372009-12-09 17:44:25 -050091extern int radeon_new_pll;
Christian Koenigdafc3bd2009-10-11 23:49:13 +020092extern int radeon_audio;
Alex Deucherf46c0122010-03-31 00:33:27 -040093extern int radeon_disp_priority;
Alex Deuchere2b0a8e2010-03-17 02:07:37 -040094extern int radeon_hw_i2c;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020095
96/*
97 * Copy from radeon_drv.h so we don't have to include both and have conflicting
98 * symbol;
99 */
100#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
Jerome Glisse225758d2010-03-09 14:45:10 +0000101#define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
Jerome Glissee8217672010-02-15 21:36:13 +0100102/* RADEON_IB_POOL_SIZE must be a power of 2 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200103#define RADEON_IB_POOL_SIZE 16
104#define RADEON_DEBUGFS_MAX_NUM_FILES 32
105#define RADEONFB_CONN_LIMIT 4
Yang Zhaof657c2a2009-09-15 12:21:01 +1000106#define RADEON_BIOS_NUM_SCRATCH 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200107
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200108/*
109 * Errata workarounds.
110 */
111enum radeon_pll_errata {
112 CHIP_ERRATA_R300_CG = 0x00000001,
113 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
114 CHIP_ERRATA_PLL_DELAY = 0x00000004
115};
116
117
118struct radeon_device;
119
120
121/*
122 * BIOS.
123 */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000124#define ATRM_BIOS_PAGE 4096
125
Dave Airlie8edb3812010-03-01 21:50:01 +1100126#if defined(CONFIG_VGA_SWITCHEROO)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000127bool radeon_atrm_supported(struct pci_dev *pdev);
128int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
Dave Airlie8edb3812010-03-01 21:50:01 +1100129#else
130static inline bool radeon_atrm_supported(struct pci_dev *pdev)
131{
132 return false;
133}
134
135static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
136 return -EINVAL;
137}
138#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200139bool radeon_get_bios(struct radeon_device *rdev);
140
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000141
142/*
143 * Dummy page
144 */
145struct radeon_dummy_page {
146 struct page *page;
147 dma_addr_t addr;
148};
149int radeon_dummy_page_init(struct radeon_device *rdev);
150void radeon_dummy_page_fini(struct radeon_device *rdev);
151
152
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200153/*
154 * Clocks
155 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200156struct radeon_clock {
157 struct radeon_pll p1pll;
158 struct radeon_pll p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500159 struct radeon_pll dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200160 struct radeon_pll spll;
161 struct radeon_pll mpll;
162 /* 10 Khz units */
163 uint32_t default_mclk;
164 uint32_t default_sclk;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500165 uint32_t default_dispclk;
166 uint32_t dp_extclk;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200167};
168
Rafał Miłecki74338742009-11-03 00:53:02 +0100169/*
170 * Power management
171 */
172int radeon_pm_init(struct radeon_device *rdev);
Alex Deucher29fb52c2010-03-11 10:01:17 -0500173void radeon_pm_fini(struct radeon_device *rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100174void radeon_pm_compute_clocks(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400175void radeon_pm_suspend(struct radeon_device *rdev);
176void radeon_pm_resume(struct radeon_device *rdev);
Alex Deucher56278a82009-12-28 13:58:44 -0500177void radeon_combios_get_power_modes(struct radeon_device *rdev);
178void radeon_atombios_get_power_modes(struct radeon_device *rdev);
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400179void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level);
Alex Deucherf8920342010-06-30 12:02:03 -0400180void rs690_pm_info(struct radeon_device *rdev);
Alex Deucher21a81222010-07-02 12:58:16 -0400181extern u32 rv6xx_get_temp(struct radeon_device *rdev);
182extern u32 rv770_get_temp(struct radeon_device *rdev);
183extern u32 evergreen_get_temp(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000184
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200185/*
186 * Fences.
187 */
188struct radeon_fence_driver {
189 uint32_t scratch_reg;
190 atomic_t seq;
191 uint32_t last_seq;
Jerome Glisse225758d2010-03-09 14:45:10 +0000192 unsigned long last_jiffies;
193 unsigned long last_timeout;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200194 wait_queue_head_t queue;
195 rwlock_t lock;
196 struct list_head created;
197 struct list_head emited;
198 struct list_head signaled;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100199 bool initialized;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200200};
201
202struct radeon_fence {
203 struct radeon_device *rdev;
204 struct kref kref;
205 struct list_head list;
206 /* protected by radeon_fence.lock */
207 uint32_t seq;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200208 bool emited;
209 bool signaled;
210};
211
212int radeon_fence_driver_init(struct radeon_device *rdev);
213void radeon_fence_driver_fini(struct radeon_device *rdev);
214int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
215int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
216void radeon_fence_process(struct radeon_device *rdev);
217bool radeon_fence_signaled(struct radeon_fence *fence);
218int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
219int radeon_fence_wait_next(struct radeon_device *rdev);
220int radeon_fence_wait_last(struct radeon_device *rdev);
221struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
222void radeon_fence_unref(struct radeon_fence **fence);
223
Dave Airliee024e112009-06-24 09:48:08 +1000224/*
225 * Tiling registers
226 */
227struct radeon_surface_reg {
Jerome Glisse4c788672009-11-20 14:29:23 +0100228 struct radeon_bo *bo;
Dave Airliee024e112009-06-24 09:48:08 +1000229};
230
231#define RADEON_GEM_MAX_SURFACES 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200232
233/*
Jerome Glisse4c788672009-11-20 14:29:23 +0100234 * TTM.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200235 */
Jerome Glisse4c788672009-11-20 14:29:23 +0100236struct radeon_mman {
237 struct ttm_bo_global_ref bo_global_ref;
Dave Airlieba4420c2010-03-09 10:56:52 +1000238 struct drm_global_reference mem_global_ref;
Jerome Glisse4c788672009-11-20 14:29:23 +0100239 struct ttm_bo_device bdev;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100240 bool mem_global_referenced;
241 bool initialized;
Jerome Glisse4c788672009-11-20 14:29:23 +0100242};
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200243
Jerome Glisse4c788672009-11-20 14:29:23 +0100244struct radeon_bo {
245 /* Protected by gem.mutex */
246 struct list_head list;
247 /* Protected by tbo.reserved */
Jerome Glisse312ea8d2009-12-07 15:52:58 +0100248 u32 placements[3];
249 struct ttm_placement placement;
Jerome Glisse4c788672009-11-20 14:29:23 +0100250 struct ttm_buffer_object tbo;
251 struct ttm_bo_kmap_obj kmap;
252 unsigned pin_count;
253 void *kptr;
254 u32 tiling_flags;
255 u32 pitch;
256 int surface_reg;
257 /* Constant after initialization */
258 struct radeon_device *rdev;
259 struct drm_gem_object *gobj;
260};
261
262struct radeon_bo_list {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200263 struct list_head list;
Jerome Glisse4c788672009-11-20 14:29:23 +0100264 struct radeon_bo *bo;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200265 uint64_t gpu_offset;
266 unsigned rdomain;
267 unsigned wdomain;
Jerome Glisse4c788672009-11-20 14:29:23 +0100268 u32 tiling_flags;
Jerome Glissee8652752010-05-19 16:05:50 +0200269 bool reserved;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200270};
271
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200272/*
273 * GEM objects.
274 */
275struct radeon_gem {
Jerome Glisse4c788672009-11-20 14:29:23 +0100276 struct mutex mutex;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200277 struct list_head objects;
278};
279
280int radeon_gem_init(struct radeon_device *rdev);
281void radeon_gem_fini(struct radeon_device *rdev);
282int radeon_gem_object_create(struct radeon_device *rdev, int size,
Jerome Glisse4c788672009-11-20 14:29:23 +0100283 int alignment, int initial_domain,
284 bool discardable, bool kernel,
285 struct drm_gem_object **obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200286int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
287 uint64_t *gpu_addr);
288void radeon_gem_object_unpin(struct drm_gem_object *obj);
289
290
291/*
292 * GART structures, functions & helpers
293 */
294struct radeon_mc;
295
296struct radeon_gart_table_ram {
297 volatile uint32_t *ptr;
298};
299
300struct radeon_gart_table_vram {
Jerome Glisse4c788672009-11-20 14:29:23 +0100301 struct radeon_bo *robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200302 volatile uint32_t *ptr;
303};
304
305union radeon_gart_table {
306 struct radeon_gart_table_ram ram;
307 struct radeon_gart_table_vram vram;
308};
309
Matt Turnera77f1712009-10-14 00:34:41 -0400310#define RADEON_GPU_PAGE_SIZE 4096
Jerome Glissed594e462010-02-17 21:54:29 +0000311#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
Matt Turnera77f1712009-10-14 00:34:41 -0400312
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200313struct radeon_gart {
314 dma_addr_t table_addr;
315 unsigned num_gpu_pages;
316 unsigned num_cpu_pages;
317 unsigned table_size;
318 union radeon_gart_table table;
319 struct page **pages;
320 dma_addr_t *pages_addr;
321 bool ready;
322};
323
324int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
325void radeon_gart_table_ram_free(struct radeon_device *rdev);
326int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
327void radeon_gart_table_vram_free(struct radeon_device *rdev);
328int radeon_gart_init(struct radeon_device *rdev);
329void radeon_gart_fini(struct radeon_device *rdev);
330void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
331 int pages);
332int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
333 int pages, struct page **pagelist);
334
335
336/*
337 * GPU MC structures, functions & helpers
338 */
339struct radeon_mc {
340 resource_size_t aper_size;
341 resource_size_t aper_base;
342 resource_size_t agp_base;
Dave Airlie7a50f012009-07-21 20:39:30 +1000343 /* for some chips with <= 32MB we need to lie
344 * about vram size near mc fb location */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000345 u64 mc_vram_size;
Jerome Glissed594e462010-02-17 21:54:29 +0000346 u64 visible_vram_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000347 u64 gtt_size;
348 u64 gtt_start;
349 u64 gtt_end;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000350 u64 vram_start;
351 u64 vram_end;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200352 unsigned vram_width;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000353 u64 real_vram_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200354 int vram_mtrr;
355 bool vram_is_ddr;
Jerome Glissed594e462010-02-17 21:54:29 +0000356 bool igp_sideport_enabled;
Alex Deucher8d369bb2010-07-15 10:51:10 -0400357 u64 gtt_base_align;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200358};
359
Alex Deucher06b64762010-01-05 11:27:29 -0500360bool radeon_combios_sideport_present(struct radeon_device *rdev);
361bool radeon_atombios_sideport_present(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200362
363/*
364 * GPU scratch registers structures, functions & helpers
365 */
366struct radeon_scratch {
367 unsigned num_reg;
368 bool free[32];
369 uint32_t reg[32];
370};
371
372int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
373void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
374
375
376/*
377 * IRQS.
378 */
379struct radeon_irq {
380 bool installed;
381 bool sw_int;
382 /* FIXME: use a define max crtc rather than hardcode it */
Alex Deucher45f9a392010-03-24 13:55:51 -0400383 bool crtc_vblank_int[6];
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100384 wait_queue_head_t vblank_queue;
Alex Deucherb500f682009-12-03 13:08:53 -0500385 /* FIXME: use defines for max hpd/dacs */
386 bool hpd[6];
Alex Deucher2031f772010-04-22 12:52:11 -0400387 bool gui_idle;
388 bool gui_idle_acked;
389 wait_queue_head_t idle_queue;
Christian Koenigf2594932010-04-10 03:13:16 +0200390 /* FIXME: use defines for max HDMI blocks */
391 bool hdmi[2];
Dave Airlie1614f8b2009-12-01 16:04:56 +1000392 spinlock_t sw_lock;
393 int sw_refcount;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200394};
395
396int radeon_irq_kms_init(struct radeon_device *rdev);
397void radeon_irq_kms_fini(struct radeon_device *rdev);
Dave Airlie1614f8b2009-12-01 16:04:56 +1000398void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
399void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200400
401/*
402 * CP & ring.
403 */
404struct radeon_ib {
405 struct list_head list;
Jerome Glissee8217672010-02-15 21:36:13 +0100406 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200407 uint64_t gpu_addr;
408 struct radeon_fence *fence;
Jerome Glissee8217672010-02-15 21:36:13 +0100409 uint32_t *ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200410 uint32_t length_dw;
Jerome Glissee8217672010-02-15 21:36:13 +0100411 bool free;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200412};
413
Dave Airlieecb114a2009-09-15 11:12:56 +1000414/*
415 * locking -
416 * mutex protects scheduled_ibs, ready, alloc_bm
417 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200418struct radeon_ib_pool {
419 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100420 struct radeon_bo *robj;
Jerome Glisse9f93ed32010-01-28 18:22:31 +0100421 struct list_head bogus_ib;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200422 struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
423 bool ready;
Jerome Glissee8217672010-02-15 21:36:13 +0100424 unsigned head_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200425};
426
427struct radeon_cp {
Jerome Glisse4c788672009-11-20 14:29:23 +0100428 struct radeon_bo *ring_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200429 volatile uint32_t *ring;
430 unsigned rptr;
431 unsigned wptr;
432 unsigned wptr_old;
433 unsigned ring_size;
434 unsigned ring_free_dw;
435 int count_dw;
436 uint64_t gpu_addr;
437 uint32_t align_mask;
438 uint32_t ptr_mask;
439 struct mutex mutex;
440 bool ready;
441};
442
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500443/*
444 * R6xx+ IH ring
445 */
446struct r600_ih {
Jerome Glisse4c788672009-11-20 14:29:23 +0100447 struct radeon_bo *ring_obj;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500448 volatile uint32_t *ring;
449 unsigned rptr;
450 unsigned wptr;
451 unsigned wptr_old;
452 unsigned ring_size;
453 uint64_t gpu_addr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500454 uint32_t ptr_mask;
455 spinlock_t lock;
456 bool enabled;
457};
458
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000459struct r600_blit {
Jerome Glisseff82f052010-01-22 15:19:00 +0100460 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100461 struct radeon_bo *shader_obj;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000462 u64 shader_gpu_addr;
463 u32 vs_offset, ps_offset;
464 u32 state_offset;
465 u32 state_len;
466 u32 vb_used, vb_total;
467 struct radeon_ib *vb_ib;
468};
469
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200470int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
471void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
472int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
473int radeon_ib_pool_init(struct radeon_device *rdev);
474void radeon_ib_pool_fini(struct radeon_device *rdev);
475int radeon_ib_test(struct radeon_device *rdev);
Jerome Glisse9f93ed32010-01-28 18:22:31 +0100476extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200477/* Ring access between begin & end cannot sleep */
478void radeon_ring_free_size(struct radeon_device *rdev);
Matthew Garrett91700f32010-04-30 15:24:17 -0400479int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200480int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
Matthew Garrett91700f32010-04-30 15:24:17 -0400481void radeon_ring_commit(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200482void radeon_ring_unlock_commit(struct radeon_device *rdev);
483void radeon_ring_unlock_undo(struct radeon_device *rdev);
484int radeon_ring_test(struct radeon_device *rdev);
485int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
486void radeon_ring_fini(struct radeon_device *rdev);
487
488
489/*
490 * CS.
491 */
492struct radeon_cs_reloc {
493 struct drm_gem_object *gobj;
Jerome Glisse4c788672009-11-20 14:29:23 +0100494 struct radeon_bo *robj;
495 struct radeon_bo_list lobj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200496 uint32_t handle;
497 uint32_t flags;
498};
499
500struct radeon_cs_chunk {
501 uint32_t chunk_id;
502 uint32_t length_dw;
Dave Airlie513bcb42009-09-23 16:56:27 +1000503 int kpage_idx[2];
504 uint32_t *kpage[2];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200505 uint32_t *kdata;
Dave Airlie513bcb42009-09-23 16:56:27 +1000506 void __user *user_ptr;
507 int last_copied_page;
508 int last_page_index;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200509};
510
511struct radeon_cs_parser {
Jerome Glissec8c15ff2010-01-18 13:01:36 +0100512 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200513 struct radeon_device *rdev;
514 struct drm_file *filp;
515 /* chunks */
516 unsigned nchunks;
517 struct radeon_cs_chunk *chunks;
518 uint64_t *chunks_array;
519 /* IB */
520 unsigned idx;
521 /* relocations */
522 unsigned nrelocs;
523 struct radeon_cs_reloc *relocs;
524 struct radeon_cs_reloc **relocs_ptr;
525 struct list_head validated;
526 /* indices of various chunks */
527 int chunk_ib_idx;
528 int chunk_relocs_idx;
529 struct radeon_ib *ib;
530 void *track;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000531 unsigned family;
Dave Airlie513bcb42009-09-23 16:56:27 +1000532 int parser_error;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200533};
534
Dave Airlie513bcb42009-09-23 16:56:27 +1000535extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
536extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
537
538
539static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
540{
541 struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
542 u32 pg_idx, pg_offset;
543 u32 idx_value = 0;
544 int new_page;
545
546 pg_idx = (idx * 4) / PAGE_SIZE;
547 pg_offset = (idx * 4) % PAGE_SIZE;
548
549 if (ibc->kpage_idx[0] == pg_idx)
550 return ibc->kpage[0][pg_offset/4];
551 if (ibc->kpage_idx[1] == pg_idx)
552 return ibc->kpage[1][pg_offset/4];
553
554 new_page = radeon_cs_update_pages(p, pg_idx);
555 if (new_page < 0) {
556 p->parser_error = new_page;
557 return 0;
558 }
559
560 idx_value = ibc->kpage[new_page][pg_offset/4];
561 return idx_value;
562}
563
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200564struct radeon_cs_packet {
565 unsigned idx;
566 unsigned type;
567 unsigned reg;
568 unsigned opcode;
569 int count;
570 unsigned one_reg_wr;
571};
572
573typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
574 struct radeon_cs_packet *pkt,
575 unsigned idx, unsigned reg);
576typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
577 struct radeon_cs_packet *pkt);
578
579
580/*
581 * AGP
582 */
583int radeon_agp_init(struct radeon_device *rdev);
Dave Airlie0ebf1712009-11-05 15:39:10 +1000584void radeon_agp_resume(struct radeon_device *rdev);
Jerome Glisse10b06122010-05-21 18:48:54 +0200585void radeon_agp_suspend(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200586void radeon_agp_fini(struct radeon_device *rdev);
587
588
589/*
590 * Writeback
591 */
592struct radeon_wb {
Jerome Glisse4c788672009-11-20 14:29:23 +0100593 struct radeon_bo *wb_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200594 volatile uint32_t *wb;
595 uint64_t gpu_addr;
596};
597
Jerome Glissec93bb852009-07-13 21:04:08 +0200598/**
599 * struct radeon_pm - power management datas
600 * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
601 * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
602 * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
603 * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
604 * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
605 * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
606 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
607 * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
608 * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
609 * @sclk: GPU clock Mhz (core bandwith depends of this clock)
610 * @needed_bandwidth: current bandwidth needs
611 *
612 * It keeps track of various data needed to take powermanagement decision.
613 * Bandwith need is used to determine minimun clock of the GPU and memory.
614 * Equation between gpu/memory clock and available bandwidth is hw dependent
615 * (type of memory, bus size, efficiency, ...)
616 */
Alex Deucherce8f5372010-05-07 15:10:16 -0400617
618enum radeon_pm_method {
619 PM_METHOD_PROFILE,
620 PM_METHOD_DYNPM,
Rafał Miłeckic913e232009-12-22 23:02:16 +0100621};
Alex Deucherce8f5372010-05-07 15:10:16 -0400622
623enum radeon_dynpm_state {
624 DYNPM_STATE_DISABLED,
625 DYNPM_STATE_MINIMUM,
626 DYNPM_STATE_PAUSED,
Rafael J. Wysocki3f53eb62010-06-17 23:02:27 +0000627 DYNPM_STATE_ACTIVE,
628 DYNPM_STATE_SUSPENDED,
Alex Deucherce8f5372010-05-07 15:10:16 -0400629};
630enum radeon_dynpm_action {
631 DYNPM_ACTION_NONE,
632 DYNPM_ACTION_MINIMUM,
633 DYNPM_ACTION_DOWNCLOCK,
634 DYNPM_ACTION_UPCLOCK,
635 DYNPM_ACTION_DEFAULT
Rafał Miłeckic913e232009-12-22 23:02:16 +0100636};
Alex Deucher56278a82009-12-28 13:58:44 -0500637
638enum radeon_voltage_type {
639 VOLTAGE_NONE = 0,
640 VOLTAGE_GPIO,
641 VOLTAGE_VDDC,
642 VOLTAGE_SW
643};
644
Alex Deucher0ec0e742009-12-23 13:21:58 -0500645enum radeon_pm_state_type {
646 POWER_STATE_TYPE_DEFAULT,
647 POWER_STATE_TYPE_POWERSAVE,
648 POWER_STATE_TYPE_BATTERY,
649 POWER_STATE_TYPE_BALANCED,
650 POWER_STATE_TYPE_PERFORMANCE,
651};
652
Alex Deucherce8f5372010-05-07 15:10:16 -0400653enum radeon_pm_profile_type {
654 PM_PROFILE_DEFAULT,
655 PM_PROFILE_AUTO,
656 PM_PROFILE_LOW,
Alex Deucherc9e75b22010-06-02 17:56:01 -0400657 PM_PROFILE_MID,
Alex Deucherce8f5372010-05-07 15:10:16 -0400658 PM_PROFILE_HIGH,
659};
660
661#define PM_PROFILE_DEFAULT_IDX 0
662#define PM_PROFILE_LOW_SH_IDX 1
Alex Deucherc9e75b22010-06-02 17:56:01 -0400663#define PM_PROFILE_MID_SH_IDX 2
664#define PM_PROFILE_HIGH_SH_IDX 3
665#define PM_PROFILE_LOW_MH_IDX 4
666#define PM_PROFILE_MID_MH_IDX 5
667#define PM_PROFILE_HIGH_MH_IDX 6
668#define PM_PROFILE_MAX 7
Alex Deucherce8f5372010-05-07 15:10:16 -0400669
670struct radeon_pm_profile {
671 int dpms_off_ps_idx;
672 int dpms_on_ps_idx;
673 int dpms_off_cm_idx;
674 int dpms_on_cm_idx;
Alex Deucher516d0e42009-12-23 14:28:05 -0500675};
676
Alex Deucher21a81222010-07-02 12:58:16 -0400677enum radeon_int_thermal_type {
678 THERMAL_TYPE_NONE,
679 THERMAL_TYPE_RV6XX,
680 THERMAL_TYPE_RV770,
681 THERMAL_TYPE_EVERGREEN,
682};
683
Alex Deucher56278a82009-12-28 13:58:44 -0500684struct radeon_voltage {
685 enum radeon_voltage_type type;
686 /* gpio voltage */
687 struct radeon_gpio_rec gpio;
688 u32 delay; /* delay in usec from voltage drop to sclk change */
689 bool active_high; /* voltage drop is active when bit is high */
690 /* VDDC voltage */
691 u8 vddc_id; /* index into vddc voltage table */
692 u8 vddci_id; /* index into vddci voltage table */
693 bool vddci_enabled;
694 /* r6xx+ sw */
695 u32 voltage;
696};
697
Alex Deucherd7311172010-05-03 01:13:14 -0400698/* clock mode flags */
699#define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
700
Alex Deucher56278a82009-12-28 13:58:44 -0500701struct radeon_pm_clock_info {
702 /* memory clock */
703 u32 mclk;
704 /* engine clock */
705 u32 sclk;
706 /* voltage info */
707 struct radeon_voltage voltage;
Alex Deucherd7311172010-05-03 01:13:14 -0400708 /* standardized clock flags */
Alex Deucher56278a82009-12-28 13:58:44 -0500709 u32 flags;
710};
711
Alex Deuchera48b9b42010-04-22 14:03:55 -0400712/* state flags */
Alex Deucherd7311172010-05-03 01:13:14 -0400713#define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400714
Alex Deucher56278a82009-12-28 13:58:44 -0500715struct radeon_power_state {
Alex Deucher0ec0e742009-12-23 13:21:58 -0500716 enum radeon_pm_state_type type;
Alex Deucher56278a82009-12-28 13:58:44 -0500717 /* XXX: use a define for num clock modes */
718 struct radeon_pm_clock_info clock_info[8];
719 /* number of valid clock modes in this power state */
720 int num_clock_modes;
Alex Deucher56278a82009-12-28 13:58:44 -0500721 struct radeon_pm_clock_info *default_clock_mode;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400722 /* standardized state flags */
723 u32 flags;
Alex Deucher79daedc2010-04-22 14:25:19 -0400724 u32 misc; /* vbios specific flags */
725 u32 misc2; /* vbios specific flags */
726 int pcie_lanes; /* pcie lanes */
Alex Deucher56278a82009-12-28 13:58:44 -0500727};
728
Rafał Miłecki27459322010-02-11 22:16:36 +0000729/*
730 * Some modes are overclocked by very low value, accept them
731 */
732#define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
733
Jerome Glissec93bb852009-07-13 21:04:08 +0200734struct radeon_pm {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100735 struct mutex mutex;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400736 u32 active_crtcs;
737 int active_crtc_count;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100738 int req_vblank;
Rafał Miłecki839461d2010-03-02 22:06:51 +0100739 bool vblank_sync;
Alex Deucher2031f772010-04-22 12:52:11 -0400740 bool gui_idle;
Jerome Glissec93bb852009-07-13 21:04:08 +0200741 fixed20_12 max_bandwidth;
742 fixed20_12 igp_sideport_mclk;
743 fixed20_12 igp_system_mclk;
744 fixed20_12 igp_ht_link_clk;
745 fixed20_12 igp_ht_link_width;
746 fixed20_12 k8_bandwidth;
747 fixed20_12 sideport_bandwidth;
748 fixed20_12 ht_bandwidth;
749 fixed20_12 core_bandwidth;
750 fixed20_12 sclk;
Alex Deucherf47299c2010-03-16 20:54:38 -0400751 fixed20_12 mclk;
Jerome Glissec93bb852009-07-13 21:04:08 +0200752 fixed20_12 needed_bandwidth;
Alex Deucher56278a82009-12-28 13:58:44 -0500753 /* XXX: use a define for num power modes */
754 struct radeon_power_state power_state[8];
755 /* number of valid power states */
756 int num_power_states;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400757 int current_power_state_index;
758 int current_clock_mode_index;
759 int requested_power_state_index;
760 int requested_clock_mode_index;
761 int default_power_state_index;
762 u32 current_sclk;
763 u32 current_mclk;
Alex Deucher4d601732010-06-07 18:15:18 -0400764 u32 current_vddc;
Alex Deucher29fb52c2010-03-11 10:01:17 -0500765 struct radeon_i2c_chan *i2c_bus;
Alex Deucherce8f5372010-05-07 15:10:16 -0400766 /* selected pm method */
767 enum radeon_pm_method pm_method;
768 /* dynpm power management */
769 struct delayed_work dynpm_idle_work;
770 enum radeon_dynpm_state dynpm_state;
771 enum radeon_dynpm_action dynpm_planned_action;
772 unsigned long dynpm_action_timeout;
773 bool dynpm_can_upclock;
774 bool dynpm_can_downclock;
775 /* profile-based power management */
776 enum radeon_pm_profile_type profile;
777 int profile_index;
778 struct radeon_pm_profile profiles[PM_PROFILE_MAX];
Alex Deucher21a81222010-07-02 12:58:16 -0400779 /* internal thermal controller on rv6xx+ */
780 enum radeon_int_thermal_type int_thermal_type;
781 struct device *int_hwmon_dev;
Jerome Glissec93bb852009-07-13 21:04:08 +0200782};
783
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200784
785/*
786 * Benchmarking
787 */
788void radeon_benchmark(struct radeon_device *rdev);
789
790
791/*
Michel Dänzerecc0b322009-07-21 11:23:57 +0200792 * Testing
793 */
794void radeon_test_moves(struct radeon_device *rdev);
795
796
797/*
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200798 * Debugfs
799 */
800int radeon_debugfs_add_files(struct radeon_device *rdev,
801 struct drm_info_list *files,
802 unsigned nfiles);
803int radeon_debugfs_fence_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200804
805
806/*
807 * ASIC specific functions.
808 */
809struct radeon_asic {
Jerome Glisse068a1172009-06-17 13:28:30 +0200810 int (*init)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000811 void (*fini)(struct radeon_device *rdev);
812 int (*resume)(struct radeon_device *rdev);
813 int (*suspend)(struct radeon_device *rdev);
Dave Airlie28d52042009-09-21 14:33:58 +1000814 void (*vga_set_state)(struct radeon_device *rdev, bool state);
Jerome Glisse225758d2010-03-09 14:45:10 +0000815 bool (*gpu_is_lockup)(struct radeon_device *rdev);
Jerome Glissea2d07b72010-03-09 14:45:11 +0000816 int (*asic_reset)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200817 void (*gart_tlb_flush)(struct radeon_device *rdev);
818 int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
819 int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
820 void (*cp_fini)(struct radeon_device *rdev);
821 void (*cp_disable)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000822 void (*cp_commit)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200823 void (*ring_start)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000824 int (*ring_test)(struct radeon_device *rdev);
825 void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200826 int (*irq_set)(struct radeon_device *rdev);
827 int (*irq_process)(struct radeon_device *rdev);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200828 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200829 void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
830 int (*cs_parse)(struct radeon_cs_parser *p);
831 int (*copy_blit)(struct radeon_device *rdev,
832 uint64_t src_offset,
833 uint64_t dst_offset,
834 unsigned num_pages,
835 struct radeon_fence *fence);
836 int (*copy_dma)(struct radeon_device *rdev,
837 uint64_t src_offset,
838 uint64_t dst_offset,
839 unsigned num_pages,
840 struct radeon_fence *fence);
841 int (*copy)(struct radeon_device *rdev,
842 uint64_t src_offset,
843 uint64_t dst_offset,
844 unsigned num_pages,
845 struct radeon_fence *fence);
Rafał Miłecki74338742009-11-03 00:53:02 +0100846 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
Rafał Miłecki74338742009-11-03 00:53:02 +0100848 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200849 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
Alex Deucherc836a412009-12-23 10:07:50 -0500850 int (*get_pcie_lanes)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200851 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
852 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
Dave Airliee024e112009-06-24 09:48:08 +1000853 int (*set_surface_reg)(struct radeon_device *rdev, int reg,
854 uint32_t tiling_flags, uint32_t pitch,
855 uint32_t offset, uint32_t obj_size);
Daniel Vetter9479c542010-03-11 21:19:16 +0000856 void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
Jerome Glissec93bb852009-07-13 21:04:08 +0200857 void (*bandwidth_update)(struct radeon_device *rdev);
Alex Deucher429770b2009-12-04 15:26:55 -0500858 void (*hpd_init)(struct radeon_device *rdev);
859 void (*hpd_fini)(struct radeon_device *rdev);
860 bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
861 void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
Jerome Glisse062b3892010-02-04 20:36:39 +0100862 /* ioctl hw specific callback. Some hw might want to perform special
863 * operation on specific ioctl. For instance on wait idle some hw
864 * might want to perform and HDP flush through MMIO as it seems that
865 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
866 * through ring.
867 */
868 void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
Alex Deucherdef9ba92010-04-22 12:39:58 -0400869 bool (*gui_idle)(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400870 /* power management */
Alex Deucher49e02b72010-04-23 17:57:27 -0400871 void (*pm_misc)(struct radeon_device *rdev);
872 void (*pm_prepare)(struct radeon_device *rdev);
873 void (*pm_finish)(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400874 void (*pm_init_profile)(struct radeon_device *rdev);
875 void (*pm_get_dynpm_state)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200876};
877
Jerome Glisse21f9a432009-09-11 15:55:33 +0200878/*
879 * Asic structures
880 */
Jerome Glisse225758d2010-03-09 14:45:10 +0000881struct r100_gpu_lockup {
882 unsigned long last_jiffies;
883 u32 last_cp_rptr;
884};
885
Dave Airlie551ebd82009-09-01 15:25:57 +1000886struct r100_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000887 const unsigned *reg_safe_bm;
888 unsigned reg_safe_bm_size;
889 u32 hdp_cntl;
890 struct r100_gpu_lockup lockup;
Dave Airlie551ebd82009-09-01 15:25:57 +1000891};
892
Jerome Glisse21f9a432009-09-11 15:55:33 +0200893struct r300_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000894 const unsigned *reg_safe_bm;
895 unsigned reg_safe_bm_size;
896 u32 resync_scratch;
897 u32 hdp_cntl;
898 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +0200899};
900
901struct r600_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000902 unsigned max_pipes;
903 unsigned max_tile_pipes;
904 unsigned max_simds;
905 unsigned max_backends;
906 unsigned max_gprs;
907 unsigned max_threads;
908 unsigned max_stack_entries;
909 unsigned max_hw_contexts;
910 unsigned max_gs_threads;
911 unsigned sx_max_export_size;
912 unsigned sx_max_export_pos_size;
913 unsigned sx_max_export_smx_size;
914 unsigned sq_num_cf_insts;
915 unsigned tiling_nbanks;
916 unsigned tiling_npipes;
917 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400918 unsigned tile_config;
Jerome Glisse225758d2010-03-09 14:45:10 +0000919 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +0200920};
921
922struct rv770_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000923 unsigned max_pipes;
924 unsigned max_tile_pipes;
925 unsigned max_simds;
926 unsigned max_backends;
927 unsigned max_gprs;
928 unsigned max_threads;
929 unsigned max_stack_entries;
930 unsigned max_hw_contexts;
931 unsigned max_gs_threads;
932 unsigned sx_max_export_size;
933 unsigned sx_max_export_pos_size;
934 unsigned sx_max_export_smx_size;
935 unsigned sq_num_cf_insts;
936 unsigned sx_num_of_sets;
937 unsigned sc_prim_fifo_size;
938 unsigned sc_hiz_tile_fifo_size;
939 unsigned sc_earlyz_tile_fifo_fize;
940 unsigned tiling_nbanks;
941 unsigned tiling_npipes;
942 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400943 unsigned tile_config;
Jerome Glisse225758d2010-03-09 14:45:10 +0000944 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +0200945};
946
Alex Deucher32fcdbf2010-03-24 13:33:47 -0400947struct evergreen_asic {
948 unsigned num_ses;
949 unsigned max_pipes;
950 unsigned max_tile_pipes;
951 unsigned max_simds;
952 unsigned max_backends;
953 unsigned max_gprs;
954 unsigned max_threads;
955 unsigned max_stack_entries;
956 unsigned max_hw_contexts;
957 unsigned max_gs_threads;
958 unsigned sx_max_export_size;
959 unsigned sx_max_export_pos_size;
960 unsigned sx_max_export_smx_size;
961 unsigned sq_num_cf_insts;
962 unsigned sx_num_of_sets;
963 unsigned sc_prim_fifo_size;
964 unsigned sc_hiz_tile_fifo_size;
965 unsigned sc_earlyz_tile_fifo_size;
966 unsigned tiling_nbanks;
967 unsigned tiling_npipes;
968 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400969 unsigned tile_config;
Alex Deucher32fcdbf2010-03-24 13:33:47 -0400970};
971
Jerome Glisse068a1172009-06-17 13:28:30 +0200972union radeon_asic_config {
973 struct r300_asic r300;
Dave Airlie551ebd82009-09-01 15:25:57 +1000974 struct r100_asic r100;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000975 struct r600_asic r600;
976 struct rv770_asic rv770;
Alex Deucher32fcdbf2010-03-24 13:33:47 -0400977 struct evergreen_asic evergreen;
Jerome Glisse068a1172009-06-17 13:28:30 +0200978};
979
Daniel Vetter0a10c852010-03-11 21:19:14 +0000980/*
981 * asic initizalization from radeon_asic.c
982 */
983void radeon_agp_disable(struct radeon_device *rdev);
984int radeon_asic_init(struct radeon_device *rdev);
985
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200986
987/*
988 * IOCTL.
989 */
990int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
991 struct drm_file *filp);
992int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
993 struct drm_file *filp);
994int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
995 struct drm_file *file_priv);
996int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
997 struct drm_file *file_priv);
998int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
999 struct drm_file *file_priv);
1000int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
1001 struct drm_file *file_priv);
1002int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1003 struct drm_file *filp);
1004int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
1005 struct drm_file *filp);
1006int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
1007 struct drm_file *filp);
1008int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1009 struct drm_file *filp);
1010int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Dave Airliee024e112009-06-24 09:48:08 +10001011int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1012 struct drm_file *filp);
1013int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1014 struct drm_file *filp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001016/* VRAM scratch page for HDP bug */
1017struct r700_vram_scratch {
1018 struct radeon_bo *robj;
1019 volatile uint32_t *ptr;
1020};
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001021
1022/*
1023 * Core structure, functions and helpers.
1024 */
1025typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1026typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1027
1028struct radeon_device {
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001029 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001030 struct drm_device *ddev;
1031 struct pci_dev *pdev;
1032 /* ASIC */
Jerome Glisse068a1172009-06-17 13:28:30 +02001033 union radeon_asic_config config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001034 enum radeon_family family;
1035 unsigned long flags;
1036 int usec_timeout;
1037 enum radeon_pll_errata pll_errata;
1038 int num_gb_pipes;
Alex Deucherf779b3e2009-08-19 19:11:39 -04001039 int num_z_pipes;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001040 int disp_priority;
1041 /* BIOS */
1042 uint8_t *bios;
1043 bool is_atom_bios;
1044 uint16_t bios_header_start;
Jerome Glisse4c788672009-11-20 14:29:23 +01001045 struct radeon_bo *stollen_vga_memory;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001046 /* Register mmio */
Dave Airlie4c9bc752009-06-29 18:29:12 +10001047 resource_size_t rmmio_base;
1048 resource_size_t rmmio_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001049 void *rmmio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001050 radeon_rreg_t mc_rreg;
1051 radeon_wreg_t mc_wreg;
1052 radeon_rreg_t pll_rreg;
1053 radeon_wreg_t pll_wreg;
Dave Airliede1b2892009-08-12 18:43:14 +10001054 uint32_t pcie_reg_mask;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001055 radeon_rreg_t pciep_rreg;
1056 radeon_wreg_t pciep_wreg;
Alex Deucher351a52a2010-06-30 11:52:50 -04001057 /* io port */
1058 void __iomem *rio_mem;
1059 resource_size_t rio_mem_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001060 struct radeon_clock clock;
1061 struct radeon_mc mc;
1062 struct radeon_gart gart;
1063 struct radeon_mode_info mode_info;
1064 struct radeon_scratch scratch;
1065 struct radeon_mman mman;
1066 struct radeon_fence_driver fence_drv;
1067 struct radeon_cp cp;
1068 struct radeon_ib_pool ib_pool;
1069 struct radeon_irq irq;
1070 struct radeon_asic *asic;
1071 struct radeon_gem gem;
Jerome Glissec93bb852009-07-13 21:04:08 +02001072 struct radeon_pm pm;
Yang Zhaof657c2a2009-09-15 12:21:01 +10001073 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001074 struct mutex cs_mutex;
1075 struct radeon_wb wb;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001076 struct radeon_dummy_page dummy_page;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001077 bool gpu_lockup;
1078 bool shutdown;
1079 bool suspend;
Dave Airliead49f502009-07-10 22:36:26 +10001080 bool need_dma32;
Jerome Glisse733289c2009-09-16 15:24:21 +02001081 bool accel_working;
Dave Airliee024e112009-06-24 09:48:08 +10001082 struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001083 const struct firmware *me_fw; /* all family ME firmware */
1084 const struct firmware *pfp_fw; /* r6/700 PFP firmware */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001085 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001086 struct r600_blit r600_blit;
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001087 struct r700_vram_scratch vram_scratch;
Alex Deucher3e5cb982009-10-16 12:21:24 -04001088 int msi_enabled; /* msi enabled */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001089 struct r600_ih ih; /* r6/700 interrupt ring */
Alex Deucherd4877cf2009-12-04 16:56:37 -05001090 struct workqueue_struct *wq;
1091 struct work_struct hotplug_work;
Alex Deucher18917b62010-02-01 16:02:25 -05001092 int num_crtc; /* number of crtcs */
Alex Deucher40bacf12009-12-23 03:23:21 -05001093 struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
Matthew Garrett5876dd22010-04-26 15:52:20 -04001094 struct mutex vram_mutex;
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001095
1096 /* audio stuff */
Rafał Miłecki7eea7e92010-06-19 12:24:56 +02001097 bool audio_enabled;
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001098 struct timer_list audio_timer;
1099 int audio_channels;
1100 int audio_rate;
1101 int audio_bits_per_sample;
1102 uint8_t audio_status_bits;
1103 uint8_t audio_category_code;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10001104
1105 bool powered_down;
Alex Deucherce8f5372010-05-07 15:10:16 -04001106 struct notifier_block acpi_nb;
Dave Airlieab9e1f52010-07-13 11:11:11 +10001107 /* only one userspace can use Hyperz features at a time */
1108 struct drm_file *hyperz_filp;
Alex Deucherf376b942010-08-05 21:21:16 -04001109 /* i2c buses */
1110 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111};
1112
1113int radeon_device_init(struct radeon_device *rdev,
1114 struct drm_device *ddev,
1115 struct pci_dev *pdev,
1116 uint32_t flags);
1117void radeon_device_fini(struct radeon_device *rdev);
1118int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
1119
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001120/* r600 blit */
1121int r600_blit_prepare_copy(struct radeon_device *rdev, int size_bytes);
1122void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence);
1123void r600_kms_blit_copy(struct radeon_device *rdev,
1124 u64 src_gpu_addr, u64 dst_gpu_addr,
1125 int size_bytes);
1126
Dave Airliede1b2892009-08-12 18:43:14 +10001127static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
1128{
Alex Deucher07bec2d2010-01-13 19:09:12 -05001129 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +10001130 return readl(((void __iomem *)rdev->rmmio) + reg);
1131 else {
1132 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1133 return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1134 }
1135}
1136
1137static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1138{
Alex Deucher07bec2d2010-01-13 19:09:12 -05001139 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +10001140 writel(v, ((void __iomem *)rdev->rmmio) + reg);
1141 else {
1142 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1143 writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1144 }
1145}
1146
Alex Deucher351a52a2010-06-30 11:52:50 -04001147static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
1148{
1149 if (reg < rdev->rio_mem_size)
1150 return ioread32(rdev->rio_mem + reg);
1151 else {
1152 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1153 return ioread32(rdev->rio_mem + RADEON_MM_DATA);
1154 }
1155}
1156
1157static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1158{
1159 if (reg < rdev->rio_mem_size)
1160 iowrite32(v, rdev->rio_mem + reg);
1161 else {
1162 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1163 iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
1164 }
1165}
1166
Jerome Glisse4c788672009-11-20 14:29:23 +01001167/*
1168 * Cast helper
1169 */
1170#define to_radeon_fence(p) ((struct radeon_fence *)(p))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001171
1172/*
1173 * Registers read & write functions.
1174 */
1175#define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
1176#define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
Dave Airliede1b2892009-08-12 18:43:14 +10001177#define RREG32(reg) r100_mm_rreg(rdev, (reg))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001178#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
Dave Airliede1b2892009-08-12 18:43:14 +10001179#define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001180#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1181#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1182#define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1183#define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1184#define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1185#define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
Dave Airliede1b2892009-08-12 18:43:14 +10001186#define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1187#define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
Rafał Miłeckiaa5120d2010-02-18 20:24:28 +00001188#define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1189#define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001190#define WREG32_P(reg, val, mask) \
1191 do { \
1192 uint32_t tmp_ = RREG32(reg); \
1193 tmp_ &= (mask); \
1194 tmp_ |= ((val) & ~(mask)); \
1195 WREG32(reg, tmp_); \
1196 } while (0)
1197#define WREG32_PLL_P(reg, val, mask) \
1198 do { \
1199 uint32_t tmp_ = RREG32_PLL(reg); \
1200 tmp_ &= (mask); \
1201 tmp_ |= ((val) & ~(mask)); \
1202 WREG32_PLL(reg, tmp_); \
1203 } while (0)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001204#define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
Alex Deucher351a52a2010-06-30 11:52:50 -04001205#define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
1206#define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001207
Dave Airliede1b2892009-08-12 18:43:14 +10001208/*
1209 * Indirect registers accessor
1210 */
1211static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1212{
1213 uint32_t r;
1214
1215 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1216 r = RREG32(RADEON_PCIE_DATA);
1217 return r;
1218}
1219
1220static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1221{
1222 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1223 WREG32(RADEON_PCIE_DATA, (v));
1224}
1225
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001226void r100_pll_errata_after_index(struct radeon_device *rdev);
1227
1228
1229/*
1230 * ASICs helpers.
1231 */
Dave Airlieb995e432009-07-14 02:02:32 +10001232#define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1233 (rdev->pdev->device == 0x5969))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001234#define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1235 (rdev->family == CHIP_RV200) || \
1236 (rdev->family == CHIP_RS100) || \
1237 (rdev->family == CHIP_RS200) || \
1238 (rdev->family == CHIP_RV250) || \
1239 (rdev->family == CHIP_RV280) || \
1240 (rdev->family == CHIP_RS300))
1241#define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
1242 (rdev->family == CHIP_RV350) || \
1243 (rdev->family == CHIP_R350) || \
1244 (rdev->family == CHIP_RV380) || \
1245 (rdev->family == CHIP_R420) || \
1246 (rdev->family == CHIP_R423) || \
1247 (rdev->family == CHIP_RV410) || \
1248 (rdev->family == CHIP_RS400) || \
1249 (rdev->family == CHIP_RS480))
1250#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1251#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1252#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001253#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254
1255/*
1256 * BIOS helpers.
1257 */
1258#define RBIOS8(i) (rdev->bios[i])
1259#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1260#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1261
1262int radeon_combios_init(struct radeon_device *rdev);
1263void radeon_combios_fini(struct radeon_device *rdev);
1264int radeon_atombios_init(struct radeon_device *rdev);
1265void radeon_atombios_fini(struct radeon_device *rdev);
1266
1267
1268/*
1269 * RING helpers.
1270 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001271static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
1272{
1273#if DRM_DEBUG_CODE
1274 if (rdev->cp.count_dw <= 0) {
1275 DRM_ERROR("radeon: writting more dword to ring than expected !\n");
1276 }
1277#endif
1278 rdev->cp.ring[rdev->cp.wptr++] = v;
1279 rdev->cp.wptr &= rdev->cp.ptr_mask;
1280 rdev->cp.count_dw--;
1281 rdev->cp.ring_free_dw--;
1282}
1283
1284
1285/*
1286 * ASICs macro.
1287 */
Jerome Glisse068a1172009-06-17 13:28:30 +02001288#define radeon_init(rdev) (rdev)->asic->init((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001289#define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1290#define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1291#define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001292#define radeon_cs_parse(p) rdev->asic->cs_parse((p))
Dave Airlie28d52042009-09-21 14:33:58 +10001293#define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
Jerome Glisse225758d2010-03-09 14:45:10 +00001294#define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
Jerome Glissea2d07b72010-03-09 14:45:11 +00001295#define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001296#define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1297#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001298#define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001299#define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001300#define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1301#define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001302#define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1303#define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
Michel Dänzer7ed220d2009-08-13 11:10:51 +02001304#define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001305#define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1306#define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1307#define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1308#define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
Rafał Miłecki74338742009-11-03 00:53:02 +01001309#define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001310#define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
Rafał Miłecki74338742009-11-03 00:53:02 +01001311#define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
Rafał Miłecki93e7de72009-11-04 23:34:10 +01001312#define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
Alex Deucherc836a412009-12-23 10:07:50 -05001313#define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001314#define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1315#define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
Dave Airliee024e112009-06-24 09:48:08 +10001316#define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1317#define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
Jerome Glissec93bb852009-07-13 21:04:08 +02001318#define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
Alex Deucher429770b2009-12-04 15:26:55 -05001319#define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1320#define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1321#define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1322#define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
Alex Deucherdef9ba92010-04-22 12:39:58 -04001323#define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
Alex Deuchera4248162010-04-24 14:50:23 -04001324#define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
1325#define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
1326#define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
Alex Deucherce8f5372010-05-07 15:10:16 -04001327#define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
1328#define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001329
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001330/* Common functions */
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001331/* AGP */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001332extern int radeon_gpu_reset(struct radeon_device *rdev);
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001333extern void radeon_agp_disable(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001334extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
Dave Airlie82568562010-02-05 16:00:07 +10001335extern void radeon_gart_restore(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001336extern int radeon_modeset_init(struct radeon_device *rdev);
1337extern void radeon_modeset_fini(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001338extern bool radeon_card_posted(struct radeon_device *rdev);
Alex Deucherf47299c2010-03-16 20:54:38 -04001339extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
Alex Deucherf46c0122010-03-31 00:33:27 -04001340extern void radeon_update_display_priority(struct radeon_device *rdev);
Dave Airlie72542d72009-12-01 14:06:31 +10001341extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001342extern void radeon_scratch_init(struct radeon_device *rdev);
1343extern void radeon_surface_init(struct radeon_device *rdev);
1344extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001345extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001346extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glisse312ea8d2009-12-07 15:52:58 +01001347extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
Jerome Glissed03d8582009-12-14 21:02:09 +01001348extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
Jerome Glissed594e462010-02-17 21:54:29 +00001349extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1350extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10001351extern int radeon_resume_kms(struct drm_device *dev);
1352extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001353
Jerome Glissea18d7ea2009-09-09 22:23:27 +02001354/* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */
Jerome Glisse225758d2010-03-09 14:45:10 +00001355extern void r100_gpu_lockup_update(struct r100_gpu_lockup *lockup, struct radeon_cp *cp);
1356extern bool r100_gpu_cp_is_lockup(struct radeon_device *rdev, struct r100_gpu_lockup *lockup, struct radeon_cp *cp);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001357
Jerome Glissed4550902009-10-01 10:12:06 +02001358/* rv200,rv250,rv280 */
1359extern void r200_set_safe_registers(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001360
1361/* r300,r350,rv350,rv370,rv380 */
1362extern void r300_set_reg_safe(struct radeon_device *rdev);
1363extern void r300_mc_program(struct radeon_device *rdev);
Jerome Glissed594e462010-02-17 21:54:29 +00001364extern void r300_mc_init(struct radeon_device *rdev);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001365extern void r300_clock_startup(struct radeon_device *rdev);
1366extern int r300_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001367extern int rv370_pcie_gart_init(struct radeon_device *rdev);
1368extern void rv370_pcie_gart_fini(struct radeon_device *rdev);
1369extern int rv370_pcie_gart_enable(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001370extern void rv370_pcie_gart_disable(struct radeon_device *rdev);
Jerome Glissea18d7ea2009-09-09 22:23:27 +02001371
Jerome Glisse905b6822009-09-09 22:24:20 +02001372/* r420,r423,rv410 */
Jerome Glisse21f9a432009-09-11 15:55:33 +02001373extern u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg);
1374extern void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001375extern int r420_debugfs_pipes_info_init(struct radeon_device *rdev);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001376extern void r420_pipes_init(struct radeon_device *rdev);
Jerome Glisse905b6822009-09-09 22:24:20 +02001377
Jerome Glisse21f9a432009-09-11 15:55:33 +02001378/* rv515 */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001379struct rv515_mc_save {
1380 u32 d1vga_control;
1381 u32 d2vga_control;
1382 u32 vga_render_control;
1383 u32 vga_hdp_control;
1384 u32 d1crtc_control;
1385 u32 d2crtc_control;
1386};
Jerome Glisse21f9a432009-09-11 15:55:33 +02001387extern void rv515_bandwidth_avivo_update(struct radeon_device *rdev);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001388extern void rv515_vga_render_disable(struct radeon_device *rdev);
1389extern void rv515_set_safe_registers(struct radeon_device *rdev);
Jerome Glissef0ed1f62009-09-28 20:39:19 +02001390extern void rv515_mc_stop(struct radeon_device *rdev, struct rv515_mc_save *save);
1391extern void rv515_mc_resume(struct radeon_device *rdev, struct rv515_mc_save *save);
1392extern void rv515_clock_startup(struct radeon_device *rdev);
1393extern void rv515_debugfs(struct radeon_device *rdev);
1394extern int rv515_suspend(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001395
Jerome Glisse3bc68532009-10-01 09:39:24 +02001396/* rs400 */
1397extern int rs400_gart_init(struct radeon_device *rdev);
1398extern int rs400_gart_enable(struct radeon_device *rdev);
1399extern void rs400_gart_adjust_size(struct radeon_device *rdev);
1400extern void rs400_gart_disable(struct radeon_device *rdev);
1401extern void rs400_gart_fini(struct radeon_device *rdev);
1402
1403/* rs600 */
1404extern void rs600_set_safe_registers(struct radeon_device *rdev);
Jerome Glisseac447df2009-09-30 22:18:43 +02001405extern int rs600_irq_set(struct radeon_device *rdev);
1406extern void rs600_irq_disable(struct radeon_device *rdev);
Jerome Glisse3bc68532009-10-01 09:39:24 +02001407
Jerome Glisse21f9a432009-09-11 15:55:33 +02001408/* rs690, rs740 */
1409extern void rs690_line_buffer_adjust(struct radeon_device *rdev,
1410 struct drm_display_mode *mode1,
1411 struct drm_display_mode *mode2);
1412
1413/* r600, rv610, rv630, rv620, rv635, rv670, rs780, rs880 */
Jerome Glissed594e462010-02-17 21:54:29 +00001414extern void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001415extern bool r600_card_posted(struct radeon_device *rdev);
1416extern void r600_cp_stop(struct radeon_device *rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04001417extern int r600_cp_start(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001418extern void r600_ring_init(struct radeon_device *rdev, unsigned ring_size);
1419extern int r600_cp_resume(struct radeon_device *rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001420extern void r600_cp_fini(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001421extern int r600_count_pipe_bits(uint32_t val);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001422extern int r600_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001423extern int r600_pcie_gart_init(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001424extern void r600_pcie_gart_tlb_flush(struct radeon_device *rdev);
1425extern int r600_ib_test(struct radeon_device *rdev);
1426extern int r600_ring_test(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001427extern void r600_wb_fini(struct radeon_device *rdev);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001428extern int r600_wb_enable(struct radeon_device *rdev);
1429extern void r600_wb_disable(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001430extern void r600_scratch_init(struct radeon_device *rdev);
1431extern int r600_blit_init(struct radeon_device *rdev);
1432extern void r600_blit_fini(struct radeon_device *rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001433extern int r600_init_microcode(struct radeon_device *rdev);
Jerome Glissea2d07b72010-03-09 14:45:11 +00001434extern int r600_asic_reset(struct radeon_device *rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001435/* r600 irq */
1436extern int r600_irq_init(struct radeon_device *rdev);
1437extern void r600_irq_fini(struct radeon_device *rdev);
1438extern void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size);
1439extern int r600_irq_set(struct radeon_device *rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01001440extern void r600_irq_suspend(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -04001441extern void r600_disable_interrupts(struct radeon_device *rdev);
1442extern void r600_rlc_stop(struct radeon_device *rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01001443/* r600 audio */
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001444extern int r600_audio_init(struct radeon_device *rdev);
1445extern int r600_audio_tmds_index(struct drm_encoder *encoder);
1446extern void r600_audio_set_clock(struct drm_encoder *encoder, int clock);
Christian König58bd0862010-04-05 22:14:55 +02001447extern int r600_audio_channels(struct radeon_device *rdev);
1448extern int r600_audio_bits_per_sample(struct radeon_device *rdev);
1449extern int r600_audio_rate(struct radeon_device *rdev);
1450extern uint8_t r600_audio_status_bits(struct radeon_device *rdev);
1451extern uint8_t r600_audio_category_code(struct radeon_device *rdev);
Christian Koenigf2594932010-04-10 03:13:16 +02001452extern void r600_audio_schedule_polling(struct radeon_device *rdev);
Christian König58bd0862010-04-05 22:14:55 +02001453extern void r600_audio_enable_polling(struct drm_encoder *encoder);
1454extern void r600_audio_disable_polling(struct drm_encoder *encoder);
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001455extern void r600_audio_fini(struct radeon_device *rdev);
1456extern void r600_hdmi_init(struct drm_encoder *encoder);
Rafał Miłecki2cd6218c2010-03-08 22:14:01 +00001457extern void r600_hdmi_enable(struct drm_encoder *encoder);
1458extern void r600_hdmi_disable(struct drm_encoder *encoder);
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001459extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1460extern int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
Christian König58bd0862010-04-05 22:14:55 +02001461extern void r600_hdmi_update_audio_settings(struct drm_encoder *encoder);
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001462
Alex Deucherfe251e22010-03-24 13:36:43 -04001463extern void r700_cp_stop(struct radeon_device *rdev);
1464extern void r700_cp_fini(struct radeon_device *rdev);
Alex Deucher0ca2ab52010-02-26 13:57:45 -05001465extern void evergreen_disable_interrupt_state(struct radeon_device *rdev);
1466extern int evergreen_irq_set(struct radeon_device *rdev);
Alex Deucherfe251e22010-03-24 13:36:43 -04001467
Alberto Miloned7a29522010-07-06 11:40:24 -04001468/* radeon_acpi.c */
1469#if defined(CONFIG_ACPI)
1470extern int radeon_acpi_init(struct radeon_device *rdev);
1471#else
1472static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
1473#endif
1474
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001475/* evergreen */
1476struct evergreen_mc_save {
1477 u32 vga_control[6];
1478 u32 vga_render_control;
1479 u32 vga_hdp_control;
1480 u32 crtc_control[6];
1481};
1482
Jerome Glisse4c788672009-11-20 14:29:23 +01001483#include "radeon_object.h"
1484
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001485#endif