radeon.h 59 KB

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