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;
100 extern int radeon_aspm;
103 * Copy from radeon_drv.h so we don't have to include both and have conflicting
106 #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
107 #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
108 /* RADEON_IB_POOL_SIZE must be a power of 2 */
109 #define RADEON_IB_POOL_SIZE 16
110 #define RADEON_DEBUGFS_MAX_COMPONENTS 32
111 #define RADEONFB_CONN_LIMIT 4
112 #define RADEON_BIOS_NUM_SCRATCH 8
114 /* max number of rings */
115 #define RADEON_NUM_RINGS 6
117 /* fence seq are set to this number when signaled */
118 #define RADEON_FENCE_SIGNALED_SEQ 0LL
120 /* internal ring indices */
121 /* r1xx+ has gfx CP ring */
122 #define RADEON_RING_TYPE_GFX_INDEX 0
124 /* cayman has 2 compute CP rings */
125 #define CAYMAN_RING_TYPE_CP1_INDEX 1
126 #define CAYMAN_RING_TYPE_CP2_INDEX 2
128 /* R600+ has an async dma ring */
129 #define R600_RING_TYPE_DMA_INDEX 3
130 /* cayman add a second async dma ring */
131 #define CAYMAN_RING_TYPE_DMA1_INDEX 4
134 #define R600_RING_TYPE_UVD_INDEX 5
136 /* hardcode those limit for now */
137 #define RADEON_VA_IB_OFFSET (1 << 20)
138 #define RADEON_VA_RESERVED_SIZE (8 << 20)
139 #define RADEON_IB_VM_MAX_SIZE (64 << 10)
142 #define RADEON_RESET_GFX (1 << 0)
143 #define RADEON_RESET_COMPUTE (1 << 1)
144 #define RADEON_RESET_DMA (1 << 2)
145 #define RADEON_RESET_CP (1 << 3)
146 #define RADEON_RESET_GRBM (1 << 4)
147 #define RADEON_RESET_DMA1 (1 << 5)
148 #define RADEON_RESET_RLC (1 << 6)
149 #define RADEON_RESET_SEM (1 << 7)
150 #define RADEON_RESET_IH (1 << 8)
151 #define RADEON_RESET_VMC (1 << 9)
152 #define RADEON_RESET_MC (1 << 10)
153 #define RADEON_RESET_DISPLAY (1 << 11)
156 #define RADEON_CG_BLOCK_GFX (1 << 0)
157 #define RADEON_CG_BLOCK_MC (1 << 1)
158 #define RADEON_CG_BLOCK_SDMA (1 << 2)
159 #define RADEON_CG_BLOCK_UVD (1 << 3)
160 #define RADEON_CG_BLOCK_VCE (1 << 4)
161 #define RADEON_CG_BLOCK_HDP (1 << 5)
163 /* max cursor sizes (in pixels) */
164 #define CURSOR_WIDTH 64
165 #define CURSOR_HEIGHT 64
167 #define CIK_CURSOR_WIDTH 128
168 #define CIK_CURSOR_HEIGHT 128
171 * Errata workarounds.
173 enum radeon_pll_errata {
174 CHIP_ERRATA_R300_CG = 0x00000001,
175 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
176 CHIP_ERRATA_PLL_DELAY = 0x00000004
180 struct radeon_device;
186 bool radeon_get_bios(struct radeon_device *rdev);
191 struct radeon_dummy_page {
195 int radeon_dummy_page_init(struct radeon_device *rdev);
196 void radeon_dummy_page_fini(struct radeon_device *rdev);
202 struct radeon_clock {
203 struct radeon_pll p1pll;
204 struct radeon_pll p2pll;
205 struct radeon_pll dcpll;
206 struct radeon_pll spll;
207 struct radeon_pll mpll;
209 uint32_t default_mclk;
210 uint32_t default_sclk;
211 uint32_t default_dispclk;
212 uint32_t current_dispclk;
214 uint32_t max_pixel_clock;
220 int radeon_pm_init(struct radeon_device *rdev);
221 void radeon_pm_fini(struct radeon_device *rdev);
222 void radeon_pm_compute_clocks(struct radeon_device *rdev);
223 void radeon_pm_suspend(struct radeon_device *rdev);
224 void radeon_pm_resume(struct radeon_device *rdev);
225 void radeon_combios_get_power_modes(struct radeon_device *rdev);
226 void radeon_atombios_get_power_modes(struct radeon_device *rdev);
227 int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
231 struct atom_clock_dividers *dividers);
232 int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
235 struct atom_mpll_param *mpll_param);
236 void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
237 int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
238 u16 voltage_level, u8 voltage_type,
239 u32 *gpio_value, u32 *gpio_mask);
240 void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
241 u32 eng_clock, u32 mem_clock);
242 int radeon_atom_get_voltage_step(struct radeon_device *rdev,
243 u8 voltage_type, u16 *voltage_step);
244 int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
245 u16 voltage_id, u16 *voltage);
246 int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
249 int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
251 int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
252 u16 *vddc, u16 *vddci,
253 u16 virtual_voltage_id,
254 u16 vbios_voltage_id);
255 int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
259 int radeon_atom_get_min_voltage(struct radeon_device *rdev,
260 u8 voltage_type, u16 *min_voltage);
261 int radeon_atom_get_max_voltage(struct radeon_device *rdev,
262 u8 voltage_type, u16 *max_voltage);
263 int radeon_atom_get_voltage_table(struct radeon_device *rdev,
264 u8 voltage_type, u8 voltage_mode,
265 struct atom_voltage_table *voltage_table);
266 bool radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
267 u8 voltage_type, u8 voltage_mode);
268 void radeon_atom_update_memory_dll(struct radeon_device *rdev,
270 void radeon_atom_set_ac_timing(struct radeon_device *rdev,
272 int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
274 struct atom_mc_reg_table *reg_table);
275 int radeon_atom_get_memory_info(struct radeon_device *rdev,
276 u8 module_index, struct atom_memory_info *mem_info);
277 int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
278 bool gddr5, u8 module_index,
279 struct atom_memory_clock_range_table *mclk_range_table);
280 int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
281 u16 voltage_id, u16 *voltage);
282 void rs690_pm_info(struct radeon_device *rdev);
283 extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
284 unsigned *bankh, unsigned *mtaspect,
285 unsigned *tile_split);
290 struct radeon_fence_driver {
291 uint32_t scratch_reg;
293 volatile uint32_t *cpu_addr;
294 /* sync_seq is protected by ring emission lock */
295 uint64_t sync_seq[RADEON_NUM_RINGS];
297 unsigned long last_activity;
301 struct radeon_fence {
302 struct radeon_device *rdev;
304 /* protected by radeon_fence.lock */
310 int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
311 int radeon_fence_driver_init(struct radeon_device *rdev);
312 void radeon_fence_driver_fini(struct radeon_device *rdev);
313 void radeon_fence_driver_force_completion(struct radeon_device *rdev);
314 int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
315 void radeon_fence_process(struct radeon_device *rdev, int ring);
316 bool radeon_fence_signaled(struct radeon_fence *fence);
317 int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
318 int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
319 int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
320 int radeon_fence_wait_any(struct radeon_device *rdev,
321 struct radeon_fence **fences,
323 struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
324 void radeon_fence_unref(struct radeon_fence **fence);
325 unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
326 bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
327 void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
328 static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
329 struct radeon_fence *b)
339 BUG_ON(a->ring != b->ring);
341 if (a->seq > b->seq) {
348 static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
349 struct radeon_fence *b)
359 BUG_ON(a->ring != b->ring);
361 return a->seq < b->seq;
367 struct radeon_surface_reg {
368 struct radeon_bo *bo;
371 #define RADEON_GEM_MAX_SURFACES 8
377 struct ttm_bo_global_ref bo_global_ref;
378 struct drm_global_reference mem_global_ref;
379 struct ttm_bo_device bdev;
380 bool mem_global_referenced;
384 /* bo virtual address in a specific vm */
385 struct radeon_bo_va {
386 /* protected by bo being reserved */
387 struct list_head bo_list;
394 /* protected by vm mutex */
395 struct list_head vm_list;
397 /* constant after initialization */
398 struct radeon_vm *vm;
399 struct radeon_bo *bo;
403 /* Protected by gem.mutex */
404 struct list_head list;
405 /* Protected by tbo.reserved */
407 struct ttm_placement placement;
408 struct ttm_buffer_object tbo;
409 struct ttm_bo_kmap_obj kmap;
415 /* list of all virtual address to which this bo
419 /* Constant after initialization */
420 struct radeon_device *rdev;
421 struct drm_gem_object gem_base;
423 struct ttm_bo_kmap_obj dma_buf_vmap;
426 #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
428 struct radeon_bo_list {
429 struct ttm_validate_buffer tv;
430 struct radeon_bo *bo;
438 int radeon_gem_debugfs_init(struct radeon_device *rdev);
440 /* sub-allocation manager, it has to be protected by another lock.
441 * By conception this is an helper for other part of the driver
442 * like the indirect buffer or semaphore, which both have their
445 * Principe is simple, we keep a list of sub allocation in offset
446 * order (first entry has offset == 0, last entry has the highest
449 * When allocating new object we first check if there is room at
450 * the end total_size - (last_object_offset + last_object_size) >=
451 * alloc_size. If so we allocate new object there.
453 * When there is not enough room at the end, we start waiting for
454 * each sub object until we reach object_offset+object_size >=
455 * alloc_size, this object then become the sub object we return.
457 * Alignment can't be bigger than page size.
459 * Hole are not considered for allocation to keep things simple.
460 * Assumption is that there won't be hole (all object on same
463 struct radeon_sa_manager {
464 wait_queue_head_t wq;
465 struct radeon_bo *bo;
466 struct list_head *hole;
467 struct list_head flist[RADEON_NUM_RINGS];
468 struct list_head olist;
478 /* sub-allocation buffer */
479 struct radeon_sa_bo {
480 struct list_head olist;
481 struct list_head flist;
482 struct radeon_sa_manager *manager;
485 struct radeon_fence *fence;
493 struct list_head objects;
496 int radeon_gem_init(struct radeon_device *rdev);
497 void radeon_gem_fini(struct radeon_device *rdev);
498 int radeon_gem_object_create(struct radeon_device *rdev, int size,
499 int alignment, int initial_domain,
500 bool discardable, bool kernel,
501 struct drm_gem_object **obj);
503 int radeon_mode_dumb_create(struct drm_file *file_priv,
504 struct drm_device *dev,
505 struct drm_mode_create_dumb *args);
506 int radeon_mode_dumb_mmap(struct drm_file *filp,
507 struct drm_device *dev,
508 uint32_t handle, uint64_t *offset_p);
509 int radeon_mode_dumb_destroy(struct drm_file *file_priv,
510 struct drm_device *dev,
516 /* everything here is constant */
517 struct radeon_semaphore {
518 struct radeon_sa_bo *sa_bo;
523 int radeon_semaphore_create(struct radeon_device *rdev,
524 struct radeon_semaphore **semaphore);
525 void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
526 struct radeon_semaphore *semaphore);
527 void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
528 struct radeon_semaphore *semaphore);
529 int radeon_semaphore_sync_rings(struct radeon_device *rdev,
530 struct radeon_semaphore *semaphore,
531 int signaler, int waiter);
532 void radeon_semaphore_free(struct radeon_device *rdev,
533 struct radeon_semaphore **semaphore,
534 struct radeon_fence *fence);
537 * GART structures, functions & helpers
541 #define RADEON_GPU_PAGE_SIZE 4096
542 #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
543 #define RADEON_GPU_PAGE_SHIFT 12
544 #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
547 dma_addr_t table_addr;
548 struct radeon_bo *robj;
550 unsigned num_gpu_pages;
551 unsigned num_cpu_pages;
554 dma_addr_t *pages_addr;
558 int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
559 void radeon_gart_table_ram_free(struct radeon_device *rdev);
560 int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
561 void radeon_gart_table_vram_free(struct radeon_device *rdev);
562 int radeon_gart_table_vram_pin(struct radeon_device *rdev);
563 void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
564 int radeon_gart_init(struct radeon_device *rdev);
565 void radeon_gart_fini(struct radeon_device *rdev);
566 void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
568 int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
569 int pages, struct page **pagelist,
570 dma_addr_t *dma_addr);
571 void radeon_gart_restore(struct radeon_device *rdev);
575 * GPU MC structures, functions & helpers
578 resource_size_t aper_size;
579 resource_size_t aper_base;
580 resource_size_t agp_base;
581 /* for some chips with <= 32MB we need to lie
582 * about vram size near mc fb location */
584 u64 visible_vram_size;
594 bool igp_sideport_enabled;
599 bool radeon_combios_sideport_present(struct radeon_device *rdev);
600 bool radeon_atombios_sideport_present(struct radeon_device *rdev);
603 * GPU scratch registers structures, functions & helpers
605 struct radeon_scratch {
612 int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
613 void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
616 * GPU doorbell structures, functions & helpers
618 struct radeon_doorbell {
622 resource_size_t base;
623 resource_size_t size;
627 int radeon_doorbell_get(struct radeon_device *rdev, u32 *page);
628 void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell);
634 struct radeon_unpin_work {
635 struct work_struct work;
636 struct radeon_device *rdev;
638 struct radeon_fence *fence;
639 struct drm_pending_vblank_event *event;
640 struct radeon_bo *old_rbo;
644 struct r500_irq_stat_regs {
649 struct r600_irq_stat_regs {
659 struct evergreen_irq_stat_regs {
680 struct cik_irq_stat_regs {
690 union radeon_irq_stat_regs {
691 struct r500_irq_stat_regs r500;
692 struct r600_irq_stat_regs r600;
693 struct evergreen_irq_stat_regs evergreen;
694 struct cik_irq_stat_regs cik;
697 #define RADEON_MAX_HPD_PINS 6
698 #define RADEON_MAX_CRTCS 6
699 #define RADEON_MAX_AFMT_BLOCKS 6
704 atomic_t ring_int[RADEON_NUM_RINGS];
705 bool crtc_vblank_int[RADEON_MAX_CRTCS];
706 atomic_t pflip[RADEON_MAX_CRTCS];
707 wait_queue_head_t vblank_queue;
708 bool hpd[RADEON_MAX_HPD_PINS];
709 bool afmt[RADEON_MAX_AFMT_BLOCKS];
710 union radeon_irq_stat_regs stat_regs;
714 int radeon_irq_kms_init(struct radeon_device *rdev);
715 void radeon_irq_kms_fini(struct radeon_device *rdev);
716 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
717 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
718 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
719 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
720 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
721 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
722 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
723 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
730 struct radeon_sa_bo *sa_bo;
735 struct radeon_fence *fence;
736 struct radeon_vm *vm;
738 struct radeon_fence *sync_to[RADEON_NUM_RINGS];
739 struct radeon_semaphore *semaphore;
743 struct radeon_bo *ring_obj;
744 volatile uint32_t *ring;
748 unsigned rptr_save_reg;
749 u64 next_rptr_gpu_addr;
750 volatile u32 *next_rptr_cpu_addr;
755 unsigned ring_free_dw;
757 unsigned long last_activity;
765 u64 last_semaphore_signal_addr;
766 u64 last_semaphore_wait_addr;
771 struct radeon_bo *mqd_obj;
772 u32 doorbell_page_num;
778 struct radeon_bo *hpd_eop_obj;
779 u64 hpd_eop_gpu_addr;
789 /* maximum number of VMIDs */
790 #define RADEON_NUM_VM 16
792 /* defines number of bits in page table versus page directory,
793 * a page is 4KB so we have 12 bits offset, 9 bits in the page
794 * table and the remaining 19 bits are in the page directory */
795 #define RADEON_VM_BLOCK_SIZE 9
797 /* number of entries in page table */
798 #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
800 /* PTBs (Page Table Blocks) need to be aligned to 32K */
801 #define RADEON_VM_PTB_ALIGN_SIZE 32768
802 #define RADEON_VM_PTB_ALIGN_MASK (RADEON_VM_PTB_ALIGN_SIZE - 1)
803 #define RADEON_VM_PTB_ALIGN(a) (((a) + RADEON_VM_PTB_ALIGN_MASK) & ~RADEON_VM_PTB_ALIGN_MASK)
806 struct list_head list;
810 /* contains the page directory */
811 struct radeon_sa_bo *page_directory;
812 uint64_t pd_gpu_addr;
814 /* array of page tables, one for each page directory entry */
815 struct radeon_sa_bo **page_tables;
818 /* last fence for cs using this vm */
819 struct radeon_fence *fence;
820 /* last flush or NULL if we still need to flush */
821 struct radeon_fence *last_flush;
824 struct radeon_vm_manager {
826 struct list_head lru_vm;
827 struct radeon_fence *active[RADEON_NUM_VM];
828 struct radeon_sa_manager sa_manager;
830 /* number of VMIDs */
832 /* vram base address for page table entry */
833 u64 vram_base_offset;
839 * file private structure
841 struct radeon_fpriv {
849 struct radeon_bo *ring_obj;
850 volatile uint32_t *ring;
862 #include "clearstate_defs.h"
865 /* for power gating */
866 struct radeon_bo *save_restore_obj;
867 uint64_t save_restore_gpu_addr;
868 volatile uint32_t *sr_ptr;
871 /* for clear state */
872 struct radeon_bo *clear_state_obj;
873 uint64_t clear_state_gpu_addr;
874 volatile uint32_t *cs_ptr;
875 const struct cs_section_def *cs_data;
876 u32 clear_state_size;
878 struct radeon_bo *cp_table_obj;
879 uint64_t cp_table_gpu_addr;
880 volatile uint32_t *cp_table_ptr;
884 int radeon_ib_get(struct radeon_device *rdev, int ring,
885 struct radeon_ib *ib, struct radeon_vm *vm,
887 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
888 void radeon_ib_sync_to(struct radeon_ib *ib, struct radeon_fence *fence);
889 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
890 struct radeon_ib *const_ib);
891 int radeon_ib_pool_init(struct radeon_device *rdev);
892 void radeon_ib_pool_fini(struct radeon_device *rdev);
893 int radeon_ib_ring_tests(struct radeon_device *rdev);
894 /* Ring access between begin & end cannot sleep */
895 bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
896 struct radeon_ring *ring);
897 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
898 int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
899 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
900 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
901 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
902 void radeon_ring_undo(struct radeon_ring *ring);
903 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
904 int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
905 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
906 void radeon_ring_lockup_update(struct radeon_ring *ring);
907 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
908 unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
910 int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
911 unsigned size, uint32_t *data);
912 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
913 unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg, u32 nop);
914 void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
918 void r600_dma_stop(struct radeon_device *rdev);
919 int r600_dma_resume(struct radeon_device *rdev);
920 void r600_dma_fini(struct radeon_device *rdev);
922 void cayman_dma_stop(struct radeon_device *rdev);
923 int cayman_dma_resume(struct radeon_device *rdev);
924 void cayman_dma_fini(struct radeon_device *rdev);
929 struct radeon_cs_reloc {
930 struct drm_gem_object *gobj;
931 struct radeon_bo *robj;
932 struct radeon_bo_list lobj;
937 struct radeon_cs_chunk {
943 void __user *user_ptr;
944 int last_copied_page;
948 struct radeon_cs_parser {
950 struct radeon_device *rdev;
951 struct drm_file *filp;
954 struct radeon_cs_chunk *chunks;
955 uint64_t *chunks_array;
960 struct radeon_cs_reloc *relocs;
961 struct radeon_cs_reloc **relocs_ptr;
962 struct list_head validated;
963 unsigned dma_reloc_idx;
964 /* indices of various chunks */
966 int chunk_relocs_idx;
968 int chunk_const_ib_idx;
970 struct radeon_ib const_ib;
977 struct ww_acquire_ctx ticket;
980 extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
981 extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
983 struct radeon_cs_packet {
992 typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
993 struct radeon_cs_packet *pkt,
994 unsigned idx, unsigned reg);
995 typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
996 struct radeon_cs_packet *pkt);
1002 int radeon_agp_init(struct radeon_device *rdev);
1003 void radeon_agp_resume(struct radeon_device *rdev);
1004 void radeon_agp_suspend(struct radeon_device *rdev);
1005 void radeon_agp_fini(struct radeon_device *rdev);
1012 struct radeon_bo *wb_obj;
1013 volatile uint32_t *wb;
1019 #define RADEON_WB_SCRATCH_OFFSET 0
1020 #define RADEON_WB_RING0_NEXT_RPTR 256
1021 #define RADEON_WB_CP_RPTR_OFFSET 1024
1022 #define RADEON_WB_CP1_RPTR_OFFSET 1280
1023 #define RADEON_WB_CP2_RPTR_OFFSET 1536
1024 #define R600_WB_DMA_RPTR_OFFSET 1792
1025 #define R600_WB_IH_WPTR_OFFSET 2048
1026 #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
1027 #define R600_WB_EVENT_OFFSET 3072
1028 #define CIK_WB_CP1_WPTR_OFFSET 3328
1029 #define CIK_WB_CP2_WPTR_OFFSET 3584
1032 * struct radeon_pm - power management datas
1033 * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
1034 * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
1035 * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
1036 * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
1037 * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
1038 * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
1039 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
1040 * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
1041 * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
1042 * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
1043 * @needed_bandwidth: current bandwidth needs
1045 * It keeps track of various data needed to take powermanagement decision.
1046 * Bandwidth need is used to determine minimun clock of the GPU and memory.
1047 * Equation between gpu/memory clock and available bandwidth is hw dependent
1048 * (type of memory, bus size, efficiency, ...)
1051 enum radeon_pm_method {
1057 enum radeon_dynpm_state {
1058 DYNPM_STATE_DISABLED,
1059 DYNPM_STATE_MINIMUM,
1062 DYNPM_STATE_SUSPENDED,
1064 enum radeon_dynpm_action {
1066 DYNPM_ACTION_MINIMUM,
1067 DYNPM_ACTION_DOWNCLOCK,
1068 DYNPM_ACTION_UPCLOCK,
1069 DYNPM_ACTION_DEFAULT
1072 enum radeon_voltage_type {
1079 enum radeon_pm_state_type {
1080 /* not used for dpm */
1081 POWER_STATE_TYPE_DEFAULT,
1082 POWER_STATE_TYPE_POWERSAVE,
1083 /* user selectable states */
1084 POWER_STATE_TYPE_BATTERY,
1085 POWER_STATE_TYPE_BALANCED,
1086 POWER_STATE_TYPE_PERFORMANCE,
1087 /* internal states */
1088 POWER_STATE_TYPE_INTERNAL_UVD,
1089 POWER_STATE_TYPE_INTERNAL_UVD_SD,
1090 POWER_STATE_TYPE_INTERNAL_UVD_HD,
1091 POWER_STATE_TYPE_INTERNAL_UVD_HD2,
1092 POWER_STATE_TYPE_INTERNAL_UVD_MVC,
1093 POWER_STATE_TYPE_INTERNAL_BOOT,
1094 POWER_STATE_TYPE_INTERNAL_THERMAL,
1095 POWER_STATE_TYPE_INTERNAL_ACPI,
1096 POWER_STATE_TYPE_INTERNAL_ULV,
1097 POWER_STATE_TYPE_INTERNAL_3DPERF,
1100 enum radeon_pm_profile_type {
1108 #define PM_PROFILE_DEFAULT_IDX 0
1109 #define PM_PROFILE_LOW_SH_IDX 1
1110 #define PM_PROFILE_MID_SH_IDX 2
1111 #define PM_PROFILE_HIGH_SH_IDX 3
1112 #define PM_PROFILE_LOW_MH_IDX 4
1113 #define PM_PROFILE_MID_MH_IDX 5
1114 #define PM_PROFILE_HIGH_MH_IDX 6
1115 #define PM_PROFILE_MAX 7
1117 struct radeon_pm_profile {
1118 int dpms_off_ps_idx;
1120 int dpms_off_cm_idx;
1124 enum radeon_int_thermal_type {
1126 THERMAL_TYPE_EXTERNAL,
1127 THERMAL_TYPE_EXTERNAL_GPIO,
1130 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1131 THERMAL_TYPE_EVERGREEN,
1135 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1140 struct radeon_voltage {
1141 enum radeon_voltage_type type;
1143 struct radeon_gpio_rec gpio;
1144 u32 delay; /* delay in usec from voltage drop to sclk change */
1145 bool active_high; /* voltage drop is active when bit is high */
1147 u8 vddc_id; /* index into vddc voltage table */
1148 u8 vddci_id; /* index into vddci voltage table */
1152 /* evergreen+ vddci */
1156 /* clock mode flags */
1157 #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
1159 struct radeon_pm_clock_info {
1165 struct radeon_voltage voltage;
1166 /* standardized clock flags */
1171 #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
1173 struct radeon_power_state {
1174 enum radeon_pm_state_type type;
1175 struct radeon_pm_clock_info *clock_info;
1176 /* number of valid clock modes in this power state */
1177 int num_clock_modes;
1178 struct radeon_pm_clock_info *default_clock_mode;
1179 /* standardized state flags */
1181 u32 misc; /* vbios specific flags */
1182 u32 misc2; /* vbios specific flags */
1183 int pcie_lanes; /* pcie lanes */
1187 * Some modes are overclocked by very low value, accept them
1189 #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
1191 enum radeon_dpm_auto_throttle_src {
1192 RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL,
1193 RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1196 enum radeon_dpm_event_src {
1197 RADEON_DPM_EVENT_SRC_ANALOG = 0,
1198 RADEON_DPM_EVENT_SRC_EXTERNAL = 1,
1199 RADEON_DPM_EVENT_SRC_DIGITAL = 2,
1200 RADEON_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1201 RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1205 u32 caps; /* vbios flags */
1206 u32 class; /* vbios flags */
1207 u32 class2; /* vbios flags */
1218 struct radeon_dpm_thermal {
1219 /* thermal interrupt work */
1220 struct work_struct work;
1221 /* low temperature threshold */
1223 /* high temperature threshold */
1225 /* was interrupt low to high or high to low */
1229 enum radeon_clk_action
1235 struct radeon_blacklist_clocks
1239 enum radeon_clk_action action;
1242 struct radeon_clock_and_voltage_limits {
1249 struct radeon_clock_array {
1254 struct radeon_clock_voltage_dependency_entry {
1259 struct radeon_clock_voltage_dependency_table {
1261 struct radeon_clock_voltage_dependency_entry *entries;
1264 union radeon_cac_leakage_entry {
1276 struct radeon_cac_leakage_table {
1278 union radeon_cac_leakage_entry *entries;
1281 struct radeon_phase_shedding_limits_entry {
1287 struct radeon_phase_shedding_limits_table {
1289 struct radeon_phase_shedding_limits_entry *entries;
1292 struct radeon_uvd_clock_voltage_dependency_entry {
1298 struct radeon_uvd_clock_voltage_dependency_table {
1300 struct radeon_uvd_clock_voltage_dependency_entry *entries;
1303 struct radeon_vce_clock_voltage_dependency_entry {
1309 struct radeon_vce_clock_voltage_dependency_table {
1311 struct radeon_vce_clock_voltage_dependency_entry *entries;
1314 struct radeon_ppm_table {
1316 u16 cpu_core_number;
1318 u32 small_ac_platform_tdp;
1320 u32 small_ac_platform_tdc;
1327 struct radeon_cac_tdp_table {
1329 u16 configurable_tdp;
1331 u16 battery_power_limit;
1332 u16 small_power_limit;
1333 u16 low_cac_leakage;
1334 u16 high_cac_leakage;
1335 u16 maximum_power_delivery_limit;
1338 struct radeon_dpm_dynamic_state {
1339 struct radeon_clock_voltage_dependency_table vddc_dependency_on_sclk;
1340 struct radeon_clock_voltage_dependency_table vddci_dependency_on_mclk;
1341 struct radeon_clock_voltage_dependency_table vddc_dependency_on_mclk;
1342 struct radeon_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1343 struct radeon_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1344 struct radeon_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1345 struct radeon_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1346 struct radeon_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1347 struct radeon_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1348 struct radeon_clock_array valid_sclk_values;
1349 struct radeon_clock_array valid_mclk_values;
1350 struct radeon_clock_and_voltage_limits max_clock_voltage_on_dc;
1351 struct radeon_clock_and_voltage_limits max_clock_voltage_on_ac;
1352 u32 mclk_sclk_ratio;
1353 u32 sclk_mclk_delta;
1354 u16 vddc_vddci_delta;
1355 u16 min_vddc_for_pcie_gen2;
1356 struct radeon_cac_leakage_table cac_leakage_table;
1357 struct radeon_phase_shedding_limits_table phase_shedding_limits_table;
1358 struct radeon_ppm_table *ppm_table;
1359 struct radeon_cac_tdp_table *cac_tdp_table;
1362 struct radeon_dpm_fan {
1372 bool ucode_fan_control;
1375 enum radeon_pcie_gen {
1376 RADEON_PCIE_GEN1 = 0,
1377 RADEON_PCIE_GEN2 = 1,
1378 RADEON_PCIE_GEN3 = 2,
1379 RADEON_PCIE_GEN_INVALID = 0xffff
1382 enum radeon_dpm_forced_level {
1383 RADEON_DPM_FORCED_LEVEL_AUTO = 0,
1384 RADEON_DPM_FORCED_LEVEL_LOW = 1,
1385 RADEON_DPM_FORCED_LEVEL_HIGH = 2,
1389 struct radeon_ps *ps;
1390 /* number of valid power states */
1392 /* current power state that is active */
1393 struct radeon_ps *current_ps;
1394 /* requested power state */
1395 struct radeon_ps *requested_ps;
1396 /* boot up power state */
1397 struct radeon_ps *boot_ps;
1398 /* default uvd power state */
1399 struct radeon_ps *uvd_ps;
1400 enum radeon_pm_state_type state;
1401 enum radeon_pm_state_type user_state;
1403 u32 voltage_response_time;
1404 u32 backbias_response_time;
1406 u32 new_active_crtcs;
1407 int new_active_crtc_count;
1408 u32 current_active_crtcs;
1409 int current_active_crtc_count;
1410 struct radeon_dpm_dynamic_state dyn_state;
1411 struct radeon_dpm_fan fan;
1414 u32 near_tdp_limit_adjusted;
1415 u32 sq_ramping_threshold;
1419 u16 load_line_slope;
1422 /* special states active */
1423 bool thermal_active;
1425 /* thermal handling */
1426 struct radeon_dpm_thermal thermal;
1428 enum radeon_dpm_forced_level forced_level;
1429 /* track UVD streams */
1434 void radeon_dpm_enable_uvd(struct radeon_device *rdev, bool enable);
1438 /* write locked while reprogramming mclk */
1439 struct rw_semaphore mclk_lock;
1441 int active_crtc_count;
1444 fixed20_12 max_bandwidth;
1445 fixed20_12 igp_sideport_mclk;
1446 fixed20_12 igp_system_mclk;
1447 fixed20_12 igp_ht_link_clk;
1448 fixed20_12 igp_ht_link_width;
1449 fixed20_12 k8_bandwidth;
1450 fixed20_12 sideport_bandwidth;
1451 fixed20_12 ht_bandwidth;
1452 fixed20_12 core_bandwidth;
1455 fixed20_12 needed_bandwidth;
1456 struct radeon_power_state *power_state;
1457 /* number of valid power states */
1458 int num_power_states;
1459 int current_power_state_index;
1460 int current_clock_mode_index;
1461 int requested_power_state_index;
1462 int requested_clock_mode_index;
1463 int default_power_state_index;
1472 struct radeon_i2c_chan *i2c_bus;
1473 /* selected pm method */
1474 enum radeon_pm_method pm_method;
1475 /* dynpm power management */
1476 struct delayed_work dynpm_idle_work;
1477 enum radeon_dynpm_state dynpm_state;
1478 enum radeon_dynpm_action dynpm_planned_action;
1479 unsigned long dynpm_action_timeout;
1480 bool dynpm_can_upclock;
1481 bool dynpm_can_downclock;
1482 /* profile-based power management */
1483 enum radeon_pm_profile_type profile;
1485 struct radeon_pm_profile profiles[PM_PROFILE_MAX];
1486 /* internal thermal controller on rv6xx+ */
1487 enum radeon_int_thermal_type int_thermal_type;
1488 struct device *int_hwmon_dev;
1491 struct radeon_dpm dpm;
1494 int radeon_pm_get_type_index(struct radeon_device *rdev,
1495 enum radeon_pm_state_type ps_type,
1500 #define RADEON_MAX_UVD_HANDLES 10
1501 #define RADEON_UVD_STACK_SIZE (1024*1024)
1502 #define RADEON_UVD_HEAP_SIZE (1024*1024)
1505 struct radeon_bo *vcpu_bo;
1509 atomic_t handles[RADEON_MAX_UVD_HANDLES];
1510 struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
1511 unsigned img_size[RADEON_MAX_UVD_HANDLES];
1512 struct delayed_work idle_work;
1515 int radeon_uvd_init(struct radeon_device *rdev);
1516 void radeon_uvd_fini(struct radeon_device *rdev);
1517 int radeon_uvd_suspend(struct radeon_device *rdev);
1518 int radeon_uvd_resume(struct radeon_device *rdev);
1519 int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
1520 uint32_t handle, struct radeon_fence **fence);
1521 int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
1522 uint32_t handle, struct radeon_fence **fence);
1523 void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo);
1524 void radeon_uvd_free_handles(struct radeon_device *rdev,
1525 struct drm_file *filp);
1526 int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
1527 void radeon_uvd_note_usage(struct radeon_device *rdev);
1528 int radeon_uvd_calc_upll_dividers(struct radeon_device *rdev,
1529 unsigned vclk, unsigned dclk,
1530 unsigned vco_min, unsigned vco_max,
1531 unsigned fb_factor, unsigned fb_mask,
1532 unsigned pd_min, unsigned pd_max,
1534 unsigned *optimal_fb_div,
1535 unsigned *optimal_vclk_div,
1536 unsigned *optimal_dclk_div);
1537 int radeon_uvd_send_upll_ctlreq(struct radeon_device *rdev,
1538 unsigned cg_upll_func_cntl);
1543 int bits_per_sample;
1551 void radeon_benchmark(struct radeon_device *rdev, int test_number);
1557 void radeon_test_moves(struct radeon_device *rdev);
1558 void radeon_test_ring_sync(struct radeon_device *rdev,
1559 struct radeon_ring *cpA,
1560 struct radeon_ring *cpB);
1561 void radeon_test_syncing(struct radeon_device *rdev);
1567 struct radeon_debugfs {
1568 struct drm_info_list *files;
1572 int radeon_debugfs_add_files(struct radeon_device *rdev,
1573 struct drm_info_list *files,
1575 int radeon_debugfs_fence_init(struct radeon_device *rdev);
1578 * ASIC ring specific functions.
1580 struct radeon_asic_ring {
1581 /* ring read/write ptr handling */
1582 u32 (*get_rptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1583 u32 (*get_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1584 void (*set_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
1586 /* validating and patching of IBs */
1587 int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
1588 int (*cs_parse)(struct radeon_cs_parser *p);
1590 /* command emmit functions */
1591 void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
1592 void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
1593 void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
1594 struct radeon_semaphore *semaphore, bool emit_wait);
1595 void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
1597 /* testing functions */
1598 int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1599 int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
1600 bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
1603 void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
1607 * ASIC specific functions.
1609 struct radeon_asic {
1610 int (*init)(struct radeon_device *rdev);
1611 void (*fini)(struct radeon_device *rdev);
1612 int (*resume)(struct radeon_device *rdev);
1613 int (*suspend)(struct radeon_device *rdev);
1614 void (*vga_set_state)(struct radeon_device *rdev, bool state);
1615 int (*asic_reset)(struct radeon_device *rdev);
1616 /* ioctl hw specific callback. Some hw might want to perform special
1617 * operation on specific ioctl. For instance on wait idle some hw
1618 * might want to perform and HDP flush through MMIO as it seems that
1619 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
1622 void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
1623 /* check if 3D engine is idle */
1624 bool (*gui_idle)(struct radeon_device *rdev);
1625 /* wait for mc_idle */
1626 int (*mc_wait_for_idle)(struct radeon_device *rdev);
1627 /* get the reference clock */
1628 u32 (*get_xclk)(struct radeon_device *rdev);
1629 /* get the gpu clock counter */
1630 uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
1633 void (*tlb_flush)(struct radeon_device *rdev);
1634 int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
1637 int (*init)(struct radeon_device *rdev);
1638 void (*fini)(struct radeon_device *rdev);
1641 void (*set_page)(struct radeon_device *rdev,
1642 struct radeon_ib *ib,
1644 uint64_t addr, unsigned count,
1645 uint32_t incr, uint32_t flags);
1647 /* ring specific callbacks */
1648 struct radeon_asic_ring *ring[RADEON_NUM_RINGS];
1651 int (*set)(struct radeon_device *rdev);
1652 int (*process)(struct radeon_device *rdev);
1656 /* display watermarks */
1657 void (*bandwidth_update)(struct radeon_device *rdev);
1658 /* get frame count */
1659 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
1660 /* wait for vblank */
1661 void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
1662 /* set backlight level */
1663 void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
1664 /* get backlight level */
1665 u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
1666 /* audio callbacks */
1667 void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
1668 void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
1670 /* copy functions for bo handling */
1672 int (*blit)(struct radeon_device *rdev,
1673 uint64_t src_offset,
1674 uint64_t dst_offset,
1675 unsigned num_gpu_pages,
1676 struct radeon_fence **fence);
1677 u32 blit_ring_index;
1678 int (*dma)(struct radeon_device *rdev,
1679 uint64_t src_offset,
1680 uint64_t dst_offset,
1681 unsigned num_gpu_pages,
1682 struct radeon_fence **fence);
1684 /* method used for bo copy */
1685 int (*copy)(struct radeon_device *rdev,
1686 uint64_t src_offset,
1687 uint64_t dst_offset,
1688 unsigned num_gpu_pages,
1689 struct radeon_fence **fence);
1690 /* ring used for bo copies */
1691 u32 copy_ring_index;
1695 int (*set_reg)(struct radeon_device *rdev, int reg,
1696 uint32_t tiling_flags, uint32_t pitch,
1697 uint32_t offset, uint32_t obj_size);
1698 void (*clear_reg)(struct radeon_device *rdev, int reg);
1700 /* hotplug detect */
1702 void (*init)(struct radeon_device *rdev);
1703 void (*fini)(struct radeon_device *rdev);
1704 bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1705 void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
1707 /* static power management */
1709 void (*misc)(struct radeon_device *rdev);
1710 void (*prepare)(struct radeon_device *rdev);
1711 void (*finish)(struct radeon_device *rdev);
1712 void (*init_profile)(struct radeon_device *rdev);
1713 void (*get_dynpm_state)(struct radeon_device *rdev);
1714 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
1715 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
1716 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
1717 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
1718 int (*get_pcie_lanes)(struct radeon_device *rdev);
1719 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
1720 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
1721 int (*set_uvd_clocks)(struct radeon_device *rdev, u32 vclk, u32 dclk);
1722 int (*get_temperature)(struct radeon_device *rdev);
1724 /* dynamic power management */
1726 int (*init)(struct radeon_device *rdev);
1727 void (*setup_asic)(struct radeon_device *rdev);
1728 int (*enable)(struct radeon_device *rdev);
1729 void (*disable)(struct radeon_device *rdev);
1730 int (*pre_set_power_state)(struct radeon_device *rdev);
1731 int (*set_power_state)(struct radeon_device *rdev);
1732 void (*post_set_power_state)(struct radeon_device *rdev);
1733 void (*display_configuration_changed)(struct radeon_device *rdev);
1734 void (*fini)(struct radeon_device *rdev);
1735 u32 (*get_sclk)(struct radeon_device *rdev, bool low);
1736 u32 (*get_mclk)(struct radeon_device *rdev, bool low);
1737 void (*print_power_state)(struct radeon_device *rdev, struct radeon_ps *ps);
1738 void (*debugfs_print_current_performance_level)(struct radeon_device *rdev, struct seq_file *m);
1739 int (*force_performance_level)(struct radeon_device *rdev, enum radeon_dpm_forced_level level);
1740 bool (*vblank_too_short)(struct radeon_device *rdev);
1741 void (*powergate_uvd)(struct radeon_device *rdev, bool gate);
1745 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
1746 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
1747 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
1755 const unsigned *reg_safe_bm;
1756 unsigned reg_safe_bm_size;
1761 const unsigned *reg_safe_bm;
1762 unsigned reg_safe_bm_size;
1769 unsigned max_tile_pipes;
1771 unsigned max_backends;
1773 unsigned max_threads;
1774 unsigned max_stack_entries;
1775 unsigned max_hw_contexts;
1776 unsigned max_gs_threads;
1777 unsigned sx_max_export_size;
1778 unsigned sx_max_export_pos_size;
1779 unsigned sx_max_export_smx_size;
1780 unsigned sq_num_cf_insts;
1781 unsigned tiling_nbanks;
1782 unsigned tiling_npipes;
1783 unsigned tiling_group_size;
1784 unsigned tile_config;
1785 unsigned backend_map;
1790 unsigned max_tile_pipes;
1792 unsigned max_backends;
1794 unsigned max_threads;
1795 unsigned max_stack_entries;
1796 unsigned max_hw_contexts;
1797 unsigned max_gs_threads;
1798 unsigned sx_max_export_size;
1799 unsigned sx_max_export_pos_size;
1800 unsigned sx_max_export_smx_size;
1801 unsigned sq_num_cf_insts;
1802 unsigned sx_num_of_sets;
1803 unsigned sc_prim_fifo_size;
1804 unsigned sc_hiz_tile_fifo_size;
1805 unsigned sc_earlyz_tile_fifo_fize;
1806 unsigned tiling_nbanks;
1807 unsigned tiling_npipes;
1808 unsigned tiling_group_size;
1809 unsigned tile_config;
1810 unsigned backend_map;
1813 struct evergreen_asic {
1816 unsigned max_tile_pipes;
1818 unsigned max_backends;
1820 unsigned max_threads;
1821 unsigned max_stack_entries;
1822 unsigned max_hw_contexts;
1823 unsigned max_gs_threads;
1824 unsigned sx_max_export_size;
1825 unsigned sx_max_export_pos_size;
1826 unsigned sx_max_export_smx_size;
1827 unsigned sq_num_cf_insts;
1828 unsigned sx_num_of_sets;
1829 unsigned sc_prim_fifo_size;
1830 unsigned sc_hiz_tile_fifo_size;
1831 unsigned sc_earlyz_tile_fifo_size;
1832 unsigned tiling_nbanks;
1833 unsigned tiling_npipes;
1834 unsigned tiling_group_size;
1835 unsigned tile_config;
1836 unsigned backend_map;
1839 struct cayman_asic {
1840 unsigned max_shader_engines;
1841 unsigned max_pipes_per_simd;
1842 unsigned max_tile_pipes;
1843 unsigned max_simds_per_se;
1844 unsigned max_backends_per_se;
1845 unsigned max_texture_channel_caches;
1847 unsigned max_threads;
1848 unsigned max_gs_threads;
1849 unsigned max_stack_entries;
1850 unsigned sx_num_of_sets;
1851 unsigned sx_max_export_size;
1852 unsigned sx_max_export_pos_size;
1853 unsigned sx_max_export_smx_size;
1854 unsigned max_hw_contexts;
1855 unsigned sq_num_cf_insts;
1856 unsigned sc_prim_fifo_size;
1857 unsigned sc_hiz_tile_fifo_size;
1858 unsigned sc_earlyz_tile_fifo_size;
1860 unsigned num_shader_engines;
1861 unsigned num_shader_pipes_per_simd;
1862 unsigned num_tile_pipes;
1863 unsigned num_simds_per_se;
1864 unsigned num_backends_per_se;
1865 unsigned backend_disable_mask_per_asic;
1866 unsigned backend_map;
1867 unsigned num_texture_channel_caches;
1868 unsigned mem_max_burst_length_bytes;
1869 unsigned mem_row_size_in_kb;
1870 unsigned shader_engine_tile_size;
1872 unsigned multi_gpu_tile_size;
1874 unsigned tile_config;
1878 unsigned max_shader_engines;
1879 unsigned max_tile_pipes;
1880 unsigned max_cu_per_sh;
1881 unsigned max_sh_per_se;
1882 unsigned max_backends_per_se;
1883 unsigned max_texture_channel_caches;
1885 unsigned max_gs_threads;
1886 unsigned max_hw_contexts;
1887 unsigned sc_prim_fifo_size_frontend;
1888 unsigned sc_prim_fifo_size_backend;
1889 unsigned sc_hiz_tile_fifo_size;
1890 unsigned sc_earlyz_tile_fifo_size;
1892 unsigned num_tile_pipes;
1893 unsigned num_backends_per_se;
1894 unsigned backend_disable_mask_per_asic;
1895 unsigned backend_map;
1896 unsigned num_texture_channel_caches;
1897 unsigned mem_max_burst_length_bytes;
1898 unsigned mem_row_size_in_kb;
1899 unsigned shader_engine_tile_size;
1901 unsigned multi_gpu_tile_size;
1903 unsigned tile_config;
1904 uint32_t tile_mode_array[32];
1908 unsigned max_shader_engines;
1909 unsigned max_tile_pipes;
1910 unsigned max_cu_per_sh;
1911 unsigned max_sh_per_se;
1912 unsigned max_backends_per_se;
1913 unsigned max_texture_channel_caches;
1915 unsigned max_gs_threads;
1916 unsigned max_hw_contexts;
1917 unsigned sc_prim_fifo_size_frontend;
1918 unsigned sc_prim_fifo_size_backend;
1919 unsigned sc_hiz_tile_fifo_size;
1920 unsigned sc_earlyz_tile_fifo_size;
1922 unsigned num_tile_pipes;
1923 unsigned num_backends_per_se;
1924 unsigned backend_disable_mask_per_asic;
1925 unsigned backend_map;
1926 unsigned num_texture_channel_caches;
1927 unsigned mem_max_burst_length_bytes;
1928 unsigned mem_row_size_in_kb;
1929 unsigned shader_engine_tile_size;
1931 unsigned multi_gpu_tile_size;
1933 unsigned tile_config;
1934 uint32_t tile_mode_array[32];
1937 union radeon_asic_config {
1938 struct r300_asic r300;
1939 struct r100_asic r100;
1940 struct r600_asic r600;
1941 struct rv770_asic rv770;
1942 struct evergreen_asic evergreen;
1943 struct cayman_asic cayman;
1945 struct cik_asic cik;
1949 * asic initizalization from radeon_asic.c
1951 void radeon_agp_disable(struct radeon_device *rdev);
1952 int radeon_asic_init(struct radeon_device *rdev);
1958 int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
1959 struct drm_file *filp);
1960 int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
1961 struct drm_file *filp);
1962 int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
1963 struct drm_file *file_priv);
1964 int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
1965 struct drm_file *file_priv);
1966 int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1967 struct drm_file *file_priv);
1968 int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
1969 struct drm_file *file_priv);
1970 int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1971 struct drm_file *filp);
1972 int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
1973 struct drm_file *filp);
1974 int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
1975 struct drm_file *filp);
1976 int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1977 struct drm_file *filp);
1978 int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
1979 struct drm_file *filp);
1980 int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1981 int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1982 struct drm_file *filp);
1983 int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1984 struct drm_file *filp);
1986 /* VRAM scratch page for HDP bug, default vram page */
1987 struct r600_vram_scratch {
1988 struct radeon_bo *robj;
1989 volatile uint32_t *ptr;
1996 struct radeon_atif_notification_cfg {
2001 struct radeon_atif_notifications {
2002 bool display_switch;
2003 bool expansion_mode_change;
2005 bool forced_power_state;
2006 bool system_power_state;
2007 bool display_conf_change;
2009 bool brightness_change;
2010 bool dgpu_display_event;
2013 struct radeon_atif_functions {
2015 bool sbios_requests;
2016 bool select_active_disp;
2018 bool get_tv_standard;
2019 bool set_tv_standard;
2020 bool get_panel_expansion_mode;
2021 bool set_panel_expansion_mode;
2022 bool temperature_change;
2023 bool graphics_device_types;
2026 struct radeon_atif {
2027 struct radeon_atif_notifications notifications;
2028 struct radeon_atif_functions functions;
2029 struct radeon_atif_notification_cfg notification_cfg;
2030 struct radeon_encoder *encoder_for_bl;
2033 struct radeon_atcs_functions {
2037 bool pcie_bus_width;
2040 struct radeon_atcs {
2041 struct radeon_atcs_functions functions;
2045 * Core structure, functions and helpers.
2047 typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
2048 typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
2050 struct radeon_device {
2052 struct drm_device *ddev;
2053 struct pci_dev *pdev;
2054 struct rw_semaphore exclusive_lock;
2056 union radeon_asic_config config;
2057 enum radeon_family family;
2058 unsigned long flags;
2060 enum radeon_pll_errata pll_errata;
2067 uint16_t bios_header_start;
2068 struct radeon_bo *stollen_vga_memory;
2070 resource_size_t rmmio_base;
2071 resource_size_t rmmio_size;
2072 /* protects concurrent MM_INDEX/DATA based register access */
2073 spinlock_t mmio_idx_lock;
2074 void __iomem *rmmio;
2075 radeon_rreg_t mc_rreg;
2076 radeon_wreg_t mc_wreg;
2077 radeon_rreg_t pll_rreg;
2078 radeon_wreg_t pll_wreg;
2079 uint32_t pcie_reg_mask;
2080 radeon_rreg_t pciep_rreg;
2081 radeon_wreg_t pciep_wreg;
2083 void __iomem *rio_mem;
2084 resource_size_t rio_mem_size;
2085 struct radeon_clock clock;
2086 struct radeon_mc mc;
2087 struct radeon_gart gart;
2088 struct radeon_mode_info mode_info;
2089 struct radeon_scratch scratch;
2090 struct radeon_doorbell doorbell;
2091 struct radeon_mman mman;
2092 struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
2093 wait_queue_head_t fence_queue;
2094 struct mutex ring_lock;
2095 struct radeon_ring ring[RADEON_NUM_RINGS];
2097 struct radeon_sa_manager ring_tmp_bo;
2098 struct radeon_irq irq;
2099 struct radeon_asic *asic;
2100 struct radeon_gem gem;
2101 struct radeon_pm pm;
2102 struct radeon_uvd uvd;
2103 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
2104 struct radeon_wb wb;
2105 struct radeon_dummy_page dummy_page;
2110 bool fastfb_working; /* IGP feature*/
2111 struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
2112 const struct firmware *me_fw; /* all family ME firmware */
2113 const struct firmware *pfp_fw; /* r6/700 PFP firmware */
2114 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
2115 const struct firmware *mc_fw; /* NI MC firmware */
2116 const struct firmware *ce_fw; /* SI CE firmware */
2117 const struct firmware *mec_fw; /* CIK MEC firmware */
2118 const struct firmware *sdma_fw; /* CIK SDMA firmware */
2119 const struct firmware *smc_fw; /* SMC firmware */
2120 const struct firmware *uvd_fw; /* UVD firmware */
2121 struct r600_vram_scratch vram_scratch;
2122 int msi_enabled; /* msi enabled */
2123 struct r600_ih ih; /* r6/700 interrupt ring */
2124 struct radeon_rlc rlc;
2125 struct radeon_mec mec;
2126 struct work_struct hotplug_work;
2127 struct work_struct audio_work;
2128 struct work_struct reset_work;
2129 int num_crtc; /* number of crtcs */
2130 struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
2133 struct r600_audio audio_status; /* audio stuff */
2134 struct notifier_block acpi_nb;
2135 /* only one userspace can use Hyperz features or CMASK at a time */
2136 struct drm_file *hyperz_filp;
2137 struct drm_file *cmask_filp;
2139 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
2141 struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
2142 unsigned debugfs_count;
2143 /* virtual memory */
2144 struct radeon_vm_manager vm_manager;
2145 struct mutex gpu_clock_mutex;
2146 /* ACPI interface */
2147 struct radeon_atif atif;
2148 struct radeon_atcs atcs;
2149 /* srbm instance registers */
2150 struct mutex srbm_mutex;
2153 int radeon_device_init(struct radeon_device *rdev,
2154 struct drm_device *ddev,
2155 struct pci_dev *pdev,
2157 void radeon_device_fini(struct radeon_device *rdev);
2158 int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
2160 uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
2161 bool always_indirect);
2162 void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
2163 bool always_indirect);
2164 u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
2165 void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
2167 u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset);
2168 void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v);
2173 #define to_radeon_fence(p) ((struct radeon_fence *)(p))
2176 * Registers read & write functions.
2178 #define RREG8(reg) readb((rdev->rmmio) + (reg))
2179 #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
2180 #define RREG16(reg) readw((rdev->rmmio) + (reg))
2181 #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
2182 #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
2183 #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
2184 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
2185 #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
2186 #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
2187 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2188 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2189 #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
2190 #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
2191 #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
2192 #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
2193 #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
2194 #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
2195 #define RREG32_PCIE_PORT(reg) rdev->pciep_rreg(rdev, (reg))
2196 #define WREG32_PCIE_PORT(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
2197 #define RREG32_SMC(reg) tn_smc_rreg(rdev, (reg))
2198 #define WREG32_SMC(reg, v) tn_smc_wreg(rdev, (reg), (v))
2199 #define RREG32_RCU(reg) r600_rcu_rreg(rdev, (reg))
2200 #define WREG32_RCU(reg, v) r600_rcu_wreg(rdev, (reg), (v))
2201 #define RREG32_CG(reg) eg_cg_rreg(rdev, (reg))
2202 #define WREG32_CG(reg, v) eg_cg_wreg(rdev, (reg), (v))
2203 #define RREG32_PIF_PHY0(reg) eg_pif_phy0_rreg(rdev, (reg))
2204 #define WREG32_PIF_PHY0(reg, v) eg_pif_phy0_wreg(rdev, (reg), (v))
2205 #define RREG32_PIF_PHY1(reg) eg_pif_phy1_rreg(rdev, (reg))
2206 #define WREG32_PIF_PHY1(reg, v) eg_pif_phy1_wreg(rdev, (reg), (v))
2207 #define RREG32_UVD_CTX(reg) r600_uvd_ctx_rreg(rdev, (reg))
2208 #define WREG32_UVD_CTX(reg, v) r600_uvd_ctx_wreg(rdev, (reg), (v))
2209 #define RREG32_DIDT(reg) cik_didt_rreg(rdev, (reg))
2210 #define WREG32_DIDT(reg, v) cik_didt_wreg(rdev, (reg), (v))
2211 #define WREG32_P(reg, val, mask) \
2213 uint32_t tmp_ = RREG32(reg); \
2215 tmp_ |= ((val) & ~(mask)); \
2216 WREG32(reg, tmp_); \
2218 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2219 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2220 #define WREG32_PLL_P(reg, val, mask) \
2222 uint32_t tmp_ = RREG32_PLL(reg); \
2224 tmp_ |= ((val) & ~(mask)); \
2225 WREG32_PLL(reg, tmp_); \
2227 #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
2228 #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
2229 #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
2231 #define RDOORBELL32(offset) cik_mm_rdoorbell(rdev, (offset))
2232 #define WDOORBELL32(offset, v) cik_mm_wdoorbell(rdev, (offset), (v))
2235 * Indirect registers accessor
2237 static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
2241 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
2242 r = RREG32(RADEON_PCIE_DATA);
2246 static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
2248 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
2249 WREG32(RADEON_PCIE_DATA, (v));
2252 static inline u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg)
2256 WREG32(TN_SMC_IND_INDEX_0, (reg));
2257 r = RREG32(TN_SMC_IND_DATA_0);
2261 static inline void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2263 WREG32(TN_SMC_IND_INDEX_0, (reg));
2264 WREG32(TN_SMC_IND_DATA_0, (v));
2267 static inline u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
2271 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
2272 r = RREG32(R600_RCU_DATA);
2276 static inline void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2278 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
2279 WREG32(R600_RCU_DATA, (v));
2282 static inline u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
2286 WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
2287 r = RREG32(EVERGREEN_CG_IND_DATA);
2291 static inline void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2293 WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
2294 WREG32(EVERGREEN_CG_IND_DATA, (v));
2297 static inline u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
2301 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
2302 r = RREG32(EVERGREEN_PIF_PHY0_DATA);
2306 static inline void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2308 WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
2309 WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
2312 static inline u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
2316 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
2317 r = RREG32(EVERGREEN_PIF_PHY1_DATA);
2321 static inline void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2323 WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
2324 WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
2327 static inline u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
2331 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
2332 r = RREG32(R600_UVD_CTX_DATA);
2336 static inline void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2338 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
2339 WREG32(R600_UVD_CTX_DATA, (v));
2343 static inline u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg)
2347 WREG32(CIK_DIDT_IND_INDEX, (reg));
2348 r = RREG32(CIK_DIDT_IND_DATA);
2352 static inline void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v)
2354 WREG32(CIK_DIDT_IND_INDEX, (reg));
2355 WREG32(CIK_DIDT_IND_DATA, (v));
2358 void r100_pll_errata_after_index(struct radeon_device *rdev);
2364 #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
2365 (rdev->pdev->device == 0x5969))
2366 #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
2367 (rdev->family == CHIP_RV200) || \
2368 (rdev->family == CHIP_RS100) || \
2369 (rdev->family == CHIP_RS200) || \
2370 (rdev->family == CHIP_RV250) || \
2371 (rdev->family == CHIP_RV280) || \
2372 (rdev->family == CHIP_RS300))
2373 #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
2374 (rdev->family == CHIP_RV350) || \
2375 (rdev->family == CHIP_R350) || \
2376 (rdev->family == CHIP_RV380) || \
2377 (rdev->family == CHIP_R420) || \
2378 (rdev->family == CHIP_R423) || \
2379 (rdev->family == CHIP_RV410) || \
2380 (rdev->family == CHIP_RS400) || \
2381 (rdev->family == CHIP_RS480))
2382 #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
2383 (rdev->ddev->pdev->device == 0x9443) || \
2384 (rdev->ddev->pdev->device == 0x944B) || \
2385 (rdev->ddev->pdev->device == 0x9506) || \
2386 (rdev->ddev->pdev->device == 0x9509) || \
2387 (rdev->ddev->pdev->device == 0x950F) || \
2388 (rdev->ddev->pdev->device == 0x689C) || \
2389 (rdev->ddev->pdev->device == 0x689D))
2390 #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
2391 #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
2392 (rdev->family == CHIP_RS690) || \
2393 (rdev->family == CHIP_RS740) || \
2394 (rdev->family >= CHIP_R600))
2395 #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
2396 #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
2397 #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
2398 #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
2399 (rdev->flags & RADEON_IS_IGP))
2400 #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
2401 #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
2402 #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
2403 (rdev->flags & RADEON_IS_IGP))
2404 #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
2405 #define ASIC_IS_NODCE(rdev) ((rdev->family == CHIP_HAINAN))
2406 #define ASIC_IS_DCE8(rdev) ((rdev->family >= CHIP_BONAIRE))
2408 #define ASIC_IS_LOMBOK(rdev) ((rdev->ddev->pdev->device == 0x6849) || \
2409 (rdev->ddev->pdev->device == 0x6850) || \
2410 (rdev->ddev->pdev->device == 0x6858) || \
2411 (rdev->ddev->pdev->device == 0x6859) || \
2412 (rdev->ddev->pdev->device == 0x6840) || \
2413 (rdev->ddev->pdev->device == 0x6841) || \
2414 (rdev->ddev->pdev->device == 0x6842) || \
2415 (rdev->ddev->pdev->device == 0x6843))
2420 #define RBIOS8(i) (rdev->bios[i])
2421 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2422 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2424 int radeon_combios_init(struct radeon_device *rdev);
2425 void radeon_combios_fini(struct radeon_device *rdev);
2426 int radeon_atombios_init(struct radeon_device *rdev);
2427 void radeon_atombios_fini(struct radeon_device *rdev);
2433 #if DRM_DEBUG_CODE == 0
2434 static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
2436 ring->ring[ring->wptr++] = v;
2437 ring->wptr &= ring->ptr_mask;
2439 ring->ring_free_dw--;
2442 /* With debugging this is just too big to inline */
2443 void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
2449 #define radeon_init(rdev) (rdev)->asic->init((rdev))
2450 #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
2451 #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
2452 #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
2453 #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)]->cs_parse((p))
2454 #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
2455 #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
2456 #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
2457 #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
2458 #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
2459 #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
2460 #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)))
2461 #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_start((rdev), (cp))
2462 #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_test((rdev), (cp))
2463 #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ib_test((rdev), (cp))
2464 #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_execute((rdev), (ib))
2465 #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_parse((rdev), (ib))
2466 #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)]->is_lockup((rdev), (cp))
2467 #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)]->vm_flush((rdev), (r), (vm))
2468 #define radeon_ring_get_rptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_rptr((rdev), (r))
2469 #define radeon_ring_get_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_wptr((rdev), (r))
2470 #define radeon_ring_set_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->set_wptr((rdev), (r))
2471 #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
2472 #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
2473 #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
2474 #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
2475 #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
2476 #define radeon_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
2477 #define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
2478 #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)]->emit_fence((rdev), (fence))
2479 #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)]->emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
2480 #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
2481 #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
2482 #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
2483 #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
2484 #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
2485 #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
2486 #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
2487 #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
2488 #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
2489 #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
2490 #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
2491 #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
2492 #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
2493 #define radeon_set_uvd_clocks(rdev, v, d) (rdev)->asic->pm.set_uvd_clocks((rdev), (v), (d))
2494 #define radeon_get_temperature(rdev) (rdev)->asic->pm.get_temperature((rdev))
2495 #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
2496 #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
2497 #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
2498 #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
2499 #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
2500 #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
2501 #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
2502 #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
2503 #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
2504 #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
2505 #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
2506 #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
2507 #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
2508 #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
2509 #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
2510 #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
2511 #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
2512 #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
2513 #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
2514 #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
2515 #define radeon_dpm_init(rdev) rdev->asic->dpm.init((rdev))
2516 #define radeon_dpm_setup_asic(rdev) rdev->asic->dpm.setup_asic((rdev))
2517 #define radeon_dpm_enable(rdev) rdev->asic->dpm.enable((rdev))
2518 #define radeon_dpm_disable(rdev) rdev->asic->dpm.disable((rdev))
2519 #define radeon_dpm_pre_set_power_state(rdev) rdev->asic->dpm.pre_set_power_state((rdev))
2520 #define radeon_dpm_set_power_state(rdev) rdev->asic->dpm.set_power_state((rdev))
2521 #define radeon_dpm_post_set_power_state(rdev) rdev->asic->dpm.post_set_power_state((rdev))
2522 #define radeon_dpm_display_configuration_changed(rdev) rdev->asic->dpm.display_configuration_changed((rdev))
2523 #define radeon_dpm_fini(rdev) rdev->asic->dpm.fini((rdev))
2524 #define radeon_dpm_get_sclk(rdev, l) rdev->asic->dpm.get_sclk((rdev), (l))
2525 #define radeon_dpm_get_mclk(rdev, l) rdev->asic->dpm.get_mclk((rdev), (l))
2526 #define radeon_dpm_print_power_state(rdev, ps) rdev->asic->dpm.print_power_state((rdev), (ps))
2527 #define radeon_dpm_debugfs_print_current_performance_level(rdev, m) rdev->asic->dpm.debugfs_print_current_performance_level((rdev), (m))
2528 #define radeon_dpm_force_performance_level(rdev, l) rdev->asic->dpm.force_performance_level((rdev), (l))
2529 #define radeon_dpm_vblank_too_short(rdev) rdev->asic->dpm.vblank_too_short((rdev))
2530 #define radeon_dpm_powergate_uvd(rdev, g) rdev->asic->dpm.powergate_uvd((rdev), (g))
2532 /* Common functions */
2534 extern int radeon_gpu_reset(struct radeon_device *rdev);
2535 extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
2536 extern void radeon_agp_disable(struct radeon_device *rdev);
2537 extern int radeon_modeset_init(struct radeon_device *rdev);
2538 extern void radeon_modeset_fini(struct radeon_device *rdev);
2539 extern bool radeon_card_posted(struct radeon_device *rdev);
2540 extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
2541 extern void radeon_update_display_priority(struct radeon_device *rdev);
2542 extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
2543 extern void radeon_scratch_init(struct radeon_device *rdev);
2544 extern void radeon_wb_fini(struct radeon_device *rdev);
2545 extern int radeon_wb_init(struct radeon_device *rdev);
2546 extern void radeon_wb_disable(struct radeon_device *rdev);
2547 extern void radeon_surface_init(struct radeon_device *rdev);
2548 extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
2549 extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
2550 extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
2551 extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
2552 extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
2553 extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
2554 extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
2555 extern int radeon_resume_kms(struct drm_device *dev);
2556 extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
2557 extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
2558 extern void radeon_program_register_sequence(struct radeon_device *rdev,
2559 const u32 *registers,
2560 const u32 array_size);
2565 int radeon_vm_manager_init(struct radeon_device *rdev);
2566 void radeon_vm_manager_fini(struct radeon_device *rdev);
2567 void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
2568 void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
2569 int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
2570 void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
2571 struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
2572 struct radeon_vm *vm, int ring);
2573 void radeon_vm_fence(struct radeon_device *rdev,
2574 struct radeon_vm *vm,
2575 struct radeon_fence *fence);
2576 uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
2577 int radeon_vm_bo_update_pte(struct radeon_device *rdev,
2578 struct radeon_vm *vm,
2579 struct radeon_bo *bo,
2580 struct ttm_mem_reg *mem);
2581 void radeon_vm_bo_invalidate(struct radeon_device *rdev,
2582 struct radeon_bo *bo);
2583 struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
2584 struct radeon_bo *bo);
2585 struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
2586 struct radeon_vm *vm,
2587 struct radeon_bo *bo);
2588 int radeon_vm_bo_set_addr(struct radeon_device *rdev,
2589 struct radeon_bo_va *bo_va,
2592 int radeon_vm_bo_rmv(struct radeon_device *rdev,
2593 struct radeon_bo_va *bo_va);
2596 void r600_audio_update_hdmi(struct work_struct *work);
2599 * R600 vram scratch functions
2601 int r600_vram_scratch_init(struct radeon_device *rdev);
2602 void r600_vram_scratch_fini(struct radeon_device *rdev);
2605 * r600 cs checking helper
2607 unsigned r600_mip_minify(unsigned size, unsigned level);
2608 bool r600_fmt_is_valid_color(u32 format);
2609 bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
2610 int r600_fmt_get_blocksize(u32 format);
2611 int r600_fmt_get_nblocksx(u32 format, u32 w);
2612 int r600_fmt_get_nblocksy(u32 format, u32 h);
2615 * r600 functions used by radeon_encoder.c
2617 struct radeon_hdmi_acr {
2631 extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
2633 extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
2634 u32 tiling_pipe_num,
2636 u32 total_max_rb_num,
2637 u32 enabled_rb_mask);
2640 * evergreen functions used by radeon_encoder.c
2643 extern int ni_init_microcode(struct radeon_device *rdev);
2644 extern int ni_mc_load_microcode(struct radeon_device *rdev);
2647 #if defined(CONFIG_ACPI)
2648 extern int radeon_acpi_init(struct radeon_device *rdev);
2649 extern void radeon_acpi_fini(struct radeon_device *rdev);
2650 extern bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev);
2651 extern int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
2652 u8 perf_req, bool advertise);
2653 extern int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev);
2655 static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
2656 static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
2659 int radeon_cs_packet_parse(struct radeon_cs_parser *p,
2660 struct radeon_cs_packet *pkt,
2662 bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
2663 void radeon_cs_dump_packet(struct radeon_cs_parser *p,
2664 struct radeon_cs_packet *pkt);
2665 int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
2666 struct radeon_cs_reloc **cs_reloc,
2668 int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
2669 uint32_t *vline_start_end,
2670 uint32_t *vline_status);
2672 #include "radeon_object.h"