radeon.h 59 KB

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