radeon.h 61 KB

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