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