radeon.h 57 KB

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