Merge branch 'fix/hda' into for-linus
[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 <asm/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
73 #include "radeon_family.h"
74 #include "radeon_mode.h"
75 #include "radeon_reg.h"
76
77 /*
78  * Modules parameters.
79  */
80 extern int radeon_no_wb;
81 extern int radeon_modeset;
82 extern int radeon_dynclks;
83 extern int radeon_r4xx_atom;
84 extern int radeon_agpmode;
85 extern int radeon_vram_limit;
86 extern int radeon_gart_size;
87 extern int radeon_benchmarking;
88 extern int radeon_testing;
89 extern int radeon_connector_table;
90 extern int radeon_tv;
91 extern int radeon_new_pll;
92 extern int radeon_dynpm;
93 extern int radeon_audio;
94 extern int radeon_disp_priority;
95 extern int radeon_hw_i2c;
96
97 /*
98  * Copy from radeon_drv.h so we don't have to include both and have conflicting
99  * symbol;
100  */
101 #define RADEON_MAX_USEC_TIMEOUT         100000  /* 100 ms */
102 /* RADEON_IB_POOL_SIZE must be a power of 2 */
103 #define RADEON_IB_POOL_SIZE             16
104 #define RADEON_DEBUGFS_MAX_NUM_FILES    32
105 #define RADEONFB_CONN_LIMIT             4
106 #define RADEON_BIOS_NUM_SCRATCH         8
107
108 /*
109  * Errata workarounds.
110  */
111 enum radeon_pll_errata {
112         CHIP_ERRATA_R300_CG             = 0x00000001,
113         CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
114         CHIP_ERRATA_PLL_DELAY           = 0x00000004
115 };
116
117
118 struct radeon_device;
119
120
121 /*
122  * BIOS.
123  */
124 #define ATRM_BIOS_PAGE 4096
125
126 #if defined(CONFIG_VGA_SWITCHEROO)
127 bool radeon_atrm_supported(struct pci_dev *pdev);
128 int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
129 #else
130 static inline bool radeon_atrm_supported(struct pci_dev *pdev)
131 {
132         return false;
133 }
134
135 static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
136         return -EINVAL;
137 }
138 #endif
139 bool radeon_get_bios(struct radeon_device *rdev);
140
141
142 /*
143  * Dummy page
144  */
145 struct radeon_dummy_page {
146         struct page     *page;
147         dma_addr_t      addr;
148 };
149 int radeon_dummy_page_init(struct radeon_device *rdev);
150 void radeon_dummy_page_fini(struct radeon_device *rdev);
151
152
153 /*
154  * Clocks
155  */
156 struct radeon_clock {
157         struct radeon_pll p1pll;
158         struct radeon_pll p2pll;
159         struct radeon_pll dcpll;
160         struct radeon_pll spll;
161         struct radeon_pll mpll;
162         /* 10 Khz units */
163         uint32_t default_mclk;
164         uint32_t default_sclk;
165         uint32_t default_dispclk;
166         uint32_t dp_extclk;
167 };
168
169 /*
170  * Power management
171  */
172 int radeon_pm_init(struct radeon_device *rdev);
173 void radeon_pm_fini(struct radeon_device *rdev);
174 void radeon_pm_compute_clocks(struct radeon_device *rdev);
175 void radeon_combios_get_power_modes(struct radeon_device *rdev);
176 void radeon_atombios_get_power_modes(struct radeon_device *rdev);
177
178 /*
179  * Fences.
180  */
181 struct radeon_fence_driver {
182         uint32_t                        scratch_reg;
183         atomic_t                        seq;
184         uint32_t                        last_seq;
185         unsigned long                   count_timeout;
186         wait_queue_head_t               queue;
187         rwlock_t                        lock;
188         struct list_head                created;
189         struct list_head                emited;
190         struct list_head                signaled;
191         bool                            initialized;
192 };
193
194 struct radeon_fence {
195         struct radeon_device            *rdev;
196         struct kref                     kref;
197         struct list_head                list;
198         /* protected by radeon_fence.lock */
199         uint32_t                        seq;
200         unsigned long                   timeout;
201         bool                            emited;
202         bool                            signaled;
203 };
204
205 int radeon_fence_driver_init(struct radeon_device *rdev);
206 void radeon_fence_driver_fini(struct radeon_device *rdev);
207 int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
208 int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
209 void radeon_fence_process(struct radeon_device *rdev);
210 bool radeon_fence_signaled(struct radeon_fence *fence);
211 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
212 int radeon_fence_wait_next(struct radeon_device *rdev);
213 int radeon_fence_wait_last(struct radeon_device *rdev);
214 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
215 void radeon_fence_unref(struct radeon_fence **fence);
216
217 /*
218  * Tiling registers
219  */
220 struct radeon_surface_reg {
221         struct radeon_bo *bo;
222 };
223
224 #define RADEON_GEM_MAX_SURFACES 8
225
226 /*
227  * TTM.
228  */
229 struct radeon_mman {
230         struct ttm_bo_global_ref        bo_global_ref;
231         struct ttm_global_reference     mem_global_ref;
232         struct ttm_bo_device            bdev;
233         bool                            mem_global_referenced;
234         bool                            initialized;
235 };
236
237 struct radeon_bo {
238         /* Protected by gem.mutex */
239         struct list_head                list;
240         /* Protected by tbo.reserved */
241         u32                             placements[3];
242         struct ttm_placement            placement;
243         struct ttm_buffer_object        tbo;
244         struct ttm_bo_kmap_obj          kmap;
245         unsigned                        pin_count;
246         void                            *kptr;
247         u32                             tiling_flags;
248         u32                             pitch;
249         int                             surface_reg;
250         /* Constant after initialization */
251         struct radeon_device            *rdev;
252         struct drm_gem_object           *gobj;
253 };
254
255 struct radeon_bo_list {
256         struct list_head        list;
257         struct radeon_bo        *bo;
258         uint64_t                gpu_offset;
259         unsigned                rdomain;
260         unsigned                wdomain;
261         u32                     tiling_flags;
262 };
263
264 /*
265  * GEM objects.
266  */
267 struct radeon_gem {
268         struct mutex            mutex;
269         struct list_head        objects;
270 };
271
272 int radeon_gem_init(struct radeon_device *rdev);
273 void radeon_gem_fini(struct radeon_device *rdev);
274 int radeon_gem_object_create(struct radeon_device *rdev, int size,
275                                 int alignment, int initial_domain,
276                                 bool discardable, bool kernel,
277                                 struct drm_gem_object **obj);
278 int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
279                           uint64_t *gpu_addr);
280 void radeon_gem_object_unpin(struct drm_gem_object *obj);
281
282
283 /*
284  * GART structures, functions & helpers
285  */
286 struct radeon_mc;
287
288 struct radeon_gart_table_ram {
289         volatile uint32_t               *ptr;
290 };
291
292 struct radeon_gart_table_vram {
293         struct radeon_bo                *robj;
294         volatile uint32_t               *ptr;
295 };
296
297 union radeon_gart_table {
298         struct radeon_gart_table_ram    ram;
299         struct radeon_gart_table_vram   vram;
300 };
301
302 #define RADEON_GPU_PAGE_SIZE 4096
303 #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
304
305 struct radeon_gart {
306         dma_addr_t                      table_addr;
307         unsigned                        num_gpu_pages;
308         unsigned                        num_cpu_pages;
309         unsigned                        table_size;
310         union radeon_gart_table         table;
311         struct page                     **pages;
312         dma_addr_t                      *pages_addr;
313         bool                            ready;
314 };
315
316 int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
317 void radeon_gart_table_ram_free(struct radeon_device *rdev);
318 int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
319 void radeon_gart_table_vram_free(struct radeon_device *rdev);
320 int radeon_gart_init(struct radeon_device *rdev);
321 void radeon_gart_fini(struct radeon_device *rdev);
322 void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
323                         int pages);
324 int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
325                      int pages, struct page **pagelist);
326
327
328 /*
329  * GPU MC structures, functions & helpers
330  */
331 struct radeon_mc {
332         resource_size_t         aper_size;
333         resource_size_t         aper_base;
334         resource_size_t         agp_base;
335         /* for some chips with <= 32MB we need to lie
336          * about vram size near mc fb location */
337         u64                     mc_vram_size;
338         u64                     visible_vram_size;
339         u64                     gtt_size;
340         u64                     gtt_start;
341         u64                     gtt_end;
342         u64                     vram_start;
343         u64                     vram_end;
344         unsigned                vram_width;
345         u64                     real_vram_size;
346         int                     vram_mtrr;
347         bool                    vram_is_ddr;
348         bool                    igp_sideport_enabled;
349 };
350
351 bool radeon_combios_sideport_present(struct radeon_device *rdev);
352 bool radeon_atombios_sideport_present(struct radeon_device *rdev);
353
354 /*
355  * GPU scratch registers structures, functions & helpers
356  */
357 struct radeon_scratch {
358         unsigned                num_reg;
359         bool                    free[32];
360         uint32_t                reg[32];
361 };
362
363 int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
364 void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
365
366
367 /*
368  * IRQS.
369  */
370 struct radeon_irq {
371         bool            installed;
372         bool            sw_int;
373         /* FIXME: use a define max crtc rather than hardcode it */
374         bool            crtc_vblank_int[2];
375         wait_queue_head_t       vblank_queue;
376         /* FIXME: use defines for max hpd/dacs */
377         bool            hpd[6];
378         spinlock_t sw_lock;
379         int sw_refcount;
380 };
381
382 int radeon_irq_kms_init(struct radeon_device *rdev);
383 void radeon_irq_kms_fini(struct radeon_device *rdev);
384 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
385 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
386
387 /*
388  * CP & ring.
389  */
390 struct radeon_ib {
391         struct list_head        list;
392         unsigned                idx;
393         uint64_t                gpu_addr;
394         struct radeon_fence     *fence;
395         uint32_t                *ptr;
396         uint32_t                length_dw;
397         bool                    free;
398 };
399
400 /*
401  * locking -
402  * mutex protects scheduled_ibs, ready, alloc_bm
403  */
404 struct radeon_ib_pool {
405         struct mutex            mutex;
406         struct radeon_bo        *robj;
407         struct list_head        bogus_ib;
408         struct radeon_ib        ibs[RADEON_IB_POOL_SIZE];
409         bool                    ready;
410         unsigned                head_id;
411 };
412
413 struct radeon_cp {
414         struct radeon_bo        *ring_obj;
415         volatile uint32_t       *ring;
416         unsigned                rptr;
417         unsigned                wptr;
418         unsigned                wptr_old;
419         unsigned                ring_size;
420         unsigned                ring_free_dw;
421         int                     count_dw;
422         uint64_t                gpu_addr;
423         uint32_t                align_mask;
424         uint32_t                ptr_mask;
425         struct mutex            mutex;
426         bool                    ready;
427 };
428
429 /*
430  * R6xx+ IH ring
431  */
432 struct r600_ih {
433         struct radeon_bo        *ring_obj;
434         volatile uint32_t       *ring;
435         unsigned                rptr;
436         unsigned                wptr;
437         unsigned                wptr_old;
438         unsigned                ring_size;
439         uint64_t                gpu_addr;
440         uint32_t                ptr_mask;
441         spinlock_t              lock;
442         bool                    enabled;
443 };
444
445 struct r600_blit {
446         struct mutex            mutex;
447         struct radeon_bo        *shader_obj;
448         u64 shader_gpu_addr;
449         u32 vs_offset, ps_offset;
450         u32 state_offset;
451         u32 state_len;
452         u32 vb_used, vb_total;
453         struct radeon_ib *vb_ib;
454 };
455
456 int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
457 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
458 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
459 int radeon_ib_pool_init(struct radeon_device *rdev);
460 void radeon_ib_pool_fini(struct radeon_device *rdev);
461 int radeon_ib_test(struct radeon_device *rdev);
462 extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
463 /* Ring access between begin & end cannot sleep */
464 void radeon_ring_free_size(struct radeon_device *rdev);
465 int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
466 void radeon_ring_unlock_commit(struct radeon_device *rdev);
467 void radeon_ring_unlock_undo(struct radeon_device *rdev);
468 int radeon_ring_test(struct radeon_device *rdev);
469 int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
470 void radeon_ring_fini(struct radeon_device *rdev);
471
472
473 /*
474  * CS.
475  */
476 struct radeon_cs_reloc {
477         struct drm_gem_object           *gobj;
478         struct radeon_bo                *robj;
479         struct radeon_bo_list           lobj;
480         uint32_t                        handle;
481         uint32_t                        flags;
482 };
483
484 struct radeon_cs_chunk {
485         uint32_t                chunk_id;
486         uint32_t                length_dw;
487         int kpage_idx[2];
488         uint32_t                *kpage[2];
489         uint32_t                *kdata;
490         void __user *user_ptr;
491         int last_copied_page;
492         int last_page_index;
493 };
494
495 struct radeon_cs_parser {
496         struct device           *dev;
497         struct radeon_device    *rdev;
498         struct drm_file         *filp;
499         /* chunks */
500         unsigned                nchunks;
501         struct radeon_cs_chunk  *chunks;
502         uint64_t                *chunks_array;
503         /* IB */
504         unsigned                idx;
505         /* relocations */
506         unsigned                nrelocs;
507         struct radeon_cs_reloc  *relocs;
508         struct radeon_cs_reloc  **relocs_ptr;
509         struct list_head        validated;
510         /* indices of various chunks */
511         int                     chunk_ib_idx;
512         int                     chunk_relocs_idx;
513         struct radeon_ib        *ib;
514         void                    *track;
515         unsigned                family;
516         int parser_error;
517 };
518
519 extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
520 extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
521
522
523 static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
524 {
525         struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
526         u32 pg_idx, pg_offset;
527         u32 idx_value = 0;
528         int new_page;
529
530         pg_idx = (idx * 4) / PAGE_SIZE;
531         pg_offset = (idx * 4) % PAGE_SIZE;
532
533         if (ibc->kpage_idx[0] == pg_idx)
534                 return ibc->kpage[0][pg_offset/4];
535         if (ibc->kpage_idx[1] == pg_idx)
536                 return ibc->kpage[1][pg_offset/4];
537
538         new_page = radeon_cs_update_pages(p, pg_idx);
539         if (new_page < 0) {
540                 p->parser_error = new_page;
541                 return 0;
542         }
543
544         idx_value = ibc->kpage[new_page][pg_offset/4];
545         return idx_value;
546 }
547
548 struct radeon_cs_packet {
549         unsigned        idx;
550         unsigned        type;
551         unsigned        reg;
552         unsigned        opcode;
553         int             count;
554         unsigned        one_reg_wr;
555 };
556
557 typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
558                                       struct radeon_cs_packet *pkt,
559                                       unsigned idx, unsigned reg);
560 typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
561                                       struct radeon_cs_packet *pkt);
562
563
564 /*
565  * AGP
566  */
567 int radeon_agp_init(struct radeon_device *rdev);
568 void radeon_agp_resume(struct radeon_device *rdev);
569 void radeon_agp_fini(struct radeon_device *rdev);
570
571
572 /*
573  * Writeback
574  */
575 struct radeon_wb {
576         struct radeon_bo        *wb_obj;
577         volatile uint32_t       *wb;
578         uint64_t                gpu_addr;
579 };
580
581 /**
582  * struct radeon_pm - power management datas
583  * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
584  * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
585  * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
586  * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
587  * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
588  * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
589  * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
590  * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
591  * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
592  * @sclk:               GPU clock Mhz (core bandwith depends of this clock)
593  * @needed_bandwidth:   current bandwidth needs
594  *
595  * It keeps track of various data needed to take powermanagement decision.
596  * Bandwith need is used to determine minimun clock of the GPU and memory.
597  * Equation between gpu/memory clock and available bandwidth is hw dependent
598  * (type of memory, bus size, efficiency, ...)
599  */
600 enum radeon_pm_state {
601         PM_STATE_DISABLED,
602         PM_STATE_MINIMUM,
603         PM_STATE_PAUSED,
604         PM_STATE_ACTIVE
605 };
606 enum radeon_pm_action {
607         PM_ACTION_NONE,
608         PM_ACTION_MINIMUM,
609         PM_ACTION_DOWNCLOCK,
610         PM_ACTION_UPCLOCK
611 };
612
613 enum radeon_voltage_type {
614         VOLTAGE_NONE = 0,
615         VOLTAGE_GPIO,
616         VOLTAGE_VDDC,
617         VOLTAGE_SW
618 };
619
620 enum radeon_pm_state_type {
621         POWER_STATE_TYPE_DEFAULT,
622         POWER_STATE_TYPE_POWERSAVE,
623         POWER_STATE_TYPE_BATTERY,
624         POWER_STATE_TYPE_BALANCED,
625         POWER_STATE_TYPE_PERFORMANCE,
626 };
627
628 enum radeon_pm_clock_mode_type {
629         POWER_MODE_TYPE_DEFAULT,
630         POWER_MODE_TYPE_LOW,
631         POWER_MODE_TYPE_MID,
632         POWER_MODE_TYPE_HIGH,
633 };
634
635 struct radeon_voltage {
636         enum radeon_voltage_type type;
637         /* gpio voltage */
638         struct radeon_gpio_rec gpio;
639         u32 delay; /* delay in usec from voltage drop to sclk change */
640         bool active_high; /* voltage drop is active when bit is high */
641         /* VDDC voltage */
642         u8 vddc_id; /* index into vddc voltage table */
643         u8 vddci_id; /* index into vddci voltage table */
644         bool vddci_enabled;
645         /* r6xx+ sw */
646         u32 voltage;
647 };
648
649 struct radeon_pm_non_clock_info {
650         /* pcie lanes */
651         int pcie_lanes;
652         /* standardized non-clock flags */
653         u32 flags;
654 };
655
656 struct radeon_pm_clock_info {
657         /* memory clock */
658         u32 mclk;
659         /* engine clock */
660         u32 sclk;
661         /* voltage info */
662         struct radeon_voltage voltage;
663         /* standardized clock flags - not sure we'll need these */
664         u32 flags;
665 };
666
667 struct radeon_power_state {
668         enum radeon_pm_state_type type;
669         /* XXX: use a define for num clock modes */
670         struct radeon_pm_clock_info clock_info[8];
671         /* number of valid clock modes in this power state */
672         int num_clock_modes;
673         struct radeon_pm_clock_info *default_clock_mode;
674         /* non clock info about this state */
675         struct radeon_pm_non_clock_info non_clock_info;
676         bool voltage_drop_active;
677 };
678
679 /*
680  * Some modes are overclocked by very low value, accept them
681  */
682 #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
683
684 struct radeon_pm {
685         struct mutex            mutex;
686         struct delayed_work     idle_work;
687         enum radeon_pm_state    state;
688         enum radeon_pm_action   planned_action;
689         unsigned long           action_timeout;
690         bool                    downclocked;
691         int                     active_crtcs;
692         int                     req_vblank;
693         bool                    vblank_sync;
694         fixed20_12              max_bandwidth;
695         fixed20_12              igp_sideport_mclk;
696         fixed20_12              igp_system_mclk;
697         fixed20_12              igp_ht_link_clk;
698         fixed20_12              igp_ht_link_width;
699         fixed20_12              k8_bandwidth;
700         fixed20_12              sideport_bandwidth;
701         fixed20_12              ht_bandwidth;
702         fixed20_12              core_bandwidth;
703         fixed20_12              sclk;
704         fixed20_12              mclk;
705         fixed20_12              needed_bandwidth;
706         /* XXX: use a define for num power modes */
707         struct radeon_power_state power_state[8];
708         /* number of valid power states */
709         int                     num_power_states;
710         struct radeon_power_state *current_power_state;
711         struct radeon_pm_clock_info *current_clock_mode;
712         struct radeon_power_state *requested_power_state;
713         struct radeon_pm_clock_info *requested_clock_mode;
714         struct radeon_power_state *default_power_state;
715         struct radeon_i2c_chan *i2c_bus;
716 };
717
718
719 /*
720  * Benchmarking
721  */
722 void radeon_benchmark(struct radeon_device *rdev);
723
724
725 /*
726  * Testing
727  */
728 void radeon_test_moves(struct radeon_device *rdev);
729
730
731 /*
732  * Debugfs
733  */
734 int radeon_debugfs_add_files(struct radeon_device *rdev,
735                              struct drm_info_list *files,
736                              unsigned nfiles);
737 int radeon_debugfs_fence_init(struct radeon_device *rdev);
738
739
740 /*
741  * ASIC specific functions.
742  */
743 struct radeon_asic {
744         int (*init)(struct radeon_device *rdev);
745         void (*fini)(struct radeon_device *rdev);
746         int (*resume)(struct radeon_device *rdev);
747         int (*suspend)(struct radeon_device *rdev);
748         void (*vga_set_state)(struct radeon_device *rdev, bool state);
749         int (*gpu_reset)(struct radeon_device *rdev);
750         void (*gart_tlb_flush)(struct radeon_device *rdev);
751         int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
752         int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
753         void (*cp_fini)(struct radeon_device *rdev);
754         void (*cp_disable)(struct radeon_device *rdev);
755         void (*cp_commit)(struct radeon_device *rdev);
756         void (*ring_start)(struct radeon_device *rdev);
757         int (*ring_test)(struct radeon_device *rdev);
758         void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
759         int (*irq_set)(struct radeon_device *rdev);
760         int (*irq_process)(struct radeon_device *rdev);
761         u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
762         void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
763         int (*cs_parse)(struct radeon_cs_parser *p);
764         int (*copy_blit)(struct radeon_device *rdev,
765                          uint64_t src_offset,
766                          uint64_t dst_offset,
767                          unsigned num_pages,
768                          struct radeon_fence *fence);
769         int (*copy_dma)(struct radeon_device *rdev,
770                         uint64_t src_offset,
771                         uint64_t dst_offset,
772                         unsigned num_pages,
773                         struct radeon_fence *fence);
774         int (*copy)(struct radeon_device *rdev,
775                     uint64_t src_offset,
776                     uint64_t dst_offset,
777                     unsigned num_pages,
778                     struct radeon_fence *fence);
779         uint32_t (*get_engine_clock)(struct radeon_device *rdev);
780         void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
781         uint32_t (*get_memory_clock)(struct radeon_device *rdev);
782         void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
783         int (*get_pcie_lanes)(struct radeon_device *rdev);
784         void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
785         void (*set_clock_gating)(struct radeon_device *rdev, int enable);
786         int (*set_surface_reg)(struct radeon_device *rdev, int reg,
787                                uint32_t tiling_flags, uint32_t pitch,
788                                uint32_t offset, uint32_t obj_size);
789         void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
790         void (*bandwidth_update)(struct radeon_device *rdev);
791         void (*hpd_init)(struct radeon_device *rdev);
792         void (*hpd_fini)(struct radeon_device *rdev);
793         bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
794         void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
795         /* ioctl hw specific callback. Some hw might want to perform special
796          * operation on specific ioctl. For instance on wait idle some hw
797          * might want to perform and HDP flush through MMIO as it seems that
798          * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
799          * through ring.
800          */
801         void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
802 };
803
804 /*
805  * Asic structures
806  */
807 struct r100_asic {
808         const unsigned  *reg_safe_bm;
809         unsigned        reg_safe_bm_size;
810         u32             hdp_cntl;
811 };
812
813 struct r300_asic {
814         const unsigned  *reg_safe_bm;
815         unsigned        reg_safe_bm_size;
816         u32             resync_scratch;
817         u32             hdp_cntl;
818 };
819
820 struct r600_asic {
821         unsigned max_pipes;
822         unsigned max_tile_pipes;
823         unsigned max_simds;
824         unsigned max_backends;
825         unsigned max_gprs;
826         unsigned max_threads;
827         unsigned max_stack_entries;
828         unsigned max_hw_contexts;
829         unsigned max_gs_threads;
830         unsigned sx_max_export_size;
831         unsigned sx_max_export_pos_size;
832         unsigned sx_max_export_smx_size;
833         unsigned sq_num_cf_insts;
834         unsigned tiling_nbanks;
835         unsigned tiling_npipes;
836         unsigned tiling_group_size;
837 };
838
839 struct rv770_asic {
840         unsigned max_pipes;
841         unsigned max_tile_pipes;
842         unsigned max_simds;
843         unsigned max_backends;
844         unsigned max_gprs;
845         unsigned max_threads;
846         unsigned max_stack_entries;
847         unsigned max_hw_contexts;
848         unsigned max_gs_threads;
849         unsigned sx_max_export_size;
850         unsigned sx_max_export_pos_size;
851         unsigned sx_max_export_smx_size;
852         unsigned sq_num_cf_insts;
853         unsigned sx_num_of_sets;
854         unsigned sc_prim_fifo_size;
855         unsigned sc_hiz_tile_fifo_size;
856         unsigned sc_earlyz_tile_fifo_fize;
857         unsigned tiling_nbanks;
858         unsigned tiling_npipes;
859         unsigned tiling_group_size;
860 };
861
862 union radeon_asic_config {
863         struct r300_asic        r300;
864         struct r100_asic        r100;
865         struct r600_asic        r600;
866         struct rv770_asic       rv770;
867 };
868
869 /*
870  * asic initizalization from radeon_asic.c
871  */
872 void radeon_agp_disable(struct radeon_device *rdev);
873 int radeon_asic_init(struct radeon_device *rdev);
874
875
876 /*
877  * IOCTL.
878  */
879 int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
880                           struct drm_file *filp);
881 int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
882                             struct drm_file *filp);
883 int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
884                          struct drm_file *file_priv);
885 int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
886                            struct drm_file *file_priv);
887 int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
888                             struct drm_file *file_priv);
889 int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
890                            struct drm_file *file_priv);
891 int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
892                                 struct drm_file *filp);
893 int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
894                           struct drm_file *filp);
895 int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
896                           struct drm_file *filp);
897 int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
898                               struct drm_file *filp);
899 int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
900 int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
901                                 struct drm_file *filp);
902 int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
903                                 struct drm_file *filp);
904
905
906 /*
907  * Core structure, functions and helpers.
908  */
909 typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
910 typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
911
912 struct radeon_device {
913         struct device                   *dev;
914         struct drm_device               *ddev;
915         struct pci_dev                  *pdev;
916         /* ASIC */
917         union radeon_asic_config        config;
918         enum radeon_family              family;
919         unsigned long                   flags;
920         int                             usec_timeout;
921         enum radeon_pll_errata          pll_errata;
922         int                             num_gb_pipes;
923         int                             num_z_pipes;
924         int                             disp_priority;
925         /* BIOS */
926         uint8_t                         *bios;
927         bool                            is_atom_bios;
928         uint16_t                        bios_header_start;
929         struct radeon_bo                *stollen_vga_memory;
930         struct fb_info                  *fbdev_info;
931         struct radeon_bo                *fbdev_rbo;
932         struct radeon_framebuffer       *fbdev_rfb;
933         /* Register mmio */
934         resource_size_t                 rmmio_base;
935         resource_size_t                 rmmio_size;
936         void                            *rmmio;
937         radeon_rreg_t                   mc_rreg;
938         radeon_wreg_t                   mc_wreg;
939         radeon_rreg_t                   pll_rreg;
940         radeon_wreg_t                   pll_wreg;
941         uint32_t                        pcie_reg_mask;
942         radeon_rreg_t                   pciep_rreg;
943         radeon_wreg_t                   pciep_wreg;
944         struct radeon_clock             clock;
945         struct radeon_mc                mc;
946         struct radeon_gart              gart;
947         struct radeon_mode_info         mode_info;
948         struct radeon_scratch           scratch;
949         struct radeon_mman              mman;
950         struct radeon_fence_driver      fence_drv;
951         struct radeon_cp                cp;
952         struct radeon_ib_pool           ib_pool;
953         struct radeon_irq               irq;
954         struct radeon_asic              *asic;
955         struct radeon_gem               gem;
956         struct radeon_pm                pm;
957         uint32_t                        bios_scratch[RADEON_BIOS_NUM_SCRATCH];
958         struct mutex                    cs_mutex;
959         struct radeon_wb                wb;
960         struct radeon_dummy_page        dummy_page;
961         bool                            gpu_lockup;
962         bool                            shutdown;
963         bool                            suspend;
964         bool                            need_dma32;
965         bool                            accel_working;
966         struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
967         const struct firmware *me_fw;   /* all family ME firmware */
968         const struct firmware *pfp_fw;  /* r6/700 PFP firmware */
969         const struct firmware *rlc_fw;  /* r6/700 RLC firmware */
970         struct r600_blit r600_blit;
971         int msi_enabled; /* msi enabled */
972         struct r600_ih ih; /* r6/700 interrupt ring */
973         struct workqueue_struct *wq;
974         struct work_struct hotplug_work;
975         int num_crtc; /* number of crtcs */
976         struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
977
978         /* audio stuff */
979         struct timer_list       audio_timer;
980         int                     audio_channels;
981         int                     audio_rate;
982         int                     audio_bits_per_sample;
983         uint8_t                 audio_status_bits;
984         uint8_t                 audio_category_code;
985
986         bool powered_down;
987 };
988
989 int radeon_device_init(struct radeon_device *rdev,
990                        struct drm_device *ddev,
991                        struct pci_dev *pdev,
992                        uint32_t flags);
993 void radeon_device_fini(struct radeon_device *rdev);
994 int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
995
996 /* r600 blit */
997 int r600_blit_prepare_copy(struct radeon_device *rdev, int size_bytes);
998 void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence);
999 void r600_kms_blit_copy(struct radeon_device *rdev,
1000                         u64 src_gpu_addr, u64 dst_gpu_addr,
1001                         int size_bytes);
1002
1003 static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
1004 {
1005         if (reg < rdev->rmmio_size)
1006                 return readl(((void __iomem *)rdev->rmmio) + reg);
1007         else {
1008                 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1009                 return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1010         }
1011 }
1012
1013 static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1014 {
1015         if (reg < rdev->rmmio_size)
1016                 writel(v, ((void __iomem *)rdev->rmmio) + reg);
1017         else {
1018                 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1019                 writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1020         }
1021 }
1022
1023 /*
1024  * Cast helper
1025  */
1026 #define to_radeon_fence(p) ((struct radeon_fence *)(p))
1027
1028 /*
1029  * Registers read & write functions.
1030  */
1031 #define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
1032 #define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
1033 #define RREG32(reg) r100_mm_rreg(rdev, (reg))
1034 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
1035 #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
1036 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1037 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1038 #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1039 #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1040 #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1041 #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
1042 #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1043 #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
1044 #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1045 #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
1046 #define WREG32_P(reg, val, mask)                                \
1047         do {                                                    \
1048                 uint32_t tmp_ = RREG32(reg);                    \
1049                 tmp_ &= (mask);                                 \
1050                 tmp_ |= ((val) & ~(mask));                      \
1051                 WREG32(reg, tmp_);                              \
1052         } while (0)
1053 #define WREG32_PLL_P(reg, val, mask)                            \
1054         do {                                                    \
1055                 uint32_t tmp_ = RREG32_PLL(reg);                \
1056                 tmp_ &= (mask);                                 \
1057                 tmp_ |= ((val) & ~(mask));                      \
1058                 WREG32_PLL(reg, tmp_);                          \
1059         } while (0)
1060 #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
1061
1062 /*
1063  * Indirect registers accessor
1064  */
1065 static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1066 {
1067         uint32_t r;
1068
1069         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1070         r = RREG32(RADEON_PCIE_DATA);
1071         return r;
1072 }
1073
1074 static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1075 {
1076         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1077         WREG32(RADEON_PCIE_DATA, (v));
1078 }
1079
1080 void r100_pll_errata_after_index(struct radeon_device *rdev);
1081
1082
1083 /*
1084  * ASICs helpers.
1085  */
1086 #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1087                             (rdev->pdev->device == 0x5969))
1088 #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1089                 (rdev->family == CHIP_RV200) || \
1090                 (rdev->family == CHIP_RS100) || \
1091                 (rdev->family == CHIP_RS200) || \
1092                 (rdev->family == CHIP_RV250) || \
1093                 (rdev->family == CHIP_RV280) || \
1094                 (rdev->family == CHIP_RS300))
1095 #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  ||     \
1096                 (rdev->family == CHIP_RV350) ||                 \
1097                 (rdev->family == CHIP_R350)  ||                 \
1098                 (rdev->family == CHIP_RV380) ||                 \
1099                 (rdev->family == CHIP_R420)  ||                 \
1100                 (rdev->family == CHIP_R423)  ||                 \
1101                 (rdev->family == CHIP_RV410) ||                 \
1102                 (rdev->family == CHIP_RS400) ||                 \
1103                 (rdev->family == CHIP_RS480))
1104 #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
1105 #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1106 #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
1107 #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
1108
1109 /*
1110  * BIOS helpers.
1111  */
1112 #define RBIOS8(i) (rdev->bios[i])
1113 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1114 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1115
1116 int radeon_combios_init(struct radeon_device *rdev);
1117 void radeon_combios_fini(struct radeon_device *rdev);
1118 int radeon_atombios_init(struct radeon_device *rdev);
1119 void radeon_atombios_fini(struct radeon_device *rdev);
1120
1121
1122 /*
1123  * RING helpers.
1124  */
1125 static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
1126 {
1127 #if DRM_DEBUG_CODE
1128         if (rdev->cp.count_dw <= 0) {
1129                 DRM_ERROR("radeon: writting more dword to ring than expected !\n");
1130         }
1131 #endif
1132         rdev->cp.ring[rdev->cp.wptr++] = v;
1133         rdev->cp.wptr &= rdev->cp.ptr_mask;
1134         rdev->cp.count_dw--;
1135         rdev->cp.ring_free_dw--;
1136 }
1137
1138
1139 /*
1140  * ASICs macro.
1141  */
1142 #define radeon_init(rdev) (rdev)->asic->init((rdev))
1143 #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1144 #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1145 #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
1146 #define radeon_cs_parse(p) rdev->asic->cs_parse((p))
1147 #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
1148 #define radeon_gpu_reset(rdev) (rdev)->asic->gpu_reset((rdev))
1149 #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1150 #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
1151 #define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
1152 #define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
1153 #define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1154 #define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
1155 #define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1156 #define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
1157 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
1158 #define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1159 #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1160 #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1161 #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
1162 #define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
1163 #define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
1164 #define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
1165 #define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
1166 #define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
1167 #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1168 #define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
1169 #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1170 #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
1171 #define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
1172 #define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1173 #define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1174 #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1175 #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
1176
1177 /* Common functions */
1178 /* AGP */
1179 extern void radeon_agp_disable(struct radeon_device *rdev);
1180 extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
1181 extern void radeon_gart_restore(struct radeon_device *rdev);
1182 extern int radeon_modeset_init(struct radeon_device *rdev);
1183 extern void radeon_modeset_fini(struct radeon_device *rdev);
1184 extern bool radeon_card_posted(struct radeon_device *rdev);
1185 extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
1186 extern void radeon_update_display_priority(struct radeon_device *rdev);
1187 extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
1188 extern int radeon_clocks_init(struct radeon_device *rdev);
1189 extern void radeon_clocks_fini(struct radeon_device *rdev);
1190 extern void radeon_scratch_init(struct radeon_device *rdev);
1191 extern void radeon_surface_init(struct radeon_device *rdev);
1192 extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
1193 extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
1194 extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
1195 extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
1196 extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
1197 extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1198 extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
1199 extern int radeon_resume_kms(struct drm_device *dev);
1200 extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
1201
1202 /* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */
1203
1204 /* rv200,rv250,rv280 */
1205 extern void r200_set_safe_registers(struct radeon_device *rdev);
1206
1207 /* r300,r350,rv350,rv370,rv380 */
1208 extern void r300_set_reg_safe(struct radeon_device *rdev);
1209 extern void r300_mc_program(struct radeon_device *rdev);
1210 extern void r300_mc_init(struct radeon_device *rdev);
1211 extern void r300_clock_startup(struct radeon_device *rdev);
1212 extern int r300_mc_wait_for_idle(struct radeon_device *rdev);
1213 extern int rv370_pcie_gart_init(struct radeon_device *rdev);
1214 extern void rv370_pcie_gart_fini(struct radeon_device *rdev);
1215 extern int rv370_pcie_gart_enable(struct radeon_device *rdev);
1216 extern void rv370_pcie_gart_disable(struct radeon_device *rdev);
1217
1218 /* r420,r423,rv410 */
1219 extern u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg);
1220 extern void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v);
1221 extern int r420_debugfs_pipes_info_init(struct radeon_device *rdev);
1222 extern void r420_pipes_init(struct radeon_device *rdev);
1223
1224 /* rv515 */
1225 struct rv515_mc_save {
1226         u32 d1vga_control;
1227         u32 d2vga_control;
1228         u32 vga_render_control;
1229         u32 vga_hdp_control;
1230         u32 d1crtc_control;
1231         u32 d2crtc_control;
1232 };
1233 extern void rv515_bandwidth_avivo_update(struct radeon_device *rdev);
1234 extern void rv515_vga_render_disable(struct radeon_device *rdev);
1235 extern void rv515_set_safe_registers(struct radeon_device *rdev);
1236 extern void rv515_mc_stop(struct radeon_device *rdev, struct rv515_mc_save *save);
1237 extern void rv515_mc_resume(struct radeon_device *rdev, struct rv515_mc_save *save);
1238 extern void rv515_clock_startup(struct radeon_device *rdev);
1239 extern void rv515_debugfs(struct radeon_device *rdev);
1240 extern int rv515_suspend(struct radeon_device *rdev);
1241
1242 /* rs400 */
1243 extern int rs400_gart_init(struct radeon_device *rdev);
1244 extern int rs400_gart_enable(struct radeon_device *rdev);
1245 extern void rs400_gart_adjust_size(struct radeon_device *rdev);
1246 extern void rs400_gart_disable(struct radeon_device *rdev);
1247 extern void rs400_gart_fini(struct radeon_device *rdev);
1248
1249 /* rs600 */
1250 extern void rs600_set_safe_registers(struct radeon_device *rdev);
1251 extern int rs600_irq_set(struct radeon_device *rdev);
1252 extern void rs600_irq_disable(struct radeon_device *rdev);
1253
1254 /* rs690, rs740 */
1255 extern void rs690_line_buffer_adjust(struct radeon_device *rdev,
1256                                         struct drm_display_mode *mode1,
1257                                         struct drm_display_mode *mode2);
1258
1259 /* r600, rv610, rv630, rv620, rv635, rv670, rs780, rs880 */
1260 extern void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
1261 extern bool r600_card_posted(struct radeon_device *rdev);
1262 extern void r600_cp_stop(struct radeon_device *rdev);
1263 extern void r600_ring_init(struct radeon_device *rdev, unsigned ring_size);
1264 extern int r600_cp_resume(struct radeon_device *rdev);
1265 extern void r600_cp_fini(struct radeon_device *rdev);
1266 extern int r600_count_pipe_bits(uint32_t val);
1267 extern int r600_mc_wait_for_idle(struct radeon_device *rdev);
1268 extern int r600_pcie_gart_init(struct radeon_device *rdev);
1269 extern void r600_pcie_gart_tlb_flush(struct radeon_device *rdev);
1270 extern int r600_ib_test(struct radeon_device *rdev);
1271 extern int r600_ring_test(struct radeon_device *rdev);
1272 extern void r600_wb_fini(struct radeon_device *rdev);
1273 extern int r600_wb_enable(struct radeon_device *rdev);
1274 extern void r600_wb_disable(struct radeon_device *rdev);
1275 extern void r600_scratch_init(struct radeon_device *rdev);
1276 extern int r600_blit_init(struct radeon_device *rdev);
1277 extern void r600_blit_fini(struct radeon_device *rdev);
1278 extern int r600_init_microcode(struct radeon_device *rdev);
1279 extern int r600_gpu_reset(struct radeon_device *rdev);
1280 /* r600 irq */
1281 extern int r600_irq_init(struct radeon_device *rdev);
1282 extern void r600_irq_fini(struct radeon_device *rdev);
1283 extern void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size);
1284 extern int r600_irq_set(struct radeon_device *rdev);
1285 extern void r600_irq_suspend(struct radeon_device *rdev);
1286 /* r600 audio */
1287 extern int r600_audio_init(struct radeon_device *rdev);
1288 extern int r600_audio_tmds_index(struct drm_encoder *encoder);
1289 extern void r600_audio_set_clock(struct drm_encoder *encoder, int clock);
1290 extern void r600_audio_fini(struct radeon_device *rdev);
1291 extern void r600_hdmi_init(struct drm_encoder *encoder);
1292 extern void r600_hdmi_enable(struct drm_encoder *encoder);
1293 extern void r600_hdmi_disable(struct drm_encoder *encoder);
1294 extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1295 extern int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder);
1296 extern void r600_hdmi_update_audio_settings(struct drm_encoder *encoder,
1297                                             int channels,
1298                                             int rate,
1299                                             int bps,
1300                                             uint8_t status_bits,
1301                                             uint8_t category_code);
1302
1303 /* evergreen */
1304 struct evergreen_mc_save {
1305         u32 vga_control[6];
1306         u32 vga_render_control;
1307         u32 vga_hdp_control;
1308         u32 crtc_control[6];
1309 };
1310
1311 #include "radeon_object.h"
1312
1313 #endif