radeon.h 55 KB

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