blob: ba643b5760542e0e6ad3298464be1e7505995739 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#ifndef __RADEON_H__
29#define __RADEON_H__
30
Jerome Glisse771fe6b2009-06-05 14:42:42 +020031/* TODO: Here are things that needs to be done :
32 * - surface allocator & initializer : (bit like scratch reg) should
33 * initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
34 * related to surface
35 * - WB : write back stuff (do it bit like scratch reg things)
36 * - Vblank : look at Jesse's rework and what we should do
37 * - r600/r700: gart & cp
38 * - cs : clean cs ioctl use bitmap & things like that.
39 * - power management stuff
40 * - Barrier in gart code
41 * - Unmappabled vram ?
42 * - TESTING, TESTING, TESTING
43 */
44
Jerome Glissed39c3b82009-09-28 18:34:43 +020045/* Initialization path:
46 * We expect that acceleration initialization might fail for various
47 * reasons even thought we work hard to make it works on most
48 * configurations. In order to still have a working userspace in such
49 * situation the init path must succeed up to the memory controller
50 * initialization point. Failure before this point are considered as
51 * fatal error. Here is the init callchain :
52 * radeon_device_init perform common structure, mutex initialization
53 * asic_init setup the GPU memory layout and perform all
54 * one time initialization (failure in this
55 * function are considered fatal)
56 * asic_startup setup the GPU acceleration, in order to
57 * follow guideline the first thing this
58 * function should do is setting the GPU
59 * memory controller (only MC setup failure
60 * are considered as fatal)
61 */
62
Jerome Glisse771fe6b2009-06-05 14:42:42 +020063#include <asm/atomic.h>
64#include <linux/wait.h>
65#include <linux/list.h>
66#include <linux/kref.h>
67
Jerome Glisse4c788672009-11-20 14:29:23 +010068#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>
Thomas Hellstrom147666f2010-11-17 12:38:32 +000072#include <ttm/ttm_execbuf_util.h>
Jerome Glisse4c788672009-11-20 14:29:23 +010073
Dave Airliec2142712009-09-22 08:50:10 +100074#include "radeon_family.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020075#include "radeon_mode.h"
76#include "radeon_reg.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020077
78/*
79 * Modules parameters.
80 */
81extern int radeon_no_wb;
82extern int radeon_modeset;
83extern int radeon_dynclks;
84extern int radeon_r4xx_atom;
85extern int radeon_agpmode;
86extern int radeon_vram_limit;
87extern int radeon_gart_size;
88extern int radeon_benchmarking;
Michel Dänzerecc0b322009-07-21 11:23:57 +020089extern int radeon_testing;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020090extern int radeon_connector_table;
Dave Airlie4ce001a2009-08-13 16:32:14 +100091extern int radeon_tv;
Christian Koenigdafc3bd2009-10-11 23:49:13 +020092extern int radeon_audio;
Alex Deucherf46c0122010-03-31 00:33:27 -040093extern int radeon_disp_priority;
Alex Deuchere2b0a8e2010-03-17 02:07:37 -040094extern int radeon_hw_i2c;
Alex Deucherd42dd572011-01-12 20:05:11 -050095extern int radeon_pcie_gen2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020096
97/*
98 * Copy from radeon_drv.h so we don't have to include both and have conflicting
99 * symbol;
100 */
101#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
Jerome Glisse225758d2010-03-09 14:45:10 +0000102#define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
Jerome Glissee8217672010-02-15 21:36:13 +0100103/* RADEON_IB_POOL_SIZE must be a power of 2 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200104#define RADEON_IB_POOL_SIZE 16
105#define RADEON_DEBUGFS_MAX_NUM_FILES 32
106#define RADEONFB_CONN_LIMIT 4
Yang Zhaof657c2a2009-09-15 12:21:01 +1000107#define RADEON_BIOS_NUM_SCRATCH 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200108
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200109/*
110 * Errata workarounds.
111 */
112enum radeon_pll_errata {
113 CHIP_ERRATA_R300_CG = 0x00000001,
114 CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
115 CHIP_ERRATA_PLL_DELAY = 0x00000004
116};
117
118
119struct radeon_device;
120
121
122/*
123 * BIOS.
124 */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000125#define ATRM_BIOS_PAGE 4096
126
Dave Airlie8edb3812010-03-01 21:50:01 +1100127#if defined(CONFIG_VGA_SWITCHEROO)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000128bool radeon_atrm_supported(struct pci_dev *pdev);
129int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
Dave Airlie8edb3812010-03-01 21:50:01 +1100130#else
131static inline bool radeon_atrm_supported(struct pci_dev *pdev)
132{
133 return false;
134}
135
136static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
137 return -EINVAL;
138}
139#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200140bool radeon_get_bios(struct radeon_device *rdev);
141
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000142
143/*
144 * Dummy page
145 */
146struct radeon_dummy_page {
147 struct page *page;
148 dma_addr_t addr;
149};
150int radeon_dummy_page_init(struct radeon_device *rdev);
151void radeon_dummy_page_fini(struct radeon_device *rdev);
152
153
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200154/*
155 * Clocks
156 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200157struct radeon_clock {
158 struct radeon_pll p1pll;
159 struct radeon_pll p2pll;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500160 struct radeon_pll dcpll;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200161 struct radeon_pll spll;
162 struct radeon_pll mpll;
163 /* 10 Khz units */
164 uint32_t default_mclk;
165 uint32_t default_sclk;
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500166 uint32_t default_dispclk;
167 uint32_t dp_extclk;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200168};
169
Rafał Miłecki74338742009-11-03 00:53:02 +0100170/*
171 * Power management
172 */
173int radeon_pm_init(struct radeon_device *rdev);
Alex Deucher29fb52c2010-03-11 10:01:17 -0500174void radeon_pm_fini(struct radeon_device *rdev);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100175void radeon_pm_compute_clocks(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400176void radeon_pm_suspend(struct radeon_device *rdev);
177void radeon_pm_resume(struct radeon_device *rdev);
Alex Deucher56278a82009-12-28 13:58:44 -0500178void radeon_combios_get_power_modes(struct radeon_device *rdev);
179void radeon_atombios_get_power_modes(struct radeon_device *rdev);
Alex Deucher8a83ec52011-04-12 14:49:23 -0400180void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
Alex Deucherf8920342010-06-30 12:02:03 -0400181void rs690_pm_info(struct radeon_device *rdev);
Alex Deucher20d391d2011-02-01 16:12:34 -0500182extern int rv6xx_get_temp(struct radeon_device *rdev);
183extern int rv770_get_temp(struct radeon_device *rdev);
184extern int evergreen_get_temp(struct radeon_device *rdev);
185extern int sumo_get_temp(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000186
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200187/*
188 * Fences.
189 */
190struct radeon_fence_driver {
191 uint32_t scratch_reg;
192 atomic_t seq;
193 uint32_t last_seq;
Jerome Glisse225758d2010-03-09 14:45:10 +0000194 unsigned long last_jiffies;
195 unsigned long last_timeout;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200196 wait_queue_head_t queue;
197 rwlock_t lock;
198 struct list_head created;
199 struct list_head emited;
200 struct list_head signaled;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100201 bool initialized;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200202};
203
204struct radeon_fence {
205 struct radeon_device *rdev;
206 struct kref kref;
207 struct list_head list;
208 /* protected by radeon_fence.lock */
209 uint32_t seq;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200210 bool emited;
211 bool signaled;
212};
213
214int radeon_fence_driver_init(struct radeon_device *rdev);
215void radeon_fence_driver_fini(struct radeon_device *rdev);
216int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
217int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
218void radeon_fence_process(struct radeon_device *rdev);
219bool radeon_fence_signaled(struct radeon_fence *fence);
220int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
221int radeon_fence_wait_next(struct radeon_device *rdev);
222int radeon_fence_wait_last(struct radeon_device *rdev);
223struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
224void radeon_fence_unref(struct radeon_fence **fence);
225
Dave Airliee024e112009-06-24 09:48:08 +1000226/*
227 * Tiling registers
228 */
229struct radeon_surface_reg {
Jerome Glisse4c788672009-11-20 14:29:23 +0100230 struct radeon_bo *bo;
Dave Airliee024e112009-06-24 09:48:08 +1000231};
232
233#define RADEON_GEM_MAX_SURFACES 8
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200234
235/*
Jerome Glisse4c788672009-11-20 14:29:23 +0100236 * TTM.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200237 */
Jerome Glisse4c788672009-11-20 14:29:23 +0100238struct radeon_mman {
239 struct ttm_bo_global_ref bo_global_ref;
Dave Airlieba4420c2010-03-09 10:56:52 +1000240 struct drm_global_reference mem_global_ref;
Jerome Glisse4c788672009-11-20 14:29:23 +0100241 struct ttm_bo_device bdev;
Jerome Glisse0a0c7592009-12-11 20:36:19 +0100242 bool mem_global_referenced;
243 bool initialized;
Jerome Glisse4c788672009-11-20 14:29:23 +0100244};
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200245
Jerome Glisse4c788672009-11-20 14:29:23 +0100246struct radeon_bo {
247 /* Protected by gem.mutex */
248 struct list_head list;
249 /* Protected by tbo.reserved */
Jerome Glisse312ea8d2009-12-07 15:52:58 +0100250 u32 placements[3];
251 struct ttm_placement placement;
Jerome Glisse4c788672009-11-20 14:29:23 +0100252 struct ttm_buffer_object tbo;
253 struct ttm_bo_kmap_obj kmap;
254 unsigned pin_count;
255 void *kptr;
256 u32 tiling_flags;
257 u32 pitch;
258 int surface_reg;
259 /* Constant after initialization */
260 struct radeon_device *rdev;
Daniel Vetter441921d2011-02-18 17:59:16 +0100261 struct drm_gem_object gem_base;
Jerome Glisse4c788672009-11-20 14:29:23 +0100262};
Daniel Vetter7e4d15d2011-02-18 17:59:17 +0100263#define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
Jerome Glisse4c788672009-11-20 14:29:23 +0100264
265struct radeon_bo_list {
Thomas Hellstrom147666f2010-11-17 12:38:32 +0000266 struct ttm_validate_buffer tv;
Jerome Glisse4c788672009-11-20 14:29:23 +0100267 struct radeon_bo *bo;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200268 uint64_t gpu_offset;
269 unsigned rdomain;
270 unsigned wdomain;
Jerome Glisse4c788672009-11-20 14:29:23 +0100271 u32 tiling_flags;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200272};
273
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200274/*
275 * GEM objects.
276 */
277struct radeon_gem {
Jerome Glisse4c788672009-11-20 14:29:23 +0100278 struct mutex mutex;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200279 struct list_head objects;
280};
281
282int radeon_gem_init(struct radeon_device *rdev);
283void radeon_gem_fini(struct radeon_device *rdev);
284int radeon_gem_object_create(struct radeon_device *rdev, int size,
Jerome Glisse4c788672009-11-20 14:29:23 +0100285 int alignment, int initial_domain,
286 bool discardable, bool kernel,
287 struct drm_gem_object **obj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200288int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
289 uint64_t *gpu_addr);
290void radeon_gem_object_unpin(struct drm_gem_object *obj);
291
Dave Airlieff72145b2011-02-07 12:16:14 +1000292int radeon_mode_dumb_create(struct drm_file *file_priv,
293 struct drm_device *dev,
294 struct drm_mode_create_dumb *args);
295int radeon_mode_dumb_mmap(struct drm_file *filp,
296 struct drm_device *dev,
297 uint32_t handle, uint64_t *offset_p);
298int radeon_mode_dumb_destroy(struct drm_file *file_priv,
299 struct drm_device *dev,
300 uint32_t handle);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200301
302/*
303 * GART structures, functions & helpers
304 */
305struct radeon_mc;
306
307struct radeon_gart_table_ram {
308 volatile uint32_t *ptr;
309};
310
311struct radeon_gart_table_vram {
Jerome Glisse4c788672009-11-20 14:29:23 +0100312 struct radeon_bo *robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200313 volatile uint32_t *ptr;
314};
315
316union radeon_gart_table {
317 struct radeon_gart_table_ram ram;
318 struct radeon_gart_table_vram vram;
319};
320
Matt Turnera77f1712009-10-14 00:34:41 -0400321#define RADEON_GPU_PAGE_SIZE 4096
Jerome Glissed594e462010-02-17 21:54:29 +0000322#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
Matt Turnera77f1712009-10-14 00:34:41 -0400323
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200324struct radeon_gart {
325 dma_addr_t table_addr;
326 unsigned num_gpu_pages;
327 unsigned num_cpu_pages;
328 unsigned table_size;
329 union radeon_gart_table table;
330 struct page **pages;
331 dma_addr_t *pages_addr;
Konrad Rzeszutek Wilkc39d3512010-12-02 11:04:29 -0500332 bool *ttm_alloced;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200333 bool ready;
334};
335
336int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
337void radeon_gart_table_ram_free(struct radeon_device *rdev);
338int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
339void radeon_gart_table_vram_free(struct radeon_device *rdev);
340int radeon_gart_init(struct radeon_device *rdev);
341void radeon_gart_fini(struct radeon_device *rdev);
342void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
343 int pages);
344int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
Konrad Rzeszutek Wilkc39d3512010-12-02 11:04:29 -0500345 int pages, struct page **pagelist,
346 dma_addr_t *dma_addr);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200347
348
349/*
350 * GPU MC structures, functions & helpers
351 */
352struct radeon_mc {
353 resource_size_t aper_size;
354 resource_size_t aper_base;
355 resource_size_t agp_base;
Dave Airlie7a50f012009-07-21 20:39:30 +1000356 /* for some chips with <= 32MB we need to lie
357 * about vram size near mc fb location */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000358 u64 mc_vram_size;
Jerome Glissed594e462010-02-17 21:54:29 +0000359 u64 visible_vram_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000360 u64 gtt_size;
361 u64 gtt_start;
362 u64 gtt_end;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000363 u64 vram_start;
364 u64 vram_end;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200365 unsigned vram_width;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000366 u64 real_vram_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200367 int vram_mtrr;
368 bool vram_is_ddr;
Jerome Glissed594e462010-02-17 21:54:29 +0000369 bool igp_sideport_enabled;
Alex Deucher8d369bb2010-07-15 10:51:10 -0400370 u64 gtt_base_align;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200371};
372
Alex Deucher06b64762010-01-05 11:27:29 -0500373bool radeon_combios_sideport_present(struct radeon_device *rdev);
374bool radeon_atombios_sideport_present(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200375
376/*
377 * GPU scratch registers structures, functions & helpers
378 */
379struct radeon_scratch {
380 unsigned num_reg;
Alex Deucher724c80e2010-08-27 18:25:25 -0400381 uint32_t reg_base;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200382 bool free[32];
383 uint32_t reg[32];
384};
385
386int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
387void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
388
389
390/*
391 * IRQS.
392 */
Alex Deucher6f34be52010-11-21 10:59:01 -0500393
394struct radeon_unpin_work {
395 struct work_struct work;
396 struct radeon_device *rdev;
397 int crtc_id;
398 struct radeon_fence *fence;
399 struct drm_pending_vblank_event *event;
400 struct radeon_bo *old_rbo;
401 u64 new_crtc_base;
402};
403
404struct r500_irq_stat_regs {
405 u32 disp_int;
406};
407
408struct r600_irq_stat_regs {
409 u32 disp_int;
410 u32 disp_int_cont;
411 u32 disp_int_cont2;
412 u32 d1grph_int;
413 u32 d2grph_int;
414};
415
416struct evergreen_irq_stat_regs {
417 u32 disp_int;
418 u32 disp_int_cont;
419 u32 disp_int_cont2;
420 u32 disp_int_cont3;
421 u32 disp_int_cont4;
422 u32 disp_int_cont5;
423 u32 d1grph_int;
424 u32 d2grph_int;
425 u32 d3grph_int;
426 u32 d4grph_int;
427 u32 d5grph_int;
428 u32 d6grph_int;
429};
430
431union radeon_irq_stat_regs {
432 struct r500_irq_stat_regs r500;
433 struct r600_irq_stat_regs r600;
434 struct evergreen_irq_stat_regs evergreen;
435};
436
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200437struct radeon_irq {
438 bool installed;
439 bool sw_int;
440 /* FIXME: use a define max crtc rather than hardcode it */
Alex Deucher45f9a392010-03-24 13:55:51 -0400441 bool crtc_vblank_int[6];
Alex Deucher6f34be52010-11-21 10:59:01 -0500442 bool pflip[6];
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100443 wait_queue_head_t vblank_queue;
Alex Deucherb500f682009-12-03 13:08:53 -0500444 /* FIXME: use defines for max hpd/dacs */
445 bool hpd[6];
Alex Deucher2031f772010-04-22 12:52:11 -0400446 bool gui_idle;
447 bool gui_idle_acked;
448 wait_queue_head_t idle_queue;
Christian Koenigf2594932010-04-10 03:13:16 +0200449 /* FIXME: use defines for max HDMI blocks */
450 bool hdmi[2];
Dave Airlie1614f8b2009-12-01 16:04:56 +1000451 spinlock_t sw_lock;
452 int sw_refcount;
Alex Deucher6f34be52010-11-21 10:59:01 -0500453 union radeon_irq_stat_regs stat_regs;
454 spinlock_t pflip_lock[6];
455 int pflip_refcount[6];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200456};
457
458int radeon_irq_kms_init(struct radeon_device *rdev);
459void radeon_irq_kms_fini(struct radeon_device *rdev);
Dave Airlie1614f8b2009-12-01 16:04:56 +1000460void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
461void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
Alex Deucher6f34be52010-11-21 10:59:01 -0500462void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
463void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200464
465/*
466 * CP & ring.
467 */
468struct radeon_ib {
469 struct list_head list;
Jerome Glissee8217672010-02-15 21:36:13 +0100470 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200471 uint64_t gpu_addr;
472 struct radeon_fence *fence;
Jerome Glissee8217672010-02-15 21:36:13 +0100473 uint32_t *ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200474 uint32_t length_dw;
Jerome Glissee8217672010-02-15 21:36:13 +0100475 bool free;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200476};
477
Dave Airlieecb114a2009-09-15 11:12:56 +1000478/*
479 * locking -
480 * mutex protects scheduled_ibs, ready, alloc_bm
481 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200482struct radeon_ib_pool {
483 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100484 struct radeon_bo *robj;
Jerome Glisse9f93ed32010-01-28 18:22:31 +0100485 struct list_head bogus_ib;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200486 struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
487 bool ready;
Jerome Glissee8217672010-02-15 21:36:13 +0100488 unsigned head_id;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200489};
490
491struct radeon_cp {
Jerome Glisse4c788672009-11-20 14:29:23 +0100492 struct radeon_bo *ring_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200493 volatile uint32_t *ring;
494 unsigned rptr;
495 unsigned wptr;
496 unsigned wptr_old;
497 unsigned ring_size;
498 unsigned ring_free_dw;
499 int count_dw;
500 uint64_t gpu_addr;
501 uint32_t align_mask;
502 uint32_t ptr_mask;
503 struct mutex mutex;
504 bool ready;
505};
506
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500507/*
508 * R6xx+ IH ring
509 */
510struct r600_ih {
Jerome Glisse4c788672009-11-20 14:29:23 +0100511 struct radeon_bo *ring_obj;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500512 volatile uint32_t *ring;
513 unsigned rptr;
514 unsigned wptr;
515 unsigned wptr_old;
516 unsigned ring_size;
517 uint64_t gpu_addr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500518 uint32_t ptr_mask;
519 spinlock_t lock;
520 bool enabled;
521};
522
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000523struct r600_blit {
Jerome Glisseff82f052010-01-22 15:19:00 +0100524 struct mutex mutex;
Jerome Glisse4c788672009-11-20 14:29:23 +0100525 struct radeon_bo *shader_obj;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000526 u64 shader_gpu_addr;
527 u32 vs_offset, ps_offset;
528 u32 state_offset;
529 u32 state_len;
530 u32 vb_used, vb_total;
531 struct radeon_ib *vb_ib;
532};
533
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200534int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
535void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
536int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
537int radeon_ib_pool_init(struct radeon_device *rdev);
538void radeon_ib_pool_fini(struct radeon_device *rdev);
539int radeon_ib_test(struct radeon_device *rdev);
Jerome Glisse9f93ed32010-01-28 18:22:31 +0100540extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200541/* Ring access between begin & end cannot sleep */
542void radeon_ring_free_size(struct radeon_device *rdev);
Matthew Garrett91700f32010-04-30 15:24:17 -0400543int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200544int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
Matthew Garrett91700f32010-04-30 15:24:17 -0400545void radeon_ring_commit(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200546void radeon_ring_unlock_commit(struct radeon_device *rdev);
547void radeon_ring_unlock_undo(struct radeon_device *rdev);
548int radeon_ring_test(struct radeon_device *rdev);
549int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
550void radeon_ring_fini(struct radeon_device *rdev);
551
552
553/*
554 * CS.
555 */
556struct radeon_cs_reloc {
557 struct drm_gem_object *gobj;
Jerome Glisse4c788672009-11-20 14:29:23 +0100558 struct radeon_bo *robj;
559 struct radeon_bo_list lobj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200560 uint32_t handle;
561 uint32_t flags;
562};
563
564struct radeon_cs_chunk {
565 uint32_t chunk_id;
566 uint32_t length_dw;
Dave Airlie513bcb42009-09-23 16:56:27 +1000567 int kpage_idx[2];
568 uint32_t *kpage[2];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200569 uint32_t *kdata;
Dave Airlie513bcb42009-09-23 16:56:27 +1000570 void __user *user_ptr;
571 int last_copied_page;
572 int last_page_index;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200573};
574
575struct radeon_cs_parser {
Jerome Glissec8c15ff2010-01-18 13:01:36 +0100576 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200577 struct radeon_device *rdev;
578 struct drm_file *filp;
579 /* chunks */
580 unsigned nchunks;
581 struct radeon_cs_chunk *chunks;
582 uint64_t *chunks_array;
583 /* IB */
584 unsigned idx;
585 /* relocations */
586 unsigned nrelocs;
587 struct radeon_cs_reloc *relocs;
588 struct radeon_cs_reloc **relocs_ptr;
589 struct list_head validated;
590 /* indices of various chunks */
591 int chunk_ib_idx;
592 int chunk_relocs_idx;
593 struct radeon_ib *ib;
594 void *track;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000595 unsigned family;
Dave Airlie513bcb42009-09-23 16:56:27 +1000596 int parser_error;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200597};
598
Dave Airlie513bcb42009-09-23 16:56:27 +1000599extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
600extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
601
602
603static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
604{
605 struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
606 u32 pg_idx, pg_offset;
607 u32 idx_value = 0;
608 int new_page;
609
610 pg_idx = (idx * 4) / PAGE_SIZE;
611 pg_offset = (idx * 4) % PAGE_SIZE;
612
613 if (ibc->kpage_idx[0] == pg_idx)
614 return ibc->kpage[0][pg_offset/4];
615 if (ibc->kpage_idx[1] == pg_idx)
616 return ibc->kpage[1][pg_offset/4];
617
618 new_page = radeon_cs_update_pages(p, pg_idx);
619 if (new_page < 0) {
620 p->parser_error = new_page;
621 return 0;
622 }
623
624 idx_value = ibc->kpage[new_page][pg_offset/4];
625 return idx_value;
626}
627
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200628struct radeon_cs_packet {
629 unsigned idx;
630 unsigned type;
631 unsigned reg;
632 unsigned opcode;
633 int count;
634 unsigned one_reg_wr;
635};
636
637typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
638 struct radeon_cs_packet *pkt,
639 unsigned idx, unsigned reg);
640typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
641 struct radeon_cs_packet *pkt);
642
643
644/*
645 * AGP
646 */
647int radeon_agp_init(struct radeon_device *rdev);
Dave Airlie0ebf1712009-11-05 15:39:10 +1000648void radeon_agp_resume(struct radeon_device *rdev);
Jerome Glisse10b06122010-05-21 18:48:54 +0200649void radeon_agp_suspend(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200650void radeon_agp_fini(struct radeon_device *rdev);
651
652
653/*
654 * Writeback
655 */
656struct radeon_wb {
Jerome Glisse4c788672009-11-20 14:29:23 +0100657 struct radeon_bo *wb_obj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200658 volatile uint32_t *wb;
659 uint64_t gpu_addr;
Alex Deucher724c80e2010-08-27 18:25:25 -0400660 bool enabled;
Alex Deucherd0f8a852010-09-04 05:04:34 -0400661 bool use_event;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200662};
663
Alex Deucher724c80e2010-08-27 18:25:25 -0400664#define RADEON_WB_SCRATCH_OFFSET 0
665#define RADEON_WB_CP_RPTR_OFFSET 1024
Alex Deucher0c88a022011-03-02 20:07:31 -0500666#define RADEON_WB_CP1_RPTR_OFFSET 1280
667#define RADEON_WB_CP2_RPTR_OFFSET 1536
Alex Deucher724c80e2010-08-27 18:25:25 -0400668#define R600_WB_IH_WPTR_OFFSET 2048
Alex Deucherd0f8a852010-09-04 05:04:34 -0400669#define R600_WB_EVENT_OFFSET 3072
Alex Deucher724c80e2010-08-27 18:25:25 -0400670
Jerome Glissec93bb852009-07-13 21:04:08 +0200671/**
672 * struct radeon_pm - power management datas
673 * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
674 * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
675 * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
676 * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
677 * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
678 * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
679 * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
680 * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
681 * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300682 * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
Jerome Glissec93bb852009-07-13 21:04:08 +0200683 * @needed_bandwidth: current bandwidth needs
684 *
685 * It keeps track of various data needed to take powermanagement decision.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300686 * Bandwidth need is used to determine minimun clock of the GPU and memory.
Jerome Glissec93bb852009-07-13 21:04:08 +0200687 * Equation between gpu/memory clock and available bandwidth is hw dependent
688 * (type of memory, bus size, efficiency, ...)
689 */
Alex Deucherce8f5372010-05-07 15:10:16 -0400690
691enum radeon_pm_method {
692 PM_METHOD_PROFILE,
693 PM_METHOD_DYNPM,
Rafał Miłeckic913e232009-12-22 23:02:16 +0100694};
Alex Deucherce8f5372010-05-07 15:10:16 -0400695
696enum radeon_dynpm_state {
697 DYNPM_STATE_DISABLED,
698 DYNPM_STATE_MINIMUM,
699 DYNPM_STATE_PAUSED,
Rafael J. Wysocki3f53eb62010-06-17 23:02:27 +0000700 DYNPM_STATE_ACTIVE,
701 DYNPM_STATE_SUSPENDED,
Alex Deucherce8f5372010-05-07 15:10:16 -0400702};
703enum radeon_dynpm_action {
704 DYNPM_ACTION_NONE,
705 DYNPM_ACTION_MINIMUM,
706 DYNPM_ACTION_DOWNCLOCK,
707 DYNPM_ACTION_UPCLOCK,
708 DYNPM_ACTION_DEFAULT
Rafał Miłeckic913e232009-12-22 23:02:16 +0100709};
Alex Deucher56278a82009-12-28 13:58:44 -0500710
711enum radeon_voltage_type {
712 VOLTAGE_NONE = 0,
713 VOLTAGE_GPIO,
714 VOLTAGE_VDDC,
715 VOLTAGE_SW
716};
717
Alex Deucher0ec0e742009-12-23 13:21:58 -0500718enum radeon_pm_state_type {
719 POWER_STATE_TYPE_DEFAULT,
720 POWER_STATE_TYPE_POWERSAVE,
721 POWER_STATE_TYPE_BATTERY,
722 POWER_STATE_TYPE_BALANCED,
723 POWER_STATE_TYPE_PERFORMANCE,
724};
725
Alex Deucherce8f5372010-05-07 15:10:16 -0400726enum radeon_pm_profile_type {
727 PM_PROFILE_DEFAULT,
728 PM_PROFILE_AUTO,
729 PM_PROFILE_LOW,
Alex Deucherc9e75b22010-06-02 17:56:01 -0400730 PM_PROFILE_MID,
Alex Deucherce8f5372010-05-07 15:10:16 -0400731 PM_PROFILE_HIGH,
732};
733
734#define PM_PROFILE_DEFAULT_IDX 0
735#define PM_PROFILE_LOW_SH_IDX 1
Alex Deucherc9e75b22010-06-02 17:56:01 -0400736#define PM_PROFILE_MID_SH_IDX 2
737#define PM_PROFILE_HIGH_SH_IDX 3
738#define PM_PROFILE_LOW_MH_IDX 4
739#define PM_PROFILE_MID_MH_IDX 5
740#define PM_PROFILE_HIGH_MH_IDX 6
741#define PM_PROFILE_MAX 7
Alex Deucherce8f5372010-05-07 15:10:16 -0400742
743struct radeon_pm_profile {
744 int dpms_off_ps_idx;
745 int dpms_on_ps_idx;
746 int dpms_off_cm_idx;
747 int dpms_on_cm_idx;
Alex Deucher516d0e42009-12-23 14:28:05 -0500748};
749
Alex Deucher21a81222010-07-02 12:58:16 -0400750enum radeon_int_thermal_type {
751 THERMAL_TYPE_NONE,
752 THERMAL_TYPE_RV6XX,
753 THERMAL_TYPE_RV770,
754 THERMAL_TYPE_EVERGREEN,
Alex Deuchere33df252010-11-22 17:56:32 -0500755 THERMAL_TYPE_SUMO,
Alex Deucher4fddba12011-01-06 21:19:22 -0500756 THERMAL_TYPE_NI,
Alex Deucher21a81222010-07-02 12:58:16 -0400757};
758
Alex Deucher56278a82009-12-28 13:58:44 -0500759struct radeon_voltage {
760 enum radeon_voltage_type type;
761 /* gpio voltage */
762 struct radeon_gpio_rec gpio;
763 u32 delay; /* delay in usec from voltage drop to sclk change */
764 bool active_high; /* voltage drop is active when bit is high */
765 /* VDDC voltage */
766 u8 vddc_id; /* index into vddc voltage table */
767 u8 vddci_id; /* index into vddci voltage table */
768 bool vddci_enabled;
769 /* r6xx+ sw */
Alex Deucher2feea492011-04-12 14:49:24 -0400770 u16 voltage;
771 /* evergreen+ vddci */
772 u16 vddci;
Alex Deucher56278a82009-12-28 13:58:44 -0500773};
774
Alex Deucherd7311172010-05-03 01:13:14 -0400775/* clock mode flags */
776#define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
777
Alex Deucher56278a82009-12-28 13:58:44 -0500778struct radeon_pm_clock_info {
779 /* memory clock */
780 u32 mclk;
781 /* engine clock */
782 u32 sclk;
783 /* voltage info */
784 struct radeon_voltage voltage;
Alex Deucherd7311172010-05-03 01:13:14 -0400785 /* standardized clock flags */
Alex Deucher56278a82009-12-28 13:58:44 -0500786 u32 flags;
787};
788
Alex Deuchera48b9b42010-04-22 14:03:55 -0400789/* state flags */
Alex Deucherd7311172010-05-03 01:13:14 -0400790#define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400791
Alex Deucher56278a82009-12-28 13:58:44 -0500792struct radeon_power_state {
Alex Deucher0ec0e742009-12-23 13:21:58 -0500793 enum radeon_pm_state_type type;
Alex Deucher56278a82009-12-28 13:58:44 -0500794 /* XXX: use a define for num clock modes */
795 struct radeon_pm_clock_info clock_info[8];
796 /* number of valid clock modes in this power state */
797 int num_clock_modes;
Alex Deucher56278a82009-12-28 13:58:44 -0500798 struct radeon_pm_clock_info *default_clock_mode;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400799 /* standardized state flags */
800 u32 flags;
Alex Deucher79daedc2010-04-22 14:25:19 -0400801 u32 misc; /* vbios specific flags */
802 u32 misc2; /* vbios specific flags */
803 int pcie_lanes; /* pcie lanes */
Alex Deucher56278a82009-12-28 13:58:44 -0500804};
805
Rafał Miłecki27459322010-02-11 22:16:36 +0000806/*
807 * Some modes are overclocked by very low value, accept them
808 */
809#define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
810
Jerome Glissec93bb852009-07-13 21:04:08 +0200811struct radeon_pm {
Rafał Miłeckic913e232009-12-22 23:02:16 +0100812 struct mutex mutex;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400813 u32 active_crtcs;
814 int active_crtc_count;
Rafał Miłeckic913e232009-12-22 23:02:16 +0100815 int req_vblank;
Rafał Miłecki839461d2010-03-02 22:06:51 +0100816 bool vblank_sync;
Alex Deucher2031f772010-04-22 12:52:11 -0400817 bool gui_idle;
Jerome Glissec93bb852009-07-13 21:04:08 +0200818 fixed20_12 max_bandwidth;
819 fixed20_12 igp_sideport_mclk;
820 fixed20_12 igp_system_mclk;
821 fixed20_12 igp_ht_link_clk;
822 fixed20_12 igp_ht_link_width;
823 fixed20_12 k8_bandwidth;
824 fixed20_12 sideport_bandwidth;
825 fixed20_12 ht_bandwidth;
826 fixed20_12 core_bandwidth;
827 fixed20_12 sclk;
Alex Deucherf47299c2010-03-16 20:54:38 -0400828 fixed20_12 mclk;
Jerome Glissec93bb852009-07-13 21:04:08 +0200829 fixed20_12 needed_bandwidth;
Alex Deucher0975b162011-02-02 18:42:03 -0500830 struct radeon_power_state *power_state;
Alex Deucher56278a82009-12-28 13:58:44 -0500831 /* number of valid power states */
832 int num_power_states;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400833 int current_power_state_index;
834 int current_clock_mode_index;
835 int requested_power_state_index;
836 int requested_clock_mode_index;
837 int default_power_state_index;
838 u32 current_sclk;
839 u32 current_mclk;
Alex Deucher2feea492011-04-12 14:49:24 -0400840 u16 current_vddc;
841 u16 current_vddci;
Alex Deucher9ace9f72011-01-06 21:19:26 -0500842 u32 default_sclk;
843 u32 default_mclk;
Alex Deucher2feea492011-04-12 14:49:24 -0400844 u16 default_vddc;
845 u16 default_vddci;
Alex Deucher29fb52c2010-03-11 10:01:17 -0500846 struct radeon_i2c_chan *i2c_bus;
Alex Deucherce8f5372010-05-07 15:10:16 -0400847 /* selected pm method */
848 enum radeon_pm_method pm_method;
849 /* dynpm power management */
850 struct delayed_work dynpm_idle_work;
851 enum radeon_dynpm_state dynpm_state;
852 enum radeon_dynpm_action dynpm_planned_action;
853 unsigned long dynpm_action_timeout;
854 bool dynpm_can_upclock;
855 bool dynpm_can_downclock;
856 /* profile-based power management */
857 enum radeon_pm_profile_type profile;
858 int profile_index;
859 struct radeon_pm_profile profiles[PM_PROFILE_MAX];
Alex Deucher21a81222010-07-02 12:58:16 -0400860 /* internal thermal controller on rv6xx+ */
861 enum radeon_int_thermal_type int_thermal_type;
862 struct device *int_hwmon_dev;
Jerome Glissec93bb852009-07-13 21:04:08 +0200863};
864
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200865
866/*
867 * Benchmarking
868 */
869void radeon_benchmark(struct radeon_device *rdev);
870
871
872/*
Michel Dänzerecc0b322009-07-21 11:23:57 +0200873 * Testing
874 */
875void radeon_test_moves(struct radeon_device *rdev);
876
877
878/*
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200879 * Debugfs
880 */
881int radeon_debugfs_add_files(struct radeon_device *rdev,
882 struct drm_info_list *files,
883 unsigned nfiles);
884int radeon_debugfs_fence_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200885
886
887/*
888 * ASIC specific functions.
889 */
890struct radeon_asic {
Jerome Glisse068a1172009-06-17 13:28:30 +0200891 int (*init)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000892 void (*fini)(struct radeon_device *rdev);
893 int (*resume)(struct radeon_device *rdev);
894 int (*suspend)(struct radeon_device *rdev);
Dave Airlie28d52042009-09-21 14:33:58 +1000895 void (*vga_set_state)(struct radeon_device *rdev, bool state);
Jerome Glisse225758d2010-03-09 14:45:10 +0000896 bool (*gpu_is_lockup)(struct radeon_device *rdev);
Jerome Glissea2d07b72010-03-09 14:45:11 +0000897 int (*asic_reset)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200898 void (*gart_tlb_flush)(struct radeon_device *rdev);
899 int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
900 int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
901 void (*cp_fini)(struct radeon_device *rdev);
902 void (*cp_disable)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000903 void (*cp_commit)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200904 void (*ring_start)(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000905 int (*ring_test)(struct radeon_device *rdev);
906 void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200907 int (*irq_set)(struct radeon_device *rdev);
908 int (*irq_process)(struct radeon_device *rdev);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200909 u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200910 void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
911 int (*cs_parse)(struct radeon_cs_parser *p);
912 int (*copy_blit)(struct radeon_device *rdev,
913 uint64_t src_offset,
914 uint64_t dst_offset,
915 unsigned num_pages,
916 struct radeon_fence *fence);
917 int (*copy_dma)(struct radeon_device *rdev,
918 uint64_t src_offset,
919 uint64_t dst_offset,
920 unsigned num_pages,
921 struct radeon_fence *fence);
922 int (*copy)(struct radeon_device *rdev,
923 uint64_t src_offset,
924 uint64_t dst_offset,
925 unsigned num_pages,
926 struct radeon_fence *fence);
Rafał Miłecki74338742009-11-03 00:53:02 +0100927 uint32_t (*get_engine_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200928 void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
Rafał Miłecki74338742009-11-03 00:53:02 +0100929 uint32_t (*get_memory_clock)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200930 void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
Alex Deucherc836a412009-12-23 10:07:50 -0500931 int (*get_pcie_lanes)(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200932 void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
933 void (*set_clock_gating)(struct radeon_device *rdev, int enable);
Dave Airliee024e112009-06-24 09:48:08 +1000934 int (*set_surface_reg)(struct radeon_device *rdev, int reg,
935 uint32_t tiling_flags, uint32_t pitch,
936 uint32_t offset, uint32_t obj_size);
Daniel Vetter9479c542010-03-11 21:19:16 +0000937 void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
Jerome Glissec93bb852009-07-13 21:04:08 +0200938 void (*bandwidth_update)(struct radeon_device *rdev);
Alex Deucher429770b2009-12-04 15:26:55 -0500939 void (*hpd_init)(struct radeon_device *rdev);
940 void (*hpd_fini)(struct radeon_device *rdev);
941 bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
942 void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
Jerome Glisse062b3892010-02-04 20:36:39 +0100943 /* ioctl hw specific callback. Some hw might want to perform special
944 * operation on specific ioctl. For instance on wait idle some hw
945 * might want to perform and HDP flush through MMIO as it seems that
946 * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
947 * through ring.
948 */
949 void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
Alex Deucherdef9ba92010-04-22 12:39:58 -0400950 bool (*gui_idle)(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400951 /* power management */
Alex Deucher49e02b72010-04-23 17:57:27 -0400952 void (*pm_misc)(struct radeon_device *rdev);
953 void (*pm_prepare)(struct radeon_device *rdev);
954 void (*pm_finish)(struct radeon_device *rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400955 void (*pm_init_profile)(struct radeon_device *rdev);
956 void (*pm_get_dynpm_state)(struct radeon_device *rdev);
Alex Deucher6f34be52010-11-21 10:59:01 -0500957 /* pageflipping */
958 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
959 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
960 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200961};
962
Jerome Glisse21f9a432009-09-11 15:55:33 +0200963/*
964 * Asic structures
965 */
Jerome Glisse225758d2010-03-09 14:45:10 +0000966struct r100_gpu_lockup {
967 unsigned long last_jiffies;
968 u32 last_cp_rptr;
969};
970
Dave Airlie551ebd82009-09-01 15:25:57 +1000971struct r100_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000972 const unsigned *reg_safe_bm;
973 unsigned reg_safe_bm_size;
974 u32 hdp_cntl;
975 struct r100_gpu_lockup lockup;
Dave Airlie551ebd82009-09-01 15:25:57 +1000976};
977
Jerome Glisse21f9a432009-09-11 15:55:33 +0200978struct r300_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000979 const unsigned *reg_safe_bm;
980 unsigned reg_safe_bm_size;
981 u32 resync_scratch;
982 u32 hdp_cntl;
983 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +0200984};
985
986struct r600_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +0000987 unsigned max_pipes;
988 unsigned max_tile_pipes;
989 unsigned max_simds;
990 unsigned max_backends;
991 unsigned max_gprs;
992 unsigned max_threads;
993 unsigned max_stack_entries;
994 unsigned max_hw_contexts;
995 unsigned max_gs_threads;
996 unsigned sx_max_export_size;
997 unsigned sx_max_export_pos_size;
998 unsigned sx_max_export_smx_size;
999 unsigned sq_num_cf_insts;
1000 unsigned tiling_nbanks;
1001 unsigned tiling_npipes;
1002 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001003 unsigned tile_config;
Jerome Glisse225758d2010-03-09 14:45:10 +00001004 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +02001005};
1006
1007struct rv770_asic {
Jerome Glisse225758d2010-03-09 14:45:10 +00001008 unsigned max_pipes;
1009 unsigned max_tile_pipes;
1010 unsigned max_simds;
1011 unsigned max_backends;
1012 unsigned max_gprs;
1013 unsigned max_threads;
1014 unsigned max_stack_entries;
1015 unsigned max_hw_contexts;
1016 unsigned max_gs_threads;
1017 unsigned sx_max_export_size;
1018 unsigned sx_max_export_pos_size;
1019 unsigned sx_max_export_smx_size;
1020 unsigned sq_num_cf_insts;
1021 unsigned sx_num_of_sets;
1022 unsigned sc_prim_fifo_size;
1023 unsigned sc_hiz_tile_fifo_size;
1024 unsigned sc_earlyz_tile_fifo_fize;
1025 unsigned tiling_nbanks;
1026 unsigned tiling_npipes;
1027 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001028 unsigned tile_config;
Jerome Glisse225758d2010-03-09 14:45:10 +00001029 struct r100_gpu_lockup lockup;
Jerome Glisse21f9a432009-09-11 15:55:33 +02001030};
1031
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001032struct evergreen_asic {
1033 unsigned num_ses;
1034 unsigned max_pipes;
1035 unsigned max_tile_pipes;
1036 unsigned max_simds;
1037 unsigned max_backends;
1038 unsigned max_gprs;
1039 unsigned max_threads;
1040 unsigned max_stack_entries;
1041 unsigned max_hw_contexts;
1042 unsigned max_gs_threads;
1043 unsigned sx_max_export_size;
1044 unsigned sx_max_export_pos_size;
1045 unsigned sx_max_export_smx_size;
1046 unsigned sq_num_cf_insts;
1047 unsigned sx_num_of_sets;
1048 unsigned sc_prim_fifo_size;
1049 unsigned sc_hiz_tile_fifo_size;
1050 unsigned sc_earlyz_tile_fifo_size;
1051 unsigned tiling_nbanks;
1052 unsigned tiling_npipes;
1053 unsigned tiling_group_size;
Alex Deuchere7aeeba2010-06-04 13:10:12 -04001054 unsigned tile_config;
Alex Deucher17db7042010-12-21 16:05:39 -05001055 struct r100_gpu_lockup lockup;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001056};
1057
Alex Deucherfecf1d02011-03-02 20:07:29 -05001058struct cayman_asic {
1059 unsigned max_shader_engines;
1060 unsigned max_pipes_per_simd;
1061 unsigned max_tile_pipes;
1062 unsigned max_simds_per_se;
1063 unsigned max_backends_per_se;
1064 unsigned max_texture_channel_caches;
1065 unsigned max_gprs;
1066 unsigned max_threads;
1067 unsigned max_gs_threads;
1068 unsigned max_stack_entries;
1069 unsigned sx_num_of_sets;
1070 unsigned sx_max_export_size;
1071 unsigned sx_max_export_pos_size;
1072 unsigned sx_max_export_smx_size;
1073 unsigned max_hw_contexts;
1074 unsigned sq_num_cf_insts;
1075 unsigned sc_prim_fifo_size;
1076 unsigned sc_hiz_tile_fifo_size;
1077 unsigned sc_earlyz_tile_fifo_size;
1078
1079 unsigned num_shader_engines;
1080 unsigned num_shader_pipes_per_simd;
1081 unsigned num_tile_pipes;
1082 unsigned num_simds_per_se;
1083 unsigned num_backends_per_se;
1084 unsigned backend_disable_mask_per_asic;
1085 unsigned backend_map;
1086 unsigned num_texture_channel_caches;
1087 unsigned mem_max_burst_length_bytes;
1088 unsigned mem_row_size_in_kb;
1089 unsigned shader_engine_tile_size;
1090 unsigned num_gpus;
1091 unsigned multi_gpu_tile_size;
1092
1093 unsigned tile_config;
1094 struct r100_gpu_lockup lockup;
1095};
1096
Jerome Glisse068a1172009-06-17 13:28:30 +02001097union radeon_asic_config {
1098 struct r300_asic r300;
Dave Airlie551ebd82009-09-01 15:25:57 +10001099 struct r100_asic r100;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001100 struct r600_asic r600;
1101 struct rv770_asic rv770;
Alex Deucher32fcdbf2010-03-24 13:33:47 -04001102 struct evergreen_asic evergreen;
Alex Deucherfecf1d02011-03-02 20:07:29 -05001103 struct cayman_asic cayman;
Jerome Glisse068a1172009-06-17 13:28:30 +02001104};
1105
Daniel Vetter0a10c852010-03-11 21:19:14 +00001106/*
1107 * asic initizalization from radeon_asic.c
1108 */
1109void radeon_agp_disable(struct radeon_device *rdev);
1110int radeon_asic_init(struct radeon_device *rdev);
1111
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001112
1113/*
1114 * IOCTL.
1115 */
1116int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
1117 struct drm_file *filp);
1118int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
1119 struct drm_file *filp);
1120int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
1121 struct drm_file *file_priv);
1122int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
1123 struct drm_file *file_priv);
1124int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
1125 struct drm_file *file_priv);
1126int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
1127 struct drm_file *file_priv);
1128int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1129 struct drm_file *filp);
1130int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
1131 struct drm_file *filp);
1132int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
1133 struct drm_file *filp);
1134int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1135 struct drm_file *filp);
1136int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Dave Airliee024e112009-06-24 09:48:08 +10001137int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1138 struct drm_file *filp);
1139int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1140 struct drm_file *filp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001142/* VRAM scratch page for HDP bug */
1143struct r700_vram_scratch {
1144 struct radeon_bo *robj;
1145 volatile uint32_t *ptr;
1146};
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001147
1148/*
1149 * Core structure, functions and helpers.
1150 */
1151typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
1152typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
1153
1154struct radeon_device {
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001155 struct device *dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001156 struct drm_device *ddev;
1157 struct pci_dev *pdev;
1158 /* ASIC */
Jerome Glisse068a1172009-06-17 13:28:30 +02001159 union radeon_asic_config config;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001160 enum radeon_family family;
1161 unsigned long flags;
1162 int usec_timeout;
1163 enum radeon_pll_errata pll_errata;
1164 int num_gb_pipes;
Alex Deucherf779b3e2009-08-19 19:11:39 -04001165 int num_z_pipes;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001166 int disp_priority;
1167 /* BIOS */
1168 uint8_t *bios;
1169 bool is_atom_bios;
1170 uint16_t bios_header_start;
Jerome Glisse4c788672009-11-20 14:29:23 +01001171 struct radeon_bo *stollen_vga_memory;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001172 /* Register mmio */
Dave Airlie4c9bc752009-06-29 18:29:12 +10001173 resource_size_t rmmio_base;
1174 resource_size_t rmmio_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001175 void *rmmio;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 radeon_rreg_t mc_rreg;
1177 radeon_wreg_t mc_wreg;
1178 radeon_rreg_t pll_rreg;
1179 radeon_wreg_t pll_wreg;
Dave Airliede1b2892009-08-12 18:43:14 +10001180 uint32_t pcie_reg_mask;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001181 radeon_rreg_t pciep_rreg;
1182 radeon_wreg_t pciep_wreg;
Alex Deucher351a52a2010-06-30 11:52:50 -04001183 /* io port */
1184 void __iomem *rio_mem;
1185 resource_size_t rio_mem_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001186 struct radeon_clock clock;
1187 struct radeon_mc mc;
1188 struct radeon_gart gart;
1189 struct radeon_mode_info mode_info;
1190 struct radeon_scratch scratch;
1191 struct radeon_mman mman;
1192 struct radeon_fence_driver fence_drv;
1193 struct radeon_cp cp;
Alex Deucher0c88a022011-03-02 20:07:31 -05001194 /* cayman compute rings */
1195 struct radeon_cp cp1;
1196 struct radeon_cp cp2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001197 struct radeon_ib_pool ib_pool;
1198 struct radeon_irq irq;
1199 struct radeon_asic *asic;
1200 struct radeon_gem gem;
Jerome Glissec93bb852009-07-13 21:04:08 +02001201 struct radeon_pm pm;
Yang Zhaof657c2a2009-09-15 12:21:01 +10001202 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001203 struct mutex cs_mutex;
1204 struct radeon_wb wb;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001205 struct radeon_dummy_page dummy_page;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001206 bool gpu_lockup;
1207 bool shutdown;
1208 bool suspend;
Dave Airliead49f502009-07-10 22:36:26 +10001209 bool need_dma32;
Jerome Glisse733289c2009-09-16 15:24:21 +02001210 bool accel_working;
Dave Airliee024e112009-06-24 09:48:08 +10001211 struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001212 const struct firmware *me_fw; /* all family ME firmware */
1213 const struct firmware *pfp_fw; /* r6/700 PFP firmware */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001214 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
Alex Deucher0af62b02011-01-06 21:19:31 -05001215 const struct firmware *mc_fw; /* NI MC firmware */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001216 struct r600_blit r600_blit;
Alex Deucher87cbf8f2010-08-27 13:59:54 -04001217 struct r700_vram_scratch vram_scratch;
Alex Deucher3e5cb982009-10-16 12:21:24 -04001218 int msi_enabled; /* msi enabled */
Alex Deucherd8f60cf2009-12-01 13:43:46 -05001219 struct r600_ih ih; /* r6/700 interrupt ring */
Alex Deucherd4877cf2009-12-04 16:56:37 -05001220 struct work_struct hotplug_work;
Alex Deucher18917b62010-02-01 16:02:25 -05001221 int num_crtc; /* number of crtcs */
Alex Deucher40bacf12009-12-23 03:23:21 -05001222 struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
Matthew Garrett5876dd22010-04-26 15:52:20 -04001223 struct mutex vram_mutex;
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001224
1225 /* audio stuff */
Rafał Miłecki7eea7e92010-06-19 12:24:56 +02001226 bool audio_enabled;
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001227 struct timer_list audio_timer;
1228 int audio_channels;
1229 int audio_rate;
1230 int audio_bits_per_sample;
1231 uint8_t audio_status_bits;
1232 uint8_t audio_category_code;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10001233
Alex Deucherce8f5372010-05-07 15:10:16 -04001234 struct notifier_block acpi_nb;
Marek Olšák9eba4a92011-01-05 05:46:48 +01001235 /* only one userspace can use Hyperz features or CMASK at a time */
Dave Airlieab9e1f52010-07-13 11:11:11 +10001236 struct drm_file *hyperz_filp;
Marek Olšák9eba4a92011-01-05 05:46:48 +01001237 struct drm_file *cmask_filp;
Alex Deucherf376b942010-08-05 21:21:16 -04001238 /* i2c buses */
1239 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001240};
1241
1242int radeon_device_init(struct radeon_device *rdev,
1243 struct drm_device *ddev,
1244 struct pci_dev *pdev,
1245 uint32_t flags);
1246void radeon_device_fini(struct radeon_device *rdev);
1247int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
1248
Dave Airliede1b2892009-08-12 18:43:14 +10001249static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
1250{
Alex Deucher07bec2d2010-01-13 19:09:12 -05001251 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +10001252 return readl(((void __iomem *)rdev->rmmio) + reg);
1253 else {
1254 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1255 return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1256 }
1257}
1258
1259static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1260{
Alex Deucher07bec2d2010-01-13 19:09:12 -05001261 if (reg < rdev->rmmio_size)
Dave Airliede1b2892009-08-12 18:43:14 +10001262 writel(v, ((void __iomem *)rdev->rmmio) + reg);
1263 else {
1264 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
1265 writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
1266 }
1267}
1268
Alex Deucher351a52a2010-06-30 11:52:50 -04001269static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
1270{
1271 if (reg < rdev->rio_mem_size)
1272 return ioread32(rdev->rio_mem + reg);
1273 else {
1274 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1275 return ioread32(rdev->rio_mem + RADEON_MM_DATA);
1276 }
1277}
1278
1279static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1280{
1281 if (reg < rdev->rio_mem_size)
1282 iowrite32(v, rdev->rio_mem + reg);
1283 else {
1284 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
1285 iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
1286 }
1287}
1288
Jerome Glisse4c788672009-11-20 14:29:23 +01001289/*
1290 * Cast helper
1291 */
1292#define to_radeon_fence(p) ((struct radeon_fence *)(p))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001293
1294/*
1295 * Registers read & write functions.
1296 */
1297#define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
1298#define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
Alex Deucher9e46a482011-01-06 18:49:35 -05001299#define RREG16(reg) readw(((void __iomem *)rdev->rmmio) + (reg))
1300#define WREG16(reg, v) writew(v, ((void __iomem *)rdev->rmmio) + (reg))
Dave Airliede1b2892009-08-12 18:43:14 +10001301#define RREG32(reg) r100_mm_rreg(rdev, (reg))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001302#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
Dave Airliede1b2892009-08-12 18:43:14 +10001303#define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001304#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1305#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
1306#define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
1307#define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
1308#define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
1309#define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
Dave Airliede1b2892009-08-12 18:43:14 +10001310#define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
1311#define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
Rafał Miłeckiaa5120d2010-02-18 20:24:28 +00001312#define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
1313#define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001314#define WREG32_P(reg, val, mask) \
1315 do { \
1316 uint32_t tmp_ = RREG32(reg); \
1317 tmp_ &= (mask); \
1318 tmp_ |= ((val) & ~(mask)); \
1319 WREG32(reg, tmp_); \
1320 } while (0)
1321#define WREG32_PLL_P(reg, val, mask) \
1322 do { \
1323 uint32_t tmp_ = RREG32_PLL(reg); \
1324 tmp_ &= (mask); \
1325 tmp_ |= ((val) & ~(mask)); \
1326 WREG32_PLL(reg, tmp_); \
1327 } while (0)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001328#define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
Alex Deucher351a52a2010-06-30 11:52:50 -04001329#define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
1330#define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001331
Dave Airliede1b2892009-08-12 18:43:14 +10001332/*
1333 * Indirect registers accessor
1334 */
1335static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
1336{
1337 uint32_t r;
1338
1339 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1340 r = RREG32(RADEON_PCIE_DATA);
1341 return r;
1342}
1343
1344static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1345{
1346 WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
1347 WREG32(RADEON_PCIE_DATA, (v));
1348}
1349
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001350void r100_pll_errata_after_index(struct radeon_device *rdev);
1351
1352
1353/*
1354 * ASICs helpers.
1355 */
Dave Airlieb995e432009-07-14 02:02:32 +10001356#define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
1357 (rdev->pdev->device == 0x5969))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001358#define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
1359 (rdev->family == CHIP_RV200) || \
1360 (rdev->family == CHIP_RS100) || \
1361 (rdev->family == CHIP_RS200) || \
1362 (rdev->family == CHIP_RV250) || \
1363 (rdev->family == CHIP_RV280) || \
1364 (rdev->family == CHIP_RS300))
1365#define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
1366 (rdev->family == CHIP_RV350) || \
1367 (rdev->family == CHIP_R350) || \
1368 (rdev->family == CHIP_RV380) || \
1369 (rdev->family == CHIP_R420) || \
1370 (rdev->family == CHIP_R423) || \
1371 (rdev->family == CHIP_RV410) || \
1372 (rdev->family == CHIP_RS400) || \
1373 (rdev->family == CHIP_RS480))
Alex Deucher3313e3d2011-01-06 18:49:34 -05001374#define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
1375 (rdev->ddev->pdev->device == 0x9443) || \
1376 (rdev->ddev->pdev->device == 0x944B) || \
1377 (rdev->ddev->pdev->device == 0x9506) || \
1378 (rdev->ddev->pdev->device == 0x9509) || \
1379 (rdev->ddev->pdev->device == 0x950F) || \
1380 (rdev->ddev->pdev->device == 0x689C) || \
1381 (rdev->ddev->pdev->device == 0x689D))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001382#define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
Alex Deucher99999aa2010-11-16 12:09:41 -05001383#define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
1384 (rdev->family == CHIP_RS690) || \
1385 (rdev->family == CHIP_RS740) || \
1386 (rdev->family >= CHIP_R600))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001387#define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
1388#define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
Alex Deucherbcc1c2a2010-01-12 17:54:34 -05001389#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
Alex Deucher633b9162011-01-06 21:19:11 -05001390#define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
1391 (rdev->flags & RADEON_IS_IGP))
Alex Deucher1fe18302011-01-06 21:19:12 -05001392#define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001393
1394/*
1395 * BIOS helpers.
1396 */
1397#define RBIOS8(i) (rdev->bios[i])
1398#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
1399#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
1400
1401int radeon_combios_init(struct radeon_device *rdev);
1402void radeon_combios_fini(struct radeon_device *rdev);
1403int radeon_atombios_init(struct radeon_device *rdev);
1404void radeon_atombios_fini(struct radeon_device *rdev);
1405
1406
1407/*
1408 * RING helpers.
1409 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001410static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
1411{
1412#if DRM_DEBUG_CODE
1413 if (rdev->cp.count_dw <= 0) {
1414 DRM_ERROR("radeon: writting more dword to ring than expected !\n");
1415 }
1416#endif
1417 rdev->cp.ring[rdev->cp.wptr++] = v;
1418 rdev->cp.wptr &= rdev->cp.ptr_mask;
1419 rdev->cp.count_dw--;
1420 rdev->cp.ring_free_dw--;
1421}
1422
1423
1424/*
1425 * ASICs macro.
1426 */
Jerome Glisse068a1172009-06-17 13:28:30 +02001427#define radeon_init(rdev) (rdev)->asic->init((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001428#define radeon_fini(rdev) (rdev)->asic->fini((rdev))
1429#define radeon_resume(rdev) (rdev)->asic->resume((rdev))
1430#define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001431#define radeon_cs_parse(p) rdev->asic->cs_parse((p))
Dave Airlie28d52042009-09-21 14:33:58 +10001432#define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
Jerome Glisse225758d2010-03-09 14:45:10 +00001433#define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
Jerome Glissea2d07b72010-03-09 14:45:11 +00001434#define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001435#define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
1436#define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001437#define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001438#define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001439#define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
1440#define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001441#define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
1442#define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
Michel Dänzer7ed220d2009-08-13 11:10:51 +02001443#define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001444#define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
1445#define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
1446#define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
1447#define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
Rafał Miłecki74338742009-11-03 00:53:02 +01001448#define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001449#define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
Rafał Miłecki74338742009-11-03 00:53:02 +01001450#define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
Rafał Miłecki93e7de72009-11-04 23:34:10 +01001451#define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
Alex Deucherc836a412009-12-23 10:07:50 -05001452#define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001453#define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
1454#define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
Dave Airliee024e112009-06-24 09:48:08 +10001455#define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
1456#define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
Jerome Glissec93bb852009-07-13 21:04:08 +02001457#define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
Alex Deucher429770b2009-12-04 15:26:55 -05001458#define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
1459#define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
1460#define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
1461#define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
Alex Deucherdef9ba92010-04-22 12:39:58 -04001462#define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
Alex Deuchera4248162010-04-24 14:50:23 -04001463#define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
1464#define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
1465#define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
Alex Deucherce8f5372010-05-07 15:10:16 -04001466#define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
1467#define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
Alex Deucher6f34be52010-11-21 10:59:01 -05001468#define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
1469#define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
1470#define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001471
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001472/* Common functions */
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001473/* AGP */
Jerome Glisse90aca4d2010-03-09 14:45:12 +00001474extern int radeon_gpu_reset(struct radeon_device *rdev);
Jerome Glisse700a0cc2010-01-13 15:16:38 +01001475extern void radeon_agp_disable(struct radeon_device *rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001476extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
Dave Airlie82568562010-02-05 16:00:07 +10001477extern void radeon_gart_restore(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001478extern int radeon_modeset_init(struct radeon_device *rdev);
1479extern void radeon_modeset_fini(struct radeon_device *rdev);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001480extern bool radeon_card_posted(struct radeon_device *rdev);
Alex Deucherf47299c2010-03-16 20:54:38 -04001481extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
Alex Deucherf46c0122010-03-31 00:33:27 -04001482extern void radeon_update_display_priority(struct radeon_device *rdev);
Dave Airlie72542d72009-12-01 14:06:31 +10001483extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001484extern void radeon_scratch_init(struct radeon_device *rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04001485extern void radeon_wb_fini(struct radeon_device *rdev);
1486extern int radeon_wb_init(struct radeon_device *rdev);
1487extern void radeon_wb_disable(struct radeon_device *rdev);
Jerome Glisse21f9a432009-09-11 15:55:33 +02001488extern void radeon_surface_init(struct radeon_device *rdev);
1489extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001490extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glissed39c3b82009-09-28 18:34:43 +02001491extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
Jerome Glisse312ea8d2009-12-07 15:52:58 +01001492extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
Jerome Glissed03d8582009-12-14 21:02:09 +01001493extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
Jerome Glissed594e462010-02-17 21:54:29 +00001494extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
1495extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10001496extern int radeon_resume_kms(struct drm_device *dev);
1497extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
Dave Airlie53595332011-03-14 09:47:24 +10001498extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +02001499
Daniel Vetter3574dda2011-02-18 17:59:19 +01001500/*
1501 * r600 functions used by radeon_encoder.c
1502 */
Rafał Miłecki2cd62182010-03-08 22:14:01 +00001503extern void r600_hdmi_enable(struct drm_encoder *encoder);
1504extern void r600_hdmi_disable(struct drm_encoder *encoder);
Christian Koenigdafc3bd2009-10-11 23:49:13 +02001505extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
Alex Deucherfe251e22010-03-24 13:36:43 -04001506
Alex Deucher0af62b02011-01-06 21:19:31 -05001507extern int ni_init_microcode(struct radeon_device *rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001508extern int ni_mc_load_microcode(struct radeon_device *rdev);
Alex Deucher0af62b02011-01-06 21:19:31 -05001509
Alberto Miloned7a29522010-07-06 11:40:24 -04001510/* radeon_acpi.c */
1511#if defined(CONFIG_ACPI)
1512extern int radeon_acpi_init(struct radeon_device *rdev);
1513#else
1514static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
1515#endif
1516
Jerome Glisse4c788672009-11-20 14:29:23 +01001517#include "radeon_object.h"
1518
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001519#endif