radeon.h 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #ifndef __RADEON_H__
  29. #define __RADEON_H__
  30. /* TODO: Here are things that needs to be done :
  31. * - surface allocator & initializer : (bit like scratch reg) should
  32. * initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
  33. * related to surface
  34. * - WB : write back stuff (do it bit like scratch reg things)
  35. * - Vblank : look at Jesse's rework and what we should do
  36. * - r600/r700: gart & cp
  37. * - cs : clean cs ioctl use bitmap & things like that.
  38. * - power management stuff
  39. * - Barrier in gart code
  40. * - Unmappabled vram ?
  41. * - TESTING, TESTING, TESTING
  42. */
  43. /* Initialization path:
  44. * We expect that acceleration initialization might fail for various
  45. * reasons even thought we work hard to make it works on most
  46. * configurations. In order to still have a working userspace in such
  47. * situation the init path must succeed up to the memory controller
  48. * initialization point. Failure before this point are considered as
  49. * fatal error. Here is the init callchain :
  50. * radeon_device_init perform common structure, mutex initialization
  51. * asic_init setup the GPU memory layout and perform all
  52. * one time initialization (failure in this
  53. * function are considered fatal)
  54. * asic_startup setup the GPU acceleration, in order to
  55. * follow guideline the first thing this
  56. * function should do is setting the GPU
  57. * memory controller (only MC setup failure
  58. * are considered as fatal)
  59. */
  60. #include <linux/atomic.h>
  61. #include <linux/wait.h>
  62. #include <linux/list.h>
  63. #include <linux/kref.h>
  64. #include <ttm/ttm_bo_api.h>
  65. #include <ttm/ttm_bo_driver.h>
  66. #include <ttm/ttm_placement.h>
  67. #include <ttm/ttm_module.h>
  68. #include <ttm/ttm_execbuf_util.h>
  69. #include "radeon_family.h"
  70. #include "radeon_mode.h"
  71. #include "radeon_reg.h"
  72. /*
  73. * Modules parameters.
  74. */
  75. extern int radeon_no_wb;
  76. extern int radeon_modeset;
  77. extern int radeon_dynclks;
  78. extern int radeon_r4xx_atom;
  79. extern int radeon_agpmode;
  80. extern int radeon_vram_limit;
  81. extern int radeon_gart_size;
  82. extern int radeon_benchmarking;
  83. extern int radeon_testing;
  84. extern int radeon_connector_table;
  85. extern int radeon_tv;
  86. extern int radeon_audio;
  87. extern int radeon_disp_priority;
  88. extern int radeon_hw_i2c;
  89. extern int radeon_pcie_gen2;
  90. /*
  91. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  92. * symbol;
  93. */
  94. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  95. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  96. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  97. #define RADEON_IB_POOL_SIZE 16
  98. #define RADEON_DEBUGFS_MAX_NUM_FILES 32
  99. #define RADEONFB_CONN_LIMIT 4
  100. #define RADEON_BIOS_NUM_SCRATCH 8
  101. /*
  102. * Errata workarounds.
  103. */
  104. enum radeon_pll_errata {
  105. CHIP_ERRATA_R300_CG = 0x00000001,
  106. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  107. CHIP_ERRATA_PLL_DELAY = 0x00000004
  108. };
  109. struct radeon_device;
  110. /*
  111. * BIOS.
  112. */
  113. #define ATRM_BIOS_PAGE 4096
  114. #if defined(CONFIG_VGA_SWITCHEROO)
  115. bool radeon_atrm_supported(struct pci_dev *pdev);
  116. int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
  117. #else
  118. static inline bool radeon_atrm_supported(struct pci_dev *pdev)
  119. {
  120. return false;
  121. }
  122. static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
  123. return -EINVAL;
  124. }
  125. #endif
  126. bool radeon_get_bios(struct radeon_device *rdev);
  127. /*
  128. * Dummy page
  129. */
  130. struct radeon_dummy_page {
  131. struct page *page;
  132. dma_addr_t addr;
  133. };
  134. int radeon_dummy_page_init(struct radeon_device *rdev);
  135. void radeon_dummy_page_fini(struct radeon_device *rdev);
  136. /*
  137. * Clocks
  138. */
  139. struct radeon_clock {
  140. struct radeon_pll p1pll;
  141. struct radeon_pll p2pll;
  142. struct radeon_pll dcpll;
  143. struct radeon_pll spll;
  144. struct radeon_pll mpll;
  145. /* 10 Khz units */
  146. uint32_t default_mclk;
  147. uint32_t default_sclk;
  148. uint32_t default_dispclk;
  149. uint32_t dp_extclk;
  150. uint32_t max_pixel_clock;
  151. };
  152. /*
  153. * Power management
  154. */
  155. int radeon_pm_init(struct radeon_device *rdev);
  156. void radeon_pm_fini(struct radeon_device *rdev);
  157. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  158. void radeon_pm_suspend(struct radeon_device *rdev);
  159. void radeon_pm_resume(struct radeon_device *rdev);
  160. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  161. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  162. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  163. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u16 *voltage);
  164. void rs690_pm_info(struct radeon_device *rdev);
  165. extern int rv6xx_get_temp(struct radeon_device *rdev);
  166. extern int rv770_get_temp(struct radeon_device *rdev);
  167. extern int evergreen_get_temp(struct radeon_device *rdev);
  168. extern int sumo_get_temp(struct radeon_device *rdev);
  169. /*
  170. * Fences.
  171. */
  172. struct radeon_fence_driver {
  173. uint32_t scratch_reg;
  174. atomic_t seq;
  175. uint32_t last_seq;
  176. unsigned long last_jiffies;
  177. unsigned long last_timeout;
  178. wait_queue_head_t queue;
  179. rwlock_t lock;
  180. struct list_head created;
  181. struct list_head emited;
  182. struct list_head signaled;
  183. bool initialized;
  184. };
  185. struct radeon_fence {
  186. struct radeon_device *rdev;
  187. struct kref kref;
  188. struct list_head list;
  189. /* protected by radeon_fence.lock */
  190. uint32_t seq;
  191. bool emited;
  192. bool signaled;
  193. };
  194. int radeon_fence_driver_init(struct radeon_device *rdev);
  195. void radeon_fence_driver_fini(struct radeon_device *rdev);
  196. int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
  197. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
  198. void radeon_fence_process(struct radeon_device *rdev);
  199. bool radeon_fence_signaled(struct radeon_fence *fence);
  200. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  201. int radeon_fence_wait_next(struct radeon_device *rdev);
  202. int radeon_fence_wait_last(struct radeon_device *rdev);
  203. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  204. void radeon_fence_unref(struct radeon_fence **fence);
  205. /*
  206. * Tiling registers
  207. */
  208. struct radeon_surface_reg {
  209. struct radeon_bo *bo;
  210. };
  211. #define RADEON_GEM_MAX_SURFACES 8
  212. /*
  213. * TTM.
  214. */
  215. struct radeon_mman {
  216. struct ttm_bo_global_ref bo_global_ref;
  217. struct drm_global_reference mem_global_ref;
  218. struct ttm_bo_device bdev;
  219. bool mem_global_referenced;
  220. bool initialized;
  221. };
  222. struct radeon_bo {
  223. /* Protected by gem.mutex */
  224. struct list_head list;
  225. /* Protected by tbo.reserved */
  226. u32 placements[3];
  227. struct ttm_placement placement;
  228. struct ttm_buffer_object tbo;
  229. struct ttm_bo_kmap_obj kmap;
  230. unsigned pin_count;
  231. void *kptr;
  232. u32 tiling_flags;
  233. u32 pitch;
  234. int surface_reg;
  235. /* Constant after initialization */
  236. struct radeon_device *rdev;
  237. struct drm_gem_object gem_base;
  238. };
  239. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  240. struct radeon_bo_list {
  241. struct ttm_validate_buffer tv;
  242. struct radeon_bo *bo;
  243. uint64_t gpu_offset;
  244. unsigned rdomain;
  245. unsigned wdomain;
  246. u32 tiling_flags;
  247. };
  248. /*
  249. * GEM objects.
  250. */
  251. struct radeon_gem {
  252. struct mutex mutex;
  253. struct list_head objects;
  254. };
  255. int radeon_gem_init(struct radeon_device *rdev);
  256. void radeon_gem_fini(struct radeon_device *rdev);
  257. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  258. int alignment, int initial_domain,
  259. bool discardable, bool kernel,
  260. struct drm_gem_object **obj);
  261. int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
  262. uint64_t *gpu_addr);
  263. void radeon_gem_object_unpin(struct drm_gem_object *obj);
  264. int radeon_mode_dumb_create(struct drm_file *file_priv,
  265. struct drm_device *dev,
  266. struct drm_mode_create_dumb *args);
  267. int radeon_mode_dumb_mmap(struct drm_file *filp,
  268. struct drm_device *dev,
  269. uint32_t handle, uint64_t *offset_p);
  270. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  271. struct drm_device *dev,
  272. uint32_t handle);
  273. /*
  274. * GART structures, functions & helpers
  275. */
  276. struct radeon_mc;
  277. struct radeon_gart_table_ram {
  278. volatile uint32_t *ptr;
  279. };
  280. struct radeon_gart_table_vram {
  281. struct radeon_bo *robj;
  282. volatile uint32_t *ptr;
  283. };
  284. union radeon_gart_table {
  285. struct radeon_gart_table_ram ram;
  286. struct radeon_gart_table_vram vram;
  287. };
  288. #define RADEON_GPU_PAGE_SIZE 4096
  289. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  290. #define RADEON_GPU_PAGE_SHIFT 12
  291. struct radeon_gart {
  292. dma_addr_t table_addr;
  293. unsigned num_gpu_pages;
  294. unsigned num_cpu_pages;
  295. unsigned table_size;
  296. union radeon_gart_table table;
  297. struct page **pages;
  298. dma_addr_t *pages_addr;
  299. bool *ttm_alloced;
  300. bool ready;
  301. };
  302. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  303. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  304. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  305. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  306. int radeon_gart_init(struct radeon_device *rdev);
  307. void radeon_gart_fini(struct radeon_device *rdev);
  308. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  309. int pages);
  310. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  311. int pages, struct page **pagelist,
  312. dma_addr_t *dma_addr);
  313. /*
  314. * GPU MC structures, functions & helpers
  315. */
  316. struct radeon_mc {
  317. resource_size_t aper_size;
  318. resource_size_t aper_base;
  319. resource_size_t agp_base;
  320. /* for some chips with <= 32MB we need to lie
  321. * about vram size near mc fb location */
  322. u64 mc_vram_size;
  323. u64 visible_vram_size;
  324. u64 gtt_size;
  325. u64 gtt_start;
  326. u64 gtt_end;
  327. u64 vram_start;
  328. u64 vram_end;
  329. unsigned vram_width;
  330. u64 real_vram_size;
  331. int vram_mtrr;
  332. bool vram_is_ddr;
  333. bool igp_sideport_enabled;
  334. u64 gtt_base_align;
  335. };
  336. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  337. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  338. /*
  339. * GPU scratch registers structures, functions & helpers
  340. */
  341. struct radeon_scratch {
  342. unsigned num_reg;
  343. uint32_t reg_base;
  344. bool free[32];
  345. uint32_t reg[32];
  346. };
  347. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  348. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  349. /*
  350. * IRQS.
  351. */
  352. struct radeon_unpin_work {
  353. struct work_struct work;
  354. struct radeon_device *rdev;
  355. int crtc_id;
  356. struct radeon_fence *fence;
  357. struct drm_pending_vblank_event *event;
  358. struct radeon_bo *old_rbo;
  359. u64 new_crtc_base;
  360. };
  361. struct r500_irq_stat_regs {
  362. u32 disp_int;
  363. };
  364. struct r600_irq_stat_regs {
  365. u32 disp_int;
  366. u32 disp_int_cont;
  367. u32 disp_int_cont2;
  368. u32 d1grph_int;
  369. u32 d2grph_int;
  370. };
  371. struct evergreen_irq_stat_regs {
  372. u32 disp_int;
  373. u32 disp_int_cont;
  374. u32 disp_int_cont2;
  375. u32 disp_int_cont3;
  376. u32 disp_int_cont4;
  377. u32 disp_int_cont5;
  378. u32 d1grph_int;
  379. u32 d2grph_int;
  380. u32 d3grph_int;
  381. u32 d4grph_int;
  382. u32 d5grph_int;
  383. u32 d6grph_int;
  384. };
  385. union radeon_irq_stat_regs {
  386. struct r500_irq_stat_regs r500;
  387. struct r600_irq_stat_regs r600;
  388. struct evergreen_irq_stat_regs evergreen;
  389. };
  390. struct radeon_irq {
  391. bool installed;
  392. bool sw_int;
  393. /* FIXME: use a define max crtc rather than hardcode it */
  394. bool crtc_vblank_int[6];
  395. bool pflip[6];
  396. wait_queue_head_t vblank_queue;
  397. /* FIXME: use defines for max hpd/dacs */
  398. bool hpd[6];
  399. bool gui_idle;
  400. bool gui_idle_acked;
  401. wait_queue_head_t idle_queue;
  402. /* FIXME: use defines for max HDMI blocks */
  403. bool hdmi[2];
  404. spinlock_t sw_lock;
  405. int sw_refcount;
  406. union radeon_irq_stat_regs stat_regs;
  407. spinlock_t pflip_lock[6];
  408. int pflip_refcount[6];
  409. };
  410. int radeon_irq_kms_init(struct radeon_device *rdev);
  411. void radeon_irq_kms_fini(struct radeon_device *rdev);
  412. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
  413. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
  414. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  415. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  416. /*
  417. * CP & ring.
  418. */
  419. struct radeon_ib {
  420. struct list_head list;
  421. unsigned idx;
  422. uint64_t gpu_addr;
  423. struct radeon_fence *fence;
  424. uint32_t *ptr;
  425. uint32_t length_dw;
  426. bool free;
  427. };
  428. /*
  429. * locking -
  430. * mutex protects scheduled_ibs, ready, alloc_bm
  431. */
  432. struct radeon_ib_pool {
  433. struct mutex mutex;
  434. struct radeon_bo *robj;
  435. struct list_head bogus_ib;
  436. struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
  437. bool ready;
  438. unsigned head_id;
  439. };
  440. struct radeon_cp {
  441. struct radeon_bo *ring_obj;
  442. volatile uint32_t *ring;
  443. unsigned rptr;
  444. unsigned wptr;
  445. unsigned wptr_old;
  446. unsigned ring_size;
  447. unsigned ring_free_dw;
  448. int count_dw;
  449. uint64_t gpu_addr;
  450. uint32_t align_mask;
  451. uint32_t ptr_mask;
  452. struct mutex mutex;
  453. bool ready;
  454. };
  455. /*
  456. * R6xx+ IH ring
  457. */
  458. struct r600_ih {
  459. struct radeon_bo *ring_obj;
  460. volatile uint32_t *ring;
  461. unsigned rptr;
  462. unsigned wptr;
  463. unsigned wptr_old;
  464. unsigned ring_size;
  465. uint64_t gpu_addr;
  466. uint32_t ptr_mask;
  467. spinlock_t lock;
  468. bool enabled;
  469. };
  470. struct r600_blit {
  471. struct mutex mutex;
  472. struct radeon_bo *shader_obj;
  473. u64 shader_gpu_addr;
  474. u32 vs_offset, ps_offset;
  475. u32 state_offset;
  476. u32 state_len;
  477. u32 vb_used, vb_total;
  478. struct radeon_ib *vb_ib;
  479. };
  480. int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
  481. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
  482. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  483. int radeon_ib_pool_init(struct radeon_device *rdev);
  484. void radeon_ib_pool_fini(struct radeon_device *rdev);
  485. int radeon_ib_test(struct radeon_device *rdev);
  486. extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
  487. /* Ring access between begin & end cannot sleep */
  488. void radeon_ring_free_size(struct radeon_device *rdev);
  489. int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
  490. int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
  491. void radeon_ring_commit(struct radeon_device *rdev);
  492. void radeon_ring_unlock_commit(struct radeon_device *rdev);
  493. void radeon_ring_unlock_undo(struct radeon_device *rdev);
  494. int radeon_ring_test(struct radeon_device *rdev);
  495. int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
  496. void radeon_ring_fini(struct radeon_device *rdev);
  497. /*
  498. * CS.
  499. */
  500. struct radeon_cs_reloc {
  501. struct drm_gem_object *gobj;
  502. struct radeon_bo *robj;
  503. struct radeon_bo_list lobj;
  504. uint32_t handle;
  505. uint32_t flags;
  506. };
  507. struct radeon_cs_chunk {
  508. uint32_t chunk_id;
  509. uint32_t length_dw;
  510. int kpage_idx[2];
  511. uint32_t *kpage[2];
  512. uint32_t *kdata;
  513. void __user *user_ptr;
  514. int last_copied_page;
  515. int last_page_index;
  516. };
  517. struct radeon_cs_parser {
  518. struct device *dev;
  519. struct radeon_device *rdev;
  520. struct drm_file *filp;
  521. /* chunks */
  522. unsigned nchunks;
  523. struct radeon_cs_chunk *chunks;
  524. uint64_t *chunks_array;
  525. /* IB */
  526. unsigned idx;
  527. /* relocations */
  528. unsigned nrelocs;
  529. struct radeon_cs_reloc *relocs;
  530. struct radeon_cs_reloc **relocs_ptr;
  531. struct list_head validated;
  532. /* indices of various chunks */
  533. int chunk_ib_idx;
  534. int chunk_relocs_idx;
  535. struct radeon_ib *ib;
  536. void *track;
  537. unsigned family;
  538. int parser_error;
  539. };
  540. extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
  541. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  542. static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
  543. {
  544. struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
  545. u32 pg_idx, pg_offset;
  546. u32 idx_value = 0;
  547. int new_page;
  548. pg_idx = (idx * 4) / PAGE_SIZE;
  549. pg_offset = (idx * 4) % PAGE_SIZE;
  550. if (ibc->kpage_idx[0] == pg_idx)
  551. return ibc->kpage[0][pg_offset/4];
  552. if (ibc->kpage_idx[1] == pg_idx)
  553. return ibc->kpage[1][pg_offset/4];
  554. new_page = radeon_cs_update_pages(p, pg_idx);
  555. if (new_page < 0) {
  556. p->parser_error = new_page;
  557. return 0;
  558. }
  559. idx_value = ibc->kpage[new_page][pg_offset/4];
  560. return idx_value;
  561. }
  562. struct radeon_cs_packet {
  563. unsigned idx;
  564. unsigned type;
  565. unsigned reg;
  566. unsigned opcode;
  567. int count;
  568. unsigned one_reg_wr;
  569. };
  570. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  571. struct radeon_cs_packet *pkt,
  572. unsigned idx, unsigned reg);
  573. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  574. struct radeon_cs_packet *pkt);
  575. /*
  576. * AGP
  577. */
  578. int radeon_agp_init(struct radeon_device *rdev);
  579. void radeon_agp_resume(struct radeon_device *rdev);
  580. void radeon_agp_suspend(struct radeon_device *rdev);
  581. void radeon_agp_fini(struct radeon_device *rdev);
  582. /*
  583. * Writeback
  584. */
  585. struct radeon_wb {
  586. struct radeon_bo *wb_obj;
  587. volatile uint32_t *wb;
  588. uint64_t gpu_addr;
  589. bool enabled;
  590. bool use_event;
  591. };
  592. #define RADEON_WB_SCRATCH_OFFSET 0
  593. #define RADEON_WB_CP_RPTR_OFFSET 1024
  594. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  595. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  596. #define R600_WB_IH_WPTR_OFFSET 2048
  597. #define R600_WB_EVENT_OFFSET 3072
  598. /**
  599. * struct radeon_pm - power management datas
  600. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  601. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  602. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  603. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  604. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  605. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  606. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  607. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  608. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  609. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  610. * @needed_bandwidth: current bandwidth needs
  611. *
  612. * It keeps track of various data needed to take powermanagement decision.
  613. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  614. * Equation between gpu/memory clock and available bandwidth is hw dependent
  615. * (type of memory, bus size, efficiency, ...)
  616. */
  617. enum radeon_pm_method {
  618. PM_METHOD_PROFILE,
  619. PM_METHOD_DYNPM,
  620. };
  621. enum radeon_dynpm_state {
  622. DYNPM_STATE_DISABLED,
  623. DYNPM_STATE_MINIMUM,
  624. DYNPM_STATE_PAUSED,
  625. DYNPM_STATE_ACTIVE,
  626. DYNPM_STATE_SUSPENDED,
  627. };
  628. enum radeon_dynpm_action {
  629. DYNPM_ACTION_NONE,
  630. DYNPM_ACTION_MINIMUM,
  631. DYNPM_ACTION_DOWNCLOCK,
  632. DYNPM_ACTION_UPCLOCK,
  633. DYNPM_ACTION_DEFAULT
  634. };
  635. enum radeon_voltage_type {
  636. VOLTAGE_NONE = 0,
  637. VOLTAGE_GPIO,
  638. VOLTAGE_VDDC,
  639. VOLTAGE_SW
  640. };
  641. enum radeon_pm_state_type {
  642. POWER_STATE_TYPE_DEFAULT,
  643. POWER_STATE_TYPE_POWERSAVE,
  644. POWER_STATE_TYPE_BATTERY,
  645. POWER_STATE_TYPE_BALANCED,
  646. POWER_STATE_TYPE_PERFORMANCE,
  647. };
  648. enum radeon_pm_profile_type {
  649. PM_PROFILE_DEFAULT,
  650. PM_PROFILE_AUTO,
  651. PM_PROFILE_LOW,
  652. PM_PROFILE_MID,
  653. PM_PROFILE_HIGH,
  654. };
  655. #define PM_PROFILE_DEFAULT_IDX 0
  656. #define PM_PROFILE_LOW_SH_IDX 1
  657. #define PM_PROFILE_MID_SH_IDX 2
  658. #define PM_PROFILE_HIGH_SH_IDX 3
  659. #define PM_PROFILE_LOW_MH_IDX 4
  660. #define PM_PROFILE_MID_MH_IDX 5
  661. #define PM_PROFILE_HIGH_MH_IDX 6
  662. #define PM_PROFILE_MAX 7
  663. struct radeon_pm_profile {
  664. int dpms_off_ps_idx;
  665. int dpms_on_ps_idx;
  666. int dpms_off_cm_idx;
  667. int dpms_on_cm_idx;
  668. };
  669. enum radeon_int_thermal_type {
  670. THERMAL_TYPE_NONE,
  671. THERMAL_TYPE_RV6XX,
  672. THERMAL_TYPE_RV770,
  673. THERMAL_TYPE_EVERGREEN,
  674. THERMAL_TYPE_SUMO,
  675. THERMAL_TYPE_NI,
  676. };
  677. struct radeon_voltage {
  678. enum radeon_voltage_type type;
  679. /* gpio voltage */
  680. struct radeon_gpio_rec gpio;
  681. u32 delay; /* delay in usec from voltage drop to sclk change */
  682. bool active_high; /* voltage drop is active when bit is high */
  683. /* VDDC voltage */
  684. u8 vddc_id; /* index into vddc voltage table */
  685. u8 vddci_id; /* index into vddci voltage table */
  686. bool vddci_enabled;
  687. /* r6xx+ sw */
  688. u16 voltage;
  689. /* evergreen+ vddci */
  690. u16 vddci;
  691. };
  692. /* clock mode flags */
  693. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  694. struct radeon_pm_clock_info {
  695. /* memory clock */
  696. u32 mclk;
  697. /* engine clock */
  698. u32 sclk;
  699. /* voltage info */
  700. struct radeon_voltage voltage;
  701. /* standardized clock flags */
  702. u32 flags;
  703. };
  704. /* state flags */
  705. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  706. struct radeon_power_state {
  707. enum radeon_pm_state_type type;
  708. /* XXX: use a define for num clock modes */
  709. struct radeon_pm_clock_info clock_info[8];
  710. /* number of valid clock modes in this power state */
  711. int num_clock_modes;
  712. struct radeon_pm_clock_info *default_clock_mode;
  713. /* standardized state flags */
  714. u32 flags;
  715. u32 misc; /* vbios specific flags */
  716. u32 misc2; /* vbios specific flags */
  717. int pcie_lanes; /* pcie lanes */
  718. };
  719. /*
  720. * Some modes are overclocked by very low value, accept them
  721. */
  722. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  723. struct radeon_pm {
  724. struct mutex mutex;
  725. u32 active_crtcs;
  726. int active_crtc_count;
  727. int req_vblank;
  728. bool vblank_sync;
  729. bool gui_idle;
  730. fixed20_12 max_bandwidth;
  731. fixed20_12 igp_sideport_mclk;
  732. fixed20_12 igp_system_mclk;
  733. fixed20_12 igp_ht_link_clk;
  734. fixed20_12 igp_ht_link_width;
  735. fixed20_12 k8_bandwidth;
  736. fixed20_12 sideport_bandwidth;
  737. fixed20_12 ht_bandwidth;
  738. fixed20_12 core_bandwidth;
  739. fixed20_12 sclk;
  740. fixed20_12 mclk;
  741. fixed20_12 needed_bandwidth;
  742. struct radeon_power_state *power_state;
  743. /* number of valid power states */
  744. int num_power_states;
  745. int current_power_state_index;
  746. int current_clock_mode_index;
  747. int requested_power_state_index;
  748. int requested_clock_mode_index;
  749. int default_power_state_index;
  750. u32 current_sclk;
  751. u32 current_mclk;
  752. u16 current_vddc;
  753. u16 current_vddci;
  754. u32 default_sclk;
  755. u32 default_mclk;
  756. u16 default_vddc;
  757. u16 default_vddci;
  758. struct radeon_i2c_chan *i2c_bus;
  759. /* selected pm method */
  760. enum radeon_pm_method pm_method;
  761. /* dynpm power management */
  762. struct delayed_work dynpm_idle_work;
  763. enum radeon_dynpm_state dynpm_state;
  764. enum radeon_dynpm_action dynpm_planned_action;
  765. unsigned long dynpm_action_timeout;
  766. bool dynpm_can_upclock;
  767. bool dynpm_can_downclock;
  768. /* profile-based power management */
  769. enum radeon_pm_profile_type profile;
  770. int profile_index;
  771. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  772. /* internal thermal controller on rv6xx+ */
  773. enum radeon_int_thermal_type int_thermal_type;
  774. struct device *int_hwmon_dev;
  775. };
  776. /*
  777. * Benchmarking
  778. */
  779. void radeon_benchmark(struct radeon_device *rdev);
  780. /*
  781. * Testing
  782. */
  783. void radeon_test_moves(struct radeon_device *rdev);
  784. /*
  785. * Debugfs
  786. */
  787. int radeon_debugfs_add_files(struct radeon_device *rdev,
  788. struct drm_info_list *files,
  789. unsigned nfiles);
  790. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  791. /*
  792. * ASIC specific functions.
  793. */
  794. struct radeon_asic {
  795. int (*init)(struct radeon_device *rdev);
  796. void (*fini)(struct radeon_device *rdev);
  797. int (*resume)(struct radeon_device *rdev);
  798. int (*suspend)(struct radeon_device *rdev);
  799. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  800. bool (*gpu_is_lockup)(struct radeon_device *rdev);
  801. int (*asic_reset)(struct radeon_device *rdev);
  802. void (*gart_tlb_flush)(struct radeon_device *rdev);
  803. int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  804. int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
  805. void (*cp_fini)(struct radeon_device *rdev);
  806. void (*cp_disable)(struct radeon_device *rdev);
  807. void (*cp_commit)(struct radeon_device *rdev);
  808. void (*ring_start)(struct radeon_device *rdev);
  809. int (*ring_test)(struct radeon_device *rdev);
  810. void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  811. int (*irq_set)(struct radeon_device *rdev);
  812. int (*irq_process)(struct radeon_device *rdev);
  813. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  814. void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
  815. int (*cs_parse)(struct radeon_cs_parser *p);
  816. int (*copy_blit)(struct radeon_device *rdev,
  817. uint64_t src_offset,
  818. uint64_t dst_offset,
  819. unsigned num_gpu_pages,
  820. struct radeon_fence *fence);
  821. int (*copy_dma)(struct radeon_device *rdev,
  822. uint64_t src_offset,
  823. uint64_t dst_offset,
  824. unsigned num_gpu_pages,
  825. struct radeon_fence *fence);
  826. int (*copy)(struct radeon_device *rdev,
  827. uint64_t src_offset,
  828. uint64_t dst_offset,
  829. unsigned num_gpu_pages,
  830. struct radeon_fence *fence);
  831. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  832. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  833. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  834. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  835. int (*get_pcie_lanes)(struct radeon_device *rdev);
  836. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  837. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  838. int (*set_surface_reg)(struct radeon_device *rdev, int reg,
  839. uint32_t tiling_flags, uint32_t pitch,
  840. uint32_t offset, uint32_t obj_size);
  841. void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
  842. void (*bandwidth_update)(struct radeon_device *rdev);
  843. void (*hpd_init)(struct radeon_device *rdev);
  844. void (*hpd_fini)(struct radeon_device *rdev);
  845. bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  846. void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  847. /* ioctl hw specific callback. Some hw might want to perform special
  848. * operation on specific ioctl. For instance on wait idle some hw
  849. * might want to perform and HDP flush through MMIO as it seems that
  850. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  851. * through ring.
  852. */
  853. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  854. bool (*gui_idle)(struct radeon_device *rdev);
  855. /* power management */
  856. void (*pm_misc)(struct radeon_device *rdev);
  857. void (*pm_prepare)(struct radeon_device *rdev);
  858. void (*pm_finish)(struct radeon_device *rdev);
  859. void (*pm_init_profile)(struct radeon_device *rdev);
  860. void (*pm_get_dynpm_state)(struct radeon_device *rdev);
  861. /* pageflipping */
  862. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  863. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  864. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  865. };
  866. /*
  867. * Asic structures
  868. */
  869. struct r100_gpu_lockup {
  870. unsigned long last_jiffies;
  871. u32 last_cp_rptr;
  872. };
  873. struct r100_asic {
  874. const unsigned *reg_safe_bm;
  875. unsigned reg_safe_bm_size;
  876. u32 hdp_cntl;
  877. struct r100_gpu_lockup lockup;
  878. };
  879. struct r300_asic {
  880. const unsigned *reg_safe_bm;
  881. unsigned reg_safe_bm_size;
  882. u32 resync_scratch;
  883. u32 hdp_cntl;
  884. struct r100_gpu_lockup lockup;
  885. };
  886. struct r600_asic {
  887. unsigned max_pipes;
  888. unsigned max_tile_pipes;
  889. unsigned max_simds;
  890. unsigned max_backends;
  891. unsigned max_gprs;
  892. unsigned max_threads;
  893. unsigned max_stack_entries;
  894. unsigned max_hw_contexts;
  895. unsigned max_gs_threads;
  896. unsigned sx_max_export_size;
  897. unsigned sx_max_export_pos_size;
  898. unsigned sx_max_export_smx_size;
  899. unsigned sq_num_cf_insts;
  900. unsigned tiling_nbanks;
  901. unsigned tiling_npipes;
  902. unsigned tiling_group_size;
  903. unsigned tile_config;
  904. unsigned backend_map;
  905. struct r100_gpu_lockup lockup;
  906. };
  907. struct rv770_asic {
  908. unsigned max_pipes;
  909. unsigned max_tile_pipes;
  910. unsigned max_simds;
  911. unsigned max_backends;
  912. unsigned max_gprs;
  913. unsigned max_threads;
  914. unsigned max_stack_entries;
  915. unsigned max_hw_contexts;
  916. unsigned max_gs_threads;
  917. unsigned sx_max_export_size;
  918. unsigned sx_max_export_pos_size;
  919. unsigned sx_max_export_smx_size;
  920. unsigned sq_num_cf_insts;
  921. unsigned sx_num_of_sets;
  922. unsigned sc_prim_fifo_size;
  923. unsigned sc_hiz_tile_fifo_size;
  924. unsigned sc_earlyz_tile_fifo_fize;
  925. unsigned tiling_nbanks;
  926. unsigned tiling_npipes;
  927. unsigned tiling_group_size;
  928. unsigned tile_config;
  929. unsigned backend_map;
  930. struct r100_gpu_lockup lockup;
  931. };
  932. struct evergreen_asic {
  933. unsigned num_ses;
  934. unsigned max_pipes;
  935. unsigned max_tile_pipes;
  936. unsigned max_simds;
  937. unsigned max_backends;
  938. unsigned max_gprs;
  939. unsigned max_threads;
  940. unsigned max_stack_entries;
  941. unsigned max_hw_contexts;
  942. unsigned max_gs_threads;
  943. unsigned sx_max_export_size;
  944. unsigned sx_max_export_pos_size;
  945. unsigned sx_max_export_smx_size;
  946. unsigned sq_num_cf_insts;
  947. unsigned sx_num_of_sets;
  948. unsigned sc_prim_fifo_size;
  949. unsigned sc_hiz_tile_fifo_size;
  950. unsigned sc_earlyz_tile_fifo_size;
  951. unsigned tiling_nbanks;
  952. unsigned tiling_npipes;
  953. unsigned tiling_group_size;
  954. unsigned tile_config;
  955. unsigned backend_map;
  956. struct r100_gpu_lockup lockup;
  957. };
  958. struct cayman_asic {
  959. unsigned max_shader_engines;
  960. unsigned max_pipes_per_simd;
  961. unsigned max_tile_pipes;
  962. unsigned max_simds_per_se;
  963. unsigned max_backends_per_se;
  964. unsigned max_texture_channel_caches;
  965. unsigned max_gprs;
  966. unsigned max_threads;
  967. unsigned max_gs_threads;
  968. unsigned max_stack_entries;
  969. unsigned sx_num_of_sets;
  970. unsigned sx_max_export_size;
  971. unsigned sx_max_export_pos_size;
  972. unsigned sx_max_export_smx_size;
  973. unsigned max_hw_contexts;
  974. unsigned sq_num_cf_insts;
  975. unsigned sc_prim_fifo_size;
  976. unsigned sc_hiz_tile_fifo_size;
  977. unsigned sc_earlyz_tile_fifo_size;
  978. unsigned num_shader_engines;
  979. unsigned num_shader_pipes_per_simd;
  980. unsigned num_tile_pipes;
  981. unsigned num_simds_per_se;
  982. unsigned num_backends_per_se;
  983. unsigned backend_disable_mask_per_asic;
  984. unsigned backend_map;
  985. unsigned num_texture_channel_caches;
  986. unsigned mem_max_burst_length_bytes;
  987. unsigned mem_row_size_in_kb;
  988. unsigned shader_engine_tile_size;
  989. unsigned num_gpus;
  990. unsigned multi_gpu_tile_size;
  991. unsigned tile_config;
  992. struct r100_gpu_lockup lockup;
  993. };
  994. union radeon_asic_config {
  995. struct r300_asic r300;
  996. struct r100_asic r100;
  997. struct r600_asic r600;
  998. struct rv770_asic rv770;
  999. struct evergreen_asic evergreen;
  1000. struct cayman_asic cayman;
  1001. };
  1002. /*
  1003. * asic initizalization from radeon_asic.c
  1004. */
  1005. void radeon_agp_disable(struct radeon_device *rdev);
  1006. int radeon_asic_init(struct radeon_device *rdev);
  1007. /*
  1008. * IOCTL.
  1009. */
  1010. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1011. struct drm_file *filp);
  1012. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1013. struct drm_file *filp);
  1014. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1015. struct drm_file *file_priv);
  1016. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1017. struct drm_file *file_priv);
  1018. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1019. struct drm_file *file_priv);
  1020. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1021. struct drm_file *file_priv);
  1022. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1023. struct drm_file *filp);
  1024. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1025. struct drm_file *filp);
  1026. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1027. struct drm_file *filp);
  1028. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1029. struct drm_file *filp);
  1030. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1031. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1032. struct drm_file *filp);
  1033. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1034. struct drm_file *filp);
  1035. /* VRAM scratch page for HDP bug */
  1036. struct r700_vram_scratch {
  1037. struct radeon_bo *robj;
  1038. volatile uint32_t *ptr;
  1039. };
  1040. /*
  1041. * Core structure, functions and helpers.
  1042. */
  1043. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1044. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1045. struct radeon_device {
  1046. struct device *dev;
  1047. struct drm_device *ddev;
  1048. struct pci_dev *pdev;
  1049. /* ASIC */
  1050. union radeon_asic_config config;
  1051. enum radeon_family family;
  1052. unsigned long flags;
  1053. int usec_timeout;
  1054. enum radeon_pll_errata pll_errata;
  1055. int num_gb_pipes;
  1056. int num_z_pipes;
  1057. int disp_priority;
  1058. /* BIOS */
  1059. uint8_t *bios;
  1060. bool is_atom_bios;
  1061. uint16_t bios_header_start;
  1062. struct radeon_bo *stollen_vga_memory;
  1063. /* Register mmio */
  1064. resource_size_t rmmio_base;
  1065. resource_size_t rmmio_size;
  1066. void __iomem *rmmio;
  1067. radeon_rreg_t mc_rreg;
  1068. radeon_wreg_t mc_wreg;
  1069. radeon_rreg_t pll_rreg;
  1070. radeon_wreg_t pll_wreg;
  1071. uint32_t pcie_reg_mask;
  1072. radeon_rreg_t pciep_rreg;
  1073. radeon_wreg_t pciep_wreg;
  1074. /* io port */
  1075. void __iomem *rio_mem;
  1076. resource_size_t rio_mem_size;
  1077. struct radeon_clock clock;
  1078. struct radeon_mc mc;
  1079. struct radeon_gart gart;
  1080. struct radeon_mode_info mode_info;
  1081. struct radeon_scratch scratch;
  1082. struct radeon_mman mman;
  1083. struct radeon_fence_driver fence_drv;
  1084. struct radeon_cp cp;
  1085. /* cayman compute rings */
  1086. struct radeon_cp cp1;
  1087. struct radeon_cp cp2;
  1088. struct radeon_ib_pool ib_pool;
  1089. struct radeon_irq irq;
  1090. struct radeon_asic *asic;
  1091. struct radeon_gem gem;
  1092. struct radeon_pm pm;
  1093. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1094. struct mutex cs_mutex;
  1095. struct radeon_wb wb;
  1096. struct radeon_dummy_page dummy_page;
  1097. bool gpu_lockup;
  1098. bool shutdown;
  1099. bool suspend;
  1100. bool need_dma32;
  1101. bool accel_working;
  1102. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1103. const struct firmware *me_fw; /* all family ME firmware */
  1104. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1105. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1106. const struct firmware *mc_fw; /* NI MC firmware */
  1107. struct r600_blit r600_blit;
  1108. struct r700_vram_scratch vram_scratch;
  1109. int msi_enabled; /* msi enabled */
  1110. struct r600_ih ih; /* r6/700 interrupt ring */
  1111. struct work_struct hotplug_work;
  1112. int num_crtc; /* number of crtcs */
  1113. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1114. struct mutex vram_mutex;
  1115. /* audio stuff */
  1116. bool audio_enabled;
  1117. struct timer_list audio_timer;
  1118. int audio_channels;
  1119. int audio_rate;
  1120. int audio_bits_per_sample;
  1121. uint8_t audio_status_bits;
  1122. uint8_t audio_category_code;
  1123. struct notifier_block acpi_nb;
  1124. /* only one userspace can use Hyperz features or CMASK at a time */
  1125. struct drm_file *hyperz_filp;
  1126. struct drm_file *cmask_filp;
  1127. /* i2c buses */
  1128. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1129. };
  1130. int radeon_device_init(struct radeon_device *rdev,
  1131. struct drm_device *ddev,
  1132. struct pci_dev *pdev,
  1133. uint32_t flags);
  1134. void radeon_device_fini(struct radeon_device *rdev);
  1135. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1136. static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
  1137. {
  1138. if (reg < rdev->rmmio_size)
  1139. return readl((rdev->rmmio) + reg);
  1140. else {
  1141. writel(reg, (rdev->rmmio) + RADEON_MM_INDEX);
  1142. return readl((rdev->rmmio) + RADEON_MM_DATA);
  1143. }
  1144. }
  1145. static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1146. {
  1147. if (reg < rdev->rmmio_size)
  1148. writel(v, (rdev->rmmio) + reg);
  1149. else {
  1150. writel(reg, (rdev->rmmio) + RADEON_MM_INDEX);
  1151. writel(v, (rdev->rmmio) + RADEON_MM_DATA);
  1152. }
  1153. }
  1154. static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
  1155. {
  1156. if (reg < rdev->rio_mem_size)
  1157. return ioread32(rdev->rio_mem + reg);
  1158. else {
  1159. iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1160. return ioread32(rdev->rio_mem + RADEON_MM_DATA);
  1161. }
  1162. }
  1163. static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1164. {
  1165. if (reg < rdev->rio_mem_size)
  1166. iowrite32(v, rdev->rio_mem + reg);
  1167. else {
  1168. iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1169. iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
  1170. }
  1171. }
  1172. /*
  1173. * Cast helper
  1174. */
  1175. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1176. /*
  1177. * Registers read & write functions.
  1178. */
  1179. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1180. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1181. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1182. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1183. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1184. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
  1185. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1186. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1187. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1188. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1189. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1190. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1191. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1192. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1193. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1194. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1195. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1196. #define WREG32_P(reg, val, mask) \
  1197. do { \
  1198. uint32_t tmp_ = RREG32(reg); \
  1199. tmp_ &= (mask); \
  1200. tmp_ |= ((val) & ~(mask)); \
  1201. WREG32(reg, tmp_); \
  1202. } while (0)
  1203. #define WREG32_PLL_P(reg, val, mask) \
  1204. do { \
  1205. uint32_t tmp_ = RREG32_PLL(reg); \
  1206. tmp_ &= (mask); \
  1207. tmp_ |= ((val) & ~(mask)); \
  1208. WREG32_PLL(reg, tmp_); \
  1209. } while (0)
  1210. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
  1211. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1212. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1213. /*
  1214. * Indirect registers accessor
  1215. */
  1216. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1217. {
  1218. uint32_t r;
  1219. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1220. r = RREG32(RADEON_PCIE_DATA);
  1221. return r;
  1222. }
  1223. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1224. {
  1225. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1226. WREG32(RADEON_PCIE_DATA, (v));
  1227. }
  1228. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1229. /*
  1230. * ASICs helpers.
  1231. */
  1232. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1233. (rdev->pdev->device == 0x5969))
  1234. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1235. (rdev->family == CHIP_RV200) || \
  1236. (rdev->family == CHIP_RS100) || \
  1237. (rdev->family == CHIP_RS200) || \
  1238. (rdev->family == CHIP_RV250) || \
  1239. (rdev->family == CHIP_RV280) || \
  1240. (rdev->family == CHIP_RS300))
  1241. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1242. (rdev->family == CHIP_RV350) || \
  1243. (rdev->family == CHIP_R350) || \
  1244. (rdev->family == CHIP_RV380) || \
  1245. (rdev->family == CHIP_R420) || \
  1246. (rdev->family == CHIP_R423) || \
  1247. (rdev->family == CHIP_RV410) || \
  1248. (rdev->family == CHIP_RS400) || \
  1249. (rdev->family == CHIP_RS480))
  1250. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1251. (rdev->ddev->pdev->device == 0x9443) || \
  1252. (rdev->ddev->pdev->device == 0x944B) || \
  1253. (rdev->ddev->pdev->device == 0x9506) || \
  1254. (rdev->ddev->pdev->device == 0x9509) || \
  1255. (rdev->ddev->pdev->device == 0x950F) || \
  1256. (rdev->ddev->pdev->device == 0x689C) || \
  1257. (rdev->ddev->pdev->device == 0x689D))
  1258. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1259. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1260. (rdev->family == CHIP_RS690) || \
  1261. (rdev->family == CHIP_RS740) || \
  1262. (rdev->family >= CHIP_R600))
  1263. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1264. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1265. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1266. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1267. (rdev->flags & RADEON_IS_IGP))
  1268. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1269. /*
  1270. * BIOS helpers.
  1271. */
  1272. #define RBIOS8(i) (rdev->bios[i])
  1273. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1274. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1275. int radeon_combios_init(struct radeon_device *rdev);
  1276. void radeon_combios_fini(struct radeon_device *rdev);
  1277. int radeon_atombios_init(struct radeon_device *rdev);
  1278. void radeon_atombios_fini(struct radeon_device *rdev);
  1279. /*
  1280. * RING helpers.
  1281. */
  1282. static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
  1283. {
  1284. #if DRM_DEBUG_CODE
  1285. if (rdev->cp.count_dw <= 0) {
  1286. DRM_ERROR("radeon: writting more dword to ring than expected !\n");
  1287. }
  1288. #endif
  1289. rdev->cp.ring[rdev->cp.wptr++] = v;
  1290. rdev->cp.wptr &= rdev->cp.ptr_mask;
  1291. rdev->cp.count_dw--;
  1292. rdev->cp.ring_free_dw--;
  1293. }
  1294. /*
  1295. * ASICs macro.
  1296. */
  1297. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1298. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1299. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1300. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1301. #define radeon_cs_parse(p) rdev->asic->cs_parse((p))
  1302. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1303. #define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
  1304. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1305. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
  1306. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
  1307. #define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
  1308. #define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
  1309. #define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
  1310. #define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
  1311. #define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
  1312. #define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
  1313. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
  1314. #define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
  1315. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
  1316. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
  1317. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
  1318. #define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
  1319. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
  1320. #define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
  1321. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
  1322. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
  1323. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
  1324. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
  1325. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
  1326. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
  1327. #define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
  1328. #define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
  1329. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
  1330. #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
  1331. #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
  1332. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1333. #define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
  1334. #define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
  1335. #define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
  1336. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
  1337. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
  1338. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
  1339. #define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
  1340. #define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
  1341. /* Common functions */
  1342. /* AGP */
  1343. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1344. extern void radeon_agp_disable(struct radeon_device *rdev);
  1345. extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  1346. extern void radeon_gart_restore(struct radeon_device *rdev);
  1347. extern int radeon_modeset_init(struct radeon_device *rdev);
  1348. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1349. extern bool radeon_card_posted(struct radeon_device *rdev);
  1350. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1351. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1352. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1353. extern void radeon_scratch_init(struct radeon_device *rdev);
  1354. extern void radeon_wb_fini(struct radeon_device *rdev);
  1355. extern int radeon_wb_init(struct radeon_device *rdev);
  1356. extern void radeon_wb_disable(struct radeon_device *rdev);
  1357. extern void radeon_surface_init(struct radeon_device *rdev);
  1358. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1359. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1360. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1361. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1362. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1363. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1364. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1365. extern int radeon_resume_kms(struct drm_device *dev);
  1366. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1367. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1368. /*
  1369. * r600 functions used by radeon_encoder.c
  1370. */
  1371. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1372. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1373. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1374. extern int ni_init_microcode(struct radeon_device *rdev);
  1375. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1376. /* radeon_acpi.c */
  1377. #if defined(CONFIG_ACPI)
  1378. extern int radeon_acpi_init(struct radeon_device *rdev);
  1379. #else
  1380. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1381. #endif
  1382. #include "radeon_object.h"
  1383. #endif