radeon.h 60 KB

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