radeon.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u16 *voltage);
  210. void rs690_pm_info(struct radeon_device *rdev);
  211. extern int rv6xx_get_temp(struct radeon_device *rdev);
  212. extern int rv770_get_temp(struct radeon_device *rdev);
  213. extern int evergreen_get_temp(struct radeon_device *rdev);
  214. extern int sumo_get_temp(struct radeon_device *rdev);
  215. /*
  216. * Fences.
  217. */
  218. struct radeon_fence_driver {
  219. uint32_t scratch_reg;
  220. uint64_t gpu_addr;
  221. volatile uint32_t *cpu_addr;
  222. atomic_t seq;
  223. uint32_t last_seq;
  224. unsigned long last_jiffies;
  225. unsigned long last_timeout;
  226. wait_queue_head_t queue;
  227. struct list_head created;
  228. struct list_head emitted;
  229. struct list_head signaled;
  230. bool initialized;
  231. };
  232. struct radeon_fence {
  233. struct radeon_device *rdev;
  234. struct kref kref;
  235. struct list_head list;
  236. /* protected by radeon_fence.lock */
  237. uint32_t seq;
  238. bool emitted;
  239. bool signaled;
  240. /* RB, DMA, etc. */
  241. int ring;
  242. struct radeon_semaphore *semaphore;
  243. };
  244. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
  245. int radeon_fence_driver_init(struct radeon_device *rdev);
  246. void radeon_fence_driver_fini(struct radeon_device *rdev);
  247. int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
  248. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
  249. void radeon_fence_process(struct radeon_device *rdev, int ring);
  250. bool radeon_fence_signaled(struct radeon_fence *fence);
  251. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  252. int radeon_fence_wait_next(struct radeon_device *rdev, int ring);
  253. int radeon_fence_wait_last(struct radeon_device *rdev, int ring);
  254. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  255. void radeon_fence_unref(struct radeon_fence **fence);
  256. int radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
  257. /*
  258. * Tiling registers
  259. */
  260. struct radeon_surface_reg {
  261. struct radeon_bo *bo;
  262. };
  263. #define RADEON_GEM_MAX_SURFACES 8
  264. /*
  265. * TTM.
  266. */
  267. struct radeon_mman {
  268. struct ttm_bo_global_ref bo_global_ref;
  269. struct drm_global_reference mem_global_ref;
  270. struct ttm_bo_device bdev;
  271. bool mem_global_referenced;
  272. bool initialized;
  273. };
  274. /* bo virtual address in a specific vm */
  275. struct radeon_bo_va {
  276. /* bo list is protected by bo being reserved */
  277. struct list_head bo_list;
  278. /* vm list is protected by vm mutex */
  279. struct list_head vm_list;
  280. /* constant after initialization */
  281. struct radeon_vm *vm;
  282. struct radeon_bo *bo;
  283. uint64_t soffset;
  284. uint64_t eoffset;
  285. uint32_t flags;
  286. bool valid;
  287. };
  288. struct radeon_bo {
  289. /* Protected by gem.mutex */
  290. struct list_head list;
  291. /* Protected by tbo.reserved */
  292. u32 placements[3];
  293. struct ttm_placement placement;
  294. struct ttm_buffer_object tbo;
  295. struct ttm_bo_kmap_obj kmap;
  296. unsigned pin_count;
  297. void *kptr;
  298. u32 tiling_flags;
  299. u32 pitch;
  300. int surface_reg;
  301. /* list of all virtual address to which this bo
  302. * is associated to
  303. */
  304. struct list_head va;
  305. /* Constant after initialization */
  306. struct radeon_device *rdev;
  307. struct drm_gem_object gem_base;
  308. };
  309. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  310. struct radeon_bo_list {
  311. struct ttm_validate_buffer tv;
  312. struct radeon_bo *bo;
  313. uint64_t gpu_offset;
  314. unsigned rdomain;
  315. unsigned wdomain;
  316. u32 tiling_flags;
  317. };
  318. /* sub-allocation manager, it has to be protected by another lock.
  319. * By conception this is an helper for other part of the driver
  320. * like the indirect buffer or semaphore, which both have their
  321. * locking.
  322. *
  323. * Principe is simple, we keep a list of sub allocation in offset
  324. * order (first entry has offset == 0, last entry has the highest
  325. * offset).
  326. *
  327. * When allocating new object we first check if there is room at
  328. * the end total_size - (last_object_offset + last_object_size) >=
  329. * alloc_size. If so we allocate new object there.
  330. *
  331. * When there is not enough room at the end, we start waiting for
  332. * each sub object until we reach object_offset+object_size >=
  333. * alloc_size, this object then become the sub object we return.
  334. *
  335. * Alignment can't be bigger than page size.
  336. *
  337. * Hole are not considered for allocation to keep things simple.
  338. * Assumption is that there won't be hole (all object on same
  339. * alignment).
  340. */
  341. struct radeon_sa_manager {
  342. struct radeon_bo *bo;
  343. struct list_head sa_bo;
  344. unsigned size;
  345. uint64_t gpu_addr;
  346. void *cpu_ptr;
  347. uint32_t domain;
  348. };
  349. struct radeon_sa_bo;
  350. /* sub-allocation buffer */
  351. struct radeon_sa_bo {
  352. struct list_head list;
  353. struct radeon_sa_manager *manager;
  354. unsigned offset;
  355. unsigned size;
  356. };
  357. /*
  358. * GEM objects.
  359. */
  360. struct radeon_gem {
  361. struct mutex mutex;
  362. struct list_head objects;
  363. };
  364. int radeon_gem_init(struct radeon_device *rdev);
  365. void radeon_gem_fini(struct radeon_device *rdev);
  366. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  367. int alignment, int initial_domain,
  368. bool discardable, bool kernel,
  369. struct drm_gem_object **obj);
  370. int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
  371. uint64_t *gpu_addr);
  372. void radeon_gem_object_unpin(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. };
  563. /*
  564. * locking -
  565. * mutex protects scheduled_ibs, ready, alloc_bm
  566. */
  567. struct radeon_ib_pool {
  568. struct radeon_mutex mutex;
  569. struct radeon_sa_manager sa_manager;
  570. struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
  571. bool ready;
  572. unsigned head_id;
  573. };
  574. struct radeon_ring {
  575. struct radeon_bo *ring_obj;
  576. volatile uint32_t *ring;
  577. unsigned rptr;
  578. unsigned rptr_offs;
  579. unsigned rptr_reg;
  580. unsigned wptr;
  581. unsigned wptr_old;
  582. unsigned wptr_reg;
  583. unsigned ring_size;
  584. unsigned ring_free_dw;
  585. int count_dw;
  586. uint64_t gpu_addr;
  587. uint32_t align_mask;
  588. uint32_t ptr_mask;
  589. struct mutex mutex;
  590. bool ready;
  591. u32 ptr_reg_shift;
  592. u32 ptr_reg_mask;
  593. u32 nop;
  594. };
  595. /*
  596. * VM
  597. */
  598. struct radeon_vm {
  599. struct list_head list;
  600. struct list_head va;
  601. int id;
  602. unsigned last_pfn;
  603. u64 pt_gpu_addr;
  604. u64 *pt;
  605. struct radeon_sa_bo sa_bo;
  606. struct mutex mutex;
  607. /* last fence for cs using this vm */
  608. struct radeon_fence *fence;
  609. };
  610. struct radeon_vm_funcs {
  611. int (*init)(struct radeon_device *rdev);
  612. void (*fini)(struct radeon_device *rdev);
  613. /* cs mutex must be lock for schedule_ib */
  614. int (*bind)(struct radeon_device *rdev, struct radeon_vm *vm, int id);
  615. void (*unbind)(struct radeon_device *rdev, struct radeon_vm *vm);
  616. void (*tlb_flush)(struct radeon_device *rdev, struct radeon_vm *vm);
  617. uint32_t (*page_flags)(struct radeon_device *rdev,
  618. struct radeon_vm *vm,
  619. uint32_t flags);
  620. void (*set_page)(struct radeon_device *rdev, struct radeon_vm *vm,
  621. unsigned pfn, uint64_t addr, uint32_t flags);
  622. };
  623. struct radeon_vm_manager {
  624. struct list_head lru_vm;
  625. uint32_t use_bitmap;
  626. struct radeon_sa_manager sa_manager;
  627. uint32_t max_pfn;
  628. /* fields constant after init */
  629. const struct radeon_vm_funcs *funcs;
  630. /* number of VMIDs */
  631. unsigned nvm;
  632. /* vram base address for page table entry */
  633. u64 vram_base_offset;
  634. /* is vm enabled? */
  635. bool enabled;
  636. };
  637. /*
  638. * file private structure
  639. */
  640. struct radeon_fpriv {
  641. struct radeon_vm vm;
  642. };
  643. /*
  644. * R6xx+ IH ring
  645. */
  646. struct r600_ih {
  647. struct radeon_bo *ring_obj;
  648. volatile uint32_t *ring;
  649. unsigned rptr;
  650. unsigned rptr_offs;
  651. unsigned wptr;
  652. unsigned wptr_old;
  653. unsigned ring_size;
  654. uint64_t gpu_addr;
  655. uint32_t ptr_mask;
  656. spinlock_t lock;
  657. bool enabled;
  658. };
  659. struct r600_blit_cp_primitives {
  660. void (*set_render_target)(struct radeon_device *rdev, int format,
  661. int w, int h, u64 gpu_addr);
  662. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  663. u32 sync_type, u32 size,
  664. u64 mc_addr);
  665. void (*set_shaders)(struct radeon_device *rdev);
  666. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  667. void (*set_tex_resource)(struct radeon_device *rdev,
  668. int format, int w, int h, int pitch,
  669. u64 gpu_addr, u32 size);
  670. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  671. int x2, int y2);
  672. void (*draw_auto)(struct radeon_device *rdev);
  673. void (*set_default_state)(struct radeon_device *rdev);
  674. };
  675. struct r600_blit {
  676. struct mutex mutex;
  677. struct radeon_bo *shader_obj;
  678. struct r600_blit_cp_primitives primitives;
  679. int max_dim;
  680. int ring_size_common;
  681. int ring_size_per_loop;
  682. u64 shader_gpu_addr;
  683. u32 vs_offset, ps_offset;
  684. u32 state_offset;
  685. u32 state_len;
  686. u32 vb_used, vb_total;
  687. struct radeon_ib *vb_ib;
  688. };
  689. void r600_blit_suspend(struct radeon_device *rdev);
  690. int radeon_ib_get(struct radeon_device *rdev, int ring,
  691. struct radeon_ib **ib, unsigned size);
  692. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
  693. bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib);
  694. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  695. int radeon_ib_pool_init(struct radeon_device *rdev);
  696. void radeon_ib_pool_fini(struct radeon_device *rdev);
  697. int radeon_ib_pool_start(struct radeon_device *rdev);
  698. int radeon_ib_pool_suspend(struct radeon_device *rdev);
  699. int radeon_ib_test(struct radeon_device *rdev);
  700. /* Ring access between begin & end cannot sleep */
  701. int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *cp);
  702. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  703. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  704. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  705. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  706. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  707. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  708. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  709. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  710. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  711. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  712. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  713. /*
  714. * CS.
  715. */
  716. struct radeon_cs_reloc {
  717. struct drm_gem_object *gobj;
  718. struct radeon_bo *robj;
  719. struct radeon_bo_list lobj;
  720. uint32_t handle;
  721. uint32_t flags;
  722. };
  723. struct radeon_cs_chunk {
  724. uint32_t chunk_id;
  725. uint32_t length_dw;
  726. int kpage_idx[2];
  727. uint32_t *kpage[2];
  728. uint32_t *kdata;
  729. void __user *user_ptr;
  730. int last_copied_page;
  731. int last_page_index;
  732. };
  733. struct radeon_cs_parser {
  734. struct device *dev;
  735. struct radeon_device *rdev;
  736. struct drm_file *filp;
  737. /* chunks */
  738. unsigned nchunks;
  739. struct radeon_cs_chunk *chunks;
  740. uint64_t *chunks_array;
  741. /* IB */
  742. unsigned idx;
  743. /* relocations */
  744. unsigned nrelocs;
  745. struct radeon_cs_reloc *relocs;
  746. struct radeon_cs_reloc **relocs_ptr;
  747. struct list_head validated;
  748. bool sync_to_ring[RADEON_NUM_RINGS];
  749. /* indices of various chunks */
  750. int chunk_ib_idx;
  751. int chunk_relocs_idx;
  752. int chunk_flags_idx;
  753. struct radeon_ib *ib;
  754. void *track;
  755. unsigned family;
  756. int parser_error;
  757. u32 cs_flags;
  758. u32 ring;
  759. s32 priority;
  760. };
  761. extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
  762. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  763. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  764. struct radeon_cs_packet {
  765. unsigned idx;
  766. unsigned type;
  767. unsigned reg;
  768. unsigned opcode;
  769. int count;
  770. unsigned one_reg_wr;
  771. };
  772. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  773. struct radeon_cs_packet *pkt,
  774. unsigned idx, unsigned reg);
  775. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  776. struct radeon_cs_packet *pkt);
  777. /*
  778. * AGP
  779. */
  780. int radeon_agp_init(struct radeon_device *rdev);
  781. void radeon_agp_resume(struct radeon_device *rdev);
  782. void radeon_agp_suspend(struct radeon_device *rdev);
  783. void radeon_agp_fini(struct radeon_device *rdev);
  784. /*
  785. * Writeback
  786. */
  787. struct radeon_wb {
  788. struct radeon_bo *wb_obj;
  789. volatile uint32_t *wb;
  790. uint64_t gpu_addr;
  791. bool enabled;
  792. bool use_event;
  793. };
  794. #define RADEON_WB_SCRATCH_OFFSET 0
  795. #define RADEON_WB_CP_RPTR_OFFSET 1024
  796. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  797. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  798. #define R600_WB_IH_WPTR_OFFSET 2048
  799. #define R600_WB_EVENT_OFFSET 3072
  800. /**
  801. * struct radeon_pm - power management datas
  802. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  803. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  804. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  805. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  806. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  807. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  808. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  809. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  810. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  811. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  812. * @needed_bandwidth: current bandwidth needs
  813. *
  814. * It keeps track of various data needed to take powermanagement decision.
  815. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  816. * Equation between gpu/memory clock and available bandwidth is hw dependent
  817. * (type of memory, bus size, efficiency, ...)
  818. */
  819. enum radeon_pm_method {
  820. PM_METHOD_PROFILE,
  821. PM_METHOD_DYNPM,
  822. };
  823. enum radeon_dynpm_state {
  824. DYNPM_STATE_DISABLED,
  825. DYNPM_STATE_MINIMUM,
  826. DYNPM_STATE_PAUSED,
  827. DYNPM_STATE_ACTIVE,
  828. DYNPM_STATE_SUSPENDED,
  829. };
  830. enum radeon_dynpm_action {
  831. DYNPM_ACTION_NONE,
  832. DYNPM_ACTION_MINIMUM,
  833. DYNPM_ACTION_DOWNCLOCK,
  834. DYNPM_ACTION_UPCLOCK,
  835. DYNPM_ACTION_DEFAULT
  836. };
  837. enum radeon_voltage_type {
  838. VOLTAGE_NONE = 0,
  839. VOLTAGE_GPIO,
  840. VOLTAGE_VDDC,
  841. VOLTAGE_SW
  842. };
  843. enum radeon_pm_state_type {
  844. POWER_STATE_TYPE_DEFAULT,
  845. POWER_STATE_TYPE_POWERSAVE,
  846. POWER_STATE_TYPE_BATTERY,
  847. POWER_STATE_TYPE_BALANCED,
  848. POWER_STATE_TYPE_PERFORMANCE,
  849. };
  850. enum radeon_pm_profile_type {
  851. PM_PROFILE_DEFAULT,
  852. PM_PROFILE_AUTO,
  853. PM_PROFILE_LOW,
  854. PM_PROFILE_MID,
  855. PM_PROFILE_HIGH,
  856. };
  857. #define PM_PROFILE_DEFAULT_IDX 0
  858. #define PM_PROFILE_LOW_SH_IDX 1
  859. #define PM_PROFILE_MID_SH_IDX 2
  860. #define PM_PROFILE_HIGH_SH_IDX 3
  861. #define PM_PROFILE_LOW_MH_IDX 4
  862. #define PM_PROFILE_MID_MH_IDX 5
  863. #define PM_PROFILE_HIGH_MH_IDX 6
  864. #define PM_PROFILE_MAX 7
  865. struct radeon_pm_profile {
  866. int dpms_off_ps_idx;
  867. int dpms_on_ps_idx;
  868. int dpms_off_cm_idx;
  869. int dpms_on_cm_idx;
  870. };
  871. enum radeon_int_thermal_type {
  872. THERMAL_TYPE_NONE,
  873. THERMAL_TYPE_RV6XX,
  874. THERMAL_TYPE_RV770,
  875. THERMAL_TYPE_EVERGREEN,
  876. THERMAL_TYPE_SUMO,
  877. THERMAL_TYPE_NI,
  878. };
  879. struct radeon_voltage {
  880. enum radeon_voltage_type type;
  881. /* gpio voltage */
  882. struct radeon_gpio_rec gpio;
  883. u32 delay; /* delay in usec from voltage drop to sclk change */
  884. bool active_high; /* voltage drop is active when bit is high */
  885. /* VDDC voltage */
  886. u8 vddc_id; /* index into vddc voltage table */
  887. u8 vddci_id; /* index into vddci voltage table */
  888. bool vddci_enabled;
  889. /* r6xx+ sw */
  890. u16 voltage;
  891. /* evergreen+ vddci */
  892. u16 vddci;
  893. };
  894. /* clock mode flags */
  895. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  896. struct radeon_pm_clock_info {
  897. /* memory clock */
  898. u32 mclk;
  899. /* engine clock */
  900. u32 sclk;
  901. /* voltage info */
  902. struct radeon_voltage voltage;
  903. /* standardized clock flags */
  904. u32 flags;
  905. };
  906. /* state flags */
  907. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  908. struct radeon_power_state {
  909. enum radeon_pm_state_type type;
  910. struct radeon_pm_clock_info *clock_info;
  911. /* number of valid clock modes in this power state */
  912. int num_clock_modes;
  913. struct radeon_pm_clock_info *default_clock_mode;
  914. /* standardized state flags */
  915. u32 flags;
  916. u32 misc; /* vbios specific flags */
  917. u32 misc2; /* vbios specific flags */
  918. int pcie_lanes; /* pcie lanes */
  919. };
  920. /*
  921. * Some modes are overclocked by very low value, accept them
  922. */
  923. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  924. struct radeon_pm {
  925. struct mutex mutex;
  926. u32 active_crtcs;
  927. int active_crtc_count;
  928. int req_vblank;
  929. bool vblank_sync;
  930. bool gui_idle;
  931. fixed20_12 max_bandwidth;
  932. fixed20_12 igp_sideport_mclk;
  933. fixed20_12 igp_system_mclk;
  934. fixed20_12 igp_ht_link_clk;
  935. fixed20_12 igp_ht_link_width;
  936. fixed20_12 k8_bandwidth;
  937. fixed20_12 sideport_bandwidth;
  938. fixed20_12 ht_bandwidth;
  939. fixed20_12 core_bandwidth;
  940. fixed20_12 sclk;
  941. fixed20_12 mclk;
  942. fixed20_12 needed_bandwidth;
  943. struct radeon_power_state *power_state;
  944. /* number of valid power states */
  945. int num_power_states;
  946. int current_power_state_index;
  947. int current_clock_mode_index;
  948. int requested_power_state_index;
  949. int requested_clock_mode_index;
  950. int default_power_state_index;
  951. u32 current_sclk;
  952. u32 current_mclk;
  953. u16 current_vddc;
  954. u16 current_vddci;
  955. u32 default_sclk;
  956. u32 default_mclk;
  957. u16 default_vddc;
  958. u16 default_vddci;
  959. struct radeon_i2c_chan *i2c_bus;
  960. /* selected pm method */
  961. enum radeon_pm_method pm_method;
  962. /* dynpm power management */
  963. struct delayed_work dynpm_idle_work;
  964. enum radeon_dynpm_state dynpm_state;
  965. enum radeon_dynpm_action dynpm_planned_action;
  966. unsigned long dynpm_action_timeout;
  967. bool dynpm_can_upclock;
  968. bool dynpm_can_downclock;
  969. /* profile-based power management */
  970. enum radeon_pm_profile_type profile;
  971. int profile_index;
  972. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  973. /* internal thermal controller on rv6xx+ */
  974. enum radeon_int_thermal_type int_thermal_type;
  975. struct device *int_hwmon_dev;
  976. };
  977. int radeon_pm_get_type_index(struct radeon_device *rdev,
  978. enum radeon_pm_state_type ps_type,
  979. int instance);
  980. /*
  981. * Benchmarking
  982. */
  983. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  984. /*
  985. * Testing
  986. */
  987. void radeon_test_moves(struct radeon_device *rdev);
  988. void radeon_test_ring_sync(struct radeon_device *rdev,
  989. struct radeon_ring *cpA,
  990. struct radeon_ring *cpB);
  991. void radeon_test_syncing(struct radeon_device *rdev);
  992. /*
  993. * Debugfs
  994. */
  995. struct radeon_debugfs {
  996. struct drm_info_list *files;
  997. unsigned num_files;
  998. };
  999. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1000. struct drm_info_list *files,
  1001. unsigned nfiles);
  1002. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1003. /*
  1004. * ASIC specific functions.
  1005. */
  1006. struct radeon_asic {
  1007. int (*init)(struct radeon_device *rdev);
  1008. void (*fini)(struct radeon_device *rdev);
  1009. int (*resume)(struct radeon_device *rdev);
  1010. int (*suspend)(struct radeon_device *rdev);
  1011. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1012. bool (*gpu_is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1013. int (*asic_reset)(struct radeon_device *rdev);
  1014. void (*gart_tlb_flush)(struct radeon_device *rdev);
  1015. int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1016. int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
  1017. void (*cp_fini)(struct radeon_device *rdev);
  1018. void (*cp_disable)(struct radeon_device *rdev);
  1019. void (*ring_start)(struct radeon_device *rdev);
  1020. struct {
  1021. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1022. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1023. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1024. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1025. struct radeon_semaphore *semaphore, bool emit_wait);
  1026. } ring[RADEON_NUM_RINGS];
  1027. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1028. int (*irq_set)(struct radeon_device *rdev);
  1029. int (*irq_process)(struct radeon_device *rdev);
  1030. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1031. int (*cs_parse)(struct radeon_cs_parser *p);
  1032. int (*copy_blit)(struct radeon_device *rdev,
  1033. uint64_t src_offset,
  1034. uint64_t dst_offset,
  1035. unsigned num_gpu_pages,
  1036. struct radeon_fence *fence);
  1037. int (*copy_dma)(struct radeon_device *rdev,
  1038. uint64_t src_offset,
  1039. uint64_t dst_offset,
  1040. unsigned num_gpu_pages,
  1041. struct radeon_fence *fence);
  1042. int (*copy)(struct radeon_device *rdev,
  1043. uint64_t src_offset,
  1044. uint64_t dst_offset,
  1045. unsigned num_gpu_pages,
  1046. struct radeon_fence *fence);
  1047. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1048. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1049. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1050. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1051. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1052. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1053. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1054. int (*set_surface_reg)(struct radeon_device *rdev, int reg,
  1055. uint32_t tiling_flags, uint32_t pitch,
  1056. uint32_t offset, uint32_t obj_size);
  1057. void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
  1058. void (*bandwidth_update)(struct radeon_device *rdev);
  1059. void (*hpd_init)(struct radeon_device *rdev);
  1060. void (*hpd_fini)(struct radeon_device *rdev);
  1061. bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1062. void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1063. /* ioctl hw specific callback. Some hw might want to perform special
  1064. * operation on specific ioctl. For instance on wait idle some hw
  1065. * might want to perform and HDP flush through MMIO as it seems that
  1066. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1067. * through ring.
  1068. */
  1069. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1070. bool (*gui_idle)(struct radeon_device *rdev);
  1071. /* power management */
  1072. void (*pm_misc)(struct radeon_device *rdev);
  1073. void (*pm_prepare)(struct radeon_device *rdev);
  1074. void (*pm_finish)(struct radeon_device *rdev);
  1075. void (*pm_init_profile)(struct radeon_device *rdev);
  1076. void (*pm_get_dynpm_state)(struct radeon_device *rdev);
  1077. /* pageflipping */
  1078. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1079. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1080. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1081. };
  1082. /*
  1083. * Asic structures
  1084. */
  1085. struct r100_gpu_lockup {
  1086. unsigned long last_jiffies;
  1087. u32 last_cp_rptr;
  1088. };
  1089. struct r100_asic {
  1090. const unsigned *reg_safe_bm;
  1091. unsigned reg_safe_bm_size;
  1092. u32 hdp_cntl;
  1093. struct r100_gpu_lockup lockup;
  1094. };
  1095. struct r300_asic {
  1096. const unsigned *reg_safe_bm;
  1097. unsigned reg_safe_bm_size;
  1098. u32 resync_scratch;
  1099. u32 hdp_cntl;
  1100. struct r100_gpu_lockup lockup;
  1101. };
  1102. struct r600_asic {
  1103. unsigned max_pipes;
  1104. unsigned max_tile_pipes;
  1105. unsigned max_simds;
  1106. unsigned max_backends;
  1107. unsigned max_gprs;
  1108. unsigned max_threads;
  1109. unsigned max_stack_entries;
  1110. unsigned max_hw_contexts;
  1111. unsigned max_gs_threads;
  1112. unsigned sx_max_export_size;
  1113. unsigned sx_max_export_pos_size;
  1114. unsigned sx_max_export_smx_size;
  1115. unsigned sq_num_cf_insts;
  1116. unsigned tiling_nbanks;
  1117. unsigned tiling_npipes;
  1118. unsigned tiling_group_size;
  1119. unsigned tile_config;
  1120. unsigned backend_map;
  1121. struct r100_gpu_lockup lockup;
  1122. };
  1123. struct rv770_asic {
  1124. unsigned max_pipes;
  1125. unsigned max_tile_pipes;
  1126. unsigned max_simds;
  1127. unsigned max_backends;
  1128. unsigned max_gprs;
  1129. unsigned max_threads;
  1130. unsigned max_stack_entries;
  1131. unsigned max_hw_contexts;
  1132. unsigned max_gs_threads;
  1133. unsigned sx_max_export_size;
  1134. unsigned sx_max_export_pos_size;
  1135. unsigned sx_max_export_smx_size;
  1136. unsigned sq_num_cf_insts;
  1137. unsigned sx_num_of_sets;
  1138. unsigned sc_prim_fifo_size;
  1139. unsigned sc_hiz_tile_fifo_size;
  1140. unsigned sc_earlyz_tile_fifo_fize;
  1141. unsigned tiling_nbanks;
  1142. unsigned tiling_npipes;
  1143. unsigned tiling_group_size;
  1144. unsigned tile_config;
  1145. unsigned backend_map;
  1146. struct r100_gpu_lockup lockup;
  1147. };
  1148. struct evergreen_asic {
  1149. unsigned num_ses;
  1150. unsigned max_pipes;
  1151. unsigned max_tile_pipes;
  1152. unsigned max_simds;
  1153. unsigned max_backends;
  1154. unsigned max_gprs;
  1155. unsigned max_threads;
  1156. unsigned max_stack_entries;
  1157. unsigned max_hw_contexts;
  1158. unsigned max_gs_threads;
  1159. unsigned sx_max_export_size;
  1160. unsigned sx_max_export_pos_size;
  1161. unsigned sx_max_export_smx_size;
  1162. unsigned sq_num_cf_insts;
  1163. unsigned sx_num_of_sets;
  1164. unsigned sc_prim_fifo_size;
  1165. unsigned sc_hiz_tile_fifo_size;
  1166. unsigned sc_earlyz_tile_fifo_size;
  1167. unsigned tiling_nbanks;
  1168. unsigned tiling_npipes;
  1169. unsigned tiling_group_size;
  1170. unsigned tile_config;
  1171. unsigned backend_map;
  1172. struct r100_gpu_lockup lockup;
  1173. };
  1174. struct cayman_asic {
  1175. unsigned max_shader_engines;
  1176. unsigned max_pipes_per_simd;
  1177. unsigned max_tile_pipes;
  1178. unsigned max_simds_per_se;
  1179. unsigned max_backends_per_se;
  1180. unsigned max_texture_channel_caches;
  1181. unsigned max_gprs;
  1182. unsigned max_threads;
  1183. unsigned max_gs_threads;
  1184. unsigned max_stack_entries;
  1185. unsigned sx_num_of_sets;
  1186. unsigned sx_max_export_size;
  1187. unsigned sx_max_export_pos_size;
  1188. unsigned sx_max_export_smx_size;
  1189. unsigned max_hw_contexts;
  1190. unsigned sq_num_cf_insts;
  1191. unsigned sc_prim_fifo_size;
  1192. unsigned sc_hiz_tile_fifo_size;
  1193. unsigned sc_earlyz_tile_fifo_size;
  1194. unsigned num_shader_engines;
  1195. unsigned num_shader_pipes_per_simd;
  1196. unsigned num_tile_pipes;
  1197. unsigned num_simds_per_se;
  1198. unsigned num_backends_per_se;
  1199. unsigned backend_disable_mask_per_asic;
  1200. unsigned backend_map;
  1201. unsigned num_texture_channel_caches;
  1202. unsigned mem_max_burst_length_bytes;
  1203. unsigned mem_row_size_in_kb;
  1204. unsigned shader_engine_tile_size;
  1205. unsigned num_gpus;
  1206. unsigned multi_gpu_tile_size;
  1207. unsigned tile_config;
  1208. struct r100_gpu_lockup lockup;
  1209. };
  1210. union radeon_asic_config {
  1211. struct r300_asic r300;
  1212. struct r100_asic r100;
  1213. struct r600_asic r600;
  1214. struct rv770_asic rv770;
  1215. struct evergreen_asic evergreen;
  1216. struct cayman_asic cayman;
  1217. };
  1218. /*
  1219. * asic initizalization from radeon_asic.c
  1220. */
  1221. void radeon_agp_disable(struct radeon_device *rdev);
  1222. int radeon_asic_init(struct radeon_device *rdev);
  1223. /*
  1224. * IOCTL.
  1225. */
  1226. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1227. struct drm_file *filp);
  1228. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1229. struct drm_file *filp);
  1230. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1231. struct drm_file *file_priv);
  1232. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1233. struct drm_file *file_priv);
  1234. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1235. struct drm_file *file_priv);
  1236. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1237. struct drm_file *file_priv);
  1238. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1239. struct drm_file *filp);
  1240. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1241. struct drm_file *filp);
  1242. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1243. struct drm_file *filp);
  1244. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1245. struct drm_file *filp);
  1246. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1247. struct drm_file *filp);
  1248. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1249. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1250. struct drm_file *filp);
  1251. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1252. struct drm_file *filp);
  1253. /* VRAM scratch page for HDP bug, default vram page */
  1254. struct r600_vram_scratch {
  1255. struct radeon_bo *robj;
  1256. volatile uint32_t *ptr;
  1257. u64 gpu_addr;
  1258. };
  1259. /*
  1260. * Core structure, functions and helpers.
  1261. */
  1262. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1263. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1264. struct radeon_device {
  1265. struct device *dev;
  1266. struct drm_device *ddev;
  1267. struct pci_dev *pdev;
  1268. /* ASIC */
  1269. union radeon_asic_config config;
  1270. enum radeon_family family;
  1271. unsigned long flags;
  1272. int usec_timeout;
  1273. enum radeon_pll_errata pll_errata;
  1274. int num_gb_pipes;
  1275. int num_z_pipes;
  1276. int disp_priority;
  1277. /* BIOS */
  1278. uint8_t *bios;
  1279. bool is_atom_bios;
  1280. uint16_t bios_header_start;
  1281. struct radeon_bo *stollen_vga_memory;
  1282. /* Register mmio */
  1283. resource_size_t rmmio_base;
  1284. resource_size_t rmmio_size;
  1285. void __iomem *rmmio;
  1286. radeon_rreg_t mc_rreg;
  1287. radeon_wreg_t mc_wreg;
  1288. radeon_rreg_t pll_rreg;
  1289. radeon_wreg_t pll_wreg;
  1290. uint32_t pcie_reg_mask;
  1291. radeon_rreg_t pciep_rreg;
  1292. radeon_wreg_t pciep_wreg;
  1293. /* io port */
  1294. void __iomem *rio_mem;
  1295. resource_size_t rio_mem_size;
  1296. struct radeon_clock clock;
  1297. struct radeon_mc mc;
  1298. struct radeon_gart gart;
  1299. struct radeon_mode_info mode_info;
  1300. struct radeon_scratch scratch;
  1301. struct radeon_mman mman;
  1302. rwlock_t fence_lock;
  1303. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1304. struct radeon_semaphore_driver semaphore_drv;
  1305. struct radeon_ring ring[RADEON_NUM_RINGS];
  1306. struct radeon_ib_pool ib_pool;
  1307. struct radeon_irq irq;
  1308. struct radeon_asic *asic;
  1309. struct radeon_gem gem;
  1310. struct radeon_pm pm;
  1311. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1312. struct radeon_mutex cs_mutex;
  1313. struct radeon_wb wb;
  1314. struct radeon_dummy_page dummy_page;
  1315. bool gpu_lockup;
  1316. bool shutdown;
  1317. bool suspend;
  1318. bool need_dma32;
  1319. bool accel_working;
  1320. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1321. const struct firmware *me_fw; /* all family ME firmware */
  1322. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1323. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1324. const struct firmware *mc_fw; /* NI MC firmware */
  1325. struct r600_blit r600_blit;
  1326. struct r600_vram_scratch vram_scratch;
  1327. int msi_enabled; /* msi enabled */
  1328. struct r600_ih ih; /* r6/700 interrupt ring */
  1329. struct work_struct hotplug_work;
  1330. int num_crtc; /* number of crtcs */
  1331. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1332. struct mutex vram_mutex;
  1333. /* audio stuff */
  1334. bool audio_enabled;
  1335. struct timer_list audio_timer;
  1336. int audio_channels;
  1337. int audio_rate;
  1338. int audio_bits_per_sample;
  1339. uint8_t audio_status_bits;
  1340. uint8_t audio_category_code;
  1341. struct notifier_block acpi_nb;
  1342. /* only one userspace can use Hyperz features or CMASK at a time */
  1343. struct drm_file *hyperz_filp;
  1344. struct drm_file *cmask_filp;
  1345. /* i2c buses */
  1346. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1347. /* debugfs */
  1348. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1349. unsigned debugfs_count;
  1350. /* virtual memory */
  1351. struct radeon_vm_manager vm_manager;
  1352. /* ring used for bo copies */
  1353. u32 copy_ring;
  1354. };
  1355. int radeon_device_init(struct radeon_device *rdev,
  1356. struct drm_device *ddev,
  1357. struct pci_dev *pdev,
  1358. uint32_t flags);
  1359. void radeon_device_fini(struct radeon_device *rdev);
  1360. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1361. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg);
  1362. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v);
  1363. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1364. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1365. /*
  1366. * Cast helper
  1367. */
  1368. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1369. /*
  1370. * Registers read & write functions.
  1371. */
  1372. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1373. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1374. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1375. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1376. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1377. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
  1378. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1379. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1380. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1381. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1382. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1383. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1384. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1385. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1386. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1387. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1388. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1389. #define WREG32_P(reg, val, mask) \
  1390. do { \
  1391. uint32_t tmp_ = RREG32(reg); \
  1392. tmp_ &= (mask); \
  1393. tmp_ |= ((val) & ~(mask)); \
  1394. WREG32(reg, tmp_); \
  1395. } while (0)
  1396. #define WREG32_PLL_P(reg, val, mask) \
  1397. do { \
  1398. uint32_t tmp_ = RREG32_PLL(reg); \
  1399. tmp_ &= (mask); \
  1400. tmp_ |= ((val) & ~(mask)); \
  1401. WREG32_PLL(reg, tmp_); \
  1402. } while (0)
  1403. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
  1404. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1405. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1406. /*
  1407. * Indirect registers accessor
  1408. */
  1409. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1410. {
  1411. uint32_t r;
  1412. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1413. r = RREG32(RADEON_PCIE_DATA);
  1414. return r;
  1415. }
  1416. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1417. {
  1418. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1419. WREG32(RADEON_PCIE_DATA, (v));
  1420. }
  1421. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1422. /*
  1423. * ASICs helpers.
  1424. */
  1425. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1426. (rdev->pdev->device == 0x5969))
  1427. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1428. (rdev->family == CHIP_RV200) || \
  1429. (rdev->family == CHIP_RS100) || \
  1430. (rdev->family == CHIP_RS200) || \
  1431. (rdev->family == CHIP_RV250) || \
  1432. (rdev->family == CHIP_RV280) || \
  1433. (rdev->family == CHIP_RS300))
  1434. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1435. (rdev->family == CHIP_RV350) || \
  1436. (rdev->family == CHIP_R350) || \
  1437. (rdev->family == CHIP_RV380) || \
  1438. (rdev->family == CHIP_R420) || \
  1439. (rdev->family == CHIP_R423) || \
  1440. (rdev->family == CHIP_RV410) || \
  1441. (rdev->family == CHIP_RS400) || \
  1442. (rdev->family == CHIP_RS480))
  1443. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1444. (rdev->ddev->pdev->device == 0x9443) || \
  1445. (rdev->ddev->pdev->device == 0x944B) || \
  1446. (rdev->ddev->pdev->device == 0x9506) || \
  1447. (rdev->ddev->pdev->device == 0x9509) || \
  1448. (rdev->ddev->pdev->device == 0x950F) || \
  1449. (rdev->ddev->pdev->device == 0x689C) || \
  1450. (rdev->ddev->pdev->device == 0x689D))
  1451. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1452. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1453. (rdev->family == CHIP_RS690) || \
  1454. (rdev->family == CHIP_RS740) || \
  1455. (rdev->family >= CHIP_R600))
  1456. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1457. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1458. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1459. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1460. (rdev->flags & RADEON_IS_IGP))
  1461. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1462. /*
  1463. * BIOS helpers.
  1464. */
  1465. #define RBIOS8(i) (rdev->bios[i])
  1466. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1467. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1468. int radeon_combios_init(struct radeon_device *rdev);
  1469. void radeon_combios_fini(struct radeon_device *rdev);
  1470. int radeon_atombios_init(struct radeon_device *rdev);
  1471. void radeon_atombios_fini(struct radeon_device *rdev);
  1472. /*
  1473. * RING helpers.
  1474. */
  1475. #if DRM_DEBUG_CODE == 0
  1476. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1477. {
  1478. ring->ring[ring->wptr++] = v;
  1479. ring->wptr &= ring->ptr_mask;
  1480. ring->count_dw--;
  1481. ring->ring_free_dw--;
  1482. }
  1483. #else
  1484. /* With debugging this is just too big to inline */
  1485. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1486. #endif
  1487. /*
  1488. * ASICs macro.
  1489. */
  1490. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1491. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1492. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1493. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1494. #define radeon_cs_parse(p) rdev->asic->cs_parse((p))
  1495. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1496. #define radeon_gpu_is_lockup(rdev, cp) (rdev)->asic->gpu_is_lockup((rdev), (cp))
  1497. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1498. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
  1499. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
  1500. #define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
  1501. #define radeon_ring_test(rdev, cp) (rdev)->asic->ring_test((rdev), (cp))
  1502. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1503. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1504. #define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
  1505. #define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
  1506. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
  1507. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1508. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1509. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
  1510. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
  1511. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
  1512. #define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
  1513. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
  1514. #define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
  1515. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
  1516. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
  1517. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
  1518. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
  1519. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
  1520. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
  1521. #define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
  1522. #define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
  1523. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
  1524. #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
  1525. #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
  1526. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1527. #define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
  1528. #define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
  1529. #define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
  1530. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
  1531. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
  1532. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
  1533. #define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
  1534. #define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
  1535. /* Common functions */
  1536. /* AGP */
  1537. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1538. extern void radeon_agp_disable(struct radeon_device *rdev);
  1539. extern int radeon_modeset_init(struct radeon_device *rdev);
  1540. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1541. extern bool radeon_card_posted(struct radeon_device *rdev);
  1542. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1543. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1544. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1545. extern void radeon_scratch_init(struct radeon_device *rdev);
  1546. extern void radeon_wb_fini(struct radeon_device *rdev);
  1547. extern int radeon_wb_init(struct radeon_device *rdev);
  1548. extern void radeon_wb_disable(struct radeon_device *rdev);
  1549. extern void radeon_surface_init(struct radeon_device *rdev);
  1550. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1551. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1552. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1553. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1554. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1555. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1556. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1557. extern int radeon_resume_kms(struct drm_device *dev);
  1558. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1559. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1560. /*
  1561. * vm
  1562. */
  1563. int radeon_vm_manager_init(struct radeon_device *rdev);
  1564. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1565. int radeon_vm_manager_start(struct radeon_device *rdev);
  1566. int radeon_vm_manager_suspend(struct radeon_device *rdev);
  1567. int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1568. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1569. int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm);
  1570. void radeon_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm);
  1571. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1572. struct radeon_vm *vm,
  1573. struct radeon_bo *bo,
  1574. struct ttm_mem_reg *mem);
  1575. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1576. struct radeon_bo *bo);
  1577. int radeon_vm_bo_add(struct radeon_device *rdev,
  1578. struct radeon_vm *vm,
  1579. struct radeon_bo *bo,
  1580. uint64_t offset,
  1581. uint32_t flags);
  1582. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1583. struct radeon_vm *vm,
  1584. struct radeon_bo *bo);
  1585. /*
  1586. * R600 vram scratch functions
  1587. */
  1588. int r600_vram_scratch_init(struct radeon_device *rdev);
  1589. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1590. /*
  1591. * r600 functions used by radeon_encoder.c
  1592. */
  1593. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1594. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1595. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1596. extern int ni_init_microcode(struct radeon_device *rdev);
  1597. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1598. /* radeon_acpi.c */
  1599. #if defined(CONFIG_ACPI)
  1600. extern int radeon_acpi_init(struct radeon_device *rdev);
  1601. #else
  1602. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1603. #endif
  1604. #include "radeon_object.h"
  1605. #endif