radeon.h 57 KB

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