radeon.h 57 KB

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