radeon.h 58 KB

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