radeon.h 61 KB

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