radeon.h 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #ifndef __RADEON_H__
  29. #define __RADEON_H__
  30. /* TODO: Here are things that needs to be done :
  31. * - surface allocator & initializer : (bit like scratch reg) should
  32. * initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
  33. * related to surface
  34. * - WB : write back stuff (do it bit like scratch reg things)
  35. * - Vblank : look at Jesse's rework and what we should do
  36. * - r600/r700: gart & cp
  37. * - cs : clean cs ioctl use bitmap & things like that.
  38. * - power management stuff
  39. * - Barrier in gart code
  40. * - Unmappabled vram ?
  41. * - TESTING, TESTING, TESTING
  42. */
  43. /* Initialization path:
  44. * We expect that acceleration initialization might fail for various
  45. * reasons even thought we work hard to make it works on most
  46. * configurations. In order to still have a working userspace in such
  47. * situation the init path must succeed up to the memory controller
  48. * initialization point. Failure before this point are considered as
  49. * fatal error. Here is the init callchain :
  50. * radeon_device_init perform common structure, mutex initialization
  51. * asic_init setup the GPU memory layout and perform all
  52. * one time initialization (failure in this
  53. * function are considered fatal)
  54. * asic_startup setup the GPU acceleration, in order to
  55. * follow guideline the first thing this
  56. * function should do is setting the GPU
  57. * memory controller (only MC setup failure
  58. * are considered as fatal)
  59. */
  60. #include <linux/atomic.h>
  61. #include <linux/wait.h>
  62. #include <linux/list.h>
  63. #include <linux/kref.h>
  64. #include <ttm/ttm_bo_api.h>
  65. #include <ttm/ttm_bo_driver.h>
  66. #include <ttm/ttm_placement.h>
  67. #include <ttm/ttm_module.h>
  68. #include <ttm/ttm_execbuf_util.h>
  69. #include "radeon_family.h"
  70. #include "radeon_mode.h"
  71. #include "radeon_reg.h"
  72. /*
  73. * Modules parameters.
  74. */
  75. extern int radeon_no_wb;
  76. extern int radeon_modeset;
  77. extern int radeon_dynclks;
  78. extern int radeon_r4xx_atom;
  79. extern int radeon_agpmode;
  80. extern int radeon_vram_limit;
  81. extern int radeon_gart_size;
  82. extern int radeon_benchmarking;
  83. extern int radeon_testing;
  84. extern int radeon_connector_table;
  85. extern int radeon_tv;
  86. extern int radeon_audio;
  87. extern int radeon_disp_priority;
  88. extern int radeon_hw_i2c;
  89. extern int radeon_pcie_gen2;
  90. extern int radeon_msi;
  91. extern int radeon_lockup_timeout;
  92. /*
  93. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  94. * symbol;
  95. */
  96. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  97. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  98. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  99. #define RADEON_IB_POOL_SIZE 16
  100. #define RADEON_DEBUGFS_MAX_COMPONENTS 32
  101. #define RADEONFB_CONN_LIMIT 4
  102. #define RADEON_BIOS_NUM_SCRATCH 8
  103. /* max number of rings */
  104. #define RADEON_NUM_RINGS 3
  105. /* fence seq are set to this number when signaled */
  106. #define RADEON_FENCE_SIGNALED_SEQ 0LL
  107. #define RADEON_FENCE_NOTEMITED_SEQ (~0LL)
  108. /* internal ring indices */
  109. /* r1xx+ has gfx CP ring */
  110. #define RADEON_RING_TYPE_GFX_INDEX 0
  111. /* cayman has 2 compute CP rings */
  112. #define CAYMAN_RING_TYPE_CP1_INDEX 1
  113. #define CAYMAN_RING_TYPE_CP2_INDEX 2
  114. /* hardcode those limit for now */
  115. #define RADEON_VA_RESERVED_SIZE (8 << 20)
  116. #define RADEON_IB_VM_MAX_SIZE (64 << 10)
  117. /*
  118. * Errata workarounds.
  119. */
  120. enum radeon_pll_errata {
  121. CHIP_ERRATA_R300_CG = 0x00000001,
  122. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  123. CHIP_ERRATA_PLL_DELAY = 0x00000004
  124. };
  125. struct radeon_device;
  126. /*
  127. * BIOS.
  128. */
  129. #define ATRM_BIOS_PAGE 4096
  130. #if defined(CONFIG_VGA_SWITCHEROO)
  131. bool radeon_atrm_supported(struct pci_dev *pdev);
  132. int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
  133. #else
  134. static inline bool radeon_atrm_supported(struct pci_dev *pdev)
  135. {
  136. return false;
  137. }
  138. static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
  139. return -EINVAL;
  140. }
  141. #endif
  142. bool radeon_get_bios(struct radeon_device *rdev);
  143. /*
  144. * Mutex which allows recursive locking from the same process.
  145. */
  146. struct radeon_mutex {
  147. struct mutex mutex;
  148. struct task_struct *owner;
  149. int level;
  150. };
  151. static inline void radeon_mutex_init(struct radeon_mutex *mutex)
  152. {
  153. mutex_init(&mutex->mutex);
  154. mutex->owner = NULL;
  155. mutex->level = 0;
  156. }
  157. static inline void radeon_mutex_lock(struct radeon_mutex *mutex)
  158. {
  159. if (mutex_trylock(&mutex->mutex)) {
  160. /* The mutex was unlocked before, so it's ours now */
  161. mutex->owner = current;
  162. } else if (mutex->owner != current) {
  163. /* Another process locked the mutex, take it */
  164. mutex_lock(&mutex->mutex);
  165. mutex->owner = current;
  166. }
  167. /* Otherwise the mutex was already locked by this process */
  168. mutex->level++;
  169. }
  170. static inline void radeon_mutex_unlock(struct radeon_mutex *mutex)
  171. {
  172. if (--mutex->level > 0)
  173. return;
  174. mutex->owner = NULL;
  175. mutex_unlock(&mutex->mutex);
  176. }
  177. /*
  178. * Dummy page
  179. */
  180. struct radeon_dummy_page {
  181. struct page *page;
  182. dma_addr_t addr;
  183. };
  184. int radeon_dummy_page_init(struct radeon_device *rdev);
  185. void radeon_dummy_page_fini(struct radeon_device *rdev);
  186. /*
  187. * Clocks
  188. */
  189. struct radeon_clock {
  190. struct radeon_pll p1pll;
  191. struct radeon_pll p2pll;
  192. struct radeon_pll dcpll;
  193. struct radeon_pll spll;
  194. struct radeon_pll mpll;
  195. /* 10 Khz units */
  196. uint32_t default_mclk;
  197. uint32_t default_sclk;
  198. uint32_t default_dispclk;
  199. uint32_t dp_extclk;
  200. uint32_t max_pixel_clock;
  201. };
  202. /*
  203. * Power management
  204. */
  205. int radeon_pm_init(struct radeon_device *rdev);
  206. void radeon_pm_fini(struct radeon_device *rdev);
  207. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  208. void radeon_pm_suspend(struct radeon_device *rdev);
  209. void radeon_pm_resume(struct radeon_device *rdev);
  210. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  211. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  212. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  213. void rs690_pm_info(struct radeon_device *rdev);
  214. extern int rv6xx_get_temp(struct radeon_device *rdev);
  215. extern int rv770_get_temp(struct radeon_device *rdev);
  216. extern int evergreen_get_temp(struct radeon_device *rdev);
  217. extern int sumo_get_temp(struct radeon_device *rdev);
  218. extern int si_get_temp(struct radeon_device *rdev);
  219. extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  220. unsigned *bankh, unsigned *mtaspect,
  221. unsigned *tile_split);
  222. /*
  223. * Fences.
  224. */
  225. struct radeon_fence_driver {
  226. uint32_t scratch_reg;
  227. uint64_t gpu_addr;
  228. volatile uint32_t *cpu_addr;
  229. /* seq is protected by ring emission lock */
  230. uint64_t seq;
  231. atomic64_t last_seq;
  232. unsigned long last_activity;
  233. wait_queue_head_t queue;
  234. bool initialized;
  235. };
  236. struct radeon_fence {
  237. struct radeon_device *rdev;
  238. struct kref kref;
  239. /* protected by radeon_fence.lock */
  240. uint64_t seq;
  241. /* RB, DMA, etc. */
  242. unsigned 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_locked(struct radeon_device *rdev, int ring);
  254. int radeon_fence_wait_empty_locked(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. unsigned 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. int radeon_semaphore_sync_rings(struct radeon_device *rdev,
  412. struct radeon_semaphore *semaphore,
  413. bool sync_to[RADEON_NUM_RINGS],
  414. int dst_ring);
  415. void radeon_semaphore_free(struct radeon_device *rdev,
  416. struct radeon_semaphore *semaphore);
  417. /*
  418. * GART structures, functions & helpers
  419. */
  420. struct radeon_mc;
  421. #define RADEON_GPU_PAGE_SIZE 4096
  422. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  423. #define RADEON_GPU_PAGE_SHIFT 12
  424. #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
  425. struct radeon_gart {
  426. dma_addr_t table_addr;
  427. struct radeon_bo *robj;
  428. void *ptr;
  429. unsigned num_gpu_pages;
  430. unsigned num_cpu_pages;
  431. unsigned table_size;
  432. struct page **pages;
  433. dma_addr_t *pages_addr;
  434. bool ready;
  435. };
  436. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  437. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  438. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  439. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  440. int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  441. void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
  442. int radeon_gart_init(struct radeon_device *rdev);
  443. void radeon_gart_fini(struct radeon_device *rdev);
  444. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  445. int pages);
  446. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  447. int pages, struct page **pagelist,
  448. dma_addr_t *dma_addr);
  449. void radeon_gart_restore(struct radeon_device *rdev);
  450. /*
  451. * GPU MC structures, functions & helpers
  452. */
  453. struct radeon_mc {
  454. resource_size_t aper_size;
  455. resource_size_t aper_base;
  456. resource_size_t agp_base;
  457. /* for some chips with <= 32MB we need to lie
  458. * about vram size near mc fb location */
  459. u64 mc_vram_size;
  460. u64 visible_vram_size;
  461. u64 gtt_size;
  462. u64 gtt_start;
  463. u64 gtt_end;
  464. u64 vram_start;
  465. u64 vram_end;
  466. unsigned vram_width;
  467. u64 real_vram_size;
  468. int vram_mtrr;
  469. bool vram_is_ddr;
  470. bool igp_sideport_enabled;
  471. u64 gtt_base_align;
  472. };
  473. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  474. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  475. /*
  476. * GPU scratch registers structures, functions & helpers
  477. */
  478. struct radeon_scratch {
  479. unsigned num_reg;
  480. uint32_t reg_base;
  481. bool free[32];
  482. uint32_t reg[32];
  483. };
  484. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  485. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  486. /*
  487. * IRQS.
  488. */
  489. struct radeon_unpin_work {
  490. struct work_struct work;
  491. struct radeon_device *rdev;
  492. int crtc_id;
  493. struct radeon_fence *fence;
  494. struct drm_pending_vblank_event *event;
  495. struct radeon_bo *old_rbo;
  496. u64 new_crtc_base;
  497. };
  498. struct r500_irq_stat_regs {
  499. u32 disp_int;
  500. u32 hdmi0_status;
  501. };
  502. struct r600_irq_stat_regs {
  503. u32 disp_int;
  504. u32 disp_int_cont;
  505. u32 disp_int_cont2;
  506. u32 d1grph_int;
  507. u32 d2grph_int;
  508. u32 hdmi0_status;
  509. u32 hdmi1_status;
  510. };
  511. struct evergreen_irq_stat_regs {
  512. u32 disp_int;
  513. u32 disp_int_cont;
  514. u32 disp_int_cont2;
  515. u32 disp_int_cont3;
  516. u32 disp_int_cont4;
  517. u32 disp_int_cont5;
  518. u32 d1grph_int;
  519. u32 d2grph_int;
  520. u32 d3grph_int;
  521. u32 d4grph_int;
  522. u32 d5grph_int;
  523. u32 d6grph_int;
  524. u32 afmt_status1;
  525. u32 afmt_status2;
  526. u32 afmt_status3;
  527. u32 afmt_status4;
  528. u32 afmt_status5;
  529. u32 afmt_status6;
  530. };
  531. union radeon_irq_stat_regs {
  532. struct r500_irq_stat_regs r500;
  533. struct r600_irq_stat_regs r600;
  534. struct evergreen_irq_stat_regs evergreen;
  535. };
  536. #define RADEON_MAX_HPD_PINS 6
  537. #define RADEON_MAX_CRTCS 6
  538. #define RADEON_MAX_AFMT_BLOCKS 6
  539. struct radeon_irq {
  540. bool installed;
  541. bool sw_int[RADEON_NUM_RINGS];
  542. bool crtc_vblank_int[RADEON_MAX_CRTCS];
  543. bool pflip[RADEON_MAX_CRTCS];
  544. wait_queue_head_t vblank_queue;
  545. bool hpd[RADEON_MAX_HPD_PINS];
  546. bool gui_idle;
  547. bool gui_idle_acked;
  548. wait_queue_head_t idle_queue;
  549. bool afmt[RADEON_MAX_AFMT_BLOCKS];
  550. spinlock_t sw_lock;
  551. int sw_refcount[RADEON_NUM_RINGS];
  552. union radeon_irq_stat_regs stat_regs;
  553. spinlock_t pflip_lock[RADEON_MAX_CRTCS];
  554. int pflip_refcount[RADEON_MAX_CRTCS];
  555. };
  556. int radeon_irq_kms_init(struct radeon_device *rdev);
  557. void radeon_irq_kms_fini(struct radeon_device *rdev);
  558. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
  559. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
  560. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  561. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  562. /*
  563. * CP & rings.
  564. */
  565. struct radeon_ib {
  566. struct radeon_sa_bo sa_bo;
  567. unsigned idx;
  568. uint32_t length_dw;
  569. uint64_t gpu_addr;
  570. uint32_t *ptr;
  571. struct radeon_fence *fence;
  572. unsigned vm_id;
  573. bool is_const_ib;
  574. };
  575. /*
  576. * locking -
  577. * mutex protects scheduled_ibs, ready, alloc_bm
  578. */
  579. struct radeon_ib_pool {
  580. struct radeon_mutex mutex;
  581. struct radeon_sa_manager sa_manager;
  582. struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
  583. bool ready;
  584. unsigned head_id;
  585. };
  586. struct radeon_ring {
  587. struct radeon_bo *ring_obj;
  588. volatile uint32_t *ring;
  589. unsigned rptr;
  590. unsigned rptr_offs;
  591. unsigned rptr_reg;
  592. unsigned wptr;
  593. unsigned wptr_old;
  594. unsigned wptr_reg;
  595. unsigned ring_size;
  596. unsigned ring_free_dw;
  597. int count_dw;
  598. unsigned long last_activity;
  599. unsigned last_rptr;
  600. uint64_t gpu_addr;
  601. uint32_t align_mask;
  602. uint32_t ptr_mask;
  603. bool ready;
  604. u32 ptr_reg_shift;
  605. u32 ptr_reg_mask;
  606. u32 nop;
  607. };
  608. /*
  609. * VM
  610. */
  611. struct radeon_vm {
  612. struct list_head list;
  613. struct list_head va;
  614. int id;
  615. unsigned last_pfn;
  616. u64 pt_gpu_addr;
  617. u64 *pt;
  618. struct radeon_sa_bo sa_bo;
  619. struct mutex mutex;
  620. /* last fence for cs using this vm */
  621. struct radeon_fence *fence;
  622. };
  623. struct radeon_vm_funcs {
  624. int (*init)(struct radeon_device *rdev);
  625. void (*fini)(struct radeon_device *rdev);
  626. /* cs mutex must be lock for schedule_ib */
  627. int (*bind)(struct radeon_device *rdev, struct radeon_vm *vm, int id);
  628. void (*unbind)(struct radeon_device *rdev, struct radeon_vm *vm);
  629. void (*tlb_flush)(struct radeon_device *rdev, struct radeon_vm *vm);
  630. uint32_t (*page_flags)(struct radeon_device *rdev,
  631. struct radeon_vm *vm,
  632. uint32_t flags);
  633. void (*set_page)(struct radeon_device *rdev, struct radeon_vm *vm,
  634. unsigned pfn, uint64_t addr, uint32_t flags);
  635. };
  636. struct radeon_vm_manager {
  637. struct list_head lru_vm;
  638. uint32_t use_bitmap;
  639. struct radeon_sa_manager sa_manager;
  640. uint32_t max_pfn;
  641. /* fields constant after init */
  642. const struct radeon_vm_funcs *funcs;
  643. /* number of VMIDs */
  644. unsigned nvm;
  645. /* vram base address for page table entry */
  646. u64 vram_base_offset;
  647. /* is vm enabled? */
  648. bool enabled;
  649. };
  650. /*
  651. * file private structure
  652. */
  653. struct radeon_fpriv {
  654. struct radeon_vm vm;
  655. };
  656. /*
  657. * R6xx+ IH ring
  658. */
  659. struct r600_ih {
  660. struct radeon_bo *ring_obj;
  661. volatile uint32_t *ring;
  662. unsigned rptr;
  663. unsigned rptr_offs;
  664. unsigned wptr;
  665. unsigned wptr_old;
  666. unsigned ring_size;
  667. uint64_t gpu_addr;
  668. uint32_t ptr_mask;
  669. spinlock_t lock;
  670. bool enabled;
  671. };
  672. struct r600_blit_cp_primitives {
  673. void (*set_render_target)(struct radeon_device *rdev, int format,
  674. int w, int h, u64 gpu_addr);
  675. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  676. u32 sync_type, u32 size,
  677. u64 mc_addr);
  678. void (*set_shaders)(struct radeon_device *rdev);
  679. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  680. void (*set_tex_resource)(struct radeon_device *rdev,
  681. int format, int w, int h, int pitch,
  682. u64 gpu_addr, u32 size);
  683. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  684. int x2, int y2);
  685. void (*draw_auto)(struct radeon_device *rdev);
  686. void (*set_default_state)(struct radeon_device *rdev);
  687. };
  688. struct r600_blit {
  689. struct mutex mutex;
  690. struct radeon_bo *shader_obj;
  691. struct r600_blit_cp_primitives primitives;
  692. int max_dim;
  693. int ring_size_common;
  694. int ring_size_per_loop;
  695. u64 shader_gpu_addr;
  696. u32 vs_offset, ps_offset;
  697. u32 state_offset;
  698. u32 state_len;
  699. u32 vb_used, vb_total;
  700. struct radeon_ib *vb_ib;
  701. };
  702. void r600_blit_suspend(struct radeon_device *rdev);
  703. /*
  704. * SI RLC stuff
  705. */
  706. struct si_rlc {
  707. /* for power gating */
  708. struct radeon_bo *save_restore_obj;
  709. uint64_t save_restore_gpu_addr;
  710. /* for clear state */
  711. struct radeon_bo *clear_state_obj;
  712. uint64_t clear_state_gpu_addr;
  713. };
  714. int radeon_ib_get(struct radeon_device *rdev, int ring,
  715. struct radeon_ib **ib, unsigned size);
  716. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
  717. bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib);
  718. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  719. int radeon_ib_pool_init(struct radeon_device *rdev);
  720. void radeon_ib_pool_fini(struct radeon_device *rdev);
  721. int radeon_ib_pool_start(struct radeon_device *rdev);
  722. int radeon_ib_pool_suspend(struct radeon_device *rdev);
  723. int radeon_ib_ring_tests(struct radeon_device *rdev);
  724. /* Ring access between begin & end cannot sleep */
  725. int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *cp);
  726. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  727. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  728. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  729. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  730. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  731. void radeon_ring_undo(struct radeon_ring *ring);
  732. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  733. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  734. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  735. void radeon_ring_lockup_update(struct radeon_ring *ring);
  736. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  737. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  738. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  739. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  740. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  741. /*
  742. * CS.
  743. */
  744. struct radeon_cs_reloc {
  745. struct drm_gem_object *gobj;
  746. struct radeon_bo *robj;
  747. struct radeon_bo_list lobj;
  748. uint32_t handle;
  749. uint32_t flags;
  750. };
  751. struct radeon_cs_chunk {
  752. uint32_t chunk_id;
  753. uint32_t length_dw;
  754. int kpage_idx[2];
  755. uint32_t *kpage[2];
  756. uint32_t *kdata;
  757. void __user *user_ptr;
  758. int last_copied_page;
  759. int last_page_index;
  760. };
  761. struct radeon_cs_parser {
  762. struct device *dev;
  763. struct radeon_device *rdev;
  764. struct drm_file *filp;
  765. /* chunks */
  766. unsigned nchunks;
  767. struct radeon_cs_chunk *chunks;
  768. uint64_t *chunks_array;
  769. /* IB */
  770. unsigned idx;
  771. /* relocations */
  772. unsigned nrelocs;
  773. struct radeon_cs_reloc *relocs;
  774. struct radeon_cs_reloc **relocs_ptr;
  775. struct list_head validated;
  776. /* indices of various chunks */
  777. int chunk_ib_idx;
  778. int chunk_relocs_idx;
  779. int chunk_flags_idx;
  780. int chunk_const_ib_idx;
  781. struct radeon_ib *ib;
  782. struct radeon_ib *const_ib;
  783. void *track;
  784. unsigned family;
  785. int parser_error;
  786. u32 cs_flags;
  787. u32 ring;
  788. s32 priority;
  789. };
  790. extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
  791. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  792. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  793. struct radeon_cs_packet {
  794. unsigned idx;
  795. unsigned type;
  796. unsigned reg;
  797. unsigned opcode;
  798. int count;
  799. unsigned one_reg_wr;
  800. };
  801. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  802. struct radeon_cs_packet *pkt,
  803. unsigned idx, unsigned reg);
  804. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  805. struct radeon_cs_packet *pkt);
  806. /*
  807. * AGP
  808. */
  809. int radeon_agp_init(struct radeon_device *rdev);
  810. void radeon_agp_resume(struct radeon_device *rdev);
  811. void radeon_agp_suspend(struct radeon_device *rdev);
  812. void radeon_agp_fini(struct radeon_device *rdev);
  813. /*
  814. * Writeback
  815. */
  816. struct radeon_wb {
  817. struct radeon_bo *wb_obj;
  818. volatile uint32_t *wb;
  819. uint64_t gpu_addr;
  820. bool enabled;
  821. bool use_event;
  822. };
  823. #define RADEON_WB_SCRATCH_OFFSET 0
  824. #define RADEON_WB_CP_RPTR_OFFSET 1024
  825. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  826. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  827. #define R600_WB_IH_WPTR_OFFSET 2048
  828. #define R600_WB_EVENT_OFFSET 3072
  829. /**
  830. * struct radeon_pm - power management datas
  831. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  832. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  833. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  834. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  835. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  836. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  837. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  838. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  839. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  840. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  841. * @needed_bandwidth: current bandwidth needs
  842. *
  843. * It keeps track of various data needed to take powermanagement decision.
  844. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  845. * Equation between gpu/memory clock and available bandwidth is hw dependent
  846. * (type of memory, bus size, efficiency, ...)
  847. */
  848. enum radeon_pm_method {
  849. PM_METHOD_PROFILE,
  850. PM_METHOD_DYNPM,
  851. };
  852. enum radeon_dynpm_state {
  853. DYNPM_STATE_DISABLED,
  854. DYNPM_STATE_MINIMUM,
  855. DYNPM_STATE_PAUSED,
  856. DYNPM_STATE_ACTIVE,
  857. DYNPM_STATE_SUSPENDED,
  858. };
  859. enum radeon_dynpm_action {
  860. DYNPM_ACTION_NONE,
  861. DYNPM_ACTION_MINIMUM,
  862. DYNPM_ACTION_DOWNCLOCK,
  863. DYNPM_ACTION_UPCLOCK,
  864. DYNPM_ACTION_DEFAULT
  865. };
  866. enum radeon_voltage_type {
  867. VOLTAGE_NONE = 0,
  868. VOLTAGE_GPIO,
  869. VOLTAGE_VDDC,
  870. VOLTAGE_SW
  871. };
  872. enum radeon_pm_state_type {
  873. POWER_STATE_TYPE_DEFAULT,
  874. POWER_STATE_TYPE_POWERSAVE,
  875. POWER_STATE_TYPE_BATTERY,
  876. POWER_STATE_TYPE_BALANCED,
  877. POWER_STATE_TYPE_PERFORMANCE,
  878. };
  879. enum radeon_pm_profile_type {
  880. PM_PROFILE_DEFAULT,
  881. PM_PROFILE_AUTO,
  882. PM_PROFILE_LOW,
  883. PM_PROFILE_MID,
  884. PM_PROFILE_HIGH,
  885. };
  886. #define PM_PROFILE_DEFAULT_IDX 0
  887. #define PM_PROFILE_LOW_SH_IDX 1
  888. #define PM_PROFILE_MID_SH_IDX 2
  889. #define PM_PROFILE_HIGH_SH_IDX 3
  890. #define PM_PROFILE_LOW_MH_IDX 4
  891. #define PM_PROFILE_MID_MH_IDX 5
  892. #define PM_PROFILE_HIGH_MH_IDX 6
  893. #define PM_PROFILE_MAX 7
  894. struct radeon_pm_profile {
  895. int dpms_off_ps_idx;
  896. int dpms_on_ps_idx;
  897. int dpms_off_cm_idx;
  898. int dpms_on_cm_idx;
  899. };
  900. enum radeon_int_thermal_type {
  901. THERMAL_TYPE_NONE,
  902. THERMAL_TYPE_RV6XX,
  903. THERMAL_TYPE_RV770,
  904. THERMAL_TYPE_EVERGREEN,
  905. THERMAL_TYPE_SUMO,
  906. THERMAL_TYPE_NI,
  907. THERMAL_TYPE_SI,
  908. };
  909. struct radeon_voltage {
  910. enum radeon_voltage_type type;
  911. /* gpio voltage */
  912. struct radeon_gpio_rec gpio;
  913. u32 delay; /* delay in usec from voltage drop to sclk change */
  914. bool active_high; /* voltage drop is active when bit is high */
  915. /* VDDC voltage */
  916. u8 vddc_id; /* index into vddc voltage table */
  917. u8 vddci_id; /* index into vddci voltage table */
  918. bool vddci_enabled;
  919. /* r6xx+ sw */
  920. u16 voltage;
  921. /* evergreen+ vddci */
  922. u16 vddci;
  923. };
  924. /* clock mode flags */
  925. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  926. struct radeon_pm_clock_info {
  927. /* memory clock */
  928. u32 mclk;
  929. /* engine clock */
  930. u32 sclk;
  931. /* voltage info */
  932. struct radeon_voltage voltage;
  933. /* standardized clock flags */
  934. u32 flags;
  935. };
  936. /* state flags */
  937. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  938. struct radeon_power_state {
  939. enum radeon_pm_state_type type;
  940. struct radeon_pm_clock_info *clock_info;
  941. /* number of valid clock modes in this power state */
  942. int num_clock_modes;
  943. struct radeon_pm_clock_info *default_clock_mode;
  944. /* standardized state flags */
  945. u32 flags;
  946. u32 misc; /* vbios specific flags */
  947. u32 misc2; /* vbios specific flags */
  948. int pcie_lanes; /* pcie lanes */
  949. };
  950. /*
  951. * Some modes are overclocked by very low value, accept them
  952. */
  953. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  954. struct radeon_pm {
  955. struct mutex mutex;
  956. u32 active_crtcs;
  957. int active_crtc_count;
  958. int req_vblank;
  959. bool vblank_sync;
  960. bool gui_idle;
  961. fixed20_12 max_bandwidth;
  962. fixed20_12 igp_sideport_mclk;
  963. fixed20_12 igp_system_mclk;
  964. fixed20_12 igp_ht_link_clk;
  965. fixed20_12 igp_ht_link_width;
  966. fixed20_12 k8_bandwidth;
  967. fixed20_12 sideport_bandwidth;
  968. fixed20_12 ht_bandwidth;
  969. fixed20_12 core_bandwidth;
  970. fixed20_12 sclk;
  971. fixed20_12 mclk;
  972. fixed20_12 needed_bandwidth;
  973. struct radeon_power_state *power_state;
  974. /* number of valid power states */
  975. int num_power_states;
  976. int current_power_state_index;
  977. int current_clock_mode_index;
  978. int requested_power_state_index;
  979. int requested_clock_mode_index;
  980. int default_power_state_index;
  981. u32 current_sclk;
  982. u32 current_mclk;
  983. u16 current_vddc;
  984. u16 current_vddci;
  985. u32 default_sclk;
  986. u32 default_mclk;
  987. u16 default_vddc;
  988. u16 default_vddci;
  989. struct radeon_i2c_chan *i2c_bus;
  990. /* selected pm method */
  991. enum radeon_pm_method pm_method;
  992. /* dynpm power management */
  993. struct delayed_work dynpm_idle_work;
  994. enum radeon_dynpm_state dynpm_state;
  995. enum radeon_dynpm_action dynpm_planned_action;
  996. unsigned long dynpm_action_timeout;
  997. bool dynpm_can_upclock;
  998. bool dynpm_can_downclock;
  999. /* profile-based power management */
  1000. enum radeon_pm_profile_type profile;
  1001. int profile_index;
  1002. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  1003. /* internal thermal controller on rv6xx+ */
  1004. enum radeon_int_thermal_type int_thermal_type;
  1005. struct device *int_hwmon_dev;
  1006. };
  1007. int radeon_pm_get_type_index(struct radeon_device *rdev,
  1008. enum radeon_pm_state_type ps_type,
  1009. int instance);
  1010. struct r600_audio {
  1011. bool enabled;
  1012. int channels;
  1013. int rate;
  1014. int bits_per_sample;
  1015. u8 status_bits;
  1016. u8 category_code;
  1017. };
  1018. /*
  1019. * Benchmarking
  1020. */
  1021. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1022. /*
  1023. * Testing
  1024. */
  1025. void radeon_test_moves(struct radeon_device *rdev);
  1026. void radeon_test_ring_sync(struct radeon_device *rdev,
  1027. struct radeon_ring *cpA,
  1028. struct radeon_ring *cpB);
  1029. void radeon_test_syncing(struct radeon_device *rdev);
  1030. /*
  1031. * Debugfs
  1032. */
  1033. struct radeon_debugfs {
  1034. struct drm_info_list *files;
  1035. unsigned num_files;
  1036. };
  1037. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1038. struct drm_info_list *files,
  1039. unsigned nfiles);
  1040. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1041. /*
  1042. * ASIC specific functions.
  1043. */
  1044. struct radeon_asic {
  1045. int (*init)(struct radeon_device *rdev);
  1046. void (*fini)(struct radeon_device *rdev);
  1047. int (*resume)(struct radeon_device *rdev);
  1048. int (*suspend)(struct radeon_device *rdev);
  1049. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1050. int (*asic_reset)(struct radeon_device *rdev);
  1051. /* ioctl hw specific callback. Some hw might want to perform special
  1052. * operation on specific ioctl. For instance on wait idle some hw
  1053. * might want to perform and HDP flush through MMIO as it seems that
  1054. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1055. * through ring.
  1056. */
  1057. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1058. /* check if 3D engine is idle */
  1059. bool (*gui_idle)(struct radeon_device *rdev);
  1060. /* wait for mc_idle */
  1061. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1062. /* gart */
  1063. struct {
  1064. void (*tlb_flush)(struct radeon_device *rdev);
  1065. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1066. } gart;
  1067. /* ring specific callbacks */
  1068. struct {
  1069. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1070. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1071. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1072. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1073. struct radeon_semaphore *semaphore, bool emit_wait);
  1074. int (*cs_parse)(struct radeon_cs_parser *p);
  1075. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1076. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1077. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1078. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1079. } ring[RADEON_NUM_RINGS];
  1080. /* irqs */
  1081. struct {
  1082. int (*set)(struct radeon_device *rdev);
  1083. int (*process)(struct radeon_device *rdev);
  1084. } irq;
  1085. /* displays */
  1086. struct {
  1087. /* display watermarks */
  1088. void (*bandwidth_update)(struct radeon_device *rdev);
  1089. /* get frame count */
  1090. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1091. /* wait for vblank */
  1092. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1093. } display;
  1094. /* copy functions for bo handling */
  1095. struct {
  1096. int (*blit)(struct radeon_device *rdev,
  1097. uint64_t src_offset,
  1098. uint64_t dst_offset,
  1099. unsigned num_gpu_pages,
  1100. struct radeon_fence *fence);
  1101. u32 blit_ring_index;
  1102. int (*dma)(struct radeon_device *rdev,
  1103. uint64_t src_offset,
  1104. uint64_t dst_offset,
  1105. unsigned num_gpu_pages,
  1106. struct radeon_fence *fence);
  1107. u32 dma_ring_index;
  1108. /* method used for bo copy */
  1109. int (*copy)(struct radeon_device *rdev,
  1110. uint64_t src_offset,
  1111. uint64_t dst_offset,
  1112. unsigned num_gpu_pages,
  1113. struct radeon_fence *fence);
  1114. /* ring used for bo copies */
  1115. u32 copy_ring_index;
  1116. } copy;
  1117. /* surfaces */
  1118. struct {
  1119. int (*set_reg)(struct radeon_device *rdev, int reg,
  1120. uint32_t tiling_flags, uint32_t pitch,
  1121. uint32_t offset, uint32_t obj_size);
  1122. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1123. } surface;
  1124. /* hotplug detect */
  1125. struct {
  1126. void (*init)(struct radeon_device *rdev);
  1127. void (*fini)(struct radeon_device *rdev);
  1128. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1129. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1130. } hpd;
  1131. /* power management */
  1132. struct {
  1133. void (*misc)(struct radeon_device *rdev);
  1134. void (*prepare)(struct radeon_device *rdev);
  1135. void (*finish)(struct radeon_device *rdev);
  1136. void (*init_profile)(struct radeon_device *rdev);
  1137. void (*get_dynpm_state)(struct radeon_device *rdev);
  1138. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1139. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1140. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1141. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1142. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1143. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1144. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1145. } pm;
  1146. /* pageflipping */
  1147. struct {
  1148. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1149. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1150. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1151. } pflip;
  1152. };
  1153. /*
  1154. * Asic structures
  1155. */
  1156. struct r100_asic {
  1157. const unsigned *reg_safe_bm;
  1158. unsigned reg_safe_bm_size;
  1159. u32 hdp_cntl;
  1160. };
  1161. struct r300_asic {
  1162. const unsigned *reg_safe_bm;
  1163. unsigned reg_safe_bm_size;
  1164. u32 resync_scratch;
  1165. u32 hdp_cntl;
  1166. };
  1167. struct r600_asic {
  1168. unsigned max_pipes;
  1169. unsigned max_tile_pipes;
  1170. unsigned max_simds;
  1171. unsigned max_backends;
  1172. unsigned max_gprs;
  1173. unsigned max_threads;
  1174. unsigned max_stack_entries;
  1175. unsigned max_hw_contexts;
  1176. unsigned max_gs_threads;
  1177. unsigned sx_max_export_size;
  1178. unsigned sx_max_export_pos_size;
  1179. unsigned sx_max_export_smx_size;
  1180. unsigned sq_num_cf_insts;
  1181. unsigned tiling_nbanks;
  1182. unsigned tiling_npipes;
  1183. unsigned tiling_group_size;
  1184. unsigned tile_config;
  1185. unsigned backend_map;
  1186. };
  1187. struct rv770_asic {
  1188. unsigned max_pipes;
  1189. unsigned max_tile_pipes;
  1190. unsigned max_simds;
  1191. unsigned max_backends;
  1192. unsigned max_gprs;
  1193. unsigned max_threads;
  1194. unsigned max_stack_entries;
  1195. unsigned max_hw_contexts;
  1196. unsigned max_gs_threads;
  1197. unsigned sx_max_export_size;
  1198. unsigned sx_max_export_pos_size;
  1199. unsigned sx_max_export_smx_size;
  1200. unsigned sq_num_cf_insts;
  1201. unsigned sx_num_of_sets;
  1202. unsigned sc_prim_fifo_size;
  1203. unsigned sc_hiz_tile_fifo_size;
  1204. unsigned sc_earlyz_tile_fifo_fize;
  1205. unsigned tiling_nbanks;
  1206. unsigned tiling_npipes;
  1207. unsigned tiling_group_size;
  1208. unsigned tile_config;
  1209. unsigned backend_map;
  1210. };
  1211. struct evergreen_asic {
  1212. unsigned num_ses;
  1213. unsigned max_pipes;
  1214. unsigned max_tile_pipes;
  1215. unsigned max_simds;
  1216. unsigned max_backends;
  1217. unsigned max_gprs;
  1218. unsigned max_threads;
  1219. unsigned max_stack_entries;
  1220. unsigned max_hw_contexts;
  1221. unsigned max_gs_threads;
  1222. unsigned sx_max_export_size;
  1223. unsigned sx_max_export_pos_size;
  1224. unsigned sx_max_export_smx_size;
  1225. unsigned sq_num_cf_insts;
  1226. unsigned sx_num_of_sets;
  1227. unsigned sc_prim_fifo_size;
  1228. unsigned sc_hiz_tile_fifo_size;
  1229. unsigned sc_earlyz_tile_fifo_size;
  1230. unsigned tiling_nbanks;
  1231. unsigned tiling_npipes;
  1232. unsigned tiling_group_size;
  1233. unsigned tile_config;
  1234. unsigned backend_map;
  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. };
  1271. struct si_asic {
  1272. unsigned max_shader_engines;
  1273. unsigned max_pipes_per_simd;
  1274. unsigned max_tile_pipes;
  1275. unsigned max_simds_per_se;
  1276. unsigned max_backends_per_se;
  1277. unsigned max_texture_channel_caches;
  1278. unsigned max_gprs;
  1279. unsigned max_gs_threads;
  1280. unsigned max_hw_contexts;
  1281. unsigned sc_prim_fifo_size_frontend;
  1282. unsigned sc_prim_fifo_size_backend;
  1283. unsigned sc_hiz_tile_fifo_size;
  1284. unsigned sc_earlyz_tile_fifo_size;
  1285. unsigned num_shader_engines;
  1286. unsigned num_tile_pipes;
  1287. unsigned num_backends_per_se;
  1288. unsigned backend_disable_mask_per_asic;
  1289. unsigned backend_map;
  1290. unsigned num_texture_channel_caches;
  1291. unsigned mem_max_burst_length_bytes;
  1292. unsigned mem_row_size_in_kb;
  1293. unsigned shader_engine_tile_size;
  1294. unsigned num_gpus;
  1295. unsigned multi_gpu_tile_size;
  1296. unsigned tile_config;
  1297. };
  1298. union radeon_asic_config {
  1299. struct r300_asic r300;
  1300. struct r100_asic r100;
  1301. struct r600_asic r600;
  1302. struct rv770_asic rv770;
  1303. struct evergreen_asic evergreen;
  1304. struct cayman_asic cayman;
  1305. struct si_asic si;
  1306. };
  1307. /*
  1308. * asic initizalization from radeon_asic.c
  1309. */
  1310. void radeon_agp_disable(struct radeon_device *rdev);
  1311. int radeon_asic_init(struct radeon_device *rdev);
  1312. /*
  1313. * IOCTL.
  1314. */
  1315. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1316. struct drm_file *filp);
  1317. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1318. struct drm_file *filp);
  1319. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1320. struct drm_file *file_priv);
  1321. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1322. struct drm_file *file_priv);
  1323. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1324. struct drm_file *file_priv);
  1325. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1326. struct drm_file *file_priv);
  1327. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1328. struct drm_file *filp);
  1329. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1330. struct drm_file *filp);
  1331. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1332. struct drm_file *filp);
  1333. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1334. struct drm_file *filp);
  1335. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1336. struct drm_file *filp);
  1337. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1338. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1339. struct drm_file *filp);
  1340. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1341. struct drm_file *filp);
  1342. /* VRAM scratch page for HDP bug, default vram page */
  1343. struct r600_vram_scratch {
  1344. struct radeon_bo *robj;
  1345. volatile uint32_t *ptr;
  1346. u64 gpu_addr;
  1347. };
  1348. /*
  1349. * Core structure, functions and helpers.
  1350. */
  1351. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1352. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1353. struct radeon_device {
  1354. struct device *dev;
  1355. struct drm_device *ddev;
  1356. struct pci_dev *pdev;
  1357. /* ASIC */
  1358. union radeon_asic_config config;
  1359. enum radeon_family family;
  1360. unsigned long flags;
  1361. int usec_timeout;
  1362. enum radeon_pll_errata pll_errata;
  1363. int num_gb_pipes;
  1364. int num_z_pipes;
  1365. int disp_priority;
  1366. /* BIOS */
  1367. uint8_t *bios;
  1368. bool is_atom_bios;
  1369. uint16_t bios_header_start;
  1370. struct radeon_bo *stollen_vga_memory;
  1371. /* Register mmio */
  1372. resource_size_t rmmio_base;
  1373. resource_size_t rmmio_size;
  1374. void __iomem *rmmio;
  1375. radeon_rreg_t mc_rreg;
  1376. radeon_wreg_t mc_wreg;
  1377. radeon_rreg_t pll_rreg;
  1378. radeon_wreg_t pll_wreg;
  1379. uint32_t pcie_reg_mask;
  1380. radeon_rreg_t pciep_rreg;
  1381. radeon_wreg_t pciep_wreg;
  1382. /* io port */
  1383. void __iomem *rio_mem;
  1384. resource_size_t rio_mem_size;
  1385. struct radeon_clock clock;
  1386. struct radeon_mc mc;
  1387. struct radeon_gart gart;
  1388. struct radeon_mode_info mode_info;
  1389. struct radeon_scratch scratch;
  1390. struct radeon_mman mman;
  1391. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1392. struct radeon_semaphore_driver semaphore_drv;
  1393. struct mutex ring_lock;
  1394. struct radeon_ring ring[RADEON_NUM_RINGS];
  1395. struct radeon_ib_pool ib_pool;
  1396. struct radeon_irq irq;
  1397. struct radeon_asic *asic;
  1398. struct radeon_gem gem;
  1399. struct radeon_pm pm;
  1400. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1401. struct radeon_mutex cs_mutex;
  1402. struct radeon_wb wb;
  1403. struct radeon_dummy_page dummy_page;
  1404. bool shutdown;
  1405. bool suspend;
  1406. bool need_dma32;
  1407. bool accel_working;
  1408. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1409. const struct firmware *me_fw; /* all family ME firmware */
  1410. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1411. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1412. const struct firmware *mc_fw; /* NI MC firmware */
  1413. const struct firmware *ce_fw; /* SI CE firmware */
  1414. struct r600_blit r600_blit;
  1415. struct r600_vram_scratch vram_scratch;
  1416. int msi_enabled; /* msi enabled */
  1417. struct r600_ih ih; /* r6/700 interrupt ring */
  1418. struct si_rlc rlc;
  1419. struct work_struct hotplug_work;
  1420. struct work_struct audio_work;
  1421. int num_crtc; /* number of crtcs */
  1422. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1423. struct mutex vram_mutex;
  1424. struct r600_audio audio; /* audio stuff */
  1425. struct notifier_block acpi_nb;
  1426. /* only one userspace can use Hyperz features or CMASK at a time */
  1427. struct drm_file *hyperz_filp;
  1428. struct drm_file *cmask_filp;
  1429. /* i2c buses */
  1430. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1431. /* debugfs */
  1432. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1433. unsigned debugfs_count;
  1434. /* virtual memory */
  1435. struct radeon_vm_manager vm_manager;
  1436. };
  1437. int radeon_device_init(struct radeon_device *rdev,
  1438. struct drm_device *ddev,
  1439. struct pci_dev *pdev,
  1440. uint32_t flags);
  1441. void radeon_device_fini(struct radeon_device *rdev);
  1442. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1443. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg);
  1444. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v);
  1445. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1446. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1447. /*
  1448. * Cast helper
  1449. */
  1450. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1451. /*
  1452. * Registers read & write functions.
  1453. */
  1454. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1455. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1456. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1457. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1458. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1459. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
  1460. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1461. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1462. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1463. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1464. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1465. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1466. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1467. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1468. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1469. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1470. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1471. #define WREG32_P(reg, val, mask) \
  1472. do { \
  1473. uint32_t tmp_ = RREG32(reg); \
  1474. tmp_ &= (mask); \
  1475. tmp_ |= ((val) & ~(mask)); \
  1476. WREG32(reg, tmp_); \
  1477. } while (0)
  1478. #define WREG32_PLL_P(reg, val, mask) \
  1479. do { \
  1480. uint32_t tmp_ = RREG32_PLL(reg); \
  1481. tmp_ &= (mask); \
  1482. tmp_ |= ((val) & ~(mask)); \
  1483. WREG32_PLL(reg, tmp_); \
  1484. } while (0)
  1485. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
  1486. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1487. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1488. /*
  1489. * Indirect registers accessor
  1490. */
  1491. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1492. {
  1493. uint32_t r;
  1494. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1495. r = RREG32(RADEON_PCIE_DATA);
  1496. return r;
  1497. }
  1498. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1499. {
  1500. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1501. WREG32(RADEON_PCIE_DATA, (v));
  1502. }
  1503. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1504. /*
  1505. * ASICs helpers.
  1506. */
  1507. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1508. (rdev->pdev->device == 0x5969))
  1509. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1510. (rdev->family == CHIP_RV200) || \
  1511. (rdev->family == CHIP_RS100) || \
  1512. (rdev->family == CHIP_RS200) || \
  1513. (rdev->family == CHIP_RV250) || \
  1514. (rdev->family == CHIP_RV280) || \
  1515. (rdev->family == CHIP_RS300))
  1516. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1517. (rdev->family == CHIP_RV350) || \
  1518. (rdev->family == CHIP_R350) || \
  1519. (rdev->family == CHIP_RV380) || \
  1520. (rdev->family == CHIP_R420) || \
  1521. (rdev->family == CHIP_R423) || \
  1522. (rdev->family == CHIP_RV410) || \
  1523. (rdev->family == CHIP_RS400) || \
  1524. (rdev->family == CHIP_RS480))
  1525. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1526. (rdev->ddev->pdev->device == 0x9443) || \
  1527. (rdev->ddev->pdev->device == 0x944B) || \
  1528. (rdev->ddev->pdev->device == 0x9506) || \
  1529. (rdev->ddev->pdev->device == 0x9509) || \
  1530. (rdev->ddev->pdev->device == 0x950F) || \
  1531. (rdev->ddev->pdev->device == 0x689C) || \
  1532. (rdev->ddev->pdev->device == 0x689D))
  1533. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1534. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1535. (rdev->family == CHIP_RS690) || \
  1536. (rdev->family == CHIP_RS740) || \
  1537. (rdev->family >= CHIP_R600))
  1538. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1539. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1540. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1541. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1542. (rdev->flags & RADEON_IS_IGP))
  1543. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1544. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  1545. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  1546. (rdev->flags & RADEON_IS_IGP))
  1547. /*
  1548. * BIOS helpers.
  1549. */
  1550. #define RBIOS8(i) (rdev->bios[i])
  1551. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1552. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1553. int radeon_combios_init(struct radeon_device *rdev);
  1554. void radeon_combios_fini(struct radeon_device *rdev);
  1555. int radeon_atombios_init(struct radeon_device *rdev);
  1556. void radeon_atombios_fini(struct radeon_device *rdev);
  1557. /*
  1558. * RING helpers.
  1559. */
  1560. #if DRM_DEBUG_CODE == 0
  1561. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1562. {
  1563. ring->ring[ring->wptr++] = v;
  1564. ring->wptr &= ring->ptr_mask;
  1565. ring->count_dw--;
  1566. ring->ring_free_dw--;
  1567. }
  1568. #else
  1569. /* With debugging this is just too big to inline */
  1570. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1571. #endif
  1572. /*
  1573. * ASICs macro.
  1574. */
  1575. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1576. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1577. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1578. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1579. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  1580. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1581. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1582. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  1583. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  1584. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  1585. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  1586. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  1587. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1588. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1589. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  1590. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  1591. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  1592. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  1593. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1594. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1595. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  1596. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  1597. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  1598. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  1599. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  1600. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  1601. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  1602. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  1603. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  1604. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  1605. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  1606. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  1607. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  1608. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  1609. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  1610. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  1611. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  1612. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  1613. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  1614. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  1615. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1616. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  1617. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  1618. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  1619. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  1620. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  1621. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pflip.pre_page_flip((rdev), (crtc))
  1622. #define radeon_page_flip(rdev, crtc, base) rdev->asic->pflip.page_flip((rdev), (crtc), (base))
  1623. #define radeon_post_page_flip(rdev, crtc) rdev->asic->pflip.post_page_flip((rdev), (crtc))
  1624. #define radeon_wait_for_vblank(rdev, crtc) rdev->asic->display.wait_for_vblank((rdev), (crtc))
  1625. #define radeon_mc_wait_for_idle(rdev) rdev->asic->mc_wait_for_idle((rdev))
  1626. /* Common functions */
  1627. /* AGP */
  1628. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1629. extern void radeon_agp_disable(struct radeon_device *rdev);
  1630. extern int radeon_modeset_init(struct radeon_device *rdev);
  1631. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1632. extern bool radeon_card_posted(struct radeon_device *rdev);
  1633. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1634. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1635. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1636. extern void radeon_scratch_init(struct radeon_device *rdev);
  1637. extern void radeon_wb_fini(struct radeon_device *rdev);
  1638. extern int radeon_wb_init(struct radeon_device *rdev);
  1639. extern void radeon_wb_disable(struct radeon_device *rdev);
  1640. extern void radeon_surface_init(struct radeon_device *rdev);
  1641. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1642. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1643. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1644. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1645. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1646. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1647. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1648. extern int radeon_resume_kms(struct drm_device *dev);
  1649. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1650. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1651. /*
  1652. * vm
  1653. */
  1654. int radeon_vm_manager_init(struct radeon_device *rdev);
  1655. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1656. int radeon_vm_manager_start(struct radeon_device *rdev);
  1657. int radeon_vm_manager_suspend(struct radeon_device *rdev);
  1658. int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1659. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1660. int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm);
  1661. void radeon_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm);
  1662. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1663. struct radeon_vm *vm,
  1664. struct radeon_bo *bo,
  1665. struct ttm_mem_reg *mem);
  1666. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1667. struct radeon_bo *bo);
  1668. int radeon_vm_bo_add(struct radeon_device *rdev,
  1669. struct radeon_vm *vm,
  1670. struct radeon_bo *bo,
  1671. uint64_t offset,
  1672. uint32_t flags);
  1673. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1674. struct radeon_vm *vm,
  1675. struct radeon_bo *bo);
  1676. /* audio */
  1677. void r600_audio_update_hdmi(struct work_struct *work);
  1678. /*
  1679. * R600 vram scratch functions
  1680. */
  1681. int r600_vram_scratch_init(struct radeon_device *rdev);
  1682. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1683. /*
  1684. * r600 cs checking helper
  1685. */
  1686. unsigned r600_mip_minify(unsigned size, unsigned level);
  1687. bool r600_fmt_is_valid_color(u32 format);
  1688. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  1689. int r600_fmt_get_blocksize(u32 format);
  1690. int r600_fmt_get_nblocksx(u32 format, u32 w);
  1691. int r600_fmt_get_nblocksy(u32 format, u32 h);
  1692. /*
  1693. * r600 functions used by radeon_encoder.c
  1694. */
  1695. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1696. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1697. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1698. extern int ni_init_microcode(struct radeon_device *rdev);
  1699. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1700. /* radeon_acpi.c */
  1701. #if defined(CONFIG_ACPI)
  1702. extern int radeon_acpi_init(struct radeon_device *rdev);
  1703. #else
  1704. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1705. #endif
  1706. #include "radeon_object.h"
  1707. #endif