radeon.h 56 KB

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