blob: c0356bb193e57f39ef602ad50c6af607b056c15a [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;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020093
94/*
95 * Copy from radeon_drv.h so we don't have to include both and have conflicting
96 * symbol;
97 */
98#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
Jerome Glisse91cb91b2010-02-15 21:36:13 +010099/* RADEON_IB_POOL_SIZE must be a power of 2 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200100#define RADEON_IB_POOL_SIZE 16
101#define RADEON_DEBUGFS_MAX_NUM_FILES 32
102#define RADEONFB_CONN_LIMIT 4
Yang Zhaof657c2a2009-09-15 12:21:01 +1000103#define RADEON_BIOS_NUM_SCRATCH 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200104
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200105/*
106 * Errata workarounds.
107 */
108enum radeon_pll_errata {
109 CHIP_ERRATA_R300_CG = 0x00000001,
110 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
111 CHIP_ERRATA_PLL_DELAY = 0x00000004
112};
113
114
115struct radeon_device;
116
117
118/*
119 * BIOS.
120 */
121bool radeon_get_bios(struct radeon_device *rdev);
122
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000123
124/*
125 * Dummy page
126 */
127struct radeon_dummy_page {
128 struct page *page;
129 dma_addr_t addr;
130};
131int radeon_dummy_page_init(struct radeon_device *rdev);
132void radeon_dummy_page_fini(struct radeon_device *rdev);
133
134
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200135/*
136 * Clocks
137 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200138struct radeon_clock {
139 struct radeon_pll p1pll;
140 struct radeon_pll p2pll;
141 struct radeon_pll spll;
142 struct radeon_pll mpll;
143 /* 10 Khz units */
144 uint32_t default_mclk;
145 uint32_t default_sclk;
146};
147
Rafał Miłecki74338742009-11-03 00:53:02 +0100148/*
149 * Power management
150 */
151int radeon_pm_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000152
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200153/*
154 * Fences.
155 */
156struct radeon_fence_driver {
157 uint32_t scratch_reg;
158 atomic_t seq;
159 uint32_t last_seq;
160 unsigned long count_timeout;
161 wait_queue_head_t queue;
162 rwlock_t lock;
163 struct list_head created;
164 struct list_head emited;
165 struct list_head signaled;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100166 bool initialized;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200167};
168
169struct radeon_fence {
170 struct radeon_device *rdev;
171 struct kref kref;
172 struct list_head list;
173 /* protected by radeon_fence.lock */
174 uint32_t seq;
175 unsigned long timeout;
176 bool emited;
177 bool signaled;
178};
179
180int radeon_fence_driver_init(struct radeon_device *rdev);
181void radeon_fence_driver_fini(struct radeon_device *rdev);
182int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
183int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
184void radeon_fence_process(struct radeon_device *rdev);
185bool radeon_fence_signaled(struct radeon_fence *fence);
186int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
187int radeon_fence_wait_next(struct radeon_device *rdev);
188int radeon_fence_wait_last(struct radeon_device *rdev);
189struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
190void radeon_fence_unref(struct radeon_fence **fence);
191
Dave Airliee024e112009-06-24 09:48:08 +1000192/*
193 * Tiling registers
194 */
195struct radeon_surface_reg {
Jerome Glisse4c788672009-11-20 14:29:23 +0100196 struct radeon_bo *bo;
Dave Airliee024e112009-06-24 09:48:08 +1000197};
198
199#define RADEON_GEM_MAX_SURFACES 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200200
201/*
Jerome Glisse4c788672009-11-20 14:29:23 +0100202 * TTM.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200203 */
Jerome Glisse4c788672009-11-20 14:29:23 +0100204struct radeon_mman {
205 struct ttm_bo_global_ref bo_global_ref;
206 struct ttm_global_reference mem_global_ref;
Jerome Glisse4c788672009-11-20 14:29:23 +0100207 struct ttm_bo_device bdev;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100208 bool mem_global_referenced;
209 bool initialized;
Jerome Glisse4c788672009-11-20 14:29:23 +0100210};
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200211
Jerome Glisse4c788672009-11-20 14:29:23 +0100212struct radeon_bo {
213 /* Protected by gem.mutex */
214 struct list_head list;
215 /* Protected by tbo.reserved */
Jerome Glisse312ea8d2009-12-07 15:52:58 +0100216 u32 placements[3];
217 struct ttm_placement placement;
Jerome Glisse4c788672009-11-20 14:29:23 +0100218 struct ttm_buffer_object tbo;
219 struct ttm_bo_kmap_obj kmap;
220 unsigned pin_count;
221 void *kptr;
222 u32 tiling_flags;
223 u32 pitch;
224 int surface_reg;
225 /* Constant after initialization */
226 struct radeon_device *rdev;
227 struct drm_gem_object *gobj;
228};
229
230struct radeon_bo_list {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200231 struct list_head list;
Jerome Glisse4c788672009-11-20 14:29:23 +0100232 struct radeon_bo *bo;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200233 uint64_t gpu_offset;
234 unsigned rdomain;
235 unsigned wdomain;
Jerome Glisse4c788672009-11-20 14:29:23 +0100236 u32 tiling_flags;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200237};
238
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200239/*
240 * GEM objects.
241 */
242struct radeon_gem {
Jerome Glisse4c788672009-11-20 14:29:23 +0100243 struct mutex mutex;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200244 struct list_head objects;
245};
246
247int radeon_gem_init(struct radeon_device *rdev);
248void radeon_gem_fini(struct radeon_device *rdev);
249int radeon_gem_object_create(struct radeon_device *rdev, int size,
Jerome Glisse4c788672009-11-20 14:29:23 +0100250 int alignment, int initial_domain,
251 bool discardable, bool kernel,
252 struct drm_gem_object **obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200253int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
254 uint64_t *gpu_addr);
255void radeon_gem_object_unpin(struct drm_gem_object *obj);
256
257
258/*
259 * GART structures, functions & helpers
260 */
261struct radeon_mc;
262
263struct radeon_gart_table_ram {
264 volatile uint32_t *ptr;
265};
266
267struct radeon_gart_table_vram {
Jerome Glisse4c788672009-11-20 14:29:23 +0100268 struct radeon_bo *robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200269 volatile uint32_t *ptr;
270};
271
272union radeon_gart_table {
273 struct radeon_gart_table_ram ram;
274 struct radeon_gart_table_vram vram;
275};
276
Matt Turnera77f1712009-10-14 00:34:41 -0400277#define RADEON_GPU_PAGE_SIZE 4096
278
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200279struct radeon_gart {
280 dma_addr_t table_addr;
281 unsigned num_gpu_pages;
282 unsigned num_cpu_pages;
283 unsigned table_size;
284 union radeon_gart_table table;
285 struct page **pages;
286 dma_addr_t *pages_addr;
287 bool ready;
288};
289
290int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
291void radeon_gart_table_ram_free(struct radeon_device *rdev);
292int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
293void radeon_gart_table_vram_free(struct radeon_device *rdev);
294int radeon_gart_init(struct radeon_device *rdev);
295void radeon_gart_fini(struct radeon_device *rdev);
296void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
297 int pages);
298int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
299 int pages, struct page **pagelist);
300
301
302/*
303 * GPU MC structures, functions & helpers
304 */
305struct radeon_mc {
306 resource_size_t aper_size;
307 resource_size_t aper_base;
308 resource_size_t agp_base;
Dave Airlie7a50f012009-07-21 20:39:30 +1000309 /* for some chips with <= 32MB we need to lie
310 * about vram size near mc fb location */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000311 u64 mc_vram_size;
312 u64 gtt_location;
313 u64 gtt_size;
314 u64 gtt_start;
315 u64 gtt_end;
316 u64 vram_location;
317 u64 vram_start;
318 u64 vram_end;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200319 unsigned vram_width;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000320 u64 real_vram_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200321 int vram_mtrr;
322 bool vram_is_ddr;
Alex Deucher06b64762010-01-05 11:27:29 -0500323 bool igp_sideport_enabled;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200324};
325
326int radeon_mc_setup(struct radeon_device *rdev);
Alex Deucher06b64762010-01-05 11:27:29 -0500327bool radeon_combios_sideport_present(struct radeon_device *rdev);
328bool radeon_atombios_sideport_present(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200329
330/*
331 * GPU scratch registers structures, functions & helpers
332 */
333struct radeon_scratch {
334 unsigned num_reg;
335 bool free[32];
336 uint32_t reg[32];
337};
338
339int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
340void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
341
342
343/*
344 * IRQS.
345 */
346struct radeon_irq {
347 bool installed;
348 bool sw_int;
349 /* FIXME: use a define max crtc rather than hardcode it */
350 bool crtc_vblank_int[2];
Alex Deucherb500f682009-12-03 13:08:53 -0500351 /* FIXME: use defines for max hpd/dacs */
352 bool hpd[6];
Dave Airlie1614f8b2009-12-01 16:04:56 +1000353 spinlock_t sw_lock;
354 int sw_refcount;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200355};
356
357int radeon_irq_kms_init(struct radeon_device *rdev);
358void radeon_irq_kms_fini(struct radeon_device *rdev);
Dave Airlie1614f8b2009-12-01 16:04:56 +1000359void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
360void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200361
362/*
363 * CP & ring.
364 */
365struct radeon_ib {
366 struct list_head list;
Jerome Glisse91cb91b2010-02-15 21:36:13 +0100367 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200368 uint64_t gpu_addr;
369 struct radeon_fence *fence;
Jerome Glisse91cb91b2010-02-15 21:36:13 +0100370 uint32_t *ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200371 uint32_t length_dw;
Jerome Glisse91cb91b2010-02-15 21:36:13 +0100372 bool free;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200373};
374
Dave Airlieecb114a2009-09-15 11:12:56 +1000375/*
376 * locking -
377 * mutex protects scheduled_ibs, ready, alloc_bm
378 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200379struct radeon_ib_pool {
380 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100381 struct radeon_bo *robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200382 struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
383 bool ready;
Jerome Glisse91cb91b2010-02-15 21:36:13 +0100384 unsigned head_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200385};
386
387struct radeon_cp {
Jerome Glisse4c788672009-11-20 14:29:23 +0100388 struct radeon_bo *ring_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200389 volatile uint32_t *ring;
390 unsigned rptr;
391 unsigned wptr;
392 unsigned wptr_old;
393 unsigned ring_size;
394 unsigned ring_free_dw;
395 int count_dw;
396 uint64_t gpu_addr;
397 uint32_t align_mask;
398 uint32_t ptr_mask;
399 struct mutex mutex;
400 bool ready;
401};
402
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500403/*
404 * R6xx+ IH ring
405 */
406struct r600_ih {
Jerome Glisse4c788672009-11-20 14:29:23 +0100407 struct radeon_bo *ring_obj;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500408 volatile uint32_t *ring;
409 unsigned rptr;
410 unsigned wptr;
411 unsigned wptr_old;
412 unsigned ring_size;
413 uint64_t gpu_addr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500414 uint32_t ptr_mask;
415 spinlock_t lock;
416 bool enabled;
417};
418
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000419struct r600_blit {
Jerome Glisseff82f052010-01-22 15:19:00 +0100420 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100421 struct radeon_bo *shader_obj;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000422 u64 shader_gpu_addr;
423 u32 vs_offset, ps_offset;
424 u32 state_offset;
425 u32 state_len;
426 u32 vb_used, vb_total;
427 struct radeon_ib *vb_ib;
428};
429
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200430int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
431void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
432int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
433int radeon_ib_pool_init(struct radeon_device *rdev);
434void radeon_ib_pool_fini(struct radeon_device *rdev);
435int radeon_ib_test(struct radeon_device *rdev);
436/* Ring access between begin & end cannot sleep */
437void radeon_ring_free_size(struct radeon_device *rdev);
438int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
439void radeon_ring_unlock_commit(struct radeon_device *rdev);
440void radeon_ring_unlock_undo(struct radeon_device *rdev);
441int radeon_ring_test(struct radeon_device *rdev);
442int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
443void radeon_ring_fini(struct radeon_device *rdev);
444
445
446/*
447 * CS.
448 */
449struct radeon_cs_reloc {
450 struct drm_gem_object *gobj;
Jerome Glisse4c788672009-11-20 14:29:23 +0100451 struct radeon_bo *robj;
452 struct radeon_bo_list lobj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200453 uint32_t handle;
454 uint32_t flags;
455};
456
457struct radeon_cs_chunk {
458 uint32_t chunk_id;
459 uint32_t length_dw;
Dave Airlie513bcb42009-09-23 16:56:27 +1000460 int kpage_idx[2];
461 uint32_t *kpage[2];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200462 uint32_t *kdata;
Dave Airlie513bcb42009-09-23 16:56:27 +1000463 void __user *user_ptr;
464 int last_copied_page;
465 int last_page_index;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200466};
467
468struct radeon_cs_parser {
Jerome Glissec8c15ff2010-01-18 13:01:36 +0100469 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200470 struct radeon_device *rdev;
471 struct drm_file *filp;
472 /* chunks */
473 unsigned nchunks;
474 struct radeon_cs_chunk *chunks;
475 uint64_t *chunks_array;
476 /* IB */
477 unsigned idx;
478 /* relocations */
479 unsigned nrelocs;
480 struct radeon_cs_reloc *relocs;
481 struct radeon_cs_reloc **relocs_ptr;
482 struct list_head validated;
483 /* indices of various chunks */
484 int chunk_ib_idx;
485 int chunk_relocs_idx;
486 struct radeon_ib *ib;
487 void *track;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000488 unsigned family;
Dave Airlie513bcb42009-09-23 16:56:27 +1000489 int parser_error;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200490};
491
Dave Airlie513bcb42009-09-23 16:56:27 +1000492extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
493extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
494
495
496static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
497{
498 struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
499 u32 pg_idx, pg_offset;
500 u32 idx_value = 0;
501 int new_page;
502
503 pg_idx = (idx * 4) / PAGE_SIZE;
504 pg_offset = (idx * 4) % PAGE_SIZE;
505
506 if (ibc->kpage_idx[0] == pg_idx)
507 return ibc->kpage[0][pg_offset/4];
508 if (ibc->kpage_idx[1] == pg_idx)
509 return ibc->kpage[1][pg_offset/4];
510
511 new_page = radeon_cs_update_pages(p, pg_idx);
512 if (new_page < 0) {
513 p->parser_error = new_page;
514 return 0;
515 }
516
517 idx_value = ibc->kpage[new_page][pg_offset/4];
518 return idx_value;
519}
520
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200521struct radeon_cs_packet {
522 unsigned idx;
523 unsigned type;
524 unsigned reg;
525 unsigned opcode;
526 int count;
527 unsigned one_reg_wr;
528};
529
530typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
531 struct radeon_cs_packet *pkt,
532 unsigned idx, unsigned reg);
533typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
534 struct radeon_cs_packet *pkt);
535
536
537/*
538 * AGP
539 */
540int radeon_agp_init(struct radeon_device *rdev);
Dave Airlie0ebf1712009-11-05 15:39:10 +1000541void radeon_agp_resume(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200542void radeon_agp_fini(struct radeon_device *rdev);
543
544
545/*
546 * Writeback
547 */
548struct radeon_wb {
Jerome Glisse4c788672009-11-20 14:29:23 +0100549 struct radeon_bo *wb_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200550 volatile uint32_t *wb;
551 uint64_t gpu_addr;
552};
553
Jerome Glissec93bb852009-07-13 21:04:08 +0200554/**
555 * struct radeon_pm - power management datas
556 * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
557 * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
558 * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
559 * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
560 * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
561 * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
562 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
563 * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
564 * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
565 * @sclk: GPU clock Mhz (core bandwith depends of this clock)
566 * @needed_bandwidth: current bandwidth needs
567 *
568 * It keeps track of various data needed to take powermanagement decision.
569 * Bandwith need is used to determine minimun clock of the GPU and memory.
570 * Equation between gpu/memory clock and available bandwidth is hw dependent
571 * (type of memory, bus size, efficiency, ...)
572 */
573struct radeon_pm {
574 fixed20_12 max_bandwidth;
575 fixed20_12 igp_sideport_mclk;
576 fixed20_12 igp_system_mclk;
577 fixed20_12 igp_ht_link_clk;
578 fixed20_12 igp_ht_link_width;
579 fixed20_12 k8_bandwidth;
580 fixed20_12 sideport_bandwidth;
581 fixed20_12 ht_bandwidth;
582 fixed20_12 core_bandwidth;
583 fixed20_12 sclk;
584 fixed20_12 needed_bandwidth;
585};
586
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200587
588/*
589 * Benchmarking
590 */
591void radeon_benchmark(struct radeon_device *rdev);
592
593
594/*
Michel Dänzerecc0b322009-07-21 11:23:57 +0200595 * Testing
596 */
597void radeon_test_moves(struct radeon_device *rdev);
598
599
600/*
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200601 * Debugfs
602 */
603int radeon_debugfs_add_files(struct radeon_device *rdev,
604 struct drm_info_list *files,
605 unsigned nfiles);
606int radeon_debugfs_fence_init(struct radeon_device *rdev);
607int r100_debugfs_rbbm_init(struct radeon_device *rdev);
608int r100_debugfs_cp_init(struct radeon_device *rdev);
609
610
611/*
612 * ASIC specific functions.
613 */
614struct radeon_asic {
Jerome Glisse068a1172009-06-17 13:28:30 +0200615 int (*init)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000616 void (*fini)(struct radeon_device *rdev);
617 int (*resume)(struct radeon_device *rdev);
618 int (*suspend)(struct radeon_device *rdev);
Dave Airlie28d52042009-09-21 14:33:58 +1000619 void (*vga_set_state)(struct radeon_device *rdev, bool state);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200620 int (*gpu_reset)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200621 void (*gart_tlb_flush)(struct radeon_device *rdev);
622 int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
623 int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
624 void (*cp_fini)(struct radeon_device *rdev);
625 void (*cp_disable)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000626 void (*cp_commit)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200627 void (*ring_start)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000628 int (*ring_test)(struct radeon_device *rdev);
629 void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200630 int (*irq_set)(struct radeon_device *rdev);
631 int (*irq_process)(struct radeon_device *rdev);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200632 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200633 void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
634 int (*cs_parse)(struct radeon_cs_parser *p);
635 int (*copy_blit)(struct radeon_device *rdev,
636 uint64_t src_offset,
637 uint64_t dst_offset,
638 unsigned num_pages,
639 struct radeon_fence *fence);
640 int (*copy_dma)(struct radeon_device *rdev,
641 uint64_t src_offset,
642 uint64_t dst_offset,
643 unsigned num_pages,
644 struct radeon_fence *fence);
645 int (*copy)(struct radeon_device *rdev,
646 uint64_t src_offset,
647 uint64_t dst_offset,
648 unsigned num_pages,
649 struct radeon_fence *fence);
Rafał Miłecki74338742009-11-03 00:53:02 +0100650 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200651 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
Rafał Miłecki74338742009-11-03 00:53:02 +0100652 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200653 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
654 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
655 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
Dave Airliee024e112009-06-24 09:48:08 +1000656 int (*set_surface_reg)(struct radeon_device *rdev, int reg,
657 uint32_t tiling_flags, uint32_t pitch,
658 uint32_t offset, uint32_t obj_size);
659 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
Jerome Glissec93bb852009-07-13 21:04:08 +0200660 void (*bandwidth_update)(struct radeon_device *rdev);
Alex Deucher429770b2009-12-04 15:26:55 -0500661 void (*hpd_init)(struct radeon_device *rdev);
662 void (*hpd_fini)(struct radeon_device *rdev);
663 bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
664 void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
Jerome Glisse062b3892010-02-04 20:36:39 +0100665 /* ioctl hw specific callback. Some hw might want to perform special
666 * operation on specific ioctl. For instance on wait idle some hw
667 * might want to perform and HDP flush through MMIO as it seems that
668 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
669 * through ring.
670 */
671 void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200672};
673
Jerome Glisse21f9a432009-09-11 15:55:33 +0200674/*
675 * Asic structures
676 */
Dave Airlie551ebd82009-09-01 15:25:57 +1000677struct r100_asic {
678 const unsigned *reg_safe_bm;
679 unsigned reg_safe_bm_size;
Jerome Glissecafe6602010-01-07 12:39:21 +0100680 u32 hdp_cntl;
Dave Airlie551ebd82009-09-01 15:25:57 +1000681};
682
Jerome Glisse21f9a432009-09-11 15:55:33 +0200683struct r300_asic {
684 const unsigned *reg_safe_bm;
685 unsigned reg_safe_bm_size;
Corbin Simpson62cdc0c2010-01-06 19:28:48 +0100686 u32 resync_scratch;
Jerome Glissecafe6602010-01-07 12:39:21 +0100687 u32 hdp_cntl;
Jerome Glisse21f9a432009-09-11 15:55:33 +0200688};
689
690struct r600_asic {
691 unsigned max_pipes;
692 unsigned max_tile_pipes;
693 unsigned max_simds;
694 unsigned max_backends;
695 unsigned max_gprs;
696 unsigned max_threads;
697 unsigned max_stack_entries;
698 unsigned max_hw_contexts;
699 unsigned max_gs_threads;
700 unsigned sx_max_export_size;
701 unsigned sx_max_export_pos_size;
702 unsigned sx_max_export_smx_size;
703 unsigned sq_num_cf_insts;
704};
705
706struct rv770_asic {
707 unsigned max_pipes;
708 unsigned max_tile_pipes;
709 unsigned max_simds;
710 unsigned max_backends;
711 unsigned max_gprs;
712 unsigned max_threads;
713 unsigned max_stack_entries;
714 unsigned max_hw_contexts;
715 unsigned max_gs_threads;
716 unsigned sx_max_export_size;
717 unsigned sx_max_export_pos_size;
718 unsigned sx_max_export_smx_size;
719 unsigned sq_num_cf_insts;
720 unsigned sx_num_of_sets;
721 unsigned sc_prim_fifo_size;
722 unsigned sc_hiz_tile_fifo_size;
723 unsigned sc_earlyz_tile_fifo_fize;
724};
725
Jerome Glisse068a1172009-06-17 13:28:30 +0200726union radeon_asic_config {
727 struct r300_asic r300;
Dave Airlie551ebd82009-09-01 15:25:57 +1000728 struct r100_asic r100;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000729 struct r600_asic r600;
730 struct rv770_asic rv770;
Jerome Glisse068a1172009-06-17 13:28:30 +0200731};
732
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200733
734/*
735 * IOCTL.
736 */
737int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
738 struct drm_file *filp);
739int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
740 struct drm_file *filp);
741int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
742 struct drm_file *file_priv);
743int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
744 struct drm_file *file_priv);
745int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
746 struct drm_file *file_priv);
747int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
748 struct drm_file *file_priv);
749int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
750 struct drm_file *filp);
751int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
752 struct drm_file *filp);
753int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
754 struct drm_file *filp);
755int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
756 struct drm_file *filp);
757int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Dave Airliee024e112009-06-24 09:48:08 +1000758int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
759 struct drm_file *filp);
760int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
761 struct drm_file *filp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200762
763
764/*
765 * Core structure, functions and helpers.
766 */
767typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
768typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
769
770struct radeon_device {
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200771 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200772 struct drm_device *ddev;
773 struct pci_dev *pdev;
774 /* ASIC */
Jerome Glisse068a1172009-06-17 13:28:30 +0200775 union radeon_asic_config config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200776 enum radeon_family family;
777 unsigned long flags;
778 int usec_timeout;
779 enum radeon_pll_errata pll_errata;
780 int num_gb_pipes;
Alex Deucherf779b3e2009-08-19 19:11:39 -0400781 int num_z_pipes;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200782 int disp_priority;
783 /* BIOS */
784 uint8_t *bios;
785 bool is_atom_bios;
786 uint16_t bios_header_start;
Jerome Glisse4c788672009-11-20 14:29:23 +0100787 struct radeon_bo *stollen_vga_memory;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200788 struct fb_info *fbdev_info;
Jerome Glisse4c788672009-11-20 14:29:23 +0100789 struct radeon_bo *fbdev_rbo;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200790 struct radeon_framebuffer *fbdev_rfb;
791 /* Register mmio */
Dave Airlie4c9bc752009-06-29 18:29:12 +1000792 resource_size_t rmmio_base;
793 resource_size_t rmmio_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200794 void *rmmio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200795 radeon_rreg_t mc_rreg;
796 radeon_wreg_t mc_wreg;
797 radeon_rreg_t pll_rreg;
798 radeon_wreg_t pll_wreg;
Dave Airliede1b2892009-08-12 18:43:14 +1000799 uint32_t pcie_reg_mask;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200800 radeon_rreg_t pciep_rreg;
801 radeon_wreg_t pciep_wreg;
802 struct radeon_clock clock;
803 struct radeon_mc mc;
804 struct radeon_gart gart;
805 struct radeon_mode_info mode_info;
806 struct radeon_scratch scratch;
807 struct radeon_mman mman;
808 struct radeon_fence_driver fence_drv;
809 struct radeon_cp cp;
810 struct radeon_ib_pool ib_pool;
811 struct radeon_irq irq;
812 struct radeon_asic *asic;
813 struct radeon_gem gem;
Jerome Glissec93bb852009-07-13 21:04:08 +0200814 struct radeon_pm pm;
Yang Zhaof657c2a2009-09-15 12:21:01 +1000815 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200816 struct mutex cs_mutex;
817 struct radeon_wb wb;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000818 struct radeon_dummy_page dummy_page;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200819 bool gpu_lockup;
820 bool shutdown;
821 bool suspend;
Dave Airliead49f502009-07-10 22:36:26 +1000822 bool need_dma32;
Jerome Glisse733289c2009-09-16 15:24:21 +0200823 bool accel_working;
Dave Airliee024e112009-06-24 09:48:08 +1000824 struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000825 const struct firmware *me_fw; /* all family ME firmware */
826 const struct firmware *pfp_fw; /* r6/700 PFP firmware */
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500827 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000828 struct r600_blit r600_blit;
Alex Deucher3e5cb982009-10-16 12:21:24 -0400829 int msi_enabled; /* msi enabled */
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500830 struct r600_ih ih; /* r6/700 interrupt ring */
Alex Deucherd4877cf2009-12-04 16:56:37 -0500831 struct workqueue_struct *wq;
832 struct work_struct hotplug_work;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200833
834 /* audio stuff */
835 struct timer_list audio_timer;
836 int audio_channels;
837 int audio_rate;
838 int audio_bits_per_sample;
839 uint8_t audio_status_bits;
840 uint8_t audio_category_code;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200841};
842
843int radeon_device_init(struct radeon_device *rdev,
844 struct drm_device *ddev,
845 struct pci_dev *pdev,
846 uint32_t flags);
847void radeon_device_fini(struct radeon_device *rdev);
848int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
849
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000850/* r600 blit */
851int r600_blit_prepare_copy(struct radeon_device *rdev, int size_bytes);
852void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence);
853void r600_kms_blit_copy(struct radeon_device *rdev,
854 u64 src_gpu_addr, u64 dst_gpu_addr,
855 int size_bytes);
856
Dave Airliede1b2892009-08-12 18:43:14 +1000857static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
858{
Alex Deucher07bec2d2010-01-13 19:09:12 -0500859 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +1000860 return readl(((void __iomem *)rdev->rmmio) + reg);
861 else {
862 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
863 return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
864 }
865}
866
867static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
868{
Alex Deucher07bec2d2010-01-13 19:09:12 -0500869 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +1000870 writel(v, ((void __iomem *)rdev->rmmio) + reg);
871 else {
872 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
873 writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
874 }
875}
876
Jerome Glisse4c788672009-11-20 14:29:23 +0100877/*
878 * Cast helper
879 */
880#define to_radeon_fence(p) ((struct radeon_fence *)(p))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200881
882/*
883 * Registers read & write functions.
884 */
885#define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
886#define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
Dave Airliede1b2892009-08-12 18:43:14 +1000887#define RREG32(reg) r100_mm_rreg(rdev, (reg))
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000888#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
Dave Airliede1b2892009-08-12 18:43:14 +1000889#define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200890#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
891#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
892#define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
893#define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
894#define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
895#define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
Dave Airliede1b2892009-08-12 18:43:14 +1000896#define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
897#define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200898#define WREG32_P(reg, val, mask) \
899 do { \
900 uint32_t tmp_ = RREG32(reg); \
901 tmp_ &= (mask); \
902 tmp_ |= ((val) & ~(mask)); \
903 WREG32(reg, tmp_); \
904 } while (0)
905#define WREG32_PLL_P(reg, val, mask) \
906 do { \
907 uint32_t tmp_ = RREG32_PLL(reg); \
908 tmp_ &= (mask); \
909 tmp_ |= ((val) & ~(mask)); \
910 WREG32_PLL(reg, tmp_); \
911 } while (0)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000912#define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200913
Dave Airliede1b2892009-08-12 18:43:14 +1000914/*
915 * Indirect registers accessor
916 */
917static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
918{
919 uint32_t r;
920
921 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
922 r = RREG32(RADEON_PCIE_DATA);
923 return r;
924}
925
926static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
927{
928 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
929 WREG32(RADEON_PCIE_DATA, (v));
930}
931
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200932void r100_pll_errata_after_index(struct radeon_device *rdev);
933
934
935/*
936 * ASICs helpers.
937 */
Dave Airlieb995e432009-07-14 02:02:32 +1000938#define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
939 (rdev->pdev->device == 0x5969))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200940#define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
941 (rdev->family == CHIP_RV200) || \
942 (rdev->family == CHIP_RS100) || \
943 (rdev->family == CHIP_RS200) || \
944 (rdev->family == CHIP_RV250) || \
945 (rdev->family == CHIP_RV280) || \
946 (rdev->family == CHIP_RS300))
947#define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
948 (rdev->family == CHIP_RV350) || \
949 (rdev->family == CHIP_R350) || \
950 (rdev->family == CHIP_RV380) || \
951 (rdev->family == CHIP_R420) || \
952 (rdev->family == CHIP_R423) || \
953 (rdev->family == CHIP_RV410) || \
954 (rdev->family == CHIP_RS400) || \
955 (rdev->family == CHIP_RS480))
956#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
957#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
958#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
959
960
961/*
962 * BIOS helpers.
963 */
964#define RBIOS8(i) (rdev->bios[i])
965#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
966#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
967
968int radeon_combios_init(struct radeon_device *rdev);
969void radeon_combios_fini(struct radeon_device *rdev);
970int radeon_atombios_init(struct radeon_device *rdev);
971void radeon_atombios_fini(struct radeon_device *rdev);
972
973
974/*
975 * RING helpers.
976 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200977static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
978{
979#if DRM_DEBUG_CODE
980 if (rdev->cp.count_dw <= 0) {
981 DRM_ERROR("radeon: writting more dword to ring than expected !\n");
982 }
983#endif
984 rdev->cp.ring[rdev->cp.wptr++] = v;
985 rdev->cp.wptr &= rdev->cp.ptr_mask;
986 rdev->cp.count_dw--;
987 rdev->cp.ring_free_dw--;
988}
989
990
991/*
992 * ASICs macro.
993 */
Jerome Glisse068a1172009-06-17 13:28:30 +0200994#define radeon_init(rdev) (rdev)->asic->init((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000995#define radeon_fini(rdev) (rdev)->asic->fini((rdev))
996#define radeon_resume(rdev) (rdev)->asic->resume((rdev))
997#define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200998#define radeon_cs_parse(p) rdev->asic->cs_parse((p))
Dave Airlie28d52042009-09-21 14:33:58 +1000999#define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001000#define radeon_gpu_reset(rdev) (rdev)->asic->gpu_reset((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001001#define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1002#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001003#define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001004#define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001005#define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1006#define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001007#define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1008#define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
Michel Dänzer7ed220d2009-08-13 11:10:51 +02001009#define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001010#define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1011#define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1012#define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1013#define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
Rafał Miłecki74338742009-11-03 00:53:02 +01001014#define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015#define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
Rafał Miłecki74338742009-11-03 00:53:02 +01001016#define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
Rafał Miłecki93e7de72009-11-04 23:34:10 +01001017#define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001018#define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1019#define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
Dave Airliee024e112009-06-24 09:48:08 +10001020#define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1021#define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
Jerome Glissec93bb852009-07-13 21:04:08 +02001022#define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
Alex Deucher429770b2009-12-04 15:26:55 -05001023#define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1024#define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1025#define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1026#define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001027
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001028/* Common functions */
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001029/* AGP */
1030extern void radeon_agp_disable(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001031extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001032extern int radeon_modeset_init(struct radeon_device *rdev);
1033extern void radeon_modeset_fini(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001034extern bool radeon_card_posted(struct radeon_device *rdev);
Dave Airlie72542d72009-12-01 14:06:31 +10001035extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001036extern int radeon_clocks_init(struct radeon_device *rdev);
1037extern void radeon_clocks_fini(struct radeon_device *rdev);
1038extern void radeon_scratch_init(struct radeon_device *rdev);
1039extern void radeon_surface_init(struct radeon_device *rdev);
1040extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001041extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001042extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glisse312ea8d2009-12-07 15:52:58 +01001043extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
Jerome Glissed03d8582009-12-14 21:02:09 +01001044extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001045
Jerome Glissea18d7ea2009-09-09 22:23:27 +02001046/* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001047struct r100_mc_save {
1048 u32 GENMO_WT;
1049 u32 CRTC_EXT_CNTL;
1050 u32 CRTC_GEN_CNTL;
1051 u32 CRTC2_GEN_CNTL;
1052 u32 CUR_OFFSET;
1053 u32 CUR2_OFFSET;
1054};
1055extern void r100_cp_disable(struct radeon_device *rdev);
1056extern int r100_cp_init(struct radeon_device *rdev, unsigned ring_size);
1057extern void r100_cp_fini(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001058extern void r100_pci_gart_tlb_flush(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001059extern int r100_pci_gart_init(struct radeon_device *rdev);
1060extern void r100_pci_gart_fini(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001061extern int r100_pci_gart_enable(struct radeon_device *rdev);
1062extern void r100_pci_gart_disable(struct radeon_device *rdev);
1063extern int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001064extern int r100_debugfs_mc_info_init(struct radeon_device *rdev);
1065extern int r100_gui_wait_for_idle(struct radeon_device *rdev);
1066extern void r100_ib_fini(struct radeon_device *rdev);
1067extern int r100_ib_init(struct radeon_device *rdev);
1068extern void r100_irq_disable(struct radeon_device *rdev);
1069extern int r100_irq_set(struct radeon_device *rdev);
1070extern void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save);
1071extern void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001072extern void r100_vram_init_sizes(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001073extern void r100_wb_disable(struct radeon_device *rdev);
1074extern void r100_wb_fini(struct radeon_device *rdev);
1075extern int r100_wb_init(struct radeon_device *rdev);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001076extern void r100_hdp_reset(struct radeon_device *rdev);
1077extern int r100_rb2d_reset(struct radeon_device *rdev);
1078extern int r100_cp_reset(struct radeon_device *rdev);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001079extern void r100_vga_render_disable(struct radeon_device *rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001080extern int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p,
1081 struct radeon_cs_packet *pkt,
Jerome Glisse4c788672009-11-20 14:29:23 +01001082 struct radeon_bo *robj);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001083extern int r100_cs_parse_packet0(struct radeon_cs_parser *p,
1084 struct radeon_cs_packet *pkt,
1085 const unsigned *auth, unsigned n,
1086 radeon_packet0_check_t check);
1087extern int r100_cs_packet_parse(struct radeon_cs_parser *p,
1088 struct radeon_cs_packet *pkt,
1089 unsigned idx);
Dave Airlie17e15b02009-11-05 15:36:53 +10001090extern void r100_enable_bm(struct radeon_device *rdev);
Alex Deucher92cde002009-12-04 10:55:12 -05001091extern void r100_set_common_regs(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001092
Jerome Glissed4550902009-10-01 10:12:06 +02001093/* rv200,rv250,rv280 */
1094extern void r200_set_safe_registers(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001095
1096/* r300,r350,rv350,rv370,rv380 */
1097extern void r300_set_reg_safe(struct radeon_device *rdev);
1098extern void r300_mc_program(struct radeon_device *rdev);
1099extern void r300_vram_info(struct radeon_device *rdev);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001100extern void r300_clock_startup(struct radeon_device *rdev);
1101extern int r300_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001102extern int rv370_pcie_gart_init(struct radeon_device *rdev);
1103extern void rv370_pcie_gart_fini(struct radeon_device *rdev);
1104extern int rv370_pcie_gart_enable(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001105extern void rv370_pcie_gart_disable(struct radeon_device *rdev);
Jerome Glissea18d7ea2009-09-09 22:23:27 +02001106
Jerome Glisse905b6822009-09-09 22:24:20 +02001107/* r420,r423,rv410 */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001108extern int r420_mc_init(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001109extern u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg);
1110extern void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001111extern int r420_debugfs_pipes_info_init(struct radeon_device *rdev);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001112extern void r420_pipes_init(struct radeon_device *rdev);
Jerome Glisse905b6822009-09-09 22:24:20 +02001113
Jerome Glisse21f9a432009-09-11 15:55:33 +02001114/* rv515 */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001115struct rv515_mc_save {
1116 u32 d1vga_control;
1117 u32 d2vga_control;
1118 u32 vga_render_control;
1119 u32 vga_hdp_control;
1120 u32 d1crtc_control;
1121 u32 d2crtc_control;
1122};
Jerome Glisse21f9a432009-09-11 15:55:33 +02001123extern void rv515_bandwidth_avivo_update(struct radeon_device *rdev);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001124extern void rv515_vga_render_disable(struct radeon_device *rdev);
1125extern void rv515_set_safe_registers(struct radeon_device *rdev);
Jerome Glissef0ed1f62009-09-28 20:39:19 +02001126extern void rv515_mc_stop(struct radeon_device *rdev, struct rv515_mc_save *save);
1127extern void rv515_mc_resume(struct radeon_device *rdev, struct rv515_mc_save *save);
1128extern void rv515_clock_startup(struct radeon_device *rdev);
1129extern void rv515_debugfs(struct radeon_device *rdev);
1130extern int rv515_suspend(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001131
Jerome Glisse3bc68532009-10-01 09:39:24 +02001132/* rs400 */
1133extern int rs400_gart_init(struct radeon_device *rdev);
1134extern int rs400_gart_enable(struct radeon_device *rdev);
1135extern void rs400_gart_adjust_size(struct radeon_device *rdev);
1136extern void rs400_gart_disable(struct radeon_device *rdev);
1137extern void rs400_gart_fini(struct radeon_device *rdev);
1138
1139/* rs600 */
1140extern void rs600_set_safe_registers(struct radeon_device *rdev);
Jerome Glisseac447df2009-09-30 22:18:43 +02001141extern int rs600_irq_set(struct radeon_device *rdev);
1142extern void rs600_irq_disable(struct radeon_device *rdev);
Jerome Glisse3bc68532009-10-01 09:39:24 +02001143
Jerome Glisse21f9a432009-09-11 15:55:33 +02001144/* rs690, rs740 */
1145extern void rs690_line_buffer_adjust(struct radeon_device *rdev,
1146 struct drm_display_mode *mode1,
1147 struct drm_display_mode *mode2);
1148
1149/* r600, rv610, rv630, rv620, rv635, rv670, rs780, rs880 */
1150extern bool r600_card_posted(struct radeon_device *rdev);
1151extern void r600_cp_stop(struct radeon_device *rdev);
1152extern void r600_ring_init(struct radeon_device *rdev, unsigned ring_size);
1153extern int r600_cp_resume(struct radeon_device *rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001154extern void r600_cp_fini(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001155extern int r600_count_pipe_bits(uint32_t val);
1156extern int r600_gart_clear_page(struct radeon_device *rdev, int i);
1157extern int r600_mc_wait_for_idle(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001158extern int r600_pcie_gart_init(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001159extern void r600_pcie_gart_tlb_flush(struct radeon_device *rdev);
1160extern int r600_ib_test(struct radeon_device *rdev);
1161extern int r600_ring_test(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001162extern void r600_wb_fini(struct radeon_device *rdev);
Jerome Glisse81cc35b2009-10-01 18:02:12 +02001163extern int r600_wb_enable(struct radeon_device *rdev);
1164extern void r600_wb_disable(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001165extern void r600_scratch_init(struct radeon_device *rdev);
1166extern int r600_blit_init(struct radeon_device *rdev);
1167extern void r600_blit_fini(struct radeon_device *rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001168extern int r600_init_microcode(struct radeon_device *rdev);
Dave Airliefe62e1a2009-09-21 14:06:30 +10001169extern int r600_gpu_reset(struct radeon_device *rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001170/* r600 irq */
1171extern int r600_irq_init(struct radeon_device *rdev);
1172extern void r600_irq_fini(struct radeon_device *rdev);
1173extern void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size);
1174extern int r600_irq_set(struct radeon_device *rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01001175extern void r600_irq_suspend(struct radeon_device *rdev);
1176/* r600 audio */
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001177extern int r600_audio_init(struct radeon_device *rdev);
1178extern int r600_audio_tmds_index(struct drm_encoder *encoder);
1179extern void r600_audio_set_clock(struct drm_encoder *encoder, int clock);
1180extern void r600_audio_fini(struct radeon_device *rdev);
1181extern void r600_hdmi_init(struct drm_encoder *encoder);
1182extern void r600_hdmi_enable(struct drm_encoder *encoder, int enable);
1183extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1184extern int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
1185extern void r600_hdmi_update_audio_settings(struct drm_encoder *encoder,
1186 int channels,
1187 int rate,
1188 int bps,
1189 uint8_t status_bits,
1190 uint8_t category_code);
1191
Jerome Glisse4c788672009-11-20 14:29:23 +01001192#include "radeon_object.h"
1193
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001194#endif