radeon.h 57 KB

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