radeon.h 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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. extern int radeon_msi;
  91. extern int radeon_lockup_timeout;
  92. /*
  93. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  94. * symbol;
  95. */
  96. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  97. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  98. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  99. #define RADEON_IB_POOL_SIZE 16
  100. #define RADEON_DEBUGFS_MAX_COMPONENTS 32
  101. #define RADEONFB_CONN_LIMIT 4
  102. #define RADEON_BIOS_NUM_SCRATCH 8
  103. /* max number of rings */
  104. #define RADEON_NUM_RINGS 5
  105. /* fence seq are set to this number when signaled */
  106. #define RADEON_FENCE_SIGNALED_SEQ 0LL
  107. /* internal ring indices */
  108. /* r1xx+ has gfx CP ring */
  109. #define RADEON_RING_TYPE_GFX_INDEX 0
  110. /* cayman has 2 compute CP rings */
  111. #define CAYMAN_RING_TYPE_CP1_INDEX 1
  112. #define CAYMAN_RING_TYPE_CP2_INDEX 2
  113. /* R600+ has an async dma ring */
  114. #define R600_RING_TYPE_DMA_INDEX 3
  115. /* cayman add a second async dma ring */
  116. #define CAYMAN_RING_TYPE_DMA1_INDEX 4
  117. /* hardcode those limit for now */
  118. #define RADEON_VA_IB_OFFSET (1 << 20)
  119. #define RADEON_VA_RESERVED_SIZE (8 << 20)
  120. #define RADEON_IB_VM_MAX_SIZE (64 << 10)
  121. /* reset flags */
  122. #define RADEON_RESET_GFX (1 << 0)
  123. #define RADEON_RESET_COMPUTE (1 << 1)
  124. #define RADEON_RESET_DMA (1 << 2)
  125. #define RADEON_RESET_CP (1 << 3)
  126. #define RADEON_RESET_GRBM (1 << 4)
  127. #define RADEON_RESET_DMA1 (1 << 5)
  128. #define RADEON_RESET_RLC (1 << 6)
  129. #define RADEON_RESET_SEM (1 << 7)
  130. #define RADEON_RESET_IH (1 << 8)
  131. #define RADEON_RESET_VMC (1 << 9)
  132. #define RADEON_RESET_MC (1 << 10)
  133. #define RADEON_RESET_DISPLAY (1 << 11)
  134. /*
  135. * Errata workarounds.
  136. */
  137. enum radeon_pll_errata {
  138. CHIP_ERRATA_R300_CG = 0x00000001,
  139. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  140. CHIP_ERRATA_PLL_DELAY = 0x00000004
  141. };
  142. struct radeon_device;
  143. /*
  144. * BIOS.
  145. */
  146. bool radeon_get_bios(struct radeon_device *rdev);
  147. /*
  148. * Dummy page
  149. */
  150. struct radeon_dummy_page {
  151. struct page *page;
  152. dma_addr_t addr;
  153. };
  154. int radeon_dummy_page_init(struct radeon_device *rdev);
  155. void radeon_dummy_page_fini(struct radeon_device *rdev);
  156. /*
  157. * Clocks
  158. */
  159. struct radeon_clock {
  160. struct radeon_pll p1pll;
  161. struct radeon_pll p2pll;
  162. struct radeon_pll dcpll;
  163. struct radeon_pll spll;
  164. struct radeon_pll mpll;
  165. /* 10 Khz units */
  166. uint32_t default_mclk;
  167. uint32_t default_sclk;
  168. uint32_t default_dispclk;
  169. uint32_t dp_extclk;
  170. uint32_t max_pixel_clock;
  171. };
  172. /*
  173. * Power management
  174. */
  175. int radeon_pm_init(struct radeon_device *rdev);
  176. void radeon_pm_fini(struct radeon_device *rdev);
  177. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  178. void radeon_pm_suspend(struct radeon_device *rdev);
  179. void radeon_pm_resume(struct radeon_device *rdev);
  180. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  181. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  182. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  183. void rs690_pm_info(struct radeon_device *rdev);
  184. extern int rv6xx_get_temp(struct radeon_device *rdev);
  185. extern int rv770_get_temp(struct radeon_device *rdev);
  186. extern int evergreen_get_temp(struct radeon_device *rdev);
  187. extern int sumo_get_temp(struct radeon_device *rdev);
  188. extern int si_get_temp(struct radeon_device *rdev);
  189. extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  190. unsigned *bankh, unsigned *mtaspect,
  191. unsigned *tile_split);
  192. /*
  193. * Fences.
  194. */
  195. struct radeon_fence_driver {
  196. uint32_t scratch_reg;
  197. uint64_t gpu_addr;
  198. volatile uint32_t *cpu_addr;
  199. /* sync_seq is protected by ring emission lock */
  200. uint64_t sync_seq[RADEON_NUM_RINGS];
  201. atomic64_t last_seq;
  202. unsigned long last_activity;
  203. bool initialized;
  204. };
  205. struct radeon_fence {
  206. struct radeon_device *rdev;
  207. struct kref kref;
  208. /* protected by radeon_fence.lock */
  209. uint64_t seq;
  210. /* RB, DMA, etc. */
  211. unsigned ring;
  212. };
  213. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
  214. int radeon_fence_driver_init(struct radeon_device *rdev);
  215. void radeon_fence_driver_fini(struct radeon_device *rdev);
  216. void radeon_fence_driver_force_completion(struct radeon_device *rdev);
  217. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
  218. void radeon_fence_process(struct radeon_device *rdev, int ring);
  219. bool radeon_fence_signaled(struct radeon_fence *fence);
  220. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  221. int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
  222. int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
  223. int radeon_fence_wait_any(struct radeon_device *rdev,
  224. struct radeon_fence **fences,
  225. bool intr);
  226. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  227. void radeon_fence_unref(struct radeon_fence **fence);
  228. unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
  229. bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
  230. void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
  231. static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
  232. struct radeon_fence *b)
  233. {
  234. if (!a) {
  235. return b;
  236. }
  237. if (!b) {
  238. return a;
  239. }
  240. BUG_ON(a->ring != b->ring);
  241. if (a->seq > b->seq) {
  242. return a;
  243. } else {
  244. return b;
  245. }
  246. }
  247. static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
  248. struct radeon_fence *b)
  249. {
  250. if (!a) {
  251. return false;
  252. }
  253. if (!b) {
  254. return true;
  255. }
  256. BUG_ON(a->ring != b->ring);
  257. return a->seq < b->seq;
  258. }
  259. /*
  260. * Tiling registers
  261. */
  262. struct radeon_surface_reg {
  263. struct radeon_bo *bo;
  264. };
  265. #define RADEON_GEM_MAX_SURFACES 8
  266. /*
  267. * TTM.
  268. */
  269. struct radeon_mman {
  270. struct ttm_bo_global_ref bo_global_ref;
  271. struct drm_global_reference mem_global_ref;
  272. struct ttm_bo_device bdev;
  273. bool mem_global_referenced;
  274. bool initialized;
  275. };
  276. /* bo virtual address in a specific vm */
  277. struct radeon_bo_va {
  278. /* protected by bo being reserved */
  279. struct list_head bo_list;
  280. uint64_t soffset;
  281. uint64_t eoffset;
  282. uint32_t flags;
  283. bool valid;
  284. unsigned ref_count;
  285. /* protected by vm mutex */
  286. struct list_head vm_list;
  287. /* constant after initialization */
  288. struct radeon_vm *vm;
  289. struct radeon_bo *bo;
  290. };
  291. struct radeon_bo {
  292. /* Protected by gem.mutex */
  293. struct list_head list;
  294. /* Protected by tbo.reserved */
  295. u32 placements[3];
  296. struct ttm_placement placement;
  297. struct ttm_buffer_object tbo;
  298. struct ttm_bo_kmap_obj kmap;
  299. unsigned pin_count;
  300. void *kptr;
  301. u32 tiling_flags;
  302. u32 pitch;
  303. int surface_reg;
  304. /* list of all virtual address to which this bo
  305. * is associated to
  306. */
  307. struct list_head va;
  308. /* Constant after initialization */
  309. struct radeon_device *rdev;
  310. struct drm_gem_object gem_base;
  311. struct ttm_bo_kmap_obj dma_buf_vmap;
  312. int vmapping_count;
  313. };
  314. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  315. struct radeon_bo_list {
  316. struct ttm_validate_buffer tv;
  317. struct radeon_bo *bo;
  318. uint64_t gpu_offset;
  319. unsigned rdomain;
  320. unsigned wdomain;
  321. u32 tiling_flags;
  322. };
  323. /* sub-allocation manager, it has to be protected by another lock.
  324. * By conception this is an helper for other part of the driver
  325. * like the indirect buffer or semaphore, which both have their
  326. * locking.
  327. *
  328. * Principe is simple, we keep a list of sub allocation in offset
  329. * order (first entry has offset == 0, last entry has the highest
  330. * offset).
  331. *
  332. * When allocating new object we first check if there is room at
  333. * the end total_size - (last_object_offset + last_object_size) >=
  334. * alloc_size. If so we allocate new object there.
  335. *
  336. * When there is not enough room at the end, we start waiting for
  337. * each sub object until we reach object_offset+object_size >=
  338. * alloc_size, this object then become the sub object we return.
  339. *
  340. * Alignment can't be bigger than page size.
  341. *
  342. * Hole are not considered for allocation to keep things simple.
  343. * Assumption is that there won't be hole (all object on same
  344. * alignment).
  345. */
  346. struct radeon_sa_manager {
  347. wait_queue_head_t wq;
  348. struct radeon_bo *bo;
  349. struct list_head *hole;
  350. struct list_head flist[RADEON_NUM_RINGS];
  351. struct list_head olist;
  352. unsigned size;
  353. uint64_t gpu_addr;
  354. void *cpu_ptr;
  355. uint32_t domain;
  356. };
  357. struct radeon_sa_bo;
  358. /* sub-allocation buffer */
  359. struct radeon_sa_bo {
  360. struct list_head olist;
  361. struct list_head flist;
  362. struct radeon_sa_manager *manager;
  363. unsigned soffset;
  364. unsigned eoffset;
  365. struct radeon_fence *fence;
  366. };
  367. /*
  368. * GEM objects.
  369. */
  370. struct radeon_gem {
  371. struct mutex mutex;
  372. struct list_head objects;
  373. };
  374. int radeon_gem_init(struct radeon_device *rdev);
  375. void radeon_gem_fini(struct radeon_device *rdev);
  376. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  377. int alignment, int initial_domain,
  378. bool discardable, bool kernel,
  379. struct drm_gem_object **obj);
  380. int radeon_mode_dumb_create(struct drm_file *file_priv,
  381. struct drm_device *dev,
  382. struct drm_mode_create_dumb *args);
  383. int radeon_mode_dumb_mmap(struct drm_file *filp,
  384. struct drm_device *dev,
  385. uint32_t handle, uint64_t *offset_p);
  386. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  387. struct drm_device *dev,
  388. uint32_t handle);
  389. /*
  390. * Semaphores.
  391. */
  392. /* everything here is constant */
  393. struct radeon_semaphore {
  394. struct radeon_sa_bo *sa_bo;
  395. signed waiters;
  396. uint64_t gpu_addr;
  397. };
  398. int radeon_semaphore_create(struct radeon_device *rdev,
  399. struct radeon_semaphore **semaphore);
  400. void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
  401. struct radeon_semaphore *semaphore);
  402. void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
  403. struct radeon_semaphore *semaphore);
  404. int radeon_semaphore_sync_rings(struct radeon_device *rdev,
  405. struct radeon_semaphore *semaphore,
  406. int signaler, int waiter);
  407. void radeon_semaphore_free(struct radeon_device *rdev,
  408. struct radeon_semaphore **semaphore,
  409. struct radeon_fence *fence);
  410. /*
  411. * GART structures, functions & helpers
  412. */
  413. struct radeon_mc;
  414. #define RADEON_GPU_PAGE_SIZE 4096
  415. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  416. #define RADEON_GPU_PAGE_SHIFT 12
  417. #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
  418. struct radeon_gart {
  419. dma_addr_t table_addr;
  420. struct radeon_bo *robj;
  421. void *ptr;
  422. unsigned num_gpu_pages;
  423. unsigned num_cpu_pages;
  424. unsigned table_size;
  425. struct page **pages;
  426. dma_addr_t *pages_addr;
  427. bool ready;
  428. };
  429. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  430. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  431. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  432. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  433. int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  434. void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
  435. int radeon_gart_init(struct radeon_device *rdev);
  436. void radeon_gart_fini(struct radeon_device *rdev);
  437. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  438. int pages);
  439. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  440. int pages, struct page **pagelist,
  441. dma_addr_t *dma_addr);
  442. void radeon_gart_restore(struct radeon_device *rdev);
  443. /*
  444. * GPU MC structures, functions & helpers
  445. */
  446. struct radeon_mc {
  447. resource_size_t aper_size;
  448. resource_size_t aper_base;
  449. resource_size_t agp_base;
  450. /* for some chips with <= 32MB we need to lie
  451. * about vram size near mc fb location */
  452. u64 mc_vram_size;
  453. u64 visible_vram_size;
  454. u64 gtt_size;
  455. u64 gtt_start;
  456. u64 gtt_end;
  457. u64 vram_start;
  458. u64 vram_end;
  459. unsigned vram_width;
  460. u64 real_vram_size;
  461. int vram_mtrr;
  462. bool vram_is_ddr;
  463. bool igp_sideport_enabled;
  464. u64 gtt_base_align;
  465. };
  466. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  467. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  468. /*
  469. * GPU scratch registers structures, functions & helpers
  470. */
  471. struct radeon_scratch {
  472. unsigned num_reg;
  473. uint32_t reg_base;
  474. bool free[32];
  475. uint32_t reg[32];
  476. };
  477. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  478. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  479. /*
  480. * IRQS.
  481. */
  482. struct radeon_unpin_work {
  483. struct work_struct work;
  484. struct radeon_device *rdev;
  485. int crtc_id;
  486. struct radeon_fence *fence;
  487. struct drm_pending_vblank_event *event;
  488. struct radeon_bo *old_rbo;
  489. u64 new_crtc_base;
  490. };
  491. struct r500_irq_stat_regs {
  492. u32 disp_int;
  493. u32 hdmi0_status;
  494. };
  495. struct r600_irq_stat_regs {
  496. u32 disp_int;
  497. u32 disp_int_cont;
  498. u32 disp_int_cont2;
  499. u32 d1grph_int;
  500. u32 d2grph_int;
  501. u32 hdmi0_status;
  502. u32 hdmi1_status;
  503. };
  504. struct evergreen_irq_stat_regs {
  505. u32 disp_int;
  506. u32 disp_int_cont;
  507. u32 disp_int_cont2;
  508. u32 disp_int_cont3;
  509. u32 disp_int_cont4;
  510. u32 disp_int_cont5;
  511. u32 d1grph_int;
  512. u32 d2grph_int;
  513. u32 d3grph_int;
  514. u32 d4grph_int;
  515. u32 d5grph_int;
  516. u32 d6grph_int;
  517. u32 afmt_status1;
  518. u32 afmt_status2;
  519. u32 afmt_status3;
  520. u32 afmt_status4;
  521. u32 afmt_status5;
  522. u32 afmt_status6;
  523. };
  524. union radeon_irq_stat_regs {
  525. struct r500_irq_stat_regs r500;
  526. struct r600_irq_stat_regs r600;
  527. struct evergreen_irq_stat_regs evergreen;
  528. };
  529. #define RADEON_MAX_HPD_PINS 6
  530. #define RADEON_MAX_CRTCS 6
  531. #define RADEON_MAX_AFMT_BLOCKS 6
  532. struct radeon_irq {
  533. bool installed;
  534. spinlock_t lock;
  535. atomic_t ring_int[RADEON_NUM_RINGS];
  536. bool crtc_vblank_int[RADEON_MAX_CRTCS];
  537. atomic_t pflip[RADEON_MAX_CRTCS];
  538. wait_queue_head_t vblank_queue;
  539. bool hpd[RADEON_MAX_HPD_PINS];
  540. bool afmt[RADEON_MAX_AFMT_BLOCKS];
  541. union radeon_irq_stat_regs stat_regs;
  542. };
  543. int radeon_irq_kms_init(struct radeon_device *rdev);
  544. void radeon_irq_kms_fini(struct radeon_device *rdev);
  545. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
  546. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
  547. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  548. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  549. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
  550. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
  551. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  552. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  553. /*
  554. * CP & rings.
  555. */
  556. struct radeon_ib {
  557. struct radeon_sa_bo *sa_bo;
  558. uint32_t length_dw;
  559. uint64_t gpu_addr;
  560. uint32_t *ptr;
  561. int ring;
  562. struct radeon_fence *fence;
  563. struct radeon_vm *vm;
  564. bool is_const_ib;
  565. struct radeon_fence *sync_to[RADEON_NUM_RINGS];
  566. struct radeon_semaphore *semaphore;
  567. };
  568. struct radeon_ring {
  569. struct radeon_bo *ring_obj;
  570. volatile uint32_t *ring;
  571. unsigned rptr;
  572. unsigned rptr_offs;
  573. unsigned rptr_reg;
  574. unsigned rptr_save_reg;
  575. u64 next_rptr_gpu_addr;
  576. volatile u32 *next_rptr_cpu_addr;
  577. unsigned wptr;
  578. unsigned wptr_old;
  579. unsigned wptr_reg;
  580. unsigned ring_size;
  581. unsigned ring_free_dw;
  582. int count_dw;
  583. unsigned long last_activity;
  584. unsigned last_rptr;
  585. uint64_t gpu_addr;
  586. uint32_t align_mask;
  587. uint32_t ptr_mask;
  588. bool ready;
  589. u32 ptr_reg_shift;
  590. u32 ptr_reg_mask;
  591. u32 nop;
  592. u32 idx;
  593. u64 last_semaphore_signal_addr;
  594. u64 last_semaphore_wait_addr;
  595. };
  596. /*
  597. * VM
  598. */
  599. /* maximum number of VMIDs */
  600. #define RADEON_NUM_VM 16
  601. /* defines number of bits in page table versus page directory,
  602. * a page is 4KB so we have 12 bits offset, 9 bits in the page
  603. * table and the remaining 19 bits are in the page directory */
  604. #define RADEON_VM_BLOCK_SIZE 9
  605. /* number of entries in page table */
  606. #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
  607. struct radeon_vm {
  608. struct list_head list;
  609. struct list_head va;
  610. unsigned id;
  611. /* contains the page directory */
  612. struct radeon_sa_bo *page_directory;
  613. uint64_t pd_gpu_addr;
  614. /* array of page tables, one for each page directory entry */
  615. struct radeon_sa_bo **page_tables;
  616. struct mutex mutex;
  617. /* last fence for cs using this vm */
  618. struct radeon_fence *fence;
  619. /* last flush or NULL if we still need to flush */
  620. struct radeon_fence *last_flush;
  621. };
  622. struct radeon_vm_manager {
  623. struct mutex lock;
  624. struct list_head lru_vm;
  625. struct radeon_fence *active[RADEON_NUM_VM];
  626. struct radeon_sa_manager sa_manager;
  627. uint32_t max_pfn;
  628. /* number of VMIDs */
  629. unsigned nvm;
  630. /* vram base address for page table entry */
  631. u64 vram_base_offset;
  632. /* is vm enabled? */
  633. bool enabled;
  634. };
  635. /*
  636. * file private structure
  637. */
  638. struct radeon_fpriv {
  639. struct radeon_vm vm;
  640. };
  641. /*
  642. * R6xx+ IH ring
  643. */
  644. struct r600_ih {
  645. struct radeon_bo *ring_obj;
  646. volatile uint32_t *ring;
  647. unsigned rptr;
  648. unsigned ring_size;
  649. uint64_t gpu_addr;
  650. uint32_t ptr_mask;
  651. atomic_t lock;
  652. bool enabled;
  653. };
  654. struct r600_blit_cp_primitives {
  655. void (*set_render_target)(struct radeon_device *rdev, int format,
  656. int w, int h, u64 gpu_addr);
  657. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  658. u32 sync_type, u32 size,
  659. u64 mc_addr);
  660. void (*set_shaders)(struct radeon_device *rdev);
  661. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  662. void (*set_tex_resource)(struct radeon_device *rdev,
  663. int format, int w, int h, int pitch,
  664. u64 gpu_addr, u32 size);
  665. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  666. int x2, int y2);
  667. void (*draw_auto)(struct radeon_device *rdev);
  668. void (*set_default_state)(struct radeon_device *rdev);
  669. };
  670. struct r600_blit {
  671. struct radeon_bo *shader_obj;
  672. struct r600_blit_cp_primitives primitives;
  673. int max_dim;
  674. int ring_size_common;
  675. int ring_size_per_loop;
  676. u64 shader_gpu_addr;
  677. u32 vs_offset, ps_offset;
  678. u32 state_offset;
  679. u32 state_len;
  680. };
  681. /*
  682. * SI RLC stuff
  683. */
  684. struct si_rlc {
  685. /* for power gating */
  686. struct radeon_bo *save_restore_obj;
  687. uint64_t save_restore_gpu_addr;
  688. /* for clear state */
  689. struct radeon_bo *clear_state_obj;
  690. uint64_t clear_state_gpu_addr;
  691. };
  692. int radeon_ib_get(struct radeon_device *rdev, int ring,
  693. struct radeon_ib *ib, struct radeon_vm *vm,
  694. unsigned size);
  695. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
  696. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
  697. struct radeon_ib *const_ib);
  698. int radeon_ib_pool_init(struct radeon_device *rdev);
  699. void radeon_ib_pool_fini(struct radeon_device *rdev);
  700. int radeon_ib_ring_tests(struct radeon_device *rdev);
  701. /* Ring access between begin & end cannot sleep */
  702. bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
  703. struct radeon_ring *ring);
  704. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  705. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  706. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  707. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  708. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  709. void radeon_ring_undo(struct radeon_ring *ring);
  710. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  711. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  712. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  713. void radeon_ring_lockup_update(struct radeon_ring *ring);
  714. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  715. unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
  716. uint32_t **data);
  717. int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
  718. unsigned size, uint32_t *data);
  719. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  720. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  721. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  722. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  723. /* r600 async dma */
  724. void r600_dma_stop(struct radeon_device *rdev);
  725. int r600_dma_resume(struct radeon_device *rdev);
  726. void r600_dma_fini(struct radeon_device *rdev);
  727. void cayman_dma_stop(struct radeon_device *rdev);
  728. int cayman_dma_resume(struct radeon_device *rdev);
  729. void cayman_dma_fini(struct radeon_device *rdev);
  730. /*
  731. * CS.
  732. */
  733. struct radeon_cs_reloc {
  734. struct drm_gem_object *gobj;
  735. struct radeon_bo *robj;
  736. struct radeon_bo_list lobj;
  737. uint32_t handle;
  738. uint32_t flags;
  739. };
  740. struct radeon_cs_chunk {
  741. uint32_t chunk_id;
  742. uint32_t length_dw;
  743. int kpage_idx[2];
  744. uint32_t *kpage[2];
  745. uint32_t *kdata;
  746. void __user *user_ptr;
  747. int last_copied_page;
  748. int last_page_index;
  749. };
  750. struct radeon_cs_parser {
  751. struct device *dev;
  752. struct radeon_device *rdev;
  753. struct drm_file *filp;
  754. /* chunks */
  755. unsigned nchunks;
  756. struct radeon_cs_chunk *chunks;
  757. uint64_t *chunks_array;
  758. /* IB */
  759. unsigned idx;
  760. /* relocations */
  761. unsigned nrelocs;
  762. struct radeon_cs_reloc *relocs;
  763. struct radeon_cs_reloc **relocs_ptr;
  764. struct list_head validated;
  765. unsigned dma_reloc_idx;
  766. /* indices of various chunks */
  767. int chunk_ib_idx;
  768. int chunk_relocs_idx;
  769. int chunk_flags_idx;
  770. int chunk_const_ib_idx;
  771. struct radeon_ib ib;
  772. struct radeon_ib const_ib;
  773. void *track;
  774. unsigned family;
  775. int parser_error;
  776. u32 cs_flags;
  777. u32 ring;
  778. s32 priority;
  779. };
  780. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  781. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  782. struct radeon_cs_packet {
  783. unsigned idx;
  784. unsigned type;
  785. unsigned reg;
  786. unsigned opcode;
  787. int count;
  788. unsigned one_reg_wr;
  789. };
  790. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  791. struct radeon_cs_packet *pkt,
  792. unsigned idx, unsigned reg);
  793. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  794. struct radeon_cs_packet *pkt);
  795. /*
  796. * AGP
  797. */
  798. int radeon_agp_init(struct radeon_device *rdev);
  799. void radeon_agp_resume(struct radeon_device *rdev);
  800. void radeon_agp_suspend(struct radeon_device *rdev);
  801. void radeon_agp_fini(struct radeon_device *rdev);
  802. /*
  803. * Writeback
  804. */
  805. struct radeon_wb {
  806. struct radeon_bo *wb_obj;
  807. volatile uint32_t *wb;
  808. uint64_t gpu_addr;
  809. bool enabled;
  810. bool use_event;
  811. };
  812. #define RADEON_WB_SCRATCH_OFFSET 0
  813. #define RADEON_WB_RING0_NEXT_RPTR 256
  814. #define RADEON_WB_CP_RPTR_OFFSET 1024
  815. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  816. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  817. #define R600_WB_DMA_RPTR_OFFSET 1792
  818. #define R600_WB_IH_WPTR_OFFSET 2048
  819. #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
  820. #define R600_WB_EVENT_OFFSET 3072
  821. /**
  822. * struct radeon_pm - power management datas
  823. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  824. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  825. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  826. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  827. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  828. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  829. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  830. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  831. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  832. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  833. * @needed_bandwidth: current bandwidth needs
  834. *
  835. * It keeps track of various data needed to take powermanagement decision.
  836. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  837. * Equation between gpu/memory clock and available bandwidth is hw dependent
  838. * (type of memory, bus size, efficiency, ...)
  839. */
  840. enum radeon_pm_method {
  841. PM_METHOD_PROFILE,
  842. PM_METHOD_DYNPM,
  843. };
  844. enum radeon_dynpm_state {
  845. DYNPM_STATE_DISABLED,
  846. DYNPM_STATE_MINIMUM,
  847. DYNPM_STATE_PAUSED,
  848. DYNPM_STATE_ACTIVE,
  849. DYNPM_STATE_SUSPENDED,
  850. };
  851. enum radeon_dynpm_action {
  852. DYNPM_ACTION_NONE,
  853. DYNPM_ACTION_MINIMUM,
  854. DYNPM_ACTION_DOWNCLOCK,
  855. DYNPM_ACTION_UPCLOCK,
  856. DYNPM_ACTION_DEFAULT
  857. };
  858. enum radeon_voltage_type {
  859. VOLTAGE_NONE = 0,
  860. VOLTAGE_GPIO,
  861. VOLTAGE_VDDC,
  862. VOLTAGE_SW
  863. };
  864. enum radeon_pm_state_type {
  865. POWER_STATE_TYPE_DEFAULT,
  866. POWER_STATE_TYPE_POWERSAVE,
  867. POWER_STATE_TYPE_BATTERY,
  868. POWER_STATE_TYPE_BALANCED,
  869. POWER_STATE_TYPE_PERFORMANCE,
  870. };
  871. enum radeon_pm_profile_type {
  872. PM_PROFILE_DEFAULT,
  873. PM_PROFILE_AUTO,
  874. PM_PROFILE_LOW,
  875. PM_PROFILE_MID,
  876. PM_PROFILE_HIGH,
  877. };
  878. #define PM_PROFILE_DEFAULT_IDX 0
  879. #define PM_PROFILE_LOW_SH_IDX 1
  880. #define PM_PROFILE_MID_SH_IDX 2
  881. #define PM_PROFILE_HIGH_SH_IDX 3
  882. #define PM_PROFILE_LOW_MH_IDX 4
  883. #define PM_PROFILE_MID_MH_IDX 5
  884. #define PM_PROFILE_HIGH_MH_IDX 6
  885. #define PM_PROFILE_MAX 7
  886. struct radeon_pm_profile {
  887. int dpms_off_ps_idx;
  888. int dpms_on_ps_idx;
  889. int dpms_off_cm_idx;
  890. int dpms_on_cm_idx;
  891. };
  892. enum radeon_int_thermal_type {
  893. THERMAL_TYPE_NONE,
  894. THERMAL_TYPE_RV6XX,
  895. THERMAL_TYPE_RV770,
  896. THERMAL_TYPE_EVERGREEN,
  897. THERMAL_TYPE_SUMO,
  898. THERMAL_TYPE_NI,
  899. THERMAL_TYPE_SI,
  900. };
  901. struct radeon_voltage {
  902. enum radeon_voltage_type type;
  903. /* gpio voltage */
  904. struct radeon_gpio_rec gpio;
  905. u32 delay; /* delay in usec from voltage drop to sclk change */
  906. bool active_high; /* voltage drop is active when bit is high */
  907. /* VDDC voltage */
  908. u8 vddc_id; /* index into vddc voltage table */
  909. u8 vddci_id; /* index into vddci voltage table */
  910. bool vddci_enabled;
  911. /* r6xx+ sw */
  912. u16 voltage;
  913. /* evergreen+ vddci */
  914. u16 vddci;
  915. };
  916. /* clock mode flags */
  917. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  918. struct radeon_pm_clock_info {
  919. /* memory clock */
  920. u32 mclk;
  921. /* engine clock */
  922. u32 sclk;
  923. /* voltage info */
  924. struct radeon_voltage voltage;
  925. /* standardized clock flags */
  926. u32 flags;
  927. };
  928. /* state flags */
  929. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  930. struct radeon_power_state {
  931. enum radeon_pm_state_type type;
  932. struct radeon_pm_clock_info *clock_info;
  933. /* number of valid clock modes in this power state */
  934. int num_clock_modes;
  935. struct radeon_pm_clock_info *default_clock_mode;
  936. /* standardized state flags */
  937. u32 flags;
  938. u32 misc; /* vbios specific flags */
  939. u32 misc2; /* vbios specific flags */
  940. int pcie_lanes; /* pcie lanes */
  941. };
  942. /*
  943. * Some modes are overclocked by very low value, accept them
  944. */
  945. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  946. struct radeon_pm {
  947. struct mutex mutex;
  948. /* write locked while reprogramming mclk */
  949. struct rw_semaphore mclk_lock;
  950. u32 active_crtcs;
  951. int active_crtc_count;
  952. int req_vblank;
  953. bool vblank_sync;
  954. fixed20_12 max_bandwidth;
  955. fixed20_12 igp_sideport_mclk;
  956. fixed20_12 igp_system_mclk;
  957. fixed20_12 igp_ht_link_clk;
  958. fixed20_12 igp_ht_link_width;
  959. fixed20_12 k8_bandwidth;
  960. fixed20_12 sideport_bandwidth;
  961. fixed20_12 ht_bandwidth;
  962. fixed20_12 core_bandwidth;
  963. fixed20_12 sclk;
  964. fixed20_12 mclk;
  965. fixed20_12 needed_bandwidth;
  966. struct radeon_power_state *power_state;
  967. /* number of valid power states */
  968. int num_power_states;
  969. int current_power_state_index;
  970. int current_clock_mode_index;
  971. int requested_power_state_index;
  972. int requested_clock_mode_index;
  973. int default_power_state_index;
  974. u32 current_sclk;
  975. u32 current_mclk;
  976. u16 current_vddc;
  977. u16 current_vddci;
  978. u32 default_sclk;
  979. u32 default_mclk;
  980. u16 default_vddc;
  981. u16 default_vddci;
  982. struct radeon_i2c_chan *i2c_bus;
  983. /* selected pm method */
  984. enum radeon_pm_method pm_method;
  985. /* dynpm power management */
  986. struct delayed_work dynpm_idle_work;
  987. enum radeon_dynpm_state dynpm_state;
  988. enum radeon_dynpm_action dynpm_planned_action;
  989. unsigned long dynpm_action_timeout;
  990. bool dynpm_can_upclock;
  991. bool dynpm_can_downclock;
  992. /* profile-based power management */
  993. enum radeon_pm_profile_type profile;
  994. int profile_index;
  995. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  996. /* internal thermal controller on rv6xx+ */
  997. enum radeon_int_thermal_type int_thermal_type;
  998. struct device *int_hwmon_dev;
  999. };
  1000. int radeon_pm_get_type_index(struct radeon_device *rdev,
  1001. enum radeon_pm_state_type ps_type,
  1002. int instance);
  1003. struct r600_audio {
  1004. int channels;
  1005. int rate;
  1006. int bits_per_sample;
  1007. u8 status_bits;
  1008. u8 category_code;
  1009. };
  1010. /*
  1011. * Benchmarking
  1012. */
  1013. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1014. /*
  1015. * Testing
  1016. */
  1017. void radeon_test_moves(struct radeon_device *rdev);
  1018. void radeon_test_ring_sync(struct radeon_device *rdev,
  1019. struct radeon_ring *cpA,
  1020. struct radeon_ring *cpB);
  1021. void radeon_test_syncing(struct radeon_device *rdev);
  1022. /*
  1023. * Debugfs
  1024. */
  1025. struct radeon_debugfs {
  1026. struct drm_info_list *files;
  1027. unsigned num_files;
  1028. };
  1029. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1030. struct drm_info_list *files,
  1031. unsigned nfiles);
  1032. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1033. /*
  1034. * ASIC specific functions.
  1035. */
  1036. struct radeon_asic {
  1037. int (*init)(struct radeon_device *rdev);
  1038. void (*fini)(struct radeon_device *rdev);
  1039. int (*resume)(struct radeon_device *rdev);
  1040. int (*suspend)(struct radeon_device *rdev);
  1041. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1042. int (*asic_reset)(struct radeon_device *rdev);
  1043. /* ioctl hw specific callback. Some hw might want to perform special
  1044. * operation on specific ioctl. For instance on wait idle some hw
  1045. * might want to perform and HDP flush through MMIO as it seems that
  1046. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1047. * through ring.
  1048. */
  1049. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1050. /* check if 3D engine is idle */
  1051. bool (*gui_idle)(struct radeon_device *rdev);
  1052. /* wait for mc_idle */
  1053. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1054. /* gart */
  1055. struct {
  1056. void (*tlb_flush)(struct radeon_device *rdev);
  1057. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1058. } gart;
  1059. struct {
  1060. int (*init)(struct radeon_device *rdev);
  1061. void (*fini)(struct radeon_device *rdev);
  1062. u32 pt_ring_index;
  1063. void (*set_page)(struct radeon_device *rdev, uint64_t pe,
  1064. uint64_t addr, unsigned count,
  1065. uint32_t incr, uint32_t flags);
  1066. } vm;
  1067. /* ring specific callbacks */
  1068. struct {
  1069. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1070. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1071. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1072. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1073. struct radeon_semaphore *semaphore, bool emit_wait);
  1074. int (*cs_parse)(struct radeon_cs_parser *p);
  1075. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1076. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1077. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1078. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1079. void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
  1080. } ring[RADEON_NUM_RINGS];
  1081. /* irqs */
  1082. struct {
  1083. int (*set)(struct radeon_device *rdev);
  1084. int (*process)(struct radeon_device *rdev);
  1085. } irq;
  1086. /* displays */
  1087. struct {
  1088. /* display watermarks */
  1089. void (*bandwidth_update)(struct radeon_device *rdev);
  1090. /* get frame count */
  1091. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1092. /* wait for vblank */
  1093. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1094. /* set backlight level */
  1095. void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
  1096. /* get backlight level */
  1097. u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
  1098. } display;
  1099. /* copy functions for bo handling */
  1100. struct {
  1101. int (*blit)(struct radeon_device *rdev,
  1102. uint64_t src_offset,
  1103. uint64_t dst_offset,
  1104. unsigned num_gpu_pages,
  1105. struct radeon_fence **fence);
  1106. u32 blit_ring_index;
  1107. int (*dma)(struct radeon_device *rdev,
  1108. uint64_t src_offset,
  1109. uint64_t dst_offset,
  1110. unsigned num_gpu_pages,
  1111. struct radeon_fence **fence);
  1112. u32 dma_ring_index;
  1113. /* method used for bo copy */
  1114. int (*copy)(struct radeon_device *rdev,
  1115. uint64_t src_offset,
  1116. uint64_t dst_offset,
  1117. unsigned num_gpu_pages,
  1118. struct radeon_fence **fence);
  1119. /* ring used for bo copies */
  1120. u32 copy_ring_index;
  1121. } copy;
  1122. /* surfaces */
  1123. struct {
  1124. int (*set_reg)(struct radeon_device *rdev, int reg,
  1125. uint32_t tiling_flags, uint32_t pitch,
  1126. uint32_t offset, uint32_t obj_size);
  1127. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1128. } surface;
  1129. /* hotplug detect */
  1130. struct {
  1131. void (*init)(struct radeon_device *rdev);
  1132. void (*fini)(struct radeon_device *rdev);
  1133. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1134. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1135. } hpd;
  1136. /* power management */
  1137. struct {
  1138. void (*misc)(struct radeon_device *rdev);
  1139. void (*prepare)(struct radeon_device *rdev);
  1140. void (*finish)(struct radeon_device *rdev);
  1141. void (*init_profile)(struct radeon_device *rdev);
  1142. void (*get_dynpm_state)(struct radeon_device *rdev);
  1143. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1144. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1145. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1146. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1147. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1148. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1149. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1150. } pm;
  1151. /* pageflipping */
  1152. struct {
  1153. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1154. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1155. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1156. } pflip;
  1157. };
  1158. /*
  1159. * Asic structures
  1160. */
  1161. struct r100_asic {
  1162. const unsigned *reg_safe_bm;
  1163. unsigned reg_safe_bm_size;
  1164. u32 hdp_cntl;
  1165. };
  1166. struct r300_asic {
  1167. const unsigned *reg_safe_bm;
  1168. unsigned reg_safe_bm_size;
  1169. u32 resync_scratch;
  1170. u32 hdp_cntl;
  1171. };
  1172. struct r600_asic {
  1173. unsigned max_pipes;
  1174. unsigned max_tile_pipes;
  1175. unsigned max_simds;
  1176. unsigned max_backends;
  1177. unsigned max_gprs;
  1178. unsigned max_threads;
  1179. unsigned max_stack_entries;
  1180. unsigned max_hw_contexts;
  1181. unsigned max_gs_threads;
  1182. unsigned sx_max_export_size;
  1183. unsigned sx_max_export_pos_size;
  1184. unsigned sx_max_export_smx_size;
  1185. unsigned sq_num_cf_insts;
  1186. unsigned tiling_nbanks;
  1187. unsigned tiling_npipes;
  1188. unsigned tiling_group_size;
  1189. unsigned tile_config;
  1190. unsigned backend_map;
  1191. };
  1192. struct rv770_asic {
  1193. unsigned max_pipes;
  1194. unsigned max_tile_pipes;
  1195. unsigned max_simds;
  1196. unsigned max_backends;
  1197. unsigned max_gprs;
  1198. unsigned max_threads;
  1199. unsigned max_stack_entries;
  1200. unsigned max_hw_contexts;
  1201. unsigned max_gs_threads;
  1202. unsigned sx_max_export_size;
  1203. unsigned sx_max_export_pos_size;
  1204. unsigned sx_max_export_smx_size;
  1205. unsigned sq_num_cf_insts;
  1206. unsigned sx_num_of_sets;
  1207. unsigned sc_prim_fifo_size;
  1208. unsigned sc_hiz_tile_fifo_size;
  1209. unsigned sc_earlyz_tile_fifo_fize;
  1210. unsigned tiling_nbanks;
  1211. unsigned tiling_npipes;
  1212. unsigned tiling_group_size;
  1213. unsigned tile_config;
  1214. unsigned backend_map;
  1215. };
  1216. struct evergreen_asic {
  1217. unsigned num_ses;
  1218. unsigned max_pipes;
  1219. unsigned max_tile_pipes;
  1220. unsigned max_simds;
  1221. unsigned max_backends;
  1222. unsigned max_gprs;
  1223. unsigned max_threads;
  1224. unsigned max_stack_entries;
  1225. unsigned max_hw_contexts;
  1226. unsigned max_gs_threads;
  1227. unsigned sx_max_export_size;
  1228. unsigned sx_max_export_pos_size;
  1229. unsigned sx_max_export_smx_size;
  1230. unsigned sq_num_cf_insts;
  1231. unsigned sx_num_of_sets;
  1232. unsigned sc_prim_fifo_size;
  1233. unsigned sc_hiz_tile_fifo_size;
  1234. unsigned sc_earlyz_tile_fifo_size;
  1235. unsigned tiling_nbanks;
  1236. unsigned tiling_npipes;
  1237. unsigned tiling_group_size;
  1238. unsigned tile_config;
  1239. unsigned backend_map;
  1240. };
  1241. struct cayman_asic {
  1242. unsigned max_shader_engines;
  1243. unsigned max_pipes_per_simd;
  1244. unsigned max_tile_pipes;
  1245. unsigned max_simds_per_se;
  1246. unsigned max_backends_per_se;
  1247. unsigned max_texture_channel_caches;
  1248. unsigned max_gprs;
  1249. unsigned max_threads;
  1250. unsigned max_gs_threads;
  1251. unsigned max_stack_entries;
  1252. unsigned sx_num_of_sets;
  1253. unsigned sx_max_export_size;
  1254. unsigned sx_max_export_pos_size;
  1255. unsigned sx_max_export_smx_size;
  1256. unsigned max_hw_contexts;
  1257. unsigned sq_num_cf_insts;
  1258. unsigned sc_prim_fifo_size;
  1259. unsigned sc_hiz_tile_fifo_size;
  1260. unsigned sc_earlyz_tile_fifo_size;
  1261. unsigned num_shader_engines;
  1262. unsigned num_shader_pipes_per_simd;
  1263. unsigned num_tile_pipes;
  1264. unsigned num_simds_per_se;
  1265. unsigned num_backends_per_se;
  1266. unsigned backend_disable_mask_per_asic;
  1267. unsigned backend_map;
  1268. unsigned num_texture_channel_caches;
  1269. unsigned mem_max_burst_length_bytes;
  1270. unsigned mem_row_size_in_kb;
  1271. unsigned shader_engine_tile_size;
  1272. unsigned num_gpus;
  1273. unsigned multi_gpu_tile_size;
  1274. unsigned tile_config;
  1275. };
  1276. struct si_asic {
  1277. unsigned max_shader_engines;
  1278. unsigned max_tile_pipes;
  1279. unsigned max_cu_per_sh;
  1280. unsigned max_sh_per_se;
  1281. unsigned max_backends_per_se;
  1282. unsigned max_texture_channel_caches;
  1283. unsigned max_gprs;
  1284. unsigned max_gs_threads;
  1285. unsigned max_hw_contexts;
  1286. unsigned sc_prim_fifo_size_frontend;
  1287. unsigned sc_prim_fifo_size_backend;
  1288. unsigned sc_hiz_tile_fifo_size;
  1289. unsigned sc_earlyz_tile_fifo_size;
  1290. unsigned num_tile_pipes;
  1291. unsigned num_backends_per_se;
  1292. unsigned backend_disable_mask_per_asic;
  1293. unsigned backend_map;
  1294. unsigned num_texture_channel_caches;
  1295. unsigned mem_max_burst_length_bytes;
  1296. unsigned mem_row_size_in_kb;
  1297. unsigned shader_engine_tile_size;
  1298. unsigned num_gpus;
  1299. unsigned multi_gpu_tile_size;
  1300. unsigned tile_config;
  1301. };
  1302. union radeon_asic_config {
  1303. struct r300_asic r300;
  1304. struct r100_asic r100;
  1305. struct r600_asic r600;
  1306. struct rv770_asic rv770;
  1307. struct evergreen_asic evergreen;
  1308. struct cayman_asic cayman;
  1309. struct si_asic si;
  1310. };
  1311. /*
  1312. * asic initizalization from radeon_asic.c
  1313. */
  1314. void radeon_agp_disable(struct radeon_device *rdev);
  1315. int radeon_asic_init(struct radeon_device *rdev);
  1316. /*
  1317. * IOCTL.
  1318. */
  1319. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1320. struct drm_file *filp);
  1321. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1322. struct drm_file *filp);
  1323. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1324. struct drm_file *file_priv);
  1325. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1326. struct drm_file *file_priv);
  1327. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1328. struct drm_file *file_priv);
  1329. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1330. struct drm_file *file_priv);
  1331. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1332. struct drm_file *filp);
  1333. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1334. struct drm_file *filp);
  1335. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1336. struct drm_file *filp);
  1337. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1338. struct drm_file *filp);
  1339. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1340. struct drm_file *filp);
  1341. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1342. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1343. struct drm_file *filp);
  1344. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1345. struct drm_file *filp);
  1346. /* VRAM scratch page for HDP bug, default vram page */
  1347. struct r600_vram_scratch {
  1348. struct radeon_bo *robj;
  1349. volatile uint32_t *ptr;
  1350. u64 gpu_addr;
  1351. };
  1352. /*
  1353. * ACPI
  1354. */
  1355. struct radeon_atif_notification_cfg {
  1356. bool enabled;
  1357. int command_code;
  1358. };
  1359. struct radeon_atif_notifications {
  1360. bool display_switch;
  1361. bool expansion_mode_change;
  1362. bool thermal_state;
  1363. bool forced_power_state;
  1364. bool system_power_state;
  1365. bool display_conf_change;
  1366. bool px_gfx_switch;
  1367. bool brightness_change;
  1368. bool dgpu_display_event;
  1369. };
  1370. struct radeon_atif_functions {
  1371. bool system_params;
  1372. bool sbios_requests;
  1373. bool select_active_disp;
  1374. bool lid_state;
  1375. bool get_tv_standard;
  1376. bool set_tv_standard;
  1377. bool get_panel_expansion_mode;
  1378. bool set_panel_expansion_mode;
  1379. bool temperature_change;
  1380. bool graphics_device_types;
  1381. };
  1382. struct radeon_atif {
  1383. struct radeon_atif_notifications notifications;
  1384. struct radeon_atif_functions functions;
  1385. struct radeon_atif_notification_cfg notification_cfg;
  1386. struct radeon_encoder *encoder_for_bl;
  1387. };
  1388. struct radeon_atcs_functions {
  1389. bool get_ext_state;
  1390. bool pcie_perf_req;
  1391. bool pcie_dev_rdy;
  1392. bool pcie_bus_width;
  1393. };
  1394. struct radeon_atcs {
  1395. struct radeon_atcs_functions functions;
  1396. };
  1397. /*
  1398. * Core structure, functions and helpers.
  1399. */
  1400. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1401. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1402. struct radeon_device {
  1403. struct device *dev;
  1404. struct drm_device *ddev;
  1405. struct pci_dev *pdev;
  1406. struct rw_semaphore exclusive_lock;
  1407. /* ASIC */
  1408. union radeon_asic_config config;
  1409. enum radeon_family family;
  1410. unsigned long flags;
  1411. int usec_timeout;
  1412. enum radeon_pll_errata pll_errata;
  1413. int num_gb_pipes;
  1414. int num_z_pipes;
  1415. int disp_priority;
  1416. /* BIOS */
  1417. uint8_t *bios;
  1418. bool is_atom_bios;
  1419. uint16_t bios_header_start;
  1420. struct radeon_bo *stollen_vga_memory;
  1421. /* Register mmio */
  1422. resource_size_t rmmio_base;
  1423. resource_size_t rmmio_size;
  1424. /* protects concurrent MM_INDEX/DATA based register access */
  1425. spinlock_t mmio_idx_lock;
  1426. void __iomem *rmmio;
  1427. radeon_rreg_t mc_rreg;
  1428. radeon_wreg_t mc_wreg;
  1429. radeon_rreg_t pll_rreg;
  1430. radeon_wreg_t pll_wreg;
  1431. uint32_t pcie_reg_mask;
  1432. radeon_rreg_t pciep_rreg;
  1433. radeon_wreg_t pciep_wreg;
  1434. /* io port */
  1435. void __iomem *rio_mem;
  1436. resource_size_t rio_mem_size;
  1437. struct radeon_clock clock;
  1438. struct radeon_mc mc;
  1439. struct radeon_gart gart;
  1440. struct radeon_mode_info mode_info;
  1441. struct radeon_scratch scratch;
  1442. struct radeon_mman mman;
  1443. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1444. wait_queue_head_t fence_queue;
  1445. struct mutex ring_lock;
  1446. struct radeon_ring ring[RADEON_NUM_RINGS];
  1447. bool ib_pool_ready;
  1448. struct radeon_sa_manager ring_tmp_bo;
  1449. struct radeon_irq irq;
  1450. struct radeon_asic *asic;
  1451. struct radeon_gem gem;
  1452. struct radeon_pm pm;
  1453. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1454. struct radeon_wb wb;
  1455. struct radeon_dummy_page dummy_page;
  1456. bool shutdown;
  1457. bool suspend;
  1458. bool need_dma32;
  1459. bool accel_working;
  1460. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1461. const struct firmware *me_fw; /* all family ME firmware */
  1462. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1463. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1464. const struct firmware *mc_fw; /* NI MC firmware */
  1465. const struct firmware *ce_fw; /* SI CE firmware */
  1466. struct r600_blit r600_blit;
  1467. struct r600_vram_scratch vram_scratch;
  1468. int msi_enabled; /* msi enabled */
  1469. struct r600_ih ih; /* r6/700 interrupt ring */
  1470. struct si_rlc rlc;
  1471. struct work_struct hotplug_work;
  1472. struct work_struct audio_work;
  1473. int num_crtc; /* number of crtcs */
  1474. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1475. bool audio_enabled;
  1476. struct r600_audio audio_status; /* audio stuff */
  1477. struct notifier_block acpi_nb;
  1478. /* only one userspace can use Hyperz features or CMASK at a time */
  1479. struct drm_file *hyperz_filp;
  1480. struct drm_file *cmask_filp;
  1481. /* i2c buses */
  1482. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1483. /* debugfs */
  1484. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1485. unsigned debugfs_count;
  1486. /* virtual memory */
  1487. struct radeon_vm_manager vm_manager;
  1488. struct mutex gpu_clock_mutex;
  1489. /* ACPI interface */
  1490. struct radeon_atif atif;
  1491. struct radeon_atcs atcs;
  1492. };
  1493. int radeon_device_init(struct radeon_device *rdev,
  1494. struct drm_device *ddev,
  1495. struct pci_dev *pdev,
  1496. uint32_t flags);
  1497. void radeon_device_fini(struct radeon_device *rdev);
  1498. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1499. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
  1500. bool always_indirect);
  1501. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
  1502. bool always_indirect);
  1503. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1504. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1505. /*
  1506. * Cast helper
  1507. */
  1508. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1509. /*
  1510. * Registers read & write functions.
  1511. */
  1512. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1513. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1514. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1515. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1516. #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
  1517. #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
  1518. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
  1519. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
  1520. #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
  1521. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1522. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1523. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1524. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1525. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1526. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1527. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1528. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1529. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1530. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1531. #define WREG32_P(reg, val, mask) \
  1532. do { \
  1533. uint32_t tmp_ = RREG32(reg); \
  1534. tmp_ &= (mask); \
  1535. tmp_ |= ((val) & ~(mask)); \
  1536. WREG32(reg, tmp_); \
  1537. } while (0)
  1538. #define WREG32_PLL_P(reg, val, mask) \
  1539. do { \
  1540. uint32_t tmp_ = RREG32_PLL(reg); \
  1541. tmp_ &= (mask); \
  1542. tmp_ |= ((val) & ~(mask)); \
  1543. WREG32_PLL(reg, tmp_); \
  1544. } while (0)
  1545. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
  1546. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1547. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1548. /*
  1549. * Indirect registers accessor
  1550. */
  1551. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1552. {
  1553. uint32_t r;
  1554. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1555. r = RREG32(RADEON_PCIE_DATA);
  1556. return r;
  1557. }
  1558. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1559. {
  1560. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1561. WREG32(RADEON_PCIE_DATA, (v));
  1562. }
  1563. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1564. /*
  1565. * ASICs helpers.
  1566. */
  1567. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1568. (rdev->pdev->device == 0x5969))
  1569. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1570. (rdev->family == CHIP_RV200) || \
  1571. (rdev->family == CHIP_RS100) || \
  1572. (rdev->family == CHIP_RS200) || \
  1573. (rdev->family == CHIP_RV250) || \
  1574. (rdev->family == CHIP_RV280) || \
  1575. (rdev->family == CHIP_RS300))
  1576. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1577. (rdev->family == CHIP_RV350) || \
  1578. (rdev->family == CHIP_R350) || \
  1579. (rdev->family == CHIP_RV380) || \
  1580. (rdev->family == CHIP_R420) || \
  1581. (rdev->family == CHIP_R423) || \
  1582. (rdev->family == CHIP_RV410) || \
  1583. (rdev->family == CHIP_RS400) || \
  1584. (rdev->family == CHIP_RS480))
  1585. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1586. (rdev->ddev->pdev->device == 0x9443) || \
  1587. (rdev->ddev->pdev->device == 0x944B) || \
  1588. (rdev->ddev->pdev->device == 0x9506) || \
  1589. (rdev->ddev->pdev->device == 0x9509) || \
  1590. (rdev->ddev->pdev->device == 0x950F) || \
  1591. (rdev->ddev->pdev->device == 0x689C) || \
  1592. (rdev->ddev->pdev->device == 0x689D))
  1593. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1594. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1595. (rdev->family == CHIP_RS690) || \
  1596. (rdev->family == CHIP_RS740) || \
  1597. (rdev->family >= CHIP_R600))
  1598. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1599. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1600. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1601. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1602. (rdev->flags & RADEON_IS_IGP))
  1603. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1604. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  1605. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  1606. (rdev->flags & RADEON_IS_IGP))
  1607. /*
  1608. * BIOS helpers.
  1609. */
  1610. #define RBIOS8(i) (rdev->bios[i])
  1611. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1612. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1613. int radeon_combios_init(struct radeon_device *rdev);
  1614. void radeon_combios_fini(struct radeon_device *rdev);
  1615. int radeon_atombios_init(struct radeon_device *rdev);
  1616. void radeon_atombios_fini(struct radeon_device *rdev);
  1617. /*
  1618. * RING helpers.
  1619. */
  1620. #if DRM_DEBUG_CODE == 0
  1621. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1622. {
  1623. ring->ring[ring->wptr++] = v;
  1624. ring->wptr &= ring->ptr_mask;
  1625. ring->count_dw--;
  1626. ring->ring_free_dw--;
  1627. }
  1628. #else
  1629. /* With debugging this is just too big to inline */
  1630. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1631. #endif
  1632. /*
  1633. * ASICs macro.
  1634. */
  1635. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1636. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1637. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1638. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1639. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  1640. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1641. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1642. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  1643. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  1644. #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
  1645. #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
  1646. #define radeon_asic_vm_set_page(rdev, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (pe), (addr), (count), (incr), (flags)))
  1647. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  1648. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  1649. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  1650. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1651. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1652. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  1653. #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)].vm_flush((rdev), (r), (vm))
  1654. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  1655. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  1656. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  1657. #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
  1658. #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
  1659. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1660. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1661. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  1662. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  1663. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  1664. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  1665. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  1666. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  1667. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  1668. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  1669. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  1670. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  1671. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  1672. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  1673. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  1674. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  1675. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  1676. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  1677. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  1678. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  1679. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  1680. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  1681. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1682. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  1683. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  1684. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  1685. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  1686. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  1687. #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
  1688. #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
  1689. #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
  1690. #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
  1691. #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
  1692. /* Common functions */
  1693. /* AGP */
  1694. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1695. extern void radeon_agp_disable(struct radeon_device *rdev);
  1696. extern int radeon_modeset_init(struct radeon_device *rdev);
  1697. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1698. extern bool radeon_card_posted(struct radeon_device *rdev);
  1699. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1700. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1701. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1702. extern void radeon_scratch_init(struct radeon_device *rdev);
  1703. extern void radeon_wb_fini(struct radeon_device *rdev);
  1704. extern int radeon_wb_init(struct radeon_device *rdev);
  1705. extern void radeon_wb_disable(struct radeon_device *rdev);
  1706. extern void radeon_surface_init(struct radeon_device *rdev);
  1707. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1708. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1709. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1710. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1711. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1712. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1713. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1714. extern int radeon_resume_kms(struct drm_device *dev);
  1715. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1716. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1717. /*
  1718. * vm
  1719. */
  1720. int radeon_vm_manager_init(struct radeon_device *rdev);
  1721. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1722. void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1723. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1724. int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
  1725. void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
  1726. struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
  1727. struct radeon_vm *vm, int ring);
  1728. void radeon_vm_fence(struct radeon_device *rdev,
  1729. struct radeon_vm *vm,
  1730. struct radeon_fence *fence);
  1731. uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
  1732. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1733. struct radeon_vm *vm,
  1734. struct radeon_bo *bo,
  1735. struct ttm_mem_reg *mem);
  1736. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1737. struct radeon_bo *bo);
  1738. struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
  1739. struct radeon_bo *bo);
  1740. struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
  1741. struct radeon_vm *vm,
  1742. struct radeon_bo *bo);
  1743. int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  1744. struct radeon_bo_va *bo_va,
  1745. uint64_t offset,
  1746. uint32_t flags);
  1747. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1748. struct radeon_bo_va *bo_va);
  1749. /* audio */
  1750. void r600_audio_update_hdmi(struct work_struct *work);
  1751. /*
  1752. * R600 vram scratch functions
  1753. */
  1754. int r600_vram_scratch_init(struct radeon_device *rdev);
  1755. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1756. /*
  1757. * r600 cs checking helper
  1758. */
  1759. unsigned r600_mip_minify(unsigned size, unsigned level);
  1760. bool r600_fmt_is_valid_color(u32 format);
  1761. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  1762. int r600_fmt_get_blocksize(u32 format);
  1763. int r600_fmt_get_nblocksx(u32 format, u32 w);
  1764. int r600_fmt_get_nblocksy(u32 format, u32 h);
  1765. /*
  1766. * r600 functions used by radeon_encoder.c
  1767. */
  1768. struct radeon_hdmi_acr {
  1769. u32 clock;
  1770. int n_32khz;
  1771. int cts_32khz;
  1772. int n_44_1khz;
  1773. int cts_44_1khz;
  1774. int n_48khz;
  1775. int cts_48khz;
  1776. };
  1777. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  1778. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1779. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1780. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1781. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  1782. u32 tiling_pipe_num,
  1783. u32 max_rb_num,
  1784. u32 total_max_rb_num,
  1785. u32 enabled_rb_mask);
  1786. /*
  1787. * evergreen functions used by radeon_encoder.c
  1788. */
  1789. extern void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1790. extern int ni_init_microcode(struct radeon_device *rdev);
  1791. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1792. /* radeon_acpi.c */
  1793. #if defined(CONFIG_ACPI)
  1794. extern int radeon_acpi_init(struct radeon_device *rdev);
  1795. extern void radeon_acpi_fini(struct radeon_device *rdev);
  1796. #else
  1797. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1798. static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
  1799. #endif
  1800. int radeon_cs_packet_parse(struct radeon_cs_parser *p,
  1801. struct radeon_cs_packet *pkt,
  1802. unsigned idx);
  1803. bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
  1804. void radeon_cs_dump_packet(struct radeon_cs_parser *p,
  1805. struct radeon_cs_packet *pkt);
  1806. int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
  1807. struct radeon_cs_reloc **cs_reloc,
  1808. int nomm);
  1809. int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
  1810. uint32_t *vline_start_end,
  1811. uint32_t *vline_status);
  1812. #include "radeon_object.h"
  1813. #endif