radeon.h 57 KB

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