radeon.h 62 KB

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