2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
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
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
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)
63 #include <linux/atomic.h>
64 #include <linux/wait.h>
65 #include <linux/list.h>
66 #include <linux/kref.h>
68 #include <ttm/ttm_bo_api.h>
69 #include <ttm/ttm_bo_driver.h>
70 #include <ttm/ttm_placement.h>
71 #include <ttm/ttm_module.h>
72 #include <ttm/ttm_execbuf_util.h>
74 #include "radeon_family.h"
75 #include "radeon_mode.h"
76 #include "radeon_reg.h"
81 extern int radeon_no_wb;
82 extern int radeon_modeset;
83 extern int radeon_dynclks;
84 extern int radeon_r4xx_atom;
85 extern int radeon_agpmode;
86 extern int radeon_vram_limit;
87 extern int radeon_gart_size;
88 extern int radeon_benchmarking;
89 extern int radeon_testing;
90 extern int radeon_connector_table;
92 extern int radeon_audio;
93 extern int radeon_disp_priority;
94 extern int radeon_hw_i2c;
95 extern int radeon_pcie_gen2;
96 extern int radeon_msi;
97 extern int radeon_lockup_timeout;
98 extern int radeon_fastfb;
99 extern int radeon_dpm;
102 * Copy from radeon_drv.h so we don't have to include both and have conflicting
105 #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
106 #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
107 /* RADEON_IB_POOL_SIZE must be a power of 2 */
108 #define RADEON_IB_POOL_SIZE 16
109 #define RADEON_DEBUGFS_MAX_COMPONENTS 32
110 #define RADEONFB_CONN_LIMIT 4
111 #define RADEON_BIOS_NUM_SCRATCH 8
113 /* max number of rings */
114 #define RADEON_NUM_RINGS 6
116 /* fence seq are set to this number when signaled */
117 #define RADEON_FENCE_SIGNALED_SEQ 0LL
119 /* internal ring indices */
120 /* r1xx+ has gfx CP ring */
121 #define RADEON_RING_TYPE_GFX_INDEX 0
123 /* cayman has 2 compute CP rings */
124 #define CAYMAN_RING_TYPE_CP1_INDEX 1
125 #define CAYMAN_RING_TYPE_CP2_INDEX 2
127 /* R600+ has an async dma ring */
128 #define R600_RING_TYPE_DMA_INDEX 3
129 /* cayman add a second async dma ring */
130 #define CAYMAN_RING_TYPE_DMA1_INDEX 4
133 #define R600_RING_TYPE_UVD_INDEX 5
135 /* hardcode those limit for now */
136 #define RADEON_VA_IB_OFFSET (1 << 20)
137 #define RADEON_VA_RESERVED_SIZE (8 << 20)
138 #define RADEON_IB_VM_MAX_SIZE (64 << 10)
141 #define RADEON_RESET_GFX (1 << 0)
142 #define RADEON_RESET_COMPUTE (1 << 1)
143 #define RADEON_RESET_DMA (1 << 2)
144 #define RADEON_RESET_CP (1 << 3)
145 #define RADEON_RESET_GRBM (1 << 4)
146 #define RADEON_RESET_DMA1 (1 << 5)
147 #define RADEON_RESET_RLC (1 << 6)
148 #define RADEON_RESET_SEM (1 << 7)
149 #define RADEON_RESET_IH (1 << 8)
150 #define RADEON_RESET_VMC (1 << 9)
151 #define RADEON_RESET_MC (1 << 10)
152 #define RADEON_RESET_DISPLAY (1 << 11)
154 /* max cursor sizes (in pixels) */
155 #define CURSOR_WIDTH 64
156 #define CURSOR_HEIGHT 64
158 #define CIK_CURSOR_WIDTH 128
159 #define CIK_CURSOR_HEIGHT 128
162 * Errata workarounds.
164 enum radeon_pll_errata {
165 CHIP_ERRATA_R300_CG = 0x00000001,
166 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
167 CHIP_ERRATA_PLL_DELAY = 0x00000004
171 struct radeon_device;
177 bool radeon_get_bios(struct radeon_device *rdev);
182 struct radeon_dummy_page {
186 int radeon_dummy_page_init(struct radeon_device *rdev);
187 void radeon_dummy_page_fini(struct radeon_device *rdev);
193 struct radeon_clock {
194 struct radeon_pll p1pll;
195 struct radeon_pll p2pll;
196 struct radeon_pll dcpll;
197 struct radeon_pll spll;
198 struct radeon_pll mpll;
200 uint32_t default_mclk;
201 uint32_t default_sclk;
202 uint32_t default_dispclk;
204 uint32_t max_pixel_clock;
210 int radeon_pm_init(struct radeon_device *rdev);
211 void radeon_pm_fini(struct radeon_device *rdev);
212 void radeon_pm_compute_clocks(struct radeon_device *rdev);
213 void radeon_pm_suspend(struct radeon_device *rdev);
214 void radeon_pm_resume(struct radeon_device *rdev);
215 void radeon_combios_get_power_modes(struct radeon_device *rdev);
216 void radeon_atombios_get_power_modes(struct radeon_device *rdev);
217 int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
221 struct atom_clock_dividers *dividers);
222 int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
225 struct atom_mpll_param *mpll_param);
226 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
227 int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
228 u16 voltage_level, u8 voltage_type,
229 u32 *gpio_value, u32 *gpio_mask);
230 void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
231 u32 eng_clock, u32 mem_clock);
232 int radeon_atom_get_voltage_step(struct radeon_device *rdev,
233 u8 voltage_type, u16 *voltage_step);
234 int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
235 u16 voltage_id, u16 *voltage);
236 int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
239 int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
243 int radeon_atom_get_min_voltage(struct radeon_device *rdev,
244 u8 voltage_type, u16 *min_voltage);
245 int radeon_atom_get_max_voltage(struct radeon_device *rdev,
246 u8 voltage_type, u16 *max_voltage);
247 int radeon_atom_get_voltage_table(struct radeon_device *rdev,
248 u8 voltage_type, u8 voltage_mode,
249 struct atom_voltage_table *voltage_table);
250 bool radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
251 u8 voltage_type, u8 voltage_mode);
252 void radeon_atom_update_memory_dll(struct radeon_device *rdev,
254 void radeon_atom_set_ac_timing(struct radeon_device *rdev,
256 int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
258 struct atom_mc_reg_table *reg_table);
259 int radeon_atom_get_memory_info(struct radeon_device *rdev,
260 u8 module_index, struct atom_memory_info *mem_info);
261 int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
262 bool gddr5, u8 module_index,
263 struct atom_memory_clock_range_table *mclk_range_table);
264 int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
265 u16 voltage_id, u16 *voltage);
266 void rs690_pm_info(struct radeon_device *rdev);
267 extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
268 unsigned *bankh, unsigned *mtaspect,
269 unsigned *tile_split);
274 struct radeon_fence_driver {
275 uint32_t scratch_reg;
277 volatile uint32_t *cpu_addr;
278 /* sync_seq is protected by ring emission lock */
279 uint64_t sync_seq[RADEON_NUM_RINGS];
281 unsigned long last_activity;
285 struct radeon_fence {
286 struct radeon_device *rdev;
288 /* protected by radeon_fence.lock */
294 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
295 int radeon_fence_driver_init(struct radeon_device *rdev);
296 void radeon_fence_driver_fini(struct radeon_device *rdev);
297 void radeon_fence_driver_force_completion(struct radeon_device *rdev);
298 int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
299 void radeon_fence_process(struct radeon_device *rdev, int ring);
300 bool radeon_fence_signaled(struct radeon_fence *fence);
301 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
302 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
303 int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
304 int radeon_fence_wait_any(struct radeon_device *rdev,
305 struct radeon_fence **fences,
307 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
308 void radeon_fence_unref(struct radeon_fence **fence);
309 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
310 bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
311 void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
312 static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
313 struct radeon_fence *b)
323 BUG_ON(a->ring != b->ring);
325 if (a->seq > b->seq) {
332 static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
333 struct radeon_fence *b)
343 BUG_ON(a->ring != b->ring);
345 return a->seq < b->seq;
351 struct radeon_surface_reg {
352 struct radeon_bo *bo;
355 #define RADEON_GEM_MAX_SURFACES 8
361 struct ttm_bo_global_ref bo_global_ref;
362 struct drm_global_reference mem_global_ref;
363 struct ttm_bo_device bdev;
364 bool mem_global_referenced;
368 /* bo virtual address in a specific vm */
369 struct radeon_bo_va {
370 /* protected by bo being reserved */
371 struct list_head bo_list;
378 /* protected by vm mutex */
379 struct list_head vm_list;
381 /* constant after initialization */
382 struct radeon_vm *vm;
383 struct radeon_bo *bo;
387 /* Protected by gem.mutex */
388 struct list_head list;
389 /* Protected by tbo.reserved */
391 struct ttm_placement placement;
392 struct ttm_buffer_object tbo;
393 struct ttm_bo_kmap_obj kmap;
399 /* list of all virtual address to which this bo
403 /* Constant after initialization */
404 struct radeon_device *rdev;
405 struct drm_gem_object gem_base;
407 struct ttm_bo_kmap_obj dma_buf_vmap;
410 #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
412 struct radeon_bo_list {
413 struct ttm_validate_buffer tv;
414 struct radeon_bo *bo;
422 int radeon_gem_debugfs_init(struct radeon_device *rdev);
424 /* sub-allocation manager, it has to be protected by another lock.
425 * By conception this is an helper for other part of the driver
426 * like the indirect buffer or semaphore, which both have their
429 * Principe is simple, we keep a list of sub allocation in offset
430 * order (first entry has offset == 0, last entry has the highest
433 * When allocating new object we first check if there is room at
434 * the end total_size - (last_object_offset + last_object_size) >=
435 * alloc_size. If so we allocate new object there.
437 * When there is not enough room at the end, we start waiting for
438 * each sub object until we reach object_offset+object_size >=
439 * alloc_size, this object then become the sub object we return.
441 * Alignment can't be bigger than page size.
443 * Hole are not considered for allocation to keep things simple.
444 * Assumption is that there won't be hole (all object on same
447 struct radeon_sa_manager {
448 wait_queue_head_t wq;
449 struct radeon_bo *bo;
450 struct list_head *hole;
451 struct list_head flist[RADEON_NUM_RINGS];
452 struct list_head olist;
461 /* sub-allocation buffer */
462 struct radeon_sa_bo {
463 struct list_head olist;
464 struct list_head flist;
465 struct radeon_sa_manager *manager;
468 struct radeon_fence *fence;
476 struct list_head objects;
479 int radeon_gem_init(struct radeon_device *rdev);
480 void radeon_gem_fini(struct radeon_device *rdev);
481 int radeon_gem_object_create(struct radeon_device *rdev, int size,
482 int alignment, int initial_domain,
483 bool discardable, bool kernel,
484 struct drm_gem_object **obj);
486 int radeon_mode_dumb_create(struct drm_file *file_priv,
487 struct drm_device *dev,
488 struct drm_mode_create_dumb *args);
489 int radeon_mode_dumb_mmap(struct drm_file *filp,
490 struct drm_device *dev,
491 uint32_t handle, uint64_t *offset_p);
492 int radeon_mode_dumb_destroy(struct drm_file *file_priv,
493 struct drm_device *dev,
499 /* everything here is constant */
500 struct radeon_semaphore {
501 struct radeon_sa_bo *sa_bo;
506 int radeon_semaphore_create(struct radeon_device *rdev,
507 struct radeon_semaphore **semaphore);
508 void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
509 struct radeon_semaphore *semaphore);
510 void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
511 struct radeon_semaphore *semaphore);
512 int radeon_semaphore_sync_rings(struct radeon_device *rdev,
513 struct radeon_semaphore *semaphore,
514 int signaler, int waiter);
515 void radeon_semaphore_free(struct radeon_device *rdev,
516 struct radeon_semaphore **semaphore,
517 struct radeon_fence *fence);
520 * GART structures, functions & helpers
524 #define RADEON_GPU_PAGE_SIZE 4096
525 #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
526 #define RADEON_GPU_PAGE_SHIFT 12
527 #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
530 dma_addr_t table_addr;
531 struct radeon_bo *robj;
533 unsigned num_gpu_pages;
534 unsigned num_cpu_pages;
537 dma_addr_t *pages_addr;
541 int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
542 void radeon_gart_table_ram_free(struct radeon_device *rdev);
543 int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
544 void radeon_gart_table_vram_free(struct radeon_device *rdev);
545 int radeon_gart_table_vram_pin(struct radeon_device *rdev);
546 void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
547 int radeon_gart_init(struct radeon_device *rdev);
548 void radeon_gart_fini(struct radeon_device *rdev);
549 void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
551 int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
552 int pages, struct page **pagelist,
553 dma_addr_t *dma_addr);
554 void radeon_gart_restore(struct radeon_device *rdev);
558 * GPU MC structures, functions & helpers
561 resource_size_t aper_size;
562 resource_size_t aper_base;
563 resource_size_t agp_base;
564 /* for some chips with <= 32MB we need to lie
565 * about vram size near mc fb location */
567 u64 visible_vram_size;
577 bool igp_sideport_enabled;
582 bool radeon_combios_sideport_present(struct radeon_device *rdev);
583 bool radeon_atombios_sideport_present(struct radeon_device *rdev);
586 * GPU scratch registers structures, functions & helpers
588 struct radeon_scratch {
595 int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
596 void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
599 * GPU doorbell structures, functions & helpers
601 struct radeon_doorbell {
605 resource_size_t base;
606 resource_size_t size;
610 int radeon_doorbell_get(struct radeon_device *rdev, u32 *page);
611 void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell);
617 struct radeon_unpin_work {
618 struct work_struct work;
619 struct radeon_device *rdev;
621 struct radeon_fence *fence;
622 struct drm_pending_vblank_event *event;
623 struct radeon_bo *old_rbo;
627 struct r500_irq_stat_regs {
632 struct r600_irq_stat_regs {
642 struct evergreen_irq_stat_regs {
663 struct cik_irq_stat_regs {
673 union radeon_irq_stat_regs {
674 struct r500_irq_stat_regs r500;
675 struct r600_irq_stat_regs r600;
676 struct evergreen_irq_stat_regs evergreen;
677 struct cik_irq_stat_regs cik;
680 #define RADEON_MAX_HPD_PINS 6
681 #define RADEON_MAX_CRTCS 6
682 #define RADEON_MAX_AFMT_BLOCKS 6
687 atomic_t ring_int[RADEON_NUM_RINGS];
688 bool crtc_vblank_int[RADEON_MAX_CRTCS];
689 atomic_t pflip[RADEON_MAX_CRTCS];
690 wait_queue_head_t vblank_queue;
691 bool hpd[RADEON_MAX_HPD_PINS];
692 bool afmt[RADEON_MAX_AFMT_BLOCKS];
693 union radeon_irq_stat_regs stat_regs;
697 int radeon_irq_kms_init(struct radeon_device *rdev);
698 void radeon_irq_kms_fini(struct radeon_device *rdev);
699 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
700 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
701 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
702 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
703 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
704 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
705 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
706 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
713 struct radeon_sa_bo *sa_bo;
718 struct radeon_fence *fence;
719 struct radeon_vm *vm;
721 struct radeon_fence *sync_to[RADEON_NUM_RINGS];
722 struct radeon_semaphore *semaphore;
726 struct radeon_bo *ring_obj;
727 volatile uint32_t *ring;
731 unsigned rptr_save_reg;
732 u64 next_rptr_gpu_addr;
733 volatile u32 *next_rptr_cpu_addr;
738 unsigned ring_free_dw;
740 unsigned long last_activity;
750 u64 last_semaphore_signal_addr;
751 u64 last_semaphore_wait_addr;
756 struct radeon_bo *mqd_obj;
757 u32 doorbell_page_num;
763 struct radeon_bo *hpd_eop_obj;
764 u64 hpd_eop_gpu_addr;
774 /* maximum number of VMIDs */
775 #define RADEON_NUM_VM 16
777 /* defines number of bits in page table versus page directory,
778 * a page is 4KB so we have 12 bits offset, 9 bits in the page
779 * table and the remaining 19 bits are in the page directory */
780 #define RADEON_VM_BLOCK_SIZE 9
782 /* number of entries in page table */
783 #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
786 struct list_head list;
790 /* contains the page directory */
791 struct radeon_sa_bo *page_directory;
792 uint64_t pd_gpu_addr;
794 /* array of page tables, one for each page directory entry */
795 struct radeon_sa_bo **page_tables;
798 /* last fence for cs using this vm */
799 struct radeon_fence *fence;
800 /* last flush or NULL if we still need to flush */
801 struct radeon_fence *last_flush;
804 struct radeon_vm_manager {
806 struct list_head lru_vm;
807 struct radeon_fence *active[RADEON_NUM_VM];
808 struct radeon_sa_manager sa_manager;
810 /* number of VMIDs */
812 /* vram base address for page table entry */
813 u64 vram_base_offset;
819 * file private structure
821 struct radeon_fpriv {
829 struct radeon_bo *ring_obj;
830 volatile uint32_t *ring;
839 struct r600_blit_cp_primitives {
840 void (*set_render_target)(struct radeon_device *rdev, int format,
841 int w, int h, u64 gpu_addr);
842 void (*cp_set_surface_sync)(struct radeon_device *rdev,
843 u32 sync_type, u32 size,
845 void (*set_shaders)(struct radeon_device *rdev);
846 void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
847 void (*set_tex_resource)(struct radeon_device *rdev,
848 int format, int w, int h, int pitch,
849 u64 gpu_addr, u32 size);
850 void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
852 void (*draw_auto)(struct radeon_device *rdev);
853 void (*set_default_state)(struct radeon_device *rdev);
857 struct radeon_bo *shader_obj;
858 struct r600_blit_cp_primitives primitives;
860 int ring_size_common;
861 int ring_size_per_loop;
863 u32 vs_offset, ps_offset;
871 #include "clearstate_defs.h"
874 /* for power gating */
875 struct radeon_bo *save_restore_obj;
876 uint64_t save_restore_gpu_addr;
877 volatile uint32_t *sr_ptr;
880 /* for clear state */
881 struct radeon_bo *clear_state_obj;
882 uint64_t clear_state_gpu_addr;
883 volatile uint32_t *cs_ptr;
884 struct cs_section_def *cs_data;
887 int radeon_ib_get(struct radeon_device *rdev, int ring,
888 struct radeon_ib *ib, struct radeon_vm *vm,
890 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
891 void radeon_ib_sync_to(struct radeon_ib *ib, struct radeon_fence *fence);
892 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
893 struct radeon_ib *const_ib);
894 int radeon_ib_pool_init(struct radeon_device *rdev);
895 void radeon_ib_pool_fini(struct radeon_device *rdev);
896 int radeon_ib_ring_tests(struct radeon_device *rdev);
897 /* Ring access between begin & end cannot sleep */
898 bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
899 struct radeon_ring *ring);
900 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
901 int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
902 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
903 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
904 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
905 void radeon_ring_undo(struct radeon_ring *ring);
906 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
907 int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
908 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
909 void radeon_ring_lockup_update(struct radeon_ring *ring);
910 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
911 unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
913 int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
914 unsigned size, uint32_t *data);
915 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
916 unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
917 u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
918 void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
922 void r600_dma_stop(struct radeon_device *rdev);
923 int r600_dma_resume(struct radeon_device *rdev);
924 void r600_dma_fini(struct radeon_device *rdev);
926 void cayman_dma_stop(struct radeon_device *rdev);
927 int cayman_dma_resume(struct radeon_device *rdev);
928 void cayman_dma_fini(struct radeon_device *rdev);
933 struct radeon_cs_reloc {
934 struct drm_gem_object *gobj;
935 struct radeon_bo *robj;
936 struct radeon_bo_list lobj;
941 struct radeon_cs_chunk {
947 void __user *user_ptr;
948 int last_copied_page;
952 struct radeon_cs_parser {
954 struct radeon_device *rdev;
955 struct drm_file *filp;
958 struct radeon_cs_chunk *chunks;
959 uint64_t *chunks_array;
964 struct radeon_cs_reloc *relocs;
965 struct radeon_cs_reloc **relocs_ptr;
966 struct list_head validated;
967 unsigned dma_reloc_idx;
968 /* indices of various chunks */
970 int chunk_relocs_idx;
972 int chunk_const_ib_idx;
974 struct radeon_ib const_ib;
983 extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
984 extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
986 struct radeon_cs_packet {
995 typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
996 struct radeon_cs_packet *pkt,
997 unsigned idx, unsigned reg);
998 typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
999 struct radeon_cs_packet *pkt);
1005 int radeon_agp_init(struct radeon_device *rdev);
1006 void radeon_agp_resume(struct radeon_device *rdev);
1007 void radeon_agp_suspend(struct radeon_device *rdev);
1008 void radeon_agp_fini(struct radeon_device *rdev);
1015 struct radeon_bo *wb_obj;
1016 volatile uint32_t *wb;
1022 #define RADEON_WB_SCRATCH_OFFSET 0
1023 #define RADEON_WB_RING0_NEXT_RPTR 256
1024 #define RADEON_WB_CP_RPTR_OFFSET 1024
1025 #define RADEON_WB_CP1_RPTR_OFFSET 1280
1026 #define RADEON_WB_CP2_RPTR_OFFSET 1536
1027 #define R600_WB_DMA_RPTR_OFFSET 1792
1028 #define R600_WB_IH_WPTR_OFFSET 2048
1029 #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
1030 #define R600_WB_UVD_RPTR_OFFSET 2560
1031 #define R600_WB_EVENT_OFFSET 3072
1032 #define CIK_WB_CP1_WPTR_OFFSET 3328
1033 #define CIK_WB_CP2_WPTR_OFFSET 3584
1036 * struct radeon_pm - power management datas
1037 * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
1038 * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
1039 * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
1040 * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
1041 * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
1042 * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
1043 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
1044 * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
1045 * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
1046 * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
1047 * @needed_bandwidth: current bandwidth needs
1049 * It keeps track of various data needed to take powermanagement decision.
1050 * Bandwidth need is used to determine minimun clock of the GPU and memory.
1051 * Equation between gpu/memory clock and available bandwidth is hw dependent
1052 * (type of memory, bus size, efficiency, ...)
1055 enum radeon_pm_method {
1061 enum radeon_dynpm_state {
1062 DYNPM_STATE_DISABLED,
1063 DYNPM_STATE_MINIMUM,
1066 DYNPM_STATE_SUSPENDED,
1068 enum radeon_dynpm_action {
1070 DYNPM_ACTION_MINIMUM,
1071 DYNPM_ACTION_DOWNCLOCK,
1072 DYNPM_ACTION_UPCLOCK,
1073 DYNPM_ACTION_DEFAULT
1076 enum radeon_voltage_type {
1083 enum radeon_pm_state_type {
1084 /* not used for dpm */
1085 POWER_STATE_TYPE_DEFAULT,
1086 POWER_STATE_TYPE_POWERSAVE,
1087 /* user selectable states */
1088 POWER_STATE_TYPE_BATTERY,
1089 POWER_STATE_TYPE_BALANCED,
1090 POWER_STATE_TYPE_PERFORMANCE,
1091 /* internal states */
1092 POWER_STATE_TYPE_INTERNAL_UVD,
1093 POWER_STATE_TYPE_INTERNAL_UVD_SD,
1094 POWER_STATE_TYPE_INTERNAL_UVD_HD,
1095 POWER_STATE_TYPE_INTERNAL_UVD_HD2,
1096 POWER_STATE_TYPE_INTERNAL_UVD_MVC,
1097 POWER_STATE_TYPE_INTERNAL_BOOT,
1098 POWER_STATE_TYPE_INTERNAL_THERMAL,
1099 POWER_STATE_TYPE_INTERNAL_ACPI,
1100 POWER_STATE_TYPE_INTERNAL_ULV,
1103 enum radeon_pm_profile_type {
1111 #define PM_PROFILE_DEFAULT_IDX 0
1112 #define PM_PROFILE_LOW_SH_IDX 1
1113 #define PM_PROFILE_MID_SH_IDX 2
1114 #define PM_PROFILE_HIGH_SH_IDX 3
1115 #define PM_PROFILE_LOW_MH_IDX 4
1116 #define PM_PROFILE_MID_MH_IDX 5
1117 #define PM_PROFILE_HIGH_MH_IDX 6
1118 #define PM_PROFILE_MAX 7
1120 struct radeon_pm_profile {
1121 int dpms_off_ps_idx;
1123 int dpms_off_cm_idx;
1127 enum radeon_int_thermal_type {
1129 THERMAL_TYPE_EXTERNAL,
1130 THERMAL_TYPE_EXTERNAL_GPIO,
1133 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1134 THERMAL_TYPE_EVERGREEN,
1138 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1142 struct radeon_voltage {
1143 enum radeon_voltage_type type;
1145 struct radeon_gpio_rec gpio;
1146 u32 delay; /* delay in usec from voltage drop to sclk change */
1147 bool active_high; /* voltage drop is active when bit is high */
1149 u8 vddc_id; /* index into vddc voltage table */
1150 u8 vddci_id; /* index into vddci voltage table */
1154 /* evergreen+ vddci */
1158 /* clock mode flags */
1159 #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
1161 struct radeon_pm_clock_info {
1167 struct radeon_voltage voltage;
1168 /* standardized clock flags */
1173 #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
1175 struct radeon_power_state {
1176 enum radeon_pm_state_type type;
1177 struct radeon_pm_clock_info *clock_info;
1178 /* number of valid clock modes in this power state */
1179 int num_clock_modes;
1180 struct radeon_pm_clock_info *default_clock_mode;
1181 /* standardized state flags */
1183 u32 misc; /* vbios specific flags */
1184 u32 misc2; /* vbios specific flags */
1185 int pcie_lanes; /* pcie lanes */
1189 * Some modes are overclocked by very low value, accept them
1191 #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
1193 enum radeon_dpm_auto_throttle_src {
1194 RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL,
1195 RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1198 enum radeon_dpm_event_src {
1199 RADEON_DPM_EVENT_SRC_ANALOG = 0,
1200 RADEON_DPM_EVENT_SRC_EXTERNAL = 1,
1201 RADEON_DPM_EVENT_SRC_DIGITAL = 2,
1202 RADEON_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1203 RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1207 u32 caps; /* vbios flags */
1208 u32 class; /* vbios flags */
1209 u32 class2; /* vbios flags */
1217 struct radeon_dpm_thermal {
1218 /* thermal interrupt work */
1219 struct work_struct work;
1220 /* low temperature threshold */
1222 /* high temperature threshold */
1224 /* was interrupt low to high or high to low */
1228 enum radeon_clk_action
1234 struct radeon_blacklist_clocks
1238 enum radeon_clk_action action;
1241 struct radeon_clock_and_voltage_limits {
1248 struct radeon_clock_array {
1253 struct radeon_clock_voltage_dependency_entry {
1258 struct radeon_clock_voltage_dependency_table {
1260 struct radeon_clock_voltage_dependency_entry *entries;
1263 struct radeon_cac_leakage_entry {
1268 struct radeon_cac_leakage_table {
1270 struct radeon_cac_leakage_entry *entries;
1273 struct radeon_dpm_dynamic_state {
1274 struct radeon_clock_voltage_dependency_table vddc_dependency_on_sclk;
1275 struct radeon_clock_voltage_dependency_table vddci_dependency_on_mclk;
1276 struct radeon_clock_voltage_dependency_table vddc_dependency_on_mclk;
1277 struct radeon_clock_array valid_sclk_values;
1278 struct radeon_clock_array valid_mclk_values;
1279 struct radeon_clock_and_voltage_limits max_clock_voltage_on_dc;
1280 struct radeon_clock_and_voltage_limits max_clock_voltage_on_ac;
1281 u32 mclk_sclk_ratio;
1282 u32 sclk_mclk_delta;
1283 u16 vddc_vddci_delta;
1284 u16 min_vddc_for_pcie_gen2;
1285 struct radeon_cac_leakage_table cac_leakage_table;
1288 struct radeon_dpm_fan {
1298 bool ucode_fan_control;
1302 struct radeon_ps *ps;
1303 /* number of valid power states */
1305 /* current power state that is active */
1306 struct radeon_ps *current_ps;
1307 /* requested power state */
1308 struct radeon_ps *requested_ps;
1309 /* boot up power state */
1310 struct radeon_ps *boot_ps;
1311 /* default uvd power state */
1312 struct radeon_ps *uvd_ps;
1313 enum radeon_pm_state_type state;
1314 enum radeon_pm_state_type user_state;
1316 u32 voltage_response_time;
1317 u32 backbias_response_time;
1319 u32 new_active_crtcs;
1320 int new_active_crtc_count;
1321 u32 current_active_crtcs;
1322 int current_active_crtc_count;
1323 struct radeon_dpm_dynamic_state dyn_state;
1324 struct radeon_dpm_fan fan;
1327 u32 sq_ramping_threshold;
1331 u16 load_line_slope;
1334 /* special states active */
1335 bool thermal_active;
1337 /* thermal handling */
1338 struct radeon_dpm_thermal thermal;
1341 void radeon_dpm_enable_power_state(struct radeon_device *rdev,
1342 enum radeon_pm_state_type dpm_state);
1347 /* write locked while reprogramming mclk */
1348 struct rw_semaphore mclk_lock;
1350 int active_crtc_count;
1353 fixed20_12 max_bandwidth;
1354 fixed20_12 igp_sideport_mclk;
1355 fixed20_12 igp_system_mclk;
1356 fixed20_12 igp_ht_link_clk;
1357 fixed20_12 igp_ht_link_width;
1358 fixed20_12 k8_bandwidth;
1359 fixed20_12 sideport_bandwidth;
1360 fixed20_12 ht_bandwidth;
1361 fixed20_12 core_bandwidth;
1364 fixed20_12 needed_bandwidth;
1365 struct radeon_power_state *power_state;
1366 /* number of valid power states */
1367 int num_power_states;
1368 int current_power_state_index;
1369 int current_clock_mode_index;
1370 int requested_power_state_index;
1371 int requested_clock_mode_index;
1372 int default_power_state_index;
1381 struct radeon_i2c_chan *i2c_bus;
1382 /* selected pm method */
1383 enum radeon_pm_method pm_method;
1384 /* dynpm power management */
1385 struct delayed_work dynpm_idle_work;
1386 enum radeon_dynpm_state dynpm_state;
1387 enum radeon_dynpm_action dynpm_planned_action;
1388 unsigned long dynpm_action_timeout;
1389 bool dynpm_can_upclock;
1390 bool dynpm_can_downclock;
1391 /* profile-based power management */
1392 enum radeon_pm_profile_type profile;
1394 struct radeon_pm_profile profiles[PM_PROFILE_MAX];
1395 /* internal thermal controller on rv6xx+ */
1396 enum radeon_int_thermal_type int_thermal_type;
1397 struct device *int_hwmon_dev;
1400 struct radeon_dpm dpm;
1403 int radeon_pm_get_type_index(struct radeon_device *rdev,
1404 enum radeon_pm_state_type ps_type,
1409 #define RADEON_MAX_UVD_HANDLES 10
1410 #define RADEON_UVD_STACK_SIZE (1024*1024)
1411 #define RADEON_UVD_HEAP_SIZE (1024*1024)
1414 struct radeon_bo *vcpu_bo;
1417 atomic_t handles[RADEON_MAX_UVD_HANDLES];
1418 struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
1419 struct delayed_work idle_work;
1422 int radeon_uvd_init(struct radeon_device *rdev);
1423 void radeon_uvd_fini(struct radeon_device *rdev);
1424 int radeon_uvd_suspend(struct radeon_device *rdev);
1425 int radeon_uvd_resume(struct radeon_device *rdev);
1426 int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
1427 uint32_t handle, struct radeon_fence **fence);
1428 int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
1429 uint32_t handle, struct radeon_fence **fence);
1430 void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo);
1431 void radeon_uvd_free_handles(struct radeon_device *rdev,
1432 struct drm_file *filp);
1433 int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
1434 void radeon_uvd_note_usage(struct radeon_device *rdev);
1435 int radeon_uvd_calc_upll_dividers(struct radeon_device *rdev,
1436 unsigned vclk, unsigned dclk,
1437 unsigned vco_min, unsigned vco_max,
1438 unsigned fb_factor, unsigned fb_mask,
1439 unsigned pd_min, unsigned pd_max,
1441 unsigned *optimal_fb_div,
1442 unsigned *optimal_vclk_div,
1443 unsigned *optimal_dclk_div);
1444 int radeon_uvd_send_upll_ctlreq(struct radeon_device *rdev,
1445 unsigned cg_upll_func_cntl);
1450 int bits_per_sample;
1458 void radeon_benchmark(struct radeon_device *rdev, int test_number);
1464 void radeon_test_moves(struct radeon_device *rdev);
1465 void radeon_test_ring_sync(struct radeon_device *rdev,
1466 struct radeon_ring *cpA,
1467 struct radeon_ring *cpB);
1468 void radeon_test_syncing(struct radeon_device *rdev);
1474 struct radeon_debugfs {
1475 struct drm_info_list *files;
1479 int radeon_debugfs_add_files(struct radeon_device *rdev,
1480 struct drm_info_list *files,
1482 int radeon_debugfs_fence_init(struct radeon_device *rdev);
1486 * ASIC specific functions.
1488 struct radeon_asic {
1489 int (*init)(struct radeon_device *rdev);
1490 void (*fini)(struct radeon_device *rdev);
1491 int (*resume)(struct radeon_device *rdev);
1492 int (*suspend)(struct radeon_device *rdev);
1493 void (*vga_set_state)(struct radeon_device *rdev, bool state);
1494 int (*asic_reset)(struct radeon_device *rdev);
1495 /* ioctl hw specific callback. Some hw might want to perform special
1496 * operation on specific ioctl. For instance on wait idle some hw
1497 * might want to perform and HDP flush through MMIO as it seems that
1498 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
1501 void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
1502 /* check if 3D engine is idle */
1503 bool (*gui_idle)(struct radeon_device *rdev);
1504 /* wait for mc_idle */
1505 int (*mc_wait_for_idle)(struct radeon_device *rdev);
1506 /* get the reference clock */
1507 u32 (*get_xclk)(struct radeon_device *rdev);
1508 /* get the gpu clock counter */
1509 uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
1512 void (*tlb_flush)(struct radeon_device *rdev);
1513 int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
1516 int (*init)(struct radeon_device *rdev);
1517 void (*fini)(struct radeon_device *rdev);
1520 void (*set_page)(struct radeon_device *rdev,
1521 struct radeon_ib *ib,
1523 uint64_t addr, unsigned count,
1524 uint32_t incr, uint32_t flags);
1526 /* ring specific callbacks */
1528 void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
1529 int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
1530 void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
1531 void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
1532 struct radeon_semaphore *semaphore, bool emit_wait);
1533 int (*cs_parse)(struct radeon_cs_parser *p);
1534 void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
1535 int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1536 int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1537 bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
1538 void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
1540 u32 (*get_rptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1541 u32 (*get_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1542 void (*set_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1543 } ring[RADEON_NUM_RINGS];
1546 int (*set)(struct radeon_device *rdev);
1547 int (*process)(struct radeon_device *rdev);
1551 /* display watermarks */
1552 void (*bandwidth_update)(struct radeon_device *rdev);
1553 /* get frame count */
1554 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
1555 /* wait for vblank */
1556 void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
1557 /* set backlight level */
1558 void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
1559 /* get backlight level */
1560 u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
1561 /* audio callbacks */
1562 void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
1563 void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
1565 /* copy functions for bo handling */
1567 int (*blit)(struct radeon_device *rdev,
1568 uint64_t src_offset,
1569 uint64_t dst_offset,
1570 unsigned num_gpu_pages,
1571 struct radeon_fence **fence);
1572 u32 blit_ring_index;
1573 int (*dma)(struct radeon_device *rdev,
1574 uint64_t src_offset,
1575 uint64_t dst_offset,
1576 unsigned num_gpu_pages,
1577 struct radeon_fence **fence);
1579 /* method used for bo copy */
1580 int (*copy)(struct radeon_device *rdev,
1581 uint64_t src_offset,
1582 uint64_t dst_offset,
1583 unsigned num_gpu_pages,
1584 struct radeon_fence **fence);
1585 /* ring used for bo copies */
1586 u32 copy_ring_index;
1590 int (*set_reg)(struct radeon_device *rdev, int reg,
1591 uint32_t tiling_flags, uint32_t pitch,
1592 uint32_t offset, uint32_t obj_size);
1593 void (*clear_reg)(struct radeon_device *rdev, int reg);
1595 /* hotplug detect */
1597 void (*init)(struct radeon_device *rdev);
1598 void (*fini)(struct radeon_device *rdev);
1599 bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1600 void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1602 /* static power management */
1604 void (*misc)(struct radeon_device *rdev);
1605 void (*prepare)(struct radeon_device *rdev);
1606 void (*finish)(struct radeon_device *rdev);
1607 void (*init_profile)(struct radeon_device *rdev);
1608 void (*get_dynpm_state)(struct radeon_device *rdev);
1609 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
1610 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
1611 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
1612 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
1613 int (*get_pcie_lanes)(struct radeon_device *rdev);
1614 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
1615 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
1616 int (*set_uvd_clocks)(struct radeon_device *rdev, u32 vclk, u32 dclk);
1617 int (*get_temperature)(struct radeon_device *rdev);
1619 /* dynamic power management */
1621 int (*init)(struct radeon_device *rdev);
1622 void (*setup_asic)(struct radeon_device *rdev);
1623 int (*enable)(struct radeon_device *rdev);
1624 void (*disable)(struct radeon_device *rdev);
1625 int (*pre_set_power_state)(struct radeon_device *rdev);
1626 int (*set_power_state)(struct radeon_device *rdev);
1627 void (*post_set_power_state)(struct radeon_device *rdev);
1628 void (*display_configuration_changed)(struct radeon_device *rdev);
1629 void (*fini)(struct radeon_device *rdev);
1630 u32 (*get_sclk)(struct radeon_device *rdev, bool low);
1631 u32 (*get_mclk)(struct radeon_device *rdev, bool low);
1632 void (*print_power_state)(struct radeon_device *rdev, struct radeon_ps *ps);
1636 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
1637 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
1638 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
1646 const unsigned *reg_safe_bm;
1647 unsigned reg_safe_bm_size;
1652 const unsigned *reg_safe_bm;
1653 unsigned reg_safe_bm_size;
1660 unsigned max_tile_pipes;
1662 unsigned max_backends;
1664 unsigned max_threads;
1665 unsigned max_stack_entries;
1666 unsigned max_hw_contexts;
1667 unsigned max_gs_threads;
1668 unsigned sx_max_export_size;
1669 unsigned sx_max_export_pos_size;
1670 unsigned sx_max_export_smx_size;
1671 unsigned sq_num_cf_insts;
1672 unsigned tiling_nbanks;
1673 unsigned tiling_npipes;
1674 unsigned tiling_group_size;
1675 unsigned tile_config;
1676 unsigned backend_map;
1681 unsigned max_tile_pipes;
1683 unsigned max_backends;
1685 unsigned max_threads;
1686 unsigned max_stack_entries;
1687 unsigned max_hw_contexts;
1688 unsigned max_gs_threads;
1689 unsigned sx_max_export_size;
1690 unsigned sx_max_export_pos_size;
1691 unsigned sx_max_export_smx_size;
1692 unsigned sq_num_cf_insts;
1693 unsigned sx_num_of_sets;
1694 unsigned sc_prim_fifo_size;
1695 unsigned sc_hiz_tile_fifo_size;
1696 unsigned sc_earlyz_tile_fifo_fize;
1697 unsigned tiling_nbanks;
1698 unsigned tiling_npipes;
1699 unsigned tiling_group_size;
1700 unsigned tile_config;
1701 unsigned backend_map;
1704 struct evergreen_asic {
1707 unsigned max_tile_pipes;
1709 unsigned max_backends;
1711 unsigned max_threads;
1712 unsigned max_stack_entries;
1713 unsigned max_hw_contexts;
1714 unsigned max_gs_threads;
1715 unsigned sx_max_export_size;
1716 unsigned sx_max_export_pos_size;
1717 unsigned sx_max_export_smx_size;
1718 unsigned sq_num_cf_insts;
1719 unsigned sx_num_of_sets;
1720 unsigned sc_prim_fifo_size;
1721 unsigned sc_hiz_tile_fifo_size;
1722 unsigned sc_earlyz_tile_fifo_size;
1723 unsigned tiling_nbanks;
1724 unsigned tiling_npipes;
1725 unsigned tiling_group_size;
1726 unsigned tile_config;
1727 unsigned backend_map;
1730 struct cayman_asic {
1731 unsigned max_shader_engines;
1732 unsigned max_pipes_per_simd;
1733 unsigned max_tile_pipes;
1734 unsigned max_simds_per_se;
1735 unsigned max_backends_per_se;
1736 unsigned max_texture_channel_caches;
1738 unsigned max_threads;
1739 unsigned max_gs_threads;
1740 unsigned max_stack_entries;
1741 unsigned sx_num_of_sets;
1742 unsigned sx_max_export_size;
1743 unsigned sx_max_export_pos_size;
1744 unsigned sx_max_export_smx_size;
1745 unsigned max_hw_contexts;
1746 unsigned sq_num_cf_insts;
1747 unsigned sc_prim_fifo_size;
1748 unsigned sc_hiz_tile_fifo_size;
1749 unsigned sc_earlyz_tile_fifo_size;
1751 unsigned num_shader_engines;
1752 unsigned num_shader_pipes_per_simd;
1753 unsigned num_tile_pipes;
1754 unsigned num_simds_per_se;
1755 unsigned num_backends_per_se;
1756 unsigned backend_disable_mask_per_asic;
1757 unsigned backend_map;
1758 unsigned num_texture_channel_caches;
1759 unsigned mem_max_burst_length_bytes;
1760 unsigned mem_row_size_in_kb;
1761 unsigned shader_engine_tile_size;
1763 unsigned multi_gpu_tile_size;
1765 unsigned tile_config;
1769 unsigned max_shader_engines;
1770 unsigned max_tile_pipes;
1771 unsigned max_cu_per_sh;
1772 unsigned max_sh_per_se;
1773 unsigned max_backends_per_se;
1774 unsigned max_texture_channel_caches;
1776 unsigned max_gs_threads;
1777 unsigned max_hw_contexts;
1778 unsigned sc_prim_fifo_size_frontend;
1779 unsigned sc_prim_fifo_size_backend;
1780 unsigned sc_hiz_tile_fifo_size;
1781 unsigned sc_earlyz_tile_fifo_size;
1783 unsigned num_tile_pipes;
1784 unsigned num_backends_per_se;
1785 unsigned backend_disable_mask_per_asic;
1786 unsigned backend_map;
1787 unsigned num_texture_channel_caches;
1788 unsigned mem_max_burst_length_bytes;
1789 unsigned mem_row_size_in_kb;
1790 unsigned shader_engine_tile_size;
1792 unsigned multi_gpu_tile_size;
1794 unsigned tile_config;
1795 uint32_t tile_mode_array[32];
1799 unsigned max_shader_engines;
1800 unsigned max_tile_pipes;
1801 unsigned max_cu_per_sh;
1802 unsigned max_sh_per_se;
1803 unsigned max_backends_per_se;
1804 unsigned max_texture_channel_caches;
1806 unsigned max_gs_threads;
1807 unsigned max_hw_contexts;
1808 unsigned sc_prim_fifo_size_frontend;
1809 unsigned sc_prim_fifo_size_backend;
1810 unsigned sc_hiz_tile_fifo_size;
1811 unsigned sc_earlyz_tile_fifo_size;
1813 unsigned num_tile_pipes;
1814 unsigned num_backends_per_se;
1815 unsigned backend_disable_mask_per_asic;
1816 unsigned backend_map;
1817 unsigned num_texture_channel_caches;
1818 unsigned mem_max_burst_length_bytes;
1819 unsigned mem_row_size_in_kb;
1820 unsigned shader_engine_tile_size;
1822 unsigned multi_gpu_tile_size;
1824 unsigned tile_config;
1825 uint32_t tile_mode_array[32];
1828 union radeon_asic_config {
1829 struct r300_asic r300;
1830 struct r100_asic r100;
1831 struct r600_asic r600;
1832 struct rv770_asic rv770;
1833 struct evergreen_asic evergreen;
1834 struct cayman_asic cayman;
1836 struct cik_asic cik;
1840 * asic initizalization from radeon_asic.c
1842 void radeon_agp_disable(struct radeon_device *rdev);
1843 int radeon_asic_init(struct radeon_device *rdev);
1849 int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
1850 struct drm_file *filp);
1851 int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
1852 struct drm_file *filp);
1853 int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
1854 struct drm_file *file_priv);
1855 int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
1856 struct drm_file *file_priv);
1857 int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1858 struct drm_file *file_priv);
1859 int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
1860 struct drm_file *file_priv);
1861 int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1862 struct drm_file *filp);
1863 int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
1864 struct drm_file *filp);
1865 int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
1866 struct drm_file *filp);
1867 int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1868 struct drm_file *filp);
1869 int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
1870 struct drm_file *filp);
1871 int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1872 int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1873 struct drm_file *filp);
1874 int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1875 struct drm_file *filp);
1877 /* VRAM scratch page for HDP bug, default vram page */
1878 struct r600_vram_scratch {
1879 struct radeon_bo *robj;
1880 volatile uint32_t *ptr;
1887 struct radeon_atif_notification_cfg {
1892 struct radeon_atif_notifications {
1893 bool display_switch;
1894 bool expansion_mode_change;
1896 bool forced_power_state;
1897 bool system_power_state;
1898 bool display_conf_change;
1900 bool brightness_change;
1901 bool dgpu_display_event;
1904 struct radeon_atif_functions {
1906 bool sbios_requests;
1907 bool select_active_disp;
1909 bool get_tv_standard;
1910 bool set_tv_standard;
1911 bool get_panel_expansion_mode;
1912 bool set_panel_expansion_mode;
1913 bool temperature_change;
1914 bool graphics_device_types;
1917 struct radeon_atif {
1918 struct radeon_atif_notifications notifications;
1919 struct radeon_atif_functions functions;
1920 struct radeon_atif_notification_cfg notification_cfg;
1921 struct radeon_encoder *encoder_for_bl;
1924 struct radeon_atcs_functions {
1928 bool pcie_bus_width;
1931 struct radeon_atcs {
1932 struct radeon_atcs_functions functions;
1936 * Core structure, functions and helpers.
1938 typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1939 typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1941 struct radeon_device {
1943 struct drm_device *ddev;
1944 struct pci_dev *pdev;
1945 struct rw_semaphore exclusive_lock;
1947 union radeon_asic_config config;
1948 enum radeon_family family;
1949 unsigned long flags;
1951 enum radeon_pll_errata pll_errata;
1958 uint16_t bios_header_start;
1959 struct radeon_bo *stollen_vga_memory;
1961 resource_size_t rmmio_base;
1962 resource_size_t rmmio_size;
1963 /* protects concurrent MM_INDEX/DATA based register access */
1964 spinlock_t mmio_idx_lock;
1965 void __iomem *rmmio;
1966 radeon_rreg_t mc_rreg;
1967 radeon_wreg_t mc_wreg;
1968 radeon_rreg_t pll_rreg;
1969 radeon_wreg_t pll_wreg;
1970 uint32_t pcie_reg_mask;
1971 radeon_rreg_t pciep_rreg;
1972 radeon_wreg_t pciep_wreg;
1974 void __iomem *rio_mem;
1975 resource_size_t rio_mem_size;
1976 struct radeon_clock clock;
1977 struct radeon_mc mc;
1978 struct radeon_gart gart;
1979 struct radeon_mode_info mode_info;
1980 struct radeon_scratch scratch;
1981 struct radeon_doorbell doorbell;
1982 struct radeon_mman mman;
1983 struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
1984 wait_queue_head_t fence_queue;
1985 struct mutex ring_lock;
1986 struct radeon_ring ring[RADEON_NUM_RINGS];
1988 struct radeon_sa_manager ring_tmp_bo;
1989 struct radeon_irq irq;
1990 struct radeon_asic *asic;
1991 struct radeon_gem gem;
1992 struct radeon_pm pm;
1993 struct radeon_uvd uvd;
1994 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1995 struct radeon_wb wb;
1996 struct radeon_dummy_page dummy_page;
2001 bool fastfb_working; /* IGP feature*/
2002 struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
2003 const struct firmware *me_fw; /* all family ME firmware */
2004 const struct firmware *pfp_fw; /* r6/700 PFP firmware */
2005 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
2006 const struct firmware *mc_fw; /* NI MC firmware */
2007 const struct firmware *ce_fw; /* SI CE firmware */
2008 const struct firmware *uvd_fw; /* UVD firmware */
2009 const struct firmware *mec_fw; /* CIK MEC firmware */
2010 const struct firmware *sdma_fw; /* CIK SDMA firmware */
2011 const struct firmware *smc_fw; /* SMC firmware */
2012 struct r600_blit r600_blit;
2013 struct r600_vram_scratch vram_scratch;
2014 int msi_enabled; /* msi enabled */
2015 struct r600_ih ih; /* r6/700 interrupt ring */
2016 struct radeon_rlc rlc;
2017 struct radeon_mec mec;
2018 struct work_struct hotplug_work;
2019 struct work_struct audio_work;
2020 struct work_struct reset_work;
2021 int num_crtc; /* number of crtcs */
2022 struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
2025 struct r600_audio audio_status; /* audio stuff */
2026 struct notifier_block acpi_nb;
2027 /* only one userspace can use Hyperz features or CMASK at a time */
2028 struct drm_file *hyperz_filp;
2029 struct drm_file *cmask_filp;
2031 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
2033 struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
2034 unsigned debugfs_count;
2035 /* virtual memory */
2036 struct radeon_vm_manager vm_manager;
2037 struct mutex gpu_clock_mutex;
2038 /* ACPI interface */
2039 struct radeon_atif atif;
2040 struct radeon_atcs atcs;
2043 int radeon_device_init(struct radeon_device *rdev,
2044 struct drm_device *ddev,
2045 struct pci_dev *pdev,
2047 void radeon_device_fini(struct radeon_device *rdev);
2048 int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
2050 uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
2051 bool always_indirect);
2052 void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
2053 bool always_indirect);
2054 u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
2055 void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
2057 u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset);
2058 void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v);
2063 #define to_radeon_fence(p) ((struct radeon_fence *)(p))
2066 * Registers read & write functions.
2068 #define RREG8(reg) readb((rdev->rmmio) + (reg))
2069 #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
2070 #define RREG16(reg) readw((rdev->rmmio) + (reg))
2071 #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
2072 #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
2073 #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
2074 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
2075 #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
2076 #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
2077 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2078 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2079 #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
2080 #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
2081 #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
2082 #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
2083 #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
2084 #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
2085 #define RREG32_PCIE_PORT(reg) rdev->pciep_rreg(rdev, (reg))
2086 #define WREG32_PCIE_PORT(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
2087 #define RREG32_SMC(reg) tn_smc_rreg(rdev, (reg))
2088 #define WREG32_SMC(reg, v) tn_smc_wreg(rdev, (reg), (v))
2089 #define RREG32_RCU(reg) r600_rcu_rreg(rdev, (reg))
2090 #define WREG32_RCU(reg, v) r600_rcu_wreg(rdev, (reg), (v))
2091 #define RREG32_CG(reg) eg_cg_rreg(rdev, (reg))
2092 #define WREG32_CG(reg, v) eg_cg_wreg(rdev, (reg), (v))
2093 #define RREG32_PIF_PHY0(reg) eg_pif_phy0_rreg(rdev, (reg))
2094 #define WREG32_PIF_PHY0(reg, v) eg_pif_phy0_wreg(rdev, (reg), (v))
2095 #define RREG32_PIF_PHY1(reg) eg_pif_phy1_rreg(rdev, (reg))
2096 #define WREG32_PIF_PHY1(reg, v) eg_pif_phy1_wreg(rdev, (reg), (v))
2097 #define RREG32_UVD_CTX(reg) r600_uvd_ctx_rreg(rdev, (reg))
2098 #define WREG32_UVD_CTX(reg, v) r600_uvd_ctx_wreg(rdev, (reg), (v))
2099 #define WREG32_P(reg, val, mask) \
2101 uint32_t tmp_ = RREG32(reg); \
2103 tmp_ |= ((val) & ~(mask)); \
2104 WREG32(reg, tmp_); \
2106 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2107 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~or)
2108 #define WREG32_PLL_P(reg, val, mask) \
2110 uint32_t tmp_ = RREG32_PLL(reg); \
2112 tmp_ |= ((val) & ~(mask)); \
2113 WREG32_PLL(reg, tmp_); \
2115 #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
2116 #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
2117 #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
2119 #define RDOORBELL32(offset) cik_mm_rdoorbell(rdev, (offset))
2120 #define WDOORBELL32(offset, v) cik_mm_wdoorbell(rdev, (offset), (v))
2123 * Indirect registers accessor
2125 static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
2129 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
2130 r = RREG32(RADEON_PCIE_DATA);
2134 static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
2136 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
2137 WREG32(RADEON_PCIE_DATA, (v));
2140 static inline u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg)
2144 WREG32(TN_SMC_IND_INDEX_0, (reg));
2145 r = RREG32(TN_SMC_IND_DATA_0);
2149 static inline void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2151 WREG32(TN_SMC_IND_INDEX_0, (reg));
2152 WREG32(TN_SMC_IND_DATA_0, (v));
2155 static inline u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
2159 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
2160 r = RREG32(R600_RCU_DATA);
2164 static inline void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2166 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
2167 WREG32(R600_RCU_DATA, (v));
2170 static inline u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
2174 WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
2175 r = RREG32(EVERGREEN_CG_IND_DATA);
2179 static inline void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2181 WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
2182 WREG32(EVERGREEN_CG_IND_DATA, (v));
2185 static inline u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
2189 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
2190 r = RREG32(EVERGREEN_PIF_PHY0_DATA);
2194 static inline void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2196 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
2197 WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
2200 static inline u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
2204 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
2205 r = RREG32(EVERGREEN_PIF_PHY1_DATA);
2209 static inline void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2211 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
2212 WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
2215 static inline u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
2219 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
2220 r = RREG32(R600_UVD_CTX_DATA);
2224 static inline void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2226 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
2227 WREG32(R600_UVD_CTX_DATA, (v));
2230 void r100_pll_errata_after_index(struct radeon_device *rdev);
2236 #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
2237 (rdev->pdev->device == 0x5969))
2238 #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
2239 (rdev->family == CHIP_RV200) || \
2240 (rdev->family == CHIP_RS100) || \
2241 (rdev->family == CHIP_RS200) || \
2242 (rdev->family == CHIP_RV250) || \
2243 (rdev->family == CHIP_RV280) || \
2244 (rdev->family == CHIP_RS300))
2245 #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
2246 (rdev->family == CHIP_RV350) || \
2247 (rdev->family == CHIP_R350) || \
2248 (rdev->family == CHIP_RV380) || \
2249 (rdev->family == CHIP_R420) || \
2250 (rdev->family == CHIP_R423) || \
2251 (rdev->family == CHIP_RV410) || \
2252 (rdev->family == CHIP_RS400) || \
2253 (rdev->family == CHIP_RS480))
2254 #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
2255 (rdev->ddev->pdev->device == 0x9443) || \
2256 (rdev->ddev->pdev->device == 0x944B) || \
2257 (rdev->ddev->pdev->device == 0x9506) || \
2258 (rdev->ddev->pdev->device == 0x9509) || \
2259 (rdev->ddev->pdev->device == 0x950F) || \
2260 (rdev->ddev->pdev->device == 0x689C) || \
2261 (rdev->ddev->pdev->device == 0x689D))
2262 #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
2263 #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
2264 (rdev->family == CHIP_RS690) || \
2265 (rdev->family == CHIP_RS740) || \
2266 (rdev->family >= CHIP_R600))
2267 #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
2268 #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
2269 #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
2270 #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
2271 (rdev->flags & RADEON_IS_IGP))
2272 #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
2273 #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
2274 #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
2275 (rdev->flags & RADEON_IS_IGP))
2276 #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
2277 #define ASIC_IS_NODCE(rdev) ((rdev->family == CHIP_HAINAN))
2278 #define ASIC_IS_DCE8(rdev) ((rdev->family >= CHIP_BONAIRE))
2280 #define ASIC_IS_LOMBOK(rdev) ((rdev->ddev->pdev->device == 0x6849) || \
2281 (rdev->ddev->pdev->device == 0x6850) || \
2282 (rdev->ddev->pdev->device == 0x6858) || \
2283 (rdev->ddev->pdev->device == 0x6859) || \
2284 (rdev->ddev->pdev->device == 0x6840) || \
2285 (rdev->ddev->pdev->device == 0x6841) || \
2286 (rdev->ddev->pdev->device == 0x6842) || \
2287 (rdev->ddev->pdev->device == 0x6843))
2292 #define RBIOS8(i) (rdev->bios[i])
2293 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2294 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2296 int radeon_combios_init(struct radeon_device *rdev);
2297 void radeon_combios_fini(struct radeon_device *rdev);
2298 int radeon_atombios_init(struct radeon_device *rdev);
2299 void radeon_atombios_fini(struct radeon_device *rdev);
2305 #if DRM_DEBUG_CODE == 0
2306 static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
2308 ring->ring[ring->wptr++] = v;
2309 ring->wptr &= ring->ptr_mask;
2311 ring->ring_free_dw--;
2314 /* With debugging this is just too big to inline */
2315 void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
2321 #define radeon_init(rdev) (rdev)->asic->init((rdev))
2322 #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
2323 #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
2324 #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
2325 #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
2326 #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
2327 #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
2328 #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
2329 #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
2330 #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
2331 #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
2332 #define radeon_asic_vm_set_page(rdev, ib, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (ib), (pe), (addr), (count), (incr), (flags)))
2333 #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
2334 #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
2335 #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
2336 #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
2337 #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
2338 #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
2339 #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)].vm_flush((rdev), (r), (vm))
2340 #define radeon_ring_get_rptr(rdev, r) (rdev)->asic->ring[(r)->idx].get_rptr((rdev), (r))
2341 #define radeon_ring_get_wptr(rdev, r) (rdev)->asic->ring[(r)->idx].get_wptr((rdev), (r))
2342 #define radeon_ring_set_wptr(rdev, r) (rdev)->asic->ring[(r)->idx].set_wptr((rdev), (r))
2343 #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
2344 #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
2345 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
2346 #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
2347 #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
2348 #define radeon_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
2349 #define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
2350 #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
2351 #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
2352 #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
2353 #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
2354 #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
2355 #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
2356 #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
2357 #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
2358 #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
2359 #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
2360 #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
2361 #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
2362 #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
2363 #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
2364 #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
2365 #define radeon_set_uvd_clocks(rdev, v, d) (rdev)->asic->pm.set_uvd_clocks((rdev), (v), (d))
2366 #define radeon_get_temperature(rdev) (rdev)->asic->pm.get_temperature((rdev))
2367 #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
2368 #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
2369 #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
2370 #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
2371 #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
2372 #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
2373 #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
2374 #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
2375 #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
2376 #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
2377 #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
2378 #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
2379 #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
2380 #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
2381 #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
2382 #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
2383 #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
2384 #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
2385 #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
2386 #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
2387 #define radeon_dpm_init(rdev) rdev->asic->dpm.init((rdev))
2388 #define radeon_dpm_setup_asic(rdev) rdev->asic->dpm.setup_asic((rdev))
2389 #define radeon_dpm_enable(rdev) rdev->asic->dpm.enable((rdev))
2390 #define radeon_dpm_disable(rdev) rdev->asic->dpm.disable((rdev))
2391 #define radeon_dpm_pre_set_power_state(rdev) rdev->asic->dpm.pre_set_power_state((rdev))
2392 #define radeon_dpm_set_power_state(rdev) rdev->asic->dpm.set_power_state((rdev))
2393 #define radeon_dpm_post_set_power_state(rdev) rdev->asic->dpm.post_set_power_state((rdev))
2394 #define radeon_dpm_display_configuration_changed(rdev) rdev->asic->dpm.display_configuration_changed((rdev))
2395 #define radeon_dpm_fini(rdev) rdev->asic->dpm.fini((rdev))
2396 #define radeon_dpm_get_sclk(rdev, l) rdev->asic->dpm.get_sclk((rdev), (l))
2397 #define radeon_dpm_get_mclk(rdev, l) rdev->asic->dpm.get_mclk((rdev), (l))
2398 #define radeon_dpm_print_power_state(rdev, ps) rdev->asic->dpm.print_power_state((rdev), (ps))
2400 /* Common functions */
2402 extern int radeon_gpu_reset(struct radeon_device *rdev);
2403 extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
2404 extern void radeon_agp_disable(struct radeon_device *rdev);
2405 extern int radeon_modeset_init(struct radeon_device *rdev);
2406 extern void radeon_modeset_fini(struct radeon_device *rdev);
2407 extern bool radeon_card_posted(struct radeon_device *rdev);
2408 extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
2409 extern void radeon_update_display_priority(struct radeon_device *rdev);
2410 extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
2411 extern void radeon_scratch_init(struct radeon_device *rdev);
2412 extern void radeon_wb_fini(struct radeon_device *rdev);
2413 extern int radeon_wb_init(struct radeon_device *rdev);
2414 extern void radeon_wb_disable(struct radeon_device *rdev);
2415 extern void radeon_surface_init(struct radeon_device *rdev);
2416 extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
2417 extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
2418 extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
2419 extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
2420 extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
2421 extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
2422 extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
2423 extern int radeon_resume_kms(struct drm_device *dev);
2424 extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
2425 extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
2426 extern void radeon_program_register_sequence(struct radeon_device *rdev,
2427 const u32 *registers,
2428 const u32 array_size);
2433 int radeon_vm_manager_init(struct radeon_device *rdev);
2434 void radeon_vm_manager_fini(struct radeon_device *rdev);
2435 void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
2436 void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
2437 int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
2438 void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
2439 struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
2440 struct radeon_vm *vm, int ring);
2441 void radeon_vm_fence(struct radeon_device *rdev,
2442 struct radeon_vm *vm,
2443 struct radeon_fence *fence);
2444 uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
2445 int radeon_vm_bo_update_pte(struct radeon_device *rdev,
2446 struct radeon_vm *vm,
2447 struct radeon_bo *bo,
2448 struct ttm_mem_reg *mem);
2449 void radeon_vm_bo_invalidate(struct radeon_device *rdev,
2450 struct radeon_bo *bo);
2451 struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
2452 struct radeon_bo *bo);
2453 struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
2454 struct radeon_vm *vm,
2455 struct radeon_bo *bo);
2456 int radeon_vm_bo_set_addr(struct radeon_device *rdev,
2457 struct radeon_bo_va *bo_va,
2460 int radeon_vm_bo_rmv(struct radeon_device *rdev,
2461 struct radeon_bo_va *bo_va);
2464 void r600_audio_update_hdmi(struct work_struct *work);
2467 * R600 vram scratch functions
2469 int r600_vram_scratch_init(struct radeon_device *rdev);
2470 void r600_vram_scratch_fini(struct radeon_device *rdev);
2473 * r600 cs checking helper
2475 unsigned r600_mip_minify(unsigned size, unsigned level);
2476 bool r600_fmt_is_valid_color(u32 format);
2477 bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
2478 int r600_fmt_get_blocksize(u32 format);
2479 int r600_fmt_get_nblocksx(u32 format, u32 w);
2480 int r600_fmt_get_nblocksy(u32 format, u32 h);
2483 * r600 functions used by radeon_encoder.c
2485 struct radeon_hdmi_acr {
2499 extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
2501 extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
2502 u32 tiling_pipe_num,
2504 u32 total_max_rb_num,
2505 u32 enabled_rb_mask);
2508 * evergreen functions used by radeon_encoder.c
2511 extern int ni_init_microcode(struct radeon_device *rdev);
2512 extern int ni_mc_load_microcode(struct radeon_device *rdev);
2515 #if defined(CONFIG_ACPI)
2516 extern int radeon_acpi_init(struct radeon_device *rdev);
2517 extern void radeon_acpi_fini(struct radeon_device *rdev);
2518 extern bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev);
2519 extern int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
2520 u8 perf_req, bool advertise);
2521 extern int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev);
2523 static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
2524 static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
2527 int radeon_cs_packet_parse(struct radeon_cs_parser *p,
2528 struct radeon_cs_packet *pkt,
2530 bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
2531 void radeon_cs_dump_packet(struct radeon_cs_parser *p,
2532 struct radeon_cs_packet *pkt);
2533 int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
2534 struct radeon_cs_reloc **cs_reloc,
2536 int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
2537 uint32_t *vline_start_end,
2538 uint32_t *vline_status);
2540 #include "radeon_object.h"