radeon.h 60 KB

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