radeon.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  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. extern int radeon_fastfb;
  93. /*
  94. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  95. * symbol;
  96. */
  97. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  98. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  99. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  100. #define RADEON_IB_POOL_SIZE 16
  101. #define RADEON_DEBUGFS_MAX_COMPONENTS 32
  102. #define RADEONFB_CONN_LIMIT 4
  103. #define RADEON_BIOS_NUM_SCRATCH 8
  104. /* max number of rings */
  105. #define RADEON_NUM_RINGS 6
  106. /* fence seq are set to this number when signaled */
  107. #define RADEON_FENCE_SIGNALED_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. /* R600+ has an async dma ring */
  115. #define R600_RING_TYPE_DMA_INDEX 3
  116. /* cayman add a second async dma ring */
  117. #define CAYMAN_RING_TYPE_DMA1_INDEX 4
  118. /* R600+ */
  119. #define R600_RING_TYPE_UVD_INDEX 5
  120. /* hardcode those limit for now */
  121. #define RADEON_VA_IB_OFFSET (1 << 20)
  122. #define RADEON_VA_RESERVED_SIZE (8 << 20)
  123. #define RADEON_IB_VM_MAX_SIZE (64 << 10)
  124. /* reset flags */
  125. #define RADEON_RESET_GFX (1 << 0)
  126. #define RADEON_RESET_COMPUTE (1 << 1)
  127. #define RADEON_RESET_DMA (1 << 2)
  128. #define RADEON_RESET_CP (1 << 3)
  129. #define RADEON_RESET_GRBM (1 << 4)
  130. #define RADEON_RESET_DMA1 (1 << 5)
  131. #define RADEON_RESET_RLC (1 << 6)
  132. #define RADEON_RESET_SEM (1 << 7)
  133. #define RADEON_RESET_IH (1 << 8)
  134. #define RADEON_RESET_VMC (1 << 9)
  135. #define RADEON_RESET_MC (1 << 10)
  136. #define RADEON_RESET_DISPLAY (1 << 11)
  137. /*
  138. * Errata workarounds.
  139. */
  140. enum radeon_pll_errata {
  141. CHIP_ERRATA_R300_CG = 0x00000001,
  142. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  143. CHIP_ERRATA_PLL_DELAY = 0x00000004
  144. };
  145. struct radeon_device;
  146. /*
  147. * BIOS.
  148. */
  149. bool radeon_get_bios(struct radeon_device *rdev);
  150. /*
  151. * Dummy page
  152. */
  153. struct radeon_dummy_page {
  154. struct page *page;
  155. dma_addr_t addr;
  156. };
  157. int radeon_dummy_page_init(struct radeon_device *rdev);
  158. void radeon_dummy_page_fini(struct radeon_device *rdev);
  159. /*
  160. * Clocks
  161. */
  162. struct radeon_clock {
  163. struct radeon_pll p1pll;
  164. struct radeon_pll p2pll;
  165. struct radeon_pll dcpll;
  166. struct radeon_pll spll;
  167. struct radeon_pll mpll;
  168. /* 10 Khz units */
  169. uint32_t default_mclk;
  170. uint32_t default_sclk;
  171. uint32_t default_dispclk;
  172. uint32_t dp_extclk;
  173. uint32_t max_pixel_clock;
  174. };
  175. /*
  176. * Power management
  177. */
  178. int radeon_pm_init(struct radeon_device *rdev);
  179. void radeon_pm_fini(struct radeon_device *rdev);
  180. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  181. void radeon_pm_suspend(struct radeon_device *rdev);
  182. void radeon_pm_resume(struct radeon_device *rdev);
  183. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  184. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  185. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  186. void rs690_pm_info(struct radeon_device *rdev);
  187. extern int rv6xx_get_temp(struct radeon_device *rdev);
  188. extern int rv770_get_temp(struct radeon_device *rdev);
  189. extern int evergreen_get_temp(struct radeon_device *rdev);
  190. extern int sumo_get_temp(struct radeon_device *rdev);
  191. extern int si_get_temp(struct radeon_device *rdev);
  192. extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  193. unsigned *bankh, unsigned *mtaspect,
  194. unsigned *tile_split);
  195. /*
  196. * Fences.
  197. */
  198. struct radeon_fence_driver {
  199. uint32_t scratch_reg;
  200. uint64_t gpu_addr;
  201. volatile uint32_t *cpu_addr;
  202. /* sync_seq is protected by ring emission lock */
  203. uint64_t sync_seq[RADEON_NUM_RINGS];
  204. atomic64_t last_seq;
  205. unsigned long last_activity;
  206. bool initialized;
  207. };
  208. struct radeon_fence {
  209. struct radeon_device *rdev;
  210. struct kref kref;
  211. /* protected by radeon_fence.lock */
  212. uint64_t seq;
  213. /* RB, DMA, etc. */
  214. unsigned ring;
  215. };
  216. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
  217. int radeon_fence_driver_init(struct radeon_device *rdev);
  218. void radeon_fence_driver_fini(struct radeon_device *rdev);
  219. void radeon_fence_driver_force_completion(struct radeon_device *rdev);
  220. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
  221. void radeon_fence_process(struct radeon_device *rdev, int ring);
  222. bool radeon_fence_signaled(struct radeon_fence *fence);
  223. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  224. int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
  225. int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
  226. int radeon_fence_wait_any(struct radeon_device *rdev,
  227. struct radeon_fence **fences,
  228. bool intr);
  229. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  230. void radeon_fence_unref(struct radeon_fence **fence);
  231. unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
  232. bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
  233. void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
  234. static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
  235. struct radeon_fence *b)
  236. {
  237. if (!a) {
  238. return b;
  239. }
  240. if (!b) {
  241. return a;
  242. }
  243. BUG_ON(a->ring != b->ring);
  244. if (a->seq > b->seq) {
  245. return a;
  246. } else {
  247. return b;
  248. }
  249. }
  250. static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
  251. struct radeon_fence *b)
  252. {
  253. if (!a) {
  254. return false;
  255. }
  256. if (!b) {
  257. return true;
  258. }
  259. BUG_ON(a->ring != b->ring);
  260. return a->seq < b->seq;
  261. }
  262. /*
  263. * Tiling registers
  264. */
  265. struct radeon_surface_reg {
  266. struct radeon_bo *bo;
  267. };
  268. #define RADEON_GEM_MAX_SURFACES 8
  269. /*
  270. * TTM.
  271. */
  272. struct radeon_mman {
  273. struct ttm_bo_global_ref bo_global_ref;
  274. struct drm_global_reference mem_global_ref;
  275. struct ttm_bo_device bdev;
  276. bool mem_global_referenced;
  277. bool initialized;
  278. };
  279. /* bo virtual address in a specific vm */
  280. struct radeon_bo_va {
  281. /* protected by bo being reserved */
  282. struct list_head bo_list;
  283. uint64_t soffset;
  284. uint64_t eoffset;
  285. uint32_t flags;
  286. bool valid;
  287. unsigned ref_count;
  288. /* protected by vm mutex */
  289. struct list_head vm_list;
  290. /* constant after initialization */
  291. struct radeon_vm *vm;
  292. struct radeon_bo *bo;
  293. };
  294. struct radeon_bo {
  295. /* Protected by gem.mutex */
  296. struct list_head list;
  297. /* Protected by tbo.reserved */
  298. u32 placements[3];
  299. struct ttm_placement placement;
  300. struct ttm_buffer_object tbo;
  301. struct ttm_bo_kmap_obj kmap;
  302. unsigned pin_count;
  303. void *kptr;
  304. u32 tiling_flags;
  305. u32 pitch;
  306. int surface_reg;
  307. /* list of all virtual address to which this bo
  308. * is associated to
  309. */
  310. struct list_head va;
  311. /* Constant after initialization */
  312. struct radeon_device *rdev;
  313. struct drm_gem_object gem_base;
  314. struct ttm_bo_kmap_obj dma_buf_vmap;
  315. };
  316. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  317. struct radeon_bo_list {
  318. struct ttm_validate_buffer tv;
  319. struct radeon_bo *bo;
  320. uint64_t gpu_offset;
  321. bool written;
  322. unsigned domain;
  323. unsigned alt_domain;
  324. u32 tiling_flags;
  325. };
  326. /* sub-allocation manager, it has to be protected by another lock.
  327. * By conception this is an helper for other part of the driver
  328. * like the indirect buffer or semaphore, which both have their
  329. * locking.
  330. *
  331. * Principe is simple, we keep a list of sub allocation in offset
  332. * order (first entry has offset == 0, last entry has the highest
  333. * offset).
  334. *
  335. * When allocating new object we first check if there is room at
  336. * the end total_size - (last_object_offset + last_object_size) >=
  337. * alloc_size. If so we allocate new object there.
  338. *
  339. * When there is not enough room at the end, we start waiting for
  340. * each sub object until we reach object_offset+object_size >=
  341. * alloc_size, this object then become the sub object we return.
  342. *
  343. * Alignment can't be bigger than page size.
  344. *
  345. * Hole are not considered for allocation to keep things simple.
  346. * Assumption is that there won't be hole (all object on same
  347. * alignment).
  348. */
  349. struct radeon_sa_manager {
  350. wait_queue_head_t wq;
  351. struct radeon_bo *bo;
  352. struct list_head *hole;
  353. struct list_head flist[RADEON_NUM_RINGS];
  354. struct list_head olist;
  355. unsigned size;
  356. uint64_t gpu_addr;
  357. void *cpu_ptr;
  358. uint32_t domain;
  359. };
  360. struct radeon_sa_bo;
  361. /* sub-allocation buffer */
  362. struct radeon_sa_bo {
  363. struct list_head olist;
  364. struct list_head flist;
  365. struct radeon_sa_manager *manager;
  366. unsigned soffset;
  367. unsigned eoffset;
  368. struct radeon_fence *fence;
  369. };
  370. /*
  371. * GEM objects.
  372. */
  373. struct radeon_gem {
  374. struct mutex mutex;
  375. struct list_head objects;
  376. };
  377. int radeon_gem_init(struct radeon_device *rdev);
  378. void radeon_gem_fini(struct radeon_device *rdev);
  379. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  380. int alignment, int initial_domain,
  381. bool discardable, bool kernel,
  382. struct drm_gem_object **obj);
  383. int radeon_mode_dumb_create(struct drm_file *file_priv,
  384. struct drm_device *dev,
  385. struct drm_mode_create_dumb *args);
  386. int radeon_mode_dumb_mmap(struct drm_file *filp,
  387. struct drm_device *dev,
  388. uint32_t handle, uint64_t *offset_p);
  389. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  390. struct drm_device *dev,
  391. uint32_t handle);
  392. /*
  393. * Semaphores.
  394. */
  395. /* everything here is constant */
  396. struct radeon_semaphore {
  397. struct radeon_sa_bo *sa_bo;
  398. signed waiters;
  399. uint64_t gpu_addr;
  400. };
  401. int radeon_semaphore_create(struct radeon_device *rdev,
  402. struct radeon_semaphore **semaphore);
  403. void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
  404. struct radeon_semaphore *semaphore);
  405. void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
  406. struct radeon_semaphore *semaphore);
  407. int radeon_semaphore_sync_rings(struct radeon_device *rdev,
  408. struct radeon_semaphore *semaphore,
  409. int signaler, int waiter);
  410. void radeon_semaphore_free(struct radeon_device *rdev,
  411. struct radeon_semaphore **semaphore,
  412. struct radeon_fence *fence);
  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. u64 mc_mask;
  469. };
  470. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  471. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  472. /*
  473. * GPU scratch registers structures, functions & helpers
  474. */
  475. struct radeon_scratch {
  476. unsigned num_reg;
  477. uint32_t reg_base;
  478. bool free[32];
  479. uint32_t reg[32];
  480. };
  481. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  482. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  483. /*
  484. * IRQS.
  485. */
  486. struct radeon_unpin_work {
  487. struct work_struct work;
  488. struct radeon_device *rdev;
  489. int crtc_id;
  490. struct radeon_fence *fence;
  491. struct drm_pending_vblank_event *event;
  492. struct radeon_bo *old_rbo;
  493. u64 new_crtc_base;
  494. };
  495. struct r500_irq_stat_regs {
  496. u32 disp_int;
  497. u32 hdmi0_status;
  498. };
  499. struct r600_irq_stat_regs {
  500. u32 disp_int;
  501. u32 disp_int_cont;
  502. u32 disp_int_cont2;
  503. u32 d1grph_int;
  504. u32 d2grph_int;
  505. u32 hdmi0_status;
  506. u32 hdmi1_status;
  507. };
  508. struct evergreen_irq_stat_regs {
  509. u32 disp_int;
  510. u32 disp_int_cont;
  511. u32 disp_int_cont2;
  512. u32 disp_int_cont3;
  513. u32 disp_int_cont4;
  514. u32 disp_int_cont5;
  515. u32 d1grph_int;
  516. u32 d2grph_int;
  517. u32 d3grph_int;
  518. u32 d4grph_int;
  519. u32 d5grph_int;
  520. u32 d6grph_int;
  521. u32 afmt_status1;
  522. u32 afmt_status2;
  523. u32 afmt_status3;
  524. u32 afmt_status4;
  525. u32 afmt_status5;
  526. u32 afmt_status6;
  527. };
  528. union radeon_irq_stat_regs {
  529. struct r500_irq_stat_regs r500;
  530. struct r600_irq_stat_regs r600;
  531. struct evergreen_irq_stat_regs evergreen;
  532. };
  533. #define RADEON_MAX_HPD_PINS 6
  534. #define RADEON_MAX_CRTCS 6
  535. #define RADEON_MAX_AFMT_BLOCKS 6
  536. struct radeon_irq {
  537. bool installed;
  538. spinlock_t lock;
  539. atomic_t ring_int[RADEON_NUM_RINGS];
  540. bool crtc_vblank_int[RADEON_MAX_CRTCS];
  541. atomic_t pflip[RADEON_MAX_CRTCS];
  542. wait_queue_head_t vblank_queue;
  543. bool hpd[RADEON_MAX_HPD_PINS];
  544. bool afmt[RADEON_MAX_AFMT_BLOCKS];
  545. union radeon_irq_stat_regs stat_regs;
  546. };
  547. int radeon_irq_kms_init(struct radeon_device *rdev);
  548. void radeon_irq_kms_fini(struct radeon_device *rdev);
  549. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
  550. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
  551. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  552. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  553. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
  554. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
  555. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  556. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  557. /*
  558. * CP & rings.
  559. */
  560. struct radeon_ib {
  561. struct radeon_sa_bo *sa_bo;
  562. uint32_t length_dw;
  563. uint64_t gpu_addr;
  564. uint32_t *ptr;
  565. int ring;
  566. struct radeon_fence *fence;
  567. struct radeon_vm *vm;
  568. bool is_const_ib;
  569. struct radeon_fence *sync_to[RADEON_NUM_RINGS];
  570. struct radeon_semaphore *semaphore;
  571. };
  572. struct radeon_ring {
  573. struct radeon_bo *ring_obj;
  574. volatile uint32_t *ring;
  575. unsigned rptr;
  576. unsigned rptr_offs;
  577. unsigned rptr_reg;
  578. unsigned rptr_save_reg;
  579. u64 next_rptr_gpu_addr;
  580. volatile u32 *next_rptr_cpu_addr;
  581. unsigned wptr;
  582. unsigned wptr_old;
  583. unsigned wptr_reg;
  584. unsigned ring_size;
  585. unsigned ring_free_dw;
  586. int count_dw;
  587. unsigned long last_activity;
  588. unsigned last_rptr;
  589. uint64_t gpu_addr;
  590. uint32_t align_mask;
  591. uint32_t ptr_mask;
  592. bool ready;
  593. u32 ptr_reg_shift;
  594. u32 ptr_reg_mask;
  595. u32 nop;
  596. u32 idx;
  597. u64 last_semaphore_signal_addr;
  598. u64 last_semaphore_wait_addr;
  599. };
  600. /*
  601. * VM
  602. */
  603. /* maximum number of VMIDs */
  604. #define RADEON_NUM_VM 16
  605. /* defines number of bits in page table versus page directory,
  606. * a page is 4KB so we have 12 bits offset, 9 bits in the page
  607. * table and the remaining 19 bits are in the page directory */
  608. #define RADEON_VM_BLOCK_SIZE 9
  609. /* number of entries in page table */
  610. #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
  611. struct radeon_vm {
  612. struct list_head list;
  613. struct list_head va;
  614. unsigned id;
  615. /* contains the page directory */
  616. struct radeon_sa_bo *page_directory;
  617. uint64_t pd_gpu_addr;
  618. /* array of page tables, one for each page directory entry */
  619. struct radeon_sa_bo **page_tables;
  620. struct mutex mutex;
  621. /* last fence for cs using this vm */
  622. struct radeon_fence *fence;
  623. /* last flush or NULL if we still need to flush */
  624. struct radeon_fence *last_flush;
  625. };
  626. struct radeon_vm_manager {
  627. struct mutex lock;
  628. struct list_head lru_vm;
  629. struct radeon_fence *active[RADEON_NUM_VM];
  630. struct radeon_sa_manager sa_manager;
  631. uint32_t max_pfn;
  632. /* number of VMIDs */
  633. unsigned nvm;
  634. /* vram base address for page table entry */
  635. u64 vram_base_offset;
  636. /* is vm enabled? */
  637. bool enabled;
  638. };
  639. /*
  640. * file private structure
  641. */
  642. struct radeon_fpriv {
  643. struct radeon_vm vm;
  644. };
  645. /*
  646. * R6xx+ IH ring
  647. */
  648. struct r600_ih {
  649. struct radeon_bo *ring_obj;
  650. volatile uint32_t *ring;
  651. unsigned rptr;
  652. unsigned ring_size;
  653. uint64_t gpu_addr;
  654. uint32_t ptr_mask;
  655. atomic_t lock;
  656. bool enabled;
  657. };
  658. struct r600_blit_cp_primitives {
  659. void (*set_render_target)(struct radeon_device *rdev, int format,
  660. int w, int h, u64 gpu_addr);
  661. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  662. u32 sync_type, u32 size,
  663. u64 mc_addr);
  664. void (*set_shaders)(struct radeon_device *rdev);
  665. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  666. void (*set_tex_resource)(struct radeon_device *rdev,
  667. int format, int w, int h, int pitch,
  668. u64 gpu_addr, u32 size);
  669. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  670. int x2, int y2);
  671. void (*draw_auto)(struct radeon_device *rdev);
  672. void (*set_default_state)(struct radeon_device *rdev);
  673. };
  674. struct r600_blit {
  675. struct radeon_bo *shader_obj;
  676. struct r600_blit_cp_primitives primitives;
  677. int max_dim;
  678. int ring_size_common;
  679. int ring_size_per_loop;
  680. u64 shader_gpu_addr;
  681. u32 vs_offset, ps_offset;
  682. u32 state_offset;
  683. u32 state_len;
  684. };
  685. /*
  686. * SI RLC stuff
  687. */
  688. struct si_rlc {
  689. /* for power gating */
  690. struct radeon_bo *save_restore_obj;
  691. uint64_t save_restore_gpu_addr;
  692. /* for clear state */
  693. struct radeon_bo *clear_state_obj;
  694. uint64_t clear_state_gpu_addr;
  695. };
  696. int radeon_ib_get(struct radeon_device *rdev, int ring,
  697. struct radeon_ib *ib, struct radeon_vm *vm,
  698. unsigned size);
  699. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
  700. void radeon_ib_sync_to(struct radeon_ib *ib, struct radeon_fence *fence);
  701. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
  702. struct radeon_ib *const_ib);
  703. int radeon_ib_pool_init(struct radeon_device *rdev);
  704. void radeon_ib_pool_fini(struct radeon_device *rdev);
  705. int radeon_ib_ring_tests(struct radeon_device *rdev);
  706. /* Ring access between begin & end cannot sleep */
  707. bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
  708. struct radeon_ring *ring);
  709. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  710. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  711. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  712. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  713. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  714. void radeon_ring_undo(struct radeon_ring *ring);
  715. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  716. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  717. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  718. void radeon_ring_lockup_update(struct radeon_ring *ring);
  719. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  720. unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
  721. uint32_t **data);
  722. int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
  723. unsigned size, uint32_t *data);
  724. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  725. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  726. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  727. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  728. /* r600 async dma */
  729. void r600_dma_stop(struct radeon_device *rdev);
  730. int r600_dma_resume(struct radeon_device *rdev);
  731. void r600_dma_fini(struct radeon_device *rdev);
  732. void cayman_dma_stop(struct radeon_device *rdev);
  733. int cayman_dma_resume(struct radeon_device *rdev);
  734. void cayman_dma_fini(struct radeon_device *rdev);
  735. /*
  736. * CS.
  737. */
  738. struct radeon_cs_reloc {
  739. struct drm_gem_object *gobj;
  740. struct radeon_bo *robj;
  741. struct radeon_bo_list lobj;
  742. uint32_t handle;
  743. uint32_t flags;
  744. };
  745. struct radeon_cs_chunk {
  746. uint32_t chunk_id;
  747. uint32_t length_dw;
  748. int kpage_idx[2];
  749. uint32_t *kpage[2];
  750. uint32_t *kdata;
  751. void __user *user_ptr;
  752. int last_copied_page;
  753. int last_page_index;
  754. };
  755. struct radeon_cs_parser {
  756. struct device *dev;
  757. struct radeon_device *rdev;
  758. struct drm_file *filp;
  759. /* chunks */
  760. unsigned nchunks;
  761. struct radeon_cs_chunk *chunks;
  762. uint64_t *chunks_array;
  763. /* IB */
  764. unsigned idx;
  765. /* relocations */
  766. unsigned nrelocs;
  767. struct radeon_cs_reloc *relocs;
  768. struct radeon_cs_reloc **relocs_ptr;
  769. struct list_head validated;
  770. unsigned dma_reloc_idx;
  771. /* indices of various chunks */
  772. int chunk_ib_idx;
  773. int chunk_relocs_idx;
  774. int chunk_flags_idx;
  775. int chunk_const_ib_idx;
  776. struct radeon_ib ib;
  777. struct radeon_ib const_ib;
  778. void *track;
  779. unsigned family;
  780. int parser_error;
  781. u32 cs_flags;
  782. u32 ring;
  783. s32 priority;
  784. };
  785. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  786. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  787. struct radeon_cs_packet {
  788. unsigned idx;
  789. unsigned type;
  790. unsigned reg;
  791. unsigned opcode;
  792. int count;
  793. unsigned one_reg_wr;
  794. };
  795. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  796. struct radeon_cs_packet *pkt,
  797. unsigned idx, unsigned reg);
  798. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  799. struct radeon_cs_packet *pkt);
  800. /*
  801. * AGP
  802. */
  803. int radeon_agp_init(struct radeon_device *rdev);
  804. void radeon_agp_resume(struct radeon_device *rdev);
  805. void radeon_agp_suspend(struct radeon_device *rdev);
  806. void radeon_agp_fini(struct radeon_device *rdev);
  807. /*
  808. * Writeback
  809. */
  810. struct radeon_wb {
  811. struct radeon_bo *wb_obj;
  812. volatile uint32_t *wb;
  813. uint64_t gpu_addr;
  814. bool enabled;
  815. bool use_event;
  816. };
  817. #define RADEON_WB_SCRATCH_OFFSET 0
  818. #define RADEON_WB_RING0_NEXT_RPTR 256
  819. #define RADEON_WB_CP_RPTR_OFFSET 1024
  820. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  821. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  822. #define R600_WB_DMA_RPTR_OFFSET 1792
  823. #define R600_WB_IH_WPTR_OFFSET 2048
  824. #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
  825. #define R600_WB_UVD_RPTR_OFFSET 2560
  826. #define R600_WB_EVENT_OFFSET 3072
  827. /**
  828. * struct radeon_pm - power management datas
  829. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  830. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  831. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  832. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  833. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  834. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  835. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  836. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  837. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  838. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  839. * @needed_bandwidth: current bandwidth needs
  840. *
  841. * It keeps track of various data needed to take powermanagement decision.
  842. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  843. * Equation between gpu/memory clock and available bandwidth is hw dependent
  844. * (type of memory, bus size, efficiency, ...)
  845. */
  846. enum radeon_pm_method {
  847. PM_METHOD_PROFILE,
  848. PM_METHOD_DYNPM,
  849. };
  850. enum radeon_dynpm_state {
  851. DYNPM_STATE_DISABLED,
  852. DYNPM_STATE_MINIMUM,
  853. DYNPM_STATE_PAUSED,
  854. DYNPM_STATE_ACTIVE,
  855. DYNPM_STATE_SUSPENDED,
  856. };
  857. enum radeon_dynpm_action {
  858. DYNPM_ACTION_NONE,
  859. DYNPM_ACTION_MINIMUM,
  860. DYNPM_ACTION_DOWNCLOCK,
  861. DYNPM_ACTION_UPCLOCK,
  862. DYNPM_ACTION_DEFAULT
  863. };
  864. enum radeon_voltage_type {
  865. VOLTAGE_NONE = 0,
  866. VOLTAGE_GPIO,
  867. VOLTAGE_VDDC,
  868. VOLTAGE_SW
  869. };
  870. enum radeon_pm_state_type {
  871. POWER_STATE_TYPE_DEFAULT,
  872. POWER_STATE_TYPE_POWERSAVE,
  873. POWER_STATE_TYPE_BATTERY,
  874. POWER_STATE_TYPE_BALANCED,
  875. POWER_STATE_TYPE_PERFORMANCE,
  876. };
  877. enum radeon_pm_profile_type {
  878. PM_PROFILE_DEFAULT,
  879. PM_PROFILE_AUTO,
  880. PM_PROFILE_LOW,
  881. PM_PROFILE_MID,
  882. PM_PROFILE_HIGH,
  883. };
  884. #define PM_PROFILE_DEFAULT_IDX 0
  885. #define PM_PROFILE_LOW_SH_IDX 1
  886. #define PM_PROFILE_MID_SH_IDX 2
  887. #define PM_PROFILE_HIGH_SH_IDX 3
  888. #define PM_PROFILE_LOW_MH_IDX 4
  889. #define PM_PROFILE_MID_MH_IDX 5
  890. #define PM_PROFILE_HIGH_MH_IDX 6
  891. #define PM_PROFILE_MAX 7
  892. struct radeon_pm_profile {
  893. int dpms_off_ps_idx;
  894. int dpms_on_ps_idx;
  895. int dpms_off_cm_idx;
  896. int dpms_on_cm_idx;
  897. };
  898. enum radeon_int_thermal_type {
  899. THERMAL_TYPE_NONE,
  900. THERMAL_TYPE_RV6XX,
  901. THERMAL_TYPE_RV770,
  902. THERMAL_TYPE_EVERGREEN,
  903. THERMAL_TYPE_SUMO,
  904. THERMAL_TYPE_NI,
  905. THERMAL_TYPE_SI,
  906. };
  907. struct radeon_voltage {
  908. enum radeon_voltage_type type;
  909. /* gpio voltage */
  910. struct radeon_gpio_rec gpio;
  911. u32 delay; /* delay in usec from voltage drop to sclk change */
  912. bool active_high; /* voltage drop is active when bit is high */
  913. /* VDDC voltage */
  914. u8 vddc_id; /* index into vddc voltage table */
  915. u8 vddci_id; /* index into vddci voltage table */
  916. bool vddci_enabled;
  917. /* r6xx+ sw */
  918. u16 voltage;
  919. /* evergreen+ vddci */
  920. u16 vddci;
  921. };
  922. /* clock mode flags */
  923. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  924. struct radeon_pm_clock_info {
  925. /* memory clock */
  926. u32 mclk;
  927. /* engine clock */
  928. u32 sclk;
  929. /* voltage info */
  930. struct radeon_voltage voltage;
  931. /* standardized clock flags */
  932. u32 flags;
  933. };
  934. /* state flags */
  935. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  936. struct radeon_power_state {
  937. enum radeon_pm_state_type type;
  938. struct radeon_pm_clock_info *clock_info;
  939. /* number of valid clock modes in this power state */
  940. int num_clock_modes;
  941. struct radeon_pm_clock_info *default_clock_mode;
  942. /* standardized state flags */
  943. u32 flags;
  944. u32 misc; /* vbios specific flags */
  945. u32 misc2; /* vbios specific flags */
  946. int pcie_lanes; /* pcie lanes */
  947. };
  948. /*
  949. * Some modes are overclocked by very low value, accept them
  950. */
  951. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  952. struct radeon_pm {
  953. struct mutex mutex;
  954. /* write locked while reprogramming mclk */
  955. struct rw_semaphore mclk_lock;
  956. u32 active_crtcs;
  957. int active_crtc_count;
  958. int req_vblank;
  959. bool vblank_sync;
  960. fixed20_12 max_bandwidth;
  961. fixed20_12 igp_sideport_mclk;
  962. fixed20_12 igp_system_mclk;
  963. fixed20_12 igp_ht_link_clk;
  964. fixed20_12 igp_ht_link_width;
  965. fixed20_12 k8_bandwidth;
  966. fixed20_12 sideport_bandwidth;
  967. fixed20_12 ht_bandwidth;
  968. fixed20_12 core_bandwidth;
  969. fixed20_12 sclk;
  970. fixed20_12 mclk;
  971. fixed20_12 needed_bandwidth;
  972. struct radeon_power_state *power_state;
  973. /* number of valid power states */
  974. int num_power_states;
  975. int current_power_state_index;
  976. int current_clock_mode_index;
  977. int requested_power_state_index;
  978. int requested_clock_mode_index;
  979. int default_power_state_index;
  980. u32 current_sclk;
  981. u32 current_mclk;
  982. u16 current_vddc;
  983. u16 current_vddci;
  984. u32 default_sclk;
  985. u32 default_mclk;
  986. u16 default_vddc;
  987. u16 default_vddci;
  988. struct radeon_i2c_chan *i2c_bus;
  989. /* selected pm method */
  990. enum radeon_pm_method pm_method;
  991. /* dynpm power management */
  992. struct delayed_work dynpm_idle_work;
  993. enum radeon_dynpm_state dynpm_state;
  994. enum radeon_dynpm_action dynpm_planned_action;
  995. unsigned long dynpm_action_timeout;
  996. bool dynpm_can_upclock;
  997. bool dynpm_can_downclock;
  998. /* profile-based power management */
  999. enum radeon_pm_profile_type profile;
  1000. int profile_index;
  1001. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  1002. /* internal thermal controller on rv6xx+ */
  1003. enum radeon_int_thermal_type int_thermal_type;
  1004. struct device *int_hwmon_dev;
  1005. };
  1006. int radeon_pm_get_type_index(struct radeon_device *rdev,
  1007. enum radeon_pm_state_type ps_type,
  1008. int instance);
  1009. /*
  1010. * UVD
  1011. */
  1012. #define RADEON_MAX_UVD_HANDLES 10
  1013. #define RADEON_UVD_STACK_SIZE (1024*1024)
  1014. #define RADEON_UVD_HEAP_SIZE (1024*1024)
  1015. struct radeon_uvd {
  1016. struct radeon_bo *vcpu_bo;
  1017. void *cpu_addr;
  1018. uint64_t gpu_addr;
  1019. atomic_t handles[RADEON_MAX_UVD_HANDLES];
  1020. struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
  1021. };
  1022. int radeon_uvd_init(struct radeon_device *rdev);
  1023. void radeon_uvd_fini(struct radeon_device *rdev);
  1024. int radeon_uvd_suspend(struct radeon_device *rdev);
  1025. int radeon_uvd_resume(struct radeon_device *rdev);
  1026. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  1027. uint32_t handle, struct radeon_fence **fence);
  1028. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  1029. uint32_t handle, struct radeon_fence **fence);
  1030. void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo);
  1031. void radeon_uvd_free_handles(struct radeon_device *rdev,
  1032. struct drm_file *filp);
  1033. int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
  1034. struct r600_audio {
  1035. int channels;
  1036. int rate;
  1037. int bits_per_sample;
  1038. u8 status_bits;
  1039. u8 category_code;
  1040. };
  1041. /*
  1042. * Benchmarking
  1043. */
  1044. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1045. /*
  1046. * Testing
  1047. */
  1048. void radeon_test_moves(struct radeon_device *rdev);
  1049. void radeon_test_ring_sync(struct radeon_device *rdev,
  1050. struct radeon_ring *cpA,
  1051. struct radeon_ring *cpB);
  1052. void radeon_test_syncing(struct radeon_device *rdev);
  1053. /*
  1054. * Debugfs
  1055. */
  1056. struct radeon_debugfs {
  1057. struct drm_info_list *files;
  1058. unsigned num_files;
  1059. };
  1060. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1061. struct drm_info_list *files,
  1062. unsigned nfiles);
  1063. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1064. /*
  1065. * ASIC specific functions.
  1066. */
  1067. struct radeon_asic {
  1068. int (*init)(struct radeon_device *rdev);
  1069. void (*fini)(struct radeon_device *rdev);
  1070. int (*resume)(struct radeon_device *rdev);
  1071. int (*suspend)(struct radeon_device *rdev);
  1072. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1073. int (*asic_reset)(struct radeon_device *rdev);
  1074. /* ioctl hw specific callback. Some hw might want to perform special
  1075. * operation on specific ioctl. For instance on wait idle some hw
  1076. * might want to perform and HDP flush through MMIO as it seems that
  1077. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1078. * through ring.
  1079. */
  1080. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1081. /* check if 3D engine is idle */
  1082. bool (*gui_idle)(struct radeon_device *rdev);
  1083. /* wait for mc_idle */
  1084. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1085. /* get the reference clock */
  1086. u32 (*get_xclk)(struct radeon_device *rdev);
  1087. /* get the gpu clock counter */
  1088. uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
  1089. /* gart */
  1090. struct {
  1091. void (*tlb_flush)(struct radeon_device *rdev);
  1092. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1093. } gart;
  1094. struct {
  1095. int (*init)(struct radeon_device *rdev);
  1096. void (*fini)(struct radeon_device *rdev);
  1097. u32 pt_ring_index;
  1098. void (*set_page)(struct radeon_device *rdev,
  1099. struct radeon_ib *ib,
  1100. uint64_t pe,
  1101. uint64_t addr, unsigned count,
  1102. uint32_t incr, uint32_t flags);
  1103. } vm;
  1104. /* ring specific callbacks */
  1105. struct {
  1106. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1107. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1108. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1109. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1110. struct radeon_semaphore *semaphore, bool emit_wait);
  1111. int (*cs_parse)(struct radeon_cs_parser *p);
  1112. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1113. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1114. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1115. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1116. void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
  1117. } ring[RADEON_NUM_RINGS];
  1118. /* irqs */
  1119. struct {
  1120. int (*set)(struct radeon_device *rdev);
  1121. int (*process)(struct radeon_device *rdev);
  1122. } irq;
  1123. /* displays */
  1124. struct {
  1125. /* display watermarks */
  1126. void (*bandwidth_update)(struct radeon_device *rdev);
  1127. /* get frame count */
  1128. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1129. /* wait for vblank */
  1130. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1131. /* set backlight level */
  1132. void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
  1133. /* get backlight level */
  1134. u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
  1135. } display;
  1136. /* copy functions for bo handling */
  1137. struct {
  1138. int (*blit)(struct radeon_device *rdev,
  1139. uint64_t src_offset,
  1140. uint64_t dst_offset,
  1141. unsigned num_gpu_pages,
  1142. struct radeon_fence **fence);
  1143. u32 blit_ring_index;
  1144. int (*dma)(struct radeon_device *rdev,
  1145. uint64_t src_offset,
  1146. uint64_t dst_offset,
  1147. unsigned num_gpu_pages,
  1148. struct radeon_fence **fence);
  1149. u32 dma_ring_index;
  1150. /* method used for bo copy */
  1151. int (*copy)(struct radeon_device *rdev,
  1152. uint64_t src_offset,
  1153. uint64_t dst_offset,
  1154. unsigned num_gpu_pages,
  1155. struct radeon_fence **fence);
  1156. /* ring used for bo copies */
  1157. u32 copy_ring_index;
  1158. } copy;
  1159. /* surfaces */
  1160. struct {
  1161. int (*set_reg)(struct radeon_device *rdev, int reg,
  1162. uint32_t tiling_flags, uint32_t pitch,
  1163. uint32_t offset, uint32_t obj_size);
  1164. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1165. } surface;
  1166. /* hotplug detect */
  1167. struct {
  1168. void (*init)(struct radeon_device *rdev);
  1169. void (*fini)(struct radeon_device *rdev);
  1170. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1171. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1172. } hpd;
  1173. /* power management */
  1174. struct {
  1175. void (*misc)(struct radeon_device *rdev);
  1176. void (*prepare)(struct radeon_device *rdev);
  1177. void (*finish)(struct radeon_device *rdev);
  1178. void (*init_profile)(struct radeon_device *rdev);
  1179. void (*get_dynpm_state)(struct radeon_device *rdev);
  1180. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1181. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1182. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1183. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1184. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1185. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1186. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1187. } pm;
  1188. /* pageflipping */
  1189. struct {
  1190. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1191. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1192. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1193. } pflip;
  1194. };
  1195. /*
  1196. * Asic structures
  1197. */
  1198. struct r100_asic {
  1199. const unsigned *reg_safe_bm;
  1200. unsigned reg_safe_bm_size;
  1201. u32 hdp_cntl;
  1202. };
  1203. struct r300_asic {
  1204. const unsigned *reg_safe_bm;
  1205. unsigned reg_safe_bm_size;
  1206. u32 resync_scratch;
  1207. u32 hdp_cntl;
  1208. };
  1209. struct r600_asic {
  1210. unsigned max_pipes;
  1211. unsigned max_tile_pipes;
  1212. unsigned max_simds;
  1213. unsigned max_backends;
  1214. unsigned max_gprs;
  1215. unsigned max_threads;
  1216. unsigned max_stack_entries;
  1217. unsigned max_hw_contexts;
  1218. unsigned max_gs_threads;
  1219. unsigned sx_max_export_size;
  1220. unsigned sx_max_export_pos_size;
  1221. unsigned sx_max_export_smx_size;
  1222. unsigned sq_num_cf_insts;
  1223. unsigned tiling_nbanks;
  1224. unsigned tiling_npipes;
  1225. unsigned tiling_group_size;
  1226. unsigned tile_config;
  1227. unsigned backend_map;
  1228. };
  1229. struct rv770_asic {
  1230. unsigned max_pipes;
  1231. unsigned max_tile_pipes;
  1232. unsigned max_simds;
  1233. unsigned max_backends;
  1234. unsigned max_gprs;
  1235. unsigned max_threads;
  1236. unsigned max_stack_entries;
  1237. unsigned max_hw_contexts;
  1238. unsigned max_gs_threads;
  1239. unsigned sx_max_export_size;
  1240. unsigned sx_max_export_pos_size;
  1241. unsigned sx_max_export_smx_size;
  1242. unsigned sq_num_cf_insts;
  1243. unsigned sx_num_of_sets;
  1244. unsigned sc_prim_fifo_size;
  1245. unsigned sc_hiz_tile_fifo_size;
  1246. unsigned sc_earlyz_tile_fifo_fize;
  1247. unsigned tiling_nbanks;
  1248. unsigned tiling_npipes;
  1249. unsigned tiling_group_size;
  1250. unsigned tile_config;
  1251. unsigned backend_map;
  1252. };
  1253. struct evergreen_asic {
  1254. unsigned num_ses;
  1255. unsigned max_pipes;
  1256. unsigned max_tile_pipes;
  1257. unsigned max_simds;
  1258. unsigned max_backends;
  1259. unsigned max_gprs;
  1260. unsigned max_threads;
  1261. unsigned max_stack_entries;
  1262. unsigned max_hw_contexts;
  1263. unsigned max_gs_threads;
  1264. unsigned sx_max_export_size;
  1265. unsigned sx_max_export_pos_size;
  1266. unsigned sx_max_export_smx_size;
  1267. unsigned sq_num_cf_insts;
  1268. unsigned sx_num_of_sets;
  1269. unsigned sc_prim_fifo_size;
  1270. unsigned sc_hiz_tile_fifo_size;
  1271. unsigned sc_earlyz_tile_fifo_size;
  1272. unsigned tiling_nbanks;
  1273. unsigned tiling_npipes;
  1274. unsigned tiling_group_size;
  1275. unsigned tile_config;
  1276. unsigned backend_map;
  1277. };
  1278. struct cayman_asic {
  1279. unsigned max_shader_engines;
  1280. unsigned max_pipes_per_simd;
  1281. unsigned max_tile_pipes;
  1282. unsigned max_simds_per_se;
  1283. unsigned max_backends_per_se;
  1284. unsigned max_texture_channel_caches;
  1285. unsigned max_gprs;
  1286. unsigned max_threads;
  1287. unsigned max_gs_threads;
  1288. unsigned max_stack_entries;
  1289. unsigned sx_num_of_sets;
  1290. unsigned sx_max_export_size;
  1291. unsigned sx_max_export_pos_size;
  1292. unsigned sx_max_export_smx_size;
  1293. unsigned max_hw_contexts;
  1294. unsigned sq_num_cf_insts;
  1295. unsigned sc_prim_fifo_size;
  1296. unsigned sc_hiz_tile_fifo_size;
  1297. unsigned sc_earlyz_tile_fifo_size;
  1298. unsigned num_shader_engines;
  1299. unsigned num_shader_pipes_per_simd;
  1300. unsigned num_tile_pipes;
  1301. unsigned num_simds_per_se;
  1302. unsigned num_backends_per_se;
  1303. unsigned backend_disable_mask_per_asic;
  1304. unsigned backend_map;
  1305. unsigned num_texture_channel_caches;
  1306. unsigned mem_max_burst_length_bytes;
  1307. unsigned mem_row_size_in_kb;
  1308. unsigned shader_engine_tile_size;
  1309. unsigned num_gpus;
  1310. unsigned multi_gpu_tile_size;
  1311. unsigned tile_config;
  1312. };
  1313. struct si_asic {
  1314. unsigned max_shader_engines;
  1315. unsigned max_tile_pipes;
  1316. unsigned max_cu_per_sh;
  1317. unsigned max_sh_per_se;
  1318. unsigned max_backends_per_se;
  1319. unsigned max_texture_channel_caches;
  1320. unsigned max_gprs;
  1321. unsigned max_gs_threads;
  1322. unsigned max_hw_contexts;
  1323. unsigned sc_prim_fifo_size_frontend;
  1324. unsigned sc_prim_fifo_size_backend;
  1325. unsigned sc_hiz_tile_fifo_size;
  1326. unsigned sc_earlyz_tile_fifo_size;
  1327. unsigned num_tile_pipes;
  1328. unsigned num_backends_per_se;
  1329. unsigned backend_disable_mask_per_asic;
  1330. unsigned backend_map;
  1331. unsigned num_texture_channel_caches;
  1332. unsigned mem_max_burst_length_bytes;
  1333. unsigned mem_row_size_in_kb;
  1334. unsigned shader_engine_tile_size;
  1335. unsigned num_gpus;
  1336. unsigned multi_gpu_tile_size;
  1337. unsigned tile_config;
  1338. };
  1339. union radeon_asic_config {
  1340. struct r300_asic r300;
  1341. struct r100_asic r100;
  1342. struct r600_asic r600;
  1343. struct rv770_asic rv770;
  1344. struct evergreen_asic evergreen;
  1345. struct cayman_asic cayman;
  1346. struct si_asic si;
  1347. };
  1348. /*
  1349. * asic initizalization from radeon_asic.c
  1350. */
  1351. void radeon_agp_disable(struct radeon_device *rdev);
  1352. int radeon_asic_init(struct radeon_device *rdev);
  1353. /*
  1354. * IOCTL.
  1355. */
  1356. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1357. struct drm_file *filp);
  1358. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1359. struct drm_file *filp);
  1360. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1361. struct drm_file *file_priv);
  1362. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1363. struct drm_file *file_priv);
  1364. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1365. struct drm_file *file_priv);
  1366. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1367. struct drm_file *file_priv);
  1368. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1369. struct drm_file *filp);
  1370. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1371. struct drm_file *filp);
  1372. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1373. struct drm_file *filp);
  1374. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1375. struct drm_file *filp);
  1376. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1377. struct drm_file *filp);
  1378. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1379. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1380. struct drm_file *filp);
  1381. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1382. struct drm_file *filp);
  1383. /* VRAM scratch page for HDP bug, default vram page */
  1384. struct r600_vram_scratch {
  1385. struct radeon_bo *robj;
  1386. volatile uint32_t *ptr;
  1387. u64 gpu_addr;
  1388. };
  1389. /*
  1390. * ACPI
  1391. */
  1392. struct radeon_atif_notification_cfg {
  1393. bool enabled;
  1394. int command_code;
  1395. };
  1396. struct radeon_atif_notifications {
  1397. bool display_switch;
  1398. bool expansion_mode_change;
  1399. bool thermal_state;
  1400. bool forced_power_state;
  1401. bool system_power_state;
  1402. bool display_conf_change;
  1403. bool px_gfx_switch;
  1404. bool brightness_change;
  1405. bool dgpu_display_event;
  1406. };
  1407. struct radeon_atif_functions {
  1408. bool system_params;
  1409. bool sbios_requests;
  1410. bool select_active_disp;
  1411. bool lid_state;
  1412. bool get_tv_standard;
  1413. bool set_tv_standard;
  1414. bool get_panel_expansion_mode;
  1415. bool set_panel_expansion_mode;
  1416. bool temperature_change;
  1417. bool graphics_device_types;
  1418. };
  1419. struct radeon_atif {
  1420. struct radeon_atif_notifications notifications;
  1421. struct radeon_atif_functions functions;
  1422. struct radeon_atif_notification_cfg notification_cfg;
  1423. struct radeon_encoder *encoder_for_bl;
  1424. };
  1425. struct radeon_atcs_functions {
  1426. bool get_ext_state;
  1427. bool pcie_perf_req;
  1428. bool pcie_dev_rdy;
  1429. bool pcie_bus_width;
  1430. };
  1431. struct radeon_atcs {
  1432. struct radeon_atcs_functions functions;
  1433. };
  1434. /*
  1435. * Core structure, functions and helpers.
  1436. */
  1437. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1438. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1439. struct radeon_device {
  1440. struct device *dev;
  1441. struct drm_device *ddev;
  1442. struct pci_dev *pdev;
  1443. struct rw_semaphore exclusive_lock;
  1444. /* ASIC */
  1445. union radeon_asic_config config;
  1446. enum radeon_family family;
  1447. unsigned long flags;
  1448. int usec_timeout;
  1449. enum radeon_pll_errata pll_errata;
  1450. int num_gb_pipes;
  1451. int num_z_pipes;
  1452. int disp_priority;
  1453. /* BIOS */
  1454. uint8_t *bios;
  1455. bool is_atom_bios;
  1456. uint16_t bios_header_start;
  1457. struct radeon_bo *stollen_vga_memory;
  1458. /* Register mmio */
  1459. resource_size_t rmmio_base;
  1460. resource_size_t rmmio_size;
  1461. /* protects concurrent MM_INDEX/DATA based register access */
  1462. spinlock_t mmio_idx_lock;
  1463. void __iomem *rmmio;
  1464. radeon_rreg_t mc_rreg;
  1465. radeon_wreg_t mc_wreg;
  1466. radeon_rreg_t pll_rreg;
  1467. radeon_wreg_t pll_wreg;
  1468. uint32_t pcie_reg_mask;
  1469. radeon_rreg_t pciep_rreg;
  1470. radeon_wreg_t pciep_wreg;
  1471. /* io port */
  1472. void __iomem *rio_mem;
  1473. resource_size_t rio_mem_size;
  1474. struct radeon_clock clock;
  1475. struct radeon_mc mc;
  1476. struct radeon_gart gart;
  1477. struct radeon_mode_info mode_info;
  1478. struct radeon_scratch scratch;
  1479. struct radeon_mman mman;
  1480. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1481. wait_queue_head_t fence_queue;
  1482. struct mutex ring_lock;
  1483. struct radeon_ring ring[RADEON_NUM_RINGS];
  1484. bool ib_pool_ready;
  1485. struct radeon_sa_manager ring_tmp_bo;
  1486. struct radeon_irq irq;
  1487. struct radeon_asic *asic;
  1488. struct radeon_gem gem;
  1489. struct radeon_pm pm;
  1490. struct radeon_uvd uvd;
  1491. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1492. struct radeon_wb wb;
  1493. struct radeon_dummy_page dummy_page;
  1494. bool shutdown;
  1495. bool suspend;
  1496. bool need_dma32;
  1497. bool accel_working;
  1498. bool fastfb_working; /* IGP feature*/
  1499. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1500. const struct firmware *me_fw; /* all family ME firmware */
  1501. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1502. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1503. const struct firmware *mc_fw; /* NI MC firmware */
  1504. const struct firmware *ce_fw; /* SI CE firmware */
  1505. const struct firmware *uvd_fw; /* UVD firmware */
  1506. struct r600_blit r600_blit;
  1507. struct r600_vram_scratch vram_scratch;
  1508. int msi_enabled; /* msi enabled */
  1509. struct r600_ih ih; /* r6/700 interrupt ring */
  1510. struct si_rlc rlc;
  1511. struct work_struct hotplug_work;
  1512. struct work_struct audio_work;
  1513. int num_crtc; /* number of crtcs */
  1514. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1515. bool audio_enabled;
  1516. struct r600_audio audio_status; /* audio stuff */
  1517. struct notifier_block acpi_nb;
  1518. /* only one userspace can use Hyperz features or CMASK at a time */
  1519. struct drm_file *hyperz_filp;
  1520. struct drm_file *cmask_filp;
  1521. /* i2c buses */
  1522. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1523. /* debugfs */
  1524. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1525. unsigned debugfs_count;
  1526. /* virtual memory */
  1527. struct radeon_vm_manager vm_manager;
  1528. struct mutex gpu_clock_mutex;
  1529. /* ACPI interface */
  1530. struct radeon_atif atif;
  1531. struct radeon_atcs atcs;
  1532. };
  1533. int radeon_device_init(struct radeon_device *rdev,
  1534. struct drm_device *ddev,
  1535. struct pci_dev *pdev,
  1536. uint32_t flags);
  1537. void radeon_device_fini(struct radeon_device *rdev);
  1538. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1539. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
  1540. bool always_indirect);
  1541. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
  1542. bool always_indirect);
  1543. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1544. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1545. /*
  1546. * Cast helper
  1547. */
  1548. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1549. /*
  1550. * Registers read & write functions.
  1551. */
  1552. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1553. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1554. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1555. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1556. #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
  1557. #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
  1558. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
  1559. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
  1560. #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
  1561. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1562. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1563. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1564. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1565. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1566. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1567. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1568. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1569. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1570. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1571. #define WREG32_P(reg, val, mask) \
  1572. do { \
  1573. uint32_t tmp_ = RREG32(reg); \
  1574. tmp_ &= (mask); \
  1575. tmp_ |= ((val) & ~(mask)); \
  1576. WREG32(reg, tmp_); \
  1577. } while (0)
  1578. #define WREG32_PLL_P(reg, val, mask) \
  1579. do { \
  1580. uint32_t tmp_ = RREG32_PLL(reg); \
  1581. tmp_ &= (mask); \
  1582. tmp_ |= ((val) & ~(mask)); \
  1583. WREG32_PLL(reg, tmp_); \
  1584. } while (0)
  1585. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
  1586. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1587. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1588. /*
  1589. * Indirect registers accessor
  1590. */
  1591. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1592. {
  1593. uint32_t r;
  1594. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1595. r = RREG32(RADEON_PCIE_DATA);
  1596. return r;
  1597. }
  1598. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1599. {
  1600. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1601. WREG32(RADEON_PCIE_DATA, (v));
  1602. }
  1603. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1604. /*
  1605. * ASICs helpers.
  1606. */
  1607. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1608. (rdev->pdev->device == 0x5969))
  1609. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1610. (rdev->family == CHIP_RV200) || \
  1611. (rdev->family == CHIP_RS100) || \
  1612. (rdev->family == CHIP_RS200) || \
  1613. (rdev->family == CHIP_RV250) || \
  1614. (rdev->family == CHIP_RV280) || \
  1615. (rdev->family == CHIP_RS300))
  1616. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1617. (rdev->family == CHIP_RV350) || \
  1618. (rdev->family == CHIP_R350) || \
  1619. (rdev->family == CHIP_RV380) || \
  1620. (rdev->family == CHIP_R420) || \
  1621. (rdev->family == CHIP_R423) || \
  1622. (rdev->family == CHIP_RV410) || \
  1623. (rdev->family == CHIP_RS400) || \
  1624. (rdev->family == CHIP_RS480))
  1625. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1626. (rdev->ddev->pdev->device == 0x9443) || \
  1627. (rdev->ddev->pdev->device == 0x944B) || \
  1628. (rdev->ddev->pdev->device == 0x9506) || \
  1629. (rdev->ddev->pdev->device == 0x9509) || \
  1630. (rdev->ddev->pdev->device == 0x950F) || \
  1631. (rdev->ddev->pdev->device == 0x689C) || \
  1632. (rdev->ddev->pdev->device == 0x689D))
  1633. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1634. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1635. (rdev->family == CHIP_RS690) || \
  1636. (rdev->family == CHIP_RS740) || \
  1637. (rdev->family >= CHIP_R600))
  1638. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1639. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1640. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1641. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1642. (rdev->flags & RADEON_IS_IGP))
  1643. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1644. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  1645. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  1646. (rdev->flags & RADEON_IS_IGP))
  1647. #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
  1648. /*
  1649. * BIOS helpers.
  1650. */
  1651. #define RBIOS8(i) (rdev->bios[i])
  1652. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1653. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1654. int radeon_combios_init(struct radeon_device *rdev);
  1655. void radeon_combios_fini(struct radeon_device *rdev);
  1656. int radeon_atombios_init(struct radeon_device *rdev);
  1657. void radeon_atombios_fini(struct radeon_device *rdev);
  1658. /*
  1659. * RING helpers.
  1660. */
  1661. #if DRM_DEBUG_CODE == 0
  1662. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1663. {
  1664. ring->ring[ring->wptr++] = v;
  1665. ring->wptr &= ring->ptr_mask;
  1666. ring->count_dw--;
  1667. ring->ring_free_dw--;
  1668. }
  1669. #else
  1670. /* With debugging this is just too big to inline */
  1671. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1672. #endif
  1673. /*
  1674. * ASICs macro.
  1675. */
  1676. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1677. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1678. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1679. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1680. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  1681. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1682. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1683. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  1684. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  1685. #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
  1686. #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
  1687. #define radeon_asic_vm_set_page(rdev, ib, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (ib), (pe), (addr), (count), (incr), (flags)))
  1688. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  1689. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  1690. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  1691. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1692. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1693. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  1694. #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)].vm_flush((rdev), (r), (vm))
  1695. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  1696. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  1697. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  1698. #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
  1699. #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
  1700. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1701. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1702. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  1703. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  1704. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  1705. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  1706. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  1707. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  1708. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  1709. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  1710. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  1711. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  1712. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  1713. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  1714. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  1715. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  1716. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  1717. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  1718. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  1719. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  1720. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  1721. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  1722. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1723. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  1724. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  1725. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  1726. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  1727. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  1728. #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
  1729. #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
  1730. #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
  1731. #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
  1732. #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
  1733. #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
  1734. #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
  1735. /* Common functions */
  1736. /* AGP */
  1737. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1738. extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
  1739. extern void radeon_agp_disable(struct radeon_device *rdev);
  1740. extern int radeon_modeset_init(struct radeon_device *rdev);
  1741. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1742. extern bool radeon_card_posted(struct radeon_device *rdev);
  1743. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1744. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1745. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1746. extern void radeon_scratch_init(struct radeon_device *rdev);
  1747. extern void radeon_wb_fini(struct radeon_device *rdev);
  1748. extern int radeon_wb_init(struct radeon_device *rdev);
  1749. extern void radeon_wb_disable(struct radeon_device *rdev);
  1750. extern void radeon_surface_init(struct radeon_device *rdev);
  1751. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1752. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1753. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1754. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1755. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1756. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1757. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1758. extern int radeon_resume_kms(struct drm_device *dev);
  1759. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1760. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1761. /*
  1762. * vm
  1763. */
  1764. int radeon_vm_manager_init(struct radeon_device *rdev);
  1765. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1766. void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1767. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1768. int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
  1769. void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
  1770. struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
  1771. struct radeon_vm *vm, int ring);
  1772. void radeon_vm_fence(struct radeon_device *rdev,
  1773. struct radeon_vm *vm,
  1774. struct radeon_fence *fence);
  1775. uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
  1776. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1777. struct radeon_vm *vm,
  1778. struct radeon_bo *bo,
  1779. struct ttm_mem_reg *mem);
  1780. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1781. struct radeon_bo *bo);
  1782. struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
  1783. struct radeon_bo *bo);
  1784. struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
  1785. struct radeon_vm *vm,
  1786. struct radeon_bo *bo);
  1787. int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  1788. struct radeon_bo_va *bo_va,
  1789. uint64_t offset,
  1790. uint32_t flags);
  1791. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1792. struct radeon_bo_va *bo_va);
  1793. /* audio */
  1794. void r600_audio_update_hdmi(struct work_struct *work);
  1795. /*
  1796. * R600 vram scratch functions
  1797. */
  1798. int r600_vram_scratch_init(struct radeon_device *rdev);
  1799. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1800. /*
  1801. * r600 cs checking helper
  1802. */
  1803. unsigned r600_mip_minify(unsigned size, unsigned level);
  1804. bool r600_fmt_is_valid_color(u32 format);
  1805. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  1806. int r600_fmt_get_blocksize(u32 format);
  1807. int r600_fmt_get_nblocksx(u32 format, u32 w);
  1808. int r600_fmt_get_nblocksy(u32 format, u32 h);
  1809. /*
  1810. * r600 functions used by radeon_encoder.c
  1811. */
  1812. struct radeon_hdmi_acr {
  1813. u32 clock;
  1814. int n_32khz;
  1815. int cts_32khz;
  1816. int n_44_1khz;
  1817. int cts_44_1khz;
  1818. int n_48khz;
  1819. int cts_48khz;
  1820. };
  1821. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  1822. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1823. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1824. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1825. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  1826. u32 tiling_pipe_num,
  1827. u32 max_rb_num,
  1828. u32 total_max_rb_num,
  1829. u32 enabled_rb_mask);
  1830. /*
  1831. * evergreen functions used by radeon_encoder.c
  1832. */
  1833. extern void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1834. extern int ni_init_microcode(struct radeon_device *rdev);
  1835. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1836. /* radeon_acpi.c */
  1837. #if defined(CONFIG_ACPI)
  1838. extern int radeon_acpi_init(struct radeon_device *rdev);
  1839. extern void radeon_acpi_fini(struct radeon_device *rdev);
  1840. #else
  1841. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1842. static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
  1843. #endif
  1844. int radeon_cs_packet_parse(struct radeon_cs_parser *p,
  1845. struct radeon_cs_packet *pkt,
  1846. unsigned idx);
  1847. bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
  1848. void radeon_cs_dump_packet(struct radeon_cs_parser *p,
  1849. struct radeon_cs_packet *pkt);
  1850. int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
  1851. struct radeon_cs_reloc **cs_reloc,
  1852. int nomm);
  1853. int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
  1854. uint32_t *vline_start_end,
  1855. uint32_t *vline_status);
  1856. #include "radeon_object.h"
  1857. #endif