radeon.h 54 KB

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