drm/radeon: use one wait queue for all rings add fence_wait_any v2
[pandora-kernel.git] / drivers / gpu / drm / radeon / radeon.h
1 /*
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
31 /* 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
45 /* 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
63 #include <linux/atomic.h>
64 #include <linux/wait.h>
65 #include <linux/list.h>
66 #include <linux/kref.h>
67
68 #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 #include <ttm/ttm_execbuf_util.h>
73
74 #include "radeon_family.h"
75 #include "radeon_mode.h"
76 #include "radeon_reg.h"
77
78 /*
79  * Modules parameters.
80  */
81 extern int radeon_no_wb;
82 extern int radeon_modeset;
83 extern int radeon_dynclks;
84 extern int radeon_r4xx_atom;
85 extern int radeon_agpmode;
86 extern int radeon_vram_limit;
87 extern int radeon_gart_size;
88 extern int radeon_benchmarking;
89 extern int radeon_testing;
90 extern int radeon_connector_table;
91 extern int radeon_tv;
92 extern int radeon_audio;
93 extern int radeon_disp_priority;
94 extern int radeon_hw_i2c;
95 extern int radeon_pcie_gen2;
96 extern int radeon_msi;
97 extern int radeon_lockup_timeout;
98
99 /*
100  * Copy from radeon_drv.h so we don't have to include both and have conflicting
101  * symbol;
102  */
103 #define RADEON_MAX_USEC_TIMEOUT                 100000  /* 100 ms */
104 #define RADEON_FENCE_JIFFIES_TIMEOUT            (HZ / 2)
105 /* RADEON_IB_POOL_SIZE must be a power of 2 */
106 #define RADEON_IB_POOL_SIZE                     16
107 #define RADEON_DEBUGFS_MAX_COMPONENTS           32
108 #define RADEONFB_CONN_LIMIT                     4
109 #define RADEON_BIOS_NUM_SCRATCH                 8
110
111 /* max number of rings */
112 #define RADEON_NUM_RINGS                        3
113
114 /* fence seq are set to this number when signaled */
115 #define RADEON_FENCE_SIGNALED_SEQ               0LL
116 #define RADEON_FENCE_NOTEMITED_SEQ              (~0LL)
117
118 /* internal ring indices */
119 /* r1xx+ has gfx CP ring */
120 #define RADEON_RING_TYPE_GFX_INDEX              0
121
122 /* cayman has 2 compute CP rings */
123 #define CAYMAN_RING_TYPE_CP1_INDEX              1
124 #define CAYMAN_RING_TYPE_CP2_INDEX              2
125
126 /* hardcode those limit for now */
127 #define RADEON_VA_RESERVED_SIZE                 (8 << 20)
128 #define RADEON_IB_VM_MAX_SIZE                   (64 << 10)
129
130 /*
131  * Errata workarounds.
132  */
133 enum radeon_pll_errata {
134         CHIP_ERRATA_R300_CG             = 0x00000001,
135         CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
136         CHIP_ERRATA_PLL_DELAY           = 0x00000004
137 };
138
139
140 struct radeon_device;
141
142
143 /*
144  * BIOS.
145  */
146 #define ATRM_BIOS_PAGE 4096
147
148 #if defined(CONFIG_VGA_SWITCHEROO)
149 bool radeon_atrm_supported(struct pci_dev *pdev);
150 int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
151 #else
152 static inline bool radeon_atrm_supported(struct pci_dev *pdev)
153 {
154         return false;
155 }
156
157 static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
158         return -EINVAL;
159 }
160 #endif
161 bool radeon_get_bios(struct radeon_device *rdev);
162
163
164 /*
165  * Mutex which allows recursive locking from the same process.
166  */
167 struct radeon_mutex {
168         struct mutex            mutex;
169         struct task_struct      *owner;
170         int                     level;
171 };
172
173 static inline void radeon_mutex_init(struct radeon_mutex *mutex)
174 {
175         mutex_init(&mutex->mutex);
176         mutex->owner = NULL;
177         mutex->level = 0;
178 }
179
180 static inline void radeon_mutex_lock(struct radeon_mutex *mutex)
181 {
182         if (mutex_trylock(&mutex->mutex)) {
183                 /* The mutex was unlocked before, so it's ours now */
184                 mutex->owner = current;
185         } else if (mutex->owner != current) {
186                 /* Another process locked the mutex, take it */
187                 mutex_lock(&mutex->mutex);
188                 mutex->owner = current;
189         }
190         /* Otherwise the mutex was already locked by this process */
191
192         mutex->level++;
193 }
194
195 static inline void radeon_mutex_unlock(struct radeon_mutex *mutex)
196 {
197         if (--mutex->level > 0)
198                 return;
199
200         mutex->owner = NULL;
201         mutex_unlock(&mutex->mutex);
202 }
203
204
205 /*
206  * Dummy page
207  */
208 struct radeon_dummy_page {
209         struct page     *page;
210         dma_addr_t      addr;
211 };
212 int radeon_dummy_page_init(struct radeon_device *rdev);
213 void radeon_dummy_page_fini(struct radeon_device *rdev);
214
215
216 /*
217  * Clocks
218  */
219 struct radeon_clock {
220         struct radeon_pll p1pll;
221         struct radeon_pll p2pll;
222         struct radeon_pll dcpll;
223         struct radeon_pll spll;
224         struct radeon_pll mpll;
225         /* 10 Khz units */
226         uint32_t default_mclk;
227         uint32_t default_sclk;
228         uint32_t default_dispclk;
229         uint32_t dp_extclk;
230         uint32_t max_pixel_clock;
231 };
232
233 /*
234  * Power management
235  */
236 int radeon_pm_init(struct radeon_device *rdev);
237 void radeon_pm_fini(struct radeon_device *rdev);
238 void radeon_pm_compute_clocks(struct radeon_device *rdev);
239 void radeon_pm_suspend(struct radeon_device *rdev);
240 void radeon_pm_resume(struct radeon_device *rdev);
241 void radeon_combios_get_power_modes(struct radeon_device *rdev);
242 void radeon_atombios_get_power_modes(struct radeon_device *rdev);
243 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
244 void rs690_pm_info(struct radeon_device *rdev);
245 extern int rv6xx_get_temp(struct radeon_device *rdev);
246 extern int rv770_get_temp(struct radeon_device *rdev);
247 extern int evergreen_get_temp(struct radeon_device *rdev);
248 extern int sumo_get_temp(struct radeon_device *rdev);
249 extern int si_get_temp(struct radeon_device *rdev);
250 extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
251                                     unsigned *bankh, unsigned *mtaspect,
252                                     unsigned *tile_split);
253
254 /*
255  * Fences.
256  */
257 struct radeon_fence_driver {
258         uint32_t                        scratch_reg;
259         uint64_t                        gpu_addr;
260         volatile uint32_t               *cpu_addr;
261         /* seq is protected by ring emission lock */
262         uint64_t                        seq;
263         atomic64_t                      last_seq;
264         unsigned long                   last_activity;
265         bool                            initialized;
266 };
267
268 struct radeon_fence {
269         struct radeon_device            *rdev;
270         struct kref                     kref;
271         /* protected by radeon_fence.lock */
272         uint64_t                        seq;
273         /* RB, DMA, etc. */
274         unsigned                        ring;
275         struct radeon_semaphore         *semaphore;
276 };
277
278 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
279 int radeon_fence_driver_init(struct radeon_device *rdev);
280 void radeon_fence_driver_fini(struct radeon_device *rdev);
281 int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
282 int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
283 void radeon_fence_process(struct radeon_device *rdev, int ring);
284 bool radeon_fence_signaled(struct radeon_fence *fence);
285 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
286 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
287 int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
288 int radeon_fence_wait_any(struct radeon_device *rdev,
289                           struct radeon_fence **fences,
290                           bool intr);
291 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
292 void radeon_fence_unref(struct radeon_fence **fence);
293 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
294
295 /*
296  * Tiling registers
297  */
298 struct radeon_surface_reg {
299         struct radeon_bo *bo;
300 };
301
302 #define RADEON_GEM_MAX_SURFACES 8
303
304 /*
305  * TTM.
306  */
307 struct radeon_mman {
308         struct ttm_bo_global_ref        bo_global_ref;
309         struct drm_global_reference     mem_global_ref;
310         struct ttm_bo_device            bdev;
311         bool                            mem_global_referenced;
312         bool                            initialized;
313 };
314
315 /* bo virtual address in a specific vm */
316 struct radeon_bo_va {
317         /* bo list is protected by bo being reserved */
318         struct list_head                bo_list;
319         /* vm list is protected by vm mutex */
320         struct list_head                vm_list;
321         /* constant after initialization */
322         struct radeon_vm                *vm;
323         struct radeon_bo                *bo;
324         uint64_t                        soffset;
325         uint64_t                        eoffset;
326         uint32_t                        flags;
327         bool                            valid;
328 };
329
330 struct radeon_bo {
331         /* Protected by gem.mutex */
332         struct list_head                list;
333         /* Protected by tbo.reserved */
334         u32                             placements[3];
335         struct ttm_placement            placement;
336         struct ttm_buffer_object        tbo;
337         struct ttm_bo_kmap_obj          kmap;
338         unsigned                        pin_count;
339         void                            *kptr;
340         u32                             tiling_flags;
341         u32                             pitch;
342         int                             surface_reg;
343         /* list of all virtual address to which this bo
344          * is associated to
345          */
346         struct list_head                va;
347         /* Constant after initialization */
348         struct radeon_device            *rdev;
349         struct drm_gem_object           gem_base;
350 };
351 #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
352
353 struct radeon_bo_list {
354         struct ttm_validate_buffer tv;
355         struct radeon_bo        *bo;
356         uint64_t                gpu_offset;
357         unsigned                rdomain;
358         unsigned                wdomain;
359         u32                     tiling_flags;
360 };
361
362 /* sub-allocation manager, it has to be protected by another lock.
363  * By conception this is an helper for other part of the driver
364  * like the indirect buffer or semaphore, which both have their
365  * locking.
366  *
367  * Principe is simple, we keep a list of sub allocation in offset
368  * order (first entry has offset == 0, last entry has the highest
369  * offset).
370  *
371  * When allocating new object we first check if there is room at
372  * the end total_size - (last_object_offset + last_object_size) >=
373  * alloc_size. If so we allocate new object there.
374  *
375  * When there is not enough room at the end, we start waiting for
376  * each sub object until we reach object_offset+object_size >=
377  * alloc_size, this object then become the sub object we return.
378  *
379  * Alignment can't be bigger than page size.
380  *
381  * Hole are not considered for allocation to keep things simple.
382  * Assumption is that there won't be hole (all object on same
383  * alignment).
384  */
385 struct radeon_sa_manager {
386         spinlock_t              lock;
387         struct radeon_bo        *bo;
388         struct list_head        sa_bo;
389         unsigned                size;
390         uint64_t                gpu_addr;
391         void                    *cpu_ptr;
392         uint32_t                domain;
393 };
394
395 struct radeon_sa_bo;
396
397 /* sub-allocation buffer */
398 struct radeon_sa_bo {
399         struct list_head                list;
400         struct radeon_sa_manager        *manager;
401         unsigned                        soffset;
402         unsigned                        eoffset;
403         struct radeon_fence             *fence;
404 };
405
406 /*
407  * GEM objects.
408  */
409 struct radeon_gem {
410         struct mutex            mutex;
411         struct list_head        objects;
412 };
413
414 int radeon_gem_init(struct radeon_device *rdev);
415 void radeon_gem_fini(struct radeon_device *rdev);
416 int radeon_gem_object_create(struct radeon_device *rdev, int size,
417                                 int alignment, int initial_domain,
418                                 bool discardable, bool kernel,
419                                 struct drm_gem_object **obj);
420
421 int radeon_mode_dumb_create(struct drm_file *file_priv,
422                             struct drm_device *dev,
423                             struct drm_mode_create_dumb *args);
424 int radeon_mode_dumb_mmap(struct drm_file *filp,
425                           struct drm_device *dev,
426                           uint32_t handle, uint64_t *offset_p);
427 int radeon_mode_dumb_destroy(struct drm_file *file_priv,
428                              struct drm_device *dev,
429                              uint32_t handle);
430
431 /*
432  * Semaphores.
433  */
434 struct radeon_ring;
435
436 #define RADEON_SEMAPHORE_BO_SIZE        256
437
438 struct radeon_semaphore_driver {
439         rwlock_t                        lock;
440         struct list_head                bo;
441 };
442
443 struct radeon_semaphore_bo;
444
445 /* everything here is constant */
446 struct radeon_semaphore {
447         struct list_head                list;
448         uint64_t                        gpu_addr;
449         uint32_t                        *cpu_ptr;
450         struct radeon_semaphore_bo      *bo;
451 };
452
453 struct radeon_semaphore_bo {
454         struct list_head                list;
455         struct radeon_ib                *ib;
456         struct list_head                free;
457         struct radeon_semaphore         semaphores[RADEON_SEMAPHORE_BO_SIZE/8];
458         unsigned                        nused;
459 };
460
461 void radeon_semaphore_driver_fini(struct radeon_device *rdev);
462 int radeon_semaphore_create(struct radeon_device *rdev,
463                             struct radeon_semaphore **semaphore);
464 void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
465                                   struct radeon_semaphore *semaphore);
466 void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
467                                 struct radeon_semaphore *semaphore);
468 int radeon_semaphore_sync_rings(struct radeon_device *rdev,
469                                 struct radeon_semaphore *semaphore,
470                                 bool sync_to[RADEON_NUM_RINGS],
471                                 int dst_ring);
472 void radeon_semaphore_free(struct radeon_device *rdev,
473                            struct radeon_semaphore *semaphore);
474
475 /*
476  * GART structures, functions & helpers
477  */
478 struct radeon_mc;
479
480 #define RADEON_GPU_PAGE_SIZE 4096
481 #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
482 #define RADEON_GPU_PAGE_SHIFT 12
483 #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
484
485 struct radeon_gart {
486         dma_addr_t                      table_addr;
487         struct radeon_bo                *robj;
488         void                            *ptr;
489         unsigned                        num_gpu_pages;
490         unsigned                        num_cpu_pages;
491         unsigned                        table_size;
492         struct page                     **pages;
493         dma_addr_t                      *pages_addr;
494         bool                            ready;
495 };
496
497 int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
498 void radeon_gart_table_ram_free(struct radeon_device *rdev);
499 int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
500 void radeon_gart_table_vram_free(struct radeon_device *rdev);
501 int radeon_gart_table_vram_pin(struct radeon_device *rdev);
502 void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
503 int radeon_gart_init(struct radeon_device *rdev);
504 void radeon_gart_fini(struct radeon_device *rdev);
505 void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
506                         int pages);
507 int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
508                      int pages, struct page **pagelist,
509                      dma_addr_t *dma_addr);
510 void radeon_gart_restore(struct radeon_device *rdev);
511
512
513 /*
514  * GPU MC structures, functions & helpers
515  */
516 struct radeon_mc {
517         resource_size_t         aper_size;
518         resource_size_t         aper_base;
519         resource_size_t         agp_base;
520         /* for some chips with <= 32MB we need to lie
521          * about vram size near mc fb location */
522         u64                     mc_vram_size;
523         u64                     visible_vram_size;
524         u64                     gtt_size;
525         u64                     gtt_start;
526         u64                     gtt_end;
527         u64                     vram_start;
528         u64                     vram_end;
529         unsigned                vram_width;
530         u64                     real_vram_size;
531         int                     vram_mtrr;
532         bool                    vram_is_ddr;
533         bool                    igp_sideport_enabled;
534         u64                     gtt_base_align;
535 };
536
537 bool radeon_combios_sideport_present(struct radeon_device *rdev);
538 bool radeon_atombios_sideport_present(struct radeon_device *rdev);
539
540 /*
541  * GPU scratch registers structures, functions & helpers
542  */
543 struct radeon_scratch {
544         unsigned                num_reg;
545         uint32_t                reg_base;
546         bool                    free[32];
547         uint32_t                reg[32];
548 };
549
550 int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
551 void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
552
553
554 /*
555  * IRQS.
556  */
557
558 struct radeon_unpin_work {
559         struct work_struct work;
560         struct radeon_device *rdev;
561         int crtc_id;
562         struct radeon_fence *fence;
563         struct drm_pending_vblank_event *event;
564         struct radeon_bo *old_rbo;
565         u64 new_crtc_base;
566 };
567
568 struct r500_irq_stat_regs {
569         u32 disp_int;
570         u32 hdmi0_status;
571 };
572
573 struct r600_irq_stat_regs {
574         u32 disp_int;
575         u32 disp_int_cont;
576         u32 disp_int_cont2;
577         u32 d1grph_int;
578         u32 d2grph_int;
579         u32 hdmi0_status;
580         u32 hdmi1_status;
581 };
582
583 struct evergreen_irq_stat_regs {
584         u32 disp_int;
585         u32 disp_int_cont;
586         u32 disp_int_cont2;
587         u32 disp_int_cont3;
588         u32 disp_int_cont4;
589         u32 disp_int_cont5;
590         u32 d1grph_int;
591         u32 d2grph_int;
592         u32 d3grph_int;
593         u32 d4grph_int;
594         u32 d5grph_int;
595         u32 d6grph_int;
596         u32 afmt_status1;
597         u32 afmt_status2;
598         u32 afmt_status3;
599         u32 afmt_status4;
600         u32 afmt_status5;
601         u32 afmt_status6;
602 };
603
604 union radeon_irq_stat_regs {
605         struct r500_irq_stat_regs r500;
606         struct r600_irq_stat_regs r600;
607         struct evergreen_irq_stat_regs evergreen;
608 };
609
610 #define RADEON_MAX_HPD_PINS 6
611 #define RADEON_MAX_CRTCS 6
612 #define RADEON_MAX_AFMT_BLOCKS 6
613
614 struct radeon_irq {
615         bool            installed;
616         bool            sw_int[RADEON_NUM_RINGS];
617         bool            crtc_vblank_int[RADEON_MAX_CRTCS];
618         bool            pflip[RADEON_MAX_CRTCS];
619         wait_queue_head_t       vblank_queue;
620         bool            hpd[RADEON_MAX_HPD_PINS];
621         bool            gui_idle;
622         bool            gui_idle_acked;
623         wait_queue_head_t       idle_queue;
624         bool            afmt[RADEON_MAX_AFMT_BLOCKS];
625         spinlock_t sw_lock;
626         int sw_refcount[RADEON_NUM_RINGS];
627         union radeon_irq_stat_regs stat_regs;
628         spinlock_t pflip_lock[RADEON_MAX_CRTCS];
629         int pflip_refcount[RADEON_MAX_CRTCS];
630 };
631
632 int radeon_irq_kms_init(struct radeon_device *rdev);
633 void radeon_irq_kms_fini(struct radeon_device *rdev);
634 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
635 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
636 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
637 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
638
639 /*
640  * CP & rings.
641  */
642
643 struct radeon_ib {
644         struct radeon_sa_bo     *sa_bo;
645         unsigned                idx;
646         uint32_t                length_dw;
647         uint64_t                gpu_addr;
648         uint32_t                *ptr;
649         struct radeon_fence     *fence;
650         unsigned                vm_id;
651         bool                    is_const_ib;
652 };
653
654 /*
655  * locking -
656  * mutex protects scheduled_ibs, ready, alloc_bm
657  */
658 struct radeon_ib_pool {
659         struct radeon_mutex             mutex;
660         struct radeon_sa_manager        sa_manager;
661         struct radeon_ib                ibs[RADEON_IB_POOL_SIZE];
662         bool                            ready;
663         unsigned                        head_id;
664 };
665
666 struct radeon_ring {
667         struct radeon_bo        *ring_obj;
668         volatile uint32_t       *ring;
669         unsigned                rptr;
670         unsigned                rptr_offs;
671         unsigned                rptr_reg;
672         unsigned                wptr;
673         unsigned                wptr_old;
674         unsigned                wptr_reg;
675         unsigned                ring_size;
676         unsigned                ring_free_dw;
677         int                     count_dw;
678         unsigned long           last_activity;
679         unsigned                last_rptr;
680         uint64_t                gpu_addr;
681         uint32_t                align_mask;
682         uint32_t                ptr_mask;
683         bool                    ready;
684         u32                     ptr_reg_shift;
685         u32                     ptr_reg_mask;
686         u32                     nop;
687 };
688
689 /*
690  * VM
691  */
692 struct radeon_vm {
693         struct list_head                list;
694         struct list_head                va;
695         int                             id;
696         unsigned                        last_pfn;
697         u64                             pt_gpu_addr;
698         u64                             *pt;
699         struct radeon_sa_bo             *sa_bo;
700         struct mutex                    mutex;
701         /* last fence for cs using this vm */
702         struct radeon_fence             *fence;
703 };
704
705 struct radeon_vm_funcs {
706         int (*init)(struct radeon_device *rdev);
707         void (*fini)(struct radeon_device *rdev);
708         /* cs mutex must be lock for schedule_ib */
709         int (*bind)(struct radeon_device *rdev, struct radeon_vm *vm, int id);
710         void (*unbind)(struct radeon_device *rdev, struct radeon_vm *vm);
711         void (*tlb_flush)(struct radeon_device *rdev, struct radeon_vm *vm);
712         uint32_t (*page_flags)(struct radeon_device *rdev,
713                                struct radeon_vm *vm,
714                                uint32_t flags);
715         void (*set_page)(struct radeon_device *rdev, struct radeon_vm *vm,
716                         unsigned pfn, uint64_t addr, uint32_t flags);
717 };
718
719 struct radeon_vm_manager {
720         struct list_head                lru_vm;
721         uint32_t                        use_bitmap;
722         struct radeon_sa_manager        sa_manager;
723         uint32_t                        max_pfn;
724         /* fields constant after init */
725         const struct radeon_vm_funcs    *funcs;
726         /* number of VMIDs */
727         unsigned                        nvm;
728         /* vram base address for page table entry  */
729         u64                             vram_base_offset;
730         /* is vm enabled? */
731         bool                            enabled;
732 };
733
734 /*
735  * file private structure
736  */
737 struct radeon_fpriv {
738         struct radeon_vm                vm;
739 };
740
741 /*
742  * R6xx+ IH ring
743  */
744 struct r600_ih {
745         struct radeon_bo        *ring_obj;
746         volatile uint32_t       *ring;
747         unsigned                rptr;
748         unsigned                rptr_offs;
749         unsigned                wptr;
750         unsigned                wptr_old;
751         unsigned                ring_size;
752         uint64_t                gpu_addr;
753         uint32_t                ptr_mask;
754         spinlock_t              lock;
755         bool                    enabled;
756 };
757
758 struct r600_blit_cp_primitives {
759         void (*set_render_target)(struct radeon_device *rdev, int format,
760                                   int w, int h, u64 gpu_addr);
761         void (*cp_set_surface_sync)(struct radeon_device *rdev,
762                                     u32 sync_type, u32 size,
763                                     u64 mc_addr);
764         void (*set_shaders)(struct radeon_device *rdev);
765         void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
766         void (*set_tex_resource)(struct radeon_device *rdev,
767                                  int format, int w, int h, int pitch,
768                                  u64 gpu_addr, u32 size);
769         void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
770                              int x2, int y2);
771         void (*draw_auto)(struct radeon_device *rdev);
772         void (*set_default_state)(struct radeon_device *rdev);
773 };
774
775 struct r600_blit {
776         struct mutex            mutex;
777         struct radeon_bo        *shader_obj;
778         struct r600_blit_cp_primitives primitives;
779         int max_dim;
780         int ring_size_common;
781         int ring_size_per_loop;
782         u64 shader_gpu_addr;
783         u32 vs_offset, ps_offset;
784         u32 state_offset;
785         u32 state_len;
786         u32 vb_used, vb_total;
787         struct radeon_ib *vb_ib;
788 };
789
790 void r600_blit_suspend(struct radeon_device *rdev);
791
792 /*
793  * SI RLC stuff
794  */
795 struct si_rlc {
796         /* for power gating */
797         struct radeon_bo        *save_restore_obj;
798         uint64_t                save_restore_gpu_addr;
799         /* for clear state */
800         struct radeon_bo        *clear_state_obj;
801         uint64_t                clear_state_gpu_addr;
802 };
803
804 int radeon_ib_get(struct radeon_device *rdev, int ring,
805                   struct radeon_ib **ib, unsigned size);
806 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
807 bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib);
808 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
809 int radeon_ib_pool_init(struct radeon_device *rdev);
810 void radeon_ib_pool_fini(struct radeon_device *rdev);
811 int radeon_ib_pool_start(struct radeon_device *rdev);
812 int radeon_ib_pool_suspend(struct radeon_device *rdev);
813 int radeon_ib_ring_tests(struct radeon_device *rdev);
814 /* Ring access between begin & end cannot sleep */
815 int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *cp);
816 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
817 int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
818 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
819 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
820 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
821 void radeon_ring_undo(struct radeon_ring *ring);
822 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
823 int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
824 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
825 void radeon_ring_lockup_update(struct radeon_ring *ring);
826 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
827 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
828                      unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
829                      u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
830 void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
831
832
833 /*
834  * CS.
835  */
836 struct radeon_cs_reloc {
837         struct drm_gem_object           *gobj;
838         struct radeon_bo                *robj;
839         struct radeon_bo_list           lobj;
840         uint32_t                        handle;
841         uint32_t                        flags;
842 };
843
844 struct radeon_cs_chunk {
845         uint32_t                chunk_id;
846         uint32_t                length_dw;
847         int                     kpage_idx[2];
848         uint32_t                *kpage[2];
849         uint32_t                *kdata;
850         void __user             *user_ptr;
851         int                     last_copied_page;
852         int                     last_page_index;
853 };
854
855 struct radeon_cs_parser {
856         struct device           *dev;
857         struct radeon_device    *rdev;
858         struct drm_file         *filp;
859         /* chunks */
860         unsigned                nchunks;
861         struct radeon_cs_chunk  *chunks;
862         uint64_t                *chunks_array;
863         /* IB */
864         unsigned                idx;
865         /* relocations */
866         unsigned                nrelocs;
867         struct radeon_cs_reloc  *relocs;
868         struct radeon_cs_reloc  **relocs_ptr;
869         struct list_head        validated;
870         /* indices of various chunks */
871         int                     chunk_ib_idx;
872         int                     chunk_relocs_idx;
873         int                     chunk_flags_idx;
874         int                     chunk_const_ib_idx;
875         struct radeon_ib        *ib;
876         struct radeon_ib        *const_ib;
877         void                    *track;
878         unsigned                family;
879         int                     parser_error;
880         u32                     cs_flags;
881         u32                     ring;
882         s32                     priority;
883 };
884
885 extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
886 extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
887 extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
888
889 struct radeon_cs_packet {
890         unsigned        idx;
891         unsigned        type;
892         unsigned        reg;
893         unsigned        opcode;
894         int             count;
895         unsigned        one_reg_wr;
896 };
897
898 typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
899                                       struct radeon_cs_packet *pkt,
900                                       unsigned idx, unsigned reg);
901 typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
902                                       struct radeon_cs_packet *pkt);
903
904
905 /*
906  * AGP
907  */
908 int radeon_agp_init(struct radeon_device *rdev);
909 void radeon_agp_resume(struct radeon_device *rdev);
910 void radeon_agp_suspend(struct radeon_device *rdev);
911 void radeon_agp_fini(struct radeon_device *rdev);
912
913
914 /*
915  * Writeback
916  */
917 struct radeon_wb {
918         struct radeon_bo        *wb_obj;
919         volatile uint32_t       *wb;
920         uint64_t                gpu_addr;
921         bool                    enabled;
922         bool                    use_event;
923 };
924
925 #define RADEON_WB_SCRATCH_OFFSET 0
926 #define RADEON_WB_CP_RPTR_OFFSET 1024
927 #define RADEON_WB_CP1_RPTR_OFFSET 1280
928 #define RADEON_WB_CP2_RPTR_OFFSET 1536
929 #define R600_WB_IH_WPTR_OFFSET   2048
930 #define R600_WB_EVENT_OFFSET     3072
931
932 /**
933  * struct radeon_pm - power management datas
934  * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
935  * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
936  * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
937  * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
938  * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
939  * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
940  * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
941  * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
942  * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
943  * @sclk:               GPU clock Mhz (core bandwidth depends of this clock)
944  * @needed_bandwidth:   current bandwidth needs
945  *
946  * It keeps track of various data needed to take powermanagement decision.
947  * Bandwidth need is used to determine minimun clock of the GPU and memory.
948  * Equation between gpu/memory clock and available bandwidth is hw dependent
949  * (type of memory, bus size, efficiency, ...)
950  */
951
952 enum radeon_pm_method {
953         PM_METHOD_PROFILE,
954         PM_METHOD_DYNPM,
955 };
956
957 enum radeon_dynpm_state {
958         DYNPM_STATE_DISABLED,
959         DYNPM_STATE_MINIMUM,
960         DYNPM_STATE_PAUSED,
961         DYNPM_STATE_ACTIVE,
962         DYNPM_STATE_SUSPENDED,
963 };
964 enum radeon_dynpm_action {
965         DYNPM_ACTION_NONE,
966         DYNPM_ACTION_MINIMUM,
967         DYNPM_ACTION_DOWNCLOCK,
968         DYNPM_ACTION_UPCLOCK,
969         DYNPM_ACTION_DEFAULT
970 };
971
972 enum radeon_voltage_type {
973         VOLTAGE_NONE = 0,
974         VOLTAGE_GPIO,
975         VOLTAGE_VDDC,
976         VOLTAGE_SW
977 };
978
979 enum radeon_pm_state_type {
980         POWER_STATE_TYPE_DEFAULT,
981         POWER_STATE_TYPE_POWERSAVE,
982         POWER_STATE_TYPE_BATTERY,
983         POWER_STATE_TYPE_BALANCED,
984         POWER_STATE_TYPE_PERFORMANCE,
985 };
986
987 enum radeon_pm_profile_type {
988         PM_PROFILE_DEFAULT,
989         PM_PROFILE_AUTO,
990         PM_PROFILE_LOW,
991         PM_PROFILE_MID,
992         PM_PROFILE_HIGH,
993 };
994
995 #define PM_PROFILE_DEFAULT_IDX 0
996 #define PM_PROFILE_LOW_SH_IDX  1
997 #define PM_PROFILE_MID_SH_IDX  2
998 #define PM_PROFILE_HIGH_SH_IDX 3
999 #define PM_PROFILE_LOW_MH_IDX  4
1000 #define PM_PROFILE_MID_MH_IDX  5
1001 #define PM_PROFILE_HIGH_MH_IDX 6
1002 #define PM_PROFILE_MAX         7
1003
1004 struct radeon_pm_profile {
1005         int dpms_off_ps_idx;
1006         int dpms_on_ps_idx;
1007         int dpms_off_cm_idx;
1008         int dpms_on_cm_idx;
1009 };
1010
1011 enum radeon_int_thermal_type {
1012         THERMAL_TYPE_NONE,
1013         THERMAL_TYPE_RV6XX,
1014         THERMAL_TYPE_RV770,
1015         THERMAL_TYPE_EVERGREEN,
1016         THERMAL_TYPE_SUMO,
1017         THERMAL_TYPE_NI,
1018         THERMAL_TYPE_SI,
1019 };
1020
1021 struct radeon_voltage {
1022         enum radeon_voltage_type type;
1023         /* gpio voltage */
1024         struct radeon_gpio_rec gpio;
1025         u32 delay; /* delay in usec from voltage drop to sclk change */
1026         bool active_high; /* voltage drop is active when bit is high */
1027         /* VDDC voltage */
1028         u8 vddc_id; /* index into vddc voltage table */
1029         u8 vddci_id; /* index into vddci voltage table */
1030         bool vddci_enabled;
1031         /* r6xx+ sw */
1032         u16 voltage;
1033         /* evergreen+ vddci */
1034         u16 vddci;
1035 };
1036
1037 /* clock mode flags */
1038 #define RADEON_PM_MODE_NO_DISPLAY          (1 << 0)
1039
1040 struct radeon_pm_clock_info {
1041         /* memory clock */
1042         u32 mclk;
1043         /* engine clock */
1044         u32 sclk;
1045         /* voltage info */
1046         struct radeon_voltage voltage;
1047         /* standardized clock flags */
1048         u32 flags;
1049 };
1050
1051 /* state flags */
1052 #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
1053
1054 struct radeon_power_state {
1055         enum radeon_pm_state_type type;
1056         struct radeon_pm_clock_info *clock_info;
1057         /* number of valid clock modes in this power state */
1058         int num_clock_modes;
1059         struct radeon_pm_clock_info *default_clock_mode;
1060         /* standardized state flags */
1061         u32 flags;
1062         u32 misc; /* vbios specific flags */
1063         u32 misc2; /* vbios specific flags */
1064         int pcie_lanes; /* pcie lanes */
1065 };
1066
1067 /*
1068  * Some modes are overclocked by very low value, accept them
1069  */
1070 #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
1071
1072 struct radeon_pm {
1073         struct mutex            mutex;
1074         u32                     active_crtcs;
1075         int                     active_crtc_count;
1076         int                     req_vblank;
1077         bool                    vblank_sync;
1078         bool                    gui_idle;
1079         fixed20_12              max_bandwidth;
1080         fixed20_12              igp_sideport_mclk;
1081         fixed20_12              igp_system_mclk;
1082         fixed20_12              igp_ht_link_clk;
1083         fixed20_12              igp_ht_link_width;
1084         fixed20_12              k8_bandwidth;
1085         fixed20_12              sideport_bandwidth;
1086         fixed20_12              ht_bandwidth;
1087         fixed20_12              core_bandwidth;
1088         fixed20_12              sclk;
1089         fixed20_12              mclk;
1090         fixed20_12              needed_bandwidth;
1091         struct radeon_power_state *power_state;
1092         /* number of valid power states */
1093         int                     num_power_states;
1094         int                     current_power_state_index;
1095         int                     current_clock_mode_index;
1096         int                     requested_power_state_index;
1097         int                     requested_clock_mode_index;
1098         int                     default_power_state_index;
1099         u32                     current_sclk;
1100         u32                     current_mclk;
1101         u16                     current_vddc;
1102         u16                     current_vddci;
1103         u32                     default_sclk;
1104         u32                     default_mclk;
1105         u16                     default_vddc;
1106         u16                     default_vddci;
1107         struct radeon_i2c_chan *i2c_bus;
1108         /* selected pm method */
1109         enum radeon_pm_method     pm_method;
1110         /* dynpm power management */
1111         struct delayed_work     dynpm_idle_work;
1112         enum radeon_dynpm_state dynpm_state;
1113         enum radeon_dynpm_action        dynpm_planned_action;
1114         unsigned long           dynpm_action_timeout;
1115         bool                    dynpm_can_upclock;
1116         bool                    dynpm_can_downclock;
1117         /* profile-based power management */
1118         enum radeon_pm_profile_type profile;
1119         int                     profile_index;
1120         struct radeon_pm_profile profiles[PM_PROFILE_MAX];
1121         /* internal thermal controller on rv6xx+ */
1122         enum radeon_int_thermal_type int_thermal_type;
1123         struct device           *int_hwmon_dev;
1124 };
1125
1126 int radeon_pm_get_type_index(struct radeon_device *rdev,
1127                              enum radeon_pm_state_type ps_type,
1128                              int instance);
1129
1130 struct r600_audio {
1131         bool                    enabled;
1132         int                     channels;
1133         int                     rate;
1134         int                     bits_per_sample;
1135         u8                      status_bits;
1136         u8                      category_code;
1137 };
1138
1139 /*
1140  * Benchmarking
1141  */
1142 void radeon_benchmark(struct radeon_device *rdev, int test_number);
1143
1144
1145 /*
1146  * Testing
1147  */
1148 void radeon_test_moves(struct radeon_device *rdev);
1149 void radeon_test_ring_sync(struct radeon_device *rdev,
1150                            struct radeon_ring *cpA,
1151                            struct radeon_ring *cpB);
1152 void radeon_test_syncing(struct radeon_device *rdev);
1153
1154
1155 /*
1156  * Debugfs
1157  */
1158 struct radeon_debugfs {
1159         struct drm_info_list    *files;
1160         unsigned                num_files;
1161 };
1162
1163 int radeon_debugfs_add_files(struct radeon_device *rdev,
1164                              struct drm_info_list *files,
1165                              unsigned nfiles);
1166 int radeon_debugfs_fence_init(struct radeon_device *rdev);
1167
1168
1169 /*
1170  * ASIC specific functions.
1171  */
1172 struct radeon_asic {
1173         int (*init)(struct radeon_device *rdev);
1174         void (*fini)(struct radeon_device *rdev);
1175         int (*resume)(struct radeon_device *rdev);
1176         int (*suspend)(struct radeon_device *rdev);
1177         void (*vga_set_state)(struct radeon_device *rdev, bool state);
1178         int (*asic_reset)(struct radeon_device *rdev);
1179         /* ioctl hw specific callback. Some hw might want to perform special
1180          * operation on specific ioctl. For instance on wait idle some hw
1181          * might want to perform and HDP flush through MMIO as it seems that
1182          * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
1183          * through ring.
1184          */
1185         void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
1186         /* check if 3D engine is idle */
1187         bool (*gui_idle)(struct radeon_device *rdev);
1188         /* wait for mc_idle */
1189         int (*mc_wait_for_idle)(struct radeon_device *rdev);
1190         /* gart */
1191         struct {
1192                 void (*tlb_flush)(struct radeon_device *rdev);
1193                 int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
1194         } gart;
1195         /* ring specific callbacks */
1196         struct {
1197                 void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
1198                 int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
1199                 void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
1200                 void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
1201                                        struct radeon_semaphore *semaphore, bool emit_wait);
1202                 int (*cs_parse)(struct radeon_cs_parser *p);
1203                 void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
1204                 int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1205                 int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1206                 bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
1207         } ring[RADEON_NUM_RINGS];
1208         /* irqs */
1209         struct {
1210                 int (*set)(struct radeon_device *rdev);
1211                 int (*process)(struct radeon_device *rdev);
1212         } irq;
1213         /* displays */
1214         struct {
1215                 /* display watermarks */
1216                 void (*bandwidth_update)(struct radeon_device *rdev);
1217                 /* get frame count */
1218                 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
1219                 /* wait for vblank */
1220                 void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
1221         } display;
1222         /* copy functions for bo handling */
1223         struct {
1224                 int (*blit)(struct radeon_device *rdev,
1225                             uint64_t src_offset,
1226                             uint64_t dst_offset,
1227                             unsigned num_gpu_pages,
1228                             struct radeon_fence *fence);
1229                 u32 blit_ring_index;
1230                 int (*dma)(struct radeon_device *rdev,
1231                            uint64_t src_offset,
1232                            uint64_t dst_offset,
1233                            unsigned num_gpu_pages,
1234                            struct radeon_fence *fence);
1235                 u32 dma_ring_index;
1236                 /* method used for bo copy */
1237                 int (*copy)(struct radeon_device *rdev,
1238                             uint64_t src_offset,
1239                             uint64_t dst_offset,
1240                             unsigned num_gpu_pages,
1241                             struct radeon_fence *fence);
1242                 /* ring used for bo copies */
1243                 u32 copy_ring_index;
1244         } copy;
1245         /* surfaces */
1246         struct {
1247                 int (*set_reg)(struct radeon_device *rdev, int reg,
1248                                        uint32_t tiling_flags, uint32_t pitch,
1249                                        uint32_t offset, uint32_t obj_size);
1250                 void (*clear_reg)(struct radeon_device *rdev, int reg);
1251         } surface;
1252         /* hotplug detect */
1253         struct {
1254                 void (*init)(struct radeon_device *rdev);
1255                 void (*fini)(struct radeon_device *rdev);
1256                 bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1257                 void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1258         } hpd;
1259         /* power management */
1260         struct {
1261                 void (*misc)(struct radeon_device *rdev);
1262                 void (*prepare)(struct radeon_device *rdev);
1263                 void (*finish)(struct radeon_device *rdev);
1264                 void (*init_profile)(struct radeon_device *rdev);
1265                 void (*get_dynpm_state)(struct radeon_device *rdev);
1266                 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
1267                 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
1268                 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
1269                 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
1270                 int (*get_pcie_lanes)(struct radeon_device *rdev);
1271                 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
1272                 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
1273         } pm;
1274         /* pageflipping */
1275         struct {
1276                 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
1277                 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
1278                 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
1279         } pflip;
1280 };
1281
1282 /*
1283  * Asic structures
1284  */
1285 struct r100_asic {
1286         const unsigned          *reg_safe_bm;
1287         unsigned                reg_safe_bm_size;
1288         u32                     hdp_cntl;
1289 };
1290
1291 struct r300_asic {
1292         const unsigned          *reg_safe_bm;
1293         unsigned                reg_safe_bm_size;
1294         u32                     resync_scratch;
1295         u32                     hdp_cntl;
1296 };
1297
1298 struct r600_asic {
1299         unsigned                max_pipes;
1300         unsigned                max_tile_pipes;
1301         unsigned                max_simds;
1302         unsigned                max_backends;
1303         unsigned                max_gprs;
1304         unsigned                max_threads;
1305         unsigned                max_stack_entries;
1306         unsigned                max_hw_contexts;
1307         unsigned                max_gs_threads;
1308         unsigned                sx_max_export_size;
1309         unsigned                sx_max_export_pos_size;
1310         unsigned                sx_max_export_smx_size;
1311         unsigned                sq_num_cf_insts;
1312         unsigned                tiling_nbanks;
1313         unsigned                tiling_npipes;
1314         unsigned                tiling_group_size;
1315         unsigned                tile_config;
1316         unsigned                backend_map;
1317 };
1318
1319 struct rv770_asic {
1320         unsigned                max_pipes;
1321         unsigned                max_tile_pipes;
1322         unsigned                max_simds;
1323         unsigned                max_backends;
1324         unsigned                max_gprs;
1325         unsigned                max_threads;
1326         unsigned                max_stack_entries;
1327         unsigned                max_hw_contexts;
1328         unsigned                max_gs_threads;
1329         unsigned                sx_max_export_size;
1330         unsigned                sx_max_export_pos_size;
1331         unsigned                sx_max_export_smx_size;
1332         unsigned                sq_num_cf_insts;
1333         unsigned                sx_num_of_sets;
1334         unsigned                sc_prim_fifo_size;
1335         unsigned                sc_hiz_tile_fifo_size;
1336         unsigned                sc_earlyz_tile_fifo_fize;
1337         unsigned                tiling_nbanks;
1338         unsigned                tiling_npipes;
1339         unsigned                tiling_group_size;
1340         unsigned                tile_config;
1341         unsigned                backend_map;
1342 };
1343
1344 struct evergreen_asic {
1345         unsigned num_ses;
1346         unsigned max_pipes;
1347         unsigned max_tile_pipes;
1348         unsigned max_simds;
1349         unsigned max_backends;
1350         unsigned max_gprs;
1351         unsigned max_threads;
1352         unsigned max_stack_entries;
1353         unsigned max_hw_contexts;
1354         unsigned max_gs_threads;
1355         unsigned sx_max_export_size;
1356         unsigned sx_max_export_pos_size;
1357         unsigned sx_max_export_smx_size;
1358         unsigned sq_num_cf_insts;
1359         unsigned sx_num_of_sets;
1360         unsigned sc_prim_fifo_size;
1361         unsigned sc_hiz_tile_fifo_size;
1362         unsigned sc_earlyz_tile_fifo_size;
1363         unsigned tiling_nbanks;
1364         unsigned tiling_npipes;
1365         unsigned tiling_group_size;
1366         unsigned tile_config;
1367         unsigned backend_map;
1368 };
1369
1370 struct cayman_asic {
1371         unsigned max_shader_engines;
1372         unsigned max_pipes_per_simd;
1373         unsigned max_tile_pipes;
1374         unsigned max_simds_per_se;
1375         unsigned max_backends_per_se;
1376         unsigned max_texture_channel_caches;
1377         unsigned max_gprs;
1378         unsigned max_threads;
1379         unsigned max_gs_threads;
1380         unsigned max_stack_entries;
1381         unsigned sx_num_of_sets;
1382         unsigned sx_max_export_size;
1383         unsigned sx_max_export_pos_size;
1384         unsigned sx_max_export_smx_size;
1385         unsigned max_hw_contexts;
1386         unsigned sq_num_cf_insts;
1387         unsigned sc_prim_fifo_size;
1388         unsigned sc_hiz_tile_fifo_size;
1389         unsigned sc_earlyz_tile_fifo_size;
1390
1391         unsigned num_shader_engines;
1392         unsigned num_shader_pipes_per_simd;
1393         unsigned num_tile_pipes;
1394         unsigned num_simds_per_se;
1395         unsigned num_backends_per_se;
1396         unsigned backend_disable_mask_per_asic;
1397         unsigned backend_map;
1398         unsigned num_texture_channel_caches;
1399         unsigned mem_max_burst_length_bytes;
1400         unsigned mem_row_size_in_kb;
1401         unsigned shader_engine_tile_size;
1402         unsigned num_gpus;
1403         unsigned multi_gpu_tile_size;
1404
1405         unsigned tile_config;
1406 };
1407
1408 struct si_asic {
1409         unsigned max_shader_engines;
1410         unsigned max_pipes_per_simd;
1411         unsigned max_tile_pipes;
1412         unsigned max_simds_per_se;
1413         unsigned max_backends_per_se;
1414         unsigned max_texture_channel_caches;
1415         unsigned max_gprs;
1416         unsigned max_gs_threads;
1417         unsigned max_hw_contexts;
1418         unsigned sc_prim_fifo_size_frontend;
1419         unsigned sc_prim_fifo_size_backend;
1420         unsigned sc_hiz_tile_fifo_size;
1421         unsigned sc_earlyz_tile_fifo_size;
1422
1423         unsigned num_shader_engines;
1424         unsigned num_tile_pipes;
1425         unsigned num_backends_per_se;
1426         unsigned backend_disable_mask_per_asic;
1427         unsigned backend_map;
1428         unsigned num_texture_channel_caches;
1429         unsigned mem_max_burst_length_bytes;
1430         unsigned mem_row_size_in_kb;
1431         unsigned shader_engine_tile_size;
1432         unsigned num_gpus;
1433         unsigned multi_gpu_tile_size;
1434
1435         unsigned tile_config;
1436 };
1437
1438 union radeon_asic_config {
1439         struct r300_asic        r300;
1440         struct r100_asic        r100;
1441         struct r600_asic        r600;
1442         struct rv770_asic       rv770;
1443         struct evergreen_asic   evergreen;
1444         struct cayman_asic      cayman;
1445         struct si_asic          si;
1446 };
1447
1448 /*
1449  * asic initizalization from radeon_asic.c
1450  */
1451 void radeon_agp_disable(struct radeon_device *rdev);
1452 int radeon_asic_init(struct radeon_device *rdev);
1453
1454
1455 /*
1456  * IOCTL.
1457  */
1458 int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
1459                           struct drm_file *filp);
1460 int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
1461                             struct drm_file *filp);
1462 int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
1463                          struct drm_file *file_priv);
1464 int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
1465                            struct drm_file *file_priv);
1466 int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1467                             struct drm_file *file_priv);
1468 int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
1469                            struct drm_file *file_priv);
1470 int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1471                                 struct drm_file *filp);
1472 int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
1473                           struct drm_file *filp);
1474 int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
1475                           struct drm_file *filp);
1476 int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1477                               struct drm_file *filp);
1478 int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
1479                           struct drm_file *filp);
1480 int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1481 int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1482                                 struct drm_file *filp);
1483 int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1484                                 struct drm_file *filp);
1485
1486 /* VRAM scratch page for HDP bug, default vram page */
1487 struct r600_vram_scratch {
1488         struct radeon_bo                *robj;
1489         volatile uint32_t               *ptr;
1490         u64                             gpu_addr;
1491 };
1492
1493
1494 /*
1495  * Core structure, functions and helpers.
1496  */
1497 typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1498 typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1499
1500 struct radeon_device {
1501         struct device                   *dev;
1502         struct drm_device               *ddev;
1503         struct pci_dev                  *pdev;
1504         /* ASIC */
1505         union radeon_asic_config        config;
1506         enum radeon_family              family;
1507         unsigned long                   flags;
1508         int                             usec_timeout;
1509         enum radeon_pll_errata          pll_errata;
1510         int                             num_gb_pipes;
1511         int                             num_z_pipes;
1512         int                             disp_priority;
1513         /* BIOS */
1514         uint8_t                         *bios;
1515         bool                            is_atom_bios;
1516         uint16_t                        bios_header_start;
1517         struct radeon_bo                *stollen_vga_memory;
1518         /* Register mmio */
1519         resource_size_t                 rmmio_base;
1520         resource_size_t                 rmmio_size;
1521         void __iomem                    *rmmio;
1522         radeon_rreg_t                   mc_rreg;
1523         radeon_wreg_t                   mc_wreg;
1524         radeon_rreg_t                   pll_rreg;
1525         radeon_wreg_t                   pll_wreg;
1526         uint32_t                        pcie_reg_mask;
1527         radeon_rreg_t                   pciep_rreg;
1528         radeon_wreg_t                   pciep_wreg;
1529         /* io port */
1530         void __iomem                    *rio_mem;
1531         resource_size_t                 rio_mem_size;
1532         struct radeon_clock             clock;
1533         struct radeon_mc                mc;
1534         struct radeon_gart              gart;
1535         struct radeon_mode_info         mode_info;
1536         struct radeon_scratch           scratch;
1537         struct radeon_mman              mman;
1538         struct radeon_fence_driver      fence_drv[RADEON_NUM_RINGS];
1539         wait_queue_head_t               fence_queue;
1540         struct radeon_semaphore_driver  semaphore_drv;
1541         struct mutex                    ring_lock;
1542         struct radeon_ring              ring[RADEON_NUM_RINGS];
1543         struct radeon_ib_pool           ib_pool;
1544         struct radeon_irq               irq;
1545         struct radeon_asic              *asic;
1546         struct radeon_gem               gem;
1547         struct radeon_pm                pm;
1548         uint32_t                        bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1549         struct radeon_mutex             cs_mutex;
1550         struct radeon_wb                wb;
1551         struct radeon_dummy_page        dummy_page;
1552         bool                            shutdown;
1553         bool                            suspend;
1554         bool                            need_dma32;
1555         bool                            accel_working;
1556         struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
1557         const struct firmware *me_fw;   /* all family ME firmware */
1558         const struct firmware *pfp_fw;  /* r6/700 PFP firmware */
1559         const struct firmware *rlc_fw;  /* r6/700 RLC firmware */
1560         const struct firmware *mc_fw;   /* NI MC firmware */
1561         const struct firmware *ce_fw;   /* SI CE firmware */
1562         struct r600_blit r600_blit;
1563         struct r600_vram_scratch vram_scratch;
1564         int msi_enabled; /* msi enabled */
1565         struct r600_ih ih; /* r6/700 interrupt ring */
1566         struct si_rlc rlc;
1567         struct work_struct hotplug_work;
1568         struct work_struct audio_work;
1569         int num_crtc; /* number of crtcs */
1570         struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
1571         struct mutex vram_mutex;
1572         struct r600_audio audio; /* audio stuff */
1573         struct notifier_block acpi_nb;
1574         /* only one userspace can use Hyperz features or CMASK at a time */
1575         struct drm_file *hyperz_filp;
1576         struct drm_file *cmask_filp;
1577         /* i2c buses */
1578         struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1579         /* debugfs */
1580         struct radeon_debugfs   debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
1581         unsigned                debugfs_count;
1582         /* virtual memory */
1583         struct radeon_vm_manager        vm_manager;
1584 };
1585
1586 int radeon_device_init(struct radeon_device *rdev,
1587                        struct drm_device *ddev,
1588                        struct pci_dev *pdev,
1589                        uint32_t flags);
1590 void radeon_device_fini(struct radeon_device *rdev);
1591 int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
1592
1593 uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg);
1594 void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v);
1595 u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
1596 void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
1597
1598 /*
1599  * Cast helper
1600  */
1601 #define to_radeon_fence(p) ((struct radeon_fence *)(p))
1602
1603 /*
1604  * Registers read & write functions.
1605  */
1606 #define RREG8(reg) readb((rdev->rmmio) + (reg))
1607 #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
1608 #define RREG16(reg) readw((rdev->rmmio) + (reg))
1609 #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
1610 #define RREG32(reg) r100_mm_rreg(rdev, (reg))
1611 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
1612 #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
1613 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1614 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1615 #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1616 #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1617 #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1618 #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
1619 #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1620 #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
1621 #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1622 #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
1623 #define WREG32_P(reg, val, mask)                                \
1624         do {                                                    \
1625                 uint32_t tmp_ = RREG32(reg);                    \
1626                 tmp_ &= (mask);                                 \
1627                 tmp_ |= ((val) & ~(mask));                      \
1628                 WREG32(reg, tmp_);                              \
1629         } while (0)
1630 #define WREG32_PLL_P(reg, val, mask)                            \
1631         do {                                                    \
1632                 uint32_t tmp_ = RREG32_PLL(reg);                \
1633                 tmp_ &= (mask);                                 \
1634                 tmp_ |= ((val) & ~(mask));                      \
1635                 WREG32_PLL(reg, tmp_);                          \
1636         } while (0)
1637 #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
1638 #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
1639 #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
1640
1641 /*
1642  * Indirect registers accessor
1643  */
1644 static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1645 {
1646         uint32_t r;
1647
1648         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1649         r = RREG32(RADEON_PCIE_DATA);
1650         return r;
1651 }
1652
1653 static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1654 {
1655         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1656         WREG32(RADEON_PCIE_DATA, (v));
1657 }
1658
1659 void r100_pll_errata_after_index(struct radeon_device *rdev);
1660
1661
1662 /*
1663  * ASICs helpers.
1664  */
1665 #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1666                             (rdev->pdev->device == 0x5969))
1667 #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1668                 (rdev->family == CHIP_RV200) || \
1669                 (rdev->family == CHIP_RS100) || \
1670                 (rdev->family == CHIP_RS200) || \
1671                 (rdev->family == CHIP_RV250) || \
1672                 (rdev->family == CHIP_RV280) || \
1673                 (rdev->family == CHIP_RS300))
1674 #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  ||     \
1675                 (rdev->family == CHIP_RV350) ||                 \
1676                 (rdev->family == CHIP_R350)  ||                 \
1677                 (rdev->family == CHIP_RV380) ||                 \
1678                 (rdev->family == CHIP_R420)  ||                 \
1679                 (rdev->family == CHIP_R423)  ||                 \
1680                 (rdev->family == CHIP_RV410) ||                 \
1681                 (rdev->family == CHIP_RS400) ||                 \
1682                 (rdev->family == CHIP_RS480))
1683 #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
1684                 (rdev->ddev->pdev->device == 0x9443) || \
1685                 (rdev->ddev->pdev->device == 0x944B) || \
1686                 (rdev->ddev->pdev->device == 0x9506) || \
1687                 (rdev->ddev->pdev->device == 0x9509) || \
1688                 (rdev->ddev->pdev->device == 0x950F) || \
1689                 (rdev->ddev->pdev->device == 0x689C) || \
1690                 (rdev->ddev->pdev->device == 0x689D))
1691 #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1692 #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600)  ||    \
1693                             (rdev->family == CHIP_RS690)  ||    \
1694                             (rdev->family == CHIP_RS740)  ||    \
1695                             (rdev->family >= CHIP_R600))
1696 #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1697 #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
1698 #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
1699 #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
1700                              (rdev->flags & RADEON_IS_IGP))
1701 #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
1702 #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
1703 #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
1704                              (rdev->flags & RADEON_IS_IGP))
1705
1706 /*
1707  * BIOS helpers.
1708  */
1709 #define RBIOS8(i) (rdev->bios[i])
1710 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1711 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1712
1713 int radeon_combios_init(struct radeon_device *rdev);
1714 void radeon_combios_fini(struct radeon_device *rdev);
1715 int radeon_atombios_init(struct radeon_device *rdev);
1716 void radeon_atombios_fini(struct radeon_device *rdev);
1717
1718
1719 /*
1720  * RING helpers.
1721  */
1722 #if DRM_DEBUG_CODE == 0
1723 static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
1724 {
1725         ring->ring[ring->wptr++] = v;
1726         ring->wptr &= ring->ptr_mask;
1727         ring->count_dw--;
1728         ring->ring_free_dw--;
1729 }
1730 #else
1731 /* With debugging this is just too big to inline */
1732 void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
1733 #endif
1734
1735 /*
1736  * ASICs macro.
1737  */
1738 #define radeon_init(rdev) (rdev)->asic->init((rdev))
1739 #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1740 #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1741 #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
1742 #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
1743 #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
1744 #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
1745 #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
1746 #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
1747 #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
1748 #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
1749 #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
1750 #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
1751 #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
1752 #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
1753 #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
1754 #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
1755 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
1756 #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
1757 #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
1758 #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
1759 #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
1760 #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
1761 #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
1762 #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
1763 #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
1764 #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
1765 #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
1766 #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
1767 #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
1768 #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
1769 #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
1770 #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
1771 #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
1772 #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
1773 #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
1774 #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
1775 #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
1776 #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
1777 #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
1778 #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
1779 #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
1780 #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
1781 #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
1782 #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
1783 #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
1784 #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pflip.pre_page_flip((rdev), (crtc))
1785 #define radeon_page_flip(rdev, crtc, base) rdev->asic->pflip.page_flip((rdev), (crtc), (base))
1786 #define radeon_post_page_flip(rdev, crtc) rdev->asic->pflip.post_page_flip((rdev), (crtc))
1787 #define radeon_wait_for_vblank(rdev, crtc) rdev->asic->display.wait_for_vblank((rdev), (crtc))
1788 #define radeon_mc_wait_for_idle(rdev) rdev->asic->mc_wait_for_idle((rdev))
1789
1790 /* Common functions */
1791 /* AGP */
1792 extern int radeon_gpu_reset(struct radeon_device *rdev);
1793 extern void radeon_agp_disable(struct radeon_device *rdev);
1794 extern int radeon_modeset_init(struct radeon_device *rdev);
1795 extern void radeon_modeset_fini(struct radeon_device *rdev);
1796 extern bool radeon_card_posted(struct radeon_device *rdev);
1797 extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
1798 extern void radeon_update_display_priority(struct radeon_device *rdev);
1799 extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
1800 extern void radeon_scratch_init(struct radeon_device *rdev);
1801 extern void radeon_wb_fini(struct radeon_device *rdev);
1802 extern int radeon_wb_init(struct radeon_device *rdev);
1803 extern void radeon_wb_disable(struct radeon_device *rdev);
1804 extern void radeon_surface_init(struct radeon_device *rdev);
1805 extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
1806 extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
1807 extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
1808 extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
1809 extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
1810 extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1811 extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
1812 extern int radeon_resume_kms(struct drm_device *dev);
1813 extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
1814 extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
1815
1816 /*
1817  * vm
1818  */
1819 int radeon_vm_manager_init(struct radeon_device *rdev);
1820 void radeon_vm_manager_fini(struct radeon_device *rdev);
1821 int radeon_vm_manager_start(struct radeon_device *rdev);
1822 int radeon_vm_manager_suspend(struct radeon_device *rdev);
1823 int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
1824 void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
1825 int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm);
1826 void radeon_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm);
1827 int radeon_vm_bo_update_pte(struct radeon_device *rdev,
1828                             struct radeon_vm *vm,
1829                             struct radeon_bo *bo,
1830                             struct ttm_mem_reg *mem);
1831 void radeon_vm_bo_invalidate(struct radeon_device *rdev,
1832                              struct radeon_bo *bo);
1833 int radeon_vm_bo_add(struct radeon_device *rdev,
1834                      struct radeon_vm *vm,
1835                      struct radeon_bo *bo,
1836                      uint64_t offset,
1837                      uint32_t flags);
1838 int radeon_vm_bo_rmv(struct radeon_device *rdev,
1839                      struct radeon_vm *vm,
1840                      struct radeon_bo *bo);
1841
1842 /* audio */
1843 void r600_audio_update_hdmi(struct work_struct *work);
1844
1845 /*
1846  * R600 vram scratch functions
1847  */
1848 int r600_vram_scratch_init(struct radeon_device *rdev);
1849 void r600_vram_scratch_fini(struct radeon_device *rdev);
1850
1851 /*
1852  * r600 cs checking helper
1853  */
1854 unsigned r600_mip_minify(unsigned size, unsigned level);
1855 bool r600_fmt_is_valid_color(u32 format);
1856 bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
1857 int r600_fmt_get_blocksize(u32 format);
1858 int r600_fmt_get_nblocksx(u32 format, u32 w);
1859 int r600_fmt_get_nblocksy(u32 format, u32 h);
1860
1861 /*
1862  * r600 functions used by radeon_encoder.c
1863  */
1864 extern void r600_hdmi_enable(struct drm_encoder *encoder);
1865 extern void r600_hdmi_disable(struct drm_encoder *encoder);
1866 extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1867
1868 extern int ni_init_microcode(struct radeon_device *rdev);
1869 extern int ni_mc_load_microcode(struct radeon_device *rdev);
1870
1871 /* radeon_acpi.c */ 
1872 #if defined(CONFIG_ACPI) 
1873 extern int radeon_acpi_init(struct radeon_device *rdev); 
1874 #else 
1875 static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; } 
1876 #endif 
1877
1878 #include "radeon_object.h"
1879
1880 #endif